feat: reformatted driver code and linkage. Some optimizations
This commit is contained in:
@@ -322,34 +322,6 @@ unsigned char ide_print_error(unsigned int drive, unsigned char err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
uint8_t ide_pci_validate(const pci_device *device);
|
||||
|
||||
uint8_t ide_pci_initialize(pci_device *device);
|
||||
|
||||
PCI_DRIVER(
|
||||
.name = "pci-ide",
|
||||
.description = "Default PCI IDE Driver",
|
||||
.order = 0xFF, // let other block_dev_drivers precede if they can
|
||||
.pci_use_subclass = true,
|
||||
.validatable = true,
|
||||
.initialisable = true,
|
||||
.pci_class = PCI_CLASS_MASS_STORAGE,
|
||||
.pci_subclass = PCI_SUB_CLASS_IDE,
|
||||
|
||||
.validate = ide_pci_validate,
|
||||
.initialize = ide_pci_initialize,
|
||||
);
|
||||
|
||||
uint8_t ide_pci_validate(const pci_device *device) {
|
||||
if (device->class != PCI_CLASS_MASS_STORAGE
|
||||
|| device->subclass != PCI_SUB_CLASS_IDE
|
||||
|| (device->programInterface != 0x8A && device->programInterface != 0x80)) {
|
||||
return PCI_VALIDATE_FAIL;
|
||||
}
|
||||
// todo other validations
|
||||
return PCI_VALIDATE_OK;
|
||||
}
|
||||
|
||||
void ide_fix_bar(bar_info *bar, uint32_t default_address, uint32_t size) {
|
||||
if (bar->address == 0x0) {
|
||||
// no need to actually write ti back
|
||||
@@ -365,6 +337,7 @@ bool ide_pci_init_channels(pci_device *device) {
|
||||
pci_config_write_byte(device->bus, device->slot, device->func, PCI_CONFIG_INTERRUPT_LINE, 0xFE);
|
||||
if (pci_config_read_byte(device->bus, device->slot, device->func, PCI_CONFIG_INTERRUPT_LINE) == 0xFE) {
|
||||
#ifdef IDE_ENABLE_INTERRUPT
|
||||
#error "Interrupt not supported"
|
||||
k_panics("NOT SUPPORTED");
|
||||
#else
|
||||
pci_config_write_byte(device->bus, device->slot, device->func, PCI_CONFIG_INTERRUPT_LINE,
|
||||
@@ -399,7 +372,8 @@ bool ide_pci_init_channels(pci_device *device) {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t ide_block_dev_access(const block_device *device, uint8_t direction, uint32_t lba, uint8_t sectors, void *target) {
|
||||
uint8_t
|
||||
ide_block_dev_access(const block_device *device, uint8_t direction, uint32_t lba, uint8_t sectors, void *target) {
|
||||
ide_block_device_info *info = device->device_info;
|
||||
uint8_t result = ide_access(direction, info->device_number, lba, sectors, target);
|
||||
if (result != 0) {
|
||||
@@ -436,7 +410,17 @@ void ide_register_block_devices() {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ide_pci_initialize(pci_device *device) {
|
||||
uint8_t used ide_pci_validate(const pci_device *device) {
|
||||
if (device->class != PCI_CLASS_MASS_STORAGE
|
||||
|| device->subclass != PCI_SUB_CLASS_IDE
|
||||
|| (device->programInterface != 0x8A && device->programInterface != 0x80)) {
|
||||
return PCI_VALIDATE_FAIL;
|
||||
}
|
||||
// todo other validations
|
||||
return PCI_VALIDATE_OK;
|
||||
}
|
||||
|
||||
uint8_t used ide_pci_initialize(pci_device *device) {
|
||||
|
||||
if (!ide_pci_init_channels(device)) {
|
||||
return PCI_INIT_FAIL;
|
||||
@@ -686,3 +670,18 @@ uint8_t ide_access(uint8_t direction, uint8_t drive, uint32_t lba, uint8_t numse
|
||||
mutex_release(ide_lock);
|
||||
return result;
|
||||
}
|
||||
|
||||
PCI_DRIVER(
|
||||
.name = "pci-ide",
|
||||
.description = "Default PCI IDE Driver",
|
||||
.order = 0xFF, // let other block_dev_drivers precede if they can
|
||||
.pci_use_subclass = true,
|
||||
.validatable = true,
|
||||
.initialisable = true,
|
||||
.pci_class = PCI_CLASS_MASS_STORAGE,
|
||||
.pci_subclass = PCI_SUB_CLASS_IDE,
|
||||
|
||||
.validate = ide_pci_validate,
|
||||
.initialize = ide_pci_initialize,
|
||||
);
|
||||
|
||||
|
||||
@@ -46,10 +46,10 @@ const struct pci_driver pci_internal_secondary_bus = {
|
||||
};
|
||||
|
||||
//const pci_driver *pci_drivers[MAX_PCI_DRIVERS];
|
||||
extern struct pci_driver __start_pci_drivers[];
|
||||
extern struct pci_driver __stop_pci_drivers[];
|
||||
#define NUM_DRIVERS ((size_t)(__stop_pci_drivers - __start_pci_drivers))
|
||||
#define DRIVER(i) ((__start_pci_drivers) + (i))
|
||||
extern struct pci_driver __start_pci_driver[];
|
||||
extern struct pci_driver __stop_pci_driver[];
|
||||
#define NUM_DRIVERS ((size_t)(__stop_pci_driver - __start_pci_driver))
|
||||
#define DRIVER(i) ((__start_pci_driver) + (i))
|
||||
int last_pci_device_index = 0;
|
||||
pci_device pci_devices[MAX_PCI_DEVICES];
|
||||
|
||||
@@ -126,18 +126,20 @@ uint8_t pci_get_header_type(uint8_t bus, uint8_t slot, uint8_t func) {
|
||||
void pci_pick_driver(pci_device *device) {
|
||||
// check special drivers
|
||||
// PCI Secondary bus
|
||||
if (device->class == pci_internal_secondary_bus.pci_class && device->subclass == pci_internal_secondary_bus.pci_subclass) {
|
||||
uint8_t secondary_bus = pci_config_read_byte(device->bus, device->slot, device->func, PCI_CONFIG_SECONDARY_BUS_NUMBER);
|
||||
if (device->class == pci_internal_secondary_bus.pci_class &&
|
||||
device->subclass == pci_internal_secondary_bus.pci_subclass) {
|
||||
uint8_t secondary_bus = pci_config_read_byte(device->bus, device->slot, device->func,
|
||||
PCI_CONFIG_SECONDARY_BUS_NUMBER);
|
||||
device->pci_driver = &pci_internal_secondary_bus;
|
||||
pci_check_bus(secondary_bus);
|
||||
return;
|
||||
}
|
||||
|
||||
// use normal drivers
|
||||
for (int i = 0; i < NUM_DRIVERS; ++i) {
|
||||
// if (DRIVER(i) == NULL) {
|
||||
// continue;
|
||||
// }
|
||||
for (size_t i = 0; i < NUM_DRIVERS; ++i) {
|
||||
if (DRIVER(i) == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (device->class != DRIVER(i)->pci_class) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#define NEW_KERNEL_PCI_H
|
||||
|
||||
#include <types.h>
|
||||
#include <driver.h>
|
||||
#include <stdbool.h>
|
||||
#include <attributes.h>
|
||||
|
||||
@@ -76,14 +77,6 @@
|
||||
|
||||
#define PCI_INTERRUPT_LINE_DISABLED 0xff
|
||||
|
||||
#ifndef PCI_DRIVER_ALIGNMENT
|
||||
#if defined(__LP64__)
|
||||
#define PCI_DRIVER_ALIGNMENT 16
|
||||
#else
|
||||
#define PCI_DRIVER_ALIGNMENT 8
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef struct pci_device pci_device;
|
||||
|
||||
typedef uint8_t (*pci_driver_validate)(const pci_device *);
|
||||
@@ -103,16 +96,9 @@ struct pci_driver {
|
||||
};
|
||||
pci_driver_validate validate;
|
||||
pci_driver_initialize initialize;
|
||||
} __attribute__((__aligned__(PCI_DRIVER_ALIGNMENT)));
|
||||
} __attribute__((__aligned__(STRUCT_ALIGNMENT)));
|
||||
|
||||
#define PCI_DRIVER_NAME(counter) DRIVER_CAT(pci_driver_, counter)
|
||||
#define DRIVER_CAT(a, b) DRIVER_DUMMY() a ## b
|
||||
#define DRIVER_DUMMY()
|
||||
|
||||
#define PCI_DRIVER(data...) \
|
||||
static struct pci_driver PCI_DRIVER_NAME(__COUNTER__) \
|
||||
__attribute((__used__, __section__("pci_drivers"))) \
|
||||
= { data }
|
||||
#define PCI_DRIVER(data...) GENERIC_DRIVER(pci_driver, data)
|
||||
|
||||
typedef struct {
|
||||
uint32_t address;
|
||||
|
||||
Reference in New Issue
Block a user