blob: 65b25a303b86e495d3f539e94d6a912ae3252325 [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{
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700144 if (!addr->address || !length)
145 return;
146
Andi Kleencfa806f2010-07-20 15:18:36 -0700147 /* Resources are never freed */
Len Browneee3c852007-02-03 01:38:16 -0500148 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Andi Kleencfa806f2010-07-20 15:18:36 -0700149 request_region(addr->address, length, desc);
Len Browneee3c852007-02-03 01:38:16 -0500150 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Andi Kleencfa806f2010-07-20 15:18:36 -0700151 request_mem_region(addr->address, length, desc);
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700152}
153
154static int __init acpi_reserve_resources(void)
155{
Len Browneee3c852007-02-03 01:38:16 -0500156 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700157 "ACPI PM1a_EVT_BLK");
158
Len Browneee3c852007-02-03 01:38:16 -0500159 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700160 "ACPI PM1b_EVT_BLK");
161
Len Browneee3c852007-02-03 01:38:16 -0500162 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700163 "ACPI PM1a_CNT_BLK");
164
Len Browneee3c852007-02-03 01:38:16 -0500165 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700166 "ACPI PM1b_CNT_BLK");
167
Len Browneee3c852007-02-03 01:38:16 -0500168 if (acpi_gbl_FADT.pm_timer_length == 4)
169 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700170
Len Browneee3c852007-02-03 01:38:16 -0500171 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700172 "ACPI PM2_CNT_BLK");
173
174 /* Length of GPE blocks must be a non-negative multiple of 2 */
175
Len Browneee3c852007-02-03 01:38:16 -0500176 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
177 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
178 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700179
Len Browneee3c852007-02-03 01:38:16 -0500180 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
181 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
182 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700183
184 return 0;
185}
186device_initcall(acpi_reserve_resources);
187
Len Browndd272b52007-05-30 00:26:11 -0400188acpi_status __init acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
190 return AE_OK;
191}
192
Len Brown4be44fc2005-08-05 00:44:28 -0400193acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Tejun Heo8fec62b2010-06-29 10:07:09 +0200195 kacpid_wq = create_workqueue("kacpid");
196 kacpi_notify_wq = create_workqueue("kacpi_notify");
197 kacpi_hotplug_wq = create_workqueue("kacpi_hotplug");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 BUG_ON(!kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400199 BUG_ON(!kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800200 BUG_ON(!kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 return AE_OK;
202}
203
Len Brown4be44fc2005-08-05 00:44:28 -0400204acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
206 if (acpi_irq_handler) {
207 acpi_os_remove_interrupt_handler(acpi_irq_irq,
208 acpi_irq_handler);
209 }
210
211 destroy_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400212 destroy_workqueue(kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800213 destroy_workqueue(kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 return AE_OK;
216}
217
Len Brown4be44fc2005-08-05 00:44:28 -0400218void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
220 va_list args;
221 va_start(args, fmt);
222 acpi_os_vprintf(fmt, args);
223 va_end(args);
224}
Len Brown4be44fc2005-08-05 00:44:28 -0400225
Len Brown4be44fc2005-08-05 00:44:28 -0400226void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
228 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 vsprintf(buffer, fmt, args);
231
232#ifdef ENABLE_DEBUGGER
233 if (acpi_in_debugger) {
234 kdb_printf("%s", buffer);
235 } else {
Frank Seidel4d939152009-02-04 17:03:07 +0100236 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 }
238#else
Frank Seidel4d939152009-02-04 17:03:07 +0100239 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240#endif
241}
242
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300243acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800246 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300247 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800248 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300249 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400251 printk(KERN_ERR PREFIX
252 "System description tables not found\n");
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300253 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 }
Len Brown239665a2007-11-23 20:08:02 -0500255 } else {
256 acpi_physical_address pa = 0;
257
258 acpi_find_root_pointer(&pa);
259 return pa;
260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261}
262
Jan Beulich2fdf0742007-12-13 08:33:59 +0000263void __iomem *__init_refok
264acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800266 if (phys > ULONG_MAX) {
267 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Randy Dunlap70c08462007-02-13 16:11:36 -0800268 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 }
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300270 if (acpi_gbl_permanent_mmap)
271 /*
272 * ioremap checks to ensure this is in reserved space
273 */
274 return ioremap((unsigned long)phys, size);
275 else
276 return __acpi_map_table((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800278EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800280void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Yinghai Lu7d972772009-02-07 15:39:41 -0800282 if (acpi_gbl_permanent_mmap)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300283 iounmap(virt);
Yinghai Lu7d972772009-02-07 15:39:41 -0800284 else
285 __acpi_unmap_table(virt, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800287EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800289void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Yinghai Lu7d972772009-02-07 15:39:41 -0800290{
291 if (!acpi_gbl_permanent_mmap)
292 __acpi_unmap_table(virt, size);
293}
294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295#ifdef ACPI_FUTURE_USAGE
296acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400297acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Len Brown4be44fc2005-08-05 00:44:28 -0400299 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 return AE_BAD_PARAMETER;
301
302 *phys = virt_to_phys(virt);
303
304 return AE_OK;
305}
306#endif
307
308#define ACPI_MAX_OVERRIDE_LEN 100
309
310static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
311
312acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400313acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
314 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
316 if (!init_val || !new_val)
317 return AE_BAD_PARAMETER;
318
319 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400320 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400322 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 *new_val = acpi_os_name;
324 }
325
326 return AE_OK;
327}
328
329acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400330acpi_os_table_override(struct acpi_table_header * existing_table,
331 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
333 if (!existing_table || !new_table)
334 return AE_BAD_PARAMETER;
335
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100336 *new_table = NULL;
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338#ifdef CONFIG_ACPI_CUSTOM_DSDT
339 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400340 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341#endif
Éric Piel6ed31e92008-02-05 00:04:50 +0100342 if (*new_table != NULL) {
343 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
344 "this is unsafe: tainting kernel\n",
345 existing_table->signature,
346 existing_table->oem_table_id);
347 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 return AE_OK;
350}
351
David Howells7d12e782006-10-05 14:55:46 +0100352static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Len Brown5229e872008-02-06 01:26:55 -0500354 u32 handled;
355
356 handled = (*acpi_irq_handler) (acpi_irq_context);
357
358 if (handled) {
359 acpi_irq_handled++;
360 return IRQ_HANDLED;
Len Brown88bea182009-04-21 00:35:47 -0400361 } else {
362 acpi_irq_not_handled++;
Len Brown5229e872008-02-06 01:26:55 -0500363 return IRQ_NONE;
Len Brown88bea182009-04-21 00:35:47 -0400364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365}
366
367acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400368acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
369 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
371 unsigned int irq;
372
Len Brown5229e872008-02-06 01:26:55 -0500373 acpi_irq_stats_init();
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 /*
376 * Ignore the GSI from the core, and use the value in our copy of the
377 * FADT. It may not be the same if an interrupt source override exists
378 * for the SCI.
379 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300380 gsi = acpi_gbl_FADT.sci_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
382 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
383 gsi);
384 return AE_OK;
385 }
386
387 acpi_irq_handler = handler;
388 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700389 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
391 return AE_NOT_ACQUIRED;
392 }
393 acpi_irq_irq = irq;
394
395 return AE_OK;
396}
397
Len Brown4be44fc2005-08-05 00:44:28 -0400398acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
400 if (irq) {
401 free_irq(irq, acpi_irq);
402 acpi_irq_handler = NULL;
403 acpi_irq_irq = 0;
404 }
405
406 return AE_OK;
407}
408
409/*
410 * Running in interpreter thread context, safe to sleep
411 */
412
Lin Ming439913f2010-01-28 10:53:19 +0800413void acpi_os_sleep(u64 ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800415 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
Len Brown4be44fc2005-08-05 00:44:28 -0400417
Len Brown4be44fc2005-08-05 00:44:28 -0400418void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
420 while (us) {
421 u32 delay = 1000;
422
423 if (delay > us)
424 delay = us;
425 udelay(delay);
426 touch_nmi_watchdog();
427 us -= delay;
428 }
429}
Len Brown4be44fc2005-08-05 00:44:28 -0400430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431/*
432 * Support ACPI 3.0 AML Timer operand
433 * Returns 64-bit free-running, monotonically increasing timer
434 * with 100ns granularity
435 */
Len Brown4be44fc2005-08-05 00:44:28 -0400436u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
438 static u64 t;
439
440#ifdef CONFIG_HPET
441 /* TBD: use HPET if available */
442#endif
443
444#ifdef CONFIG_X86_PM_TIMER
445 /* TBD: default to PM timer if HPET was not available */
446#endif
447 if (!t)
448 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
449
450 return ++t;
451}
452
Len Brown4be44fc2005-08-05 00:44:28 -0400453acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
455 u32 dummy;
456
457 if (!value)
458 value = &dummy;
459
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800460 *value = 0;
461 if (width <= 8) {
Len Brown4be44fc2005-08-05 00:44:28 -0400462 *(u8 *) value = inb(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800463 } else if (width <= 16) {
Len Brown4be44fc2005-08-05 00:44:28 -0400464 *(u16 *) value = inw(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800465 } else if (width <= 32) {
Len Brown4be44fc2005-08-05 00:44:28 -0400466 *(u32 *) value = inl(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800467 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 BUG();
469 }
470
471 return AE_OK;
472}
Len Brown4be44fc2005-08-05 00:44:28 -0400473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474EXPORT_SYMBOL(acpi_os_read_port);
475
Len Brown4be44fc2005-08-05 00:44:28 -0400476acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800478 if (width <= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 outb(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800480 } else if (width <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 outw(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800482 } else if (width <= 32) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 outl(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800484 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 BUG();
486 }
487
488 return AE_OK;
489}
Len Brown4be44fc2005-08-05 00:44:28 -0400490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491EXPORT_SYMBOL(acpi_os_write_port);
492
493acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400494acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
Len Brown4be44fc2005-08-05 00:44:28 -0400496 u32 dummy;
497 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800499 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 if (!value)
501 value = &dummy;
502
503 switch (width) {
504 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400505 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 break;
507 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400508 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 break;
510 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400511 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 break;
513 default:
514 BUG();
515 }
516
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800517 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519 return AE_OK;
520}
521
522acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400523acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
Len Brown4be44fc2005-08-05 00:44:28 -0400525 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800527 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 switch (width) {
530 case 8:
531 writeb(value, virt_addr);
532 break;
533 case 16:
534 writew(value, virt_addr);
535 break;
536 case 32:
537 writel(value, virt_addr);
538 break;
539 default:
540 BUG();
541 }
542
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800543 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
545 return AE_OK;
546}
547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400549acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Linus Torvalds10270d42008-02-13 09:56:14 -0800550 u32 *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
552 int result, size;
553
554 if (!value)
555 return AE_BAD_PARAMETER;
556
557 switch (width) {
558 case 8:
559 size = 1;
560 break;
561 case 16:
562 size = 2;
563 break;
564 case 32:
565 size = 4;
566 break;
567 default:
568 return AE_ERROR;
569 }
570
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500571 result = raw_pci_read(pci_id->segment, pci_id->bus,
572 PCI_DEVFN(pci_id->device, pci_id->function),
573 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
575 return (result ? AE_ERROR : AE_OK);
576}
Len Brown4be44fc2005-08-05 00:44:28 -0400577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400579acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Lin Ming439913f2010-01-28 10:53:19 +0800580 u64 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
582 int result, size;
583
584 switch (width) {
585 case 8:
586 size = 1;
587 break;
588 case 16:
589 size = 2;
590 break;
591 case 32:
592 size = 4;
593 break;
594 default:
595 return AE_ERROR;
596 }
597
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500598 result = raw_pci_write(pci_id->segment, pci_id->bus,
599 PCI_DEVFN(pci_id->device, pci_id->function),
600 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 return (result ? AE_ERROR : AE_OK);
603}
604
605/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400606static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
607 acpi_handle chandle, /* current node */
608 struct acpi_pci_id **id,
609 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
Len Brown4be44fc2005-08-05 00:44:28 -0400611 acpi_handle handle;
612 struct acpi_pci_id *pci_id = *id;
613 acpi_status status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400614 unsigned long long temp;
Len Brown4be44fc2005-08-05 00:44:28 -0400615 acpi_object_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 acpi_get_parent(chandle, &handle);
618 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400619 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
620 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400623 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 return;
625
Matthew Wilcox27663c52008-10-10 02:22:59 -0400626 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400627 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 if (ACPI_SUCCESS(status)) {
Linus Torvalds10270d42008-02-13 09:56:14 -0800629 u32 val;
Len Brown4be44fc2005-08-05 00:44:28 -0400630 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
631 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
633 if (*is_bridge)
634 pci_id->bus = *bus_number;
635
636 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400637 status =
Linus Torvalds10270d42008-02-13 09:56:14 -0800638 acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
Len Brown4be44fc2005-08-05 00:44:28 -0400639 8);
640 if (ACPI_SUCCESS(status)
Linus Torvalds10270d42008-02-13 09:56:14 -0800641 && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400642 status =
643 acpi_os_read_pci_configuration(pci_id, 0x18,
Linus Torvalds10270d42008-02-13 09:56:14 -0800644 &val, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 if (!ACPI_SUCCESS(status)) {
646 /* Certainly broken... FIX ME */
647 return;
648 }
649 *is_bridge = 1;
Linus Torvalds10270d42008-02-13 09:56:14 -0800650 pci_id->bus = val;
Len Brown4be44fc2005-08-05 00:44:28 -0400651 status =
652 acpi_os_read_pci_configuration(pci_id, 0x19,
Linus Torvalds10270d42008-02-13 09:56:14 -0800653 &val, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 if (ACPI_SUCCESS(status)) {
Linus Torvalds10270d42008-02-13 09:56:14 -0800655 *bus_number = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 }
657 } else
658 *is_bridge = 0;
659 }
660 }
661}
662
Len Brown4be44fc2005-08-05 00:44:28 -0400663void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
664 acpi_handle chandle, /* current node */
665 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666{
667 int is_bridge = 1;
668 u8 bus_number = (*id)->bus;
669
670 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
671}
672
David Howells65f27f32006-11-22 14:55:48 +0000673static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
David Howells65f27f32006-11-22 14:55:48 +0000675 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400676
Bjorn Helgaas9ac61852009-08-31 22:32:10 +0000677 if (dpc->wait)
678 acpi_os_wait_events_complete(NULL);
Zhang Rui19cd8472008-08-28 10:05:06 +0800679
680 dpc->function(dpc->context);
681 kfree(dpc);
Zhang Rui19cd8472008-08-28 10:05:06 +0800682}
683
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400684/*******************************************************************************
685 *
686 * FUNCTION: acpi_os_execute
687 *
688 * PARAMETERS: Type - Type of the callback
689 * Function - Function to be executed
690 * Context - Function parameters
691 *
692 * RETURN: Status
693 *
694 * DESCRIPTION: Depending on type, either queues function for deferred execution or
695 * immediately executes function on a separate thread.
696 *
697 ******************************************************************************/
698
Zhang Rui19cd8472008-08-28 10:05:06 +0800699static acpi_status __acpi_os_execute(acpi_execute_type type,
700 acpi_osd_exec_callback function, void *context, int hp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Len Brown4be44fc2005-08-05 00:44:28 -0400702 acpi_status status = AE_OK;
703 struct acpi_os_dpc *dpc;
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300704 struct workqueue_struct *queue;
Zhang Rui19cd8472008-08-28 10:05:06 +0800705 int ret;
Len Brown72945b22006-07-12 22:46:42 -0400706 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
707 "Scheduling function [%p(%p)] for deferred execution.\n",
708 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 /*
711 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000712 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 * way that allows us to also free its memory inside the callee.
714 * Because we may want to schedule several tasks with different
715 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000716 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 */
Len Brown72945b22006-07-12 22:46:42 -0400718
David Howells65f27f32006-11-22 14:55:48 +0000719 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 if (!dpc)
Lin Ming889c78b2008-12-31 09:23:57 +0800721 return AE_NO_MEMORY;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 dpc->function = function;
724 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800725
Zhang Ruic02256b2009-06-23 10:20:29 +0800726 /*
727 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
728 * because the hotplug code may call driver .remove() functions,
729 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
730 * to flush these workqueues.
731 */
732 queue = hp ? kacpi_hotplug_wq :
733 (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
Bjorn Helgaas9ac61852009-08-31 22:32:10 +0000734 dpc->wait = hp ? 1 : 0;
Zhang Ruibc736752010-03-22 15:48:54 +0800735
736 if (queue == kacpi_hotplug_wq)
737 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
738 else if (queue == kacpi_notify_wq)
739 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
740 else
741 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
742
Tejun Heo8fec62b2010-06-29 10:07:09 +0200743 /*
744 * On some machines, a software-initiated SMI causes corruption unless
745 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
746 * typically it's done in GPE-related methods that are run via
747 * workqueues, so we can avoid the known corruption cases by always
748 * queueing on CPU 0.
749 */
750 ret = queue_work_on(0, queue, &dpc->work);
Zhang Rui19cd8472008-08-28 10:05:06 +0800751
752 if (!ret) {
Lin Ming55ac9a02008-09-28 14:51:56 +0800753 printk(KERN_ERR PREFIX
754 "Call to queue_work() failed.\n");
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300755 status = AE_ERROR;
756 kfree(dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
Lin Ming889c78b2008-12-31 09:23:57 +0800758 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759}
Len Brown4be44fc2005-08-05 00:44:28 -0400760
Zhang Rui19cd8472008-08-28 10:05:06 +0800761acpi_status acpi_os_execute(acpi_execute_type type,
762 acpi_osd_exec_callback function, void *context)
763{
764 return __acpi_os_execute(type, function, context, 0);
765}
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400766EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Zhang Rui19cd8472008-08-28 10:05:06 +0800768acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
769 void *context)
770{
771 return __acpi_os_execute(0, function, context, 1);
772}
773
Len Brown4be44fc2005-08-05 00:44:28 -0400774void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
776 flush_workqueue(kacpid_wq);
Zhang Rui2f67a062008-04-29 02:34:42 -0400777 flush_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778}
Len Brown4be44fc2005-08-05 00:44:28 -0400779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780EXPORT_SYMBOL(acpi_os_wait_events_complete);
781
782/*
783 * Allocate the memory for a spinlock and initialize it.
784 */
Bob Moore967440e2006-06-23 17:04:00 -0400785acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
Bob Moore967440e2006-06-23 17:04:00 -0400787 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Patrick Mocheld550d982006-06-27 00:41:40 -0400789 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790}
791
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792/*
793 * Deallocate the memory for a spinlock.
794 */
Bob Moore967440e2006-06-23 17:04:00 -0400795void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796{
Patrick Mocheld550d982006-06-27 00:41:40 -0400797 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798}
799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400801acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
Len Brown4be44fc2005-08-05 00:44:28 -0400803 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 sem = acpi_os_allocate(sizeof(struct semaphore));
806 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400807 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 memset(sem, 0, sizeof(struct semaphore));
809
810 sema_init(sem, initial_units);
811
Len Brown4be44fc2005-08-05 00:44:28 -0400812 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Len Brown4be44fc2005-08-05 00:44:28 -0400814 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
815 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Patrick Mocheld550d982006-06-27 00:41:40 -0400817 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820/*
821 * TODO: A better way to delete semaphores? Linux doesn't have a
822 * 'delete_semaphore()' function -- may result in an invalid
823 * pointer dereference for non-synchronized consumers. Should
824 * we at least check for blocked threads and signal/cancel them?
825 */
826
Len Brown4be44fc2005-08-05 00:44:28 -0400827acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828{
Len Brown4be44fc2005-08-05 00:44:28 -0400829 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400832 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Len Brown4be44fc2005-08-05 00:44:28 -0400834 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400836 BUG_ON(!list_empty(&sem->wait_list));
Len Brown02438d82006-06-30 03:19:10 -0400837 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400838 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Patrick Mocheld550d982006-06-27 00:41:40 -0400840 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 * TODO: Support for units > 1?
845 */
Len Brown4be44fc2005-08-05 00:44:28 -0400846acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
Len Brown4be44fc2005-08-05 00:44:28 -0400848 acpi_status status = AE_OK;
849 struct semaphore *sem = (struct semaphore *)handle;
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400850 long jiffies;
Len Brown4be44fc2005-08-05 00:44:28 -0400851 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400854 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
856 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400857 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Len Brown4be44fc2005-08-05 00:44:28 -0400859 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
860 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400862 if (timeout == ACPI_WAIT_FOREVER)
863 jiffies = MAX_SCHEDULE_TIMEOUT;
864 else
865 jiffies = msecs_to_jiffies(timeout);
866
867 ret = down_timeout(sem, jiffies);
868 if (ret)
869 status = AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400872 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400873 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400874 handle, units, timeout,
875 acpi_format_exception(status)));
876 } else {
877 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400878 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400879 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 }
881
Patrick Mocheld550d982006-06-27 00:41:40 -0400882 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885/*
886 * TODO: Support for units > 1?
887 */
Len Brown4be44fc2005-08-05 00:44:28 -0400888acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889{
Len Brown4be44fc2005-08-05 00:44:28 -0400890 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400893 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400896 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
Len Brown4be44fc2005-08-05 00:44:28 -0400898 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
899 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901 up(sem);
902
Patrick Mocheld550d982006-06-27 00:41:40 -0400903 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904}
Len Brown4be44fc2005-08-05 00:44:28 -0400905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400907u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
909
910#ifdef ENABLE_DEBUGGER
911 if (acpi_in_debugger) {
912 u32 chars;
913
914 kdb_read(buffer, sizeof(line_buf));
915
916 /* remove the CR kdb includes */
917 chars = strlen(buffer) - 1;
918 buffer[chars] = '\0';
919 }
920#endif
921
922 return 0;
923}
Len Brown4be44fc2005-08-05 00:44:28 -0400924#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Len Brown4be44fc2005-08-05 00:44:28 -0400926acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927{
Len Brown4be44fc2005-08-05 00:44:28 -0400928 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 case ACPI_SIGNAL_FATAL:
930 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
931 break;
932 case ACPI_SIGNAL_BREAKPOINT:
933 /*
934 * AML Breakpoint
935 * ACPI spec. says to treat it as a NOP unless
936 * you are debugging. So if/when we integrate
937 * AML debugger into the kernel debugger its
938 * hook will go here. But until then it is
939 * not useful to print anything on breakpoints.
940 */
941 break;
942 default:
943 break;
944 }
945
946 return AE_OK;
947}
Len Brown4be44fc2005-08-05 00:44:28 -0400948
Len Brown4be44fc2005-08-05 00:44:28 -0400949static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
951 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400952 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
954 if (!str || !*str)
955 return 0;
956
957 for (; count-- && str && *str; str++) {
958 if (isalnum(*str) || *str == ' ' || *str == ':')
959 *p++ = *str;
960 else if (*str == '\'' || *str == '"')
961 continue;
962 else
963 break;
964 }
965 *p = 0;
966
967 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
971__setup("acpi_os_name=", acpi_os_name_setup);
972
Len Brownd4b7dc42008-01-23 20:50:56 -0500973static void __init set_osi_linux(unsigned int enable)
974{
975 if (osi_linux.enable != enable) {
976 osi_linux.enable = enable;
977 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
978 enable ? "Add": "Delet");
979 }
980 return;
981}
Len Brownf5076542007-05-30 00:10:38 -0400982
Len Brownd4b7dc42008-01-23 20:50:56 -0500983static void __init acpi_cmdline_osi_linux(unsigned int enable)
984{
985 osi_linux.cmdline = 1; /* cmdline set the default */
986 set_osi_linux(enable);
Len Brownf5076542007-05-30 00:10:38 -0400987
Len Brownd4b7dc42008-01-23 20:50:56 -0500988 return;
989}
990
991void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
992{
993 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
994
995 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
996
997 if (enable == -1)
998 return;
999
1000 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
1001
1002 set_osi_linux(enable);
1003
Len Brownf5076542007-05-30 00:10:38 -04001004 return;
1005}
1006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007/*
Len Brownae00d812007-05-29 18:43:33 -04001008 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1009 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 * empty string disables _OSI
Len Brownae00d812007-05-29 18:43:33 -04001011 * string starting with '!' disables that string
1012 * otherwise string is added to list, augmenting built-in strings
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 */
Len Brown46c1fbd2008-02-13 23:13:25 -05001014int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015{
1016 if (str == NULL || *str == '\0') {
1017 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1018 acpi_gbl_create_osi_method = FALSE;
Len Brownaa2e09d2007-07-02 23:57:45 -04001019 } else if (!strcmp("!Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001020 acpi_cmdline_osi_linux(0); /* !enable */
Len Brownae00d812007-05-29 18:43:33 -04001021 } else if (*str == '!') {
1022 if (acpi_osi_invalidate(++str) == AE_OK)
1023 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
Len Brownf5076542007-05-30 00:10:38 -04001024 } else if (!strcmp("Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001025 acpi_cmdline_osi_linux(1); /* enable */
Len Brownae00d812007-05-29 18:43:33 -04001026 } else if (*osi_additional_string == '\0') {
1027 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
1028 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 }
1030
1031 return 1;
1032}
1033
1034__setup("acpi_osi=", acpi_osi_setup);
1035
1036/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001037static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038{
1039 printk(KERN_INFO PREFIX "serialize enabled\n");
1040
1041 acpi_gbl_all_methods_serialized = TRUE;
1042
1043 return 1;
1044}
1045
1046__setup("acpi_serialize", acpi_serialize_setup);
1047
Thomas Renningerdf92e692008-02-04 23:31:22 -08001048/* Check of resource interference between native drivers and ACPI
1049 * OperationRegions (SystemIO and System Memory only).
1050 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1051 * in arbitrary AML code and can interfere with legacy drivers.
1052 * acpi_enforce_resources= can be set to:
1053 *
Luca Tettamanti7e905602009-03-30 00:01:27 +02001054 * - strict (default) (2)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001055 * -> further driver trying to access the resources will not load
Luca Tettamanti7e905602009-03-30 00:01:27 +02001056 * - lax (1)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001057 * -> further driver trying to access the resources will load, but you
1058 * get a system message that something might go wrong...
1059 *
1060 * - no (0)
1061 * -> ACPI Operation Region resources will not be registered
1062 *
1063 */
1064#define ENFORCE_RESOURCES_STRICT 2
1065#define ENFORCE_RESOURCES_LAX 1
1066#define ENFORCE_RESOURCES_NO 0
1067
Luca Tettamanti7e905602009-03-30 00:01:27 +02001068static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001069
1070static int __init acpi_enforce_resources_setup(char *str)
1071{
1072 if (str == NULL || *str == '\0')
1073 return 0;
1074
1075 if (!strcmp("strict", str))
1076 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1077 else if (!strcmp("lax", str))
1078 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1079 else if (!strcmp("no", str))
1080 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1081
1082 return 1;
1083}
1084
1085__setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1086
1087/* Check for resource conflicts between ACPI OperationRegions and native
1088 * drivers */
Jean Delvare876fba42009-11-11 15:22:15 +01001089int acpi_check_resource_conflict(const struct resource *res)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001090{
1091 struct acpi_res_list *res_list_elem;
1092 int ioport;
1093 int clash = 0;
1094
1095 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1096 return 0;
1097 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1098 return 0;
1099
1100 ioport = res->flags & IORESOURCE_IO;
1101
1102 spin_lock(&acpi_res_lock);
1103 list_for_each_entry(res_list_elem, &resource_list_head,
1104 resource_list) {
1105 if (ioport && (res_list_elem->resource_type
1106 != ACPI_ADR_SPACE_SYSTEM_IO))
1107 continue;
1108 if (!ioport && (res_list_elem->resource_type
1109 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1110 continue;
1111
1112 if (res->end < res_list_elem->start
1113 || res_list_elem->end < res->start)
1114 continue;
1115 clash = 1;
1116 break;
1117 }
1118 spin_unlock(&acpi_res_lock);
1119
1120 if (clash) {
1121 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
Chase Douglas1638bca2010-03-22 15:08:09 -04001122 printk(KERN_WARNING "ACPI: resource %s %pR"
1123 " conflicts with ACPI region %s %pR\n",
1124 res->name, res, res_list_elem->name,
1125 res_list_elem);
Jean Delvare14f03342009-09-08 15:31:46 +02001126 if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
1127 printk(KERN_NOTICE "ACPI: This conflict may"
1128 " cause random problems and system"
1129 " instability\n");
1130 printk(KERN_INFO "ACPI: If an ACPI driver is available"
1131 " for this device, you should use it instead of"
1132 " the native driver\n");
Thomas Renningerdf92e692008-02-04 23:31:22 -08001133 }
1134 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1135 return -EBUSY;
1136 }
1137 return 0;
1138}
Thomas Renninger443dea72008-02-04 23:31:23 -08001139EXPORT_SYMBOL(acpi_check_resource_conflict);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001140
1141int acpi_check_region(resource_size_t start, resource_size_t n,
1142 const char *name)
1143{
1144 struct resource res = {
1145 .start = start,
1146 .end = start + n - 1,
1147 .name = name,
1148 .flags = IORESOURCE_IO,
1149 };
1150
1151 return acpi_check_resource_conflict(&res);
1152}
1153EXPORT_SYMBOL(acpi_check_region);
1154
1155int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1156 const char *name)
1157{
1158 struct resource res = {
1159 .start = start,
1160 .end = start + n - 1,
1161 .name = name,
1162 .flags = IORESOURCE_MEM,
1163 };
1164
1165 return acpi_check_resource_conflict(&res);
1166
1167}
1168EXPORT_SYMBOL(acpi_check_mem_region);
1169
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170/*
Jean Delvare70dd6be2010-05-27 19:58:37 +02001171 * Let drivers know whether the resource checks are effective
1172 */
1173int acpi_resources_are_enforced(void)
1174{
1175 return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
1176}
1177EXPORT_SYMBOL(acpi_resources_are_enforced);
1178
1179/*
Robert Moore73459f72005-06-24 00:00:00 -04001180 * Acquire a spinlock.
1181 *
1182 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001183 */
1184
Bob Moore967440e2006-06-23 17:04:00 -04001185acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001186{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001187 acpi_cpu_flags flags;
Bob Moore967440e2006-06-23 17:04:00 -04001188 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001189 return flags;
1190}
1191
1192/*
1193 * Release a spinlock. See above.
1194 */
1195
Bob Moore967440e2006-06-23 17:04:00 -04001196void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001197{
Bob Moore967440e2006-06-23 17:04:00 -04001198 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001199}
1200
Robert Moore73459f72005-06-24 00:00:00 -04001201#ifndef ACPI_USE_LOCAL_CACHE
1202
1203/*******************************************************************************
1204 *
1205 * FUNCTION: acpi_os_create_cache
1206 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001207 * PARAMETERS: name - Ascii name for the cache
1208 * size - Size of each cached object
1209 * depth - Maximum depth of the cache (in objects) <ignored>
1210 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001211 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001212 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001213 *
1214 * DESCRIPTION: Create a cache object
1215 *
1216 ******************************************************************************/
1217
1218acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001219acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001220{
Paul Mundt20c2df82007-07-20 10:11:58 +09001221 *cache = kmem_cache_create(name, size, 0, 0, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001222 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001223 return AE_ERROR;
1224 else
1225 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001226}
1227
1228/*******************************************************************************
1229 *
1230 * FUNCTION: acpi_os_purge_cache
1231 *
1232 * PARAMETERS: Cache - Handle to cache object
1233 *
1234 * RETURN: Status
1235 *
1236 * DESCRIPTION: Free all objects within the requested cache.
1237 *
1238 ******************************************************************************/
1239
Len Brown4be44fc2005-08-05 00:44:28 -04001240acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001241{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001242 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001243 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001244}
1245
1246/*******************************************************************************
1247 *
1248 * FUNCTION: acpi_os_delete_cache
1249 *
1250 * PARAMETERS: Cache - Handle to cache object
1251 *
1252 * RETURN: Status
1253 *
1254 * DESCRIPTION: Free all objects within the requested cache and delete the
1255 * cache object.
1256 *
1257 ******************************************************************************/
1258
Len Brown4be44fc2005-08-05 00:44:28 -04001259acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001260{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001261 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001262 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001263}
1264
1265/*******************************************************************************
1266 *
1267 * FUNCTION: acpi_os_release_object
1268 *
1269 * PARAMETERS: Cache - Handle to cache object
1270 * Object - The object to be released
1271 *
1272 * RETURN: None
1273 *
1274 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1275 * the object is deleted.
1276 *
1277 ******************************************************************************/
1278
Len Brown4be44fc2005-08-05 00:44:28 -04001279acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001280{
Len Brown4be44fc2005-08-05 00:44:28 -04001281 kmem_cache_free(cache, object);
1282 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001283}
1284
Bob Mooreb229cf92006-04-21 17:15:00 -04001285/******************************************************************************
1286 *
1287 * FUNCTION: acpi_os_validate_interface
1288 *
1289 * PARAMETERS: interface - Requested interface to be validated
1290 *
1291 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1292 *
1293 * DESCRIPTION: Match an interface string to the interfaces supported by the
1294 * host. Strings originate from an AML call to the _OSI method.
1295 *
1296 *****************************************************************************/
1297
1298acpi_status
1299acpi_os_validate_interface (char *interface)
1300{
Len Brownae00d812007-05-29 18:43:33 -04001301 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1302 return AE_OK;
Len Brownf5076542007-05-30 00:10:38 -04001303 if (!strcmp("Linux", interface)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001304
1305 printk(KERN_NOTICE PREFIX
1306 "BIOS _OSI(Linux) query %s%s\n",
1307 osi_linux.enable ? "honored" : "ignored",
1308 osi_linux.cmdline ? " via cmdline" :
1309 osi_linux.dmi ? " via DMI" : "");
1310
Len Brownd4b7dc42008-01-23 20:50:56 -05001311 if (osi_linux.enable)
Len Brownf5076542007-05-30 00:10:38 -04001312 return AE_OK;
1313 }
Len Brownae00d812007-05-29 18:43:33 -04001314 return AE_SUPPORT;
Bob Mooreb229cf92006-04-21 17:15:00 -04001315}
1316
Lin Minga5fe1a02009-08-13 10:43:27 +08001317static inline int acpi_res_list_add(struct acpi_res_list *res)
1318{
1319 struct acpi_res_list *res_list_elem;
1320
1321 list_for_each_entry(res_list_elem, &resource_list_head,
1322 resource_list) {
1323
1324 if (res->resource_type == res_list_elem->resource_type &&
1325 res->start == res_list_elem->start &&
1326 res->end == res_list_elem->end) {
1327
1328 /*
1329 * The Region(addr,len) already exist in the list,
1330 * just increase the count
1331 */
1332
1333 res_list_elem->count++;
1334 return 0;
1335 }
1336 }
1337
1338 res->count = 1;
1339 list_add(&res->resource_list, &resource_list_head);
1340 return 1;
1341}
1342
1343static inline void acpi_res_list_del(struct acpi_res_list *res)
1344{
1345 struct acpi_res_list *res_list_elem;
1346
1347 list_for_each_entry(res_list_elem, &resource_list_head,
1348 resource_list) {
1349
1350 if (res->resource_type == res_list_elem->resource_type &&
1351 res->start == res_list_elem->start &&
1352 res->end == res_list_elem->end) {
1353
1354 /*
1355 * If the res count is decreased to 0,
1356 * remove and free it
1357 */
1358
1359 if (--res_list_elem->count == 0) {
1360 list_del(&res_list_elem->resource_list);
1361 kfree(res_list_elem);
1362 }
1363 return;
1364 }
1365 }
1366}
1367
1368acpi_status
1369acpi_os_invalidate_address(
1370 u8 space_id,
1371 acpi_physical_address address,
1372 acpi_size length)
1373{
1374 struct acpi_res_list res;
1375
1376 switch (space_id) {
1377 case ACPI_ADR_SPACE_SYSTEM_IO:
1378 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
Thomas Weber88393162010-03-16 11:47:56 +01001379 /* Only interference checks against SystemIO and SystemMemory
Lin Minga5fe1a02009-08-13 10:43:27 +08001380 are needed */
1381 res.start = address;
1382 res.end = address + length - 1;
1383 res.resource_type = space_id;
1384 spin_lock(&acpi_res_lock);
1385 acpi_res_list_del(&res);
1386 spin_unlock(&acpi_res_lock);
1387 break;
1388 case ACPI_ADR_SPACE_PCI_CONFIG:
1389 case ACPI_ADR_SPACE_EC:
1390 case ACPI_ADR_SPACE_SMBUS:
1391 case ACPI_ADR_SPACE_CMOS:
1392 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1393 case ACPI_ADR_SPACE_DATA_TABLE:
1394 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1395 break;
1396 }
1397 return AE_OK;
1398}
1399
Bob Mooreb229cf92006-04-21 17:15:00 -04001400/******************************************************************************
1401 *
1402 * FUNCTION: acpi_os_validate_address
1403 *
1404 * PARAMETERS: space_id - ACPI space ID
1405 * address - Physical address
1406 * length - Address length
1407 *
1408 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1409 * should return AE_AML_ILLEGAL_ADDRESS.
1410 *
1411 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1412 * the addresses accessed by AML operation regions.
1413 *
1414 *****************************************************************************/
1415
1416acpi_status
1417acpi_os_validate_address (
1418 u8 space_id,
1419 acpi_physical_address address,
Thomas Renningerdf92e692008-02-04 23:31:22 -08001420 acpi_size length,
1421 char *name)
Bob Mooreb229cf92006-04-21 17:15:00 -04001422{
Thomas Renningerdf92e692008-02-04 23:31:22 -08001423 struct acpi_res_list *res;
Lin Minga5fe1a02009-08-13 10:43:27 +08001424 int added;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001425 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1426 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001427
Thomas Renningerdf92e692008-02-04 23:31:22 -08001428 switch (space_id) {
1429 case ACPI_ADR_SPACE_SYSTEM_IO:
1430 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
Thomas Weber88393162010-03-16 11:47:56 +01001431 /* Only interference checks against SystemIO and SystemMemory
Thomas Renningerdf92e692008-02-04 23:31:22 -08001432 are needed */
1433 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1434 if (!res)
1435 return AE_OK;
1436 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1437 strlcpy(res->name, name, 5);
1438 res->start = address;
1439 res->end = address + length - 1;
1440 res->resource_type = space_id;
1441 spin_lock(&acpi_res_lock);
Lin Minga5fe1a02009-08-13 10:43:27 +08001442 added = acpi_res_list_add(res);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001443 spin_unlock(&acpi_res_lock);
Lin Minga5fe1a02009-08-13 10:43:27 +08001444 pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
1445 "name: %s\n", added ? "Added" : "Already exist",
1446 (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001447 ? "SystemIO" : "System Memory",
1448 (unsigned long long)res->start,
1449 (unsigned long long)res->end,
1450 res->name);
Lin Minga5fe1a02009-08-13 10:43:27 +08001451 if (!added)
1452 kfree(res);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001453 break;
1454 case ACPI_ADR_SPACE_PCI_CONFIG:
1455 case ACPI_ADR_SPACE_EC:
1456 case ACPI_ADR_SPACE_SMBUS:
1457 case ACPI_ADR_SPACE_CMOS:
1458 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1459 case ACPI_ADR_SPACE_DATA_TABLE:
1460 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1461 break;
1462 }
1463 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001464}
1465
Robert Moore73459f72005-06-24 00:00:00 -04001466#endif