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