From adfa24dd1e0efd74d57923f4cdcba4084ca06382 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Sat, 6 May 2023 17:27:52 -0400 Subject: [PATCH] ahci: complete hbafis_t struct --- include/dev/ahci.h | 42 ++++++++++++++++++++++++++++++++++++++++++ mem/buddy.c | 8 ++++++++ 2 files changed, 50 insertions(+) diff --git a/include/dev/ahci.h b/include/dev/ahci.h index 99d53d4..d8e0f6a 100644 --- a/include/dev/ahci.h +++ b/include/dev/ahci.h @@ -161,6 +161,24 @@ struct fis_pio_setup { uint16_t reserved5; } PACKED; +struct fis_set_device_bits { + /* 0x00 */ + uint8_t fis_type; + + uint8_t pmult : 4; + uint8_t reserved : 2; + uint8_t interrupt : 1; + uint8_t n : 1; + + uint8_t statusl : 3; + uint8_t reserved2 : 1; + uint8_t statush : 3; + uint8_t reserved3 : 1; + + /* 0x04 */ + uint8_t errorl : 3; +} PACKED; + typedef volatile struct { /* 0x00 */ uint32_t clb; @@ -221,6 +239,30 @@ typedef volatile struct { hbaport_t ports[32]; } PACKED hbamem_t; +typedef volatile struct { + /* 0x00 */ + struct fis_dma_setup dfis; + uint32_t reserved; + + /* 0x20 */ + struct fis_pio_setup pfis; + uint32_t reserved1[3]; + + /* 0x40 */ + struct fis_reg_d2h rfis; + uint32_t reserved2; + + struct fis_set_device_bits sdbfis; + + /* 0x60 */ + uint8_t ufis[64]; + + + /* 0xA0 */ + uint8_t reserved3[0x60]; + +} PACKED hbafis_t; + void ahci_init(); #endif /* _AHCI_H_ */ diff --git a/mem/buddy.c b/mem/buddy.c index 7b2c640..65692c9 100644 --- a/mem/buddy.c +++ b/mem/buddy.c @@ -402,12 +402,20 @@ void mem_early_init(char *mem, size_t len) alloc_page = kmap_alloc_page; pml4 = NULL; + /* map the kernel */ struct mem_region lastregion = mem_regions[num_regions - 1]; kmap(kpaddr, kvaddr, kernel_size, attrs.val); /* identity map the entire physical address space */ + attrs.pcd = 1; kmap(0, hhdm_start, lastregion.base + lastregion.len, attrs.val); + /* remap usable regions with pcd=0 */ + attrs.pcd = 0; + for (unsigned int i = 0; i < num_regions; i++) { + kmap(regions[i].base, regions[i].base | hhdm_start, regions[i].len, attrs.val); + } + pml4_paddr = (uintptr_t)pml4; pml4_paddr &= (~hhdm_start); cr3.pml4_addr = pml4_paddr >> 12;