aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/drivers/acpi.c19
-rw-r--r--kernel/inc/acpi.h40
2 files changed, 59 insertions, 0 deletions
diff --git a/kernel/drivers/acpi.c b/kernel/drivers/acpi.c
index 02f3718..f7f643c 100644
--- a/kernel/drivers/acpi.c
+++ b/kernel/drivers/acpi.c
@@ -44,6 +44,19 @@ struct rsdp *find_rsdp()
return NULL;
}
+void *find_sdt(struct rsdt *rsdt, const char *signature)
+{
+ int entries = (rsdt->header.length - sizeof(rsdt->header)) / 4;
+
+ for (int i = 0; i < entries; i++) {
+ struct sdt_header *header = (struct sdt_header *)rsdt->sdt_pointer[i];
+ if (memcmp(header->signature, signature, 4) == 0)
+ return header;
+ }
+
+ return NULL;
+}
+
void acpi_install()
{
struct rsdp *rsdp = find_rsdp();
@@ -51,4 +64,10 @@ void acpi_install()
struct rsdt *rsdt = rsdp->rsdt;
assert(rsdt && memcmp(rsdt->header.signature, RSDT_MAGIC, 4) == 0 &&
check_sdt(&rsdt->header));
+
+ madt = find_sdt(rsdt, MADT_MAGIC);
+ fadt = find_sdt(rsdt, FADT_MAGIC);
+ hpet = find_sdt(rsdt, HPET_MAGIC);
+ assert(madt && check_sdt(&madt->header) && fadt && check_sdt(&fadt->header) && hpet &&
+ check_sdt(&hpet->header));
}
diff --git a/kernel/inc/acpi.h b/kernel/inc/acpi.h
index f620d55..2b4c76e 100644
--- a/kernel/inc/acpi.h
+++ b/kernel/inc/acpi.h
@@ -7,6 +7,17 @@
#define RSDP_MAGIC "RSD PTR "
#define RSDT_MAGIC "RSDT"
+#define MADT_MAGIC "APIC"
+#define FADT_MAGIC "FACP"
+#define HPET_MAGIC "HPET"
+
+struct address_structure {
+ u8 address_space_id;
+ u8 register_bit_width;
+ u8 register_bit_offset;
+ u8 reserved;
+ u64 address;
+};
struct sdt_header {
char signature[4];
@@ -32,11 +43,40 @@ struct rsdt {
u32 sdt_pointer[];
};
+struct madt {
+ struct sdt_header header;
+ u32 local_address;
+ u32 flags;
+};
+
+struct fadt {
+ struct sdt_header header;
+ // TODO: FADT table (big!)
+};
+
+struct hpet {
+ struct sdt_header header;
+ u8 hardware_rev_id;
+ u8 comparator_count : 5;
+ u8 counter_size : 1;
+ u8 reserved : 1;
+ u8 legacy_replacement : 1;
+ u16 pci_vendor_id;
+ struct address_structure address;
+ u8 hpet_number;
+ u16 minimum_tick;
+ u8 page_protection;
+};
+
struct rsdp {
struct sdp_header header;
struct rsdt *rsdt;
};
+struct madt *madt;
+struct fadt *fadt;
+struct hpet *hpet;
+
void acpi_install();
#endif