+ // Scan Bus (Bus 0, Don't fill gPCI_Devices)\r
+ i = PCI_ScanBus(0, 0);\r
+ if(i != MODULE_ERR_OK) return i;\r
+ \r
+ if(giPCI_DeviceCount == 0) {\r
+ Log_Notice("PCI", "No devices were found");\r
+ return MODULE_ERR_NOTNEEDED;\r
+ }\r
+ \r
+ // Allocate device buffer\r
+ tmpPtr = malloc(giPCI_DeviceCount * sizeof(tPCIDevice));\r
+ if(tmpPtr == NULL) {\r
+ Log_Warning("PCI", "Malloc ERROR");\r
+ return MODULE_ERR_MALLOC;\r
+ }\r
+ gPCI_Devices = tmpPtr;\r
+ \r
+ Log_Log("PCI", "%i devices, filling structure", giPCI_DeviceCount);\r
+ \r
+ // Reset counts\r
+ giPCI_DeviceCount = 0;\r
+ giPCI_BusCount = 0;\r
+ memset(gaPCI_BusBitmap, 0, sizeof(gaPCI_BusBitmap));\r
+ // Rescan, filling the PCI device array\r
+ PCI_ScanBus(0, 1);\r
+ \r
+ // Complete Driver Structure\r
+ gPCI_DriverStruct.RootNode.Size = giPCI_DeviceCount;\r
+ \r
+ // And add to DevFS\r
+ DevFS_AddDevice(&gPCI_DriverStruct);\r
+ \r
+ return MODULE_ERR_OK;\r
+}\r
+\r
+/**\r
+ * \brief Scans a specific PCI Bus\r
+ * \param BusID PCI Bus ID to scan\r
+ * \param bFill Fill the \a gPCI_Devices array?\r
+ */\r
+int PCI_ScanBus(int BusID, int bFill)\r
+{\r
+ int dev, fcn;\r
+ tPCIDevice devInfo;\r
+ \r
+ if( gaPCI_BusBitmap[BusID/32] & (1 << (BusID%32)) )\r
+ return MODULE_ERR_OK;\r
+ \r
+ gaPCI_BusBitmap[BusID/32] |= (1 << (BusID%32));\r
+ \r
+ for( dev = 0; dev < 32; dev++ ) // 32 Devices per bus\r