11 #include <cdi-osdep.h> 13 #include <cdi/lists.h> 17 #include "modules/Module.h" 18 #include "pedigree/kernel/Log.h" 19 #include "pedigree/kernel/compiler.h" 20 #include "pedigree/kernel/machine/Device.h" 21 #include "pedigree/kernel/machine/Pci.h" 22 #include "pedigree/kernel/processor/types.h" 23 #include "pedigree/kernel/utilities/StaticString.h" 24 #include "pedigree/kernel/utilities/String.h" 25 #include "pedigree/kernel/utilities/Vector.h" 26 #include "pedigree/kernel/utilities/new" 28 static cdi_list_t drivers = NULL;
29 static cdi_list_t devices = NULL;
31 static void cdi_destroy(
void);
33 void cdi_run_drivers(
void);
37 struct cdi_pci_device *dev =
new struct cdi_pci_device;
38 dev->bus_data.bus_type = CDI_PCI;
61 dev->resources = cdi_list_create();
62 for(
size_t j = 0; j < p->
addresses().count(); j++)
65 struct cdi_pci_resource *res =
new struct cdi_pci_resource;
67 res->type = CDI_PCI_IOPORTS;
69 res->type = CDI_PCI_MEMORY;
71 res->length = addr->
m_Size;
73 res->address =
reinterpret_cast<void*
>(res->start);
75 cdi_list_push(dev->resources, res);
78 dev->meta.backdev =
reinterpret_cast<void *
>(p);
80 cdi_list_push(devices, dev);
92 drivers = cdi_list_create();
93 devices = cdi_list_create();
100 static bool cdi_module_init()
106 EXPORTED_PUBLIC bool cdi_pedigree_walk_dev_list_init(
struct cdi_driver *dev)
110 struct cdi_driver* driver = dev;
111 struct cdi_bus_data* device;
113 for (i = 0; (device =
reinterpret_cast<struct cdi_bus_data*
>(cdi_list_get(devices, i))); i++) {
114 if (driver->init_device) {
115 struct cdi_device *p = driver->init_device(device);
127 EXPORTED_PUBLIC void cdi_pedigree_walk_dev_list_destroy(
struct cdi_driver *dev)
129 struct cdi_driver* driver = dev;
130 struct cdi_device* device;
132 for (i = 0; (device =
reinterpret_cast<struct cdi_device*
>(cdi_list_get(devices, i))); i++) {
133 if (driver->remove_device) {
134 driver->remove_device(device);
142 static void cdi_destroy(
void)
152 void cdi_run_drivers(
void)
155 struct cdi_driver* driver;
157 for (i = 0; (driver =
reinterpret_cast<struct cdi_driver*
>(cdi_list_get(drivers, i))); i++) {
158 cdi_pedigree_walk_dev_list_init(driver);
165 void cdi_driver_init(
struct cdi_driver* driver)
167 driver->devices = cdi_list_create();
173 void cdi_driver_destroy(
struct cdi_driver* driver)
175 cdi_list_destroy(driver->devices);
183 void cdi_driver_register(
struct cdi_driver* driver)
185 cdi_list_push(drivers, driver);
188 int cdi_provide_device(
struct cdi_bus_data *device)
191 switch(device->bus_type)
196 struct cdi_pci_device *pci =
reinterpret_cast<struct cdi_pci_device *
>(device);
199 if(pci->meta.backdev)
207 pDevice->
setPciIdentifiers(pci->class_id, pci->subclass_id, pci->vendor_id, pci->device_id, pci->interface_id);
211 struct cdi_pci_resource *pResource = 0;
212 for(
int i = 0; (pResource =
reinterpret_cast<struct cdi_pci_resource *
>(cdi_list_get(pci->resources, i))); i++)
215 barName.append(i, 10);
229 WARNING(
"CDI: Unimplemented device type for cdi_provide_device(): " << static_cast<int>(device->bus_type));
236 MODULE_INFO(
"cdi", &cdi_module_init, &cdi_destroy,
"dma",
"network-stack",
"vfs");
uint8_t getPciSubclassCode()
uint32_t getPciDevicePosition()
virtual void setInterruptNumber(uintptr_t n)
virtual Vector< Address * > & addresses()
static void addToRoot(Device *device)
uint32_t getPciBusPosition()
virtual uintptr_t getInterruptNumber()
uint32_t getPciFunctionNumber()
uint32_t readConfigSpace(Device *pDev, uint8_t offset)
uint8_t getPciProgInterface()
void setPciPosition(uint32_t bus, uint32_t device, uint32_t func)
uint16_t getPciDeviceId()
static void foreach(Callback callback, Device *root=0)
void setPciIdentifiers(uint8_t classCode, uint8_t subclassCode, uint16_t vendorId, uint16_t deviceId, uint8_t progIf)
uint8_t getPciClassCode()
void writeConfigSpace(Device *pDev, uint8_t offset, uint32_t data)
uint16_t getPciVendorId()