mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
pci: legacy_write and pci_setcommand
This commit is contained in:
@@ -81,6 +81,11 @@ static inline void* getbarmemaddr(pci_deviceheader* e, int bar){
|
|||||||
return e->BAR[bar] & ~(0xF);
|
return e->BAR[bar] & ~(0xF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PCI_COMMAND_IO 1
|
||||||
|
#define PCI_COMMAND_MEMORY 2
|
||||||
|
#define PCI_COMMAND_MASTER 4
|
||||||
|
|
||||||
|
void pci_setcommand(pci_enumeration* e, int which, int val);
|
||||||
pci_enumeration* pci_getdevicecs(int class, int subclass, int n);
|
pci_enumeration* pci_getdevicecs(int class, int subclass, int n);
|
||||||
pci_enumeration* pci_getdevicecsp(int class, int subclass, int progif, 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);
|
uint64_t pci_msi_build(uint64_t* data, uint8_t vector, uint8_t processor, uint8_t edgetrigger, uint8_t deassert);
|
||||||
|
|||||||
+32
-1
@@ -9,6 +9,8 @@ pci_enumeration* enumerations;
|
|||||||
#define CONFIG_ADDRESS 0xCF8
|
#define CONFIG_ADDRESS 0xCF8
|
||||||
#define CONFIG_DATA 0xCFC
|
#define CONFIG_DATA 0xCFC
|
||||||
|
|
||||||
|
#define COMMAND_REG 1
|
||||||
|
|
||||||
pci_enumeration* pci_getdevicecs(int class, int subclass, int n){
|
pci_enumeration* pci_getdevicecs(int class, int subclass, int n){
|
||||||
|
|
||||||
pci_enumeration* ptr = enumerations;
|
pci_enumeration* ptr = enumerations;
|
||||||
@@ -73,7 +75,7 @@ pci_enumeration* pci_getdevicecsp(int class, int subclass, int progif, int n){
|
|||||||
return save;
|
return save;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t legacy_readdata(int bus, int device, int func, int reg){
|
static uint32_t legacy_readdata(int bus, int device, int func, int reg){
|
||||||
|
|
||||||
uint32_t address = reg << 2;
|
uint32_t address = reg << 2;
|
||||||
address |= (func & 0b111) << 8;
|
address |= (func & 0b111) << 8;
|
||||||
@@ -87,6 +89,35 @@ uint32_t legacy_readdata(int bus, int device, int func, int reg){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void legacy_writedata(int bus, int device, int func, int reg, uint32_t val){
|
||||||
|
|
||||||
|
uint32_t address = reg << 2;
|
||||||
|
address |= (func & 0b111) << 8;
|
||||||
|
address |= (device & 0b11111) << 11;
|
||||||
|
address |= (bus & 0xFF) << 16;
|
||||||
|
address |= 1 << 31;
|
||||||
|
|
||||||
|
outd(CONFIG_ADDRESS, address);
|
||||||
|
|
||||||
|
outd(CONFIG_DATA, val);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void pci_setcommand(pci_enumeration* e, int which, int val){
|
||||||
|
|
||||||
|
uint32_t regsave = legacy_readdata(e->bus, e->device, e->function, COMMAND_REG);
|
||||||
|
|
||||||
|
if(val == 0){
|
||||||
|
regsave &= ~which;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
regsave |= which;
|
||||||
|
}
|
||||||
|
|
||||||
|
legacy_writedata(e->bus, e->device, e->function, COMMAND_REG, regsave);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool legacy_exists(int bus, int device, int func){
|
static inline bool legacy_exists(int bus, int device, int func){
|
||||||
return legacy_readdata(bus, device, func, 0) != 0xFFFFFFFF;
|
return legacy_readdata(bus, device, func, 0) != 0xFFFFFFFF;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user