pci: fix allocating enumerations and add a way to get enumerations

This commit is contained in:
Matheus
2022-11-21 19:57:04 -03:00
parent 51c6aebf35
commit 33f5a3d674
2 changed files with 66 additions and 1 deletions
+2
View File
@@ -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();
+64 -1
View File
@@ -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();
}