Add madt_entry_types and print out value

This commit is contained in:
Michael Shaw 2023-02-28 17:24:32 -05:00
commit b8599a4e8e
4 changed files with 62 additions and 4 deletions

View file

@ -7,7 +7,15 @@
struct limine_rsdp_request rsdp_req = { .id = LIMINE_RSDP_REQUEST,
.revision = 0 };
static struct rsdp *rsdp;
static struct rsdp *rsdp = NULL;
struct madt *__madt = NULL;
static const char *madt_entry_types[] = {
"L-APIC", "I/O-APIC", "I/O-APIC_IRQ_SRC_OVRD",
"I/O-APIC_NMI_SRC", "L-APIC_NMI", "L-APIC_ADDR_OVRD",
"INVALID", "INVALID", "INVALID",
"CPU_LOCAL_X2-APIC"
};
void rsdt_print(struct rsdt *rsdt)
{
@ -19,12 +27,32 @@ void rsdt_print(struct rsdt *rsdt)
uint64_t sdt_addr = (uint64_t)rsdt->sdt[i];
struct acpi_sdt_header *h = (struct acpi_sdt_header *)sdt_addr;
if (!(memcmp(h->signature, "APIC", 4))) {
__madt = (struct madt *)h;
}
char buf[9];
memcpy(buf, h->signature, 4);
printf("[ACPI] %s %d %x \n", buf, h->revision, h->checksum);
}
}
int parse_next_madt_entry(int offset)
{
if ((unsigned)offset >= (__madt->h.length - 1))
return 0;
static int n = 0; /* Entry number */
uint8_t *madt = (uint8_t *)__madt;
int type = madt[offset];
int len = madt[offset + 1];
printf("MADT Entry %d: %s\n", n, madt_entry_types[type]);
return offset + len;
}
void acpi_init()
{
rsdp = (struct rsdp *)rsdp_req.response->address;
@ -32,10 +60,20 @@ void acpi_init()
/* 2 steps silences warning */
uint64_t rsdt_addr = (uint64_t)rsdp->rsdt_addr;
struct rsdt *rsdt = (struct rsdt *)rsdt_addr;
rsdt_print(rsdt);
printf("ACPI version: %d\n", rsdp->revision);
if (__madt == NULL) {
printf("Failed to locate MADT\n");
} else {
/* First variable entry in MADT */
int offset = 0x2C;
int length = __madt->h.length;
printf("MADT Length: %x\n", length);
while ((offset = parse_next_madt_entry(offset)))
;
}
printf("ACPI version: %d\n", rsdp->revision);
printf("ACPI initialized\n");
}