The Pedigree Project  0.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Static Private Member Functions | List of all members
Device Class Reference

#include <Device.h>

+ Inheritance diagram for Device:
+ Collaboration diagram for Device:

Classes

class  Address
 

Public Types

enum  Type {
  Generic, Root, Disk, Bus,
  Display, Network, Sound, Console,
  Mouse, Controller, UsbController, UsbGeneric,
  UsbContainer
}
 
typedef Device *(* Callback) (Device *)
 

Public Member Functions

 Device (Device *p)
 
DevicegetParent () const
 
void setParent (Device *p)
 
virtual void getName (String &str)
 
virtual Type getType ()
 
virtual String getSpecificType ()
 
virtual void setSpecificType (String str)
 
void setPciPosition (uint32_t bus, uint32_t device, uint32_t func)
 
void setPciIdentifiers (uint8_t classCode, uint8_t subclassCode, uint16_t vendorId, uint16_t deviceId, uint8_t progIf)
 
void setPciConfigHeader (const PciBus::ConfigSpace &space)
 
PciBus::ConfigSpace getPciConfigHeader () const
 
uint8_t getPciClassCode ()
 
uint8_t getPciSubclassCode ()
 
uint16_t getPciVendorId ()
 
uint16_t getPciDeviceId ()
 
uint8_t getPciProgInterface ()
 
uint32_t getPciBusPosition ()
 
uint32_t getPciDevicePosition ()
 
uint32_t getPciFunctionNumber ()
 
virtual void dump (String &str)
 
virtual Vector< Address * > & addresses ()
 
virtual uintptr_t getInterruptNumber ()
 
virtual void setInterruptNumber (uintptr_t n)
 
void addChild (Device *pDevice)
 
DevicegetChild (size_t n)
 
size_t getNumChildren ()
 
void removeChild (size_t n)
 
void removeChild (Device *d)
 
void replaceChild (Device *src, Device *dest)
 

Static Public Member Functions

static void foreach (Callback callback, Device *root=0)
 
template<class F , class... Args>
static void foreach (pedigree_std::Callable< F > &callback, Device *root, Args...args)
 
static void addToRoot (Device *device)
 
static void searchByVendorId (uint16_t vendorId, void(*callback)(Device *), Device *root=0)
 
static void searchByVendorIdAndDeviceId (uint16_t vendorId, uint16_t deviceId, void(*callback)(Device *), Device *root=0)
 
static void searchByClass (uint16_t classCode, void(*callback)(Device *), Device *root=0)
 
static void searchByClassAndSubclass (uint16_t classCode, uint16_t subclassCode, void(*callback)(Device *), Device *root=0)
 
static void searchByClassSubclassAndProgInterface (uint16_t classCode, uint16_t subclassCode, uint8_t progInterface, void(*callback)(Device *), Device *root=0)
 

Protected Member Functions

 NOT_COPYABLE_OR_ASSIGNABLE (Device)
 

Static Protected Member Functions

static Deviceroot ()
 

Protected Attributes

Vector< Address * > m_Addresses
 
Vector< Device * > m_Children
 
Devicem_pParent
 
uintptr_t m_InterruptNumber
 
String m_SpecificType
 
PciBus::ConfigSpace m_ConfigHeader
 
uint8_t m_ClassCode
 
uint8_t m_SubclassCode
 
uint16_t m_VendorId
 
uint16_t m_DeviceId
 
uint8_t m_ProgInterface
 
uint32_t m_PciBusPos
 
uint32_t m_PciDevicePos
 
uint32_t m_PciFunctionNum
 

Static Protected Attributes

static Device m_Root
 
static Mutex m_TreeLock
 

Private Member Functions

void removeIoMappings ()
 

Static Private Member Functions

static void foreachInternal (Callback callback, Device *root)
 
template<class F , class... Args>
static void foreachInternal (pedigree_std::Callable< F > &callback, Device *root, Args...args)
 
static void searchByVendorIdInternal (uint16_t vendorId, void(*callback)(Device *), Device *root)
 
static void searchByVendorIdAndDeviceIdInternal (uint16_t vendorId, uint16_t deviceId, void(*callback)(Device *), Device *root)
 
