The Pedigree Project
0.1
|
#include <Device.h>
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) | |
Device * | getParent () 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) |
Device * | getChild (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 Device & | root () |
Protected Attributes | |
Vector< Address * > | m_Addresses |
Vector< Device * > | m_Children |
Device * | m_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) |
Represents a node in the device tree. This could either be a bus (non-leaf node) or a device (leaf node).
enum Device::Type |
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. |
Device::Device | ( | Device * | p | ) |
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().
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().
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().
|
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().
|
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().
|
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.
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().
|
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().
|
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().
|
virtual |
Stores the device's name in str.
Reimplemented in UsbDeviceContainer, VmwareGraphics, Ohci, Ehci, Uhci, ScsiDisk, Display, Network, AtaDisk, FileDisk, Ib700Watchdog, AtaController, Disk, Ne2k, Loopback, PciAtaController, Rtl8139, Ps2Mouse, Ps2Controller, Dm9601, Nic3C90x, IsaAtaController, DiskImage, CdiDisk, UsbHubDevice, Bus, Controller, CdiNet, and Partition.
Definition at line 121 of file Device.cc.
Referenced by DevicesCommand::execute(), DeviceHashTree::getHash(), and RawFs::getRoot().
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().
|
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().
|
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().
|
inline |
Returns the PCI class code.
Definition at line 209 of file Device.h.
Referenced by searchByVendorIdInternal().
|
inline |
|
inline |
Returns the PCI device ID.
Definition at line 224 of file Device.h.
Referenced by PciAtaController::PciAtaController(), and searchByVendorIdInternal().
|
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().
|
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().
|
inline |
Returns the PCI programming interface.
Definition at line 229 of file Device.h.
Referenced by PciAtaController::PciAtaController(), and searchByVendorIdInternal().
|
inline |
Returns the PCI subclass code.
Definition at line 214 of file Device.h.
Referenced by searchByVendorIdInternal().
|
inline |
Returns the PCI vendor ID.
Definition at line 219 of file Device.h.
Referenced by searchByVendorIdInternal().
|
inlinevirtual |
Returns the (specific) type of the device, in string form.
Definition at line 169 of file Device.h.
Referenced by DevicesCommand::execute().
|
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().
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().
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.
|
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().
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.
|
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().
|
static |
Search functions
Definition at line 182 of file Device.cc.
References root(), and searchByVendorIdInternal().
|
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().
|
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().
|
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().
|
inline |
|
inline |
PCI-specific identifiers - class code, subclass code, vendor and device ID
Definition at line 188 of file Device.h.
Referenced by ArmBeagle::initialiseDeviceTree().
|
inline |
|
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().
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().
The children of this device.
Definition at line 364 of file Device.h.
Referenced by addChild(), NetworkStack::deRegisterDevice(), Device(), UsbHub::deviceDisconnected(), getChild(), NetworkStack::getDevice(), getNumChildren(), NetworkStack::getNumDevices(), PciAtaController::PciAtaController(), NetworkStack::registerDevice(), removeChild(), and replaceChild().
|
protected |
|
protected |
|
protected |
|
protected |
|
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().
|
protected |
|
staticprotected |
|
protected |
|
staticprotected |