diff options
author | Marvin Borner | 2020-09-06 13:15:14 +0200 |
---|---|---|
committer | Marvin Borner | 2020-09-06 13:15:14 +0200 |
commit | c2d88b639c759e06444c1bf0efdd96e243d3a6c2 (patch) | |
tree | 72d933526dab390fcc0c1125e15ecf6b223b893b /kernel/drivers/acpi.c | |
parent | c0608f199fc711aa82867f80059dfeebf38b4a25 (diff) |
Started ACPI driver
Diffstat (limited to 'kernel/drivers/acpi.c')
-rw-r--r-- | kernel/drivers/acpi.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/kernel/drivers/acpi.c b/kernel/drivers/acpi.c new file mode 100644 index 0000000..02f3718 --- /dev/null +++ b/kernel/drivers/acpi.c @@ -0,0 +1,54 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#include <acpi.h> +#include <assert.h> +#include <cpu.h> +#include <def.h> +#include <mem.h> +#include <print.h> + +int check_sdt(struct sdt_header *header) +{ + u8 sum = 0; + + for (u32 i = 0; i < header->length; i++) + sum += ((char *)header)[i]; + + return sum == 0; +} + +int check_sdp(struct sdp_header *header) +{ + u8 sum = 0; + + for (u32 i = 0; i < sizeof(struct rsdp); i++) + sum += ((char *)header)[i]; + + return sum == 0; +} + +struct rsdp *find_rsdp() +{ + // Main BIOS area + for (int i = 0xe0000; i < 0xfffff; i++) { + if (memcmp((u32 *)i, RSDP_MAGIC, 8) == 0) + return (struct rsdp *)i; + } + + // Or first KB of EBDA? + for (int i = 0x100000; i < 0x101000; i++) { + if (memcmp((u32 *)i, RSDP_MAGIC, 8) == 0) + return (struct rsdp *)i; + } + + return NULL; +} + +void acpi_install() +{ + struct rsdp *rsdp = find_rsdp(); + assert(rsdp && rsdp->header.revision == 0 && check_sdp(&rsdp->header)); + struct rsdt *rsdt = rsdp->rsdt; + assert(rsdt && memcmp(rsdt->header.signature, RSDT_MAGIC, 4) == 0 && + check_sdt(&rsdt->header)); +} |