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