update comments
[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  * ACPI FADT & FACS added by Nick Barker <nick.barker9@btinternet.com>
10  * those parts (C) 2004 Nick Barker
11  * 
12  * ACPI SRAT support added in 2005.9 by yhlu
13  * Copyright 2005 ADVANCED MICRO DEVICES, INC. All Rights Reserved.
14  *
15  */
16
17
18 #ifndef __ASM_ACPI_H
19 #define __ASM_ACPI_H
20
21 #if HAVE_ACPI_TABLES==1
22
23 typedef unsigned char u8;
24 typedef unsigned short u16;
25 typedef unsigned int u32;
26 typedef unsigned long long u64;
27
28 #define RSDP_SIG              "RSD PTR "  /* RSDT Pointer signature */
29 #define RSDP_NAME             "RSDP"
30
31 #define RSDT_NAME             "RSDT"
32 #define HPET_NAME             "HPET"
33 #define MADT_NAME             "APIC"
34 #define SRAT_NAME             "SRAT"
35
36 #define RSDT_TABLE            "RSDT    "
37 #define HPET_TABLE            "AMD64   "
38 #define MADT_TABLE            "MADT    "
39 #define SRAT_TABLE            "SRAT    "
40
41 #define OEM_ID                "LXBIOS"
42 #define ASLC                  "NONE"
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 (incl. 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[5+ACPI_SSDTX_NUM]; /* HPET, FADT, SRAT, MADT(APIC), SSDT, SSDTX */
88 } __attribute__ ((packed)) acpi_rsdt_t;
89
90 /* XSDT */
91 typedef struct acpi_xsdt {
92         struct acpi_table_header header;
93         u64 entry[5+ACPI_SSDTX_NUM];
94 } __attribute__ ((packed)) acpi_xsdt_t;
95
96
97 /* HPET TIMERS */
98 typedef struct acpi_hpet {
99         struct acpi_table_header header;
100         u32 id;
101         struct acpi_gen_regaddr addr;
102         u8 number;
103         u16 min_tick;
104         u8 attributes;
105 } __attribute__ ((packed)) acpi_hpet_t;
106
107 /* SRAT */
108 typedef struct acpi_srat {
109         struct acpi_table_header header;
110         u32 resv;
111         u64 resv1;
112         /* followed by static resource allocation structure[n]*/
113 } __attribute__ ((packed)) acpi_srat_t;
114
115
116 typedef struct acpi_srat_lapic {
117         u8 type;
118         u8 length;
119         u8 proximity_domain_7_0;
120         u8 apic_id;
121         u32 flags; /* enable bit 0  = 1, other bits reserved to 0 */
122         u8 local_sapic_eid;
123         u8 proximity_domain_31_8[3];
124         u32 resv;
125 } __attribute__ ((packed)) acpi_srat_lapic_t;
126
127 typedef struct acpi_srat_mem {
128         u8 type;
129         u8 length;
130         u32 proximity_domain;
131         u16 resv;
132         u32 base_address_low;
133         u32 base_address_high;
134         u32 length_low;
135         u32 length_high;
136         u32 resv1;
137         u32 flags; /* enable bit 0,  hot pluggable bit 1; Non Volatile bit 2, other bits reserved */
138         u32 resv2[2];
139 } __attribute__ ((packed)) acpi_srat_mem_t;
140
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