static void searchByClassInternal (uint16_t classCode, void(*callback)(Device *), Device *root)
 
static void searchByClassAndSubclassInternal (uint16_t classCode, uint16_t subclassCode, void(*callback)(Device *), Device *root)
 
static void searchByClassSubclassAndProgInterfaceInternal (uint16_t classCode, uint16_t subclassCode, uint8_t progInterface, void(*callback)(Device *), Device *root)
 

Detailed Description

Represents a node in the device tree. This could either be a bus (non-leaf node) or a device (leaf node).

Definition at line 43 of file Device.h.

Member Enumeration Documentation

Every device has a type. This can be used to downcast to a more specific class during runtime without RTTI.

Enumerator
Generic 

The device type is not covered by any other value.

Root 

The device is the root of the device tree.

Disk 

A disk device - a block device in UNIX terms.

Bus 

A node that performs address space translation and I/O multiplexing.

Display 

A display device. This can either be a dumb framebuffer or something more complex.

Network 

A communication device.

Sound 

A device that can play sounds.

Console 

A keyboard-like human interface device.

Mouse 

A mouse-like human interface device (includes trackpads and styluses)

Controller 

A device which exposes other devices but requires a driver, and does no address space translation.

UsbController 

Same as Controller, but exposes USB devices.

UsbGeneric 

Same as Generic, but for USB devices.

UsbContainer 

Wraps a UsbDevice (which does not inherit Device) in a Device so it can be in the tree.

Definition at line 50 of file Device.h.

Constructor & Destructor Documentation

Device::Device ( Device p)
Warning
This renders 'p' unusable - it deletes all its IoPorts and MemoryMappedIo's. This is because the new Device must have access to the IoBases of the old device, and multiple instances of the same IoBase cannot be shared!

Definition at line 51 of file Device.cc.

References Vector< T >::count(), Hex, Device::Address::m_Address, m_Addresses, m_Children, Device::Address::m_Io, Device::Address::m_IsIoSpace, Device::Address::m_Name, Device::Address::m_Padding, m_pParent, Device::Address::m_Size, NOTICE, Vector< T >::pushBack(), and removeIoMappings().

Member Function Documentation

void Device::addChild ( Device pDevice)

Sets pDevice as a child of this device. pDevice's parent is NOT updated.

Adds a device as a child of this device.

Definition at line 127 of file Device.cc.

References m_Children, and Vector< T >::pushBack().

Referenced by addToRoot(), UsbHub::deviceConnected(), ArmBeagle::initialiseDeviceTree(), Pc::initialiseDeviceTree(), PciAtaController::PciAtaController(), and Mac::~Mac().

+ Here is the caller graph for this function:

virtual Vector<Address *>& Device::addresses ( )
inlinevirtual

Returns the addresses of the device, in its parent's address space

Definition at line 256 of file Device.h.

Referenced by ArmBeagle::initialiseDeviceTree(), Pc::initialiseDeviceTree(), PciAtaController::PciAtaController(), Heathrow::unregisterHandler(), and OpenPic::unregisterHandler().

+ Here is the caller graph for this function:

void Device::addToRoot ( Device device)
static

Adds the given object to the root of the device tree, atomically.

Definition at line 102 of file Device.cc.

References addChild(), root(), and setParent().

Referenced by ArmBeagle::initialiseDeviceTree(), Pc::initialiseDeviceTree(), CdiNet::setStationInfo(), and CdiDisk::write().

+ Here is the caller graph for this function:

virtual void Device::dump ( String str)
inlinevirtual

Dumps a textual representation of the device into the given string.

Reimplemented in UsbDeviceContainer, VmwareGraphics, Display, Network, Disk, Ps2Controller, Partition, DiskImage, Bus, and Controller.

Definition at line 250 of file Device.h.

Referenced by DeviceHashTree::add(), DevicesCommand::execute(), and DeviceHashTree::getHash().

+ Here is the caller graph for this function:

void Device::foreach ( Device::Callback  callback,
Device root = 0 
)
static

Traverses the full device tree, calling the given callback for each item.

