diff --git a/include/io/pci.h b/include/io/pci.h index 67b635d..40470d1 100644 --- a/include/io/pci.h +++ b/include/io/pci.h @@ -45,10 +45,21 @@ //.. +//----------------------------------------------------------------------------// + + +typedef struct { + ushort vendorID; + ushort deviceID; + void* configAddr; +} pciDev_t; + + //----------------------------------------------------------------------------// void IoInitPCI(); void IoPciEnumerate(); +pciDev_t *IoPciGetDevice(ushort vendorID, ushort deviceID); #endif diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 877606a..ddec416 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -88,6 +88,14 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) // PCI 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 PsInitSched(); diff --git a/kaleid/kernel/io/pci.c b/kaleid/kernel/io/pci.c index 094e761..955e818 100644 --- a/kaleid/kernel/io/pci.c +++ b/kaleid/kernel/io/pci.c @@ -75,19 +75,42 @@ void IoPciEnumerate() return; } - for(uchar bus = 0; bus < 255; bus++) { + for(ushort bus = 0; bus < 256; bus++) { for(uchar device = 0; device < 32; device++) { 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; DebugLog("PCI device found ! vendor: %x, device: %x\n", 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()