blob: 46cce391fa462000aeec64396691382e3a04f15b [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
Len Brownae00d812007-05-29 18:43:33 -040098#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
99static char osi_additional_string[OSI_STRING_LENGTH_MAX];
100
Len Brownd4b7dc42008-01-23 20:50:56 -0500101/*
Len Browna6e08872008-11-08 01:21:10 -0500102 * The story of _OSI(Linux)
Len Brownd4b7dc42008-01-23 20:50:56 -0500103 *
Len Browna6e08872008-11-08 01:21:10 -0500104 * From pre-history through Linux-2.6.22,
105 * Linux responded TRUE upon a BIOS OSI(Linux) query.
Len Brownd4b7dc42008-01-23 20:50:56 -0500106 *
Len Browna6e08872008-11-08 01:21:10 -0500107 * Unfortunately, reference BIOS writers got wind of this
108 * and put OSI(Linux) in their example code, quickly exposing
109 * this string as ill-conceived and opening the door to
110 * an un-bounded number of BIOS incompatibilities.
Len Brownd4b7dc42008-01-23 20:50:56 -0500111 *
Len Browna6e08872008-11-08 01:21:10 -0500112 * For example, OSI(Linux) was used on resume to re-POST a
113 * video card on one system, because Linux at that time
114 * could not do a speedy restore in its native driver.
115 * But then upon gaining quick native restore capability,
116 * Linux has no way to tell the BIOS to skip the time-consuming
117 * POST -- putting Linux at a permanent performance disadvantage.
118 * On another system, the BIOS writer used OSI(Linux)
119 * to infer native OS support for IPMI! On other systems,
120 * OSI(Linux) simply got in the way of Linux claiming to
121 * be compatible with other operating systems, exposing
122 * BIOS issues such as skipped device initialization.
Len Brownd4b7dc42008-01-23 20:50:56 -0500123 *
Len Browna6e08872008-11-08 01:21:10 -0500124 * So "Linux" turned out to be a really poor chose of
125 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
Len Brownd4b7dc42008-01-23 20:50:56 -0500126 *
127 * BIOS writers should NOT query _OSI(Linux) on future systems.
Len Browna6e08872008-11-08 01:21:10 -0500128 * Linux will complain on the console when it sees it, and return FALSE.
129 * To get Linux to return TRUE for your system will require
130 * a kernel source update to add a DMI entry,
131 * or boot with "acpi_osi=Linux"
Len Brownd4b7dc42008-01-23 20:50:56 -0500132 */
Len Brownd4b7dc42008-01-23 20:50:56 -0500133
Adrian Bunk1d15d842008-01-29 00:10:15 +0200134static struct osi_linux {
Len Brownd4b7dc42008-01-23 20:50:56 -0500135 unsigned int enable:1;
136 unsigned int dmi:1;
137 unsigned int cmdline:1;
138 unsigned int known:1;
Len Browna6e08872008-11-08 01:21:10 -0500139} osi_linux = { 0, 0, 0, 0};
Len Brownf5076542007-05-30 00:10:38 -0400140
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700141static void __init acpi_request_region (struct acpi_generic_address *addr,
142 unsigned int length, char *desc)
143{
144 struct resource *res;
145
146 if (!addr->address || !length)
147 return;
148
Len Browneee3c852007-02-03 01:38:16 -0500149 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700150 res = request_region(addr->address, length, desc);
Len Browneee3c852007-02-03 01:38:16 -0500151 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700152 res = request_mem_region(addr->address, length, desc);
153}
154
155static int __init acpi_reserve_resources(void)
156{
Len Browneee3c852007-02-03 01:38:16 -0500157 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700158 "ACPI PM1a_EVT_BLK");
159
Len Browneee3c852007-02-03 01:38:16 -0500160 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700161 "ACPI PM1b_EVT_BLK");
162
Len Browneee3c852007-02-03 01:38:16 -0500163 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700164 "ACPI PM1a_CNT_BLK");
165
Len Browneee3c852007-02-03 01:38:16 -0500166 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700167 "ACPI PM1b_CNT_BLK");
168
Len Browneee3c852007-02-03 01:38:16 -0500169 if (acpi_gbl_FADT.pm_timer_length == 4)
170 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700171
Len Browneee3c852007-02-03 01:38:16 -0500172 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700173 "ACPI PM2_CNT_BLK");
174
175 /* Length of GPE blocks must be a non-negative multiple of 2 */
176
Len Browneee3c852007-02-03 01:38:16 -0500177 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
178 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
179 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700180
Len Browneee3c852007-02-03 01:38:16 -0500181 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
182 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
183 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700184
185 return 0;
186}
187device_initcall(acpi_reserve_resources);
188
Len Browndd272b52007-05-30 00:26:11 -0400189acpi_status __init acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
191 return AE_OK;
192}
193
Len Brown4be44fc2005-08-05 00:44:28 -0400194acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Tejun Heo8fec62b2010-06-29 10:07:09 +0200196 kacpid_wq = create_workqueue("kacpid");
197 kacpi_notify_wq = create_workqueue("kacpi_notify");
198 kacpi_hotplug_wq = create_workqueue("kacpi_hotplug");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 BUG_ON(!kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400200 BUG_ON(!kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800201 BUG_ON(!kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return AE_OK;
203}
204
Len Brown4be44fc2005-08-05 00:44:28 -0400205acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206{
207 if (acpi_irq_handler) {
208 acpi_os_remove_interrupt_handler(acpi_irq_irq,
209 acpi_irq_handler);
210 }
211
212 destroy_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400213 destroy_workqueue(kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800214 destroy_workqueue(kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 return AE_OK;
217}
218
Len Brown4be44fc2005-08-05 00:44:28 -0400219void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
221 va_list args;
222 va_start(args, fmt);
223 acpi_os_vprintf(fmt, args);
224 va_end(args);
225}
Len Brown4be44fc2005-08-05 00:44:28 -0400226
Len Brown4be44fc2005-08-05 00:44:28 -0400227void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
229 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 vsprintf(buffer, fmt, args);
232
233#ifdef ENABLE_DEBUGGER
234 if (acpi_in_debugger) {
235 kdb_printf("%s", buffer);
236 } else {
Frank Seidel4d939152009-02-04 17:03:07 +0100237 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 }
239#else
Frank Seidel4d939152009-02-04 17:03:07 +0100240 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241#endif
242}
243
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300244acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800247 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300248 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800249 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300250 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400252 printk(KERN_ERR PREFIX
253 "System description tables not found\n");
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300254 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 }
Len Brown239665a2007-11-23 20:08:02 -0500256 } else {
257 acpi_physical_address pa = 0;
258
259 acpi_find_root_pointer(&pa);
260 return pa;
261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
263
Jan Beulich2fdf0742007-12-13 08:33:59 +0000264void __iomem *__init_refok
265acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800267 if (phys > ULONG_MAX) {
268 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Randy Dunlap70c08462007-02-13 16:11:36 -0800269 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300271 if (acpi_gbl_permanent_mmap)
272 /*
273 * ioremap checks to ensure this is in reserved space
274 */
275 return ioremap((unsigned long)phys, size);
276 else
277 return __acpi_map_table((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800279EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800281void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
Yinghai Lu7d972772009-02-07 15:39:41 -0800283 if (acpi_gbl_permanent_mmap)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300284 iounmap(virt);
Yinghai Lu7d972772009-02-07 15:39:41 -0800285 else
286 __acpi_unmap_table(virt, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800288EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800290void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Yinghai Lu7d972772009-02-07 15:39:41 -0800291{
292 if (!acpi_gbl_permanent_mmap)
293 __acpi_unmap_table(virt, size);
294}
295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296#ifdef ACPI_FUTURE_USAGE
297acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400298acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
Len Brown4be44fc2005-08-05 00:44:28 -0400300 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 return AE_BAD_PARAMETER;
302
303 *phys = virt_to_phys(virt);
304
305 return AE_OK;
306}
307#endif
308
309#define ACPI_MAX_OVERRIDE_LEN 100
310
311static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
312
313acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400314acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
315 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
317 if (!init_val || !new_val)
318 return AE_BAD_PARAMETER;
319
320 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400321 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400323 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 *new_val = acpi_os_name;
325 }
326
327 return AE_OK;
328}
329
330acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400331acpi_os_table_override(struct acpi_table_header * existing_table,
332 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
334 if (!existing_table || !new_table)
335 return AE_BAD_PARAMETER;
336
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100337 *new_table = NULL;
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339#ifdef CONFIG_ACPI_CUSTOM_DSDT
340 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400341 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#endif
Éric Piel6ed31e92008-02-05 00:04:50 +0100343 if (*new_table != NULL) {
344 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
345 "this is unsafe: tainting kernel\n",
346 existing_table->signature,
347 existing_table->oem_table_id);
348 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 return AE_OK;
351}
352
David Howells7d12e782006-10-05 14:55:46 +0100353static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354{
Len Brown5229e872008-02-06 01:26:55 -0500355 u32 handled;
356
357 handled = (*acpi_irq_handler) (acpi_irq_context);
358
359 if (handled) {
360 acpi_irq_handled++;
361 return IRQ_HANDLED;
Len Brown88bea182009-04-21 00:35:47 -0400362 } else {
363 acpi_irq_not_handled++;
Len Brown5229e872008-02-06 01:26:55 -0500364 return IRQ_NONE;
Len Brown88bea182009-04-21 00:35:47 -0400365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367
368acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400369acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
370 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
372 unsigned int irq;
373
Len Brown5229e872008-02-06 01:26:55 -0500374 acpi_irq_stats_init();
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 /*
377 * Ignore the GSI from the core, and use the value in our copy of the
378 * FADT. It may not be the same if an interrupt source override exists
379 * for the SCI.
380 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300381 gsi = acpi_gbl_FADT.sci_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
383 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
384 gsi);
385 return AE_OK;
386 }
387
388 acpi_irq_handler = handler;
389 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700390 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
392 return AE_NOT_ACQUIRED;
393 }
394 acpi_irq_irq = irq;
395
396 return AE_OK;
397}
398
Len Brown4be44fc2005-08-05 00:44:28 -0400399acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400{
401 if (irq) {
402 free_irq(irq, acpi_irq);
403 acpi_irq_handler = NULL;
404 acpi_irq_irq = 0;
405 }
406
407 return AE_OK;
408}
409
410/*
411 * Running in interpreter thread context, safe to sleep
412 */
413
Lin Ming439913f2010-01-28 10:53:19 +0800414void acpi_os_sleep(u64 ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800416 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417}
Len Brown4be44fc2005-08-05 00:44:28 -0400418
Len Brown4be44fc2005-08-05 00:44:28 -0400419void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
421 while (us) {
422 u32 delay = 1000;
423
424 if (delay > us)
425 delay = us;
426 udelay(delay);
427 touch_nmi_watchdog();
428 us -= delay;
429 }
430}
Len Brown4be44fc2005-08-05 00:44:28 -0400431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432/*
433 * Support ACPI 3.0 AML Timer operand
434 * Returns 64-bit free-running, monotonically increasing timer
435 * with 100ns granularity
436 */
Len Brown4be44fc2005-08-05 00:44:28 -0400437u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
439 static u64 t;
440
441#ifdef CONFIG_HPET
442 /* TBD: use HPET if available */
443#endif
444
445#ifdef CONFIG_X86_PM_TIMER
446 /* TBD: default to PM timer if HPET was not available */
447#endif
448 if (!t)
449 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
450
451 return ++t;
452}
453
Len Brown4be44fc2005-08-05 00:44:28 -0400454acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
456 u32 dummy;
457
458 if (!value)
459 value = &dummy;
460
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800461 *value = 0;
462 if (width <= 8) {
Len Brown4be44fc2005-08-05 00:44:28 -0400463 *(u8 *) value = inb(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800464 } else if (width <= 16) {
Len Brown4be44fc2005-08-05 00:44:28 -0400465 *(u16 *) value = inw(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800466 } else if (width <= 32) {
Len Brown4be44fc2005-08-05 00:44:28 -0400467 *(u32 *) value = inl(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800468 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 BUG();
470 }
471
472 return AE_OK;
473}
Len Brown4be44fc2005-08-05 00:44:28 -0400474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475EXPORT_SYMBOL(acpi_os_read_port);
476
Len Brown4be44fc2005-08-05 00:44:28 -0400477acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800479 if (width <= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 outb(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800481 } else if (width <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 outw(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800483 } else if (width <= 32) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 outl(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800485 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 BUG();
487 }
488
489 return AE_OK;
490}
Len Brown4be44fc2005-08-05 00:44:28 -0400491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492EXPORT_SYMBOL(acpi_os_write_port);
493
494acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400495acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
Len Brown4be44fc2005-08-05 00:44:28 -0400497 u32 dummy;
498 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800500 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 if (!value)
502 value = &dummy;
503
504 switch (width) {
505 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400506 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 break;
508 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400509 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 break;
511 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400512 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 break;
514 default:
515 BUG();
516 }
517
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800518 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 return AE_OK;
521}
522
523acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400524acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
Len Brown4be44fc2005-08-05 00:44:28 -0400526 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800528 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530 switch (width) {
531 case 8:
532 writeb(value, virt_addr);
533 break;
534 case 16:
535 writew(value, virt_addr);
536 break;
537 case 32:
538 writel(value, virt_addr);
539 break;
540 default:
541 BUG();
542 }
543
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800544 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 return AE_OK;
547}
548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400550acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Linus Torvalds10270d42008-02-13 09:56:14 -0800551 u32 *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552{
553 int result, size;
554
555 if (!value)
556 return AE_BAD_PARAMETER;
557
558 switch (width) {
559 case 8:
560 size = 1;
561 break;
562 case 16:
563 size = 2;
564 break;
565 case 32:
566 size = 4;
567 break;
568 default:
569 return AE_ERROR;
570 }
571
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500572 result = raw_pci_read(pci_id->segment, pci_id->bus,
573 PCI_DEVFN(pci_id->device, pci_id->function),
574 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 return (result ? AE_ERROR : AE_OK);
577}
Len Brown4be44fc2005-08-05 00:44:28 -0400578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400580acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Lin Ming439913f2010-01-28 10:53:19 +0800581 u64 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
583 int result, size;
584
585 switch (width) {
586 case 8:
587 size = 1;
588 break;
589 case 16:
590 size = 2;
591 break;
592 case 32:
593 size = 4;
594 break;
595 default:
596 return AE_ERROR;
597 }
598
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500599 result = raw_pci_write(pci_id->segment, pci_id->bus,
600 PCI_DEVFN(pci_id->device, pci_id->function),
601 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603 return (result ? AE_ERROR : AE_OK);
604}
605
606/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400607static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
608 acpi_handle chandle, /* current node */
609 struct acpi_pci_id **id,
610 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Len Brown4be44fc2005-08-05 00:44:28 -0400612 acpi_handle handle;
613 struct acpi_pci_id *pci_id = *id;
614 acpi_status status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400615 unsigned long long temp;
Len Brown4be44fc2005-08-05 00:44:28 -0400616 acpi_object_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 acpi_get_parent(chandle, &handle);
619 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400620 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
621 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400624 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 return;
626
Matthew Wilcox27663c52008-10-10 02:22:59 -0400627 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400628 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 if (ACPI_SUCCESS(status)) {
Linus Torvalds10270d42008-02-13 09:56:14 -0800630 u32 val;
Len Brown4be44fc2005-08-05 00:44:28 -0400631 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
632 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 if (*is_bridge)
635 pci_id->bus = *bus_number;
636
637 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400638 status =
Linus Torvalds10270d42008-02-13 09:56:14 -0800639 acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
Len Brown4be44fc2005-08-05 00:44:28 -0400640 8);
641 if (ACPI_SUCCESS(status)
Linus Torvalds10270d42008-02-13 09:56:14 -0800642 && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400643 status =
644 acpi_os_read_pci_configuration(pci_id, 0x18,
Linus Torvalds10270d42008-02-13 09:56:14 -0800645 &val, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if (!ACPI_SUCCESS(status)) {
647 /* Certainly broken... FIX ME */
648 return;
649 }
650 *is_bridge = 1;
Linus Torvalds10270d42008-02-13 09:56:14 -0800651 pci_id->bus = val;
Len Brown4be44fc2005-08-05 00:44:28 -0400652 status =
653 acpi_os_read_pci_configuration(pci_id, 0x19,
Linus Torvalds10270d42008-02-13 09:56:14 -0800654 &val, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 if (ACPI_SUCCESS(status)) {
Linus Torvalds10270d42008-02-13 09:56:14 -0800656 *bus_number = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 }
658 } else
659 *is_bridge = 0;
660 }
661 }
662}
663
Len Brown4be44fc2005-08-05 00:44:28 -0400664void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
665 acpi_handle chandle, /* current node */
666 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667{
668 int is_bridge = 1;
669 u8 bus_number = (*id)->bus;
670
671 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
672}
673
David Howells65f27f32006-11-22 14:55:48 +0000674static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675{
David Howells65f27f32006-11-22 14:55:48 +0000676 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400677
Bjorn Helgaas9ac61852009-08-31 22:32:10 +0000678 if (dpc->wait)
679 acpi_os_wait_events_complete(NULL);
Zhang Rui19cd8472008-08-28 10:05:06 +0800680
681 dpc->function(dpc->context);
682 kfree(dpc);
Zhang Rui19cd8472008-08-28 10:05:06 +0800683}
684
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400685/*******************************************************************************
686 *
687 * FUNCTION: acpi_os_execute
688 *
689 * PARAMETERS: Type - Type of the callback
690 * Function - Function to be executed
691 * Context - Function parameters
692 *
693 * RETURN: Status
694 *
695 * DESCRIPTION: Depending on type, either queues function for deferred execution or
696 * immediately executes function on a separate thread.
697 *
698 ******************************************************************************/
699
Zhang Rui19cd8472008-08-28 10:05:06 +0800700static acpi_status __acpi_os_execute(acpi_execute_type type,
701 acpi_osd_exec_callback function, void *context, int hp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
Len Brown4be44fc2005-08-05 00:44:28 -0400703 acpi_status status = AE_OK;
704 struct acpi_os_dpc *dpc;
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300705 struct workqueue_struct *queue;
Zhang Rui19cd8472008-08-28 10:05:06 +0800706 int ret;
Len Brown72945b22006-07-12 22:46:42 -0400707 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
708 "Scheduling function [%p(%p)] for deferred execution.\n",
709 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 /*
712 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000713 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 * way that allows us to also free its memory inside the callee.
715 * Because we may want to schedule several tasks with different
716 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000717 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 */
Len Brown72945b22006-07-12 22:46:42 -0400719
David Howells65f27f32006-11-22 14:55:48 +0000720 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 if (!dpc)
Lin Ming889c78b2008-12-31 09:23:57 +0800722 return AE_NO_MEMORY;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800723
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 dpc->function = function;
725 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800726
Zhang Ruic02256b2009-06-23 10:20:29 +0800727 /*
728 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
729 * because the hotplug code may call driver .remove() functions,
730 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
731 * to flush these workqueues.
732 */
733 queue = hp ? kacpi_hotplug_wq :
734 (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
Bjorn Helgaas9ac61852009-08-31 22:32:10 +0000735 dpc->wait = hp ? 1 : 0;
Zhang Ruibc736752010-03-22 15:48:54 +0800736
737 if (queue == kacpi_hotplug_wq)
738 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
739 else if (queue == kacpi_notify_wq)
740 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
741 else
742 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
743
Tejun Heo8fec62b2010-06-29 10:07:09 +0200744 /*
745 * On some machines, a software-initiated SMI causes corruption unless
746 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
747 * typically it's done in GPE-related methods that are run via
748 * workqueues, so we can avoid the known corruption cases by always
749 * queueing on CPU 0.
750 */
751 ret = queue_work_on(0, queue, &dpc->work);
Zhang Rui19cd8472008-08-28 10:05:06 +0800752
753 if (!ret) {
Lin Ming55ac9a02008-09-28 14:51:56 +0800754 printk(KERN_ERR PREFIX
755 "Call to queue_work() failed.\n");
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300756 status = AE_ERROR;
757 kfree(dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
Lin Ming889c78b2008-12-31 09:23:57 +0800759 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760}
Len Brown4be44fc2005-08-05 00:44:28 -0400761
Zhang Rui19cd8472008-08-28 10:05:06 +0800762acpi_status acpi_os_execute(acpi_execute_type type,
763 acpi_osd_exec_callback function, void *context)
764{
765 return __acpi_os_execute(type, function, context, 0);
766}
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400767EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Zhang Rui19cd8472008-08-28 10:05:06 +0800769acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
770 void *context)
771{
772 return __acpi_os_execute(0, function, context, 1);
773}
774
Len Brown4be44fc2005-08-05 00:44:28 -0400775void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776{
777 flush_workqueue(kacpid_wq);
Zhang Rui2f67a062008-04-29 02:34:42 -0400778 flush_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779}
Len Brown4be44fc2005-08-05 00:44:28 -0400780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781EXPORT_SYMBOL(acpi_os_wait_events_complete);
782
783/*
784 * Allocate the memory for a spinlock and initialize it.
785 */
Bob Moore967440e2006-06-23 17:04:00 -0400786acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787{
Bob Moore967440e2006-06-23 17:04:00 -0400788 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Patrick Mocheld550d982006-06-27 00:41:40 -0400790 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791}
792
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793/*
794 * Deallocate the memory for a spinlock.
795 */
Bob Moore967440e2006-06-23 17:04:00 -0400796void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
Patrick Mocheld550d982006-06-27 00:41:40 -0400798 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799}
800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400802acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
Len Brown4be44fc2005-08-05 00:44:28 -0400804 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 sem = acpi_os_allocate(sizeof(struct semaphore));
807 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400808 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 memset(sem, 0, sizeof(struct semaphore));
810
811 sema_init(sem, initial_units);
812
Len Brown4be44fc2005-08-05 00:44:28 -0400813 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Len Brown4be44fc2005-08-05 00:44:28 -0400815 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
816 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Patrick Mocheld550d982006-06-27 00:41:40 -0400818 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821/*
822 * TODO: A better way to delete semaphores? Linux doesn't have a
823 * 'delete_semaphore()' function -- may result in an invalid
824 * pointer dereference for non-synchronized consumers. Should
825 * we at least check for blocked threads and signal/cancel them?
826 */
827
Len Brown4be44fc2005-08-05 00:44:28 -0400828acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
Len Brown4be44fc2005-08-05 00:44:28 -0400830 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400833 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Len Brown4be44fc2005-08-05 00:44:28 -0400835 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400837 BUG_ON(!list_empty(&sem->wait_list));
Len Brown02438d82006-06-30 03:19:10 -0400838 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400839 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Patrick Mocheld550d982006-06-27 00:41:40 -0400841 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 * TODO: Support for units > 1?
846 */
Len Brown4be44fc2005-08-05 00:44:28 -0400847acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848{
Len Brown4be44fc2005-08-05 00:44:28 -0400849 acpi_status status = AE_OK;
850 struct semaphore *sem = (struct semaphore *)handle;
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400851 long jiffies;
Len Brown4be44fc2005-08-05 00:44:28 -0400852 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400855 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
857 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400858 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Len Brown4be44fc2005-08-05 00:44:28 -0400860 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
861 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400863 if (timeout == ACPI_WAIT_FOREVER)
864 jiffies = MAX_SCHEDULE_TIMEOUT;
865 else
866 jiffies = msecs_to_jiffies(timeout);
867
868 ret = down_timeout(sem, jiffies);
869 if (ret)
870 status = AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400873 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400874 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400875 handle, units, timeout,
876 acpi_format_exception(status)));
877 } else {
878 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400879 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400880 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 }
882
Patrick Mocheld550d982006-06-27 00:41:40 -0400883 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886/*
887 * TODO: Support for units > 1?
888 */
Len Brown4be44fc2005-08-05 00:44:28 -0400889acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890{
Len Brown4be44fc2005-08-05 00:44:28 -0400891 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400894 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400897 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Len Brown4be44fc2005-08-05 00:44:28 -0400899 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
900 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902 up(sem);
903
Patrick Mocheld550d982006-06-27 00:41:40 -0400904 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905}
Len Brown4be44fc2005-08-05 00:44:28 -0400906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400908u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909{
910
911#ifdef ENABLE_DEBUGGER
912 if (acpi_in_debugger) {
913 u32 chars;
914
915 kdb_read(buffer, sizeof(line_buf));
916
917 /* remove the CR kdb includes */
918 chars = strlen(buffer) - 1;
919 buffer[chars] = '\0';
920 }
921#endif
922
923 return 0;
924}
Len Brown4be44fc2005-08-05 00:44:28 -0400925#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
Len Brown4be44fc2005-08-05 00:44:28 -0400927acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928{
Len Brown4be44fc2005-08-05 00:44:28 -0400929 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 case ACPI_SIGNAL_FATAL:
931 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
932 break;
933 case ACPI_SIGNAL_BREAKPOINT:
934 /*
935 * AML Breakpoint
936 * ACPI spec. says to treat it as a NOP unless
937 * you are debugging. So if/when we integrate
938 * AML debugger into the kernel debugger its
939 * hook will go here. But until then it is
940 * not useful to print anything on breakpoints.
941 */
942 break;
943 default:
944 break;
945 }
946
947 return AE_OK;
948}
Len Brown4be44fc2005-08-05 00:44:28 -0400949
Len Brown4be44fc2005-08-05 00:44:28 -0400950static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951{
952 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400953 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 if (!str || !*str)
956 return 0;
957
958 for (; count-- && str && *str; str++) {
959 if (isalnum(*str) || *str == ' ' || *str == ':')
960 *p++ = *str;
961 else if (*str == '\'' || *str == '"')
962 continue;
963 else
964 break;
965 }
966 *p = 0;
967
968 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970}
971
972__setup("acpi_os_name=", acpi_os_name_setup);
973
Len Brownd4b7dc42008-01-23 20:50:56 -0500974static void __init set_osi_linux(unsigned int enable)
975{
976 if (osi_linux.enable != enable) {
977 osi_linux.enable = enable;
978 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
979 enable ? "Add": "Delet");
980 }
981 return;
982}
Len Brownf5076542007-05-30 00:10:38 -0400983
Len Brownd4b7dc42008-01-23 20:50:56 -0500984static void __init acpi_cmdline_osi_linux(unsigned int enable)
985{
986 osi_linux.cmdline = 1; /* cmdline set the default */
987 set_osi_linux(enable);
Len Brownf5076542007-05-30 00:10:38 -0400988
Len Brownd4b7dc42008-01-23 20:50:56 -0500989 return;
990}
991
992void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
993{
994 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
995
996 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
997
998 if (enable == -1)
999 return;
1000
1001 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
1002
1003 set_osi_linux(enable);
1004
Len Brownf5076542007-05-30 00:10:38 -04001005 return;
1006}
1007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008/*
Len Brownae00d812007-05-29 18:43:33 -04001009 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1010 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 * empty string disables _OSI
Len Brownae00d812007-05-29 18:43:33 -04001012 * string starting with '!' disables that string
1013 * otherwise string is added to list, augmenting built-in strings
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 */
Len Brown46c1fbd2008-02-13 23:13:25 -05001015int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
1017 if (str == NULL || *str == '\0') {
1018 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1019 acpi_gbl_create_osi_method = FALSE;
Len Brownaa2e09d2007-07-02 23:57:45 -04001020 } else if (!strcmp("!Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001021 acpi_cmdline_osi_linux(0); /* !enable */
Len Brownae00d812007-05-29 18:43:33 -04001022 } else if (*str == '!') {
1023 if (acpi_osi_invalidate(++str) == AE_OK)
1024 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
Len Brownf5076542007-05-30 00:10:38 -04001025 } else if (!strcmp("Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001026 acpi_cmdline_osi_linux(1); /* enable */
Len Brownae00d812007-05-29 18:43:33 -04001027 } else if (*osi_additional_string == '\0') {
1028 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
1029 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031
1032 return 1;
1033}
1034
1035__setup("acpi_osi=", acpi_osi_setup);
1036
1037/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001038static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039{
1040 printk(KERN_INFO PREFIX "serialize enabled\n");
1041
1042 acpi_gbl_all_methods_serialized = TRUE;
1043
1044 return 1;
1045}
1046
1047__setup("acpi_serialize", acpi_serialize_setup);
1048
1049/*
1050 * Wake and Run-Time GPES are expected to be separate.
1051 * We disable wake-GPEs at run-time to prevent spurious
1052 * interrupts.
1053 *
1054 * However, if a system exists that shares Wake and
1055 * Run-time events on the same GPE this flag is available
1056 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1057 */
Len Brown4be44fc2005-08-05 00:44:28 -04001058static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059{
1060 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1061
1062 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1063
1064 return 1;
1065}
1066
1067__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1068
Thomas Renningerdf92e692008-02-04 23:31:22 -08001069/* Check of resource interference between native drivers and ACPI
1070 * OperationRegions (SystemIO and System Memory only).
1071 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1072 * in arbitrary AML code and can interfere with legacy drivers.
1073 * acpi_enforce_resources= can be set to:
1074 *
Luca Tettamanti7e905602009-03-30 00:01:27 +02001075 * - strict (default) (2)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001076 * -> further driver trying to access the resources will not load
Luca Tettamanti7e905602009-03-30 00:01:27 +02001077 * - lax (1)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001078 * -> further driver trying to access the resources will load, but you
1079 * get a system message that something might go wrong...
1080 *
1081 * - no (0)
1082 * -> ACPI Operation Region resources will not be registered
1083 *
1084 */
1085#define ENFORCE_RESOURCES_STRICT 2
1086#define ENFORCE_RESOURCES_LAX 1
1087#define ENFORCE_RESOURCES_NO 0
1088
Luca Tettamanti7e905602009-03-30 00:01:27 +02001089static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001090
1091static int __init acpi_enforce_resources_setup(char *str)
1092{
1093 if (str == NULL || *str == '\0')
1094 return 0;
1095
1096 if (!strcmp("strict", str))
1097 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1098 else if (!strcmp("lax", str))
1099 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1100 else if (!strcmp("no", str))
1101 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1102
1103 return 1;
1104}
1105
1106__setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1107
1108/* Check for resource conflicts between ACPI OperationRegions and native
1109 * drivers */
Jean Delvare876fba42009-11-11 15:22:15 +01001110int acpi_check_resource_conflict(const struct resource *res)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001111{
1112 struct acpi_res_list *res_list_elem;
1113 int ioport;
1114 int clash = 0;
1115
1116 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1117 return 0;
1118 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1119 return 0;
1120
1121 ioport = res->flags & IORESOURCE_IO;
1122
1123 spin_lock(&acpi_res_lock);
1124 list_for_each_entry(res_list_elem, &resource_list_head,
1125 resource_list) {
1126 if (ioport && (res_list_elem->resource_type
1127 != ACPI_ADR_SPACE_SYSTEM_IO))
1128 continue;
1129 if (!ioport && (res_list_elem->resource_type
1130 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1131 continue;
1132
1133 if (res->end < res_list_elem->start
1134 || res_list_elem->end < res->start)
1135 continue;
1136 clash = 1;
1137 break;
1138 }
1139 spin_unlock(&acpi_res_lock);
1140
1141 if (clash) {
1142 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
Chase Douglas1638bca2010-03-22 15:08:09 -04001143 printk(KERN_WARNING "ACPI: resource %s %pR"
1144 " conflicts with ACPI region %s %pR\n",
1145 res->name, res, res_list_elem->name,
1146 res_list_elem);
Jean Delvare14f03342009-09-08 15:31:46 +02001147 if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
1148 printk(KERN_NOTICE "ACPI: This conflict may"
1149 " cause random problems and system"
1150 " instability\n");
1151 printk(KERN_INFO "ACPI: If an ACPI driver is available"
1152 " for this device, you should use it instead of"
1153 " the native driver\n");
Thomas Renningerdf92e692008-02-04 23:31:22 -08001154 }
1155 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1156 return -EBUSY;
1157 }
1158 return 0;
1159}
Thomas Renninger443dea72008-02-04 23:31:23 -08001160EXPORT_SYMBOL(acpi_check_resource_conflict);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001161
1162int acpi_check_region(resource_size_t start, resource_size_t n,
1163 const char *name)
1164{
1165 struct resource res = {
1166 .start = start,
1167 .end = start + n - 1,
1168 .name = name,
1169 .flags = IORESOURCE_IO,
1170 };
1171
1172 return acpi_check_resource_conflict(&res);
1173}
1174EXPORT_SYMBOL(acpi_check_region);
1175
1176int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1177 const char *name)
1178{
1179 struct resource res = {
1180 .start = start,
1181 .end = start + n - 1,
1182 .name = name,
1183 .flags = IORESOURCE_MEM,
1184 };
1185
1186 return acpi_check_resource_conflict(&res);
1187
1188}
1189EXPORT_SYMBOL(acpi_check_mem_region);
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191/*
Jean Delvare70dd6be2010-05-27 19:58:37 +02001192 * Let drivers know whether the resource checks are effective
1193 */
1194int acpi_resources_are_enforced(void)
1195{
1196 return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
1197}
1198EXPORT_SYMBOL(acpi_resources_are_enforced);
1199
1200/*
Robert Moore73459f72005-06-24 00:00:00 -04001201 * Acquire a spinlock.
1202 *
1203 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001204 */
1205
Bob Moore967440e2006-06-23 17:04:00 -04001206acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001207{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001208 acpi_cpu_flags flags;
Bob Moore967440e2006-06-23 17:04:00 -04001209 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001210 return flags;
1211}
1212
1213/*
1214 * Release a spinlock. See above.
1215 */
1216
Bob Moore967440e2006-06-23 17:04:00 -04001217void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001218{
Bob Moore967440e2006-06-23 17:04:00 -04001219 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001220}
1221
Robert Moore73459f72005-06-24 00:00:00 -04001222#ifndef ACPI_USE_LOCAL_CACHE
1223
1224/*******************************************************************************
1225 *
1226 * FUNCTION: acpi_os_create_cache
1227 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001228 * PARAMETERS: name - Ascii name for the cache
1229 * size - Size of each cached object
1230 * depth - Maximum depth of the cache (in objects) <ignored>
1231 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001232 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001233 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001234 *
1235 * DESCRIPTION: Create a cache object
1236 *
1237 ******************************************************************************/
1238
1239acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001240acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001241{
Paul Mundt20c2df82007-07-20 10:11:58 +09001242 *cache = kmem_cache_create(name, size, 0, 0, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001243 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001244 return AE_ERROR;
1245 else
1246 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001247}
1248
1249/*******************************************************************************
1250 *
1251 * FUNCTION: acpi_os_purge_cache
1252 *
1253 * PARAMETERS: Cache - Handle to cache object
1254 *
1255 * RETURN: Status
1256 *
1257 * DESCRIPTION: Free all objects within the requested cache.
1258 *
1259 ******************************************************************************/
1260
Len Brown4be44fc2005-08-05 00:44:28 -04001261acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001262{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001263 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001264 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001265}
1266
1267/*******************************************************************************
1268 *
1269 * FUNCTION: acpi_os_delete_cache
1270 *
1271 * PARAMETERS: Cache - Handle to cache object
1272 *
1273 * RETURN: Status
1274 *
1275 * DESCRIPTION: Free all objects within the requested cache and delete the
1276 * cache object.
1277 *
1278 ******************************************************************************/
1279
Len Brown4be44fc2005-08-05 00:44:28 -04001280acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001281{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001282 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001283 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001284}
1285
1286/*******************************************************************************
1287 *
1288 * FUNCTION: acpi_os_release_object
1289 *
1290 * PARAMETERS: Cache - Handle to cache object
1291 * Object - The object to be released
1292 *
1293 * RETURN: None
1294 *
1295 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1296 * the object is deleted.
1297 *
1298 ******************************************************************************/
1299
Len Brown4be44fc2005-08-05 00:44:28 -04001300acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001301{
Len Brown4be44fc2005-08-05 00:44:28 -04001302 kmem_cache_free(cache, object);
1303 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001304}
1305
Bob Mooreb229cf92006-04-21 17:15:00 -04001306/******************************************************************************
1307 *
1308 * FUNCTION: acpi_os_validate_interface
1309 *
1310 * PARAMETERS: interface - Requested interface to be validated
1311 *
1312 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1313 *
1314 * DESCRIPTION: Match an interface string to the interfaces supported by the
1315 * host. Strings originate from an AML call to the _OSI method.
1316 *
1317 *****************************************************************************/
1318
1319acpi_status
1320acpi_os_validate_interface (char *interface)
1321{
Len Brownae00d812007-05-29 18:43:33 -04001322 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1323 return AE_OK;
Len Brownf5076542007-05-30 00:10:38 -04001324 if (!strcmp("Linux", interface)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001325
1326 printk(KERN_NOTICE PREFIX
1327 "BIOS _OSI(Linux) query %s%s\n",
1328 osi_linux.enable ? "honored" : "ignored",
1329 osi_linux.cmdline ? " via cmdline" :
1330 osi_linux.dmi ? " via DMI" : "");
1331
Len Brownd4b7dc42008-01-23 20:50:56 -05001332 if (osi_linux.enable)
Len Brownf5076542007-05-30 00:10:38 -04001333 return AE_OK;
1334 }
Len Brownae00d812007-05-29 18:43:33 -04001335 return AE_SUPPORT;
Bob Mooreb229cf92006-04-21 17:15:00 -04001336}
1337
Lin Minga5fe1a02009-08-13 10:43:27 +08001338static inline int acpi_res_list_add(struct acpi_res_list *res)
1339{
1340 struct acpi_res_list *res_list_elem;
1341
1342 list_for_each_entry(res_list_elem, &resource_list_head,
1343 resource_list) {
1344
1345 if (res->resource_type == res_list_elem->resource_type &&
1346 res->start == res_list_elem->start &&
1347 res->end == res_list_elem->end) {
1348
1349 /*
1350 * The Region(addr,len) already exist in the list,
1351 * just increase the count
1352 */
1353
1354 res_list_elem->count++;
1355 return 0;
1356 }
1357 }
1358
1359 res->count = 1;
1360 list_add(&res->resource_list, &resource_list_head);
1361 return 1;
1362}
1363
1364static inline void acpi_res_list_del(struct acpi_res_list *res)
1365{
1366 struct acpi_res_list *res_list_elem;
1367
1368 list_for_each_entry(res_list_elem, &resource_list_head,
1369 resource_list) {
1370
1371 if (res->resource_type == res_list_elem->resource_type &&
1372 res->start == res_list_elem->start &&
1373 res->end == res_list_elem->end) {
1374
1375 /*
1376 * If the res count is decreased to 0,
1377 * remove and free it
1378 */
1379
1380 if (--res_list_elem->count == 0) {
1381 list_del(&res_list_elem->resource_list);
1382 kfree(res_list_elem);
1383 }
1384 return;
1385 }
1386 }
1387}
1388
1389acpi_status
1390acpi_os_invalidate_address(
1391 u8 space_id,
1392 acpi_physical_address address,
1393 acpi_size length)
1394{
1395 struct acpi_res_list res;
1396
1397 switch (space_id) {
1398 case ACPI_ADR_SPACE_SYSTEM_IO:
1399 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
Thomas Weber88393162010-03-16 11:47:56 +01001400 /* Only interference checks against SystemIO and SystemMemory
Lin Minga5fe1a02009-08-13 10:43:27 +08001401 are needed */
1402 res.start = address;
1403 res.end = address + length - 1;
1404 res.resource_type = space_id;
1405 spin_lock(&acpi_res_lock);
1406 acpi_res_list_del(&res);
1407 spin_unlock(&acpi_res_lock);
1408 break;
1409 case ACPI_ADR_SPACE_PCI_CONFIG:
1410 case ACPI_ADR_SPACE_EC:
1411 case ACPI_ADR_SPACE_SMBUS:
1412 case ACPI_ADR_SPACE_CMOS:
1413 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1414 case ACPI_ADR_SPACE_DATA_TABLE:
1415 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1416 break;
1417 }
1418 return AE_OK;
1419}
1420
Bob Mooreb229cf92006-04-21 17:15:00 -04001421/******************************************************************************
1422 *
1423 * FUNCTION: acpi_os_validate_address
1424 *
1425 * PARAMETERS: space_id - ACPI space ID
1426 * address - Physical address
1427 * length - Address length
1428 *
1429 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1430 * should return AE_AML_ILLEGAL_ADDRESS.
1431 *
1432 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1433 * the addresses accessed by AML operation regions.
1434 *
1435 *****************************************************************************/
1436
1437acpi_status
1438acpi_os_validate_address (
1439 u8 space_id,
1440 acpi_physical_address address,
Thomas Renningerdf92e692008-02-04 23:31:22 -08001441 acpi_size length,
1442 char *name)
Bob Mooreb229cf92006-04-21 17:15:00 -04001443{
Thomas Renningerdf92e692008-02-04 23:31:22 -08001444 struct acpi_res_list *res;
Lin Minga5fe1a02009-08-13 10:43:27 +08001445 int added;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001446 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1447 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001448
Thomas Renningerdf92e692008-02-04 23:31:22 -08001449 switch (space_id) {
1450 case ACPI_ADR_SPACE_SYSTEM_IO:
1451 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
Thomas Weber88393162010-03-16 11:47:56 +01001452 /* Only interference checks against SystemIO and SystemMemory
Thomas Renningerdf92e692008-02-04 23:31:22 -08001453 are needed */
1454 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1455 if (!res)
1456 return AE_OK;
1457 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1458 strlcpy(res->name, name, 5);
1459 res->start = address;
1460 res->end = address + length - 1;
1461 res->resource_type = space_id;
1462 spin_lock(&acpi_res_lock);
Lin Minga5fe1a02009-08-13 10:43:27 +08001463 added = acpi_res_list_add(res);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001464 spin_unlock(&acpi_res_lock);
Lin Minga5fe1a02009-08-13 10:43:27 +08001465 pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
1466 "name: %s\n", added ? "Added" : "Already exist",
1467 (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001468 ? "SystemIO" : "System Memory",
1469 (unsigned long long)res->start,
1470 (unsigned long long)res->end,
1471 res->name);
Lin Minga5fe1a02009-08-13 10:43:27 +08001472 if (!added)
1473 kfree(res);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001474 break;
1475 case ACPI_ADR_SPACE_PCI_CONFIG:
1476 case ACPI_ADR_SPACE_EC:
1477 case ACPI_ADR_SPACE_SMBUS:
1478 case ACPI_ADR_SPACE_CMOS:
1479 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1480 case ACPI_ADR_SPACE_DATA_TABLE:
1481 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1482 break;
1483 }
1484 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001485}
1486
Robert Moore73459f72005-06-24 00:00:00 -04001487#endif