blob: 222f7b1b66f75d690a95dca338e1e0a299b0687b [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 Starikovskiyad71860a2007-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
Len Brownd4b7dc42008-01-23 20:50:56 -050094/*
95 * "Ode to _OSI(Linux)"
96 *
97 * osi_linux -- Control response to BIOS _OSI(Linux) query.
98 *
99 * As Linux evolves, the features that it supports change.
100 * So an OSI string such as "Linux" is not specific enough
101 * to be useful across multiple versions of Linux. It
102 * doesn't identify any particular feature, interface,
103 * or even any particular version of Linux...
104 *
105 * Unfortunately, Linux-2.6.22 and earlier responded "yes"
106 * to a BIOS _OSI(Linux) query. When
107 * a reference mobile BIOS started using it, its use
108 * started to spread to many vendor platforms.
109 * As it is not supportable, we need to halt that spread.
110 *
111 * Today, most BIOS references to _OSI(Linux) are noise --
112 * they have no functional effect and are just dead code
113 * carried over from the reference BIOS.
114 *
115 * The next most common case is that _OSI(Linux) harms Linux,
116 * usually by causing the BIOS to follow paths that are
117 * not tested during Windows validation.
118 *
119 * Finally, there is a short list of platforms
120 * where OSI(Linux) benefits Linux.
121 *
122 * In Linux-2.6.23, OSI(Linux) is first disabled by default.
123 * DMI is used to disable the dmesg warning about OSI(Linux)
124 * on platforms where it is known to have no effect.
125 * But a dmesg warning remains for systems where
126 * we do not know if OSI(Linux) is good or bad for the system.
127 * DMI is also used to enable OSI(Linux) for the machines
128 * that are known to need it.
129 *
130 * BIOS writers should NOT query _OSI(Linux) on future systems.
131 * It will be ignored by default, and to get Linux to
132 * not ignore it will require a kernel source update to
133 * add a DMI entry, or a boot-time "acpi_osi=Linux" invocation.
134 */
135#define OSI_LINUX_ENABLE 0
136
137struct osi_linux {
138 unsigned int enable:1;
139 unsigned int dmi:1;
140 unsigned int cmdline:1;
141 unsigned int known:1;
142} osi_linux = { OSI_LINUX_ENABLE, 0, 0, 0};
Len Brownf5076542007-05-30 00:10:38 -0400143
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700144static void __init acpi_request_region (struct acpi_generic_address *addr,
145 unsigned int length, char *desc)
146{
147 struct resource *res;
148
149 if (!addr->address || !length)
150 return;
151
Len Browneee3c852007-02-03 01:38:16 -0500152 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700153 res = request_region(addr->address, length, desc);
Len Browneee3c852007-02-03 01:38:16 -0500154 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700155 res = request_mem_region(addr->address, length, desc);
156}
157
158static int __init acpi_reserve_resources(void)
159{
Len Browneee3c852007-02-03 01:38:16 -0500160 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700161 "ACPI PM1a_EVT_BLK");
162
Len Browneee3c852007-02-03 01:38:16 -0500163 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700164 "ACPI PM1b_EVT_BLK");
165
Len Browneee3c852007-02-03 01:38:16 -0500166 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700167 "ACPI PM1a_CNT_BLK");
168
Len Browneee3c852007-02-03 01:38:16 -0500169 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700170 "ACPI PM1b_CNT_BLK");
171
Len Browneee3c852007-02-03 01:38:16 -0500172 if (acpi_gbl_FADT.pm_timer_length == 4)
173 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700174
Len Browneee3c852007-02-03 01:38:16 -0500175 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700176 "ACPI PM2_CNT_BLK");
177
178 /* Length of GPE blocks must be a non-negative multiple of 2 */
179
Len Browneee3c852007-02-03 01:38:16 -0500180 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
181 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
182 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700183
Len Browneee3c852007-02-03 01:38:16 -0500184 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
185 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
186 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
Bjorn Helgaas9a47cdb2007-01-18 16:42:55 -0700187
188 return 0;
189}
190device_initcall(acpi_reserve_resources);
191
Len Browndd272b52007-05-30 00:26:11 -0400192acpi_status __init acpi_os_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
194 return AE_OK;
195}
196
Len Brown4be44fc2005-08-05 00:44:28 -0400197acpi_status acpi_os_initialize1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
199 /*
200 * Initialize PCI configuration space access, as we'll need to access
201 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
202 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 if (!raw_pci_ops) {
Len Brown4be44fc2005-08-05 00:44:28 -0400204 printk(KERN_ERR PREFIX
205 "Access to PCI configuration space unavailable\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return AE_NULL_ENTRY;
207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 kacpid_wq = create_singlethread_workqueue("kacpid");
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400209 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 BUG_ON(!kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400211 BUG_ON(!kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 return AE_OK;
213}
214
Len Brown4be44fc2005-08-05 00:44:28 -0400215acpi_status acpi_os_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
217 if (acpi_irq_handler) {
218 acpi_os_remove_interrupt_handler(acpi_irq_irq,
219 acpi_irq_handler);
220 }
221
222 destroy_workqueue(kacpid_wq);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400223 destroy_workqueue(kacpi_notify_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 return AE_OK;
226}
227
Len Brown4be44fc2005-08-05 00:44:28 -0400228void acpi_os_printf(const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
230 va_list args;
231 va_start(args, fmt);
232 acpi_os_vprintf(fmt, args);
233 va_end(args);
234}
Len Brown4be44fc2005-08-05 00:44:28 -0400235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236EXPORT_SYMBOL(acpi_os_printf);
237
Len Brown4be44fc2005-08-05 00:44:28 -0400238void acpi_os_vprintf(const char *fmt, va_list args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
240 static char buffer[512];
Len Brown4be44fc2005-08-05 00:44:28 -0400241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 vsprintf(buffer, fmt, args);
243
244#ifdef ENABLE_DEBUGGER
245 if (acpi_in_debugger) {
246 kdb_printf("%s", buffer);
247 } else {
248 printk("%s", buffer);
249 }
250#else
251 printk("%s", buffer);
252#endif
253}
254
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300255acpi_physical_address __init acpi_os_get_root_pointer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
257 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800258 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300259 return efi.acpi20;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800260 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300261 return efi.acpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400263 printk(KERN_ERR PREFIX
264 "System description tables not found\n");
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300265 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300267 } else
268 return acpi_find_rsdp();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269}
270
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300271void __iomem *acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800273 if (phys > ULONG_MAX) {
274 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
Randy Dunlap70c08462007-02-13 16:11:36 -0800275 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300277 if (acpi_gbl_permanent_mmap)
278 /*
279 * ioremap checks to ensure this is in reserved space
280 */
281 return ioremap((unsigned long)phys, size);
282 else
283 return __acpi_map_table((unsigned long)phys, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800285EXPORT_SYMBOL_GPL(acpi_os_map_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Len Brown4be44fc2005-08-05 00:44:28 -0400287void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300289 if (acpi_gbl_permanent_mmap) {
290 iounmap(virt);
291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800293EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295#ifdef ACPI_FUTURE_USAGE
296acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400297acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Len Brown4be44fc2005-08-05 00:44:28 -0400299 if (!phys || !virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 return AE_BAD_PARAMETER;
301
302 *phys = virt_to_phys(virt);
303
304 return AE_OK;
305}
306#endif
307
308#define ACPI_MAX_OVERRIDE_LEN 100
309
310static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
311
312acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400313acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
314 acpi_string * new_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
316 if (!init_val || !new_val)
317 return AE_BAD_PARAMETER;
318
319 *new_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400320 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400322 acpi_os_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 *new_val = acpi_os_name;
324 }
325
326 return AE_OK;
327}
328
329acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400330acpi_os_table_override(struct acpi_table_header * existing_table,
331 struct acpi_table_header ** new_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
333 if (!existing_table || !new_table)
334 return AE_BAD_PARAMETER;
335
336#ifdef CONFIG_ACPI_CUSTOM_DSDT
337 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400338 *new_table = (struct acpi_table_header *)AmlCode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 else
340 *new_table = NULL;
341#else
342 *new_table = NULL;
343#endif
344 return AE_OK;
345}
346
David Howells7d12e782006-10-05 14:55:46 +0100347static irqreturn_t acpi_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
Len Brown4be44fc2005-08-05 00:44:28 -0400349 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
352acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400353acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
354 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
356 unsigned int irq;
357
358 /*
359 * Ignore the GSI from the core, and use the value in our copy of the
360 * FADT. It may not be the same if an interrupt source override exists
361 * for the SCI.
362 */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300363 gsi = acpi_gbl_FADT.sci_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
365 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
366 gsi);
367 return AE_OK;
368 }
369
370 acpi_irq_handler = handler;
371 acpi_irq_context = context;
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700372 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
374 return AE_NOT_ACQUIRED;
375 }
376 acpi_irq_irq = irq;
377
378 return AE_OK;
379}
380
Len Brown4be44fc2005-08-05 00:44:28 -0400381acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
383 if (irq) {
384 free_irq(irq, acpi_irq);
385 acpi_irq_handler = NULL;
386 acpi_irq_irq = 0;
387 }
388
389 return AE_OK;
390}
391
392/*
393 * Running in interpreter thread context, safe to sleep
394 */
395
Len Brown4be44fc2005-08-05 00:44:28 -0400396void acpi_os_sleep(acpi_integer ms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800398 schedule_timeout_interruptible(msecs_to_jiffies(ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399}
Len Brown4be44fc2005-08-05 00:44:28 -0400400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401EXPORT_SYMBOL(acpi_os_sleep);
402
Len Brown4be44fc2005-08-05 00:44:28 -0400403void acpi_os_stall(u32 us)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
405 while (us) {
406 u32 delay = 1000;
407
408 if (delay > us)
409 delay = us;
410 udelay(delay);
411 touch_nmi_watchdog();
412 us -= delay;
413 }
414}
Len Brown4be44fc2005-08-05 00:44:28 -0400415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416EXPORT_SYMBOL(acpi_os_stall);
417
418/*
419 * Support ACPI 3.0 AML Timer operand
420 * Returns 64-bit free-running, monotonically increasing timer
421 * with 100ns granularity
422 */
Len Brown4be44fc2005-08-05 00:44:28 -0400423u64 acpi_os_get_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
425 static u64 t;
426
427#ifdef CONFIG_HPET
428 /* TBD: use HPET if available */
429#endif
430
431#ifdef CONFIG_X86_PM_TIMER
432 /* TBD: default to PM timer if HPET was not available */
433#endif
434 if (!t)
435 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
436
437 return ++t;
438}
439
Len Brown4be44fc2005-08-05 00:44:28 -0400440acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
442 u32 dummy;
443
444 if (!value)
445 value = &dummy;
446
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800447 *value = 0;
448 if (width <= 8) {
Len Brown4be44fc2005-08-05 00:44:28 -0400449 *(u8 *) value = inb(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800450 } else if (width <= 16) {
Len Brown4be44fc2005-08-05 00:44:28 -0400451 *(u16 *) value = inw(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800452 } else if (width <= 32) {
Len Brown4be44fc2005-08-05 00:44:28 -0400453 *(u32 *) value = inl(port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800454 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 BUG();
456 }
457
458 return AE_OK;
459}
Len Brown4be44fc2005-08-05 00:44:28 -0400460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461EXPORT_SYMBOL(acpi_os_read_port);
462
Len Brown4be44fc2005-08-05 00:44:28 -0400463acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800465 if (width <= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 outb(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800467 } else if (width <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 outw(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800469 } else if (width <= 32) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 outl(value, port);
Zhao Yakui49fbabf2007-11-15 17:01:06 +0800471 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 BUG();
473 }
474
475 return AE_OK;
476}
Len Brown4be44fc2005-08-05 00:44:28 -0400477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478EXPORT_SYMBOL(acpi_os_write_port);
479
480acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400481acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
Len Brown4be44fc2005-08-05 00:44:28 -0400483 u32 dummy;
484 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800486 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 if (!value)
488 value = &dummy;
489
490 switch (width) {
491 case 8:
Len Brown4be44fc2005-08-05 00:44:28 -0400492 *(u8 *) value = readb(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 break;
494 case 16:
Len Brown4be44fc2005-08-05 00:44:28 -0400495 *(u16 *) value = readw(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 break;
497 case 32:
Len Brown4be44fc2005-08-05 00:44:28 -0400498 *(u32 *) value = readl(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 break;
500 default:
501 BUG();
502 }
503
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800504 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 return AE_OK;
507}
508
509acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400510acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511{
Len Brown4be44fc2005-08-05 00:44:28 -0400512 void __iomem *virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800514 virt_addr = ioremap(phys_addr, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 switch (width) {
517 case 8:
518 writeb(value, virt_addr);
519 break;
520 case 16:
521 writew(value, virt_addr);
522 break;
523 case 32:
524 writel(value, virt_addr);
525 break;
526 default:
527 BUG();
528 }
529
Bjorn Helgaas9f4fd612006-03-26 01:37:10 -0800530 iounmap(virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532 return AE_OK;
533}
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400536acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
537 void *value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
539 int result, size;
540
541 if (!value)
542 return AE_BAD_PARAMETER;
543
544 switch (width) {
545 case 8:
546 size = 1;
547 break;
548 case 16:
549 size = 2;
550 break;
551 case 32:
552 size = 4;
553 break;
554 default:
555 return AE_ERROR;
556 }
557
558 BUG_ON(!raw_pci_ops);
559
560 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400561 PCI_DEVFN(pci_id->device, pci_id->function),
562 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564 return (result ? AE_ERROR : AE_OK);
565}
Len Brown4be44fc2005-08-05 00:44:28 -0400566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567EXPORT_SYMBOL(acpi_os_read_pci_configuration);
568
569acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400570acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
571 acpi_integer value, u32 width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572{
573 int result, size;
574
575 switch (width) {
576 case 8:
577 size = 1;
578 break;
579 case 16:
580 size = 2;
581 break;
582 case 32:
583 size = 4;
584 break;
585 default:
586 return AE_ERROR;
587 }
588
589 BUG_ON(!raw_pci_ops);
590
591 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
Len Brown4be44fc2005-08-05 00:44:28 -0400592 PCI_DEVFN(pci_id->device, pci_id->function),
593 reg, size, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
595 return (result ? AE_ERROR : AE_OK);
596}
597
598/* TODO: Change code to take advantage of driver model more */
Len Brown4be44fc2005-08-05 00:44:28 -0400599static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
600 acpi_handle chandle, /* current node */
601 struct acpi_pci_id **id,
602 int *is_bridge, u8 * bus_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Len Brown4be44fc2005-08-05 00:44:28 -0400604 acpi_handle handle;
605 struct acpi_pci_id *pci_id = *id;
606 acpi_status status;
607 unsigned long temp;
608 acpi_object_type type;
609 u8 tu8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 acpi_get_parent(chandle, &handle);
612 if (handle != rhandle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400613 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
614 bus_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616 status = acpi_get_type(handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400617 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 return;
619
Len Brown4be44fc2005-08-05 00:44:28 -0400620 status =
621 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
622 &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 if (ACPI_SUCCESS(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400624 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
625 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 if (*is_bridge)
628 pci_id->bus = *bus_number;
629
630 /* any nicer way to get bus number of bridge ? */
Len Brown4be44fc2005-08-05 00:44:28 -0400631 status =
632 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
633 8);
634 if (ACPI_SUCCESS(status)
635 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
636 status =
637 acpi_os_read_pci_configuration(pci_id, 0x18,
638 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 if (!ACPI_SUCCESS(status)) {
640 /* Certainly broken... FIX ME */
641 return;
642 }
643 *is_bridge = 1;
644 pci_id->bus = tu8;
Len Brown4be44fc2005-08-05 00:44:28 -0400645 status =
646 acpi_os_read_pci_configuration(pci_id, 0x19,
647 &tu8, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 if (ACPI_SUCCESS(status)) {
649 *bus_number = tu8;
650 }
651 } else
652 *is_bridge = 0;
653 }
654 }
655}
656
Len Brown4be44fc2005-08-05 00:44:28 -0400657void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
658 acpi_handle chandle, /* current node */
659 struct acpi_pci_id **id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
661 int is_bridge = 1;
662 u8 bus_number = (*id)->bus;
663
664 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
665}
666
David Howells65f27f32006-11-22 14:55:48 +0000667static void acpi_os_execute_deferred(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668{
David Howells65f27f32006-11-22 14:55:48 +0000669 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400670 if (!dpc) {
671 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
672 return;
673 }
674
675 dpc->function(dpc->context);
676 kfree(dpc);
677
678 /* Yield cpu to notify thread */
679 cond_resched();
680
681 return;
682}
683
684static void acpi_os_execute_notify(struct work_struct *work)
685{
686 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 if (!dpc) {
Len Brown64684632006-06-26 23:41:38 -0400689 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400690 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 }
692
693 dpc->function(dpc->context);
694
695 kfree(dpc);
696
Patrick Mocheld550d982006-06-27 00:41:40 -0400697 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698}
699
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400700/*******************************************************************************
701 *
702 * FUNCTION: acpi_os_execute
703 *
704 * PARAMETERS: Type - Type of the callback
705 * Function - Function to be executed
706 * Context - Function parameters
707 *
708 * RETURN: Status
709 *
710 * DESCRIPTION: Depending on type, either queues function for deferred execution or
711 * immediately executes function on a separate thread.
712 *
713 ******************************************************************************/
714
715acpi_status acpi_os_execute(acpi_execute_type type,
Len Brown4be44fc2005-08-05 00:44:28 -0400716 acpi_osd_exec_callback function, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
Len Brown4be44fc2005-08-05 00:44:28 -0400718 acpi_status status = AE_OK;
719 struct acpi_os_dpc *dpc;
Len Brown72945b22006-07-12 22:46:42 -0400720
Len Brown72945b22006-07-12 22:46:42 -0400721 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
722 "Scheduling function [%p(%p)] for deferred execution.\n",
723 function, context));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725 if (!function)
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400726 return AE_BAD_PARAMETER;
Len Brown72945b22006-07-12 22:46:42 -0400727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 /*
729 * Allocate/initialize DPC structure. Note that this memory will be
David Howells65f27f32006-11-22 14:55:48 +0000730 * freed by the callee. The kernel handles the work_struct list in a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 * way that allows us to also free its memory inside the callee.
732 * Because we may want to schedule several tasks with different
733 * parameters we can't use the approach some kernel code uses of
David Howells65f27f32006-11-22 14:55:48 +0000734 * having a static work_struct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 */
Len Brown72945b22006-07-12 22:46:42 -0400736
David Howells65f27f32006-11-22 14:55:48 +0000737 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 if (!dpc)
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800739 return_ACPI_STATUS(AE_NO_MEMORY);
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 dpc->function = function;
742 dpc->context = context;
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800743
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400744 if (type == OSL_NOTIFY_HANDLER) {
745 INIT_WORK(&dpc->work, acpi_os_execute_notify);
746 if (!queue_work(kacpi_notify_wq, &dpc->work)) {
747 status = AE_ERROR;
748 kfree(dpc);
749 }
750 } else {
751 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
752 if (!queue_work(kacpid_wq, &dpc->work)) {
753 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800754 "Call to queue_work() failed.\n"));
Alexey Starikovskiy88db5e12007-05-09 23:31:03 -0400755 status = AE_ERROR;
756 kfree(dpc);
757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
Linus Torvaldsb976fe12006-11-17 19:31:09 -0800759 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760}
Len Brown4be44fc2005-08-05 00:44:28 -0400761
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400762EXPORT_SYMBOL(acpi_os_execute);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Len Brown4be44fc2005-08-05 00:44:28 -0400764void acpi_os_wait_events_complete(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765{
766 flush_workqueue(kacpid_wq);
767}
Len Brown4be44fc2005-08-05 00:44:28 -0400768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769EXPORT_SYMBOL(acpi_os_wait_events_complete);
770
771/*
772 * Allocate the memory for a spinlock and initialize it.
773 */
Bob Moore967440e32006-06-23 17:04:00 -0400774acpi_status acpi_os_create_lock(acpi_spinlock * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
Bob Moore967440e32006-06-23 17:04:00 -0400776 spin_lock_init(*handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
Patrick Mocheld550d982006-06-27 00:41:40 -0400778 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779}
780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781/*
782 * Deallocate the memory for a spinlock.
783 */
Bob Moore967440e32006-06-23 17:04:00 -0400784void acpi_os_delete_lock(acpi_spinlock handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785{
Patrick Mocheld550d982006-06-27 00:41:40 -0400786 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787}
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400790acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791{
Len Brown4be44fc2005-08-05 00:44:28 -0400792 struct semaphore *sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795 sem = acpi_os_allocate(sizeof(struct semaphore));
796 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400797 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 memset(sem, 0, sizeof(struct semaphore));
799
800 sema_init(sem, initial_units);
801
Len Brown4be44fc2005-08-05 00:44:28 -0400802 *handle = (acpi_handle *) sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Len Brown4be44fc2005-08-05 00:44:28 -0400804 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
805 *handle, initial_units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Patrick Mocheld550d982006-06-27 00:41:40 -0400807 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Len Brown4be44fc2005-08-05 00:44:28 -0400810EXPORT_SYMBOL(acpi_os_create_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812/*
813 * TODO: A better way to delete semaphores? Linux doesn't have a
814 * 'delete_semaphore()' function -- may result in an invalid
815 * pointer dereference for non-synchronized consumers. Should
816 * we at least check for blocked threads and signal/cancel them?
817 */
818
Len Brown4be44fc2005-08-05 00:44:28 -0400819acpi_status acpi_os_delete_semaphore(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
Len Brown4be44fc2005-08-05 00:44:28 -0400821 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824 if (!sem)
Patrick Mocheld550d982006-06-27 00:41:40 -0400825 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Len Brown4be44fc2005-08-05 00:44:28 -0400827 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Len Brown02438d82006-06-30 03:19:10 -0400829 kfree(sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400830 sem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Patrick Mocheld550d982006-06-27 00:41:40 -0400832 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Len Brown4be44fc2005-08-05 00:44:28 -0400835EXPORT_SYMBOL(acpi_os_delete_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837/*
838 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
839 * improvise. The process is to sleep for one scheduler quantum
840 * until the semaphore becomes available. Downside is that this
841 * may result in starvation for timeout-based waits when there's
842 * lots of semaphore activity.
843 *
844 * TODO: Support for units > 1?
845 */
Len Brown4be44fc2005-08-05 00:44:28 -0400846acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
Len Brown4be44fc2005-08-05 00:44:28 -0400848 acpi_status status = AE_OK;
849 struct semaphore *sem = (struct semaphore *)handle;
850 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400854 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
856 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400857 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Len Brown4be44fc2005-08-05 00:44:28 -0400859 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
860 handle, units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Len Brownd68909f2006-08-16 19:16:58 -0400862 /*
863 * This can be called during resume with interrupts off.
864 * Like boot-time, we should be single threaded and will
865 * always get the lock if we try -- timeout or not.
866 * If this doesn't succeed, then we will oops courtesy of
867 * might_sleep() in down().
868 */
869 if (!down_trylock(sem))
870 return AE_OK;
871
Len Brown4be44fc2005-08-05 00:44:28 -0400872 switch (timeout) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 /*
874 * No Wait:
875 * --------
876 * A zero timeout value indicates that we shouldn't wait - just
877 * acquire the semaphore if available otherwise return AE_TIME
878 * (a.k.a. 'would block').
879 */
Len Brown4be44fc2005-08-05 00:44:28 -0400880 case 0:
881 if (down_trylock(sem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 status = AE_TIME;
883 break;
884
885 /*
886 * Wait Indefinitely:
887 * ------------------
888 */
Len Brown4be44fc2005-08-05 00:44:28 -0400889 case ACPI_WAIT_FOREVER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 down(sem);
891 break;
892
893 /*
894 * Wait w/ Timeout:
895 * ----------------
896 */
Len Brown4be44fc2005-08-05 00:44:28 -0400897 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 // TODO: A better timeout algorithm?
899 {
900 int i = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400901 static const int quantum_ms = 1000 / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903 ret = down_trylock(sem);
Yu Lumingdacd9b82005-12-31 01:45:00 -0500904 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
Nishanth Aravamudan01a527e2005-11-07 01:01:14 -0800905 schedule_timeout_interruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 ret = down_trylock(sem);
907 }
Len Brown4be44fc2005-08-05 00:44:28 -0400908
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 if (ret != 0)
910 status = AE_TIME;
911 }
912 break;
913 }
914
915 if (ACPI_FAILURE(status)) {
Bjorn Helgaas9e7e2c02006-04-27 05:25:00 -0400916 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400917 "Failed to acquire semaphore[%p|%d|%d], %s",
Len Brown4be44fc2005-08-05 00:44:28 -0400918 handle, units, timeout,
919 acpi_format_exception(status)));
920 } else {
921 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
Thomas Renningera6fc6722006-06-26 23:58:43 -0400922 "Acquired semaphore[%p|%d|%d]", handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400923 units, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
925
Patrick Mocheld550d982006-06-27 00:41:40 -0400926 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Len Brown4be44fc2005-08-05 00:44:28 -0400929EXPORT_SYMBOL(acpi_os_wait_semaphore);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931/*
932 * TODO: Support for units > 1?
933 */
Len Brown4be44fc2005-08-05 00:44:28 -0400934acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935{
Len Brown4be44fc2005-08-05 00:44:28 -0400936 struct semaphore *sem = (struct semaphore *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 if (!sem || (units < 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400940 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 if (units > 1)
Patrick Mocheld550d982006-06-27 00:41:40 -0400943 return AE_SUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Len Brown4be44fc2005-08-05 00:44:28 -0400945 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
946 units));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
948 up(sem);
949
Patrick Mocheld550d982006-06-27 00:41:40 -0400950 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951}
Len Brown4be44fc2005-08-05 00:44:28 -0400952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953EXPORT_SYMBOL(acpi_os_signal_semaphore);
954
955#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -0400956u32 acpi_os_get_line(char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957{
958
959#ifdef ENABLE_DEBUGGER
960 if (acpi_in_debugger) {
961 u32 chars;
962
963 kdb_read(buffer, sizeof(line_buf));
964
965 /* remove the CR kdb includes */
966 chars = strlen(buffer) - 1;
967 buffer[chars] = '\0';
968 }
969#endif
970
971 return 0;
972}
Len Brown4be44fc2005-08-05 00:44:28 -0400973#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Len Brown4be44fc2005-08-05 00:44:28 -0400975acpi_status acpi_os_signal(u32 function, void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
Len Brown4be44fc2005-08-05 00:44:28 -0400977 switch (function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 case ACPI_SIGNAL_FATAL:
979 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
980 break;
981 case ACPI_SIGNAL_BREAKPOINT:
982 /*
983 * AML Breakpoint
984 * ACPI spec. says to treat it as a NOP unless
985 * you are debugging. So if/when we integrate
986 * AML debugger into the kernel debugger its
987 * hook will go here. But until then it is
988 * not useful to print anything on breakpoints.
989 */
990 break;
991 default:
992 break;
993 }
994
995 return AE_OK;
996}
Len Brown4be44fc2005-08-05 00:44:28 -0400997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998EXPORT_SYMBOL(acpi_os_signal);
999
Len Brown4be44fc2005-08-05 00:44:28 -04001000static int __init acpi_os_name_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001{
1002 char *p = acpi_os_name;
Len Brown4be44fc2005-08-05 00:44:28 -04001003 int count = ACPI_MAX_OVERRIDE_LEN - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 if (!str || !*str)
1006 return 0;
1007
1008 for (; count-- && str && *str; str++) {
1009 if (isalnum(*str) || *str == ' ' || *str == ':')
1010 *p++ = *str;
1011 else if (*str == '\'' || *str == '"')
1012 continue;
1013 else
1014 break;
1015 }
1016 *p = 0;
1017
1018 return 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020}
1021
1022__setup("acpi_os_name=", acpi_os_name_setup);
1023
Len Brownd4b7dc42008-01-23 20:50:56 -05001024static void __init set_osi_linux(unsigned int enable)
1025{
1026 if (osi_linux.enable != enable) {
1027 osi_linux.enable = enable;
1028 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
1029 enable ? "Add": "Delet");
1030 }
1031 return;
1032}
Len Brownf5076542007-05-30 00:10:38 -04001033
Len Brownd4b7dc42008-01-23 20:50:56 -05001034static void __init acpi_cmdline_osi_linux(unsigned int enable)
1035{
1036 osi_linux.cmdline = 1; /* cmdline set the default */
1037 set_osi_linux(enable);
Len Brownf5076542007-05-30 00:10:38 -04001038
Len Brownd4b7dc42008-01-23 20:50:56 -05001039 return;
1040}
1041
1042void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1043{
1044 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1045
1046 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1047
1048 if (enable == -1)
1049 return;
1050
1051 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
1052
1053 set_osi_linux(enable);
1054
Len Brownf5076542007-05-30 00:10:38 -04001055 return;
1056}
1057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058/*
Len Brownae00d812007-05-29 18:43:33 -04001059 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1060 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 * empty string disables _OSI
Len Brownae00d812007-05-29 18:43:33 -04001062 * string starting with '!' disables that string
1063 * otherwise string is added to list, augmenting built-in strings
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 */
Len Brown4be44fc2005-08-05 00:44:28 -04001065static int __init acpi_osi_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
1067 if (str == NULL || *str == '\0') {
1068 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1069 acpi_gbl_create_osi_method = FALSE;
Len Brownaa2e09d2007-07-02 23:57:45 -04001070 } else if (!strcmp("!Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001071 acpi_cmdline_osi_linux(0); /* !enable */
Len Brownae00d812007-05-29 18:43:33 -04001072 } else if (*str == '!') {
1073 if (acpi_osi_invalidate(++str) == AE_OK)
1074 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
Len Brownf5076542007-05-30 00:10:38 -04001075 } else if (!strcmp("Linux", str)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001076 acpi_cmdline_osi_linux(1); /* enable */
Len Brownae00d812007-05-29 18:43:33 -04001077 } else if (*osi_additional_string == '\0') {
1078 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
1079 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 }
1081
1082 return 1;
1083}
1084
1085__setup("acpi_osi=", acpi_osi_setup);
1086
1087/* enable serialization to combat AE_ALREADY_EXISTS errors */
Len Brown4be44fc2005-08-05 00:44:28 -04001088static int __init acpi_serialize_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089{
1090 printk(KERN_INFO PREFIX "serialize enabled\n");
1091
1092 acpi_gbl_all_methods_serialized = TRUE;
1093
1094 return 1;
1095}
1096
1097__setup("acpi_serialize", acpi_serialize_setup);
1098
1099/*
1100 * Wake and Run-Time GPES are expected to be separate.
1101 * We disable wake-GPEs at run-time to prevent spurious
1102 * interrupts.
1103 *
1104 * However, if a system exists that shares Wake and
1105 * Run-time events on the same GPE this flag is available
1106 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1107 */
Len Brown4be44fc2005-08-05 00:44:28 -04001108static int __init acpi_wake_gpes_always_on_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109{
1110 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1111
1112 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1113
1114 return 1;
1115}
1116
1117__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1118
Thomas Renningerdf92e692008-02-04 23:31:22 -08001119/* Check of resource interference between native drivers and ACPI
1120 * OperationRegions (SystemIO and System Memory only).
1121 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1122 * in arbitrary AML code and can interfere with legacy drivers.
1123 * acpi_enforce_resources= can be set to:
1124 *
1125 * - strict (2)
1126 * -> further driver trying to access the resources will not load
1127 * - lax (default) (1)
1128 * -> further driver trying to access the resources will load, but you
1129 * get a system message that something might go wrong...
1130 *
1131 * - no (0)
1132 * -> ACPI Operation Region resources will not be registered
1133 *
1134 */
1135#define ENFORCE_RESOURCES_STRICT 2
1136#define ENFORCE_RESOURCES_LAX 1
1137#define ENFORCE_RESOURCES_NO 0
1138
1139static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1140
1141static int __init acpi_enforce_resources_setup(char *str)
1142{
1143 if (str == NULL || *str == '\0')
1144 return 0;
1145
1146 if (!strcmp("strict", str))
1147 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1148 else if (!strcmp("lax", str))
1149 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1150 else if (!strcmp("no", str))
1151 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1152
1153 return 1;
1154}
1155
1156__setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1157
1158/* Check for resource conflicts between ACPI OperationRegions and native
1159 * drivers */
1160static int acpi_check_resource_conflict(struct resource *res)
1161{
1162 struct acpi_res_list *res_list_elem;
1163 int ioport;
1164 int clash = 0;
1165
1166 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1167 return 0;
1168 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1169 return 0;
1170
1171 ioport = res->flags & IORESOURCE_IO;
1172
1173 spin_lock(&acpi_res_lock);
1174 list_for_each_entry(res_list_elem, &resource_list_head,
1175 resource_list) {
1176 if (ioport && (res_list_elem->resource_type
1177 != ACPI_ADR_SPACE_SYSTEM_IO))
1178 continue;
1179 if (!ioport && (res_list_elem->resource_type
1180 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1181 continue;
1182
1183 if (res->end < res_list_elem->start
1184 || res_list_elem->end < res->start)
1185 continue;
1186 clash = 1;
1187 break;
1188 }
1189 spin_unlock(&acpi_res_lock);
1190
1191 if (clash) {
1192 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
1193 printk(KERN_INFO "%sACPI: %s resource %s [0x%llx-0x%llx]"
1194 " conflicts with ACPI region %s"
1195 " [0x%llx-0x%llx]\n",
1196 acpi_enforce_resources == ENFORCE_RESOURCES_LAX
1197 ? KERN_WARNING : KERN_ERR,
1198 ioport ? "I/O" : "Memory", res->name,
1199 (long long) res->start, (long long) res->end,
1200 res_list_elem->name,
1201 (long long) res_list_elem->start,
1202 (long long) res_list_elem->end);
1203 printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
1204 }
1205 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1206 return -EBUSY;
1207 }
1208 return 0;
1209}
1210
1211int acpi_check_region(resource_size_t start, resource_size_t n,
1212 const char *name)
1213{
1214 struct resource res = {
1215 .start = start,
1216 .end = start + n - 1,
1217 .name = name,
1218 .flags = IORESOURCE_IO,
1219 };
1220
1221 return acpi_check_resource_conflict(&res);
1222}
1223EXPORT_SYMBOL(acpi_check_region);
1224
1225int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1226 const char *name)
1227{
1228 struct resource res = {
1229 .start = start,
1230 .end = start + n - 1,
1231 .name = name,
1232 .flags = IORESOURCE_MEM,
1233 };
1234
1235 return acpi_check_resource_conflict(&res);
1236
1237}
1238EXPORT_SYMBOL(acpi_check_mem_region);
1239
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240/*
Robert Moore73459f72005-06-24 00:00:00 -04001241 * Acquire a spinlock.
1242 *
1243 * handle is a pointer to the spinlock_t.
Robert Moore73459f72005-06-24 00:00:00 -04001244 */
1245
Bob Moore967440e32006-06-23 17:04:00 -04001246acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
Robert Moore73459f72005-06-24 00:00:00 -04001247{
Bob Mooreb8e4d892006-01-27 16:43:00 -05001248 acpi_cpu_flags flags;
Bob Moore967440e32006-06-23 17:04:00 -04001249 spin_lock_irqsave(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001250 return flags;
1251}
1252
1253/*
1254 * Release a spinlock. See above.
1255 */
1256
Bob Moore967440e32006-06-23 17:04:00 -04001257void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
Robert Moore73459f72005-06-24 00:00:00 -04001258{
Bob Moore967440e32006-06-23 17:04:00 -04001259 spin_unlock_irqrestore(lockp, flags);
Robert Moore73459f72005-06-24 00:00:00 -04001260}
1261
Robert Moore73459f72005-06-24 00:00:00 -04001262#ifndef ACPI_USE_LOCAL_CACHE
1263
1264/*******************************************************************************
1265 *
1266 * FUNCTION: acpi_os_create_cache
1267 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001268 * PARAMETERS: name - Ascii name for the cache
1269 * size - Size of each cached object
1270 * depth - Maximum depth of the cache (in objects) <ignored>
1271 * cache - Where the new cache object is returned
Robert Moore73459f72005-06-24 00:00:00 -04001272 *
Bob Mooreb229cf92006-04-21 17:15:00 -04001273 * RETURN: status
Robert Moore73459f72005-06-24 00:00:00 -04001274 *
1275 * DESCRIPTION: Create a cache object
1276 *
1277 ******************************************************************************/
1278
1279acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001280acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
Robert Moore73459f72005-06-24 00:00:00 -04001281{
Paul Mundt20c2df82007-07-20 10:11:58 +09001282 *cache = kmem_cache_create(name, size, 0, 0, NULL);
Adrian Bunka6fdbf92006-12-19 12:56:13 -08001283 if (*cache == NULL)
Bob Mooreb229cf92006-04-21 17:15:00 -04001284 return AE_ERROR;
1285 else
1286 return AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001287}
1288
1289/*******************************************************************************
1290 *
1291 * FUNCTION: acpi_os_purge_cache
1292 *
1293 * PARAMETERS: Cache - Handle to cache object
1294 *
1295 * RETURN: Status
1296 *
1297 * DESCRIPTION: Free all objects within the requested cache.
1298 *
1299 ******************************************************************************/
1300
Len Brown4be44fc2005-08-05 00:44:28 -04001301acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001302{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001303 kmem_cache_shrink(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001304 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001305}
1306
1307/*******************************************************************************
1308 *
1309 * FUNCTION: acpi_os_delete_cache
1310 *
1311 * PARAMETERS: Cache - Handle to cache object
1312 *
1313 * RETURN: Status
1314 *
1315 * DESCRIPTION: Free all objects within the requested cache and delete the
1316 * cache object.
1317 *
1318 ******************************************************************************/
1319
Len Brown4be44fc2005-08-05 00:44:28 -04001320acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
Robert Moore73459f72005-06-24 00:00:00 -04001321{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001322 kmem_cache_destroy(cache);
Len Brown4be44fc2005-08-05 00:44:28 -04001323 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001324}
1325
1326/*******************************************************************************
1327 *
1328 * FUNCTION: acpi_os_release_object
1329 *
1330 * PARAMETERS: Cache - Handle to cache object
1331 * Object - The object to be released
1332 *
1333 * RETURN: None
1334 *
1335 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1336 * the object is deleted.
1337 *
1338 ******************************************************************************/
1339
Len Brown4be44fc2005-08-05 00:44:28 -04001340acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
Robert Moore73459f72005-06-24 00:00:00 -04001341{
Len Brown4be44fc2005-08-05 00:44:28 -04001342 kmem_cache_free(cache, object);
1343 return (AE_OK);
Robert Moore73459f72005-06-24 00:00:00 -04001344}
1345
Len Brown5a4e1432008-01-23 20:01:22 -05001346/**
1347 * acpi_dmi_dump - dump DMI slots needed for blacklist entry
1348 *
1349 * Returns 0 on success
1350 */
1351int acpi_dmi_dump(void)
1352{
1353
1354 if (!dmi_available)
1355 return -1;
1356
1357 printk(KERN_NOTICE PREFIX "DMI System Vendor: %s\n",
1358 dmi_get_slot(DMI_SYS_VENDOR));
1359 printk(KERN_NOTICE PREFIX "DMI Product Name: %s\n",
1360 dmi_get_slot(DMI_PRODUCT_NAME));
1361 printk(KERN_NOTICE PREFIX "DMI Product Version: %s\n",
1362 dmi_get_slot(DMI_PRODUCT_VERSION));
1363 printk(KERN_NOTICE PREFIX "DMI Board Name: %s\n",
1364 dmi_get_slot(DMI_BOARD_NAME));
1365 printk(KERN_NOTICE PREFIX "DMI BIOS Vendor: %s\n",
1366 dmi_get_slot(DMI_BIOS_VENDOR));
1367 printk(KERN_NOTICE PREFIX "DMI BIOS Date: %s\n",
1368 dmi_get_slot(DMI_BIOS_DATE));
1369
1370 return 0;
1371}
1372
1373
Bob Mooreb229cf92006-04-21 17:15:00 -04001374/******************************************************************************
1375 *
1376 * FUNCTION: acpi_os_validate_interface
1377 *
1378 * PARAMETERS: interface - Requested interface to be validated
1379 *
1380 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1381 *
1382 * DESCRIPTION: Match an interface string to the interfaces supported by the
1383 * host. Strings originate from an AML call to the _OSI method.
1384 *
1385 *****************************************************************************/
1386
1387acpi_status
1388acpi_os_validate_interface (char *interface)
1389{
Len Brownae00d812007-05-29 18:43:33 -04001390 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1391 return AE_OK;
Len Brownf5076542007-05-30 00:10:38 -04001392 if (!strcmp("Linux", interface)) {
Len Brownd4b7dc42008-01-23 20:50:56 -05001393
1394 printk(KERN_NOTICE PREFIX
1395 "BIOS _OSI(Linux) query %s%s\n",
1396 osi_linux.enable ? "honored" : "ignored",
1397 osi_linux.cmdline ? " via cmdline" :
1398 osi_linux.dmi ? " via DMI" : "");
1399
1400 if (!osi_linux.dmi) {
1401 if (acpi_dmi_dump())
1402 printk(KERN_NOTICE PREFIX
1403 "[please extract dmidecode output]\n");
Len Brownf40cd6f2008-01-23 20:04:28 -05001404 printk(KERN_NOTICE PREFIX
Len Brownd4b7dc42008-01-23 20:50:56 -05001405 "Please send DMI info above to "
1406 "linux-acpi@vger.kernel.org\n");
1407 }
1408 if (!osi_linux.known && !osi_linux.cmdline) {
1409 printk(KERN_NOTICE PREFIX
1410 "If \"acpi_osi=%sLinux\" works better, "
1411 "please notify linux-acpi@vger.kernel.org\n",
1412 osi_linux.enable ? "!" : "");
1413 }
1414
1415 if (osi_linux.enable)
Len Brownf5076542007-05-30 00:10:38 -04001416 return AE_OK;
1417 }
Len Brownae00d812007-05-29 18:43:33 -04001418 return AE_SUPPORT;
Bob Mooreb229cf92006-04-21 17:15:00 -04001419}
1420
Bob Mooreb229cf92006-04-21 17:15:00 -04001421/******************************************************************************
1422 *
1423 * FUNCTION: acpi_os_validate_address
1424 *
1425 * PARAMETERS: space_id - ACPI space ID
1426 * address - Physical address
1427 * length - Address length
1428 *
1429 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1430 * should return AE_AML_ILLEGAL_ADDRESS.
1431 *
1432 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1433 * the addresses accessed by AML operation regions.
1434 *
1435 *****************************************************************************/
1436
1437acpi_status
1438acpi_os_validate_address (
1439 u8 space_id,
1440 acpi_physical_address address,
Thomas Renningerdf92e692008-02-04 23:31:22 -08001441 acpi_size length,
1442 char *name)
Bob Mooreb229cf92006-04-21 17:15:00 -04001443{
Thomas Renningerdf92e692008-02-04 23:31:22 -08001444 struct acpi_res_list *res;
1445 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1446 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001447
Thomas Renningerdf92e692008-02-04 23:31:22 -08001448 switch (space_id) {
1449 case ACPI_ADR_SPACE_SYSTEM_IO:
1450 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1451 /* Only interference checks against SystemIO and SytemMemory
1452 are needed */
1453 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1454 if (!res)
1455 return AE_OK;
1456 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1457 strlcpy(res->name, name, 5);
1458 res->start = address;
1459 res->end = address + length - 1;
1460 res->resource_type = space_id;
1461 spin_lock(&acpi_res_lock);
1462 list_add(&res->resource_list, &resource_list_head);
1463 spin_unlock(&acpi_res_lock);
1464 pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, "
1465 "name: %s\n", (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
1466 ? "SystemIO" : "System Memory",
1467 (unsigned long long)res->start,
1468 (unsigned long long)res->end,
1469 res->name);
1470 break;
1471 case ACPI_ADR_SPACE_PCI_CONFIG:
1472 case ACPI_ADR_SPACE_EC:
1473 case ACPI_ADR_SPACE_SMBUS:
1474 case ACPI_ADR_SPACE_CMOS:
1475 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1476 case ACPI_ADR_SPACE_DATA_TABLE:
1477 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1478 break;
1479 }
1480 return AE_OK;
Bob Mooreb229cf92006-04-21 17:15:00 -04001481}
1482
Robert Moore73459f72005-06-24 00:00:00 -04001483#endif