blob: c1c2100fe133b0926eca78a1048e74a3ca61c127 [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>
Alexey Starikovskiyad718602007-02-02 19:48:19 +030039#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#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>
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_OS_SERVICES
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("osl")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define PREFIX "ACPI: "
Len Brown4be44fc2005-08-05 00:44:28 -040051struct acpi_os_dpc {
52 acpi_osd_exec_callback function;
53 void *context;
David Howells65f27f32006-11-22 14:55:48 +000054 struct work_struct work;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055};
56
57#ifdef CONFIG_ACPI_CUSTOM_DSDT
58#include CONFIG_ACPI_CUSTOM_DSDT_FILE
59#endif
60
61#ifdef ENABLE_DEBUGGER
62#include <linux/kdb.h>
63
64/* stuff for debugger support */
65int acpi_in_debugger;
66EXPORT_SYMBOL(acpi_in_debugger);
67
68extern char line_buf[80];
Len Brown4be44fc2005-08-05 00:44:28 -040069#endif /*ENABLE_DEBUGGER */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Luming Yu30e332f2005-08-12 00:31:00 -040071int acpi_specific_hotkey_enabled = TRUE;
Luming Yufb9802f2005-03-18 18:03:45 -050072EXPORT_SYMBOL(acpi_specific_hotkey_enabled);
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074static unsigned int acpi_irq_irq;
75static acpi_osd_handler acpi_irq_handler;
76static void *acpi_irq_context;
77static struct workqueue_struct *kacpid_wq;
78
Len Brown4be44fc2005-08-05 00:44:28 -040079acpi_status acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 return AE_OK;
82}
83
Len Brown4be44fc2005-08-05 00:44:28 -040084acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
86 /*
87 * Initialize PCI configuration space access, as we'll need to access
88 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
89 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 if (!raw_pci_ops) {
Len Brown4be44fc2005-08-05 00:44:28 -040091 printk(KERN_ERR PREFIX
92 "Access to PCI configuration space unavailable\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return AE_NULL_ENTRY;
94 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 kacpid_wq = create_singlethread_workqueue("kacpid");
96 BUG_ON(!kacpid_wq);
Linus Torvaldsb976fe12006-11-17 19:31:09 -080097
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return AE_OK;
99}
100
Len Brown4be44fc2005-08-05 00:44:28 -0400101acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
103 if (acpi_irq_handler) {
104 acpi_os_remove_interrupt_handler(acpi_irq_irq,
105 acpi_irq_handler);
106 }
107
108 destroy_workqueue(kacpid_wq);
109
110 return AE_OK;
111}
112
Len Brown4be44fc2005-08-05 00:44:28 -0400113void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
115 va_list args;
116 va_start(args, fmt);
117 acpi_os_vprintf(fmt, args);
118 va_end(args);
119}
Len Brown4be44fc2005-08-05 00:44:28 -0400120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121EXPORT_SYMBOL(acpi_os_printf);
122
Len Brown4be44fc2005-08-05 00:44:28 -0400123void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 vsprintf(buffer, fmt, args);
128
129#ifdef ENABLE_DEBUGGER
130 if (acpi_in_debugger) {
131 kdb_printf("%s", buffer);
132 } else {
133 printk("%s", buffer);
134 }
135#else
136 printk("%s", buffer);
137#endif
138}
139
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300140acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
142 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800143 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300144 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800145 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300146 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400148 printk(KERN_ERR PREFIX
149 "System description tables not found\n");
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300150 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300152 } else
153 return acpi_find_rsdp();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154}
155
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300156void __iomem *acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800158 if (phys > ULONG_MAX) {
159 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300160 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300162 if (acpi_gbl_permanent_mmap)
163 /*
164 * ioremap checks to ensure this is in reserved space
165 */
166 return ioremap((unsigned long)phys, size);
167 else
168 return __acpi_map_table((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800170EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Len Brown4be44fc2005-08-05 00:44:28 -0400172void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300174 if (acpi_gbl_permanent_mmap) {
175 iounmap(virt);
176 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800178EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180#ifdef ACPI_FUTURE_USAGE
181acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400182acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
Len Brown4be44fc2005-08-05 00:44:28 -0400184 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return AE_BAD_PARAMETER;
186
187 *phys = virt_to_phys(virt);
188
189 return AE_OK;
190}
191#endif
192
193#define ACPI_MAX_OVERRIDE_LEN 100
194
195static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
196
197acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400198acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
199 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
201 if (!init_val || !new_val)
202 return AE_BAD_PARAMETER;
203
204 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400205 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400207 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 *new_val = acpi_os_name;
209 }
210
211 return AE_OK;
212}
213
214acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400215acpi_os_table_override(struct acpi_table_header * existing_table,
216 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
218 if (!existing_table || !new_table)
219 return AE_BAD_PARAMETER;
220
221#ifdef CONFIG_ACPI_CUSTOM_DSDT
222 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400223 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 else
225 *new_table = NULL;
226#else
227 *new_table = NULL;
228#endif
229 return AE_OK;
230}
231
David Howells7d12e782006-10-05 14:55:46 +0100232static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Len Brown4be44fc2005-08-05 00:44:28 -0400234 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235}
236
237acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400238acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
239 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 unsigned int irq;
242
243 /*
244 * Ignore the GSI from the core, and use the value in our copy of the
245 * FADT. It may not be the same if an interrupt source override exists
246 * for the SCI.
247 */
248 gsi = acpi_fadt.sci_int;
249 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
250 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
251 gsi);
252 return AE_OK;
253 }
254
255 acpi_irq_handler = handler;
256 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700257 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
259 return AE_NOT_ACQUIRED;
260 }
261 acpi_irq_irq = irq;
262
263 return AE_OK;
264}
265
Len Brown4be44fc2005-08-05 00:44:28 -0400266acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 if (irq) {
269 free_irq(irq, acpi_irq);
270 acpi_irq_handler = NULL;
271 acpi_irq_irq = 0;
272 }
273
274 return AE_OK;
275}
276
277/*
278 * Running in interpreter thread context, safe to sleep
279 */
280
Len Brown4be44fc2005-08-05 00:44:28 -0400281void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800283 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284}
Len Brown4be44fc2005-08-05 00:44:28 -0400285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286EXPORT_SYMBOL(acpi_os_sleep);
287
Len Brown4be44fc2005-08-05 00:44:28 -0400288void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
290 while (us) {
291 u32 delay = 1000;
292
293 if (delay > us)
294 delay = us;
295 udelay(delay);
296 touch_nmi_watchdog();
297 us -= delay;
298 }
299}
Len Brown4be44fc2005-08-05 00:44:28 -0400300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301EXPORT_SYMBOL(acpi_os_stall);
302
303/*
304 * Support ACPI 3.0 AML Timer operand
305 * Returns 64-bit free-running, monotonically increasing timer
306 * with 100ns granularity
307 */
Len Brown4be44fc2005-08-05 00:44:28 -0400308u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
310 static u64 t;
311
312#ifdef CONFIG_HPET
313 /* TBD: use HPET if available */
314#endif
315
316#ifdef CONFIG_X86_PM_TIMER
317 /* TBD: default to PM timer if HPET was not available */
318#endif
319 if (!t)
320 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
321
322 return ++t;
323}
324
Len Brown4be44fc2005-08-05 00:44:28 -0400325acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
327 u32 dummy;
328
329 if (!value)
330 value = &dummy;
331
Len Brown4be44fc2005-08-05 00:44:28 -0400332 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400334 *(u8 *) value = inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 break;
336 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400337 *(u16 *) value = inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 break;
339 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400340 *(u32 *) value = inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 break;
342 default:
343 BUG();
344 }
345
346 return AE_OK;
347}
Len Brown4be44fc2005-08-05 00:44:28 -0400348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349EXPORT_SYMBOL(acpi_os_read_port);
350
Len Brown4be44fc2005-08-05 00:44:28 -0400351acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
Len Brown4be44fc2005-08-05 00:44:28 -0400353 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 case 8:
355 outb(value, port);
356 break;
357 case 16:
358 outw(value, port);
359 break;
360 case 32:
361 outl(value, port);
362 break;
363 default:
364 BUG();
365 }
366
367 return AE_OK;
368}
Len Brown4be44fc2005-08-05 00:44:28 -0400369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370EXPORT_SYMBOL(acpi_os_write_port);
371
372acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400373acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
Len Brown4be44fc2005-08-05 00:44:28 -0400375 u32 dummy;
376 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800378 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 if (!value)
380 value = &dummy;
381
382 switch (width) {
383 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400384 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 break;
386 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400387 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 break;
389 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400390 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 break;
392 default:
393 BUG();
394 }
395
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800396 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 return AE_OK;
399}
400
401acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400402acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Len Brown4be44fc2005-08-05 00:44:28 -0400404 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800406 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 switch (width) {
409 case 8:
410 writeb(value, virt_addr);
411 break;
412 case 16:
413 writew(value, virt_addr);
414 break;
415 case 32:
416 writel(value, virt_addr);
417 break;
418 default:
419 BUG();
420 }
421
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800422 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424 return AE_OK;
425}
426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400428acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
429 void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
431 int result, size;
432
433 if (!value)
434 return AE_BAD_PARAMETER;
435
436 switch (width) {
437 case 8:
438 size = 1;
439 break;
440 case 16:
441 size = 2;
442 break;
443 case 32:
444 size = 4;
445 break;
446 default:
447 return AE_ERROR;
448 }
449
450 BUG_ON(!raw_pci_ops);
451
452 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400453 PCI_DEVFN(pci_id->device, pci_id->function),
454 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
456 return (result ? AE_ERROR : AE_OK);
457}
Len Brown4be44fc2005-08-05 00:44:28 -0400458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459EXPORT_SYMBOL(acpi_os_read_pci_configuration);
460
461acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400462acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
463 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
465 int result, size;
466
467 switch (width) {
468 case 8:
469 size = 1;
470 break;
471 case 16:
472 size = 2;
473 break;
474 case 32:
475 size = 4;
476 break;
477 default:
478 return AE_ERROR;
479 }
480
481 BUG_ON(!raw_pci_ops);
482
483 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400484 PCI_DEVFN(pci_id->device, pci_id->function),
485 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 return (result ? AE_ERROR : AE_OK);
488}
489
490/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400491static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
492 acpi_handle chandle, /* current node */
493 struct acpi_pci_id **id,
494 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
Len Brown4be44fc2005-08-05 00:44:28 -0400496 acpi_handle handle;
497 struct acpi_pci_id *pci_id = *id;
498 acpi_status status;
499 unsigned long temp;
500 acpi_object_type type;
501 u8 tu8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 acpi_get_parent(chandle, &handle);
504 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400505 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
506 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400509 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 return;
511
Len Brown4be44fc2005-08-05 00:44:28 -0400512 status =
513 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
514 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (ACPI_SUCCESS(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400516 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
517 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519 if (*is_bridge)
520 pci_id->bus = *bus_number;
521
522 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400523 status =
524 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
525 8);
526 if (ACPI_SUCCESS(status)
527 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
528 status =
529 acpi_os_read_pci_configuration(pci_id, 0x18,
530 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 if (!ACPI_SUCCESS(status)) {
532 /* Certainly broken... FIX ME */
533 return;
534 }
535 *is_bridge = 1;
536 pci_id->bus = tu8;
Len Brown4be44fc2005-08-05 00:44:28 -0400537 status =
538 acpi_os_read_pci_configuration(pci_id, 0x19,
539 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 if (ACPI_SUCCESS(status)) {
541 *bus_number = tu8;
542 }
543 } else
544 *is_bridge = 0;
545 }
546 }
547}
548
Len Brown4be44fc2005-08-05 00:44:28 -0400549void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
550 acpi_handle chandle, /* current node */
551 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552{
553 int is_bridge = 1;
554 u8 bus_number = (*id)->bus;
555
556 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
557}
558
David Howells65f27f32006-11-22 14:55:48 +0000559static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
David Howells65f27f32006-11-22 14:55:48 +0000561 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 if (!dpc) {
Len Brown64684632006-06-26 23:41:38 -0400564 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400565 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 }
567
568 dpc->function(dpc->context);
569
570 kfree(dpc);
571
Patrick Mocheld550d982006-06-27 00:41:40 -0400572 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573}
574
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400575/*******************************************************************************
576 *
577 * FUNCTION: acpi_os_execute
578 *
579 * PARAMETERS: Type - Type of the callback
580 * Function - Function to be executed
581 * Context - Function parameters
582 *
583 * RETURN: Status
584 *
585 * DESCRIPTION: Depending on type, either queues function for deferred execution or
586 * immediately executes function on a separate thread.
587 *
588 ******************************************************************************/
589
590acpi_status acpi_os_execute(acpi_execute_type type,
Len Brown4be44fc2005-08-05 00:44:28 -0400591 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Len Brown4be44fc2005-08-05 00:44:28 -0400593 acpi_status status = AE_OK;
594 struct acpi_os_dpc *dpc;
Len Brown72945b22006-07-12 22:46:42 -0400595
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800596 ACPI_FUNCTION_TRACE("os_queue_for_execution");
597
Len Brown72945b22006-07-12 22:46:42 -0400598 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
599 "Scheduling function [%p(%p)] for deferred execution.\n",
600 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 if (!function)
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800603 return_ACPI_STATUS(AE_BAD_PARAMETER);
Len Brown72945b22006-07-12 22:46:42 -0400604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 /*
606 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000607 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 * way that allows us to also free its memory inside the callee.
609 * Because we may want to schedule several tasks with different
610 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000611 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 */
Len Brown72945b22006-07-12 22:46:42 -0400613
David Howells65f27f32006-11-22 14:55:48 +0000614 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 if (!dpc)
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800616 return_ACPI_STATUS(AE_NO_MEMORY);
617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 dpc->function = function;
619 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800620
David Howells65f27f32006-11-22 14:55:48 +0000621 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
622 if (!queue_work(kacpid_wq, &dpc->work)) {
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800623 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
624 "Call to queue_work() failed.\n"));
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -0400625 kfree(dpc);
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800626 status = AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 }
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800628
629 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630}
Len Brown4be44fc2005-08-05 00:44:28 -0400631
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400632EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Len Brown4be44fc2005-08-05 00:44:28 -0400634void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635{
636 flush_workqueue(kacpid_wq);
637}
Len Brown4be44fc2005-08-05 00:44:28 -0400638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639EXPORT_SYMBOL(acpi_os_wait_events_complete);
640
641/*
642 * Allocate the memory for a spinlock and initialize it.
643 */
Bob Moore967440e2006-06-23 17:04:00 -0400644acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645{
Bob Moore967440e2006-06-23 17:04:00 -0400646 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Patrick Mocheld550d982006-06-27 00:41:40 -0400648 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649}
650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651/*
652 * Deallocate the memory for a spinlock.
653 */
Bob Moore967440e2006-06-23 17:04:00 -0400654void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
Patrick Mocheld550d982006-06-27 00:41:40 -0400656 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400660acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661{
Len Brown4be44fc2005-08-05 00:44:28 -0400662 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
665 sem = acpi_os_allocate(sizeof(struct semaphore));
666 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400667 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 memset(sem, 0, sizeof(struct semaphore));
669
670 sema_init(sem, initial_units);
671
Len Brown4be44fc2005-08-05 00:44:28 -0400672 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Len Brown4be44fc2005-08-05 00:44:28 -0400674 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
675 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Patrick Mocheld550d982006-06-27 00:41:40 -0400677 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Len Brown4be44fc2005-08-05 00:44:28 -0400680EXPORT_SYMBOL(acpi_os_create_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
682/*
683 * TODO: A better way to delete semaphores? Linux doesn't have a
684 * 'delete_semaphore()' function -- may result in an invalid
685 * pointer dereference for non-synchronized consumers. Should
686 * we at least check for blocked threads and signal/cancel them?
687 */
688
Len Brown4be44fc2005-08-05 00:44:28 -0400689acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
Len Brown4be44fc2005-08-05 00:44:28 -0400691 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
694 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400695 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Len Brown02438d82006-06-30 03:19:10 -0400699 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400700 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Patrick Mocheld550d982006-06-27 00:41:40 -0400702 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Len Brown4be44fc2005-08-05 00:44:28 -0400705EXPORT_SYMBOL(acpi_os_delete_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
707/*
708 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
709 * improvise. The process is to sleep for one scheduler quantum
710 * until the semaphore becomes available. Downside is that this
711 * may result in starvation for timeout-based waits when there's
712 * lots of semaphore activity.
713 *
714 * TODO: Support for units > 1?
715 */
Len Brown4be44fc2005-08-05 00:44:28 -0400716acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
Len Brown4be44fc2005-08-05 00:44:28 -0400718 acpi_status status = AE_OK;
719 struct semaphore *sem = (struct semaphore *)handle;
720 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
723 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400724 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
726 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400727 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Len Brown4be44fc2005-08-05 00:44:28 -0400729 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
730 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Len Brownd68909f2006-08-16 19:16:58 -0400732 /*
733 * This can be called during resume with interrupts off.
734 * Like boot-time, we should be single threaded and will
735 * always get the lock if we try -- timeout or not.
736 * If this doesn't succeed, then we will oops courtesy of
737 * might_sleep() in down().
738 */
739 if (!down_trylock(sem))
740 return AE_OK;
741
Len Brown4be44fc2005-08-05 00:44:28 -0400742 switch (timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 /*
744 * No Wait:
745 * --------
746 * A zero timeout value indicates that we shouldn't wait - just
747 * acquire the semaphore if available otherwise return AE_TIME
748 * (a.k.a. 'would block').
749 */
Len Brown4be44fc2005-08-05 00:44:28 -0400750 case 0:
751 if (down_trylock(sem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 status = AE_TIME;
753 break;
754
755 /*
756 * Wait Indefinitely:
757 * ------------------
758 */
Len Brown4be44fc2005-08-05 00:44:28 -0400759 case ACPI_WAIT_FOREVER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 down(sem);
761 break;
762
763 /*
764 * Wait w/ Timeout:
765 * ----------------
766 */
Len Brown4be44fc2005-08-05 00:44:28 -0400767 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 // TODO: A better timeout algorithm?
769 {
770 int i = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400771 static const int quantum_ms = 1000 / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773 ret = down_trylock(sem);
Yu Lumingdacd9b82005-12-31 01:45:00 -0500774 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800775 schedule_timeout_interruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 ret = down_trylock(sem);
777 }
Len Brown4be44fc2005-08-05 00:44:28 -0400778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 if (ret != 0)
780 status = AE_TIME;
781 }
782 break;
783 }
784
785 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400786 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400787 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400788 handle, units, timeout,
789 acpi_format_exception(status)));
790 } else {
791 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400792 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400793 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 }
795
Patrick Mocheld550d982006-06-27 00:41:40 -0400796 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Len Brown4be44fc2005-08-05 00:44:28 -0400799EXPORT_SYMBOL(acpi_os_wait_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
801/*
802 * TODO: Support for units > 1?
803 */
Len Brown4be44fc2005-08-05 00:44:28 -0400804acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805{
Len Brown4be44fc2005-08-05 00:44:28 -0400806 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400810 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400813 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Len Brown4be44fc2005-08-05 00:44:28 -0400815 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
816 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818 up(sem);
819
Patrick Mocheld550d982006-06-27 00:41:40 -0400820 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821}
Len Brown4be44fc2005-08-05 00:44:28 -0400822
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823EXPORT_SYMBOL(acpi_os_signal_semaphore);
824
825#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400826u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
828
829#ifdef ENABLE_DEBUGGER
830 if (acpi_in_debugger) {
831 u32 chars;
832
833 kdb_read(buffer, sizeof(line_buf));
834
835 /* remove the CR kdb includes */
836 chars = strlen(buffer) - 1;
837 buffer[chars] = '\0';
838 }
839#endif
840
841 return 0;
842}
Len Brown4be44fc2005-08-05 00:44:28 -0400843#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845/* Assumes no unreadable holes inbetween */
Len Brown4be44fc2005-08-05 00:44:28 -0400846u8 acpi_os_readable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
Len Brown4be44fc2005-08-05 00:44:28 -0400848#if defined(__i386__) || defined(__x86_64__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 char tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400850 return !__get_user(tmp, (char __user *)ptr)
851 && !__get_user(tmp, (char __user *)ptr + len - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852#endif
853 return 1;
854}
855
856#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400857u8 acpi_os_writable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
859 /* could do dummy write (racy) or a kernel page table lookup.
860 The later may be difficult at early boot when kmap doesn't work yet. */
861 return 1;
862}
863#endif
864
Len Brown4be44fc2005-08-05 00:44:28 -0400865acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
Len Brown4be44fc2005-08-05 00:44:28 -0400867 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 case ACPI_SIGNAL_FATAL:
869 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
870 break;
871 case ACPI_SIGNAL_BREAKPOINT:
872 /*
873 * AML Breakpoint
874 * ACPI spec. says to treat it as a NOP unless
875 * you are debugging. So if/when we integrate
876 * AML debugger into the kernel debugger its
877 * hook will go here. But until then it is
878 * not useful to print anything on breakpoints.
879 */
880 break;
881 default:
882 break;
883 }
884
885 return AE_OK;
886}
Len Brown4be44fc2005-08-05 00:44:28 -0400887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888EXPORT_SYMBOL(acpi_os_signal);
889
Len Brown4be44fc2005-08-05 00:44:28 -0400890static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
892 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400893 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895 if (!str || !*str)
896 return 0;
897
898 for (; count-- && str && *str; str++) {
899 if (isalnum(*str) || *str == ' ' || *str == ':')
900 *p++ = *str;
901 else if (*str == '\'' || *str == '"')
902 continue;
903 else
904 break;
905 }
906 *p = 0;
907
908 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910}
911
912__setup("acpi_os_name=", acpi_os_name_setup);
913
914/*
915 * _OSI control
916 * empty string disables _OSI
917 * TBD additional string adds to _OSI
918 */
Len Brown4be44fc2005-08-05 00:44:28 -0400919static int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920{
921 if (str == NULL || *str == '\0') {
922 printk(KERN_INFO PREFIX "_OSI method disabled\n");
923 acpi_gbl_create_osi_method = FALSE;
Len Brown4be44fc2005-08-05 00:44:28 -0400924 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 /* TBD */
Len Brown4be44fc2005-08-05 00:44:28 -0400926 printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n",
927 str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 }
929
930 return 1;
931}
932
933__setup("acpi_osi=", acpi_osi_setup);
934
935/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -0400936static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937{
938 printk(KERN_INFO PREFIX "serialize enabled\n");
939
940 acpi_gbl_all_methods_serialized = TRUE;
941
942 return 1;
943}
944
945__setup("acpi_serialize", acpi_serialize_setup);
946
947/*
948 * Wake and Run-Time GPES are expected to be separate.
949 * We disable wake-GPEs at run-time to prevent spurious
950 * interrupts.
951 *
952 * However, if a system exists that shares Wake and
953 * Run-time events on the same GPE this flag is available
954 * to tell Linux to keep the wake-time GPEs enabled at run-time.
955 */
Len Brown4be44fc2005-08-05 00:44:28 -0400956static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957{
958 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
959
960 acpi_gbl_leave_wake_gpes_disabled = FALSE;
961
962 return 1;
963}
964
965__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
966
Adrian Bunk8713cbe2005-09-02 17:16:48 -0400967static int __init acpi_hotkey_setup(char *str)
Luming Yufb9802f2005-03-18 18:03:45 -0500968{
Luming Yu30e332f2005-08-12 00:31:00 -0400969 acpi_specific_hotkey_enabled = FALSE;
Luming Yufb9802f2005-03-18 18:03:45 -0500970 return 1;
971}
972
Luming Yu30e332f2005-08-12 00:31:00 -0400973__setup("acpi_generic_hotkey", acpi_hotkey_setup);
Luming Yufb9802f2005-03-18 18:03:45 -0500974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975/*
976 * max_cstate is defined in the base kernel so modules can
977 * change it w/o depending on the state of the processor module.
978 */
979unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981EXPORT_SYMBOL(max_cstate);
Robert Moore73459f72005-06-24 00:00:00 -0400982
983/*
984 * Acquire a spinlock.
985 *
986 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -0400987 */
988
Bob Moore967440e2006-06-23 17:04:00 -0400989acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -0400990{
Bob Mooreb8e4d892006-01-27 16:43:00 -0500991 acpi_cpu_flags flags;
Bob Moore967440e2006-06-23 17:04:00 -0400992 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -0400993 return flags;
994}
995
996/*
997 * Release a spinlock. See above.
998 */
999
Bob Moore967440e2006-06-23 17:04:00 -04001000void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001001{
Bob Moore967440e2006-06-23 17:04:00 -04001002 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001003}
1004
Robert Moore73459f72005-06-24 00:00:00 -04001005#ifndef ACPI_USE_LOCAL_CACHE
1006
1007/*******************************************************************************
1008 *
1009 * FUNCTION: acpi_os_create_cache
1010 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001011 * PARAMETERS: name - Ascii name for the cache
1012 * size - Size of each cached object
1013 * depth - Maximum depth of the cache (in objects) <ignored>
1014 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001015 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001016 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001017 *
1018 * DESCRIPTION: Create a cache object
1019 *
1020 ******************************************************************************/
1021
1022acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001023acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001024{
Len Brown4be44fc2005-08-05 00:44:28 -04001025 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001026 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001027 return AE_ERROR;
1028 else
1029 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001030}
1031
1032/*******************************************************************************
1033 *
1034 * FUNCTION: acpi_os_purge_cache
1035 *
1036 * PARAMETERS: Cache - Handle to cache object
1037 *
1038 * RETURN: Status
1039 *
1040 * DESCRIPTION: Free all objects within the requested cache.
1041 *
1042 ******************************************************************************/
1043
Len Brown4be44fc2005-08-05 00:44:28 -04001044acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001045{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001046 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001047 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001048}
1049
1050/*******************************************************************************
1051 *
1052 * FUNCTION: acpi_os_delete_cache
1053 *
1054 * PARAMETERS: Cache - Handle to cache object
1055 *
1056 * RETURN: Status
1057 *
1058 * DESCRIPTION: Free all objects within the requested cache and delete the
1059 * cache object.
1060 *
1061 ******************************************************************************/
1062
Len Brown4be44fc2005-08-05 00:44:28 -04001063acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001064{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001065 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001066 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001067}
1068
1069/*******************************************************************************
1070 *
1071 * FUNCTION: acpi_os_release_object
1072 *
1073 * PARAMETERS: Cache - Handle to cache object
1074 * Object - The object to be released
1075 *
1076 * RETURN: None
1077 *
1078 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1079 * the object is deleted.
1080 *
1081 ******************************************************************************/
1082
Len Brown4be44fc2005-08-05 00:44:28 -04001083acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001084{
Len Brown4be44fc2005-08-05 00:44:28 -04001085 kmem_cache_free(cache, object);
1086 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001087}
1088
Bob Mooreb229cf92006-04-21 17:15:00 -04001089/******************************************************************************
1090 *
1091 * FUNCTION: acpi_os_validate_interface
1092 *
1093 * PARAMETERS: interface - Requested interface to be validated
1094 *
1095 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1096 *
1097 * DESCRIPTION: Match an interface string to the interfaces supported by the
1098 * host. Strings originate from an AML call to the _OSI method.
1099 *
1100 *****************************************************************************/
1101
1102acpi_status
1103acpi_os_validate_interface (char *interface)
1104{
1105
1106 return AE_SUPPORT;
1107}
1108
1109
1110/******************************************************************************
1111 *
1112 * FUNCTION: acpi_os_validate_address
1113 *
1114 * PARAMETERS: space_id - ACPI space ID
1115 * address - Physical address
1116 * length - Address length
1117 *
1118 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1119 * should return AE_AML_ILLEGAL_ADDRESS.
1120 *
1121 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1122 * the addresses accessed by AML operation regions.
1123 *
1124 *****************************************************************************/
1125
1126acpi_status
1127acpi_os_validate_address (
1128 u8 space_id,
1129 acpi_physical_address address,
1130 acpi_size length)
1131{
1132
1133 return AE_OK;
1134}
1135
1136
Robert Moore73459f72005-06-24 00:00:00 -04001137#endif