1 #include "ahci.h"
2 #include <common/kprint.h>
3 #include <mm/slab.h>
4 #include <common/string.h>
5 #include <common/block.h>
6 #include <debug/bug.h>
7 #include <common/kthread.h>
8
9 /// @brief 保留了对 pci设备获取 和 mm内存映射 的依赖
ahci_cpp_init(uint32_t * count_ahci_devices,struct pci_device_structure_header_t * ahci_devs[MAX_AHCI_DEVICES],struct pci_device_structure_general_device_t * gen_devs[MAX_AHCI_DEVICES])10 void ahci_cpp_init(uint32_t *count_ahci_devices, struct pci_device_structure_header_t *ahci_devs[MAX_AHCI_DEVICES], struct pci_device_structure_general_device_t *gen_devs[MAX_AHCI_DEVICES])
11 {
12 kinfo("Initializing AHCI...");
13
14 pci_get_device_structure(0x1, 0x6, ahci_devs, count_ahci_devices);
15
16 if (*count_ahci_devices == 0)
17 {
18 kwarn("There is no AHCI device found on this computer!");
19 return;
20 }
21
22 for (int i = 0; i < *count_ahci_devices; i++)
23 {
24 gen_devs[i] = ((struct pci_device_structure_general_device_t *)(ahci_devs[i]));
25 }
26
27 // 映射ABAR
28 uint32_t bar5 = gen_devs[0]->BAR5;
29 mm_map_phys_addr(AHCI_MAPPING_BASE, (ul)(bar5)&PAGE_2M_MASK, PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false);
30
31 kinfo("ABAR mapped!");
32 }
33