blob: 27ccd68b8f462de790a7243219197e4631b8fcf9 [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>
7 *
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 *
26 */
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/slab.h>
31#include <linux/mm.h>
32#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/interrupt.h>
34#include <linux/kmod.h>
35#include <linux/delay.h>
Len Brownf5076542007-05-30 00:10:38 -040036#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/workqueue.h>
38#include <linux/nmi.h>
Alexey Starikovskiyad718602007-02-02 19:48:19 +030039#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <acpi/acpi.h>
41#include <asm/io.h>
42#include <acpi/acpi_bus.h>
43#include <acpi/processor.h>
44#include <asm/uaccess.h>
45
46#include <linux/efi.h>
Thomas Renningerdf92e692008-02-04 23:31:22 -080047#include <linux/ioport.h>
48#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define _COMPONENT ACPI_OS_SERVICES
Len Brownf52fd662007-02-12 22:42:12 -050051ACPI_MODULE_NAME("osl");
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define PREFIX "ACPI: "
Len Brown4be44fc2005-08-05 00:44:28 -040053struct acpi_os_dpc {
54 acpi_osd_exec_callback function;
55 void *context;
David Howells65f27f32006-11-22 14:55:48 +000056 struct work_struct work;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057};
58
59#ifdef CONFIG_ACPI_CUSTOM_DSDT
60#include CONFIG_ACPI_CUSTOM_DSDT_FILE
61#endif
62
63#ifdef ENABLE_DEBUGGER
64#include <linux/kdb.h>
65
66/* stuff for debugger support */
67int acpi_in_debugger;
68EXPORT_SYMBOL(acpi_in_debugger);
69
70extern char line_buf[80];
Len Brown4be44fc2005-08-05 00:44:28 -040071#endif /*ENABLE_DEBUGGER */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73static unsigned int acpi_irq_irq;
74static acpi_osd_handler acpi_irq_handler;
75static void *acpi_irq_context;
76static struct workqueue_struct *kacpid_wq;
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -040077static struct workqueue_struct *kacpi_notify_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Thomas Renningerdf92e692008-02-04 23:31:22 -080079struct acpi_res_list {
80 resource_size_t start;
81 resource_size_t end;
82 acpi_adr_space_type resource_type; /* IO port, System memory, ...*/
83 char name[5]; /* only can have a length of 4 chars, make use of this
84 one instead of res->name, no need to kalloc then */
85 struct list_head resource_list;
86};
87
88static LIST_HEAD(resource_list_head);
89static DEFINE_SPINLOCK(acpi_res_lock);
90
Len Brownae00d812007-05-29 18:43:33 -040091#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
92static char osi_additional_string[OSI_STRING_LENGTH_MAX];
93
Éric Piel9cbc7962008-02-05 00:04:58 +010094#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
95static int acpi_no_initrd_override;
96#endif
97
Len Brownd4b7dc42008-01-23 20:50:56 -050098/*
99 * "Ode to _OSI(Linux)"
100 *
101 * osi_linux -- Control response to BIOS _OSI(Linux) query.
102 *
103 * As Linux evolves, the features that it supports change.
104 * So an OSI string such as "Linux" is not specific enough
105 * to be useful across multiple versions of Linux. It
106 * doesn't identify any particular feature, interface,
107 * or even any particular version of Linux...
108 *
109 * Unfortunately, Linux-2.6.22 and earlier responded "yes"
110 * to a BIOS _OSI(Linux) query. When
111 * a reference mobile BIOS started using it, its use
112 * started to spread to many vendor platforms.
113 * As it is not supportable, we need to halt that spread.
114 *
115 * Today, most BIOS references to _OSI(Linux) are noise --
116 * they have no functional effect and are just dead code
117 * carried over from the reference BIOS.
118 *
119 * The next most common case is that _OSI(Linux) harms Linux,
120 * usually by causing the BIOS to follow paths that are
121 * not tested during Windows validation.
122 *
123 * Finally, there is a short list of platforms
124 * where OSI(Linux) benefits Linux.
125 *
126 * In Linux-2.6.23, OSI(Linux) is first disabled by default.
127 * DMI is used to disable the dmesg warning about OSI(Linux)
128 * on platforms where it is known to have no effect.
129 * But a dmesg warning remains for systems where
130 * we do not know if OSI(Linux) is good or bad for the system.
131 * DMI is also used to enable OSI(Linux) for the machines
132 * that are known to need it.
133 *
134 * BIOS writers should NOT query _OSI(Linux) on future systems.
135 * It will be ignored by default, and to get Linux to
136 * not ignore it will require a kernel source update to
137 * add a DMI entry, or a boot-time "acpi_osi=Linux" invocation.
138 */
139#define OSI_LINUX_ENABLE 0
140
Adrian Bunk1d15d842008-01-29 00:10:15 +0200141static struct osi_linux {
Len Brownd4b7dc42008-01-23 20:50:56 -0500142 unsigned int enable:1;
143 unsigned int dmi:1;
144 unsigned int cmdline:1;
145 unsigned int known:1;
146} osi_linux = { OSI_LINUX_ENABLE, 0, 0, 0};
Len Brownf5076542007-05-30 00:10:38 -0400147
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700148static void __init acpi_request_region (struct acpi_generic_address *addr,
149 unsigned int length, char *desc)
150{
151 struct resource *res;
152
153 if (!addr->address || !length)
154 return;
155
Len Browneee3c852007-02-03 01:38:16 -0500156 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700157 res = request_region(addr->address, length, desc);
Len Browneee3c852007-02-03 01:38:16 -0500158 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700159 res = request_mem_region(addr->address, length, desc);
160}
161
162static int __init acpi_reserve_resources(void)
163{
Len Browneee3c852007-02-03 01:38:16 -0500164 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700165 "ACPI PM1a_EVT_BLK");
166
Len Browneee3c852007-02-03 01:38:16 -0500167 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700168 "ACPI PM1b_EVT_BLK");
169
Len Browneee3c852007-02-03 01:38:16 -0500170 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700171 "ACPI PM1a_CNT_BLK");
172
Len Browneee3c852007-02-03 01:38:16 -0500173 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700174 "ACPI PM1b_CNT_BLK");
175
Len Browneee3c852007-02-03 01:38:16 -0500176 if (acpi_gbl_FADT.pm_timer_length == 4)
177 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700178
Len Browneee3c852007-02-03 01:38:16 -0500179 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700180 "ACPI PM2_CNT_BLK");
181
182 /* Length of GPE blocks must be a non-negative multiple of 2 */
183
Len Browneee3c852007-02-03 01:38:16 -0500184 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
185 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
186 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700187
Len Browneee3c852007-02-03 01:38:16 -0500188 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
189 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
190 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700191
192 return 0;
193}
194device_initcall(acpi_reserve_resources);
195
Len Browndd272b52007-05-30 00:26:11 -0400196acpi_status __init acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
198 return AE_OK;
199}
200
Len Brown4be44fc2005-08-05 00:44:28 -0400201acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
203 /*
204 * Initialize PCI configuration space access, as we'll need to access
205 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
206 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 if (!raw_pci_ops) {
Len Brown4be44fc2005-08-05 00:44:28 -0400208 printk(KERN_ERR PREFIX
209 "Access to PCI configuration space unavailable\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 return AE_NULL_ENTRY;
211 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 kacpid_wq = create_singlethread_workqueue("kacpid");
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400213 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 BUG_ON(!kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400215 BUG_ON(!kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 return AE_OK;
217}
218
Len Brown4be44fc2005-08-05 00:44:28 -0400219acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
221 if (acpi_irq_handler) {
222 acpi_os_remove_interrupt_handler(acpi_irq_irq,
223 acpi_irq_handler);
224 }
225
226 destroy_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400227 destroy_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 return AE_OK;
230}
231
Len Brown4be44fc2005-08-05 00:44:28 -0400232void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
234 va_list args;
235 va_start(args, fmt);
236 acpi_os_vprintf(fmt, args);
237 va_end(args);
238}
Len Brown4be44fc2005-08-05 00:44:28 -0400239
Len Brown4be44fc2005-08-05 00:44:28 -0400240void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
242 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 vsprintf(buffer, fmt, args);
245
246#ifdef ENABLE_DEBUGGER
247 if (acpi_in_debugger) {
248 kdb_printf("%s", buffer);
249 } else {
250 printk("%s", buffer);
251 }
252#else
253 printk("%s", buffer);
254#endif
255}
256
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300257acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800260 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300261 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800262 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300263 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400265 printk(KERN_ERR PREFIX
266 "System description tables not found\n");
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300267 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
Len Brown239665a2007-11-23 20:08:02 -0500269 } else {
270 acpi_physical_address pa = 0;
271
272 acpi_find_root_pointer(&pa);
273 return pa;
274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
Jan Beulich2fdf0742007-12-13 08:33:59 +0000277void __iomem *__init_refok
278acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800280 if (phys > ULONG_MAX) {
281 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Randy Dunlap70c08462007-02-13 16:11:36 -0800282 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300284 if (acpi_gbl_permanent_mmap)
285 /*
286 * ioremap checks to ensure this is in reserved space
287 */
288 return ioremap((unsigned long)phys, size);
289 else
290 return __acpi_map_table((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800292EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Len Brown4be44fc2005-08-05 00:44:28 -0400294void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300296 if (acpi_gbl_permanent_mmap) {
297 iounmap(virt);
298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800300EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302#ifdef ACPI_FUTURE_USAGE
303acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400304acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Len Brown4be44fc2005-08-05 00:44:28 -0400306 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 return AE_BAD_PARAMETER;
308
309 *phys = virt_to_phys(virt);
310
311 return AE_OK;
312}
313#endif
314
315#define ACPI_MAX_OVERRIDE_LEN 100
316
317static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
318
319acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400320acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
321 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
323 if (!init_val || !new_val)
324 return AE_BAD_PARAMETER;
325
326 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400327 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400329 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 *new_val = acpi_os_name;
331 }
332
333 return AE_OK;
334}
335
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100336#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
337struct acpi_table_header *acpi_find_dsdt_initrd(void)
338{
339 struct file *firmware_file;
340 mm_segment_t oldfs;
341 unsigned long len, len2;
342 struct acpi_table_header *dsdt_buffer, *ret = NULL;
343 struct kstat stat;
344 char *ramfs_dsdt_name = "/DSDT.aml";
345
Len Brown04d94882008-02-06 19:49:54 -0500346 printk(KERN_INFO PREFIX "Checking initramfs for custom DSDT");
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100347
348 /*
349 * Never do this at home, only the user-space is allowed to open a file.
Len Brown04d94882008-02-06 19:49:54 -0500350 * The clean way would be to use the firmware loader.
351 * But this code must be run before there is any userspace available.
352 * A static/init firmware infrastructure doesn't exist yet...
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100353 */
Len Brown04d94882008-02-06 19:49:54 -0500354 if (vfs_stat(ramfs_dsdt_name, &stat) < 0)
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100355 return ret;
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100356
357 len = stat.size;
358 /* check especially against empty files */
359 if (len <= 4) {
Len Brown04d94882008-02-06 19:49:54 -0500360 printk(KERN_ERR PREFIX "Failed: DSDT only %lu bytes.\n", len);
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100361 return ret;
362 }
363
364 firmware_file = filp_open(ramfs_dsdt_name, O_RDONLY, 0);
365 if (IS_ERR(firmware_file)) {
Len Brown04d94882008-02-06 19:49:54 -0500366 printk(KERN_ERR PREFIX "Failed to open %s.\n", ramfs_dsdt_name);
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100367 return ret;
368 }
369
Len Brown04d94882008-02-06 19:49:54 -0500370 dsdt_buffer = kmalloc(len, GFP_ATOMIC);
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100371 if (!dsdt_buffer) {
Len Brown04d94882008-02-06 19:49:54 -0500372 printk(KERN_ERR PREFIX "Failed to allocate %lu bytes.\n", len);
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100373 goto err;
374 }
375
376 oldfs = get_fs();
377 set_fs(KERNEL_DS);
Len Brown04d94882008-02-06 19:49:54 -0500378 len2 = vfs_read(firmware_file, (char __user *)dsdt_buffer, len,
379 &firmware_file->f_pos);
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100380 set_fs(oldfs);
381 if (len2 < len) {
Len Brown04d94882008-02-06 19:49:54 -0500382 printk(KERN_ERR PREFIX "Failed to read %lu bytes from %s.\n",
383 len, ramfs_dsdt_name);
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100384 ACPI_FREE(dsdt_buffer);
385 goto err;
386 }
387
Len Brown04d94882008-02-06 19:49:54 -0500388 printk(KERN_INFO PREFIX "Found %lu byte DSDT in %s.\n",
389 len, ramfs_dsdt_name);
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100390 ret = dsdt_buffer;
391err:
392 filp_close(firmware_file, NULL);
393 return ret;
394}
395#endif
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400398acpi_os_table_override(struct acpi_table_header * existing_table,
399 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400{
401 if (!existing_table || !new_table)
402 return AE_BAD_PARAMETER;
403
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100404 *new_table = NULL;
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#ifdef CONFIG_ACPI_CUSTOM_DSDT
407 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400408 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409#endif
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100410#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
Éric Piel9cbc7962008-02-05 00:04:58 +0100411 if ((strncmp(existing_table->signature, "DSDT", 4) == 0) &&
412 !acpi_no_initrd_override) {
Len Brown04d94882008-02-06 19:49:54 -0500413 struct acpi_table_header *initrd_table;
414
415 initrd_table = acpi_find_dsdt_initrd();
Markus Gaugusch71fc47a2008-02-05 00:04:06 +0100416 if (initrd_table)
417 *new_table = initrd_table;
418 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#endif
Éric Piel6ed31e92008-02-05 00:04:50 +0100420 if (*new_table != NULL) {
421 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
422 "this is unsafe: tainting kernel\n",
423 existing_table->signature,
424 existing_table->oem_table_id);
425 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 return AE_OK;
428}
429
Éric Piel9cbc7962008-02-05 00:04:58 +0100430#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
431int __init acpi_no_initrd_override_setup(char *s)
432{
433 acpi_no_initrd_override = 1;
434 return 1;
435}
436__setup("acpi_no_initrd_override", acpi_no_initrd_override_setup);
437#endif
438
David Howells7d12e782006-10-05 14:55:46 +0100439static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Len Brown5229e872008-02-06 01:26:55 -0500441 u32 handled;
442
443 handled = (*acpi_irq_handler) (acpi_irq_context);
444
445 if (handled) {
446 acpi_irq_handled++;
447 return IRQ_HANDLED;
448 } else
449 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450}
451
452acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400453acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
454 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
456 unsigned int irq;
457
Len Brown5229e872008-02-06 01:26:55 -0500458 acpi_irq_stats_init();
459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 /*
461 * Ignore the GSI from the core, and use the value in our copy of the
462 * FADT. It may not be the same if an interrupt source override exists
463 * for the SCI.
464 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300465 gsi = acpi_gbl_FADT.sci_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
467 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
468 gsi);
469 return AE_OK;
470 }
471
472 acpi_irq_handler = handler;
473 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700474 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
476 return AE_NOT_ACQUIRED;
477 }
478 acpi_irq_irq = irq;
479
480 return AE_OK;
481}
482
Len Brown4be44fc2005-08-05 00:44:28 -0400483acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
485 if (irq) {
486 free_irq(irq, acpi_irq);
487 acpi_irq_handler = NULL;
488 acpi_irq_irq = 0;
489 }
490
491 return AE_OK;
492}
493
494/*
495 * Running in interpreter thread context, safe to sleep
496 */
497
Len Brown4be44fc2005-08-05 00:44:28 -0400498void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800500 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
Len Brown4be44fc2005-08-05 00:44:28 -0400502
Len Brown4be44fc2005-08-05 00:44:28 -0400503void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
505 while (us) {
506 u32 delay = 1000;
507
508 if (delay > us)
509 delay = us;
510 udelay(delay);
511 touch_nmi_watchdog();
512 us -= delay;
513 }
514}
Len Brown4be44fc2005-08-05 00:44:28 -0400515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516/*
517 * Support ACPI 3.0 AML Timer operand
518 * Returns 64-bit free-running, monotonically increasing timer
519 * with 100ns granularity
520 */
Len Brown4be44fc2005-08-05 00:44:28 -0400521u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
523 static u64 t;
524
525#ifdef CONFIG_HPET
526 /* TBD: use HPET if available */
527#endif
528
529#ifdef CONFIG_X86_PM_TIMER
530 /* TBD: default to PM timer if HPET was not available */
531#endif
532 if (!t)
533 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
534
535 return ++t;
536}
537
Len Brown4be44fc2005-08-05 00:44:28 -0400538acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
540 u32 dummy;
541
542 if (!value)
543 value = &dummy;
544
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800545 *value = 0;
546 if (width <= 8) {
Len Brown4be44fc2005-08-05 00:44:28 -0400547 *(u8 *) value = inb(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800548 } else if (width <= 16) {
Len Brown4be44fc2005-08-05 00:44:28 -0400549 *(u16 *) value = inw(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800550 } else if (width <= 32) {
Len Brown4be44fc2005-08-05 00:44:28 -0400551 *(u32 *) value = inl(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800552 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 BUG();
554 }
555
556 return AE_OK;
557}
Len Brown4be44fc2005-08-05 00:44:28 -0400558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559EXPORT_SYMBOL(acpi_os_read_port);
560
Len Brown4be44fc2005-08-05 00:44:28 -0400561acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562{
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800563 if (width <= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 outb(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800565 } else if (width <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 outw(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800567 } else if (width <= 32) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 outl(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800569 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 BUG();
571 }
572
573 return AE_OK;
574}
Len Brown4be44fc2005-08-05 00:44:28 -0400575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576EXPORT_SYMBOL(acpi_os_write_port);
577
578acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400579acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Len Brown4be44fc2005-08-05 00:44:28 -0400581 u32 dummy;
582 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800584 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 if (!value)
586 value = &dummy;
587
588 switch (width) {
589 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400590 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 break;
592 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400593 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 break;
595 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400596 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 break;
598 default:
599 BUG();
600 }
601
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800602 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 return AE_OK;
605}
606
607acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400608acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
Len Brown4be44fc2005-08-05 00:44:28 -0400610 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800612 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614 switch (width) {
615 case 8:
616 writeb(value, virt_addr);
617 break;
618 case 16:
619 writew(value, virt_addr);
620 break;
621 case 32:
622 writel(value, virt_addr);
623 break;
624 default:
625 BUG();
626 }
627
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800628 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
630 return AE_OK;
631}
632
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400634acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
635 void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636{
637 int result, size;
638
639 if (!value)
640 return AE_BAD_PARAMETER;
641
642 switch (width) {
643 case 8:
644 size = 1;
645 break;
646 case 16:
647 size = 2;
648 break;
649 case 32:
650 size = 4;
651 break;
652 default:
653 return AE_ERROR;
654 }
655
656 BUG_ON(!raw_pci_ops);
657
658 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400659 PCI_DEVFN(pci_id->device, pci_id->function),
660 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 return (result ? AE_ERROR : AE_OK);
663}
Len Brown4be44fc2005-08-05 00:44:28 -0400664
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400666acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
667 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668{
669 int result, size;
670
671 switch (width) {
672 case 8:
673 size = 1;
674 break;
675 case 16:
676 size = 2;
677 break;
678 case 32:
679 size = 4;
680 break;
681 default:
682 return AE_ERROR;
683 }
684
685 BUG_ON(!raw_pci_ops);
686
687 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400688 PCI_DEVFN(pci_id->device, pci_id->function),
689 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 return (result ? AE_ERROR : AE_OK);
692}
693
694/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400695static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
696 acpi_handle chandle, /* current node */
697 struct acpi_pci_id **id,
698 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699{
Len Brown4be44fc2005-08-05 00:44:28 -0400700 acpi_handle handle;
701 struct acpi_pci_id *pci_id = *id;
702 acpi_status status;
703 unsigned long temp;
704 acpi_object_type type;
705 u8 tu8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
707 acpi_get_parent(chandle, &handle);
708 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400709 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
710 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
712 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400713 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 return;
715
Len Brown4be44fc2005-08-05 00:44:28 -0400716 status =
717 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
718 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 if (ACPI_SUCCESS(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400720 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
721 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
723 if (*is_bridge)
724 pci_id->bus = *bus_number;
725
726 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400727 status =
728 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
729 8);
730 if (ACPI_SUCCESS(status)
731 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
732 status =
733 acpi_os_read_pci_configuration(pci_id, 0x18,
734 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 if (!ACPI_SUCCESS(status)) {
736 /* Certainly broken... FIX ME */
737 return;
738 }
739 *is_bridge = 1;
740 pci_id->bus = tu8;
Len Brown4be44fc2005-08-05 00:44:28 -0400741 status =
742 acpi_os_read_pci_configuration(pci_id, 0x19,
743 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 if (ACPI_SUCCESS(status)) {
745 *bus_number = tu8;
746 }
747 } else
748 *is_bridge = 0;
749 }
750 }
751}
752
Len Brown4be44fc2005-08-05 00:44:28 -0400753void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
754 acpi_handle chandle, /* current node */
755 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756{
757 int is_bridge = 1;
758 u8 bus_number = (*id)->bus;
759
760 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
761}
762
David Howells65f27f32006-11-22 14:55:48 +0000763static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764{
David Howells65f27f32006-11-22 14:55:48 +0000765 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400766 if (!dpc) {
767 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
768 return;
769 }
770
771 dpc->function(dpc->context);
772 kfree(dpc);
773
Patrick Mocheld550d982006-06-27 00:41:40 -0400774 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}
776
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400777/*******************************************************************************
778 *
779 * FUNCTION: acpi_os_execute
780 *
781 * PARAMETERS: Type - Type of the callback
782 * Function - Function to be executed
783 * Context - Function parameters
784 *
785 * RETURN: Status
786 *
787 * DESCRIPTION: Depending on type, either queues function for deferred execution or
788 * immediately executes function on a separate thread.
789 *
790 ******************************************************************************/
791
792acpi_status acpi_os_execute(acpi_execute_type type,
Len Brown4be44fc2005-08-05 00:44:28 -0400793 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794{
Len Brown4be44fc2005-08-05 00:44:28 -0400795 acpi_status status = AE_OK;
796 struct acpi_os_dpc *dpc;
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300797 struct workqueue_struct *queue;
Len Brown72945b22006-07-12 22:46:42 -0400798 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
799 "Scheduling function [%p(%p)] for deferred execution.\n",
800 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 if (!function)
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400803 return AE_BAD_PARAMETER;
Len Brown72945b22006-07-12 22:46:42 -0400804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 /*
806 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000807 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 * way that allows us to also free its memory inside the callee.
809 * Because we may want to schedule several tasks with different
810 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000811 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 */
Len Brown72945b22006-07-12 22:46:42 -0400813
David Howells65f27f32006-11-22 14:55:48 +0000814 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 if (!dpc)
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800816 return_ACPI_STATUS(AE_NO_MEMORY);
817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 dpc->function = function;
819 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800820
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300821 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
822 queue = (type == OSL_NOTIFY_HANDLER) ? kacpi_notify_wq : kacpid_wq;
823 if (!queue_work(queue, &dpc->work)) {
824 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
825 "Call to queue_work() failed.\n"));
826 status = AE_ERROR;
827 kfree(dpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 }
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800829 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830}
Len Brown4be44fc2005-08-05 00:44:28 -0400831
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400832EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Len Brown4be44fc2005-08-05 00:44:28 -0400834void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835{
836 flush_workqueue(kacpid_wq);
837}
Len Brown4be44fc2005-08-05 00:44:28 -0400838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839EXPORT_SYMBOL(acpi_os_wait_events_complete);
840
841/*
842 * Allocate the memory for a spinlock and initialize it.
843 */
Bob Moore967440e2006-06-23 17:04:00 -0400844acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845{
Bob Moore967440e2006-06-23 17:04:00 -0400846 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Patrick Mocheld550d982006-06-27 00:41:40 -0400848 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849}
850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851/*
852 * Deallocate the memory for a spinlock.
853 */
Bob Moore967440e2006-06-23 17:04:00 -0400854void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
Patrick Mocheld550d982006-06-27 00:41:40 -0400856 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857}
858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400860acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
Len Brown4be44fc2005-08-05 00:44:28 -0400862 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
865 sem = acpi_os_allocate(sizeof(struct semaphore));
866 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400867 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 memset(sem, 0, sizeof(struct semaphore));
869
870 sema_init(sem, initial_units);
871
Len Brown4be44fc2005-08-05 00:44:28 -0400872 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Len Brown4be44fc2005-08-05 00:44:28 -0400874 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
875 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Patrick Mocheld550d982006-06-27 00:41:40 -0400877 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880/*
881 * TODO: A better way to delete semaphores? Linux doesn't have a
882 * 'delete_semaphore()' function -- may result in an invalid
883 * pointer dereference for non-synchronized consumers. Should
884 * we at least check for blocked threads and signal/cancel them?
885 */
886
Len Brown4be44fc2005-08-05 00:44:28 -0400887acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
Len Brown4be44fc2005-08-05 00:44:28 -0400889 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
892 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400893 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
Len Brown4be44fc2005-08-05 00:44:28 -0400895 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Len Brown02438d82006-06-30 03:19:10 -0400897 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400898 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Patrick Mocheld550d982006-06-27 00:41:40 -0400900 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903/*
904 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
905 * improvise. The process is to sleep for one scheduler quantum
906 * until the semaphore becomes available. Downside is that this
907 * may result in starvation for timeout-based waits when there's
908 * lots of semaphore activity.
909 *
910 * TODO: Support for units > 1?
911 */
Len Brown4be44fc2005-08-05 00:44:28 -0400912acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913{
Len Brown4be44fc2005-08-05 00:44:28 -0400914 acpi_status status = AE_OK;
915 struct semaphore *sem = (struct semaphore *)handle;
916 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
919 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400920 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400923 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Len Brown4be44fc2005-08-05 00:44:28 -0400925 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
926 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Len Brownd68909f2006-08-16 19:16:58 -0400928 /*
929 * This can be called during resume with interrupts off.
930 * Like boot-time, we should be single threaded and will
931 * always get the lock if we try -- timeout or not.
932 * If this doesn't succeed, then we will oops courtesy of
933 * might_sleep() in down().
934 */
935 if (!down_trylock(sem))
936 return AE_OK;
937
Len Brown4be44fc2005-08-05 00:44:28 -0400938 switch (timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 /*
940 * No Wait:
941 * --------
942 * A zero timeout value indicates that we shouldn't wait - just
943 * acquire the semaphore if available otherwise return AE_TIME
944 * (a.k.a. 'would block').
945 */
Len Brown4be44fc2005-08-05 00:44:28 -0400946 case 0:
947 if (down_trylock(sem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 status = AE_TIME;
949 break;
950
951 /*
952 * Wait Indefinitely:
953 * ------------------
954 */
Len Brown4be44fc2005-08-05 00:44:28 -0400955 case ACPI_WAIT_FOREVER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 down(sem);
957 break;
958
959 /*
960 * Wait w/ Timeout:
961 * ----------------
962 */
Len Brown4be44fc2005-08-05 00:44:28 -0400963 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 // TODO: A better timeout algorithm?
965 {
966 int i = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400967 static const int quantum_ms = 1000 / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
969 ret = down_trylock(sem);
Yu Lumingdacd9b82005-12-31 01:45:00 -0500970 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800971 schedule_timeout_interruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 ret = down_trylock(sem);
973 }
Len Brown4be44fc2005-08-05 00:44:28 -0400974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 if (ret != 0)
976 status = AE_TIME;
977 }
978 break;
979 }
980
981 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400982 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400983 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400984 handle, units, timeout,
985 acpi_format_exception(status)));
986 } else {
987 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400988 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400989 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 }
991
Patrick Mocheld550d982006-06-27 00:41:40 -0400992 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995/*
996 * TODO: Support for units > 1?
997 */
Len Brown4be44fc2005-08-05 00:44:28 -0400998acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999{
Len Brown4be44fc2005-08-05 00:44:28 -04001000 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
1003 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -04001004 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
1006 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -04001007 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Len Brown4be44fc2005-08-05 00:44:28 -04001009 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
1010 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
1012 up(sem);
1013
Patrick Mocheld550d982006-06-27 00:41:40 -04001014 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015}
Len Brown4be44fc2005-08-05 00:44:28 -04001016
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -04001018u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019{
1020
1021#ifdef ENABLE_DEBUGGER
1022 if (acpi_in_debugger) {
1023 u32 chars;
1024
1025 kdb_read(buffer, sizeof(line_buf));
1026
1027 /* remove the CR kdb includes */
1028 chars = strlen(buffer) - 1;
1029 buffer[chars] = '\0';
1030 }
1031#endif
1032
1033 return 0;
1034}
Len Brown4be44fc2005-08-05 00:44:28 -04001035#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
Len Brown4be44fc2005-08-05 00:44:28 -04001037acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038{
Len Brown4be44fc2005-08-05 00:44:28 -04001039 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 case ACPI_SIGNAL_FATAL:
1041 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
1042 break;
1043 case ACPI_SIGNAL_BREAKPOINT:
1044 /*
1045 * AML Breakpoint
1046 * ACPI spec. says to treat it as a NOP unless
1047 * you are debugging. So if/when we integrate
1048 * AML debugger into the kernel debugger its
1049 * hook will go here. But until then it is
1050 * not useful to print anything on breakpoints.
1051 */
1052 break;
1053 default:
1054 break;
1055 }
1056
1057 return AE_OK;
1058}
Len Brown4be44fc2005-08-05 00:44:28 -04001059
Len Brown4be44fc2005-08-05 00:44:28 -04001060static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061{
1062 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -04001063 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
1065 if (!str || !*str)
1066 return 0;
1067
1068 for (; count-- && str && *str; str++) {
1069 if (isalnum(*str) || *str == ' ' || *str == ':')
1070 *p++ = *str;
1071 else if (*str == '\'' || *str == '"')
1072 continue;
1073 else
1074 break;
1075 }
1076 *p = 0;
1077
1078 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001079
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080}
1081
1082__setup("acpi_os_name=", acpi_os_name_setup);
1083
Len Brownd4b7dc42008-01-23 20:50:56 -05001084static void __init set_osi_linux(unsigned int enable)
1085{
1086 if (osi_linux.enable != enable) {
1087 osi_linux.enable = enable;
1088 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
1089 enable ? "Add": "Delet");
1090 }
1091 return;
1092}
Len Brownf5076542007-05-30 00:10:38 -04001093
Len Brownd4b7dc42008-01-23 20:50:56 -05001094static void __init acpi_cmdline_osi_linux(unsigned int enable)
1095{
1096 osi_linux.cmdline = 1; /* cmdline set the default */
1097 set_osi_linux(enable);
Len Brownf5076542007-05-30 00:10:38 -04001098
Len Brownd4b7dc42008-01-23 20:50:56 -05001099 return;
1100}
1101
1102void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1103{
1104 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1105
1106 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1107
1108 if (enable == -1)
1109 return;
1110
1111 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
1112
1113 set_osi_linux(enable);
1114
Len Brownf5076542007-05-30 00:10:38 -04001115 return;
1116}
1117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118/*
Len Brownae00d812007-05-29 18:43:33 -04001119 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1120 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 * empty string disables _OSI
Len Brownae00d812007-05-29 18:43:33 -04001122 * string starting with '!' disables that string
1123 * otherwise string is added to list, augmenting built-in strings
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 */
Len Brown4be44fc2005-08-05 00:44:28 -04001125static int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126{
1127 if (str == NULL || *str == '\0') {
1128 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1129 acpi_gbl_create_osi_method = FALSE;
Len Brownaa2e09d2007-07-02 23:57:45 -04001130 } else if (!strcmp("!Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001131 acpi_cmdline_osi_linux(0); /* !enable */
Len Brownae00d812007-05-29 18:43:33 -04001132 } else if (*str == '!') {
1133 if (acpi_osi_invalidate(++str) == AE_OK)
1134 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
Len Brownf5076542007-05-30 00:10:38 -04001135 } else if (!strcmp("Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001136 acpi_cmdline_osi_linux(1); /* enable */
Len Brownae00d812007-05-29 18:43:33 -04001137 } else if (*osi_additional_string == '\0') {
1138 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
1139 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 }
1141
1142 return 1;
1143}
1144
1145__setup("acpi_osi=", acpi_osi_setup);
1146
1147/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001148static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
1150 printk(KERN_INFO PREFIX "serialize enabled\n");
1151
1152 acpi_gbl_all_methods_serialized = TRUE;
1153
1154 return 1;
1155}
1156
1157__setup("acpi_serialize", acpi_serialize_setup);
1158
1159/*
1160 * Wake and Run-Time GPES are expected to be separate.
1161 * We disable wake-GPEs at run-time to prevent spurious
1162 * interrupts.
1163 *
1164 * However, if a system exists that shares Wake and
1165 * Run-time events on the same GPE this flag is available
1166 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1167 */
Len Brown4be44fc2005-08-05 00:44:28 -04001168static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169{
1170 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1171
1172 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1173
1174 return 1;
1175}
1176
1177__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1178
Thomas Renningerdf92e692008-02-04 23:31:22 -08001179/* Check of resource interference between native drivers and ACPI
1180 * OperationRegions (SystemIO and System Memory only).
1181 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1182 * in arbitrary AML code and can interfere with legacy drivers.
1183 * acpi_enforce_resources= can be set to:
1184 *
1185 * - strict (2)
1186 * -> further driver trying to access the resources will not load
1187 * - lax (default) (1)
1188 * -> further driver trying to access the resources will load, but you
1189 * get a system message that something might go wrong...
1190 *
1191 * - no (0)
1192 * -> ACPI Operation Region resources will not be registered
1193 *
1194 */
1195#define ENFORCE_RESOURCES_STRICT 2
1196#define ENFORCE_RESOURCES_LAX 1
1197#define ENFORCE_RESOURCES_NO 0
1198
1199static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1200
1201static int __init acpi_enforce_resources_setup(char *str)
1202{
1203 if (str == NULL || *str == '\0')
1204 return 0;
1205
1206 if (!strcmp("strict", str))
1207 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1208 else if (!strcmp("lax", str))
1209 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1210 else if (!strcmp("no", str))
1211 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1212
1213 return 1;
1214}
1215
1216__setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1217
1218/* Check for resource conflicts between ACPI OperationRegions and native
1219 * drivers */
Thomas Renninger443dea72008-02-04 23:31:23 -08001220int acpi_check_resource_conflict(struct resource *res)
Thomas Renningerdf92e692008-02-04 23:31:22 -08001221{
1222 struct acpi_res_list *res_list_elem;
1223 int ioport;
1224 int clash = 0;
1225
1226 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1227 return 0;
1228 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1229 return 0;
1230
1231 ioport = res->flags & IORESOURCE_IO;
1232
1233 spin_lock(&acpi_res_lock);
1234 list_for_each_entry(res_list_elem, &resource_list_head,
1235 resource_list) {
1236 if (ioport && (res_list_elem->resource_type
1237 != ACPI_ADR_SPACE_SYSTEM_IO))
1238 continue;
1239 if (!ioport && (res_list_elem->resource_type
1240 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1241 continue;
1242
1243 if (res->end < res_list_elem->start
1244 || res_list_elem->end < res->start)
1245 continue;
1246 clash = 1;
1247 break;
1248 }
1249 spin_unlock(&acpi_res_lock);
1250
1251 if (clash) {
1252 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
1253 printk(KERN_INFO "%sACPI: %s resource %s [0x%llx-0x%llx]"
1254 " conflicts with ACPI region %s"
1255 " [0x%llx-0x%llx]\n",
1256 acpi_enforce_resources == ENFORCE_RESOURCES_LAX
1257 ? KERN_WARNING : KERN_ERR,
1258 ioport ? "I/O" : "Memory", res->name,
1259 (long long) res->start, (long long) res->end,
1260 res_list_elem->name,
1261 (long long) res_list_elem->start,
1262 (long long) res_list_elem->end);
1263 printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
1264 }
1265 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1266 return -EBUSY;
1267 }
1268 return 0;
1269}
Thomas Renninger443dea72008-02-04 23:31:23 -08001270EXPORT_SYMBOL(acpi_check_resource_conflict);
Thomas Renningerdf92e692008-02-04 23:31:22 -08001271
1272int acpi_check_region(resource_size_t start, resource_size_t n,
1273 const char *name)
1274{
1275 struct resource res = {
1276 .start = start,
1277 .end = start + n - 1,
1278 .name = name,
1279 .flags = IORESOURCE_IO,
1280 };
1281
1282 return acpi_check_resource_conflict(&res);
1283}
1284EXPORT_SYMBOL(acpi_check_region);
1285
1286int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1287 const char *name)
1288{
1289 struct resource res = {
1290 .start = start,
1291 .end = start + n - 1,
1292 .name = name,
1293 .flags = IORESOURCE_MEM,
1294 };
1295
1296 return acpi_check_resource_conflict(&res);
1297
1298}
1299EXPORT_SYMBOL(acpi_check_mem_region);
1300
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301/*
Robert Moore73459f72005-06-24 00:00:00 -04001302 * Acquire a spinlock.
1303 *
1304 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001305 */
1306
Bob Moore967440e2006-06-23 17:04:00 -04001307acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001308{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001309 acpi_cpu_flags flags;
Bob Moore967440e2006-06-23 17:04:00 -04001310 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001311 return flags;
1312}
1313
1314/*
1315 * Release a spinlock. See above.
1316 */
1317
Bob Moore967440e2006-06-23 17:04:00 -04001318void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001319{
Bob Moore967440e2006-06-23 17:04:00 -04001320 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001321}
1322
Robert Moore73459f72005-06-24 00:00:00 -04001323#ifndef ACPI_USE_LOCAL_CACHE
1324
1325/*******************************************************************************
1326 *
1327 * FUNCTION: acpi_os_create_cache
1328 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001329 * PARAMETERS: name - Ascii name for the cache
1330 * size - Size of each cached object
1331 * depth - Maximum depth of the cache (in objects) <ignored>
1332 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001333 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001334 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001335 *
1336 * DESCRIPTION: Create a cache object
1337 *
1338 ******************************************************************************/
1339
1340acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001341acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001342{
Paul Mundt20c2df82007-07-20 10:11:58 +09001343 *cache = kmem_cache_create(name, size, 0, 0, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001344 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001345 return AE_ERROR;
1346 else
1347 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001348}
1349
1350/*******************************************************************************
1351 *
1352 * FUNCTION: acpi_os_purge_cache
1353 *
1354 * PARAMETERS: Cache - Handle to cache object
1355 *
1356 * RETURN: Status
1357 *
1358 * DESCRIPTION: Free all objects within the requested cache.
1359 *
1360 ******************************************************************************/
1361
Len Brown4be44fc2005-08-05 00:44:28 -04001362acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001363{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001364 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001365 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001366}
1367
1368/*******************************************************************************
1369 *
1370 * FUNCTION: acpi_os_delete_cache
1371 *
1372 * PARAMETERS: Cache - Handle to cache object
1373 *
1374 * RETURN: Status
1375 *
1376 * DESCRIPTION: Free all objects within the requested cache and delete the
1377 * cache object.
1378 *
1379 ******************************************************************************/
1380
Len Brown4be44fc2005-08-05 00:44:28 -04001381acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001382{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001383 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001384 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001385}
1386
1387/*******************************************************************************
1388 *
1389 * FUNCTION: acpi_os_release_object
1390 *
1391 * PARAMETERS: Cache - Handle to cache object
1392 * Object - The object to be released
1393 *
1394 * RETURN: None
1395 *
1396 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1397 * the object is deleted.
1398 *
1399 ******************************************************************************/
1400
Len Brown4be44fc2005-08-05 00:44:28 -04001401acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001402{
Len Brown4be44fc2005-08-05 00:44:28 -04001403 kmem_cache_free(cache, object);
1404 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001405}
1406
Len Brown5a4e1432008-01-23 20:01:22 -05001407/**
1408 * acpi_dmi_dump - dump DMI slots needed for blacklist entry
1409 *
1410 * Returns 0 on success
1411 */
Adrian Bunk12d39312008-01-29 00:10:12 +02001412static int acpi_dmi_dump(void)
Len Brown5a4e1432008-01-23 20:01:22 -05001413{
1414
1415 if (!dmi_available)
1416 return -1;
1417
1418 printk(KERN_NOTICE PREFIX "DMI System Vendor: %s\n",
Len Browne6298c62008-01-25 15:40:02 -05001419 dmi_get_system_info(DMI_SYS_VENDOR));
Len Brown5a4e1432008-01-23 20:01:22 -05001420 printk(KERN_NOTICE PREFIX "DMI Product Name: %s\n",
Len Browne6298c62008-01-25 15:40:02 -05001421 dmi_get_system_info(DMI_PRODUCT_NAME));
Len Brown5a4e1432008-01-23 20:01:22 -05001422 printk(KERN_NOTICE PREFIX "DMI Product Version: %s\n",
Len Browne6298c62008-01-25 15:40:02 -05001423 dmi_get_system_info(DMI_PRODUCT_VERSION));
Len Brown5a4e1432008-01-23 20:01:22 -05001424 printk(KERN_NOTICE PREFIX "DMI Board Name: %s\n",
Len Browne6298c62008-01-25 15:40:02 -05001425 dmi_get_system_info(DMI_BOARD_NAME));
Len Brown5a4e1432008-01-23 20:01:22 -05001426 printk(KERN_NOTICE PREFIX "DMI BIOS Vendor: %s\n",
Len Browne6298c62008-01-25 15:40:02 -05001427 dmi_get_system_info(DMI_BIOS_VENDOR));
Len Brown5a4e1432008-01-23 20:01:22 -05001428 printk(KERN_NOTICE PREFIX "DMI BIOS Date: %s\n",
Len Browne6298c62008-01-25 15:40:02 -05001429 dmi_get_system_info(DMI_BIOS_DATE));
Len Brown5a4e1432008-01-23 20:01:22 -05001430
1431 return 0;
1432}
1433
1434
Bob Mooreb229cf92006-04-21 17:15:00 -04001435/******************************************************************************
1436 *
1437 * FUNCTION: acpi_os_validate_interface
1438 *
1439 * PARAMETERS: interface - Requested interface to be validated
1440 *
1441 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1442 *
1443 * DESCRIPTION: Match an interface string to the interfaces supported by the
1444 * host. Strings originate from an AML call to the _OSI method.
1445 *
1446 *****************************************************************************/
1447
1448acpi_status
1449acpi_os_validate_interface (char *interface)
1450{
Len Brownae00d812007-05-29 18:43:33 -04001451 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1452 return AE_OK;
Len Brownf5076542007-05-30 00:10:38 -04001453 if (!strcmp("Linux", interface)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001454
1455 printk(KERN_NOTICE PREFIX
1456 "BIOS _OSI(Linux) query %s%s\n",
1457 osi_linux.enable ? "honored" : "ignored",
1458 osi_linux.cmdline ? " via cmdline" :
1459 osi_linux.dmi ? " via DMI" : "");
1460
1461 if (!osi_linux.dmi) {
1462 if (acpi_dmi_dump())
1463 printk(KERN_NOTICE PREFIX
1464 "[please extract dmidecode output]\n");
Len Brownf40cd6f2008-01-23 20:04:28 -05001465 printk(KERN_NOTICE PREFIX
Len Brownd4b7dc42008-01-23 20:50:56 -05001466 "Please send DMI info above to "
1467 "linux-acpi@vger.kernel.org\n");
1468 }
1469 if (!osi_linux.known && !osi_linux.cmdline) {
1470 printk(KERN_NOTICE PREFIX
1471 "If \"acpi_osi=%sLinux\" works better, "
1472 "please notify linux-acpi@vger.kernel.org\n",
1473 osi_linux.enable ? "!" : "");
1474 }
1475
1476 if (osi_linux.enable)
Len Brownf5076542007-05-30 00:10:38 -04001477 return AE_OK;
1478 }
Len Brownae00d812007-05-29 18:43:33 -04001479 return AE_SUPPORT;
Bob Mooreb229cf92006-04-21 17:15:00 -04001480}
1481
Bob Mooreb229cf92006-04-21 17:15:00 -04001482/******************************************************************************
1483 *
1484 * FUNCTION: acpi_os_validate_address
1485 *
1486 * PARAMETERS: space_id - ACPI space ID
1487 * address - Physical address
1488 * length - Address length
1489 *
1490 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1491 * should return AE_AML_ILLEGAL_ADDRESS.
1492 *
1493 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1494 * the addresses accessed by AML operation regions.
1495 *
1496 *****************************************************************************/
1497
1498acpi_status
1499acpi_os_validate_address (
1500 u8 space_id,
1501 acpi_physical_address address,
Thomas Renningerdf92e692008-02-04 23:31:22 -08001502 acpi_size length,
1503 char *name)
Bob Mooreb229cf92006-04-21 17:15:00 -04001504{
Thomas Renningerdf92e692008-02-04 23:31:22 -08001505 struct acpi_res_list *res;
1506 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1507 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001508
Thomas Renningerdf92e692008-02-04 23:31:22 -08001509 switch (space_id) {
1510 case ACPI_ADR_SPACE_SYSTEM_IO:
1511 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1512 /* Only interference checks against SystemIO and SytemMemory
1513 are needed */
1514 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1515 if (!res)
1516 return AE_OK;
1517 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1518 strlcpy(res->name, name, 5);
1519 res->start = address;
1520 res->end = address + length - 1;
1521 res->resource_type = space_id;
1522 spin_lock(&acpi_res_lock);
1523 list_add(&res->resource_list, &resource_list_head);
1524 spin_unlock(&acpi_res_lock);
1525 pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, "
1526 "name: %s\n", (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
1527 ? "SystemIO" : "System Memory",
1528 (unsigned long long)res->start,
1529 (unsigned long long)res->end,
1530 res->name);
1531 break;
1532 case ACPI_ADR_SPACE_PCI_CONFIG:
1533 case ACPI_ADR_SPACE_EC:
1534 case ACPI_ADR_SPACE_SMBUS:
1535 case ACPI_ADR_SPACE_CMOS:
1536 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1537 case ACPI_ADR_SPACE_DATA_TABLE:
1538 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1539 break;
1540 }
1541 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001542}
1543
Robert Moore73459f72005-06-24 00:00:00 -04001544#endif