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