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> | |
f507654d | 38 | #include <linux/dmi.h> |
1da177e4 LT |
39 | #include <linux/workqueue.h> |
40 | #include <linux/nmi.h> | |
ad71860a | 41 | #include <linux/acpi.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; |
1da177e4 LT |
62 | }; |
63 | ||
64 | #ifdef CONFIG_ACPI_CUSTOM_DSDT | |
65 | #include CONFIG_ACPI_CUSTOM_DSDT_FILE | |
66 | #endif | |
67 | ||
68 | #ifdef ENABLE_DEBUGGER | |
69 | #include <linux/kdb.h> | |
70 | ||
71 | /* stuff for debugger support */ | |
72 | int acpi_in_debugger; | |
73 | EXPORT_SYMBOL(acpi_in_debugger); | |
74 | ||
75 | extern char line_buf[80]; | |
4be44fcd | 76 | #endif /*ENABLE_DEBUGGER */ |
1da177e4 LT |
77 | |
78 | static unsigned int acpi_irq_irq; | |
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; |
1da177e4 | 83 | |
df92e695 TR |
84 | struct acpi_res_list { |
85 | resource_size_t start; | |
86 | resource_size_t end; | |
87 | acpi_adr_space_type resource_type; /* IO port, System memory, ...*/ | |
88 | char name[5]; /* only can have a length of 4 chars, make use of this | |
89 | one instead of res->name, no need to kalloc then */ | |
90 | struct list_head resource_list; | |
91 | }; | |
92 | ||
93 | static LIST_HEAD(resource_list_head); | |
94 | static DEFINE_SPINLOCK(acpi_res_lock); | |
95 | ||
ae00d812 LB |
96 | #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */ |
97 | static char osi_additional_string[OSI_STRING_LENGTH_MAX]; | |
98 | ||
d4b7dc49 LB |
99 | /* |
100 | * "Ode to _OSI(Linux)" | |
101 | * | |
102 | * osi_linux -- Control response to BIOS _OSI(Linux) query. | |
103 | * | |
104 | * As Linux evolves, the features that it supports change. | |
105 | * So an OSI string such as "Linux" is not specific enough | |
106 | * to be useful across multiple versions of Linux. It | |
107 | * doesn't identify any particular feature, interface, | |
108 | * or even any particular version of Linux... | |
109 | * | |
110 | * Unfortunately, Linux-2.6.22 and earlier responded "yes" | |
111 | * to a BIOS _OSI(Linux) query. When | |
112 | * a reference mobile BIOS started using it, its use | |
113 | * started to spread to many vendor platforms. | |
114 | * As it is not supportable, we need to halt that spread. | |
115 | * | |
116 | * Today, most BIOS references to _OSI(Linux) are noise -- | |
117 | * they have no functional effect and are just dead code | |
118 | * carried over from the reference BIOS. | |
119 | * | |
120 | * The next most common case is that _OSI(Linux) harms Linux, | |
121 | * usually by causing the BIOS to follow paths that are | |
122 | * not tested during Windows validation. | |
123 | * | |
124 | * Finally, there is a short list of platforms | |
125 | * where OSI(Linux) benefits Linux. | |
126 | * | |
127 | * In Linux-2.6.23, OSI(Linux) is first disabled by default. | |
128 | * DMI is used to disable the dmesg warning about OSI(Linux) | |
129 | * on platforms where it is known to have no effect. | |
130 | * But a dmesg warning remains for systems where | |
131 | * we do not know if OSI(Linux) is good or bad for the system. | |
132 | * DMI is also used to enable OSI(Linux) for the machines | |
133 | * that are known to need it. | |
134 | * | |
135 | * BIOS writers should NOT query _OSI(Linux) on future systems. | |
136 | * It will be ignored by default, and to get Linux to | |
137 | * not ignore it will require a kernel source update to | |
138 | * add a DMI entry, or a boot-time "acpi_osi=Linux" invocation. | |
139 | */ | |
140 | #define OSI_LINUX_ENABLE 0 | |
141 | ||
1d15d84e | 142 | static struct osi_linux { |
d4b7dc49 LB |
143 | unsigned int enable:1; |
144 | unsigned int dmi:1; | |
145 | unsigned int cmdline:1; | |
146 | unsigned int known:1; | |
147 | } osi_linux = { OSI_LINUX_ENABLE, 0, 0, 0}; | |
f507654d | 148 | |
9a47cdb1 BH |
149 | static void __init acpi_request_region (struct acpi_generic_address *addr, |
150 | unsigned int length, char *desc) | |
151 | { | |
152 | struct resource *res; | |
153 | ||
154 | if (!addr->address || !length) | |
155 | return; | |
156 | ||
eee3c859 | 157 | if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO) |
9a47cdb1 | 158 | res = request_region(addr->address, length, desc); |
eee3c859 | 159 | else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) |
9a47cdb1 BH |
160 | res = request_mem_region(addr->address, length, desc); |
161 | } | |
162 | ||
163 | static int __init acpi_reserve_resources(void) | |
164 | { | |
eee3c859 | 165 | acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length, |
9a47cdb1 BH |
166 | "ACPI PM1a_EVT_BLK"); |
167 | ||
eee3c859 | 168 | acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length, |
9a47cdb1 BH |
169 | "ACPI PM1b_EVT_BLK"); |
170 | ||
eee3c859 | 171 | acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length, |
9a47cdb1 BH |
172 | "ACPI PM1a_CNT_BLK"); |
173 | ||
eee3c859 | 174 | acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length, |
9a47cdb1 BH |
175 | "ACPI PM1b_CNT_BLK"); |
176 | ||
eee3c859 LB |
177 | if (acpi_gbl_FADT.pm_timer_length == 4) |
178 | acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR"); | |
9a47cdb1 | 179 | |
eee3c859 | 180 | acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length, |
9a47cdb1 BH |
181 | "ACPI PM2_CNT_BLK"); |
182 | ||
183 | /* Length of GPE blocks must be a non-negative multiple of 2 */ | |
184 | ||
eee3c859 LB |
185 | if (!(acpi_gbl_FADT.gpe0_block_length & 0x1)) |
186 | acpi_request_region(&acpi_gbl_FADT.xgpe0_block, | |
187 | acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK"); | |
9a47cdb1 | 188 | |
eee3c859 LB |
189 | if (!(acpi_gbl_FADT.gpe1_block_length & 0x1)) |
190 | acpi_request_region(&acpi_gbl_FADT.xgpe1_block, | |
191 | acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK"); | |
9a47cdb1 BH |
192 | |
193 | return 0; | |
194 | } | |
195 | device_initcall(acpi_reserve_resources); | |
196 | ||
dd272b57 | 197 | acpi_status __init acpi_os_initialize(void) |
1da177e4 LT |
198 | { |
199 | return AE_OK; | |
200 | } | |
201 | ||
4be44fcd | 202 | acpi_status acpi_os_initialize1(void) |
1da177e4 | 203 | { |
1da177e4 | 204 | kacpid_wq = create_singlethread_workqueue("kacpid"); |
88db5e14 | 205 | kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify"); |
1da177e4 | 206 | BUG_ON(!kacpid_wq); |
88db5e14 | 207 | BUG_ON(!kacpi_notify_wq); |
1da177e4 LT |
208 | return AE_OK; |
209 | } | |
210 | ||
4be44fcd | 211 | acpi_status acpi_os_terminate(void) |
1da177e4 LT |
212 | { |
213 | if (acpi_irq_handler) { | |
214 | acpi_os_remove_interrupt_handler(acpi_irq_irq, | |
215 | acpi_irq_handler); | |
216 | } | |
217 | ||
218 | destroy_workqueue(kacpid_wq); | |
88db5e14 | 219 | destroy_workqueue(kacpi_notify_wq); |
1da177e4 LT |
220 | |
221 | return AE_OK; | |
222 | } | |
223 | ||
4be44fcd | 224 | void acpi_os_printf(const char *fmt, ...) |
1da177e4 LT |
225 | { |
226 | va_list args; | |
227 | va_start(args, fmt); | |
228 | acpi_os_vprintf(fmt, args); | |
229 | va_end(args); | |
230 | } | |
4be44fcd | 231 | |
4be44fcd | 232 | void acpi_os_vprintf(const char *fmt, va_list args) |
1da177e4 LT |
233 | { |
234 | static char buffer[512]; | |
4be44fcd | 235 | |
1da177e4 LT |
236 | vsprintf(buffer, fmt, args); |
237 | ||
238 | #ifdef ENABLE_DEBUGGER | |
239 | if (acpi_in_debugger) { | |
240 | kdb_printf("%s", buffer); | |
241 | } else { | |
242 | printk("%s", buffer); | |
243 | } | |
244 | #else | |
245 | printk("%s", buffer); | |
246 | #endif | |
247 | } | |
248 | ||
ad71860a | 249 | acpi_physical_address __init acpi_os_get_root_pointer(void) |
1da177e4 LT |
250 | { |
251 | if (efi_enabled) { | |
b2c99e3c | 252 | if (efi.acpi20 != EFI_INVALID_TABLE_ADDR) |
ad71860a | 253 | return efi.acpi20; |
b2c99e3c | 254 | else if (efi.acpi != EFI_INVALID_TABLE_ADDR) |
ad71860a | 255 | return efi.acpi; |
1da177e4 | 256 | else { |
4be44fcd LB |
257 | printk(KERN_ERR PREFIX |
258 | "System description tables not found\n"); | |
ad71860a | 259 | return 0; |
1da177e4 | 260 | } |
239665a3 LB |
261 | } else { |
262 | acpi_physical_address pa = 0; | |
263 | ||
264 | acpi_find_root_pointer(&pa); | |
265 | return pa; | |
266 | } | |
1da177e4 LT |
267 | } |
268 | ||
2fdf0741 JB |
269 | void __iomem *__init_refok |
270 | acpi_os_map_memory(acpi_physical_address phys, acpi_size size) | |
1da177e4 | 271 | { |
9f4fd61f BH |
272 | if (phys > ULONG_MAX) { |
273 | printk(KERN_ERR PREFIX "Cannot map memory that high\n"); | |
70c0846e | 274 | return NULL; |
1da177e4 | 275 | } |
ad71860a AS |
276 | if (acpi_gbl_permanent_mmap) |
277 | /* | |
278 | * ioremap checks to ensure this is in reserved space | |
279 | */ | |
280 | return ioremap((unsigned long)phys, size); | |
281 | else | |
282 | return __acpi_map_table((unsigned long)phys, size); | |
1da177e4 | 283 | } |
55a82ab3 | 284 | EXPORT_SYMBOL_GPL(acpi_os_map_memory); |
1da177e4 | 285 | |
4be44fcd | 286 | void acpi_os_unmap_memory(void __iomem * virt, acpi_size size) |
1da177e4 | 287 | { |
ad71860a AS |
288 | if (acpi_gbl_permanent_mmap) { |
289 | iounmap(virt); | |
290 | } | |
1da177e4 | 291 | } |
55a82ab3 | 292 | EXPORT_SYMBOL_GPL(acpi_os_unmap_memory); |
1da177e4 LT |
293 | |
294 | #ifdef ACPI_FUTURE_USAGE | |
295 | acpi_status | |
4be44fcd | 296 | acpi_os_get_physical_address(void *virt, acpi_physical_address * phys) |
1da177e4 | 297 | { |
4be44fcd | 298 | if (!phys || !virt) |
1da177e4 LT |
299 | return AE_BAD_PARAMETER; |
300 | ||
301 | *phys = virt_to_phys(virt); | |
302 | ||
303 | return AE_OK; | |
304 | } | |
305 | #endif | |
306 | ||
307 | #define ACPI_MAX_OVERRIDE_LEN 100 | |
308 | ||
309 | static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN]; | |
310 | ||
311 | acpi_status | |
4be44fcd LB |
312 | acpi_os_predefined_override(const struct acpi_predefined_names *init_val, |
313 | acpi_string * new_val) | |
1da177e4 LT |
314 | { |
315 | if (!init_val || !new_val) | |
316 | return AE_BAD_PARAMETER; | |
317 | ||
318 | *new_val = NULL; | |
4be44fcd | 319 | if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) { |
1da177e4 | 320 | printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n", |
4be44fcd | 321 | acpi_os_name); |
1da177e4 LT |
322 | *new_val = acpi_os_name; |
323 | } | |
324 | ||
325 | return AE_OK; | |
326 | } | |
327 | ||
328 | acpi_status | |
4be44fcd LB |
329 | acpi_os_table_override(struct acpi_table_header * existing_table, |
330 | struct acpi_table_header ** new_table) | |
1da177e4 LT |
331 | { |
332 | if (!existing_table || !new_table) | |
333 | return AE_BAD_PARAMETER; | |
334 | ||
71fc47a9 MG |
335 | *new_table = NULL; |
336 | ||
1da177e4 LT |
337 | #ifdef CONFIG_ACPI_CUSTOM_DSDT |
338 | if (strncmp(existing_table->signature, "DSDT", 4) == 0) | |
4be44fcd | 339 | *new_table = (struct acpi_table_header *)AmlCode; |
1da177e4 | 340 | #endif |
6ed31e92 ÉP |
341 | if (*new_table != NULL) { |
342 | printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], " | |
343 | "this is unsafe: tainting kernel\n", | |
344 | existing_table->signature, | |
345 | existing_table->oem_table_id); | |
346 | add_taint(TAINT_OVERRIDDEN_ACPI_TABLE); | |
347 | } | |
1da177e4 LT |
348 | return AE_OK; |
349 | } | |
350 | ||
7d12e780 | 351 | static irqreturn_t acpi_irq(int irq, void *dev_id) |
1da177e4 | 352 | { |
5229e87d LB |
353 | u32 handled; |
354 | ||
355 | handled = (*acpi_irq_handler) (acpi_irq_context); | |
356 | ||
357 | if (handled) { | |
358 | acpi_irq_handled++; | |
359 | return IRQ_HANDLED; | |
360 | } else | |
361 | return IRQ_NONE; | |
1da177e4 LT |
362 | } |
363 | ||
364 | acpi_status | |
4be44fcd LB |
365 | acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler, |
366 | void *context) | |
1da177e4 LT |
367 | { |
368 | unsigned int irq; | |
369 | ||
5229e87d LB |
370 | acpi_irq_stats_init(); |
371 | ||
1da177e4 LT |
372 | /* |
373 | * Ignore the GSI from the core, and use the value in our copy of the | |
374 | * FADT. It may not be the same if an interrupt source override exists | |
375 | * for the SCI. | |
376 | */ | |
cee324b1 | 377 | gsi = acpi_gbl_FADT.sci_interrupt; |
1da177e4 LT |
378 | if (acpi_gsi_to_irq(gsi, &irq) < 0) { |
379 | printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n", | |
380 | gsi); | |
381 | return AE_OK; | |
382 | } | |
383 | ||
384 | acpi_irq_handler = handler; | |
385 | acpi_irq_context = context; | |
dace1453 | 386 | if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) { |
1da177e4 LT |
387 | printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq); |
388 | return AE_NOT_ACQUIRED; | |
389 | } | |
390 | acpi_irq_irq = irq; | |
391 | ||
392 | return AE_OK; | |
393 | } | |
394 | ||
4be44fcd | 395 | acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler) |
1da177e4 LT |
396 | { |
397 | if (irq) { | |
398 | free_irq(irq, acpi_irq); | |
399 | acpi_irq_handler = NULL; | |
400 | acpi_irq_irq = 0; | |
401 | } | |
402 | ||
403 | return AE_OK; | |
404 | } | |
405 | ||
406 | /* | |
407 | * Running in interpreter thread context, safe to sleep | |
408 | */ | |
409 | ||
4be44fcd | 410 | void acpi_os_sleep(acpi_integer ms) |
1da177e4 | 411 | { |
01a527ec | 412 | schedule_timeout_interruptible(msecs_to_jiffies(ms)); |
1da177e4 | 413 | } |
4be44fcd | 414 | |
4be44fcd | 415 | void acpi_os_stall(u32 us) |
1da177e4 LT |
416 | { |
417 | while (us) { | |
418 | u32 delay = 1000; | |
419 | ||
420 | if (delay > us) | |
421 | delay = us; | |
422 | udelay(delay); | |
423 | touch_nmi_watchdog(); | |
424 | us -= delay; | |
425 | } | |
426 | } | |
4be44fcd | 427 | |
1da177e4 LT |
428 | /* |
429 | * Support ACPI 3.0 AML Timer operand | |
430 | * Returns 64-bit free-running, monotonically increasing timer | |
431 | * with 100ns granularity | |
432 | */ | |
4be44fcd | 433 | u64 acpi_os_get_timer(void) |
1da177e4 LT |
434 | { |
435 | static u64 t; | |
436 | ||
437 | #ifdef CONFIG_HPET | |
438 | /* TBD: use HPET if available */ | |
439 | #endif | |
440 | ||
441 | #ifdef CONFIG_X86_PM_TIMER | |
442 | /* TBD: default to PM timer if HPET was not available */ | |
443 | #endif | |
444 | if (!t) | |
445 | printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n"); | |
446 | ||
447 | return ++t; | |
448 | } | |
449 | ||
4be44fcd | 450 | acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width) |
1da177e4 LT |
451 | { |
452 | u32 dummy; | |
453 | ||
454 | if (!value) | |
455 | value = &dummy; | |
456 | ||
49fbabf5 ZY |
457 | *value = 0; |
458 | if (width <= 8) { | |
4be44fcd | 459 | *(u8 *) value = inb(port); |
49fbabf5 | 460 | } else if (width <= 16) { |
4be44fcd | 461 | *(u16 *) value = inw(port); |
49fbabf5 | 462 | } else if (width <= 32) { |
4be44fcd | 463 | *(u32 *) value = inl(port); |
49fbabf5 | 464 | } else { |
1da177e4 LT |
465 | BUG(); |
466 | } | |
467 | ||
468 | return AE_OK; | |
469 | } | |
4be44fcd | 470 | |
1da177e4 LT |
471 | EXPORT_SYMBOL(acpi_os_read_port); |
472 | ||
4be44fcd | 473 | acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width) |
1da177e4 | 474 | { |
49fbabf5 | 475 | if (width <= 8) { |
1da177e4 | 476 | outb(value, port); |
49fbabf5 | 477 | } else if (width <= 16) { |
1da177e4 | 478 | outw(value, port); |
49fbabf5 | 479 | } else if (width <= 32) { |
1da177e4 | 480 | outl(value, port); |
49fbabf5 | 481 | } else { |
1da177e4 LT |
482 | BUG(); |
483 | } | |
484 | ||
485 | return AE_OK; | |
486 | } | |
4be44fcd | 487 | |
1da177e4 LT |
488 | EXPORT_SYMBOL(acpi_os_write_port); |
489 | ||
490 | acpi_status | |
4be44fcd | 491 | acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width) |
1da177e4 | 492 | { |
4be44fcd LB |
493 | u32 dummy; |
494 | void __iomem *virt_addr; | |
1da177e4 | 495 | |
9f4fd61f | 496 | virt_addr = ioremap(phys_addr, width); |
1da177e4 LT |
497 | if (!value) |
498 | value = &dummy; | |
499 | ||
500 | switch (width) { | |
501 | case 8: | |
4be44fcd | 502 | *(u8 *) value = readb(virt_addr); |
1da177e4 LT |
503 | break; |
504 | case 16: | |
4be44fcd | 505 | *(u16 *) value = readw(virt_addr); |
1da177e4 LT |
506 | break; |
507 | case 32: | |
4be44fcd | 508 | *(u32 *) value = readl(virt_addr); |
1da177e4 LT |
509 | break; |
510 | default: | |
511 | BUG(); | |
512 | } | |
513 | ||
9f4fd61f | 514 | iounmap(virt_addr); |
1da177e4 LT |
515 | |
516 | return AE_OK; | |
517 | } | |
518 | ||
519 | acpi_status | |
4be44fcd | 520 | acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width) |
1da177e4 | 521 | { |
4be44fcd | 522 | void __iomem *virt_addr; |
1da177e4 | 523 | |
9f4fd61f | 524 | virt_addr = ioremap(phys_addr, width); |
1da177e4 LT |
525 | |
526 | switch (width) { | |
527 | case 8: | |
528 | writeb(value, virt_addr); | |
529 | break; | |
530 | case 16: | |
531 | writew(value, virt_addr); | |
532 | break; | |
533 | case 32: | |
534 | writel(value, virt_addr); | |
535 | break; | |
536 | default: | |
537 | BUG(); | |
538 | } | |
539 | ||
9f4fd61f | 540 | iounmap(virt_addr); |
1da177e4 LT |
541 | |
542 | return AE_OK; | |
543 | } | |
544 | ||
1da177e4 | 545 | acpi_status |
4be44fcd | 546 | acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
10270d48 | 547 | u32 *value, u32 width) |
1da177e4 LT |
548 | { |
549 | int result, size; | |
550 | ||
551 | if (!value) | |
552 | return AE_BAD_PARAMETER; | |
553 | ||
554 | switch (width) { | |
555 | case 8: | |
556 | size = 1; | |
557 | break; | |
558 | case 16: | |
559 | size = 2; | |
560 | break; | |
561 | case 32: | |
562 | size = 4; | |
563 | break; | |
564 | default: | |
565 | return AE_ERROR; | |
566 | } | |
567 | ||
b6ce068a MW |
568 | result = raw_pci_read(pci_id->segment, pci_id->bus, |
569 | PCI_DEVFN(pci_id->device, pci_id->function), | |
570 | reg, size, value); | |
1da177e4 LT |
571 | |
572 | return (result ? AE_ERROR : AE_OK); | |
573 | } | |
4be44fcd | 574 | |
1da177e4 | 575 | acpi_status |
4be44fcd LB |
576 | acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg, |
577 | acpi_integer value, u32 width) | |
1da177e4 LT |
578 | { |
579 | int result, size; | |
580 | ||
581 | switch (width) { | |
582 | case 8: | |
583 | size = 1; | |
584 | break; | |
585 | case 16: | |
586 | size = 2; | |
587 | break; | |
588 | case 32: | |
589 | size = 4; | |
590 | break; | |
591 | default: | |
592 | return AE_ERROR; | |
593 | } | |
594 | ||
b6ce068a MW |
595 | result = raw_pci_write(pci_id->segment, pci_id->bus, |
596 | PCI_DEVFN(pci_id->device, pci_id->function), | |
597 | reg, size, value); | |
1da177e4 LT |
598 | |
599 | return (result ? AE_ERROR : AE_OK); | |
600 | } | |
601 | ||
602 | /* TODO: Change code to take advantage of driver model more */ | |
4be44fcd LB |
603 | static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */ |
604 | acpi_handle chandle, /* current node */ | |
605 | struct acpi_pci_id **id, | |
606 | int *is_bridge, u8 * bus_number) | |
1da177e4 | 607 | { |
4be44fcd LB |
608 | acpi_handle handle; |
609 | struct acpi_pci_id *pci_id = *id; | |
610 | acpi_status status; | |
611 | unsigned long temp; | |
612 | acpi_object_type type; | |
1da177e4 LT |
613 | |
614 | acpi_get_parent(chandle, &handle); | |
615 | if (handle != rhandle) { | |
4be44fcd LB |
616 | acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge, |
617 | bus_number); | |
1da177e4 LT |
618 | |
619 | status = acpi_get_type(handle, &type); | |
4be44fcd | 620 | if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE)) |
1da177e4 LT |
621 | return; |
622 | ||
4be44fcd LB |
623 | status = |
624 | acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, | |
625 | &temp); | |
1da177e4 | 626 | if (ACPI_SUCCESS(status)) { |
10270d48 | 627 | u32 val; |
4be44fcd LB |
628 | pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp)); |
629 | pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp)); | |
1da177e4 LT |
630 | |
631 | if (*is_bridge) | |
632 | pci_id->bus = *bus_number; | |
633 | ||
634 | /* any nicer way to get bus number of bridge ? */ | |
4be44fcd | 635 | status = |
10270d48 | 636 | acpi_os_read_pci_configuration(pci_id, 0x0e, &val, |
4be44fcd LB |
637 | 8); |
638 | if (ACPI_SUCCESS(status) | |
10270d48 | 639 | && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) { |
4be44fcd LB |
640 | status = |
641 | acpi_os_read_pci_configuration(pci_id, 0x18, | |
10270d48 | 642 | &val, 8); |
1da177e4 LT |
643 | if (!ACPI_SUCCESS(status)) { |
644 | /* Certainly broken... FIX ME */ | |
645 | return; | |
646 | } | |
647 | *is_bridge = 1; | |
10270d48 | 648 | pci_id->bus = val; |
4be44fcd LB |
649 | status = |
650 | acpi_os_read_pci_configuration(pci_id, 0x19, | |
10270d48 | 651 | &val, 8); |
1da177e4 | 652 | if (ACPI_SUCCESS(status)) { |
10270d48 | 653 | *bus_number = val; |
1da177e4 LT |
654 | } |
655 | } else | |
656 | *is_bridge = 0; | |
657 | } | |
658 | } | |
659 | } | |
660 | ||
4be44fcd LB |
661 | void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */ |
662 | acpi_handle chandle, /* current node */ | |
663 | struct acpi_pci_id **id) | |
1da177e4 LT |
664 | { |
665 | int is_bridge = 1; | |
666 | u8 bus_number = (*id)->bus; | |
667 | ||
668 | acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number); | |
669 | } | |
670 | ||
65f27f38 | 671 | static void acpi_os_execute_deferred(struct work_struct *work) |
88db5e14 AS |
672 | { |
673 | struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); | |
674 | if (!dpc) { | |
675 | printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); | |
676 | return; | |
677 | } | |
678 | ||
679 | dpc->function(dpc->context); | |
680 | kfree(dpc); | |
681 | ||
d550d98d | 682 | return; |
1da177e4 LT |
683 | } |
684 | ||
19cd847a ZR |
685 | static void acpi_os_execute_hp_deferred(struct work_struct *work) |
686 | { | |
687 | struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); | |
688 | if (!dpc) { | |
689 | printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); | |
690 | return; | |
691 | } | |
692 | ||
693 | acpi_os_wait_events_complete(NULL); | |
694 | ||
695 | dpc->function(dpc->context); | |
696 | kfree(dpc); | |
697 | ||
698 | return; | |
699 | } | |
700 | ||
b8d35192 AS |
701 | /******************************************************************************* |
702 | * | |
703 | * FUNCTION: acpi_os_execute | |
704 | * | |
705 | * PARAMETERS: Type - Type of the callback | |
706 | * Function - Function to be executed | |
707 | * Context - Function parameters | |
708 | * | |
709 | * RETURN: Status | |
710 | * | |
711 | * DESCRIPTION: Depending on type, either queues function for deferred execution or | |
712 | * immediately executes function on a separate thread. | |
713 | * | |
714 | ******************************************************************************/ | |
715 | ||
19cd847a ZR |
716 | static acpi_status __acpi_os_execute(acpi_execute_type type, |
717 | acpi_osd_exec_callback function, void *context, int hp) | |
1da177e4 | 718 | { |
4be44fcd LB |
719 | acpi_status status = AE_OK; |
720 | struct acpi_os_dpc *dpc; | |
17bc54ee | 721 | struct workqueue_struct *queue; |
19cd847a | 722 | int ret; |
72945b2b LB |
723 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
724 | "Scheduling function [%p(%p)] for deferred execution.\n", | |
725 | function, context)); | |
1da177e4 LT |
726 | |
727 | if (!function) | |
88db5e14 | 728 | return AE_BAD_PARAMETER; |
72945b2b | 729 | |
1da177e4 LT |
730 | /* |
731 | * Allocate/initialize DPC structure. Note that this memory will be | |
65f27f38 | 732 | * freed by the callee. The kernel handles the work_struct list in a |
1da177e4 LT |
733 | * way that allows us to also free its memory inside the callee. |
734 | * Because we may want to schedule several tasks with different | |
735 | * parameters we can't use the approach some kernel code uses of | |
65f27f38 | 736 | * having a static work_struct. |
1da177e4 | 737 | */ |
72945b2b | 738 | |
65f27f38 | 739 | dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC); |
1da177e4 | 740 | if (!dpc) |
b976fe19 LT |
741 | return_ACPI_STATUS(AE_NO_MEMORY); |
742 | ||
1da177e4 LT |
743 | dpc->function = function; |
744 | dpc->context = context; | |
b976fe19 | 745 | |
19cd847a ZR |
746 | if (!hp) { |
747 | INIT_WORK(&dpc->work, acpi_os_execute_deferred); | |
748 | queue = (type == OSL_NOTIFY_HANDLER) ? | |
749 | kacpi_notify_wq : kacpid_wq; | |
750 | ret = queue_work(queue, &dpc->work); | |
751 | } else { | |
752 | INIT_WORK(&dpc->work, acpi_os_execute_hp_deferred); | |
753 | ret = schedule_work(&dpc->work); | |
754 | } | |
755 | ||
756 | if (!ret) { | |
17bc54ee AS |
757 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
758 | "Call to queue_work() failed.\n")); | |
759 | status = AE_ERROR; | |
760 | kfree(dpc); | |
1da177e4 | 761 | } |
b976fe19 | 762 | return_ACPI_STATUS(status); |
1da177e4 | 763 | } |
4be44fcd | 764 | |
19cd847a ZR |
765 | acpi_status acpi_os_execute(acpi_execute_type type, |
766 | acpi_osd_exec_callback function, void *context) | |
767 | { | |
768 | return __acpi_os_execute(type, function, context, 0); | |
769 | } | |
b8d35192 | 770 | EXPORT_SYMBOL(acpi_os_execute); |
1da177e4 | 771 | |
19cd847a ZR |
772 | acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function, |
773 | void *context) | |
774 | { | |
775 | return __acpi_os_execute(0, function, context, 1); | |
776 | } | |
777 | ||
4be44fcd | 778 | void acpi_os_wait_events_complete(void *context) |
1da177e4 LT |
779 | { |
780 | flush_workqueue(kacpid_wq); | |
2f67a069 | 781 | flush_workqueue(kacpi_notify_wq); |
1da177e4 | 782 | } |
4be44fcd | 783 | |
1da177e4 LT |
784 | EXPORT_SYMBOL(acpi_os_wait_events_complete); |
785 | ||
786 | /* | |
787 | * Allocate the memory for a spinlock and initialize it. | |
788 | */ | |
967440e3 | 789 | acpi_status acpi_os_create_lock(acpi_spinlock * handle) |
1da177e4 | 790 | { |
967440e3 | 791 | spin_lock_init(*handle); |
1da177e4 | 792 | |
d550d98d | 793 | return AE_OK; |
1da177e4 LT |
794 | } |
795 | ||
1da177e4 LT |
796 | /* |
797 | * Deallocate the memory for a spinlock. | |
798 | */ | |
967440e3 | 799 | void acpi_os_delete_lock(acpi_spinlock handle) |
1da177e4 | 800 | { |
d550d98d | 801 | return; |
1da177e4 LT |
802 | } |
803 | ||
1da177e4 | 804 | acpi_status |
4be44fcd | 805 | acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle) |
1da177e4 | 806 | { |
4be44fcd | 807 | struct semaphore *sem = NULL; |
1da177e4 | 808 | |
1da177e4 LT |
809 | sem = acpi_os_allocate(sizeof(struct semaphore)); |
810 | if (!sem) | |
d550d98d | 811 | return AE_NO_MEMORY; |
1da177e4 LT |
812 | memset(sem, 0, sizeof(struct semaphore)); |
813 | ||
814 | sema_init(sem, initial_units); | |
815 | ||
4be44fcd | 816 | *handle = (acpi_handle *) sem; |
1da177e4 | 817 | |
4be44fcd LB |
818 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n", |
819 | *handle, initial_units)); | |
1da177e4 | 820 | |
d550d98d | 821 | return AE_OK; |
1da177e4 | 822 | } |
1da177e4 | 823 | |
1da177e4 LT |
824 | /* |
825 | * TODO: A better way to delete semaphores? Linux doesn't have a | |
826 | * 'delete_semaphore()' function -- may result in an invalid | |
827 | * pointer dereference for non-synchronized consumers. Should | |
828 | * we at least check for blocked threads and signal/cancel them? | |
829 | */ | |
830 | ||
4be44fcd | 831 | acpi_status acpi_os_delete_semaphore(acpi_handle handle) |
1da177e4 | 832 | { |
4be44fcd | 833 | struct semaphore *sem = (struct semaphore *)handle; |
1da177e4 | 834 | |
1da177e4 | 835 | if (!sem) |
d550d98d | 836 | return AE_BAD_PARAMETER; |
1da177e4 | 837 | |
4be44fcd | 838 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); |
1da177e4 | 839 | |
f1241c87 | 840 | BUG_ON(!list_empty(&sem->wait_list)); |
02438d87 | 841 | kfree(sem); |
4be44fcd | 842 | sem = NULL; |
1da177e4 | 843 | |
d550d98d | 844 | return AE_OK; |
1da177e4 | 845 | } |
1da177e4 | 846 | |
1da177e4 | 847 | /* |
1da177e4 LT |
848 | * TODO: Support for units > 1? |
849 | */ | |
4be44fcd | 850 | acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout) |
1da177e4 | 851 | { |
4be44fcd LB |
852 | acpi_status status = AE_OK; |
853 | struct semaphore *sem = (struct semaphore *)handle; | |
f1241c87 | 854 | long jiffies; |
4be44fcd | 855 | int ret = 0; |
1da177e4 | 856 | |
1da177e4 | 857 | if (!sem || (units < 1)) |
d550d98d | 858 | return AE_BAD_PARAMETER; |
1da177e4 LT |
859 | |
860 | if (units > 1) | |
d550d98d | 861 | return AE_SUPPORT; |
1da177e4 | 862 | |
4be44fcd LB |
863 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n", |
864 | handle, units, timeout)); | |
1da177e4 | 865 | |
f1241c87 MW |
866 | if (timeout == ACPI_WAIT_FOREVER) |
867 | jiffies = MAX_SCHEDULE_TIMEOUT; | |
868 | else | |
869 | jiffies = msecs_to_jiffies(timeout); | |
870 | ||
871 | ret = down_timeout(sem, jiffies); | |
872 | if (ret) | |
873 | status = AE_TIME; | |
1da177e4 LT |
874 | |
875 | if (ACPI_FAILURE(status)) { | |
9e7e2c04 | 876 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
a6fc6720 | 877 | "Failed to acquire semaphore[%p|%d|%d], %s", |
4be44fcd LB |
878 | handle, units, timeout, |
879 | acpi_format_exception(status))); | |
880 | } else { | |
881 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, | |
a6fc6720 | 882 | "Acquired semaphore[%p|%d|%d]", handle, |
4be44fcd | 883 | units, timeout)); |
1da177e4 LT |
884 | } |
885 | ||
d550d98d | 886 | return status; |
1da177e4 | 887 | } |
1da177e4 | 888 | |
1da177e4 LT |
889 | /* |
890 | * TODO: Support for units > 1? | |
891 | */ | |
4be44fcd | 892 | acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) |
1da177e4 | 893 | { |
4be44fcd | 894 | struct semaphore *sem = (struct semaphore *)handle; |
1da177e4 | 895 | |
1da177e4 | 896 | if (!sem || (units < 1)) |
d550d98d | 897 | return AE_BAD_PARAMETER; |
1da177e4 LT |
898 | |
899 | if (units > 1) | |
d550d98d | 900 | return AE_SUPPORT; |
1da177e4 | 901 | |
4be44fcd LB |
902 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle, |
903 | units)); | |
1da177e4 LT |
904 | |
905 | up(sem); | |
906 | ||
d550d98d | 907 | return AE_OK; |
1da177e4 | 908 | } |
4be44fcd | 909 | |
1da177e4 | 910 | #ifdef ACPI_FUTURE_USAGE |
4be44fcd | 911 | u32 acpi_os_get_line(char *buffer) |
1da177e4 LT |
912 | { |
913 | ||
914 | #ifdef ENABLE_DEBUGGER | |
915 | if (acpi_in_debugger) { | |
916 | u32 chars; | |
917 | ||
918 | kdb_read(buffer, sizeof(line_buf)); | |
919 | ||
920 | /* remove the CR kdb includes */ | |
921 | chars = strlen(buffer) - 1; | |
922 | buffer[chars] = '\0'; | |
923 | } | |
924 | #endif | |
925 | ||
926 | return 0; | |
927 | } | |
4be44fcd | 928 | #endif /* ACPI_FUTURE_USAGE */ |
1da177e4 | 929 | |
4be44fcd | 930 | acpi_status acpi_os_signal(u32 function, void *info) |
1da177e4 | 931 | { |
4be44fcd | 932 | switch (function) { |
1da177e4 LT |
933 | case ACPI_SIGNAL_FATAL: |
934 | printk(KERN_ERR PREFIX "Fatal opcode executed\n"); | |
935 | break; | |
936 | case ACPI_SIGNAL_BREAKPOINT: | |
937 | /* | |
938 | * AML Breakpoint | |
939 | * ACPI spec. says to treat it as a NOP unless | |
940 | * you are debugging. So if/when we integrate | |
941 | * AML debugger into the kernel debugger its | |
942 | * hook will go here. But until then it is | |
943 | * not useful to print anything on breakpoints. | |
944 | */ | |
945 | break; | |
946 | default: | |
947 | break; | |
948 | } | |
949 | ||
950 | return AE_OK; | |
951 | } | |
4be44fcd | 952 | |
4be44fcd | 953 | static int __init acpi_os_name_setup(char *str) |
1da177e4 LT |
954 | { |
955 | char *p = acpi_os_name; | |
4be44fcd | 956 | int count = ACPI_MAX_OVERRIDE_LEN - 1; |
1da177e4 LT |
957 | |
958 | if (!str || !*str) | |
959 | return 0; | |
960 | ||
961 | for (; count-- && str && *str; str++) { | |
962 | if (isalnum(*str) || *str == ' ' || *str == ':') | |
963 | *p++ = *str; | |
964 | else if (*str == '\'' || *str == '"') | |
965 | continue; | |
966 | else | |
967 | break; | |
968 | } | |
969 | *p = 0; | |
970 | ||
971 | return 1; | |
4be44fcd | 972 | |
1da177e4 LT |
973 | } |
974 | ||
975 | __setup("acpi_os_name=", acpi_os_name_setup); | |
976 | ||
d4b7dc49 LB |
977 | static void __init set_osi_linux(unsigned int enable) |
978 | { | |
979 | if (osi_linux.enable != enable) { | |
980 | osi_linux.enable = enable; | |
981 | printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n", | |
982 | enable ? "Add": "Delet"); | |
983 | } | |
984 | return; | |
985 | } | |
986 | ||
987 | static void __init acpi_cmdline_osi_linux(unsigned int enable) | |
988 | { | |
989 | osi_linux.cmdline = 1; /* cmdline set the default */ | |
990 | set_osi_linux(enable); | |
991 | ||
992 | return; | |
993 | } | |
994 | ||
995 | void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d) | |
996 | { | |
997 | osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */ | |
998 | ||
999 | printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident); | |
1000 | ||
1001 | if (enable == -1) | |
1002 | return; | |
1003 | ||
1004 | osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */ | |
f507654d | 1005 | |
d4b7dc49 | 1006 | set_osi_linux(enable); |
f507654d | 1007 | |
f507654d LB |
1008 | return; |
1009 | } | |
1010 | ||
1da177e4 | 1011 | /* |
ae00d812 LB |
1012 | * Modify the list of "OS Interfaces" reported to BIOS via _OSI |
1013 | * | |
1da177e4 | 1014 | * empty string disables _OSI |
ae00d812 LB |
1015 | * string starting with '!' disables that string |
1016 | * otherwise string is added to list, augmenting built-in strings | |
1da177e4 | 1017 | */ |
46c1fbdb | 1018 | int __init acpi_osi_setup(char *str) |
1da177e4 LT |
1019 | { |
1020 | if (str == NULL || *str == '\0') { | |
1021 | printk(KERN_INFO PREFIX "_OSI method disabled\n"); | |
1022 | acpi_gbl_create_osi_method = FALSE; | |
aa2e09da | 1023 | } else if (!strcmp("!Linux", str)) { |
d4b7dc49 | 1024 | acpi_cmdline_osi_linux(0); /* !enable */ |
ae00d812 LB |
1025 | } else if (*str == '!') { |
1026 | if (acpi_osi_invalidate(++str) == AE_OK) | |
1027 | printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str); | |
f507654d | 1028 | } else if (!strcmp("Linux", str)) { |
d4b7dc49 | 1029 | acpi_cmdline_osi_linux(1); /* enable */ |
ae00d812 LB |
1030 | } else if (*osi_additional_string == '\0') { |
1031 | strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX); | |
1032 | printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str); | |
1da177e4 LT |
1033 | } |
1034 | ||
1035 | return 1; | |
1036 | } | |
1037 | ||
1038 | __setup("acpi_osi=", acpi_osi_setup); | |
1039 | ||
1040 | /* enable serialization to combat AE_ALREADY_EXISTS errors */ | |
4be44fcd | 1041 | static int __init acpi_serialize_setup(char *str) |
1da177e4 LT |
1042 | { |
1043 | printk(KERN_INFO PREFIX "serialize enabled\n"); | |
1044 | ||
1045 | acpi_gbl_all_methods_serialized = TRUE; | |
1046 | ||
1047 | return 1; | |
1048 | } | |
1049 | ||
1050 | __setup("acpi_serialize", acpi_serialize_setup); | |
1051 | ||
1052 | /* | |
1053 | * Wake and Run-Time GPES are expected to be separate. | |
1054 | * We disable wake-GPEs at run-time to prevent spurious | |
1055 | * interrupts. | |
1056 | * | |
1057 | * However, if a system exists that shares Wake and | |
1058 | * Run-time events on the same GPE this flag is available | |
1059 | * to tell Linux to keep the wake-time GPEs enabled at run-time. | |
1060 | */ | |
4be44fcd | 1061 | static int __init acpi_wake_gpes_always_on_setup(char *str) |
1da177e4 LT |
1062 | { |
1063 | printk(KERN_INFO PREFIX "wake GPEs not disabled\n"); | |
1064 | ||
1065 | acpi_gbl_leave_wake_gpes_disabled = FALSE; | |
1066 | ||
1067 | return 1; | |
1068 | } | |
1069 | ||
1070 | __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup); | |
1071 | ||
df92e695 TR |
1072 | /* Check of resource interference between native drivers and ACPI |
1073 | * OperationRegions (SystemIO and System Memory only). | |
1074 | * IO ports and memory declared in ACPI might be used by the ACPI subsystem | |
1075 | * in arbitrary AML code and can interfere with legacy drivers. | |
1076 | * acpi_enforce_resources= can be set to: | |
1077 | * | |
1078 | * - strict (2) | |
1079 | * -> further driver trying to access the resources will not load | |
1080 | * - lax (default) (1) | |
1081 | * -> further driver trying to access the resources will load, but you | |
1082 | * get a system message that something might go wrong... | |
1083 | * | |
1084 | * - no (0) | |
1085 | * -> ACPI Operation Region resources will not be registered | |
1086 | * | |
1087 | */ | |
1088 | #define ENFORCE_RESOURCES_STRICT 2 | |
1089 | #define ENFORCE_RESOURCES_LAX 1 | |
1090 | #define ENFORCE_RESOURCES_NO 0 | |
1091 | ||
1092 | static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_LAX; | |
1093 | ||
1094 | static int __init acpi_enforce_resources_setup(char *str) | |
1095 | { | |
1096 | if (str == NULL || *str == '\0') | |
1097 | return 0; | |
1098 | ||
1099 | if (!strcmp("strict", str)) | |
1100 | acpi_enforce_resources = ENFORCE_RESOURCES_STRICT; | |
1101 | else if (!strcmp("lax", str)) | |
1102 | acpi_enforce_resources = ENFORCE_RESOURCES_LAX; | |
1103 | else if (!strcmp("no", str)) | |
1104 | acpi_enforce_resources = ENFORCE_RESOURCES_NO; | |
1105 | ||
1106 | return 1; | |
1107 | } | |
1108 | ||
1109 | __setup("acpi_enforce_resources=", acpi_enforce_resources_setup); | |
1110 | ||
1111 | /* Check for resource conflicts between ACPI OperationRegions and native | |
1112 | * drivers */ | |
443dea72 | 1113 | int acpi_check_resource_conflict(struct resource *res) |
df92e695 TR |
1114 | { |
1115 | struct acpi_res_list *res_list_elem; | |
1116 | int ioport; | |
1117 | int clash = 0; | |
1118 | ||
1119 | if (acpi_enforce_resources == ENFORCE_RESOURCES_NO) | |
1120 | return 0; | |
1121 | if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM)) | |
1122 | return 0; | |
1123 | ||
1124 | ioport = res->flags & IORESOURCE_IO; | |
1125 | ||
1126 | spin_lock(&acpi_res_lock); | |
1127 | list_for_each_entry(res_list_elem, &resource_list_head, | |
1128 | resource_list) { | |
1129 | if (ioport && (res_list_elem->resource_type | |
1130 | != ACPI_ADR_SPACE_SYSTEM_IO)) | |
1131 | continue; | |
1132 | if (!ioport && (res_list_elem->resource_type | |
1133 | != ACPI_ADR_SPACE_SYSTEM_MEMORY)) | |
1134 | continue; | |
1135 | ||
1136 | if (res->end < res_list_elem->start | |
1137 | || res_list_elem->end < res->start) | |
1138 | continue; | |
1139 | clash = 1; | |
1140 | break; | |
1141 | } | |
1142 | spin_unlock(&acpi_res_lock); | |
1143 | ||
1144 | if (clash) { | |
1145 | if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) { | |
bd12935f | 1146 | printk("%sACPI: %s resource %s [0x%llx-0x%llx]" |
df92e695 TR |
1147 | " conflicts with ACPI region %s" |
1148 | " [0x%llx-0x%llx]\n", | |
1149 | acpi_enforce_resources == ENFORCE_RESOURCES_LAX | |
1150 | ? KERN_WARNING : KERN_ERR, | |
1151 | ioport ? "I/O" : "Memory", res->name, | |
1152 | (long long) res->start, (long long) res->end, | |
1153 | res_list_elem->name, | |
1154 | (long long) res_list_elem->start, | |
1155 | (long long) res_list_elem->end); | |
1156 | printk(KERN_INFO "ACPI: Device needs an ACPI driver\n"); | |
1157 | } | |
1158 | if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT) | |
1159 | return -EBUSY; | |
1160 | } | |
1161 | return 0; | |
1162 | } | |
443dea72 | 1163 | EXPORT_SYMBOL(acpi_check_resource_conflict); |
df92e695 TR |
1164 | |
1165 | int acpi_check_region(resource_size_t start, resource_size_t n, | |
1166 | const char *name) | |
1167 | { | |
1168 | struct resource res = { | |
1169 | .start = start, | |
1170 | .end = start + n - 1, | |
1171 | .name = name, | |
1172 | .flags = IORESOURCE_IO, | |
1173 | }; | |
1174 | ||
1175 | return acpi_check_resource_conflict(&res); | |
1176 | } | |
1177 | EXPORT_SYMBOL(acpi_check_region); | |
1178 | ||
1179 | int acpi_check_mem_region(resource_size_t start, resource_size_t n, | |
1180 | const char *name) | |
1181 | { | |
1182 | struct resource res = { | |
1183 | .start = start, | |
1184 | .end = start + n - 1, | |
1185 | .name = name, | |
1186 | .flags = IORESOURCE_MEM, | |
1187 | }; | |
1188 | ||
1189 | return acpi_check_resource_conflict(&res); | |
1190 | ||
1191 | } | |
1192 | EXPORT_SYMBOL(acpi_check_mem_region); | |
1193 | ||
73459f73 RM |
1194 | /* |
1195 | * Acquire a spinlock. | |
1196 | * | |
1197 | * handle is a pointer to the spinlock_t. | |
73459f73 RM |
1198 | */ |
1199 | ||
967440e3 | 1200 | acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp) |
73459f73 | 1201 | { |
b8e4d893 | 1202 | acpi_cpu_flags flags; |
967440e3 | 1203 | spin_lock_irqsave(lockp, flags); |
73459f73 RM |
1204 | return flags; |
1205 | } | |
1206 | ||
1207 | /* | |
1208 | * Release a spinlock. See above. | |
1209 | */ | |
1210 | ||
967440e3 | 1211 | void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags) |
73459f73 | 1212 | { |
967440e3 | 1213 | spin_unlock_irqrestore(lockp, flags); |
73459f73 RM |
1214 | } |
1215 | ||
73459f73 RM |
1216 | #ifndef ACPI_USE_LOCAL_CACHE |
1217 | ||
1218 | /******************************************************************************* | |
1219 | * | |
1220 | * FUNCTION: acpi_os_create_cache | |
1221 | * | |
b229cf92 BM |
1222 | * PARAMETERS: name - Ascii name for the cache |
1223 | * size - Size of each cached object | |
1224 | * depth - Maximum depth of the cache (in objects) <ignored> | |
1225 | * cache - Where the new cache object is returned | |
73459f73 | 1226 | * |
b229cf92 | 1227 | * RETURN: status |
73459f73 RM |
1228 | * |
1229 | * DESCRIPTION: Create a cache object | |
1230 | * | |
1231 | ******************************************************************************/ | |
1232 | ||
1233 | acpi_status | |
4be44fcd | 1234 | acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache) |
73459f73 | 1235 | { |
20c2df83 | 1236 | *cache = kmem_cache_create(name, size, 0, 0, NULL); |
a6fdbf90 | 1237 | if (*cache == NULL) |
b229cf92 BM |
1238 | return AE_ERROR; |
1239 | else | |
1240 | return AE_OK; | |
73459f73 RM |
1241 | } |
1242 | ||
1243 | /******************************************************************************* | |
1244 | * | |
1245 | * FUNCTION: acpi_os_purge_cache | |
1246 | * | |
1247 | * PARAMETERS: Cache - Handle to cache object | |
1248 | * | |
1249 | * RETURN: Status | |
1250 | * | |
1251 | * DESCRIPTION: Free all objects within the requested cache. | |
1252 | * | |
1253 | ******************************************************************************/ | |
1254 | ||
4be44fcd | 1255 | acpi_status acpi_os_purge_cache(acpi_cache_t * cache) |
73459f73 | 1256 | { |
50dd0969 | 1257 | kmem_cache_shrink(cache); |
4be44fcd | 1258 | return (AE_OK); |
73459f73 RM |
1259 | } |
1260 | ||
1261 | /******************************************************************************* | |
1262 | * | |
1263 | * FUNCTION: acpi_os_delete_cache | |
1264 | * | |
1265 | * PARAMETERS: Cache - Handle to cache object | |
1266 | * | |
1267 | * RETURN: Status | |
1268 | * | |
1269 | * DESCRIPTION: Free all objects within the requested cache and delete the | |
1270 | * cache object. | |
1271 | * | |
1272 | ******************************************************************************/ | |
1273 | ||
4be44fcd | 1274 | acpi_status acpi_os_delete_cache(acpi_cache_t * cache) |
73459f73 | 1275 | { |
1a1d92c1 | 1276 | kmem_cache_destroy(cache); |
4be44fcd | 1277 | return (AE_OK); |
73459f73 RM |
1278 | } |
1279 | ||
1280 | /******************************************************************************* | |
1281 | * | |
1282 | * FUNCTION: acpi_os_release_object | |
1283 | * | |
1284 | * PARAMETERS: Cache - Handle to cache object | |
1285 | * Object - The object to be released | |
1286 | * | |
1287 | * RETURN: None | |
1288 | * | |
1289 | * DESCRIPTION: Release an object to the specified cache. If cache is full, | |
1290 | * the object is deleted. | |
1291 | * | |
1292 | ******************************************************************************/ | |
1293 | ||
4be44fcd | 1294 | acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object) |
73459f73 | 1295 | { |
4be44fcd LB |
1296 | kmem_cache_free(cache, object); |
1297 | return (AE_OK); | |
73459f73 RM |
1298 | } |
1299 | ||
5a4e1432 LB |
1300 | /** |
1301 | * acpi_dmi_dump - dump DMI slots needed for blacklist entry | |
1302 | * | |
1303 | * Returns 0 on success | |
1304 | */ | |
12d3931c | 1305 | static int acpi_dmi_dump(void) |
5a4e1432 LB |
1306 | { |
1307 | ||
1308 | if (!dmi_available) | |
1309 | return -1; | |
1310 | ||
1311 | printk(KERN_NOTICE PREFIX "DMI System Vendor: %s\n", | |
e6298c6d | 1312 | dmi_get_system_info(DMI_SYS_VENDOR)); |
5a4e1432 | 1313 | printk(KERN_NOTICE PREFIX "DMI Product Name: %s\n", |
e6298c6d | 1314 | dmi_get_system_info(DMI_PRODUCT_NAME)); |
5a4e1432 | 1315 | printk(KERN_NOTICE PREFIX "DMI Product Version: %s\n", |
e6298c6d | 1316 | dmi_get_system_info(DMI_PRODUCT_VERSION)); |
5a4e1432 | 1317 | printk(KERN_NOTICE PREFIX "DMI Board Name: %s\n", |
e6298c6d | 1318 | dmi_get_system_info(DMI_BOARD_NAME)); |
5a4e1432 | 1319 | printk(KERN_NOTICE PREFIX "DMI BIOS Vendor: %s\n", |
e6298c6d | 1320 | dmi_get_system_info(DMI_BIOS_VENDOR)); |
5a4e1432 | 1321 | printk(KERN_NOTICE PREFIX "DMI BIOS Date: %s\n", |
e6298c6d | 1322 | dmi_get_system_info(DMI_BIOS_DATE)); |
5a4e1432 LB |
1323 | |
1324 | return 0; | |
1325 | } | |
1326 | ||
1327 | ||
b229cf92 BM |
1328 | /****************************************************************************** |
1329 | * | |
1330 | * FUNCTION: acpi_os_validate_interface | |
1331 | * | |
1332 | * PARAMETERS: interface - Requested interface to be validated | |
1333 | * | |
1334 | * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise | |
1335 | * | |
1336 | * DESCRIPTION: Match an interface string to the interfaces supported by the | |
1337 | * host. Strings originate from an AML call to the _OSI method. | |
1338 | * | |
1339 | *****************************************************************************/ | |
1340 | ||
1341 | acpi_status | |
1342 | acpi_os_validate_interface (char *interface) | |
1343 | { | |
ae00d812 LB |
1344 | if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX)) |
1345 | return AE_OK; | |
f507654d | 1346 | if (!strcmp("Linux", interface)) { |
d4b7dc49 | 1347 | |
f40cd6fd | 1348 | printk(KERN_NOTICE PREFIX |
d4b7dc49 LB |
1349 | "BIOS _OSI(Linux) query %s%s\n", |
1350 | osi_linux.enable ? "honored" : "ignored", | |
1351 | osi_linux.cmdline ? " via cmdline" : | |
1352 | osi_linux.dmi ? " via DMI" : ""); | |
1353 | ||
1354 | if (!osi_linux.dmi) { | |
1355 | if (acpi_dmi_dump()) | |
1356 | printk(KERN_NOTICE PREFIX | |
1357 | "[please extract dmidecode output]\n"); | |
1358 | printk(KERN_NOTICE PREFIX | |
1359 | "Please send DMI info above to " | |
1360 | "linux-acpi@vger.kernel.org\n"); | |
1361 | } | |
1362 | if (!osi_linux.known && !osi_linux.cmdline) { | |
1363 | printk(KERN_NOTICE PREFIX | |
1364 | "If \"acpi_osi=%sLinux\" works better, " | |
1365 | "please notify linux-acpi@vger.kernel.org\n", | |
1366 | osi_linux.enable ? "!" : ""); | |
1367 | } | |
1368 | ||
1369 | if (osi_linux.enable) | |
f507654d LB |
1370 | return AE_OK; |
1371 | } | |
ae00d812 | 1372 | return AE_SUPPORT; |
b229cf92 BM |
1373 | } |
1374 | ||
b229cf92 BM |
1375 | /****************************************************************************** |
1376 | * | |
1377 | * FUNCTION: acpi_os_validate_address | |
1378 | * | |
1379 | * PARAMETERS: space_id - ACPI space ID | |
1380 | * address - Physical address | |
1381 | * length - Address length | |
1382 | * | |
1383 | * RETURN: AE_OK if address/length is valid for the space_id. Otherwise, | |
1384 | * should return AE_AML_ILLEGAL_ADDRESS. | |
1385 | * | |
1386 | * DESCRIPTION: Validate a system address via the host OS. Used to validate | |
1387 | * the addresses accessed by AML operation regions. | |
1388 | * | |
1389 | *****************************************************************************/ | |
1390 | ||
1391 | acpi_status | |
1392 | acpi_os_validate_address ( | |
1393 | u8 space_id, | |
1394 | acpi_physical_address address, | |
df92e695 TR |
1395 | acpi_size length, |
1396 | char *name) | |
b229cf92 | 1397 | { |
df92e695 TR |
1398 | struct acpi_res_list *res; |
1399 | if (acpi_enforce_resources == ENFORCE_RESOURCES_NO) | |
1400 | return AE_OK; | |
b229cf92 | 1401 | |
df92e695 TR |
1402 | switch (space_id) { |
1403 | case ACPI_ADR_SPACE_SYSTEM_IO: | |
1404 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: | |
1405 | /* Only interference checks against SystemIO and SytemMemory | |
1406 | are needed */ | |
1407 | res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL); | |
1408 | if (!res) | |
1409 | return AE_OK; | |
1410 | /* ACPI names are fixed to 4 bytes, still better use strlcpy */ | |
1411 | strlcpy(res->name, name, 5); | |
1412 | res->start = address; | |
1413 | res->end = address + length - 1; | |
1414 | res->resource_type = space_id; | |
1415 | spin_lock(&acpi_res_lock); | |
1416 | list_add(&res->resource_list, &resource_list_head); | |
1417 | spin_unlock(&acpi_res_lock); | |
1418 | pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, " | |
1419 | "name: %s\n", (space_id == ACPI_ADR_SPACE_SYSTEM_IO) | |
1420 | ? "SystemIO" : "System Memory", | |
1421 | (unsigned long long)res->start, | |
1422 | (unsigned long long)res->end, | |
1423 | res->name); | |
1424 | break; | |
1425 | case ACPI_ADR_SPACE_PCI_CONFIG: | |
1426 | case ACPI_ADR_SPACE_EC: | |
1427 | case ACPI_ADR_SPACE_SMBUS: | |
1428 | case ACPI_ADR_SPACE_CMOS: | |
1429 | case ACPI_ADR_SPACE_PCI_BAR_TARGET: | |
1430 | case ACPI_ADR_SPACE_DATA_TABLE: | |
1431 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | |
1432 | break; | |
1433 | } | |
1434 | return AE_OK; | |
b229cf92 BM |
1435 | } |
1436 | ||
73459f73 | 1437 | #endif |