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