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
 
class  TreeLockGuard
 

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 const 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 ()
 
Device * getPhysicalFunction () const
 
size_t getVirtualFunctionIndex () const
 
void setVirtualFunction (Device *physicalFunction, size_t index)
 
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 bool treeLockHeldByCurrentThread ()
 
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
 
Device * m_PhysicalFunction
 
size_t m_VirtualFunctionIndex
 
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 41 of file Device.h.

Member Typedef Documentation

◆ Callback

typedef Device *(* Device::Callback) (Device *)

Definition at line 43 of file Device.h.

Member Enumeration Documentation

◆ 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.

Definition at line 72 of file Device.h.

Constructor & Destructor Documentation

◆ Device() [1/2]

Device::Device ( )

Definition at line 48 of file Device.cc.

◆ Device() [2/2]

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 66 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, Vector< T >::pushBack(), and removeIoMappings().

◆ ~Device()

Device::~Device ( )
virtual

Definition at line 98 of file Device.cc.

Member Function Documentation

◆ addChild()

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 135 of file Device.cc.

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

Referenced by addToRoot(), and Pc::initialiseDeviceTree().

+ Here is the caller graph for this function:

◆ addresses()

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

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

Definition at line 266 of file Device.h.

Referenced by Pc::initialiseDeviceTree(), and PciAtaController::PciAtaController().

+ Here is the caller graph for this function:

◆ addToRoot()

void Device::addToRoot ( Device *  device)
static

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

Definition at line 114 of file Device.cc.

References addChild(), and root().

Referenced by Pc::initialiseDeviceTree().

+ Here is the caller graph for this function:

◆ dump()

virtual void Device::dump ( String &  str)
inlinevirtual

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

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

Definition at line 261 of file Device.h.

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

+ Here is the caller graph for this function:

◆ foreach() [1/2]

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 107 of file Device.cc.

References root().

Referenced by DeviceHashTree::fill(), ProcFs::initialise(), UsbPnP::reprobeDevices(), PciDevicesFile::resync(), and MountService::serve().

+ Here is the caller graph for this function:

◆ foreach() [2/2]

template<class F , class... Args>
void Device::foreach ( pedigree_std::Callable< F > &  callback,
Device *  root,
Args...  args 
)
static

Definition at line 388 of file Device.h.

◆ foreachInternal() [1/2]

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

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

◆ foreachInternal() [2/2]

template<class F , class... Args>
void Device::foreachInternal ( pedigree_std::Callable< F > &  callback,
Device *  root,
Args...  args 
)
staticprivate

Definition at line 401 of file Device.h.

◆ getChild()

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 139 of file Device.cc.

References m_Children.

Referenced by IsaAtaController::irq(), PciAtaController::irq(), AtaController::maskDiskInterrupts(), searchByVendorIdInternal(), ScsiController::shutdownDiskCaches(), and AtaController::stopDiskDma().

+ Here is the caller graph for this function:

◆ getInterruptNumber()

virtual uintptr_t Device::getInterruptNumber ( )
inlinevirtual

Returns the interrupt number of the device.

Definition at line 271 of file Device.h.

Referenced by AtaDisk::doRead(), AtaDisk::initialise(), PciAtaController::irq(), Ne2k::Ne2k(), PciAtaController::PciAtaController(), Pic::registerHardPciIrqHandler(), Pic::registerPciIrqHandler(), and AtaDisk::writePageBuffer().

+ Here is the caller graph for this function:

◆ getName()

void Device::getName ( String &  str)
virtual

◆ getNumChildren()

size_t Device::getNumChildren ( )

Returns the number of children this device has.

Retrieves the number of children of this device.

Definition at line 143 of file Device.cc.

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

Referenced by IsaAtaController::irq(), PciAtaController::irq(), AtaController::maskDiskInterrupts(), searchByVendorIdInternal(), ScsiController::shutdownDiskCaches(), and AtaController::stopDiskDma().

+ Here is the caller graph for this function:

◆ getParent()

Device * Device::getParent ( ) const
inline

◆ getPciBusPosition()

uint32_t Device::getPciBusPosition ( )
inline

Returns the PCI bus position for this device.

Definition at line 236 of file Device.h.

Referenced by DeviceHashTree::getHash().

+ Here is the caller graph for this function:

◆ getPciClassCode()

uint8_t Device::getPciClassCode ( )
inline

Returns the PCI class code.

Definition at line 216 of file Device.h.

◆ getPciConfigHeader()

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

Returns the PCI configuration header in full.

Definition at line 212 of file Device.h.

◆ getPciDeviceId()

uint16_t Device::getPciDeviceId ( )
inline

Returns the PCI device ID.

Definition at line 228 of file Device.h.

Referenced by PciAtaController::PciAtaController().

+ Here is the caller graph for this function:

◆ getPciDevicePosition()

uint32_t Device::getPciDevicePosition ( )
inline

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

Definition at line 240 of file Device.h.

Referenced by DeviceHashTree::getHash().

+ Here is the caller graph for this function:

◆ getPciFunctionNumber()

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().

+ Here is the caller graph for this function:

◆ getPciProgInterface()

uint8_t Device::getPciProgInterface ( )
inline

Returns the PCI programming interface.

Definition at line 232 of file Device.h.

Referenced by PciAtaController::PciAtaController().

+ Here is the caller graph for this function:

◆ getPciSubclassCode()

uint8_t Device::getPciSubclassCode ( )
inline

Returns the PCI subclass code.

Definition at line 220 of file Device.h.

◆ getPciVendorId()

uint16_t Device::getPciVendorId ( )
inline

Returns the PCI vendor ID.

Definition at line 224 of file Device.h.

Referenced by searchByVendorIdInternal().

+ Here is the caller graph for this function:

◆ getPhysicalFunction()

Device * Device::getPhysicalFunction ( ) const
inline

Definition at line 248 of file Device.h.

◆ getSpecificType()

virtual const String & Device::getSpecificType ( )
inlinevirtual

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

Definition at line 183 of file Device.h.

◆ getType()

virtual Type Device::getType ( )
inlinevirtual

Returns the (abstract) type of the device.

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

Definition at line 178 of file Device.h.

Referenced by UsbHub::disconnectAllDevices(), UsbPnP::doProbe(), UsbPnP::probeDevice(), and UsbPnP::reprobeDevices().

+ Here is the caller graph for this function:

◆ getVirtualFunctionIndex()

size_t Device::getVirtualFunctionIndex ( ) const
inline

Definition at line 251 of file Device.h.

◆ removeChild() [1/2]

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 157 of file Device.cc.

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

◆ removeChild() [2/2]

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 147 of file Device.cc.

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

Referenced by UsbHub::disconnectAllDevices(), and UsbDeviceContainer::replaceUsbDevice().

+ Here is the caller graph for this function:

◆ removeIoMappings()

void Device::removeIoMappings ( )
private

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

Definition at line 121 of file Device.cc.

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

Referenced by Device().

+ Here is the caller graph for this function:

◆ replaceChild()

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 166 of file Device.cc.

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

◆ root()

static Device & Device::root ( )
inlinestaticprotected

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

Definition at line 344 of file Device.h.

Referenced by addToRoot(), foreach(), searchByVendorId(), and searchByVendorIdInternal().

+ Here is the caller graph for this function:

◆ searchByClass()

void Device::searchByClass ( uint16_t  classCode,
void(*)(Device *)  callback,
Device *  root = 0 
)
static

Definition at line 198 of file Device.cc.

◆ searchByClassAndSubclass()

void Device::searchByClassAndSubclass ( uint16_t  classCode,
uint16_t  subclassCode,
void(*)(Device *)  callback,
Device *  root = 0 
)
static

Definition at line 208 of file Device.cc.

◆ searchByClassAndSubclassInternal()

void Device::searchByClassAndSubclassInternal ( uint16_t  classCode,
uint16_t  subclassCode,
void(*)(Device *)  callback,
Device *  root 
)
staticprivate

Definition at line 278 of file Device.cc.

◆ searchByClassInternal()

void Device::searchByClassInternal ( uint16_t  classCode,
void(*)(Device *)  callback,
Device *  root 
)
staticprivate

Definition at line 263 of file Device.cc.

◆ searchByClassSubclassAndProgInterface()

void Device::searchByClassSubclassAndProgInterface ( uint16_t  classCode,
uint16_t  subclassCode,
uint8_t  progInterface,
void(*)(Device *)  callback,
Device *  root = 0 
)
static

Definition at line 219 of file Device.cc.

◆ searchByClassSubclassAndProgInterfaceInternal()

void Device::searchByClassSubclassAndProgInterfaceInternal ( uint16_t  classCode,
uint16_t  subclassCode,
uint8_t  progInterface,
void(*)(Device *)  callback,
Device *  root 
)
staticprivate

Definition at line 295 of file Device.cc.

◆ searchByVendorId()

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

Search functions

Definition at line 177 of file Device.cc.

References root(), and searchByVendorIdInternal().

◆ searchByVendorIdAndDeviceId()

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

Definition at line 187 of file Device.cc.

◆ searchByVendorIdAndDeviceIdInternal()

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

Definition at line 247 of file Device.cc.

◆ searchByVendorIdInternal()

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

Do-ers for search functions.

Definition at line 232 of file Device.cc.

References getChild(), getNumChildren(), getPciVendorId(), root(), and searchByVendorIdInternal().

Referenced by searchByVendorId(), and searchByVendorIdInternal().

+ Here is the caller graph for this function:

◆ setInterruptNumber()

virtual void Device::setInterruptNumber ( uintptr_t  n)
inlinevirtual

Sets the interrupt number of the device.

Definition at line 276 of file Device.h.

Referenced by Pc::initialiseDeviceTree().

+ Here is the caller graph for this function:

◆ setParent()

void Device::setParent ( Device *  p)
inline

Sets the device's parent.

Definition at line 170 of file Device.h.

Referenced by UsbHub::disconnectAllDevices(), Pc::initialiseDeviceTree(), and UsbDeviceContainer::replaceUsbDevice().

+ Here is the caller graph for this function:

◆ setPciConfigHeader()

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

Set the PCI configuration header.

Definition at line 208 of file Device.h.

◆ setPciIdentifiers()

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 199 of file Device.h.

◆ setPciPosition()

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

PCI-specific location identifiers

Definition at line 192 of file Device.h.

◆ setSpecificType()

virtual void Device::setSpecificType ( String  str)
inlinevirtual

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

Definition at line 187 of file Device.h.

Referenced by Pc::initialiseDeviceTree(), Ne2k::Ne2k(), Nic3C90x::Nic3C90x(), and PciAtaController::PciAtaController().

+ Here is the caller graph for this function:

◆ setVirtualFunction()

void Device::setVirtualFunction ( Device *  physicalFunction,
size_t  index 
)
inline

Set by the PF owner, which retains the VF's BAR apertures and lifetime.

Definition at line 255 of file Device.h.

◆ treeLockHeldByCurrentThread()

bool Device::treeLockHeldByCurrentThread ( )
static

Allows callbacks shared by tree traversals and runtime discovery to preserve the caller's existing tree lock without acquiring it twice.

Definition at line 40 of file Device.cc.

References Mutex::isOwnedByCurrentThread(), and m_TreeLock.

Referenced by PartitionService::serve().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_Addresses

Vector<Address*> Device::m_Addresses
protected

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

Definition at line 349 of file Device.h.

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

◆ m_Children

Vector<Device*> Device::m_Children
protected

◆ m_ClassCode

uint8_t Device::m_ClassCode
protected

PCI Device class

Definition at line 365 of file Device.h.

◆ m_ConfigHeader

PciBus::ConfigSpace Device::m_ConfigHeader
protected

PCI config header.

Definition at line 363 of file Device.h.

◆ m_DeviceId

uint16_t Device::m_DeviceId
protected

PCI Device ID

Definition at line 371 of file Device.h.

◆ m_InterruptNumber

uintptr_t Device::m_InterruptNumber
protected

The interrupt number

Definition at line 359 of file Device.h.

◆ m_PciBusPos

uint32_t Device::m_PciBusPos
protected

PCI Bus number

Definition at line 376 of file Device.h.

◆ m_PciDevicePos

uint32_t Device::m_PciDevicePos
protected

PCI Device number

Definition at line 378 of file Device.h.

◆ m_PciFunctionNum

uint32_t Device::m_PciFunctionNum
protected

PCI Function number

Definition at line 380 of file Device.h.

◆ m_PhysicalFunction

Device* Device::m_PhysicalFunction
protected

Definition at line 354 of file Device.h.

◆ m_pParent

Device* Device::m_pParent
protected

◆ m_ProgInterface

uint8_t Device::m_ProgInterface
protected

PCI Programming Interface

Definition at line 373 of file Device.h.

◆ m_Root

Device Device::m_Root
staticprotected

The root node.

Singleton Device instantiation.

Definition at line 357 of file Device.h.

◆ m_SpecificType

String Device::m_SpecificType
protected

The specific device type

Definition at line 361 of file Device.h.

◆ m_SubclassCode

uint8_t Device::m_SubclassCode
protected

PCI subclass

Definition at line 367 of file Device.h.

◆ m_TreeLock

Mutex Device::m_TreeLock
staticprotected

Lock to manage access to the device tree.

Definition at line 383 of file Device.h.

Referenced by treeLockHeldByCurrentThread().

◆ m_VendorId

uint16_t Device::m_VendorId
protected

PCI Vendor ID

Definition at line 369 of file Device.h.

◆ m_VirtualFunctionIndex

size_t Device::m_VirtualFunctionIndex
protected

Definition at line 355 of file Device.h.


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