blob: 20c9a37643c73110f0e18fd5efef989906d2bf14 [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 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
David Shaohua Li11e981f2005-08-03 23:46:33 -0400139extern int acpi_in_resume;
Len Brown4be44fc2005-08-05 00:44:28 -0400140void *acpi_os_allocate(acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
David Shaohua Li11e981f2005-08-03 23:46:33 -0400142 if (acpi_in_resume)
143 return kmalloc(size, GFP_ATOMIC);
144 else
145 return kmalloc(size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
Len Brown4be44fc2005-08-05 00:44:28 -0400148void acpi_os_free(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
150 kfree(ptr);
151}
Len Brown4be44fc2005-08-05 00:44:28 -0400152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153EXPORT_SYMBOL(acpi_os_free);
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
157 if (efi_enabled) {
158 addr->pointer_type = ACPI_PHYSICAL_POINTER;
159 if (efi.acpi20)
160 addr->pointer.physical =
Len Brown4be44fc2005-08-05 00:44:28 -0400161 (acpi_physical_address) virt_to_phys(efi.acpi20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 else if (efi.acpi)
163 addr->pointer.physical =
Len Brown4be44fc2005-08-05 00:44:28 -0400164 (acpi_physical_address) virt_to_phys(efi.acpi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400166 printk(KERN_ERR PREFIX
167 "System description tables not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return AE_NOT_FOUND;
169 }
170 } else {
171 if (ACPI_FAILURE(acpi_find_root_pointer(flags, addr))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400172 printk(KERN_ERR PREFIX
173 "System description tables not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 return AE_NOT_FOUND;
175 }
176 }
177
178 return AE_OK;
179}
180
181acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400182acpi_os_map_memory(acpi_physical_address phys, acpi_size size,
183 void __iomem ** virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
185 if (efi_enabled) {
186 if (EFI_MEMORY_WB & efi_mem_attributes(phys)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400187 *virt = (void __iomem *)phys_to_virt(phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 } else {
189 *virt = ioremap(phys, size);
190 }
191 } else {
192 if (phys > ULONG_MAX) {
193 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
194 return AE_BAD_PARAMETER;
195 }
196 /*
Len Brown4be44fc2005-08-05 00:44:28 -0400197 * ioremap checks to ensure this is in reserved space
198 */
199 *virt = ioremap((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 }
201
202 if (!*virt)
203 return AE_NO_MEMORY;
204
205 return AE_OK;
206}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800207EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Len Brown4be44fc2005-08-05 00:44:28 -0400209void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
211 iounmap(virt);
212}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800213EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
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{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800318 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
Len Brown4be44fc2005-08-05 00:44:28 -0400320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321EXPORT_SYMBOL(acpi_os_sleep);
322
Len Brown4be44fc2005-08-05 00:44:28 -0400323void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
325 while (us) {
326 u32 delay = 1000;
327
328 if (delay > us)
329 delay = us;
330 udelay(delay);
331 touch_nmi_watchdog();
332 us -= delay;
333 }
334}
Len Brown4be44fc2005-08-05 00:44:28 -0400335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336EXPORT_SYMBOL(acpi_os_stall);
337
338/*
339 * Support ACPI 3.0 AML Timer operand
340 * Returns 64-bit free-running, monotonically increasing timer
341 * with 100ns granularity
342 */
Len Brown4be44fc2005-08-05 00:44:28 -0400343u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
345 static u64 t;
346
347#ifdef CONFIG_HPET
348 /* TBD: use HPET if available */
349#endif
350
351#ifdef CONFIG_X86_PM_TIMER
352 /* TBD: default to PM timer if HPET was not available */
353#endif
354 if (!t)
355 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
356
357 return ++t;
358}
359
Len Brown4be44fc2005-08-05 00:44:28 -0400360acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
362 u32 dummy;
363
364 if (!value)
365 value = &dummy;
366
Len Brown4be44fc2005-08-05 00:44:28 -0400367 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400369 *(u8 *) value = inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 break;
371 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400372 *(u16 *) value = inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 break;
374 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400375 *(u32 *) value = inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 break;
377 default:
378 BUG();
379 }
380
381 return AE_OK;
382}
Len Brown4be44fc2005-08-05 00:44:28 -0400383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384EXPORT_SYMBOL(acpi_os_read_port);
385
Len Brown4be44fc2005-08-05 00:44:28 -0400386acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
Len Brown4be44fc2005-08-05 00:44:28 -0400388 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 case 8:
390 outb(value, port);
391 break;
392 case 16:
393 outw(value, port);
394 break;
395 case 32:
396 outl(value, port);
397 break;
398 default:
399 BUG();
400 }
401
402 return AE_OK;
403}
Len Brown4be44fc2005-08-05 00:44:28 -0400404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405EXPORT_SYMBOL(acpi_os_write_port);
406
407acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400408acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
Len Brown4be44fc2005-08-05 00:44:28 -0400410 u32 dummy;
411 void __iomem *virt_addr;
412 int iomem = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 if (efi_enabled) {
415 if (EFI_MEMORY_WB & efi_mem_attributes(phys_addr)) {
416 /* HACK ALERT! We can use readb/w/l on real memory too.. */
Len Brown4be44fc2005-08-05 00:44:28 -0400417 virt_addr = (void __iomem *)phys_to_virt(phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 } else {
419 iomem = 1;
420 virt_addr = ioremap(phys_addr, width);
421 }
422 } else
Len Brown4be44fc2005-08-05 00:44:28 -0400423 virt_addr = (void __iomem *)phys_to_virt(phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 if (!value)
425 value = &dummy;
426
427 switch (width) {
428 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400429 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 break;
431 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400432 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 break;
434 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400435 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 break;
437 default:
438 BUG();
439 }
440
441 if (efi_enabled) {
442 if (iomem)
443 iounmap(virt_addr);
444 }
445
446 return AE_OK;
447}
448
449acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400450acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
Len Brown4be44fc2005-08-05 00:44:28 -0400452 void __iomem *virt_addr;
453 int iomem = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 if (efi_enabled) {
456 if (EFI_MEMORY_WB & efi_mem_attributes(phys_addr)) {
457 /* HACK ALERT! We can use writeb/w/l on real memory too */
Len Brown4be44fc2005-08-05 00:44:28 -0400458 virt_addr = (void __iomem *)phys_to_virt(phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 } else {
460 iomem = 1;
461 virt_addr = ioremap(phys_addr, width);
462 }
463 } else
Len Brown4be44fc2005-08-05 00:44:28 -0400464 virt_addr = (void __iomem *)phys_to_virt(phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466 switch (width) {
467 case 8:
468 writeb(value, virt_addr);
469 break;
470 case 16:
471 writew(value, virt_addr);
472 break;
473 case 32:
474 writel(value, virt_addr);
475 break;
476 default:
477 BUG();
478 }
479
480 if (iomem)
481 iounmap(virt_addr);
482
483 return AE_OK;
484}
485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400487acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
488 void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
490 int result, size;
491
492 if (!value)
493 return AE_BAD_PARAMETER;
494
495 switch (width) {
496 case 8:
497 size = 1;
498 break;
499 case 16:
500 size = 2;
501 break;
502 case 32:
503 size = 4;
504 break;
505 default:
506 return AE_ERROR;
507 }
508
509 BUG_ON(!raw_pci_ops);
510
511 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400512 PCI_DEVFN(pci_id->device, pci_id->function),
513 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 return (result ? AE_ERROR : AE_OK);
516}
Len Brown4be44fc2005-08-05 00:44:28 -0400517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518EXPORT_SYMBOL(acpi_os_read_pci_configuration);
519
520acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400521acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
522 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523{
524 int result, size;
525
526 switch (width) {
527 case 8:
528 size = 1;
529 break;
530 case 16:
531 size = 2;
532 break;
533 case 32:
534 size = 4;
535 break;
536 default:
537 return AE_ERROR;
538 }
539
540 BUG_ON(!raw_pci_ops);
541
542 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400543 PCI_DEVFN(pci_id->device, pci_id->function),
544 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 return (result ? AE_ERROR : AE_OK);
547}
548
549/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400550static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
551 acpi_handle chandle, /* current node */
552 struct acpi_pci_id **id,
553 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554{
Len Brown4be44fc2005-08-05 00:44:28 -0400555 acpi_handle handle;
556 struct acpi_pci_id *pci_id = *id;
557 acpi_status status;
558 unsigned long temp;
559 acpi_object_type type;
560 u8 tu8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562 acpi_get_parent(chandle, &handle);
563 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400564 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
565 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
567 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400568 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 return;
570
Len Brown4be44fc2005-08-05 00:44:28 -0400571 status =
572 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
573 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 if (ACPI_SUCCESS(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400575 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
576 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 if (*is_bridge)
579 pci_id->bus = *bus_number;
580
581 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400582 status =
583 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
584 8);
585 if (ACPI_SUCCESS(status)
586 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
587 status =
588 acpi_os_read_pci_configuration(pci_id, 0x18,
589 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 if (!ACPI_SUCCESS(status)) {
591 /* Certainly broken... FIX ME */
592 return;
593 }
594 *is_bridge = 1;
595 pci_id->bus = tu8;
Len Brown4be44fc2005-08-05 00:44:28 -0400596 status =
597 acpi_os_read_pci_configuration(pci_id, 0x19,
598 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 if (ACPI_SUCCESS(status)) {
600 *bus_number = tu8;
601 }
602 } else
603 *is_bridge = 0;
604 }
605 }
606}
607
Len Brown4be44fc2005-08-05 00:44:28 -0400608void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
609 acpi_handle chandle, /* current node */
610 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
612 int is_bridge = 1;
613 u8 bus_number = (*id)->bus;
614
615 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
616}
617
Len Brown4be44fc2005-08-05 00:44:28 -0400618static void acpi_os_execute_deferred(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
Len Brown4be44fc2005-08-05 00:44:28 -0400620 struct acpi_os_dpc *dpc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Len Brown4be44fc2005-08-05 00:44:28 -0400622 ACPI_FUNCTION_TRACE("os_execute_deferred");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Len Brown4be44fc2005-08-05 00:44:28 -0400624 dpc = (struct acpi_os_dpc *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 if (!dpc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400626 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) context.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 return_VOID;
628 }
629
630 dpc->function(dpc->context);
631
632 kfree(dpc);
633
634 return_VOID;
635}
636
637acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400638acpi_os_queue_for_execution(u32 priority,
639 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640{
Len Brown4be44fc2005-08-05 00:44:28 -0400641 acpi_status status = AE_OK;
642 struct acpi_os_dpc *dpc;
643 struct work_struct *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Len Brown4be44fc2005-08-05 00:44:28 -0400645 ACPI_FUNCTION_TRACE("os_queue_for_execution");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Len Brown4be44fc2005-08-05 00:44:28 -0400647 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
648 "Scheduling function [%p(%p)] for deferred execution.\n",
649 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 if (!function)
Len Brown4be44fc2005-08-05 00:44:28 -0400652 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654 /*
655 * Allocate/initialize DPC structure. Note that this memory will be
656 * freed by the callee. The kernel handles the tq_struct list in a
657 * way that allows us to also free its memory inside the callee.
658 * Because we may want to schedule several tasks with different
659 * parameters we can't use the approach some kernel code uses of
660 * having a static tq_struct.
661 * We can save time and code by allocating the DPC and tq_structs
662 * from the same memory.
663 */
664
Len Brown4be44fc2005-08-05 00:44:28 -0400665 dpc =
666 kmalloc(sizeof(struct acpi_os_dpc) + sizeof(struct work_struct),
667 GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 if (!dpc)
Len Brown4be44fc2005-08-05 00:44:28 -0400669 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671 dpc->function = function;
672 dpc->context = context;
673
Len Brown4be44fc2005-08-05 00:44:28 -0400674 task = (void *)(dpc + 1);
675 INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
677 if (!queue_work(kacpid_wq, task)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400678 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
679 "Call to queue_work() failed.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 kfree(dpc);
681 status = AE_ERROR;
682 }
683
Len Brown4be44fc2005-08-05 00:44:28 -0400684 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685}
Len Brown4be44fc2005-08-05 00:44:28 -0400686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687EXPORT_SYMBOL(acpi_os_queue_for_execution);
688
Len Brown4be44fc2005-08-05 00:44:28 -0400689void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
691 flush_workqueue(kacpid_wq);
692}
Len Brown4be44fc2005-08-05 00:44:28 -0400693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694EXPORT_SYMBOL(acpi_os_wait_events_complete);
695
696/*
697 * Allocate the memory for a spinlock and initialize it.
698 */
Len Brown4be44fc2005-08-05 00:44:28 -0400699acpi_status acpi_os_create_lock(acpi_handle * out_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
701 spinlock_t *lock_ptr;
702
Len Brown4be44fc2005-08-05 00:44:28 -0400703 ACPI_FUNCTION_TRACE("os_create_lock");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
705 lock_ptr = acpi_os_allocate(sizeof(spinlock_t));
706
707 spin_lock_init(lock_ptr);
708
Len Brown4be44fc2005-08-05 00:44:28 -0400709 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating spinlock[%p].\n", lock_ptr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
711 *out_handle = lock_ptr;
712
Len Brown4be44fc2005-08-05 00:44:28 -0400713 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714}
715
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716/*
717 * Deallocate the memory for a spinlock.
718 */
Len Brown4be44fc2005-08-05 00:44:28 -0400719void acpi_os_delete_lock(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720{
Len Brown4be44fc2005-08-05 00:44:28 -0400721 ACPI_FUNCTION_TRACE("os_create_lock");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Len Brown4be44fc2005-08-05 00:44:28 -0400723 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting spinlock[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725 acpi_os_free(handle);
726
727 return_VOID;
728}
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400731acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
Len Brown4be44fc2005-08-05 00:44:28 -0400733 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Len Brown4be44fc2005-08-05 00:44:28 -0400735 ACPI_FUNCTION_TRACE("os_create_semaphore");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 sem = acpi_os_allocate(sizeof(struct semaphore));
738 if (!sem)
Len Brown4be44fc2005-08-05 00:44:28 -0400739 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 memset(sem, 0, sizeof(struct semaphore));
741
742 sema_init(sem, initial_units);
743
Len Brown4be44fc2005-08-05 00:44:28 -0400744 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Len Brown4be44fc2005-08-05 00:44:28 -0400746 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
747 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Len Brown4be44fc2005-08-05 00:44:28 -0400749 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Len Brown4be44fc2005-08-05 00:44:28 -0400752EXPORT_SYMBOL(acpi_os_create_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754/*
755 * TODO: A better way to delete semaphores? Linux doesn't have a
756 * 'delete_semaphore()' function -- may result in an invalid
757 * pointer dereference for non-synchronized consumers. Should
758 * we at least check for blocked threads and signal/cancel them?
759 */
760
Len Brown4be44fc2005-08-05 00:44:28 -0400761acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762{
Len Brown4be44fc2005-08-05 00:44:28 -0400763 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Len Brown4be44fc2005-08-05 00:44:28 -0400765 ACPI_FUNCTION_TRACE("os_delete_semaphore");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
767 if (!sem)
Len Brown4be44fc2005-08-05 00:44:28 -0400768 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Len Brown4be44fc2005-08-05 00:44:28 -0400770 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Len Brown4be44fc2005-08-05 00:44:28 -0400772 acpi_os_free(sem);
773 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Len Brown4be44fc2005-08-05 00:44:28 -0400775 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
Len Brown4be44fc2005-08-05 00:44:28 -0400778EXPORT_SYMBOL(acpi_os_delete_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
780/*
781 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
782 * improvise. The process is to sleep for one scheduler quantum
783 * until the semaphore becomes available. Downside is that this
784 * may result in starvation for timeout-based waits when there's
785 * lots of semaphore activity.
786 *
787 * TODO: Support for units > 1?
788 */
Len Brown4be44fc2005-08-05 00:44:28 -0400789acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790{
Len Brown4be44fc2005-08-05 00:44:28 -0400791 acpi_status status = AE_OK;
792 struct semaphore *sem = (struct semaphore *)handle;
793 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Len Brown4be44fc2005-08-05 00:44:28 -0400795 ACPI_FUNCTION_TRACE("os_wait_semaphore");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 if (!sem || (units < 1))
Len Brown4be44fc2005-08-05 00:44:28 -0400798 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 if (units > 1)
Len Brown4be44fc2005-08-05 00:44:28 -0400801 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Len Brown4be44fc2005-08-05 00:44:28 -0400803 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
804 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 if (in_atomic())
807 timeout = 0;
808
Len Brown4be44fc2005-08-05 00:44:28 -0400809 switch (timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 /*
811 * No Wait:
812 * --------
813 * A zero timeout value indicates that we shouldn't wait - just
814 * acquire the semaphore if available otherwise return AE_TIME
815 * (a.k.a. 'would block').
816 */
Len Brown4be44fc2005-08-05 00:44:28 -0400817 case 0:
818 if (down_trylock(sem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 status = AE_TIME;
820 break;
821
822 /*
823 * Wait Indefinitely:
824 * ------------------
825 */
Len Brown4be44fc2005-08-05 00:44:28 -0400826 case ACPI_WAIT_FOREVER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 down(sem);
828 break;
829
830 /*
831 * Wait w/ Timeout:
832 * ----------------
833 */
Len Brown4be44fc2005-08-05 00:44:28 -0400834 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 // TODO: A better timeout algorithm?
836 {
837 int i = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400838 static const int quantum_ms = 1000 / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 ret = down_trylock(sem);
841 for (i = timeout; (i > 0 && ret < 0); i -= quantum_ms) {
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800842 schedule_timeout_interruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 ret = down_trylock(sem);
844 }
Len Brown4be44fc2005-08-05 00:44:28 -0400845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 if (ret != 0)
847 status = AE_TIME;
848 }
849 break;
850 }
851
852 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400853 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
854 "Failed to acquire semaphore[%p|%d|%d], %s\n",
855 handle, units, timeout,
856 acpi_format_exception(status)));
857 } else {
858 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
859 "Acquired semaphore[%p|%d|%d]\n", handle,
860 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 }
862
Len Brown4be44fc2005-08-05 00:44:28 -0400863 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Len Brown4be44fc2005-08-05 00:44:28 -0400866EXPORT_SYMBOL(acpi_os_wait_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868/*
869 * TODO: Support for units > 1?
870 */
Len Brown4be44fc2005-08-05 00:44:28 -0400871acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872{
Len Brown4be44fc2005-08-05 00:44:28 -0400873 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Len Brown4be44fc2005-08-05 00:44:28 -0400875 ACPI_FUNCTION_TRACE("os_signal_semaphore");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 if (!sem || (units < 1))
Len Brown4be44fc2005-08-05 00:44:28 -0400878 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
880 if (units > 1)
Len Brown4be44fc2005-08-05 00:44:28 -0400881 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
Len Brown4be44fc2005-08-05 00:44:28 -0400883 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
884 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886 up(sem);
887
Len Brown4be44fc2005-08-05 00:44:28 -0400888 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889}
Len Brown4be44fc2005-08-05 00:44:28 -0400890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891EXPORT_SYMBOL(acpi_os_signal_semaphore);
892
893#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400894u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
896
897#ifdef ENABLE_DEBUGGER
898 if (acpi_in_debugger) {
899 u32 chars;
900
901 kdb_read(buffer, sizeof(line_buf));
902
903 /* remove the CR kdb includes */
904 chars = strlen(buffer) - 1;
905 buffer[chars] = '\0';
906 }
907#endif
908
909 return 0;
910}
Len Brown4be44fc2005-08-05 00:44:28 -0400911#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913/* Assumes no unreadable holes inbetween */
Len Brown4be44fc2005-08-05 00:44:28 -0400914u8 acpi_os_readable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Len Brown4be44fc2005-08-05 00:44:28 -0400916#if defined(__i386__) || defined(__x86_64__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 char tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400918 return !__get_user(tmp, (char __user *)ptr)
919 && !__get_user(tmp, (char __user *)ptr + len - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920#endif
921 return 1;
922}
923
924#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400925u8 acpi_os_writable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
927 /* could do dummy write (racy) or a kernel page table lookup.
928 The later may be difficult at early boot when kmap doesn't work yet. */
929 return 1;
930}
931#endif
932
Len Brown4be44fc2005-08-05 00:44:28 -0400933u32 acpi_os_get_thread_id(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
935 if (!in_atomic())
936 return current->pid;
937
938 return 0;
939}
940
Len Brown4be44fc2005-08-05 00:44:28 -0400941acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942{
Len Brown4be44fc2005-08-05 00:44:28 -0400943 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 case ACPI_SIGNAL_FATAL:
945 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
946 break;
947 case ACPI_SIGNAL_BREAKPOINT:
948 /*
949 * AML Breakpoint
950 * ACPI spec. says to treat it as a NOP unless
951 * you are debugging. So if/when we integrate
952 * AML debugger into the kernel debugger its
953 * hook will go here. But until then it is
954 * not useful to print anything on breakpoints.
955 */
956 break;
957 default:
958 break;
959 }
960
961 return AE_OK;
962}
Len Brown4be44fc2005-08-05 00:44:28 -0400963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964EXPORT_SYMBOL(acpi_os_signal);
965
Len Brown4be44fc2005-08-05 00:44:28 -0400966static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967{
968 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400969 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
971 if (!str || !*str)
972 return 0;
973
974 for (; count-- && str && *str; str++) {
975 if (isalnum(*str) || *str == ' ' || *str == ':')
976 *p++ = *str;
977 else if (*str == '\'' || *str == '"')
978 continue;
979 else
980 break;
981 }
982 *p = 0;
983
984 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400985
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986}
987
988__setup("acpi_os_name=", acpi_os_name_setup);
989
990/*
991 * _OSI control
992 * empty string disables _OSI
993 * TBD additional string adds to _OSI
994 */
Len Brown4be44fc2005-08-05 00:44:28 -0400995static int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996{
997 if (str == NULL || *str == '\0') {
998 printk(KERN_INFO PREFIX "_OSI method disabled\n");
999 acpi_gbl_create_osi_method = FALSE;
Len Brown4be44fc2005-08-05 00:44:28 -04001000 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 /* TBD */
Len Brown4be44fc2005-08-05 00:44:28 -04001002 printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n",
1003 str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 }
1005
1006 return 1;
1007}
1008
1009__setup("acpi_osi=", acpi_osi_setup);
1010
1011/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001012static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
1014 printk(KERN_INFO PREFIX "serialize enabled\n");
1015
1016 acpi_gbl_all_methods_serialized = TRUE;
1017
1018 return 1;
1019}
1020
1021__setup("acpi_serialize", acpi_serialize_setup);
1022
1023/*
1024 * Wake and Run-Time GPES are expected to be separate.
1025 * We disable wake-GPEs at run-time to prevent spurious
1026 * interrupts.
1027 *
1028 * However, if a system exists that shares Wake and
1029 * Run-time events on the same GPE this flag is available
1030 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1031 */
Len Brown4be44fc2005-08-05 00:44:28 -04001032static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033{
1034 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1035
1036 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1037
1038 return 1;
1039}
1040
1041__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1042
Adrian Bunk8713cbe2005-09-02 17:16:48 -04001043static int __init acpi_hotkey_setup(char *str)
Luming Yufb9802f2005-03-18 18:03:45 -05001044{
Luming Yu30e332f2005-08-12 00:31:00 -04001045 acpi_specific_hotkey_enabled = FALSE;
Luming Yufb9802f2005-03-18 18:03:45 -05001046 return 1;
1047}
1048
Luming Yu30e332f2005-08-12 00:31:00 -04001049__setup("acpi_generic_hotkey", acpi_hotkey_setup);
Luming Yufb9802f2005-03-18 18:03:45 -05001050
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051/*
1052 * max_cstate is defined in the base kernel so modules can
1053 * change it w/o depending on the state of the processor module.
1054 */
1055unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
1056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057EXPORT_SYMBOL(max_cstate);
Robert Moore73459f72005-06-24 00:00:00 -04001058
1059/*
1060 * Acquire a spinlock.
1061 *
1062 * handle is a pointer to the spinlock_t.
1063 * flags is *not* the result of save_flags - it is an ACPI-specific flag variable
1064 * that indicates whether we are at interrupt level.
1065 */
1066
Len Brown4be44fc2005-08-05 00:44:28 -04001067unsigned long acpi_os_acquire_lock(acpi_handle handle)
Robert Moore73459f72005-06-24 00:00:00 -04001068{
1069 unsigned long flags;
Len Brown4be44fc2005-08-05 00:44:28 -04001070 spin_lock_irqsave((spinlock_t *) handle, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001071 return flags;
1072}
1073
1074/*
1075 * Release a spinlock. See above.
1076 */
1077
Len Brown4be44fc2005-08-05 00:44:28 -04001078void acpi_os_release_lock(acpi_handle handle, unsigned long flags)
Robert Moore73459f72005-06-24 00:00:00 -04001079{
Len Brown4be44fc2005-08-05 00:44:28 -04001080 spin_unlock_irqrestore((spinlock_t *) handle, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001081}
1082
Robert Moore73459f72005-06-24 00:00:00 -04001083#ifndef ACPI_USE_LOCAL_CACHE
1084
1085/*******************************************************************************
1086 *
1087 * FUNCTION: acpi_os_create_cache
1088 *
1089 * PARAMETERS: CacheName - Ascii name for the cache
1090 * ObjectSize - Size of each cached object
1091 * MaxDepth - Maximum depth of the cache (in objects)
1092 * ReturnCache - Where the new cache object is returned
1093 *
1094 * RETURN: Status
1095 *
1096 * DESCRIPTION: Create a cache object
1097 *
1098 ******************************************************************************/
1099
1100acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001101acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001102{
Len Brown4be44fc2005-08-05 00:44:28 -04001103 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
Robert Moore73459f72005-06-24 00:00:00 -04001104 return AE_OK;
1105}
1106
1107/*******************************************************************************
1108 *
1109 * FUNCTION: acpi_os_purge_cache
1110 *
1111 * PARAMETERS: Cache - Handle to cache object
1112 *
1113 * RETURN: Status
1114 *
1115 * DESCRIPTION: Free all objects within the requested cache.
1116 *
1117 ******************************************************************************/
1118
Len Brown4be44fc2005-08-05 00:44:28 -04001119acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001120{
Len Brown4be44fc2005-08-05 00:44:28 -04001121 (void)kmem_cache_shrink(cache);
1122 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001123}
1124
1125/*******************************************************************************
1126 *
1127 * FUNCTION: acpi_os_delete_cache
1128 *
1129 * PARAMETERS: Cache - Handle to cache object
1130 *
1131 * RETURN: Status
1132 *
1133 * DESCRIPTION: Free all objects within the requested cache and delete the
1134 * cache object.
1135 *
1136 ******************************************************************************/
1137
Len Brown4be44fc2005-08-05 00:44:28 -04001138acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001139{
Len Brown4be44fc2005-08-05 00:44:28 -04001140 (void)kmem_cache_destroy(cache);
1141 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001142}
1143
1144/*******************************************************************************
1145 *
1146 * FUNCTION: acpi_os_release_object
1147 *
1148 * PARAMETERS: Cache - Handle to cache object
1149 * Object - The object to be released
1150 *
1151 * RETURN: None
1152 *
1153 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1154 * the object is deleted.
1155 *
1156 ******************************************************************************/
1157
Len Brown4be44fc2005-08-05 00:44:28 -04001158acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001159{
Len Brown4be44fc2005-08-05 00:44:28 -04001160 kmem_cache_free(cache, object);
1161 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001162}
1163
1164/*******************************************************************************
1165 *
1166 * FUNCTION: acpi_os_acquire_object
1167 *
1168 * PARAMETERS: Cache - Handle to cache object
1169 * ReturnObject - Where the object is returned
1170 *
1171 * RETURN: Status
1172 *
1173 * DESCRIPTION: Get an object from the specified cache. If cache is empty,
1174 * the object is allocated.
1175 *
1176 ******************************************************************************/
1177
Len Brown4be44fc2005-08-05 00:44:28 -04001178void *acpi_os_acquire_object(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001179{
Len Brown4be44fc2005-08-05 00:44:28 -04001180 void *object = kmem_cache_alloc(cache, GFP_KERNEL);
1181 WARN_ON(!object);
1182 return object;
Robert Moore73459f72005-06-24 00:00:00 -04001183}
1184
1185#endif