Revision: linuxbios@linuxbios.org--devel/freebios--devel--2.0--patch-13
[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 char u8;
21 typedef unsigned short u16;
22 typedef unsigned int u32;
23 typedef unsigned long long u64;
24
25 #define RSDP_SIG              "RSD PTR "  /* RSDT Pointer signature */
26 #define RSDP_NAME             "RSDP"
27
28 #define RSDT_NAME             "RSDT"
29 #define HPET_NAME             "HPET"
30 #define MADT_NAME             "APIC"
31
32 #define RSDT_TABLE            "RSDT    "
33 #define HPET_TABLE            "AMD64   "
34 #define MADT_TABLE            "MADT    "
35
36 #define OEM_ID                "LXBIOS"
37 #define ASLC                  "NONE"
38
39 /* ACPI 2.0 table RSDP */
40
41 typedef struct acpi_rsdp {
42         char  signature[8];
43         u8    checksum;
44         char  oem_id[6];
45         u8    revision;
46         u32   rsdt_address;
47         u32   length;
48         u64   xsdt_address;
49         u8    ext_checksum;
50         u8    reserved[3];
51 } __attribute__((packed)) acpi_rsdp_t;
52
53 /* Generic Address Container */
54
55 typedef struct acpi_gen_regaddr {
56         u8  space_id;
57         u8  bit_width;
58         u8  bit_offset;
59         u8  resv;
60         u32 addrl;
61         u32 addrh;
62 } __attribute__ ((packed)) acpi_addr_t;
63
64 /* Generic ACPI Header, provided by (almost) all tables */
65
66 typedef struct acpi_table_header         /* ACPI common table header */
67 {
68         char signature [4];          /* ACPI signature (4 ASCII characters) */\
69         u32  length;                 /* Length of table, in bytes, including header */\
70         u8   revision;               /* ACPI Specification minor version # */\
71         u8   checksum;               /* To make sum of entire table == 0 */\
72         char oem_id [6];             /* OEM identification */\
73         char oem_table_id [8];       /* OEM table identification */\
74         u32  oem_revision;           /* OEM revision number */\
75         char asl_compiler_id [4];    /* ASL compiler vendor ID */\
76         u32  asl_compiler_revision;  /* ASL compiler revision number */
77 } __attribute__ ((packed)) acpi_header_t;
78
79 /* RSDT */
80 typedef struct acpi_rsdt {
81         struct acpi_table_header header;
82         u32 entry[8];
83 } __attribute__ ((packed)) acpi_rsdt_t;
84
85 /* XSDT */
86 typedef struct acpi_xsdt {
87         struct acpi_table_header header;
88         u64 entry[8];
89 } __attribute__ ((packed)) acpi_xsdt_t;
90
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 typedef struct acpi_madt {
103         struct acpi_table_header header;
104         u32 lapic_addr;
105         u32 flags;
106 } __attribute__ ((packed)) acpi_madt_t;
107
108 enum acpi_apic_types {
109         LocalApic               = 0,
110         IOApic                  = 1,
111         IRQSourceOverride       = 2,
112         NMI                     = 3,
113         LocalApicNMI            = 4,
114         LApicAddressOverride    = 5,
115         IOSApic                 = 6,
116         LocalSApic              = 7,
117         PlatformIRQSources      = 8
118 };
119
120 typedef struct acpi_madt_lapic {
121         u8 type;
122         u8 length;
123         u8 processor_id;
124         u8 apic_id;
125         u32 flags;
126 } __attribute__ ((packed)) acpi_madt_lapic_t;
127
128 typedef struct acpi_madt_lapic_nmi {
129         u8 type;
130         u8 length;
131         u8 processor_id;
132         u16 flags;
133         u8 lint;
134 } __attribute__ ((packed)) acpi_madt_lapic_nmi_t;
135
136
137 typedef struct acpi_madt_ioapic {
138         u8 type;
139         u8 length;
140         u8 ioapic_id;
141         u8 reserved;
142         u32 ioapic_addr;
143         u32 gsi_base;
144 } __attribute__ ((packed)) acpi_madt_ioapic_t;
145
146 typedef struct acpi_madt_irqoverride {
147         u8 type;
148         u8 length;
149         u8 bus;
150         u8 source;
151         u32 gsirq;
152         u16 flags;
153 } __attribute__ ((packed)) acpi_madt_irqoverride_t;
154
155
156 typedef struct acpi_fadt {
157         struct acpi_table_header header;
158         u32 firmware_ctrl;
159         u32 dsdt;
160         u8 res1;
161         u8 preferred_pm_profile;
162         u16 sci_int;
163         u32 smi_cmd;
164         u8 acpi_enable;
165         u8 acpi_disable;
166         u8 s4bios_req;
167         u8 pstate_cnt;
168         u32 pm1a_evt_blk;
169         u32 pm1b_evt_blk;
170         u32 pm1a_cnt_blk;
171         u32 pm1b_cnt_blk;
172         u32 pm2_cnt_blk;
173         u32 pm_tmr_blk;
174         u32 gpe0_blk;
175         u32 gpe1_blk;
176         u8 pm1_evt_len;
177         u8 pm1_cnt_len;
178         u8 pm2_cnt_len;
179         u8 pm_tmr_len;
180         u8 gpe0_blk_len;
181         u8 gpe1_blk_len;
182         u8 gpe1_base;
183         u8 cst_cnt;
184         u16 p_lvl2_lat;
185         u16 p_lvl3_lat;
186         u16 flush_size;
187         u16 flush_stride;
188         u8 duty_offset;
189         u8 duty_width;
190         u8 day_alrm;
191         u8 mon_alrm;
192         u8 century;
193         u16 iapc_boot_arch;
194         u8 res2;
195         u32 flags;
196         struct acpi_gen_regaddr reset_reg;
197         u8 reset_value;
198         u8 res3;
199         u8 res4;
200         u8 res5;
201         u32 x_firmware_ctl_l;
202         u32 x_firmware_ctl_h;
203         u32 x_dsdt_l;
204         u32 x_dsdt_h;
205         struct acpi_gen_regaddr x_pm1a_evt_blk;
206         struct acpi_gen_regaddr x_pm1b_evt_blk;
207         struct acpi_gen_regaddr x_pm1a_cnt_blk;
208         struct acpi_gen_regaddr x_pm1b_cnt_blk;
209         struct acpi_gen_regaddr x_pm2_cnt_blk;
210         struct acpi_gen_regaddr x_pm_tmr_blk;
211         struct acpi_gen_regaddr x_gpe0_blk;
212         struct acpi_gen_regaddr x_gpe1_blk;
213 } __attribute__ ((packed)) acpi_fadt_t;
214
215 typedef struct acpi_facs {
216         char signature[4];
217         u32 length;
218         u32 hardware_signature;
219         u32 firmware_waking_vector;
220         u32 global_lock;
221         u32 flags;
222         u32 x_firmware_waking_vector_l;
223         u32 x_firmware_waking_vector_h;
224         u8 version;
225         u8 resv[33];
226 } __attribute__ ((packed)) acpi_facs_t;
227
228 /* These are implemented by the target port */
229 unsigned long write_acpi_tables(unsigned long addr);
230 unsigned long acpi_dump_apics(unsigned long current);
231
232
233 /* These can be used by the target port */
234 u8 acpi_checksum(u8 *table, u32 length);
235 void acpi_add_table(acpi_rsdt_t *rsdt, void *table);
236 int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic);
237 int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,u32 gsi_base);
238 void acpi_create_madt(acpi_madt_t *madt);
239 void acpi_create_hpet(acpi_hpet_t *hpet);
240 void acpi_create_facs(acpi_facs_t *facs);
241 void acpi_write_rsdt(acpi_rsdt_t *rsdt);
242 void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt);
243
244 #define ACPI_WRITE_MADT_IOAPIC(dev,id)                  \
245 do {                                                    \
246         struct resource *res;                           \
247         res = find_resource(dev, PCI_BASE_ADDRESS_0);   \
248         if (!res) break;                                \
249         current += acpi_create_madt_ioapic(             \
250                 (acpi_madt_ioapic_t *)current,          \
251                 id, res->base, gsi_base);               \
252         gsi_base+=4;                                    \
253 } while(0);
254
255 #define IO_APIC_ADDR    0xfec00000UL
256
257 #else // HAVE_ACPI_TABLES
258
259 #define write_acpi_tables(start) (start)
260
261 #endif
262
263 #endif