clean up acpi table strings, as discussed on the list
[coreboot.git] / src / arch / i386 / include / arch / acpi.h
1 /*
2  * coreboot ACPI Support - headers and defines.
3  * 
4  * written by Stefan Reinauer <stepan@coresystems.de>
5  * Copyright (C) 2004 SUSE LINUX AG
6  * Copyright (C) 2008-2009 coresystems GmbH
7  *
8  * The ACPI table structs are based on the Linux kernel sources.
9  * ACPI FADT & FACS added by Nick Barker <nick.barker9@btinternet.com>
10  * those parts (C) 2004 Nick Barker
11  */
12
13
14 #ifndef __ASM_ACPI_H
15 #define __ASM_ACPI_H
16
17 #if CONFIG_HAVE_ACPI_TABLES==1
18
19 #include <stdint.h>
20  
21 #define RSDP_SIG                "RSD PTR "  /* RSDT Pointer signature */
22 #define ACPI_TABLE_CREATOR      "COREBOOT"
23 #define OEM_ID                  "CORE  "
24 #define ASLC                    "CORE"
25
26 /* ACPI 3.0 table RSDP */
27
28 typedef struct acpi_rsdp {
29         char  signature[8];     /* RSDP signature "RSD PTR" */
30         u8    checksum;         /* checksum of the first 20 bytes */
31         char  oem_id[6];        /* OEM ID, "LXBIOS" */
32         u8    revision;         /* 0 for APCI 1.0, 2 for ACPI 2.0/3.0 */
33         u32   rsdt_address;     /* physical address of RSDT */
34         u32   length;           /* total length of RSDP (including extended part) */
35         u64   xsdt_address;     /* physical address of XSDT */
36         u8    ext_checksum;     /* chechsum of whole table */
37         u8    reserved[3];
38 } __attribute__((packed)) acpi_rsdp_t;
39
40 /* Generic Address Container */
41
42 typedef struct acpi_gen_regaddr {
43         u8  space_id;
44         u8  bit_width;
45         u8  bit_offset;
46         u8  resv;
47         u32 addrl;
48         u32 addrh;
49 } __attribute__ ((packed)) acpi_addr_t;
50
51 /* Generic ACPI Header, provided by (almost) all tables */
52
53 typedef struct acpi_table_header         /* ACPI common table header */
54 {
55         char signature [4];          /* ACPI signature (4 ASCII characters) */\
56         u32  length;                 /* Length of table, in bytes, including header */\
57         u8   revision;               /* ACPI Specification minor version # */\
58         u8   checksum;               /* To make sum of entire table == 0 */\
59         char oem_id [6];             /* OEM identification */\
60         char oem_table_id [8];       /* OEM table identification */\
61         u32  oem_revision;           /* OEM revision number */\
62         char asl_compiler_id [4];    /* ASL compiler vendor ID */\
63         u32  asl_compiler_revision;  /* ASL compiler revision number */
64 } __attribute__ ((packed)) acpi_header_t;
65
66 /* FIXME: This is very fragile:
67  * MCONFIG, HPET, FADT, SRAT, SLIT, MADT(APIC), SSDT, SSDTX, and SSDT for CPU
68  * pstate
69  */
70
71 #define MAX_ACPI_TABLES (7 + CONFIG_ACPI_SSDTX_NUM + CONFIG_MAX_CPUS)
72
73 /* RSDT */
74 typedef struct acpi_rsdt {
75         struct acpi_table_header header;
76         u32 entry[MAX_ACPI_TABLES];
77 } __attribute__ ((packed)) acpi_rsdt_t;
78
79 /* XSDT */
80 typedef struct acpi_xsdt {
81         struct acpi_table_header header;
82         u64 entry[MAX_ACPI_TABLES];
83 } __attribute__ ((packed)) acpi_xsdt_t;
84
85 /* HPET TIMERS */
86 typedef struct acpi_hpet {
87         struct acpi_table_header header;
88         u32 id;
89         struct acpi_gen_regaddr addr;
90         u8 number;
91         u16 min_tick;
92         u8 attributes;
93 } __attribute__ ((packed)) acpi_hpet_t;
94
95 /* MCFG */
96 typedef struct acpi_mcfg {
97         struct acpi_table_header header;
98         u8 reserved[8];
99 } __attribute__ ((packed)) acpi_mcfg_t;
100
101 typedef struct acpi_mcfg_mmconfig {
102         u32 base_address;
103         u32 base_reserved;
104         u16 pci_segment_group_number;
105         u8 start_bus_number;
106         u8 end_bus_number;
107         u8 reserved[4];
108 } __attribute__ ((packed)) acpi_mcfg_mmconfig_t;
109
110
111 /* SRAT */
112 typedef struct acpi_srat {
113         struct acpi_table_header header;
114         u32 resv;
115         u64 resv1;
116         /* followed by static resource allocation structure[n]*/
117 } __attribute__ ((packed)) acpi_srat_t;
118
119
120 typedef struct acpi_srat_lapic {
121         u8 type;
122         u8 length;
123         u8 proximity_domain_7_0;
124         u8 apic_id;
125         u32 flags; /* enable bit 0  = 1, other bits reserved to 0 */
126         u8 local_sapic_eid;
127         u8 proximity_domain_31_8[3];
128         u32 resv;
129 } __attribute__ ((packed)) acpi_srat_lapic_t;
130
131 typedef struct acpi_srat_mem {
132         u8 type;
133         u8 length;
134         u32 proximity_domain;
135         u16 resv;
136         u32 base_address_low;
137         u32 base_address_high;
138         u32 length_low;
139         u32 length_high;
140         u32 resv1;
141         u32 flags; /* enable bit 0,  hot pluggable bit 1; Non Volatile bit 2, other bits reserved */
142         u32 resv2[2];
143 } __attribute__ ((packed)) acpi_srat_mem_t;
144
145 /* SLIT */
146 typedef struct acpi_slit {
147         struct acpi_table_header header;
148         /* followed by static resource allocation 8+byte[num*num]*/
149 } __attribute__ ((packed)) acpi_slit_t;
150
151
152 /* MADT */
153 typedef struct acpi_madt {
154         struct acpi_table_header header;
155         u32 lapic_addr;
156         u32 flags;
157 } __attribute__ ((packed)) acpi_madt_t;
158
159 enum acpi_apic_types {
160         LocalApic               = 0,
161         IOApic                  = 1,
162         IRQSourceOverride       = 2,
163         NMI                     = 3,
164         LocalApicNMI            = 4,
165         LApicAddressOverride    = 5,
166         IOSApic                 = 6,
167         LocalSApic              = 7,
168         PlatformIRQSources      = 8
169 };
170
171 typedef struct acpi_madt_lapic {
172         u8 type;
173         u8 length;
174         u8 processor_id;
175         u8 apic_id;
176         u32 flags;
177 } __attribute__ ((packed)) acpi_madt_lapic_t;
178
179 typedef struct acpi_madt_lapic_nmi {
180         u8 type;
181         u8 length;
182         u8 processor_id;
183         u16 flags;
184         u8 lint;
185 } __attribute__ ((packed)) acpi_madt_lapic_nmi_t;
186
187
188 typedef struct acpi_madt_ioapic {
189         u8 type;
190         u8 length;
191         u8 ioapic_id;
192         u8 reserved;
193         u32 ioapic_addr;
194         u32 gsi_base;
195 } __attribute__ ((packed)) acpi_madt_ioapic_t;
196
197 typedef struct acpi_madt_irqoverride {
198         u8 type;
199         u8 length;
200         u8 bus;
201         u8 source;
202         u32 gsirq;
203         u16 flags;
204 } __attribute__ ((packed)) acpi_madt_irqoverride_t;
205
206 /* FADT */
207
208 typedef struct acpi_fadt {
209         struct acpi_table_header header;
210         u32 firmware_ctrl;
211         u32 dsdt;
212         u8 model;
213         u8 preferred_pm_profile;
214         u16 sci_int;
215         u32 smi_cmd;
216         u8 acpi_enable;
217         u8 acpi_disable;
218         u8 s4bios_req;
219         u8 pstate_cnt;
220         u32 pm1a_evt_blk;
221         u32 pm1b_evt_blk;
222         u32 pm1a_cnt_blk;
223         u32 pm1b_cnt_blk;
224         u32 pm2_cnt_blk;
225         u32 pm_tmr_blk;
226         u32 gpe0_blk;
227         u32 gpe1_blk;
228         u8 pm1_evt_len;
229         u8 pm1_cnt_len;
230         u8 pm2_cnt_len;
231         u8 pm_tmr_len;
232         u8 gpe0_blk_len;
233         u8 gpe1_blk_len;
234         u8 gpe1_base;
235         u8 cst_cnt;
236         u16 p_lvl2_lat;
237         u16 p_lvl3_lat;
238         u16 flush_size;
239         u16 flush_stride;
240         u8 duty_offset;
241         u8 duty_width;
242         u8 day_alrm;
243         u8 mon_alrm;
244         u8 century;
245         u16 iapc_boot_arch;
246         u8 res2;
247         u32 flags;
248         struct acpi_gen_regaddr reset_reg;
249         u8 reset_value;
250         u8 res3;
251         u8 res4;
252         u8 res5;
253         u32 x_firmware_ctl_l;
254         u32 x_firmware_ctl_h;
255         u32 x_dsdt_l;
256         u32 x_dsdt_h;
257         struct acpi_gen_regaddr x_pm1a_evt_blk;
258         struct acpi_gen_regaddr x_pm1b_evt_blk;
259         struct acpi_gen_regaddr x_pm1a_cnt_blk;
260         struct acpi_gen_regaddr x_pm1b_cnt_blk;
261         struct acpi_gen_regaddr x_pm2_cnt_blk;
262         struct acpi_gen_regaddr x_pm_tmr_blk;
263         struct acpi_gen_regaddr x_gpe0_blk;
264         struct acpi_gen_regaddr x_gpe1_blk;
265 } __attribute__ ((packed)) acpi_fadt_t;
266
267 //
268 // FADT Feature Flags
269 //
270 #define ACPI_FADT_WBINVD                (1 << 0)
271 #define ACPI_FADT_WBINVD_FLUSH          (1 << 1)
272 #define ACPI_FADT_C1_SUPPORTED          (1 << 2)
273 #define ACPI_FADT_C2_MP_SUPPORTED       (1 << 3)
274 #define ACPI_FADT_POWER_BUTTON          (1 << 4)
275 #define ACPI_FADT_SLEEP_BUTTON          (1 << 5)
276 #define ACPI_FADT_FIXED_RTC             (1 << 6)
277 #define ACPI_FADT_S4_RTC_WAKE           (1 << 7)
278 #define ACPI_FADT_32BIT_TIMER           (1 << 8)
279 #define ACPI_FADT_DOCKING_SUPPORTED     (1 << 9)
280 #define ACPI_FADT_RESET_REGISTER        (1 << 10)
281 #define ACPI_FADT_SEALED_CASE           (1 << 11)
282 #define ACPI_FADT_HEADLESS              (1 << 12)
283 #define ACPI_FADT_SLEEP_TYPE            (1 << 13)
284 #define ACPI_FADT_PCI_EXPRESS_WAKE      (1 << 14)
285 #define ACPI_FADT_PLATFORM_CLOCK        (1 << 15)
286 #define ACPI_FADT_S4_RTC_VALID          (1 << 16)
287 #define ACPI_FADT_REMOTE_POWER_ON       (1 << 17)
288 #define ACPI_FADT_APIC_CLUSTER          (1 << 18)
289 #define ACPI_FADT_APIC_PHYSICAL         (1 << 19)
290
291 //
292 // FADT Boot Architecture Flags
293 //
294 #define ACPI_FADT_LEGACY_DEVICES        (1 << 0)
295 #define ACPI_FADT_8042                  (1 << 1)
296 #define ACPI_FADT_VGA_NOT_PRESENT       (1 << 2)
297 #define ACPI_FADT_MSI_NOT_SUPPORTED     (1 << 3)
298 #define ACPI_FADT_NO_PCIE_ASPM_CONTROL  (1 << 4)
299
300 //
301 // FADT Preferred Power Management Profile
302 //
303 enum acpi_preferred_pm_profiles {
304         PM_UNSPECIFIED          = 0,
305         PM_DESKTOP              = 1,
306         PM_MOBILE               = 2,
307         PM_WORKSTATION          = 3,
308         PM_ENTERPRISE_SERVER    = 4,
309         PM_SOHO_SERVER          = 5,
310         PM_APPLIANCE_PC         = 6,
311         PM_PERFORMANCE_SERVER   = 7
312 };
313
314 /* FACS */
315 typedef struct acpi_facs {
316         char signature[4];
317         u32 length;
318         u32 hardware_signature;
319         u32 firmware_waking_vector;
320         u32 global_lock;
321         u32 flags;
322         u32 x_firmware_waking_vector_l;
323         u32 x_firmware_waking_vector_h;
324         u8 version;
325         u8 resv[31];
326 } __attribute__ ((packed)) acpi_facs_t;
327
328 //
329 // FACS Flags
330 //
331 #define ACPI_FACS_S4BIOS_F      (1 << 0)
332
333 /* These are implemented by the target port */
334 unsigned long write_acpi_tables(unsigned long addr);
335 unsigned long acpi_fill_madt(unsigned long current);
336 unsigned long acpi_fill_mcfg(unsigned long current);
337 unsigned long acpi_fill_srat(unsigned long current);
338 unsigned long acpi_fill_slit(unsigned long current);
339 unsigned long acpi_fill_ssdt_generator(unsigned long current, char *oem_table_id);
340 void acpi_create_ssdt_generator(acpi_header_t *ssdt, char *oem_table_id);
341 void acpi_create_fadt(acpi_fadt_t *fadt,acpi_facs_t *facs,void *dsdt);
342
343 /* These can be used by the target port */
344 u8 acpi_checksum(u8 *table, u32 length);
345
346 void acpi_add_table(acpi_rsdp_t *rsdp, void *table);
347
348
349 int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic);
350 int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,u32 gsi_base);
351 int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
352                 u8 bus, u8 source, u32 gsirq, u16 flags);
353 int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
354                 u16 flags, u8 lint);
355 void acpi_create_madt(acpi_madt_t *madt);
356 unsigned long acpi_create_madt_lapics(unsigned long current);
357 unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags, u8 lint);
358
359
360 int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic);
361 int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek,u32 sizek, u32 flags);
362 int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base, u16 seg_nr, u8 start, u8 end);
363 unsigned long acpi_create_srat_lapics(unsigned long current);
364 void acpi_create_srat(acpi_srat_t *srat);
365
366 void acpi_create_slit(acpi_slit_t *slit);
367
368 void acpi_create_hpet(acpi_hpet_t *hpet);
369
370 void acpi_create_mcfg(acpi_mcfg_t *mcfg);
371
372 void acpi_create_facs(acpi_facs_t *facs);
373
374 void acpi_write_rsdt(acpi_rsdt_t *rsdt);
375 void acpi_write_xsdt(acpi_xsdt_t *xsdt);
376 void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, acpi_xsdt_t *xsdt);
377
378 #if CONFIG_HAVE_ACPI_RESUME
379 /* 0 = S0, 1 = S1 ...*/
380 extern u8 acpi_slp_type;
381
382 void suspend_resume(void);
383 void *acpi_find_wakeup_vector(void);
384 void *acpi_get_wakeup_rsdp(void);
385 void acpi_jmp_to_realm_wakeup(u32 linear_addr);
386 void acpi_jump_to_wakeup(void *wakeup_addr);
387
388 int acpi_get_sleep_type(void);
389
390 #endif
391
392 unsigned long acpi_add_ssdt_pstates(acpi_rsdt_t *rsdt, unsigned long current);
393
394 #define ACPI_WRITE_MADT_IOAPIC(dev,id)                  \
395 do {                                                    \
396         struct resource *res;                           \
397         res = find_resource(dev, PCI_BASE_ADDRESS_0);   \
398         if (!res) break;                                \
399         current += acpi_create_madt_ioapic(             \
400                 (acpi_madt_ioapic_t *)current,          \
401                 id, res->base, gsi_base);               \
402         gsi_base+=4;                                    \
403 } while(0);
404
405 #define IO_APIC_ADDR    0xfec00000UL
406
407 #else // CONFIG_HAVE_ACPI_TABLES
408
409 #define write_acpi_tables(start) (start)
410
411 #endif
412
413 #endif