This will take a lock if threading is enabled, such that any operations taking place on the device tree will block until iteration completes.

To facilitate environments that may need to replace objects, the callback returns a Device pointer. If this pointer is null, the referenced Device is removed from the tree. If this pointer is different to the original, the original is replaced by the new pointer in the tree. Otherwise, if the pointer does not differ, no action is taken.

This characteristic allows for a full traversal to be performed, editing the tree along the way, safely and without conflicting with other attempts to edit the tree.

You, in almost every case, want this function if the Device you're editing is already linked into the Device tree.

Todo:

add filters to avoid the need to filter in callbacks

add a way to end iteration early

Definition at line 94 of file Device.cc.

Referenced by DevicesCommand::execute(), DeviceHashTree::fill(), ProcFs::initialise(), UsbPnP::reprobeDevices(), PciDevicesFile::resync(), PartitionService::serve(), and CdiNet::setStationInfo().

+ Here is the caller graph for this function:

static void Device::foreachInternal ( Callback  callback,
Device root 
)
staticprivate

Actual do-er for foreach (does not take lock).

Device * Device::getChild ( size_t  n)

Returns the n'th child of this device, or 0 if the device has less than n children.

Retrieves the n'th child of this device.

Definition at line 132 of file Device.cc.

References m_Children.

Referenced by DevicesCommand::execute(), RawFs::getRoot(), PciAtaController::irq(), PciAtaController::PciAtaController(), searchByVendorIdInternal(), Heathrow::unregisterHandler(), and OpenPic::unregisterHandler().

+ Here is the caller graph for this function:

virtual uintptr_t Device::getInterruptNumber ( )
inlinevirtual

Returns the interrupt number of the device.

Definition at line 262 of file Device.h.

Referenced by AtaDisk::doRead(), AtaDisk::doWrite(), AtaDisk::initialise(), PciAtaController::irq(), Ne2k::Ne2k(), Nic3C90x::Nic3C90x(), PciAtaController::PciAtaController(), HostedIrqManager::registerPciIrqHandler(), and Pic::registerPciIrqHandler().

+ Here is the caller graph for this function:

void Device::getName ( String str)
virtual
size_t Device::getNumChildren ( )

Returns the number of children this device has.

Retrieves the number of children of this device.

Definition at line 137 of file Device.cc.

References Vector< T >::count(), and m_Children.

Referenced by DevicesCommand::execute(), RawFs::getRoot(), AtaController::irq(), PciAtaController::irq(), PciAtaController::PciAtaController(), searchByVendorIdInternal(), Heathrow::unregisterHandler(), and OpenPic::unregisterHandler().

+ Here is the caller graph for this function:

Device* Device::getParent ( ) const
inline

Returns the device's parent

Definition at line 149 of file Device.h.

Referenced by UsbHub::deviceConnected(), UsbHub::deviceDisconnected(), DevicesCommand::execute(), Partition::getBlockSize(), Dm9601::initialiseDriver(), Ne2k::Ne2k(), Nic3C90x::Nic3C90x(), Partition::read(), and Partition::write().

+ Here is the caller graph for this function:

uint32_t Device::getPciBusPosition ( )
inline

Returns the PCI bus position for this device.

Definition at line 234 of file Device.h.

Referenced by DeviceHashTree::getHash(), PciBus::readConfigSpace(), and PciBus::writeConfigSpace().

+ Here is the caller graph for this function:

uint8_t Device::getPciClassCode ( )
inline

Returns the PCI class code.

Definition at line 209 of file Device.h.

Referenced by searchByVendorIdInternal().

+ Here is the caller graph for this function:

PciBus::ConfigSpace Device::getPciConfigHeader ( ) const
inline

Returns the PCI configuration header in full.

Definition at line 204 of file Device.h.

uint16_t Device::getPciDeviceId ( )
inline

Returns the PCI device ID.

Definition at line 224 of file Device.h.

Referenced by PciAtaController::PciAtaController(), and searchByVendorIdInternal().

+ Here is the caller graph for this function:

uint32_t Device::getPciDevicePosition ( )
inline

Returns the PCI device position on the bus for this device.

Definition at line 239 of file Device.h.

Referenced by DeviceHashTree::getHash(), PciBus::readConfigSpace(), and PciBus::writeConfigSpace().

+ Here is the caller graph for this function:

uint32_t Device::getPciFunctionNumber ( )
inline

Returns the PCI Function number for this device.

Definition at line 244 of file Device.h.

Referenced by DeviceHashTree::getHash(), PciBus::readConfigSpace(), and PciBus::writeConfigSpace().

+ Here is the caller graph for this function:

uint8_t Device::getPciProgInterface ( )
inline

Returns the PCI programming interface.

Definition at line 229 of file Device.h.

Referenced by PciAtaController::PciAtaController(), and searchByVendorIdInternal().

+ Here is the caller graph for this function:

uint8_t Device::getPciSubclassCode ( )
inline

Returns the PCI subclass code.

Definition at line 214 of file Device.h.

Referenced by searchByVendorIdInternal().

+ Here is the caller graph for this function:

uint16_t Device::getPciVendorId ( )
inline

Returns the PCI vendor ID.

Definition at line 219 of file Device.h.

Referenced by searchByVendorIdInternal().

+ Here is the caller graph for this function:

virtual String Device::getSpecificType ( )
inlinevirtual

Returns the (specific) type of the device, in string form.

Definition at line 169 of file Device.h.

Referenced by DevicesCommand::execute().

+ Here is the caller graph for this function:

virtual Type Device::getType ( )
inlinevirtual

Returns the (abstract) type of the device.

Reimplemented in UsbDeviceContainer, Display, Network, Disk, UsbHub, Controller, and Bus.

Definition at line 163 of file Device.h.

Referenced by UsbHub::deviceConnected(), UsbHub::deviceDisconnected(), UsbPnP::doProbe(), and RawFs::getRoot().

+ Here is the caller graph for this function:

void Device::removeChild ( size_t  n)

Removes the n'th child from this device. The result is undefined if the device does not have n children.

Removes the n'th child of this device.

Definition at line 142 of file Device.cc.

References Vector< T >::begin(), Vector< T >::end(), Vector< T >::erase(), and m_Children.

Referenced by PciAtaController::PciAtaController().

+ Here is the caller graph for this function:

void Device::removeChild ( Device d)

Attempts to find the device d, if found, removes it.

Removes the given Device from this device's child list.

Definition at line 156 of file Device.cc.

References Vector< T >::begin(), Vector< T >::end(), Vector< T >::erase(), and m_Children.

void Device::removeIoMappings ( )
private

Destroys all IoBases in this class. Called from the constructor Device(Device*).

Definition at line 110 of file Device.cc.

References m_Addresses, and Device::Address::m_Io.

Referenced by Device().

+ Here is the caller graph for this function:

void Device::replaceChild ( Device src,
Device dest 
)

Attempts to find the device src in this device's children. If found, it replaces 'src' with 'dest' in this device's child list, so that 'src' is no longer a child of this device, and 'dest' is, in the same position that 'src' was.

Definition at line 168 of file Device.cc.

References Vector< T >::begin(), Vector< T >::end(), and m_Children.

static Device& Device::root ( )
inlinestaticprotected

Retrieves the root device. Still needs to be public for RawFs...

Definition at line 356 of file Device.h.

Referenced by addToRoot(), Heathrow::initialise(), OpenPic::initialise(), Mac::initialiseDeviceTree(), and searchByVendorId().

+ Here is the caller graph for this function:

void Device::searchByVendorId ( uint16_t  vendorId,
void(*)(Device *)  callback,
Device root = 0 
)
static

Search functions

Definition at line 182 of file Device.cc.

References root(), and searchByVendorIdInternal().

void Device::searchByVendorIdInternal ( uint16_t  vendorId,
void(*)(Device *)  callback,
Device root 
)
staticprivate

Do-ers for search functions.

Definition at line 251 of file Device.cc.

References getChild(), getNumChildren(), getPciClassCode(), getPciDeviceId(), getPciProgInterface(), getPciSubclassCode(), and getPciVendorId().

