diff --git a/kernel/inc/drivers/acpi/acpi.h b/kernel/inc/drivers/acpi/acpi.h index 84f6ff5..6a0042c 100644 --- a/kernel/inc/drivers/acpi/acpi.h +++ b/kernel/inc/drivers/acpi/acpi.h @@ -18,6 +18,14 @@ typedef struct { uint32_t creator_revision; } __attribute__((packed)) acpi_sdt_header_T; +typedef struct { + uint8_t address_space; + uint8_t bit_width; + uint8_t bit_offset; + uint8_t access_size; + uint64_t address; +} __attribute__((packed)) acpi_gas_T; + void acpi_init (boot_info_T* boot_info); acpi_sdt_header_T* acpi_find_table (acpi_sdt_header_T* xsdt, string_t table_id); diff --git a/kernel/inc/drivers/acpi/fadt.h b/kernel/inc/drivers/acpi/fadt.h new file mode 100644 index 0000000..e3e74fb --- /dev/null +++ b/kernel/inc/drivers/acpi/fadt.h @@ -0,0 +1,68 @@ +// This file is part of noxos and licensed under the MIT open source license + +#ifndef NOX_FADT_H +#define NOX_FADT_H + +#include "drivers/acpi/acpi.h" + +typedef struct { + acpi_sdt_header_T header; + uint32_t firmware_control; + uint32_t dsdt; + uint8_t reserved; + uint8_t preferred_power_management_profile; + uint16_t sci_interrupt; + uint32_t smi_command_port; + uint8_t apci_enable; + uint8_t apci_disable; + uint8_t s4_bios_request; + 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 c_state_control; + uint16_t c2_worst_latency; + uint16_t c3_worst_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 ia_boot_architecture_flags; + uint8_t reserved_2; + uint32_t flags; + acpi_gas_T reset_register; + uint8_t reset_value; + uint8_t reserved_3[3]; + uint64_t x_firmware_control; + uint64_t x_dsdt; + acpi_gas_T x_pm1a_event_block; + acpi_gas_T x_pm1b_event_block; + acpi_gas_T x_pm1a_control_block; + acpi_gas_T x_pm1b_control_block; + acpi_gas_T x_pm2_control_block; + acpi_gas_T x_pm_timer_block; + acpi_gas_T x_gpe0_block; + acpi_gas_T x_gpe1_block; + acpi_gas_T sleep_control_register; + acpi_gas_T sleep_status_register; + uint64_t hypervisor_vendor_identity; +} __attribute__((packed)) acpi_fadt_T; + +extern acpi_fadt_T* g_acpi_table_fadt; + +#endif //NOX_FADT_H diff --git a/kernel/src/drivers/acpi/acpi.c b/kernel/src/drivers/acpi/acpi.c index 8b206f1..57de2ea 100644 --- a/kernel/src/drivers/acpi/acpi.c +++ b/kernel/src/drivers/acpi/acpi.c @@ -2,8 +2,12 @@ #include "drivers/acpi/acpi.h" #include "drivers/acpi/rsdp.h" +#include "drivers/acpi/fadt.h" #include "utils/logger.h" #include "utils/memory.h" +#include "utils/panic.h" + +acpi_fadt_T* g_acpi_table_fadt; void acpi_init(boot_info_T* boot_info) { log(LOG_INFO, "Initializing ACPI - RSDP: 0x%x", boot_info->rsdp); @@ -22,8 +26,12 @@ void acpi_init(boot_info_T* boot_info) { if (!rsdp_descriptor_v2_verify(boot_info->rsdp)) { log(LOG_WARNING, " RSDP header verification failed"); } + g_acpi_table_fadt = (acpi_fadt_T*)acpi_find_table((acpi_sdt_header_T*)((rsdp_descriptor_v2_T*)boot_info->rsdp)->xsdt_address, "FACP"); - acpi_find_table(((rsdp_descriptor_v2_T*)boot_info->rsdp)->xsdt_address, "FACP"); + if (g_acpi_table_fadt == NULL) { + panic(NULL, " FADT table not found"); + } + log(LOG_INFO, " found FADT at address 0x%x", g_acpi_table_fadt); break; } default: {