diff --git a/src/arch/x86_64/include/arch/pci.h b/src/arch/x86_64/include/arch/pci.h index 877246f9..792d8dd9 100644 --- a/src/arch/x86_64/include/arch/pci.h +++ b/src/arch/x86_64/include/arch/pci.h @@ -50,6 +50,8 @@ typedef struct _pci_enumeration{ pci_common* header; } pci_enumeration; +pci_enumeration* pci_getdevicecs(int class, int subclass, int n); +pci_enumeration* pci_getdevicecsp(int class, int subclass, int progif, int n); uint64_t pci_msi_build(uint64_t* data, uint8_t vector, uint8_t processor, uint8_t edgetrigger, uint8_t deassert); void pci_enumerate(); diff --git a/src/arch/x86_64/pci.c b/src/arch/x86_64/pci.c index 640e1f62..81ccb20a 100644 --- a/src/arch/x86_64/pci.c +++ b/src/arch/x86_64/pci.c @@ -9,6 +9,68 @@ pci_enumeration* enumerations; #define CONFIG_ADDRESS 0xCF8 #define CONFIG_DATA 0xCFC +pci_enumeration* pci_getdevicecs(int class, int subclass, int n){ + + pci_enumeration* ptr = enumerations; + pci_enumeration* save = NULL; + + while(true){ + while(ptr){ + + pci_common* common = ptr->header; + if((common->type & 0x7F) == PCI_DEV_HEADER && common->class == class && common->subclass == subclass){ + save = ptr; + ptr = ptr->next; + break; + + } + + ptr = ptr->next; + } + + if(!ptr) + break; + + if(n-- == 0) + break; + } + + if(n >= 0) + save = NULL; + + return save; + +} +pci_enumeration* pci_getdevicecsp(int class, int subclass, int progif, int n){ + pci_enumeration* ptr = enumerations; + pci_enumeration* save = NULL; + + while(ptr){ + while(ptr){ + + pci_common* common = ptr->header; + + if((common->type & 0x7F) == PCI_DEV_HEADER && common->class == class && common->subclass == subclass && common->progif == progif){ + save = ptr; + ptr = ptr->next; + break; + + } + + ptr = ptr->next; + } + + if(n-- == 0) + break; + + } + + if(n < 0) + save = NULL; + + return save; +} + uint32_t legacy_readdata(int bus, int device, int func, int reg){ uint32_t address = reg << 2; @@ -33,8 +95,10 @@ static pci_enumeration* allocnewenum(){ if(!enumerations){ enumeration = alloc(sizeof(pci_enumeration)); + enumerations = enumeration; } else{ + enumeration = enumerations; while(enumeration->next != NULL) enumeration = enumeration->next; @@ -133,5 +197,4 @@ void pci_enumerate(){ legacy_enumeration(); - }