Added: pci device struct and useful function for drivers

This commit is contained in:
Antoine Cure 2020-02-12 18:28:32 +01:00
parent 03af335ead
commit 06a80dc073
No known key found for this signature in database
GPG Key ID: DCA412F83BD81F24
3 changed files with 46 additions and 4 deletions

View File

@ -45,10 +45,21 @@
//.. //..
//----------------------------------------------------------------------------//
typedef struct {
ushort vendorID;
ushort deviceID;
void* configAddr;
} pciDev_t;
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void IoInitPCI(); void IoInitPCI();
void IoPciEnumerate(); void IoPciEnumerate();
pciDev_t *IoPciGetDevice(ushort vendorID, ushort deviceID);
#endif #endif

View File

@ -88,6 +88,14 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
// PCI // PCI
IoInitPCI(); IoInitPCI();
// Test RTL8139
pciDev_t *rtl8139_pciDev = IoPciGetDevice(0x10EC, 0x8139);
if(rtl8139_pciDev != NULL)
{
KernLog("Network card RTL8139 found ! PCI config addr = %p\n",
rtl8139_pciDev->configAddr);
}
// Scheduler // Scheduler
PsInitSched(); PsInitSched();

View File

@ -75,19 +75,42 @@ void IoPciEnumerate()
return; return;
} }
for(uchar bus = 0; bus < 255; bus++) { for(ushort bus = 0; bus < 256; bus++) {
for(uchar device = 0; device < 32; device++) { for(uchar device = 0; device < 32; device++) {
for(uchar function = 0; function < 8; function++) { for(uchar function = 0; function < 8; function++) {
ushort vendor = pciReadConfigWord(bus, device, function, PCI_REG_VENDOR); ushort vendor = pciReadConfigWord((uchar)bus, device, function, PCI_REG_VENDOR);
if(vendor == 0xffff) continue; if(vendor == 0xffff) continue;
DebugLog("PCI device found ! vendor: %x, device: %x\n", DebugLog("PCI device found ! vendor: %x, device: %x\n",
vendor, vendor,
pciReadConfigWord(bus, device, function, PCI_REG_DEVICE) pciReadConfigWord((uchar)bus, device, function, PCI_REG_DEVICE)
); );
} }
} }
} }
}
pciDev_t *IoPciGetDevice(ushort vendorID, ushort deviceID)
{
if(pciConfigBaseAddress == NULL) {
KernLog("Unable to access PCI configuration : MCFG table not reachable\n");
return NULL;
}
for(ushort bus = 0; bus < 256; bus++) {
for(uchar device = 0; device < 32; device++) {
for(uchar function = 0; function < 8; function++) {
if(vendorID == pciReadConfigWord((uchar)bus, device, function, PCI_REG_VENDOR)
&& deviceID == pciReadConfigWord((uchar)bus, device, function, PCI_REG_DEVICE)) {
pciDev_t *pciDevicePtr = (pciDev_t *)malloc(sizeof(pciDev_t));
pciDevicePtr->vendorID = vendorID;
pciDevicePtr->deviceID = deviceID;
pciDevicePtr->configAddr = pciGetConfigAddr((uchar)bus, device, function, 0);
return pciDevicePtr;
}
}
}
}
return NULL;
} }
void IoInitPCI() void IoInitPCI()