blob: f4760cfa61e18dd63a0128ea39ec7b68607409d1 [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
Len Brownae00d812007-05-29 18:43:33 -040076#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
77static char osi_additional_string[OSI_STRING_LENGTH_MAX];
78
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -070079static void __init acpi_request_region (struct acpi_generic_address *addr,
80 unsigned int length, char *desc)
81{
82 struct resource *res;
83
84 if (!addr->address || !length)
85 return;
86
Len Browneee3c852007-02-03 01:38:16 -050087 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -070088 res = request_region(addr->address, length, desc);
Len Browneee3c852007-02-03 01:38:16 -050089 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -070090 res = request_mem_region(addr->address, length, desc);
91}
92
93static int __init acpi_reserve_resources(void)
94{
Len Browneee3c852007-02-03 01:38:16 -050095 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -070096 "ACPI PM1a_EVT_BLK");
97
Len Browneee3c852007-02-03 01:38:16 -050098 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -070099 "ACPI PM1b_EVT_BLK");
100
Len Browneee3c852007-02-03 01:38:16 -0500101 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700102 "ACPI PM1a_CNT_BLK");
103
Len Browneee3c852007-02-03 01:38:16 -0500104 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700105 "ACPI PM1b_CNT_BLK");
106
Len Browneee3c852007-02-03 01:38:16 -0500107 if (acpi_gbl_FADT.pm_timer_length == 4)
108 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700109
Len Browneee3c852007-02-03 01:38:16 -0500110 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700111 "ACPI PM2_CNT_BLK");
112
113 /* Length of GPE blocks must be a non-negative multiple of 2 */
114
Len Browneee3c852007-02-03 01:38:16 -0500115 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
116 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
117 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700118
Len Browneee3c852007-02-03 01:38:16 -0500119 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
120 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
121 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700122
123 return 0;
124}
125device_initcall(acpi_reserve_resources);
126
Len Brown4be44fc2005-08-05 00:44:28 -0400127acpi_status acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129 return AE_OK;
130}
131
Len Brown4be44fc2005-08-05 00:44:28 -0400132acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
134 /*
135 * Initialize PCI configuration space access, as we'll need to access
136 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
137 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 if (!raw_pci_ops) {
Len Brown4be44fc2005-08-05 00:44:28 -0400139 printk(KERN_ERR PREFIX
140 "Access to PCI configuration space unavailable\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 return AE_NULL_ENTRY;
142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 kacpid_wq = create_singlethread_workqueue("kacpid");
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400144 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 BUG_ON(!kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400146 BUG_ON(!kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 return AE_OK;
148}
149
Len Brown4be44fc2005-08-05 00:44:28 -0400150acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
152 if (acpi_irq_handler) {
153 acpi_os_remove_interrupt_handler(acpi_irq_irq,
154 acpi_irq_handler);
155 }
156
157 destroy_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400158 destroy_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160 return AE_OK;
161}
162
Len Brown4be44fc2005-08-05 00:44:28 -0400163void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
165 va_list args;
166 va_start(args, fmt);
167 acpi_os_vprintf(fmt, args);
168 va_end(args);
169}
Len Brown4be44fc2005-08-05 00:44:28 -0400170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171EXPORT_SYMBOL(acpi_os_printf);
172
Len Brown4be44fc2005-08-05 00:44:28 -0400173void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
175 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 vsprintf(buffer, fmt, args);
178
179#ifdef ENABLE_DEBUGGER
180 if (acpi_in_debugger) {
181 kdb_printf("%s", buffer);
182 } else {
183 printk("%s", buffer);
184 }
185#else
186 printk("%s", buffer);
187#endif
188}
189
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300190acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
192 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800193 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300194 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800195 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300196 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400198 printk(KERN_ERR PREFIX
199 "System description tables not found\n");
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300200 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300202 } else
203 return acpi_find_rsdp();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
205
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300206void __iomem *acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800208 if (phys > ULONG_MAX) {
209 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Randy Dunlap70c08462007-02-13 16:11:36 -0800210 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300212 if (acpi_gbl_permanent_mmap)
213 /*
214 * ioremap checks to ensure this is in reserved space
215 */
216 return ioremap((unsigned long)phys, size);
217 else
218 return __acpi_map_table((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800220EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Len Brown4be44fc2005-08-05 00:44:28 -0400222void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300224 if (acpi_gbl_permanent_mmap) {
225 iounmap(virt);
226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800228EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230#ifdef ACPI_FUTURE_USAGE
231acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400232acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Len Brown4be44fc2005-08-05 00:44:28 -0400234 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 return AE_BAD_PARAMETER;
236
237 *phys = virt_to_phys(virt);
238
239 return AE_OK;
240}
241#endif
242
243#define ACPI_MAX_OVERRIDE_LEN 100
244
245static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
246
247acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400248acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
249 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
251 if (!init_val || !new_val)
252 return AE_BAD_PARAMETER;
253
254 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400255 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400257 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 *new_val = acpi_os_name;
259 }
260
261 return AE_OK;
262}
263
264acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400265acpi_os_table_override(struct acpi_table_header * existing_table,
266 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 if (!existing_table || !new_table)
269 return AE_BAD_PARAMETER;
270
271#ifdef CONFIG_ACPI_CUSTOM_DSDT
272 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400273 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 else
275 *new_table = NULL;
276#else
277 *new_table = NULL;
278#endif
279 return AE_OK;
280}
281
David Howells7d12e782006-10-05 14:55:46 +0100282static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Len Brown4be44fc2005-08-05 00:44:28 -0400284 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
287acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400288acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
289 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
291 unsigned int irq;
292
293 /*
294 * Ignore the GSI from the core, and use the value in our copy of the
295 * FADT. It may not be the same if an interrupt source override exists
296 * for the SCI.
297 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300298 gsi = acpi_gbl_FADT.sci_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
300 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
301 gsi);
302 return AE_OK;
303 }
304
305 acpi_irq_handler = handler;
306 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700307 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
309 return AE_NOT_ACQUIRED;
310 }
311 acpi_irq_irq = irq;
312
313 return AE_OK;
314}
315
Len Brown4be44fc2005-08-05 00:44:28 -0400316acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
318 if (irq) {
319 free_irq(irq, acpi_irq);
320 acpi_irq_handler = NULL;
321 acpi_irq_irq = 0;
322 }
323
324 return AE_OK;
325}
326
327/*
328 * Running in interpreter thread context, safe to sleep
329 */
330
Len Brown4be44fc2005-08-05 00:44:28 -0400331void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800333 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334}
Len Brown4be44fc2005-08-05 00:44:28 -0400335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336EXPORT_SYMBOL(acpi_os_sleep);
337
Len Brown4be44fc2005-08-05 00:44:28 -0400338void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339{
340 while (us) {
341 u32 delay = 1000;
342
343 if (delay > us)
344 delay = us;
345 udelay(delay);
346 touch_nmi_watchdog();
347 us -= delay;
348 }
349}
Len Brown4be44fc2005-08-05 00:44:28 -0400350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351EXPORT_SYMBOL(acpi_os_stall);
352
353/*
354 * Support ACPI 3.0 AML Timer operand
355 * Returns 64-bit free-running, monotonically increasing timer
356 * with 100ns granularity
357 */
Len Brown4be44fc2005-08-05 00:44:28 -0400358u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
360 static u64 t;
361
362#ifdef CONFIG_HPET
363 /* TBD: use HPET if available */
364#endif
365
366#ifdef CONFIG_X86_PM_TIMER
367 /* TBD: default to PM timer if HPET was not available */
368#endif
369 if (!t)
370 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
371
372 return ++t;
373}
374
Len Brown4be44fc2005-08-05 00:44:28 -0400375acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
377 u32 dummy;
378
379 if (!value)
380 value = &dummy;
381
Len Brown4be44fc2005-08-05 00:44:28 -0400382 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400384 *(u8 *) value = inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 break;
386 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400387 *(u16 *) value = inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 break;
389 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400390 *(u32 *) value = inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 break;
392 default:
393 BUG();
394 }
395
396 return AE_OK;
397}
Len Brown4be44fc2005-08-05 00:44:28 -0400398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399EXPORT_SYMBOL(acpi_os_read_port);
400
Len Brown4be44fc2005-08-05 00:44:28 -0400401acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
Len Brown4be44fc2005-08-05 00:44:28 -0400403 switch (width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 case 8:
405 outb(value, port);
406 break;
407 case 16:
408 outw(value, port);
409 break;
410 case 32:
411 outl(value, port);
412 break;
413 default:
414 BUG();
415 }
416
417 return AE_OK;
418}
Len Brown4be44fc2005-08-05 00:44:28 -0400419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420EXPORT_SYMBOL(acpi_os_write_port);
421
422acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400423acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
Len Brown4be44fc2005-08-05 00:44:28 -0400425 u32 dummy;
426 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800428 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 if (!value)
430 value = &dummy;
431
432 switch (width) {
433 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400434 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 break;
436 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400437 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 break;
439 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400440 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 break;
442 default:
443 BUG();
444 }
445
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800446 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 return AE_OK;
449}
450
451acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400452acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
Len Brown4be44fc2005-08-05 00:44:28 -0400454 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800456 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 switch (width) {
459 case 8:
460 writeb(value, virt_addr);
461 break;
462 case 16:
463 writew(value, virt_addr);
464 break;
465 case 32:
466 writel(value, virt_addr);
467 break;
468 default:
469 BUG();
470 }
471
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800472 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474 return AE_OK;
475}
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400478acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
479 void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
481 int result, size;
482
483 if (!value)
484 return AE_BAD_PARAMETER;
485
486 switch (width) {
487 case 8:
488 size = 1;
489 break;
490 case 16:
491 size = 2;
492 break;
493 case 32:
494 size = 4;
495 break;
496 default:
497 return AE_ERROR;
498 }
499
500 BUG_ON(!raw_pci_ops);
501
502 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400503 PCI_DEVFN(pci_id->device, pci_id->function),
504 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 return (result ? AE_ERROR : AE_OK);
507}
Len Brown4be44fc2005-08-05 00:44:28 -0400508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509EXPORT_SYMBOL(acpi_os_read_pci_configuration);
510
511acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400512acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
513 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
515 int result, size;
516
517 switch (width) {
518 case 8:
519 size = 1;
520 break;
521 case 16:
522 size = 2;
523 break;
524 case 32:
525 size = 4;
526 break;
527 default:
528 return AE_ERROR;
529 }
530
531 BUG_ON(!raw_pci_ops);
532
533 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400534 PCI_DEVFN(pci_id->device, pci_id->function),
535 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
537 return (result ? AE_ERROR : AE_OK);
538}
539
540/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400541static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
542 acpi_handle chandle, /* current node */
543 struct acpi_pci_id **id,
544 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
Len Brown4be44fc2005-08-05 00:44:28 -0400546 acpi_handle handle;
547 struct acpi_pci_id *pci_id = *id;
548 acpi_status status;
549 unsigned long temp;
550 acpi_object_type type;
551 u8 tu8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 acpi_get_parent(chandle, &handle);
554 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400555 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
556 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400559 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 return;
561
Len Brown4be44fc2005-08-05 00:44:28 -0400562 status =
563 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
564 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 if (ACPI_SUCCESS(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400566 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
567 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
569 if (*is_bridge)
570 pci_id->bus = *bus_number;
571
572 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400573 status =
574 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
575 8);
576 if (ACPI_SUCCESS(status)
577 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
578 status =
579 acpi_os_read_pci_configuration(pci_id, 0x18,
580 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 if (!ACPI_SUCCESS(status)) {
582 /* Certainly broken... FIX ME */
583 return;
584 }
585 *is_bridge = 1;
586 pci_id->bus = tu8;
Len Brown4be44fc2005-08-05 00:44:28 -0400587 status =
588 acpi_os_read_pci_configuration(pci_id, 0x19,
589 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 if (ACPI_SUCCESS(status)) {
591 *bus_number = tu8;
592 }
593 } else
594 *is_bridge = 0;
595 }
596 }
597}
598
Len Brown4be44fc2005-08-05 00:44:28 -0400599void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
600 acpi_handle chandle, /* current node */
601 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
603 int is_bridge = 1;
604 u8 bus_number = (*id)->bus;
605
606 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
607}
608
David Howells65f27f32006-11-22 14:55:48 +0000609static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
David Howells65f27f32006-11-22 14:55:48 +0000611 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400612 if (!dpc) {
613 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
614 return;
615 }
616
617 dpc->function(dpc->context);
618 kfree(dpc);
619
620 /* Yield cpu to notify thread */
621 cond_resched();
622
623 return;
624}
625
626static void acpi_os_execute_notify(struct work_struct *work)
627{
628 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 if (!dpc) {
Len Brown64684632006-06-26 23:41:38 -0400631 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400632 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 }
634
635 dpc->function(dpc->context);
636
637 kfree(dpc);
638
Patrick Mocheld550d982006-06-27 00:41:40 -0400639 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}
641
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400642/*******************************************************************************
643 *
644 * FUNCTION: acpi_os_execute
645 *
646 * PARAMETERS: Type - Type of the callback
647 * Function - Function to be executed
648 * Context - Function parameters
649 *
650 * RETURN: Status
651 *
652 * DESCRIPTION: Depending on type, either queues function for deferred execution or
653 * immediately executes function on a separate thread.
654 *
655 ******************************************************************************/
656
657acpi_status acpi_os_execute(acpi_execute_type type,
Len Brown4be44fc2005-08-05 00:44:28 -0400658 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659{
Len Brown4be44fc2005-08-05 00:44:28 -0400660 acpi_status status = AE_OK;
661 struct acpi_os_dpc *dpc;
Len Brown72945b22006-07-12 22:46:42 -0400662
Len Brown72945b22006-07-12 22:46:42 -0400663 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
664 "Scheduling function [%p(%p)] for deferred execution.\n",
665 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
667 if (!function)
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400668 return AE_BAD_PARAMETER;
Len Brown72945b22006-07-12 22:46:42 -0400669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 /*
671 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000672 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 * way that allows us to also free its memory inside the callee.
674 * Because we may want to schedule several tasks with different
675 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000676 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 */
Len Brown72945b22006-07-12 22:46:42 -0400678
David Howells65f27f32006-11-22 14:55:48 +0000679 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 if (!dpc)
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800681 return_ACPI_STATUS(AE_NO_MEMORY);
682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 dpc->function = function;
684 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800685
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400686 if (type == OSL_NOTIFY_HANDLER) {
687 INIT_WORK(&dpc->work, acpi_os_execute_notify);
688 if (!queue_work(kacpi_notify_wq, &dpc->work)) {
689 status = AE_ERROR;
690 kfree(dpc);
691 }
692 } else {
693 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
694 if (!queue_work(kacpid_wq, &dpc->work)) {
695 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800696 "Call to queue_work() failed.\n"));
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400697 status = AE_ERROR;
698 kfree(dpc);
699 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800701 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702}
Len Brown4be44fc2005-08-05 00:44:28 -0400703
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400704EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Len Brown4be44fc2005-08-05 00:44:28 -0400706void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
708 flush_workqueue(kacpid_wq);
709}
Len Brown4be44fc2005-08-05 00:44:28 -0400710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711EXPORT_SYMBOL(acpi_os_wait_events_complete);
712
713/*
714 * Allocate the memory for a spinlock and initialize it.
715 */
Bob Moore967440e2006-06-23 17:04:00 -0400716acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
Bob Moore967440e2006-06-23 17:04:00 -0400718 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Patrick Mocheld550d982006-06-27 00:41:40 -0400720 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723/*
724 * Deallocate the memory for a spinlock.
725 */
Bob Moore967440e2006-06-23 17:04:00 -0400726void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727{
Patrick Mocheld550d982006-06-27 00:41:40 -0400728 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729}
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400732acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
Len Brown4be44fc2005-08-05 00:44:28 -0400734 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 sem = acpi_os_allocate(sizeof(struct semaphore));
738 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400739 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 memset(sem, 0, sizeof(struct semaphore));
741
742 sema_init(sem, initial_units);
743
Len Brown4be44fc2005-08-05 00:44:28 -0400744 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Len Brown4be44fc2005-08-05 00:44:28 -0400746 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
747 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Patrick Mocheld550d982006-06-27 00:41:40 -0400749 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Len Brown4be44fc2005-08-05 00:44:28 -0400752EXPORT_SYMBOL(acpi_os_create_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754/*
755 * TODO: A better way to delete semaphores? Linux doesn't have a
756 * 'delete_semaphore()' function -- may result in an invalid
757 * pointer dereference for non-synchronized consumers. Should
758 * we at least check for blocked threads and signal/cancel them?
759 */
760
Len Brown4be44fc2005-08-05 00:44:28 -0400761acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762{
Len Brown4be44fc2005-08-05 00:44:28 -0400763 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
766 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400767 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Len Brown4be44fc2005-08-05 00:44:28 -0400769 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Len Brown02438d82006-06-30 03:19:10 -0400771 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400772 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Patrick Mocheld550d982006-06-27 00:41:40 -0400774 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Len Brown4be44fc2005-08-05 00:44:28 -0400777EXPORT_SYMBOL(acpi_os_delete_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779/*
780 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
781 * improvise. The process is to sleep for one scheduler quantum
782 * until the semaphore becomes available. Downside is that this
783 * may result in starvation for timeout-based waits when there's
784 * lots of semaphore activity.
785 *
786 * TODO: Support for units > 1?
787 */
Len Brown4be44fc2005-08-05 00:44:28 -0400788acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
Len Brown4be44fc2005-08-05 00:44:28 -0400790 acpi_status status = AE_OK;
791 struct semaphore *sem = (struct semaphore *)handle;
792 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400796 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400799 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Len Brown4be44fc2005-08-05 00:44:28 -0400801 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
802 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Len Brownd68909f2006-08-16 19:16:58 -0400804 /*
805 * This can be called during resume with interrupts off.
806 * Like boot-time, we should be single threaded and will
807 * always get the lock if we try -- timeout or not.
808 * If this doesn't succeed, then we will oops courtesy of
809 * might_sleep() in down().
810 */
811 if (!down_trylock(sem))
812 return AE_OK;
813
Len Brown4be44fc2005-08-05 00:44:28 -0400814 switch (timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 /*
816 * No Wait:
817 * --------
818 * A zero timeout value indicates that we shouldn't wait - just
819 * acquire the semaphore if available otherwise return AE_TIME
820 * (a.k.a. 'would block').
821 */
Len Brown4be44fc2005-08-05 00:44:28 -0400822 case 0:
823 if (down_trylock(sem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 status = AE_TIME;
825 break;
826
827 /*
828 * Wait Indefinitely:
829 * ------------------
830 */
Len Brown4be44fc2005-08-05 00:44:28 -0400831 case ACPI_WAIT_FOREVER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 down(sem);
833 break;
834
835 /*
836 * Wait w/ Timeout:
837 * ----------------
838 */
Len Brown4be44fc2005-08-05 00:44:28 -0400839 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 // TODO: A better timeout algorithm?
841 {
842 int i = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400843 static const int quantum_ms = 1000 / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845 ret = down_trylock(sem);
Yu Lumingdacd9b82005-12-31 01:45:00 -0500846 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800847 schedule_timeout_interruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 ret = down_trylock(sem);
849 }
Len Brown4be44fc2005-08-05 00:44:28 -0400850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 if (ret != 0)
852 status = AE_TIME;
853 }
854 break;
855 }
856
857 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400858 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400859 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400860 handle, units, timeout,
861 acpi_format_exception(status)));
862 } else {
863 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400864 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400865 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
867
Patrick Mocheld550d982006-06-27 00:41:40 -0400868 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Len Brown4be44fc2005-08-05 00:44:28 -0400871EXPORT_SYMBOL(acpi_os_wait_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873/*
874 * TODO: Support for units > 1?
875 */
Len Brown4be44fc2005-08-05 00:44:28 -0400876acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
Len Brown4be44fc2005-08-05 00:44:28 -0400878 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
881 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400882 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
884 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400885 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Len Brown4be44fc2005-08-05 00:44:28 -0400887 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
888 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890 up(sem);
891
Patrick Mocheld550d982006-06-27 00:41:40 -0400892 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893}
Len Brown4be44fc2005-08-05 00:44:28 -0400894
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895EXPORT_SYMBOL(acpi_os_signal_semaphore);
896
897#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400898u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
900
901#ifdef ENABLE_DEBUGGER
902 if (acpi_in_debugger) {
903 u32 chars;
904
905 kdb_read(buffer, sizeof(line_buf));
906
907 /* remove the CR kdb includes */
908 chars = strlen(buffer) - 1;
909 buffer[chars] = '\0';
910 }
911#endif
912
913 return 0;
914}
Len Brown4be44fc2005-08-05 00:44:28 -0400915#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Len Brown4be44fc2005-08-05 00:44:28 -0400917acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918{
Len Brown4be44fc2005-08-05 00:44:28 -0400919 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 case ACPI_SIGNAL_FATAL:
921 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
922 break;
923 case ACPI_SIGNAL_BREAKPOINT:
924 /*
925 * AML Breakpoint
926 * ACPI spec. says to treat it as a NOP unless
927 * you are debugging. So if/when we integrate
928 * AML debugger into the kernel debugger its
929 * hook will go here. But until then it is
930 * not useful to print anything on breakpoints.
931 */
932 break;
933 default:
934 break;
935 }
936
937 return AE_OK;
938}
Len Brown4be44fc2005-08-05 00:44:28 -0400939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940EXPORT_SYMBOL(acpi_os_signal);
941
Len Brown4be44fc2005-08-05 00:44:28 -0400942static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
944 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400945 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 if (!str || !*str)
948 return 0;
949
950 for (; count-- && str && *str; str++) {
951 if (isalnum(*str) || *str == ' ' || *str == ':')
952 *p++ = *str;
953 else if (*str == '\'' || *str == '"')
954 continue;
955 else
956 break;
957 }
958 *p = 0;
959
960 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962}
963
964__setup("acpi_os_name=", acpi_os_name_setup);
965
966/*
Len Brownae00d812007-05-29 18:43:33 -0400967 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
968 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 * empty string disables _OSI
Len Brownae00d812007-05-29 18:43:33 -0400970 * string starting with '!' disables that string
971 * otherwise string is added to list, augmenting built-in strings
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 */
Len Brown4be44fc2005-08-05 00:44:28 -0400973static int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974{
975 if (str == NULL || *str == '\0') {
976 printk(KERN_INFO PREFIX "_OSI method disabled\n");
977 acpi_gbl_create_osi_method = FALSE;
Len Brownae00d812007-05-29 18:43:33 -0400978 } else if (*str == '!') {
979 if (acpi_osi_invalidate(++str) == AE_OK)
980 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
981 } else if (*osi_additional_string == '\0') {
982 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
983 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 }
985
986 return 1;
987}
988
989__setup("acpi_osi=", acpi_osi_setup);
990
991/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -0400992static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
994 printk(KERN_INFO PREFIX "serialize enabled\n");
995
996 acpi_gbl_all_methods_serialized = TRUE;
997
998 return 1;
999}
1000
1001__setup("acpi_serialize", acpi_serialize_setup);
1002
1003/*
1004 * Wake and Run-Time GPES are expected to be separate.
1005 * We disable wake-GPEs at run-time to prevent spurious
1006 * interrupts.
1007 *
1008 * However, if a system exists that shares Wake and
1009 * Run-time events on the same GPE this flag is available
1010 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1011 */
Len Brown4be44fc2005-08-05 00:44:28 -04001012static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
1014 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1015
1016 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1017
1018 return 1;
1019}
1020
1021__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1022
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023/*
1024 * max_cstate is defined in the base kernel so modules can
1025 * change it w/o depending on the state of the processor module.
1026 */
1027unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
1028
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029EXPORT_SYMBOL(max_cstate);
Robert Moore73459f72005-06-24 00:00:00 -04001030
1031/*
1032 * Acquire a spinlock.
1033 *
1034 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001035 */
1036
Bob Moore967440e2006-06-23 17:04:00 -04001037acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001038{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001039 acpi_cpu_flags flags;
Bob Moore967440e2006-06-23 17:04:00 -04001040 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001041 return flags;
1042}
1043
1044/*
1045 * Release a spinlock. See above.
1046 */
1047
Bob Moore967440e2006-06-23 17:04:00 -04001048void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001049{
Bob Moore967440e2006-06-23 17:04:00 -04001050 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001051}
1052
Robert Moore73459f72005-06-24 00:00:00 -04001053#ifndef ACPI_USE_LOCAL_CACHE
1054
1055/*******************************************************************************
1056 *
1057 * FUNCTION: acpi_os_create_cache
1058 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001059 * PARAMETERS: name - Ascii name for the cache
1060 * size - Size of each cached object
1061 * depth - Maximum depth of the cache (in objects) <ignored>
1062 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001063 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001064 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001065 *
1066 * DESCRIPTION: Create a cache object
1067 *
1068 ******************************************************************************/
1069
1070acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001071acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001072{
Len Brown4be44fc2005-08-05 00:44:28 -04001073 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001074 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001075 return AE_ERROR;
1076 else
1077 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001078}
1079
1080/*******************************************************************************
1081 *
1082 * FUNCTION: acpi_os_purge_cache
1083 *
1084 * PARAMETERS: Cache - Handle to cache object
1085 *
1086 * RETURN: Status
1087 *
1088 * DESCRIPTION: Free all objects within the requested cache.
1089 *
1090 ******************************************************************************/
1091
Len Brown4be44fc2005-08-05 00:44:28 -04001092acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001093{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001094 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001095 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001096}
1097
1098/*******************************************************************************
1099 *
1100 * FUNCTION: acpi_os_delete_cache
1101 *
1102 * PARAMETERS: Cache - Handle to cache object
1103 *
1104 * RETURN: Status
1105 *
1106 * DESCRIPTION: Free all objects within the requested cache and delete the
1107 * cache object.
1108 *
1109 ******************************************************************************/
1110
Len Brown4be44fc2005-08-05 00:44:28 -04001111acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001112{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001113 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001114 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001115}
1116
1117/*******************************************************************************
1118 *
1119 * FUNCTION: acpi_os_release_object
1120 *
1121 * PARAMETERS: Cache - Handle to cache object
1122 * Object - The object to be released
1123 *
1124 * RETURN: None
1125 *
1126 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1127 * the object is deleted.
1128 *
1129 ******************************************************************************/
1130
Len Brown4be44fc2005-08-05 00:44:28 -04001131acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001132{
Len Brown4be44fc2005-08-05 00:44:28 -04001133 kmem_cache_free(cache, object);
1134 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001135}
1136
Bob Mooreb229cf92006-04-21 17:15:00 -04001137/******************************************************************************
1138 *
1139 * FUNCTION: acpi_os_validate_interface
1140 *
1141 * PARAMETERS: interface - Requested interface to be validated
1142 *
1143 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1144 *
1145 * DESCRIPTION: Match an interface string to the interfaces supported by the
1146 * host. Strings originate from an AML call to the _OSI method.
1147 *
1148 *****************************************************************************/
1149
1150acpi_status
1151acpi_os_validate_interface (char *interface)
1152{
Len Brownae00d812007-05-29 18:43:33 -04001153 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1154 return AE_OK;
1155 return AE_SUPPORT;
Bob Mooreb229cf92006-04-21 17:15:00 -04001156}
1157
Bob Mooreb229cf92006-04-21 17:15:00 -04001158/******************************************************************************
1159 *
1160 * FUNCTION: acpi_os_validate_address
1161 *
1162 * PARAMETERS: space_id - ACPI space ID
1163 * address - Physical address
1164 * length - Address length
1165 *
1166 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1167 * should return AE_AML_ILLEGAL_ADDRESS.
1168 *
1169 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1170 * the addresses accessed by AML operation regions.
1171 *
1172 *****************************************************************************/
1173
1174acpi_status
1175acpi_os_validate_address (
1176 u8 space_id,
1177 acpi_physical_address address,
1178 acpi_size length)
1179{
1180
1181 return AE_OK;
1182}
1183
1184
Robert Moore73459f72005-06-24 00:00:00 -04001185#endif