blob: 507f051d1cefd437634454809aa69c748f256a0d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/slab.h>
31#include <linux/mm.h>
32#include <linux/pci.h>
33#include <linux/smp_lock.h>
34#include <linux/interrupt.h>
35#include <linux/kmod.h>
36#include <linux/delay.h>
37#include <linux/workqueue.h>
38#include <linux/nmi.h>
39#include <acpi/acpi.h>
40#include <asm/io.h>
41#include <acpi/acpi_bus.h>
42#include <acpi/processor.h>
43#include <asm/uaccess.h>
44
45#include <linux/efi.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define _COMPONENT ACPI_OS_SERVICES
Len Brown4be44fc2005-08-05 00:44:28 -040048ACPI_MODULE_NAME("osl")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define PREFIX "ACPI: "
Len Brown4be44fc2005-08-05 00:44:28 -040050struct acpi_os_dpc {
51 acpi_osd_exec_callback function;
52 void *context;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053};
54
55#ifdef CONFIG_ACPI_CUSTOM_DSDT
56#include CONFIG_ACPI_CUSTOM_DSDT_FILE
57#endif
58
59#ifdef ENABLE_DEBUGGER
60#include <linux/kdb.h>
61
62/* stuff for debugger support */
63int acpi_in_debugger;
64EXPORT_SYMBOL(acpi_in_debugger);
65
66extern char line_buf[80];
Len Brown4be44fc2005-08-05 00:44:28 -040067#endif /*ENABLE_DEBUGGER */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Luming Yu30e332f2005-08-12 00:31:00 -040069int acpi_specific_hotkey_enabled = TRUE;
Luming Yufb9802f2005-03-18 18:03:45 -050070EXPORT_SYMBOL(acpi_specific_hotkey_enabled);
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072static unsigned int acpi_irq_irq;
73static acpi_osd_handler acpi_irq_handler;
74static void *acpi_irq_context;
75static struct workqueue_struct *kacpid_wq;
76
Len Brown4be44fc2005-08-05 00:44:28 -040077acpi_status acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
79 return AE_OK;
80}
81
Len Brown4be44fc2005-08-05 00:44:28 -040082acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 /*
85 * Initialize PCI configuration space access, as we'll need to access
86 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
87 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 if (!raw_pci_ops) {
Len Brown4be44fc2005-08-05 00:44:28 -040089 printk(KERN_ERR PREFIX
90 "Access to PCI configuration space unavailable\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return AE_NULL_ENTRY;
92 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 kacpid_wq = create_singlethread_workqueue("kacpid");
94 BUG_ON(!kacpid_wq);
95
96 return AE_OK;
97}
98
Len Brown4be44fc2005-08-05 00:44:28 -040099acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
101 if (acpi_irq_handler) {
102 acpi_os_remove_interrupt_handler(acpi_irq_irq,
103 acpi_irq_handler);
104 }
105
106 destroy_workqueue(kacpid_wq);
107
108 return AE_OK;
109}
110
Len Brown4be44fc2005-08-05 00:44:28 -0400111void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
113 va_list args;
114 va_start(args, fmt);
115 acpi_os_vprintf(fmt, args);
116 va_end(args);
117}
Len Brown4be44fc2005-08-05 00:44:28 -0400118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119EXPORT_SYMBOL(acpi_os_printf);
120
Len Brown4be44fc2005-08-05 00:44:28 -0400121void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
123 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 vsprintf(buffer, fmt, args);
126
127#ifdef ENABLE_DEBUGGER
128 if (acpi_in_debugger) {
129 kdb_printf("%s", buffer);
130 } else {
131 printk("%s", buffer);
132 }
133#else
134 printk("%s", buffer);
135#endif
136}
137
Len Brown4be44fc2005-08-05 00:44:28 -0400138acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
140 if (efi_enabled) {
141 addr->pointer_type = ACPI_PHYSICAL_POINTER;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800142 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
143 addr->pointer.physical = efi.acpi20;
144 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
145 addr->pointer.physical = efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400147 printk(KERN_ERR PREFIX
148 "System description tables not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 return AE_NOT_FOUND;
150 }
151 } else {
152 if (ACPI_FAILURE(acpi_find_root_pointer(flags, addr))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400153 printk(KERN_ERR PREFIX
154 "System description tables not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 return AE_NOT_FOUND;
156 }
157 }
158
159 return AE_OK;
160}
161
162acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400163acpi_os_map_memory(acpi_physical_address phys, acpi_size size,
164 void __iomem ** virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800166 if (phys > ULONG_MAX) {
167 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
168 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 }
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800170 /*
171 * ioremap checks to ensure this is in reserved space
172 */
173 *virt = ioremap((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 if (!*virt)
176 return AE_NO_MEMORY;
177
178 return AE_OK;
179}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800180EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Len Brown4be44fc2005-08-05 00:44:28 -0400182void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
184 iounmap(virt);
185}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800186EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188#ifdef ACPI_FUTURE_USAGE
189acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400190acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
Len Brown4be44fc2005-08-05 00:44:28 -0400192 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return AE_BAD_PARAMETER;
194
195 *phys = virt_to_phys(virt);
196
197 return AE_OK;
198}
199#endif
200
201#define ACPI_MAX_OVERRIDE_LEN 100
202
203static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
204
205acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400206acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
207 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
209 if (!init_val || !new_val)
210 return AE_BAD_PARAMETER;
211
212 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400213 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400215 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 *new_val = acpi_os_name;
217 }
218
219 return AE_OK;
220}
221
222acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400223acpi_os_table_override(struct acpi_table_header * existing_table,
224 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
226 if (!existing_table || !new_table)
227 return AE_BAD_PARAMETER;
228
229#ifdef CONFIG_ACPI_CUSTOM_DSDT
230 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400231 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 else
233 *new_table = NULL;
234#else
235 *new_table = NULL;
236#endif
237 return AE_OK;
238}
239
Len Brown4be44fc2005-08-05 00:44:28 -0400240static irqreturn_t acpi_irq(int irq, void *dev_id, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
Len Brown4be44fc2005-08-05 00:44:28 -0400242 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243}
244
245acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400246acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
247 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
249 unsigned int irq;
250
251 /*
252 * Ignore the GSI from the core, and use the value in our copy of the
253 * FADT. It may not be the same if an interrupt source override exists
254 * for the SCI.
255 */
256 gsi = acpi_fadt.sci_int;
257 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
258 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
259 gsi);
260 return AE_OK;
261 }
262
263 acpi_irq_handler = handler;
264 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700265 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
267 return AE_NOT_ACQUIRED;
268 }
269 acpi_irq_irq = irq;
270
271 return AE_OK;
272}
273
Len Brown4be44fc2005-08-05 00:44:28 -0400274acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
276 if (irq) {
277 free_irq(irq, acpi_irq);
278 acpi_irq_handler = NULL;
279 acpi_irq_irq = 0;
280 }
281
282 return AE_OK;
283}
284
285/*
286 * Running in interpreter thread context, safe to sleep
287 */
288
Len Brown4be44fc2005-08-05 00:44:28 -0400289void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800291 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
Len Brown4be44fc2005-08-05 00:44:28 -0400293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294EXPORT_SYMBOL(acpi_os_sleep);
295
Len Brown4be44fc2005-08-05 00:44:28 -0400296void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
298 while (us) {
299 u32 delay = 1000;
300
301 if (delay > us)
302 delay = us;
303 udelay(delay);
304 touch_nmi_watchdog();
305 us -= delay;
306 }
307}
Len Brown4be44fc2005-08-05 00:44:28 -0400308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309EXPORT_SYMBOL(acpi_os_stall);
310
311/*
312 * Support ACPI 3.0 AML Timer operand
313 * Returns 64-bit free-running, monotonically increasing timer
314 * with 100ns granularity
315 */
Len Brown4be44fc2005-08-05 00:44:28 -0400316u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
318 static u64 t;
319
320#ifdef CONFIG_HPET
321 /* TBD: use HPET if available */
322#endif
323
324#ifdef CONFIG_X86_PM_TIMER
325 /* TBD: default to PM timer if HPET was not available */
326#endif
327 if (!t)
328 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
329
330 return ++t;
331}
332
Len Brown4be44fc2005-08-05 00:44:28 -0400333acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
335 u32 dummy;
336
337 if (!value)
338 value = &dummy;
339
Len Brown4be44fc2005-08-05 00:44:28 -0400340 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400342 *(u8 *) value = inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 break;
344 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400345 *(u16 *) value = inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 break;
347 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400348 *(u32 *) value = inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 break;
350 default:
351 BUG();
352 }
353
354 return AE_OK;
355}
Len Brown4be44fc2005-08-05 00:44:28 -0400356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357EXPORT_SYMBOL(acpi_os_read_port);
358
Len Brown4be44fc2005-08-05 00:44:28 -0400359acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Len Brown4be44fc2005-08-05 00:44:28 -0400361 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 case 8:
363 outb(value, port);
364 break;
365 case 16:
366 outw(value, port);
367 break;
368 case 32:
369 outl(value, port);
370 break;
371 default:
372 BUG();
373 }
374
375 return AE_OK;
376}
Len Brown4be44fc2005-08-05 00:44:28 -0400377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378EXPORT_SYMBOL(acpi_os_write_port);
379
380acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400381acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
Len Brown4be44fc2005-08-05 00:44:28 -0400383 u32 dummy;
384 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800386 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 if (!value)
388 value = &dummy;
389
390 switch (width) {
391 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400392 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 break;
394 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400395 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 break;
397 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400398 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 break;
400 default:
401 BUG();
402 }
403
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800404 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 return AE_OK;
407}
408
409acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400410acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
Len Brown4be44fc2005-08-05 00:44:28 -0400412 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800414 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
416 switch (width) {
417 case 8:
418 writeb(value, virt_addr);
419 break;
420 case 16:
421 writew(value, virt_addr);
422 break;
423 case 32:
424 writel(value, virt_addr);
425 break;
426 default:
427 BUG();
428 }
429
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800430 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 return AE_OK;
433}
434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400436acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
437 void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
439 int result, size;
440
441 if (!value)
442 return AE_BAD_PARAMETER;
443
444 switch (width) {
445 case 8:
446 size = 1;
447 break;
448 case 16:
449 size = 2;
450 break;
451 case 32:
452 size = 4;
453 break;
454 default:
455 return AE_ERROR;
456 }
457
458 BUG_ON(!raw_pci_ops);
459
460 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400461 PCI_DEVFN(pci_id->device, pci_id->function),
462 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464 return (result ? AE_ERROR : AE_OK);
465}
Len Brown4be44fc2005-08-05 00:44:28 -0400466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467EXPORT_SYMBOL(acpi_os_read_pci_configuration);
468
469acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400470acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
471 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
473 int result, size;
474
475 switch (width) {
476 case 8:
477 size = 1;
478 break;
479 case 16:
480 size = 2;
481 break;
482 case 32:
483 size = 4;
484 break;
485 default:
486 return AE_ERROR;
487 }
488
489 BUG_ON(!raw_pci_ops);
490
491 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400492 PCI_DEVFN(pci_id->device, pci_id->function),
493 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 return (result ? AE_ERROR : AE_OK);
496}
497
498/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400499static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
500 acpi_handle chandle, /* current node */
501 struct acpi_pci_id **id,
502 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
Len Brown4be44fc2005-08-05 00:44:28 -0400504 acpi_handle handle;
505 struct acpi_pci_id *pci_id = *id;
506 acpi_status status;
507 unsigned long temp;
508 acpi_object_type type;
509 u8 tu8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 acpi_get_parent(chandle, &handle);
512 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400513 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
514 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400517 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return;
519
Len Brown4be44fc2005-08-05 00:44:28 -0400520 status =
521 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
522 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 if (ACPI_SUCCESS(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400524 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
525 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527 if (*is_bridge)
528 pci_id->bus = *bus_number;
529
530 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400531 status =
532 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
533 8);
534 if (ACPI_SUCCESS(status)
535 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
536 status =
537 acpi_os_read_pci_configuration(pci_id, 0x18,
538 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 if (!ACPI_SUCCESS(status)) {
540 /* Certainly broken... FIX ME */
541 return;
542 }
543 *is_bridge = 1;
544 pci_id->bus = tu8;
Len Brown4be44fc2005-08-05 00:44:28 -0400545 status =
546 acpi_os_read_pci_configuration(pci_id, 0x19,
547 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 if (ACPI_SUCCESS(status)) {
549 *bus_number = tu8;
550 }
551 } else
552 *is_bridge = 0;
553 }
554 }
555}
556
Len Brown4be44fc2005-08-05 00:44:28 -0400557void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
558 acpi_handle chandle, /* current node */
559 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
561 int is_bridge = 1;
562 u8 bus_number = (*id)->bus;
563
564 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
565}
566
Len Brown4be44fc2005-08-05 00:44:28 -0400567static void acpi_os_execute_deferred(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
Len Brown4be44fc2005-08-05 00:44:28 -0400569 struct acpi_os_dpc *dpc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Len Brown4be44fc2005-08-05 00:44:28 -0400572 dpc = (struct acpi_os_dpc *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 if (!dpc) {
Len Brown64684632006-06-26 23:41:38 -0400574 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400575 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 }
577
578 dpc->function(dpc->context);
579
580 kfree(dpc);
581
Patrick Mocheld550d982006-06-27 00:41:40 -0400582 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583}
584
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400585/*******************************************************************************
586 *
587 * FUNCTION: acpi_os_execute
588 *
589 * PARAMETERS: Type - Type of the callback
590 * Function - Function to be executed
591 * Context - Function parameters
592 *
593 * RETURN: Status
594 *
595 * DESCRIPTION: Depending on type, either queues function for deferred execution or
596 * immediately executes function on a separate thread.
597 *
598 ******************************************************************************/
599
600acpi_status acpi_os_execute(acpi_execute_type type,
Len Brown4be44fc2005-08-05 00:44:28 -0400601 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Len Brown4be44fc2005-08-05 00:44:28 -0400603 acpi_status status = AE_OK;
604 struct acpi_os_dpc *dpc;
605 struct work_struct *task;
Len Brown72945b22006-07-12 22:46:42 -0400606
607 ACPI_FUNCTION_TRACE("os_queue_for_execution");
608
609 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
610 "Scheduling function [%p(%p)] for deferred execution.\n",
611 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 if (!function)
Len Brown72945b22006-07-12 22:46:42 -0400614 return_ACPI_STATUS(AE_BAD_PARAMETER);
615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 /*
617 * Allocate/initialize DPC structure. Note that this memory will be
618 * freed by the callee. The kernel handles the tq_struct list in a
619 * way that allows us to also free its memory inside the callee.
620 * Because we may want to schedule several tasks with different
621 * parameters we can't use the approach some kernel code uses of
622 * having a static tq_struct.
623 * We can save time and code by allocating the DPC and tq_structs
624 * from the same memory.
625 */
Len Brown72945b22006-07-12 22:46:42 -0400626
627 dpc =
628 kmalloc(sizeof(struct acpi_os_dpc) + sizeof(struct work_struct),
629 GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 if (!dpc)
Len Brown72945b22006-07-12 22:46:42 -0400631 return_ACPI_STATUS(AE_NO_MEMORY);
632
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 dpc->function = function;
634 dpc->context = context;
635
Len Brown72945b22006-07-12 22:46:42 -0400636 task = (void *)(dpc + 1);
637 INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc);
638
639 if (!queue_work(kacpid_wq, task)) {
640 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
641 "Call to queue_work() failed.\n"));
642 kfree(dpc);
643 status = AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 }
Len Brown72945b22006-07-12 22:46:42 -0400645
646 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
Len Brown4be44fc2005-08-05 00:44:28 -0400648
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400649EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Len Brown4be44fc2005-08-05 00:44:28 -0400651void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
653 flush_workqueue(kacpid_wq);
654}
Len Brown4be44fc2005-08-05 00:44:28 -0400655
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656EXPORT_SYMBOL(acpi_os_wait_events_complete);
657
658/*
659 * Allocate the memory for a spinlock and initialize it.
660 */
Bob Moore967440e32006-06-23 17:04:00 -0400661acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662{
Bob Moore967440e32006-06-23 17:04:00 -0400663 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Patrick Mocheld550d982006-06-27 00:41:40 -0400665 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668/*
669 * Deallocate the memory for a spinlock.
670 */
Bob Moore967440e32006-06-23 17:04:00 -0400671void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
Patrick Mocheld550d982006-06-27 00:41:40 -0400673 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674}
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400677acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
Len Brown4be44fc2005-08-05 00:44:28 -0400679 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
682 sem = acpi_os_allocate(sizeof(struct semaphore));
683 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400684 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 memset(sem, 0, sizeof(struct semaphore));
686
687 sema_init(sem, initial_units);
688
Len Brown4be44fc2005-08-05 00:44:28 -0400689 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Len Brown4be44fc2005-08-05 00:44:28 -0400691 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
692 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Patrick Mocheld550d982006-06-27 00:41:40 -0400694 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Len Brown4be44fc2005-08-05 00:44:28 -0400697EXPORT_SYMBOL(acpi_os_create_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699/*
700 * TODO: A better way to delete semaphores? Linux doesn't have a
701 * 'delete_semaphore()' function -- may result in an invalid
702 * pointer dereference for non-synchronized consumers. Should
703 * we at least check for blocked threads and signal/cancel them?
704 */
705
Len Brown4be44fc2005-08-05 00:44:28 -0400706acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
Len Brown4be44fc2005-08-05 00:44:28 -0400708 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
711 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400712 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Len Brown4be44fc2005-08-05 00:44:28 -0400714 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Len Brown02438d82006-06-30 03:19:10 -0400716 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400717 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Patrick Mocheld550d982006-06-27 00:41:40 -0400719 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Len Brown4be44fc2005-08-05 00:44:28 -0400722EXPORT_SYMBOL(acpi_os_delete_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724/*
725 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
726 * improvise. The process is to sleep for one scheduler quantum
727 * until the semaphore becomes available. Downside is that this
728 * may result in starvation for timeout-based waits when there's
729 * lots of semaphore activity.
730 *
731 * TODO: Support for units > 1?
732 */
Len Brown4be44fc2005-08-05 00:44:28 -0400733acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734{
Len Brown4be44fc2005-08-05 00:44:28 -0400735 acpi_status status = AE_OK;
736 struct semaphore *sem = (struct semaphore *)handle;
737 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400741 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
743 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400744 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Len Brown4be44fc2005-08-05 00:44:28 -0400746 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
747 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Len Brownd68909f2006-08-16 19:16:58 -0400749 /*
750 * This can be called during resume with interrupts off.
751 * Like boot-time, we should be single threaded and will
752 * always get the lock if we try -- timeout or not.
753 * If this doesn't succeed, then we will oops courtesy of
754 * might_sleep() in down().
755 */
756 if (!down_trylock(sem))
757 return AE_OK;
758
Len Brown4be44fc2005-08-05 00:44:28 -0400759 switch (timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 /*
761 * No Wait:
762 * --------
763 * A zero timeout value indicates that we shouldn't wait - just
764 * acquire the semaphore if available otherwise return AE_TIME
765 * (a.k.a. 'would block').
766 */
Len Brown4be44fc2005-08-05 00:44:28 -0400767 case 0:
768 if (down_trylock(sem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 status = AE_TIME;
770 break;
771
772 /*
773 * Wait Indefinitely:
774 * ------------------
775 */
Len Brown4be44fc2005-08-05 00:44:28 -0400776 case ACPI_WAIT_FOREVER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 down(sem);
778 break;
779
780 /*
781 * Wait w/ Timeout:
782 * ----------------
783 */
Len Brown4be44fc2005-08-05 00:44:28 -0400784 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 // TODO: A better timeout algorithm?
786 {
787 int i = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400788 static const int quantum_ms = 1000 / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 ret = down_trylock(sem);
Yu Lumingdacd9b82005-12-31 01:45:00 -0500791 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800792 schedule_timeout_interruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 ret = down_trylock(sem);
794 }
Len Brown4be44fc2005-08-05 00:44:28 -0400795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 if (ret != 0)
797 status = AE_TIME;
798 }
799 break;
800 }
801
802 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400803 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400804 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400805 handle, units, timeout,
806 acpi_format_exception(status)));
807 } else {
808 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400809 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400810 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 }
812
Patrick Mocheld550d982006-06-27 00:41:40 -0400813 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Len Brown4be44fc2005-08-05 00:44:28 -0400816EXPORT_SYMBOL(acpi_os_wait_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818/*
819 * TODO: Support for units > 1?
820 */
Len Brown4be44fc2005-08-05 00:44:28 -0400821acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
Len Brown4be44fc2005-08-05 00:44:28 -0400823 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400827 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400830 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Len Brown4be44fc2005-08-05 00:44:28 -0400832 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
833 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
835 up(sem);
836
Patrick Mocheld550d982006-06-27 00:41:40 -0400837 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838}
Len Brown4be44fc2005-08-05 00:44:28 -0400839
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840EXPORT_SYMBOL(acpi_os_signal_semaphore);
841
842#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400843u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
845
846#ifdef ENABLE_DEBUGGER
847 if (acpi_in_debugger) {
848 u32 chars;
849
850 kdb_read(buffer, sizeof(line_buf));
851
852 /* remove the CR kdb includes */
853 chars = strlen(buffer) - 1;
854 buffer[chars] = '\0';
855 }
856#endif
857
858 return 0;
859}
Len Brown4be44fc2005-08-05 00:44:28 -0400860#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862/* Assumes no unreadable holes inbetween */
Len Brown4be44fc2005-08-05 00:44:28 -0400863u8 acpi_os_readable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
Len Brown4be44fc2005-08-05 00:44:28 -0400865#if defined(__i386__) || defined(__x86_64__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 char tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400867 return !__get_user(tmp, (char __user *)ptr)
868 && !__get_user(tmp, (char __user *)ptr + len - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869#endif
870 return 1;
871}
872
873#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400874u8 acpi_os_writable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
876 /* could do dummy write (racy) or a kernel page table lookup.
877 The later may be difficult at early boot when kmap doesn't work yet. */
878 return 1;
879}
880#endif
881
Len Brown4be44fc2005-08-05 00:44:28 -0400882acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883{
Len Brown4be44fc2005-08-05 00:44:28 -0400884 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 case ACPI_SIGNAL_FATAL:
886 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
887 break;
888 case ACPI_SIGNAL_BREAKPOINT:
889 /*
890 * AML Breakpoint
891 * ACPI spec. says to treat it as a NOP unless
892 * you are debugging. So if/when we integrate
893 * AML debugger into the kernel debugger its
894 * hook will go here. But until then it is
895 * not useful to print anything on breakpoints.
896 */
897 break;
898 default:
899 break;
900 }
901
902 return AE_OK;
903}
Len Brown4be44fc2005-08-05 00:44:28 -0400904
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905EXPORT_SYMBOL(acpi_os_signal);
906
Len Brown4be44fc2005-08-05 00:44:28 -0400907static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
909 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400910 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 if (!str || !*str)
913 return 0;
914
915 for (; count-- && str && *str; str++) {
916 if (isalnum(*str) || *str == ' ' || *str == ':')
917 *p++ = *str;
918 else if (*str == '\'' || *str == '"')
919 continue;
920 else
921 break;
922 }
923 *p = 0;
924
925 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927}
928
929__setup("acpi_os_name=", acpi_os_name_setup);
930
931/*
932 * _OSI control
933 * empty string disables _OSI
934 * TBD additional string adds to _OSI
935 */
Len Brown4be44fc2005-08-05 00:44:28 -0400936static int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937{
938 if (str == NULL || *str == '\0') {
939 printk(KERN_INFO PREFIX "_OSI method disabled\n");
940 acpi_gbl_create_osi_method = FALSE;
Len Brown4be44fc2005-08-05 00:44:28 -0400941 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 /* TBD */
Len Brown4be44fc2005-08-05 00:44:28 -0400943 printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n",
944 str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 }
946
947 return 1;
948}
949
950__setup("acpi_osi=", acpi_osi_setup);
951
952/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -0400953static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
955 printk(KERN_INFO PREFIX "serialize enabled\n");
956
957 acpi_gbl_all_methods_serialized = TRUE;
958
959 return 1;
960}
961
962__setup("acpi_serialize", acpi_serialize_setup);
963
964/*
965 * Wake and Run-Time GPES are expected to be separate.
966 * We disable wake-GPEs at run-time to prevent spurious
967 * interrupts.
968 *
969 * However, if a system exists that shares Wake and
970 * Run-time events on the same GPE this flag is available
971 * to tell Linux to keep the wake-time GPEs enabled at run-time.
972 */
Len Brown4be44fc2005-08-05 00:44:28 -0400973static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974{
975 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
976
977 acpi_gbl_leave_wake_gpes_disabled = FALSE;
978
979 return 1;
980}
981
982__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
983
Adrian Bunk8713cbe2005-09-02 17:16:48 -0400984static int __init acpi_hotkey_setup(char *str)
Luming Yufb9802f2005-03-18 18:03:45 -0500985{
Luming Yu30e332f2005-08-12 00:31:00 -0400986 acpi_specific_hotkey_enabled = FALSE;
Luming Yufb9802f2005-03-18 18:03:45 -0500987 return 1;
988}
989
Luming Yu30e332f2005-08-12 00:31:00 -0400990__setup("acpi_generic_hotkey", acpi_hotkey_setup);
Luming Yufb9802f2005-03-18 18:03:45 -0500991
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992/*
993 * max_cstate is defined in the base kernel so modules can
994 * change it w/o depending on the state of the processor module.
995 */
996unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998EXPORT_SYMBOL(max_cstate);
Robert Moore73459f72005-06-24 00:00:00 -0400999
1000/*
1001 * Acquire a spinlock.
1002 *
1003 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001004 */
1005
Bob Moore967440e32006-06-23 17:04:00 -04001006acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001007{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001008 acpi_cpu_flags flags;
Bob Moore967440e32006-06-23 17:04:00 -04001009 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001010 return flags;
1011}
1012
1013/*
1014 * Release a spinlock. See above.
1015 */
1016
Bob Moore967440e32006-06-23 17:04:00 -04001017void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001018{
Bob Moore967440e32006-06-23 17:04:00 -04001019 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001020}
1021
Robert Moore73459f72005-06-24 00:00:00 -04001022#ifndef ACPI_USE_LOCAL_CACHE
1023
1024/*******************************************************************************
1025 *
1026 * FUNCTION: acpi_os_create_cache
1027 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001028 * PARAMETERS: name - Ascii name for the cache
1029 * size - Size of each cached object
1030 * depth - Maximum depth of the cache (in objects) <ignored>
1031 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001032 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001033 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001034 *
1035 * DESCRIPTION: Create a cache object
1036 *
1037 ******************************************************************************/
1038
1039acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001040acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001041{
Len Brown4be44fc2005-08-05 00:44:28 -04001042 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
Bob Mooreb229cf92006-04-21 17:15:00 -04001043 if (cache == NULL)
1044 return AE_ERROR;
1045 else
1046 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001047}
1048
1049/*******************************************************************************
1050 *
1051 * FUNCTION: acpi_os_purge_cache
1052 *
1053 * PARAMETERS: Cache - Handle to cache object
1054 *
1055 * RETURN: Status
1056 *
1057 * DESCRIPTION: Free all objects within the requested cache.
1058 *
1059 ******************************************************************************/
1060
Len Brown4be44fc2005-08-05 00:44:28 -04001061acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001062{
Len Brown4be44fc2005-08-05 00:44:28 -04001063 (void)kmem_cache_shrink(cache);
1064 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001065}
1066
1067/*******************************************************************************
1068 *
1069 * FUNCTION: acpi_os_delete_cache
1070 *
1071 * PARAMETERS: Cache - Handle to cache object
1072 *
1073 * RETURN: Status
1074 *
1075 * DESCRIPTION: Free all objects within the requested cache and delete the
1076 * cache object.
1077 *
1078 ******************************************************************************/
1079
Len Brown4be44fc2005-08-05 00:44:28 -04001080acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001081{
Len Brown4be44fc2005-08-05 00:44:28 -04001082 (void)kmem_cache_destroy(cache);
1083 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001084}
1085
1086/*******************************************************************************
1087 *
1088 * FUNCTION: acpi_os_release_object
1089 *
1090 * PARAMETERS: Cache - Handle to cache object
1091 * Object - The object to be released
1092 *
1093 * RETURN: None
1094 *
1095 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1096 * the object is deleted.
1097 *
1098 ******************************************************************************/
1099
Len Brown4be44fc2005-08-05 00:44:28 -04001100acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001101{
Len Brown4be44fc2005-08-05 00:44:28 -04001102 kmem_cache_free(cache, object);
1103 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001104}
1105
Bob Mooreb229cf92006-04-21 17:15:00 -04001106/******************************************************************************
1107 *
1108 * FUNCTION: acpi_os_validate_interface
1109 *
1110 * PARAMETERS: interface - Requested interface to be validated
1111 *
1112 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1113 *
1114 * DESCRIPTION: Match an interface string to the interfaces supported by the
1115 * host. Strings originate from an AML call to the _OSI method.
1116 *
1117 *****************************************************************************/
1118
1119acpi_status
1120acpi_os_validate_interface (char *interface)
1121{
1122
1123 return AE_SUPPORT;
1124}
1125
1126
1127/******************************************************************************
1128 *
1129 * FUNCTION: acpi_os_validate_address
1130 *
1131 * PARAMETERS: space_id - ACPI space ID
1132 * address - Physical address
1133 * length - Address length
1134 *
1135 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1136 * should return AE_AML_ILLEGAL_ADDRESS.
1137 *
1138 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1139 * the addresses accessed by AML operation regions.
1140 *
1141 *****************************************************************************/
1142
1143acpi_status
1144acpi_os_validate_address (
1145 u8 space_id,
1146 acpi_physical_address address,
1147 acpi_size length)
1148{
1149
1150 return AE_OK;
1151}
1152
1153
Robert Moore73459f72005-06-24 00:00:00 -04001154#endif