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