diff options
author | Anton Kling <anton@kling.gg> | 2024-02-21 00:14:29 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-02-21 00:14:29 +0100 |
commit | 8ff63b062d724826d8017504063df9b92f8e6703 (patch) | |
tree | 03bf0b5a278a4908da8912f956e5651bea9412f1 /kernel/drivers | |
parent | a85eacdd2406fede4d6ff5cb130b1758978cabb3 (diff) |
New clang-format options
Diffstat (limited to 'kernel/drivers')
-rw-r--r-- | kernel/drivers/ahci.c | 21 | ||||
-rw-r--r-- | kernel/drivers/ata.c | 15 | ||||
-rw-r--r-- | kernel/drivers/keyboard.c | 8 | ||||
-rw-r--r-- | kernel/drivers/mouse.c | 3 | ||||
-rw-r--r-- | kernel/drivers/pci.c | 15 | ||||
-rw-r--r-- | kernel/drivers/rtl8139.c | 6 |
6 files changed, 45 insertions, 23 deletions
diff --git a/kernel/drivers/ahci.c b/kernel/drivers/ahci.c index 918551e..5a65408 100644 --- a/kernel/drivers/ahci.c +++ b/kernel/drivers/ahci.c @@ -181,10 +181,12 @@ u32 check_type(volatile struct HBA_PORT *port) { u8 ipm = (ssts >> 8) & 0x0F; u8 det = ssts & 0x0F; - if (det != HBA_PORT_DET_PRESENT) // Check drive status + if (det != HBA_PORT_DET_PRESENT) { // Check drive status return AHCI_DEV_NULL; - if (ipm != HBA_PORT_IPM_ACTIVE) + } + if (ipm != HBA_PORT_IPM_ACTIVE) { return AHCI_DEV_NULL; + } switch (port->sig) { case SATA_SIG_ATAPI: @@ -380,8 +382,9 @@ u8 ahci_perform_command(volatile struct HBA_PORT *port, u32 startl, u32 starth, for (;;) { // In some longer duration reads, it may be helpful to spin on the DPS bit // in the PxIS port field as well (1 << 5) - if ((port->ci & (1 << command_slot)) == 0) + if ((port->ci & (1 << command_slot)) == 0) { break; + } if (port->is & HBA_PxIS_TFES) // Task file error { kprintf("Read disk error\n"); @@ -417,8 +420,9 @@ int ahci_write(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) { int rc = len; u32 sector_count = len / 512; - if (len % 512 != 0) + if (len % 512 != 0) { sector_count++; + } for (; sector_count >= num_prdt; lba++) { ahci_raw_write(&hba->ports[port], lba, 0, num_prdt, (u16 *)buffer); offset = 0; @@ -445,8 +449,9 @@ int ahci_read(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) { int rc = len; u32 sector_count = len / 512; - if (len % 512 != 0) + if (len % 512 != 0) { sector_count++; + } u8 tmp_buffer[512 * num_prdt]; for (; sector_count >= num_prdt; lba++) { ahci_raw_read(&hba->ports[port], lba, 0, num_prdt, (u16 *)tmp_buffer); @@ -477,8 +482,9 @@ void add_devfs_drive_file(u8 port) { void ahci_init(void) { struct PCI_DEVICE device; - if (!pci_devices_by_id(0x01, 0x06, &device)) + if (!pci_devices_by_id(0x01, 0x06, &device)) { return; + } kprintf("vendor: %x\n", device.vendor); kprintf("device: %x\n", device.device); kprintf("header_type: %x\n", device.header_type); @@ -489,8 +495,9 @@ void ahci_init(void) { u8 *HBA_base = mmu_map_frames((void *)bar.address, bar.size); hba = (volatile struct HBA_MEM *)(HBA_base); for (u8 i = 0; i < 32; i++) { - if (!((hba->pi >> i) & 1)) + if (!((hba->pi >> i) & 1)) { continue; + } u32 type = check_type(&hba->ports[i]); switch (type) { case AHCI_DEV_SATA: diff --git a/kernel/drivers/ata.c b/kernel/drivers/ata.c index ee9e81b..0537f6e 100644 --- a/kernel/drivers/ata.c +++ b/kernel/drivers/ata.c @@ -43,8 +43,9 @@ int identify(int master_slave) { outb(io_base + LBAmid, 0); outb(io_base + LBAhi, 0); outb(io_base + COMMAND_PORT, IDENTIFY); - if (0 == inb(io_base + STATUS_PORT)) + if (0 == inb(io_base + STATUS_PORT)) { return 0; // Drive does not exist + } for (; 0 != (inb(io_base + STATUS_PORT) & STATUS_BSY);) ; @@ -67,8 +68,9 @@ int identify(int master_slave) { return -2; } - if ((status & STATUS_DRQ)) + if ((status & STATUS_DRQ)) { break; + } } // The data is ready to read from the Data @@ -86,8 +88,9 @@ int poll_status(void) { // Read the Regular Status port until... // We read this 15 times to give some // time for the drive to catch up. - for (int n = 0; n < 15; n++) + for (int n = 0; n < 15; n++) { status = inb(io_base + STATUS_PORT); + } // ERR or // DF sets @@ -98,8 +101,9 @@ int poll_status(void) { // BSY clears // DRQ sets - if (0 == (status & STATUS_BSY) && 0 != (status & STATUS_DRQ)) + if (0 == (status & STATUS_BSY) && 0 != (status & STATUS_DRQ)) { break; + } } return 1; } @@ -160,8 +164,9 @@ void ata_write_lba28(u32 lba, u32 sector_count, volatile const u8 *buffer) { // Wait for BSY to clear for (;;) { u16 status = inb(io_base + STATUS_PORT); - if (!(status & STATUS_BSY)) + if (!(status & STATUS_BSY)) { break; + } } } diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c index da04b1c..ec87390 100644 --- a/kernel/drivers/keyboard.c +++ b/kernel/drivers/keyboard.c @@ -90,12 +90,14 @@ u8 capital_ascii_table[] = { vfs_inode_t *kb_inode; u8 keyboard_to_ascii(u16 key, u8 capital) { - if ((key & 0xFF) > sizeof(ascii_table)) + if ((key & 0xFF) > sizeof(ascii_table)) { return 'U'; - if (capital) + } + if (capital) { return capital_ascii_table[key & 0xFF]; - else + } else { return ascii_table[key & 0xFF]; + } } u8 is_shift_down = 0; diff --git a/kernel/drivers/mouse.c b/kernel/drivers/mouse.c index 821bd1c..ec7ce8c 100644 --- a/kernel/drivers/mouse.c +++ b/kernel/drivers/mouse.c @@ -28,8 +28,9 @@ int fs_mouse_write(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) { int fs_mouse_read(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) { FIFO_FILE *f = fd->inode->internal_object; - if (!mouse_inode->has_data) + if (!mouse_inode->has_data) { return 0; + } int rc = fifo_object_read(buffer, offset, len, f); mouse_inode->has_data = f->has_data; return rc; diff --git a/kernel/drivers/pci.c b/kernel/drivers/pci.c index 7484a41..464d400 100644 --- a/kernel/drivers/pci.c +++ b/kernel/drivers/pci.c @@ -13,8 +13,9 @@ // 0 Failure u8 pci_get_bar(const struct PCI_DEVICE *device, u8 bar_index, struct PCI_BaseAddressRegister *bar) { - if (bar_index > 5) + if (bar_index > 5) { return 0; + } u8 offset = 0x10 + bar_index * sizeof(u32); u32 physical_bar = pci_config_read32(device, 0, offset); u32 original_bar = physical_bar; @@ -90,10 +91,12 @@ u8 pci_devices_by_id(u8 class_id, u8 subclass_id, u16 class_info = pci_config_read32(pci_device, 0, 0x8) >> 16; u16 h_classcode = (class_info & 0xFF00) >> 8; u16 h_subclass = (class_info & 0x00FF); - if (h_classcode != class_id) + if (h_classcode != class_id) { continue; - if (h_subclass != subclass_id) + } + if (h_subclass != subclass_id) { continue; + } u32 device_vendor = pci_config_read32(pci_device, 0, 0); pci_device->vendor = (device_vendor & 0xFFFF); @@ -120,10 +123,12 @@ int pci_populate_device_struct(u16 vendor, u16 device, tmp.bus = bus; tmp.slot = slot; u32 device_vendor = pci_config_read32(&tmp, 0, 0); - if (vendor != (device_vendor & 0xFFFF)) + if (vendor != (device_vendor & 0xFFFF)) { continue; - if (device != (device_vendor >> 16)) + } + if (device != (device_vendor >> 16)) { continue; + } pci_device->bus = bus; pci_device->slot = slot; u32 bar0 = pci_config_read32(pci_device, 0, 0x10); diff --git a/kernel/drivers/rtl8139.c b/kernel/drivers/rtl8139.c index 34d9b85..b22bb8a 100644 --- a/kernel/drivers/rtl8139.c +++ b/kernel/drivers/rtl8139.c @@ -146,8 +146,9 @@ void get_mac_address(u8 mac[6]) { u8 rtl8139_get_transmit_status(u32 base_address) { u32 status_register = inl(base_address + 0x3E); - if ((status_register >> 3) & 0x1) + if ((status_register >> 3) & 0x1) { kprintf("transmit error :(\n"); + } u8 status = (status_register >> 2) & 0x1; outl(base_address + 0x3E, 0x5); return status; @@ -200,6 +201,7 @@ void rtl8139_init(void) { // ksbrk() seems to have the magical ability of disabling interrupts? // I have no fucking clue why that happens and it was a pain to debug. - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { send_buffers[i] = ksbrk(0x1000); + } } |