]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * acpi_osl.c - OS-dependent functions ($Revision: 83 $) | |
3 | * | |
4 | * Copyright (C) 2000 Andrew Henroid | |
5 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | |
6 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | |
f1241c87 MW |
7 | * Copyright (c) 2008 Intel Corporation |
8 | * Author: Matthew Wilcox <willy@linux.intel.com> | |
1da177e4 LT |
9 | * |
10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU General Public License as published by | |
14 | * the Free Software Foundation; either version 2 of the License, or | |
15 | * (at your option) any later version. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License | |
23 | * along with this program; if not, write to the Free Software | |
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
25 | * | |
26 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
27 | * | |
28 | */ | |
29 | ||
1da177e4 LT |
30 | #include <linux/module.h> |
31 | #include <linux/kernel.h> | |
32 | #include <linux/slab.h> | |
33 | #include <linux/mm.h> | |
34 | #include <linux/pci.h> | |
1da177e4 LT |
35 | #include <linux/interrupt.h> |
36 | #include <linux/kmod.h> | |
37 | #include <linux/delay.h> | |
38 | #include <linux/workqueue.h> | |
39 | #include <linux/nmi.h> | |
ad71860a | 40 | #include <linux/acpi.h> |
2d6d9fd3 | 41 | #include <linux/acpi_io.h> |
1da177e4 | 42 | #include <linux/efi.h> |
df92e695 TR |
43 | #include <linux/ioport.h> |
44 | #include <linux/list.h> | |
f1241c87 MW |
45 | #include <linux/jiffies.h> |
46 | #include <linux/semaphore.h> | |
47 | ||
48 | #include <asm/io.h> | |
49 | #include <asm/uaccess.h> | |
50 | ||
51 | #include <acpi/acpi.h> | |
52 | #include <acpi/acpi_bus.h> | |
53 | #include <acpi/processor.h> | |
1da177e4 | 54 | |
1da177e4 | 55 | #define _COMPONENT ACPI_OS_SERVICES |
f52fd66d | 56 | ACPI_MODULE_NAME("osl"); |
1da177e4 | 57 | #define PREFIX "ACPI: " |
4be44fcd LB |
58 | struct acpi_os_dpc { |
59 | acpi_osd_exec_callback function; | |
60 | void *context; | |
65f27f38 | 61 | struct work_struct work; |
9ac61856 | 62 | int wait; |
1da177e4 LT |
63 | }; |
64 | ||
65 | #ifdef CONFIG_ACPI_CUSTOM_DSDT | |
66 | #include CONFIG_ACPI_CUSTOM_DSDT_FILE | |
67 | #endif | |
68 | ||
69 | #ifdef ENABLE_DEBUGGER | |
70 | #include <linux/kdb.h> | |
71 | ||
72 | /* stuff for debugger support */ | |
73 | int acpi_in_debugger; | |
74 | EXPORT_SYMBOL(acpi_in_debugger); | |
75 | ||
76 | extern char line_buf[80]; | |
4be44fcd | 77 | #endif /*ENABLE_DEBUGGER */ |
1da177e4 | 78 | |
1da177e4 LT |
79 | static acpi_osd_handler acpi_irq_handler; |
80 | static void *acpi_irq_context; | |
81 | static struct workqueue_struct *kacpid_wq; | |
88db5e14 | 82 | static struct workqueue_struct *kacpi_notify_wq; |
6af8bef1 PB |
83 | struct workqueue_struct *kacpi_hotplug_wq; |
84 | EXPORT_SYMBOL(kacpi_hotplug_wq); | |
1da177e4 | 85 | |
df92e695 TR |
86 | struct acpi_res_list { |
87 | resource_size_t start; | |
88 | resource_size_t end; | |
89 | acpi_adr_space_type resource_type; /* IO port, System memory, ...*/ | |
90 | char name[5]; /* only can have a length of 4 chars, make use of this | |
91 | one instead of res->name, no need to kalloc then */ | |
92 | struct list_head resource_list; | |
a5fe1a03 | 93 | int count; |
df92e695 TR |
94 | }; |
95 | ||
96 | static LIST_HEAD(resource_list_head); | |
97 | static DEFINE_SPINLOCK(acpi_res_lock); | |
98 | ||
620242ae MS |
99 | /* |
100 | * This list of permanent mappings is for memory that may be accessed from | |
101 | * interrupt context, where we can't do the ioremap(). | |
102 | */ | |
103 | struct acpi_ioremap { | |
104 | struct list_head list; | |
105 | void __iomem *virt; | |
106 | acpi_physical_address phys; | |
107 | acpi_size size; | |
b7c1fadd | 108 | unsigned long refcount; |
620242ae MS |
109 | }; |
110 | ||
111 | static LIST_HEAD(acpi_ioremaps); | |
7bbb8903 | 112 | static DEFINE_MUTEX(acpi_ioremap_lock); |
620242ae | 113 | |
b0ed7a91 | 114 | static void __init acpi_osi_setup_late(void); |
ae00d812 | 115 | |
d4b7dc49 | 116 | /* |
a6e0887f | 117 | * The story of _OSI(Linux) |
d4b7dc49 | 118 | * |
a6e0887f LB |
119 | * From pre-history through Linux-2.6.22, |
120 | * Linux responded TRUE upon a BIOS OSI(Linux) query. | |
d4b7dc49 | 121 | * |
a6e0887f LB |
122 | * Unfortunately, reference BIOS writers got wind of this |
123 | * and put OSI(Linux) in their example code, quickly exposing | |
124 | * this string as ill-conceived and opening the door to | |
125 | * an un-bounded number of BIOS incompatibilities. | |
d4b7dc49 | 126 | * |
a6e0887f LB |
127 | * For example, OSI(Linux) was used on resume to re-POST a |
128 | * video card on one system, because Linux at that time | |
129 | * could not do a speedy restore in its native driver. | |
130 | * But then upon gaining quick native restore capability, | |
131 | * Linux has no way to tell the BIOS to skip the time-consuming | |
132 | * POST -- putting Linux at a permanent performance disadvantage. | |
133 | * On another system, the BIOS writer used OSI(Linux) | |
134 | * to infer native OS support for IPMI! On other systems, | |
135 | * OSI(Linux) simply got in the way of Linux claiming to | |
136 | * be compatible with other operating systems, exposing | |
137 | * BIOS issues such as skipped device initialization. | |
d4b7dc49 | 138 | * |
a6e0887f LB |
139 | * So "Linux" turned out to be a really poor chose of |
140 | * OSI string, and from Linux-2.6.23 onward we respond FALSE. | |
d4b7dc49 LB |
141 | * |
142 | * BIOS writers should NOT query _OSI(Linux) on future systems. | |
a6e0887f LB |
143 | * Linux will complain on the console when it sees it, and return FALSE. |
144 | * To get Linux to return TRUE for your system will require | |
145 | * a kernel source update to add a DMI entry, | |
146 | * or boot with "acpi_osi=Linux" | |
d4b7dc49 | 147 | */ |
d4b7dc49 | 148 | |
1d15d84e | 149 | static struct osi_linux { |
d4b7dc49 LB |
150 | unsigned int enable:1; |
151 | unsigned int dmi:1; | |
152 | unsigned int cmdline:1; | |
d90aa92c | 153 | } osi_linux = {0, 0, 0}; |
f507654d | 154 | |
b0ed7a91 LM |
155 | static u32 acpi_osi_handler(acpi_string interface, u32 supported) |
156 | { | |
157 | if (!strcmp("Linux", interface)) { | |
158 | ||
8997621b | 159 | printk_once(KERN_NOTICE FW_BUG PREFIX |
b0ed7a91 LM |
160 | "BIOS _OSI(Linux) query %s%s\n", |
161 | osi_linux.enable ? "honored" : "ignored", | |
162 | osi_linux.cmdline ? " via cmdline" : | |
163 | osi_linux.dmi ? " via DMI" : ""); | |
164 | } | |
165 | ||
166 | return supported; | |
167 | } | |
168 | ||
9a47cdb1 BH |
169 | static void __init acpi_request_region (struct acpi_generic_address *addr, |
170 | unsigned int length, char *desc) | |
171 | { | |
9a47cdb1 BH |
172 | if (!addr->address || !length) |
173 | return; | |
174 | ||
cfa806f0 | 175 | /* Resources are never freed */ |
eee3c859 | 176 | if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO) |
cfa806f0 | 177 | request_region(addr->address, length, desc); |
eee3c859 | 178 | else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) |
cfa806f0 | 179 | request_mem_region(addr->address, length, desc); |
9a47cdb1 BH |
180 | } |
181 | ||
182 | static int __init acpi_reserve_resources(void) | |
183 | { | |
eee3c859 | 184 | acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length, |
9a47cdb1 BH |
185 | "ACPI PM1a_EVT_BLK"); |
186 | ||
eee3c859 | 187 | acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length, |
9a47cdb1 BH |
188 | "ACPI PM1b_EVT_BLK"); |
189 | ||
eee3c859 | 190 | acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length, |
9a47cdb1 BH |
191 | "ACPI PM1a_CNT_BLK"); |
192 | ||
eee3c859 | 193 | acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length, |
9a47cdb1 BH |
194 | "ACPI PM1b_CNT_BLK"); |
195 | ||
eee3c859 LB |
196 | if (acpi_gbl_FADT.pm_timer_length == 4) |
197 | acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR"); | |
9a47cdb1 | 198 | |
eee3c859 | 199 | acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length, |
9a47cdb1 BH |
200 | "ACPI PM2_CNT_BLK"); |
201 | ||
202 | /* Length of GPE blocks must be a non-negative multiple of 2 */ | |
203 | ||
eee3c859 LB |
204 | if (!(acpi_gbl_FADT.gpe0_block_length & 0x1)) |
205 | acpi_request_region(&acpi_gbl_FADT.xgpe0_block, | |
206 | acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK"); | |
9a47cdb1 | 207 | |
eee3c859 LB |
208 | if (!(acpi_gbl_FADT.gpe1_block_length & 0x1)) |
209 | acpi_request_region(&acpi_gbl_FADT.xgpe1_block, | |
210 | acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK"); | |
9a47cdb1 BH |
211 | |
212 | return 0; | |
213 | } | |
214 | device_initcall(acpi_reserve_resources); | |
215 | ||
4be44fcd | 216 | void acpi_os_printf(const char *fmt, ...) |
1da177e4 LT |
217 | { |
218 | va_list args; | |
219 | va_start(args, fmt); | |
220 | acpi_os_vprintf(fmt, args); | |
221 | va_end(args); | |
222 | } | |
4be44fcd | 223 | |
4be44fcd | 224 | void acpi_os_vprintf(const char *fmt, va_list args) |
1da177e4 LT |
225 | { |
226 | static char buffer[512]; | |
4be44fcd | 227 | |
1da177e4 LT |
228 | vsprintf(buffer, fmt, args); |
229 | ||
230 | #ifdef ENABLE_DEBUGGER | |
231 | if (acpi_in_debugger) { | |
232 | kdb_printf("%s", buffer); | |
233 | } else { | |
4d939155 | 234 | printk(KERN_CONT "%s", buffer); |
1da177e4 LT |
235 | } |
236 | #else | |
4d939155 | 237 | printk(KERN_CONT "%s", buffer); |
1da177e4 LT |
238 | #endif |
239 | } | |
240 | ||
4996c023 TI |
241 | #ifdef CONFIG_KEXEC |
242 | static unsigned long acpi_rsdp; | |
243 | static int __init setup_acpi_rsdp(char *arg) | |
244 | { | |
245 | acpi_rsdp = simple_strtoul(arg, NULL, 16); | |
246 | return 0; | |
247 | } | |
248 | early_param("acpi_rsdp", setup_acpi_rsdp); | |
249 | #endif | |
250 | ||
ad71860a | 251 | acpi_physical_address __init acpi_os_get_root_pointer(void) |
1da177e4 | 252 | { |
4996c023 TI |
253 | #ifdef CONFIG_KEXEC |
254 | if (acpi_rsdp) | |
255 | return acpi_rsdp; | |
256 | #endif | |
257 | ||
1da177e4 | 258 | if (efi_enabled) { |
b2c99e3c | 259 | if (efi.acpi20 != EFI_INVALID_TABLE_ADDR) |
ad71860a | 260 | return efi.acpi20; |
b2c99e3c | 261 | else if (efi.acpi != EFI_INVALID_TABLE_ADDR) |
ad71860a | 262 | return efi.acpi; |
1da177e4 | 263 | else { |
4be44fcd LB |
264 | printk(KERN_ERR PREFIX |
265 | "System description tables not found\n"); | |
ad71860a | 266 | return 0; |
1da177e4 | 267 | } |
239665a3 LB |
268 | } else { |
269 | acpi_physical_address pa = 0; | |
270 | ||
271 | acpi_find_root_pointer(&pa); | |
272 | return pa; | |
273 | } | |
1da177e4 LT |
274 | } |
275 | ||
78cdb3ed | 276 | /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */ |
4a3cba5e MS |
277 | static struct acpi_ioremap * |
278 | acpi_map_lookup(acpi_physical_address phys, acpi_size size) | |
620242ae MS |
279 | { |
280 | struct acpi_ioremap *map; | |
281 | ||
78cdb3ed | 282 | list_for_each_entry_rcu(map, &acpi_ioremaps, list) |
620242ae MS |
283 | if (map->phys <= phys && |
284 | phys + size <= map->phys + map->size) | |
4a3cba5e MS |
285 | return map; |
286 | ||
287 | return NULL; | |
288 | } | |
289 | ||
290 | /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */ | |
291 | static void __iomem * | |
292 | acpi_map_vaddr_lookup(acpi_physical_address phys, unsigned int size) | |
293 | { | |
294 | struct acpi_ioremap *map; | |
295 | ||
296 | map = acpi_map_lookup(phys, size); | |
297 | if (map) | |
298 | return map->virt + (phys - map->phys); | |
620242ae MS |
299 | |
300 | return NULL; | |
301 | } | |
302 | ||
13606a2d RW |
303 | void __iomem *acpi_os_get_iomem(acpi_physical_address phys, unsigned int size) |
304 | { | |
305 | struct acpi_ioremap *map; | |
306 | void __iomem *virt = NULL; | |
307 | ||
308 | mutex_lock(&acpi_ioremap_lock); | |
309 | map = acpi_map_lookup(phys, size); | |
310 | if (map) { | |
311 | virt = map->virt + (phys - map->phys); | |
312 | map->refcount++; | |
313 | } | |
314 | mutex_unlock(&acpi_ioremap_lock); | |
315 | return virt; | |
316 | } | |
317 | EXPORT_SYMBOL_GPL(acpi_os_get_iomem); | |
318 | ||
78cdb3ed | 319 | /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */ |
620242ae MS |
320 | static struct acpi_ioremap * |
321 | acpi_map_lookup_virt(void __iomem *virt, acpi_size size) | |
322 | { | |
323 | struct acpi_ioremap *map; | |
324 | ||
78cdb3ed | 325 | list_for_each_entry_rcu(map, &acpi_ioremaps, list) |
4a3cba5e MS |
326 | if (map->virt <= virt && |
327 | virt + size <= map->virt + map->size) | |
620242ae MS |
328 | return map; |
329 | ||
330 | return NULL; | |
331 | } | |
332 | ||
2fdf0741 JB |
333 | void __iomem *__init_refok |
334 | acpi_os_map_memory(acpi_physical_address phys, acpi_size size) | |
1da177e4 | 335 | { |
7ffd0443 | 336 | struct acpi_ioremap *map; |
620242ae | 337 | void __iomem *virt; |
2d6d9fd3 RW |
338 | acpi_physical_address pg_off; |
339 | acpi_size pg_sz; | |
620242ae | 340 | |
9f4fd61f BH |
341 | if (phys > ULONG_MAX) { |
342 | printk(KERN_ERR PREFIX "Cannot map memory that high\n"); | |
70c0846e | 343 | return NULL; |
1da177e4 | 344 | } |
620242ae MS |
345 | |
346 | if (!acpi_gbl_permanent_mmap) | |
ad71860a | 347 | return __acpi_map_table((unsigned long)phys, size); |
620242ae | 348 | |
7ffd0443 RW |
349 | mutex_lock(&acpi_ioremap_lock); |
350 | /* Check if there's a suitable mapping already. */ | |
351 | map = acpi_map_lookup(phys, size); | |
352 | if (map) { | |
b7c1fadd | 353 | map->refcount++; |
7ffd0443 RW |
354 | goto out; |
355 | } | |
356 | ||
620242ae | 357 | map = kzalloc(sizeof(*map), GFP_KERNEL); |
7ffd0443 RW |
358 | if (!map) { |
359 | mutex_unlock(&acpi_ioremap_lock); | |
620242ae | 360 | return NULL; |
7ffd0443 | 361 | } |
620242ae | 362 | |
4a3cba5e MS |
363 | pg_off = round_down(phys, PAGE_SIZE); |
364 | pg_sz = round_up(phys + size, PAGE_SIZE) - pg_off; | |
2d6d9fd3 | 365 | virt = acpi_os_ioremap(pg_off, pg_sz); |
620242ae | 366 | if (!virt) { |
7ffd0443 | 367 | mutex_unlock(&acpi_ioremap_lock); |
620242ae MS |
368 | kfree(map); |
369 | return NULL; | |
370 | } | |
371 | ||
372 | INIT_LIST_HEAD(&map->list); | |
373 | map->virt = virt; | |
4a3cba5e MS |
374 | map->phys = pg_off; |
375 | map->size = pg_sz; | |
b7c1fadd | 376 | map->refcount = 1; |
620242ae | 377 | |
78cdb3ed | 378 | list_add_tail_rcu(&map->list, &acpi_ioremaps); |
620242ae | 379 | |
7ffd0443 RW |
380 | out: |
381 | mutex_unlock(&acpi_ioremap_lock); | |
4a3cba5e | 382 | return map->virt + (phys - map->phys); |
1da177e4 | 383 | } |
55a82ab3 | 384 | EXPORT_SYMBOL_GPL(acpi_os_map_memory); |
1da177e4 | 385 | |
b7c1fadd | 386 | static void acpi_os_drop_map_ref(struct acpi_ioremap *map) |
4a3cba5e | 387 | { |
b7c1fadd RW |
388 | if (!--map->refcount) |
389 | list_del_rcu(&map->list); | |
4a3cba5e | 390 | } |
4a3cba5e | 391 | |
b7c1fadd | 392 | static void acpi_os_map_cleanup(struct acpi_ioremap *map) |
7fe135dc | 393 | { |
b7c1fadd RW |
394 | if (!map->refcount) { |
395 | synchronize_rcu(); | |
396 | iounmap(map->virt); | |
397 | kfree(map); | |
398 | } | |
4a3cba5e MS |
399 | } |
400 | ||
0d3a9cf5 | 401 | void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size) |
1da177e4 | 402 | { |
620242ae | 403 | struct acpi_ioremap *map; |
620242ae MS |
404 | |
405 | if (!acpi_gbl_permanent_mmap) { | |
7d97277b | 406 | __acpi_unmap_table(virt, size); |
620242ae MS |
407 | return; |
408 | } | |
409 | ||
7bbb8903 | 410 | mutex_lock(&acpi_ioremap_lock); |
620242ae MS |
411 | map = acpi_map_lookup_virt(virt, size); |
412 | if (!map) { | |
7bbb8903 | 413 | mutex_unlock(&acpi_ioremap_lock); |
7fe135dc | 414 | WARN(true, PREFIX "%s: bad address %p\n", __func__, virt); |
620242ae MS |
415 | return; |
416 | } | |
b7c1fadd | 417 | acpi_os_drop_map_ref(map); |
7bbb8903 | 418 | mutex_unlock(&acpi_ioremap_lock); |
620242ae | 419 | |
b7c1fadd | 420 | acpi_os_map_cleanup(map); |
1da177e4 | 421 | } |
55a82ab3 | 422 | EXPORT_SYMBOL_GPL(acpi_os_unmap_memory); |
1da177e4 | 423 | |
0d3a9cf5 | 424 | void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size) |
7d97277b YL |
425 | { |
426 | if (!acpi_gbl_permanent_mmap) | |
427 | __acpi_unmap_table(virt, size); | |
428 | } | |
429 | ||
073b4964 | 430 | static int acpi_os_map_generic_address(struct acpi_generic_address *addr) |
29718521 MS |
431 | { |
432 | void __iomem *virt; | |
433 | ||
434 | if (addr->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) | |
435 | return 0; | |
436 | ||
437 | if (!addr->address || !addr->bit_width) | |
438 | return -EINVAL; | |
439 | ||
440 | virt = acpi_os_map_memory(addr->address, addr->bit_width / 8); | |
441 | if (!virt) | |
442 | return -EIO; | |
443 | ||
444 | return 0; | |
445 | } | |
29718521 | 446 | |
073b4964 | 447 | static void acpi_os_unmap_generic_address(struct acpi_generic_address *addr) |
29718521 | 448 | { |
7fe135dc | 449 | struct acpi_ioremap *map; |
29718521 MS |
450 | |
451 | if (addr->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) | |
452 | return; | |
453 | ||
454 | if (!addr->address || !addr->bit_width) | |
455 | return; | |
456 | ||
7bbb8903 | 457 | mutex_lock(&acpi_ioremap_lock); |
7fe135dc RW |
458 | map = acpi_map_lookup(addr->address, addr->bit_width / 8); |
459 | if (!map) { | |
460 | mutex_unlock(&acpi_ioremap_lock); | |
461 | return; | |
462 | } | |
b7c1fadd | 463 | acpi_os_drop_map_ref(map); |
7bbb8903 | 464 | mutex_unlock(&acpi_ioremap_lock); |
29718521 | 465 | |
b7c1fadd | 466 | acpi_os_map_cleanup(map); |
29718521 | 467 | } |
29718521 | 468 | |
1da177e4 LT |
469 | #ifdef ACPI_FUTURE_USAGE |
470 | acpi_status | |
4be44fcd | 471 | acpi_os_get_physical_address(void *virt, acpi_physical_address * phys) |
1da177e4 | 472 | { |
4be44fcd | 473 | if (!phys || !virt) |
1da177e4 LT |
474 | return AE_BAD_PARAMETER; |
475 | ||
476 | *phys = virt_to_phys(virt); | |
477 | ||
478 | return AE_OK; | |
479 | } | |
480 | #endif | |
481 | ||
482 | #define ACPI_MAX_OVERRIDE_LEN 100 | |
483 | ||
484 | static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN]; | |
485 | ||
486 | acpi_status | |
4be44fcd LB |
487 | acpi_os_predefined_override(const struct acpi_predefined_names *init_val, |
488 | acpi_string * new_val) | |
1da177e4 LT |
489 | { |
490 | if (!init_val || !new_val) | |
491 | return AE_BAD_PARAMETER; | |
492 | ||
493 | *new_val = NULL; | |
4be44fcd | 494 | if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) { |
1da177e4 | 495 | printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n", |
4be44fcd | 496 | acpi_os_name); |
1da177e4 LT |
497 | *new_val = acpi_os_name; |
498 | } | |
499 | ||
500 | return AE_OK; | |
501 | } | |
502 | ||
503 | acpi_status | |
4be44fcd LB |
504 | acpi_os_table_override(struct acpi_table_header * existing_table, |
505 | struct acpi_table_header ** new_table) | |
1da177e4 LT |
506 | { |
507 | if (!existing_table || !new_table) | |
508 | return AE_BAD_PARAMETER; | |
509 | ||
71fc47a9 MG |
510 | *new_table = NULL; |
511 | ||
1da177e4 LT |
512 | #ifdef CONFIG_ACPI_CUSTOM_DSDT |
513 | if (strncmp(existing_table->signature, "DSDT", 4) == 0) | |
4be44fcd | 514 | *new_table = (struct acpi_table_header *)AmlCode; |
1da177e4 | 515 | #endif |
6ed31e92 ÉP |
516 | if (*new_table != NULL) { |
517 | printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], " | |
518 | "this is unsafe: tainting kernel\n", | |
519 | existing_table->signature, | |
520 | existing_table->oem_table_id); | |
521 | add_taint(TAINT_OVERRIDDEN_ACPI_TABLE); | |
522 | } | |
1da177e4 LT |
523 | return AE_OK; |
524 | } | |
525 | ||
7d12e780 | 526 | static irqreturn_t acpi_irq(int irq, void *dev_id) |
1da177e4 | 527 | { |
5229e87d LB |
528 | u32 handled; |
529 | ||
530 | handled = (*acpi_irq_handler) (acpi_irq_context); | |
531 | ||
532 | if (handled) { | |
533 | acpi_irq_handled++; | |
534 | return IRQ_HANDLED; | |
88bea188 LB |
535 | } else { |
536 | acpi_irq_not_handled++; | |
5229e87d | 537 | return IRQ_NONE; |
88bea188 | 538 | } |
1da177e4 LT |
539 | } |
540 | ||
541 | acpi_status | |
4be44fcd LB |
542 | acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler, |
543 | void *context) | |
1da177e4 LT |
544 | { |
545 | unsigned int irq; | |
546 | ||
5229e87d LB |
547 | acpi_irq_stats_init(); |
548 | ||
1da177e4 | 549 | /* |
23fe3630 RW |
550 | * ACPI interrupts different from the SCI in our copy of the FADT are |
551 | * not supported. | |
1da177e4 | 552 | */ |
23fe3630 RW |
553 | if (gsi != acpi_gbl_FADT.sci_interrupt) |
554 | return AE_BAD_PARAMETER; | |
555 | ||
556 | if (acpi_irq_handler) | |
557 | return AE_ALREADY_ACQUIRED; | |
558 | ||
1da177e4 LT |
559 | if (acpi_gsi_to_irq(gsi, &irq) < 0) { |
560 | printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n", | |
561 | gsi); | |
562 | return AE_OK; | |
563 | } | |
564 | ||
565 | acpi_irq_handler = handler; | |
566 | acpi_irq_context = context; | |
dace1453 | 567 | if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) { |
1da177e4 | 568 | printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq); |
23fe3630 | 569 | acpi_irq_handler = NULL; |
1da177e4 LT |
570 | return AE_NOT_ACQUIRED; |
571 | } | |
1da177e4 LT |
572 | |
573 | return AE_OK; | |
574 | } | |
575 | ||
4be44fcd | 576 | acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler) |
1da177e4 | 577 | { |
23fe3630 RW |
578 | if (irq != acpi_gbl_FADT.sci_interrupt) |
579 | return AE_BAD_PARAMETER; | |
580 | ||
581 | free_irq(irq, acpi_irq); | |
582 | acpi_irq_handler = NULL; | |
1da177e4 LT |
583 | |
584 | return AE_OK; | |
585 | } | |
586 | ||
587 | /* | |
588 | * Running in interpreter thread context, safe to sleep | |
589 | */ | |
590 | ||
439913ff | 591 | void acpi_os_sleep(u64 ms) |
1da177e4 | 592 | { |
01a527ec | 593 | schedule_timeout_interruptible(msecs_to_jiffies(ms)); |
1da177e4 | 594 | } |
4be44fcd | 595 | |
4be44fcd | 596 | void acpi_os_stall(u32 us) |
1da177e4 LT |
597 | { |
598 | while (us) { | |
599 | u32 delay = 1000; | |
600 | ||
601 | if (delay > us) | |
602 | delay = us; | |
603 | udelay(delay); | |
604 | touch_nmi_watchdog(); | |
605 | us -= delay; | |
606 | } | |
607 | } | |
4be44fcd | 608 | |
1da177e4 LT |
609 | /* |
610 | * Support ACPI 3.0 AML Timer operand | |
611 | * Returns 64-bit free-running, monotonically increasing timer | |
612 | * with 100ns granularity | |
613 | */ | |
4be44fcd | 614 | u64 acpi_os_get_timer(void) |
1da177e4 LT |
615 | { |
616 | static u64 t; | |
617 | ||
618 | #ifdef CONFIG_HPET | |
619 | /* TBD: use HPET if available */ | |
620 | #endif | |
621 | ||
622 | #ifdef CONFIG_X86_PM_TIMER | |
623 | /* TBD: default to PM timer if HPET was not available */ | |
624 | #endif | |
625 | if (!t) | |
626 | printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n"); | |
627 | ||
628 | return ++t; | |
629 | } | |
630 | ||
4be44fcd | 631 | acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width) |
1da177e4 LT |
632 | { |
633 | u32 dummy; | |
634 | ||
635 | if (!value) | |
636 | value = &dummy; | |
637 | ||
49fbabf5 ZY |
638 | *value = 0; |
639 | if (width <= 8) { | |
4be44fcd | 640 | *(u8 *) value = inb(port); |
49fbabf5 | 641 | } else if (width <= 16) { |
4be44fcd | 642 | *(u16 *) value = inw(port); |
49fbabf5 | 643 | } else if (width <= 32) { |
4be44fcd | 644 | *(u32 *) value = inl(port); |
49fbabf5 | 645 | } else { |
1da177e4 LT |
646 | BUG(); |
647 | } | |
648 | ||
649 | return AE_OK; | |
650 | } | |
4be44fcd | 651 | |
1da177e4 LT |
652 | EXPORT_SYMBOL(acpi_os_read_port); |
653 | ||
4be44fcd | 654 | acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width) |
1da177e4 | 655 | { |
49fbabf5 | 656 | if (width <= 8) { |
1da177e4 | 657 | outb(value, port); |
49fbabf5 | 658 | } else if (width <= 16) { |
1da177e4 | 659 | outw(value, port); |
49fbabf5 | 660 | } else if (width <= 32) { |
1da177e4 | 661 | outl(value, port); |
49fbabf5 | 662 | } else { |
1da177e4 LT |
663 | BUG(); |
664 | } | |
665 | ||
666 | return AE_OK; | |
667 | } | |
4be44fcd | 668 | |
1da177e4 LT |
669 | EXPORT_SYMBOL(acpi_os_write_port); |
670 | ||
671 | acpi_status | |
4be44fcd | 672 | acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width) |
1da177e4 | 673 | { |
4be44fcd | 674 | void __iomem *virt_addr; |
884b821f RW |
675 | unsigned int size = width / 8; |
676 | bool unmap = false; | |
677 | u32 dummy; | |
620242ae | 678 | |
78cdb3ed | 679 | rcu_read_lock(); |
620242ae | 680 | virt_addr = acpi_map_vaddr_lookup(phys_addr, size); |
620242ae | 681 | if (!virt_addr) { |
884b821f | 682 | rcu_read_unlock(); |
2d6d9fd3 | 683 | virt_addr = acpi_os_ioremap(phys_addr, size); |
884b821f RW |
684 | if (!virt_addr) |
685 | return AE_BAD_ADDRESS; | |
686 | unmap = true; | |
620242ae | 687 | } |
884b821f | 688 | |
1da177e4 LT |
689 | if (!value) |
690 | value = &dummy; | |
691 | ||
692 | switch (width) { | |
693 | case 8: | |
4be44fcd | 694 | *(u8 *) value = readb(virt_addr); |
1da177e4 LT |
695 | break; |
696 | case 16: | |
4be44fcd | 697 | *(u16 *) value = readw(virt_addr); |
1da177e4 LT |
698 | break; |
699 | case 32: | |
4be44fcd | 700 | *(u32 *) value = readl(virt_addr); |
1da177e4 LT |
701 | break; |
702 | default: | |
703 | BUG(); | |
704 | } | |
705 | ||
620242ae MS |
706 | if (unmap) |
707 | iounmap(virt_addr); | |
884b821f RW |
708 | else |
709 | rcu_read_unlock(); | |
1da177e4 LT |
710 | |
711 | return AE_OK; | |
712 | } | |
713 | ||
714 | acpi_status | |
4be44fcd | 715 | acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width) |
1da177e4 | 716 | { |
4be44fcd | 717 | void __iomem *virt_addr; |
884b821f RW |
718 | unsigned int size = width / 8; |
719 | bool unmap = false; | |
620242ae | 720 | |
78cdb3ed | 721 | rcu_read_lock(); |
620242ae | 722 | virt_addr = acpi_map_vaddr_lookup(phys_addr, size); |
620242ae | 723 | if (!virt_addr) { |
884b821f | 724 | rcu_read_unlock(); |
2d6d9fd3 | 725 | virt_addr = acpi_os_ioremap(phys_addr, size); |
884b821f RW |
726 | if (!virt_addr) |
727 | return AE_BAD_ADDRESS; | |
728 | unmap = true; | |
620242ae | 729 | } |
1da177e4 LT |
730 | |
731 | switch (width) { | |
732 | case 8: | |
733 | writeb(value, virt_addr); | |
734 | break; | |
735 | case 16: | |
736 | writew(value, virt_addr); | |
737 | break; | |
738 | case 32: | |
739 | writel(value, virt_addr); | |
740 | break; | |
741 | default: | |
742 | BUG(); | |
743 | } | |
744 | ||
620242ae MS |
745 | if (unmap) |
746 | iounmap(virt_addr); | |
884b821f RW |
747 | else |
748 | rcu_read_unlock(); | |
1da177e4 LT |
749 | |
750 | return AE_OK; | |
751 | } | |
752 | ||
1da177e4 | 753 | acpi_status |
4be44fcd | 754 | acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
c5f0231e | 755 | u64 *value, u32 width) |
1da177e4 LT |
756 | { |
757 | int result, size; | |
c5f0231e | 758 | u32 value32; |
1da177e4 LT |
759 | |
760 | if (!value) | |
761 | return AE_BAD_PARAMETER; | |
762 | ||
763 | switch (width) { | |
764 | case 8: | |
765 | size = 1; | |
766 | break; | |
767 | case 16: | |
768 | size = 2; | |
769 | break; | |
770 | case 32: | |
771 | size = 4; | |
772 | break; | |
773 | default: | |
774 | return AE_ERROR; | |
775 | } | |
776 | ||
b6ce068a MW |
777 | result = raw_pci_read(pci_id->segment, pci_id->bus, |
778 | PCI_DEVFN(pci_id->device, pci_id->function), | |
c5f0231e BM |
779 | reg, size, &value32); |
780 | *value = value32; | |
1da177e4 LT |
781 | |
782 | return (result ? AE_ERROR : AE_OK); | |
783 | } | |
4be44fcd | 784 | |
1da177e4 | 785 | acpi_status |
4be44fcd | 786 | acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
439913ff | 787 | u64 value, u32 width) |
1da177e4 LT |
788 | { |
789 | int result, size; | |
790 | ||
791 | switch (width) { | |
792 | case 8: | |
793 | size = 1; | |
794 | break; | |
795 | case 16: | |
796 | size = 2; | |
797 | break; | |
798 | case 32: | |
799 | size = 4; | |
800 | break; | |
801 | default: | |
802 | return AE_ERROR; | |
803 | } | |
804 | ||
b6ce068a MW |
805 | result = raw_pci_write(pci_id->segment, pci_id->bus, |
806 | PCI_DEVFN(pci_id->device, pci_id->function), | |
807 | reg, size, value); | |
1da177e4 LT |
808 | |
809 | return (result ? AE_ERROR : AE_OK); | |
810 | } | |
811 | ||
65f27f38 | 812 | static void acpi_os_execute_deferred(struct work_struct *work) |
88db5e14 AS |
813 | { |
814 | struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); | |
88db5e14 | 815 | |
9ac61856 BH |
816 | if (dpc->wait) |
817 | acpi_os_wait_events_complete(NULL); | |
19cd847a ZR |
818 | |
819 | dpc->function(dpc->context); | |
820 | kfree(dpc); | |
19cd847a ZR |
821 | } |
822 | ||
b8d35192 AS |
823 | /******************************************************************************* |
824 | * | |
825 | * FUNCTION: acpi_os_execute | |
826 | * | |
827 | * PARAMETERS: Type - Type of the callback | |
828 | * Function - Function to be executed | |
829 | * Context - Function parameters | |
830 | * | |
831 | * RETURN: Status | |
832 | * | |
833 | * DESCRIPTION: Depending on type, either queues function for deferred execution or | |
834 | * immediately executes function on a separate thread. | |
835 | * | |
836 | ******************************************************************************/ | |
837 | ||
19cd847a ZR |
838 | static acpi_status __acpi_os_execute(acpi_execute_type type, |
839 | acpi_osd_exec_callback function, void *context, int hp) | |
1da177e4 | 840 | { |
4be44fcd LB |
841 | acpi_status status = AE_OK; |
842 | struct acpi_os_dpc *dpc; | |
17bc54ee | 843 | struct workqueue_struct *queue; |
19cd847a | 844 | int ret; |
72945b2b LB |
845 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
846 | "Scheduling function [%p(%p)] for deferred execution.\n", | |
847 | function, context)); | |
1da177e4 | 848 | |
1da177e4 LT |
849 | /* |
850 | * Allocate/initialize DPC structure. Note that this memory will be | |
65f27f38 | 851 | * freed by the callee. The kernel handles the work_struct list in a |
1da177e4 LT |
852 | * way that allows us to also free its memory inside the callee. |
853 | * Because we may want to schedule several tasks with different | |
854 | * parameters we can't use the approach some kernel code uses of | |
65f27f38 | 855 | * having a static work_struct. |
1da177e4 | 856 | */ |
72945b2b | 857 | |
65f27f38 | 858 | dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC); |
1da177e4 | 859 | if (!dpc) |
889c78be | 860 | return AE_NO_MEMORY; |
b976fe19 | 861 | |
1da177e4 LT |
862 | dpc->function = function; |
863 | dpc->context = context; | |
b976fe19 | 864 | |
c02256be ZR |
865 | /* |
866 | * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq | |
867 | * because the hotplug code may call driver .remove() functions, | |
868 | * which invoke flush_scheduled_work/acpi_os_wait_events_complete | |
869 | * to flush these workqueues. | |
870 | */ | |
871 | queue = hp ? kacpi_hotplug_wq : | |
872 | (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq); | |
9ac61856 | 873 | dpc->wait = hp ? 1 : 0; |
bc73675b ZR |
874 | |
875 | if (queue == kacpi_hotplug_wq) | |
876 | INIT_WORK(&dpc->work, acpi_os_execute_deferred); | |
877 | else if (queue == kacpi_notify_wq) | |
878 | INIT_WORK(&dpc->work, acpi_os_execute_deferred); | |
879 | else | |
880 | INIT_WORK(&dpc->work, acpi_os_execute_deferred); | |
881 | ||
8fec62b2 TH |
882 | /* |
883 | * On some machines, a software-initiated SMI causes corruption unless | |
884 | * the SMI runs on CPU 0. An SMI can be initiated by any AML, but | |
885 | * typically it's done in GPE-related methods that are run via | |
886 | * workqueues, so we can avoid the known corruption cases by always | |
887 | * queueing on CPU 0. | |
888 | */ | |
889 | ret = queue_work_on(0, queue, &dpc->work); | |
19cd847a ZR |
890 | |
891 | if (!ret) { | |
55ac9a01 LM |
892 | printk(KERN_ERR PREFIX |
893 | "Call to queue_work() failed.\n"); | |
17bc54ee AS |
894 | status = AE_ERROR; |
895 | kfree(dpc); | |
1da177e4 | 896 | } |
889c78be | 897 | return status; |
1da177e4 | 898 | } |
4be44fcd | 899 | |
19cd847a ZR |
900 | acpi_status acpi_os_execute(acpi_execute_type type, |
901 | acpi_osd_exec_callback function, void *context) | |
902 | { | |
903 | return __acpi_os_execute(type, function, context, 0); | |
904 | } | |
b8d35192 | 905 | EXPORT_SYMBOL(acpi_os_execute); |
1da177e4 | 906 | |
19cd847a ZR |
907 | acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function, |
908 | void *context) | |
909 | { | |
910 | return __acpi_os_execute(0, function, context, 1); | |
911 | } | |
912 | ||
4be44fcd | 913 | void acpi_os_wait_events_complete(void *context) |
1da177e4 LT |
914 | { |
915 | flush_workqueue(kacpid_wq); | |
2f67a069 | 916 | flush_workqueue(kacpi_notify_wq); |
1da177e4 | 917 | } |
4be44fcd | 918 | |
1da177e4 LT |
919 | EXPORT_SYMBOL(acpi_os_wait_events_complete); |
920 | ||
1da177e4 | 921 | acpi_status |
4be44fcd | 922 | acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle) |
1da177e4 | 923 | { |
4be44fcd | 924 | struct semaphore *sem = NULL; |
1da177e4 | 925 | |
1da177e4 LT |
926 | sem = acpi_os_allocate(sizeof(struct semaphore)); |
927 | if (!sem) | |
d550d98d | 928 | return AE_NO_MEMORY; |
1da177e4 LT |
929 | memset(sem, 0, sizeof(struct semaphore)); |
930 | ||
931 | sema_init(sem, initial_units); | |
932 | ||
4be44fcd | 933 | *handle = (acpi_handle *) sem; |
1da177e4 | 934 | |
4be44fcd LB |
935 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n", |
936 | *handle, initial_units)); | |
1da177e4 | 937 | |
d550d98d | 938 | return AE_OK; |
1da177e4 | 939 | } |
1da177e4 | 940 | |
1da177e4 LT |
941 | /* |
942 | * TODO: A better way to delete semaphores? Linux doesn't have a | |
943 | * 'delete_semaphore()' function -- may result in an invalid | |
944 | * pointer dereference for non-synchronized consumers. Should | |
945 | * we at least check for blocked threads and signal/cancel them? | |
946 | */ | |
947 | ||
4be44fcd | 948 | acpi_status acpi_os_delete_semaphore(acpi_handle handle) |
1da177e4 | 949 | { |
4be44fcd | 950 | struct semaphore *sem = (struct semaphore *)handle; |
1da177e4 | 951 | |
1da177e4 | 952 | if (!sem) |
d550d98d | 953 | return AE_BAD_PARAMETER; |
1da177e4 | 954 | |
4be44fcd | 955 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); |
1da177e4 | 956 | |
f1241c87 | 957 | BUG_ON(!list_empty(&sem->wait_list)); |
02438d87 | 958 | kfree(sem); |
4be44fcd | 959 | sem = NULL; |
1da177e4 | 960 | |
d550d98d | 961 | return AE_OK; |
1da177e4 | 962 | } |
1da177e4 | 963 | |
1da177e4 | 964 | /* |
1da177e4 LT |
965 | * TODO: Support for units > 1? |
966 | */ | |
4be44fcd | 967 | acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout) |
1da177e4 | 968 | { |
4be44fcd LB |
969 | acpi_status status = AE_OK; |
970 | struct semaphore *sem = (struct semaphore *)handle; | |
f1241c87 | 971 | long jiffies; |
4be44fcd | 972 | int ret = 0; |
1da177e4 | 973 | |
1da177e4 | 974 | if (!sem || (units < 1)) |
d550d98d | 975 | return AE_BAD_PARAMETER; |
1da177e4 LT |
976 | |
977 | if (units > 1) | |
d550d98d | 978 | return AE_SUPPORT; |
1da177e4 | 979 | |
4be44fcd LB |
980 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n", |
981 | handle, units, timeout)); | |
1da177e4 | 982 | |
f1241c87 MW |
983 | if (timeout == ACPI_WAIT_FOREVER) |
984 | jiffies = MAX_SCHEDULE_TIMEOUT; | |
985 | else | |
986 | jiffies = msecs_to_jiffies(timeout); | |
987 | ||
988 | ret = down_timeout(sem, jiffies); | |
989 | if (ret) | |
990 | status = AE_TIME; | |
1da177e4 LT |
991 | |
992 | if (ACPI_FAILURE(status)) { | |
9e7e2c04 | 993 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
a6fc6720 | 994 | "Failed to acquire semaphore[%p|%d|%d], %s", |
4be44fcd LB |
995 | handle, units, timeout, |
996 | acpi_format_exception(status))); | |
997 | } else { | |
998 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, | |
a6fc6720 | 999 | "Acquired semaphore[%p|%d|%d]", handle, |
4be44fcd | 1000 | units, timeout)); |
1da177e4 LT |
1001 | } |
1002 | ||
d550d98d | 1003 | return status; |
1da177e4 | 1004 | } |
1da177e4 | 1005 | |
1da177e4 LT |
1006 | /* |
1007 | * TODO: Support for units > 1? | |
1008 | */ | |
4be44fcd | 1009 | acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) |
1da177e4 | 1010 | { |
4be44fcd | 1011 | struct semaphore *sem = (struct semaphore *)handle; |
1da177e4 | 1012 | |
1da177e4 | 1013 | if (!sem || (units < 1)) |
d550d98d | 1014 | return AE_BAD_PARAMETER; |
1da177e4 LT |
1015 | |
1016 | if (units > 1) | |
d550d98d | 1017 | return AE_SUPPORT; |
1da177e4 | 1018 | |
4be44fcd LB |
1019 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle, |
1020 | units)); | |
1da177e4 LT |
1021 | |
1022 | up(sem); | |
1023 | ||
d550d98d | 1024 | return AE_OK; |
1da177e4 | 1025 | } |
4be44fcd | 1026 | |
1da177e4 | 1027 | #ifdef ACPI_FUTURE_USAGE |
4be44fcd | 1028 | u32 acpi_os_get_line(char *buffer) |
1da177e4 LT |
1029 | { |
1030 | ||
1031 | #ifdef ENABLE_DEBUGGER | |
1032 | if (acpi_in_debugger) { | |
1033 | u32 chars; | |
1034 | ||
1035 | kdb_read(buffer, sizeof(line_buf)); | |
1036 | ||
1037 | /* remove the CR kdb includes */ | |
1038 | chars = strlen(buffer) - 1; | |
1039 | buffer[chars] = '\0'; | |
1040 | } | |
1041 | #endif | |
1042 | ||
1043 | return 0; | |
1044 | } | |
4be44fcd | 1045 | #endif /* ACPI_FUTURE_USAGE */ |
1da177e4 | 1046 | |
4be44fcd | 1047 | acpi_status acpi_os_signal(u32 function, void *info) |
1da177e4 | 1048 | { |
4be44fcd | 1049 | switch (function) { |
1da177e4 LT |
1050 | case ACPI_SIGNAL_FATAL: |
1051 | printk(KERN_ERR PREFIX "Fatal opcode executed\n"); | |
1052 | break; | |
1053 | case ACPI_SIGNAL_BREAKPOINT: | |
1054 | /* | |
1055 | * AML Breakpoint | |
1056 | * ACPI spec. says to treat it as a NOP unless | |
1057 | * you are debugging. So if/when we integrate | |
1058 | * AML debugger into the kernel debugger its | |
1059 | * hook will go here. But until then it is | |
1060 | * not useful to print anything on breakpoints. | |
1061 | */ | |
1062 | break; | |
1063 | default: | |
1064 | break; | |
1065 | } | |
1066 | ||
1067 | return AE_OK; | |
1068 | } | |
4be44fcd | 1069 | |
4be44fcd | 1070 | static int __init acpi_os_name_setup(char *str) |
1da177e4 LT |
1071 | { |
1072 | char *p = acpi_os_name; | |
4be44fcd | 1073 | int count = ACPI_MAX_OVERRIDE_LEN - 1; |
1da177e4 LT |
1074 | |
1075 | if (!str || !*str) | |
1076 | return 0; | |
1077 | ||
1078 | for (; count-- && str && *str; str++) { | |
1079 | if (isalnum(*str) || *str == ' ' || *str == ':') | |
1080 | *p++ = *str; | |
1081 | else if (*str == '\'' || *str == '"') | |
1082 | continue; | |
1083 | else | |
1084 | break; | |
1085 | } | |
1086 | *p = 0; | |
1087 | ||
1088 | return 1; | |
4be44fcd | 1089 | |
1da177e4 LT |
1090 | } |
1091 | ||
1092 | __setup("acpi_os_name=", acpi_os_name_setup); | |
1093 | ||
12d32064 LM |
1094 | #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */ |
1095 | #define OSI_STRING_ENTRIES_MAX 16 /* arbitrary */ | |
1096 | ||
1097 | struct osi_setup_entry { | |
1098 | char string[OSI_STRING_LENGTH_MAX]; | |
1099 | bool enable; | |
1100 | }; | |
1101 | ||
aa165971 SL |
1102 | static struct osi_setup_entry __initdata |
1103 | osi_setup_entries[OSI_STRING_ENTRIES_MAX] = { | |
1104 | {"Module Device", true}, | |
1105 | {"Processor Device", true}, | |
1106 | {"3.0 _SCP Extensions", true}, | |
1107 | {"Processor Aggregator Device", true}, | |
1108 | }; | |
12d32064 | 1109 | |
d90aa92c LM |
1110 | void __init acpi_osi_setup(char *str) |
1111 | { | |
12d32064 LM |
1112 | struct osi_setup_entry *osi; |
1113 | bool enable = true; | |
1114 | int i; | |
1115 | ||
d90aa92c LM |
1116 | if (!acpi_gbl_create_osi_method) |
1117 | return; | |
1118 | ||
1119 | if (str == NULL || *str == '\0') { | |
1120 | printk(KERN_INFO PREFIX "_OSI method disabled\n"); | |
1121 | acpi_gbl_create_osi_method = FALSE; | |
12d32064 LM |
1122 | return; |
1123 | } | |
1124 | ||
1125 | if (*str == '!') { | |
1126 | str++; | |
1127 | enable = false; | |
1128 | } | |
1129 | ||
1130 | for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) { | |
1131 | osi = &osi_setup_entries[i]; | |
1132 | if (!strcmp(osi->string, str)) { | |
1133 | osi->enable = enable; | |
1134 | break; | |
1135 | } else if (osi->string[0] == '\0') { | |
1136 | osi->enable = enable; | |
1137 | strncpy(osi->string, str, OSI_STRING_LENGTH_MAX); | |
1138 | break; | |
1139 | } | |
1140 | } | |
d90aa92c LM |
1141 | } |
1142 | ||
d4b7dc49 LB |
1143 | static void __init set_osi_linux(unsigned int enable) |
1144 | { | |
d90aa92c | 1145 | if (osi_linux.enable != enable) |
d4b7dc49 | 1146 | osi_linux.enable = enable; |
b0ed7a91 LM |
1147 | |
1148 | if (osi_linux.enable) | |
1149 | acpi_osi_setup("Linux"); | |
1150 | else | |
1151 | acpi_osi_setup("!Linux"); | |
1152 | ||
d4b7dc49 LB |
1153 | return; |
1154 | } | |
1155 | ||
1156 | static void __init acpi_cmdline_osi_linux(unsigned int enable) | |
1157 | { | |
d90aa92c LM |
1158 | osi_linux.cmdline = 1; /* cmdline set the default and override DMI */ |
1159 | osi_linux.dmi = 0; | |
d4b7dc49 LB |
1160 | set_osi_linux(enable); |
1161 | ||
1162 | return; | |
1163 | } | |
1164 | ||
1165 | void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d) | |
1166 | { | |
d4b7dc49 LB |
1167 | printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident); |
1168 | ||
1169 | if (enable == -1) | |
1170 | return; | |
1171 | ||
d90aa92c | 1172 | osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */ |
d4b7dc49 | 1173 | set_osi_linux(enable); |
f507654d | 1174 | |
f507654d LB |
1175 | return; |
1176 | } | |
1177 | ||
1da177e4 | 1178 | /* |
ae00d812 LB |
1179 | * Modify the list of "OS Interfaces" reported to BIOS via _OSI |
1180 | * | |
1da177e4 | 1181 | * empty string disables _OSI |
ae00d812 LB |
1182 | * string starting with '!' disables that string |
1183 | * otherwise string is added to list, augmenting built-in strings | |
1da177e4 | 1184 | */ |
b0ed7a91 | 1185 | static void __init acpi_osi_setup_late(void) |
1da177e4 | 1186 | { |
12d32064 LM |
1187 | struct osi_setup_entry *osi; |
1188 | char *str; | |
1189 | int i; | |
d90aa92c | 1190 | acpi_status status; |
b0ed7a91 | 1191 | |
12d32064 LM |
1192 | for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) { |
1193 | osi = &osi_setup_entries[i]; | |
1194 | str = osi->string; | |
b0ed7a91 | 1195 | |
12d32064 LM |
1196 | if (*str == '\0') |
1197 | break; | |
1198 | if (osi->enable) { | |
1199 | status = acpi_install_interface(str); | |
d90aa92c | 1200 | |
12d32064 LM |
1201 | if (ACPI_SUCCESS(status)) |
1202 | printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str); | |
1203 | } else { | |
1204 | status = acpi_remove_interface(str); | |
d90aa92c | 1205 | |
12d32064 LM |
1206 | if (ACPI_SUCCESS(status)) |
1207 | printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str); | |
1208 | } | |
b0ed7a91 LM |
1209 | } |
1210 | } | |
1211 | ||
d90aa92c | 1212 | static int __init osi_setup(char *str) |
b0ed7a91 | 1213 | { |
d90aa92c LM |
1214 | if (str && !strcmp("Linux", str)) |
1215 | acpi_cmdline_osi_linux(1); | |
1216 | else if (str && !strcmp("!Linux", str)) | |
1217 | acpi_cmdline_osi_linux(0); | |
1218 | else | |
1219 | acpi_osi_setup(str); | |
1da177e4 LT |
1220 | |
1221 | return 1; | |
1222 | } | |
1223 | ||
d90aa92c | 1224 | __setup("acpi_osi=", osi_setup); |
1da177e4 LT |
1225 | |
1226 | /* enable serialization to combat AE_ALREADY_EXISTS errors */ | |
4be44fcd | 1227 | static int __init acpi_serialize_setup(char *str) |
1da177e4 LT |
1228 | { |
1229 | printk(KERN_INFO PREFIX "serialize enabled\n"); | |
1230 | ||
1231 | acpi_gbl_all_methods_serialized = TRUE; | |
1232 | ||
1233 | return 1; | |
1234 | } | |
1235 | ||
1236 | __setup("acpi_serialize", acpi_serialize_setup); | |
1237 | ||
df92e695 TR |
1238 | /* Check of resource interference between native drivers and ACPI |
1239 | * OperationRegions (SystemIO and System Memory only). | |
1240 | * IO ports and memory declared in ACPI might be used by the ACPI subsystem | |
1241 | * in arbitrary AML code and can interfere with legacy drivers. | |
1242 | * acpi_enforce_resources= can be set to: | |
1243 | * | |
7e90560c | 1244 | * - strict (default) (2) |
df92e695 | 1245 | * -> further driver trying to access the resources will not load |
7e90560c | 1246 | * - lax (1) |
df92e695 TR |
1247 | * -> further driver trying to access the resources will load, but you |
1248 | * get a system message that something might go wrong... | |
1249 | * | |
1250 | * - no (0) | |
1251 | * -> ACPI Operation Region resources will not be registered | |
1252 | * | |
1253 | */ | |
1254 | #define ENFORCE_RESOURCES_STRICT 2 | |
1255 | #define ENFORCE_RESOURCES_LAX 1 | |
1256 | #define ENFORCE_RESOURCES_NO 0 | |
1257 | ||
7e90560c | 1258 | static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT; |
df92e695 TR |
1259 | |
1260 | static int __init acpi_enforce_resources_setup(char *str) | |
1261 | { | |
1262 | if (str == NULL || *str == '\0') | |
1263 | return 0; | |
1264 | ||
1265 | if (!strcmp("strict", str)) | |
1266 | acpi_enforce_resources = ENFORCE_RESOURCES_STRICT; | |
1267 | else if (!strcmp("lax", str)) | |
1268 | acpi_enforce_resources = ENFORCE_RESOURCES_LAX; | |
1269 | else if (!strcmp("no", str)) | |
1270 | acpi_enforce_resources = ENFORCE_RESOURCES_NO; | |
1271 | ||
1272 | return 1; | |
1273 | } | |
1274 | ||
1275 | __setup("acpi_enforce_resources=", acpi_enforce_resources_setup); | |
1276 | ||
1277 | /* Check for resource conflicts between ACPI OperationRegions and native | |
1278 | * drivers */ | |
876fba43 | 1279 | int acpi_check_resource_conflict(const struct resource *res) |
df92e695 TR |
1280 | { |
1281 | struct acpi_res_list *res_list_elem; | |
106d1a0a | 1282 | int ioport = 0, clash = 0; |
df92e695 TR |
1283 | |
1284 | if (acpi_enforce_resources == ENFORCE_RESOURCES_NO) | |
1285 | return 0; | |
1286 | if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM)) | |
1287 | return 0; | |
1288 | ||
1289 | ioport = res->flags & IORESOURCE_IO; | |
1290 | ||
1291 | spin_lock(&acpi_res_lock); | |
1292 | list_for_each_entry(res_list_elem, &resource_list_head, | |
1293 | resource_list) { | |
1294 | if (ioport && (res_list_elem->resource_type | |
1295 | != ACPI_ADR_SPACE_SYSTEM_IO)) | |
1296 | continue; | |
1297 | if (!ioport && (res_list_elem->resource_type | |
1298 | != ACPI_ADR_SPACE_SYSTEM_MEMORY)) | |
1299 | continue; | |
1300 | ||
1301 | if (res->end < res_list_elem->start | |
1302 | || res_list_elem->end < res->start) | |
1303 | continue; | |
1304 | clash = 1; | |
1305 | break; | |
1306 | } | |
1307 | spin_unlock(&acpi_res_lock); | |
1308 | ||
1309 | if (clash) { | |
1310 | if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) { | |
1638bca8 | 1311 | printk(KERN_WARNING "ACPI: resource %s %pR" |
106d1a0a TR |
1312 | " conflicts with ACPI region %s " |
1313 | "[%s 0x%zx-0x%zx]\n", | |
1638bca8 | 1314 | res->name, res, res_list_elem->name, |
106d1a0a TR |
1315 | (res_list_elem->resource_type == |
1316 | ACPI_ADR_SPACE_SYSTEM_IO) ? "io" : "mem", | |
1317 | (size_t) res_list_elem->start, | |
1318 | (size_t) res_list_elem->end); | |
14f03343 JD |
1319 | if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX) |
1320 | printk(KERN_NOTICE "ACPI: This conflict may" | |
1321 | " cause random problems and system" | |
1322 | " instability\n"); | |
1323 | printk(KERN_INFO "ACPI: If an ACPI driver is available" | |
1324 | " for this device, you should use it instead of" | |
1325 | " the native driver\n"); | |
df92e695 TR |
1326 | } |
1327 | if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT) | |
1328 | return -EBUSY; | |
1329 | } | |
1330 | return 0; | |
1331 | } | |
443dea72 | 1332 | EXPORT_SYMBOL(acpi_check_resource_conflict); |
df92e695 TR |
1333 | |
1334 | int acpi_check_region(resource_size_t start, resource_size_t n, | |
1335 | const char *name) | |
1336 | { | |
1337 | struct resource res = { | |
1338 | .start = start, | |
1339 | .end = start + n - 1, | |
1340 | .name = name, | |
1341 | .flags = IORESOURCE_IO, | |
1342 | }; | |
1343 | ||
1344 | return acpi_check_resource_conflict(&res); | |
1345 | } | |
1346 | EXPORT_SYMBOL(acpi_check_region); | |
1347 | ||
70dd6bea JD |
1348 | /* |
1349 | * Let drivers know whether the resource checks are effective | |
1350 | */ | |
1351 | int acpi_resources_are_enforced(void) | |
1352 | { | |
1353 | return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT; | |
1354 | } | |
1355 | EXPORT_SYMBOL(acpi_resources_are_enforced); | |
1356 | ||
9f63b88b LM |
1357 | /* |
1358 | * Deallocate the memory for a spinlock. | |
1359 | */ | |
1360 | void acpi_os_delete_lock(acpi_spinlock handle) | |
1361 | { | |
1362 | ACPI_FREE(handle); | |
1363 | } | |
1364 | ||
73459f73 RM |
1365 | /* |
1366 | * Acquire a spinlock. | |
1367 | * | |
1368 | * handle is a pointer to the spinlock_t. | |
73459f73 RM |
1369 | */ |
1370 | ||
967440e3 | 1371 | acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp) |
73459f73 | 1372 | { |
b8e4d893 | 1373 | acpi_cpu_flags flags; |
967440e3 | 1374 | spin_lock_irqsave(lockp, flags); |
73459f73 RM |
1375 | return flags; |
1376 | } | |
1377 | ||
1378 | /* | |
1379 | * Release a spinlock. See above. | |
1380 | */ | |
1381 | ||
967440e3 | 1382 | void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags) |
73459f73 | 1383 | { |
967440e3 | 1384 | spin_unlock_irqrestore(lockp, flags); |
73459f73 RM |
1385 | } |
1386 | ||
73459f73 RM |
1387 | #ifndef ACPI_USE_LOCAL_CACHE |
1388 | ||
1389 | /******************************************************************************* | |
1390 | * | |
1391 | * FUNCTION: acpi_os_create_cache | |
1392 | * | |
b229cf92 BM |
1393 | * PARAMETERS: name - Ascii name for the cache |
1394 | * size - Size of each cached object | |
1395 | * depth - Maximum depth of the cache (in objects) <ignored> | |
1396 | * cache - Where the new cache object is returned | |
73459f73 | 1397 | * |
b229cf92 | 1398 | * RETURN: status |
73459f73 RM |
1399 | * |
1400 | * DESCRIPTION: Create a cache object | |
1401 | * | |
1402 | ******************************************************************************/ | |
1403 | ||
1404 | acpi_status | |
4be44fcd | 1405 | acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache) |
73459f73 | 1406 | { |
20c2df83 | 1407 | *cache = kmem_cache_create(name, size, 0, 0, NULL); |
a6fdbf90 | 1408 | if (*cache == NULL) |
b229cf92 BM |
1409 | return AE_ERROR; |
1410 | else | |
1411 | return AE_OK; | |
73459f73 RM |
1412 | } |
1413 | ||
1414 | /******************************************************************************* | |
1415 | * | |
1416 | * FUNCTION: acpi_os_purge_cache | |
1417 | * | |
1418 | * PARAMETERS: Cache - Handle to cache object | |
1419 | * | |
1420 | * RETURN: Status | |
1421 | * | |
1422 | * DESCRIPTION: Free all objects within the requested cache. | |
1423 | * | |
1424 | ******************************************************************************/ | |
1425 | ||
4be44fcd | 1426 | acpi_status acpi_os_purge_cache(acpi_cache_t * cache) |
73459f73 | 1427 | { |
50dd0969 | 1428 | kmem_cache_shrink(cache); |
4be44fcd | 1429 | return (AE_OK); |
73459f73 RM |
1430 | } |
1431 | ||
1432 | /******************************************************************************* | |
1433 | * | |
1434 | * FUNCTION: acpi_os_delete_cache | |
1435 | * | |
1436 | * PARAMETERS: Cache - Handle to cache object | |
1437 | * | |
1438 | * RETURN: Status | |
1439 | * | |
1440 | * DESCRIPTION: Free all objects within the requested cache and delete the | |
1441 | * cache object. | |
1442 | * | |
1443 | ******************************************************************************/ | |
1444 | ||
4be44fcd | 1445 | acpi_status acpi_os_delete_cache(acpi_cache_t * cache) |
73459f73 | 1446 | { |
1a1d92c1 | 1447 | kmem_cache_destroy(cache); |
4be44fcd | 1448 | return (AE_OK); |
73459f73 RM |
1449 | } |
1450 | ||
1451 | /******************************************************************************* | |
1452 | * | |
1453 | * FUNCTION: acpi_os_release_object | |
1454 | * | |
1455 | * PARAMETERS: Cache - Handle to cache object | |
1456 | * Object - The object to be released | |
1457 | * | |
1458 | * RETURN: None | |
1459 | * | |
1460 | * DESCRIPTION: Release an object to the specified cache. If cache is full, | |
1461 | * the object is deleted. | |
1462 | * | |
1463 | ******************************************************************************/ | |
1464 | ||
4be44fcd | 1465 | acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object) |
73459f73 | 1466 | { |
4be44fcd LB |
1467 | kmem_cache_free(cache, object); |
1468 | return (AE_OK); | |
73459f73 RM |
1469 | } |
1470 | ||
a5fe1a03 LM |
1471 | static inline int acpi_res_list_add(struct acpi_res_list *res) |
1472 | { | |
1473 | struct acpi_res_list *res_list_elem; | |
1474 | ||
1475 | list_for_each_entry(res_list_elem, &resource_list_head, | |
1476 | resource_list) { | |
1477 | ||
1478 | if (res->resource_type == res_list_elem->resource_type && | |
1479 | res->start == res_list_elem->start && | |
1480 | res->end == res_list_elem->end) { | |
1481 | ||
1482 | /* | |
1483 | * The Region(addr,len) already exist in the list, | |
1484 | * just increase the count | |
1485 | */ | |
1486 | ||
1487 | res_list_elem->count++; | |
1488 | return 0; | |
1489 | } | |
1490 | } | |
1491 | ||
1492 | res->count = 1; | |
1493 | list_add(&res->resource_list, &resource_list_head); | |
1494 | return 1; | |
1495 | } | |
1496 | ||
1497 | static inline void acpi_res_list_del(struct acpi_res_list *res) | |
1498 | { | |
1499 | struct acpi_res_list *res_list_elem; | |
1500 | ||
1501 | list_for_each_entry(res_list_elem, &resource_list_head, | |
1502 | resource_list) { | |
1503 | ||
1504 | if (res->resource_type == res_list_elem->resource_type && | |
1505 | res->start == res_list_elem->start && | |
1506 | res->end == res_list_elem->end) { | |
1507 | ||
1508 | /* | |
1509 | * If the res count is decreased to 0, | |
1510 | * remove and free it | |
1511 | */ | |
1512 | ||
1513 | if (--res_list_elem->count == 0) { | |
1514 | list_del(&res_list_elem->resource_list); | |
1515 | kfree(res_list_elem); | |
1516 | } | |
1517 | return; | |
1518 | } | |
1519 | } | |
1520 | } | |
1521 | ||
1522 | acpi_status | |
1523 | acpi_os_invalidate_address( | |
1524 | u8 space_id, | |
1525 | acpi_physical_address address, | |
1526 | acpi_size length) | |
1527 | { | |
1528 | struct acpi_res_list res; | |
1529 | ||
1530 | switch (space_id) { | |
1531 | case ACPI_ADR_SPACE_SYSTEM_IO: | |
1532 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: | |
88393161 | 1533 | /* Only interference checks against SystemIO and SystemMemory |
a5fe1a03 LM |
1534 | are needed */ |
1535 | res.start = address; | |
1536 | res.end = address + length - 1; | |
1537 | res.resource_type = space_id; | |
1538 | spin_lock(&acpi_res_lock); | |
1539 | acpi_res_list_del(&res); | |
1540 | spin_unlock(&acpi_res_lock); | |
1541 | break; | |
1542 | case ACPI_ADR_SPACE_PCI_CONFIG: | |
1543 | case ACPI_ADR_SPACE_EC: | |
1544 | case ACPI_ADR_SPACE_SMBUS: | |
1545 | case ACPI_ADR_SPACE_CMOS: | |
1546 | case ACPI_ADR_SPACE_PCI_BAR_TARGET: | |
1547 | case ACPI_ADR_SPACE_DATA_TABLE: | |
1548 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | |
1549 | break; | |
1550 | } | |
1551 | return AE_OK; | |
1552 | } | |
1553 | ||
b229cf92 BM |
1554 | /****************************************************************************** |
1555 | * | |
1556 | * FUNCTION: acpi_os_validate_address | |
1557 | * | |
1558 | * PARAMETERS: space_id - ACPI space ID | |
1559 | * address - Physical address | |
1560 | * length - Address length | |
1561 | * | |
1562 | * RETURN: AE_OK if address/length is valid for the space_id. Otherwise, | |
1563 | * should return AE_AML_ILLEGAL_ADDRESS. | |
1564 | * | |
1565 | * DESCRIPTION: Validate a system address via the host OS. Used to validate | |
1566 | * the addresses accessed by AML operation regions. | |
1567 | * | |
1568 | *****************************************************************************/ | |
1569 | ||
1570 | acpi_status | |
1571 | acpi_os_validate_address ( | |
1572 | u8 space_id, | |
1573 | acpi_physical_address address, | |
df92e695 TR |
1574 | acpi_size length, |
1575 | char *name) | |
b229cf92 | 1576 | { |
df92e695 | 1577 | struct acpi_res_list *res; |
a5fe1a03 | 1578 | int added; |
df92e695 TR |
1579 | if (acpi_enforce_resources == ENFORCE_RESOURCES_NO) |
1580 | return AE_OK; | |
b229cf92 | 1581 | |
df92e695 TR |
1582 | switch (space_id) { |
1583 | case ACPI_ADR_SPACE_SYSTEM_IO: | |
1584 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: | |
88393161 | 1585 | /* Only interference checks against SystemIO and SystemMemory |
df92e695 TR |
1586 | are needed */ |
1587 | res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL); | |
1588 | if (!res) | |
1589 | return AE_OK; | |
1590 | /* ACPI names are fixed to 4 bytes, still better use strlcpy */ | |
1591 | strlcpy(res->name, name, 5); | |
1592 | res->start = address; | |
1593 | res->end = address + length - 1; | |
1594 | res->resource_type = space_id; | |
1595 | spin_lock(&acpi_res_lock); | |
a5fe1a03 | 1596 | added = acpi_res_list_add(res); |
df92e695 | 1597 | spin_unlock(&acpi_res_lock); |
a5fe1a03 LM |
1598 | pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, " |
1599 | "name: %s\n", added ? "Added" : "Already exist", | |
1600 | (space_id == ACPI_ADR_SPACE_SYSTEM_IO) | |
df92e695 TR |
1601 | ? "SystemIO" : "System Memory", |
1602 | (unsigned long long)res->start, | |
1603 | (unsigned long long)res->end, | |
1604 | res->name); | |
a5fe1a03 LM |
1605 | if (!added) |
1606 | kfree(res); | |
df92e695 TR |
1607 | break; |
1608 | case ACPI_ADR_SPACE_PCI_CONFIG: | |
1609 | case ACPI_ADR_SPACE_EC: | |
1610 | case ACPI_ADR_SPACE_SMBUS: | |
1611 | case ACPI_ADR_SPACE_CMOS: | |
1612 | case ACPI_ADR_SPACE_PCI_BAR_TARGET: | |
1613 | case ACPI_ADR_SPACE_DATA_TABLE: | |
1614 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | |
1615 | break; | |
1616 | } | |
1617 | return AE_OK; | |
b229cf92 | 1618 | } |
73459f73 | 1619 | #endif |
d362edaf MS |
1620 | |
1621 | acpi_status __init acpi_os_initialize(void) | |
1622 | { | |
1623 | acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1a_event_block); | |
1624 | acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1b_event_block); | |
1625 | acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe0_block); | |
1626 | acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe1_block); | |
1627 | ||
1628 | return AE_OK; | |
1629 | } | |
1630 | ||
32d47eef | 1631 | acpi_status __init acpi_os_initialize1(void) |
d362edaf | 1632 | { |
44d2588e TH |
1633 | kacpid_wq = alloc_workqueue("kacpid", 0, 1); |
1634 | kacpi_notify_wq = alloc_workqueue("kacpi_notify", 0, 1); | |
1635 | kacpi_hotplug_wq = alloc_workqueue("kacpi_hotplug", 0, 1); | |
d362edaf MS |
1636 | BUG_ON(!kacpid_wq); |
1637 | BUG_ON(!kacpi_notify_wq); | |
1638 | BUG_ON(!kacpi_hotplug_wq); | |
1bd64d42 LB |
1639 | acpi_install_interface_handler(acpi_osi_handler); |
1640 | acpi_osi_setup_late(); | |
d362edaf MS |
1641 | return AE_OK; |
1642 | } | |
1643 | ||
1644 | acpi_status acpi_os_terminate(void) | |
1645 | { | |
1646 | if (acpi_irq_handler) { | |
23fe3630 | 1647 | acpi_os_remove_interrupt_handler(acpi_gbl_FADT.sci_interrupt, |
d362edaf MS |
1648 | acpi_irq_handler); |
1649 | } | |
1650 | ||
1651 | acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe1_block); | |
1652 | acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe0_block); | |
1653 | acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1b_event_block); | |
1654 | acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1a_event_block); | |
1655 | ||
1656 | destroy_workqueue(kacpid_wq); | |
1657 | destroy_workqueue(kacpi_notify_wq); | |
1658 | destroy_workqueue(kacpi_hotplug_wq); | |
1659 | ||
1660 | return AE_OK; | |
1661 | } |