2023-02-09 19:09:07 +00:00
|
|
|
#ifndef ARCH_ACPI_H_
|
|
|
|
|
#define ARCH_ACPI_H_
|
|
|
|
|
|
|
|
|
|
#include <socks/compiler.h>
|
|
|
|
|
#include <socks/status.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2023-03-20 20:41:39 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-02-09 21:39:20 +00:00
|
|
|
#define ACPI_MADT_LAPIC 0x00
|
|
|
|
|
#define ACPI_MADT_IOAPIC 0x01
|
2023-03-24 14:21:02 +00:00
|
|
|
#define ACPI_MADT_IRQSRC_OVERRIDE 0x02
|
2023-02-09 21:39:20 +00:00
|
|
|
#define ACPI_MADT_LAPIC_OVERRIDE 0x05
|
|
|
|
|
|
2023-02-09 19:09:07 +00:00
|
|
|
#define ACPI_SIG_RSDP 0x2052545020445352ULL
|
|
|
|
|
#define ACPI_SIG_FADT 0x50434146
|
2023-02-09 21:39:20 +00:00
|
|
|
#define ACPI_SIG_MADT 0x43495041
|
2023-02-09 19:09:07 +00:00
|
|
|
|
2023-03-19 20:36:36 +00:00
|
|
|
#define AP_TRAMPOLINE_PADDR 0x8000
|
|
|
|
|
#define LAPIC_IPI_STATUS_REG 0x0280
|
|
|
|
|
#define LAPIC_IPI_DEST_REG 0x0310
|
|
|
|
|
#define LAPIC_IPI_ICR_REG 0x0300
|
|
|
|
|
|
2023-02-09 19:09:07 +00:00
|
|
|
struct acpi_rsdp_10 {
|
|
|
|
|
char r_sig[8];
|
|
|
|
|
uint8_t r_chksum;
|
|
|
|
|
char r_oem[6];
|
|
|
|
|
uint8_t r_revision;
|
|
|
|
|
uint32_t r_rsdt_ptr;
|
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
|
|
struct acpi_rsdp_20 {
|
|
|
|
|
struct acpi_rsdp_10 r_base;
|
|
|
|
|
|
|
|
|
|
uint32_t r_length;
|
|
|
|
|
uint64_t r_xsdt_ptr;
|
|
|
|
|
uint8_t r_chksum_ext;
|
|
|
|
|
uint8_t r_reserved[3];
|
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
|
|
struct acpi_rsdp {
|
|
|
|
|
union {
|
|
|
|
|
struct acpi_rsdp_10 rsdp_10;
|
|
|
|
|
struct acpi_rsdp_20 rsdp_20;
|
|
|
|
|
};
|
|
|
|
|
} __packed;
|
2023-03-18 19:35:00 +00:00
|
|
|
|
2023-02-09 19:09:07 +00:00
|
|
|
struct acpi_sdt {
|
|
|
|
|
char s_sig[4];
|
|
|
|
|
uint32_t s_length;
|
|
|
|
|
uint8_t s_revision;
|
|
|
|
|
uint8_t s_chksum;
|
|
|
|
|
char s_oem[6];
|
|
|
|
|
char s_oem_table[8];
|
|
|
|
|
uint32_t s_oem_revision;
|
|
|
|
|
uint32_t s_creator;
|
|
|
|
|
uint32_t s_creator_revision;
|
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
|
|
struct acpi_rsdt {
|
|
|
|
|
struct acpi_sdt r_header;
|
2023-03-20 20:41:39 +00:00
|
|
|
uint32_t r_tables[1];
|
2023-02-09 19:09:07 +00:00
|
|
|
} __packed;
|
|
|
|
|
|
|
|
|
|
struct acpi_xsdt {
|
|
|
|
|
struct acpi_sdt x_header;
|
2023-03-20 20:41:39 +00:00
|
|
|
uint64_t x_tables[1];
|
2023-02-09 19:09:07 +00:00
|
|
|
} __packed;
|
|
|
|
|
|
2023-02-09 21:39:20 +00:00
|
|
|
struct acpi_madt {
|
|
|
|
|
struct acpi_sdt m_base;
|
|
|
|
|
uint32_t m_lapic_ptr;
|
|
|
|
|
uint32_t m_flags;
|
|
|
|
|
} __packed;
|
|
|
|
|
|
2023-03-19 20:36:36 +00:00
|
|
|
struct acpi_madt_record {
|
|
|
|
|
uint8_t r_type;
|
|
|
|
|
uint8_t r_length;
|
|
|
|
|
} __packed;
|
|
|
|
|
|
2023-03-24 14:21:02 +00:00
|
|
|
struct acpi_madt_ioapic {
|
|
|
|
|
uint8_t io_apic_id;
|
|
|
|
|
uint8_t io_reserved;
|
|
|
|
|
uint32_t io_address;
|
|
|
|
|
uint32_t io_intbase;
|
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
|
|
struct acpi_madt_irqsrc_override {
|
|
|
|
|
uint8_t irq_bus;
|
|
|
|
|
/* the irq vector as delivered from the APIC to the CPU */
|
|
|
|
|
uint8_t irq_destvec;
|
|
|
|
|
/* the irq vector as delivered from the hardware to the APIC */
|
|
|
|
|
uint32_t irq_srcvec;
|
|
|
|
|
uint16_t irq_flags;
|
|
|
|
|
} __packed;
|
|
|
|
|
|
2023-03-19 20:36:36 +00:00
|
|
|
struct lapic_record {
|
|
|
|
|
uint8_t l_cpu_id;
|
|
|
|
|
uint8_t l_apic_id;
|
|
|
|
|
uint32_t l_flags;
|
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
|
|
struct lapic_override_record {
|
|
|
|
|
uint16_t l_reserved;
|
|
|
|
|
uint64_t l_lapic_ptr;
|
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
|
|
|
2023-02-09 19:09:07 +00:00
|
|
|
extern kern_status_t acpi_init(void);
|
2023-03-18 19:35:00 +00:00
|
|
|
extern kern_status_t acpi_scan_cpu_topology(void);
|
2023-02-09 19:09:07 +00:00
|
|
|
|
2023-05-03 19:27:39 +01:00
|
|
|
extern kern_status_t ap_apic_init(void);
|
2023-03-19 20:36:36 +00:00
|
|
|
extern kern_status_t apic_init(void);
|
|
|
|
|
extern kern_status_t smp_init(void);
|
|
|
|
|
|
2023-02-09 19:09:07 +00:00
|
|
|
extern struct acpi_sdt *acpi_find_sdt(uint32_t sig);
|
|
|
|
|
|
2023-03-24 14:21:02 +00:00
|
|
|
extern void irq_ack(unsigned int vec);
|
|
|
|
|
|
2023-03-20 20:41:39 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-02-09 19:09:07 +00:00
|
|
|
#endif
|