feat: fixed some bugs for running on real hardware

This commit is contained in:
2021-03-05 22:23:39 +01:00
parent e532099ea7
commit 310f3621a2
6 changed files with 43 additions and 15 deletions

View File

@@ -32,6 +32,8 @@ const pci_driver *pci_drivers[MAX_PCI_DRIVERS];
int last_pci_device_index = 0;
pci_device pci_devices[MAX_PCI_DEVICES];
void pci_check_bus(uint8_t bus);
uint32_t pci_register_driver(const pci_driver *pci_driver) {
for (int i = 0; i < MAX_PCI_DRIVERS; ++i) {
if (pci_drivers[i] != NULL) {
@@ -137,9 +139,16 @@ void pci_check_function(uint8_t bus, uint8_t slot, uint8_t func) {
pci_devices[last_pci_device_index].config_line_2 = pci_config_read_double_word(bus, slot, func, PCI_CONFIG_LINE_2);
pci_devices[last_pci_device_index].config_line_3 = pci_config_read_double_word(bus, slot, func, PCI_CONFIG_LINE_3);
pci_devices[last_pci_device_index].device_state.present = 1;
pci_pick_driver(&pci_devices[last_pci_device_index]);
last_pci_device_index++;
if (pci_devices[last_pci_device_index-1].class == 0x06 && pci_devices[last_pci_device_index-1].subclass == 0x04) {
uint8_t secondary_bus = pci_config_read_byte(bus, slot, func, PCI_CONFIG_SECONDARY_BUS_NUMBER);
printf("Found secondary bus: %d\n", secondary_bus);
pci_check_bus(secondary_bus);
} else {
pci_pick_driver(&pci_devices[last_pci_device_index-1]);
}
// todo do something with the function
}

View File

@@ -57,6 +57,23 @@
#define PCI_CONFIG_MAX_GRANT 0x3E
#define PCI_CONFIG_MAX_LATENCY 0x3F
// header type 1
#define PCI_CONFIG_PRIMARY_BUS_NUMBER 0x18
#define PCI_CONFIG_SECONDARY_BUS_NUMBER 0x19
#define PCI_CONFIG_SUBORDINATE_BUS_NUMBER 0x1A
#define PCI_CONFIG_SECONDARY_LATENCY_TIMER 0x1B
#define PCI_CONFIG_IO_BASE 0x1C
#define PCI_CONFIG_IO_LIMIT 0x1D
#define PCI_CONFIG_SECONDARY_STATUS 0x1E
#define PCI_CONFIG_MEMORY_BASE 0x20
#define PCI_CONFIG_MEMORY_LIMIT 0x22
#define PCI_CONFIG_MEMORY_BASE_UPPER 0x28
#define PCI_CONFIG_MEMORY_LIMIT_UPPER 0x2C
#define PCI_CONFIG_IO_BASE_UPPER 0x30
#define PCI_CONFIG_IO_LIMIT_UPPER 0x32
#define PCI_CONFIG_EXPANSION_ROM 0x38
#define PCI_CONFIG_BRIDGE_CONTROL 0x3E
#define PCI_INTERRUPT_LINE_DISABLED 0xff
typedef struct pci_driver pci_driver;