source: trunk/hal/x86_64/core/hal_acpi.h @ 275

Last change on this file since 275 was 275, checked in by max@…, 4 years ago

Add a SRAT parser. For some reason, QEMU does not want to enable the
memory ranges...

File size: 9.6 KB
Line 
1/*
2 * hal_acpi.h - ACPI-specific values and structures
3 *
4 * Copyright (c) 2017 Maxime Villard
5 * Inspired by ACPICA.
6 *
7 * This file is part of ALMOS-MKH.
8 *
9 * ALMOS-MKH is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2.0 of the License.
12 *
13 * ALMOS-MKH is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/*
24 * Copyright (C) 2000 - 2017, Intel Corp.
25 * All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 * 1. Redistributions of source code must retain the above copyright
31 *    notice, this list of conditions, and the following disclaimer,
32 *    without modification.
33 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
34 *    substantially similar to the "NO WARRANTY" disclaimer below
35 *    ("Disclaimer") and any redistribution must be conditioned upon
36 *    including a substantially similar Disclaimer requirement for further
37 *    binary redistribution.
38 * 3. Neither the names of the above-listed copyright holders nor the names
39 *    of any contributors may be used to endorse or promote products derived
40 *    from this software without specific prior written permission.
41 *
42 * Alternatively, this software may be distributed under the terms of the
43 * GNU General Public License ("GPL") version 2 as published by the Free
44 * Software Foundation.
45 *
46 * NO WARRANTY
47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
50 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
51 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
55 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
56 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57 * POSSIBILITY OF SUCH DAMAGES.
58 */
59
60void hal_acpi_init();
61
62#define ACPI_RSDP_ALIGN 16
63#define ACPI_RSDP_SIGNATURE     "RSD PTR "
64#define ACPI_RSDP_SIGNATURE_SIZE        8
65
66#define ACPI_OEM_ID_SIZE        6
67
68#define ACPI_NAME_SIZE  4
69
70/* Sizes for ACPI table headers */
71#define ACPI_OEM_ID_SIZE                6
72#define ACPI_OEM_TABLE_ID_SIZE  8
73
74
75/*******************************************************************************
76 * RSDP - Root System Description Pointer (Signature is "RSD PTR ")
77 *        Version 2
78 ******************************************************************************/
79
80struct acpi_table_rsdp {
81        char Signature[8];            /* ACPI signature, contains "RSD PTR " */
82        uint8_t Checksum;             /* ACPI 1.0 checksum */
83        char OemId[ACPI_OEM_ID_SIZE]; /* OEM identification */
84        uint8_t Revision;             /* Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ */
85        uint32_t RsdtPhysicalAddress; /* 32-bit physical address of the RSDT */
86        uint32_t Length;              /* Table length in bytes, including header (ACPI 2.0+) */
87        uint64_t XsdtPhysicalAddress; /* 64-bit physical address of the XSDT (ACPI 2.0+) */
88        uint8_t ExtendedChecksum;     /* Checksum of entire table (ACPI 2.0+) */
89        uint8_t Reserved[3];          /* Reserved, must be zero */
90} __packed;
91typedef struct acpi_table_rsdp  rsdp_t;
92
93/*******************************************************************************
94 * Master ACPI Table Header. This common header is used by all ACPI tables
95 * except the RSDP and FACS.
96 ******************************************************************************/
97
98struct acpi_table_header {
99        char Signature[ACPI_NAME_SIZE];          /* ASCII table signature */
100        uint32_t Length;                         /* Length of table in bytes, including this header */
101        uint8_t Revision;                        /* ACPI Specification minor version number */
102        uint8_t Checksum;                        /* To make sum of entire table == 0 */
103        char OemId[ACPI_OEM_ID_SIZE];            /* ASCII OEM identification */
104        char OemTableId[ACPI_OEM_TABLE_ID_SIZE]; /* ASCII OEM table identification */
105        uint32_t OemRevision;                    /* OEM revision number */
106        char AslCompilerId[ACPI_NAME_SIZE];      /* ASCII ASL compiler vendor ID */
107        uint32_t AslCompilerRevision;            /* ASL compiler version */
108} __packed;
109typedef struct acpi_table_header        header_t;
110
111/*******************************************************************************
112 * RSDT - Root System Description Tables
113 *        Version 1
114 ******************************************************************************/
115
116struct acpi_table_rsdt {
117        header_t Header;              /* Common ACPI table header */
118    uint32_t TableOffsetEntry[1]; /* Array of pointers to ACPI tables */
119} __packed;
120typedef struct acpi_table_rsdt  rsdt_t;
121
122/*******************************************************************************
123 * Common subtable headers
124 ******************************************************************************/
125
126struct acpi_subtable_header {
127        uint8_t Type;
128        uint8_t Length;
129} __packed;
130typedef struct acpi_subtable_header     subheader_t;
131
132/*******************************************************************************
133 * MADT - Multiple APIC Description Table
134 *        Version 3
135 ******************************************************************************/
136
137struct acpi_table_madt {
138        header_t Header;  /* Common ACPI table header */
139        uint32_t Address; /* Physical address of local APIC */
140        uint32_t Flags;
141} __packed;
142typedef struct acpi_table_madt  madt_t;
143
144/*******************************************************************************
145 * MADT structures
146 ******************************************************************************/
147
148#define ACPI_MADT_LAPIC_ENABLED 0x01
149
150enum AcpiMadtType {
151        ACPI_MADT_TYPE_LOCAL_APIC            = 0,
152        ACPI_MADT_TYPE_IO_APIC               = 1,
153        ACPI_MADT_TYPE_INTERRUPT_OVERRIDE    = 2,
154        ACPI_MADT_TYPE_NMI_SOURCE            = 3,
155        ACPI_MADT_TYPE_LOCAL_APIC_NMI        = 4,
156        ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE   = 5,
157        ACPI_MADT_TYPE_IO_SAPIC              = 6,
158        ACPI_MADT_TYPE_LOCAL_SAPIC           = 7,
159        ACPI_MADT_TYPE_INTERRUPT_SOURCE      = 8,
160        ACPI_MADT_TYPE_LOCAL_X2APIC          = 9,
161        ACPI_MADT_TYPE_LOCAL_X2APIC_NMI      = 10,
162        ACPI_MADT_TYPE_GENERIC_INTERRUPT     = 11,
163        ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR   = 12,
164        ACPI_MADT_TYPE_GENERIC_MSI_FRAME     = 13,
165        ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR = 14,
166        ACPI_MADT_TYPE_GENERIC_TRANSLATOR    = 15,
167        ACPI_MADT_TYPE_RESERVED              = 16  /* 16 and greater are reserved */
168};
169
170struct acpi_madt_local_apic {
171        subheader_t Header;
172        uint8_t ProcessorId; /* ACPI processor id */
173        uint8_t Id;          /* Processor's local APIC id */
174        uint32_t LapicFlags;
175} __packed;
176typedef struct acpi_madt_local_apic     madt_lapic_t;
177
178struct acpi_madt_local_apic_override {
179        subheader_t Header;
180        uint16_t Reserved; /* Reserved, must be zero */
181        uint64_t Address;  /* APIC physical address */
182} __packed;
183typedef struct acpi_madt_local_apic_override madt_lapic_override_t;
184
185struct acpi_madt_io_apic {
186        subheader_t Header;
187        uint8_t Id;             /* I/O APIC ID */
188        uint8_t Reserved;       /* Reserved - must be zero */
189        uint32_t Address;       /* APIC physical address */
190        uint32_t GlobalIrqBase; /* Global system interrupt where INTI lines start */
191} __packed;
192typedef struct acpi_madt_io_apic madt_ioapic_t;
193
194/*******************************************************************************
195 * SRAT - System Resource Affinity Table
196 *        Version 3
197 ******************************************************************************/
198
199struct acpi_table_srat {
200        header_t Header;        /* Common ACPI table header */
201        uint32_t TableRevision; /* Must be value '1' */
202        uint64_t Reserved;      /* Reserved, must be zero */
203};
204typedef struct acpi_table_srat  srat_t;
205
206/*******************************************************************************
207 * SRAT structures
208 ******************************************************************************/
209
210enum AcpiSratType {
211        ACPI_SRAT_TYPE_CPU_AFFINITY        = 0,
212        ACPI_SRAT_TYPE_MEMORY_AFFINITY     = 1,
213        ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY = 2,
214        ACPI_SRAT_TYPE_GICC_AFFINITY       = 3,
215        ACPI_SRAT_TYPE_RESERVED            = 4  /* 4 and greater are reserved */
216};
217
218#define ACPI_SRAT_CPU_USE_AFFINITY  (1) /* 00: Use affinity structure */
219
220struct acpi_srat_cpu_affinity {
221        subheader_t Header;
222        uint8_t ProximityDomainLo;
223        uint8_t ApicId;
224        uint32_t Flags;
225        uint8_t LocalSapicEid;
226        uint8_t ProximityDomainHi[3];
227        uint32_t ClockDomain;
228};
229typedef struct acpi_srat_cpu_affinity   srat_cpu_affinity_t;
230
231#define ACPI_SRAT_MEM_ENABLED       (1)    /* 00: Use affinity structure */
232#define ACPI_SRAT_MEM_HOT_PLUGGABLE (1<<1) /* 01: Memory region is hot pluggable */
233#define ACPI_SRAT_MEM_NON_VOLATILE  (1<<2) /* 02: Memory region is non-volatile */
234
235struct acpi_srat_mem_affinity {
236        subheader_t Header;
237        uint32_t ProximityDomain;
238        uint16_t Reserved;        /* Reserved, must be zero */
239        uint64_t BaseAddress;
240        uint64_t Length;
241        uint32_t Reserved1;
242        uint32_t Flags;
243        uint64_t Reserved2;       /* Reserved, must be zero */
244};
245typedef struct acpi_srat_mem_affinity   srat_mem_affinity_t;
246
Note: See TracBrowser for help on using the repository browser.