feat: added basic ACPI support using LAI
This commit is contained in:
14
include/myke/acpi/acpi.h
Normal file
14
include/myke/acpi/acpi.h
Normal file
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by rick on 22-08-21.
|
||||
//
|
||||
|
||||
#ifndef NEW_KERNEL_ACPI_H
|
||||
#define NEW_KERNEL_ACPI_H
|
||||
|
||||
void acpi_parse();
|
||||
|
||||
void acpi_init();
|
||||
|
||||
void* acpi_find_table_by_name(const char* name, int skip);
|
||||
|
||||
#endif //NEW_KERNEL_ACPI_H
|
||||
256
include/myke/acpi/structures.h
Normal file
256
include/myke/acpi/structures.h
Normal file
@@ -0,0 +1,256 @@
|
||||
//
|
||||
// Created by rick on 22-08-21.
|
||||
//
|
||||
|
||||
#ifndef NEW_KERNEL_STRUCTURES_H
|
||||
#define NEW_KERNEL_STRUCTURES_H
|
||||
|
||||
#include <attributes.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define RDSP_SIGNATURE_LENGTH 8
|
||||
#define RSDP_SIGNATURE "RSD PTR "
|
||||
|
||||
enum generic_address_structure_address_space {
|
||||
system_memory = 0,
|
||||
system_io = 1,
|
||||
pci_config_space = 2,
|
||||
embedded_controller = 3,
|
||||
system_management_bus = 4,
|
||||
system_cmos = 5,
|
||||
pci_device_bar = 6,
|
||||
ipmi = 7,
|
||||
gpio = 8,
|
||||
gsb = 9,
|
||||
pmc = 0x0A
|
||||
};
|
||||
|
||||
enum generic_address_structure_access_size {
|
||||
undefined = 0,
|
||||
uint8 = 1,
|
||||
uint16 = 2,
|
||||
uint32 = 3,
|
||||
uint64 = 4,
|
||||
};
|
||||
|
||||
struct generic_address_structure {
|
||||
uint8_t address_space;
|
||||
uint8_t bit_width;
|
||||
uint8_t bit_offset;
|
||||
uint8_t access_size;
|
||||
uint64_t address;
|
||||
};
|
||||
|
||||
struct acpi_rsdp_descriptor {
|
||||
char signature[8];
|
||||
uint8_t checksum;
|
||||
char oem_id[6];
|
||||
uint8_t revision;
|
||||
uint32_t rsdt_address;
|
||||
} att_packed;
|
||||
|
||||
struct acpi_rsdp_descriptor_20 {
|
||||
struct acpi_rsdp_descriptor rsdp;
|
||||
|
||||
uint32_t length;
|
||||
uint64_t xsdt_address;
|
||||
uint8_t extended_checksum;
|
||||
uint32_t: 24; // reserved
|
||||
} att_packed;
|
||||
|
||||
struct acpi_sdt_header {
|
||||
char signature[4];
|
||||
uint32_t length;
|
||||
uint8_t revision;
|
||||
uint8_t checksum;
|
||||
char oem_id[6];
|
||||
char oem_table_id[8];
|
||||
uint32_t oem_revision;
|
||||
uint32_t creator_id;
|
||||
uint32_t creator_revision;
|
||||
} att_packed;
|
||||
|
||||
struct acpi_rsdt {
|
||||
struct acpi_sdt_header header;
|
||||
uint32_t pointer_to_other_sdt[];
|
||||
} att_packed;
|
||||
|
||||
struct acpi_xsdt {
|
||||
struct acpi_sdt_header header;
|
||||
uint64_t pointer_to_other_sdt[];
|
||||
} att_packed;
|
||||
|
||||
struct acpi_fadt {
|
||||
struct acpi_sdt_header header;
|
||||
uint32_t firmware_ctrl;
|
||||
uint32_t dsdt;
|
||||
|
||||
// field used in ACPI 1.0; no longer in use, for compatibility only
|
||||
uint8_t: 8;
|
||||
|
||||
uint8_t preferred_power_management_profile;
|
||||
uint16_t sci_interrupt;
|
||||
uint32_t smi_command_port;
|
||||
uint8_t acpi_enable;
|
||||
uint8_t acpi_disable;
|
||||
uint8_t s4bios_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;
|
||||
|
||||
// reserved in ACPI 1.0; used since ACPI 2.0+
|
||||
uint16_t boot_architecture_flags;
|
||||
|
||||
uint8_t: 8;
|
||||
uint32_t flags;
|
||||
|
||||
// 12 byte structure; see below for details
|
||||
struct generic_address_structure reset_reg;
|
||||
uint8_t reset_value;
|
||||
uint16_t arm_boot_arch;
|
||||
uint8_t fadt_minor_version;
|
||||
|
||||
// 64bit pointers - Available on ACPI 2.0+
|
||||
uint64_t x_firmware_control;
|
||||
uint64_t x_dsdt;
|
||||
|
||||
struct generic_address_structure x_pm1a_event_block;
|
||||
struct generic_address_structure x_pm1b_event_block;
|
||||
struct generic_address_structure x_pm1a_control_block;
|
||||
struct generic_address_structure x_pm1b_control_block;
|
||||
struct generic_address_structure x_pm2_control_block;
|
||||
struct generic_address_structure x_pm_timer_block;
|
||||
struct generic_address_structure x_gpe0_block;
|
||||
struct generic_address_structure x_gpe1_block;
|
||||
struct generic_address_structure sleep_control_register;
|
||||
struct generic_address_structure sleep_status_register;
|
||||
uint64_t hypervisor_id;
|
||||
} att_packed;
|
||||
|
||||
#define MADT_TYPE_PROCESSOR_LOCAL_APIC 0
|
||||
#define MADT_TYPE_IO_APIC 1
|
||||
#define MADT_TYPE_IO_APIC_INTERRUPT_SOURCE_OVERRIDE 2
|
||||
#define MADT_TYPE_IO_APIC_NON_MASKABLE_INTERRUPT_SOURCE 3
|
||||
#define MADT_TYPE_LOCAL_APIC_NON_MASKABLE_INTERRUPTS 4
|
||||
#define MADT_TYPE_LOCAL_APIC_ADDRESS_OVERRIDE 5
|
||||
#define MADT_TYPE_PROCESSOR_LOCAL_X2_APIC 9
|
||||
|
||||
union madt_local_apic_flags {
|
||||
uint32_t flags_int;
|
||||
struct {
|
||||
bool processor_enabled: 1;
|
||||
bool online_capable: 1;
|
||||
} flags;
|
||||
};
|
||||
|
||||
union madt_interrupt_flags {
|
||||
uint16_t flags_int;
|
||||
struct {
|
||||
bool: 1; // 1
|
||||
bool active_low: 1; // 2
|
||||
bool: 1; // 4
|
||||
bool level_triggered: 1; // 8
|
||||
} att_packed;
|
||||
};
|
||||
|
||||
struct acpi_madt {
|
||||
struct acpi_sdt_header header;
|
||||
uint32_t local_apic_addr;
|
||||
union {
|
||||
uint32_t flags_int;
|
||||
struct {
|
||||
bool dual_8259_legacy_pics: 1;
|
||||
};
|
||||
};
|
||||
uint8_t entries[];
|
||||
} att_packed;
|
||||
|
||||
struct acpi_madt_entry_header {
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
} att_packed;
|
||||
|
||||
struct acpi_madt_local_apic { // type 0
|
||||
struct acpi_madt_entry_header header;
|
||||
uint8_t processor_id;
|
||||
uint8_t apic_id;
|
||||
union madt_local_apic_flags flags;
|
||||
} att_packed;
|
||||
|
||||
struct acpi_madt_io_apic { // type 1
|
||||
struct acpi_madt_entry_header header;
|
||||
uint8_t apic_id;
|
||||
uint8_t: 8; // reserved
|
||||
uint32_t io_apic_address;
|
||||
uint32_t global_system_interrupt_base;
|
||||
} att_packed;
|
||||
|
||||
struct acpi_madt_io_apic_interrupt_source_override { // type 2
|
||||
struct acpi_madt_entry_header header;
|
||||
uint8_t bus_source;
|
||||
uint8_t irq_source;
|
||||
uint32_t global_system_interrupt;
|
||||
union madt_interrupt_flags flags;
|
||||
} att_packed;
|
||||
|
||||
struct acpi_madt_io_apic_non_maskable_interrupt { // type 3
|
||||
struct acpi_madt_entry_header header;
|
||||
uint8_t nmi_source;
|
||||
uint8_t: 8; // reserved
|
||||
union madt_interrupt_flags flags;
|
||||
uint32_t global_system_interrupt;
|
||||
} att_packed;
|
||||
|
||||
struct acpi_madt_local_apic_non_maskable_interrupts {
|
||||
struct acpi_madt_entry_header header;
|
||||
uint8_t acpi_processor_id;
|
||||
union madt_interrupt_flags flags;
|
||||
uint8_t lint_no;
|
||||
} att_packed;
|
||||
|
||||
struct acpi_madt_local_apic_address_override {
|
||||
struct acpi_madt_entry_header header;
|
||||
uint16_t: 16; // reserved
|
||||
uint64_t physical_address_local_apic;
|
||||
} att_packed;
|
||||
|
||||
struct acpi_madt_processor_local_x2_apic {
|
||||
struct acpi_madt_entry_header header;
|
||||
uint16_t: 16; // reserved
|
||||
uint32_t processors_local_x2_apic_id;
|
||||
union madt_local_apic_flags flags;
|
||||
uint32_t acpi_id;
|
||||
} att_packed;
|
||||
|
||||
struct acpi_type {
|
||||
char name[4];
|
||||
char *description;
|
||||
|
||||
void (*handle_table)(const struct acpi_sdt_header *addr);
|
||||
};
|
||||
|
||||
#endif //NEW_KERNEL_STRUCTURES_H
|
||||
Reference in New Issue
Block a user