Merge rsync://rsync.kernel.org/pub/scm/linux/kernel/git/paulus/ppc64-2.6
[pandora-kernel.git] / include / linux / acpi.h
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 #include <linux/config.h>
29
30 #ifdef  CONFIG_ACPI
31
32 #ifndef _LINUX
33 #define _LINUX
34 #endif
35
36 #include <linux/list.h>
37
38 #include <acpi/acpi.h>
39 #include <acpi/acpi_bus.h>
40 #include <acpi/acpi_drivers.h>
41 #include <asm/acpi.h>
42
43
44 #ifdef CONFIG_ACPI_BOOT
45
46 enum acpi_irq_model_id {
47         ACPI_IRQ_MODEL_PIC = 0,
48         ACPI_IRQ_MODEL_IOAPIC,
49         ACPI_IRQ_MODEL_IOSAPIC,
50         ACPI_IRQ_MODEL_COUNT
51 };
52
53 extern enum acpi_irq_model_id   acpi_irq_model;
54
55
56 /* Root System Description Pointer (RSDP) */
57
58 struct acpi_table_rsdp {
59         char                    signature[8];
60         u8                      checksum;
61         char                    oem_id[6];
62         u8                      revision;
63         u32                     rsdt_address;
64 } __attribute__ ((packed));
65
66 struct acpi20_table_rsdp {
67         char                    signature[8];
68         u8                      checksum;
69         char                    oem_id[6];
70         u8                      revision;
71         u32                     rsdt_address;
72         u32                     length;
73         u64                     xsdt_address;
74         u8                      ext_checksum;
75         u8                      reserved[3];
76 } __attribute__ ((packed));
77
78 typedef struct {
79         u8                      type;
80         u8                      length;
81 } __attribute__ ((packed)) acpi_table_entry_header;
82
83 /* Root System Description Table (RSDT) */
84
85 struct acpi_table_rsdt {
86         struct acpi_table_header header;
87         u32                     entry[8];
88 } __attribute__ ((packed));
89
90 /* Extended System Description Table (XSDT) */
91
92 struct acpi_table_xsdt {
93         struct acpi_table_header header;
94         u64                     entry[1];
95 } __attribute__ ((packed));
96
97 /* Fixed ACPI Description Table (FADT) */
98
99 struct acpi_table_fadt {
100         struct acpi_table_header header;
101         u32 facs_addr;
102         u32 dsdt_addr;
103         /* ... */
104 } __attribute__ ((packed));
105
106 /* Multiple APIC Description Table (MADT) */
107
108 struct acpi_table_madt {
109         struct acpi_table_header header;
110         u32                     lapic_address;
111         struct {
112                 u32                     pcat_compat:1;
113                 u32                     reserved:31;
114         }                       flags;
115 } __attribute__ ((packed));
116
117 enum acpi_madt_entry_id {
118         ACPI_MADT_LAPIC = 0,
119         ACPI_MADT_IOAPIC,
120         ACPI_MADT_INT_SRC_OVR,
121         ACPI_MADT_NMI_SRC,
122         ACPI_MADT_LAPIC_NMI,
123         ACPI_MADT_LAPIC_ADDR_OVR,
124         ACPI_MADT_IOSAPIC,
125         ACPI_MADT_LSAPIC,
126         ACPI_MADT_PLAT_INT_SRC,
127         ACPI_MADT_ENTRY_COUNT
128 };
129
130 typedef struct {
131         u16                     polarity:2;
132         u16                     trigger:2;
133         u16                     reserved:12;
134 } __attribute__ ((packed)) acpi_interrupt_flags;
135
136 struct acpi_table_lapic {
137         acpi_table_entry_header header;
138         u8                      acpi_id;
139         u8                      id;
140         struct {
141                 u32                     enabled:1;
142                 u32                     reserved:31;
143         }                       flags;
144 } __attribute__ ((packed));
145
146 struct acpi_table_ioapic {
147         acpi_table_entry_header header;
148         u8                      id;
149         u8                      reserved;
150         u32                     address;
151         u32                     global_irq_base;
152 } __attribute__ ((packed));
153
154 struct acpi_table_int_src_ovr {
155         acpi_table_entry_header header;
156         u8                      bus;
157         u8                      bus_irq;
158         u32                     global_irq;
159         acpi_interrupt_flags    flags;
160 } __attribute__ ((packed));
161
162 struct acpi_table_nmi_src {
163         acpi_table_entry_header header;
164         acpi_interrupt_flags    flags;
165         u32                     global_irq;
166 } __attribute__ ((packed));
167
168 struct acpi_table_lapic_nmi {
169         acpi_table_entry_header header;
170         u8                      acpi_id;
171         acpi_interrupt_flags    flags;
172         u8                      lint;
173 } __attribute__ ((packed));
174
175 struct acpi_table_lapic_addr_ovr {
176         acpi_table_entry_header header;
177         u8                      reserved[2];
178         u64                     address;
179 } __attribute__ ((packed));
180
181 struct acpi_table_iosapic {
182         acpi_table_entry_header header;
183         u8                      id;
184         u8                      reserved;
185         u32                     global_irq_base;
186         u64                     address;
187 } __attribute__ ((packed));
188
189 struct acpi_table_lsapic {
190         acpi_table_entry_header header;
191         u8                      acpi_id;
192         u8                      id;
193         u8                      eid;
194         u8                      reserved[3];
195         struct {
196                 u32                     enabled:1;
197                 u32                     reserved:31;
198         }                       flags;
199 } __attribute__ ((packed));
200
201 struct acpi_table_plat_int_src {
202         acpi_table_entry_header header;
203         acpi_interrupt_flags    flags;
204         u8                      type;   /* See acpi_interrupt_type */
205         u8                      id;
206         u8                      eid;
207         u8                      iosapic_vector;
208         u32                     global_irq;
209         u32                     reserved;
210 } __attribute__ ((packed));
211
212 enum acpi_interrupt_id {
213         ACPI_INTERRUPT_PMI      = 1,
214         ACPI_INTERRUPT_INIT,
215         ACPI_INTERRUPT_CPEI,
216         ACPI_INTERRUPT_COUNT
217 };
218
219 #define ACPI_SPACE_MEM          0
220
221 struct acpi_gen_regaddr {
222         u8  space_id;
223         u8  bit_width;
224         u8  bit_offset;
225         u8  resv;
226         u32 addrl;
227         u32 addrh;
228 } __attribute__ ((packed));
229
230 struct acpi_table_hpet {
231         struct acpi_table_header header;
232         u32 id;
233         struct acpi_gen_regaddr addr;
234         u8 number;
235         u16 min_tick;
236         u8 page_protect;
237 } __attribute__ ((packed));
238
239 /*
240  * Simple Boot Flags
241  * http://www.microsoft.com/whdc/hwdev/resources/specs/simp_bios.mspx
242  */
243 struct acpi_table_sbf
244 {
245         u8 sbf_signature[4];
246         u32 sbf_len;
247         u8 sbf_revision;
248         u8 sbf_csum;
249         u8 sbf_oemid[6];
250         u8 sbf_oemtable[8];
251         u8 sbf_revdata[4];
252         u8 sbf_creator[4];
253         u8 sbf_crearev[4];
254         u8 sbf_cmos;
255         u8 sbf_spare[3];
256 } __attribute__ ((packed));
257
258 /*
259  * System Resource Affinity Table (SRAT)
260  * http://www.microsoft.com/whdc/hwdev/platform/proc/SRAT.mspx
261  */
262
263 struct acpi_table_srat {
264         struct acpi_table_header header;
265         u32                     table_revision;
266         u64                     reserved;
267 } __attribute__ ((packed));
268
269 enum acpi_srat_entry_id {
270         ACPI_SRAT_PROCESSOR_AFFINITY = 0,
271         ACPI_SRAT_MEMORY_AFFINITY,
272         ACPI_SRAT_ENTRY_COUNT
273 };
274
275 struct acpi_table_processor_affinity {
276         acpi_table_entry_header header;
277         u8                      proximity_domain;
278         u8                      apic_id;
279         struct {
280                 u32                     enabled:1;
281                 u32                     reserved:31;
282         }                       flags;
283         u8                      lsapic_eid;
284         u8                      reserved[7];
285 } __attribute__ ((packed));
286
287 struct acpi_table_memory_affinity {
288         acpi_table_entry_header header;
289         u8                      proximity_domain;
290         u8                      reserved1[5];
291         u32                     base_addr_lo;
292         u32                     base_addr_hi;
293         u32                     length_lo;
294         u32                     length_hi;
295         u32                     memory_type;    /* See acpi_address_range_id */
296         struct {
297                 u32                     enabled:1;
298                 u32                     hot_pluggable:1;
299                 u32                     reserved:30;
300         }                       flags;
301         u64                     reserved2;
302 } __attribute__ ((packed));
303
304 enum acpi_address_range_id {
305         ACPI_ADDRESS_RANGE_MEMORY = 1,
306         ACPI_ADDRESS_RANGE_RESERVED = 2,
307         ACPI_ADDRESS_RANGE_ACPI = 3,
308         ACPI_ADDRESS_RANGE_NVS  = 4,
309         ACPI_ADDRESS_RANGE_COUNT
310 };
311
312 /*
313  * System Locality Information Table (SLIT)
314  *   see http://devresource.hp.com/devresource/docs/techpapers/ia64/slit.pdf
315  */
316
317 struct acpi_table_slit {
318         struct acpi_table_header header;
319         u64                     localities;
320         u8                      entry[1];       /* real size = localities^2 */
321 } __attribute__ ((packed));
322
323 /* Smart Battery Description Table (SBST) */
324
325 struct acpi_table_sbst {
326         struct acpi_table_header header;
327         u32                     warning;        /* Warn user */
328         u32                     low;            /* Critical sleep */
329         u32                     critical;       /* Critical shutdown */
330 } __attribute__ ((packed));
331
332 /* Embedded Controller Boot Resources Table (ECDT) */
333
334 struct acpi_table_ecdt {
335         struct acpi_table_header        header;
336         struct acpi_generic_address     ec_control;
337         struct acpi_generic_address     ec_data;
338         u32                             uid;
339         u8                              gpe_bit;
340         char                            ec_id[0];
341 } __attribute__ ((packed));
342
343 /* PCI MMCONFIG */
344
345 /* Defined in PCI Firmware Specification 3.0 */
346 struct acpi_table_mcfg_config {
347         u32                             base_address;
348         u32                             base_reserved;
349         u16                             pci_segment_group_number;
350         u8                              start_bus_number;
351         u8                              end_bus_number;
352         u8                              reserved[4];
353 } __attribute__ ((packed));
354 struct acpi_table_mcfg {
355         struct acpi_table_header        header;
356         u8                              reserved[8];
357         struct acpi_table_mcfg_config   config[0];
358 } __attribute__ ((packed));
359
360 /* Table Handlers */
361
362 enum acpi_table_id {
363         ACPI_TABLE_UNKNOWN = 0,
364         ACPI_APIC,
365         ACPI_BOOT,
366         ACPI_DBGP,
367         ACPI_DSDT,
368         ACPI_ECDT,
369         ACPI_ETDT,
370         ACPI_FADT,
371         ACPI_FACS,
372         ACPI_OEMX,
373         ACPI_PSDT,
374         ACPI_SBST,
375         ACPI_SLIT,
376         ACPI_SPCR,
377         ACPI_SRAT,
378         ACPI_SSDT,
379         ACPI_SPMI,
380         ACPI_HPET,
381         ACPI_MCFG,
382         ACPI_TABLE_COUNT
383 };
384
385 typedef int (*acpi_table_handler) (unsigned long phys_addr, unsigned long size);
386
387 extern acpi_table_handler acpi_table_ops[ACPI_TABLE_COUNT];
388
389 typedef int (*acpi_madt_entry_handler) (acpi_table_entry_header *header, const unsigned long end);
390
391 char * __acpi_map_table (unsigned long phys_addr, unsigned long size);
392 unsigned long acpi_find_rsdp (void);
393 int acpi_boot_init (void);
394 int acpi_boot_table_init (void);
395 int acpi_numa_init (void);
396
397 int acpi_table_init (void);
398 int acpi_table_parse (enum acpi_table_id id, acpi_table_handler handler);
399 int acpi_get_table_header_early (enum acpi_table_id id, struct acpi_table_header **header);
400 int acpi_table_parse_madt (enum acpi_madt_entry_id id, acpi_madt_entry_handler handler, unsigned int max_entries);
401 int acpi_table_parse_srat (enum acpi_srat_entry_id id, acpi_madt_entry_handler handler, unsigned int max_entries);
402 int acpi_parse_mcfg (unsigned long phys_addr, unsigned long size);
403 void acpi_table_print (struct acpi_table_header *header, unsigned long phys_addr);
404 void acpi_table_print_madt_entry (acpi_table_entry_header *madt);
405 void acpi_table_print_srat_entry (acpi_table_entry_header *srat);
406
407 /* the following four functions are architecture-dependent */
408 void acpi_numa_slit_init (struct acpi_table_slit *slit);
409 void acpi_numa_processor_affinity_init (struct acpi_table_processor_affinity *pa);
410 void acpi_numa_memory_affinity_init (struct acpi_table_memory_affinity *ma);
411 void acpi_numa_arch_fixup(void);
412
413 #ifdef CONFIG_ACPI_HOTPLUG_CPU
414 /* Arch dependent functions for cpu hotplug support */
415 int acpi_map_lsapic(acpi_handle handle, int *pcpu);
416 int acpi_unmap_lsapic(int cpu);
417 #endif /* CONFIG_ACPI_HOTPLUG_CPU */
418
419 int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base);
420 int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base);
421
422 extern int acpi_mp_config;
423
424 extern struct acpi_table_mcfg_config *pci_mmcfg_config;
425 extern int pci_mmcfg_config_num;
426
427 extern int sbf_port ;
428
429 #else   /*!CONFIG_ACPI_BOOT*/
430
431 #define acpi_mp_config  0
432
433 static inline int acpi_boot_init(void)
434 {
435         return 0;
436 }
437
438 static inline int acpi_boot_table_init(void)
439 {
440         return 0;
441 }
442
443 #endif  /*!CONFIG_ACPI_BOOT*/
444
445 unsigned int acpi_register_gsi (u32 gsi, int edge_level, int active_high_low);
446 int acpi_gsi_to_irq (u32 gsi, unsigned int *irq);
447
448 /*
449  * This function undoes the effect of one call to acpi_register_gsi().
450  * If this matches the last registration, any IRQ resources for gsi
451  * are freed.
452  */
453 #ifdef CONFIG_ACPI_DEALLOCATE_IRQ
454 void acpi_unregister_gsi (u32 gsi);
455 #endif
456
457 #ifdef CONFIG_ACPI_PCI
458
459 struct acpi_prt_entry {
460         struct list_head        node;
461         struct acpi_pci_id      id;
462         u8                      pin;
463         struct {
464                 acpi_handle             handle;
465                 u32                     index;
466         }                       link;
467         u32                     irq;
468 };
469
470 struct acpi_prt_list {
471         int                     count;
472         struct list_head        entries;
473 };
474
475 struct pci_dev;
476
477 int acpi_pci_irq_enable (struct pci_dev *dev);
478 void acpi_penalize_isa_irq(int irq);
479
480 #ifdef CONFIG_ACPI_DEALLOCATE_IRQ
481 void acpi_pci_irq_disable (struct pci_dev *dev);
482 #endif
483
484 struct acpi_pci_driver {
485         struct acpi_pci_driver *next;
486         int (*add)(acpi_handle handle);
487         void (*remove)(acpi_handle handle);
488 };
489
490 int acpi_pci_register_driver(struct acpi_pci_driver *driver);
491 void acpi_pci_unregister_driver(struct acpi_pci_driver *driver);
492
493 #endif /*CONFIG_ACPI_PCI*/
494
495 #ifdef CONFIG_ACPI_EC
496
497 extern int ec_read(u8 addr, u8 *val);
498 extern int ec_write(u8 addr, u8 val);
499
500 #endif /*CONFIG_ACPI_EC*/
501
502 #ifdef CONFIG_ACPI_INTERPRETER
503
504 extern int acpi_blacklisted(void);
505 extern void acpi_bios_year(char *s);
506
507 #else /*!CONFIG_ACPI_INTERPRETER*/
508
509 static inline int acpi_blacklisted(void)
510 {
511         return 0;
512 }
513
514 #endif /*!CONFIG_ACPI_INTERPRETER*/
515
516 #define ACPI_CSTATE_LIMIT_DEFINED       /* for driver builds */
517 #ifdef  CONFIG_ACPI
518
519 /*
520  * Set highest legal C-state
521  * 0: C0 okay, but not C1
522  * 1: C1 okay, but not C2
523  * 2: C2 okay, but not C3 etc.
524  */
525
526 extern unsigned int max_cstate;
527
528 static inline unsigned int acpi_get_cstate_limit(void)
529 {
530         return max_cstate;
531 }
532 static inline void acpi_set_cstate_limit(unsigned int new_limit)
533 {
534         max_cstate = new_limit;
535         return;
536 }
537 #else
538 static inline unsigned int acpi_get_cstate_limit(void) { return 0; }
539 static inline void acpi_set_cstate_limit(unsigned int new_limit) { return; }
540 #endif
541
542 #ifdef CONFIG_ACPI_NUMA
543 int acpi_get_pxm(acpi_handle handle);
544 #else
545 static inline int acpi_get_pxm(acpi_handle handle)
546 {
547         return 0;
548 }
549 #endif
550
551 extern int pnpacpi_disabled;
552
553 #endif  /* CONFIG_ACPI */
554 #endif  /*_LINUX_ACPI_H*/