Add madt_entry_types and print out value
This commit is contained in:
parent
2146b49bb3
commit
b8599a4e8e
4 changed files with 62 additions and 4 deletions
|
|
@ -28,9 +28,17 @@ struct acpi_sdt_header {
|
|||
struct rsdt {
|
||||
struct acpi_sdt_header h;
|
||||
uint32_t sdt[];
|
||||
};
|
||||
} PACKED;
|
||||
|
||||
struct madt {
|
||||
struct acpi_sdt_header h;
|
||||
uint32_t lapic_addr;
|
||||
uint32_t flags;
|
||||
} PACKED;
|
||||
|
||||
void acpi_init();
|
||||
|
||||
extern struct madt *__madt;
|
||||
|
||||
#endif /* __ASM__ */
|
||||
#endif /* _ACPI_H_ */
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <kernel/common.h>
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t num);
|
||||
int memcmp(const void *aa, const void *bb, size_t num);
|
||||
char *strcpy(char *dest, const char *src);
|
||||
|
||||
#endif /* __ASM__ */
|
||||
|
|
|
|||
44
init/acpi.c
44
init/acpi.c
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
11
lib/string.c
11
lib/string.c
|
|
@ -16,3 +16,14 @@ char *strcpy(char *dest, const char *src)
|
|||
;
|
||||
return dest;
|
||||
}
|
||||
|
||||
int memcmp(const void *aa, const void *bb, size_t num)
|
||||
{
|
||||
const char *a = (const char *)aa;
|
||||
const char *b = (const char *)bb;
|
||||
for (size_t i = 0; i < num; i++) {
|
||||
if (*a++ != *b++)
|
||||
return a - b;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue