blob: 9127760d36c590765d72bfaa80363522da2f54cc [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
28#include <linux/config.h>
29#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/slab.h>
32#include <linux/mm.h>
33#include <linux/pci.h>
34#include <linux/smp_lock.h>
35#include <linux/interrupt.h>
36#include <linux/kmod.h>
37#include <linux/delay.h>
38#include <linux/workqueue.h>
39#include <linux/nmi.h>
40#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 Yufb9802f2005-03-18 18:03:45 -050070int acpi_specific_hotkey_enabled;
71EXPORT_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 */
89#ifdef CONFIG_ACPI_PCI
90 if (!raw_pci_ops) {
Len Brown4be44fc2005-08-05 00:44:28 -040091 printk(KERN_ERR PREFIX
92 "Access to PCI configuration space unavailable\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return AE_NULL_ENTRY;
94 }
95#endif
96 kacpid_wq = create_singlethread_workqueue("kacpid");
97 BUG_ON(!kacpid_wq);
98
99 return AE_OK;
100}
101
Len Brown4be44fc2005-08-05 00:44:28 -0400102acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
104 if (acpi_irq_handler) {
105 acpi_os_remove_interrupt_handler(acpi_irq_irq,
106 acpi_irq_handler);
107 }
108
109 destroy_workqueue(kacpid_wq);
110
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
David Shaohua Li11e981f2005-08-03 23:46:33 -0400141extern int acpi_in_resume;
Len Brown4be44fc2005-08-05 00:44:28 -0400142void *acpi_os_allocate(acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
David Shaohua Li11e981f2005-08-03 23:46:33 -0400144 if (acpi_in_resume)
145 return kmalloc(size, GFP_ATOMIC);
146 else
147 return kmalloc(size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148}
149
Len Brown4be44fc2005-08-05 00:44:28 -0400150void acpi_os_free(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
152 kfree(ptr);
153}
Len Brown4be44fc2005-08-05 00:44:28 -0400154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155EXPORT_SYMBOL(acpi_os_free);
156
Len Brown4be44fc2005-08-05 00:44:28 -0400157acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 if (efi_enabled) {
160 addr->pointer_type = ACPI_PHYSICAL_POINTER;
161 if (efi.acpi20)
162 addr->pointer.physical =
Len Brown4be44fc2005-08-05 00:44:28 -0400163 (acpi_physical_address) virt_to_phys(efi.acpi20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 else if (efi.acpi)
165 addr->pointer.physical =
Len Brown4be44fc2005-08-05 00:44:28 -0400166 (acpi_physical_address) virt_to_phys(efi.acpi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400168 printk(KERN_ERR PREFIX
169 "System description tables not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 return AE_NOT_FOUND;
171 }
172 } else {
173 if (ACPI_FAILURE(acpi_find_root_pointer(flags, addr))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400174 printk(KERN_ERR PREFIX
175 "System description tables not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return AE_NOT_FOUND;
177 }
178 }
179
180 return AE_OK;
181}
182
183acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400184acpi_os_map_memory(acpi_physical_address phys, acpi_size size,
185 void __iomem ** virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
187 if (efi_enabled) {
188 if (EFI_MEMORY_WB & efi_mem_attributes(phys)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400189 *virt = (void __iomem *)phys_to_virt(phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 } else {
191 *virt = ioremap(phys, size);
192 }
193 } else {
194 if (phys > ULONG_MAX) {
195 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
196 return AE_BAD_PARAMETER;
197 }
198 /*
Len Brown4be44fc2005-08-05 00:44:28 -0400199 * ioremap checks to ensure this is in reserved space
200 */
201 *virt = ioremap((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
203
204 if (!*virt)
205 return AE_NO_MEMORY;
206
207 return AE_OK;
208}
209
Len Brown4be44fc2005-08-05 00:44:28 -0400210void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
212 iounmap(virt);
213}
214
215#ifdef ACPI_FUTURE_USAGE
216acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400217acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Len Brown4be44fc2005-08-05 00:44:28 -0400219 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 return AE_BAD_PARAMETER;
221
222 *phys = virt_to_phys(virt);
223
224 return AE_OK;
225}
226#endif
227
228#define ACPI_MAX_OVERRIDE_LEN 100
229
230static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
231
232acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400233acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
234 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
236 if (!init_val || !new_val)
237 return AE_BAD_PARAMETER;
238
239 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400240 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400242 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 *new_val = acpi_os_name;
244 }
245
246 return AE_OK;
247}
248
249acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400250acpi_os_table_override(struct acpi_table_header * existing_table,
251 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
253 if (!existing_table || !new_table)
254 return AE_BAD_PARAMETER;
255
256#ifdef CONFIG_ACPI_CUSTOM_DSDT
257 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400258 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 else
260 *new_table = NULL;
261#else
262 *new_table = NULL;
263#endif
264 return AE_OK;
265}
266
Len Brown4be44fc2005-08-05 00:44:28 -0400267static irqreturn_t acpi_irq(int irq, void *dev_id, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
Len Brown4be44fc2005-08-05 00:44:28 -0400269 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270}
271
272acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400273acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
274 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
276 unsigned int irq;
277
278 /*
279 * Ignore the GSI from the core, and use the value in our copy of the
280 * FADT. It may not be the same if an interrupt source override exists
281 * for the SCI.
282 */
283 gsi = acpi_fadt.sci_int;
284 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
285 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
286 gsi);
287 return AE_OK;
288 }
289
290 acpi_irq_handler = handler;
291 acpi_irq_context = context;
292 if (request_irq(irq, acpi_irq, SA_SHIRQ, "acpi", acpi_irq)) {
293 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
294 return AE_NOT_ACQUIRED;
295 }
296 acpi_irq_irq = irq;
297
298 return AE_OK;
299}
300
Len Brown4be44fc2005-08-05 00:44:28 -0400301acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
303 if (irq) {
304 free_irq(irq, acpi_irq);
305 acpi_irq_handler = NULL;
306 acpi_irq_irq = 0;
307 }
308
309 return AE_OK;
310}
311
312/*
313 * Running in interpreter thread context, safe to sleep
314 */
315
Len Brown4be44fc2005-08-05 00:44:28 -0400316void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
318 current->state = TASK_INTERRUPTIBLE;
Len Brown4be44fc2005-08-05 00:44:28 -0400319 schedule_timeout(((signed long)ms * HZ) / 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320}
Len Brown4be44fc2005-08-05 00:44:28 -0400321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322EXPORT_SYMBOL(acpi_os_sleep);
323
Len Brown4be44fc2005-08-05 00:44:28 -0400324void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
326 while (us) {
327 u32 delay = 1000;
328
329 if (delay > us)
330 delay = us;
331 udelay(delay);
332 touch_nmi_watchdog();
333 us -= delay;
334 }
335}
Len Brown4be44fc2005-08-05 00:44:28 -0400336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337EXPORT_SYMBOL(acpi_os_stall);
338
339/*
340 * Support ACPI 3.0 AML Timer operand
341 * Returns 64-bit free-running, monotonically increasing timer
342 * with 100ns granularity
343 */
Len Brown4be44fc2005-08-05 00:44:28 -0400344u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
346 static u64 t;
347
348#ifdef CONFIG_HPET
349 /* TBD: use HPET if available */
350#endif
351
352#ifdef CONFIG_X86_PM_TIMER
353 /* TBD: default to PM timer if HPET was not available */
354#endif
355 if (!t)
356 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
357
358 return ++t;
359}
360
Len Brown4be44fc2005-08-05 00:44:28 -0400361acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
363 u32 dummy;
364
365 if (!value)
366 value = &dummy;
367
Len Brown4be44fc2005-08-05 00:44:28 -0400368 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400370 *(u8 *) value = inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 break;
372 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400373 *(u16 *) value = inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 break;
375 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400376 *(u32 *) value = inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 break;
378 default:
379 BUG();
380 }
381
382 return AE_OK;
383}
Len Brown4be44fc2005-08-05 00:44:28 -0400384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385EXPORT_SYMBOL(acpi_os_read_port);
386
Len Brown4be44fc2005-08-05 00:44:28 -0400387acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
Len Brown4be44fc2005-08-05 00:44:28 -0400389 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 case 8:
391 outb(value, port);
392 break;
393 case 16:
394 outw(value, port);
395 break;
396 case 32:
397 outl(value, port);
398 break;
399 default:
400 BUG();
401 }
402
403 return AE_OK;
404}
Len Brown4be44fc2005-08-05 00:44:28 -0400405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406EXPORT_SYMBOL(acpi_os_write_port);
407
408acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400409acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
Len Brown4be44fc2005-08-05 00:44:28 -0400411 u32 dummy;
412 void __iomem *virt_addr;
413 int iomem = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 if (efi_enabled) {
416 if (EFI_MEMORY_WB & efi_mem_attributes(phys_addr)) {
417 /* HACK ALERT! We can use readb/w/l on real memory too.. */
Len Brown4be44fc2005-08-05 00:44:28 -0400418 virt_addr = (void __iomem *)phys_to_virt(phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 } else {
420 iomem = 1;
421 virt_addr = ioremap(phys_addr, width);
422 }
423 } else
Len Brown4be44fc2005-08-05 00:44:28 -0400424 virt_addr = (void __iomem *)phys_to_virt(phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 if (!value)
426 value = &dummy;
427
428 switch (width) {
429 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400430 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 break;
432 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400433 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 break;
435 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400436 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 break;
438 default:
439 BUG();
440 }
441
442 if (efi_enabled) {
443 if (iomem)
444 iounmap(virt_addr);
445 }
446
447 return AE_OK;
448}
449
450acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400451acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452{
Len Brown4be44fc2005-08-05 00:44:28 -0400453 void __iomem *virt_addr;
454 int iomem = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
456 if (efi_enabled) {
457 if (EFI_MEMORY_WB & efi_mem_attributes(phys_addr)) {
458 /* HACK ALERT! We can use writeb/w/l on real memory too */
Len Brown4be44fc2005-08-05 00:44:28 -0400459 virt_addr = (void __iomem *)phys_to_virt(phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 } else {
461 iomem = 1;
462 virt_addr = ioremap(phys_addr, width);
463 }
464 } else
Len Brown4be44fc2005-08-05 00:44:28 -0400465 virt_addr = (void __iomem *)phys_to_virt(phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467 switch (width) {
468 case 8:
469 writeb(value, virt_addr);
470 break;
471 case 16:
472 writew(value, virt_addr);
473 break;
474 case 32:
475 writel(value, virt_addr);
476 break;
477 default:
478 BUG();
479 }
480
481 if (iomem)
482 iounmap(virt_addr);
483
484 return AE_OK;
485}
486
487#ifdef CONFIG_ACPI_PCI
488
489acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400490acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
491 void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
493 int result, size;
494
495 if (!value)
496 return AE_BAD_PARAMETER;
497
498 switch (width) {
499 case 8:
500 size = 1;
501 break;
502 case 16:
503 size = 2;
504 break;
505 case 32:
506 size = 4;
507 break;
508 default:
509 return AE_ERROR;
510 }
511
512 BUG_ON(!raw_pci_ops);
513
514 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400515 PCI_DEVFN(pci_id->device, pci_id->function),
516 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 return (result ? AE_ERROR : AE_OK);
519}
Len Brown4be44fc2005-08-05 00:44:28 -0400520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521EXPORT_SYMBOL(acpi_os_read_pci_configuration);
522
523acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400524acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
525 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526{
527 int result, size;
528
529 switch (width) {
530 case 8:
531 size = 1;
532 break;
533 case 16:
534 size = 2;
535 break;
536 case 32:
537 size = 4;
538 break;
539 default:
540 return AE_ERROR;
541 }
542
543 BUG_ON(!raw_pci_ops);
544
545 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400546 PCI_DEVFN(pci_id->device, pci_id->function),
547 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 return (result ? AE_ERROR : AE_OK);
550}
551
552/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400553static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
554 acpi_handle chandle, /* current node */
555 struct acpi_pci_id **id,
556 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
Len Brown4be44fc2005-08-05 00:44:28 -0400558 acpi_handle handle;
559 struct acpi_pci_id *pci_id = *id;
560 acpi_status status;
561 unsigned long temp;
562 acpi_object_type type;
563 u8 tu8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 acpi_get_parent(chandle, &handle);
566 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400567 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
568 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400571 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 return;
573
Len Brown4be44fc2005-08-05 00:44:28 -0400574 status =
575 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
576 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 if (ACPI_SUCCESS(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400578 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
579 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581 if (*is_bridge)
582 pci_id->bus = *bus_number;
583
584 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400585 status =
586 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
587 8);
588 if (ACPI_SUCCESS(status)
589 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
590 status =
591 acpi_os_read_pci_configuration(pci_id, 0x18,
592 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 if (!ACPI_SUCCESS(status)) {
594 /* Certainly broken... FIX ME */
595 return;
596 }
597 *is_bridge = 1;
598 pci_id->bus = tu8;
Len Brown4be44fc2005-08-05 00:44:28 -0400599 status =
600 acpi_os_read_pci_configuration(pci_id, 0x19,
601 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 if (ACPI_SUCCESS(status)) {
603 *bus_number = tu8;
604 }
605 } else
606 *is_bridge = 0;
607 }
608 }
609}
610
Len Brown4be44fc2005-08-05 00:44:28 -0400611void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
612 acpi_handle chandle, /* current node */
613 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
615 int is_bridge = 1;
616 u8 bus_number = (*id)->bus;
617
618 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
619}
620
Len Brown4be44fc2005-08-05 00:44:28 -0400621#else /*!CONFIG_ACPI_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400624acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id,
625 u32 reg, acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626{
627 return AE_SUPPORT;
628}
629
630acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400631acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id,
632 u32 reg, void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
634 return AE_SUPPORT;
635}
636
Len Brown4be44fc2005-08-05 00:44:28 -0400637void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
638 acpi_handle chandle, /* current node */
639 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640{
641}
642
Len Brown4be44fc2005-08-05 00:44:28 -0400643#endif /*CONFIG_ACPI_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Len Brown4be44fc2005-08-05 00:44:28 -0400645static void acpi_os_execute_deferred(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646{
Len Brown4be44fc2005-08-05 00:44:28 -0400647 struct acpi_os_dpc *dpc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Len Brown4be44fc2005-08-05 00:44:28 -0400649 ACPI_FUNCTION_TRACE("os_execute_deferred");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Len Brown4be44fc2005-08-05 00:44:28 -0400651 dpc = (struct acpi_os_dpc *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if (!dpc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400653 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) context.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 return_VOID;
655 }
656
657 dpc->function(dpc->context);
658
659 kfree(dpc);
660
661 return_VOID;
662}
663
664acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400665acpi_os_queue_for_execution(u32 priority,
666 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667{
Len Brown4be44fc2005-08-05 00:44:28 -0400668 acpi_status status = AE_OK;
669 struct acpi_os_dpc *dpc;
670 struct work_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Len Brown4be44fc2005-08-05 00:44:28 -0400672 ACPI_FUNCTION_TRACE("os_queue_for_execution");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Len Brown4be44fc2005-08-05 00:44:28 -0400674 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
675 "Scheduling function [%p(%p)] for deferred execution.\n",
676 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
678 if (!function)
Len Brown4be44fc2005-08-05 00:44:28 -0400679 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
681 /*
682 * Allocate/initialize DPC structure. Note that this memory will be
683 * freed by the callee. The kernel handles the tq_struct list in a
684 * way that allows us to also free its memory inside the callee.
685 * Because we may want to schedule several tasks with different
686 * parameters we can't use the approach some kernel code uses of
687 * having a static tq_struct.
688 * We can save time and code by allocating the DPC and tq_structs
689 * from the same memory.
690 */
691
Len Brown4be44fc2005-08-05 00:44:28 -0400692 dpc =
693 kmalloc(sizeof(struct acpi_os_dpc) + sizeof(struct work_struct),
694 GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 if (!dpc)
Len Brown4be44fc2005-08-05 00:44:28 -0400696 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
698 dpc->function = function;
699 dpc->context = context;
700
Len Brown4be44fc2005-08-05 00:44:28 -0400701 task = (void *)(dpc + 1);
702 INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
704 if (!queue_work(kacpid_wq, task)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400705 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
706 "Call to queue_work() failed.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 kfree(dpc);
708 status = AE_ERROR;
709 }
710
Len Brown4be44fc2005-08-05 00:44:28 -0400711 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712}
Len Brown4be44fc2005-08-05 00:44:28 -0400713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714EXPORT_SYMBOL(acpi_os_queue_for_execution);
715
Len Brown4be44fc2005-08-05 00:44:28 -0400716void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
718 flush_workqueue(kacpid_wq);
719}
Len Brown4be44fc2005-08-05 00:44:28 -0400720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721EXPORT_SYMBOL(acpi_os_wait_events_complete);
722
723/*
724 * Allocate the memory for a spinlock and initialize it.
725 */
Len Brown4be44fc2005-08-05 00:44:28 -0400726acpi_status acpi_os_create_lock(acpi_handle * out_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727{
728 spinlock_t *lock_ptr;
729
Len Brown4be44fc2005-08-05 00:44:28 -0400730 ACPI_FUNCTION_TRACE("os_create_lock");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
732 lock_ptr = acpi_os_allocate(sizeof(spinlock_t));
733
734 spin_lock_init(lock_ptr);
735
Len Brown4be44fc2005-08-05 00:44:28 -0400736 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating spinlock[%p].\n", lock_ptr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 *out_handle = lock_ptr;
739
Len Brown4be44fc2005-08-05 00:44:28 -0400740 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741}
742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743/*
744 * Deallocate the memory for a spinlock.
745 */
Len Brown4be44fc2005-08-05 00:44:28 -0400746void acpi_os_delete_lock(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
Len Brown4be44fc2005-08-05 00:44:28 -0400748 ACPI_FUNCTION_TRACE("os_create_lock");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Len Brown4be44fc2005-08-05 00:44:28 -0400750 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting spinlock[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
752 acpi_os_free(handle);
753
754 return_VOID;
755}
756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400758acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759{
Len Brown4be44fc2005-08-05 00:44:28 -0400760 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Len Brown4be44fc2005-08-05 00:44:28 -0400762 ACPI_FUNCTION_TRACE("os_create_semaphore");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764 sem = acpi_os_allocate(sizeof(struct semaphore));
765 if (!sem)
Len Brown4be44fc2005-08-05 00:44:28 -0400766 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 memset(sem, 0, sizeof(struct semaphore));
768
769 sema_init(sem, initial_units);
770
Len Brown4be44fc2005-08-05 00:44:28 -0400771 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Len Brown4be44fc2005-08-05 00:44:28 -0400773 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
774 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Len Brown4be44fc2005-08-05 00:44:28 -0400776 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Len Brown4be44fc2005-08-05 00:44:28 -0400779EXPORT_SYMBOL(acpi_os_create_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781/*
782 * TODO: A better way to delete semaphores? Linux doesn't have a
783 * 'delete_semaphore()' function -- may result in an invalid
784 * pointer dereference for non-synchronized consumers. Should
785 * we at least check for blocked threads and signal/cancel them?
786 */
787
Len Brown4be44fc2005-08-05 00:44:28 -0400788acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
Len Brown4be44fc2005-08-05 00:44:28 -0400790 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Len Brown4be44fc2005-08-05 00:44:28 -0400792 ACPI_FUNCTION_TRACE("os_delete_semaphore");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 if (!sem)
Len Brown4be44fc2005-08-05 00:44:28 -0400795 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Len Brown4be44fc2005-08-05 00:44:28 -0400797 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Len Brown4be44fc2005-08-05 00:44:28 -0400799 acpi_os_free(sem);
800 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Len Brown4be44fc2005-08-05 00:44:28 -0400802 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Len Brown4be44fc2005-08-05 00:44:28 -0400805EXPORT_SYMBOL(acpi_os_delete_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
807/*
808 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
809 * improvise. The process is to sleep for one scheduler quantum
810 * until the semaphore becomes available. Downside is that this
811 * may result in starvation for timeout-based waits when there's
812 * lots of semaphore activity.
813 *
814 * TODO: Support for units > 1?
815 */
Len Brown4be44fc2005-08-05 00:44:28 -0400816acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817{
Len Brown4be44fc2005-08-05 00:44:28 -0400818 acpi_status status = AE_OK;
819 struct semaphore *sem = (struct semaphore *)handle;
820 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Len Brown4be44fc2005-08-05 00:44:28 -0400822 ACPI_FUNCTION_TRACE("os_wait_semaphore");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824 if (!sem || (units < 1))
Len Brown4be44fc2005-08-05 00:44:28 -0400825 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 if (units > 1)
Len Brown4be44fc2005-08-05 00:44:28 -0400828 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Len Brown4be44fc2005-08-05 00:44:28 -0400830 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
831 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 if (in_atomic())
834 timeout = 0;
835
Len Brown4be44fc2005-08-05 00:44:28 -0400836 switch (timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 /*
838 * No Wait:
839 * --------
840 * A zero timeout value indicates that we shouldn't wait - just
841 * acquire the semaphore if available otherwise return AE_TIME
842 * (a.k.a. 'would block').
843 */
Len Brown4be44fc2005-08-05 00:44:28 -0400844 case 0:
845 if (down_trylock(sem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 status = AE_TIME;
847 break;
848
849 /*
850 * Wait Indefinitely:
851 * ------------------
852 */
Len Brown4be44fc2005-08-05 00:44:28 -0400853 case ACPI_WAIT_FOREVER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 down(sem);
855 break;
856
857 /*
858 * Wait w/ Timeout:
859 * ----------------
860 */
Len Brown4be44fc2005-08-05 00:44:28 -0400861 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 // TODO: A better timeout algorithm?
863 {
864 int i = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400865 static const int quantum_ms = 1000 / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
867 ret = down_trylock(sem);
868 for (i = timeout; (i > 0 && ret < 0); i -= quantum_ms) {
869 current->state = TASK_INTERRUPTIBLE;
870 schedule_timeout(1);
871 ret = down_trylock(sem);
872 }
Len Brown4be44fc2005-08-05 00:44:28 -0400873
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 if (ret != 0)
875 status = AE_TIME;
876 }
877 break;
878 }
879
880 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400881 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
882 "Failed to acquire semaphore[%p|%d|%d], %s\n",
883 handle, units, timeout,
884 acpi_format_exception(status)));
885 } else {
886 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
887 "Acquired semaphore[%p|%d|%d]\n", handle,
888 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 }
890
Len Brown4be44fc2005-08-05 00:44:28 -0400891 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Len Brown4be44fc2005-08-05 00:44:28 -0400894EXPORT_SYMBOL(acpi_os_wait_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896/*
897 * TODO: Support for units > 1?
898 */
Len Brown4be44fc2005-08-05 00:44:28 -0400899acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
Len Brown4be44fc2005-08-05 00:44:28 -0400901 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Len Brown4be44fc2005-08-05 00:44:28 -0400903 ACPI_FUNCTION_TRACE("os_signal_semaphore");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905 if (!sem || (units < 1))
Len Brown4be44fc2005-08-05 00:44:28 -0400906 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908 if (units > 1)
Len Brown4be44fc2005-08-05 00:44:28 -0400909 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Len Brown4be44fc2005-08-05 00:44:28 -0400911 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
912 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
914 up(sem);
915
Len Brown4be44fc2005-08-05 00:44:28 -0400916 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917}
Len Brown4be44fc2005-08-05 00:44:28 -0400918
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919EXPORT_SYMBOL(acpi_os_signal_semaphore);
920
921#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400922u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923{
924
925#ifdef ENABLE_DEBUGGER
926 if (acpi_in_debugger) {
927 u32 chars;
928
929 kdb_read(buffer, sizeof(line_buf));
930
931 /* remove the CR kdb includes */
932 chars = strlen(buffer) - 1;
933 buffer[chars] = '\0';
934 }
935#endif
936
937 return 0;
938}
Len Brown4be44fc2005-08-05 00:44:28 -0400939#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941/* Assumes no unreadable holes inbetween */
Len Brown4be44fc2005-08-05 00:44:28 -0400942u8 acpi_os_readable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
Len Brown4be44fc2005-08-05 00:44:28 -0400944#if defined(__i386__) || defined(__x86_64__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 char tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400946 return !__get_user(tmp, (char __user *)ptr)
947 && !__get_user(tmp, (char __user *)ptr + len - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948#endif
949 return 1;
950}
951
952#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400953u8 acpi_os_writable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
955 /* could do dummy write (racy) or a kernel page table lookup.
956 The later may be difficult at early boot when kmap doesn't work yet. */
957 return 1;
958}
959#endif
960
Len Brown4be44fc2005-08-05 00:44:28 -0400961u32 acpi_os_get_thread_id(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962{
963 if (!in_atomic())
964 return current->pid;
965
966 return 0;
967}
968
Len Brown4be44fc2005-08-05 00:44:28 -0400969acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970{
Len Brown4be44fc2005-08-05 00:44:28 -0400971 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 case ACPI_SIGNAL_FATAL:
973 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
974 break;
975 case ACPI_SIGNAL_BREAKPOINT:
976 /*
977 * AML Breakpoint
978 * ACPI spec. says to treat it as a NOP unless
979 * you are debugging. So if/when we integrate
980 * AML debugger into the kernel debugger its
981 * hook will go here. But until then it is
982 * not useful to print anything on breakpoints.
983 */
984 break;
985 default:
986 break;
987 }
988
989 return AE_OK;
990}
Len Brown4be44fc2005-08-05 00:44:28 -0400991
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992EXPORT_SYMBOL(acpi_os_signal);
993
Len Brown4be44fc2005-08-05 00:44:28 -0400994static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
996 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400997 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
999 if (!str || !*str)
1000 return 0;
1001
1002 for (; count-- && str && *str; str++) {
1003 if (isalnum(*str) || *str == ' ' || *str == ':')
1004 *p++ = *str;
1005 else if (*str == '\'' || *str == '"')
1006 continue;
1007 else
1008 break;
1009 }
1010 *p = 0;
1011
1012 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001013
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014}
1015
1016__setup("acpi_os_name=", acpi_os_name_setup);
1017
1018/*
1019 * _OSI control
1020 * empty string disables _OSI
1021 * TBD additional string adds to _OSI
1022 */
Len Brown4be44fc2005-08-05 00:44:28 -04001023static int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024{
1025 if (str == NULL || *str == '\0') {
1026 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1027 acpi_gbl_create_osi_method = FALSE;
Len Brown4be44fc2005-08-05 00:44:28 -04001028 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 /* TBD */
Len Brown4be44fc2005-08-05 00:44:28 -04001030 printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n",
1031 str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 }
1033
1034 return 1;
1035}
1036
1037__setup("acpi_osi=", acpi_osi_setup);
1038
1039/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001040static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
1042 printk(KERN_INFO PREFIX "serialize enabled\n");
1043
1044 acpi_gbl_all_methods_serialized = TRUE;
1045
1046 return 1;
1047}
1048
1049__setup("acpi_serialize", acpi_serialize_setup);
1050
1051/*
1052 * Wake and Run-Time GPES are expected to be separate.
1053 * We disable wake-GPEs at run-time to prevent spurious
1054 * interrupts.
1055 *
1056 * However, if a system exists that shares Wake and
1057 * Run-time events on the same GPE this flag is available
1058 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1059 */
Len Brown4be44fc2005-08-05 00:44:28 -04001060static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061{
1062 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1063
1064 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1065
1066 return 1;
1067}
1068
1069__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1070
Len Brown4be44fc2005-08-05 00:44:28 -04001071int __init acpi_hotkey_setup(char *str)
Luming Yufb9802f2005-03-18 18:03:45 -05001072{
1073 acpi_specific_hotkey_enabled = TRUE;
1074 return 1;
1075}
1076
1077__setup("acpi_specific_hotkey", acpi_hotkey_setup);
1078
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079/*
1080 * max_cstate is defined in the base kernel so modules can
1081 * change it w/o depending on the state of the processor module.
1082 */
1083unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
1084
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085EXPORT_SYMBOL(max_cstate);
Robert Moore73459f72005-06-24 00:00:00 -04001086
1087/*
1088 * Acquire a spinlock.
1089 *
1090 * handle is a pointer to the spinlock_t.
1091 * flags is *not* the result of save_flags - it is an ACPI-specific flag variable
1092 * that indicates whether we are at interrupt level.
1093 */
1094
Len Brown4be44fc2005-08-05 00:44:28 -04001095unsigned long acpi_os_acquire_lock(acpi_handle handle)
Robert Moore73459f72005-06-24 00:00:00 -04001096{
1097 unsigned long flags;
Len Brown4be44fc2005-08-05 00:44:28 -04001098 spin_lock_irqsave((spinlock_t *) handle, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001099 return flags;
1100}
1101
1102/*
1103 * Release a spinlock. See above.
1104 */
1105
Len Brown4be44fc2005-08-05 00:44:28 -04001106void acpi_os_release_lock(acpi_handle handle, unsigned long flags)
Robert Moore73459f72005-06-24 00:00:00 -04001107{
Len Brown4be44fc2005-08-05 00:44:28 -04001108 spin_unlock_irqrestore((spinlock_t *) handle, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001109}
1110
Robert Moore73459f72005-06-24 00:00:00 -04001111#ifndef ACPI_USE_LOCAL_CACHE
1112
1113/*******************************************************************************
1114 *
1115 * FUNCTION: acpi_os_create_cache
1116 *
1117 * PARAMETERS: CacheName - Ascii name for the cache
1118 * ObjectSize - Size of each cached object
1119 * MaxDepth - Maximum depth of the cache (in objects)
1120 * ReturnCache - Where the new cache object is returned
1121 *
1122 * RETURN: Status
1123 *
1124 * DESCRIPTION: Create a cache object
1125 *
1126 ******************************************************************************/
1127
1128acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001129acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001130{
Len Brown4be44fc2005-08-05 00:44:28 -04001131 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
Robert Moore73459f72005-06-24 00:00:00 -04001132 return AE_OK;
1133}
1134
1135/*******************************************************************************
1136 *
1137 * FUNCTION: acpi_os_purge_cache
1138 *
1139 * PARAMETERS: Cache - Handle to cache object
1140 *
1141 * RETURN: Status
1142 *
1143 * DESCRIPTION: Free all objects within the requested cache.
1144 *
1145 ******************************************************************************/
1146
Len Brown4be44fc2005-08-05 00:44:28 -04001147acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001148{
Len Brown4be44fc2005-08-05 00:44:28 -04001149 (void)kmem_cache_shrink(cache);
1150 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001151}
1152
1153/*******************************************************************************
1154 *
1155 * FUNCTION: acpi_os_delete_cache
1156 *
1157 * PARAMETERS: Cache - Handle to cache object
1158 *
1159 * RETURN: Status
1160 *
1161 * DESCRIPTION: Free all objects within the requested cache and delete the
1162 * cache object.
1163 *
1164 ******************************************************************************/
1165
Len Brown4be44fc2005-08-05 00:44:28 -04001166acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001167{
Len Brown4be44fc2005-08-05 00:44:28 -04001168 (void)kmem_cache_destroy(cache);
1169 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001170}
1171
1172/*******************************************************************************
1173 *
1174 * FUNCTION: acpi_os_release_object
1175 *
1176 * PARAMETERS: Cache - Handle to cache object
1177 * Object - The object to be released
1178 *
1179 * RETURN: None
1180 *
1181 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1182 * the object is deleted.
1183 *
1184 ******************************************************************************/
1185
Len Brown4be44fc2005-08-05 00:44:28 -04001186acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001187{
Len Brown4be44fc2005-08-05 00:44:28 -04001188 kmem_cache_free(cache, object);
1189 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001190}
1191
1192/*******************************************************************************
1193 *
1194 * FUNCTION: acpi_os_acquire_object
1195 *
1196 * PARAMETERS: Cache - Handle to cache object
1197 * ReturnObject - Where the object is returned
1198 *
1199 * RETURN: Status
1200 *
1201 * DESCRIPTION: Get an object from the specified cache. If cache is empty,
1202 * the object is allocated.
1203 *
1204 ******************************************************************************/
1205
Len Brown4be44fc2005-08-05 00:44:28 -04001206void *acpi_os_acquire_object(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001207{
Len Brown4be44fc2005-08-05 00:44:28 -04001208 void *object = kmem_cache_alloc(cache, GFP_KERNEL);
1209 WARN_ON(!object);
1210 return object;
Robert Moore73459f72005-06-24 00:00:00 -04001211}
1212
1213#endif