mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
Added: pci device struct and useful function for drivers
This commit is contained in:
parent
03af335ead
commit
06a80dc073
@ -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
|
||||
|
@ -89,6 +89,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();
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user