Revision: linuxbios@linuxbios.org--devel/freebios--devel--2.0--patch-36
[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
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 typedef struct acpi_madt {
104         struct acpi_table_header header;
105         u32 lapic_addr;
106         u32 flags;
107 } __attribute__ ((packed)) acpi_madt_t;
108
109 enum acpi_apic_types {
110         LocalApic               = 0,
111         IOApic                  = 1,
112         IRQSourceOverride       = 2,
113         NMI                     = 3,
114         LocalApicNMI            = 4,
115         LApicAddressOverride    = 5,
116         IOSApic                 = 6,
117         LocalSApic              = 7,
118         PlatformIRQSources      = 8
119 };
120
121 typedef struct acpi_madt_lapic {
122         u8 type;
123         u8 length;
124         u8 processor_id;
125         u8 apic_id;
126         u32 flags;
127 } __attribute__ ((packed)) acpi_madt_lapic_t;
128
129 typedef struct acpi_madt_lapic_nmi {
130         u8 type;
131         u8 length;
132         u8 processor_id;
133         u16 flags;
134         u8 lint;
135 } __attribute__ ((packed)) acpi_madt_lapic_nmi_t;
136
137
138 typedef struct acpi_madt_ioapic {
139         u8 type;
140         u8 length;
141         u8 ioapic_id;
142         u8 reserved;
143         u32 ioapic_addr;
144         u32 gsi_base;
145 } __attribute__ ((packed)) acpi_madt_ioapic_t;
146
147 typedef struct acpi_madt_irqoverride {
148         u8 type;
149         u8 length;
150         u8 bus;
151         u8 source;
152         u32 gsirq;
153         u16 flags;
154 } __attribute__ ((packed)) acpi_madt_irqoverride_t;
155
156
157 typedef struct acpi_fadt {
158         struct acpi_table_header header;
159         u32 firmware_ctrl;
160         u32 dsdt;
161         u8 res1;
162         u8 preferred_pm_profile;
163         u16 sci_int;
164         u32 smi_cmd;
165         u8 acpi_enable;
166         u8 acpi_disable;
167         u8 s4bios_req;
168         u8 pstate_cnt;
169         u32 pm1a_evt_blk;
170         u32 pm1b_evt_blk;
171         u32 pm1a_cnt_blk;
172         u32 pm1b_cnt_blk;
173         u32 pm2_cnt_blk;
174         u32 pm_tmr_blk;
175         u32 gpe0_blk;
176         u32 gpe1_blk;
177         u8 pm1_evt_len;
178         u8 pm1_cnt_len;
179         u8 pm2_cnt_len;
180         u8 pm_tmr_len;
181         u8 gpe0_blk_len;
182         u8 gpe1_blk_len;
183         u8 gpe1_base;
184         u8 cst_cnt;
185         u16 p_lvl2_lat;
186         u16 p_lvl3_lat;
187         u16 flush_size;
188         u16 flush_stride;
189         u8 duty_offset;
190         u8 duty_width;
191         u8 day_alrm;
192         u8 mon_alrm;
193         u8 century;
194         u16 iapc_boot_arch;
195         u8 res2;
196         u32 flags;
197         struct acpi_gen_regaddr reset_reg;
198         u8 reset_value;
199         u8 res3;
200         u8 res4;
201         u8 res5;
202         u32 x_firmware_ctl_l;
203         u32 x_firmware_ctl_h;
204         u32 x_dsdt_l;
205         u32 x_dsdt_h;
206         struct acpi_gen_regaddr x_pm1a_evt_blk;
207         struct acpi_gen_regaddr x_pm1b_evt_blk;
208         struct acpi_gen_regaddr x_pm1a_cnt_blk;
209         struct acpi_gen_regaddr x_pm1b_cnt_blk;
210         struct acpi_gen_regaddr x_pm2_cnt_blk;
211         struct acpi_gen_regaddr x_pm_tmr_blk;
212         struct acpi_gen_regaddr x_gpe0_blk;
213         struct acpi_gen_regaddr x_gpe1_blk;
214 } __attribute__ ((packed)) acpi_fadt_t;
215
216 typedef struct acpi_facs {
217         char signature[4];
218         u32 length;
219         u32 hardware_signature;
220         u32 firmware_waking_vector;
221         u32 global_lock;
222         u32 flags;
223         u32 x_firmware_waking_vector_l;
224         u32 x_firmware_waking_vector_h;
225         u8 version;
226         u8 resv[33];
227 } __attribute__ ((packed)) acpi_facs_t;
228
229 /* These are implemented by the target port */
230 unsigned long write_acpi_tables(unsigned long addr);
231 unsigned long acpi_dump_apics(unsigned long current);
232
233
234 /* These can be used by the target port */
235 u8 acpi_checksum(u8 *table, u32 length);
236 void acpi_add_table(acpi_rsdt_t *rsdt, void *table);
237 int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic);
238 int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,u32 gsi_base);
239 void acpi_create_madt(acpi_madt_t *madt);
240 void acpi_create_hpet(acpi_hpet_t *hpet);
241 void acpi_create_facs(acpi_facs_t *facs);
242 void acpi_write_rsdt(acpi_rsdt_t *rsdt);
243 void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt);
244
245 #define ACPI_WRITE_MADT_IOAPIC(dev,id)                  \
246 do {                                                    \
247         struct resource *res;                           \
248         res = find_resource(dev, PCI_BASE_ADDRESS_0);   \
249         if (!res) break;                                \
250         current += acpi_create_madt_ioapic(             \
251                 (acpi_madt_ioapic_t *)current,          \
252                 id, res->base, gsi_base);               \
253         gsi_base+=4;                                    \
254 } while(0);
255
256 #define IO_APIC_ADDR    0xfec00000UL
257
258 #else // HAVE_ACPI_TABLES
259
260 #define write_acpi_tables(start) (start)
261
262 #endif
263
264 #endif