blob: 90a8e86e86f55d29fdd17df00d99a5dc2763101d [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 Starikovskiyad71860a2007-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 */
Lin Mingb0ed7a92010-08-06 09:35:51 +080099static char osi_setup_string[OSI_STRING_LENGTH_MAX];
100
101static void __init acpi_osi_setup_late(void);
Len Brownae00d812007-05-29 18:43:33 -0400102
Len Brownd4b7dc42008-01-23 20:50:56 -0500103/*
Len Browna6e08872008-11-08 01:21:10 -0500104 * The story of _OSI(Linux)
Len Brownd4b7dc42008-01-23 20:50:56 -0500105 *
Len Browna6e08872008-11-08 01:21:10 -0500106 * From pre-history through Linux-2.6.22,
107 * Linux responded TRUE upon a BIOS OSI(Linux) query.
Len Brownd4b7dc42008-01-23 20:50:56 -0500108 *
Len Browna6e08872008-11-08 01:21:10 -0500109 * Unfortunately, reference BIOS writers got wind of this
110 * and put OSI(Linux) in their example code, quickly exposing
111 * this string as ill-conceived and opening the door to
112 * an un-bounded number of BIOS incompatibilities.
Len Brownd4b7dc42008-01-23 20:50:56 -0500113 *
Len Browna6e08872008-11-08 01:21:10 -0500114 * For example, OSI(Linux) was used on resume to re-POST a
115 * video card on one system, because Linux at that time
116 * could not do a speedy restore in its native driver.
117 * But then upon gaining quick native restore capability,
118 * Linux has no way to tell the BIOS to skip the time-consuming
119 * POST -- putting Linux at a permanent performance disadvantage.
120 * On another system, the BIOS writer used OSI(Linux)
121 * to infer native OS support for IPMI! On other systems,
122 * OSI(Linux) simply got in the way of Linux claiming to
123 * be compatible with other operating systems, exposing
124 * BIOS issues such as skipped device initialization.
Len Brownd4b7dc42008-01-23 20:50:56 -0500125 *
Len Browna6e08872008-11-08 01:21:10 -0500126 * So "Linux" turned out to be a really poor chose of
127 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
Len Brownd4b7dc42008-01-23 20:50:56 -0500128 *
129 * BIOS writers should NOT query _OSI(Linux) on future systems.
Len Browna6e08872008-11-08 01:21:10 -0500130 * Linux will complain on the console when it sees it, and return FALSE.
131 * To get Linux to return TRUE for your system will require
132 * a kernel source update to add a DMI entry,
133 * or boot with "acpi_osi=Linux"
Len Brownd4b7dc42008-01-23 20:50:56 -0500134 */
Len Brownd4b7dc42008-01-23 20:50:56 -0500135
Adrian Bunk1d15d842008-01-29 00:10:15 +0200136static struct osi_linux {
Len Brownd4b7dc42008-01-23 20:50:56 -0500137 unsigned int enable:1;
138 unsigned int dmi:1;
139 unsigned int cmdline:1;
140 unsigned int known:1;
Len Browna6e08872008-11-08 01:21:10 -0500141} osi_linux = { 0, 0, 0, 0};
Len Brownf5076542007-05-30 00:10:38 -0400142
Lin Mingb0ed7a92010-08-06 09:35:51 +0800143static u32 acpi_osi_handler(acpi_string interface, u32 supported)
144{
145 if (!strcmp("Linux", interface)) {
146
147 printk(KERN_NOTICE PREFIX
148 "BIOS _OSI(Linux) query %s%s\n",
149 osi_linux.enable ? "honored" : "ignored",
150 osi_linux.cmdline ? " via cmdline" :
151 osi_linux.dmi ? " via DMI" : "");
152 }
153
154 return supported;
155}
156
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700157static void __init acpi_request_region (struct acpi_generic_address *addr,
158 unsigned int length, char *desc)
159{
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700160 if (!addr->address || !length)
161 return;
162
Andi Kleencfa806f2010-07-20 15:18:36 -0700163 /* Resources are never freed */
Len Browneee3c852007-02-03 01:38:16 -0500164 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Andi Kleencfa806f2010-07-20 15:18:36 -0700165 request_region(addr->address, length, desc);
Len Browneee3c852007-02-03 01:38:16 -0500166 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Andi Kleencfa806f2010-07-20 15:18:36 -0700167 request_mem_region(addr->address, length, desc);
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700168}
169
170static int __init acpi_reserve_resources(void)
171{
Len Browneee3c852007-02-03 01:38:16 -0500172 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700173 "ACPI PM1a_EVT_BLK");
174
Len Browneee3c852007-02-03 01:38:16 -0500175 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700176 "ACPI PM1b_EVT_BLK");
177
Len Browneee3c852007-02-03 01:38:16 -0500178 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700179 "ACPI PM1a_CNT_BLK");
180
Len Browneee3c852007-02-03 01:38:16 -0500181 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700182 "ACPI PM1b_CNT_BLK");
183
Len Browneee3c852007-02-03 01:38:16 -0500184 if (acpi_gbl_FADT.pm_timer_length == 4)
185 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700186
Len Browneee3c852007-02-03 01:38:16 -0500187 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700188 "ACPI PM2_CNT_BLK");
189
190 /* Length of GPE blocks must be a non-negative multiple of 2 */
191
Len Browneee3c852007-02-03 01:38:16 -0500192 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
193 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
194 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700195
Len Browneee3c852007-02-03 01:38:16 -0500196 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
197 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
198 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700199
200 return 0;
201}
202device_initcall(acpi_reserve_resources);
203
Len Browndd272b52007-05-30 00:26:11 -0400204acpi_status __init acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
206 return AE_OK;
207}
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Tejun Heo8fec62b2010-06-29 10:07:09 +0200211 kacpid_wq = create_workqueue("kacpid");
212 kacpi_notify_wq = create_workqueue("kacpi_notify");
213 kacpi_hotplug_wq = create_workqueue("kacpi_hotplug");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 BUG_ON(!kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400215 BUG_ON(!kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800216 BUG_ON(!kacpi_hotplug_wq);
Lin Mingb0ed7a92010-08-06 09:35:51 +0800217 acpi_install_interface_handler(acpi_osi_handler);
218 acpi_osi_setup_late();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return AE_OK;
220}
221
Len Brown4be44fc2005-08-05 00:44:28 -0400222acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
224 if (acpi_irq_handler) {
225 acpi_os_remove_interrupt_handler(acpi_irq_irq,
226 acpi_irq_handler);
227 }
228
229 destroy_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400230 destroy_workqueue(kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800231 destroy_workqueue(kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 return AE_OK;
234}
235
Len Brown4be44fc2005-08-05 00:44:28 -0400236void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
238 va_list args;
239 va_start(args, fmt);
240 acpi_os_vprintf(fmt, args);
241 va_end(args);
242}
Len Brown4be44fc2005-08-05 00:44:28 -0400243
Len Brown4be44fc2005-08-05 00:44:28 -0400244void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 vsprintf(buffer, fmt, args);
249
250#ifdef ENABLE_DEBUGGER
251 if (acpi_in_debugger) {
252 kdb_printf("%s", buffer);
253 } else {
Frank Seidel4d939152009-02-04 17:03:07 +0100254 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 }
256#else
Frank Seidel4d939152009-02-04 17:03:07 +0100257 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#endif
259}
260
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300261acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
263 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800264 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300265 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800266 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300267 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400269 printk(KERN_ERR PREFIX
270 "System description tables not found\n");
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300271 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 }
Len Brown239665a2007-11-23 20:08:02 -0500273 } else {
274 acpi_physical_address pa = 0;
275
276 acpi_find_root_pointer(&pa);
277 return pa;
278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}
280
Jan Beulich2fdf0742007-12-13 08:33:59 +0000281void __iomem *__init_refok
282acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800284 if (phys > ULONG_MAX) {
285 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Randy Dunlap70c08462007-02-13 16:11:36 -0800286 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 }
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300288 if (acpi_gbl_permanent_mmap)
289 /*
290 * ioremap checks to ensure this is in reserved space
291 */
292 return ioremap((unsigned long)phys, size);
293 else
294 return __acpi_map_table((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800296EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800298void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
Yinghai Lu7d972772009-02-07 15:39:41 -0800300 if (acpi_gbl_permanent_mmap)
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300301 iounmap(virt);
Yinghai Lu7d972772009-02-07 15:39:41 -0800302 else
303 __acpi_unmap_table(virt, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800305EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800307void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Yinghai Lu7d972772009-02-07 15:39:41 -0800308{
309 if (!acpi_gbl_permanent_mmap)
310 __acpi_unmap_table(virt, size);
311}
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#ifdef ACPI_FUTURE_USAGE
314acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400315acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
Len Brown4be44fc2005-08-05 00:44:28 -0400317 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 return AE_BAD_PARAMETER;
319
320 *phys = virt_to_phys(virt);
321
322 return AE_OK;
323}
324#endif
325
326#define ACPI_MAX_OVERRIDE_LEN 100
327
328static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
329
330acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400331acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
332 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
334 if (!init_val || !new_val)
335 return AE_BAD_PARAMETER;
336
337 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400338 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400340 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 *new_val = acpi_os_name;
342 }
343
344 return AE_OK;
345}
346
347acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400348acpi_os_table_override(struct acpi_table_header * existing_table,
349 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
351 if (!existing_table || !new_table)
352 return AE_BAD_PARAMETER;
353
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100354 *new_table = NULL;
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356#ifdef CONFIG_ACPI_CUSTOM_DSDT
357 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400358 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#endif
Éric Piel6ed31e92008-02-05 00:04:50 +0100360 if (*new_table != NULL) {
361 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
362 "this is unsafe: tainting kernel\n",
363 existing_table->signature,
364 existing_table->oem_table_id);
365 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 return AE_OK;
368}
369
David Howells7d12e782006-10-05 14:55:46 +0100370static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Len Brown5229e872008-02-06 01:26:55 -0500372 u32 handled;
373
374 handled = (*acpi_irq_handler) (acpi_irq_context);
375
376 if (handled) {
377 acpi_irq_handled++;
378 return IRQ_HANDLED;
Len Brown88bea182009-04-21 00:35:47 -0400379 } else {
380 acpi_irq_not_handled++;
Len Brown5229e872008-02-06 01:26:55 -0500381 return IRQ_NONE;
Len Brown88bea182009-04-21 00:35:47 -0400382 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383}
384
385acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400386acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
387 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
389 unsigned int irq;
390
Len Brown5229e872008-02-06 01:26:55 -0500391 acpi_irq_stats_init();
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 /*
394 * Ignore the GSI from the core, and use the value in our copy of the
395 * FADT. It may not be the same if an interrupt source override exists
396 * for the SCI.
397 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300398 gsi = acpi_gbl_FADT.sci_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
400 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
401 gsi);
402 return AE_OK;
403 }
404
405 acpi_irq_handler = handler;
406 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700407 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
409 return AE_NOT_ACQUIRED;
410 }
411 acpi_irq_irq = irq;
412
413 return AE_OK;
414}
415
Len Brown4be44fc2005-08-05 00:44:28 -0400416acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417{
418 if (irq) {
419 free_irq(irq, acpi_irq);
420 acpi_irq_handler = NULL;
421 acpi_irq_irq = 0;
422 }
423
424 return AE_OK;
425}
426
427/*
428 * Running in interpreter thread context, safe to sleep
429 */
430
Lin Ming439913f2010-01-28 10:53:19 +0800431void acpi_os_sleep(u64 ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800433 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434}
Len Brown4be44fc2005-08-05 00:44:28 -0400435
Len Brown4be44fc2005-08-05 00:44:28 -0400436void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
438 while (us) {
439 u32 delay = 1000;
440
441 if (delay > us)
442 delay = us;
443 udelay(delay);
444 touch_nmi_watchdog();
445 us -= delay;
446 }
447}
Len Brown4be44fc2005-08-05 00:44:28 -0400448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449/*
450 * Support ACPI 3.0 AML Timer operand
451 * Returns 64-bit free-running, monotonically increasing timer
452 * with 100ns granularity
453 */
Len Brown4be44fc2005-08-05 00:44:28 -0400454u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
456 static u64 t;
457
458#ifdef CONFIG_HPET
459 /* TBD: use HPET if available */
460#endif
461
462#ifdef CONFIG_X86_PM_TIMER
463 /* TBD: default to PM timer if HPET was not available */
464#endif
465 if (!t)
466 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
467
468 return ++t;
469}
470
Len Brown4be44fc2005-08-05 00:44:28 -0400471acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
473 u32 dummy;
474
475 if (!value)
476 value = &dummy;
477
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800478 *value = 0;
479 if (width <= 8) {
Len Brown4be44fc2005-08-05 00:44:28 -0400480 *(u8 *) value = inb(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800481 } else if (width <= 16) {
Len Brown4be44fc2005-08-05 00:44:28 -0400482 *(u16 *) value = inw(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800483 } else if (width <= 32) {
Len Brown4be44fc2005-08-05 00:44:28 -0400484 *(u32 *) value = inl(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_read_port);
493
Len Brown4be44fc2005-08-05 00:44:28 -0400494acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800496 if (width <= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 outb(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800498 } else if (width <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 outw(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800500 } else if (width <= 32) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 outl(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800502 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 BUG();
504 }
505
506 return AE_OK;
507}
Len Brown4be44fc2005-08-05 00:44:28 -0400508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509EXPORT_SYMBOL(acpi_os_write_port);
510
511acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400512acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513{
Len Brown4be44fc2005-08-05 00:44:28 -0400514 u32 dummy;
515 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800517 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 if (!value)
519 value = &dummy;
520
521 switch (width) {
522 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400523 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 break;
525 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400526 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 break;
528 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400529 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 break;
531 default:
532 BUG();
533 }
534
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800535 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
537 return AE_OK;
538}
539
540acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400541acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Len Brown4be44fc2005-08-05 00:44:28 -0400543 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800545 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 switch (width) {
548 case 8:
549 writeb(value, virt_addr);
550 break;
551 case 16:
552 writew(value, virt_addr);
553 break;
554 case 32:
555 writel(value, virt_addr);
556 break;
557 default:
558 BUG();
559 }
560
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800561 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 return AE_OK;
564}
565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400567acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Bob Moorec5f02312010-08-06 08:57:53 +0800568 u64 *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
570 int result, size;
Bob Moorec5f02312010-08-06 08:57:53 +0800571 u32 value32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 if (!value)
574 return AE_BAD_PARAMETER;
575
576 switch (width) {
577 case 8:
578 size = 1;
579 break;
580 case 16:
581 size = 2;
582 break;
583 case 32:
584 size = 4;
585 break;
586 default:
587 return AE_ERROR;
588 }
589
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500590 result = raw_pci_read(pci_id->segment, pci_id->bus,
591 PCI_DEVFN(pci_id->device, pci_id->function),
Bob Moorec5f02312010-08-06 08:57:53 +0800592 reg, size, &value32);
593 *value = value32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
595 return (result ? AE_ERROR : AE_OK);
596}
Len Brown4be44fc2005-08-05 00:44:28 -0400597
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400599acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Lin Ming439913f2010-01-28 10:53:19 +0800600 u64 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
602 int result, size;
603
604 switch (width) {
605 case 8:
606 size = 1;
607 break;
608 case 16:
609 size = 2;
610 break;
611 case 32:
612 size = 4;
613 break;
614 default:
615 return AE_ERROR;
616 }
617
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500618 result = raw_pci_write(pci_id->segment, pci_id->bus,
619 PCI_DEVFN(pci_id->device, pci_id->function),
620 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 return (result ? AE_ERROR : AE_OK);
623}
624
David Howells65f27f32006-11-22 14:55:48 +0000625static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626{
David Howells65f27f32006-11-22 14:55:48 +0000627 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400628
Bjorn Helgaas9ac61852009-08-31 22:32:10 +0000629 if (dpc->wait)
630 acpi_os_wait_events_complete(NULL);
Zhang Rui19cd8472008-08-28 10:05:06 +0800631
632 dpc->function(dpc->context);
633 kfree(dpc);
Zhang Rui19cd8472008-08-28 10:05:06 +0800634}
635
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400636/*******************************************************************************
637 *
638 * FUNCTION: acpi_os_execute
639 *
640 * PARAMETERS: Type - Type of the callback
641 * Function - Function to be executed
642 * Context - Function parameters
643 *
644 * RETURN: Status
645 *
646 * DESCRIPTION: Depending on type, either queues function for deferred execution or
647 * immediately executes function on a separate thread.
648 *
649 ******************************************************************************/
650
Zhang Rui19cd8472008-08-28 10:05:06 +0800651static acpi_status __acpi_os_execute(acpi_execute_type type,
652 acpi_osd_exec_callback function, void *context, int hp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
Len Brown4be44fc2005-08-05 00:44:28 -0400654 acpi_status status = AE_OK;
655 struct acpi_os_dpc *dpc;
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300656 struct workqueue_struct *queue;
Zhang Rui19cd8472008-08-28 10:05:06 +0800657 int ret;
Len Brown72945b22006-07-12 22:46:42 -0400658 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
659 "Scheduling function [%p(%p)] for deferred execution.\n",
660 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 /*
663 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000664 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 * way that allows us to also free its memory inside the callee.
666 * Because we may want to schedule several tasks with different
667 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000668 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 */
Len Brown72945b22006-07-12 22:46:42 -0400670
David Howells65f27f32006-11-22 14:55:48 +0000671 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 if (!dpc)
Lin Ming889c78b2008-12-31 09:23:57 +0800673 return AE_NO_MEMORY;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 dpc->function = function;
676 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800677
Zhang Ruic02256b2009-06-23 10:20:29 +0800678 /*
679 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
680 * because the hotplug code may call driver .remove() functions,
681 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
682 * to flush these workqueues.
683 */
684 queue = hp ? kacpi_hotplug_wq :
685 (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
Bjorn Helgaas9ac61852009-08-31 22:32:10 +0000686 dpc->wait = hp ? 1 : 0;
Zhang Ruibc736752010-03-22 15:48:54 +0800687
688 if (queue == kacpi_hotplug_wq)
689 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
690 else if (queue == kacpi_notify_wq)
691 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
692 else
693 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
694
Tejun Heo8fec62b2010-06-29 10:07:09 +0200695 /*
696 * On some machines, a software-initiated SMI causes corruption unless
697 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
698 * typically it's done in GPE-related methods that are run via
699 * workqueues, so we can avoid the known corruption cases by always
700 * queueing on CPU 0.
701 */
702 ret = queue_work_on(0, queue, &dpc->work);
Zhang Rui19cd8472008-08-28 10:05:06 +0800703
704 if (!ret) {
Lin Ming55ac9a02008-09-28 14:51:56 +0800705 printk(KERN_ERR PREFIX
706 "Call to queue_work() failed.\n");
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300707 status = AE_ERROR;
708 kfree(dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 }
Lin Ming889c78b2008-12-31 09:23:57 +0800710 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711}
Len Brown4be44fc2005-08-05 00:44:28 -0400712
Zhang Rui19cd8472008-08-28 10:05:06 +0800713acpi_status acpi_os_execute(acpi_execute_type type,
714 acpi_osd_exec_callback function, void *context)
715{
716 return __acpi_os_execute(type, function, context, 0);
717}
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400718EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Zhang Rui19cd8472008-08-28 10:05:06 +0800720acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
721 void *context)
722{
723 return __acpi_os_execute(0, function, context, 1);
724}
725
Len Brown4be44fc2005-08-05 00:44:28 -0400726void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727{
728 flush_workqueue(kacpid_wq);
Zhang Rui2f67a062008-04-29 02:34:42 -0400729 flush_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730}
Len Brown4be44fc2005-08-05 00:44:28 -0400731
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732EXPORT_SYMBOL(acpi_os_wait_events_complete);
733
734/*
735 * Allocate the memory for a spinlock and initialize it.
736 */
Bob Moore967440e32006-06-23 17:04:00 -0400737acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738{
Bob Moore967440e32006-06-23 17:04:00 -0400739 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Patrick Mocheld550d982006-06-27 00:41:40 -0400741 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744/*
745 * Deallocate the memory for a spinlock.
746 */
Bob Moore967440e32006-06-23 17:04:00 -0400747void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
Patrick Mocheld550d982006-06-27 00:41:40 -0400749 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750}
751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400753acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754{
Len Brown4be44fc2005-08-05 00:44:28 -0400755 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 sem = acpi_os_allocate(sizeof(struct semaphore));
758 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400759 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 memset(sem, 0, sizeof(struct semaphore));
761
762 sema_init(sem, initial_units);
763
Len Brown4be44fc2005-08-05 00:44:28 -0400764 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Len Brown4be44fc2005-08-05 00:44:28 -0400766 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
767 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Patrick Mocheld550d982006-06-27 00:41:40 -0400769 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772/*
773 * TODO: A better way to delete semaphores? Linux doesn't have a
774 * 'delete_semaphore()' function -- may result in an invalid
775 * pointer dereference for non-synchronized consumers. Should
776 * we at least check for blocked threads and signal/cancel them?
777 */
778
Len Brown4be44fc2005-08-05 00:44:28 -0400779acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
Len Brown4be44fc2005-08-05 00:44:28 -0400781 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400784 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Len Brown4be44fc2005-08-05 00:44:28 -0400786 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400788 BUG_ON(!list_empty(&sem->wait_list));
Len Brown02438d82006-06-30 03:19:10 -0400789 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400790 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Patrick Mocheld550d982006-06-27 00:41:40 -0400792 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 * TODO: Support for units > 1?
797 */
Len Brown4be44fc2005-08-05 00:44:28 -0400798acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
Len Brown4be44fc2005-08-05 00:44:28 -0400800 acpi_status status = AE_OK;
801 struct semaphore *sem = (struct semaphore *)handle;
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400802 long jiffies;
Len Brown4be44fc2005-08-05 00:44:28 -0400803 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400806 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
808 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400809 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Len Brown4be44fc2005-08-05 00:44:28 -0400811 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
812 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400814 if (timeout == ACPI_WAIT_FOREVER)
815 jiffies = MAX_SCHEDULE_TIMEOUT;
816 else
817 jiffies = msecs_to_jiffies(timeout);
818
819 ret = down_timeout(sem, jiffies);
820 if (ret)
821 status = AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400824 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400825 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400826 handle, units, timeout,
827 acpi_format_exception(status)));
828 } else {
829 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400830 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400831 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 }
833
Patrick Mocheld550d982006-06-27 00:41:40 -0400834 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837/*
838 * TODO: Support for units > 1?
839 */
Len Brown4be44fc2005-08-05 00:44:28 -0400840acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
Len Brown4be44fc2005-08-05 00:44:28 -0400842 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400845 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400848 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Len Brown4be44fc2005-08-05 00:44:28 -0400850 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
851 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 up(sem);
854
Patrick Mocheld550d982006-06-27 00:41:40 -0400855 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856}
Len Brown4be44fc2005-08-05 00:44:28 -0400857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400859u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860{
861
862#ifdef ENABLE_DEBUGGER
863 if (acpi_in_debugger) {
864 u32 chars;
865
866 kdb_read(buffer, sizeof(line_buf));
867
868 /* remove the CR kdb includes */
869 chars = strlen(buffer) - 1;
870 buffer[chars] = '\0';
871 }
872#endif
873
874 return 0;
875}
Len Brown4be44fc2005-08-05 00:44:28 -0400876#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Len Brown4be44fc2005-08-05 00:44:28 -0400878acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
Len Brown4be44fc2005-08-05 00:44:28 -0400880 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 case ACPI_SIGNAL_FATAL:
882 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
883 break;
884 case ACPI_SIGNAL_BREAKPOINT:
885 /*
886 * AML Breakpoint
887 * ACPI spec. says to treat it as a NOP unless
888 * you are debugging. So if/when we integrate
889 * AML debugger into the kernel debugger its
890 * hook will go here. But until then it is
891 * not useful to print anything on breakpoints.
892 */
893 break;
894 default:
895 break;
896 }
897
898 return AE_OK;
899}
Len Brown4be44fc2005-08-05 00:44:28 -0400900
Len Brown4be44fc2005-08-05 00:44:28 -0400901static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902{
903 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400904 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
906 if (!str || !*str)
907 return 0;
908
909 for (; count-- && str && *str; str++) {
910 if (isalnum(*str) || *str == ' ' || *str == ':')
911 *p++ = *str;
912 else if (*str == '\'' || *str == '"')
913 continue;
914 else
915 break;
916 }
917 *p = 0;
918
919 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400920
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921}
922
923__setup("acpi_os_name=", acpi_os_name_setup);
924
Len Brownd4b7dc42008-01-23 20:50:56 -0500925static void __init set_osi_linux(unsigned int enable)
926{
927 if (osi_linux.enable != enable) {
928 osi_linux.enable = enable;
929 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
930 enable ? "Add": "Delet");
931 }
Lin Mingb0ed7a92010-08-06 09:35:51 +0800932
933 if (osi_linux.enable)
934 acpi_osi_setup("Linux");
935 else
936 acpi_osi_setup("!Linux");
937
Len Brownd4b7dc42008-01-23 20:50:56 -0500938 return;
939}
Len Brownf5076542007-05-30 00:10:38 -0400940
Len Brownd4b7dc42008-01-23 20:50:56 -0500941static void __init acpi_cmdline_osi_linux(unsigned int enable)
942{
943 osi_linux.cmdline = 1; /* cmdline set the default */
944 set_osi_linux(enable);
Len Brownf5076542007-05-30 00:10:38 -0400945
Len Brownd4b7dc42008-01-23 20:50:56 -0500946 return;
947}
948
949void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
950{
951 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
952
953 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
954
955 if (enable == -1)
956 return;
957
958 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
959
960 set_osi_linux(enable);
961
Len Brownf5076542007-05-30 00:10:38 -0400962 return;
963}
964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965/*
Len Brownae00d812007-05-29 18:43:33 -0400966 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
967 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 * empty string disables _OSI
Len Brownae00d812007-05-29 18:43:33 -0400969 * string starting with '!' disables that string
970 * otherwise string is added to list, augmenting built-in strings
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 */
Lin Mingb0ed7a92010-08-06 09:35:51 +0800972static void __init acpi_osi_setup_late(void)
973{
974 char *str = osi_setup_string;
975
976 if (*str == '\0')
977 return;
978
979 if (!strcmp("!Linux", str)) {
980 acpi_cmdline_osi_linux(0); /* !enable */
981 } else if (*str == '!') {
982 if (acpi_remove_interface(++str) == AE_OK)
983 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
984 } else if (!strcmp("Linux", str)) {
985 acpi_cmdline_osi_linux(1); /* enable */
986 } else {
987 if (acpi_install_interface(str) == AE_OK)
988 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
989 }
990}
991
Len Brown46c1fbd2008-02-13 23:13:25 -0500992int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
994 if (str == NULL || *str == '\0') {
995 printk(KERN_INFO PREFIX "_OSI method disabled\n");
996 acpi_gbl_create_osi_method = FALSE;
Lin Mingb0ed7a92010-08-06 09:35:51 +0800997 } else {
998 strncpy(osi_setup_string, str, OSI_STRING_LENGTH_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 }
1000
1001 return 1;
1002}
1003
1004__setup("acpi_osi=", acpi_osi_setup);
1005
1006/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001007static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008{
1009 printk(KERN_INFO PREFIX "serialize enabled\n");
1010
1011 acpi_gbl_all_methods_serialized = TRUE;
1012
1013 return 1;
1014}
1015
1016__setup("acpi_serialize", acpi_serialize_setup);
1017
Thomas Renningerdf92e692008-02-04 23:31:22 -08001018/* Check of resource interference between native drivers and ACPI
1019 * OperationRegions (SystemIO and System Memory only).
1020 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1021 * in arbitrary AML code and can interfere with legacy drivers.
1022 * acpi_enforce_resources= can be set to:
1023 *
Luca Tettamanti7e905602009-03-30 00:01:27 +02001024 * - strict (default) (2)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001025 * -> further driver trying to access the resources will not load
Luca Tettamanti7e905602009-03-30 00:01:27 +02001026 * - lax (1)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001027 * -> further driver trying to access the resources will load, but you
1028 * get a system message that something might go wrong...
1029 *
1030 * - no (0)
1031 * -> ACPI Operation Region resources will not be registered
1032 *
1033 */
1034#define ENFORCE_RESOURCES_STRICT 2
1035#define ENFORCE_RESOURCES_LAX 1
1036#define ENFORCE_RESOURCES_NO 0
1037
Luca Tettamanti7e905602009-03-30 00:01:27 +02001038static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001039
1040static int __init acpi_enforce_resources_setup(char *str)
1041{
1042 if (str == NULL || *str == '\0')
1043 return 0;
1044
1045 if (!strcmp("strict", str))
1046 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1047 else if (!strcmp("lax", str))
1048 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1049 else if (!strcmp("no", str))
1050 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1051
1052 return 1;
1053}
1054
1055__setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1056
1057/* Check for resource conflicts between ACPI OperationRegions and native
1058 * drivers */
Jean Delvare876fba42009-11-11 15:22:15 +01001059int acpi_check_resource_conflict(const struct resource *res)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001060{
1061 struct acpi_res_list *res_list_elem;
1062 int ioport;
1063 int clash = 0;
1064
1065 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1066 return 0;
1067 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1068 return 0;
1069
1070 ioport = res->flags & IORESOURCE_IO;
1071
1072 spin_lock(&acpi_res_lock);
1073 list_for_each_entry(res_list_elem, &resource_list_head,
1074 resource_list) {
1075 if (ioport && (res_list_elem->resource_type
1076 != ACPI_ADR_SPACE_SYSTEM_IO))
1077 continue;
1078 if (!ioport && (res_list_elem->resource_type
1079 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1080 continue;
1081
1082 if (res->end < res_list_elem->start
1083 || res_list_elem->end < res->start)
1084 continue;
1085 clash = 1;
1086 break;
1087 }
1088 spin_unlock(&acpi_res_lock);
1089
1090 if (clash) {
1091 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
Chase Douglas1638bca2010-03-22 15:08:09 -04001092 printk(KERN_WARNING "ACPI: resource %s %pR"
1093 " conflicts with ACPI region %s %pR\n",
1094 res->name, res, res_list_elem->name,
1095 res_list_elem);
Jean Delvare14f03342009-09-08 15:31:46 +02001096 if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
1097 printk(KERN_NOTICE "ACPI: This conflict may"
1098 " cause random problems and system"
1099 " instability\n");
1100 printk(KERN_INFO "ACPI: If an ACPI driver is available"
1101 " for this device, you should use it instead of"
1102 " the native driver\n");
Thomas Renningerdf92e692008-02-04 23:31:22 -08001103 }
1104 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1105 return -EBUSY;
1106 }
1107 return 0;
1108}
Thomas Renninger443dea72008-02-04 23:31:23 -08001109EXPORT_SYMBOL(acpi_check_resource_conflict);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001110
1111int acpi_check_region(resource_size_t start, resource_size_t n,
1112 const char *name)
1113{
1114 struct resource res = {
1115 .start = start,
1116 .end = start + n - 1,
1117 .name = name,
1118 .flags = IORESOURCE_IO,
1119 };
1120
1121 return acpi_check_resource_conflict(&res);
1122}
1123EXPORT_SYMBOL(acpi_check_region);
1124
1125int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1126 const char *name)
1127{
1128 struct resource res = {
1129 .start = start,
1130 .end = start + n - 1,
1131 .name = name,
1132 .flags = IORESOURCE_MEM,
1133 };
1134
1135 return acpi_check_resource_conflict(&res);
1136
1137}
1138EXPORT_SYMBOL(acpi_check_mem_region);
1139
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140/*
Jean Delvare70dd6be2010-05-27 19:58:37 +02001141 * Let drivers know whether the resource checks are effective
1142 */
1143int acpi_resources_are_enforced(void)
1144{
1145 return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
1146}
1147EXPORT_SYMBOL(acpi_resources_are_enforced);
1148
1149/*
Robert Moore73459f72005-06-24 00:00:00 -04001150 * Acquire a spinlock.
1151 *
1152 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001153 */
1154
Bob Moore967440e32006-06-23 17:04:00 -04001155acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001156{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001157 acpi_cpu_flags flags;
Bob Moore967440e32006-06-23 17:04:00 -04001158 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001159 return flags;
1160}
1161
1162/*
1163 * Release a spinlock. See above.
1164 */
1165
Bob Moore967440e32006-06-23 17:04:00 -04001166void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001167{
Bob Moore967440e32006-06-23 17:04:00 -04001168 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001169}
1170
Robert Moore73459f72005-06-24 00:00:00 -04001171#ifndef ACPI_USE_LOCAL_CACHE
1172
1173/*******************************************************************************
1174 *
1175 * FUNCTION: acpi_os_create_cache
1176 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001177 * PARAMETERS: name - Ascii name for the cache
1178 * size - Size of each cached object
1179 * depth - Maximum depth of the cache (in objects) <ignored>
1180 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001181 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001182 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001183 *
1184 * DESCRIPTION: Create a cache object
1185 *
1186 ******************************************************************************/
1187
1188acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001189acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001190{
Paul Mundt20c2df82007-07-20 10:11:58 +09001191 *cache = kmem_cache_create(name, size, 0, 0, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001192 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001193 return AE_ERROR;
1194 else
1195 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001196}
1197
1198/*******************************************************************************
1199 *
1200 * FUNCTION: acpi_os_purge_cache
1201 *
1202 * PARAMETERS: Cache - Handle to cache object
1203 *
1204 * RETURN: Status
1205 *
1206 * DESCRIPTION: Free all objects within the requested cache.
1207 *
1208 ******************************************************************************/
1209
Len Brown4be44fc2005-08-05 00:44:28 -04001210acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001211{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001212 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001213 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001214}
1215
1216/*******************************************************************************
1217 *
1218 * FUNCTION: acpi_os_delete_cache
1219 *
1220 * PARAMETERS: Cache - Handle to cache object
1221 *
1222 * RETURN: Status
1223 *
1224 * DESCRIPTION: Free all objects within the requested cache and delete the
1225 * cache object.
1226 *
1227 ******************************************************************************/
1228
Len Brown4be44fc2005-08-05 00:44:28 -04001229acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001230{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001231 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001232 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001233}
1234
1235/*******************************************************************************
1236 *
1237 * FUNCTION: acpi_os_release_object
1238 *
1239 * PARAMETERS: Cache - Handle to cache object
1240 * Object - The object to be released
1241 *
1242 * RETURN: None
1243 *
1244 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1245 * the object is deleted.
1246 *
1247 ******************************************************************************/
1248
Len Brown4be44fc2005-08-05 00:44:28 -04001249acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001250{
Len Brown4be44fc2005-08-05 00:44:28 -04001251 kmem_cache_free(cache, object);
1252 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001253}
1254
Lin Minga5fe1a02009-08-13 10:43:27 +08001255static inline int acpi_res_list_add(struct acpi_res_list *res)
1256{
1257 struct acpi_res_list *res_list_elem;
1258
1259 list_for_each_entry(res_list_elem, &resource_list_head,
1260 resource_list) {
1261
1262 if (res->resource_type == res_list_elem->resource_type &&
1263 res->start == res_list_elem->start &&
1264 res->end == res_list_elem->end) {
1265
1266 /*
1267 * The Region(addr,len) already exist in the list,
1268 * just increase the count
1269 */
1270
1271 res_list_elem->count++;
1272 return 0;
1273 }
1274 }
1275
1276 res->count = 1;
1277 list_add(&res->resource_list, &resource_list_head);
1278 return 1;
1279}
1280
1281static inline void acpi_res_list_del(struct acpi_res_list *res)
1282{
1283 struct acpi_res_list *res_list_elem;
1284
1285 list_for_each_entry(res_list_elem, &resource_list_head,
1286 resource_list) {
1287
1288 if (res->resource_type == res_list_elem->resource_type &&
1289 res->start == res_list_elem->start &&
1290 res->end == res_list_elem->end) {
1291
1292 /*
1293 * If the res count is decreased to 0,
1294 * remove and free it
1295 */
1296
1297 if (--res_list_elem->count == 0) {
1298 list_del(&res_list_elem->resource_list);
1299 kfree(res_list_elem);
1300 }
1301 return;
1302 }
1303 }
1304}
1305
1306acpi_status
1307acpi_os_invalidate_address(
1308 u8 space_id,
1309 acpi_physical_address address,
1310 acpi_size length)
1311{
1312 struct acpi_res_list res;
1313
1314 switch (space_id) {
1315 case ACPI_ADR_SPACE_SYSTEM_IO:
1316 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
Thomas Weber88393162010-03-16 11:47:56 +01001317 /* Only interference checks against SystemIO and SystemMemory
Lin Minga5fe1a02009-08-13 10:43:27 +08001318 are needed */
1319 res.start = address;
1320 res.end = address + length - 1;
1321 res.resource_type = space_id;
1322 spin_lock(&acpi_res_lock);
1323 acpi_res_list_del(&res);
1324 spin_unlock(&acpi_res_lock);
1325 break;
1326 case ACPI_ADR_SPACE_PCI_CONFIG:
1327 case ACPI_ADR_SPACE_EC:
1328 case ACPI_ADR_SPACE_SMBUS:
1329 case ACPI_ADR_SPACE_CMOS:
1330 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1331 case ACPI_ADR_SPACE_DATA_TABLE:
1332 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1333 break;
1334 }
1335 return AE_OK;
1336}
1337
Bob Mooreb229cf92006-04-21 17:15:00 -04001338/******************************************************************************
1339 *
1340 * FUNCTION: acpi_os_validate_address
1341 *
1342 * PARAMETERS: space_id - ACPI space ID
1343 * address - Physical address
1344 * length - Address length
1345 *
1346 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1347 * should return AE_AML_ILLEGAL_ADDRESS.
1348 *
1349 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1350 * the addresses accessed by AML operation regions.
1351 *
1352 *****************************************************************************/
1353
1354acpi_status
1355acpi_os_validate_address (
1356 u8 space_id,
1357 acpi_physical_address address,
Thomas Renningerdf92e692008-02-04 23:31:22 -08001358 acpi_size length,
1359 char *name)
Bob Mooreb229cf92006-04-21 17:15:00 -04001360{
Thomas Renningerdf92e692008-02-04 23:31:22 -08001361 struct acpi_res_list *res;
Lin Minga5fe1a02009-08-13 10:43:27 +08001362 int added;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001363 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1364 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001365
Thomas Renningerdf92e692008-02-04 23:31:22 -08001366 switch (space_id) {
1367 case ACPI_ADR_SPACE_SYSTEM_IO:
1368 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
Thomas Weber88393162010-03-16 11:47:56 +01001369 /* Only interference checks against SystemIO and SystemMemory
Thomas Renningerdf92e692008-02-04 23:31:22 -08001370 are needed */
1371 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1372 if (!res)
1373 return AE_OK;
1374 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1375 strlcpy(res->name, name, 5);
1376 res->start = address;
1377 res->end = address + length - 1;
1378 res->resource_type = space_id;
1379 spin_lock(&acpi_res_lock);
Lin Minga5fe1a02009-08-13 10:43:27 +08001380 added = acpi_res_list_add(res);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001381 spin_unlock(&acpi_res_lock);
Lin Minga5fe1a02009-08-13 10:43:27 +08001382 pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
1383 "name: %s\n", added ? "Added" : "Already exist",
1384 (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001385 ? "SystemIO" : "System Memory",
1386 (unsigned long long)res->start,
1387 (unsigned long long)res->end,
1388 res->name);
Lin Minga5fe1a02009-08-13 10:43:27 +08001389 if (!added)
1390 kfree(res);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001391 break;
1392 case ACPI_ADR_SPACE_PCI_CONFIG:
1393 case ACPI_ADR_SPACE_EC:
1394 case ACPI_ADR_SPACE_SMBUS:
1395 case ACPI_ADR_SPACE_CMOS:
1396 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1397 case ACPI_ADR_SPACE_DATA_TABLE:
1398 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1399 break;
1400 }
1401 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001402}
1403
Robert Moore73459f72005-06-24 00:00:00 -04001404#endif