diff options
author | trimill <trimill@trimillxyz.org> | 2024-02-03 21:05:27 -0500 |
---|---|---|
committer | trimill <trimill@trimillxyz.org> | 2024-02-03 21:08:36 -0500 |
commit | 85a94437048e85aa97991899abbdd0cc927ca671 (patch) | |
tree | 2cb682af2be6ec7e94ebc3f010a780d1b4037c93 /src/arch/amd64/drivers | |
parent | fix lib (diff) | |
download | corn-85a94437048e85aa97991899abbdd0cc927ca671.tar.gz corn-85a94437048e85aa97991899abbdd0cc927ca671.tar.bz2 corn-85a94437048e85aa97991899abbdd0cc927ca671.zip |
formatting
Diffstat (limited to 'src/arch/amd64/drivers')
-rw-r--r-- | src/arch/amd64/drivers/bochs.c | 44 | ||||
-rw-r--r-- | src/arch/amd64/drivers/pci.c | 26 |
2 files changed, 35 insertions, 35 deletions
diff --git a/src/arch/amd64/drivers/bochs.c b/src/arch/amd64/drivers/bochs.c index 1abb927..b3908f9 100644 --- a/src/arch/amd64/drivers/bochs.c +++ b/src/arch/amd64/drivers/bochs.c @@ -30,44 +30,44 @@ #define BOCHS_PCI_DEVICE 0x1111 static void write(uint16_t index, uint16_t data) { - outw(INDEX, index); - outw(DATA, data); + outw(INDEX, index); + outw(DATA, data); } static uint16_t read(uint16_t value) { - outw(INDEX, value); - return inw(DATA); + outw(INDEX, value); + return inw(DATA); } static int is_available(void) { - return (read(INDEX_ID) == 0xB0C5); + return (read(INDEX_ID) == 0xB0C5); } static void set_mode(uint16_t width, uint16_t height, uint16_t bit_depth, int lfb, int clear) { - write(INDEX_ENABLE, DATA_DISP_DISABLE); - write(INDEX_XRES, width); - write(INDEX_YRES, height); - write(INDEX_BPP, bit_depth); - write(INDEX_ENABLE, DATA_DISP_ENABLE | - (lfb ? DATA_LFB_ENABLE : 0) | - (clear ? 0 : DATA_NO_CLEAR_MEM)); + write(INDEX_ENABLE, DATA_DISP_DISABLE); + write(INDEX_XRES, width); + write(INDEX_YRES, height); + write(INDEX_BPP, bit_depth); + write(INDEX_ENABLE, DATA_DISP_ENABLE | + (lfb ? DATA_LFB_ENABLE : 0) | + (clear ? 0 : DATA_NO_CLEAR_MEM)); } -volatile uint32_t* bochs_init(uint16_t width, uint16_t height, uint8_t bit_depth) { +volatile uint32_t *bochs_init(uint16_t width, uint16_t height, uint8_t bit_depth) { set_mode(width, height, bit_depth, true, true); if (!is_available()) - return NULL; + return NULL; - struct pci_device bochs = {0}; - bool found = pci_findby_id(&bochs, BOCHS_PCI_DEVICE, BOCHS_PCI_VENDOR, NULL); - if (!found) - return NULL; + struct pci_device bochs = {0}; + bool found = pci_findby_id(&bochs, BOCHS_PCI_DEVICE, BOCHS_PCI_VENDOR, NULL); + if (!found) + return NULL; - uint32_t bar0 = pci_rcfg_d(bochs, PCI_BAR0_D); - uint32_t *addr = (uint32_t*) (uintptr_t) bar0; - addr = mmap(addr, width * height * bit_depth); + uint32_t bar0 = pci_rcfg_d(bochs, PCI_BAR0_D); + uint32_t *addr = (uint32_t *) (uintptr_t) bar0; + addr = mmap(addr, width * height * bit_depth); - return addr; + return addr; } diff --git a/src/arch/amd64/drivers/pci.c b/src/arch/amd64/drivers/pci.c index 410eb7e..7aa11c8 100644 --- a/src/arch/amd64/drivers/pci.c +++ b/src/arch/amd64/drivers/pci.c @@ -88,7 +88,7 @@ static void print_device(struct pci_table_entry *entry) { } static struct pci_table_entry *load_device(struct pci_device dev) { - if(pci_table_next >= TABLE_LEN) panic("Too many PCI devices: limit is %d", TABLE_LEN); + if (pci_table_next >= TABLE_LEN) panic("Too many PCI devices: limit is %d", TABLE_LEN); struct pci_table_entry *entry = &pci_table[pci_table_next++]; entry->device = dev; uint32_t dword0 = pci_rcfg_d(dev, 0); @@ -108,25 +108,25 @@ static struct pci_table_entry *load_device(struct pci_device dev) { void pci_init(void) { pci_table_next = 0; struct pci_device pcidev; - for(int bus = 0; bus < 256; bus++) { + for (int bus = 0; bus < 256; bus++) { pcidev.bus = bus; - for(int dev = 0; dev < 32; dev++) { + for (int dev = 0; dev < 32; dev++) { pcidev.device = dev; pcidev.function = 0; uint16_t vendor = pci_rcfg_w(pcidev, 0); - if(vendor == 0xFFFF) continue; + if (vendor == 0xFFFF) continue; load_device(pcidev); uint8_t header_type = pci_rcfg_b(pcidev, 14); - if(!(header_type & 0x80)) continue; - for(int func = 1; func < 8; func++) { + if (!(header_type & 0x80)) continue; + for (int func = 1; func < 8; func++) { pcidev.function = func; uint16_t vendor = pci_rcfg_w(pcidev, 0); - if(vendor == 0xFFFF) continue; + if (vendor == 0xFFFF) continue; load_device(pcidev); } @@ -141,10 +141,10 @@ void pci_init(void) { bool pci_findby_class(struct pci_device *dest, uint8_t class, uint8_t subclass, size_t *offset) { size_t o = 0; - if(offset == NULL) offset = &o; - for(; *offset < pci_table_next; (*offset)++) { + if (offset == NULL) offset = &o; + for (; *offset < pci_table_next; (*offset)++) { struct pci_table_entry *entry = &pci_table[*offset]; - if(entry->class == class && entry->subclass == subclass) { + if (entry->class == class && entry->subclass == subclass) { *dest = entry->device; return true; } @@ -154,10 +154,10 @@ bool pci_findby_class(struct pci_device *dest, uint8_t class, uint8_t subclass, bool pci_findby_id(struct pci_device *dest, uint16_t device, uint16_t vendor, size_t *offset) { size_t o = 0; - if(offset == NULL) offset = &o; - for(; *offset < pci_table_next; (*offset)++) { + if (offset == NULL) offset = &o; + for (; *offset < pci_table_next; (*offset)++) { struct pci_table_entry *entry = &pci_table[*offset]; - if(entry->device_id == device && entry->vendor_id == vendor) { + if (entry->device_id == device && entry->vendor_id == vendor) { *dest = entry->device; return true; } |