blob: e10679ce1e0eb090ccc3e3e896f129ce931d5108 [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;
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -040076static struct workqueue_struct *kacpi_notify_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
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");
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -040095 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 BUG_ON(!kacpid_wq);
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -040097 BUG_ON(!kacpi_notify_wq);
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);
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -0400109 destroy_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 return AE_OK;
112}
113
Len Brown4be44fc2005-08-05 00:44:28 -0400114void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 va_list args;
117 va_start(args, fmt);
118 acpi_os_vprintf(fmt, args);
119 va_end(args);
120}
Len Brown4be44fc2005-08-05 00:44:28 -0400121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122EXPORT_SYMBOL(acpi_os_printf);
123
Len Brown4be44fc2005-08-05 00:44:28 -0400124void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
126 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 vsprintf(buffer, fmt, args);
129
130#ifdef ENABLE_DEBUGGER
131 if (acpi_in_debugger) {
132 kdb_printf("%s", buffer);
133 } else {
134 printk("%s", buffer);
135 }
136#else
137 printk("%s", buffer);
138#endif
139}
140
Len Brown4be44fc2005-08-05 00:44:28 -0400141acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
143 if (efi_enabled) {
144 addr->pointer_type = ACPI_PHYSICAL_POINTER;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800145 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
146 addr->pointer.physical = efi.acpi20;
147 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
148 addr->pointer.physical = efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400150 printk(KERN_ERR PREFIX
151 "System description tables not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 return AE_NOT_FOUND;
153 }
154 } else {
155 if (ACPI_FAILURE(acpi_find_root_pointer(flags, addr))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400156 printk(KERN_ERR PREFIX
157 "System description tables not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return AE_NOT_FOUND;
159 }
160 }
161
162 return AE_OK;
163}
164
165acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400166acpi_os_map_memory(acpi_physical_address phys, acpi_size size,
167 void __iomem ** virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800169 if (phys > ULONG_MAX) {
170 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
171 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800173 /*
174 * ioremap checks to ensure this is in reserved space
175 */
176 *virt = ioremap((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 if (!*virt)
179 return AE_NO_MEMORY;
180
181 return AE_OK;
182}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800183EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Len Brown4be44fc2005-08-05 00:44:28 -0400185void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
187 iounmap(virt);
188}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800189EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191#ifdef ACPI_FUTURE_USAGE
192acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400193acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Len Brown4be44fc2005-08-05 00:44:28 -0400195 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 return AE_BAD_PARAMETER;
197
198 *phys = virt_to_phys(virt);
199
200 return AE_OK;
201}
202#endif
203
204#define ACPI_MAX_OVERRIDE_LEN 100
205
206static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
207
208acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400209acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
210 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
212 if (!init_val || !new_val)
213 return AE_BAD_PARAMETER;
214
215 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400216 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400218 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 *new_val = acpi_os_name;
220 }
221
222 return AE_OK;
223}
224
225acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400226acpi_os_table_override(struct acpi_table_header * existing_table,
227 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
229 if (!existing_table || !new_table)
230 return AE_BAD_PARAMETER;
231
232#ifdef CONFIG_ACPI_CUSTOM_DSDT
233 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400234 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 else
236 *new_table = NULL;
237#else
238 *new_table = NULL;
239#endif
240 return AE_OK;
241}
242
David Howells7d12e782006-10-05 14:55:46 +0100243static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Len Brown4be44fc2005-08-05 00:44:28 -0400245 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246}
247
248acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400249acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
250 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
252 unsigned int irq;
253
254 /*
255 * Ignore the GSI from the core, and use the value in our copy of the
256 * FADT. It may not be the same if an interrupt source override exists
257 * for the SCI.
258 */
259 gsi = acpi_fadt.sci_int;
260 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
261 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
262 gsi);
263 return AE_OK;
264 }
265
266 acpi_irq_handler = handler;
267 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700268 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
270 return AE_NOT_ACQUIRED;
271 }
272 acpi_irq_irq = irq;
273
274 return AE_OK;
275}
276
Len Brown4be44fc2005-08-05 00:44:28 -0400277acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
279 if (irq) {
280 free_irq(irq, acpi_irq);
281 acpi_irq_handler = NULL;
282 acpi_irq_irq = 0;
283 }
284
285 return AE_OK;
286}
287
288/*
289 * Running in interpreter thread context, safe to sleep
290 */
291
Len Brown4be44fc2005-08-05 00:44:28 -0400292void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800294 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
Len Brown4be44fc2005-08-05 00:44:28 -0400296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297EXPORT_SYMBOL(acpi_os_sleep);
298
Len Brown4be44fc2005-08-05 00:44:28 -0400299void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
301 while (us) {
302 u32 delay = 1000;
303
304 if (delay > us)
305 delay = us;
306 udelay(delay);
307 touch_nmi_watchdog();
308 us -= delay;
309 }
310}
Len Brown4be44fc2005-08-05 00:44:28 -0400311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312EXPORT_SYMBOL(acpi_os_stall);
313
314/*
315 * Support ACPI 3.0 AML Timer operand
316 * Returns 64-bit free-running, monotonically increasing timer
317 * with 100ns granularity
318 */
Len Brown4be44fc2005-08-05 00:44:28 -0400319u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
321 static u64 t;
322
323#ifdef CONFIG_HPET
324 /* TBD: use HPET if available */
325#endif
326
327#ifdef CONFIG_X86_PM_TIMER
328 /* TBD: default to PM timer if HPET was not available */
329#endif
330 if (!t)
331 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
332
333 return ++t;
334}
335
Len Brown4be44fc2005-08-05 00:44:28 -0400336acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
338 u32 dummy;
339
340 if (!value)
341 value = &dummy;
342
Len Brown4be44fc2005-08-05 00:44:28 -0400343 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400345 *(u8 *) value = inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 break;
347 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400348 *(u16 *) value = inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 break;
350 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400351 *(u32 *) value = inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 break;
353 default:
354 BUG();
355 }
356
357 return AE_OK;
358}
Len Brown4be44fc2005-08-05 00:44:28 -0400359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360EXPORT_SYMBOL(acpi_os_read_port);
361
Len Brown4be44fc2005-08-05 00:44:28 -0400362acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Len Brown4be44fc2005-08-05 00:44:28 -0400364 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 case 8:
366 outb(value, port);
367 break;
368 case 16:
369 outw(value, port);
370 break;
371 case 32:
372 outl(value, port);
373 break;
374 default:
375 BUG();
376 }
377
378 return AE_OK;
379}
Len Brown4be44fc2005-08-05 00:44:28 -0400380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381EXPORT_SYMBOL(acpi_os_write_port);
382
383acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400384acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
Len Brown4be44fc2005-08-05 00:44:28 -0400386 u32 dummy;
387 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800389 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 if (!value)
391 value = &dummy;
392
393 switch (width) {
394 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400395 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 break;
397 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400398 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 break;
400 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400401 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 break;
403 default:
404 BUG();
405 }
406
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800407 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 return AE_OK;
410}
411
412acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400413acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Len Brown4be44fc2005-08-05 00:44:28 -0400415 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800417 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419 switch (width) {
420 case 8:
421 writeb(value, virt_addr);
422 break;
423 case 16:
424 writew(value, virt_addr);
425 break;
426 case 32:
427 writel(value, virt_addr);
428 break;
429 default:
430 BUG();
431 }
432
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800433 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 return AE_OK;
436}
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400439acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
440 void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
442 int result, size;
443
444 if (!value)
445 return AE_BAD_PARAMETER;
446
447 switch (width) {
448 case 8:
449 size = 1;
450 break;
451 case 16:
452 size = 2;
453 break;
454 case 32:
455 size = 4;
456 break;
457 default:
458 return AE_ERROR;
459 }
460
461 BUG_ON(!raw_pci_ops);
462
463 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400464 PCI_DEVFN(pci_id->device, pci_id->function),
465 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467 return (result ? AE_ERROR : AE_OK);
468}
Len Brown4be44fc2005-08-05 00:44:28 -0400469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470EXPORT_SYMBOL(acpi_os_read_pci_configuration);
471
472acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400473acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
474 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
476 int result, size;
477
478 switch (width) {
479 case 8:
480 size = 1;
481 break;
482 case 16:
483 size = 2;
484 break;
485 case 32:
486 size = 4;
487 break;
488 default:
489 return AE_ERROR;
490 }
491
492 BUG_ON(!raw_pci_ops);
493
494 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400495 PCI_DEVFN(pci_id->device, pci_id->function),
496 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 return (result ? AE_ERROR : AE_OK);
499}
500
501/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400502static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
503 acpi_handle chandle, /* current node */
504 struct acpi_pci_id **id,
505 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
Len Brown4be44fc2005-08-05 00:44:28 -0400507 acpi_handle handle;
508 struct acpi_pci_id *pci_id = *id;
509 acpi_status status;
510 unsigned long temp;
511 acpi_object_type type;
512 u8 tu8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514 acpi_get_parent(chandle, &handle);
515 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400516 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
517 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400520 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 return;
522
Len Brown4be44fc2005-08-05 00:44:28 -0400523 status =
524 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
525 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (ACPI_SUCCESS(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400527 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
528 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530 if (*is_bridge)
531 pci_id->bus = *bus_number;
532
533 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400534 status =
535 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
536 8);
537 if (ACPI_SUCCESS(status)
538 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
539 status =
540 acpi_os_read_pci_configuration(pci_id, 0x18,
541 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 if (!ACPI_SUCCESS(status)) {
543 /* Certainly broken... FIX ME */
544 return;
545 }
546 *is_bridge = 1;
547 pci_id->bus = tu8;
Len Brown4be44fc2005-08-05 00:44:28 -0400548 status =
549 acpi_os_read_pci_configuration(pci_id, 0x19,
550 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 if (ACPI_SUCCESS(status)) {
552 *bus_number = tu8;
553 }
554 } else
555 *is_bridge = 0;
556 }
557 }
558}
559
Len Brown4be44fc2005-08-05 00:44:28 -0400560void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
561 acpi_handle chandle, /* current node */
562 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563{
564 int is_bridge = 1;
565 u8 bus_number = (*id)->bus;
566
567 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
568}
569
Len Brown4be44fc2005-08-05 00:44:28 -0400570static void acpi_os_execute_deferred(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -0400572 struct acpi_os_dpc *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
Len Brown72945b22006-07-12 22:46:42 -0400607 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
608 "Scheduling function [%p(%p)] for deferred execution.\n",
609 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 if (!function)
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -0400612 return AE_BAD_PARAMETER;
Len Brown72945b22006-07-12 22:46:42 -0400613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 /*
615 * Allocate/initialize DPC structure. Note that this memory will be
616 * freed by the callee. The kernel handles the tq_struct list in a
617 * way that allows us to also free its memory inside the callee.
618 * Because we may want to schedule several tasks with different
619 * parameters we can't use the approach some kernel code uses of
620 * having a static tq_struct.
621 * We can save time and code by allocating the DPC and tq_structs
622 * from the same memory.
623 */
Len Brown72945b22006-07-12 22:46:42 -0400624
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -0400625 dpc = kmalloc(sizeof(struct acpi_os_dpc) +
626 sizeof(struct work_struct), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 if (!dpc)
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -0400628 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 dpc->function = function;
630 dpc->context = context;
Len Brown72945b22006-07-12 22:46:42 -0400631 task = (void *)(dpc + 1);
632 INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc);
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -0400633 if (!queue_work((type == OSL_NOTIFY_HANDLER)?
634 kacpi_notify_wq : kacpid_wq, task)) {
Len Brown72945b22006-07-12 22:46:42 -0400635 status = AE_ERROR;
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -0400636 kfree(dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
Alexey Y. Starikovskiy37605a62006-09-26 04:20:47 -0400638 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639}
Len Brown4be44fc2005-08-05 00:44:28 -0400640
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400641EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Len Brown4be44fc2005-08-05 00:44:28 -0400643void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644{
645 flush_workqueue(kacpid_wq);
646}
Len Brown4be44fc2005-08-05 00:44:28 -0400647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648EXPORT_SYMBOL(acpi_os_wait_events_complete);
649
650/*
651 * Allocate the memory for a spinlock and initialize it.
652 */
Bob Moore967440e2006-06-23 17:04:00 -0400653acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654{
Bob Moore967440e2006-06-23 17:04:00 -0400655 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Patrick Mocheld550d982006-06-27 00:41:40 -0400657 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658}
659
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660/*
661 * Deallocate the memory for a spinlock.
662 */
Bob Moore967440e2006-06-23 17:04:00 -0400663void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
Patrick Mocheld550d982006-06-27 00:41:40 -0400665 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400669acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670{
Len Brown4be44fc2005-08-05 00:44:28 -0400671 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674 sem = acpi_os_allocate(sizeof(struct semaphore));
675 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400676 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 memset(sem, 0, sizeof(struct semaphore));
678
679 sema_init(sem, initial_units);
680
Len Brown4be44fc2005-08-05 00:44:28 -0400681 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
Len Brown4be44fc2005-08-05 00:44:28 -0400683 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
684 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Patrick Mocheld550d982006-06-27 00:41:40 -0400686 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Len Brown4be44fc2005-08-05 00:44:28 -0400689EXPORT_SYMBOL(acpi_os_create_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691/*
692 * TODO: A better way to delete semaphores? Linux doesn't have a
693 * 'delete_semaphore()' function -- may result in an invalid
694 * pointer dereference for non-synchronized consumers. Should
695 * we at least check for blocked threads and signal/cancel them?
696 */
697
Len Brown4be44fc2005-08-05 00:44:28 -0400698acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699{
Len Brown4be44fc2005-08-05 00:44:28 -0400700 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
703 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400704 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Len Brown4be44fc2005-08-05 00:44:28 -0400706 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Len Brown02438d82006-06-30 03:19:10 -0400708 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400709 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Patrick Mocheld550d982006-06-27 00:41:40 -0400711 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Len Brown4be44fc2005-08-05 00:44:28 -0400714EXPORT_SYMBOL(acpi_os_delete_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716/*
717 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
718 * improvise. The process is to sleep for one scheduler quantum
719 * until the semaphore becomes available. Downside is that this
720 * may result in starvation for timeout-based waits when there's
721 * lots of semaphore activity.
722 *
723 * TODO: Support for units > 1?
724 */
Len Brown4be44fc2005-08-05 00:44:28 -0400725acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726{
Len Brown4be44fc2005-08-05 00:44:28 -0400727 acpi_status status = AE_OK;
728 struct semaphore *sem = (struct semaphore *)handle;
729 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
732 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400733 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400736 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Len Brown4be44fc2005-08-05 00:44:28 -0400738 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
739 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Len Brownd68909f2006-08-16 19:16:58 -0400741 /*
742 * This can be called during resume with interrupts off.
743 * Like boot-time, we should be single threaded and will
744 * always get the lock if we try -- timeout or not.
745 * If this doesn't succeed, then we will oops courtesy of
746 * might_sleep() in down().
747 */
748 if (!down_trylock(sem))
749 return AE_OK;
750
Len Brown4be44fc2005-08-05 00:44:28 -0400751 switch (timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 /*
753 * No Wait:
754 * --------
755 * A zero timeout value indicates that we shouldn't wait - just
756 * acquire the semaphore if available otherwise return AE_TIME
757 * (a.k.a. 'would block').
758 */
Len Brown4be44fc2005-08-05 00:44:28 -0400759 case 0:
760 if (down_trylock(sem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 status = AE_TIME;
762 break;
763
764 /*
765 * Wait Indefinitely:
766 * ------------------
767 */
Len Brown4be44fc2005-08-05 00:44:28 -0400768 case ACPI_WAIT_FOREVER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 down(sem);
770 break;
771
772 /*
773 * Wait w/ Timeout:
774 * ----------------
775 */
Len Brown4be44fc2005-08-05 00:44:28 -0400776 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 // TODO: A better timeout algorithm?
778 {
779 int i = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400780 static const int quantum_ms = 1000 / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
782 ret = down_trylock(sem);
Yu Lumingdacd9b82005-12-31 01:45:00 -0500783 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800784 schedule_timeout_interruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 ret = down_trylock(sem);
786 }
Len Brown4be44fc2005-08-05 00:44:28 -0400787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 if (ret != 0)
789 status = AE_TIME;
790 }
791 break;
792 }
793
794 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400795 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400796 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400797 handle, units, timeout,
798 acpi_format_exception(status)));
799 } else {
800 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400801 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400802 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 }
804
Patrick Mocheld550d982006-06-27 00:41:40 -0400805 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Len Brown4be44fc2005-08-05 00:44:28 -0400808EXPORT_SYMBOL(acpi_os_wait_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
810/*
811 * TODO: Support for units > 1?
812 */
Len Brown4be44fc2005-08-05 00:44:28 -0400813acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
Len Brown4be44fc2005-08-05 00:44:28 -0400815 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400819 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
821 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400822 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Len Brown4be44fc2005-08-05 00:44:28 -0400824 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
825 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 up(sem);
828
Patrick Mocheld550d982006-06-27 00:41:40 -0400829 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830}
Len Brown4be44fc2005-08-05 00:44:28 -0400831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832EXPORT_SYMBOL(acpi_os_signal_semaphore);
833
834#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400835u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836{
837
838#ifdef ENABLE_DEBUGGER
839 if (acpi_in_debugger) {
840 u32 chars;
841
842 kdb_read(buffer, sizeof(line_buf));
843
844 /* remove the CR kdb includes */
845 chars = strlen(buffer) - 1;
846 buffer[chars] = '\0';
847 }
848#endif
849
850 return 0;
851}
Len Brown4be44fc2005-08-05 00:44:28 -0400852#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854/* Assumes no unreadable holes inbetween */
Len Brown4be44fc2005-08-05 00:44:28 -0400855u8 acpi_os_readable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
Len Brown4be44fc2005-08-05 00:44:28 -0400857#if defined(__i386__) || defined(__x86_64__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 char tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400859 return !__get_user(tmp, (char __user *)ptr)
860 && !__get_user(tmp, (char __user *)ptr + len - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861#endif
862 return 1;
863}
864
865#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400866u8 acpi_os_writable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867{
868 /* could do dummy write (racy) or a kernel page table lookup.
869 The later may be difficult at early boot when kmap doesn't work yet. */
870 return 1;
871}
872#endif
873
Len Brown4be44fc2005-08-05 00:44:28 -0400874acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
Len Brown4be44fc2005-08-05 00:44:28 -0400876 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 case ACPI_SIGNAL_FATAL:
878 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
879 break;
880 case ACPI_SIGNAL_BREAKPOINT:
881 /*
882 * AML Breakpoint
883 * ACPI spec. says to treat it as a NOP unless
884 * you are debugging. So if/when we integrate
885 * AML debugger into the kernel debugger its
886 * hook will go here. But until then it is
887 * not useful to print anything on breakpoints.
888 */
889 break;
890 default:
891 break;
892 }
893
894 return AE_OK;
895}
Len Brown4be44fc2005-08-05 00:44:28 -0400896
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897EXPORT_SYMBOL(acpi_os_signal);
898
Len Brown4be44fc2005-08-05 00:44:28 -0400899static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
901 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400902 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904 if (!str || !*str)
905 return 0;
906
907 for (; count-- && str && *str; str++) {
908 if (isalnum(*str) || *str == ' ' || *str == ':')
909 *p++ = *str;
910 else if (*str == '\'' || *str == '"')
911 continue;
912 else
913 break;
914 }
915 *p = 0;
916
917 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400918
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919}
920
921__setup("acpi_os_name=", acpi_os_name_setup);
922
923/*
924 * _OSI control
925 * empty string disables _OSI
926 * TBD additional string adds to _OSI
927 */
Len Brown4be44fc2005-08-05 00:44:28 -0400928static int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929{
930 if (str == NULL || *str == '\0') {
931 printk(KERN_INFO PREFIX "_OSI method disabled\n");
932 acpi_gbl_create_osi_method = FALSE;
Len Brown4be44fc2005-08-05 00:44:28 -0400933 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 /* TBD */
Len Brown4be44fc2005-08-05 00:44:28 -0400935 printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n",
936 str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 }
938
939 return 1;
940}
941
942__setup("acpi_osi=", acpi_osi_setup);
943
944/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -0400945static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
947 printk(KERN_INFO PREFIX "serialize enabled\n");
948
949 acpi_gbl_all_methods_serialized = TRUE;
950
951 return 1;
952}
953
954__setup("acpi_serialize", acpi_serialize_setup);
955
956/*
957 * Wake and Run-Time GPES are expected to be separate.
958 * We disable wake-GPEs at run-time to prevent spurious
959 * interrupts.
960 *
961 * However, if a system exists that shares Wake and
962 * Run-time events on the same GPE this flag is available
963 * to tell Linux to keep the wake-time GPEs enabled at run-time.
964 */
Len Brown4be44fc2005-08-05 00:44:28 -0400965static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
967 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
968
969 acpi_gbl_leave_wake_gpes_disabled = FALSE;
970
971 return 1;
972}
973
974__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
975
Adrian Bunk8713cbe2005-09-02 17:16:48 -0400976static int __init acpi_hotkey_setup(char *str)
Luming Yufb9802f2005-03-18 18:03:45 -0500977{
Luming Yu30e332f2005-08-12 00:31:00 -0400978 acpi_specific_hotkey_enabled = FALSE;
Luming Yufb9802f2005-03-18 18:03:45 -0500979 return 1;
980}
981
Luming Yu30e332f2005-08-12 00:31:00 -0400982__setup("acpi_generic_hotkey", acpi_hotkey_setup);
Luming Yufb9802f2005-03-18 18:03:45 -0500983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984/*
985 * max_cstate is defined in the base kernel so modules can
986 * change it w/o depending on the state of the processor module.
987 */
988unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990EXPORT_SYMBOL(max_cstate);
Robert Moore73459f72005-06-24 00:00:00 -0400991
992/*
993 * Acquire a spinlock.
994 *
995 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -0400996 */
997
Bob Moore967440e2006-06-23 17:04:00 -0400998acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -0400999{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001000 acpi_cpu_flags flags;
Bob Moore967440e2006-06-23 17:04:00 -04001001 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001002 return flags;
1003}
1004
1005/*
1006 * Release a spinlock. See above.
1007 */
1008
Bob Moore967440e2006-06-23 17:04:00 -04001009void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001010{
Bob Moore967440e2006-06-23 17:04:00 -04001011 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001012}
1013
Robert Moore73459f72005-06-24 00:00:00 -04001014#ifndef ACPI_USE_LOCAL_CACHE
1015
1016/*******************************************************************************
1017 *
1018 * FUNCTION: acpi_os_create_cache
1019 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001020 * PARAMETERS: name - Ascii name for the cache
1021 * size - Size of each cached object
1022 * depth - Maximum depth of the cache (in objects) <ignored>
1023 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001024 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001025 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001026 *
1027 * DESCRIPTION: Create a cache object
1028 *
1029 ******************************************************************************/
1030
1031acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001032acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001033{
Len Brown4be44fc2005-08-05 00:44:28 -04001034 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001035 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001036 return AE_ERROR;
1037 else
1038 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001039}
1040
1041/*******************************************************************************
1042 *
1043 * FUNCTION: acpi_os_purge_cache
1044 *
1045 * PARAMETERS: Cache - Handle to cache object
1046 *
1047 * RETURN: Status
1048 *
1049 * DESCRIPTION: Free all objects within the requested cache.
1050 *
1051 ******************************************************************************/
1052
Len Brown4be44fc2005-08-05 00:44:28 -04001053acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001054{
Len Brown4be44fc2005-08-05 00:44:28 -04001055 (void)kmem_cache_shrink(cache);
1056 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001057}
1058
1059/*******************************************************************************
1060 *
1061 * FUNCTION: acpi_os_delete_cache
1062 *
1063 * PARAMETERS: Cache - Handle to cache object
1064 *
1065 * RETURN: Status
1066 *
1067 * DESCRIPTION: Free all objects within the requested cache and delete the
1068 * cache object.
1069 *
1070 ******************************************************************************/
1071
Len Brown4be44fc2005-08-05 00:44:28 -04001072acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001073{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001074 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001075 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001076}
1077
1078/*******************************************************************************
1079 *
1080 * FUNCTION: acpi_os_release_object
1081 *
1082 * PARAMETERS: Cache - Handle to cache object
1083 * Object - The object to be released
1084 *
1085 * RETURN: None
1086 *
1087 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1088 * the object is deleted.
1089 *
1090 ******************************************************************************/
1091
Len Brown4be44fc2005-08-05 00:44:28 -04001092acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001093{
Len Brown4be44fc2005-08-05 00:44:28 -04001094 kmem_cache_free(cache, object);
1095 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001096}
1097
Bob Mooreb229cf92006-04-21 17:15:00 -04001098/******************************************************************************
1099 *
1100 * FUNCTION: acpi_os_validate_interface
1101 *
1102 * PARAMETERS: interface - Requested interface to be validated
1103 *
1104 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1105 *
1106 * DESCRIPTION: Match an interface string to the interfaces supported by the
1107 * host. Strings originate from an AML call to the _OSI method.
1108 *
1109 *****************************************************************************/
1110
1111acpi_status
1112acpi_os_validate_interface (char *interface)
1113{
1114
1115 return AE_SUPPORT;
1116}
1117
1118
1119/******************************************************************************
1120 *
1121 * FUNCTION: acpi_os_validate_address
1122 *
1123 * PARAMETERS: space_id - ACPI space ID
1124 * address - Physical address
1125 * length - Address length
1126 *
1127 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1128 * should return AE_AML_ILLEGAL_ADDRESS.
1129 *
1130 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1131 * the addresses accessed by AML operation regions.
1132 *
1133 *****************************************************************************/
1134
1135acpi_status
1136acpi_os_validate_address (
1137 u8 space_id,
1138 acpi_physical_address address,
1139 acpi_size length)
1140{
1141
1142 return AE_OK;
1143}
1144
1145
Robert Moore73459f72005-06-24 00:00:00 -04001146#endif