1 /*
2  * acpi.h - ACPI Interface
3  *
4  * Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
5  *
6  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23  */
24 
25 #ifndef _LINUX_ACPI_H
26 #define _LINUX_ACPI_H
27 
28 #ifndef _LINUX
29 #define _LINUX
30 #endif
31 
32 #include <linux/list.h>
33 
34 #include <acpi/acpi.h>
35 #include <acpi/acpi_bus.h>
36 #include <acpi/acpi_drivers.h>
37 #include <asm/acpi.h>
38 
39 
40 #ifdef CONFIG_ACPI_BOOT
41 
42 enum acpi_irq_model_id {
43 	ACPI_IRQ_MODEL_PIC = 0,
44 	ACPI_IRQ_MODEL_IOAPIC,
45 	ACPI_IRQ_MODEL_IOSAPIC,
46 	ACPI_IRQ_MODEL_COUNT
47 };
48 
49 extern enum acpi_irq_model_id	acpi_irq_model;
50 
51 
52 /* Root System Description Pointer (RSDP) */
53 
54 struct acpi_table_rsdp {
55 	char			signature[8];
56 	u8			checksum;
57 	char			oem_id[6];
58 	u8			revision;
59 	u32			rsdt_address;
60 } __attribute__ ((packed));
61 
62 struct acpi20_table_rsdp {
63 	char			signature[8];
64 	u8			checksum;
65 	char			oem_id[6];
66 	u8			revision;
67 	u32			rsdt_address;
68 	u32			length;
69 	u64			xsdt_address;
70 	u8			ext_checksum;
71 	u8			reserved[3];
72 } __attribute__ ((packed));
73 
74 typedef struct {
75 	u8			type;
76 	u8			length;
77 } __attribute__ ((packed)) acpi_table_entry_header;
78 
79 /* Root System Description Table (RSDT) */
80 
81 struct acpi_table_rsdt {
82 	struct acpi_table_header header;
83 	u32			entry[1];
84 } __attribute__ ((packed));
85 
86 /* Extended System Description Table (XSDT) */
87 
88 struct acpi_table_xsdt {
89 	struct acpi_table_header header;
90 	u64			entry[1];
91 } __attribute__ ((packed));
92 
93 /* Fixed ACPI Description Table (FADT) */
94 
95 struct acpi_table_fadt {
96 	struct acpi_table_header header;
97 	u32 facs_addr;
98 	u32 dsdt_addr;
99 	/* ... */
100 } __attribute__ ((packed));
101 
102 /* Multiple APIC Description Table (MADT) */
103 
104 struct acpi_table_madt {
105 	struct acpi_table_header header;
106 	u32			lapic_address;
107 	struct {
108 		u32			pcat_compat:1;
109 		u32			reserved:31;
110 	}			flags;
111 } __attribute__ ((packed));
112 
113 enum acpi_madt_entry_id {
114 	ACPI_MADT_LAPIC = 0,
115 	ACPI_MADT_IOAPIC,
116 	ACPI_MADT_INT_SRC_OVR,
117 	ACPI_MADT_NMI_SRC,
118 	ACPI_MADT_LAPIC_NMI,
119 	ACPI_MADT_LAPIC_ADDR_OVR,
120 	ACPI_MADT_IOSAPIC,
121 	ACPI_MADT_LSAPIC,
122 	ACPI_MADT_PLAT_INT_SRC,
123 	ACPI_MADT_ENTRY_COUNT
124 };
125 
126 typedef struct {
127 	u16			polarity:2;
128 	u16			trigger:2;
129 	u16			reserved:12;
130 } __attribute__ ((packed)) acpi_interrupt_flags;
131 
132 struct acpi_table_lapic {
133 	acpi_table_entry_header	header;
134 	u8			acpi_id;
135 	u8			id;
136 	struct {
137 		u32			enabled:1;
138 		u32			reserved:31;
139 	}			flags;
140 } __attribute__ ((packed));
141 
142 struct acpi_table_ioapic {
143 	acpi_table_entry_header	header;
144 	u8			id;
145 	u8			reserved;
146 	u32			address;
147 	u32			global_irq_base;
148 } __attribute__ ((packed));
149 
150 struct acpi_table_int_src_ovr {
151 	acpi_table_entry_header	header;
152 	u8			bus;
153 	u8			bus_irq;
154 	u32			global_irq;
155 	acpi_interrupt_flags	flags;
156 } __attribute__ ((packed));
157 
158 struct acpi_table_nmi_src {
159 	acpi_table_entry_header	header;
160 	acpi_interrupt_flags	flags;
161 	u32			global_irq;
162 } __attribute__ ((packed));
163 
164 struct acpi_table_lapic_nmi {
165 	acpi_table_entry_header	header;
166 	u8			acpi_id;
167 	acpi_interrupt_flags	flags;
168 	u8			lint;
169 } __attribute__ ((packed));
170 
171 struct acpi_table_lapic_addr_ovr {
172 	acpi_table_entry_header	header;
173 	u8			reserved[2];
174 	u64			address;
175 } __attribute__ ((packed));
176 
177 struct acpi_table_iosapic {
178 	acpi_table_entry_header	header;
179 	u8			id;
180 	u8			reserved;
181 	u32			global_irq_base;
182 	u64			address;
183 } __attribute__ ((packed));
184 
185 struct acpi_table_lsapic {
186 	acpi_table_entry_header	header;
187 	u8			acpi_id;
188 	u8			id;
189 	u8			eid;
190 	u8			reserved[3];
191 	struct {
192 		u32			enabled:1;
193 		u32			reserved:31;
194 	}			flags;
195 } __attribute__ ((packed));
196 
197 struct acpi_table_plat_int_src {
198 	acpi_table_entry_header	header;
199 	acpi_interrupt_flags	flags;
200 	u8			type;	/* See acpi_interrupt_type */
201 	u8			id;
202 	u8			eid;
203 	u8			iosapic_vector;
204 	u32			global_irq;
205 	u32			reserved;
206 } __attribute__ ((packed));
207 
208 enum acpi_interrupt_id {
209 	ACPI_INTERRUPT_PMI	= 1,
210 	ACPI_INTERRUPT_INIT,
211 	ACPI_INTERRUPT_CPEI,
212 	ACPI_INTERRUPT_COUNT
213 };
214 
215 #define	ACPI_SPACE_MEM		0
216 
217 struct acpi_gen_regaddr {
218 	u8  space_id;
219 	u8  bit_width;
220 	u8  bit_offset;
221 	u8  resv;
222 	u32 addrl;
223 	u32 addrh;
224 } __attribute__ ((packed));
225 
226 struct acpi_table_hpet {
227 	struct acpi_table_header header;
228 	u32 id;
229 	struct acpi_gen_regaddr addr;
230 	u8 number;
231 	u16 min_tick;
232 	u8 page_protect;
233 } __attribute__ ((packed));
234 
235 /*
236  * System Resource Affinity Table (SRAT)
237  *   see http://www.microsoft.com/hwdev/design/srat.htm
238  */
239 
240 struct acpi_table_srat {
241 	struct acpi_table_header header;
242 	u32			table_revision;
243 	u64			reserved;
244 } __attribute__ ((packed));
245 
246 enum acpi_srat_entry_id {
247 	ACPI_SRAT_PROCESSOR_AFFINITY = 0,
248 	ACPI_SRAT_MEMORY_AFFINITY,
249 	ACPI_SRAT_ENTRY_COUNT
250 };
251 
252 struct acpi_table_processor_affinity {
253 	acpi_table_entry_header	header;
254 	u8			proximity_domain;
255 	u8			apic_id;
256 	struct {
257 		u32			enabled:1;
258 		u32			reserved:31;
259 	}			flags;
260 	u8			lsapic_eid;
261 	u8			reserved[7];
262 } __attribute__ ((packed));
263 
264 struct acpi_table_memory_affinity {
265 	acpi_table_entry_header	header;
266 	u8			proximity_domain;
267 	u8			reserved1[5];
268 	u32			base_addr_lo;
269 	u32			base_addr_hi;
270 	u32			length_lo;
271 	u32			length_hi;
272 	u32			memory_type;	/* See acpi_address_range_id */
273 	struct {
274 		u32			enabled:1;
275 		u32			hot_pluggable:1;
276 		u32			reserved:30;
277 	}			flags;
278 	u64			reserved2;
279 } __attribute__ ((packed));
280 
281 enum acpi_address_range_id {
282 	ACPI_ADDRESS_RANGE_MEMORY = 1,
283 	ACPI_ADDRESS_RANGE_RESERVED = 2,
284 	ACPI_ADDRESS_RANGE_ACPI = 3,
285 	ACPI_ADDRESS_RANGE_NVS	= 4,
286 	ACPI_ADDRESS_RANGE_COUNT
287 };
288 
289 /*
290  * System Locality Information Table (SLIT)
291  *   see http://devresource.hp.com/devresource/docs/techpapers/ia64/slit.pdf
292  */
293 
294 struct acpi_table_slit {
295 	struct acpi_table_header header;
296 	u64			localities;
297 	u8			entry[1];	/* real size = localities^2 */
298 } __attribute__ ((packed));
299 
300 /* Smart Battery Description Table (SBST) */
301 
302 struct acpi_table_sbst {
303 	struct acpi_table_header header;
304 	u32			warning;	/* Warn user */
305 	u32			low;		/* Critical sleep */
306 	u32			critical;	/* Critical shutdown */
307 } __attribute__ ((packed));
308 
309 /* Embedded Controller Boot Resources Table (ECDT) */
310 
311 struct acpi_table_ecdt {
312 	struct acpi_table_header	header;
313 	struct acpi_generic_address	ec_control;
314 	struct acpi_generic_address	ec_data;
315 	u32				uid;
316 	u8				gpe_bit;
317 	char				ec_id[0];
318 } __attribute__ ((packed));
319 
320 /* Table Handlers */
321 
322 /* PCI MMCONFIG */
323 struct acpi_table_mcfg {
324 	struct acpi_table_header	header;
325 	u8				reserved[8];
326 	u32				base_address;
327 	u32				base_reserved;
328 } __attribute__ ((packed));
329 
330 enum acpi_table_id {
331 	ACPI_TABLE_UNKNOWN = 0,
332 	ACPI_APIC,
333 	ACPI_BOOT,
334 	ACPI_DBGP,
335 	ACPI_DSDT,
336 	ACPI_ECDT,
337 	ACPI_ETDT,
338 	ACPI_FADT,
339 	ACPI_FACS,
340 	ACPI_OEMX,
341 	ACPI_PSDT,
342 	ACPI_SBST,
343 	ACPI_SLIT,
344 	ACPI_SPCR,
345 	ACPI_SRAT,
346 	ACPI_SSDT,
347 	ACPI_SPMI,
348 	ACPI_HPET,
349 	ACPI_MCFG,
350 	ACPI_TABLE_COUNT
351 };
352 
353 typedef int (*acpi_table_handler) (unsigned long phys_addr, unsigned long size);
354 
355 extern acpi_table_handler acpi_table_ops[ACPI_TABLE_COUNT];
356 
357 typedef int (*acpi_madt_entry_handler) (acpi_table_entry_header *header);
358 
359 char * __acpi_map_table (unsigned long phys_addr, unsigned long size);
360 unsigned long acpi_find_rsdp (void);
361 int acpi_boot_init (void);
362 int acpi_numa_init (void);
363 
364 int acpi_table_init (void);
365 int acpi_table_parse (enum acpi_table_id id, acpi_table_handler handler);
366 int acpi_get_table_header_early (enum acpi_table_id id, struct acpi_table_header **header);
367 int acpi_table_parse_madt (enum acpi_madt_entry_id id, acpi_madt_entry_handler handler);
368 int acpi_table_parse_srat (enum acpi_srat_entry_id id, acpi_madt_entry_handler handler);
369 void acpi_table_print (struct acpi_table_header *header, unsigned long phys_addr);
370 void acpi_table_print_madt_entry (acpi_table_entry_header *madt);
371 void acpi_table_print_srat_entry (acpi_table_entry_header *srat);
372 
373 /* the following four functions are architecture-dependent */
374 void acpi_numa_slit_init (struct acpi_table_slit *slit);
375 void acpi_numa_processor_affinity_init (struct acpi_table_processor_affinity *pa);
376 void acpi_numa_memory_affinity_init (struct acpi_table_memory_affinity *ma);
377 void acpi_numa_arch_fixup(void);
378 
379 #else /*!CONFIG_ACPI_BOOT*/
380 
acpi_boot_init(void)381 static inline int acpi_boot_init(void)
382 {
383 	return 0;
384 }
385 
386 #endif /*!CONFIG_ACPI_BOOT*/
387 
388 
389 #ifdef CONFIG_ACPI_PCI
390 
391 struct acpi_prt_entry {
392 	struct list_head	node;
393 	struct acpi_pci_id	id;
394 	u8			pin;
395 	struct {
396 		acpi_handle		handle;
397 		u32			index;
398 	}			link;
399 	u32			irq;
400 };
401 
402 struct acpi_prt_list {
403 	int			count;
404 	struct list_head	entries;
405 };
406 
407 extern struct acpi_prt_list	acpi_prt;
408 
409 struct pci_dev;
410 
411 int acpi_pci_irq_enable (struct pci_dev *dev);
412 int acpi_pci_irq_init (void);
413 
414 struct acpi_pci_driver {
415 	struct acpi_pci_driver *next;
416 	int (*add)(acpi_handle handle);
417 	void (*remove)(acpi_handle handle);
418 };
419 
420 int acpi_pci_register_driver(struct acpi_pci_driver *driver);
421 void acpi_pci_unregister_driver(struct acpi_pci_driver *driver);
422 
423 #endif /*CONFIG_ACPI_PCI*/
424 
425 #ifdef CONFIG_ACPI_EC
426 
427 int ec_read(u8 addr, u8 *val);
428 int ec_write(u8 addr, u8 val);
429 
430 #endif /*CONFIG_ACPI_EC*/
431 
432 #ifdef CONFIG_ACPI_INTERPRETER
433 
434 int acpi_blacklisted(void);
435 
436 #else /*!CONFIG_ACPI_INTERPRETER*/
437 
acpi_blacklisted(void)438 static inline int acpi_blacklisted(void)
439 {
440 	return 0;
441 }
442 
443 #endif /*!CONFIG_ACPI_INTERPRETER*/
444 
445 #endif /*_LINUX_ACPI_H*/
446