blob: c5b4f1ed9b71f4fb821232e547b48392f35e39c8 [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061};
62
63#ifdef CONFIG_ACPI_CUSTOM_DSDT
64#include CONFIG_ACPI_CUSTOM_DSDT_FILE
65#endif
66
67#ifdef ENABLE_DEBUGGER
68#include <linux/kdb.h>
69
70/* stuff for debugger support */
71int acpi_in_debugger;
72EXPORT_SYMBOL(acpi_in_debugger);
73
74extern char line_buf[80];
Len Brown4be44fc2005-08-05 00:44:28 -040075#endif /*ENABLE_DEBUGGER */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77static unsigned int acpi_irq_irq;
78static acpi_osd_handler acpi_irq_handler;
79static void *acpi_irq_context;
80static struct workqueue_struct *kacpid_wq;
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -040081static struct workqueue_struct *kacpi_notify_wq;
Zhang Ruic02256b2009-06-23 10:20:29 +080082static struct workqueue_struct *kacpi_hotplug_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Thomas Renningerdf92e692008-02-04 23:31:22 -080084struct acpi_res_list {
85 resource_size_t start;
86 resource_size_t end;
87 acpi_adr_space_type resource_type; /* IO port, System memory, ...*/
88 char name[5]; /* only can have a length of 4 chars, make use of this
89 one instead of res->name, no need to kalloc then */
90 struct list_head resource_list;
Lin Minga5fe1a02009-08-13 10:43:27 +080091 int count;
Thomas Renningerdf92e692008-02-04 23:31:22 -080092};
93
94static LIST_HEAD(resource_list_head);
95static DEFINE_SPINLOCK(acpi_res_lock);
96
Len Brownae00d812007-05-29 18:43:33 -040097#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
98static char osi_additional_string[OSI_STRING_LENGTH_MAX];
99
Len Brownd4b7dc42008-01-23 20:50:56 -0500100/*
Len Browna6e08872008-11-08 01:21:10 -0500101 * The story of _OSI(Linux)
Len Brownd4b7dc42008-01-23 20:50:56 -0500102 *
Len Browna6e08872008-11-08 01:21:10 -0500103 * From pre-history through Linux-2.6.22,
104 * Linux responded TRUE upon a BIOS OSI(Linux) query.
Len Brownd4b7dc42008-01-23 20:50:56 -0500105 *
Len Browna6e08872008-11-08 01:21:10 -0500106 * Unfortunately, reference BIOS writers got wind of this
107 * and put OSI(Linux) in their example code, quickly exposing
108 * this string as ill-conceived and opening the door to
109 * an un-bounded number of BIOS incompatibilities.
Len Brownd4b7dc42008-01-23 20:50:56 -0500110 *
Len Browna6e08872008-11-08 01:21:10 -0500111 * For example, OSI(Linux) was used on resume to re-POST a
112 * video card on one system, because Linux at that time
113 * could not do a speedy restore in its native driver.
114 * But then upon gaining quick native restore capability,
115 * Linux has no way to tell the BIOS to skip the time-consuming
116 * POST -- putting Linux at a permanent performance disadvantage.
117 * On another system, the BIOS writer used OSI(Linux)
118 * to infer native OS support for IPMI! On other systems,
119 * OSI(Linux) simply got in the way of Linux claiming to
120 * be compatible with other operating systems, exposing
121 * BIOS issues such as skipped device initialization.
Len Brownd4b7dc42008-01-23 20:50:56 -0500122 *
Len Browna6e08872008-11-08 01:21:10 -0500123 * So "Linux" turned out to be a really poor chose of
124 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
Len Brownd4b7dc42008-01-23 20:50:56 -0500125 *
126 * BIOS writers should NOT query _OSI(Linux) on future systems.
Len Browna6e08872008-11-08 01:21:10 -0500127 * Linux will complain on the console when it sees it, and return FALSE.
128 * To get Linux to return TRUE for your system will require
129 * a kernel source update to add a DMI entry,
130 * or boot with "acpi_osi=Linux"
Len Brownd4b7dc42008-01-23 20:50:56 -0500131 */
Len Brownd4b7dc42008-01-23 20:50:56 -0500132
Adrian Bunk1d15d842008-01-29 00:10:15 +0200133static struct osi_linux {
Len Brownd4b7dc42008-01-23 20:50:56 -0500134 unsigned int enable:1;
135 unsigned int dmi:1;
136 unsigned int cmdline:1;
137 unsigned int known:1;
Len Browna6e08872008-11-08 01:21:10 -0500138} osi_linux = { 0, 0, 0, 0};
Len Brownf5076542007-05-30 00:10:38 -0400139
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700140static void __init acpi_request_region (struct acpi_generic_address *addr,
141 unsigned int length, char *desc)
142{
143 struct resource *res;
144
145 if (!addr->address || !length)
146 return;
147
Len Browneee3c852007-02-03 01:38:16 -0500148 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700149 res = request_region(addr->address, length, desc);
Len Browneee3c852007-02-03 01:38:16 -0500150 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700151 res = request_mem_region(addr->address, length, desc);
152}
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
Bjorn Helgaas74b58202009-07-29 15:54:25 -0600193static void bind_to_cpu0(struct work_struct *work)
194{
195 set_cpus_allowed(current, cpumask_of_cpu(0));
196 kfree(work);
197}
198
199static void bind_workqueue(struct workqueue_struct *wq)
200{
201 struct work_struct *work;
202
203 work = kzalloc(sizeof(struct work_struct), GFP_KERNEL);
204 INIT_WORK(work, bind_to_cpu0);
205 queue_work(wq, work);
206}
207
Len Brown4be44fc2005-08-05 00:44:28 -0400208acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Bjorn Helgaas74b58202009-07-29 15:54:25 -0600210 /*
211 * On some machines, a software-initiated SMI causes corruption unless
212 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
213 * typically it's done in GPE-related methods that are run via
214 * workqueues, so we can avoid the known corruption cases by binding
215 * the workqueues to CPU 0.
216 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 kacpid_wq = create_singlethread_workqueue("kacpid");
Bjorn Helgaas74b58202009-07-29 15:54:25 -0600218 bind_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400219 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
Bjorn Helgaas74b58202009-07-29 15:54:25 -0600220 bind_workqueue(kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800221 kacpi_hotplug_wq = create_singlethread_workqueue("kacpi_hotplug");
Bjorn Helgaas74b58202009-07-29 15:54:25 -0600222 bind_workqueue(kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 BUG_ON(!kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400224 BUG_ON(!kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800225 BUG_ON(!kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 return AE_OK;
227}
228
Len Brown4be44fc2005-08-05 00:44:28 -0400229acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
231 if (acpi_irq_handler) {
232 acpi_os_remove_interrupt_handler(acpi_irq_irq,
233 acpi_irq_handler);
234 }
235
236 destroy_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400237 destroy_workqueue(kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800238 destroy_workqueue(kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 return AE_OK;
241}
242
Len Brown4be44fc2005-08-05 00:44:28 -0400243void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 va_list args;
246 va_start(args, fmt);
247 acpi_os_vprintf(fmt, args);
248 va_end(args);
249}
Len Brown4be44fc2005-08-05 00:44:28 -0400250
Len Brown4be44fc2005-08-05 00:44:28 -0400251void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
253 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 vsprintf(buffer, fmt, args);
256
257#ifdef ENABLE_DEBUGGER
258 if (acpi_in_debugger) {
259 kdb_printf("%s", buffer);
260 } else {
Frank Seidel4d939152009-02-04 17:03:07 +0100261 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
263#else
Frank Seidel4d939152009-02-04 17:03:07 +0100264 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#endif
266}
267
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300268acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
270 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800271 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300272 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800273 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300274 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400276 printk(KERN_ERR PREFIX
277 "System description tables not found\n");
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300278 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }
Len Brown239665a2007-11-23 20:08:02 -0500280 } else {
281 acpi_physical_address pa = 0;
282
283 acpi_find_root_pointer(&pa);
284 return pa;
285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
287
Jan Beulich2fdf0742007-12-13 08:33:59 +0000288void __iomem *__init_refok
289acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800291 if (phys > ULONG_MAX) {
292 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Randy Dunlap70c08462007-02-13 16:11:36 -0800293 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300295 if (acpi_gbl_permanent_mmap)
296 /*
297 * ioremap checks to ensure this is in reserved space
298 */
299 return ioremap((unsigned long)phys, size);
300 else
301 return __acpi_map_table((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800303EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800305void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
Yinghai Lu7d972772009-02-07 15:39:41 -0800307 if (acpi_gbl_permanent_mmap)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300308 iounmap(virt);
Yinghai Lu7d972772009-02-07 15:39:41 -0800309 else
310 __acpi_unmap_table(virt, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800312EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800314void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Yinghai Lu7d972772009-02-07 15:39:41 -0800315{
316 if (!acpi_gbl_permanent_mmap)
317 __acpi_unmap_table(virt, size);
318}
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#ifdef ACPI_FUTURE_USAGE
321acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400322acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
Len Brown4be44fc2005-08-05 00:44:28 -0400324 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 return AE_BAD_PARAMETER;
326
327 *phys = virt_to_phys(virt);
328
329 return AE_OK;
330}
331#endif
332
333#define ACPI_MAX_OVERRIDE_LEN 100
334
335static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
336
337acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400338acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
339 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
341 if (!init_val || !new_val)
342 return AE_BAD_PARAMETER;
343
344 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400345 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400347 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 *new_val = acpi_os_name;
349 }
350
351 return AE_OK;
352}
353
354acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400355acpi_os_table_override(struct acpi_table_header * existing_table,
356 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
358 if (!existing_table || !new_table)
359 return AE_BAD_PARAMETER;
360
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100361 *new_table = NULL;
362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363#ifdef CONFIG_ACPI_CUSTOM_DSDT
364 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400365 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366#endif
Éric Piel6ed31e92008-02-05 00:04:50 +0100367 if (*new_table != NULL) {
368 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
369 "this is unsafe: tainting kernel\n",
370 existing_table->signature,
371 existing_table->oem_table_id);
372 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 return AE_OK;
375}
376
David Howells7d12e782006-10-05 14:55:46 +0100377static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
Len Brown5229e872008-02-06 01:26:55 -0500379 u32 handled;
380
381 handled = (*acpi_irq_handler) (acpi_irq_context);
382
383 if (handled) {
384 acpi_irq_handled++;
385 return IRQ_HANDLED;
Len Brown88bea182009-04-21 00:35:47 -0400386 } else {
387 acpi_irq_not_handled++;
Len Brown5229e872008-02-06 01:26:55 -0500388 return IRQ_NONE;
Len Brown88bea182009-04-21 00:35:47 -0400389 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390}
391
392acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400393acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
394 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
396 unsigned int irq;
397
Len Brown5229e872008-02-06 01:26:55 -0500398 acpi_irq_stats_init();
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 /*
401 * Ignore the GSI from the core, and use the value in our copy of the
402 * FADT. It may not be the same if an interrupt source override exists
403 * for the SCI.
404 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300405 gsi = acpi_gbl_FADT.sci_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
407 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
408 gsi);
409 return AE_OK;
410 }
411
412 acpi_irq_handler = handler;
413 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700414 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
416 return AE_NOT_ACQUIRED;
417 }
418 acpi_irq_irq = irq;
419
420 return AE_OK;
421}
422
Len Brown4be44fc2005-08-05 00:44:28 -0400423acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
425 if (irq) {
426 free_irq(irq, acpi_irq);
427 acpi_irq_handler = NULL;
428 acpi_irq_irq = 0;
429 }
430
431 return AE_OK;
432}
433
434/*
435 * Running in interpreter thread context, safe to sleep
436 */
437
Len Brown4be44fc2005-08-05 00:44:28 -0400438void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800440 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441}
Len Brown4be44fc2005-08-05 00:44:28 -0400442
Len Brown4be44fc2005-08-05 00:44:28 -0400443void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
445 while (us) {
446 u32 delay = 1000;
447
448 if (delay > us)
449 delay = us;
450 udelay(delay);
451 touch_nmi_watchdog();
452 us -= delay;
453 }
454}
Len Brown4be44fc2005-08-05 00:44:28 -0400455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456/*
457 * Support ACPI 3.0 AML Timer operand
458 * Returns 64-bit free-running, monotonically increasing timer
459 * with 100ns granularity
460 */
Len Brown4be44fc2005-08-05 00:44:28 -0400461u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
463 static u64 t;
464
465#ifdef CONFIG_HPET
466 /* TBD: use HPET if available */
467#endif
468
469#ifdef CONFIG_X86_PM_TIMER
470 /* TBD: default to PM timer if HPET was not available */
471#endif
472 if (!t)
473 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
474
475 return ++t;
476}
477
Len Brown4be44fc2005-08-05 00:44:28 -0400478acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
480 u32 dummy;
481
482 if (!value)
483 value = &dummy;
484
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800485 *value = 0;
486 if (width <= 8) {
Len Brown4be44fc2005-08-05 00:44:28 -0400487 *(u8 *) value = inb(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800488 } else if (width <= 16) {
Len Brown4be44fc2005-08-05 00:44:28 -0400489 *(u16 *) value = inw(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800490 } else if (width <= 32) {
Len Brown4be44fc2005-08-05 00:44:28 -0400491 *(u32 *) value = inl(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800492 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 BUG();
494 }
495
496 return AE_OK;
497}
Len Brown4be44fc2005-08-05 00:44:28 -0400498
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499EXPORT_SYMBOL(acpi_os_read_port);
500
Len Brown4be44fc2005-08-05 00:44:28 -0400501acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502{
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800503 if (width <= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 outb(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800505 } else if (width <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 outw(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800507 } else if (width <= 32) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 outl(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800509 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 BUG();
511 }
512
513 return AE_OK;
514}
Len Brown4be44fc2005-08-05 00:44:28 -0400515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516EXPORT_SYMBOL(acpi_os_write_port);
517
518acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400519acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520{
Len Brown4be44fc2005-08-05 00:44:28 -0400521 u32 dummy;
522 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800524 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 if (!value)
526 value = &dummy;
527
528 switch (width) {
529 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400530 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 break;
532 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400533 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 break;
535 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400536 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 break;
538 default:
539 BUG();
540 }
541
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800542 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 return AE_OK;
545}
546
547acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400548acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
Len Brown4be44fc2005-08-05 00:44:28 -0400550 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800552 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554 switch (width) {
555 case 8:
556 writeb(value, virt_addr);
557 break;
558 case 16:
559 writew(value, virt_addr);
560 break;
561 case 32:
562 writel(value, virt_addr);
563 break;
564 default:
565 BUG();
566 }
567
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800568 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 return AE_OK;
571}
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400574acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Linus Torvalds10270d42008-02-13 09:56:14 -0800575 u32 *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
577 int result, size;
578
579 if (!value)
580 return AE_BAD_PARAMETER;
581
582 switch (width) {
583 case 8:
584 size = 1;
585 break;
586 case 16:
587 size = 2;
588 break;
589 case 32:
590 size = 4;
591 break;
592 default:
593 return AE_ERROR;
594 }
595
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500596 result = raw_pci_read(pci_id->segment, pci_id->bus,
597 PCI_DEVFN(pci_id->device, pci_id->function),
598 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600 return (result ? AE_ERROR : AE_OK);
601}
Len Brown4be44fc2005-08-05 00:44:28 -0400602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400604acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
605 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606{
607 int result, size;
608
609 switch (width) {
610 case 8:
611 size = 1;
612 break;
613 case 16:
614 size = 2;
615 break;
616 case 32:
617 size = 4;
618 break;
619 default:
620 return AE_ERROR;
621 }
622
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500623 result = raw_pci_write(pci_id->segment, pci_id->bus,
624 PCI_DEVFN(pci_id->device, pci_id->function),
625 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 return (result ? AE_ERROR : AE_OK);
628}
629
630/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400631static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
632 acpi_handle chandle, /* current node */
633 struct acpi_pci_id **id,
634 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635{
Len Brown4be44fc2005-08-05 00:44:28 -0400636 acpi_handle handle;
637 struct acpi_pci_id *pci_id = *id;
638 acpi_status status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400639 unsigned long long temp;
Len Brown4be44fc2005-08-05 00:44:28 -0400640 acpi_object_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
642 acpi_get_parent(chandle, &handle);
643 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400644 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
645 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400648 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 return;
650
Matthew Wilcox27663c52008-10-10 02:22:59 -0400651 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400652 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 if (ACPI_SUCCESS(status)) {
Linus Torvalds10270d42008-02-13 09:56:14 -0800654 u32 val;
Len Brown4be44fc2005-08-05 00:44:28 -0400655 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
656 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658 if (*is_bridge)
659 pci_id->bus = *bus_number;
660
661 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400662 status =
Linus Torvalds10270d42008-02-13 09:56:14 -0800663 acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
Len Brown4be44fc2005-08-05 00:44:28 -0400664 8);
665 if (ACPI_SUCCESS(status)
Linus Torvalds10270d42008-02-13 09:56:14 -0800666 && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400667 status =
668 acpi_os_read_pci_configuration(pci_id, 0x18,
Linus Torvalds10270d42008-02-13 09:56:14 -0800669 &val, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 if (!ACPI_SUCCESS(status)) {
671 /* Certainly broken... FIX ME */
672 return;
673 }
674 *is_bridge = 1;
Linus Torvalds10270d42008-02-13 09:56:14 -0800675 pci_id->bus = val;
Len Brown4be44fc2005-08-05 00:44:28 -0400676 status =
677 acpi_os_read_pci_configuration(pci_id, 0x19,
Linus Torvalds10270d42008-02-13 09:56:14 -0800678 &val, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 if (ACPI_SUCCESS(status)) {
Linus Torvalds10270d42008-02-13 09:56:14 -0800680 *bus_number = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
682 } else
683 *is_bridge = 0;
684 }
685 }
686}
687
Len Brown4be44fc2005-08-05 00:44:28 -0400688void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
689 acpi_handle chandle, /* current node */
690 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
692 int is_bridge = 1;
693 u8 bus_number = (*id)->bus;
694
695 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
696}
697
David Howells65f27f32006-11-22 14:55:48 +0000698static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699{
David Howells65f27f32006-11-22 14:55:48 +0000700 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400701 if (!dpc) {
702 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
703 return;
704 }
705
706 dpc->function(dpc->context);
707 kfree(dpc);
708
Patrick Mocheld550d982006-06-27 00:41:40 -0400709 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710}
711
Zhang Rui19cd8472008-08-28 10:05:06 +0800712static void acpi_os_execute_hp_deferred(struct work_struct *work)
713{
714 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
715 if (!dpc) {
716 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
717 return;
718 }
719
720 acpi_os_wait_events_complete(NULL);
721
722 dpc->function(dpc->context);
723 kfree(dpc);
724
725 return;
726}
727
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400728/*******************************************************************************
729 *
730 * FUNCTION: acpi_os_execute
731 *
732 * PARAMETERS: Type - Type of the callback
733 * Function - Function to be executed
734 * Context - Function parameters
735 *
736 * RETURN: Status
737 *
738 * DESCRIPTION: Depending on type, either queues function for deferred execution or
739 * immediately executes function on a separate thread.
740 *
741 ******************************************************************************/
742
Zhang Rui19cd8472008-08-28 10:05:06 +0800743static acpi_status __acpi_os_execute(acpi_execute_type type,
744 acpi_osd_exec_callback function, void *context, int hp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745{
Len Brown4be44fc2005-08-05 00:44:28 -0400746 acpi_status status = AE_OK;
747 struct acpi_os_dpc *dpc;
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300748 struct workqueue_struct *queue;
Zhang Ruic02256b2009-06-23 10:20:29 +0800749 work_func_t func;
Zhang Rui19cd8472008-08-28 10:05:06 +0800750 int ret;
Len Brown72945b22006-07-12 22:46:42 -0400751 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
752 "Scheduling function [%p(%p)] for deferred execution.\n",
753 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755 if (!function)
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400756 return AE_BAD_PARAMETER;
Len Brown72945b22006-07-12 22:46:42 -0400757
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 /*
759 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000760 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 * way that allows us to also free its memory inside the callee.
762 * Because we may want to schedule several tasks with different
763 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000764 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 */
Len Brown72945b22006-07-12 22:46:42 -0400766
David Howells65f27f32006-11-22 14:55:48 +0000767 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 if (!dpc)
Lin Ming889c78b2008-12-31 09:23:57 +0800769 return AE_NO_MEMORY;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 dpc->function = function;
772 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800773
Zhang Ruic02256b2009-06-23 10:20:29 +0800774 /*
775 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
776 * because the hotplug code may call driver .remove() functions,
777 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
778 * to flush these workqueues.
779 */
780 queue = hp ? kacpi_hotplug_wq :
781 (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
782 func = hp ? acpi_os_execute_hp_deferred : acpi_os_execute_deferred;
783 INIT_WORK(&dpc->work, func);
784 ret = queue_work(queue, &dpc->work);
Zhang Rui19cd8472008-08-28 10:05:06 +0800785
786 if (!ret) {
Lin Ming55ac9a02008-09-28 14:51:56 +0800787 printk(KERN_ERR PREFIX
788 "Call to queue_work() failed.\n");
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300789 status = AE_ERROR;
790 kfree(dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 }
Lin Ming889c78b2008-12-31 09:23:57 +0800792 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793}
Len Brown4be44fc2005-08-05 00:44:28 -0400794
Zhang Rui19cd8472008-08-28 10:05:06 +0800795acpi_status acpi_os_execute(acpi_execute_type type,
796 acpi_osd_exec_callback function, void *context)
797{
798 return __acpi_os_execute(type, function, context, 0);
799}
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400800EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Zhang Rui19cd8472008-08-28 10:05:06 +0800802acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
803 void *context)
804{
805 return __acpi_os_execute(0, function, context, 1);
806}
807
Len Brown4be44fc2005-08-05 00:44:28 -0400808void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809{
810 flush_workqueue(kacpid_wq);
Zhang Rui2f67a062008-04-29 02:34:42 -0400811 flush_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812}
Len Brown4be44fc2005-08-05 00:44:28 -0400813
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814EXPORT_SYMBOL(acpi_os_wait_events_complete);
815
816/*
817 * Allocate the memory for a spinlock and initialize it.
818 */
Bob Moore967440e2006-06-23 17:04:00 -0400819acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
Bob Moore967440e2006-06-23 17:04:00 -0400821 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Patrick Mocheld550d982006-06-27 00:41:40 -0400823 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824}
825
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826/*
827 * Deallocate the memory for a spinlock.
828 */
Bob Moore967440e2006-06-23 17:04:00 -0400829void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830{
Patrick Mocheld550d982006-06-27 00:41:40 -0400831 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832}
833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400835acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836{
Len Brown4be44fc2005-08-05 00:44:28 -0400837 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 sem = acpi_os_allocate(sizeof(struct semaphore));
840 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400841 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 memset(sem, 0, sizeof(struct semaphore));
843
844 sema_init(sem, initial_units);
845
Len Brown4be44fc2005-08-05 00:44:28 -0400846 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Len Brown4be44fc2005-08-05 00:44:28 -0400848 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
849 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Patrick Mocheld550d982006-06-27 00:41:40 -0400851 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854/*
855 * TODO: A better way to delete semaphores? Linux doesn't have a
856 * 'delete_semaphore()' function -- may result in an invalid
857 * pointer dereference for non-synchronized consumers. Should
858 * we at least check for blocked threads and signal/cancel them?
859 */
860
Len Brown4be44fc2005-08-05 00:44:28 -0400861acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862{
Len Brown4be44fc2005-08-05 00:44:28 -0400863 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400866 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Len Brown4be44fc2005-08-05 00:44:28 -0400868 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400870 BUG_ON(!list_empty(&sem->wait_list));
Len Brown02438d82006-06-30 03:19:10 -0400871 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400872 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Patrick Mocheld550d982006-06-27 00:41:40 -0400874 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 * TODO: Support for units > 1?
879 */
Len Brown4be44fc2005-08-05 00:44:28 -0400880acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881{
Len Brown4be44fc2005-08-05 00:44:28 -0400882 acpi_status status = AE_OK;
883 struct semaphore *sem = (struct semaphore *)handle;
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400884 long jiffies;
Len Brown4be44fc2005-08-05 00:44:28 -0400885 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400888 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400891 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Len Brown4be44fc2005-08-05 00:44:28 -0400893 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
894 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400896 if (timeout == ACPI_WAIT_FOREVER)
897 jiffies = MAX_SCHEDULE_TIMEOUT;
898 else
899 jiffies = msecs_to_jiffies(timeout);
900
901 ret = down_timeout(sem, jiffies);
902 if (ret)
903 status = AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400906 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400907 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400908 handle, units, timeout,
909 acpi_format_exception(status)));
910 } else {
911 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400912 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400913 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 }
915
Patrick Mocheld550d982006-06-27 00:41:40 -0400916 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919/*
920 * TODO: Support for units > 1?
921 */
Len Brown4be44fc2005-08-05 00:44:28 -0400922acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923{
Len Brown4be44fc2005-08-05 00:44:28 -0400924 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400927 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400930 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Len Brown4be44fc2005-08-05 00:44:28 -0400932 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
933 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
935 up(sem);
936
Patrick Mocheld550d982006-06-27 00:41:40 -0400937 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938}
Len Brown4be44fc2005-08-05 00:44:28 -0400939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400941u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942{
943
944#ifdef ENABLE_DEBUGGER
945 if (acpi_in_debugger) {
946 u32 chars;
947
948 kdb_read(buffer, sizeof(line_buf));
949
950 /* remove the CR kdb includes */
951 chars = strlen(buffer) - 1;
952 buffer[chars] = '\0';
953 }
954#endif
955
956 return 0;
957}
Len Brown4be44fc2005-08-05 00:44:28 -0400958#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
Len Brown4be44fc2005-08-05 00:44:28 -0400960acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961{
Len Brown4be44fc2005-08-05 00:44:28 -0400962 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 case ACPI_SIGNAL_FATAL:
964 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
965 break;
966 case ACPI_SIGNAL_BREAKPOINT:
967 /*
968 * AML Breakpoint
969 * ACPI spec. says to treat it as a NOP unless
970 * you are debugging. So if/when we integrate
971 * AML debugger into the kernel debugger its
972 * hook will go here. But until then it is
973 * not useful to print anything on breakpoints.
974 */
975 break;
976 default:
977 break;
978 }
979
980 return AE_OK;
981}
Len Brown4be44fc2005-08-05 00:44:28 -0400982
Len Brown4be44fc2005-08-05 00:44:28 -0400983static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984{
985 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400986 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988 if (!str || !*str)
989 return 0;
990
991 for (; count-- && str && *str; str++) {
992 if (isalnum(*str) || *str == ' ' || *str == ':')
993 *p++ = *str;
994 else if (*str == '\'' || *str == '"')
995 continue;
996 else
997 break;
998 }
999 *p = 0;
1000
1001 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003}
1004
1005__setup("acpi_os_name=", acpi_os_name_setup);
1006
Len Brownd4b7dc42008-01-23 20:50:56 -05001007static void __init set_osi_linux(unsigned int enable)
1008{
1009 if (osi_linux.enable != enable) {
1010 osi_linux.enable = enable;
1011 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
1012 enable ? "Add": "Delet");
1013 }
1014 return;
1015}
Len Brownf5076542007-05-30 00:10:38 -04001016
Len Brownd4b7dc42008-01-23 20:50:56 -05001017static void __init acpi_cmdline_osi_linux(unsigned int enable)
1018{
1019 osi_linux.cmdline = 1; /* cmdline set the default */
1020 set_osi_linux(enable);
Len Brownf5076542007-05-30 00:10:38 -04001021
Len Brownd4b7dc42008-01-23 20:50:56 -05001022 return;
1023}
1024
1025void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1026{
1027 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1028
1029 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1030
1031 if (enable == -1)
1032 return;
1033
1034 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
1035
1036 set_osi_linux(enable);
1037
Len Brownf5076542007-05-30 00:10:38 -04001038 return;
1039}
1040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041/*
Len Brownae00d812007-05-29 18:43:33 -04001042 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1043 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 * empty string disables _OSI
Len Brownae00d812007-05-29 18:43:33 -04001045 * string starting with '!' disables that string
1046 * otherwise string is added to list, augmenting built-in strings
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 */
Len Brown46c1fbd2008-02-13 23:13:25 -05001048int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049{
1050 if (str == NULL || *str == '\0') {
1051 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1052 acpi_gbl_create_osi_method = FALSE;
Len Brownaa2e09d2007-07-02 23:57:45 -04001053 } else if (!strcmp("!Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001054 acpi_cmdline_osi_linux(0); /* !enable */
Len Brownae00d812007-05-29 18:43:33 -04001055 } else if (*str == '!') {
1056 if (acpi_osi_invalidate(++str) == AE_OK)
1057 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
Len Brownf5076542007-05-30 00:10:38 -04001058 } else if (!strcmp("Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001059 acpi_cmdline_osi_linux(1); /* enable */
Len Brownae00d812007-05-29 18:43:33 -04001060 } else if (*osi_additional_string == '\0') {
1061 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
1062 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
1064
1065 return 1;
1066}
1067
1068__setup("acpi_osi=", acpi_osi_setup);
1069
1070/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001071static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072{
1073 printk(KERN_INFO PREFIX "serialize enabled\n");
1074
1075 acpi_gbl_all_methods_serialized = TRUE;
1076
1077 return 1;
1078}
1079
1080__setup("acpi_serialize", acpi_serialize_setup);
1081
1082/*
1083 * Wake and Run-Time GPES are expected to be separate.
1084 * We disable wake-GPEs at run-time to prevent spurious
1085 * interrupts.
1086 *
1087 * However, if a system exists that shares Wake and
1088 * Run-time events on the same GPE this flag is available
1089 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1090 */
Len Brown4be44fc2005-08-05 00:44:28 -04001091static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092{
1093 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1094
1095 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1096
1097 return 1;
1098}
1099
1100__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1101
Thomas Renningerdf92e692008-02-04 23:31:22 -08001102/* Check of resource interference between native drivers and ACPI
1103 * OperationRegions (SystemIO and System Memory only).
1104 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1105 * in arbitrary AML code and can interfere with legacy drivers.
1106 * acpi_enforce_resources= can be set to:
1107 *
Luca Tettamanti7e905602009-03-30 00:01:27 +02001108 * - strict (default) (2)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001109 * -> further driver trying to access the resources will not load
Luca Tettamanti7e905602009-03-30 00:01:27 +02001110 * - lax (1)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001111 * -> further driver trying to access the resources will load, but you
1112 * get a system message that something might go wrong...
1113 *
1114 * - no (0)
1115 * -> ACPI Operation Region resources will not be registered
1116 *
1117 */
1118#define ENFORCE_RESOURCES_STRICT 2
1119#define ENFORCE_RESOURCES_LAX 1
1120#define ENFORCE_RESOURCES_NO 0
1121
Luca Tettamanti7e905602009-03-30 00:01:27 +02001122static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001123
1124static int __init acpi_enforce_resources_setup(char *str)
1125{
1126 if (str == NULL || *str == '\0')
1127 return 0;
1128
1129 if (!strcmp("strict", str))
1130 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1131 else if (!strcmp("lax", str))
1132 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1133 else if (!strcmp("no", str))
1134 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1135
1136 return 1;
1137}
1138
1139__setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1140
1141/* Check for resource conflicts between ACPI OperationRegions and native
1142 * drivers */
Thomas Renninger443dea72008-02-04 23:31:23 -08001143int acpi_check_resource_conflict(struct resource *res)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001144{
1145 struct acpi_res_list *res_list_elem;
1146 int ioport;
1147 int clash = 0;
1148
1149 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1150 return 0;
1151 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1152 return 0;
1153
1154 ioport = res->flags & IORESOURCE_IO;
1155
1156 spin_lock(&acpi_res_lock);
1157 list_for_each_entry(res_list_elem, &resource_list_head,
1158 resource_list) {
1159 if (ioport && (res_list_elem->resource_type
1160 != ACPI_ADR_SPACE_SYSTEM_IO))
1161 continue;
1162 if (!ioport && (res_list_elem->resource_type
1163 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1164 continue;
1165
1166 if (res->end < res_list_elem->start
1167 || res_list_elem->end < res->start)
1168 continue;
1169 clash = 1;
1170 break;
1171 }
1172 spin_unlock(&acpi_res_lock);
1173
1174 if (clash) {
1175 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
Jean Delvarebd129352008-02-27 20:56:01 +01001176 printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
Thomas Renningerdf92e692008-02-04 23:31:22 -08001177 " conflicts with ACPI region %s"
1178 " [0x%llx-0x%llx]\n",
1179 acpi_enforce_resources == ENFORCE_RESOURCES_LAX
1180 ? KERN_WARNING : KERN_ERR,
1181 ioport ? "I/O" : "Memory", res->name,
1182 (long long) res->start, (long long) res->end,
1183 res_list_elem->name,
1184 (long long) res_list_elem->start,
1185 (long long) res_list_elem->end);
1186 printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
1187 }
1188 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1189 return -EBUSY;
1190 }
1191 return 0;
1192}
Thomas Renninger443dea72008-02-04 23:31:23 -08001193EXPORT_SYMBOL(acpi_check_resource_conflict);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001194
1195int acpi_check_region(resource_size_t start, resource_size_t n,
1196 const char *name)
1197{
1198 struct resource res = {
1199 .start = start,
1200 .end = start + n - 1,
1201 .name = name,
1202 .flags = IORESOURCE_IO,
1203 };
1204
1205 return acpi_check_resource_conflict(&res);
1206}
1207EXPORT_SYMBOL(acpi_check_region);
1208
1209int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1210 const char *name)
1211{
1212 struct resource res = {
1213 .start = start,
1214 .end = start + n - 1,
1215 .name = name,
1216 .flags = IORESOURCE_MEM,
1217 };
1218
1219 return acpi_check_resource_conflict(&res);
1220
1221}
1222EXPORT_SYMBOL(acpi_check_mem_region);
1223
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224/*
Robert Moore73459f72005-06-24 00:00:00 -04001225 * Acquire a spinlock.
1226 *
1227 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001228 */
1229
Bob Moore967440e2006-06-23 17:04:00 -04001230acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001231{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001232 acpi_cpu_flags flags;
Bob Moore967440e2006-06-23 17:04:00 -04001233 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001234 return flags;
1235}
1236
1237/*
1238 * Release a spinlock. See above.
1239 */
1240
Bob Moore967440e2006-06-23 17:04:00 -04001241void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001242{
Bob Moore967440e2006-06-23 17:04:00 -04001243 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001244}
1245
Robert Moore73459f72005-06-24 00:00:00 -04001246#ifndef ACPI_USE_LOCAL_CACHE
1247
1248/*******************************************************************************
1249 *
1250 * FUNCTION: acpi_os_create_cache
1251 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001252 * PARAMETERS: name - Ascii name for the cache
1253 * size - Size of each cached object
1254 * depth - Maximum depth of the cache (in objects) <ignored>
1255 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001256 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001257 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001258 *
1259 * DESCRIPTION: Create a cache object
1260 *
1261 ******************************************************************************/
1262
1263acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001264acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001265{
Paul Mundt20c2df82007-07-20 10:11:58 +09001266 *cache = kmem_cache_create(name, size, 0, 0, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001267 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001268 return AE_ERROR;
1269 else
1270 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001271}
1272
1273/*******************************************************************************
1274 *
1275 * FUNCTION: acpi_os_purge_cache
1276 *
1277 * PARAMETERS: Cache - Handle to cache object
1278 *
1279 * RETURN: Status
1280 *
1281 * DESCRIPTION: Free all objects within the requested cache.
1282 *
1283 ******************************************************************************/
1284
Len Brown4be44fc2005-08-05 00:44:28 -04001285acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001286{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001287 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001288 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001289}
1290
1291/*******************************************************************************
1292 *
1293 * FUNCTION: acpi_os_delete_cache
1294 *
1295 * PARAMETERS: Cache - Handle to cache object
1296 *
1297 * RETURN: Status
1298 *
1299 * DESCRIPTION: Free all objects within the requested cache and delete the
1300 * cache object.
1301 *
1302 ******************************************************************************/
1303
Len Brown4be44fc2005-08-05 00:44:28 -04001304acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001305{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001306 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001307 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001308}
1309
1310/*******************************************************************************
1311 *
1312 * FUNCTION: acpi_os_release_object
1313 *
1314 * PARAMETERS: Cache - Handle to cache object
1315 * Object - The object to be released
1316 *
1317 * RETURN: None
1318 *
1319 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1320 * the object is deleted.
1321 *
1322 ******************************************************************************/
1323
Len Brown4be44fc2005-08-05 00:44:28 -04001324acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001325{
Len Brown4be44fc2005-08-05 00:44:28 -04001326 kmem_cache_free(cache, object);
1327 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001328}
1329
Bob Mooreb229cf92006-04-21 17:15:00 -04001330/******************************************************************************
1331 *
1332 * FUNCTION: acpi_os_validate_interface
1333 *
1334 * PARAMETERS: interface - Requested interface to be validated
1335 *
1336 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1337 *
1338 * DESCRIPTION: Match an interface string to the interfaces supported by the
1339 * host. Strings originate from an AML call to the _OSI method.
1340 *
1341 *****************************************************************************/
1342
1343acpi_status
1344acpi_os_validate_interface (char *interface)
1345{
Len Brownae00d812007-05-29 18:43:33 -04001346 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1347 return AE_OK;
Len Brownf5076542007-05-30 00:10:38 -04001348 if (!strcmp("Linux", interface)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001349
1350 printk(KERN_NOTICE PREFIX
1351 "BIOS _OSI(Linux) query %s%s\n",
1352 osi_linux.enable ? "honored" : "ignored",
1353 osi_linux.cmdline ? " via cmdline" :
1354 osi_linux.dmi ? " via DMI" : "");
1355
Len Brownd4b7dc42008-01-23 20:50:56 -05001356 if (osi_linux.enable)
Len Brownf5076542007-05-30 00:10:38 -04001357 return AE_OK;
1358 }
Len Brownae00d812007-05-29 18:43:33 -04001359 return AE_SUPPORT;
Bob Mooreb229cf92006-04-21 17:15:00 -04001360}
1361
Lin Minga5fe1a02009-08-13 10:43:27 +08001362static inline int acpi_res_list_add(struct acpi_res_list *res)
1363{
1364 struct acpi_res_list *res_list_elem;
1365
1366 list_for_each_entry(res_list_elem, &resource_list_head,
1367 resource_list) {
1368
1369 if (res->resource_type == res_list_elem->resource_type &&
1370 res->start == res_list_elem->start &&
1371 res->end == res_list_elem->end) {
1372
1373 /*
1374 * The Region(addr,len) already exist in the list,
1375 * just increase the count
1376 */
1377
1378 res_list_elem->count++;
1379 return 0;
1380 }
1381 }
1382
1383 res->count = 1;
1384 list_add(&res->resource_list, &resource_list_head);
1385 return 1;
1386}
1387
1388static inline void acpi_res_list_del(struct acpi_res_list *res)
1389{
1390 struct acpi_res_list *res_list_elem;
1391
1392 list_for_each_entry(res_list_elem, &resource_list_head,
1393 resource_list) {
1394
1395 if (res->resource_type == res_list_elem->resource_type &&
1396 res->start == res_list_elem->start &&
1397 res->end == res_list_elem->end) {
1398
1399 /*
1400 * If the res count is decreased to 0,
1401 * remove and free it
1402 */
1403
1404 if (--res_list_elem->count == 0) {
1405 list_del(&res_list_elem->resource_list);
1406 kfree(res_list_elem);
1407 }
1408 return;
1409 }
1410 }
1411}
1412
1413acpi_status
1414acpi_os_invalidate_address(
1415 u8 space_id,
1416 acpi_physical_address address,
1417 acpi_size length)
1418{
1419 struct acpi_res_list res;
1420
1421 switch (space_id) {
1422 case ACPI_ADR_SPACE_SYSTEM_IO:
1423 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1424 /* Only interference checks against SystemIO and SytemMemory
1425 are needed */
1426 res.start = address;
1427 res.end = address + length - 1;
1428 res.resource_type = space_id;
1429 spin_lock(&acpi_res_lock);
1430 acpi_res_list_del(&res);
1431 spin_unlock(&acpi_res_lock);
1432 break;
1433 case ACPI_ADR_SPACE_PCI_CONFIG:
1434 case ACPI_ADR_SPACE_EC:
1435 case ACPI_ADR_SPACE_SMBUS:
1436 case ACPI_ADR_SPACE_CMOS:
1437 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1438 case ACPI_ADR_SPACE_DATA_TABLE:
1439 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1440 break;
1441 }
1442 return AE_OK;
1443}
1444
Bob Mooreb229cf92006-04-21 17:15:00 -04001445/******************************************************************************
1446 *
1447 * FUNCTION: acpi_os_validate_address
1448 *
1449 * PARAMETERS: space_id - ACPI space ID
1450 * address - Physical address
1451 * length - Address length
1452 *
1453 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1454 * should return AE_AML_ILLEGAL_ADDRESS.
1455 *
1456 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1457 * the addresses accessed by AML operation regions.
1458 *
1459 *****************************************************************************/
1460
1461acpi_status
1462acpi_os_validate_address (
1463 u8 space_id,
1464 acpi_physical_address address,
Thomas Renningerdf92e692008-02-04 23:31:22 -08001465 acpi_size length,
1466 char *name)
Bob Mooreb229cf92006-04-21 17:15:00 -04001467{
Thomas Renningerdf92e692008-02-04 23:31:22 -08001468 struct acpi_res_list *res;
Lin Minga5fe1a02009-08-13 10:43:27 +08001469 int added;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001470 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1471 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001472
Thomas Renningerdf92e692008-02-04 23:31:22 -08001473 switch (space_id) {
1474 case ACPI_ADR_SPACE_SYSTEM_IO:
1475 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1476 /* Only interference checks against SystemIO and SytemMemory
1477 are needed */
1478 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1479 if (!res)
1480 return AE_OK;
1481 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1482 strlcpy(res->name, name, 5);
1483 res->start = address;
1484 res->end = address + length - 1;
1485 res->resource_type = space_id;
1486 spin_lock(&acpi_res_lock);
Lin Minga5fe1a02009-08-13 10:43:27 +08001487 added = acpi_res_list_add(res);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001488 spin_unlock(&acpi_res_lock);
Lin Minga5fe1a02009-08-13 10:43:27 +08001489 pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
1490 "name: %s\n", added ? "Added" : "Already exist",
1491 (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001492 ? "SystemIO" : "System Memory",
1493 (unsigned long long)res->start,
1494 (unsigned long long)res->end,
1495 res->name);
Lin Minga5fe1a02009-08-13 10:43:27 +08001496 if (!added)
1497 kfree(res);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001498 break;
1499 case ACPI_ADR_SPACE_PCI_CONFIG:
1500 case ACPI_ADR_SPACE_EC:
1501 case ACPI_ADR_SPACE_SMBUS:
1502 case ACPI_ADR_SPACE_CMOS:
1503 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1504 case ACPI_ADR_SPACE_DATA_TABLE:
1505 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1506 break;
1507 }
1508 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001509}
1510
Robert Moore73459f72005-06-24 00:00:00 -04001511#endif