summaryrefslogtreecommitdiff
path: root/include/acpi.h
diff options
context:
space:
mode:
authorAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2023-12-13 13:24:48 +0100
committerAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2023-12-25 18:37:20 +0100
commit30d6e8f850d2fe26fffdeef0c38fc627ef8bab9a (patch)
treecd786b6a79d6a58590b2d35308746761c1e3d977 /include/acpi.h
initial commit
currently with: booted via multiboot 1 protected mode to long mode boostrap code vga used for outputting gdt and idt set up identity paging for the whole memory reported by multiboot pic and ps/2 set up acpi code exists but is broken
Diffstat (limited to 'include/acpi.h')
-rw-r--r--include/acpi.h143
1 files changed, 143 insertions, 0 deletions
diff --git a/include/acpi.h b/include/acpi.h
new file mode 100644
index 0000000..1c68ef4
--- /dev/null
+++ b/include/acpi.h
@@ -0,0 +1,143 @@
+#ifndef _ACPI_H_
+#define _ACPI_H_
+
+#include <stdint.h>
+#include <stddef.h>
+
+struct rsdp {
+ char signature[8];
+ uint8_t checksum;
+ char oemid[6];
+ uint8_t revision;
+ uint32_t rsdt_address;
+} __attribute__((packed));
+
+struct xsdp {
+ char signature[8];
+ uint8_t checksum;
+ char oemid[6];
+ uint8_t revision;
+ uint32_t rsdt_address; // deprecated since version 2.0
+
+ uint32_t length;
+ uint64_t xsdt_address;
+ uint8_t extended_checksum;
+ uint8_t reserved[3];
+} __attribute__((packed));
+
+struct acpi_sdt_header {
+ char signature[4];
+ uint32_t len;
+ uint8_t rev;
+ uint8_t checksum;
+ char oemid[6];
+ char oem_tableid[8];
+ uint32_t oem_revision;
+ uint32_t creatorid;
+ uint32_t creator_rev;
+} __attribute__((packed));
+
+struct rsdt {
+ struct acpi_sdt_header header;
+ uint32_t sdt_pointers[];
+} __attribute__((packed));
+
+struct xsdt {
+ struct acpi_sdt_header header;
+ uint64_t sdt_pointers[];
+} __attribute__((packed));
+
+struct generic_address {
+ uint8_t address_space;
+ uint8_t bid_width;
+ uint8_t bit_offset;
+ uint8_t access_size;
+ uint64_t address;
+} __attribute__((packed));
+
+struct fadt {
+ struct acpi_sdt_header header;
+ uint32_t firmware_ctrl;
+ uint32_t dsdt;
+
+ uint8_t reserved;
+
+ uint8_t prevered_power_management_profile;
+ uint16_t sci_interrupt;
+ uint32_t smi_command_port;
+ uint8_t acpi_enable;
+ uint8_t acpi_disable;
+ uint8_t s4_bios_req;
+ uint8_t pstate_control;
+
+ uint32_t pm1a_event_block;
+ uint32_t pm1b_event_block;
+
+ uint32_t pm1a_control_block;
+ uint32_t pm1b_control_block;
+
+ uint32_t pm2_control_block;
+
+ uint32_t pm_timer_block;
+
+ uint32_t gpe0_block;
+ uint32_t gpe1_block;
+
+ uint8_t pm1_event_length;
+ uint8_t pm1_control_length;
+ uint8_t pm2_control_length;
+ uint8_t pm_timer_length;
+
+ uint8_t gpe0_length;
+ uint8_t gpe1_length;
+ uint8_t gpe1_base;
+
+ uint8_t cstate_control;
+
+ uint16_t worst_c2_latency;
+ uint16_t worst_c3_latency;
+
+ uint16_t flush_size;
+ uint16_t flush_stride;
+
+ uint8_t duty_offset;
+ uint8_t duty_width;
+
+ uint8_t day_alarm;
+ uint8_t month_alarm;
+ uint8_t century;
+
+ uint16_t boot_arch_flags;
+
+ uint8_t reserved_2;
+ uint32_t flags;
+
+ struct generic_address reset_reg;
+
+ uint8_t reset_valued;
+ uint8_t reserved_3[3];
+
+ uint64_t x_firmware_control;
+ uint64_t x_dsdt;
+
+ struct generic_address x_pm1a_event_block;
+ struct generic_address x_pm1b_event_block;
+ struct generic_address x_pm1a_control_block;
+ struct generic_address x_pm1b_control_block;
+ struct generic_address x_pm2_control_block;
+ struct generic_address x_pm_timer_block;
+ struct generic_address x_gpe0_block;
+ struct generic_address x_gpe1_block;
+} __attribute__((packed));
+
+struct xsdp *find_rsdp();
+struct fadt *find_facp(struct xsdt *root_sdt);
+void print_rsdp(const struct rsdp *rsdp);
+
+static inline struct xsdt *get_rsdt(struct xsdp *rsdp) {
+ if (rsdp == NULL || rsdp->revision == 0)
+ return NULL;
+ return (struct xsdt *) rsdp->xsdt_address;
+}
+
+#endif