2 * This file is part of the coreboot project.
4 * Copyright (C) 2004 SUSE LINUX AG
5 * Copyright (C) 2004 Nick Barker
6 * Copyright (C) 2008-2009 coresystems GmbH
7 * (Written by Stefan Reinauer <stepan@coresystems.de>)
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 * coreboot ACPI support - headers and defines.
30 #if CONFIG_GENERATE_ACPI_TABLES==1
34 #define RSDP_SIG "RSD PTR " /* RSDT pointer signature */
35 #define ACPI_TABLE_CREATOR "COREBOOT" /* Must be exactly 8 bytes long! */
36 #define OEM_ID "CORE " /* Must be exactly 6 bytes long! */
37 #define ASLC "CORE" /* Must be exactly 4 bytes long! */
39 /* RSDP (Root System Description Pointer) */
40 typedef struct acpi_rsdp {
41 char signature[8]; /* RSDP signature */
42 u8 checksum; /* Checksum of the first 20 bytes */
43 char oem_id[6]; /* OEM ID */
44 u8 revision; /* 0 for ACPI 1.0, 2 for ACPI 2.0/3.0/4.0 */
45 u32 rsdt_address; /* Physical address of RSDT (32 bits) */
46 u32 length; /* Total RSDP length (incl. extended part) */
47 u64 xsdt_address; /* Physical address of XSDT (64 bits) */
48 u8 ext_checksum; /* Checksum of the whole table */
50 } __attribute__ ((packed)) acpi_rsdp_t;
51 /* Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum. */
53 /* GAS (Generic Address Structure) */
54 typedef struct acpi_gen_regaddr {
55 u8 space_id; /* Address space ID */
56 u8 bit_width; /* Register size in bits */
57 u8 bit_offset; /* Register bit offset */
58 u8 resv; /* FIXME: Access size in ACPI 2.0/3.0/4.0 */
59 u32 addrl; /* Register address, low 32 bits */
60 u32 addrh; /* Register address, high 32 bits */
61 } __attribute__ ((packed)) acpi_addr_t;
63 #define ACPI_ADDRESS_SPACE_MEMORY 0 /* System memory */
64 #define ACPI_ADDRESS_SPACE_IO 1 /* System I/O */
65 #define ACPI_ADDRESS_SPACE_PCI 2 /* PCI config space */
66 #define ACPI_ADDRESS_SPACE_EC 3 /* Embedded controller */
67 #define ACPI_ADDRESS_SPACE_SMBUS 4 /* SMBus */
68 #define ACPI_ADDRESS_SPACE_FIXED 0x7f /* Functional fixed hardware */
69 /* 0x80-0xbf: Reserved */
70 /* 0xc0-0xff: OEM defined */
72 /* Generic ACPI header, provided by (almost) all tables */
73 typedef struct acpi_table_header {
74 char signature[4]; /* ACPI signature (4 ASCII characters) */
75 u32 length; /* Table length in bytes (incl. header) */
76 u8 revision; /* Table version (not ACPI version!) */
77 u8 checksum; /* To make sum of entire table == 0 */
78 char oem_id[6]; /* OEM identification */
79 char oem_table_id[8]; /* OEM table identification */
80 u32 oem_revision; /* OEM revision number */
81 char asl_compiler_id[4]; /* ASL compiler vendor ID */
82 u32 asl_compiler_revision; /* ASL compiler revision number */
83 } __attribute__ ((packed)) acpi_header_t;
85 /* A maximum number of 32 ACPI tables ought to be enough for now. */
86 #define MAX_ACPI_TABLES 32
88 /* RSDT (Root System Description Table) */
89 typedef struct acpi_rsdt {
90 struct acpi_table_header header;
91 u32 entry[MAX_ACPI_TABLES];
92 } __attribute__ ((packed)) acpi_rsdt_t;
94 /* XSDT (Extended System Description Table) */
95 typedef struct acpi_xsdt {
96 struct acpi_table_header header;
97 u64 entry[MAX_ACPI_TABLES];
98 } __attribute__ ((packed)) acpi_xsdt_t;
101 typedef struct acpi_hpet {
102 struct acpi_table_header header;
104 struct acpi_gen_regaddr addr;
108 } __attribute__ ((packed)) acpi_hpet_t;
110 /* MCFG (PCI Express MMIO config space BAR description table) */
111 typedef struct acpi_mcfg {
112 struct acpi_table_header header;
114 } __attribute__ ((packed)) acpi_mcfg_t;
116 typedef struct acpi_mcfg_mmconfig {
119 u16 pci_segment_group_number;
123 } __attribute__ ((packed)) acpi_mcfg_mmconfig_t;
125 /* SRAT (System Resource Affinity Table) */
126 typedef struct acpi_srat {
127 struct acpi_table_header header;
130 /* Followed by static resource allocation structure[n] */
131 } __attribute__ ((packed)) acpi_srat_t;
133 /* SRAT: Processor Local APIC/SAPIC Affinity Structure */
134 typedef struct acpi_srat_lapic {
135 u8 type; /* Type (0) */
136 u8 length; /* Length in bytes (16) */
137 u8 proximity_domain_7_0; /* Proximity domain bits[7:0] */
138 u8 apic_id; /* Local APIC ID */
139 u32 flags; /* Enable bit 0 = 1, other bits reserved to 0 */
140 u8 local_sapic_eid; /* Local SAPIC EID */
141 u8 proximity_domain_31_8[3]; /* Proximity domain bits[31:8] */
142 u32 resv; /* TODO: Clock domain in ACPI 4.0. */
143 } __attribute__ ((packed)) acpi_srat_lapic_t;
145 /* SRAT: Memory Affinity Structure */
146 typedef struct acpi_srat_mem {
147 u8 type; /* Type (1) */
148 u8 length; /* Length in bytes (40) */
149 u32 proximity_domain; /* Proximity domain */
151 u32 base_address_low; /* Mem range base address, low */
152 u32 base_address_high; /* Mem range base address, high */
153 u32 length_low; /* Mem range length, low */
154 u32 length_high; /* Mem range length, high */
156 u32 flags; /* Enable bit 0, hot pluggable bit 1; Non Volatile bit 2, other bits reserved to 0 */
158 } __attribute__ ((packed)) acpi_srat_mem_t;
160 /* SLIT (System Locality Distance Information Table) */
161 typedef struct acpi_slit {
162 struct acpi_table_header header;
163 /* Followed by static resource allocation 8+byte[num*num] */
164 } __attribute__ ((packed)) acpi_slit_t;
166 /* MADT (Multiple APIC Description Table) */
167 typedef struct acpi_madt {
168 struct acpi_table_header header;
169 u32 lapic_addr; /* Local APIC address */
170 u32 flags; /* Multiple APIC flags */
171 } __attribute__ ((packed)) acpi_madt_t;
173 /* MADT: APIC Structure Types */
174 /* TODO: Convert to ALLCAPS. */
175 enum acpi_apic_types {
176 LocalApic = 0, /* Processor local APIC */
177 IOApic = 1, /* I/O APIC */
178 IRQSourceOverride = 2, /* Interrupt source override */
179 NMIType = 3, /* NMI source */
180 LocalApicNMI = 4, /* Local APIC NMI */
181 LApicAddressOverride = 5, /* Local APIC address override */
182 IOSApic = 6, /* I/O SAPIC */
183 LocalSApic = 7, /* Local SAPIC */
184 PlatformIRQSources = 8, /* Platform interrupt sources */
185 Localx2Apic = 9, /* Processor local x2APIC */
186 Localx2ApicNMI = 10, /* Local x2APIC NMI */
187 /* 0x0b-0x7f: Reserved */
188 /* 0x80-0xff: Reserved for OEM use */
191 /* MADT: Processor Local APIC Structure */
192 typedef struct acpi_madt_lapic {
193 u8 type; /* Type (0) */
194 u8 length; /* Length in bytes (8) */
195 u8 processor_id; /* ACPI processor ID */
196 u8 apic_id; /* Local APIC ID */
197 u32 flags; /* Local APIC flags */
198 } __attribute__ ((packed)) acpi_madt_lapic_t;
200 /* MADT: Local APIC NMI Structure */
201 typedef struct acpi_madt_lapic_nmi {
202 u8 type; /* Type (4) */
203 u8 length; /* Length in bytes (6) */
204 u8 processor_id; /* ACPI processor ID */
205 u16 flags; /* MPS INTI flags */
206 u8 lint; /* Local APIC LINT# */
207 } __attribute__ ((packed)) acpi_madt_lapic_nmi_t;
209 /* MADT: I/O APIC Structure */
210 typedef struct acpi_madt_ioapic {
211 u8 type; /* Type (1) */
212 u8 length; /* Length in bytes (12) */
213 u8 ioapic_id; /* I/O APIC ID */
215 u32 ioapic_addr; /* I/O APIC address */
216 u32 gsi_base; /* Global system interrupt base */
217 } __attribute__ ((packed)) acpi_madt_ioapic_t;
219 /* MADT: Interrupt Source Override Structure */
220 typedef struct acpi_madt_irqoverride {
221 u8 type; /* Type (2) */
222 u8 length; /* Length in bytes (10) */
223 u8 bus; /* ISA (0) */
224 u8 source; /* Bus-relative int. source (IRQ) */
225 u32 gsirq; /* Global system interrupt */
226 u16 flags; /* MPS INTI flags */
227 } __attribute__ ((packed)) acpi_madt_irqoverride_t;
229 /* FADT (Fixed ACPI Description Table) */
230 typedef struct acpi_fadt {
231 struct acpi_table_header header;
235 u8 preferred_pm_profile;
270 struct acpi_gen_regaddr reset_reg;
275 u32 x_firmware_ctl_l;
276 u32 x_firmware_ctl_h;
279 struct acpi_gen_regaddr x_pm1a_evt_blk;
280 struct acpi_gen_regaddr x_pm1b_evt_blk;
281 struct acpi_gen_regaddr x_pm1a_cnt_blk;
282 struct acpi_gen_regaddr x_pm1b_cnt_blk;
283 struct acpi_gen_regaddr x_pm2_cnt_blk;
284 struct acpi_gen_regaddr x_pm_tmr_blk;
285 struct acpi_gen_regaddr x_gpe0_blk;
286 struct acpi_gen_regaddr x_gpe1_blk;
287 } __attribute__ ((packed)) acpi_fadt_t;
289 /* FADT Feature Flags */
290 #define ACPI_FADT_WBINVD (1 << 0)
291 #define ACPI_FADT_WBINVD_FLUSH (1 << 1)
292 #define ACPI_FADT_C1_SUPPORTED (1 << 2)
293 #define ACPI_FADT_C2_MP_SUPPORTED (1 << 3)
294 #define ACPI_FADT_POWER_BUTTON (1 << 4)
295 #define ACPI_FADT_SLEEP_BUTTON (1 << 5)
296 #define ACPI_FADT_FIXED_RTC (1 << 6)
297 #define ACPI_FADT_S4_RTC_WAKE (1 << 7)
298 #define ACPI_FADT_32BIT_TIMER (1 << 8)
299 #define ACPI_FADT_DOCKING_SUPPORTED (1 << 9)
300 #define ACPI_FADT_RESET_REGISTER (1 << 10)
301 #define ACPI_FADT_SEALED_CASE (1 << 11)
302 #define ACPI_FADT_HEADLESS (1 << 12)
303 #define ACPI_FADT_SLEEP_TYPE (1 << 13)
304 #define ACPI_FADT_PCI_EXPRESS_WAKE (1 << 14)
305 #define ACPI_FADT_PLATFORM_CLOCK (1 << 15)
306 #define ACPI_FADT_S4_RTC_VALID (1 << 16)
307 #define ACPI_FADT_REMOTE_POWER_ON (1 << 17)
308 #define ACPI_FADT_APIC_CLUSTER (1 << 18)
309 #define ACPI_FADT_APIC_PHYSICAL (1 << 19)
310 /* Bits 20-31: reserved */
312 /* FADT Boot Architecture Flags */
313 #define ACPI_FADT_LEGACY_DEVICES (1 << 0)
314 #define ACPI_FADT_8042 (1 << 1)
315 #define ACPI_FADT_VGA_NOT_PRESENT (1 << 2)
316 #define ACPI_FADT_MSI_NOT_SUPPORTED (1 << 3)
317 #define ACPI_FADT_NO_PCIE_ASPM_CONTROL (1 << 4)
319 /* FADT Preferred Power Management Profile */
320 enum acpi_preferred_pm_profiles {
325 PM_ENTERPRISE_SERVER = 4,
328 PM_PERFORMANCE_SERVER = 7,
331 /* FACS (Firmware ACPI Control Structure) */
332 typedef struct acpi_facs {
333 char signature[4]; /* "FACS" */
334 u32 length; /* Length in bytes (>= 64) */
335 u32 hardware_signature; /* Hardware signature */
336 u32 firmware_waking_vector; /* Firmware waking vector */
337 u32 global_lock; /* Global lock */
338 u32 flags; /* FACS flags */
339 u32 x_firmware_waking_vector_l; /* X FW waking vector, low */
340 u32 x_firmware_waking_vector_h; /* X FW waking vector, high */
341 u8 version; /* ACPI 4.0: 2 */
342 u8 resv[31]; /* FIXME: 4.0: ospm_flags */
343 } __attribute__ ((packed)) acpi_facs_t;
346 #define ACPI_FACS_S4BIOS_F (1 << 0)
347 #define ACPI_FACS_64BIT_WAKE_F (1 << 1)
348 /* Bits 31..2: reserved */
350 /* ECDT (Embedded Controller Boot Resources Table) */
351 typedef struct acpi_ecdt {
352 struct acpi_table_header header;
353 struct acpi_gen_regaddr ec_control; /* EC control register */
354 struct acpi_gen_regaddr ec_data; /* EC data register */
356 u8 gpe_bit; /* GPE bit */
357 u8 ec_id[]; /* EC ID */
358 } __attribute__ ((packed)) acpi_ecdt_t;
360 /* These are implemented by the target port or north/southbridge. */
361 unsigned long write_acpi_tables(unsigned long addr);
362 unsigned long acpi_fill_madt(unsigned long current);
363 unsigned long acpi_fill_mcfg(unsigned long current);
364 unsigned long acpi_fill_srat(unsigned long current);
365 unsigned long acpi_fill_slit(unsigned long current);
366 unsigned long acpi_fill_ssdt_generator(unsigned long current,
367 const char *oem_table_id);
368 void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id);
369 void acpi_create_fadt(acpi_fadt_t *fadt,acpi_facs_t *facs, void *dsdt);
371 void update_ssdt(void *ssdt);
372 void update_ssdtx(void *ssdtx, int i);
374 /* These can be used by the target port. */
375 u8 acpi_checksum(u8 *table, u32 length);
377 void acpi_add_table(acpi_rsdp_t *rsdp, void *table);
379 int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic);
380 int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,
382 int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
383 u8 bus, u8 source, u32 gsirq, u16 flags);
384 int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
386 void acpi_create_madt(acpi_madt_t *madt);
387 unsigned long acpi_create_madt_lapics(unsigned long current);
388 unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags,
391 int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic);
392 int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek,u32 sizek,
394 int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base,
395 u16 seg_nr, u8 start, u8 end);
396 unsigned long acpi_create_srat_lapics(unsigned long current);
397 void acpi_create_srat(acpi_srat_t *srat);
399 void acpi_create_slit(acpi_slit_t *slit);
401 void acpi_create_hpet(acpi_hpet_t *hpet);
403 void acpi_create_mcfg(acpi_mcfg_t *mcfg);
405 void acpi_create_facs(acpi_facs_t *facs);
407 #if CONFIG_HAVE_ACPI_SLIC
408 unsigned long acpi_create_slic(unsigned long current);
411 void acpi_write_rsdt(acpi_rsdt_t *rsdt);
412 void acpi_write_xsdt(acpi_xsdt_t *xsdt);
413 void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, acpi_xsdt_t *xsdt);
415 #if CONFIG_HAVE_ACPI_RESUME
416 /* 0 = S0, 1 = S1 ...*/
417 extern u8 acpi_slp_type;
419 void suspend_resume(void);
420 void *acpi_find_wakeup_vector(void);
421 void *acpi_get_wakeup_rsdp(void);
422 void acpi_jump_to_wakeup(void *wakeup_addr);
424 int acpi_get_sleep_type(void);
428 /* northbridge/amd/amdfam10/amdfam10_acpi.c */
429 unsigned long acpi_add_ssdt_pstates(acpi_rsdp_t *rsdp, unsigned long current);
431 /* cpu/intel/speedstep/acpi.c */
432 void generate_cpu_entries(void);
434 #else // CONFIG_GENERATE_ACPI_TABLES
436 #define write_acpi_tables(start) (start)