blob: 5691f165a9527f209c7fcac6febbd73cae43bb65 [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;
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;
91};
92
93static LIST_HEAD(resource_list_head);
94static DEFINE_SPINLOCK(acpi_res_lock);
95
Len Brownae00d812007-05-29 18:43:33 -040096#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
97static char osi_additional_string[OSI_STRING_LENGTH_MAX];
98
Len Brownd4b7dc42008-01-23 20:50:56 -050099/*
Len Browna6e08872008-11-08 01:21:10 -0500100 * The story of _OSI(Linux)
Len Brownd4b7dc42008-01-23 20:50:56 -0500101 *
Len Browna6e08872008-11-08 01:21:10 -0500102 * From pre-history through Linux-2.6.22,
103 * Linux responded TRUE upon a BIOS OSI(Linux) query.
Len Brownd4b7dc42008-01-23 20:50:56 -0500104 *
Len Browna6e08872008-11-08 01:21:10 -0500105 * Unfortunately, reference BIOS writers got wind of this
106 * and put OSI(Linux) in their example code, quickly exposing
107 * this string as ill-conceived and opening the door to
108 * an un-bounded number of BIOS incompatibilities.
Len Brownd4b7dc42008-01-23 20:50:56 -0500109 *
Len Browna6e08872008-11-08 01:21:10 -0500110 * For example, OSI(Linux) was used on resume to re-POST a
111 * video card on one system, because Linux at that time
112 * could not do a speedy restore in its native driver.
113 * But then upon gaining quick native restore capability,
114 * Linux has no way to tell the BIOS to skip the time-consuming
115 * POST -- putting Linux at a permanent performance disadvantage.
116 * On another system, the BIOS writer used OSI(Linux)
117 * to infer native OS support for IPMI! On other systems,
118 * OSI(Linux) simply got in the way of Linux claiming to
119 * be compatible with other operating systems, exposing
120 * BIOS issues such as skipped device initialization.
Len Brownd4b7dc42008-01-23 20:50:56 -0500121 *
Len Browna6e08872008-11-08 01:21:10 -0500122 * So "Linux" turned out to be a really poor chose of
123 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
Len Brownd4b7dc42008-01-23 20:50:56 -0500124 *
125 * BIOS writers should NOT query _OSI(Linux) on future systems.
Len Browna6e08872008-11-08 01:21:10 -0500126 * Linux will complain on the console when it sees it, and return FALSE.
127 * To get Linux to return TRUE for your system will require
128 * a kernel source update to add a DMI entry,
129 * or boot with "acpi_osi=Linux"
Len Brownd4b7dc42008-01-23 20:50:56 -0500130 */
Len Brownd4b7dc42008-01-23 20:50:56 -0500131
Adrian Bunk1d15d842008-01-29 00:10:15 +0200132static struct osi_linux {
Len Brownd4b7dc42008-01-23 20:50:56 -0500133 unsigned int enable:1;
134 unsigned int dmi:1;
135 unsigned int cmdline:1;
136 unsigned int known:1;
Len Browna6e08872008-11-08 01:21:10 -0500137} osi_linux = { 0, 0, 0, 0};
Len Brownf5076542007-05-30 00:10:38 -0400138
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700139static void __init acpi_request_region (struct acpi_generic_address *addr,
140 unsigned int length, char *desc)
141{
142 struct resource *res;
143
144 if (!addr->address || !length)
145 return;
146
Len Browneee3c852007-02-03 01:38:16 -0500147 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700148 res = request_region(addr->address, length, desc);
Len Browneee3c852007-02-03 01:38:16 -0500149 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700150 res = request_mem_region(addr->address, length, desc);
151}
152
153static int __init acpi_reserve_resources(void)
154{
Len Browneee3c852007-02-03 01:38:16 -0500155 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700156 "ACPI PM1a_EVT_BLK");
157
Len Browneee3c852007-02-03 01:38:16 -0500158 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700159 "ACPI PM1b_EVT_BLK");
160
Len Browneee3c852007-02-03 01:38:16 -0500161 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700162 "ACPI PM1a_CNT_BLK");
163
Len Browneee3c852007-02-03 01:38:16 -0500164 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700165 "ACPI PM1b_CNT_BLK");
166
Len Browneee3c852007-02-03 01:38:16 -0500167 if (acpi_gbl_FADT.pm_timer_length == 4)
168 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700169
Len Browneee3c852007-02-03 01:38:16 -0500170 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700171 "ACPI PM2_CNT_BLK");
172
173 /* Length of GPE blocks must be a non-negative multiple of 2 */
174
Len Browneee3c852007-02-03 01:38:16 -0500175 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
176 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
177 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700178
Len Browneee3c852007-02-03 01:38:16 -0500179 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
180 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
181 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700182
183 return 0;
184}
185device_initcall(acpi_reserve_resources);
186
Len Browndd272b52007-05-30 00:26:11 -0400187acpi_status __init acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
189 return AE_OK;
190}
191
Bjorn Helgaas74b58202009-07-29 15:54:25 -0600192static void bind_to_cpu0(struct work_struct *work)
193{
194 set_cpus_allowed(current, cpumask_of_cpu(0));
195 kfree(work);
196}
197
198static void bind_workqueue(struct workqueue_struct *wq)
199{
200 struct work_struct *work;
201
202 work = kzalloc(sizeof(struct work_struct), GFP_KERNEL);
203 INIT_WORK(work, bind_to_cpu0);
204 queue_work(wq, work);
205}
206
Len Brown4be44fc2005-08-05 00:44:28 -0400207acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Bjorn Helgaas74b58202009-07-29 15:54:25 -0600209 /*
210 * On some machines, a software-initiated SMI causes corruption unless
211 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
212 * typically it's done in GPE-related methods that are run via
213 * workqueues, so we can avoid the known corruption cases by binding
214 * the workqueues to CPU 0.
215 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 kacpid_wq = create_singlethread_workqueue("kacpid");
Bjorn Helgaas74b58202009-07-29 15:54:25 -0600217 bind_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400218 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
Bjorn Helgaas74b58202009-07-29 15:54:25 -0600219 bind_workqueue(kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800220 kacpi_hotplug_wq = create_singlethread_workqueue("kacpi_hotplug");
Bjorn Helgaas74b58202009-07-29 15:54:25 -0600221 bind_workqueue(kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 BUG_ON(!kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400223 BUG_ON(!kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800224 BUG_ON(!kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 return AE_OK;
226}
227
Len Brown4be44fc2005-08-05 00:44:28 -0400228acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
230 if (acpi_irq_handler) {
231 acpi_os_remove_interrupt_handler(acpi_irq_irq,
232 acpi_irq_handler);
233 }
234
235 destroy_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400236 destroy_workqueue(kacpi_notify_wq);
Zhang Ruic02256b2009-06-23 10:20:29 +0800237 destroy_workqueue(kacpi_hotplug_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239 return AE_OK;
240}
241
Len Brown4be44fc2005-08-05 00:44:28 -0400242void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
244 va_list args;
245 va_start(args, fmt);
246 acpi_os_vprintf(fmt, args);
247 va_end(args);
248}
Len Brown4be44fc2005-08-05 00:44:28 -0400249
Len Brown4be44fc2005-08-05 00:44:28 -0400250void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
252 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 vsprintf(buffer, fmt, args);
255
256#ifdef ENABLE_DEBUGGER
257 if (acpi_in_debugger) {
258 kdb_printf("%s", buffer);
259 } else {
Frank Seidel4d939152009-02-04 17:03:07 +0100260 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 }
262#else
Frank Seidel4d939152009-02-04 17:03:07 +0100263 printk(KERN_CONT "%s", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#endif
265}
266
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300267acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
269 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800270 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300271 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800272 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300273 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400275 printk(KERN_ERR PREFIX
276 "System description tables not found\n");
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300277 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 }
Len Brown239665a2007-11-23 20:08:02 -0500279 } else {
280 acpi_physical_address pa = 0;
281
282 acpi_find_root_pointer(&pa);
283 return pa;
284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
Jan Beulich2fdf0742007-12-13 08:33:59 +0000287void __iomem *__init_refok
288acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800290 if (phys > ULONG_MAX) {
291 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Randy Dunlap70c08462007-02-13 16:11:36 -0800292 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 }
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300294 if (acpi_gbl_permanent_mmap)
295 /*
296 * ioremap checks to ensure this is in reserved space
297 */
298 return ioremap((unsigned long)phys, size);
299 else
300 return __acpi_map_table((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800302EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800304void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Yinghai Lu7d972772009-02-07 15:39:41 -0800306 if (acpi_gbl_permanent_mmap)
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300307 iounmap(virt);
Yinghai Lu7d972772009-02-07 15:39:41 -0800308 else
309 __acpi_unmap_table(virt, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800311EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Jeremy Fitzhardinge0d3a9cf2009-02-22 14:58:56 -0800313void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
Yinghai Lu7d972772009-02-07 15:39:41 -0800314{
315 if (!acpi_gbl_permanent_mmap)
316 __acpi_unmap_table(virt, size);
317}
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#ifdef ACPI_FUTURE_USAGE
320acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400321acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
Len Brown4be44fc2005-08-05 00:44:28 -0400323 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 return AE_BAD_PARAMETER;
325
326 *phys = virt_to_phys(virt);
327
328 return AE_OK;
329}
330#endif
331
332#define ACPI_MAX_OVERRIDE_LEN 100
333
334static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
335
336acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400337acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
338 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339{
340 if (!init_val || !new_val)
341 return AE_BAD_PARAMETER;
342
343 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400344 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400346 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 *new_val = acpi_os_name;
348 }
349
350 return AE_OK;
351}
352
353acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400354acpi_os_table_override(struct acpi_table_header * existing_table,
355 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
357 if (!existing_table || !new_table)
358 return AE_BAD_PARAMETER;
359
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100360 *new_table = NULL;
361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362#ifdef CONFIG_ACPI_CUSTOM_DSDT
363 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400364 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#endif
Éric Piel6ed31e92008-02-05 00:04:50 +0100366 if (*new_table != NULL) {
367 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
368 "this is unsafe: tainting kernel\n",
369 existing_table->signature,
370 existing_table->oem_table_id);
371 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 return AE_OK;
374}
375
David Howells7d12e782006-10-05 14:55:46 +0100376static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377{
Len Brown5229e872008-02-06 01:26:55 -0500378 u32 handled;
379
380 handled = (*acpi_irq_handler) (acpi_irq_context);
381
382 if (handled) {
383 acpi_irq_handled++;
384 return IRQ_HANDLED;
Len Brown88bea182009-04-21 00:35:47 -0400385 } else {
386 acpi_irq_not_handled++;
Len Brown5229e872008-02-06 01:26:55 -0500387 return IRQ_NONE;
Len Brown88bea182009-04-21 00:35:47 -0400388 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
391acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400392acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
393 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
395 unsigned int irq;
396
Len Brown5229e872008-02-06 01:26:55 -0500397 acpi_irq_stats_init();
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 /*
400 * Ignore the GSI from the core, and use the value in our copy of the
401 * FADT. It may not be the same if an interrupt source override exists
402 * for the SCI.
403 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300404 gsi = acpi_gbl_FADT.sci_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
406 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
407 gsi);
408 return AE_OK;
409 }
410
411 acpi_irq_handler = handler;
412 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700413 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
415 return AE_NOT_ACQUIRED;
416 }
417 acpi_irq_irq = irq;
418
419 return AE_OK;
420}
421
Len Brown4be44fc2005-08-05 00:44:28 -0400422acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
424 if (irq) {
425 free_irq(irq, acpi_irq);
426 acpi_irq_handler = NULL;
427 acpi_irq_irq = 0;
428 }
429
430 return AE_OK;
431}
432
433/*
434 * Running in interpreter thread context, safe to sleep
435 */
436
Len Brown4be44fc2005-08-05 00:44:28 -0400437void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800439 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
Len Brown4be44fc2005-08-05 00:44:28 -0400441
Len Brown4be44fc2005-08-05 00:44:28 -0400442void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
444 while (us) {
445 u32 delay = 1000;
446
447 if (delay > us)
448 delay = us;
449 udelay(delay);
450 touch_nmi_watchdog();
451 us -= delay;
452 }
453}
Len Brown4be44fc2005-08-05 00:44:28 -0400454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455/*
456 * Support ACPI 3.0 AML Timer operand
457 * Returns 64-bit free-running, monotonically increasing timer
458 * with 100ns granularity
459 */
Len Brown4be44fc2005-08-05 00:44:28 -0400460u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
462 static u64 t;
463
464#ifdef CONFIG_HPET
465 /* TBD: use HPET if available */
466#endif
467
468#ifdef CONFIG_X86_PM_TIMER
469 /* TBD: default to PM timer if HPET was not available */
470#endif
471 if (!t)
472 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
473
474 return ++t;
475}
476
Len Brown4be44fc2005-08-05 00:44:28 -0400477acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
479 u32 dummy;
480
481 if (!value)
482 value = &dummy;
483
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800484 *value = 0;
485 if (width <= 8) {
Len Brown4be44fc2005-08-05 00:44:28 -0400486 *(u8 *) value = inb(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800487 } else if (width <= 16) {
Len Brown4be44fc2005-08-05 00:44:28 -0400488 *(u16 *) value = inw(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800489 } else if (width <= 32) {
Len Brown4be44fc2005-08-05 00:44:28 -0400490 *(u32 *) value = inl(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800491 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 BUG();
493 }
494
495 return AE_OK;
496}
Len Brown4be44fc2005-08-05 00:44:28 -0400497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498EXPORT_SYMBOL(acpi_os_read_port);
499
Len Brown4be44fc2005-08-05 00:44:28 -0400500acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800502 if (width <= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 outb(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800504 } else if (width <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 outw(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800506 } else if (width <= 32) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 outl(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800508 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 BUG();
510 }
511
512 return AE_OK;
513}
Len Brown4be44fc2005-08-05 00:44:28 -0400514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515EXPORT_SYMBOL(acpi_os_write_port);
516
517acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400518acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
Len Brown4be44fc2005-08-05 00:44:28 -0400520 u32 dummy;
521 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800523 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 if (!value)
525 value = &dummy;
526
527 switch (width) {
528 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400529 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 break;
531 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400532 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 break;
534 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400535 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 break;
537 default:
538 BUG();
539 }
540
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800541 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543 return AE_OK;
544}
545
546acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400547acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Len Brown4be44fc2005-08-05 00:44:28 -0400549 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800551 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 switch (width) {
554 case 8:
555 writeb(value, virt_addr);
556 break;
557 case 16:
558 writew(value, virt_addr);
559 break;
560 case 32:
561 writel(value, virt_addr);
562 break;
563 default:
564 BUG();
565 }
566
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800567 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
569 return AE_OK;
570}
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400573acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
Linus Torvalds10270d42008-02-13 09:56:14 -0800574 u32 *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575{
576 int result, size;
577
578 if (!value)
579 return AE_BAD_PARAMETER;
580
581 switch (width) {
582 case 8:
583 size = 1;
584 break;
585 case 16:
586 size = 2;
587 break;
588 case 32:
589 size = 4;
590 break;
591 default:
592 return AE_ERROR;
593 }
594
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500595 result = raw_pci_read(pci_id->segment, pci_id->bus,
596 PCI_DEVFN(pci_id->device, pci_id->function),
597 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599 return (result ? AE_ERROR : AE_OK);
600}
Len Brown4be44fc2005-08-05 00:44:28 -0400601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400603acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
604 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605{
606 int result, size;
607
608 switch (width) {
609 case 8:
610 size = 1;
611 break;
612 case 16:
613 size = 2;
614 break;
615 case 32:
616 size = 4;
617 break;
618 default:
619 return AE_ERROR;
620 }
621
Matthew Wilcoxb6ce0682008-02-10 09:45:28 -0500622 result = raw_pci_write(pci_id->segment, pci_id->bus,
623 PCI_DEVFN(pci_id->device, pci_id->function),
624 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
626 return (result ? AE_ERROR : AE_OK);
627}
628
629/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400630static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
631 acpi_handle chandle, /* current node */
632 struct acpi_pci_id **id,
633 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
Len Brown4be44fc2005-08-05 00:44:28 -0400635 acpi_handle handle;
636 struct acpi_pci_id *pci_id = *id;
637 acpi_status status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400638 unsigned long long temp;
Len Brown4be44fc2005-08-05 00:44:28 -0400639 acpi_object_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641 acpi_get_parent(chandle, &handle);
642 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400643 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
644 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400647 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 return;
649
Matthew Wilcox27663c52008-10-10 02:22:59 -0400650 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400651 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if (ACPI_SUCCESS(status)) {
Linus Torvalds10270d42008-02-13 09:56:14 -0800653 u32 val;
Len Brown4be44fc2005-08-05 00:44:28 -0400654 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
655 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
657 if (*is_bridge)
658 pci_id->bus = *bus_number;
659
660 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400661 status =
Linus Torvalds10270d42008-02-13 09:56:14 -0800662 acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
Len Brown4be44fc2005-08-05 00:44:28 -0400663 8);
664 if (ACPI_SUCCESS(status)
Linus Torvalds10270d42008-02-13 09:56:14 -0800665 && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400666 status =
667 acpi_os_read_pci_configuration(pci_id, 0x18,
Linus Torvalds10270d42008-02-13 09:56:14 -0800668 &val, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 if (!ACPI_SUCCESS(status)) {
670 /* Certainly broken... FIX ME */
671 return;
672 }
673 *is_bridge = 1;
Linus Torvalds10270d42008-02-13 09:56:14 -0800674 pci_id->bus = val;
Len Brown4be44fc2005-08-05 00:44:28 -0400675 status =
676 acpi_os_read_pci_configuration(pci_id, 0x19,
Linus Torvalds10270d42008-02-13 09:56:14 -0800677 &val, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 if (ACPI_SUCCESS(status)) {
Linus Torvalds10270d42008-02-13 09:56:14 -0800679 *bus_number = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 }
681 } else
682 *is_bridge = 0;
683 }
684 }
685}
686
Len Brown4be44fc2005-08-05 00:44:28 -0400687void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
688 acpi_handle chandle, /* current node */
689 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
691 int is_bridge = 1;
692 u8 bus_number = (*id)->bus;
693
694 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
695}
696
David Howells65f27f32006-11-22 14:55:48 +0000697static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698{
David Howells65f27f32006-11-22 14:55:48 +0000699 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400700 if (!dpc) {
701 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
702 return;
703 }
704
705 dpc->function(dpc->context);
706 kfree(dpc);
707
Patrick Mocheld550d982006-06-27 00:41:40 -0400708 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709}
710
Zhang Rui19cd8472008-08-28 10:05:06 +0800711static void acpi_os_execute_hp_deferred(struct work_struct *work)
712{
713 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
714 if (!dpc) {
715 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
716 return;
717 }
718
719 acpi_os_wait_events_complete(NULL);
720
721 dpc->function(dpc->context);
722 kfree(dpc);
723
724 return;
725}
726
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400727/*******************************************************************************
728 *
729 * FUNCTION: acpi_os_execute
730 *
731 * PARAMETERS: Type - Type of the callback
732 * Function - Function to be executed
733 * Context - Function parameters
734 *
735 * RETURN: Status
736 *
737 * DESCRIPTION: Depending on type, either queues function for deferred execution or
738 * immediately executes function on a separate thread.
739 *
740 ******************************************************************************/
741
Zhang Rui19cd8472008-08-28 10:05:06 +0800742static acpi_status __acpi_os_execute(acpi_execute_type type,
743 acpi_osd_exec_callback function, void *context, int hp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744{
Len Brown4be44fc2005-08-05 00:44:28 -0400745 acpi_status status = AE_OK;
746 struct acpi_os_dpc *dpc;
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300747 struct workqueue_struct *queue;
Zhang Ruic02256b2009-06-23 10:20:29 +0800748 work_func_t func;
Zhang Rui19cd8472008-08-28 10:05:06 +0800749 int ret;
Len Brown72945b22006-07-12 22:46:42 -0400750 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
751 "Scheduling function [%p(%p)] for deferred execution.\n",
752 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 if (!function)
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400755 return AE_BAD_PARAMETER;
Len Brown72945b22006-07-12 22:46:42 -0400756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 /*
758 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000759 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 * way that allows us to also free its memory inside the callee.
761 * Because we may want to schedule several tasks with different
762 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000763 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 */
Len Brown72945b22006-07-12 22:46:42 -0400765
David Howells65f27f32006-11-22 14:55:48 +0000766 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 if (!dpc)
Lin Ming889c78b2008-12-31 09:23:57 +0800768 return AE_NO_MEMORY;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 dpc->function = function;
771 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800772
Zhang Ruic02256b2009-06-23 10:20:29 +0800773 /*
774 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
775 * because the hotplug code may call driver .remove() functions,
776 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
777 * to flush these workqueues.
778 */
779 queue = hp ? kacpi_hotplug_wq :
780 (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
781 func = hp ? acpi_os_execute_hp_deferred : acpi_os_execute_deferred;
782 INIT_WORK(&dpc->work, func);
783 ret = queue_work(queue, &dpc->work);
Zhang Rui19cd8472008-08-28 10:05:06 +0800784
785 if (!ret) {
Lin Ming55ac9a02008-09-28 14:51:56 +0800786 printk(KERN_ERR PREFIX
787 "Call to queue_work() failed.\n");
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300788 status = AE_ERROR;
789 kfree(dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 }
Lin Ming889c78b2008-12-31 09:23:57 +0800791 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792}
Len Brown4be44fc2005-08-05 00:44:28 -0400793
Zhang Rui19cd8472008-08-28 10:05:06 +0800794acpi_status acpi_os_execute(acpi_execute_type type,
795 acpi_osd_exec_callback function, void *context)
796{
797 return __acpi_os_execute(type, function, context, 0);
798}
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400799EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Zhang Rui19cd8472008-08-28 10:05:06 +0800801acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
802 void *context)
803{
804 return __acpi_os_execute(0, function, context, 1);
805}
806
Len Brown4be44fc2005-08-05 00:44:28 -0400807void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808{
809 flush_workqueue(kacpid_wq);
Zhang Rui2f67a062008-04-29 02:34:42 -0400810 flush_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811}
Len Brown4be44fc2005-08-05 00:44:28 -0400812
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813EXPORT_SYMBOL(acpi_os_wait_events_complete);
814
815/*
816 * Allocate the memory for a spinlock and initialize it.
817 */
Bob Moore967440e32006-06-23 17:04:00 -0400818acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819{
Bob Moore967440e32006-06-23 17:04:00 -0400820 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Patrick Mocheld550d982006-06-27 00:41:40 -0400822 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
824
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825/*
826 * Deallocate the memory for a spinlock.
827 */
Bob Moore967440e32006-06-23 17:04:00 -0400828void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
Patrick Mocheld550d982006-06-27 00:41:40 -0400830 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831}
832
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400834acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835{
Len Brown4be44fc2005-08-05 00:44:28 -0400836 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 sem = acpi_os_allocate(sizeof(struct semaphore));
839 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400840 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 memset(sem, 0, sizeof(struct semaphore));
842
843 sema_init(sem, initial_units);
844
Len Brown4be44fc2005-08-05 00:44:28 -0400845 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
Len Brown4be44fc2005-08-05 00:44:28 -0400847 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
848 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Patrick Mocheld550d982006-06-27 00:41:40 -0400850 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853/*
854 * TODO: A better way to delete semaphores? Linux doesn't have a
855 * 'delete_semaphore()' function -- may result in an invalid
856 * pointer dereference for non-synchronized consumers. Should
857 * we at least check for blocked threads and signal/cancel them?
858 */
859
Len Brown4be44fc2005-08-05 00:44:28 -0400860acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
Len Brown4be44fc2005-08-05 00:44:28 -0400862 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400865 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Len Brown4be44fc2005-08-05 00:44:28 -0400867 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400869 BUG_ON(!list_empty(&sem->wait_list));
Len Brown02438d82006-06-30 03:19:10 -0400870 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400871 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Patrick Mocheld550d982006-06-27 00:41:40 -0400873 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 * TODO: Support for units > 1?
878 */
Len Brown4be44fc2005-08-05 00:44:28 -0400879acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880{
Len Brown4be44fc2005-08-05 00:44:28 -0400881 acpi_status status = AE_OK;
882 struct semaphore *sem = (struct semaphore *)handle;
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400883 long jiffies;
Len Brown4be44fc2005-08-05 00:44:28 -0400884 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400887 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
889 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400890 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Len Brown4be44fc2005-08-05 00:44:28 -0400892 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
893 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
Matthew Wilcoxf1241c82008-03-14 13:43:13 -0400895 if (timeout == ACPI_WAIT_FOREVER)
896 jiffies = MAX_SCHEDULE_TIMEOUT;
897 else
898 jiffies = msecs_to_jiffies(timeout);
899
900 ret = down_timeout(sem, jiffies);
901 if (ret)
902 status = AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400905 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400906 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400907 handle, units, timeout,
908 acpi_format_exception(status)));
909 } else {
910 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400911 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400912 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
914
Patrick Mocheld550d982006-06-27 00:41:40 -0400915 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918/*
919 * TODO: Support for units > 1?
920 */
Len Brown4be44fc2005-08-05 00:44:28 -0400921acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922{
Len Brown4be44fc2005-08-05 00:44:28 -0400923 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400926 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400929 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Len Brown4be44fc2005-08-05 00:44:28 -0400931 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
932 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934 up(sem);
935
Patrick Mocheld550d982006-06-27 00:41:40 -0400936 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937}
Len Brown4be44fc2005-08-05 00:44:28 -0400938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400940u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
942
943#ifdef ENABLE_DEBUGGER
944 if (acpi_in_debugger) {
945 u32 chars;
946
947 kdb_read(buffer, sizeof(line_buf));
948
949 /* remove the CR kdb includes */
950 chars = strlen(buffer) - 1;
951 buffer[chars] = '\0';
952 }
953#endif
954
955 return 0;
956}
Len Brown4be44fc2005-08-05 00:44:28 -0400957#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Len Brown4be44fc2005-08-05 00:44:28 -0400959acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
Len Brown4be44fc2005-08-05 00:44:28 -0400961 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 case ACPI_SIGNAL_FATAL:
963 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
964 break;
965 case ACPI_SIGNAL_BREAKPOINT:
966 /*
967 * AML Breakpoint
968 * ACPI spec. says to treat it as a NOP unless
969 * you are debugging. So if/when we integrate
970 * AML debugger into the kernel debugger its
971 * hook will go here. But until then it is
972 * not useful to print anything on breakpoints.
973 */
974 break;
975 default:
976 break;
977 }
978
979 return AE_OK;
980}
Len Brown4be44fc2005-08-05 00:44:28 -0400981
Len Brown4be44fc2005-08-05 00:44:28 -0400982static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983{
984 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -0400985 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
987 if (!str || !*str)
988 return 0;
989
990 for (; count-- && str && *str; str++) {
991 if (isalnum(*str) || *str == ' ' || *str == ':')
992 *p++ = *str;
993 else if (*str == '\'' || *str == '"')
994 continue;
995 else
996 break;
997 }
998 *p = 0;
999
1000 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001001
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002}
1003
1004__setup("acpi_os_name=", acpi_os_name_setup);
1005
Len Brownd4b7dc42008-01-23 20:50:56 -05001006static void __init set_osi_linux(unsigned int enable)
1007{
1008 if (osi_linux.enable != enable) {
1009 osi_linux.enable = enable;
1010 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
1011 enable ? "Add": "Delet");
1012 }
1013 return;
1014}
Len Brownf5076542007-05-30 00:10:38 -04001015
Len Brownd4b7dc42008-01-23 20:50:56 -05001016static void __init acpi_cmdline_osi_linux(unsigned int enable)
1017{
1018 osi_linux.cmdline = 1; /* cmdline set the default */
1019 set_osi_linux(enable);
Len Brownf5076542007-05-30 00:10:38 -04001020
Len Brownd4b7dc42008-01-23 20:50:56 -05001021 return;
1022}
1023
1024void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1025{
1026 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1027
1028 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1029
1030 if (enable == -1)
1031 return;
1032
1033 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
1034
1035 set_osi_linux(enable);
1036
Len Brownf5076542007-05-30 00:10:38 -04001037 return;
1038}
1039
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040/*
Len Brownae00d812007-05-29 18:43:33 -04001041 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1042 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 * empty string disables _OSI
Len Brownae00d812007-05-29 18:43:33 -04001044 * string starting with '!' disables that string
1045 * otherwise string is added to list, augmenting built-in strings
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 */
Len Brown46c1fbd2008-02-13 23:13:25 -05001047int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
1049 if (str == NULL || *str == '\0') {
1050 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1051 acpi_gbl_create_osi_method = FALSE;
Len Brownaa2e09d2007-07-02 23:57:45 -04001052 } else if (!strcmp("!Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001053 acpi_cmdline_osi_linux(0); /* !enable */
Len Brownae00d812007-05-29 18:43:33 -04001054 } else if (*str == '!') {
1055 if (acpi_osi_invalidate(++str) == AE_OK)
1056 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
Len Brownf5076542007-05-30 00:10:38 -04001057 } else if (!strcmp("Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001058 acpi_cmdline_osi_linux(1); /* enable */
Len Brownae00d812007-05-29 18:43:33 -04001059 } else if (*osi_additional_string == '\0') {
1060 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
1061 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
1063
1064 return 1;
1065}
1066
1067__setup("acpi_osi=", acpi_osi_setup);
1068
1069/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001070static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071{
1072 printk(KERN_INFO PREFIX "serialize enabled\n");
1073
1074 acpi_gbl_all_methods_serialized = TRUE;
1075
1076 return 1;
1077}
1078
1079__setup("acpi_serialize", acpi_serialize_setup);
1080
1081/*
1082 * Wake and Run-Time GPES are expected to be separate.
1083 * We disable wake-GPEs at run-time to prevent spurious
1084 * interrupts.
1085 *
1086 * However, if a system exists that shares Wake and
1087 * Run-time events on the same GPE this flag is available
1088 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1089 */
Len Brown4be44fc2005-08-05 00:44:28 -04001090static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
1092 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1093
1094 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1095
1096 return 1;
1097}
1098
1099__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1100
Thomas Renningerdf92e692008-02-04 23:31:22 -08001101/* Check of resource interference between native drivers and ACPI
1102 * OperationRegions (SystemIO and System Memory only).
1103 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1104 * in arbitrary AML code and can interfere with legacy drivers.
1105 * acpi_enforce_resources= can be set to:
1106 *
Luca Tettamanti7e905602009-03-30 00:01:27 +02001107 * - strict (default) (2)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001108 * -> further driver trying to access the resources will not load
Luca Tettamanti7e905602009-03-30 00:01:27 +02001109 * - lax (1)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001110 * -> further driver trying to access the resources will load, but you
1111 * get a system message that something might go wrong...
1112 *
1113 * - no (0)
1114 * -> ACPI Operation Region resources will not be registered
1115 *
1116 */
1117#define ENFORCE_RESOURCES_STRICT 2
1118#define ENFORCE_RESOURCES_LAX 1
1119#define ENFORCE_RESOURCES_NO 0
1120
Luca Tettamanti7e905602009-03-30 00:01:27 +02001121static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
Thomas Renningerdf92e692008-02-04 23:31:22 -08001122
1123static int __init acpi_enforce_resources_setup(char *str)
1124{
1125 if (str == NULL || *str == '\0')
1126 return 0;
1127
1128 if (!strcmp("strict", str))
1129 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1130 else if (!strcmp("lax", str))
1131 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1132 else if (!strcmp("no", str))
1133 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1134
1135 return 1;
1136}
1137
1138__setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1139
1140/* Check for resource conflicts between ACPI OperationRegions and native
1141 * drivers */
Thomas Renninger443dea72008-02-04 23:31:23 -08001142int acpi_check_resource_conflict(struct resource *res)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001143{
1144 struct acpi_res_list *res_list_elem;
1145 int ioport;
1146 int clash = 0;
1147
1148 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1149 return 0;
1150 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1151 return 0;
1152
1153 ioport = res->flags & IORESOURCE_IO;
1154
1155 spin_lock(&acpi_res_lock);
1156 list_for_each_entry(res_list_elem, &resource_list_head,
1157 resource_list) {
1158 if (ioport && (res_list_elem->resource_type
1159 != ACPI_ADR_SPACE_SYSTEM_IO))
1160 continue;
1161 if (!ioport && (res_list_elem->resource_type
1162 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1163 continue;
1164
1165 if (res->end < res_list_elem->start
1166 || res_list_elem->end < res->start)
1167 continue;
1168 clash = 1;
1169 break;
1170 }
1171 spin_unlock(&acpi_res_lock);
1172
1173 if (clash) {
1174 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
Jean Delvarebd129352008-02-27 20:56:01 +01001175 printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
Thomas Renningerdf92e692008-02-04 23:31:22 -08001176 " conflicts with ACPI region %s"
1177 " [0x%llx-0x%llx]\n",
1178 acpi_enforce_resources == ENFORCE_RESOURCES_LAX
1179 ? KERN_WARNING : KERN_ERR,
1180 ioport ? "I/O" : "Memory", res->name,
1181 (long long) res->start, (long long) res->end,
1182 res_list_elem->name,
1183 (long long) res_list_elem->start,
1184 (long long) res_list_elem->end);
1185 printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
1186 }
1187 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1188 return -EBUSY;
1189 }
1190 return 0;
1191}
Thomas Renninger443dea72008-02-04 23:31:23 -08001192EXPORT_SYMBOL(acpi_check_resource_conflict);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001193
1194int acpi_check_region(resource_size_t start, resource_size_t n,
1195 const char *name)
1196{
1197 struct resource res = {
1198 .start = start,
1199 .end = start + n - 1,
1200 .name = name,
1201 .flags = IORESOURCE_IO,
1202 };
1203
1204 return acpi_check_resource_conflict(&res);
1205}
1206EXPORT_SYMBOL(acpi_check_region);
1207
1208int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1209 const char *name)
1210{
1211 struct resource res = {
1212 .start = start,
1213 .end = start + n - 1,
1214 .name = name,
1215 .flags = IORESOURCE_MEM,
1216 };
1217
1218 return acpi_check_resource_conflict(&res);
1219
1220}
1221EXPORT_SYMBOL(acpi_check_mem_region);
1222
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223/*
Robert Moore73459f72005-06-24 00:00:00 -04001224 * Acquire a spinlock.
1225 *
1226 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001227 */
1228
Bob Moore967440e32006-06-23 17:04:00 -04001229acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001230{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001231 acpi_cpu_flags flags;
Bob Moore967440e32006-06-23 17:04:00 -04001232 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001233 return flags;
1234}
1235
1236/*
1237 * Release a spinlock. See above.
1238 */
1239
Bob Moore967440e32006-06-23 17:04:00 -04001240void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001241{
Bob Moore967440e32006-06-23 17:04:00 -04001242 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001243}
1244
Robert Moore73459f72005-06-24 00:00:00 -04001245#ifndef ACPI_USE_LOCAL_CACHE
1246
1247/*******************************************************************************
1248 *
1249 * FUNCTION: acpi_os_create_cache
1250 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001251 * PARAMETERS: name - Ascii name for the cache
1252 * size - Size of each cached object
1253 * depth - Maximum depth of the cache (in objects) <ignored>
1254 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001255 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001256 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001257 *
1258 * DESCRIPTION: Create a cache object
1259 *
1260 ******************************************************************************/
1261
1262acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001263acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001264{
Paul Mundt20c2df82007-07-20 10:11:58 +09001265 *cache = kmem_cache_create(name, size, 0, 0, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001266 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001267 return AE_ERROR;
1268 else
1269 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001270}
1271
1272/*******************************************************************************
1273 *
1274 * FUNCTION: acpi_os_purge_cache
1275 *
1276 * PARAMETERS: Cache - Handle to cache object
1277 *
1278 * RETURN: Status
1279 *
1280 * DESCRIPTION: Free all objects within the requested cache.
1281 *
1282 ******************************************************************************/
1283
Len Brown4be44fc2005-08-05 00:44:28 -04001284acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001285{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001286 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001287 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001288}
1289
1290/*******************************************************************************
1291 *
1292 * FUNCTION: acpi_os_delete_cache
1293 *
1294 * PARAMETERS: Cache - Handle to cache object
1295 *
1296 * RETURN: Status
1297 *
1298 * DESCRIPTION: Free all objects within the requested cache and delete the
1299 * cache object.
1300 *
1301 ******************************************************************************/
1302
Len Brown4be44fc2005-08-05 00:44:28 -04001303acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001304{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001305 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001306 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001307}
1308
1309/*******************************************************************************
1310 *
1311 * FUNCTION: acpi_os_release_object
1312 *
1313 * PARAMETERS: Cache - Handle to cache object
1314 * Object - The object to be released
1315 *
1316 * RETURN: None
1317 *
1318 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1319 * the object is deleted.
1320 *
1321 ******************************************************************************/
1322
Len Brown4be44fc2005-08-05 00:44:28 -04001323acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001324{
Len Brown4be44fc2005-08-05 00:44:28 -04001325 kmem_cache_free(cache, object);
1326 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001327}
1328
Bob Mooreb229cf92006-04-21 17:15:00 -04001329/******************************************************************************
1330 *
1331 * FUNCTION: acpi_os_validate_interface
1332 *
1333 * PARAMETERS: interface - Requested interface to be validated
1334 *
1335 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1336 *
1337 * DESCRIPTION: Match an interface string to the interfaces supported by the
1338 * host. Strings originate from an AML call to the _OSI method.
1339 *
1340 *****************************************************************************/
1341
1342acpi_status
1343acpi_os_validate_interface (char *interface)
1344{
Len Brownae00d812007-05-29 18:43:33 -04001345 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1346 return AE_OK;
Len Brownf5076542007-05-30 00:10:38 -04001347 if (!strcmp("Linux", interface)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001348
1349 printk(KERN_NOTICE PREFIX
1350 "BIOS _OSI(Linux) query %s%s\n",
1351 osi_linux.enable ? "honored" : "ignored",
1352 osi_linux.cmdline ? " via cmdline" :
1353 osi_linux.dmi ? " via DMI" : "");
1354
Len Brownd4b7dc42008-01-23 20:50:56 -05001355 if (osi_linux.enable)
Len Brownf5076542007-05-30 00:10:38 -04001356 return AE_OK;
1357 }
Len Brownae00d812007-05-29 18:43:33 -04001358 return AE_SUPPORT;
Bob Mooreb229cf92006-04-21 17:15:00 -04001359}
1360
Bob Mooreb229cf92006-04-21 17:15:00 -04001361/******************************************************************************
1362 *
1363 * FUNCTION: acpi_os_validate_address
1364 *
1365 * PARAMETERS: space_id - ACPI space ID
1366 * address - Physical address
1367 * length - Address length
1368 *
1369 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1370 * should return AE_AML_ILLEGAL_ADDRESS.
1371 *
1372 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1373 * the addresses accessed by AML operation regions.
1374 *
1375 *****************************************************************************/
1376
1377acpi_status
1378acpi_os_validate_address (
1379 u8 space_id,
1380 acpi_physical_address address,
Thomas Renningerdf92e692008-02-04 23:31:22 -08001381 acpi_size length,
1382 char *name)
Bob Mooreb229cf92006-04-21 17:15:00 -04001383{
Thomas Renningerdf92e692008-02-04 23:31:22 -08001384 struct acpi_res_list *res;
1385 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1386 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001387
Thomas Renningerdf92e692008-02-04 23:31:22 -08001388 switch (space_id) {
1389 case ACPI_ADR_SPACE_SYSTEM_IO:
1390 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1391 /* Only interference checks against SystemIO and SytemMemory
1392 are needed */
1393 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1394 if (!res)
1395 return AE_OK;
1396 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1397 strlcpy(res->name, name, 5);
1398 res->start = address;
1399 res->end = address + length - 1;
1400 res->resource_type = space_id;
1401 spin_lock(&acpi_res_lock);
1402 list_add(&res->resource_list, &resource_list_head);
1403 spin_unlock(&acpi_res_lock);
1404 pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, "
1405 "name: %s\n", (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
1406 ? "SystemIO" : "System Memory",
1407 (unsigned long long)res->start,
1408 (unsigned long long)res->end,
1409 res->name);
1410 break;
1411 case ACPI_ADR_SPACE_PCI_CONFIG:
1412 case ACPI_ADR_SPACE_EC:
1413 case ACPI_ADR_SPACE_SMBUS:
1414 case ACPI_ADR_SPACE_CMOS:
1415 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1416 case ACPI_ADR_SPACE_DATA_TABLE:
1417 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1418 break;
1419 }
1420 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001421}
1422
Robert Moore73459f72005-06-24 00:00:00 -04001423#endif