mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-18 09:04:49 -04:00
Offer more capabilities for the drivers
This commit is contained in:
parent
9d52e2390f
commit
2b975b4a1b
@ -51,6 +51,9 @@ void detect_devices();
|
|||||||
size_t number_of_devices();
|
size_t number_of_devices();
|
||||||
device_descriptor& device(size_t index);
|
device_descriptor& device(size_t index);
|
||||||
|
|
||||||
|
uint32_t read_config_dword(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset);
|
||||||
|
void write_config_dword(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint32_t value);
|
||||||
|
|
||||||
} //end of namespace pci
|
} //end of namespace pci
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,50 +18,37 @@ std::vector<pci::device_descriptor> devices;
|
|||||||
#define PCI_CONFIG_ADDRESS 0xCF8
|
#define PCI_CONFIG_ADDRESS 0xCF8
|
||||||
#define PCI_CONFIG_DATA 0xCFC
|
#define PCI_CONFIG_DATA 0xCFC
|
||||||
|
|
||||||
uint32_t pci_config_read_dword (uint8_t bus, uint8_t device, uint8_t function, uint8_t offset){
|
|
||||||
uint32_t address =
|
|
||||||
static_cast<uint32_t>(1 << 31) //enabled
|
|
||||||
| (uint32_t(bus) << 16) //bus number
|
|
||||||
| (uint32_t(device) << 11) //device number
|
|
||||||
| (uint32_t(function) << 8) //function number
|
|
||||||
| ((uint32_t(offset) ) & 0xfc); //Register number
|
|
||||||
|
|
||||||
out_dword(PCI_CONFIG_ADDRESS, address);
|
|
||||||
|
|
||||||
return in_dword(PCI_CONFIG_DATA);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t get_vendor_id(uint8_t bus, uint8_t device, uint8_t function){
|
uint16_t get_vendor_id(uint8_t bus, uint8_t device, uint8_t function){
|
||||||
// read "device id | vendor id"
|
// read "device id | vendor id"
|
||||||
auto large = pci_config_read_dword(bus, device, function, 0);
|
auto large = pci::read_config_dword(bus, device, function, 0);
|
||||||
// extract vendor id
|
// extract vendor id
|
||||||
return large;
|
return large;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t get_device_id(uint8_t bus, uint8_t device, uint8_t function){
|
uint16_t get_device_id(uint8_t bus, uint8_t device, uint8_t function){
|
||||||
// read "device id | vendor id"
|
// read "device id | vendor id"
|
||||||
auto large = pci_config_read_dword(bus, device, function, 0);
|
auto large = pci::read_config_dword(bus, device, function, 0);
|
||||||
// extract device id
|
// extract device id
|
||||||
return large >> 16;
|
return large >> 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t get_class_code(uint8_t bus, uint8_t device, uint8_t function){
|
uint8_t get_class_code(uint8_t bus, uint8_t device, uint8_t function){
|
||||||
// read "class code | subclass | prog if | revision id"
|
// read "class code | subclass | prog if | revision id"
|
||||||
auto large = pci_config_read_dword(bus, device, function, 8);
|
auto large = pci::read_config_dword(bus, device, function, 8);
|
||||||
// extract class code only
|
// extract class code only
|
||||||
return large >> 24 & 0xFF;
|
return large >> 24 & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t get_subclass(uint8_t bus, uint8_t device, uint8_t function){
|
uint8_t get_subclass(uint8_t bus, uint8_t device, uint8_t function){
|
||||||
// read "class code | subclass | prog if | revision id"
|
// read "class code | subclass | prog if | revision id"
|
||||||
auto large = pci_config_read_dword(bus, device, function, 8);
|
auto large = pci::read_config_dword(bus, device, function, 8);
|
||||||
// extract subclass only
|
// extract subclass only
|
||||||
return large >> 16 & 0xFF;
|
return large >> 16 & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t get_header_type(uint8_t bus, uint8_t device, uint8_t function){
|
uint8_t get_header_type(uint8_t bus, uint8_t device, uint8_t function){
|
||||||
// read "BIST | header type | latency timer | cache line size"
|
// read "BIST | header type | latency timer | cache line size"
|
||||||
auto large = pci_config_read_dword(bus, device, function, 12);
|
auto large = pci::read_config_dword(bus, device, function, 12);
|
||||||
// extract header type only
|
// extract header type only
|
||||||
return large >> 16 & 0xFF;
|
return large >> 16 & 0xFF;
|
||||||
}
|
}
|
||||||
@ -139,3 +126,29 @@ size_t pci::number_of_devices(){
|
|||||||
pci::device_descriptor& pci::device(size_t index){
|
pci::device_descriptor& pci::device(size_t index){
|
||||||
return devices[index];
|
return devices[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
| (uint32_t(bus) << 16) //bus number
|
||||||
|
| (uint32_t(device) << 11) //device number
|
||||||
|
| (uint32_t(function) << 8) //function number
|
||||||
|
| ((uint32_t(offset) ) & 0xfc); //Register number
|
||||||
|
|
||||||
|
out_dword(PCI_CONFIG_ADDRESS, address);
|
||||||
|
|
||||||
|
return in_dword(PCI_CONFIG_DATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
| (uint32_t(bus) << 16) //bus number
|
||||||
|
| (uint32_t(device) << 11) //device number
|
||||||
|
| (uint32_t(function) << 8) //function number
|
||||||
|
| ((uint32_t(offset) ) & 0xfc); //Register number
|
||||||
|
|
||||||
|
out_dword(PCI_CONFIG_ADDRESS, address);
|
||||||
|
|
||||||
|
out_dword(PCI_CONFIG_DATA, value);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user