feat: refactor to use gcc types

This commit is contained in:
2021-02-12 22:16:03 +01:00
parent 555c1177a6
commit 8f615b259c
33 changed files with 419 additions and 361 deletions

View File

@@ -32,7 +32,7 @@ const pci_driver *pci_drivers[MAX_PCI_DRIVERS];
int last_pci_device_index = 0;
pci_device pci_devices[MAX_PCI_DEVICES];
u32 pci_register_driver(const pci_driver *pci_driver) {
uint32_t pci_register_driver(const pci_driver *pci_driver) {
for (int i = 0; i < MAX_PCI_DRIVERS; ++i) {
if (pci_drivers[i] != NULL) {
continue;
@@ -43,55 +43,55 @@ u32 pci_register_driver(const pci_driver *pci_driver) {
return PCI_REGISTER_ERR_FULL;
}
u32 pci_config_address(u8 bus, u8 slot, u8 func, u8 offset) {
uint32_t pci_config_address(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) {
return PCI_CONFIG_ENABLE
| ((u32) bus << PCI_CONFIG_SHIFT_BUS_NUMBER)
| ((u32) slot << PCI_CONFIG_SHIFT_DEV_NUMBER)
| ((u32) func << PCI_CONFIG_SHIFT_FUNC_NUMBER)
| ((uint32_t) bus << PCI_CONFIG_SHIFT_BUS_NUMBER)
| ((uint32_t) slot << PCI_CONFIG_SHIFT_DEV_NUMBER)
| ((uint32_t) func << PCI_CONFIG_SHIFT_FUNC_NUMBER)
| (offset & 0xFC);
}
u32 pci_config_read_double_word(u8 bus, u8 slot, u8 func, u8 offset) {
u32 address = pci_config_address(bus, slot, func, offset);
uint32_t pci_config_read_double_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) {
uint32_t address = pci_config_address(bus, slot, func, offset);
port_double_word_out(PORT_PCI_CONFIG_ADDRESS, address);
return port_double_word_in(PORT_PCI_CONFIG_DATA);
}
u16 pci_config_read_word(u8 bus, u8 slot, u8 func, u8 offset) {
u32 address = pci_config_address(bus, slot, func, offset);
uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) {
uint32_t address = pci_config_address(bus, slot, func, offset);
port_double_word_out(PORT_PCI_CONFIG_ADDRESS, address);
return port_double_word_in(PORT_PCI_CONFIG_DATA) >> ((offset & 2) * 8) & 0xFFFF;
}
u8 pci_config_read_byte(u8 bus, u8 slot, u8 func, u8 offset) {
u32 address = pci_config_address(bus, slot, func, offset);
uint8_t pci_config_read_byte(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) {
uint32_t address = pci_config_address(bus, slot, func, offset);
port_double_word_out(PORT_PCI_CONFIG_ADDRESS, address);
return port_double_word_in(PORT_PCI_CONFIG_DATA) >> ((offset & 0b11) * 8) & 0xFF;
}
void pci_config_write_double_word(u8 bus, u8 slot, u8 func, u8 offset, u32 value) {
u32 address = pci_config_address(bus, slot, func, offset);
void pci_config_write_double_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint32_t value) {
uint32_t address = pci_config_address(bus, slot, func, offset);
port_double_word_out(PORT_PCI_CONFIG_ADDRESS, address);
port_double_word_out(PORT_PCI_CONFIG_DATA, value);
}
void pci_config_write_word(u8 bus, u8 slot, u8 func, u8 offset, u16 value) {
u32 address = pci_config_address(bus, slot, func, offset);
void pci_config_write_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint16_t value) {
uint32_t address = pci_config_address(bus, slot, func, offset);
port_double_word_out(PORT_PCI_CONFIG_ADDRESS, address);
port_word_out(PORT_PCI_CONFIG_DATA, value);
}
void pci_config_write_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 value) {
u32 address = pci_config_address(bus, slot, func, offset);
void pci_config_write_byte(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint8_t value) {
uint32_t address = pci_config_address(bus, slot, func, offset);
port_double_word_out(PORT_PCI_CONFIG_ADDRESS, address);
port_byte_out(PORT_PCI_CONFIG_DATA, value);
}
u16 pci_get_vendor_id(u8 bus, u8 slot, u8 func) {
uint16_t pci_get_vendor_id(uint8_t bus, uint8_t slot, uint8_t func) {
return pci_config_read_word(bus, slot, func, PCI_CONFIG_VENDOR_ID);
}
u8 pci_get_header_type(u8 bus, u8 slot, u8 func) {
uint8_t pci_get_header_type(uint8_t bus, uint8_t slot, uint8_t func) {
return pci_config_read_byte(bus, slot, func, PCI_CONFIG_HEADER_TYPE);
}
@@ -113,7 +113,7 @@ void pci_pick_driver(pci_device *device) {
}
}
void pci_check_function(u8 bus, u8 slot, u8 func) {
void pci_check_function(uint8_t bus, uint8_t slot, uint8_t func) {
pci_devices[last_pci_device_index].bus = bus;
pci_devices[last_pci_device_index].slot = slot;
pci_devices[last_pci_device_index].func = func;
@@ -127,12 +127,12 @@ void pci_check_function(u8 bus, u8 slot, u8 func) {
// todo do something with the function
}
void pci_check_device(u8 bus, u8 device) {
u8 function = 0;
u16 vendor_id = pci_get_vendor_id(bus, device, function);
void pci_check_device(uint8_t bus, uint8_t device) {
uint8_t function = 0;
uint16_t vendor_id = pci_get_vendor_id(bus, device, function);
if (vendor_id == 0xFFFF) return;
pci_check_function(bus, device, function);
u8 header_type = pci_get_header_type(bus, device, function);
uint8_t header_type = pci_get_header_type(bus, device, function);
if (header_type & PCI_HEADER_TYPE_MULTI_FUNC) {
for (function = 1; function < 8; ++function) {
if (pci_get_vendor_id(bus, device, function) != 0xFFFF) {
@@ -142,7 +142,7 @@ void pci_check_device(u8 bus, u8 device) {
}
}
void pci_check_bus(u8 bus) {
void pci_check_bus(uint8_t bus) {
for (int device = 0; device < 32; ++device) {
pci_check_device(bus, device);
}
@@ -156,7 +156,7 @@ void pci_scan() {
if (last_pci_device_index != 0) {
k_panics("Can only scan once!");
}
u8 header_type = pci_get_header_type(0, 0, 0);
uint8_t header_type = pci_get_header_type(0, 0, 0);
if (header_type & PCI_HEADER_TYPE_MULTI_FUNC) {
// multiple pci host controllers
for (int function = 0; function < 8; ++function) {
@@ -193,12 +193,12 @@ void pci_print_info() {
}
}
void pci_init_bar(pci_device *device, u8 bar_index) {
void pci_init_bar(pci_device *device, uint8_t bar_index) {
if (device->headerType != 0x00) {
k_panics("Only header 0x00 supported for now");
return;
}
u8 offset = 0;
uint8_t offset = 0;
bar_info *bar;
switch (bar_index) {
case 0:
@@ -231,9 +231,9 @@ void pci_init_bar(pci_device *device, u8 bar_index) {
}
u32 original_address = pci_config_read_double_word(device->bus, device->slot, device->func, offset);
uint32_t original_address = pci_config_read_double_word(device->bus, device->slot, device->func, offset);
pci_config_write_double_word(device->bus, device->slot, device->func, offset, 0xFFFFFFFF);
u32 masked_size = pci_config_read_double_word(device->bus, device->slot, device->func, offset);
uint32_t masked_size = pci_config_read_double_word(device->bus, device->slot, device->func, offset);
if (original_address & 0x1) {
// IO Space