20#include "pedigree/kernel/Log.h"
21#include "pedigree/kernel/machine/Device.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#if THREADS && !defined(STANDALONE_MUTEXES)
52 m_PhysicalFunction(nullptr),
53 m_VirtualFunctionIndex(0),
64 m_PciFunctionNum(0) {}
70 m_PhysicalFunction(p->m_PhysicalFunction),
71 m_VirtualFunctionIndex(p->m_VirtualFunctionIndex),
72 m_InterruptNumber(p->m_InterruptNumber),
73 m_SpecificType(p->m_SpecificType),
74 m_ConfigHeader(p->m_ConfigHeader),
75 m_ClassCode(p->m_ClassCode),
76 m_SubclassCode(p->m_SubclassCode),
77 m_VendorId(p->m_VendorId),
78 m_DeviceId(p->m_DeviceId),
79 m_ProgInterface(p->m_ProgInterface),
80 m_PciBusPos(p->m_PciBusPos),
81 m_PciDevicePos(p->m_PciDevicePos),
82 m_PciFunctionNum(p->m_PciFunctionNum) {
90 for (
unsigned int i = 0; i < p->
m_Addresses.count(); i++) {
93 NOTICE(
"address=" <<
Hex << a <<
", m_Io=" << a->
m_Io);
99 for (
unsigned int i = 0; i <
m_Addresses.count(); i++) {
109 pedigree_std::Callable<
decltype(callback)> cb(callback);
122 for (
unsigned int i = 0; i <
m_Addresses.count(); i++) {
131 str.assign(
"Root", 5);
187void Device::searchByVendorIdAndDeviceId(uint16_t vendorId, uint16_t deviceId,
195 searchByVendorIdAndDeviceIdInternal(vendorId, deviceId, callback,
root);
198void Device::searchByClass(uint16_t classCode,
void (*callback)(
Device*),
Device* root) {
205 searchByClassInternal(classCode, callback,
root);
208void Device::searchByClassAndSubclass(uint16_t classCode, uint16_t subclassCode,
216 searchByClassAndSubclassInternal(classCode, subclassCode, callback,
root);
219void Device::searchByClassSubclassAndProgInterface(uint16_t classCode, uint16_t subclassCode,
220 uint8_t progInterface,
void (*callback)(
Device*),
228 searchByClassSubclassAndProgInterfaceInternal(classCode, subclassCode, progInterface, callback,
247void Device::searchByVendorIdAndDeviceIdInternal(uint16_t vendorId, uint16_t deviceId,
259 searchByVendorIdAndDeviceIdInternal(vendorId, deviceId, callback, pChild);
263void Device::searchByClassInternal(uint16_t classCode,
void (*callback)(
Device*),
Device* root) {
274 searchByClassInternal(classCode, callback, pChild);
278void Device::searchByClassAndSubclassInternal(uint16_t classCode, uint16_t subclassCode,
291 searchByClassAndSubclassInternal(classCode, subclassCode, callback, pChild);
295void Device::searchByClassSubclassAndProgInterfaceInternal(uint16_t classCode,
296 uint16_t subclassCode,
297 uint8_t progInterface,
298 void (*callback)(
Device*),
312 searchByClassSubclassAndProgInterfaceInternal(classCode, subclassCode, progInterface, callback,
325#ifndef DEVICE_IGNORE_ADDRESSES
326 EMIT_IF(!KERNEL_PROCESSOR_NO_PORT_IO) {
337 uint32_t numPages = s / pageSize;
347#ifndef DEVICE_IGNORE_ADDRESSES
350 EMIT_IF(!KERNEL_PROCESSOR_NO_PORT_IO) {
358 size_t s = forcedSize ? forcedSize : m_Size;
359 uint32_t numPages = s / pageSize;
363 size_t cacheFlags = 0;
366 else if (bWriteThrough)
377 ERROR(
"Device::Address - map for " <<
Hex << m_Address <<
" failed!");
380 NOTICE(
"Device::Address: mapped " <<
Hex << m_Address <<
" -> "
387Device::Address::~Address() {
388#ifndef DEVICE_IGNORE_ADDRESSES
void map(size_t forcedSize=0, bool bUser=false, bool bWriteCombine=false, bool bWriteThrough=false)
Address(const String &n, uintptr_t a, size_t s, bool io, size_t pad=1)
uint16_t getPciDeviceId()
Device * getChild(size_t n)
uint16_t getPciVendorId()
static void addToRoot(Device *device)
static void foreach(Callback callback, Device *root=0)
uint8_t getPciClassCode()
static void searchByVendorId(uint16_t vendorId, void(*callback)(Device *), Device *root=0)
void addChild(Device *pDevice)
static bool treeLockHeldByCurrentThread()
Vector< Address * > m_Addresses
uint8_t getPciSubclassCode()
uint8_t getPciProgInterface()
virtual void getName(String &str)
Vector< Device * > m_Children
static void searchByVendorIdInternal(uint16_t vendorId, void(*callback)(Device *), Device *root)
void removeChild(size_t n)
void replaceChild(Device *src, Device *dest)
bool allocate(io_port_t ioPort, size_t size)
bool isOwnedByCurrentThread() const
static const size_t continuous
static PhysicalMemoryManager & instance()
static constexpr size_t getPageSize() PURE
static const size_t force
static const size_t nonRamMemory
virtual bool allocateRegion(MemoryRegion &Region, size_t cPages, size_t pageConstraints, size_t Flags, physical_uintptr_t start=-1)=0
static const size_t CacheDisable
static const size_t WriteCombine
static const size_t KernelMode
static const size_t Write
static const size_t WriteThrough
void pushBack(const T &value)