bc7b082f7d6db43dfc6cd3a55389f89bcfa5ff5b
[coreboot.git] / src / arch / i386 / include / arch / acpi.h
1 /*
2  * This file is part of the coreboot project.
3  *
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>)
8  *
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.
12  *
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.
17  *
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
21  */
22
23 /*
24  * coreboot ACPI Support - headers and defines.
25  */
26
27 #ifndef __ASM_ACPI_H
28 #define __ASM_ACPI_H
29
30 #if CONFIG_GENERATE_ACPI_TABLES==1
31
32 #include <stdint.h>
33
34 #define RSDP_SIG                "RSD PTR "  /* RSDT Pointer signature */
35 #define ACPI_TABLE_CREATOR      "COREBOOT"
36 #define OEM_ID                  "CORE  "
37 #define ASLC                    "CORE"
38
39 /* ACPI 3.0 table RSDP */
40
41 typedef struct acpi_rsdp {
42         char  signature[8];     /* RSDP signature "RSD PTR" */
43         u8    checksum;         /* checksum of the first 20 bytes */
44         char  oem_id[6];        /* OEM ID, "LXBIOS" */
45         u8    revision;         /* 0 for ACPI 1.0, 2 for ACPI 2.0/3.0 */
46         u32   rsdt_address;     /* physical address of RSDT */
47         u32   length;           /* total length of RSDP (including extended part) */
48         u64   xsdt_address;     /* physical address of XSDT */
49         u8    ext_checksum;     /* chechsum of whole table */
50         u8    reserved[3];
51 } __attribute__((packed)) acpi_rsdp_t;
52
53 /* Generic Address Container */
54
55 typedef struct acpi_gen_regaddr {
56         u8  space_id;
57         u8  bit_width;
58         u8  bit_offset;
59         u8  resv;
60         u32 addrl;
61         u32 addrh;
62 } __attribute__ ((packed)) acpi_addr_t;
63
64 #define ACPI_ADDRESS_SPACE_MEMORY          0
65 #define ACPI_ADDRESS_SPACE_IO              1
66 #define ACPI_ADDRESS_SPACE_PCI             2
67 #define ACPI_ADDRESS_SPACE_FIXED        0x7f
68
69
70 /* Generic ACPI Header, provided by (almost) all tables */
71
72 typedef struct acpi_table_header         /* ACPI common table header */
73 {
74         char signature [4];          /* ACPI signature (4 ASCII characters) */\
75         u32  length;                 /* Length of table, in bytes, including header */\
76         u8   revision;               /* ACPI Specification minor 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;
84
85 /* A maximum number of 32 ACPI tables ought to be enough for now */
86 #define MAX_ACPI_TABLES 32
87
88 /* RSDT */
89 typedef struct acpi_rsdt {
90         struct acpi_table_header header;
91         u32 entry[MAX_ACPI_TABLES];
92 } __attribute__ ((packed)) acpi_rsdt_t;
93
94 /* XSDT */
95 typedef struct acpi_xsdt {
96         struct acpi_table_header header;
97         u64 entry[MAX_ACPI_TABLES];
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 */
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 //
283 // FADT Feature Flags
284 //
285 #define ACPI_FADT_WBINVD                (1 << 0)
286 #define ACPI_FADT_WBINVD_FLUSH          (1 << 1)
287 #define ACPI_FADT_C1_SUPPORTED          (1 << 2)
288 #define ACPI_FADT_C2_MP_SUPPORTED       (1 << 3)
289 #define ACPI_FADT_POWER_BUTTON          (1 << 4)
290 #define ACPI_FADT_SLEEP_BUTTON          (1 << 5)
291 #define ACPI_FADT_FIXED_RTC             (1 << 6)
292 #define ACPI_FADT_S4_RTC_WAKE           (1 << 7)
293 #define ACPI_FADT_32BIT_TIMER           (1 << 8)
294 #define ACPI_FADT_DOCKING_SUPPORTED     (1 << 9)
295 #define ACPI_FADT_RESET_REGISTER        (1 << 10)
296 #define ACPI_FADT_SEALED_CASE           (1 << 11)
297 #define ACPI_FADT_HEADLESS              (1 << 12)
298 #define ACPI_FADT_SLEEP_TYPE            (1 << 13)
299 #define ACPI_FADT_PCI_EXPRESS_WAKE      (1 << 14)
300 #define ACPI_FADT_PLATFORM_CLOCK        (1 << 15)
301 #define ACPI_FADT_S4_RTC_VALID          (1 << 16)
302 #define ACPI_FADT_REMOTE_POWER_ON       (1 << 17)
303 #define ACPI_FADT_APIC_CLUSTER          (1 << 18)
304 #define ACPI_FADT_APIC_PHYSICAL         (1 << 19)
305
306 //
307 // FADT Boot Architecture Flags
308 //
309 #define ACPI_FADT_LEGACY_DEVICES        (1 << 0)
310 #define ACPI_FADT_8042                  (1 << 1)
311 #define ACPI_FADT_VGA_NOT_PRESENT       (1 << 2)
312 #define ACPI_FADT_MSI_NOT_SUPPORTED     (1 << 3)
313 #define ACPI_FADT_NO_PCIE_ASPM_CONTROL  (1 << 4)
314
315 //
316 // FADT Preferred Power Management Profile
317 //
318 enum acpi_preferred_pm_profiles {
319         PM_UNSPECIFIED          = 0,
320         PM_DESKTOP              = 1,
321         PM_MOBILE               = 2,
322         PM_WORKSTATION          = 3,
323         PM_ENTERPRISE_SERVER    = 4,
324         PM_SOHO_SERVER          = 5,
325         PM_APPLIANCE_PC         = 6,
326         PM_PERFORMANCE_SERVER   = 7
327 };
328
329 /* FACS */
330 typedef struct acpi_facs {
331         char signature[4];
332         u32 length;
333         u32 hardware_signature;
334         u32 firmware_waking_vector;
335         u32 global_lock;
336         u32 flags;
337         u32 x_firmware_waking_vector_l;
338         u32 x_firmware_waking_vector_h;
339         u8 version;
340         u8 resv[31];
341 } __attribute__ ((packed)) acpi_facs_t;
342
343 //
344 // FACS Flags
345 //
346 #define ACPI_FACS_S4BIOS_F      (1 << 0)
347
348 typedef struct acpi_ecdt {
349         struct acpi_table_header header;
350         struct acpi_gen_regaddr ec_control;
351         struct acpi_gen_regaddr ec_data;
352         u32 uid;
353         u8 gpe_bit;
354         u8 ec_id[];
355 } __attribute__ ((packed)) acpi_ecdt_t;
356
357
358 /* These are implemented by the target port or north/southbridge*/
359 unsigned long write_acpi_tables(unsigned long addr);
360 unsigned long acpi_fill_madt(unsigned long current);
361 unsigned long acpi_fill_mcfg(unsigned long current);
362 unsigned long acpi_fill_srat(unsigned long current);
363 unsigned long acpi_fill_slit(unsigned long current);
364 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id);
365 void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id);
366 void acpi_create_fadt(acpi_fadt_t *fadt,acpi_facs_t *facs, void *dsdt);
367
368 void update_ssdt(void* ssdt);
369 void update_ssdtx(void* ssdtx, int i);
370
371 /* These can be used by the target port */
372 u8 acpi_checksum(u8 *table, u32 length);
373
374 void acpi_add_table(acpi_rsdp_t *rsdp, void *table);
375
376
377 int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic);
378 int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,u32 gsi_base);
379 int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
380                 u8 bus, u8 source, u32 gsirq, u16 flags);
381 int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
382                 u16 flags, u8 lint);
383 void acpi_create_madt(acpi_madt_t *madt);
384 unsigned long acpi_create_madt_lapics(unsigned long current);
385 unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags, u8 lint);
386
387
388 int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic);
389 int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek,u32 sizek, u32 flags);
390 int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base, u16 seg_nr, u8 start, u8 end);
391 unsigned long acpi_create_srat_lapics(unsigned long current);
392 void acpi_create_srat(acpi_srat_t *srat);
393
394 void acpi_create_slit(acpi_slit_t *slit);
395
396 void acpi_create_hpet(acpi_hpet_t *hpet);
397
398 void acpi_create_mcfg(acpi_mcfg_t *mcfg);
399
400 void acpi_create_facs(acpi_facs_t *facs);
401
402 #if CONFIG_HAVE_ACPI_SLIC
403 unsigned long acpi_create_slic(unsigned long current);
404 #endif
405
406 void acpi_write_rsdt(acpi_rsdt_t *rsdt);
407 void acpi_write_xsdt(acpi_xsdt_t *xsdt);
408 void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, acpi_xsdt_t *xsdt);
409
410 #if CONFIG_HAVE_ACPI_RESUME
411 /* 0 = S0, 1 = S1 ...*/
412 extern u8 acpi_slp_type;
413
414 void suspend_resume(void);
415 void *acpi_find_wakeup_vector(void);
416 void *acpi_get_wakeup_rsdp(void);
417 void acpi_jump_to_wakeup(void *wakeup_addr);
418
419 int acpi_get_sleep_type(void);
420
421 #endif
422
423 /* northbridge/amd/amdfam10/amdfam10_acpi.c */
424 unsigned long acpi_add_ssdt_pstates(acpi_rsdp_t *rsdp, unsigned long current);
425 /* cpu/intel/speedstep/acpi.c */
426 void generate_cpu_entries(void);
427
428 #define ACPI_WRITE_MADT_IOAPIC(dev,id)                  \
429 do {                                                    \
430         struct resource *res;                           \
431         res = find_resource(dev, PCI_BASE_ADDRESS_0);   \
432         if (!res) break;                                \
433         current += acpi_create_madt_ioapic(             \
434                 (acpi_madt_ioapic_t *)current,          \
435                 id, res->base, gsi_base);               \
436         gsi_base+=4;                                    \
437 } while(0);
438
439 #else // CONFIG_GENERATE_ACPI_TABLES
440
441 #define write_acpi_tables(start) (start)
442
443 #endif
444
445 #endif