feat: rank drivers at compile time

This commit is contained in:
2021-03-07 20:30:07 +01:00
parent f6e720bad9
commit 945b18b2b2
11 changed files with 1254 additions and 62 deletions

View File

@@ -671,10 +671,9 @@ uint8_t ide_access(uint8_t direction, uint8_t drive, uint32_t lba, uint8_t numse
return result;
}
PCI_DRIVER(
PCI_DRIVER(900) = {
.name = "pci-ide",
.description = "Default PCI IDE Driver",
.rank = 10000, // let other block_dev_drivers precede if they can
.validatable = true,
.initialisable = true,
.match.class = PCI_CLASS_MASS_STORAGE,
@@ -683,5 +682,5 @@ PCI_DRIVER(
.mask.subclass = true,
.validate = ide_pci_validate,
.initialize = ide_pci_initialize,
);
};

View File

@@ -13,7 +13,6 @@
#ifdef ENABLE_PCIPP
#include <drivers/pci_devices.h>
#include <libc/sort.h>
#endif
@@ -192,21 +191,6 @@ void pci_check_bus(uint8_t bus) {
}
}
int pci_driver_compare(const void* a, const void* b) {
int rank_a = ((struct pci_driver *) a)->rank;
int rank_b = ((struct pci_driver *) b)->rank;
if (rank_a > rank_b) {
return 1;
} else if (rank_a < rank_b) {
return -1;
}
return 0;
}
void pci_sort_drivers() {
qsort(DRIVER(0), NUM_DRIVERS, sizeof(struct pci_driver), pci_driver_compare);
}
void pci_scan() {
if (last_pci_device_index != 0) {
k_panics("Can only scan once!");
@@ -385,16 +369,15 @@ void pci_init_bar(pci_device *device, uint8_t bar_index) {
}
// internal drivers
PCI_DRIVER(
PCI_DRIVER(0) = {
.name = "pci-secondary-bus",
.description = "A PCI bus connected to the primary bus",
.rank = 0, // internal driver for PCI bus
.match.class = PCI_CLASS_BRIDGE,
.match.subclass = PCI_SUB_CLASS_PCI_PCI_BRIDGE_4,
.mask.class = true,
.mask.subclass = true,
.direct_use = true,
.use = pci_secondary_bus_use,
);
};
// todo https://wiki.osdev.org/Universal_Serial_Bus if i dare

View File

@@ -96,7 +96,6 @@ typedef uint8_t (*pci_driver_initialize)(pci_device *);
struct pci_driver {
const char *name;
const char *description;
uint16_t rank;
struct {
uint8_t class;
uint8_t subclass;
@@ -121,7 +120,7 @@ struct pci_driver {
pci_driver_initialize initialize;
} __attribute__((__aligned__(STRUCT_ALIGNMENT)));
#define PCI_DRIVER(data...) GENERIC_DRIVER(pci_driver, data)
#define PCI_DRIVER(order) GENERIC_DRIVER(pci_driver, order)
typedef struct {
uint32_t address;
@@ -223,8 +222,6 @@ void pci_pretty_print();
#endif
void pci_sort_drivers();
void pci_init_drivers();
void pci_scan();