blob: b998340e23d4126074a36cc1af38d05461b4bde9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * acpi_osl.c - OS-dependent functions ($Revision: 83 $)
3 *
4 * Copyright (C) 2000 Andrew Henroid
5 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 *
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 *
26 */
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/slab.h>
31#include <linux/mm.h>
32#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/interrupt.h>
34#include <linux/kmod.h>
35#include <linux/delay.h>
36#include <linux/workqueue.h>
37#include <linux/nmi.h>
Alexey Starikovskiyad718602007-02-02 19:48:19 +030038#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <acpi/acpi.h>
40#include <asm/io.h>
41#include <acpi/acpi_bus.h>
42#include <acpi/processor.h>
43#include <asm/uaccess.h>
44
45#include <linux/efi.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define _COMPONENT ACPI_OS_SERVICES
Len Brownf52fd662007-02-12 22:42:12 -050048ACPI_MODULE_NAME("osl");
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define PREFIX "ACPI: "
Len Brown4be44fc2005-08-05 00:44:28 -040050struct acpi_os_dpc {
51 acpi_osd_exec_callback function;
52 void *context;
David Howells65f27f32006-11-22 14:55:48 +000053 struct work_struct work;
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
70static unsigned int acpi_irq_irq;
71static acpi_osd_handler acpi_irq_handler;
72static void *acpi_irq_context;
73static struct workqueue_struct *kacpid_wq;
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -040074static struct workqueue_struct *kacpi_notify_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -070076static void __init acpi_request_region (struct acpi_generic_address *addr,
77 unsigned int length, char *desc)
78{
79 struct resource *res;
80
81 if (!addr->address || !length)
82 return;
83
Len Browneee3c852007-02-03 01:38:16 -050084 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -070085 res = request_region(addr->address, length, desc);
Len Browneee3c852007-02-03 01:38:16 -050086 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -070087 res = request_mem_region(addr->address, length, desc);
88}
89
90static int __init acpi_reserve_resources(void)
91{
Len Browneee3c852007-02-03 01:38:16 -050092 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -070093 "ACPI PM1a_EVT_BLK");
94
Len Browneee3c852007-02-03 01:38:16 -050095 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -070096 "ACPI PM1b_EVT_BLK");
97
Len Browneee3c852007-02-03 01:38:16 -050098 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -070099 "ACPI PM1a_CNT_BLK");
100
Len Browneee3c852007-02-03 01:38:16 -0500101 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700102 "ACPI PM1b_CNT_BLK");
103
Len Browneee3c852007-02-03 01:38:16 -0500104 if (acpi_gbl_FADT.pm_timer_length == 4)
105 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700106
Len Browneee3c852007-02-03 01:38:16 -0500107 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700108 "ACPI PM2_CNT_BLK");
109
110 /* Length of GPE blocks must be a non-negative multiple of 2 */
111
Len Browneee3c852007-02-03 01:38:16 -0500112 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
113 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
114 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700115
Len Browneee3c852007-02-03 01:38:16 -0500116 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
117 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
118 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700119
120 return 0;
121}
122device_initcall(acpi_reserve_resources);
123
Len Brown4be44fc2005-08-05 00:44:28 -0400124acpi_status acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
126 return AE_OK;
127}
128
Len Brown4be44fc2005-08-05 00:44:28 -0400129acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
131 /*
132 * Initialize PCI configuration space access, as we'll need to access
133 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
134 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 if (!raw_pci_ops) {
Len Brown4be44fc2005-08-05 00:44:28 -0400136 printk(KERN_ERR PREFIX
137 "Access to PCI configuration space unavailable\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return AE_NULL_ENTRY;
139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 kacpid_wq = create_singlethread_workqueue("kacpid");
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400141 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 BUG_ON(!kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400143 BUG_ON(!kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return AE_OK;
145}
146
Len Brown4be44fc2005-08-05 00:44:28 -0400147acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
149 if (acpi_irq_handler) {
150 acpi_os_remove_interrupt_handler(acpi_irq_irq,
151 acpi_irq_handler);
152 }
153
154 destroy_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400155 destroy_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 return AE_OK;
158}
159
Len Brown4be44fc2005-08-05 00:44:28 -0400160void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
162 va_list args;
163 va_start(args, fmt);
164 acpi_os_vprintf(fmt, args);
165 va_end(args);
166}
Len Brown4be44fc2005-08-05 00:44:28 -0400167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168EXPORT_SYMBOL(acpi_os_printf);
169
Len Brown4be44fc2005-08-05 00:44:28 -0400170void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
172 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 vsprintf(buffer, fmt, args);
175
176#ifdef ENABLE_DEBUGGER
177 if (acpi_in_debugger) {
178 kdb_printf("%s", buffer);
179 } else {
180 printk("%s", buffer);
181 }
182#else
183 printk("%s", buffer);
184#endif
185}
186
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300187acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
189 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800190 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300191 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800192 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300193 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400195 printk(KERN_ERR PREFIX
196 "System description tables not found\n");
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300197 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 }
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300199 } else
200 return acpi_find_rsdp();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
202
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300203void __iomem *acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800205 if (phys > ULONG_MAX) {
206 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Randy Dunlap70c08462007-02-13 16:11:36 -0800207 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 }
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300209 if (acpi_gbl_permanent_mmap)
210 /*
211 * ioremap checks to ensure this is in reserved space
212 */
213 return ioremap((unsigned long)phys, size);
214 else
215 return __acpi_map_table((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800217EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Len Brown4be44fc2005-08-05 00:44:28 -0400219void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300221 if (acpi_gbl_permanent_mmap) {
222 iounmap(virt);
223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800225EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227#ifdef ACPI_FUTURE_USAGE
228acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400229acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Len Brown4be44fc2005-08-05 00:44:28 -0400231 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return AE_BAD_PARAMETER;
233
234 *phys = virt_to_phys(virt);
235
236 return AE_OK;
237}
238#endif
239
240#define ACPI_MAX_OVERRIDE_LEN 100
241
242static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
243
244acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400245acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
246 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
248 if (!init_val || !new_val)
249 return AE_BAD_PARAMETER;
250
251 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400252 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400254 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 *new_val = acpi_os_name;
256 }
257
258 return AE_OK;
259}
260
261acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400262acpi_os_table_override(struct acpi_table_header * existing_table,
263 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
265 if (!existing_table || !new_table)
266 return AE_BAD_PARAMETER;
267
268#ifdef CONFIG_ACPI_CUSTOM_DSDT
269 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400270 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 else
272 *new_table = NULL;
273#else
274 *new_table = NULL;
275#endif
276 return AE_OK;
277}
278
David Howells7d12e782006-10-05 14:55:46 +0100279static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
Len Brown4be44fc2005-08-05 00:44:28 -0400281 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
284acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400285acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
286 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 unsigned int irq;
289
290 /*
291 * Ignore the GSI from the core, and use the value in our copy of the
292 * FADT. It may not be the same if an interrupt source override exists
293 * for the SCI.
294 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300295 gsi = acpi_gbl_FADT.sci_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
297 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
298 gsi);
299 return AE_OK;
300 }
301
302 acpi_irq_handler = handler;
303 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700304 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
306 return AE_NOT_ACQUIRED;
307 }
308 acpi_irq_irq = irq;
309
310 return AE_OK;
311}
312
Len Brown4be44fc2005-08-05 00:44:28 -0400313acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
315 if (irq) {
316 free_irq(irq, acpi_irq);
317 acpi_irq_handler = NULL;
318 acpi_irq_irq = 0;
319 }
320
321 return AE_OK;
322}
323
324/*
325 * Running in interpreter thread context, safe to sleep
326 */
327
Len Brown4be44fc2005-08-05 00:44:28 -0400328void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800330 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331}
Len Brown4be44fc2005-08-05 00:44:28 -0400332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333EXPORT_SYMBOL(acpi_os_sleep);
334
Len Brown4be44fc2005-08-05 00:44:28 -0400335void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
337 while (us) {
338 u32 delay = 1000;
339
340 if (delay > us)
341 delay = us;
342 udelay(delay);
343 touch_nmi_watchdog();
344 us -= delay;
345 }
346}
Len Brown4be44fc2005-08-05 00:44:28 -0400347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348EXPORT_SYMBOL(acpi_os_stall);
349
350/*
351 * Support ACPI 3.0 AML Timer operand
352 * Returns 64-bit free-running, monotonically increasing timer
353 * with 100ns granularity
354 */
Len Brown4be44fc2005-08-05 00:44:28 -0400355u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
357 static u64 t;
358
359#ifdef CONFIG_HPET
360 /* TBD: use HPET if available */
361#endif
362
363#ifdef CONFIG_X86_PM_TIMER
364 /* TBD: default to PM timer if HPET was not available */
365#endif
366 if (!t)
367 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
368
369 return ++t;
370}
371
Len Brown4be44fc2005-08-05 00:44:28 -0400372acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
374 u32 dummy;
375
376 if (!value)
377 value = &dummy;
378
Len Brown4be44fc2005-08-05 00:44:28 -0400379 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400381 *(u8 *) value = inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 break;
383 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400384 *(u16 *) value = inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 break;
386 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400387 *(u32 *) value = inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 break;
389 default:
390 BUG();
391 }
392
393 return AE_OK;
394}
Len Brown4be44fc2005-08-05 00:44:28 -0400395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396EXPORT_SYMBOL(acpi_os_read_port);
397
Len Brown4be44fc2005-08-05 00:44:28 -0400398acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Len Brown4be44fc2005-08-05 00:44:28 -0400400 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 case 8:
402 outb(value, port);
403 break;
404 case 16:
405 outw(value, port);
406 break;
407 case 32:
408 outl(value, port);
409 break;
410 default:
411 BUG();
412 }
413
414 return AE_OK;
415}
Len Brown4be44fc2005-08-05 00:44:28 -0400416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417EXPORT_SYMBOL(acpi_os_write_port);
418
419acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400420acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Len Brown4be44fc2005-08-05 00:44:28 -0400422 u32 dummy;
423 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800425 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 if (!value)
427 value = &dummy;
428
429 switch (width) {
430 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400431 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 break;
433 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400434 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 break;
436 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400437 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 break;
439 default:
440 BUG();
441 }
442
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800443 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445 return AE_OK;
446}
447
448acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400449acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
Len Brown4be44fc2005-08-05 00:44:28 -0400451 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800453 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 switch (width) {
456 case 8:
457 writeb(value, virt_addr);
458 break;
459 case 16:
460 writew(value, virt_addr);
461 break;
462 case 32:
463 writel(value, virt_addr);
464 break;
465 default:
466 BUG();
467 }
468
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800469 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 return AE_OK;
472}
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400475acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
476 void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
478 int result, size;
479
480 if (!value)
481 return AE_BAD_PARAMETER;
482
483 switch (width) {
484 case 8:
485 size = 1;
486 break;
487 case 16:
488 size = 2;
489 break;
490 case 32:
491 size = 4;
492 break;
493 default:
494 return AE_ERROR;
495 }
496
497 BUG_ON(!raw_pci_ops);
498
499 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400500 PCI_DEVFN(pci_id->device, pci_id->function),
501 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 return (result ? AE_ERROR : AE_OK);
504}
Len Brown4be44fc2005-08-05 00:44:28 -0400505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506EXPORT_SYMBOL(acpi_os_read_pci_configuration);
507
508acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400509acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
510 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511{
512 int result, size;
513
514 switch (width) {
515 case 8:
516 size = 1;
517 break;
518 case 16:
519 size = 2;
520 break;
521 case 32:
522 size = 4;
523 break;
524 default:
525 return AE_ERROR;
526 }
527
528 BUG_ON(!raw_pci_ops);
529
530 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400531 PCI_DEVFN(pci_id->device, pci_id->function),
532 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 return (result ? AE_ERROR : AE_OK);
535}
536
537/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400538static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
539 acpi_handle chandle, /* current node */
540 struct acpi_pci_id **id,
541 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Len Brown4be44fc2005-08-05 00:44:28 -0400543 acpi_handle handle;
544 struct acpi_pci_id *pci_id = *id;
545 acpi_status status;
546 unsigned long temp;
547 acpi_object_type type;
548 u8 tu8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 acpi_get_parent(chandle, &handle);
551 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400552 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
553 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400556 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 return;
558
Len Brown4be44fc2005-08-05 00:44:28 -0400559 status =
560 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
561 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (ACPI_SUCCESS(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400563 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
564 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566 if (*is_bridge)
567 pci_id->bus = *bus_number;
568
569 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400570 status =
571 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
572 8);
573 if (ACPI_SUCCESS(status)
574 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
575 status =
576 acpi_os_read_pci_configuration(pci_id, 0x18,
577 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 if (!ACPI_SUCCESS(status)) {
579 /* Certainly broken... FIX ME */
580 return;
581 }
582 *is_bridge = 1;
583 pci_id->bus = tu8;
Len Brown4be44fc2005-08-05 00:44:28 -0400584 status =
585 acpi_os_read_pci_configuration(pci_id, 0x19,
586 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 if (ACPI_SUCCESS(status)) {
588 *bus_number = tu8;
589 }
590 } else
591 *is_bridge = 0;
592 }
593 }
594}
595
Len Brown4be44fc2005-08-05 00:44:28 -0400596void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
597 acpi_handle chandle, /* current node */
598 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
600 int is_bridge = 1;
601 u8 bus_number = (*id)->bus;
602
603 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
604}
605
David Howells65f27f32006-11-22 14:55:48 +0000606static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
David Howells65f27f32006-11-22 14:55:48 +0000608 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400609 if (!dpc) {
610 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
611 return;
612 }
613
614 dpc->function(dpc->context);
615 kfree(dpc);
616
617 /* Yield cpu to notify thread */
618 cond_resched();
619
620 return;
621}
622
623static void acpi_os_execute_notify(struct work_struct *work)
624{
625 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 if (!dpc) {
Len Brown64684632006-06-26 23:41:38 -0400628 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400629 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 }
631
632 dpc->function(dpc->context);
633
634 kfree(dpc);
635
Patrick Mocheld550d982006-06-27 00:41:40 -0400636 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637}
638
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400639/*******************************************************************************
640 *
641 * FUNCTION: acpi_os_execute
642 *
643 * PARAMETERS: Type - Type of the callback
644 * Function - Function to be executed
645 * Context - Function parameters
646 *
647 * RETURN: Status
648 *
649 * DESCRIPTION: Depending on type, either queues function for deferred execution or
650 * immediately executes function on a separate thread.
651 *
652 ******************************************************************************/
653
654acpi_status acpi_os_execute(acpi_execute_type type,
Len Brown4be44fc2005-08-05 00:44:28 -0400655 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
Len Brown4be44fc2005-08-05 00:44:28 -0400657 acpi_status status = AE_OK;
658 struct acpi_os_dpc *dpc;
Len Brown72945b22006-07-12 22:46:42 -0400659
Len Brown72945b22006-07-12 22:46:42 -0400660 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
661 "Scheduling function [%p(%p)] for deferred execution.\n",
662 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 if (!function)
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400665 return AE_BAD_PARAMETER;
Len Brown72945b22006-07-12 22:46:42 -0400666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 /*
668 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000669 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 * way that allows us to also free its memory inside the callee.
671 * Because we may want to schedule several tasks with different
672 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000673 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 */
Len Brown72945b22006-07-12 22:46:42 -0400675
David Howells65f27f32006-11-22 14:55:48 +0000676 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 if (!dpc)
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800678 return_ACPI_STATUS(AE_NO_MEMORY);
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 dpc->function = function;
681 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800682
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400683 if (type == OSL_NOTIFY_HANDLER) {
684 INIT_WORK(&dpc->work, acpi_os_execute_notify);
685 if (!queue_work(kacpi_notify_wq, &dpc->work)) {
686 status = AE_ERROR;
687 kfree(dpc);
688 }
689 } else {
690 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
691 if (!queue_work(kacpid_wq, &dpc->work)) {
692 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800693 "Call to queue_work() failed.\n"));
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400694 status = AE_ERROR;
695 kfree(dpc);
696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 }
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800698 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
Len Brown4be44fc2005-08-05 00:44:28 -0400700
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400701EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Len Brown4be44fc2005-08-05 00:44:28 -0400703void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704{
705 flush_workqueue(kacpid_wq);
706}
Len Brown4be44fc2005-08-05 00:44:28 -0400707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708EXPORT_SYMBOL(acpi_os_wait_events_complete);
709
710/*
711 * Allocate the memory for a spinlock and initialize it.
712 */
Bob Moore967440e2006-06-23 17:04:00 -0400713acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714{
Bob Moore967440e2006-06-23 17:04:00 -0400715 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Patrick Mocheld550d982006-06-27 00:41:40 -0400717 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718}
719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720/*
721 * Deallocate the memory for a spinlock.
722 */
Bob Moore967440e2006-06-23 17:04:00 -0400723void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724{
Patrick Mocheld550d982006-06-27 00:41:40 -0400725 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726}
727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400729acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
Len Brown4be44fc2005-08-05 00:44:28 -0400731 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734 sem = acpi_os_allocate(sizeof(struct semaphore));
735 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400736 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 memset(sem, 0, sizeof(struct semaphore));
738
739 sema_init(sem, initial_units);
740
Len Brown4be44fc2005-08-05 00:44:28 -0400741 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Len Brown4be44fc2005-08-05 00:44:28 -0400743 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
744 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Patrick Mocheld550d982006-06-27 00:41:40 -0400746 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Len Brown4be44fc2005-08-05 00:44:28 -0400749EXPORT_SYMBOL(acpi_os_create_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751/*
752 * TODO: A better way to delete semaphores? Linux doesn't have a
753 * 'delete_semaphore()' function -- may result in an invalid
754 * pointer dereference for non-synchronized consumers. Should
755 * we at least check for blocked threads and signal/cancel them?
756 */
757
Len Brown4be44fc2005-08-05 00:44:28 -0400758acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759{
Len Brown4be44fc2005-08-05 00:44:28 -0400760 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400764 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Len Brown4be44fc2005-08-05 00:44:28 -0400766 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Len Brown02438d82006-06-30 03:19:10 -0400768 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400769 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Patrick Mocheld550d982006-06-27 00:41:40 -0400771 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Len Brown4be44fc2005-08-05 00:44:28 -0400774EXPORT_SYMBOL(acpi_os_delete_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776/*
777 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
778 * improvise. The process is to sleep for one scheduler quantum
779 * until the semaphore becomes available. Downside is that this
780 * may result in starvation for timeout-based waits when there's
781 * lots of semaphore activity.
782 *
783 * TODO: Support for units > 1?
784 */
Len Brown4be44fc2005-08-05 00:44:28 -0400785acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
Len Brown4be44fc2005-08-05 00:44:28 -0400787 acpi_status status = AE_OK;
788 struct semaphore *sem = (struct semaphore *)handle;
789 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
792 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400793 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400796 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Len Brown4be44fc2005-08-05 00:44:28 -0400798 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
799 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Len Brownd68909f2006-08-16 19:16:58 -0400801 /*
802 * This can be called during resume with interrupts off.
803 * Like boot-time, we should be single threaded and will
804 * always get the lock if we try -- timeout or not.
805 * If this doesn't succeed, then we will oops courtesy of
806 * might_sleep() in down().
807 */
808 if (!down_trylock(sem))
809 return AE_OK;
810
Len Brown4be44fc2005-08-05 00:44:28 -0400811 switch (timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 /*
813 * No Wait:
814 * --------
815 * A zero timeout value indicates that we shouldn't wait - just
816 * acquire the semaphore if available otherwise return AE_TIME
817 * (a.k.a. 'would block').
818 */
Len Brown4be44fc2005-08-05 00:44:28 -0400819 case 0:
820 if (down_trylock(sem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 status = AE_TIME;
822 break;
823
824 /*
825 * Wait Indefinitely:
826 * ------------------
827 */
Len Brown4be44fc2005-08-05 00:44:28 -0400828 case ACPI_WAIT_FOREVER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 down(sem);
830 break;
831
832 /*
833 * Wait w/ Timeout:
834 * ----------------
835 */
Len Brown4be44fc2005-08-05 00:44:28 -0400836 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 // TODO: A better timeout algorithm?
838 {
839 int i = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400840 static const int quantum_ms = 1000 / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
842 ret = down_trylock(sem);
Yu Lumingdacd9b82005-12-31 01:45:00 -0500843 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800844 schedule_timeout_interruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 ret = down_trylock(sem);
846 }
Len Brown4be44fc2005-08-05 00:44:28 -0400847
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 if (ret != 0)
849 status = AE_TIME;
850 }
851 break;
852 }
853
854 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400855 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400856 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400857 handle, units, timeout,
858 acpi_format_exception(status)));
859 } else {
860 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400861 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400862 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 }
864
Patrick Mocheld550d982006-06-27 00:41:40 -0400865 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Len Brown4be44fc2005-08-05 00:44:28 -0400868EXPORT_SYMBOL(acpi_os_wait_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
870/*
871 * TODO: Support for units > 1?
872 */
Len Brown4be44fc2005-08-05 00:44:28 -0400873acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
Len Brown4be44fc2005-08-05 00:44:28 -0400875 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400879 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
881 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400882 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Len Brown4be44fc2005-08-05 00:44:28 -0400884 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
885 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 up(sem);
888
Patrick Mocheld550d982006-06-27 00:41:40 -0400889 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890}
Len Brown4be44fc2005-08-05 00:44:28 -0400891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892EXPORT_SYMBOL(acpi_os_signal_semaphore);
893
894#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400895u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896{
897
898#ifdef ENABLE_DEBUGGER
899 if (acpi_in_debugger) {
900 u32 chars;
901
902 kdb_read(buffer, sizeof(line_buf));
903
904 /* remove the CR kdb includes */
905 chars = strlen(buffer) - 1;
906 buffer[chars] = '\0';
907 }
908#endif
909
910 return 0;
911}
Len Brown4be44fc2005-08-05 00:44:28 -0400912#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Len Brown4be44fc2005-08-05 00:44:28 -0400914acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Len Brown4be44fc2005-08-05 00:44:28 -0400916 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 case ACPI_SIGNAL_FATAL:
918 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
919 break;
920 case ACPI_SIGNAL_BREAKPOINT:
921 /*
922 * AML Breakpoint
923 * ACPI spec. says to treat it as a NOP unless
924 * you are debugging. So if/when we integrate
925 * AML debugger into the kernel debugger its
926 * hook will go here. But until then it is
927 * not useful to print anything on breakpoints.
928 */
929 break;
930 default:
931 break;
932 }
933
934 return AE_OK;
935}
Len Brown4be44fc2005-08-05 00:44:28 -0400936
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937EXPORT_SYMBOL(acpi_os_signal);
938
Len Brown4be44fc2005-08-05 00:44:28 -0400939static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940{
941 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400942 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
944 if (!str || !*str)
945 return 0;
946
947 for (; count-- && str && *str; str++) {
948 if (isalnum(*str) || *str == ' ' || *str == ':')
949 *p++ = *str;
950 else if (*str == '\'' || *str == '"')
951 continue;
952 else
953 break;
954 }
955 *p = 0;
956
957 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400958
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959}
960
961__setup("acpi_os_name=", acpi_os_name_setup);
962
963/*
964 * _OSI control
965 * empty string disables _OSI
966 * TBD additional string adds to _OSI
967 */
Len Brown4be44fc2005-08-05 00:44:28 -0400968static int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
970 if (str == NULL || *str == '\0') {
971 printk(KERN_INFO PREFIX "_OSI method disabled\n");
972 acpi_gbl_create_osi_method = FALSE;
Len Brown4be44fc2005-08-05 00:44:28 -0400973 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 /* TBD */
Len Brown4be44fc2005-08-05 00:44:28 -0400975 printk(KERN_ERR PREFIX "_OSI additional string ignored -- %s\n",
976 str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 }
978
979 return 1;
980}
981
982__setup("acpi_osi=", acpi_osi_setup);
983
984/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -0400985static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986{
987 printk(KERN_INFO PREFIX "serialize enabled\n");
988
989 acpi_gbl_all_methods_serialized = TRUE;
990
991 return 1;
992}
993
994__setup("acpi_serialize", acpi_serialize_setup);
995
996/*
997 * Wake and Run-Time GPES are expected to be separate.
998 * We disable wake-GPEs at run-time to prevent spurious
999 * interrupts.
1000 *
1001 * However, if a system exists that shares Wake and
1002 * Run-time events on the same GPE this flag is available
1003 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1004 */
Len Brown4be44fc2005-08-05 00:44:28 -04001005static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006{
1007 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1008
1009 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1010
1011 return 1;
1012}
1013
1014__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1015
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016/*
1017 * max_cstate is defined in the base kernel so modules can
1018 * change it w/o depending on the state of the processor module.
1019 */
1020unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
1021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022EXPORT_SYMBOL(max_cstate);
Robert Moore73459f72005-06-24 00:00:00 -04001023
1024/*
1025 * Acquire a spinlock.
1026 *
1027 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001028 */
1029
Bob Moore967440e2006-06-23 17:04:00 -04001030acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001031{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001032 acpi_cpu_flags flags;
Bob Moore967440e2006-06-23 17:04:00 -04001033 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001034 return flags;
1035}
1036
1037/*
1038 * Release a spinlock. See above.
1039 */
1040
Bob Moore967440e2006-06-23 17:04:00 -04001041void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001042{
Bob Moore967440e2006-06-23 17:04:00 -04001043 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001044}
1045
Robert Moore73459f72005-06-24 00:00:00 -04001046#ifndef ACPI_USE_LOCAL_CACHE
1047
1048/*******************************************************************************
1049 *
1050 * FUNCTION: acpi_os_create_cache
1051 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001052 * PARAMETERS: name - Ascii name for the cache
1053 * size - Size of each cached object
1054 * depth - Maximum depth of the cache (in objects) <ignored>
1055 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001056 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001057 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001058 *
1059 * DESCRIPTION: Create a cache object
1060 *
1061 ******************************************************************************/
1062
1063acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001064acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001065{
Len Brown4be44fc2005-08-05 00:44:28 -04001066 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001067 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001068 return AE_ERROR;
1069 else
1070 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001071}
1072
1073/*******************************************************************************
1074 *
1075 * FUNCTION: acpi_os_purge_cache
1076 *
1077 * PARAMETERS: Cache - Handle to cache object
1078 *
1079 * RETURN: Status
1080 *
1081 * DESCRIPTION: Free all objects within the requested cache.
1082 *
1083 ******************************************************************************/
1084
Len Brown4be44fc2005-08-05 00:44:28 -04001085acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001086{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001087 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001088 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001089}
1090
1091/*******************************************************************************
1092 *
1093 * FUNCTION: acpi_os_delete_cache
1094 *
1095 * PARAMETERS: Cache - Handle to cache object
1096 *
1097 * RETURN: Status
1098 *
1099 * DESCRIPTION: Free all objects within the requested cache and delete the
1100 * cache object.
1101 *
1102 ******************************************************************************/
1103
Len Brown4be44fc2005-08-05 00:44:28 -04001104acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001105{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001106 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001107 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001108}
1109
1110/*******************************************************************************
1111 *
1112 * FUNCTION: acpi_os_release_object
1113 *
1114 * PARAMETERS: Cache - Handle to cache object
1115 * Object - The object to be released
1116 *
1117 * RETURN: None
1118 *
1119 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1120 * the object is deleted.
1121 *
1122 ******************************************************************************/
1123
Len Brown4be44fc2005-08-05 00:44:28 -04001124acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001125{
Len Brown4be44fc2005-08-05 00:44:28 -04001126 kmem_cache_free(cache, object);
1127 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001128}
1129
Bob Mooreb229cf92006-04-21 17:15:00 -04001130/******************************************************************************
1131 *
1132 * FUNCTION: acpi_os_validate_interface
1133 *
1134 * PARAMETERS: interface - Requested interface to be validated
1135 *
1136 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1137 *
1138 * DESCRIPTION: Match an interface string to the interfaces supported by the
1139 * host. Strings originate from an AML call to the _OSI method.
1140 *
1141 *****************************************************************************/
1142
1143acpi_status
1144acpi_os_validate_interface (char *interface)
1145{
1146
1147 return AE_SUPPORT;
1148}
1149
1150
1151/******************************************************************************
1152 *
1153 * FUNCTION: acpi_os_validate_address
1154 *
1155 * PARAMETERS: space_id - ACPI space ID
1156 * address - Physical address
1157 * length - Address length
1158 *
1159 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1160 * should return AE_AML_ILLEGAL_ADDRESS.
1161 *
1162 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1163 * the addresses accessed by AML operation regions.
1164 *
1165 *****************************************************************************/
1166
1167acpi_status
1168acpi_os_validate_address (
1169 u8 space_id,
1170 acpi_physical_address address,
1171 acpi_size length)
1172{
1173
1174 return AE_OK;
1175}
1176
1177
Robert Moore73459f72005-06-24 00:00:00 -04001178#endif