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, see <http://www.gnu.org/licenses/>.
20  *
21  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22  */
23 
24 #ifndef _LINUX_ACPI_H
25 #define _LINUX_ACPI_H
26 
27 #ifndef _LINUX
28 #define _LINUX
29 #endif
30 
31 #include <xen/list.h>
32 
33 #include <acpi/acpi.h>
34 #include <asm/acpi.h>
35 
36 #define ACPI_MADT_GET_(fld, x) (((x) & ACPI_MADT_##fld##_MASK) / \
37 	(ACPI_MADT_##fld##_MASK & -ACPI_MADT_##fld##_MASK))
38 
39 #define ACPI_MADT_GET_POLARITY(inti)	ACPI_MADT_GET_(POLARITY, inti)
40 #define ACPI_MADT_GET_TRIGGER(inti)	ACPI_MADT_GET_(TRIGGER, inti)
41 
42 /*
43  * Fixmap pages to reserve for ACPI boot-time tables (see asm-x86/fixmap.h or
44  * asm-arm/config.h, 64 pages(256KB) is large enough for most cases.)
45  */
46 #define NUM_FIXMAP_ACPI_PAGES  64
47 
48 #define BAD_MADT_ENTRY(entry, end) (                                        \
49                 (!(entry)) || (unsigned long)(entry) + sizeof(*(entry)) > (end) ||  \
50                 (entry)->header.length < sizeof(*(entry)))
51 
52 #ifdef CONFIG_ACPI
53 
54 extern acpi_physical_address rsdp_hint;
55 
56 enum acpi_interrupt_id {
57 	ACPI_INTERRUPT_PMI	= 1,
58 	ACPI_INTERRUPT_INIT,
59 	ACPI_INTERRUPT_CPEI,
60 	ACPI_INTERRUPT_COUNT
61 };
62 
63 typedef int (*acpi_madt_entry_handler) (struct acpi_subtable_header *header, const unsigned long end);
64 
65 typedef int (*acpi_table_handler) (struct acpi_table_header *table);
66 
67 typedef int (*acpi_table_entry_handler) (struct acpi_subtable_header *header, const unsigned long end);
68 
69 unsigned int acpi_get_processor_id (unsigned int cpu);
70 char * __acpi_map_table (paddr_t phys_addr, unsigned long size);
71 int acpi_boot_init (void);
72 int acpi_boot_table_init (void);
73 int acpi_numa_init (void);
74 int erst_init(void);
75 void acpi_hest_init(void);
76 
77 int acpi_table_init (void);
78 int acpi_table_parse(char *id, acpi_table_handler handler);
79 int acpi_parse_entries(char *id, unsigned long table_size,
80 		       acpi_table_entry_handler handler,
81 		       struct acpi_table_header *table_header,
82 		       int entry_id, unsigned int max_entries);
83 int acpi_table_parse_entries(char *id, unsigned long table_size,
84 	int entry_id, acpi_table_entry_handler handler, unsigned int max_entries);
85 struct acpi_subtable_header *acpi_table_get_entry_madt(enum acpi_madt_type id,
86 						      unsigned int entry_index);
87 int acpi_table_parse_madt(enum acpi_madt_type id, acpi_table_entry_handler handler, unsigned int max_entries);
88 int acpi_table_parse_srat(int id, acpi_madt_entry_handler handler,
89 	unsigned int max_entries);
90 int acpi_parse_srat(struct acpi_table_header *);
91 void acpi_table_print (struct acpi_table_header *header, unsigned long phys_addr);
92 void acpi_table_print_madt_entry (struct acpi_subtable_header *madt);
93 void acpi_table_print_srat_entry (struct acpi_subtable_header *srat);
94 
95 /* the following four functions are architecture-dependent */
96 void acpi_numa_slit_init (struct acpi_table_slit *slit);
97 void acpi_numa_processor_affinity_init(const struct acpi_srat_cpu_affinity *);
98 void acpi_numa_x2apic_affinity_init(const struct acpi_srat_x2apic_cpu_affinity *);
99 void acpi_numa_memory_affinity_init(const struct acpi_srat_mem_affinity *);
100 void acpi_numa_arch_fixup(void);
101 
102 #ifdef CONFIG_ACPI_HOTPLUG_CPU
103 /* Arch dependent functions for cpu hotplug support */
104 int acpi_map_lsapic(acpi_handle handle, int *pcpu);
105 int acpi_unmap_lsapic(int cpu);
106 #endif /* CONFIG_ACPI_HOTPLUG_CPU */
107 
108 extern int acpi_mp_config;
109 
110 extern u32 pci_mmcfg_base_addr;
111 
112 #else	/*!CONFIG_ACPI*/
113 
114 #define acpi_mp_config	0
115 
acpi_boot_init(void)116 static inline int acpi_boot_init(void)
117 {
118 	return 0;
119 }
120 
acpi_boot_table_init(void)121 static inline int acpi_boot_table_init(void)
122 {
123 	return 0;
124 }
125 
126 #endif 	/*!CONFIG_ACPI*/
127 
128 int get_cpu_id(u32 acpi_id);
129 
130 unsigned int acpi_register_gsi (u32 gsi, int edge_level, int active_high_low);
131 int acpi_gsi_to_irq (u32 gsi, unsigned int *irq);
132 
133 /*
134  * This function undoes the effect of one call to acpi_register_gsi().
135  * If this matches the last registration, any IRQ resources for gsi
136  * are freed.
137  */
138 #ifdef CONFIG_ACPI_DEALLOCATE_IRQ
139 void acpi_unregister_gsi (u32 gsi);
140 #endif
141 
142 #ifdef	CONFIG_ACPI_CSTATE
143 /*
144  * max_cstate sets the highest legal C-state.
145  * max_cstate = 0: C0 okay, but not C1
146  * max_cstate = 1: C1 okay, but not C2
147  * max_cstate = 2: C2 okay, but not C3 etc.
148 
149  * max_csubstate sets the highest legal C-state sub-state. Only applies to the
150  * highest legal C-state.
151  * max_cstate = 1, max_csubstate = 0 ==> C0, C1 okay, but not C1E
152  * max_cstate = 1, max_csubstate = 1 ==> C0, C1 and C1E okay, but not C2
153  * max_cstate = 2, max_csubstate = 0 ==> C0, C1, C1E, C2 okay, but not C3
154  * max_cstate = 2, max_csubstate = 1 ==> C0, C1, C1E, C2 okay, but not C3
155  */
156 
157 extern unsigned int max_cstate;
158 extern unsigned int max_csubstate;
159 
acpi_get_cstate_limit(void)160 static inline unsigned int acpi_get_cstate_limit(void)
161 {
162 	return max_cstate;
163 }
acpi_set_cstate_limit(unsigned int new_limit)164 static inline void acpi_set_cstate_limit(unsigned int new_limit)
165 {
166 	max_cstate = new_limit;
167 	return;
168 }
169 
acpi_get_csubstate_limit(void)170 static inline unsigned int acpi_get_csubstate_limit(void)
171 {
172 	return max_csubstate;
173 }
174 
acpi_set_csubstate_limit(unsigned int new_limit)175 static inline void acpi_set_csubstate_limit(unsigned int new_limit)
176 {
177 	max_csubstate = new_limit;
178 }
179 
180 #else
acpi_get_cstate_limit(void)181 static inline unsigned int acpi_get_cstate_limit(void) { return 0; }
acpi_set_cstate_limit(unsigned int new_limit)182 static inline void acpi_set_cstate_limit(unsigned int new_limit) { return; }
acpi_get_csubstate_limit(void)183 static inline unsigned int acpi_get_csubstate_limit(void) { return 0; }
acpi_set_csubstate_limit(unsigned int new_limit)184 static inline void acpi_set_csubstate_limit(unsigned int new_limit) { return; }
185 #endif
186 
187 #ifdef XEN_GUEST_HANDLE
188 int acpi_set_pdc_bits(uint32_t acpi_id, XEN_GUEST_HANDLE(uint32));
189 #endif
190 int arch_acpi_set_pdc_bits(u32 acpi_id, u32 *, u32 mask);
191 
192 #ifdef CONFIG_ACPI_NUMA
193 int acpi_get_pxm(acpi_handle handle);
194 #else
acpi_get_pxm(acpi_handle handle)195 static inline int acpi_get_pxm(acpi_handle handle)
196 {
197 	return 0;
198 }
199 #endif
200 
201 void acpi_reboot(void);
202 
203 void acpi_dmar_zap(void);
204 void acpi_dmar_reinstate(void);
205 
206 #endif /*_LINUX_ACPI_H*/
207