From 852509789da4de4fc91216602dc54d707cfc45a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Fri, 9 Nov 2018 16:44:56 +0100 Subject: [PATCH] fix: correction detection pci --- include/pci.h | 3 +++ lib/pci.c | 39 +++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/include/pci.h b/include/pci.h index 9a06375..739d863 100755 --- a/include/pci.h +++ b/include/pci.h @@ -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); diff --git a/lib/pci.c b/lib/pci.c index 2385075..0c6bc19 100755 --- a/lib/pci.c +++ b/lib/pci.c @@ -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