|
@@ -4,21 +4,25 @@
|
|
|
#include "../multiboot2/multiboot2.h"
|
|
|
#include "../../mm/mm.h"
|
|
|
|
|
|
-// 获取RSDT entry的虚拟地址
|
|
|
-#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_HEDERS_BASE + (phys_addr)-acpi_RSDT_entry_phys_base) // 获取RSDT entry的虚拟地址
|
|
|
+// #define acpi_get_XSDT_entry_vaddr(phys_addr) (ACPI_DESCRIPTION_HEDERS_BASE + (phys_addr)-acpi_XSDT_entry_phys_base) // 获取XSDT entry的虚拟地址
|
|
|
|
|
|
static struct acpi_RSDP_t *rsdpv1;
|
|
|
static struct acpi_RSDP_2_t *rsdpv2;
|
|
|
static struct acpi_RSDT_Structure_t *rsdt;
|
|
|
+static struct acpi_XSDT_Structure_t *xsdt;
|
|
|
|
|
|
static struct multiboot_tag_old_acpi_t old_acpi;
|
|
|
static struct multiboot_tag_new_acpi_t new_acpi;
|
|
|
|
|
|
static ul acpi_RSDT_offset = 0;
|
|
|
+static ul acpi_XSDT_offset = 0;
|
|
|
static uint acpi_RSDT_Entry_num = 0;
|
|
|
+static uint acpi_XSDT_Entry_num = 0;
|
|
|
|
|
|
-// RSDT中的第一个entry所在物理页的基地址
|
|
|
-static ul acpi_RSDT_entry_phys_base = 0;
|
|
|
+static ul acpi_RSDT_entry_phys_base = 0; // RSDT中的第一个entry所在物理页的基地址
|
|
|
+
|
|
|
+// static ul acpi_XSDT_entry_phys_base = 0; // XSDT中的第一个entry所在物理页的基地址
|
|
|
|
|
|
/**
|
|
|
* @brief 迭代器,用于迭代描述符头(位于ACPI标准文件的Table 5-29)
|
|
@@ -30,17 +34,30 @@ void acpi_iter_SDT(bool (*_fun)(const struct acpi_system_description_table_heade
|
|
|
{
|
|
|
|
|
|
struct acpi_system_description_table_header_t *sdt_header;
|
|
|
- uint *ent = &(rsdt->Entry);
|
|
|
- for (int i = 0; i < acpi_RSDT_Entry_num; ++i)
|
|
|
+ if (acpi_use_xsdt)
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ sdt_header = (struct acpi_system_description_table_header_t *)((ul)(ACPI_XSDT_DESCRIPTION_HEDERS_BASE + PAGE_2M_SIZE * i));
|
|
|
+
|
|
|
+ if (_fun(sdt_header, _data) == true)
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
+ uint *ent = &(rsdt->Entry);
|
|
|
+ for (int i = 0; i < acpi_RSDT_Entry_num; ++i)
|
|
|
+ {
|
|
|
|
|
|
- sdt_header = (struct acpi_system_description_table_header_t *)(acpi_get_RSDT_entry_vaddr((ul)(*(ent + i))));
|
|
|
- kwarn("vvv=%#018lx", (ul)(*(ent + i)));
|
|
|
- kwarn("vaddr=%#018lx", (ul)acpi_get_RSDT_entry_vaddr((ul)(*(ent + i))));
|
|
|
- printk_color(ORANGE, BLACK,"kkl=%s\n", sdt_header->Signature);
|
|
|
+ sdt_header = (struct acpi_system_description_table_header_t *)(acpi_get_RSDT_entry_vaddr((ul)(*(ent + i))));
|
|
|
+
|
|
|
|
|
|
- if (_fun(sdt_header, _data) == true)
|
|
|
- return;
|
|
|
+ if (_fun(sdt_header, _data) == true)
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return;
|
|
@@ -61,9 +78,7 @@ bool acpi_get_MADT(const struct acpi_system_description_table_header_t *_iter_da
|
|
|
return false;
|
|
|
//*(struct acpi_Multiple_APIC_Description_Table_t *)_data = *(struct acpi_Multiple_APIC_Description_Table_t *)_iter_data;
|
|
|
// 返回MADT的虚拟地址
|
|
|
-
|
|
|
*(ul *)_data = (ul)_iter_data;
|
|
|
- printk_color(ORANGE, BLACK,"xxx=%#018lx\n", (ul)_iter_data);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
@@ -82,42 +97,105 @@ void acpi_init()
|
|
|
int reserved;
|
|
|
multiboot2_iter(multiboot2_get_acpi_old_RSDP, &old_acpi, &reserved);
|
|
|
|
|
|
- *rsdpv1 = (old_acpi.rsdp);
|
|
|
+ rsdpv1 = &(old_acpi.rsdp);
|
|
|
|
|
|
kdebug("RSDT_phys_Address=%#018lx", rsdpv1->RsdtAddress);
|
|
|
kdebug("RSDP_Revision=%d", rsdpv1->Revision);
|
|
|
|
|
|
- // 映射RSDT的物理地址到页表
|
|
|
- // 暂定字节数为2MB
|
|
|
- // 由于页表映射的原因,需要清除低21位地址,才能填入页表
|
|
|
- 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);
|
|
|
- kdebug("RSDT mapped!");
|
|
|
-
|
|
|
multiboot2_iter(multiboot2_get_acpi_new_RSDP, &new_acpi, &reserved);
|
|
|
- *rsdpv2 = new_acpi.rsdp;
|
|
|
+ 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);
|
|
|
|
|
|
- rsdt = (struct acpi_RSDT_Structure_t *)(ACPI_RSDT_VIRT_ADDR_BASE + acpi_RSDT_offset);
|
|
|
-
|
|
|
- // 计算RSDT Entry的数量
|
|
|
- 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);
|
|
|
- // 映射所有的Entry的物理地址
|
|
|
- acpi_RSDT_entry_phys_base = ((ul)(rsdt->Entry)) & PAGE_2M_MASK;
|
|
|
- // 由于地址只是32bit的,并且存在脏数据,这里需要手动清除高32bit,否则会触发#GP
|
|
|
- acpi_RSDT_entry_phys_base = MASK_HIGH_32bit(acpi_RSDT_entry_phys_base);
|
|
|
+ // An ACPI-compatible OS must use the XSDT if present
|
|
|
+ if (rsdpv2->XsdtAddress != 0x00UL)
|
|
|
+ {
|
|
|
+ /*
|
|
|
+ acpi_use_xsdt = true;
|
|
|
+ ul xsdt_phys_base = rsdpv2->XsdtAddress & PAGE_2M_MASK;
|
|
|
+ acpi_XSDT_offset = rsdpv2->XsdtAddress - xsdt_phys_base;
|
|
|
+ mm_map_phys_addr(ACPI_XSDT_VIRT_ADDR_BASE, xsdt_phys_base, PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD);
|
|
|
+ kdebug("XSDT mapped!");
|
|
|
+
|
|
|
+ xsdt = (struct acpi_XSDT_Structure_t *)(ACPI_XSDT_VIRT_ADDR_BASE + acpi_XSDT_offset);
|
|
|
+ // 计算RSDT Entry的数量
|
|
|
+ kdebug("offset=%d", sizeof(xsdt->header));
|
|
|
+ kdebug("xsdt sign=%s", xsdt->header.Signature);
|
|
|
+ acpi_XSDT_Entry_num = (xsdt->header.Length - sizeof(xsdt->header)) / 8;
|
|
|
+
|
|
|
+ printk_color(ORANGE, BLACK, "XSDT Length=%dbytes.\n", xsdt->header.Length);
|
|
|
+ printk_color(ORANGE, BLACK, "XSDT Entry num=%d\n", acpi_XSDT_Entry_num);
|
|
|
+
|
|
|
+ mm_map_phys_addr(ACPI_XSDT_VIRT_ADDR_BASE, xsdt_phys_base, xsdt->header.Length + PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD);
|
|
|
+ // 映射所有的Entry的物理地址
|
|
|
+ ul *ent = &(xsdt->Entry);
|
|
|
+ for (int j = 0; j < acpi_XSDT_Entry_num; ++j)
|
|
|
+ {
|
|
|
+ kdebug("entry=%#018lx, virt=%#018lx", (*(ent + j)) & PAGE_2M_MASK, ACPI_XSDT_DESCRIPTION_HEDERS_BASE + PAGE_2M_SIZE * j);
|
|
|
+ // 映射RSDT ENTRY的物理地址
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ */
|
|
|
+ // 由于解析XSDT出现问题。暂时只使用Rsdpv2的rsdt,但是这是不符合ACPI规范的!!!
|
|
|
+ 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);
|
|
|
+ kdebug("RSDT mapped!(v2)");
|
|
|
+ rsdt = (struct acpi_RSDT_Structure_t *)(ACPI_RSDT_VIRT_ADDR_BASE + acpi_RSDT_offset);
|
|
|
+ // 计算RSDT Entry的数量
|
|
|
+ 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);
|
|
|
+ // 映射所有的Entry的物理地址
|
|
|
+ acpi_RSDT_entry_phys_base = ((ul)(rsdt->Entry)) & PAGE_2M_MASK;
|
|
|
+ // 由于地址只是32bit的,并且存在脏数据,这里需要手动清除高32bit,否则会触发#GP
|
|
|
+ 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);
|
|
|
+ // 映射RSDT ENTRY的物理地址
|
|
|
+ mm_map_phys_addr(ACPI_DESCRIPTION_HEDERS_BASE, acpi_RSDT_entry_phys_base, PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD);
|
|
|
+ }
|
|
|
+ else if (rsdpv1->RsdtAddress != (uint)0x00UL)
|
|
|
+ { // 映射RSDT的物理地址到页表
|
|
|
+ // 暂定字节数为2MB
|
|
|
+ // 由于页表映射的原因,需要清除低21位地址,才能填入页表
|
|
|
+ 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);
|
|
|
+ kdebug("RSDT mapped!");
|
|
|
+ rsdt = (struct acpi_RSDT_Structure_t *)(ACPI_RSDT_VIRT_ADDR_BASE + acpi_RSDT_offset);
|
|
|
+ // 计算RSDT Entry的数量
|
|
|
+ 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);
|
|
|
+ // 映射所有的Entry的物理地址
|
|
|
+ acpi_RSDT_entry_phys_base = ((ul)(rsdt->Entry)) & PAGE_2M_MASK;
|
|
|
+ // 由于地址只是32bit的,并且存在脏数据,这里需要手动清除高32bit,否则会触发#GP
|
|
|
+ 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);
|
|
|
+ // 映射RSDT ENTRY的物理地址
|
|
|
+ mm_map_phys_addr(ACPI_DESCRIPTION_HEDERS_BASE, acpi_RSDT_entry_phys_base, PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // should not reach here!
|
|
|
+ kBUG("At acpi_init(): Cannot get right SDT!");
|
|
|
+ while (1)
|
|
|
+ ;
|
|
|
+ }
|
|
|
|
|
|
- kdebug("entry=%#018lx", rsdt->Entry);
|
|
|
- kdebug("acpi_RSDT_entry_phys_base=%#018lx", acpi_RSDT_entry_phys_base);
|
|
|
- // 映射RSDT ENTRY的物理地址
|
|
|
- mm_map_phys_addr(ACPI_DESCRIPTION_HEDERS_BASE, acpi_RSDT_entry_phys_base, PAGE_2M_SIZE, PAGE_KERNEL_PAGE | PAGE_PWT | PAGE_PCD);
|
|
|
kinfo("ACPI module initialized!")
|
|
|
}
|