Referenced by searchByVendorId().

+ Here is the caller graph for this function:

virtual void Device::setInterruptNumber ( uintptr_t  n)
inlinevirtual

Sets the interrupt number of the device.

Definition at line 268 of file Device.h.

Referenced by ArmBeagle::initialiseDeviceTree(), Pc::initialiseDeviceTree(), PciAtaController::PciAtaController(), and Mac::~Mac().

+ Here is the caller graph for this function:

void Device::setParent ( Device p)
inline

Sets the device's parent.

Definition at line 154 of file Device.h.

Referenced by addToRoot(), UsbHub::deviceConnected(), UsbDevice::getString(), ArmBeagle::initialiseDeviceTree(), Pc::initialiseDeviceTree(), and Mac::~Mac().

+ Here is the caller graph for this function:

void Device::setPciConfigHeader ( const PciBus::ConfigSpace space)
inline

Set the PCI configuration header.

Definition at line 199 of file Device.h.

void Device::setPciIdentifiers ( uint8_t  classCode,
uint8_t  subclassCode,
uint16_t  vendorId,
uint16_t  deviceId,
uint8_t  progIf 
)
inline

PCI-specific identifiers - class code, subclass code, vendor and device ID

Definition at line 188 of file Device.h.

Referenced by ArmBeagle::initialiseDeviceTree().

+ Here is the caller graph for this function:

void Device::setPciPosition ( uint32_t  bus,
uint32_t  device,
uint32_t  func 
)
inline

PCI-specific location identifiers

Definition at line 180 of file Device.h.

virtual void Device::setSpecificType ( String  str)
inlinevirtual

Sets the specific type of the device, in string form.

Definition at line 174 of file Device.h.

Referenced by CdiNet::CdiNet(), ArmBeagle::initialiseDeviceTree(), Pc::initialiseDeviceTree(), Ne2k::Ne2k(), Nic3C90x::Nic3C90x(), PciAtaController::PciAtaController(), and Mac::~Mac().

+ Here is the caller graph for this function:

Member Data Documentation

Vector<Address *> Device::m_Addresses
protected

The address of this device, in its parent's address space.

Definition at line 362 of file Device.h.

Referenced by Device(), Ne2k::Ne2k(), Nic3C90x::Nic3C90x(), and removeIoMappings().

Vector<Device *> Device::m_Children
protected
uint8_t Device::m_ClassCode
protected

PCI Device class

Definition at line 380 of file Device.h.

PciBus::ConfigSpace Device::m_ConfigHeader
protected

PCI config header.

Definition at line 378 of file Device.h.

uint16_t Device::m_DeviceId
protected

PCI Device ID

Definition at line 386 of file Device.h.

uintptr_t Device::m_InterruptNumber
protected

The interrupt number

Definition at line 370 of file Device.h.

uint32_t Device::m_PciBusPos
protected

PCI Bus number

Definition at line 391 of file Device.h.

uint32_t Device::m_PciDevicePos
protected

PCI Device number

Definition at line 393 of file Device.h.

uint32_t Device::m_PciFunctionNum
protected

PCI Function number

Definition at line 395 of file Device.h.

Device* Device::m_pParent
protected

This device's parent.

Definition at line 366 of file Device.h.

Referenced by Device(), ScsiDisk::flush(), AtaDisk::initialise(), ScsiDisk::initialise(), ScsiDisk::read(), and ScsiDisk::write().

uint8_t Device::m_ProgInterface
protected

PCI Programming Interface

Definition at line 388 of file Device.h.

Device Device::m_Root
staticprotected

The root node.

Singleton Device instantiation.

Definition at line 368 of file Device.h.

String Device::m_SpecificType
protected

The specific device type

Definition at line 372 of file Device.h.

uint8_t Device::m_SubclassCode
protected

PCI subclass

Definition at line 382 of file Device.h.

Mutex Device::m_TreeLock
staticprotected

Lock to manage access to the device tree.

Definition at line 398 of file Device.h.

uint16_t Device::m_VendorId
protected

PCI Vendor ID

Definition at line 384 of file Device.h.


The documentation for this class was generated from the following files: