20 #include "pedigree/kernel/machine/Device.h" 21 #include "pedigree/kernel/Log.h" 22 #include "pedigree/kernel/processor/IoBase.h" 23 #include "pedigree/kernel/processor/IoPort.h" 24 #include "pedigree/kernel/processor/MemoryMappedIo.h" 25 #include "pedigree/kernel/processor/PhysicalMemoryManager.h" 26 #include "pedigree/kernel/processor/VirtualAddressSpace.h" 29 #include "pedigree/kernel/LockGuard.h" 30 #define RAII_LOCK() LockGuard<Mutex> guard(m_TreeLock) 41 : m_Addresses(), m_Children(), m_pParent(0),
45 m_InterruptNumber(0), m_SpecificType(), m_ConfigHeader(), m_ClassCode(0),
46 m_SubclassCode(0), m_VendorId(0), m_DeviceId(0), m_ProgInterface(0),
47 m_PciBusPos(0), m_PciDevicePos(0), m_PciFunctionNum(0)
52 : m_Addresses(), m_Children(), m_pParent(0),
53 m_InterruptNumber(p->m_InterruptNumber),
57 m_SpecificType(p->m_SpecificType), m_ConfigHeader(p->m_ConfigHeader),
58 m_ClassCode(p->m_ClassCode), m_SubclassCode(p->m_SubclassCode),
59 m_VendorId(p->m_VendorId), m_DeviceId(p->m_DeviceId),
60 m_ProgInterface(p->m_ProgInterface), m_PciBusPos(p->m_PciBusPos),
61 m_PciDevicePos(p->m_PciDevicePos), m_PciFunctionNum(p->m_PciFunctionNum)
71 for (
unsigned int i = 0; i < p->
m_Addresses.count(); i++)
84 for (
unsigned int i = 0; i <
m_Addresses.count(); i++)
97 pedigree_std::Callable<decltype(callback)> cb(callback);
112 for (
unsigned int i = 0; i <
m_Addresses.count(); i++)
195 void Device::searchByVendorIdAndDeviceId(
196 uint16_t vendorId, uint16_t deviceId,
void (*callback)(
Device *),
206 searchByVendorIdAndDeviceIdInternal(vendorId, deviceId, callback, root);
209 void Device::searchByClass(
210 uint16_t classCode,
void (*callback)(
Device *),
Device *root)
219 searchByClassInternal(classCode, callback, root);
222 void Device::searchByClassAndSubclass(
223 uint16_t classCode, uint16_t subclassCode,
void (*callback)(
Device *),
233 searchByClassAndSubclassInternal(classCode, subclassCode, callback, root);
236 void Device::searchByClassSubclassAndProgInterface(
237 uint16_t classCode, uint16_t subclassCode, uint8_t progInterface,
247 searchByClassSubclassAndProgInterfaceInternal(
248 classCode, subclassCode, progInterface, callback, root);
252 uint16_t vendorId,
void (*callback)(
Device *),
Device *root)
270 void Device::searchByVendorIdAndDeviceIdInternal(
271 uint16_t vendorId, uint16_t deviceId,
void (*callback)(
Device *),
287 searchByVendorIdAndDeviceIdInternal(
288 vendorId, deviceId, callback, pChild);
292 void Device::searchByClassInternal(
293 uint16_t classCode,
void (*callback)(
Device *),
Device *root)
307 searchByClassInternal(classCode, callback, pChild);
311 void Device::searchByClassAndSubclassInternal(
312 uint16_t classCode, uint16_t subclassCode,
void (*callback)(
Device *),
328 searchByClassAndSubclassInternal(
329 classCode, subclassCode, callback, pChild);
333 void Device::searchByClassSubclassAndProgInterfaceInternal(
334 uint16_t classCode, uint16_t subclassCode, uint8_t progInterface,
351 searchByClassSubclassAndProgInterfaceInternal(
352 classCode, subclassCode, progInterface, callback, pChild);
357 const String &n, uintptr_t a,
size_t s,
bool io,
size_t pad)
358 : m_Name(n), m_Address(a), m_Size(s), m_IsIoSpace(io), m_Io(0),
359 m_Padding(pad), m_bMapped(false)
361 #ifndef DEVICE_IGNORE_ADDRESSES 362 #ifndef KERNEL_PROCESSOR_NO_PORT_IO 374 uint32_t numPages = s / pageSize;
380 #ifndef KERNEL_PROCESSOR_NO_PORT_IO 383 #endif // DEVICE_IGNORE_ADDRESSES 387 size_t forcedSize,
bool bUser,
bool bWriteCombine,
bool bWriteThrough)
389 #ifndef DEVICE_IGNORE_ADDRESSES 392 #ifndef KERNEL_PROCESSOR_NO_PORT_IO 400 size_t s = forcedSize ? forcedSize :
m_Size;
401 uint32_t numPages = s / pageSize;
405 size_t cacheFlags = 0;
408 else if (bWriteThrough)
415 *static_cast<MemoryMappedIo *>(
m_Io), numPages,
427 "Device::Address: mapped " 429 << static_cast<MemoryMappedIo *>(
m_Io)->virtualAddress());
432 #endif // DEVICE_IGNORE_ADDRESSES 435 Device::Address::~Address()
437 #ifndef DEVICE_IGNORE_ADDRESSES
static void searchByVendorIdInternal(uint16_t vendorId, void(*callback)(Device *), Device *root)
void removeChild(size_t n)
Device * getChild(size_t n)
void pushBack(const T &value)
static size_t getPageSize() PURE
static PhysicalMemoryManager & instance()
uint8_t getPciSubclassCode()
static const size_t continuous
Address(const String &n, uintptr_t a, size_t s, bool io, size_t pad=1)
A vector / dynamic array.
virtual void getName(String &str)
static const size_t force
static const size_t WriteThrough
static void addToRoot(Device *device)
void map(size_t forcedSize=0, bool bUser=false, bool bWriteCombine=false, bool bWriteThrough=false)
void replaceChild(Device *src, Device *dest)
static void searchByVendorId(uint16_t vendorId, void(*callback)(Device *), Device *root=0)
static const size_t WriteCombine
static const size_t Write
static const size_t KernelMode
void addChild(Device *pDevice)
uint8_t getPciProgInterface()
bool allocate(io_port_t ioPort, size_t size)
uint16_t getPciDeviceId()
void setParent(Device *p)
static void foreach(Callback callback, Device *root=0)
Vector< Address * > m_Addresses
virtual bool allocateRegion(MemoryRegion &Region, size_t cPages, size_t pageConstraints, size_t Flags, physical_uintptr_t start=-1)=0
static const size_t nonRamMemory
uint8_t getPciClassCode()
static const size_t CacheDisable
Vector< Device * > m_Children
uint16_t getPciVendorId()