blob: 7d4cc122b026a4a98d071a1e1f25f21494d04fa8 [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>
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -040040#include <linux/kthread.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <acpi/acpi.h>
42#include <asm/io.h>
43#include <acpi/acpi_bus.h>
44#include <acpi/processor.h>
45#include <asm/uaccess.h>
46
47#include <linux/efi.h>
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define _COMPONENT ACPI_OS_SERVICES
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("osl")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define PREFIX "ACPI: "
Len Brown4be44fc2005-08-05 00:44:28 -040052struct acpi_os_dpc {
53 acpi_osd_exec_callback function;
54 void *context;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055};
56
57#ifdef CONFIG_ACPI_CUSTOM_DSDT
58#include CONFIG_ACPI_CUSTOM_DSDT_FILE
59#endif
60
61#ifdef ENABLE_DEBUGGER
62#include <linux/kdb.h>
63
64/* stuff for debugger support */
65int acpi_in_debugger;
66EXPORT_SYMBOL(acpi_in_debugger);
67
68extern char line_buf[80];
Len Brown4be44fc2005-08-05 00:44:28 -040069#endif /*ENABLE_DEBUGGER */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Luming Yu30e332f2005-08-12 00:31:00 -040071int acpi_specific_hotkey_enabled = TRUE;
Luming Yufb9802f2005-03-18 18:03:45 -050072EXPORT_SYMBOL(acpi_specific_hotkey_enabled);
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074static unsigned int acpi_irq_irq;
75static acpi_osd_handler acpi_irq_handler;
76static void *acpi_irq_context;
77static struct workqueue_struct *kacpid_wq;
78
Len Brown4be44fc2005-08-05 00:44:28 -040079acpi_status acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 return AE_OK;
82}
83
Len Brown4be44fc2005-08-05 00:44:28 -040084acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
86 /*
87 * Initialize PCI configuration space access, as we'll need to access
88 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
89 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 kacpid_wq = create_singlethread_workqueue("kacpid");
96 BUG_ON(!kacpid_wq);
97
98 return AE_OK;
99}
100
Len Brown4be44fc2005-08-05 00:44:28 -0400101acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
103 if (acpi_irq_handler) {
104 acpi_os_remove_interrupt_handler(acpi_irq_irq,
105 acpi_irq_handler);
106 }
107
108 destroy_workqueue(kacpid_wq);
109
110 return AE_OK;
111}
112
Len Brown4be44fc2005-08-05 00:44:28 -0400113void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
115 va_list args;
116 va_start(args, fmt);
117 acpi_os_vprintf(fmt, args);
118 va_end(args);
119}
Len Brown4be44fc2005-08-05 00:44:28 -0400120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121EXPORT_SYMBOL(acpi_os_printf);
122
Len Brown4be44fc2005-08-05 00:44:28 -0400123void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 vsprintf(buffer, fmt, args);
128
129#ifdef ENABLE_DEBUGGER
130 if (acpi_in_debugger) {
131 kdb_printf("%s", buffer);
132 } else {
133 printk("%s", buffer);
134 }
135#else
136 printk("%s", buffer);
137#endif
138}
139
Thomas Renningera6fc6722006-06-26 23:58:43 -0400140
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;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800161 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
162 addr->pointer.physical = efi.acpi20;
163 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
164 addr->pointer.physical = 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{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800185 if (phys > ULONG_MAX) {
186 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
187 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800189 /*
190 * ioremap checks to ensure this is in reserved space
191 */
192 *virt = ioremap((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 if (!*virt)
195 return AE_NO_MEMORY;
196
197 return AE_OK;
198}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800199EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Len Brown4be44fc2005-08-05 00:44:28 -0400201void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
203 iounmap(virt);
204}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800205EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207#ifdef ACPI_FUTURE_USAGE
208acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400209acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Len Brown4be44fc2005-08-05 00:44:28 -0400211 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 return AE_BAD_PARAMETER;
213
214 *phys = virt_to_phys(virt);
215
216 return AE_OK;
217}
218#endif
219
220#define ACPI_MAX_OVERRIDE_LEN 100
221
222static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
223
224acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400225acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
226 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
228 if (!init_val || !new_val)
229 return AE_BAD_PARAMETER;
230
231 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400232 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400234 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 *new_val = acpi_os_name;
236 }
237
238 return AE_OK;
239}
240
241acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400242acpi_os_table_override(struct acpi_table_header * existing_table,
243 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 if (!existing_table || !new_table)
246 return AE_BAD_PARAMETER;
247
248#ifdef CONFIG_ACPI_CUSTOM_DSDT
249 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400250 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 else
252 *new_table = NULL;
253#else
254 *new_table = NULL;
255#endif
256 return AE_OK;
257}
258
Len Brown4be44fc2005-08-05 00:44:28 -0400259static irqreturn_t acpi_irq(int irq, void *dev_id, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Len Brown4be44fc2005-08-05 00:44:28 -0400261 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
263
264acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400265acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
266 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 unsigned int irq;
269
270 /*
271 * Ignore the GSI from the core, and use the value in our copy of the
272 * FADT. It may not be the same if an interrupt source override exists
273 * for the SCI.
274 */
275 gsi = acpi_fadt.sci_int;
276 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
277 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
278 gsi);
279 return AE_OK;
280 }
281
282 acpi_irq_handler = handler;
283 acpi_irq_context = context;
284 if (request_irq(irq, acpi_irq, SA_SHIRQ, "acpi", acpi_irq)) {
285 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
286 return AE_NOT_ACQUIRED;
287 }
288 acpi_irq_irq = irq;
289
290 return AE_OK;
291}
292
Len Brown4be44fc2005-08-05 00:44:28 -0400293acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 if (irq) {
296 free_irq(irq, acpi_irq);
297 acpi_irq_handler = NULL;
298 acpi_irq_irq = 0;
299 }
300
301 return AE_OK;
302}
303
304/*
305 * Running in interpreter thread context, safe to sleep
306 */
307
Len Brown4be44fc2005-08-05 00:44:28 -0400308void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800310 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
Len Brown4be44fc2005-08-05 00:44:28 -0400312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313EXPORT_SYMBOL(acpi_os_sleep);
314
Len Brown4be44fc2005-08-05 00:44:28 -0400315void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
317 while (us) {
318 u32 delay = 1000;
319
320 if (delay > us)
321 delay = us;
322 udelay(delay);
323 touch_nmi_watchdog();
324 us -= delay;
325 }
326}
Len Brown4be44fc2005-08-05 00:44:28 -0400327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328EXPORT_SYMBOL(acpi_os_stall);
329
330/*
331 * Support ACPI 3.0 AML Timer operand
332 * Returns 64-bit free-running, monotonically increasing timer
333 * with 100ns granularity
334 */
Len Brown4be44fc2005-08-05 00:44:28 -0400335u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
337 static u64 t;
338
339#ifdef CONFIG_HPET
340 /* TBD: use HPET if available */
341#endif
342
343#ifdef CONFIG_X86_PM_TIMER
344 /* TBD: default to PM timer if HPET was not available */
345#endif
346 if (!t)
347 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
348
349 return ++t;
350}
351
Len Brown4be44fc2005-08-05 00:44:28 -0400352acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
354 u32 dummy;
355
356 if (!value)
357 value = &dummy;
358
Len Brown4be44fc2005-08-05 00:44:28 -0400359 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400361 *(u8 *) value = inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 break;
363 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400364 *(u16 *) value = inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 break;
366 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400367 *(u32 *) value = inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 break;
369 default:
370 BUG();
371 }
372
373 return AE_OK;
374}
Len Brown4be44fc2005-08-05 00:44:28 -0400375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376EXPORT_SYMBOL(acpi_os_read_port);
377
Len Brown4be44fc2005-08-05 00:44:28 -0400378acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
Len Brown4be44fc2005-08-05 00:44:28 -0400380 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 case 8:
382 outb(value, port);
383 break;
384 case 16:
385 outw(value, port);
386 break;
387 case 32:
388 outl(value, port);
389 break;
390 default:
391 BUG();
392 }
393
394 return AE_OK;
395}
Len Brown4be44fc2005-08-05 00:44:28 -0400396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397EXPORT_SYMBOL(acpi_os_write_port);
398
399acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400400acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
Len Brown4be44fc2005-08-05 00:44:28 -0400402 u32 dummy;
403 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800405 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 if (!value)
407 value = &dummy;
408
409 switch (width) {
410 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400411 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 break;
413 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400414 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 break;
416 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400417 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 break;
419 default:
420 BUG();
421 }
422
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800423 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 return AE_OK;
426}
427
428acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400429acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Len Brown4be44fc2005-08-05 00:44:28 -0400431 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800433 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 switch (width) {
436 case 8:
437 writeb(value, virt_addr);
438 break;
439 case 16:
440 writew(value, virt_addr);
441 break;
442 case 32:
443 writel(value, virt_addr);
444 break;
445 default:
446 BUG();
447 }
448
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800449 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451 return AE_OK;
452}
453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400455acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
456 void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457{
458 int result, size;
459
460 if (!value)
461 return AE_BAD_PARAMETER;
462
463 switch (width) {
464 case 8:
465 size = 1;
466 break;
467 case 16:
468 size = 2;
469 break;
470 case 32:
471 size = 4;
472 break;
473 default:
474 return AE_ERROR;
475 }
476
477 BUG_ON(!raw_pci_ops);
478
479 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400480 PCI_DEVFN(pci_id->device, pci_id->function),
481 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 return (result ? AE_ERROR : AE_OK);
484}
Len Brown4be44fc2005-08-05 00:44:28 -0400485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486EXPORT_SYMBOL(acpi_os_read_pci_configuration);
487
488acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400489acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
490 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
492 int result, size;
493
494 switch (width) {
495 case 8:
496 size = 1;
497 break;
498 case 16:
499 size = 2;
500 break;
501 case 32:
502 size = 4;
503 break;
504 default:
505 return AE_ERROR;
506 }
507
508 BUG_ON(!raw_pci_ops);
509
510 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400511 PCI_DEVFN(pci_id->device, pci_id->function),
512 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514 return (result ? AE_ERROR : AE_OK);
515}
516
517/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400518static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
519 acpi_handle chandle, /* current node */
520 struct acpi_pci_id **id,
521 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
Len Brown4be44fc2005-08-05 00:44:28 -0400523 acpi_handle handle;
524 struct acpi_pci_id *pci_id = *id;
525 acpi_status status;
526 unsigned long temp;
527 acpi_object_type type;
528 u8 tu8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530 acpi_get_parent(chandle, &handle);
531 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400532 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
533 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400536 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 return;
538
Len Brown4be44fc2005-08-05 00:44:28 -0400539 status =
540 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
541 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 if (ACPI_SUCCESS(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400543 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
544 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 if (*is_bridge)
547 pci_id->bus = *bus_number;
548
549 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400550 status =
551 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
552 8);
553 if (ACPI_SUCCESS(status)
554 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
555 status =
556 acpi_os_read_pci_configuration(pci_id, 0x18,
557 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 if (!ACPI_SUCCESS(status)) {
559 /* Certainly broken... FIX ME */
560 return;
561 }
562 *is_bridge = 1;
563 pci_id->bus = tu8;
Len Brown4be44fc2005-08-05 00:44:28 -0400564 status =
565 acpi_os_read_pci_configuration(pci_id, 0x19,
566 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 if (ACPI_SUCCESS(status)) {
568 *bus_number = tu8;
569 }
570 } else
571 *is_bridge = 0;
572 }
573 }
574}
575
Len Brown4be44fc2005-08-05 00:44:28 -0400576void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
577 acpi_handle chandle, /* current node */
578 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
580 int is_bridge = 1;
581 u8 bus_number = (*id)->bus;
582
583 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
584}
585
Len Brown4be44fc2005-08-05 00:44:28 -0400586static void acpi_os_execute_deferred(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
Len Brown4be44fc2005-08-05 00:44:28 -0400588 struct acpi_os_dpc *dpc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Len Brown4be44fc2005-08-05 00:44:28 -0400590 ACPI_FUNCTION_TRACE("os_execute_deferred");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Len Brown4be44fc2005-08-05 00:44:28 -0400592 dpc = (struct acpi_os_dpc *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 if (!dpc) {
Len Brown64684632006-06-26 23:41:38 -0400594 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 return_VOID;
596 }
597
598 dpc->function(dpc->context);
599
600 kfree(dpc);
601
602 return_VOID;
603}
604
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400605static int acpi_os_execute_thread(void *context)
606{
607 struct acpi_os_dpc *dpc = (struct acpi_os_dpc *)context;
608 if (dpc) {
609 dpc->function(dpc->context);
610 kfree(dpc);
611 }
612 do_exit(0);
613}
614
615/*******************************************************************************
616 *
617 * FUNCTION: acpi_os_execute
618 *
619 * PARAMETERS: Type - Type of the callback
620 * Function - Function to be executed
621 * Context - Function parameters
622 *
623 * RETURN: Status
624 *
625 * DESCRIPTION: Depending on type, either queues function for deferred execution or
626 * immediately executes function on a separate thread.
627 *
628 ******************************************************************************/
629
630acpi_status acpi_os_execute(acpi_execute_type type,
Len Brown4be44fc2005-08-05 00:44:28 -0400631 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632{
Len Brown4be44fc2005-08-05 00:44:28 -0400633 acpi_status status = AE_OK;
634 struct acpi_os_dpc *dpc;
635 struct work_struct *task;
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400636 struct task_struct *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
638 if (!function)
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400639 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 /*
641 * Allocate/initialize DPC structure. Note that this memory will be
642 * freed by the callee. The kernel handles the tq_struct list in a
643 * way that allows us to also free its memory inside the callee.
644 * Because we may want to schedule several tasks with different
645 * parameters we can't use the approach some kernel code uses of
646 * having a static tq_struct.
647 * We can save time and code by allocating the DPC and tq_structs
648 * from the same memory.
649 */
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400650 if (type == OSL_NOTIFY_HANDLER) {
651 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_KERNEL);
652 } else {
653 dpc = kmalloc(sizeof(struct acpi_os_dpc) +
654 sizeof(struct work_struct), GFP_ATOMIC);
655 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 if (!dpc)
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400657 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 dpc->function = function;
659 dpc->context = context;
660
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400661 if (type == OSL_NOTIFY_HANDLER) {
662 p = kthread_create(acpi_os_execute_thread, dpc, "kacpid_notify");
663 if (!IS_ERR(p)) {
664 wake_up_process(p);
665 } else {
666 status = AE_NO_MEMORY;
667 kfree(dpc);
668 }
669 } else {
670 task = (void *)(dpc + 1);
671 INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc);
672 if (!queue_work(kacpid_wq, task)) {
673 status = AE_ERROR;
674 kfree(dpc);
675 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 }
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400677 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
Len Brown4be44fc2005-08-05 00:44:28 -0400679
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400680EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Len Brown4be44fc2005-08-05 00:44:28 -0400682void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683{
684 flush_workqueue(kacpid_wq);
685}
Len Brown4be44fc2005-08-05 00:44:28 -0400686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687EXPORT_SYMBOL(acpi_os_wait_events_complete);
688
689/*
690 * Allocate the memory for a spinlock and initialize it.
691 */
Len Brown4be44fc2005-08-05 00:44:28 -0400692acpi_status acpi_os_create_lock(acpi_handle * out_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
694 spinlock_t *lock_ptr;
695
Len Brown4be44fc2005-08-05 00:44:28 -0400696 ACPI_FUNCTION_TRACE("os_create_lock");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
698 lock_ptr = acpi_os_allocate(sizeof(spinlock_t));
699
700 spin_lock_init(lock_ptr);
701
Len Brown4be44fc2005-08-05 00:44:28 -0400702 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating spinlock[%p].\n", lock_ptr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
704 *out_handle = lock_ptr;
705
Len Brown4be44fc2005-08-05 00:44:28 -0400706 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707}
708
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709/*
710 * Deallocate the memory for a spinlock.
711 */
Len Brown4be44fc2005-08-05 00:44:28 -0400712void acpi_os_delete_lock(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713{
Len Brown4be44fc2005-08-05 00:44:28 -0400714 ACPI_FUNCTION_TRACE("os_create_lock");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Len Brown4be44fc2005-08-05 00:44:28 -0400716 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting spinlock[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
718 acpi_os_free(handle);
719
720 return_VOID;
721}
722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400724acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
Len Brown4be44fc2005-08-05 00:44:28 -0400726 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Len Brown4be44fc2005-08-05 00:44:28 -0400728 ACPI_FUNCTION_TRACE("os_create_semaphore");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 sem = acpi_os_allocate(sizeof(struct semaphore));
731 if (!sem)
Len Brown4be44fc2005-08-05 00:44:28 -0400732 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 memset(sem, 0, sizeof(struct semaphore));
734
735 sema_init(sem, initial_units);
736
Len Brown4be44fc2005-08-05 00:44:28 -0400737 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Len Brown4be44fc2005-08-05 00:44:28 -0400739 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
740 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Len Brown4be44fc2005-08-05 00:44:28 -0400742 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Len Brown4be44fc2005-08-05 00:44:28 -0400745EXPORT_SYMBOL(acpi_os_create_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747/*
748 * TODO: A better way to delete semaphores? Linux doesn't have a
749 * 'delete_semaphore()' function -- may result in an invalid
750 * pointer dereference for non-synchronized consumers. Should
751 * we at least check for blocked threads and signal/cancel them?
752 */
753
Len Brown4be44fc2005-08-05 00:44:28 -0400754acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755{
Len Brown4be44fc2005-08-05 00:44:28 -0400756 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Len Brown4be44fc2005-08-05 00:44:28 -0400758 ACPI_FUNCTION_TRACE("os_delete_semaphore");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760 if (!sem)
Len Brown4be44fc2005-08-05 00:44:28 -0400761 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Len Brown4be44fc2005-08-05 00:44:28 -0400763 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Len Brown4be44fc2005-08-05 00:44:28 -0400765 acpi_os_free(sem);
766 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Len Brown4be44fc2005-08-05 00:44:28 -0400768 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Len Brown4be44fc2005-08-05 00:44:28 -0400771EXPORT_SYMBOL(acpi_os_delete_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773/*
774 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
775 * improvise. The process is to sleep for one scheduler quantum
776 * until the semaphore becomes available. Downside is that this
777 * may result in starvation for timeout-based waits when there's
778 * lots of semaphore activity.
779 *
780 * TODO: Support for units > 1?
781 */
Len Brown4be44fc2005-08-05 00:44:28 -0400782acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783{
Len Brown4be44fc2005-08-05 00:44:28 -0400784 acpi_status status = AE_OK;
785 struct semaphore *sem = (struct semaphore *)handle;
786 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Len Brown4be44fc2005-08-05 00:44:28 -0400788 ACPI_FUNCTION_TRACE("os_wait_semaphore");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 if (!sem || (units < 1))
Len Brown4be44fc2005-08-05 00:44:28 -0400791 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
793 if (units > 1)
Len Brown4be44fc2005-08-05 00:44:28 -0400794 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Len Brown4be44fc2005-08-05 00:44:28 -0400796 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
797 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Len Brown4be44fc2005-08-05 00:44:28 -0400799 switch (timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 /*
801 * No Wait:
802 * --------
803 * A zero timeout value indicates that we shouldn't wait - just
804 * acquire the semaphore if available otherwise return AE_TIME
805 * (a.k.a. 'would block').
806 */
Len Brown4be44fc2005-08-05 00:44:28 -0400807 case 0:
808 if (down_trylock(sem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 status = AE_TIME;
810 break;
811
812 /*
813 * Wait Indefinitely:
814 * ------------------
815 */
Len Brown4be44fc2005-08-05 00:44:28 -0400816 case ACPI_WAIT_FOREVER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 down(sem);
818 break;
819
820 /*
821 * Wait w/ Timeout:
822 * ----------------
823 */
Len Brown4be44fc2005-08-05 00:44:28 -0400824 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 // TODO: A better timeout algorithm?
826 {
827 int i = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400828 static const int quantum_ms = 1000 / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 ret = down_trylock(sem);
Yu Lumingdacd9b82005-12-31 01:45:00 -0500831 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800832 schedule_timeout_interruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 ret = down_trylock(sem);
834 }
Len Brown4be44fc2005-08-05 00:44:28 -0400835
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 if (ret != 0)
837 status = AE_TIME;
838 }
839 break;
840 }
841
842 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400843 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400844 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400845 handle, units, timeout,
846 acpi_format_exception(status)));
847 } else {
848 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400849 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400850 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 }
852
Len Brown4be44fc2005-08-05 00:44:28 -0400853 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Len Brown4be44fc2005-08-05 00:44:28 -0400856EXPORT_SYMBOL(acpi_os_wait_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858/*
859 * TODO: Support for units > 1?
860 */
Len Brown4be44fc2005-08-05 00:44:28 -0400861acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862{
Len Brown4be44fc2005-08-05 00:44:28 -0400863 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Len Brown4be44fc2005-08-05 00:44:28 -0400865 ACPI_FUNCTION_TRACE("os_signal_semaphore");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
867 if (!sem || (units < 1))
Len Brown4be44fc2005-08-05 00:44:28 -0400868 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
870 if (units > 1)
Len Brown4be44fc2005-08-05 00:44:28 -0400871 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Len Brown4be44fc2005-08-05 00:44:28 -0400873 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
874 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
876 up(sem);
877
Len Brown4be44fc2005-08-05 00:44:28 -0400878 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879}
Len Brown4be44fc2005-08-05 00:44:28 -0400880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881EXPORT_SYMBOL(acpi_os_signal_semaphore);
882
883#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400884u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
886
887#ifdef ENABLE_DEBUGGER
888 if (acpi_in_debugger) {
889 u32 chars;
890
891 kdb_read(buffer, sizeof(line_buf));
892
893 /* remove the CR kdb includes */
894 chars = strlen(buffer) - 1;
895 buffer[chars] = '\0';
896 }
897#endif
898
899 return 0;
900}
Len Brown4be44fc2005-08-05 00:44:28 -0400901#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903/* Assumes no unreadable holes inbetween */
Len Brown4be44fc2005-08-05 00:44:28 -0400904u8 acpi_os_readable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Len Brown4be44fc2005-08-05 00:44:28 -0400906#if defined(__i386__) || defined(__x86_64__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 char tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400908 return !__get_user(tmp, (char __user *)ptr)
909 && !__get_user(tmp, (char __user *)ptr + len - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910#endif
911 return 1;
912}
913
914#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400915u8 acpi_os_writable(void *ptr, acpi_size len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916{
917 /* could do dummy write (racy) or a kernel page table lookup.
918 The later may be difficult at early boot when kmap doesn't work yet. */
919 return 1;
920}
921#endif
922
Len Brown4be44fc2005-08-05 00:44:28 -0400923acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924{
Len Brown4be44fc2005-08-05 00:44:28 -0400925 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 case ACPI_SIGNAL_FATAL:
927 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
928 break;
929 case ACPI_SIGNAL_BREAKPOINT:
930 /*
931 * AML Breakpoint
932 * ACPI spec. says to treat it as a NOP unless
933 * you are debugging. So if/when we integrate
934 * AML debugger into the kernel debugger its
935 * hook will go here. But until then it is
936 * not useful to print anything on breakpoints.
937 */
938 break;
939 default:
940 break;
941 }
942
943 return AE_OK;
944}
Len Brown4be44fc2005-08-05 00:44:28 -0400945
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946EXPORT_SYMBOL(acpi_os_signal);
947
Len Brown4be44fc2005-08-05 00:44:28 -0400948static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949{
950 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400951 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
953 if (!str || !*str)
954 return 0;
955
956 for (; count-- && str && *str; str++) {
957 if (isalnum(*str) || *str == ' ' || *str == ':')
958 *p++ = *str;
959 else if (*str == '\'' || *str == '"')
960 continue;
961 else
962 break;
963 }
964 *p = 0;
965
966 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400967
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968}
969
970__setup("acpi_os_name=", acpi_os_name_setup);
971
972/*
973 * _OSI control
974 * empty string disables _OSI
975 * TBD additional string adds to _OSI
976 */
Len Brown4be44fc2005-08-05 00:44:28 -0400977static int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
979 if (str == NULL || *str == '\0') {
980 printk(KERN_INFO PREFIX "_OSI method disabled\n");
981 acpi_gbl_create_osi_method = FALSE;
Len Brown4be44fc2005-08-05 00:44:28 -0400982 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 /* TBD */
Len Brown4be44fc2005-08-05 00:44:28 -0400984 printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n",
985 str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 }
987
988 return 1;
989}
990
991__setup("acpi_osi=", acpi_osi_setup);
992
993/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -0400994static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
996 printk(KERN_INFO PREFIX "serialize enabled\n");
997
998 acpi_gbl_all_methods_serialized = TRUE;
999
1000 return 1;
1001}
1002
1003__setup("acpi_serialize", acpi_serialize_setup);
1004
1005/*
1006 * Wake and Run-Time GPES are expected to be separate.
1007 * We disable wake-GPEs at run-time to prevent spurious
1008 * interrupts.
1009 *
1010 * However, if a system exists that shares Wake and
1011 * Run-time events on the same GPE this flag is available
1012 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1013 */
Len Brown4be44fc2005-08-05 00:44:28 -04001014static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015{
1016 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1017
1018 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1019
1020 return 1;
1021}
1022
1023__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1024
Adrian Bunk8713cbe2005-09-02 17:16:48 -04001025static int __init acpi_hotkey_setup(char *str)
Luming Yufb9802f2005-03-18 18:03:45 -05001026{
Luming Yu30e332f2005-08-12 00:31:00 -04001027 acpi_specific_hotkey_enabled = FALSE;
Luming Yufb9802f2005-03-18 18:03:45 -05001028 return 1;
1029}
1030
Luming Yu30e332f2005-08-12 00:31:00 -04001031__setup("acpi_generic_hotkey", acpi_hotkey_setup);
Luming Yufb9802f2005-03-18 18:03:45 -05001032
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033/*
1034 * max_cstate is defined in the base kernel so modules can
1035 * change it w/o depending on the state of the processor module.
1036 */
1037unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039EXPORT_SYMBOL(max_cstate);
Robert Moore73459f72005-06-24 00:00:00 -04001040
1041/*
1042 * Acquire a spinlock.
1043 *
1044 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001045 */
1046
Bob Mooreb8e4d892006-01-27 16:43:00 -05001047acpi_cpu_flags acpi_os_acquire_lock(acpi_handle handle)
Robert Moore73459f72005-06-24 00:00:00 -04001048{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001049 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -04001050 spin_lock_irqsave((spinlock_t *) handle, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001051 return flags;
1052}
1053
1054/*
1055 * Release a spinlock. See above.
1056 */
1057
Bob Mooreb8e4d892006-01-27 16:43:00 -05001058void acpi_os_release_lock(acpi_handle handle, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001059{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001060 spin_unlock_irqrestore((spinlock_t *) handle, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001061}
1062
Robert Moore73459f72005-06-24 00:00:00 -04001063#ifndef ACPI_USE_LOCAL_CACHE
1064
1065/*******************************************************************************
1066 *
1067 * FUNCTION: acpi_os_create_cache
1068 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001069 * PARAMETERS: name - Ascii name for the cache
1070 * size - Size of each cached object
1071 * depth - Maximum depth of the cache (in objects) <ignored>
1072 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001073 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001074 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001075 *
1076 * DESCRIPTION: Create a cache object
1077 *
1078 ******************************************************************************/
1079
1080acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001081acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001082{
Len Brown4be44fc2005-08-05 00:44:28 -04001083 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
Bob Mooreb229cf92006-04-21 17:15:00 -04001084 if (cache == NULL)
1085 return AE_ERROR;
1086 else
1087 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001088}
1089
1090/*******************************************************************************
1091 *
1092 * FUNCTION: acpi_os_purge_cache
1093 *
1094 * PARAMETERS: Cache - Handle to cache object
1095 *
1096 * RETURN: Status
1097 *
1098 * DESCRIPTION: Free all objects within the requested cache.
1099 *
1100 ******************************************************************************/
1101
Len Brown4be44fc2005-08-05 00:44:28 -04001102acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001103{
Len Brown4be44fc2005-08-05 00:44:28 -04001104 (void)kmem_cache_shrink(cache);
1105 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001106}
1107
1108/*******************************************************************************
1109 *
1110 * FUNCTION: acpi_os_delete_cache
1111 *
1112 * PARAMETERS: Cache - Handle to cache object
1113 *
1114 * RETURN: Status
1115 *
1116 * DESCRIPTION: Free all objects within the requested cache and delete the
1117 * cache object.
1118 *
1119 ******************************************************************************/
1120
Len Brown4be44fc2005-08-05 00:44:28 -04001121acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001122{
Len Brown4be44fc2005-08-05 00:44:28 -04001123 (void)kmem_cache_destroy(cache);
1124 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001125}
1126
1127/*******************************************************************************
1128 *
1129 * FUNCTION: acpi_os_release_object
1130 *
1131 * PARAMETERS: Cache - Handle to cache object
1132 * Object - The object to be released
1133 *
1134 * RETURN: None
1135 *
1136 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1137 * the object is deleted.
1138 *
1139 ******************************************************************************/
1140
Len Brown4be44fc2005-08-05 00:44:28 -04001141acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001142{
Len Brown4be44fc2005-08-05 00:44:28 -04001143 kmem_cache_free(cache, object);
1144 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001145}
1146
1147/*******************************************************************************
1148 *
1149 * FUNCTION: acpi_os_acquire_object
1150 *
1151 * PARAMETERS: Cache - Handle to cache object
1152 * ReturnObject - Where the object is returned
1153 *
1154 * RETURN: Status
1155 *
Bob Moore616861242006-03-17 16:44:00 -05001156 * DESCRIPTION: Return a zero-filled object.
Robert Moore73459f72005-06-24 00:00:00 -04001157 *
1158 ******************************************************************************/
1159
Len Brown4be44fc2005-08-05 00:44:28 -04001160void *acpi_os_acquire_object(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001161{
Bob Moore616861242006-03-17 16:44:00 -05001162 void *object = kmem_cache_zalloc(cache, GFP_KERNEL);
Len Brown4be44fc2005-08-05 00:44:28 -04001163 WARN_ON(!object);
1164 return object;
Robert Moore73459f72005-06-24 00:00:00 -04001165}
1166
Bob Mooreb229cf92006-04-21 17:15:00 -04001167/******************************************************************************
1168 *
1169 * FUNCTION: acpi_os_validate_interface
1170 *
1171 * PARAMETERS: interface - Requested interface to be validated
1172 *
1173 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1174 *
1175 * DESCRIPTION: Match an interface string to the interfaces supported by the
1176 * host. Strings originate from an AML call to the _OSI method.
1177 *
1178 *****************************************************************************/
1179
1180acpi_status
1181acpi_os_validate_interface (char *interface)
1182{
1183
1184 return AE_SUPPORT;
1185}
1186
1187
1188/******************************************************************************
1189 *
1190 * FUNCTION: acpi_os_validate_address
1191 *
1192 * PARAMETERS: space_id - ACPI space ID
1193 * address - Physical address
1194 * length - Address length
1195 *
1196 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1197 * should return AE_AML_ILLEGAL_ADDRESS.
1198 *
1199 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1200 * the addresses accessed by AML operation regions.
1201 *
1202 *****************************************************************************/
1203
1204acpi_status
1205acpi_os_validate_address (
1206 u8 space_id,
1207 acpi_physical_address address,
1208 acpi_size length)
1209{
1210
1211 return AE_OK;
1212}
1213
1214
Robert Moore73459f72005-06-24 00:00:00 -04001215#endif