diff options
author | Marvin Borner | 2020-06-17 18:31:46 +0200 |
---|---|---|
committer | Marvin Borner | 2020-06-17 18:31:46 +0200 |
commit | eed77bd2970a00d1394ed027ceca5b646e4671ce (patch) | |
tree | c44643d98aed2b6818f2b33417c0dea9c5853094 /src/kernel/acpi | |
parent | 49dfa1f4021026bf7c4d77817959c8aa24067016 (diff) |
Started rewrite
Diffstat (limited to 'src/kernel/acpi')
-rw-r--r-- | src/kernel/acpi/acpi.c | 112 | ||||
-rw-r--r-- | src/kernel/acpi/acpi.h | 169 |
2 files changed, 0 insertions, 281 deletions
diff --git a/src/kernel/acpi/acpi.c b/src/kernel/acpi/acpi.c deleted file mode 100644 index 6e1811c..0000000 --- a/src/kernel/acpi/acpi.c +++ /dev/null @@ -1,112 +0,0 @@ -// Important specification: https://uefi.org/sites/default/files/resources/ACPI_6_2.pdf -// HPET: https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/software-developers-hpet-spec-1-0a.pdf - -#include <acpi/acpi.h> -#include <io/io.h> -#include <lib/lib.h> -#include <lib/stdio.h> -#include <lib/stdlib.h> -#include <memory/alloc.h> -#include <memory/paging.h> -#include <multiboot.h> -#include <stddef.h> -#include <system.h> - -struct rsdt *rsdt; -struct fadt *fadt; -struct hpet *hpet; -struct madt *madt; - -int check_sum(struct sdt_header *header) -{ - u8 sum = 0; - - for (u32 i = 0; i < header->length; i++) - sum += ((char *)header)[i]; - - return sum == 0; -} - -void acpi_init(struct rsdp *rsdp) -{ - // TODO: Fix ACPI table discovering (HPET & MADT missing) - // TODO: Fix ACPI breaking VESA (why?!) - - struct sdt_header *header = (struct sdt_header *)malloc(sizeof(struct sdt_header)); - rsdt = (struct rsdt *)malloc(sizeof(struct rsdt)); - fadt = (struct fadt *)malloc(sizeof(struct fadt)); - hpet = (struct hpet *)malloc(sizeof(struct hpet)); - madt = (struct madt *)malloc(sizeof(struct madt)); - - if (strncmp(rsdp->signature, "RSD PTR ", 8) == 0) { - memcpy(rsdt, rsdp->rsdt_address, sizeof(struct rsdt) + 32); - debug("Found RSDT"); - if (!check_sum((struct sdt_header *)rsdt)) { - warn("Corrupted RSDT!"); - } else { - u32 *pointer = (u32 *)(rsdt + 1); - u32 *end = (u32 *)((u8 *)rsdt + rsdt->header.length); - - while (pointer < end) { - u32 address = *pointer++; - memcpy(header, (void *)address, sizeof(struct sdt_header)); - - if (strncmp(header->signature, "FACP", 4) == 0) { - debug("Found FADT"); - memcpy(fadt, (void *)address, sizeof(struct fadt)); - if (!check_sum((struct sdt_header *)fadt)) - warn("Corrupted FADT!"); - } else if (strncmp(header->signature, "HPET", 4) == 0) { - debug("Found HPET"); - memcpy(hpet, (void *)address, sizeof(struct hpet)); - if (!check_sum((struct sdt_header *)hpet)) - warn("Corrupted HPET!"); - } else if (strncmp(header->signature, "APIC", 4) == 0) { - debug("Found MADT"); - memcpy(madt, (void *)address, sizeof(struct madt)); - if (!check_sum((struct sdt_header *)madt)) - warn("Corrupted MADT!"); - } - } - } - } else { - warn("Wrong RSD signature!"); - } - free(header); -} - -void acpi_old_init(struct multiboot_tag_old_acpi *tag) -{ - // acpi_init((struct rsdp *)tag->rsdp); -} - -void acpi_new_init(struct multiboot_tag_new_acpi *tag) -{ - // acpi_init((struct rsdp *)tag->rsdp); -} - -void acpi_poweroff() -{ - // TODO: Add APCI poweroff support - cli(); - outw(0x604, 0x2000); // QEMU - outw(0xB004, 0x2000); // Bochs - outw(0x4004, 0x3400); // VirtualBox - halt_loop(); -} - -void reboot() -{ - cli(); - if (fadt->header.revision >= 2 && fadt->flags.reset_support) { - debug("Reset support!"); - outb(fadt->reset_reg.address, fadt->reset_value); - halt_loop(); - } else { - u8 good = 0x02; - while (good & 0x02) - good = inb(0x64); - outb(0x64, 0xFE); - halt_loop(); - } -}
\ No newline at end of file diff --git a/src/kernel/acpi/acpi.h b/src/kernel/acpi/acpi.h deleted file mode 100644 index 9b64f7c..0000000 --- a/src/kernel/acpi/acpi.h +++ /dev/null @@ -1,169 +0,0 @@ -#ifndef MELVIX_ACPI_H -#define MELVIX_ACPI_H - -#include <multiboot.h> -#include <stdint.h> - -/** - * Initialize the ACP interface - */ -void acpi_old_init(struct multiboot_tag_old_acpi *tag); -void acpi_new_init(struct multiboot_tag_new_acpi *tag); - -/** - * Activate a ACPI based device reboot - */ -void reboot(); - -/** - * Activate a ACPI based device shutdown/poweroff - */ -void acpi_poweroff(); - -struct address_structure { - u8 address_space_id; - u8 register_bit_width; - u8 register_bit_offset; - u8 reserved; - u64 address; -}; - -// p. 138 -struct fadt_flags { - u8 WBINVD : 1; - u8 WBINVD_flush : 1; - u8 C1_support : 1; - u8 C2_mp_support : 1; - u8 power_button : 1; // 1 if not present - u8 sleep_button : 1; // 1 if not present - u8 rtc_fix_reg : 1; - u8 rtc_wakes_S4 : 1; - u8 timer_32 : 1; - u8 dock_support : 1; - u8 reset_support : 1; - u8 sealed_case : 1; - u8 headless : 1; - u8 slp_instruction : 1; - u8 pci_wake_support : 1; - u8 use_platform_clock : 1; - u8 rtc_valid_S4 : 1; - u8 remote_on_support : 1; - u8 force_apic_cluster : 1; - u8 force_apic_physical : 1; - u8 hw_reduced_acpi : 1; - u8 low_power_S0_support : 1; - u16 reserved : 10; -}; - -struct rsdp { - char signature[8]; - char checksum; - char oem_id[6]; - char revision; - u32 *rsdt_address; -}; - -struct sdt_header { - char signature[4]; - u32 length; - u8 revision; - u8 checksum; - char oem_id[6]; - char oem_table_id[8]; - u32 oem_revision; - u32 creator_id; - u32 creator_revision; -}; - -struct rsdt { - struct sdt_header header; - u32 sdt_pointer[]; -}; - -struct xsdt { - struct sdt_header header; - u32 sdt_pointer[]; -}; - -struct fadt { - struct sdt_header header; - u32 firmware_ctl; - u32 dsdt; - u8 reserved; - u8 preferred_power_management; - u16 sci_interrupt; - u32 smi_commandPort; - u8 acpi_enable; - u8 acpi_disable; - u8 S4BIOS_req; - u8 PSTATE_control; - u32 PM1a_event_block; - u32 PM1b_event_block; - u32 PM1a_control_block; - u32 PM1b_control_block; - u32 PM2_control_block; - u32 PM_timer_block; - u32 GPE0_block; - u32 GPE1_block; - u8 PM1_event_length; - u8 PM1_control_length; - u8 PM2_control_length; - u8 PM_timer_length; - u8 GPE0_length; - u8 GPE1_length; - u8 GPE1_base; - u8 C_state_control; - u16 worst_C2_latency; - u16 worst_C3_latency; - u16 flush_size; - u16 flush_stride; - u8 duty_offset; - u8 duty_width; - u8 day_alarm; - u8 month_alarm; - u8 century; - u16 boot_architecture_flags; // Reserved in 1.0 - u8 reserved2; - struct fadt_flags flags; - struct address_structure reset_reg; - u8 reset_value; - u8 reserved3[3]; - u64 x_firmware_control; // Reserved in 1.0 - u64 x_dsdt; // Reserved in 1.0 - struct address_structure x_PM1a_event_block; - struct address_structure x_PM1b_event_block; - struct address_structure x_PM1a_control_block; - struct address_structure x_PM1b_control_block; - struct address_structure x_PM2_control_block; - struct address_structure x_PM_timer_block; - struct address_structure x_GPE0_block; - struct address_structure x_GPE1_block; -}; - -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 madt { - struct sdt_header header; - u32 address; - u32 flags; - // Interrupt devices... -}; - -struct rsdt *rsdt; -struct fadt *fadt; -struct hpet *hpet; -struct madt *madt; - -#endif
\ No newline at end of file |