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