blob: d4bd314d60baab5d02cac35612d78c5970411a26 [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 Starikovskiyb8d35192006-05-05 03:23:00 -040039#include <linux/kthread.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;
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);
96
97 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
Thomas Renningera6fc6722006-06-26 23:58:43 -0400139
David Shaohua Li11e981f2005-08-03 23:46:33 -0400140extern int acpi_in_resume;
Len Brown4be44fc2005-08-05 00:44:28 -0400141void *acpi_os_allocate(acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
David Shaohua Li11e981f2005-08-03 23:46:33 -0400143 if (acpi_in_resume)
144 return kmalloc(size, GFP_ATOMIC);
145 else
146 return kmalloc(size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
Len Brown4be44fc2005-08-05 00:44:28 -0400149acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
151 if (efi_enabled) {
152 addr->pointer_type = ACPI_PHYSICAL_POINTER;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800153 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
154 addr->pointer.physical = efi.acpi20;
155 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
156 addr->pointer.physical = efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400158 printk(KERN_ERR PREFIX
159 "System description tables not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 return AE_NOT_FOUND;
161 }
162 } else {
163 if (ACPI_FAILURE(acpi_find_root_pointer(flags, addr))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400164 printk(KERN_ERR PREFIX
165 "System description tables not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 return AE_NOT_FOUND;
167 }
168 }
169
170 return AE_OK;
171}
172
173acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400174acpi_os_map_memory(acpi_physical_address phys, acpi_size size,
175 void __iomem ** virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800177 if (phys > ULONG_MAX) {
178 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
179 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 }
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800181 /*
182 * ioremap checks to ensure this is in reserved space
183 */
184 *virt = ioremap((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 if (!*virt)
187 return AE_NO_MEMORY;
188
189 return AE_OK;
190}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800191EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Len Brown4be44fc2005-08-05 00:44:28 -0400193void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
195 iounmap(virt);
196}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800197EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199#ifdef ACPI_FUTURE_USAGE
200acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400201acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
Len Brown4be44fc2005-08-05 00:44:28 -0400203 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 return AE_BAD_PARAMETER;
205
206 *phys = virt_to_phys(virt);
207
208 return AE_OK;
209}
210#endif
211
212#define ACPI_MAX_OVERRIDE_LEN 100
213
214static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
215
216acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400217acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
218 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
220 if (!init_val || !new_val)
221 return AE_BAD_PARAMETER;
222
223 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400224 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400226 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 *new_val = acpi_os_name;
228 }
229
230 return AE_OK;
231}
232
233acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400234acpi_os_table_override(struct acpi_table_header * existing_table,
235 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
237 if (!existing_table || !new_table)
238 return AE_BAD_PARAMETER;
239
240#ifdef CONFIG_ACPI_CUSTOM_DSDT
241 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400242 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 else
244 *new_table = NULL;
245#else
246 *new_table = NULL;
247#endif
248 return AE_OK;
249}
250
Len Brown4be44fc2005-08-05 00:44:28 -0400251static irqreturn_t acpi_irq(int irq, void *dev_id, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Len Brown4be44fc2005-08-05 00:44:28 -0400253 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
255
256acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400257acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
258 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
260 unsigned int irq;
261
262 /*
263 * Ignore the GSI from the core, and use the value in our copy of the
264 * FADT. It may not be the same if an interrupt source override exists
265 * for the SCI.
266 */
267 gsi = acpi_fadt.sci_int;
268 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
269 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
270 gsi);
271 return AE_OK;
272 }
273
274 acpi_irq_handler = handler;
275 acpi_irq_context = context;
276 if (request_irq(irq, acpi_irq, SA_SHIRQ, "acpi", acpi_irq)) {
277 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
278 return AE_NOT_ACQUIRED;
279 }
280 acpi_irq_irq = irq;
281
282 return AE_OK;
283}
284
Len Brown4be44fc2005-08-05 00:44:28 -0400285acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
287 if (irq) {
288 free_irq(irq, acpi_irq);
289 acpi_irq_handler = NULL;
290 acpi_irq_irq = 0;
291 }
292
293 return AE_OK;
294}
295
296/*
297 * Running in interpreter thread context, safe to sleep
298 */
299
Len Brown4be44fc2005-08-05 00:44:28 -0400300void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800302 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303}
Len Brown4be44fc2005-08-05 00:44:28 -0400304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305EXPORT_SYMBOL(acpi_os_sleep);
306
Len Brown4be44fc2005-08-05 00:44:28 -0400307void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
309 while (us) {
310 u32 delay = 1000;
311
312 if (delay > us)
313 delay = us;
314 udelay(delay);
315 touch_nmi_watchdog();
316 us -= delay;
317 }
318}
Len Brown4be44fc2005-08-05 00:44:28 -0400319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320EXPORT_SYMBOL(acpi_os_stall);
321
322/*
323 * Support ACPI 3.0 AML Timer operand
324 * Returns 64-bit free-running, monotonically increasing timer
325 * with 100ns granularity
326 */
Len Brown4be44fc2005-08-05 00:44:28 -0400327u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
329 static u64 t;
330
331#ifdef CONFIG_HPET
332 /* TBD: use HPET if available */
333#endif
334
335#ifdef CONFIG_X86_PM_TIMER
336 /* TBD: default to PM timer if HPET was not available */
337#endif
338 if (!t)
339 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
340
341 return ++t;
342}
343
Len Brown4be44fc2005-08-05 00:44:28 -0400344acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
346 u32 dummy;
347
348 if (!value)
349 value = &dummy;
350
Len Brown4be44fc2005-08-05 00:44:28 -0400351 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400353 *(u8 *) value = inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 break;
355 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400356 *(u16 *) value = inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 break;
358 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400359 *(u32 *) value = inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 break;
361 default:
362 BUG();
363 }
364
365 return AE_OK;
366}
Len Brown4be44fc2005-08-05 00:44:28 -0400367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368EXPORT_SYMBOL(acpi_os_read_port);
369
Len Brown4be44fc2005-08-05 00:44:28 -0400370acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Len Brown4be44fc2005-08-05 00:44:28 -0400372 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 case 8:
374 outb(value, port);
375 break;
376 case 16:
377 outw(value, port);
378 break;
379 case 32:
380 outl(value, port);
381 break;
382 default:
383 BUG();
384 }
385
386 return AE_OK;
387}
Len Brown4be44fc2005-08-05 00:44:28 -0400388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389EXPORT_SYMBOL(acpi_os_write_port);
390
391acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400392acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
Len Brown4be44fc2005-08-05 00:44:28 -0400394 u32 dummy;
395 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800397 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 if (!value)
399 value = &dummy;
400
401 switch (width) {
402 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400403 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 break;
405 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400406 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 break;
408 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400409 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 break;
411 default:
412 BUG();
413 }
414
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800415 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 return AE_OK;
418}
419
420acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400421acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
Len Brown4be44fc2005-08-05 00:44:28 -0400423 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800425 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 switch (width) {
428 case 8:
429 writeb(value, virt_addr);
430 break;
431 case 16:
432 writew(value, virt_addr);
433 break;
434 case 32:
435 writel(value, virt_addr);
436 break;
437 default:
438 BUG();
439 }
440
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800441 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443 return AE_OK;
444}
445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400447acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
448 void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
450 int result, size;
451
452 if (!value)
453 return AE_BAD_PARAMETER;
454
455 switch (width) {
456 case 8:
457 size = 1;
458 break;
459 case 16:
460 size = 2;
461 break;
462 case 32:
463 size = 4;
464 break;
465 default:
466 return AE_ERROR;
467 }
468
469 BUG_ON(!raw_pci_ops);
470
471 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400472 PCI_DEVFN(pci_id->device, pci_id->function),
473 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 return (result ? AE_ERROR : AE_OK);
476}
Len Brown4be44fc2005-08-05 00:44:28 -0400477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478EXPORT_SYMBOL(acpi_os_read_pci_configuration);
479
480acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400481acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
482 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
484 int result, size;
485
486 switch (width) {
487 case 8:
488 size = 1;
489 break;
490 case 16:
491 size = 2;
492 break;
493 case 32:
494 size = 4;
495 break;
496 default:
497 return AE_ERROR;
498 }
499
500 BUG_ON(!raw_pci_ops);
501
502 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400503 PCI_DEVFN(pci_id->device, pci_id->function),
504 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 return (result ? AE_ERROR : AE_OK);
507}
508
509/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400510static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
511 acpi_handle chandle, /* current node */
512 struct acpi_pci_id **id,
513 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
Len Brown4be44fc2005-08-05 00:44:28 -0400515 acpi_handle handle;
516 struct acpi_pci_id *pci_id = *id;
517 acpi_status status;
518 unsigned long temp;
519 acpi_object_type type;
520 u8 tu8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522 acpi_get_parent(chandle, &handle);
523 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400524 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
525 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400528 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 return;
530
Len Brown4be44fc2005-08-05 00:44:28 -0400531 status =
532 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
533 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 if (ACPI_SUCCESS(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400535 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
536 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 if (*is_bridge)
539 pci_id->bus = *bus_number;
540
541 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400542 status =
543 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
544 8);
545 if (ACPI_SUCCESS(status)
546 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
547 status =
548 acpi_os_read_pci_configuration(pci_id, 0x18,
549 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (!ACPI_SUCCESS(status)) {
551 /* Certainly broken... FIX ME */
552 return;
553 }
554 *is_bridge = 1;
555 pci_id->bus = tu8;
Len Brown4be44fc2005-08-05 00:44:28 -0400556 status =
557 acpi_os_read_pci_configuration(pci_id, 0x19,
558 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 if (ACPI_SUCCESS(status)) {
560 *bus_number = tu8;
561 }
562 } else
563 *is_bridge = 0;
564 }
565 }
566}
567
Len Brown4be44fc2005-08-05 00:44:28 -0400568void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
569 acpi_handle chandle, /* current node */
570 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
572 int is_bridge = 1;
573 u8 bus_number = (*id)->bus;
574
575 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
576}
577
Len Brown4be44fc2005-08-05 00:44:28 -0400578static void acpi_os_execute_deferred(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Len Brown4be44fc2005-08-05 00:44:28 -0400580 struct acpi_os_dpc *dpc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Len Brown4be44fc2005-08-05 00:44:28 -0400583 dpc = (struct acpi_os_dpc *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 if (!dpc) {
Len Brown64684632006-06-26 23:41:38 -0400585 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400586 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
588
589 dpc->function(dpc->context);
590
591 kfree(dpc);
592
Patrick Mocheld550d982006-06-27 00:41:40 -0400593 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594}
595
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400596static int acpi_os_execute_thread(void *context)
597{
598 struct acpi_os_dpc *dpc = (struct acpi_os_dpc *)context;
599 if (dpc) {
600 dpc->function(dpc->context);
601 kfree(dpc);
602 }
603 do_exit(0);
604}
605
606/*******************************************************************************
607 *
608 * FUNCTION: acpi_os_execute
609 *
610 * PARAMETERS: Type - Type of the callback
611 * Function - Function to be executed
612 * Context - Function parameters
613 *
614 * RETURN: Status
615 *
616 * DESCRIPTION: Depending on type, either queues function for deferred execution or
617 * immediately executes function on a separate thread.
618 *
619 ******************************************************************************/
620
621acpi_status acpi_os_execute(acpi_execute_type type,
Len Brown4be44fc2005-08-05 00:44:28 -0400622 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
Len Brown4be44fc2005-08-05 00:44:28 -0400624 acpi_status status = AE_OK;
625 struct acpi_os_dpc *dpc;
626 struct work_struct *task;
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400627 struct task_struct *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629 if (!function)
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400630 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 /*
632 * Allocate/initialize DPC structure. Note that this memory will be
633 * freed by the callee. The kernel handles the tq_struct list in a
634 * way that allows us to also free its memory inside the callee.
635 * Because we may want to schedule several tasks with different
636 * parameters we can't use the approach some kernel code uses of
637 * having a static tq_struct.
638 * We can save time and code by allocating the DPC and tq_structs
639 * from the same memory.
640 */
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400641 if (type == OSL_NOTIFY_HANDLER) {
642 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_KERNEL);
643 } else {
644 dpc = kmalloc(sizeof(struct acpi_os_dpc) +
645 sizeof(struct work_struct), GFP_ATOMIC);
646 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (!dpc)
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400648 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 dpc->function = function;
650 dpc->context = context;
651
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400652 if (type == OSL_NOTIFY_HANDLER) {
653 p = kthread_create(acpi_os_execute_thread, dpc, "kacpid_notify");
654 if (!IS_ERR(p)) {
655 wake_up_process(p);
656 } else {
657 status = AE_NO_MEMORY;
658 kfree(dpc);
659 }
660 } else {
661 task = (void *)(dpc + 1);
662 INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc);
663 if (!queue_work(kacpid_wq, task)) {
664 status = AE_ERROR;
665 kfree(dpc);
666 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 }
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400668 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669}
Len Brown4be44fc2005-08-05 00:44:28 -0400670
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400671EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Len Brown4be44fc2005-08-05 00:44:28 -0400673void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
675 flush_workqueue(kacpid_wq);
676}
Len Brown4be44fc2005-08-05 00:44:28 -0400677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678EXPORT_SYMBOL(acpi_os_wait_events_complete);
679
680/*
681 * Allocate the memory for a spinlock and initialize it.
682 */
Bob Moore967440e2006-06-23 17:04:00 -0400683acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
Bob Moore967440e2006-06-23 17:04:00 -0400685 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Patrick Mocheld550d982006-06-27 00:41:40 -0400687 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688}
689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690/*
691 * Deallocate the memory for a spinlock.
692 */
Bob Moore967440e2006-06-23 17:04:00 -0400693void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694{
Patrick Mocheld550d982006-06-27 00:41:40 -0400695 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696}
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400699acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
Len Brown4be44fc2005-08-05 00:44:28 -0400701 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
704 sem = acpi_os_allocate(sizeof(struct semaphore));
705 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400706 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 memset(sem, 0, sizeof(struct semaphore));
708
709 sema_init(sem, initial_units);
710
Len Brown4be44fc2005-08-05 00:44:28 -0400711 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Len Brown4be44fc2005-08-05 00:44:28 -0400713 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
714 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Patrick Mocheld550d982006-06-27 00:41:40 -0400716 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Len Brown4be44fc2005-08-05 00:44:28 -0400719EXPORT_SYMBOL(acpi_os_create_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
721/*
722 * TODO: A better way to delete semaphores? Linux doesn't have a
723 * 'delete_semaphore()' function -- may result in an invalid
724 * pointer dereference for non-synchronized consumers. Should
725 * we at least check for blocked threads and signal/cancel them?
726 */
727
Len Brown4be44fc2005-08-05 00:44:28 -0400728acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729{
Len Brown4be44fc2005-08-05 00:44:28 -0400730 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400734 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Len Brown4be44fc2005-08-05 00:44:28 -0400736 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Len Brown02438d82006-06-30 03:19:10 -0400738 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400739 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Patrick Mocheld550d982006-06-27 00:41:40 -0400741 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
Len Brown4be44fc2005-08-05 00:44:28 -0400744EXPORT_SYMBOL(acpi_os_delete_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746/*
747 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
748 * improvise. The process is to sleep for one scheduler quantum
749 * until the semaphore becomes available. Downside is that this
750 * may result in starvation for timeout-based waits when there's
751 * lots of semaphore activity.
752 *
753 * TODO: Support for units > 1?
754 */
Len Brown4be44fc2005-08-05 00:44:28 -0400755acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756{
Len Brown4be44fc2005-08-05 00:44:28 -0400757 acpi_status status = AE_OK;
758 struct semaphore *sem = (struct semaphore *)handle;
759 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400763 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400766 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Len Brown4be44fc2005-08-05 00:44:28 -0400768 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
769 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Len Brown4be44fc2005-08-05 00:44:28 -0400771 switch (timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 /*
773 * No Wait:
774 * --------
775 * A zero timeout value indicates that we shouldn't wait - just
776 * acquire the semaphore if available otherwise return AE_TIME
777 * (a.k.a. 'would block').
778 */
Len Brown4be44fc2005-08-05 00:44:28 -0400779 case 0:
780 if (down_trylock(sem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 status = AE_TIME;
782 break;
783
784 /*
785 * Wait Indefinitely:
786 * ------------------
787 */
Len Brown4be44fc2005-08-05 00:44:28 -0400788 case ACPI_WAIT_FOREVER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 down(sem);
790 break;
791
792 /*
793 * Wait w/ Timeout:
794 * ----------------
795 */
Len Brown4be44fc2005-08-05 00:44:28 -0400796 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 // TODO: A better timeout algorithm?
798 {
799 int i = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400800 static const int quantum_ms = 1000 / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 ret = down_trylock(sem);
Yu Lumingdacd9b82005-12-31 01:45:00 -0500803 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800804 schedule_timeout_interruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 ret = down_trylock(sem);
806 }
Len Brown4be44fc2005-08-05 00:44:28 -0400807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 if (ret != 0)
809 status = AE_TIME;
810 }
811 break;
812 }
813
814 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400815 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400816 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400817 handle, units, timeout,
818 acpi_format_exception(status)));
819 } else {
820 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400821 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400822 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 }
824
Patrick Mocheld550d982006-06-27 00:41:40 -0400825 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Len Brown4be44fc2005-08-05 00:44:28 -0400828EXPORT_SYMBOL(acpi_os_wait_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830/*
831 * TODO: Support for units > 1?
832 */
Len Brown4be44fc2005-08-05 00:44:28 -0400833acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
Len Brown4be44fc2005-08-05 00:44:28 -0400835 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400839 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400842 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
Len Brown4be44fc2005-08-05 00:44:28 -0400844 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
845 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 up(sem);
848
Patrick Mocheld550d982006-06-27 00:41:40 -0400849 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850}
Len Brown4be44fc2005-08-05 00:44:28 -0400851
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852EXPORT_SYMBOL(acpi_os_signal_semaphore);
853
854#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400855u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
857
858#ifdef ENABLE_DEBUGGER
859 if (acpi_in_debugger) {
860 u32 chars;
861
862 kdb_read(buffer, sizeof(line_buf));
863
864 /* remove the CR kdb includes */
865 chars = strlen(buffer) - 1;
866 buffer[chars] = '\0';
867 }
868#endif
869
870 return 0;
871}
Len Brown4be44fc2005-08-05 00:44:28 -0400872#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
874/* Assumes no unreadable holes inbetween */
Len Brown4be44fc2005-08-05 00:44:28 -0400875u8 acpi_os_readable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
Len Brown4be44fc2005-08-05 00:44:28 -0400877#if defined(__i386__) || defined(__x86_64__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 char tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400879 return !__get_user(tmp, (char __user *)ptr)
880 && !__get_user(tmp, (char __user *)ptr + len - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881#endif
882 return 1;
883}
884
885#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400886u8 acpi_os_writable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887{
888 /* could do dummy write (racy) or a kernel page table lookup.
889 The later may be difficult at early boot when kmap doesn't work yet. */
890 return 1;
891}
892#endif
893
Len Brown4be44fc2005-08-05 00:44:28 -0400894acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
Len Brown4be44fc2005-08-05 00:44:28 -0400896 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 case ACPI_SIGNAL_FATAL:
898 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
899 break;
900 case ACPI_SIGNAL_BREAKPOINT:
901 /*
902 * AML Breakpoint
903 * ACPI spec. says to treat it as a NOP unless
904 * you are debugging. So if/when we integrate
905 * AML debugger into the kernel debugger its
906 * hook will go here. But until then it is
907 * not useful to print anything on breakpoints.
908 */
909 break;
910 default:
911 break;
912 }
913
914 return AE_OK;
915}
Len Brown4be44fc2005-08-05 00:44:28 -0400916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917EXPORT_SYMBOL(acpi_os_signal);
918
Len Brown4be44fc2005-08-05 00:44:28 -0400919static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920{
921 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400922 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 if (!str || !*str)
925 return 0;
926
927 for (; count-- && str && *str; str++) {
928 if (isalnum(*str) || *str == ' ' || *str == ':')
929 *p++ = *str;
930 else if (*str == '\'' || *str == '"')
931 continue;
932 else
933 break;
934 }
935 *p = 0;
936
937 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939}
940
941__setup("acpi_os_name=", acpi_os_name_setup);
942
943/*
944 * _OSI control
945 * empty string disables _OSI
946 * TBD additional string adds to _OSI
947 */
Len Brown4be44fc2005-08-05 00:44:28 -0400948static int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949{
950 if (str == NULL || *str == '\0') {
951 printk(KERN_INFO PREFIX "_OSI method disabled\n");
952 acpi_gbl_create_osi_method = FALSE;
Len Brown4be44fc2005-08-05 00:44:28 -0400953 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 /* TBD */
Len Brown4be44fc2005-08-05 00:44:28 -0400955 printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n",
956 str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 }
958
959 return 1;
960}
961
962__setup("acpi_osi=", acpi_osi_setup);
963
964/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -0400965static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
967 printk(KERN_INFO PREFIX "serialize enabled\n");
968
969 acpi_gbl_all_methods_serialized = TRUE;
970
971 return 1;
972}
973
974__setup("acpi_serialize", acpi_serialize_setup);
975
976/*
977 * Wake and Run-Time GPES are expected to be separate.
978 * We disable wake-GPEs at run-time to prevent spurious
979 * interrupts.
980 *
981 * However, if a system exists that shares Wake and
982 * Run-time events on the same GPE this flag is available
983 * to tell Linux to keep the wake-time GPEs enabled at run-time.
984 */
Len Brown4be44fc2005-08-05 00:44:28 -0400985static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986{
987 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
988
989 acpi_gbl_leave_wake_gpes_disabled = FALSE;
990
991 return 1;
992}
993
994__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
995
Adrian Bunk8713cbe2005-09-02 17:16:48 -0400996static int __init acpi_hotkey_setup(char *str)
Luming Yufb9802f2005-03-18 18:03:45 -0500997{
Luming Yu30e332f2005-08-12 00:31:00 -0400998 acpi_specific_hotkey_enabled = FALSE;
Luming Yufb9802f2005-03-18 18:03:45 -0500999 return 1;
1000}
1001
Luming Yu30e332f2005-08-12 00:31:00 -04001002__setup("acpi_generic_hotkey", acpi_hotkey_setup);
Luming Yufb9802f2005-03-18 18:03:45 -05001003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004/*
1005 * max_cstate is defined in the base kernel so modules can
1006 * change it w/o depending on the state of the processor module.
1007 */
1008unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
1009
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010EXPORT_SYMBOL(max_cstate);
Robert Moore73459f72005-06-24 00:00:00 -04001011
1012/*
1013 * Acquire a spinlock.
1014 *
1015 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001016 */
1017
Bob Moore967440e2006-06-23 17:04:00 -04001018acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001019{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001020 acpi_cpu_flags flags;
Bob Moore967440e2006-06-23 17:04:00 -04001021 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001022 return flags;
1023}
1024
1025/*
1026 * Release a spinlock. See above.
1027 */
1028
Bob Moore967440e2006-06-23 17:04:00 -04001029void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001030{
Bob Moore967440e2006-06-23 17:04:00 -04001031 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001032}
1033
Robert Moore73459f72005-06-24 00:00:00 -04001034#ifndef ACPI_USE_LOCAL_CACHE
1035
1036/*******************************************************************************
1037 *
1038 * FUNCTION: acpi_os_create_cache
1039 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001040 * PARAMETERS: name - Ascii name for the cache
1041 * size - Size of each cached object
1042 * depth - Maximum depth of the cache (in objects) <ignored>
1043 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001044 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001045 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001046 *
1047 * DESCRIPTION: Create a cache object
1048 *
1049 ******************************************************************************/
1050
1051acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001052acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001053{
Len Brown4be44fc2005-08-05 00:44:28 -04001054 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
Bob Mooreb229cf92006-04-21 17:15:00 -04001055 if (cache == NULL)
1056 return AE_ERROR;
1057 else
1058 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001059}
1060
1061/*******************************************************************************
1062 *
1063 * FUNCTION: acpi_os_purge_cache
1064 *
1065 * PARAMETERS: Cache - Handle to cache object
1066 *
1067 * RETURN: Status
1068 *
1069 * DESCRIPTION: Free all objects within the requested cache.
1070 *
1071 ******************************************************************************/
1072
Len Brown4be44fc2005-08-05 00:44:28 -04001073acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001074{
Len Brown4be44fc2005-08-05 00:44:28 -04001075 (void)kmem_cache_shrink(cache);
1076 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001077}
1078
1079/*******************************************************************************
1080 *
1081 * FUNCTION: acpi_os_delete_cache
1082 *
1083 * PARAMETERS: Cache - Handle to cache object
1084 *
1085 * RETURN: Status
1086 *
1087 * DESCRIPTION: Free all objects within the requested cache and delete the
1088 * cache object.
1089 *
1090 ******************************************************************************/
1091
Len Brown4be44fc2005-08-05 00:44:28 -04001092acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001093{
Len Brown4be44fc2005-08-05 00:44:28 -04001094 (void)kmem_cache_destroy(cache);
1095 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001096}
1097
1098/*******************************************************************************
1099 *
1100 * FUNCTION: acpi_os_release_object
1101 *
1102 * PARAMETERS: Cache - Handle to cache object
1103 * Object - The object to be released
1104 *
1105 * RETURN: None
1106 *
1107 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1108 * the object is deleted.
1109 *
1110 ******************************************************************************/
1111
Len Brown4be44fc2005-08-05 00:44:28 -04001112acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001113{
Len Brown4be44fc2005-08-05 00:44:28 -04001114 kmem_cache_free(cache, object);
1115 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001116}
1117
1118/*******************************************************************************
1119 *
1120 * FUNCTION: acpi_os_acquire_object
1121 *
1122 * PARAMETERS: Cache - Handle to cache object
1123 * ReturnObject - Where the object is returned
1124 *
1125 * RETURN: Status
1126 *
Bob Moore61686122006-03-17 16:44:00 -05001127 * DESCRIPTION: Return a zero-filled object.
Robert Moore73459f72005-06-24 00:00:00 -04001128 *
1129 ******************************************************************************/
1130
Len Brown4be44fc2005-08-05 00:44:28 -04001131void *acpi_os_acquire_object(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001132{
Bob Moore61686122006-03-17 16:44:00 -05001133 void *object = kmem_cache_zalloc(cache, GFP_KERNEL);
Len Brown4be44fc2005-08-05 00:44:28 -04001134 WARN_ON(!object);
1135 return object;
Robert Moore73459f72005-06-24 00:00:00 -04001136}
1137
Bob Mooreb229cf92006-04-21 17:15:00 -04001138/******************************************************************************
1139 *
1140 * FUNCTION: acpi_os_validate_interface
1141 *
1142 * PARAMETERS: interface - Requested interface to be validated
1143 *
1144 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1145 *
1146 * DESCRIPTION: Match an interface string to the interfaces supported by the
1147 * host. Strings originate from an AML call to the _OSI method.
1148 *
1149 *****************************************************************************/
1150
1151acpi_status
1152acpi_os_validate_interface (char *interface)
1153{
1154
1155 return AE_SUPPORT;
1156}
1157
1158
1159/******************************************************************************
1160 *
1161 * FUNCTION: acpi_os_validate_address
1162 *
1163 * PARAMETERS: space_id - ACPI space ID
1164 * address - Physical address
1165 * length - Address length
1166 *
1167 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1168 * should return AE_AML_ILLEGAL_ADDRESS.
1169 *
1170 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1171 * the addresses accessed by AML operation regions.
1172 *
1173 *****************************************************************************/
1174
1175acpi_status
1176acpi_os_validate_address (
1177 u8 space_id,
1178 acpi_physical_address address,
1179 acpi_size length)
1180{
1181
1182 return AE_OK;
1183}
1184
1185
Robert Moore73459f72005-06-24 00:00:00 -04001186#endif