|
@@ -3,8 +3,9 @@
|
|
|
#include <common/kprint.h>
|
|
|
#include <driver/multiboot2/multiboot2.h>
|
|
|
#include <mm/mm.h>
|
|
|
+#include <mm/mmio.h>
|
|
|
|
|
|
-#define acpi_get_RSDT_entry_vaddr(phys_addr) (ACPI_DESCRIPTION_HEDERS_BASE + (phys_addr)-acpi_RSDT_entry_phys_base)
|
|
|
+#define acpi_get_RSDT_entry_vaddr(phys_addr) (acpi_description_header_base + (phys_addr)-acpi_RSDT_entry_phys_base)
|
|
|
|
|
|
|
|
|
static struct acpi_RSDP_t *rsdpv1;
|
|
@@ -22,7 +23,9 @@ static uint acpi_XSDT_Entry_num = 0;
|
|
|
|
|
|
static ul acpi_RSDT_entry_phys_base = 0;
|
|
|
|
|
|
-static uint64_t acpi_madt_vaddr = 0;
|
|
|
+static uint64_t acpi_madt_vaddr = 0;
|
|
|
+static uint64_t acpi_rsdt_virt_addr_base = 0;
|
|
|
+static uint64_t acpi_description_header_base = 0;
|
|
|
|
|
|
|
|
|
|
|
@@ -41,8 +44,8 @@ void acpi_iter_SDT(bool (*_fun)(const struct acpi_system_description_table_heade
|
|
|
ul *ent = &(xsdt->Entry);
|
|
|
for (int i = 0; i < acpi_XSDT_Entry_num; ++i)
|
|
|
{
|
|
|
- mm_map_phys_addr(ACPI_XSDT_DESCRIPTION_HEDERS_BASE + PAGE_2M_SIZE * i, (*(ent + i)) & PAGE_2M_MASK, PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false);
|
|
|
- sdt_header = (struct acpi_system_description_table_header_t *)((ul)(ACPI_XSDT_DESCRIPTION_HEDERS_BASE + PAGE_2M_SIZE * i));
|
|
|
+ mm_map_phys_addr(acpi_description_header_base + PAGE_2M_SIZE * i, (*(ent + i)) & PAGE_2M_MASK, PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false);
|
|
|
+ sdt_header = (struct acpi_system_description_table_header_t *)((ul)(acpi_description_header_base + PAGE_2M_SIZE * i));
|
|
|
|
|
|
if (_fun(sdt_header, _data) == true)
|
|
|
return;
|
|
@@ -100,7 +103,6 @@ bool acpi_get_HPET(const struct acpi_system_description_table_header_t *_iter_da
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
* @brief 初始化acpi模块
|
|
|
*
|
|
@@ -110,26 +112,20 @@ void acpi_init()
|
|
|
{
|
|
|
kinfo("Initializing ACPI...");
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
int reserved;
|
|
|
- multiboot2_iter(multiboot2_get_acpi_old_RSDP, &old_acpi, &reserved);
|
|
|
|
|
|
+ multiboot2_iter(multiboot2_get_acpi_old_RSDP, &old_acpi, &reserved);
|
|
|
rsdpv1 = &(old_acpi.rsdp);
|
|
|
|
|
|
- kdebug("RSDT_phys_Address=%#018lx", rsdpv1->RsdtAddress);
|
|
|
- kdebug("RSDP_Revision=%d", rsdpv1->Revision);
|
|
|
-
|
|
|
multiboot2_iter(multiboot2_get_acpi_new_RSDP, &new_acpi, &reserved);
|
|
|
rsdpv2 = &(new_acpi.rsdp);
|
|
|
|
|
|
- kdebug("Rsdt_v2_phys_Address=%#018lx", rsdpv2->rsdp1.RsdtAddress);
|
|
|
- kdebug("Xsdt_phys_Address=%#018lx", rsdpv2->XsdtAddress);
|
|
|
- kdebug("RSDP_v2_Revision=%d", rsdpv2->rsdp1.Revision);
|
|
|
-
|
|
|
+ uint64_t paddr = 0;
|
|
|
|
|
|
if (rsdpv2->XsdtAddress != 0x00UL)
|
|
|
{
|
|
|
+
|
|
|
|
|
|
acpi_use_xsdt = true;
|
|
|
ul xsdt_phys_base = rsdpv2->XsdtAddress & PAGE_2M_MASK;
|
|
@@ -156,12 +152,23 @@ void acpi_init()
|
|
|
mm_map_phys_addr(ACPI_XSDT_DESCRIPTION_HEDERS_BASE + PAGE_2M_SIZE * j, (*(ent + j)) & PAGE_2M_MASK, PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false);
|
|
|
}
|
|
|
*/
|
|
|
+
|
|
|
|
|
|
ul rsdt_phys_base = rsdpv2->rsdp1.RsdtAddress & PAGE_2M_MASK;
|
|
|
acpi_RSDT_offset = rsdpv2->rsdp1.RsdtAddress - rsdt_phys_base;
|
|
|
- mm_map_phys_addr(ACPI_RSDT_VIRT_ADDR_BASE, rsdt_phys_base, PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false);
|
|
|
+
|
|
|
+
|
|
|
+ uint64_t size = 0;
|
|
|
+ mmio_create(PAGE_2M_SIZE, VM_IO | VM_DONTCOPY, &acpi_rsdt_virt_addr_base, &size);
|
|
|
+
|
|
|
+
|
|
|
+ paddr = (uint64_t)rsdt_phys_base;
|
|
|
+ mm_map(&initial_mm, acpi_rsdt_virt_addr_base, PAGE_2M_SIZE, paddr);
|
|
|
+
|
|
|
+
|
|
|
+ rsdt = (struct acpi_RSDT_Structure_t *)(acpi_rsdt_virt_addr_base + acpi_RSDT_offset);
|
|
|
kdebug("RSDT mapped!(v2)");
|
|
|
- rsdt = (struct acpi_RSDT_Structure_t *)(ACPI_RSDT_VIRT_ADDR_BASE + acpi_RSDT_offset);
|
|
|
+
|
|
|
|
|
|
kdebug("offset=%d", sizeof(rsdt->header));
|
|
|
acpi_RSDT_Entry_num = (rsdt->header.Length - 36) / 4;
|
|
@@ -169,43 +176,57 @@ void acpi_init()
|
|
|
printk_color(ORANGE, BLACK, "RSDT Length=%dbytes.\n", rsdt->header.Length);
|
|
|
printk_color(ORANGE, BLACK, "RSDT Entry num=%d\n", acpi_RSDT_Entry_num);
|
|
|
|
|
|
- mm_map_phys_addr(ACPI_RSDT_VIRT_ADDR_BASE, rsdt_phys_base, rsdt->header.Length + PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false);
|
|
|
+
|
|
|
+ mmio_create(PAGE_2M_SIZE, VM_IO | VM_DONTCOPY, &acpi_description_header_base, &size);
|
|
|
+
|
|
|
|
|
|
acpi_RSDT_entry_phys_base = ((ul)(rsdt->Entry)) & PAGE_2M_MASK;
|
|
|
|
|
|
acpi_RSDT_entry_phys_base = MASK_HIGH_32bit(acpi_RSDT_entry_phys_base);
|
|
|
|
|
|
- kdebug("entry=%#018lx", rsdt->Entry);
|
|
|
- kdebug("acpi_RSDT_entry_phys_base=%#018lx", acpi_RSDT_entry_phys_base);
|
|
|
-
|
|
|
- mm_map_phys_addr(ACPI_DESCRIPTION_HEDERS_BASE, acpi_RSDT_entry_phys_base, PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false);
|
|
|
+ paddr = (uint64_t)acpi_RSDT_entry_phys_base;
|
|
|
+ mm_map(&initial_mm, acpi_description_header_base, PAGE_2M_SIZE, paddr);
|
|
|
}
|
|
|
else if (rsdpv1->RsdtAddress != (uint)0x00UL)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
+ {
|
|
|
+
|
|
|
ul rsdt_phys_base = rsdpv1->RsdtAddress & PAGE_2M_MASK;
|
|
|
acpi_RSDT_offset = rsdpv1->RsdtAddress - rsdt_phys_base;
|
|
|
- mm_map_phys_addr(ACPI_RSDT_VIRT_ADDR_BASE, rsdt_phys_base, PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false);
|
|
|
+
|
|
|
+ kdebug("rsdpv1->RsdtAddress=%#018lx", rsdpv1->RsdtAddress);
|
|
|
+
|
|
|
+ uint64_t size = 0;
|
|
|
+ mmio_create(PAGE_2M_SIZE, VM_IO | VM_DONTCOPY, &acpi_rsdt_virt_addr_base, &size);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ paddr = (uint64_t)rsdt_phys_base;
|
|
|
+ mm_map(&initial_mm, acpi_rsdt_virt_addr_base, PAGE_2M_SIZE, paddr);
|
|
|
+
|
|
|
+ rsdt = (struct acpi_RSDT_Structure_t *)(acpi_rsdt_virt_addr_base + acpi_RSDT_offset);
|
|
|
kdebug("RSDT mapped!");
|
|
|
- rsdt = (struct acpi_RSDT_Structure_t *)(ACPI_RSDT_VIRT_ADDR_BASE + acpi_RSDT_offset);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- kdebug("offset=%d", sizeof(rsdt->header));
|
|
|
+
|
|
|
+
|
|
|
acpi_RSDT_Entry_num = (rsdt->header.Length - 36) / 4;
|
|
|
|
|
|
printk_color(ORANGE, BLACK, "RSDT Length=%dbytes.\n", rsdt->header.Length);
|
|
|
printk_color(ORANGE, BLACK, "RSDT Entry num=%d\n", acpi_RSDT_Entry_num);
|
|
|
|
|
|
- mm_map_phys_addr(ACPI_RSDT_VIRT_ADDR_BASE, rsdt_phys_base, rsdt->header.Length + PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false);
|
|
|
+
|
|
|
+ mmio_create(PAGE_2M_SIZE, VM_IO | VM_DONTCOPY, &acpi_description_header_base, &size);
|
|
|
+
|
|
|
|
|
|
acpi_RSDT_entry_phys_base = ((ul)(rsdt->Entry)) & PAGE_2M_MASK;
|
|
|
|
|
|
acpi_RSDT_entry_phys_base = MASK_HIGH_32bit(acpi_RSDT_entry_phys_base);
|
|
|
|
|
|
- kdebug("entry=%#018lx", rsdt->Entry);
|
|
|
- kdebug("acpi_RSDT_entry_phys_base=%#018lx", acpi_RSDT_entry_phys_base);
|
|
|
-
|
|
|
- mm_map_phys_addr(ACPI_DESCRIPTION_HEDERS_BASE, acpi_RSDT_entry_phys_base, PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD, false);
|
|
|
+ paddr = (uint64_t)acpi_RSDT_entry_phys_base;
|
|
|
+ mm_map(&initial_mm, acpi_description_header_base, PAGE_2M_SIZE, paddr);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -216,4 +237,5 @@ void acpi_init()
|
|
|
}
|
|
|
|
|
|
kinfo("ACPI module initialized!");
|
|
|
-}
|
|
|
+ return;
|
|
|
+}
|