vaseboot/include/VasEBoot/acpi.h

304 lines
9.2 KiB
C

/*
* VAS_EBOOT -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* VAS_EBOOT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VAS_EBOOT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VAS_EBOOT. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VAS_EBOOT_ACPI_HEADER
#define VAS_EBOOT_ACPI_HEADER 1
#ifndef VAS_EBOOT_DSDT_TEST
#include <VasEBoot/types.h>
#include <VasEBoot/err.h>
#else
#define VAS_EBOOT_PACKED __attribute__ ((packed))
#endif
#define VAS_EBOOT_RSDP_SIGNATURE "RSD PTR "
#define VAS_EBOOT_RSDP_SIGNATURE_SIZE 8
struct VasEBoot_acpi_rsdp_v10
{
VasEBoot_uint8_t signature[VAS_EBOOT_RSDP_SIGNATURE_SIZE];
VasEBoot_uint8_t checksum;
VasEBoot_uint8_t oemid[6];
VasEBoot_uint8_t revision;
VasEBoot_uint32_t rsdt_addr;
} VAS_EBOOT_PACKED;
struct VasEBoot_acpi_rsdp_v20
{
struct VasEBoot_acpi_rsdp_v10 rsdpv1;
VasEBoot_uint32_t length;
VasEBoot_uint64_t xsdt_addr;
VasEBoot_uint8_t checksum;
VasEBoot_uint8_t reserved[3];
} VAS_EBOOT_PACKED;
struct VasEBoot_acpi_table_header
{
VasEBoot_uint8_t signature[4];
VasEBoot_uint32_t length;
VasEBoot_uint8_t revision;
VasEBoot_uint8_t checksum;
VasEBoot_uint8_t oemid[6];
VasEBoot_uint8_t oemtable[8];
VasEBoot_uint32_t oemrev;
VasEBoot_uint8_t creator_id[4];
VasEBoot_uint32_t creator_rev;
} VAS_EBOOT_PACKED;
#define VAS_EBOOT_ACPI_FADT_SIGNATURE "FACP"
struct VasEBoot_acpi_fadt
{
struct VasEBoot_acpi_table_header hdr;
VasEBoot_uint32_t facs_addr;
VasEBoot_uint32_t dsdt_addr;
VasEBoot_uint8_t somefields1[20];
VasEBoot_uint32_t pm1a;
VasEBoot_uint8_t somefields2[8];
VasEBoot_uint32_t pmtimer;
VasEBoot_uint8_t somefields3[32];
VasEBoot_uint32_t flags;
VasEBoot_uint8_t somefields4[16];
VasEBoot_uint64_t facs_xaddr;
VasEBoot_uint64_t dsdt_xaddr;
VasEBoot_uint8_t somefields5[96];
} VAS_EBOOT_PACKED;
#define VAS_EBOOT_ACPI_MADT_SIGNATURE "APIC"
/* Note: here VAS_EBOOT_PACKED is not needed because we have VasEBoot_uint8_t only. */
struct VasEBoot_acpi_madt_entry_header
{
VasEBoot_uint8_t type;
VasEBoot_uint8_t len;
};
struct VasEBoot_acpi_madt
{
struct VasEBoot_acpi_table_header hdr;
VasEBoot_uint32_t lapic_addr;
VasEBoot_uint32_t flags;
struct VasEBoot_acpi_madt_entry_header entries[0];
} VAS_EBOOT_PACKED;
enum
{
VAS_EBOOT_ACPI_MADT_ENTRY_TYPE_LAPIC = 0,
VAS_EBOOT_ACPI_MADT_ENTRY_TYPE_IOAPIC = 1,
VAS_EBOOT_ACPI_MADT_ENTRY_TYPE_INTERRUPT_OVERRIDE = 2,
VAS_EBOOT_ACPI_MADT_ENTRY_TYPE_LAPIC_NMI = 4,
VAS_EBOOT_ACPI_MADT_ENTRY_TYPE_SAPIC = 6,
VAS_EBOOT_ACPI_MADT_ENTRY_TYPE_LSAPIC = 7,
VAS_EBOOT_ACPI_MADT_ENTRY_TYPE_PLATFORM_INT_SOURCE = 8
};
struct VasEBoot_acpi_madt_entry_lapic
{
struct VasEBoot_acpi_madt_entry_header hdr;
VasEBoot_uint8_t acpiid;
VasEBoot_uint8_t apicid;
VasEBoot_uint32_t flags;
} VAS_EBOOT_PACKED;
struct VasEBoot_acpi_madt_entry_ioapic
{
struct VasEBoot_acpi_madt_entry_header hdr;
VasEBoot_uint8_t id;
VasEBoot_uint8_t pad;
VasEBoot_uint32_t address;
VasEBoot_uint32_t global_sys_interrupt;
} VAS_EBOOT_PACKED;
struct VasEBoot_acpi_madt_entry_interrupt_override
{
struct VasEBoot_acpi_madt_entry_header hdr;
VasEBoot_uint8_t bus;
VasEBoot_uint8_t source;
VasEBoot_uint32_t global_sys_interrupt;
VasEBoot_uint16_t flags;
} VAS_EBOOT_PACKED;
struct VasEBoot_acpi_madt_entry_lapic_nmi
{
struct VasEBoot_acpi_madt_entry_header hdr;
VasEBoot_uint8_t acpiid;
VasEBoot_uint16_t flags;
VasEBoot_uint8_t lint;
} VAS_EBOOT_PACKED;
struct VasEBoot_acpi_madt_entry_sapic
{
struct VasEBoot_acpi_madt_entry_header hdr;
VasEBoot_uint8_t id;
VasEBoot_uint8_t pad;
VasEBoot_uint32_t global_sys_interrupt_base;
VasEBoot_uint64_t addr;
} VAS_EBOOT_PACKED;
struct VasEBoot_acpi_madt_entry_lsapic
{
struct VasEBoot_acpi_madt_entry_header hdr;
VasEBoot_uint8_t cpu_id;
VasEBoot_uint8_t id;
VasEBoot_uint8_t eid;
VasEBoot_uint8_t pad[3];
VasEBoot_uint32_t flags;
VasEBoot_uint32_t cpu_uid;
VasEBoot_uint8_t cpu_uid_str[0];
} VAS_EBOOT_PACKED;
struct VasEBoot_acpi_madt_entry_platform_int_source
{
struct VasEBoot_acpi_madt_entry_header hdr;
VasEBoot_uint16_t flags;
VasEBoot_uint8_t inttype;
VasEBoot_uint8_t cpu_id;
VasEBoot_uint8_t cpu_eid;
VasEBoot_uint8_t sapic_vector;
VasEBoot_uint32_t global_sys_int;
VasEBoot_uint32_t src_flags;
} VAS_EBOOT_PACKED;
enum
{
VAS_EBOOT_ACPI_MADT_ENTRY_SAPIC_FLAGS_ENABLED = 1
};
struct VasEBoot_acpi_genaddr {
VasEBoot_uint8_t space_id;
#define VAS_EBOOT_ACPI_GENADDR_MEM_SPACE 0x00
#define VAS_EBOOT_ACPI_GENADDR_IO_SPACE 0x01
VasEBoot_uint8_t bit_width;
VasEBoot_uint8_t bit_offset;
VasEBoot_uint8_t access_size;
#define VAS_EBOOT_ACPI_GENADDR_SIZE_LGCY 0x00
#define VAS_EBOOT_ACPI_GENADDR_SIZE_BYTE 0x01
#define VAS_EBOOT_ACPI_GENADDR_SIZE_WORD 0x02
#define VAS_EBOOT_ACPI_GENADDR_SIZE_DWORD 0x03
#define VAS_EBOOT_ACPI_GENADDR_SIZE_QWORD 0x04
VasEBoot_uint64_t addr;
} VAS_EBOOT_PACKED;
#define VAS_EBOOT_ACPI_SPCR_SIGNATURE "SPCR"
struct VasEBoot_acpi_spcr {
struct VasEBoot_acpi_table_header hdr;
VasEBoot_uint8_t intf_type;
#define VAS_EBOOT_ACPI_SPCR_INTF_TYPE_16550 0x00
#define VAS_EBOOT_ACPI_SPCR_INTF_TYPE_16550_DBGP 0x01
#define VAS_EBOOT_ACPI_SPCR_INTF_TYPE_16550_DBG2 0x12
VasEBoot_uint8_t reserved_0[3];
struct VasEBoot_acpi_genaddr base_addr;
VasEBoot_uint8_t interrupt_type;
VasEBoot_uint8_t irq;
VasEBoot_uint32_t gsi;
VasEBoot_uint8_t baud_rate;
#define VAS_EBOOT_ACPI_SPCR_BAUD_CURRENT 0x00
#define VAS_EBOOT_ACPI_SPCR_BAUD_9600 0x03
#define VAS_EBOOT_ACPI_SPCR_BAUD_19200 0x04
#define VAS_EBOOT_ACPI_SPCR_BAUD_57600 0x06
#define VAS_EBOOT_ACPI_SPCR_BAUD_115200 0x07
VasEBoot_uint8_t parity;
VasEBoot_uint8_t stop_bits;
VasEBoot_uint8_t flow_control;
#define VAS_EBOOT_ACPI_SPCR_FC_DCD_TX (1 << 0)
#define VAS_EBOOT_ACPI_SPCR_FC_RTSCTS (1 << 1)
#define VAS_EBOOT_ACPI_SPCR_FC_XONXOFF (1 << 2)
VasEBoot_uint8_t terminal_type;
VasEBoot_uint8_t language;
VasEBoot_uint16_t pci_device_id;
VasEBoot_uint16_t pci_vendor_id;
VasEBoot_uint8_t pci_bus;
VasEBoot_uint8_t pci_device;
VasEBoot_uint8_t pci_function;
VasEBoot_uint32_t pci_flags;
VasEBoot_uint8_t pci_segment;
VasEBoot_uint32_t reserved_1;
} VAS_EBOOT_PACKED;
#ifndef VAS_EBOOT_DSDT_TEST
struct VasEBoot_acpi_rsdp_v10 *VasEBoot_acpi_get_rsdpv1 (void);
struct VasEBoot_acpi_rsdp_v20 *VasEBoot_acpi_get_rsdpv2 (void);
struct VasEBoot_acpi_rsdp_v10 *EXPORT_FUNC(VasEBoot_machine_acpi_get_rsdpv1) (void);
struct VasEBoot_acpi_rsdp_v20 *EXPORT_FUNC(VasEBoot_machine_acpi_get_rsdpv2) (void);
VasEBoot_uint8_t EXPORT_FUNC(VasEBoot_byte_checksum) (void *base, VasEBoot_size_t size);
VasEBoot_err_t VasEBoot_acpi_create_ebda (void);
void VasEBoot_acpi_halt (void);
#endif
#define VAS_EBOOT_ACPI_SLP_EN (1 << 13)
#define VAS_EBOOT_ACPI_SLP_TYP_OFFSET 10
enum
{
VAS_EBOOT_ACPI_OPCODE_ZERO = 0, VAS_EBOOT_ACPI_OPCODE_ONE = 1,
VAS_EBOOT_ACPI_OPCODE_NAME = 8, VAS_EBOOT_ACPI_OPCODE_ALIAS = 0x06,
VAS_EBOOT_ACPI_OPCODE_BYTE_CONST = 0x0a,
VAS_EBOOT_ACPI_OPCODE_WORD_CONST = 0x0b,
VAS_EBOOT_ACPI_OPCODE_DWORD_CONST = 0x0c,
VAS_EBOOT_ACPI_OPCODE_STRING_CONST = 0x0d,
VAS_EBOOT_ACPI_OPCODE_SCOPE = 0x10,
VAS_EBOOT_ACPI_OPCODE_BUFFER = 0x11,
VAS_EBOOT_ACPI_OPCODE_PACKAGE = 0x12,
VAS_EBOOT_ACPI_OPCODE_METHOD = 0x14, VAS_EBOOT_ACPI_OPCODE_EXTOP = 0x5b,
VAS_EBOOT_ACPI_OPCODE_ADD = 0x72,
VAS_EBOOT_ACPI_OPCODE_CONCAT = 0x73,
VAS_EBOOT_ACPI_OPCODE_SUBTRACT = 0x74,
VAS_EBOOT_ACPI_OPCODE_MULTIPLY = 0x77,
VAS_EBOOT_ACPI_OPCODE_DIVIDE = 0x78,
VAS_EBOOT_ACPI_OPCODE_LSHIFT = 0x79,
VAS_EBOOT_ACPI_OPCODE_RSHIFT = 0x7a,
VAS_EBOOT_ACPI_OPCODE_AND = 0x7b,
VAS_EBOOT_ACPI_OPCODE_NAND = 0x7c,
VAS_EBOOT_ACPI_OPCODE_OR = 0x7d,
VAS_EBOOT_ACPI_OPCODE_NOR = 0x7e,
VAS_EBOOT_ACPI_OPCODE_XOR = 0x7f,
VAS_EBOOT_ACPI_OPCODE_CONCATRES = 0x84,
VAS_EBOOT_ACPI_OPCODE_MOD = 0x85,
VAS_EBOOT_ACPI_OPCODE_INDEX = 0x88,
VAS_EBOOT_ACPI_OPCODE_CREATE_DWORD_FIELD = 0x8a,
VAS_EBOOT_ACPI_OPCODE_CREATE_WORD_FIELD = 0x8b,
VAS_EBOOT_ACPI_OPCODE_CREATE_BYTE_FIELD = 0x8c,
VAS_EBOOT_ACPI_OPCODE_TOSTRING = 0x9c,
VAS_EBOOT_ACPI_OPCODE_IF = 0xa0, VAS_EBOOT_ACPI_OPCODE_ONES = 0xff
};
enum
{
VAS_EBOOT_ACPI_EXTOPCODE_MUTEX = 0x01,
VAS_EBOOT_ACPI_EXTOPCODE_EVENT_OP = 0x02,
VAS_EBOOT_ACPI_EXTOPCODE_OPERATION_REGION = 0x80,
VAS_EBOOT_ACPI_EXTOPCODE_FIELD_OP = 0x81,
VAS_EBOOT_ACPI_EXTOPCODE_DEVICE_OP = 0x82,
VAS_EBOOT_ACPI_EXTOPCODE_PROCESSOR_OP = 0x83,
VAS_EBOOT_ACPI_EXTOPCODE_POWER_RES_OP = 0x84,
VAS_EBOOT_ACPI_EXTOPCODE_THERMAL_ZONE_OP = 0x85,
VAS_EBOOT_ACPI_EXTOPCODE_INDEX_FIELD_OP = 0x86,
VAS_EBOOT_ACPI_EXTOPCODE_BANK_FIELD_OP = 0x87,
};
struct VasEBoot_acpi_fadt *
EXPORT_FUNC(VasEBoot_acpi_find_fadt) (void);
void *
EXPORT_FUNC(VasEBoot_acpi_find_table) (const char *sig);
#endif /* ! VAS_EBOOT_ACPI_HEADER */