mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-14 06:56:51 -04:00
Better PCI support
This commit is contained in:
parent
bba38e340a
commit
fd03371249
@ -51,7 +51,12 @@ void detect_devices();
|
||||
size_t number_of_devices();
|
||||
device_descriptor& device(size_t index);
|
||||
|
||||
uint8_t read_config_byte(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset);
|
||||
uint16_t read_config_word(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset);
|
||||
uint32_t read_config_dword(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset);
|
||||
|
||||
void write_config_byte(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint8_t value);
|
||||
void write_config_word(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint16_t value);
|
||||
void write_config_dword(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint32_t value);
|
||||
|
||||
} //end of namespace pci
|
||||
|
@ -127,6 +127,16 @@ pci::device_descriptor& pci::device(size_t index){
|
||||
return devices[index];
|
||||
}
|
||||
|
||||
uint8_t pci::read_config_byte(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset){
|
||||
auto value = read_config_dword(bus, device, function, offset);
|
||||
return (value >> ((offset & 3) * 8)) & 0xff;
|
||||
}
|
||||
|
||||
uint16_t pci::read_config_word(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset){
|
||||
auto value = read_config_dword(bus, device, function, offset);
|
||||
return (value >> ((offset & 3) * 8)) & 0xffff;
|
||||
}
|
||||
|
||||
uint32_t pci::read_config_dword(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset){
|
||||
uint32_t address =
|
||||
static_cast<uint32_t>(1 << 31) //enabled
|
||||
@ -140,6 +150,24 @@ uint32_t pci::read_config_dword (uint8_t bus, uint8_t device, uint8_t function,
|
||||
return in_dword(PCI_CONFIG_DATA);
|
||||
}
|
||||
|
||||
void pci::write_config_byte(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint8_t value){
|
||||
auto tmp = read_config_dword(bus, device, function, offset);
|
||||
|
||||
tmp &= ~(0xff << ((offset & 3) * 8));
|
||||
tmp |= (value << ((offset & 3) * 8));
|
||||
|
||||
write_config_dword(bus, device, function, offset, tmp);
|
||||
}
|
||||
|
||||
void pci::write_config_word(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint16_t value){
|
||||
auto tmp = read_config_dword(bus, device, function, offset);
|
||||
|
||||
tmp &= ~(0xffff << ((offset & 3) * 8));
|
||||
tmp |= (value << ((offset & 3) * 8));
|
||||
|
||||
write_config_dword(bus, device, function, offset, tmp);
|
||||
}
|
||||
|
||||
void pci::write_config_dword (uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint32_t value){
|
||||
uint32_t address =
|
||||
static_cast<uint32_t>(1 << 31) //enabled
|
||||
|
Loading…
x
Reference in New Issue
Block a user