blob: 02b30ae6a68edf4b8e433e6c0f3f19674d2e6159 [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;
David Howells65f27f32006-11-22 14:55:48 +000053 struct work_struct work;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054};
55
56#ifdef CONFIG_ACPI_CUSTOM_DSDT
57#include CONFIG_ACPI_CUSTOM_DSDT_FILE
58#endif
59
60#ifdef ENABLE_DEBUGGER
61#include <linux/kdb.h>
62
63/* stuff for debugger support */
64int acpi_in_debugger;
65EXPORT_SYMBOL(acpi_in_debugger);
66
67extern char line_buf[80];
Len Brown4be44fc2005-08-05 00:44:28 -040068#endif /*ENABLE_DEBUGGER */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Luming Yu30e332f2005-08-12 00:31:00 -040070int acpi_specific_hotkey_enabled = TRUE;
Luming Yufb9802f2005-03-18 18:03:45 -050071EXPORT_SYMBOL(acpi_specific_hotkey_enabled);
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static unsigned int acpi_irq_irq;
74static acpi_osd_handler acpi_irq_handler;
75static void *acpi_irq_context;
76static struct workqueue_struct *kacpid_wq;
77
Len Brown4be44fc2005-08-05 00:44:28 -040078acpi_status acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
80 return AE_OK;
81}
82
Len Brown4be44fc2005-08-05 00:44:28 -040083acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
85 /*
86 * Initialize PCI configuration space access, as we'll need to access
87 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
88 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 if (!raw_pci_ops) {
Len Brown4be44fc2005-08-05 00:44:28 -040090 printk(KERN_ERR PREFIX
91 "Access to PCI configuration space unavailable\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 return AE_NULL_ENTRY;
93 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 kacpid_wq = create_singlethread_workqueue("kacpid");
95 BUG_ON(!kacpid_wq);
Linus Torvaldsb976fe12006-11-17 19:31:09 -080096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 return AE_OK;
98}
99
Len Brown4be44fc2005-08-05 00:44:28 -0400100acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
102 if (acpi_irq_handler) {
103 acpi_os_remove_interrupt_handler(acpi_irq_irq,
104 acpi_irq_handler);
105 }
106
107 destroy_workqueue(kacpid_wq);
108
109 return AE_OK;
110}
111
Len Brown4be44fc2005-08-05 00:44:28 -0400112void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
114 va_list args;
115 va_start(args, fmt);
116 acpi_os_vprintf(fmt, args);
117 va_end(args);
118}
Len Brown4be44fc2005-08-05 00:44:28 -0400119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120EXPORT_SYMBOL(acpi_os_printf);
121
Len Brown4be44fc2005-08-05 00:44:28 -0400122void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
124 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 vsprintf(buffer, fmt, args);
127
128#ifdef ENABLE_DEBUGGER
129 if (acpi_in_debugger) {
130 kdb_printf("%s", buffer);
131 } else {
132 printk("%s", buffer);
133 }
134#else
135 printk("%s", buffer);
136#endif
137}
138
Len Brown4be44fc2005-08-05 00:44:28 -0400139acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
141 if (efi_enabled) {
142 addr->pointer_type = ACPI_PHYSICAL_POINTER;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800143 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
144 addr->pointer.physical = efi.acpi20;
145 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
146 addr->pointer.physical = 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");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 return AE_NOT_FOUND;
151 }
152 } else {
153 if (ACPI_FAILURE(acpi_find_root_pointer(flags, addr))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400154 printk(KERN_ERR PREFIX
155 "System description tables not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 return AE_NOT_FOUND;
157 }
158 }
159
160 return AE_OK;
161}
162
163acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400164acpi_os_map_memory(acpi_physical_address phys, acpi_size size,
165 void __iomem ** virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800167 if (phys > ULONG_MAX) {
168 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
169 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 }
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800171 /*
172 * ioremap checks to ensure this is in reserved space
173 */
174 *virt = ioremap((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 if (!*virt)
177 return AE_NO_MEMORY;
178
179 return AE_OK;
180}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800181EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Len Brown4be44fc2005-08-05 00:44:28 -0400183void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
185 iounmap(virt);
186}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800187EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189#ifdef ACPI_FUTURE_USAGE
190acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400191acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Len Brown4be44fc2005-08-05 00:44:28 -0400193 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 return AE_BAD_PARAMETER;
195
196 *phys = virt_to_phys(virt);
197
198 return AE_OK;
199}
200#endif
201
202#define ACPI_MAX_OVERRIDE_LEN 100
203
204static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
205
206acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400207acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
208 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
210 if (!init_val || !new_val)
211 return AE_BAD_PARAMETER;
212
213 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400214 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400216 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 *new_val = acpi_os_name;
218 }
219
220 return AE_OK;
221}
222
223acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400224acpi_os_table_override(struct acpi_table_header * existing_table,
225 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
227 if (!existing_table || !new_table)
228 return AE_BAD_PARAMETER;
229
230#ifdef CONFIG_ACPI_CUSTOM_DSDT
231 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400232 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 else
234 *new_table = NULL;
235#else
236 *new_table = NULL;
237#endif
238 return AE_OK;
239}
240
David Howells7d12e782006-10-05 14:55:46 +0100241static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Len Brown4be44fc2005-08-05 00:44:28 -0400243 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
246acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400247acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
248 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
250 unsigned int irq;
251
252 /*
253 * Ignore the GSI from the core, and use the value in our copy of the
254 * FADT. It may not be the same if an interrupt source override exists
255 * for the SCI.
256 */
257 gsi = acpi_fadt.sci_int;
258 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
259 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
260 gsi);
261 return AE_OK;
262 }
263
264 acpi_irq_handler = handler;
265 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700266 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
268 return AE_NOT_ACQUIRED;
269 }
270 acpi_irq_irq = irq;
271
272 return AE_OK;
273}
274
Len Brown4be44fc2005-08-05 00:44:28 -0400275acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
277 if (irq) {
278 free_irq(irq, acpi_irq);
279 acpi_irq_handler = NULL;
280 acpi_irq_irq = 0;
281 }
282
283 return AE_OK;
284}
285
286/*
287 * Running in interpreter thread context, safe to sleep
288 */
289
Len Brown4be44fc2005-08-05 00:44:28 -0400290void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800292 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293}
Len Brown4be44fc2005-08-05 00:44:28 -0400294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295EXPORT_SYMBOL(acpi_os_sleep);
296
Len Brown4be44fc2005-08-05 00:44:28 -0400297void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
299 while (us) {
300 u32 delay = 1000;
301
302 if (delay > us)
303 delay = us;
304 udelay(delay);
305 touch_nmi_watchdog();
306 us -= delay;
307 }
308}
Len Brown4be44fc2005-08-05 00:44:28 -0400309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310EXPORT_SYMBOL(acpi_os_stall);
311
312/*
313 * Support ACPI 3.0 AML Timer operand
314 * Returns 64-bit free-running, monotonically increasing timer
315 * with 100ns granularity
316 */
Len Brown4be44fc2005-08-05 00:44:28 -0400317u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
319 static u64 t;
320
321#ifdef CONFIG_HPET
322 /* TBD: use HPET if available */
323#endif
324
325#ifdef CONFIG_X86_PM_TIMER
326 /* TBD: default to PM timer if HPET was not available */
327#endif
328 if (!t)
329 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
330
331 return ++t;
332}
333
Len Brown4be44fc2005-08-05 00:44:28 -0400334acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
336 u32 dummy;
337
338 if (!value)
339 value = &dummy;
340
Len Brown4be44fc2005-08-05 00:44:28 -0400341 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400343 *(u8 *) value = inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 break;
345 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400346 *(u16 *) value = inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 break;
348 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400349 *(u32 *) value = inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 break;
351 default:
352 BUG();
353 }
354
355 return AE_OK;
356}
Len Brown4be44fc2005-08-05 00:44:28 -0400357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358EXPORT_SYMBOL(acpi_os_read_port);
359
Len Brown4be44fc2005-08-05 00:44:28 -0400360acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Len Brown4be44fc2005-08-05 00:44:28 -0400362 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 case 8:
364 outb(value, port);
365 break;
366 case 16:
367 outw(value, port);
368 break;
369 case 32:
370 outl(value, port);
371 break;
372 default:
373 BUG();
374 }
375
376 return AE_OK;
377}
Len Brown4be44fc2005-08-05 00:44:28 -0400378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379EXPORT_SYMBOL(acpi_os_write_port);
380
381acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400382acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
Len Brown4be44fc2005-08-05 00:44:28 -0400384 u32 dummy;
385 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800387 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 if (!value)
389 value = &dummy;
390
391 switch (width) {
392 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400393 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 break;
395 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400396 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 break;
398 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400399 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 break;
401 default:
402 BUG();
403 }
404
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800405 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407 return AE_OK;
408}
409
410acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400411acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
Len Brown4be44fc2005-08-05 00:44:28 -0400413 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800415 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 switch (width) {
418 case 8:
419 writeb(value, virt_addr);
420 break;
421 case 16:
422 writew(value, virt_addr);
423 break;
424 case 32:
425 writel(value, virt_addr);
426 break;
427 default:
428 BUG();
429 }
430
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800431 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 return AE_OK;
434}
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400437acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
438 void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
440 int result, size;
441
442 if (!value)
443 return AE_BAD_PARAMETER;
444
445 switch (width) {
446 case 8:
447 size = 1;
448 break;
449 case 16:
450 size = 2;
451 break;
452 case 32:
453 size = 4;
454 break;
455 default:
456 return AE_ERROR;
457 }
458
459 BUG_ON(!raw_pci_ops);
460
461 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400462 PCI_DEVFN(pci_id->device, pci_id->function),
463 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465 return (result ? AE_ERROR : AE_OK);
466}
Len Brown4be44fc2005-08-05 00:44:28 -0400467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468EXPORT_SYMBOL(acpi_os_read_pci_configuration);
469
470acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400471acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
472 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
474 int result, size;
475
476 switch (width) {
477 case 8:
478 size = 1;
479 break;
480 case 16:
481 size = 2;
482 break;
483 case 32:
484 size = 4;
485 break;
486 default:
487 return AE_ERROR;
488 }
489
490 BUG_ON(!raw_pci_ops);
491
492 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400493 PCI_DEVFN(pci_id->device, pci_id->function),
494 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 return (result ? AE_ERROR : AE_OK);
497}
498
499/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400500static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
501 acpi_handle chandle, /* current node */
502 struct acpi_pci_id **id,
503 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Len Brown4be44fc2005-08-05 00:44:28 -0400505 acpi_handle handle;
506 struct acpi_pci_id *pci_id = *id;
507 acpi_status status;
508 unsigned long temp;
509 acpi_object_type type;
510 u8 tu8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 acpi_get_parent(chandle, &handle);
513 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400514 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
515 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400518 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 return;
520
Len Brown4be44fc2005-08-05 00:44:28 -0400521 status =
522 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
523 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 if (ACPI_SUCCESS(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400525 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
526 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 if (*is_bridge)
529 pci_id->bus = *bus_number;
530
531 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400532 status =
533 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
534 8);
535 if (ACPI_SUCCESS(status)
536 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
537 status =
538 acpi_os_read_pci_configuration(pci_id, 0x18,
539 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 if (!ACPI_SUCCESS(status)) {
541 /* Certainly broken... FIX ME */
542 return;
543 }
544 *is_bridge = 1;
545 pci_id->bus = tu8;
Len Brown4be44fc2005-08-05 00:44:28 -0400546 status =
547 acpi_os_read_pci_configuration(pci_id, 0x19,
548 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 if (ACPI_SUCCESS(status)) {
550 *bus_number = tu8;
551 }
552 } else
553 *is_bridge = 0;
554 }
555 }
556}
557
Len Brown4be44fc2005-08-05 00:44:28 -0400558void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
559 acpi_handle chandle, /* current node */
560 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
562 int is_bridge = 1;
563 u8 bus_number = (*id)->bus;
564
565 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
566}
567
David Howells65f27f32006-11-22 14:55:48 +0000568static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
David Howells65f27f32006-11-22 14:55:48 +0000570 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (!dpc) {
Len Brown64684632006-06-26 23:41:38 -0400572 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400573 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 }
575
576 dpc->function(dpc->context);
577
578 kfree(dpc);
579
Patrick Mocheld550d982006-06-27 00:41:40 -0400580 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581}
582
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400583/*******************************************************************************
584 *
585 * FUNCTION: acpi_os_execute
586 *
587 * PARAMETERS: Type - Type of the callback
588 * Function - Function to be executed
589 * Context - Function parameters
590 *
591 * RETURN: Status
592 *
593 * DESCRIPTION: Depending on type, either queues function for deferred execution or
594 * immediately executes function on a separate thread.
595 *
596 ******************************************************************************/
597
598acpi_status acpi_os_execute(acpi_execute_type type,
Len Brown4be44fc2005-08-05 00:44:28 -0400599 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Len Brown4be44fc2005-08-05 00:44:28 -0400601 acpi_status status = AE_OK;
602 struct acpi_os_dpc *dpc;
Len Brown72945b22006-07-12 22:46:42 -0400603
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800604 ACPI_FUNCTION_TRACE("os_queue_for_execution");
605
Len Brown72945b22006-07-12 22:46:42 -0400606 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
607 "Scheduling function [%p(%p)] for deferred execution.\n",
608 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 if (!function)
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800611 return_ACPI_STATUS(AE_BAD_PARAMETER);
Len Brown72945b22006-07-12 22:46:42 -0400612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 /*
614 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000615 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 * way that allows us to also free its memory inside the callee.
617 * Because we may want to schedule several tasks with different
618 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000619 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 */
Len Brown72945b22006-07-12 22:46:42 -0400621
David Howells65f27f32006-11-22 14:55:48 +0000622 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 if (!dpc)
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800624 return_ACPI_STATUS(AE_NO_MEMORY);
625
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 dpc->function = function;
627 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800628
David Howells65f27f32006-11-22 14:55:48 +0000629 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
630 if (!queue_work(kacpid_wq, &dpc->work)) {
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800631 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
632 "Call to queue_work() failed.\n"));
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -0400633 kfree(dpc);
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800634 status = AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 }
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800636
637 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638}
Len Brown4be44fc2005-08-05 00:44:28 -0400639
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400640EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Len Brown4be44fc2005-08-05 00:44:28 -0400642void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
644 flush_workqueue(kacpid_wq);
645}
Len Brown4be44fc2005-08-05 00:44:28 -0400646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647EXPORT_SYMBOL(acpi_os_wait_events_complete);
648
649/*
650 * Allocate the memory for a spinlock and initialize it.
651 */
Bob Moore967440e2006-06-23 17:04:00 -0400652acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
Bob Moore967440e2006-06-23 17:04:00 -0400654 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Patrick Mocheld550d982006-06-27 00:41:40 -0400656 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659/*
660 * Deallocate the memory for a spinlock.
661 */
Bob Moore967440e2006-06-23 17:04:00 -0400662void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
Patrick Mocheld550d982006-06-27 00:41:40 -0400664 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665}
666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400668acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669{
Len Brown4be44fc2005-08-05 00:44:28 -0400670 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673 sem = acpi_os_allocate(sizeof(struct semaphore));
674 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400675 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 memset(sem, 0, sizeof(struct semaphore));
677
678 sema_init(sem, initial_units);
679
Len Brown4be44fc2005-08-05 00:44:28 -0400680 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Len Brown4be44fc2005-08-05 00:44:28 -0400682 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
683 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Patrick Mocheld550d982006-06-27 00:41:40 -0400685 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Len Brown4be44fc2005-08-05 00:44:28 -0400688EXPORT_SYMBOL(acpi_os_create_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
690/*
691 * TODO: A better way to delete semaphores? Linux doesn't have a
692 * 'delete_semaphore()' function -- may result in an invalid
693 * pointer dereference for non-synchronized consumers. Should
694 * we at least check for blocked threads and signal/cancel them?
695 */
696
Len Brown4be44fc2005-08-05 00:44:28 -0400697acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698{
Len Brown4be44fc2005-08-05 00:44:28 -0400699 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
702 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400703 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Len Brown4be44fc2005-08-05 00:44:28 -0400705 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Len Brown02438d82006-06-30 03:19:10 -0400707 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400708 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Patrick Mocheld550d982006-06-27 00:41:40 -0400710 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Len Brown4be44fc2005-08-05 00:44:28 -0400713EXPORT_SYMBOL(acpi_os_delete_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715/*
716 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
717 * improvise. The process is to sleep for one scheduler quantum
718 * until the semaphore becomes available. Downside is that this
719 * may result in starvation for timeout-based waits when there's
720 * lots of semaphore activity.
721 *
722 * TODO: Support for units > 1?
723 */
Len Brown4be44fc2005-08-05 00:44:28 -0400724acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
Len Brown4be44fc2005-08-05 00:44:28 -0400726 acpi_status status = AE_OK;
727 struct semaphore *sem = (struct semaphore *)handle;
728 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400732 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400735 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Len Brown4be44fc2005-08-05 00:44:28 -0400737 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
738 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Len Brownd68909f2006-08-16 19:16:58 -0400740 /*
741 * This can be called during resume with interrupts off.
742 * Like boot-time, we should be single threaded and will
743 * always get the lock if we try -- timeout or not.
744 * If this doesn't succeed, then we will oops courtesy of
745 * might_sleep() in down().
746 */
747 if (!down_trylock(sem))
748 return AE_OK;
749
Len Brown4be44fc2005-08-05 00:44:28 -0400750 switch (timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 /*
752 * No Wait:
753 * --------
754 * A zero timeout value indicates that we shouldn't wait - just
755 * acquire the semaphore if available otherwise return AE_TIME
756 * (a.k.a. 'would block').
757 */
Len Brown4be44fc2005-08-05 00:44:28 -0400758 case 0:
759 if (down_trylock(sem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 status = AE_TIME;
761 break;
762
763 /*
764 * Wait Indefinitely:
765 * ------------------
766 */
Len Brown4be44fc2005-08-05 00:44:28 -0400767 case ACPI_WAIT_FOREVER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 down(sem);
769 break;
770
771 /*
772 * Wait w/ Timeout:
773 * ----------------
774 */
Len Brown4be44fc2005-08-05 00:44:28 -0400775 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 // TODO: A better timeout algorithm?
777 {
778 int i = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400779 static const int quantum_ms = 1000 / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 ret = down_trylock(sem);
Yu Lumingdacd9b82005-12-31 01:45:00 -0500782 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800783 schedule_timeout_interruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 ret = down_trylock(sem);
785 }
Len Brown4be44fc2005-08-05 00:44:28 -0400786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 if (ret != 0)
788 status = AE_TIME;
789 }
790 break;
791 }
792
793 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400794 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400795 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400796 handle, units, timeout,
797 acpi_format_exception(status)));
798 } else {
799 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400800 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400801 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 }
803
Patrick Mocheld550d982006-06-27 00:41:40 -0400804 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Len Brown4be44fc2005-08-05 00:44:28 -0400807EXPORT_SYMBOL(acpi_os_wait_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809/*
810 * TODO: Support for units > 1?
811 */
Len Brown4be44fc2005-08-05 00:44:28 -0400812acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Len Brown4be44fc2005-08-05 00:44:28 -0400814 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
817 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400818 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400821 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Len Brown4be44fc2005-08-05 00:44:28 -0400823 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
824 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 up(sem);
827
Patrick Mocheld550d982006-06-27 00:41:40 -0400828 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829}
Len Brown4be44fc2005-08-05 00:44:28 -0400830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831EXPORT_SYMBOL(acpi_os_signal_semaphore);
832
833#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400834u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835{
836
837#ifdef ENABLE_DEBUGGER
838 if (acpi_in_debugger) {
839 u32 chars;
840
841 kdb_read(buffer, sizeof(line_buf));
842
843 /* remove the CR kdb includes */
844 chars = strlen(buffer) - 1;
845 buffer[chars] = '\0';
846 }
847#endif
848
849 return 0;
850}
Len Brown4be44fc2005-08-05 00:44:28 -0400851#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853/* Assumes no unreadable holes inbetween */
Len Brown4be44fc2005-08-05 00:44:28 -0400854u8 acpi_os_readable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
Len Brown4be44fc2005-08-05 00:44:28 -0400856#if defined(__i386__) || defined(__x86_64__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 char tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400858 return !__get_user(tmp, (char __user *)ptr)
859 && !__get_user(tmp, (char __user *)ptr + len - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860#endif
861 return 1;
862}
863
864#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400865u8 acpi_os_writable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
867 /* could do dummy write (racy) or a kernel page table lookup.
868 The later may be difficult at early boot when kmap doesn't work yet. */
869 return 1;
870}
871#endif
872
Len Brown4be44fc2005-08-05 00:44:28 -0400873acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
Len Brown4be44fc2005-08-05 00:44:28 -0400875 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 case ACPI_SIGNAL_FATAL:
877 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
878 break;
879 case ACPI_SIGNAL_BREAKPOINT:
880 /*
881 * AML Breakpoint
882 * ACPI spec. says to treat it as a NOP unless
883 * you are debugging. So if/when we integrate
884 * AML debugger into the kernel debugger its
885 * hook will go here. But until then it is
886 * not useful to print anything on breakpoints.
887 */
888 break;
889 default:
890 break;
891 }
892
893 return AE_OK;
894}
Len Brown4be44fc2005-08-05 00:44:28 -0400895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896EXPORT_SYMBOL(acpi_os_signal);
897
Len Brown4be44fc2005-08-05 00:44:28 -0400898static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
900 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400901 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903 if (!str || !*str)
904 return 0;
905
906 for (; count-- && str && *str; str++) {
907 if (isalnum(*str) || *str == ' ' || *str == ':')
908 *p++ = *str;
909 else if (*str == '\'' || *str == '"')
910 continue;
911 else
912 break;
913 }
914 *p = 0;
915
916 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400917
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918}
919
920__setup("acpi_os_name=", acpi_os_name_setup);
921
922/*
923 * _OSI control
924 * empty string disables _OSI
925 * TBD additional string adds to _OSI
926 */
Len Brown4be44fc2005-08-05 00:44:28 -0400927static int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928{
929 if (str == NULL || *str == '\0') {
930 printk(KERN_INFO PREFIX "_OSI method disabled\n");
931 acpi_gbl_create_osi_method = FALSE;
Len Brown4be44fc2005-08-05 00:44:28 -0400932 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 /* TBD */
Len Brown4be44fc2005-08-05 00:44:28 -0400934 printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n",
935 str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 }
937
938 return 1;
939}
940
941__setup("acpi_osi=", acpi_osi_setup);
942
943/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -0400944static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945{
946 printk(KERN_INFO PREFIX "serialize enabled\n");
947
948 acpi_gbl_all_methods_serialized = TRUE;
949
950 return 1;
951}
952
953__setup("acpi_serialize", acpi_serialize_setup);
954
955/*
956 * Wake and Run-Time GPES are expected to be separate.
957 * We disable wake-GPEs at run-time to prevent spurious
958 * interrupts.
959 *
960 * However, if a system exists that shares Wake and
961 * Run-time events on the same GPE this flag is available
962 * to tell Linux to keep the wake-time GPEs enabled at run-time.
963 */
Len Brown4be44fc2005-08-05 00:44:28 -0400964static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965{
966 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
967
968 acpi_gbl_leave_wake_gpes_disabled = FALSE;
969
970 return 1;
971}
972
973__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
974
Adrian Bunk8713cbe2005-09-02 17:16:48 -0400975static int __init acpi_hotkey_setup(char *str)
Luming Yufb9802f2005-03-18 18:03:45 -0500976{
Luming Yu30e332f2005-08-12 00:31:00 -0400977 acpi_specific_hotkey_enabled = FALSE;
Luming Yufb9802f2005-03-18 18:03:45 -0500978 return 1;
979}
980
Luming Yu30e332f2005-08-12 00:31:00 -0400981__setup("acpi_generic_hotkey", acpi_hotkey_setup);
Luming Yufb9802f2005-03-18 18:03:45 -0500982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983/*
984 * max_cstate is defined in the base kernel so modules can
985 * change it w/o depending on the state of the processor module.
986 */
987unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
988
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989EXPORT_SYMBOL(max_cstate);
Robert Moore73459f72005-06-24 00:00:00 -0400990
991/*
992 * Acquire a spinlock.
993 *
994 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -0400995 */
996
Bob Moore967440e2006-06-23 17:04:00 -0400997acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -0400998{
Bob Mooreb8e4d892006-01-27 16:43:00 -0500999 acpi_cpu_flags flags;
Bob Moore967440e2006-06-23 17:04:00 -04001000 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001001 return flags;
1002}
1003
1004/*
1005 * Release a spinlock. See above.
1006 */
1007
Bob Moore967440e2006-06-23 17:04:00 -04001008void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001009{
Bob Moore967440e2006-06-23 17:04:00 -04001010 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001011}
1012
Robert Moore73459f72005-06-24 00:00:00 -04001013#ifndef ACPI_USE_LOCAL_CACHE
1014
1015/*******************************************************************************
1016 *
1017 * FUNCTION: acpi_os_create_cache
1018 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001019 * PARAMETERS: name - Ascii name for the cache
1020 * size - Size of each cached object
1021 * depth - Maximum depth of the cache (in objects) <ignored>
1022 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001023 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001024 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001025 *
1026 * DESCRIPTION: Create a cache object
1027 *
1028 ******************************************************************************/
1029
1030acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001031acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001032{
Len Brown4be44fc2005-08-05 00:44:28 -04001033 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
Bob Mooreb229cf92006-04-21 17:15:00 -04001034 if (cache == NULL)
1035 return AE_ERROR;
1036 else
1037 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001038}
1039
1040/*******************************************************************************
1041 *
1042 * FUNCTION: acpi_os_purge_cache
1043 *
1044 * PARAMETERS: Cache - Handle to cache object
1045 *
1046 * RETURN: Status
1047 *
1048 * DESCRIPTION: Free all objects within the requested cache.
1049 *
1050 ******************************************************************************/
1051
Len Brown4be44fc2005-08-05 00:44:28 -04001052acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001053{
Len Brown4be44fc2005-08-05 00:44:28 -04001054 (void)kmem_cache_shrink(cache);
1055 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001056}
1057
1058/*******************************************************************************
1059 *
1060 * FUNCTION: acpi_os_delete_cache
1061 *
1062 * PARAMETERS: Cache - Handle to cache object
1063 *
1064 * RETURN: Status
1065 *
1066 * DESCRIPTION: Free all objects within the requested cache and delete the
1067 * cache object.
1068 *
1069 ******************************************************************************/
1070
Len Brown4be44fc2005-08-05 00:44:28 -04001071acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001072{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001073 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001074 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001075}
1076
1077/*******************************************************************************
1078 *
1079 * FUNCTION: acpi_os_release_object
1080 *
1081 * PARAMETERS: Cache - Handle to cache object
1082 * Object - The object to be released
1083 *
1084 * RETURN: None
1085 *
1086 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1087 * the object is deleted.
1088 *
1089 ******************************************************************************/
1090
Len Brown4be44fc2005-08-05 00:44:28 -04001091acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001092{
Len Brown4be44fc2005-08-05 00:44:28 -04001093 kmem_cache_free(cache, object);
1094 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001095}
1096
Bob Mooreb229cf92006-04-21 17:15:00 -04001097/******************************************************************************
1098 *
1099 * FUNCTION: acpi_os_validate_interface
1100 *
1101 * PARAMETERS: interface - Requested interface to be validated
1102 *
1103 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1104 *
1105 * DESCRIPTION: Match an interface string to the interfaces supported by the
1106 * host. Strings originate from an AML call to the _OSI method.
1107 *
1108 *****************************************************************************/
1109
1110acpi_status
1111acpi_os_validate_interface (char *interface)
1112{
1113
1114 return AE_SUPPORT;
1115}
1116
1117
1118/******************************************************************************
1119 *
1120 * FUNCTION: acpi_os_validate_address
1121 *
1122 * PARAMETERS: space_id - ACPI space ID
1123 * address - Physical address
1124 * length - Address length
1125 *
1126 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1127 * should return AE_AML_ILLEGAL_ADDRESS.
1128 *
1129 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1130 * the addresses accessed by AML operation regions.
1131 *
1132 *****************************************************************************/
1133
1134acpi_status
1135acpi_os_validate_address (
1136 u8 space_id,
1137 acpi_physical_address address,
1138 acpi_size length)
1139{
1140
1141 return AE_OK;
1142}
1143
1144
Robert Moore73459f72005-06-24 00:00:00 -04001145#endif