2020-03-26 03:37:56 +03:00
|
|
|
|
#ifndef __LIB__ACPI_H__
|
|
|
|
|
#define __LIB__ACPI_H__
|
|
|
|
|
|
2020-09-17 13:06:35 +03:00
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stddef.h>
|
2022-07-01 16:04:57 +03:00
|
|
|
|
#include <sys/cpu.h>
|
2020-09-17 13:06:35 +03:00
|
|
|
|
|
2022-07-01 16:04:57 +03:00
|
|
|
|
#define EBDA (ebda_get())
|
|
|
|
|
|
2022-09-02 03:29:12 +03:00
|
|
|
|
#if defined (BIOS)
|
2022-07-01 16:04:57 +03:00
|
|
|
|
static inline uintptr_t ebda_get(void) {
|
|
|
|
|
uintptr_t ebda = (uintptr_t)mminw(0x40e) << 4;
|
|
|
|
|
|
|
|
|
|
// Sanity checks
|
|
|
|
|
if (ebda < 0x80000 || ebda >= 0xa0000) {
|
|
|
|
|
ebda = 0x80000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ebda;
|
|
|
|
|
}
|
2022-08-18 18:32:54 +03:00
|
|
|
|
#endif
|
2020-09-17 13:06:35 +03:00
|
|
|
|
|
|
|
|
|
struct sdt {
|
|
|
|
|
char signature[4];
|
|
|
|
|
uint32_t length;
|
|
|
|
|
uint8_t rev;
|
|
|
|
|
uint8_t checksum;
|
|
|
|
|
char oem_id[6];
|
|
|
|
|
char oem_table_id[8];
|
|
|
|
|
uint32_t oem_rev;
|
2021-08-20 02:13:20 +03:00
|
|
|
|
char creator_id[4];
|
2020-09-17 13:06:35 +03:00
|
|
|
|
uint32_t creator_rev;
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
|
|
struct rsdp {
|
|
|
|
|
char signature[8];
|
|
|
|
|
uint8_t checksum;
|
|
|
|
|
char oem_id[6];
|
|
|
|
|
uint8_t rev;
|
|
|
|
|
uint32_t rsdt_addr;
|
2021-10-08 04:52:22 +03:00
|
|
|
|
// Revision 2 only after this comment
|
2020-09-17 13:06:35 +03:00
|
|
|
|
uint32_t length;
|
|
|
|
|
uint64_t xsdt_addr;
|
|
|
|
|
uint8_t ext_checksum;
|
|
|
|
|
uint8_t reserved[3];
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
|
|
struct rsdt {
|
2021-05-28 17:05:42 +03:00
|
|
|
|
struct sdt header;
|
2020-09-17 15:37:22 +03:00
|
|
|
|
char ptrs_start[];
|
2020-09-17 13:06:35 +03:00
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
2021-10-08 04:52:22 +03:00
|
|
|
|
struct smbios_entry_point_32 {
|
|
|
|
|
char anchor_str[4];
|
|
|
|
|
/// This value summed with all the values of the table.
|
|
|
|
|
uint8_t checksum;
|
|
|
|
|
/// Length of the entry point table.
|
|
|
|
|
uint8_t length;
|
|
|
|
|
/// Major version of SMBIOS.
|
|
|
|
|
uint8_t major_version;
|
|
|
|
|
/// Minor version of SMBIOS.
|
|
|
|
|
uint8_t minor_version;
|
|
|
|
|
/// Size of the largest SMBIOS structure, in bytes, and encompasses the
|
|
|
|
|
/// structure’s formatted area and text strings
|
|
|
|
|
uint16_t max_structure_size;
|
|
|
|
|
uint8_t entry_point_revision;
|
|
|
|
|
char formatted_area[5];
|
|
|
|
|
|
|
|
|
|
char intermediate_anchor_str[5];
|
2022-01-26 05:58:28 +03:00
|
|
|
|
/// Checksum for values from intermediate anchor str to the
|
2021-10-08 04:52:22 +03:00
|
|
|
|
/// end of table.
|
|
|
|
|
uint8_t intermediate_checksum;
|
|
|
|
|
/// Total length of SMBIOS Structure Table, pointed to by the structure
|
|
|
|
|
/// table address, in bytes.
|
|
|
|
|
uint16_t table_length;
|
|
|
|
|
/// 32-bit physical starting address of the read-only SMBIOS Structure
|
|
|
|
|
/// Table.
|
|
|
|
|
uint32_t table_address;
|
|
|
|
|
/// Total number of structures present in the SMBIOS Structure Table.
|
|
|
|
|
uint16_t number_of_structures;
|
|
|
|
|
/// Indicates compliance with a revision of this specification.
|
|
|
|
|
uint8_t bcd_revision;
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
|
|
struct smbios_entry_point_64 {
|
|
|
|
|
char anchor_str[5];
|
|
|
|
|
/// This value summed with all the values of the table.
|
|
|
|
|
uint8_t checksum;
|
|
|
|
|
/// Length of the entry point table.
|
|
|
|
|
uint8_t length;
|
|
|
|
|
/// Major version of SMBIOS.
|
|
|
|
|
uint8_t major_version;
|
|
|
|
|
/// Minor version of SMBIOS.
|
|
|
|
|
uint8_t minor_version;
|
|
|
|
|
uint8_t docrev;
|
|
|
|
|
uint8_t entry_point_revision;
|
|
|
|
|
uint8_t reserved;
|
|
|
|
|
/// Size of the largest SMBIOS structure, in bytes, and encompasses the
|
|
|
|
|
/// structure’s formatted area and text strings
|
|
|
|
|
uint16_t max_structure_size;
|
|
|
|
|
/// 64-bit physical starting address of the read-only SMBIOS Structure
|
|
|
|
|
/// Table.
|
|
|
|
|
uint64_t table_address;
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
2023-09-13 17:14:40 +03:00
|
|
|
|
struct madt {
|
|
|
|
|
struct sdt header;
|
|
|
|
|
uint32_t local_controller_addr;
|
|
|
|
|
uint32_t flags;
|
|
|
|
|
char madt_entries_begin[];
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
|
|
struct madt_header {
|
|
|
|
|
uint8_t type;
|
|
|
|
|
uint8_t length;
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
|
|
struct madt_lapic {
|
|
|
|
|
struct madt_header header;
|
|
|
|
|
uint8_t acpi_processor_uid;
|
|
|
|
|
uint8_t lapic_id;
|
|
|
|
|
uint32_t flags;
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
|
|
struct madt_x2apic {
|
|
|
|
|
struct madt_header header;
|
|
|
|
|
uint8_t reserved[2];
|
|
|
|
|
uint32_t x2apic_id;
|
|
|
|
|
uint32_t flags;
|
|
|
|
|
uint32_t acpi_processor_uid;
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
2023-09-13 18:18:09 +03:00
|
|
|
|
struct madt_io_apic {
|
|
|
|
|
uint8_t type;
|
|
|
|
|
uint8_t length;
|
|
|
|
|
uint8_t apic_id;
|
|
|
|
|
uint8_t reserved;
|
|
|
|
|
uint32_t address;
|
|
|
|
|
uint32_t gsib;
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
2023-09-13 17:14:40 +03:00
|
|
|
|
struct madt_gicc {
|
|
|
|
|
struct madt_header header;
|
|
|
|
|
uint8_t reserved1[2];
|
|
|
|
|
uint32_t iface_no;
|
|
|
|
|
uint32_t acpi_uid;
|
|
|
|
|
uint32_t flags;
|
|
|
|
|
uint32_t parking_ver;
|
|
|
|
|
uint32_t perf_gsiv;
|
|
|
|
|
uint64_t parking_addr;
|
|
|
|
|
uint64_t gicc_base_addr;
|
|
|
|
|
uint64_t gicv_base_addr;
|
|
|
|
|
uint64_t gich_base_addr;
|
|
|
|
|
uint32_t vgic_maint_gsiv;
|
|
|
|
|
uint64_t gicr_base_addr;
|
|
|
|
|
uint64_t mpidr;
|
|
|
|
|
uint8_t power_eff_class;
|
|
|
|
|
uint8_t reserved2;
|
|
|
|
|
uint16_t spe_overflow_gsiv;
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
|
|
// Reference: https://github.com/riscv-non-isa/riscv-acpi/issues/15
|
|
|
|
|
struct madt_riscv_intc {
|
|
|
|
|
struct madt_header header;
|
|
|
|
|
uint8_t version;
|
|
|
|
|
uint8_t reserved;
|
|
|
|
|
uint32_t flags;
|
|
|
|
|
uint64_t hartid;
|
|
|
|
|
uint32_t acpi_processor_uid;
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
|
|
#define MADT_RISCV_INTC_ENABLED ((uint32_t)1 << 0)
|
|
|
|
|
#define MADT_RISCV_INTC_ONLINE_CAPABLE ((uint32_t)1 << 1)
|
|
|
|
|
|
2020-09-17 13:06:35 +03:00
|
|
|
|
uint8_t acpi_checksum(void *ptr, size_t size);
|
|
|
|
|
void *acpi_get_rsdp(void);
|
2021-10-05 04:07:52 +03:00
|
|
|
|
|
|
|
|
|
void *acpi_get_rsdp_v1(void);
|
|
|
|
|
void *acpi_get_rsdp_v2(void);
|
|
|
|
|
|
2020-09-17 15:37:22 +03:00
|
|
|
|
void *acpi_get_table(const char *signature, int index);
|
2021-04-28 21:15:24 +03:00
|
|
|
|
void acpi_get_smbios(void **smbios32, void **smbios64);
|
2020-03-26 03:37:56 +03:00
|
|
|
|
|
|
|
|
|
#endif
|