blob: fc6c5d21c3eb315f8b3311ee963edce81b2610f5 [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>
Matthew Wilcoxf1241c82008-03-14 13:43:13 -04007 * Copyright (c) 2008 Intel Corporation
8 * Author: Matthew Wilcox <willy@linux.intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 *
28 */
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/slab.h>
33#include <linux/mm.h>
34#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/interrupt.h>
36#include <linux/kmod.h>
37#include <linux/delay.h>
38#include <linux/workqueue.h>
39#include <linux/nmi.h>
Alexey Starikovskiyad718602007-02-02 19:48:19 +030040#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/efi.h>
Thomas Renningerdf92e692008-02-04 23:31:22 -080042#include <linux/ioport.h>
43#include <linux/list.h>
Matthew Wilcoxf1241c82008-03-14 13:43:13 -040044#include <linux/jiffies.h>
45#include <linux/semaphore.h>
46
47#include <asm/io.h>
48#include <asm/uaccess.h>
49
50#include <acpi/acpi.h>
51#include <acpi/acpi_bus.h>
52#include <acpi/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#define _COMPONENT ACPI_OS_SERVICES
Len Brownf52fd662007-02-12 22:42:12 -050055ACPI_MODULE_NAME("osl");
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#define PREFIX "ACPI: "
Len Brown4be44fc2005-08-05 00:44:28 -040057struct acpi_os_dpc {
58 acpi_osd_exec_callback function;
59 void *context;
David Howells65f27f32006-11-22 14:55:48 +000060 struct work_struct work;
Bjorn Helgaas9ac61852009-08-31 22:32:10 +000061 int wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062};
63
64#ifdef CONFIG_ACPI_CUSTOM_DSDT
65#include CONFIG_ACPI_CUSTOM_DSDT_FILE
66#endif
67
68#ifdef ENABLE_DEBUGGER
69#include <linux/kdb.h>
70
71/* stuff for debugger support */
72int acpi_in_debugger;
73EXPORT_SYMBOL(acpi_in_debugger);
74
75extern char line_buf[80];
Len Brown4be44fc2005-08-05 00:44:28 -040076#endif /*ENABLE_DEBUGGER */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78static unsigned int acpi_irq_irq;
79static acpi_osd_handler acpi_irq_handler;
80static void *acpi_irq_context;
81static struct workqueue_struct *kacpid_wq;
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -040082static struct workqueue_struct *kacpi_notify_wq;
Zhang Ruic02256b2009-06-23 10:20:29 +080083static struct workqueue_struct *kacpi_hotplug_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Thomas Renningerdf92e692008-02-04 23:31:22 -080085struct acpi_res_list {
86 resource_size_t start;
87 resource_size_t end;
88 acpi_adr_space_type resource_type; /* IO port, System memory, ...*/
89 char name[5]; /* only can have a length of 4 chars, make use of this
90 one instead of res->name, no need to kalloc then */
91 struct list_head resource_list;
Lin Minga5fe1a02009-08-13 10:43:27 +080092 int count;
Thomas Renningerdf92e692008-02-04 23:31:22 -080093};
94
95static LIST_HEAD(resource_list_head);
96static DEFINE_SPINLOCK(acpi_res_lock);
97
Myron Stowe620242a2010-10-21 14:23:53 -060098/*
99 * This list of permanent mappings is for memory that may be accessed from
100 * interrupt context, where we can't do the ioremap().
101 */
102struct acpi_ioremap {
103 struct list_head list;
104 void __iomem *virt;
105 acpi_physical_address phys;
106 acpi_size size;
107};
108
109static LIST_HEAD(acpi_ioremaps);
110static DEFINE_SPINLOCK(acpi_ioremap_lock);
111
Len Brownae00d812007-05-29 18:43:33 -0400112#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
113static char osi_additional_string[OSI_STRING_LENGTH_MAX];
114
Len Brownd4b7dc42008-01-23 20:50:56 -0500115/*
Len Browna6e08872008-11-08 01:21:10 -0500116 * The story of _OSI(Linux)
Len Brownd4b7dc42008-01-23 20:50:56 -0500117 *
Len Browna6e08872008-11-08 01:21:10 -0500118 * From pre-history through Linux-2.6.22,
119 * Linux responded TRUE upon a BIOS OSI(Linux) query.
Len Brownd4b7dc42008-01-23 20:50:56 -0500120 *
Len Browna6e08872008-11-08 01:21:10 -0500121 * Unfortunately, reference BIOS writers got wind of this
122 * and put OSI(Linux) in their example code, quickly exposing
123 * this string as ill-conceived and opening the door to
124 * an un-bounded number of BIOS incompatibilities.
Len Brownd4b7dc42008-01-23 20:50:56 -0500125 *
Len Browna6e08872008-11-08 01:21:10 -0500126 * For example, OSI(Linux) was used on resume to re-POST a
127 * video card on one system, because Linux at that time
128 * could not do a speedy restore in its native driver.
129 * But then upon gaining quick native restore capability,
130 * Linux has no way to tell the BIOS to skip the time-consuming
131 * POST -- putting Linux at a permanent performance disadvantage.
132 * On another system, the BIOS writer used OSI(Linux)
133 * to infer native OS support for IPMI! On other systems,
134 * OSI(Linux) simply got in the way of Linux claiming to
135 * be compatible with other operating systems, exposing
136 * BIOS issues such as skipped device initialization.
Len Brownd4b7dc42008-01-23 20:50:56 -0500137 *
Len Browna6e08872008-11-08 01:21:10 -0500138 * So "Linux" turned out to be a really poor chose of
139 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
Len Brownd4b7dc42008-01-23 20:50:56 -0500140 *
141 * BIOS writers should NOT query _OSI(Linux) on future systems.
Len Browna6e08872008-11-08 01:21:10 -0500142 * Linux will complain on the console when it sees it, and return FALSE.
143 * To get Linux to return TRUE for your system will require
144 * a kernel source update to add a DMI entry,
145 * or boot with "acpi_osi=Linux"
Len Brownd4b7dc42008-01-23 20:50:56 -0500146 */
Len Brownd4b7dc42008-01-23 20:50:56 -0500147
Adrian Bunk1d15d842008-01-29 00:10:15 +0200148static struct osi_linux {
Len Brownd4b7dc42008-01-23 20:50:56 -0500149 unsigned int enable:1;
150 unsigned int dmi:1;
151 unsigned int cmdline:1;
152 unsigned int known:1;
Len Browna6e08872008-11-08 01:21:10 -0500153} osi_linux = { 0, 0, 0, 0};
Len Brownf5076542007-05-30 00:10:38 -0400154
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700155static void __init acpi_request_region (struct acpi_generic_address *addr,
156 unsigned int length, char *desc)
157{
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700158 if (!addr->address || !length)
159 return;
160
Andi Kleencfa806f2010-07-20 15:18:36 -0700161 /* Resources are never freed */
Len Browneee3c852007-02-03 01:38:16 -0500162 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Andi Kleencfa806f2010-07-20 15:18:36 -0700163 request_region(addr->address, length, desc);
Len Browneee3c852007-02-03 01:38:16 -0500164 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Andi Kleencfa806f2010-07-20 15:18:36 -0700165 request_mem_region(addr->address, length, desc);
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700166}
167
168static int __init acpi_reserve_resources(void)
169{
Len Browneee3c852007-02-03 01:38:16 -0500170 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700171 "ACPI PM1a_EVT_BLK");
172
Len Browneee3c852007-02-03 01:38:16 -0500173 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700174 "ACPI PM1b_EVT_BLK");
175
Len Browneee3c852007-02-03 01:38:16 -0500176 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700177 "ACPI PM1a_CNT_BLK");
178
Len Browneee3c852007-02-03 01:38:16 -0500179 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700180 "ACPI PM1b_CNT_BLK");
181
Len Browneee3c852007-02-03 01:38:16 -0500182 if (acpi_gbl_FADT.pm_timer_length == 4)
183 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700184
Len Browneee3c852007-02-03 01:38:16 -0500185 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700186 "ACPI PM2_CNT_BLK");
187
188 /* Length of GPE blocks must be a non-negative multiple of 2 */
189
Len Browneee3c852007-02-03 01:38:16 -0500190 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
191 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
192 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700193
Len Browneee3c852007-02-03 01:38:16 -0500194 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
195 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
196 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700197
198 return 0;
199}
200device_initcall(acpi_reserve_resources);
201
Len Browndd272b52007-05-30 00:26:11 -0400202acpi_status __init acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
204 return AE_OK;
205}
206
Len Brown4be44fc2005-08-05 00:44:28 -0400207acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Tejun Heo8fec62b2010-06-29 10:07:09 +0200209 kacpid_wq = create_workqueue("kacpid");
210 kacpi_notify_wq = create_workqueue("kacpi_notify");
211 kacpi_hotplug_wq = create_workqueue("kacpi_hotplug");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 BUG_ON(!kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400213 BUG_ON(!kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800214 BUG_ON(!kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 return AE_OK;
216}
217
Len Brown4be44fc2005-08-05 00:44:28 -0400218acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
220 if (acpi_irq_handler) {
221 acpi_os_remove_interrupt_handler(acpi_irq_irq,
222 acpi_irq_handler);
223 }
224
225 destroy_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400226 destroy_workqueue(kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800227 destroy_workqueue(kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 return AE_OK;
230}
231
Len Brown4be44fc2005-08-05 00:44:28 -0400232void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
234 va_list args;
235 va_start(args, fmt);
236 acpi_os_vprintf(fmt, args);
237 va_end(args);
238}
Len Brown4be44fc2005-08-05 00:44:28 -0400239
Len Brown4be44fc2005-08-05 00:44:28 -0400240void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
242 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 vsprintf(buffer, fmt, args);
245
246#ifdef ENABLE_DEBUGGER
247 if (acpi_in_debugger) {
248 kdb_printf("%s", buffer);
249 } else {
Frank Seidel4d939152009-02-04 17:03:07 +0100250 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 }
252#else
Frank Seidel4d939152009-02-04 17:03:07 +0100253 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254#endif
255}
256
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300257acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800260 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300261 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800262 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300263 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400265 printk(KERN_ERR PREFIX
266 "System description tables not found\n");
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300267 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
Len Brown239665a2007-11-23 20:08:02 -0500269 } else {
270 acpi_physical_address pa = 0;
271
272 acpi_find_root_pointer(&pa);
273 return pa;
274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
Myron Stowe620242a2010-10-21 14:23:53 -0600277/* Must be called with 'acpi_ioremap_lock' lock held. */
278static void __iomem *
279acpi_map_vaddr_lookup(acpi_physical_address phys, acpi_size size)
280{
281 struct acpi_ioremap *map;
282
283 list_for_each_entry(map, &acpi_ioremaps, list)
284 if (map->phys <= phys &&
285 phys + size <= map->phys + map->size)
286 return map->virt + (phys - map->phys);
287
288 return NULL;
289}
290
291/* Must be called with 'acpi_ioremap_lock' lock held. */
292static struct acpi_ioremap *
293acpi_map_lookup_virt(void __iomem *virt, acpi_size size)
294{
295 struct acpi_ioremap *map;
296
297 list_for_each_entry(map, &acpi_ioremaps, list)
298 if (map->virt == virt && map->size == size)
299 return map;
300
301 return NULL;
302}
303
Jan Beulich2fdf0742007-12-13 08:33:59 +0000304void __iomem *__init_refok
305acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
Myron Stowe620242a2010-10-21 14:23:53 -0600307 struct acpi_ioremap *map;
308 unsigned long flags;
309 void __iomem *virt;
310
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800311 if (phys > ULONG_MAX) {
312 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Randy Dunlap70c08462007-02-13 16:11:36 -0800313 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 }
Myron Stowe620242a2010-10-21 14:23:53 -0600315
316 if (!acpi_gbl_permanent_mmap)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300317 return __acpi_map_table((unsigned long)phys, size);
Myron Stowe620242a2010-10-21 14:23:53 -0600318
319 map = kzalloc(sizeof(*map), GFP_KERNEL);
320 if (!map)
321 return NULL;
322
323 virt = ioremap(phys, size);
324 if (!virt) {
325 kfree(map);
326 return NULL;
327 }
328
329 INIT_LIST_HEAD(&map->list);
330 map->virt = virt;
331 map->phys = phys;
332 map->size = size;
333
334 spin_lock_irqsave(&acpi_ioremap_lock, flags);
335 list_add_tail(&map->list, &acpi_ioremaps);
336 spin_unlock_irqrestore(&acpi_ioremap_lock, flags);
337
338 return virt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800340EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800342void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
Myron Stowe620242a2010-10-21 14:23:53 -0600344 struct acpi_ioremap *map;
345 unsigned long flags;
346
347 if (!acpi_gbl_permanent_mmap) {
Yinghai Lu7d972772009-02-07 15:39:41 -0800348 __acpi_unmap_table(virt, size);
Myron Stowe620242a2010-10-21 14:23:53 -0600349 return;
350 }
351
352 spin_lock_irqsave(&acpi_ioremap_lock, flags);
353 map = acpi_map_lookup_virt(virt, size);
354 if (!map) {
355 spin_unlock_irqrestore(&acpi_ioremap_lock, flags);
356 printk(KERN_ERR PREFIX "%s: bad address %p\n", __func__, virt);
357 dump_stack();
358 return;
359 }
360
361 list_del(&map->list);
362 spin_unlock_irqrestore(&acpi_ioremap_lock, flags);
363
364 iounmap(map->virt);
365 kfree(map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800367EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800369void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Yinghai Lu7d972772009-02-07 15:39:41 -0800370{
371 if (!acpi_gbl_permanent_mmap)
372 __acpi_unmap_table(virt, size);
373}
374
Myron Stowe29718522010-10-21 14:23:59 -0600375int acpi_os_map_generic_address(struct acpi_generic_address *addr)
376{
377 void __iomem *virt;
378
379 if (addr->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
380 return 0;
381
382 if (!addr->address || !addr->bit_width)
383 return -EINVAL;
384
385 virt = acpi_os_map_memory(addr->address, addr->bit_width / 8);
386 if (!virt)
387 return -EIO;
388
389 return 0;
390}
391EXPORT_SYMBOL_GPL(acpi_os_map_generic_address);
392
393void acpi_os_unmap_generic_address(struct acpi_generic_address *addr)
394{
395 void __iomem *virt;
396 unsigned long flags;
397 acpi_size size = addr->bit_width / 8;
398
399 if (addr->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
400 return;
401
402 if (!addr->address || !addr->bit_width)
403 return;
404
405 spin_lock_irqsave(&acpi_ioremap_lock, flags);
406 virt = acpi_map_vaddr_lookup(addr->address, size);
407 spin_unlock_irqrestore(&acpi_ioremap_lock, flags);
408
409 acpi_os_unmap_memory(virt, size);
410}
411EXPORT_SYMBOL_GPL(acpi_os_unmap_generic_address);
412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413#ifdef ACPI_FUTURE_USAGE
414acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400415acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
Len Brown4be44fc2005-08-05 00:44:28 -0400417 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return AE_BAD_PARAMETER;
419
420 *phys = virt_to_phys(virt);
421
422 return AE_OK;
423}
424#endif
425
426#define ACPI_MAX_OVERRIDE_LEN 100
427
428static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
429
430acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400431acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
432 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
434 if (!init_val || !new_val)
435 return AE_BAD_PARAMETER;
436
437 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400438 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400440 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 *new_val = acpi_os_name;
442 }
443
444 return AE_OK;
445}
446
447acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400448acpi_os_table_override(struct acpi_table_header * existing_table,
449 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
451 if (!existing_table || !new_table)
452 return AE_BAD_PARAMETER;
453
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100454 *new_table = NULL;
455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#ifdef CONFIG_ACPI_CUSTOM_DSDT
457 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400458 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#endif
Éric Piel6ed31e92008-02-05 00:04:50 +0100460 if (*new_table != NULL) {
461 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
462 "this is unsafe: tainting kernel\n",
463 existing_table->signature,
464 existing_table->oem_table_id);
465 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 return AE_OK;
468}
469
David Howells7d12e782006-10-05 14:55:46 +0100470static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Len Brown5229e872008-02-06 01:26:55 -0500472 u32 handled;
473
474 handled = (*acpi_irq_handler) (acpi_irq_context);
475
476 if (handled) {
477 acpi_irq_handled++;
478 return IRQ_HANDLED;
Len Brown88bea182009-04-21 00:35:47 -0400479 } else {
480 acpi_irq_not_handled++;
Len Brown5229e872008-02-06 01:26:55 -0500481 return IRQ_NONE;
Len Brown88bea182009-04-21 00:35:47 -0400482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483}
484
485acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400486acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
487 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
489 unsigned int irq;
490
Len Brown5229e872008-02-06 01:26:55 -0500491 acpi_irq_stats_init();
492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 /*
494 * Ignore the GSI from the core, and use the value in our copy of the
495 * FADT. It may not be the same if an interrupt source override exists
496 * for the SCI.
497 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300498 gsi = acpi_gbl_FADT.sci_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
500 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
501 gsi);
502 return AE_OK;
503 }
504
505 acpi_irq_handler = handler;
506 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700507 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
509 return AE_NOT_ACQUIRED;
510 }
511 acpi_irq_irq = irq;
512
513 return AE_OK;
514}
515
Len Brown4be44fc2005-08-05 00:44:28 -0400516acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517{
518 if (irq) {
519 free_irq(irq, acpi_irq);
520 acpi_irq_handler = NULL;
521 acpi_irq_irq = 0;
522 }
523
524 return AE_OK;
525}
526
527/*
528 * Running in interpreter thread context, safe to sleep
529 */
530
Lin Ming439913f2010-01-28 10:53:19 +0800531void acpi_os_sleep(u64 ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800533 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534}
Len Brown4be44fc2005-08-05 00:44:28 -0400535
Len Brown4be44fc2005-08-05 00:44:28 -0400536void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537{
538 while (us) {
539 u32 delay = 1000;
540
541 if (delay > us)
542 delay = us;
543 udelay(delay);
544 touch_nmi_watchdog();
545 us -= delay;
546 }
547}
Len Brown4be44fc2005-08-05 00:44:28 -0400548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549/*
550 * Support ACPI 3.0 AML Timer operand
551 * Returns 64-bit free-running, monotonically increasing timer
552 * with 100ns granularity
553 */
Len Brown4be44fc2005-08-05 00:44:28 -0400554u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
556 static u64 t;
557
558#ifdef CONFIG_HPET
559 /* TBD: use HPET if available */
560#endif
561
562#ifdef CONFIG_X86_PM_TIMER
563 /* TBD: default to PM timer if HPET was not available */
564#endif
565 if (!t)
566 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
567
568 return ++t;
569}
570
Len Brown4be44fc2005-08-05 00:44:28 -0400571acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572{
573 u32 dummy;
574
575 if (!value)
576 value = &dummy;
577
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800578 *value = 0;
579 if (width <= 8) {
Len Brown4be44fc2005-08-05 00:44:28 -0400580 *(u8 *) value = inb(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800581 } else if (width <= 16) {
Len Brown4be44fc2005-08-05 00:44:28 -0400582 *(u16 *) value = inw(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800583 } else if (width <= 32) {
Len Brown4be44fc2005-08-05 00:44:28 -0400584 *(u32 *) value = inl(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800585 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 BUG();
587 }
588
589 return AE_OK;
590}
Len Brown4be44fc2005-08-05 00:44:28 -0400591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592EXPORT_SYMBOL(acpi_os_read_port);
593
Len Brown4be44fc2005-08-05 00:44:28 -0400594acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800596 if (width <= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 outb(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800598 } else if (width <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 outw(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800600 } else if (width <= 32) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 outl(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800602 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 BUG();
604 }
605
606 return AE_OK;
607}
Len Brown4be44fc2005-08-05 00:44:28 -0400608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609EXPORT_SYMBOL(acpi_os_write_port);
610
611acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400612acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
Len Brown4be44fc2005-08-05 00:44:28 -0400614 u32 dummy;
615 void __iomem *virt_addr;
Myron Stowe620242a2010-10-21 14:23:53 -0600616 int size = width / 8, unmap = 0;
617 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Myron Stowe620242a2010-10-21 14:23:53 -0600619 spin_lock_irqsave(&acpi_ioremap_lock, flags);
620 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
621 spin_unlock_irqrestore(&acpi_ioremap_lock, flags);
622 if (!virt_addr) {
623 virt_addr = ioremap(phys_addr, size);
624 unmap = 1;
625 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 if (!value)
627 value = &dummy;
628
629 switch (width) {
630 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400631 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 break;
633 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400634 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 break;
636 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400637 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 break;
639 default:
640 BUG();
641 }
642
Myron Stowe620242a2010-10-21 14:23:53 -0600643 if (unmap)
644 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646 return AE_OK;
647}
648
649acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400650acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
Len Brown4be44fc2005-08-05 00:44:28 -0400652 void __iomem *virt_addr;
Myron Stowe620242a2010-10-21 14:23:53 -0600653 int size = width / 8, unmap = 0;
654 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Myron Stowe620242a2010-10-21 14:23:53 -0600656 spin_lock_irqsave(&acpi_ioremap_lock, flags);
657 virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
658 spin_unlock_irqrestore(&acpi_ioremap_lock, flags);
659 if (!virt_addr) {
660 virt_addr = ioremap(phys_addr, size);
661 unmap = 1;
662 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 switch (width) {
665 case 8:
666 writeb(value, virt_addr);
667 break;
668 case 16:
669 writew(value, virt_addr);
670 break;
671 case 32:
672 writel(value, virt_addr);
673 break;
674 default:
675 BUG();
676 }
677
Myron Stowe620242a2010-10-21 14:23:53 -0600678 if (unmap)
679 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
681 return AE_OK;
682}
683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400685acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Linus Torvalds10270d42008-02-13 09:56:14 -0800686 u32 *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
688 int result, size;
689
690 if (!value)
691 return AE_BAD_PARAMETER;
692
693 switch (width) {
694 case 8:
695 size = 1;
696 break;
697 case 16:
698 size = 2;
699 break;
700 case 32:
701 size = 4;
702 break;
703 default:
704 return AE_ERROR;
705 }
706
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500707 result = raw_pci_read(pci_id->segment, pci_id->bus,
708 PCI_DEVFN(pci_id->device, pci_id->function),
709 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
711 return (result ? AE_ERROR : AE_OK);
712}
Len Brown4be44fc2005-08-05 00:44:28 -0400713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400715acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Lin Ming439913f2010-01-28 10:53:19 +0800716 u64 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
718 int result, size;
719
720 switch (width) {
721 case 8:
722 size = 1;
723 break;
724 case 16:
725 size = 2;
726 break;
727 case 32:
728 size = 4;
729 break;
730 default:
731 return AE_ERROR;
732 }
733
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500734 result = raw_pci_write(pci_id->segment, pci_id->bus,
735 PCI_DEVFN(pci_id->device, pci_id->function),
736 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 return (result ? AE_ERROR : AE_OK);
739}
740
741/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400742static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
743 acpi_handle chandle, /* current node */
744 struct acpi_pci_id **id,
745 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
Len Brown4be44fc2005-08-05 00:44:28 -0400747 acpi_handle handle;
748 struct acpi_pci_id *pci_id = *id;
749 acpi_status status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400750 unsigned long long temp;
Len Brown4be44fc2005-08-05 00:44:28 -0400751 acpi_object_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 acpi_get_parent(chandle, &handle);
754 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400755 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
756 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
758 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400759 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 return;
761
Matthew Wilcox27663c52008-10-10 02:22:59 -0400762 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400763 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 if (ACPI_SUCCESS(status)) {
Linus Torvalds10270d42008-02-13 09:56:14 -0800765 u32 val;
Len Brown4be44fc2005-08-05 00:44:28 -0400766 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
767 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769 if (*is_bridge)
770 pci_id->bus = *bus_number;
771
772 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400773 status =
Linus Torvalds10270d42008-02-13 09:56:14 -0800774 acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
Len Brown4be44fc2005-08-05 00:44:28 -0400775 8);
776 if (ACPI_SUCCESS(status)
Linus Torvalds10270d42008-02-13 09:56:14 -0800777 && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400778 status =
779 acpi_os_read_pci_configuration(pci_id, 0x18,
Linus Torvalds10270d42008-02-13 09:56:14 -0800780 &val, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 if (!ACPI_SUCCESS(status)) {
782 /* Certainly broken... FIX ME */
783 return;
784 }
785 *is_bridge = 1;
Linus Torvalds10270d42008-02-13 09:56:14 -0800786 pci_id->bus = val;
Len Brown4be44fc2005-08-05 00:44:28 -0400787 status =
788 acpi_os_read_pci_configuration(pci_id, 0x19,
Linus Torvalds10270d42008-02-13 09:56:14 -0800789 &val, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 if (ACPI_SUCCESS(status)) {
Linus Torvalds10270d42008-02-13 09:56:14 -0800791 *bus_number = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 }
793 } else
794 *is_bridge = 0;
795 }
796 }
797}
798
Len Brown4be44fc2005-08-05 00:44:28 -0400799void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
800 acpi_handle chandle, /* current node */
801 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
803 int is_bridge = 1;
804 u8 bus_number = (*id)->bus;
805
806 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
807}
808
David Howells65f27f32006-11-22 14:55:48 +0000809static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
David Howells65f27f32006-11-22 14:55:48 +0000811 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400812
Bjorn Helgaas9ac61852009-08-31 22:32:10 +0000813 if (dpc->wait)
814 acpi_os_wait_events_complete(NULL);
Zhang Rui19cd8472008-08-28 10:05:06 +0800815
816 dpc->function(dpc->context);
817 kfree(dpc);
Zhang Rui19cd8472008-08-28 10:05:06 +0800818}
819
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400820/*******************************************************************************
821 *
822 * FUNCTION: acpi_os_execute
823 *
824 * PARAMETERS: Type - Type of the callback
825 * Function - Function to be executed
826 * Context - Function parameters
827 *
828 * RETURN: Status
829 *
830 * DESCRIPTION: Depending on type, either queues function for deferred execution or
831 * immediately executes function on a separate thread.
832 *
833 ******************************************************************************/
834
Zhang Rui19cd8472008-08-28 10:05:06 +0800835static acpi_status __acpi_os_execute(acpi_execute_type type,
836 acpi_osd_exec_callback function, void *context, int hp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
Len Brown4be44fc2005-08-05 00:44:28 -0400838 acpi_status status = AE_OK;
839 struct acpi_os_dpc *dpc;
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300840 struct workqueue_struct *queue;
Zhang Rui19cd8472008-08-28 10:05:06 +0800841 int ret;
Len Brown72945b22006-07-12 22:46:42 -0400842 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
843 "Scheduling function [%p(%p)] for deferred execution.\n",
844 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 /*
847 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000848 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 * way that allows us to also free its memory inside the callee.
850 * Because we may want to schedule several tasks with different
851 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000852 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 */
Len Brown72945b22006-07-12 22:46:42 -0400854
David Howells65f27f32006-11-22 14:55:48 +0000855 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 if (!dpc)
Lin Ming889c78b2008-12-31 09:23:57 +0800857 return AE_NO_MEMORY;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 dpc->function = function;
860 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800861
Zhang Ruic02256b2009-06-23 10:20:29 +0800862 /*
863 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
864 * because the hotplug code may call driver .remove() functions,
865 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
866 * to flush these workqueues.
867 */
868 queue = hp ? kacpi_hotplug_wq :
869 (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
Bjorn Helgaas9ac61852009-08-31 22:32:10 +0000870 dpc->wait = hp ? 1 : 0;
Zhang Ruibc736752010-03-22 15:48:54 +0800871
872 if (queue == kacpi_hotplug_wq)
873 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
874 else if (queue == kacpi_notify_wq)
875 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
876 else
877 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
878
Tejun Heo8fec62b2010-06-29 10:07:09 +0200879 /*
880 * On some machines, a software-initiated SMI causes corruption unless
881 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
882 * typically it's done in GPE-related methods that are run via
883 * workqueues, so we can avoid the known corruption cases by always
884 * queueing on CPU 0.
885 */
886 ret = queue_work_on(0, queue, &dpc->work);
Zhang Rui19cd8472008-08-28 10:05:06 +0800887
888 if (!ret) {
Lin Ming55ac9a02008-09-28 14:51:56 +0800889 printk(KERN_ERR PREFIX
890 "Call to queue_work() failed.\n");
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300891 status = AE_ERROR;
892 kfree(dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 }
Lin Ming889c78b2008-12-31 09:23:57 +0800894 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895}
Len Brown4be44fc2005-08-05 00:44:28 -0400896
Zhang Rui19cd8472008-08-28 10:05:06 +0800897acpi_status acpi_os_execute(acpi_execute_type type,
898 acpi_osd_exec_callback function, void *context)
899{
900 return __acpi_os_execute(type, function, context, 0);
901}
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400902EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Zhang Rui19cd8472008-08-28 10:05:06 +0800904acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
905 void *context)
906{
907 return __acpi_os_execute(0, function, context, 1);
908}
909
Len Brown4be44fc2005-08-05 00:44:28 -0400910void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911{
912 flush_workqueue(kacpid_wq);
Zhang Rui2f67a062008-04-29 02:34:42 -0400913 flush_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914}
Len Brown4be44fc2005-08-05 00:44:28 -0400915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916EXPORT_SYMBOL(acpi_os_wait_events_complete);
917
918/*
919 * Allocate the memory for a spinlock and initialize it.
920 */
Bob Moore967440e2006-06-23 17:04:00 -0400921acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922{
Bob Moore967440e2006-06-23 17:04:00 -0400923 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Patrick Mocheld550d982006-06-27 00:41:40 -0400925 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926}
927
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928/*
929 * Deallocate the memory for a spinlock.
930 */
Bob Moore967440e2006-06-23 17:04:00 -0400931void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932{
Patrick Mocheld550d982006-06-27 00:41:40 -0400933 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934}
935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400937acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
Len Brown4be44fc2005-08-05 00:44:28 -0400939 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 sem = acpi_os_allocate(sizeof(struct semaphore));
942 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400943 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 memset(sem, 0, sizeof(struct semaphore));
945
946 sema_init(sem, initial_units);
947
Len Brown4be44fc2005-08-05 00:44:28 -0400948 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Len Brown4be44fc2005-08-05 00:44:28 -0400950 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
951 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Patrick Mocheld550d982006-06-27 00:41:40 -0400953 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956/*
957 * TODO: A better way to delete semaphores? Linux doesn't have a
958 * 'delete_semaphore()' function -- may result in an invalid
959 * pointer dereference for non-synchronized consumers. Should
960 * we at least check for blocked threads and signal/cancel them?
961 */
962
Len Brown4be44fc2005-08-05 00:44:28 -0400963acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964{
Len Brown4be44fc2005-08-05 00:44:28 -0400965 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400968 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Len Brown4be44fc2005-08-05 00:44:28 -0400970 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400972 BUG_ON(!list_empty(&sem->wait_list));
Len Brown02438d82006-06-30 03:19:10 -0400973 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400974 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Patrick Mocheld550d982006-06-27 00:41:40 -0400976 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 * TODO: Support for units > 1?
981 */
Len Brown4be44fc2005-08-05 00:44:28 -0400982acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983{
Len Brown4be44fc2005-08-05 00:44:28 -0400984 acpi_status status = AE_OK;
985 struct semaphore *sem = (struct semaphore *)handle;
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400986 long jiffies;
Len Brown4be44fc2005-08-05 00:44:28 -0400987 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400990 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
992 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400993 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Len Brown4be44fc2005-08-05 00:44:28 -0400995 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
996 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400998 if (timeout == ACPI_WAIT_FOREVER)
999 jiffies = MAX_SCHEDULE_TIMEOUT;
1000 else
1001 jiffies = msecs_to_jiffies(timeout);
1002
1003 ret = down_timeout(sem, jiffies);
1004 if (ret)
1005 status = AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -04001008 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -04001009 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -04001010 handle, units, timeout,
1011 acpi_format_exception(status)));
1012 } else {
1013 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -04001014 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001015 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 }
1017
Patrick Mocheld550d982006-06-27 00:41:40 -04001018 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021/*
1022 * TODO: Support for units > 1?
1023 */
Len Brown4be44fc2005-08-05 00:44:28 -04001024acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025{
Len Brown4be44fc2005-08-05 00:44:28 -04001026 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -04001029 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
1031 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -04001032 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
Len Brown4be44fc2005-08-05 00:44:28 -04001034 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
1035 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
1037 up(sem);
1038
Patrick Mocheld550d982006-06-27 00:41:40 -04001039 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040}
Len Brown4be44fc2005-08-05 00:44:28 -04001041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -04001043u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044{
1045
1046#ifdef ENABLE_DEBUGGER
1047 if (acpi_in_debugger) {
1048 u32 chars;
1049
1050 kdb_read(buffer, sizeof(line_buf));
1051
1052 /* remove the CR kdb includes */
1053 chars = strlen(buffer) - 1;
1054 buffer[chars] = '\0';
1055 }
1056#endif
1057
1058 return 0;
1059}
Len Brown4be44fc2005-08-05 00:44:28 -04001060#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Len Brown4be44fc2005-08-05 00:44:28 -04001062acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
Len Brown4be44fc2005-08-05 00:44:28 -04001064 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 case ACPI_SIGNAL_FATAL:
1066 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
1067 break;
1068 case ACPI_SIGNAL_BREAKPOINT:
1069 /*
1070 * AML Breakpoint
1071 * ACPI spec. says to treat it as a NOP unless
1072 * you are debugging. So if/when we integrate
1073 * AML debugger into the kernel debugger its
1074 * hook will go here. But until then it is
1075 * not useful to print anything on breakpoints.
1076 */
1077 break;
1078 default:
1079 break;
1080 }
1081
1082 return AE_OK;
1083}
Len Brown4be44fc2005-08-05 00:44:28 -04001084
Len Brown4be44fc2005-08-05 00:44:28 -04001085static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
1087 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -04001088 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
1090 if (!str || !*str)
1091 return 0;
1092
1093 for (; count-- && str && *str; str++) {
1094 if (isalnum(*str) || *str == ' ' || *str == ':')
1095 *p++ = *str;
1096 else if (*str == '\'' || *str == '"')
1097 continue;
1098 else
1099 break;
1100 }
1101 *p = 0;
1102
1103 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001104
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105}
1106
1107__setup("acpi_os_name=", acpi_os_name_setup);
1108
Len Brownd4b7dc42008-01-23 20:50:56 -05001109static void __init set_osi_linux(unsigned int enable)
1110{
1111 if (osi_linux.enable != enable) {
1112 osi_linux.enable = enable;
1113 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
1114 enable ? "Add": "Delet");
1115 }
1116 return;
1117}
Len Brownf5076542007-05-30 00:10:38 -04001118
Len Brownd4b7dc42008-01-23 20:50:56 -05001119static void __init acpi_cmdline_osi_linux(unsigned int enable)
1120{
1121 osi_linux.cmdline = 1; /* cmdline set the default */
1122 set_osi_linux(enable);
Len Brownf5076542007-05-30 00:10:38 -04001123
Len Brownd4b7dc42008-01-23 20:50:56 -05001124 return;
1125}
1126
1127void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1128{
1129 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1130
1131 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1132
1133 if (enable == -1)
1134 return;
1135
1136 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
1137
1138 set_osi_linux(enable);
1139
Len Brownf5076542007-05-30 00:10:38 -04001140 return;
1141}
1142
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143/*
Len Brownae00d812007-05-29 18:43:33 -04001144 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1145 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 * empty string disables _OSI
Len Brownae00d812007-05-29 18:43:33 -04001147 * string starting with '!' disables that string
1148 * otherwise string is added to list, augmenting built-in strings
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 */
Len Brown46c1fbd2008-02-13 23:13:25 -05001150int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151{
1152 if (str == NULL || *str == '\0') {
1153 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1154 acpi_gbl_create_osi_method = FALSE;
Len Brownaa2e09d2007-07-02 23:57:45 -04001155 } else if (!strcmp("!Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001156 acpi_cmdline_osi_linux(0); /* !enable */
Len Brownae00d812007-05-29 18:43:33 -04001157 } else if (*str == '!') {
1158 if (acpi_osi_invalidate(++str) == AE_OK)
1159 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
Len Brownf5076542007-05-30 00:10:38 -04001160 } else if (!strcmp("Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001161 acpi_cmdline_osi_linux(1); /* enable */
Len Brownae00d812007-05-29 18:43:33 -04001162 } else if (*osi_additional_string == '\0') {
1163 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
1164 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
1166
1167 return 1;
1168}
1169
1170__setup("acpi_osi=", acpi_osi_setup);
1171
1172/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001173static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174{
1175 printk(KERN_INFO PREFIX "serialize enabled\n");
1176
1177 acpi_gbl_all_methods_serialized = TRUE;
1178
1179 return 1;
1180}
1181
1182__setup("acpi_serialize", acpi_serialize_setup);
1183
Thomas Renningerdf92e692008-02-04 23:31:22 -08001184/* Check of resource interference between native drivers and ACPI
1185 * OperationRegions (SystemIO and System Memory only).
1186 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1187 * in arbitrary AML code and can interfere with legacy drivers.
1188 * acpi_enforce_resources= can be set to:
1189 *
Luca Tettamanti7e905602009-03-30 00:01:27 +02001190 * - strict (default) (2)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001191 * -> further driver trying to access the resources will not load
Luca Tettamanti7e905602009-03-30 00:01:27 +02001192 * - lax (1)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001193 * -> further driver trying to access the resources will load, but you
1194 * get a system message that something might go wrong...
1195 *
1196 * - no (0)
1197 * -> ACPI Operation Region resources will not be registered
1198 *
1199 */
1200#define ENFORCE_RESOURCES_STRICT 2
1201#define ENFORCE_RESOURCES_LAX 1
1202#define ENFORCE_RESOURCES_NO 0
1203
Luca Tettamanti7e905602009-03-30 00:01:27 +02001204static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001205
1206static int __init acpi_enforce_resources_setup(char *str)
1207{
1208 if (str == NULL || *str == '\0')
1209 return 0;
1210
1211 if (!strcmp("strict", str))
1212 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1213 else if (!strcmp("lax", str))
1214 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1215 else if (!strcmp("no", str))
1216 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1217
1218 return 1;
1219}
1220
1221__setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1222
1223/* Check for resource conflicts between ACPI OperationRegions and native
1224 * drivers */
Jean Delvare876fba42009-11-11 15:22:15 +01001225int acpi_check_resource_conflict(const struct resource *res)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001226{
1227 struct acpi_res_list *res_list_elem;
1228 int ioport;
1229 int clash = 0;
1230
1231 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1232 return 0;
1233 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1234 return 0;
1235
1236 ioport = res->flags & IORESOURCE_IO;
1237
1238 spin_lock(&acpi_res_lock);
1239 list_for_each_entry(res_list_elem, &resource_list_head,
1240 resource_list) {
1241 if (ioport && (res_list_elem->resource_type
1242 != ACPI_ADR_SPACE_SYSTEM_IO))
1243 continue;
1244 if (!ioport && (res_list_elem->resource_type
1245 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1246 continue;
1247
1248 if (res->end < res_list_elem->start
1249 || res_list_elem->end < res->start)
1250 continue;
1251 clash = 1;
1252 break;
1253 }
1254 spin_unlock(&acpi_res_lock);
1255
1256 if (clash) {
1257 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
Chase Douglas1638bca2010-03-22 15:08:09 -04001258 printk(KERN_WARNING "ACPI: resource %s %pR"
1259 " conflicts with ACPI region %s %pR\n",
1260 res->name, res, res_list_elem->name,
1261 res_list_elem);
Jean Delvare14f03342009-09-08 15:31:46 +02001262 if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
1263 printk(KERN_NOTICE "ACPI: This conflict may"
1264 " cause random problems and system"
1265 " instability\n");
1266 printk(KERN_INFO "ACPI: If an ACPI driver is available"
1267 " for this device, you should use it instead of"
1268 " the native driver\n");
Thomas Renningerdf92e692008-02-04 23:31:22 -08001269 }
1270 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1271 return -EBUSY;
1272 }
1273 return 0;
1274}
Thomas Renninger443dea72008-02-04 23:31:23 -08001275EXPORT_SYMBOL(acpi_check_resource_conflict);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001276
1277int acpi_check_region(resource_size_t start, resource_size_t n,
1278 const char *name)
1279{
1280 struct resource res = {
1281 .start = start,
1282 .end = start + n - 1,
1283 .name = name,
1284 .flags = IORESOURCE_IO,
1285 };
1286
1287 return acpi_check_resource_conflict(&res);
1288}
1289EXPORT_SYMBOL(acpi_check_region);
1290
1291int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1292 const char *name)
1293{
1294 struct resource res = {
1295 .start = start,
1296 .end = start + n - 1,
1297 .name = name,
1298 .flags = IORESOURCE_MEM,
1299 };
1300
1301 return acpi_check_resource_conflict(&res);
1302
1303}
1304EXPORT_SYMBOL(acpi_check_mem_region);
1305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306/*
Jean Delvare70dd6be2010-05-27 19:58:37 +02001307 * Let drivers know whether the resource checks are effective
1308 */
1309int acpi_resources_are_enforced(void)
1310{
1311 return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
1312}
1313EXPORT_SYMBOL(acpi_resources_are_enforced);
1314
1315/*
Robert Moore73459f72005-06-24 00:00:00 -04001316 * Acquire a spinlock.
1317 *
1318 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001319 */
1320
Bob Moore967440e2006-06-23 17:04:00 -04001321acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001322{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001323 acpi_cpu_flags flags;
Bob Moore967440e2006-06-23 17:04:00 -04001324 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001325 return flags;
1326}
1327
1328/*
1329 * Release a spinlock. See above.
1330 */
1331
Bob Moore967440e2006-06-23 17:04:00 -04001332void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001333{
Bob Moore967440e2006-06-23 17:04:00 -04001334 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001335}
1336
Robert Moore73459f72005-06-24 00:00:00 -04001337#ifndef ACPI_USE_LOCAL_CACHE
1338
1339/*******************************************************************************
1340 *
1341 * FUNCTION: acpi_os_create_cache
1342 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001343 * PARAMETERS: name - Ascii name for the cache
1344 * size - Size of each cached object
1345 * depth - Maximum depth of the cache (in objects) <ignored>
1346 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001347 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001348 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001349 *
1350 * DESCRIPTION: Create a cache object
1351 *
1352 ******************************************************************************/
1353
1354acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001355acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001356{
Paul Mundt20c2df82007-07-20 10:11:58 +09001357 *cache = kmem_cache_create(name, size, 0, 0, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001358 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001359 return AE_ERROR;
1360 else
1361 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001362}
1363
1364/*******************************************************************************
1365 *
1366 * FUNCTION: acpi_os_purge_cache
1367 *
1368 * PARAMETERS: Cache - Handle to cache object
1369 *
1370 * RETURN: Status
1371 *
1372 * DESCRIPTION: Free all objects within the requested cache.
1373 *
1374 ******************************************************************************/
1375
Len Brown4be44fc2005-08-05 00:44:28 -04001376acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001377{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001378 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001379 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001380}
1381
1382/*******************************************************************************
1383 *
1384 * FUNCTION: acpi_os_delete_cache
1385 *
1386 * PARAMETERS: Cache - Handle to cache object
1387 *
1388 * RETURN: Status
1389 *
1390 * DESCRIPTION: Free all objects within the requested cache and delete the
1391 * cache object.
1392 *
1393 ******************************************************************************/
1394
Len Brown4be44fc2005-08-05 00:44:28 -04001395acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001396{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001397 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001398 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001399}
1400
1401/*******************************************************************************
1402 *
1403 * FUNCTION: acpi_os_release_object
1404 *
1405 * PARAMETERS: Cache - Handle to cache object
1406 * Object - The object to be released
1407 *
1408 * RETURN: None
1409 *
1410 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1411 * the object is deleted.
1412 *
1413 ******************************************************************************/
1414
Len Brown4be44fc2005-08-05 00:44:28 -04001415acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001416{
Len Brown4be44fc2005-08-05 00:44:28 -04001417 kmem_cache_free(cache, object);
1418 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001419}
1420
Bob Mooreb229cf92006-04-21 17:15:00 -04001421/******************************************************************************
1422 *
1423 * FUNCTION: acpi_os_validate_interface
1424 *
1425 * PARAMETERS: interface - Requested interface to be validated
1426 *
1427 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1428 *
1429 * DESCRIPTION: Match an interface string to the interfaces supported by the
1430 * host. Strings originate from an AML call to the _OSI method.
1431 *
1432 *****************************************************************************/
1433
1434acpi_status
1435acpi_os_validate_interface (char *interface)
1436{
Len Brownae00d812007-05-29 18:43:33 -04001437 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1438 return AE_OK;
Len Brownf5076542007-05-30 00:10:38 -04001439 if (!strcmp("Linux", interface)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001440
1441 printk(KERN_NOTICE PREFIX
1442 "BIOS _OSI(Linux) query %s%s\n",
1443 osi_linux.enable ? "honored" : "ignored",
1444 osi_linux.cmdline ? " via cmdline" :
1445 osi_linux.dmi ? " via DMI" : "");
1446
Len Brownd4b7dc42008-01-23 20:50:56 -05001447 if (osi_linux.enable)
Len Brownf5076542007-05-30 00:10:38 -04001448 return AE_OK;
1449 }
Len Brownae00d812007-05-29 18:43:33 -04001450 return AE_SUPPORT;
Bob Mooreb229cf92006-04-21 17:15:00 -04001451}
1452
Lin Minga5fe1a02009-08-13 10:43:27 +08001453static inline int acpi_res_list_add(struct acpi_res_list *res)
1454{
1455 struct acpi_res_list *res_list_elem;
1456
1457 list_for_each_entry(res_list_elem, &resource_list_head,
1458 resource_list) {
1459
1460 if (res->resource_type == res_list_elem->resource_type &&
1461 res->start == res_list_elem->start &&
1462 res->end == res_list_elem->end) {
1463
1464 /*
1465 * The Region(addr,len) already exist in the list,
1466 * just increase the count
1467 */
1468
1469 res_list_elem->count++;
1470 return 0;
1471 }
1472 }
1473
1474 res->count = 1;
1475 list_add(&res->resource_list, &resource_list_head);
1476 return 1;
1477}
1478
1479static inline void acpi_res_list_del(struct acpi_res_list *res)
1480{
1481 struct acpi_res_list *res_list_elem;
1482
1483 list_for_each_entry(res_list_elem, &resource_list_head,
1484 resource_list) {
1485
1486 if (res->resource_type == res_list_elem->resource_type &&
1487 res->start == res_list_elem->start &&
1488 res->end == res_list_elem->end) {
1489
1490 /*
1491 * If the res count is decreased to 0,
1492 * remove and free it
1493 */
1494
1495 if (--res_list_elem->count == 0) {
1496 list_del(&res_list_elem->resource_list);
1497 kfree(res_list_elem);
1498 }
1499 return;
1500 }
1501 }
1502}
1503
1504acpi_status
1505acpi_os_invalidate_address(
1506 u8 space_id,
1507 acpi_physical_address address,
1508 acpi_size length)
1509{
1510 struct acpi_res_list res;
1511
1512 switch (space_id) {
1513 case ACPI_ADR_SPACE_SYSTEM_IO:
1514 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
Thomas Weber88393162010-03-16 11:47:56 +01001515 /* Only interference checks against SystemIO and SystemMemory
Lin Minga5fe1a02009-08-13 10:43:27 +08001516 are needed */
1517 res.start = address;
1518 res.end = address + length - 1;
1519 res.resource_type = space_id;
1520 spin_lock(&acpi_res_lock);
1521 acpi_res_list_del(&res);
1522 spin_unlock(&acpi_res_lock);
1523 break;
1524 case ACPI_ADR_SPACE_PCI_CONFIG:
1525 case ACPI_ADR_SPACE_EC:
1526 case ACPI_ADR_SPACE_SMBUS:
1527 case ACPI_ADR_SPACE_CMOS:
1528 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1529 case ACPI_ADR_SPACE_DATA_TABLE:
1530 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1531 break;
1532 }
1533 return AE_OK;
1534}
1535
Bob Mooreb229cf92006-04-21 17:15:00 -04001536/******************************************************************************
1537 *
1538 * FUNCTION: acpi_os_validate_address
1539 *
1540 * PARAMETERS: space_id - ACPI space ID
1541 * address - Physical address
1542 * length - Address length
1543 *
1544 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1545 * should return AE_AML_ILLEGAL_ADDRESS.
1546 *
1547 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1548 * the addresses accessed by AML operation regions.
1549 *
1550 *****************************************************************************/
1551
1552acpi_status
1553acpi_os_validate_address (
1554 u8 space_id,
1555 acpi_physical_address address,
Thomas Renningerdf92e692008-02-04 23:31:22 -08001556 acpi_size length,
1557 char *name)
Bob Mooreb229cf92006-04-21 17:15:00 -04001558{
Thomas Renningerdf92e692008-02-04 23:31:22 -08001559 struct acpi_res_list *res;
Lin Minga5fe1a02009-08-13 10:43:27 +08001560 int added;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001561 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1562 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001563
Thomas Renningerdf92e692008-02-04 23:31:22 -08001564 switch (space_id) {
1565 case ACPI_ADR_SPACE_SYSTEM_IO:
1566 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
Thomas Weber88393162010-03-16 11:47:56 +01001567 /* Only interference checks against SystemIO and SystemMemory
Thomas Renningerdf92e692008-02-04 23:31:22 -08001568 are needed */
1569 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1570 if (!res)
1571 return AE_OK;
1572 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1573 strlcpy(res->name, name, 5);
1574 res->start = address;
1575 res->end = address + length - 1;
1576 res->resource_type = space_id;
1577 spin_lock(&acpi_res_lock);
Lin Minga5fe1a02009-08-13 10:43:27 +08001578 added = acpi_res_list_add(res);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001579 spin_unlock(&acpi_res_lock);
Lin Minga5fe1a02009-08-13 10:43:27 +08001580 pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
1581 "name: %s\n", added ? "Added" : "Already exist",
1582 (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001583 ? "SystemIO" : "System Memory",
1584 (unsigned long long)res->start,
1585 (unsigned long long)res->end,
1586 res->name);
Lin Minga5fe1a02009-08-13 10:43:27 +08001587 if (!added)
1588 kfree(res);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001589 break;
1590 case ACPI_ADR_SPACE_PCI_CONFIG:
1591 case ACPI_ADR_SPACE_EC:
1592 case ACPI_ADR_SPACE_SMBUS:
1593 case ACPI_ADR_SPACE_CMOS:
1594 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1595 case ACPI_ADR_SPACE_DATA_TABLE:
1596 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1597 break;
1598 }
1599 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001600}
1601
Robert Moore73459f72005-06-24 00:00:00 -04001602#endif