fix: correction detection pci

This commit is contained in:
Nicolas Hordé 2018-11-09 16:44:56 +01:00
parent 42f87229ad
commit 852509789d
2 changed files with 24 additions and 18 deletions

View File

@ -12,3 +12,6 @@ typedef struct pcidev {
};
} pcidev __attribute__ ((packed));
u16 pciConfigReadWord(const u8 bus, const u8 dev, const u8 function, const u8 offset);
void scanPCI(void);
pcidev getPCImininfo(const u8 bus, const u8 dev, const u8 function);

View File

@ -6,48 +6,51 @@
#include "types.h"
#include "pci.h"
#define MAX_BUS_SCAN 256
#define MAX_DEVICE_SCAN 32
#define MAX_FUNCTION_SCAN 8
/*******************************************************************************/
/* Detecte s */
/* Récupère les identifiants vendeur / periphérique du periphérique PCI donnée */
pcidev getPCIinfo(const u8 bus, const u8 dev, const u8 function)
pcidev getPCImininfo(const u8 bus, const u8 dev, const u8 function)
{
pcidev result;
const u32 registry = 0;
u32 addr = (0x80000000|(bus << 16)|(dev << 11)|(function << 8)|(registry & 0xFC));
outd(0xCF8, addr);
result.dword = ind(0xCFC);
if (result.dword == 0xFFFFFFFF)
result.dword = 0x0;
if ((result.vendor = pciConfigReadWord(bus,dev,function,0x0)) != 0xFFFF) {
result.device = pciConfigReadWord(bus,dev,function,0x2);
}
return result;
}
/*******************************************************************************/
/* Récupère les informations sur le periphérique PCI donnée */
u16 pciConfigReadWord(const u8 bus, const u8 dev, const u8 function, const u8 offset)
{
u16 tmp = 0;
u32 addr = (0x80000000|(bus << 16)|(dev << 11)|(function << 8)|(offset & 0xFC));
outd(0xCF8, addr);
tmp = (u16)((ind(0xCFC) >> ((offset & 2) * 8)) & 0xffff);
return tmp;
}
/*******************************************************************************/
/* Scan le bus PCI et affiche les périphériques */
void scanPCI(void)
{
u32 i, bus, device, function;
u16 bus,device,function;
pcidev result;
i = 0;
for (bus=0; bus<MAX_BUS_SCAN; ++bus)
for (device=0; device<MAX_DEVICE_SCAN; ++device)
for (function=0; function<MAX_FUNCTION_SCAN; ++function)
{
result = getPCIinfo(bus, device, function);
if (result.dword)
printf("%d) Bus: 0x%x, Device: 0x%x. Function: 0x%x (0x%hx:0x%hx)\r\n",
++i, bus, device, function, result.vendor, result.device);
result = getPCImininfo(bus,device,function);
if (result.vendor != 0xFFFF)
printf("Bus:%hx Dev:%hx Func:%hx %hx:%hx\r\n",bus, device, function, result.vendor, result.device);
}
return;
}
/*******************************************************************************/