Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus
[linux-2.6-block.git] / drivers / acpi / osl.c
CommitLineData
1da177e4
LT
1/*
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>
f1241c87
MW
7 * Copyright (c) 2008 Intel Corporation
8 * Author: Matthew Wilcox <willy@linux.intel.com>
1da177e4
LT
9 *
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 *
28 */
29
1da177e4
LT
30#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/slab.h>
33#include <linux/mm.h>
34#include <linux/pci.h>
1da177e4
LT
35#include <linux/interrupt.h>
36#include <linux/kmod.h>
37#include <linux/delay.h>
38#include <linux/workqueue.h>
39#include <linux/nmi.h>
ad71860a 40#include <linux/acpi.h>
1da177e4 41#include <linux/efi.h>
df92e695
TR
42#include <linux/ioport.h>
43#include <linux/list.h>
f1241c87
MW
44#include <linux/jiffies.h>
45#include <linux/semaphore.h>
46
47#include <asm/io.h>
48#include <asm/uaccess.h>
49
50#include <acpi/acpi.h>
51#include <acpi/acpi_bus.h>
52#include <acpi/processor.h>
1da177e4 53
1da177e4 54#define _COMPONENT ACPI_OS_SERVICES
f52fd66d 55ACPI_MODULE_NAME("osl");
1da177e4 56#define PREFIX "ACPI: "
4be44fcd
LB
57struct acpi_os_dpc {
58 acpi_osd_exec_callback function;
59 void *context;
65f27f38 60 struct work_struct work;
9ac61856 61 int wait;
1da177e4
LT
62};
63
64#ifdef CONFIG_ACPI_CUSTOM_DSDT
65#include CONFIG_ACPI_CUSTOM_DSDT_FILE
66#endif
67
68#ifdef ENABLE_DEBUGGER
69#include <linux/kdb.h>
70
71/* stuff for debugger support */
72int acpi_in_debugger;
73EXPORT_SYMBOL(acpi_in_debugger);
74
75extern char line_buf[80];
4be44fcd 76#endif /*ENABLE_DEBUGGER */
1da177e4
LT
77
78static unsigned int acpi_irq_irq;
79static acpi_osd_handler acpi_irq_handler;
80static void *acpi_irq_context;
81static struct workqueue_struct *kacpid_wq;
88db5e14 82static struct workqueue_struct *kacpi_notify_wq;
c02256be 83static struct workqueue_struct *kacpi_hotplug_wq;
1da177e4 84
df92e695
TR
85struct acpi_res_list {
86 resource_size_t start;
87 resource_size_t end;
88 acpi_adr_space_type resource_type; /* IO port, System memory, ...*/
89 char name[5]; /* only can have a length of 4 chars, make use of this
90 one instead of res->name, no need to kalloc then */
91 struct list_head resource_list;
a5fe1a03 92 int count;
df92e695
TR
93};
94
95static LIST_HEAD(resource_list_head);
96static DEFINE_SPINLOCK(acpi_res_lock);
97
ae00d812
LB
98#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
99static char osi_additional_string[OSI_STRING_LENGTH_MAX];
100
d4b7dc49 101/*
a6e0887f 102 * The story of _OSI(Linux)
d4b7dc49 103 *
a6e0887f
LB
104 * From pre-history through Linux-2.6.22,
105 * Linux responded TRUE upon a BIOS OSI(Linux) query.
d4b7dc49 106 *
a6e0887f
LB
107 * Unfortunately, reference BIOS writers got wind of this
108 * and put OSI(Linux) in their example code, quickly exposing
109 * this string as ill-conceived and opening the door to
110 * an un-bounded number of BIOS incompatibilities.
d4b7dc49 111 *
a6e0887f
LB
112 * For example, OSI(Linux) was used on resume to re-POST a
113 * video card on one system, because Linux at that time
114 * could not do a speedy restore in its native driver.
115 * But then upon gaining quick native restore capability,
116 * Linux has no way to tell the BIOS to skip the time-consuming
117 * POST -- putting Linux at a permanent performance disadvantage.
118 * On another system, the BIOS writer used OSI(Linux)
119 * to infer native OS support for IPMI! On other systems,
120 * OSI(Linux) simply got in the way of Linux claiming to
121 * be compatible with other operating systems, exposing
122 * BIOS issues such as skipped device initialization.
d4b7dc49 123 *
a6e0887f
LB
124 * So "Linux" turned out to be a really poor chose of
125 * OSI string, and from Linux-2.6.23 onward we respond FALSE.
d4b7dc49
LB
126 *
127 * BIOS writers should NOT query _OSI(Linux) on future systems.
a6e0887f
LB
128 * Linux will complain on the console when it sees it, and return FALSE.
129 * To get Linux to return TRUE for your system will require
130 * a kernel source update to add a DMI entry,
131 * or boot with "acpi_osi=Linux"
d4b7dc49 132 */
d4b7dc49 133
1d15d84e 134static struct osi_linux {
d4b7dc49
LB
135 unsigned int enable:1;
136 unsigned int dmi:1;
137 unsigned int cmdline:1;
138 unsigned int known:1;
a6e0887f 139} osi_linux = { 0, 0, 0, 0};
f507654d 140
9a47cdb1
BH
141static void __init acpi_request_region (struct acpi_generic_address *addr,
142 unsigned int length, char *desc)
143{
144 struct resource *res;
145
146 if (!addr->address || !length)
147 return;
148
eee3c859 149 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
9a47cdb1 150 res = request_region(addr->address, length, desc);
eee3c859 151 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
9a47cdb1
BH
152 res = request_mem_region(addr->address, length, desc);
153}
154
155static int __init acpi_reserve_resources(void)
156{
eee3c859 157 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
9a47cdb1
BH
158 "ACPI PM1a_EVT_BLK");
159
eee3c859 160 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
9a47cdb1
BH
161 "ACPI PM1b_EVT_BLK");
162
eee3c859 163 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
9a47cdb1
BH
164 "ACPI PM1a_CNT_BLK");
165
eee3c859 166 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
9a47cdb1
BH
167 "ACPI PM1b_CNT_BLK");
168
eee3c859
LB
169 if (acpi_gbl_FADT.pm_timer_length == 4)
170 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
9a47cdb1 171
eee3c859 172 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
9a47cdb1
BH
173 "ACPI PM2_CNT_BLK");
174
175 /* Length of GPE blocks must be a non-negative multiple of 2 */
176
eee3c859
LB
177 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
178 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
179 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
9a47cdb1 180
eee3c859
LB
181 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
182 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
183 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
9a47cdb1
BH
184
185 return 0;
186}
187device_initcall(acpi_reserve_resources);
188
dd272b57 189acpi_status __init acpi_os_initialize(void)
1da177e4
LT
190{
191 return AE_OK;
192}
193
74b58208
BH
194static void bind_to_cpu0(struct work_struct *work)
195{
e68110fb 196 set_cpus_allowed_ptr(current, cpumask_of(0));
74b58208
BH
197 kfree(work);
198}
199
200static void bind_workqueue(struct workqueue_struct *wq)
201{
202 struct work_struct *work;
203
204 work = kzalloc(sizeof(struct work_struct), GFP_KERNEL);
205 INIT_WORK(work, bind_to_cpu0);
206 queue_work(wq, work);
207}
208
4be44fcd 209acpi_status acpi_os_initialize1(void)
1da177e4 210{
74b58208
BH
211 /*
212 * On some machines, a software-initiated SMI causes corruption unless
213 * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
214 * typically it's done in GPE-related methods that are run via
215 * workqueues, so we can avoid the known corruption cases by binding
216 * the workqueues to CPU 0.
217 */
1da177e4 218 kacpid_wq = create_singlethread_workqueue("kacpid");
74b58208 219 bind_workqueue(kacpid_wq);
88db5e14 220 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
74b58208 221 bind_workqueue(kacpi_notify_wq);
c02256be 222 kacpi_hotplug_wq = create_singlethread_workqueue("kacpi_hotplug");
74b58208 223 bind_workqueue(kacpi_hotplug_wq);
1da177e4 224 BUG_ON(!kacpid_wq);
88db5e14 225 BUG_ON(!kacpi_notify_wq);
c02256be 226 BUG_ON(!kacpi_hotplug_wq);
1da177e4
LT
227 return AE_OK;
228}
229
4be44fcd 230acpi_status acpi_os_terminate(void)
1da177e4
LT
231{
232 if (acpi_irq_handler) {
233 acpi_os_remove_interrupt_handler(acpi_irq_irq,
234 acpi_irq_handler);
235 }
236
237 destroy_workqueue(kacpid_wq);
88db5e14 238 destroy_workqueue(kacpi_notify_wq);
c02256be 239 destroy_workqueue(kacpi_hotplug_wq);
1da177e4
LT
240
241 return AE_OK;
242}
243
4be44fcd 244void acpi_os_printf(const char *fmt, ...)
1da177e4
LT
245{
246 va_list args;
247 va_start(args, fmt);
248 acpi_os_vprintf(fmt, args);
249 va_end(args);
250}
4be44fcd 251
4be44fcd 252void acpi_os_vprintf(const char *fmt, va_list args)
1da177e4
LT
253{
254 static char buffer[512];
4be44fcd 255
1da177e4
LT
256 vsprintf(buffer, fmt, args);
257
258#ifdef ENABLE_DEBUGGER
259 if (acpi_in_debugger) {
260 kdb_printf("%s", buffer);
261 } else {
4d939155 262 printk(KERN_CONT "%s", buffer);
1da177e4
LT
263 }
264#else
4d939155 265 printk(KERN_CONT "%s", buffer);
1da177e4
LT
266#endif
267}
268
ad71860a 269acpi_physical_address __init acpi_os_get_root_pointer(void)
1da177e4
LT
270{
271 if (efi_enabled) {
b2c99e3c 272 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
ad71860a 273 return efi.acpi20;
b2c99e3c 274 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
ad71860a 275 return efi.acpi;
1da177e4 276 else {
4be44fcd
LB
277 printk(KERN_ERR PREFIX
278 "System description tables not found\n");
ad71860a 279 return 0;
1da177e4 280 }
239665a3
LB
281 } else {
282 acpi_physical_address pa = 0;
283
284 acpi_find_root_pointer(&pa);
285 return pa;
286 }
1da177e4
LT
287}
288
2fdf0741
JB
289void __iomem *__init_refok
290acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
1da177e4 291{
9f4fd61f
BH
292 if (phys > ULONG_MAX) {
293 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
70c0846e 294 return NULL;
1da177e4 295 }
ad71860a
AS
296 if (acpi_gbl_permanent_mmap)
297 /*
298 * ioremap checks to ensure this is in reserved space
299 */
300 return ioremap((unsigned long)phys, size);
301 else
302 return __acpi_map_table((unsigned long)phys, size);
1da177e4 303}
55a82ab3 304EXPORT_SYMBOL_GPL(acpi_os_map_memory);
1da177e4 305
0d3a9cf5 306void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
1da177e4 307{
7d97277b 308 if (acpi_gbl_permanent_mmap)
ad71860a 309 iounmap(virt);
7d97277b
YL
310 else
311 __acpi_unmap_table(virt, size);
1da177e4 312}
55a82ab3 313EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
1da177e4 314
0d3a9cf5 315void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
7d97277b
YL
316{
317 if (!acpi_gbl_permanent_mmap)
318 __acpi_unmap_table(virt, size);
319}
320
1da177e4
LT
321#ifdef ACPI_FUTURE_USAGE
322acpi_status
4be44fcd 323acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
1da177e4 324{
4be44fcd 325 if (!phys || !virt)
1da177e4
LT
326 return AE_BAD_PARAMETER;
327
328 *phys = virt_to_phys(virt);
329
330 return AE_OK;
331}
332#endif
333
334#define ACPI_MAX_OVERRIDE_LEN 100
335
336static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
337
338acpi_status
4be44fcd
LB
339acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
340 acpi_string * new_val)
1da177e4
LT
341{
342 if (!init_val || !new_val)
343 return AE_BAD_PARAMETER;
344
345 *new_val = NULL;
4be44fcd 346 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
1da177e4 347 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
4be44fcd 348 acpi_os_name);
1da177e4
LT
349 *new_val = acpi_os_name;
350 }
351
352 return AE_OK;
353}
354
355acpi_status
4be44fcd
LB
356acpi_os_table_override(struct acpi_table_header * existing_table,
357 struct acpi_table_header ** new_table)
1da177e4
LT
358{
359 if (!existing_table || !new_table)
360 return AE_BAD_PARAMETER;
361
71fc47a9
MG
362 *new_table = NULL;
363
1da177e4
LT
364#ifdef CONFIG_ACPI_CUSTOM_DSDT
365 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
4be44fcd 366 *new_table = (struct acpi_table_header *)AmlCode;
1da177e4 367#endif
6ed31e92
ÉP
368 if (*new_table != NULL) {
369 printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
370 "this is unsafe: tainting kernel\n",
371 existing_table->signature,
372 existing_table->oem_table_id);
373 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
374 }
1da177e4
LT
375 return AE_OK;
376}
377
7d12e780 378static irqreturn_t acpi_irq(int irq, void *dev_id)
1da177e4 379{
5229e87d
LB
380 u32 handled;
381
382 handled = (*acpi_irq_handler) (acpi_irq_context);
383
384 if (handled) {
385 acpi_irq_handled++;
386 return IRQ_HANDLED;
88bea188
LB
387 } else {
388 acpi_irq_not_handled++;
5229e87d 389 return IRQ_NONE;
88bea188 390 }
1da177e4
LT
391}
392
393acpi_status
4be44fcd
LB
394acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
395 void *context)
1da177e4
LT
396{
397 unsigned int irq;
398
5229e87d
LB
399 acpi_irq_stats_init();
400
1da177e4
LT
401 /*
402 * Ignore the GSI from the core, and use the value in our copy of the
403 * FADT. It may not be the same if an interrupt source override exists
404 * for the SCI.
405 */
cee324b1 406 gsi = acpi_gbl_FADT.sci_interrupt;
1da177e4
LT
407 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
408 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
409 gsi);
410 return AE_OK;
411 }
412
413 acpi_irq_handler = handler;
414 acpi_irq_context = context;
dace1453 415 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
1da177e4
LT
416 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
417 return AE_NOT_ACQUIRED;
418 }
419 acpi_irq_irq = irq;
420
421 return AE_OK;
422}
423
4be44fcd 424acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
1da177e4
LT
425{
426 if (irq) {
427 free_irq(irq, acpi_irq);
428 acpi_irq_handler = NULL;
429 acpi_irq_irq = 0;
430 }
431
432 return AE_OK;
433}
434
435/*
436 * Running in interpreter thread context, safe to sleep
437 */
438
4be44fcd 439void acpi_os_sleep(acpi_integer ms)
1da177e4 440{
01a527ec 441 schedule_timeout_interruptible(msecs_to_jiffies(ms));
1da177e4 442}
4be44fcd 443
4be44fcd 444void acpi_os_stall(u32 us)
1da177e4
LT
445{
446 while (us) {
447 u32 delay = 1000;
448
449 if (delay > us)
450 delay = us;
451 udelay(delay);
452 touch_nmi_watchdog();
453 us -= delay;
454 }
455}
4be44fcd 456
1da177e4
LT
457/*
458 * Support ACPI 3.0 AML Timer operand
459 * Returns 64-bit free-running, monotonically increasing timer
460 * with 100ns granularity
461 */
4be44fcd 462u64 acpi_os_get_timer(void)
1da177e4
LT
463{
464 static u64 t;
465
466#ifdef CONFIG_HPET
467 /* TBD: use HPET if available */
468#endif
469
470#ifdef CONFIG_X86_PM_TIMER
471 /* TBD: default to PM timer if HPET was not available */
472#endif
473 if (!t)
474 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
475
476 return ++t;
477}
478
4be44fcd 479acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
1da177e4
LT
480{
481 u32 dummy;
482
483 if (!value)
484 value = &dummy;
485
49fbabf5
ZY
486 *value = 0;
487 if (width <= 8) {
4be44fcd 488 *(u8 *) value = inb(port);
49fbabf5 489 } else if (width <= 16) {
4be44fcd 490 *(u16 *) value = inw(port);
49fbabf5 491 } else if (width <= 32) {
4be44fcd 492 *(u32 *) value = inl(port);
49fbabf5 493 } else {
1da177e4
LT
494 BUG();
495 }
496
497 return AE_OK;
498}
4be44fcd 499
1da177e4
LT
500EXPORT_SYMBOL(acpi_os_read_port);
501
4be44fcd 502acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
1da177e4 503{
49fbabf5 504 if (width <= 8) {
1da177e4 505 outb(value, port);
49fbabf5 506 } else if (width <= 16) {
1da177e4 507 outw(value, port);
49fbabf5 508 } else if (width <= 32) {
1da177e4 509 outl(value, port);
49fbabf5 510 } else {
1da177e4
LT
511 BUG();
512 }
513
514 return AE_OK;
515}
4be44fcd 516
1da177e4
LT
517EXPORT_SYMBOL(acpi_os_write_port);
518
519acpi_status
4be44fcd 520acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
1da177e4 521{
4be44fcd
LB
522 u32 dummy;
523 void __iomem *virt_addr;
1da177e4 524
9f4fd61f 525 virt_addr = ioremap(phys_addr, width);
1da177e4
LT
526 if (!value)
527 value = &dummy;
528
529 switch (width) {
530 case 8:
4be44fcd 531 *(u8 *) value = readb(virt_addr);
1da177e4
LT
532 break;
533 case 16:
4be44fcd 534 *(u16 *) value = readw(virt_addr);
1da177e4
LT
535 break;
536 case 32:
4be44fcd 537 *(u32 *) value = readl(virt_addr);
1da177e4
LT
538 break;
539 default:
540 BUG();
541 }
542
9f4fd61f 543 iounmap(virt_addr);
1da177e4
LT
544
545 return AE_OK;
546}
547
548acpi_status
4be44fcd 549acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
1da177e4 550{
4be44fcd 551 void __iomem *virt_addr;
1da177e4 552
9f4fd61f 553 virt_addr = ioremap(phys_addr, width);
1da177e4
LT
554
555 switch (width) {
556 case 8:
557 writeb(value, virt_addr);
558 break;
559 case 16:
560 writew(value, virt_addr);
561 break;
562 case 32:
563 writel(value, virt_addr);
564 break;
565 default:
566 BUG();
567 }
568
9f4fd61f 569 iounmap(virt_addr);
1da177e4
LT
570
571 return AE_OK;
572}
573
1da177e4 574acpi_status
4be44fcd 575acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
10270d48 576 u32 *value, u32 width)
1da177e4
LT
577{
578 int result, size;
579
580 if (!value)
581 return AE_BAD_PARAMETER;
582
583 switch (width) {
584 case 8:
585 size = 1;
586 break;
587 case 16:
588 size = 2;
589 break;
590 case 32:
591 size = 4;
592 break;
593 default:
594 return AE_ERROR;
595 }
596
b6ce068a
MW
597 result = raw_pci_read(pci_id->segment, pci_id->bus,
598 PCI_DEVFN(pci_id->device, pci_id->function),
599 reg, size, value);
1da177e4
LT
600
601 return (result ? AE_ERROR : AE_OK);
602}
4be44fcd 603
1da177e4 604acpi_status
4be44fcd
LB
605acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
606 acpi_integer value, u32 width)
1da177e4
LT
607{
608 int result, size;
609
610 switch (width) {
611 case 8:
612 size = 1;
613 break;
614 case 16:
615 size = 2;
616 break;
617 case 32:
618 size = 4;
619 break;
620 default:
621 return AE_ERROR;
622 }
623
b6ce068a
MW
624 result = raw_pci_write(pci_id->segment, pci_id->bus,
625 PCI_DEVFN(pci_id->device, pci_id->function),
626 reg, size, value);
1da177e4
LT
627
628 return (result ? AE_ERROR : AE_OK);
629}
630
631/* TODO: Change code to take advantage of driver model more */
4be44fcd
LB
632static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
633 acpi_handle chandle, /* current node */
634 struct acpi_pci_id **id,
635 int *is_bridge, u8 * bus_number)
1da177e4 636{
4be44fcd
LB
637 acpi_handle handle;
638 struct acpi_pci_id *pci_id = *id;
639 acpi_status status;
27663c58 640 unsigned long long temp;
4be44fcd 641 acpi_object_type type;
1da177e4
LT
642
643 acpi_get_parent(chandle, &handle);
644 if (handle != rhandle) {
4be44fcd
LB
645 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
646 bus_number);
1da177e4
LT
647
648 status = acpi_get_type(handle, &type);
4be44fcd 649 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
1da177e4
LT
650 return;
651
27663c58 652 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
4be44fcd 653 &temp);
1da177e4 654 if (ACPI_SUCCESS(status)) {
10270d48 655 u32 val;
4be44fcd
LB
656 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
657 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
1da177e4
LT
658
659 if (*is_bridge)
660 pci_id->bus = *bus_number;
661
662 /* any nicer way to get bus number of bridge ? */
4be44fcd 663 status =
10270d48 664 acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
4be44fcd
LB
665 8);
666 if (ACPI_SUCCESS(status)
10270d48 667 && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
4be44fcd
LB
668 status =
669 acpi_os_read_pci_configuration(pci_id, 0x18,
10270d48 670 &val, 8);
1da177e4
LT
671 if (!ACPI_SUCCESS(status)) {
672 /* Certainly broken... FIX ME */
673 return;
674 }
675 *is_bridge = 1;
10270d48 676 pci_id->bus = val;
4be44fcd
LB
677 status =
678 acpi_os_read_pci_configuration(pci_id, 0x19,
10270d48 679 &val, 8);
1da177e4 680 if (ACPI_SUCCESS(status)) {
10270d48 681 *bus_number = val;
1da177e4
LT
682 }
683 } else
684 *is_bridge = 0;
685 }
686 }
687}
688
4be44fcd
LB
689void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
690 acpi_handle chandle, /* current node */
691 struct acpi_pci_id **id)
1da177e4
LT
692{
693 int is_bridge = 1;
694 u8 bus_number = (*id)->bus;
695
696 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
697}
698
65f27f38 699static void acpi_os_execute_deferred(struct work_struct *work)
88db5e14
AS
700{
701 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
88db5e14 702
9ac61856
BH
703 if (dpc->wait)
704 acpi_os_wait_events_complete(NULL);
19cd847a
ZR
705
706 dpc->function(dpc->context);
707 kfree(dpc);
19cd847a
ZR
708}
709
b8d35192
AS
710/*******************************************************************************
711 *
712 * FUNCTION: acpi_os_execute
713 *
714 * PARAMETERS: Type - Type of the callback
715 * Function - Function to be executed
716 * Context - Function parameters
717 *
718 * RETURN: Status
719 *
720 * DESCRIPTION: Depending on type, either queues function for deferred execution or
721 * immediately executes function on a separate thread.
722 *
723 ******************************************************************************/
724
19cd847a
ZR
725static acpi_status __acpi_os_execute(acpi_execute_type type,
726 acpi_osd_exec_callback function, void *context, int hp)
1da177e4 727{
4be44fcd
LB
728 acpi_status status = AE_OK;
729 struct acpi_os_dpc *dpc;
17bc54ee 730 struct workqueue_struct *queue;
19cd847a 731 int ret;
72945b2b
LB
732 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
733 "Scheduling function [%p(%p)] for deferred execution.\n",
734 function, context));
1da177e4 735
1da177e4
LT
736 /*
737 * Allocate/initialize DPC structure. Note that this memory will be
65f27f38 738 * freed by the callee. The kernel handles the work_struct list in a
1da177e4
LT
739 * way that allows us to also free its memory inside the callee.
740 * Because we may want to schedule several tasks with different
741 * parameters we can't use the approach some kernel code uses of
65f27f38 742 * having a static work_struct.
1da177e4 743 */
72945b2b 744
65f27f38 745 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
1da177e4 746 if (!dpc)
889c78be 747 return AE_NO_MEMORY;
b976fe19 748
1da177e4
LT
749 dpc->function = function;
750 dpc->context = context;
b976fe19 751
c02256be
ZR
752 /*
753 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
754 * because the hotplug code may call driver .remove() functions,
755 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
756 * to flush these workqueues.
757 */
758 queue = hp ? kacpi_hotplug_wq :
759 (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
9ac61856
BH
760 dpc->wait = hp ? 1 : 0;
761 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
c02256be 762 ret = queue_work(queue, &dpc->work);
19cd847a
ZR
763
764 if (!ret) {
55ac9a01
LM
765 printk(KERN_ERR PREFIX
766 "Call to queue_work() failed.\n");
17bc54ee
AS
767 status = AE_ERROR;
768 kfree(dpc);
1da177e4 769 }
889c78be 770 return status;
1da177e4 771}
4be44fcd 772
19cd847a
ZR
773acpi_status acpi_os_execute(acpi_execute_type type,
774 acpi_osd_exec_callback function, void *context)
775{
776 return __acpi_os_execute(type, function, context, 0);
777}
b8d35192 778EXPORT_SYMBOL(acpi_os_execute);
1da177e4 779
19cd847a
ZR
780acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
781 void *context)
782{
783 return __acpi_os_execute(0, function, context, 1);
784}
785
4be44fcd 786void acpi_os_wait_events_complete(void *context)
1da177e4
LT
787{
788 flush_workqueue(kacpid_wq);
2f67a069 789 flush_workqueue(kacpi_notify_wq);
1da177e4 790}
4be44fcd 791
1da177e4
LT
792EXPORT_SYMBOL(acpi_os_wait_events_complete);
793
794/*
795 * Allocate the memory for a spinlock and initialize it.
796 */
967440e3 797acpi_status acpi_os_create_lock(acpi_spinlock * handle)
1da177e4 798{
967440e3 799 spin_lock_init(*handle);
1da177e4 800
d550d98d 801 return AE_OK;
1da177e4
LT
802}
803
1da177e4
LT
804/*
805 * Deallocate the memory for a spinlock.
806 */
967440e3 807void acpi_os_delete_lock(acpi_spinlock handle)
1da177e4 808{
d550d98d 809 return;
1da177e4
LT
810}
811
1da177e4 812acpi_status
4be44fcd 813acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
1da177e4 814{
4be44fcd 815 struct semaphore *sem = NULL;
1da177e4 816
1da177e4
LT
817 sem = acpi_os_allocate(sizeof(struct semaphore));
818 if (!sem)
d550d98d 819 return AE_NO_MEMORY;
1da177e4
LT
820 memset(sem, 0, sizeof(struct semaphore));
821
822 sema_init(sem, initial_units);
823
4be44fcd 824 *handle = (acpi_handle *) sem;
1da177e4 825
4be44fcd
LB
826 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
827 *handle, initial_units));
1da177e4 828
d550d98d 829 return AE_OK;
1da177e4 830}
1da177e4 831
1da177e4
LT
832/*
833 * TODO: A better way to delete semaphores? Linux doesn't have a
834 * 'delete_semaphore()' function -- may result in an invalid
835 * pointer dereference for non-synchronized consumers. Should
836 * we at least check for blocked threads and signal/cancel them?
837 */
838
4be44fcd 839acpi_status acpi_os_delete_semaphore(acpi_handle handle)
1da177e4 840{
4be44fcd 841 struct semaphore *sem = (struct semaphore *)handle;
1da177e4 842
1da177e4 843 if (!sem)
d550d98d 844 return AE_BAD_PARAMETER;
1da177e4 845
4be44fcd 846 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
1da177e4 847
f1241c87 848 BUG_ON(!list_empty(&sem->wait_list));
02438d87 849 kfree(sem);
4be44fcd 850 sem = NULL;
1da177e4 851
d550d98d 852 return AE_OK;
1da177e4 853}
1da177e4 854
1da177e4 855/*
1da177e4
LT
856 * TODO: Support for units > 1?
857 */
4be44fcd 858acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
1da177e4 859{
4be44fcd
LB
860 acpi_status status = AE_OK;
861 struct semaphore *sem = (struct semaphore *)handle;
f1241c87 862 long jiffies;
4be44fcd 863 int ret = 0;
1da177e4 864
1da177e4 865 if (!sem || (units < 1))
d550d98d 866 return AE_BAD_PARAMETER;
1da177e4
LT
867
868 if (units > 1)
d550d98d 869 return AE_SUPPORT;
1da177e4 870
4be44fcd
LB
871 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
872 handle, units, timeout));
1da177e4 873
f1241c87
MW
874 if (timeout == ACPI_WAIT_FOREVER)
875 jiffies = MAX_SCHEDULE_TIMEOUT;
876 else
877 jiffies = msecs_to_jiffies(timeout);
878
879 ret = down_timeout(sem, jiffies);
880 if (ret)
881 status = AE_TIME;
1da177e4
LT
882
883 if (ACPI_FAILURE(status)) {
9e7e2c04 884 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
a6fc6720 885 "Failed to acquire semaphore[%p|%d|%d], %s",
4be44fcd
LB
886 handle, units, timeout,
887 acpi_format_exception(status)));
888 } else {
889 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
a6fc6720 890 "Acquired semaphore[%p|%d|%d]", handle,
4be44fcd 891 units, timeout));
1da177e4
LT
892 }
893
d550d98d 894 return status;
1da177e4 895}
1da177e4 896
1da177e4
LT
897/*
898 * TODO: Support for units > 1?
899 */
4be44fcd 900acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
1da177e4 901{
4be44fcd 902 struct semaphore *sem = (struct semaphore *)handle;
1da177e4 903
1da177e4 904 if (!sem || (units < 1))
d550d98d 905 return AE_BAD_PARAMETER;
1da177e4
LT
906
907 if (units > 1)
d550d98d 908 return AE_SUPPORT;
1da177e4 909
4be44fcd
LB
910 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
911 units));
1da177e4
LT
912
913 up(sem);
914
d550d98d 915 return AE_OK;
1da177e4 916}
4be44fcd 917
1da177e4 918#ifdef ACPI_FUTURE_USAGE
4be44fcd 919u32 acpi_os_get_line(char *buffer)
1da177e4
LT
920{
921
922#ifdef ENABLE_DEBUGGER
923 if (acpi_in_debugger) {
924 u32 chars;
925
926 kdb_read(buffer, sizeof(line_buf));
927
928 /* remove the CR kdb includes */
929 chars = strlen(buffer) - 1;
930 buffer[chars] = '\0';
931 }
932#endif
933
934 return 0;
935}
4be44fcd 936#endif /* ACPI_FUTURE_USAGE */
1da177e4 937
4be44fcd 938acpi_status acpi_os_signal(u32 function, void *info)
1da177e4 939{
4be44fcd 940 switch (function) {
1da177e4
LT
941 case ACPI_SIGNAL_FATAL:
942 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
943 break;
944 case ACPI_SIGNAL_BREAKPOINT:
945 /*
946 * AML Breakpoint
947 * ACPI spec. says to treat it as a NOP unless
948 * you are debugging. So if/when we integrate
949 * AML debugger into the kernel debugger its
950 * hook will go here. But until then it is
951 * not useful to print anything on breakpoints.
952 */
953 break;
954 default:
955 break;
956 }
957
958 return AE_OK;
959}
4be44fcd 960
4be44fcd 961static int __init acpi_os_name_setup(char *str)
1da177e4
LT
962{
963 char *p = acpi_os_name;
4be44fcd 964 int count = ACPI_MAX_OVERRIDE_LEN - 1;
1da177e4
LT
965
966 if (!str || !*str)
967 return 0;
968
969 for (; count-- && str && *str; str++) {
970 if (isalnum(*str) || *str == ' ' || *str == ':')
971 *p++ = *str;
972 else if (*str == '\'' || *str == '"')
973 continue;
974 else
975 break;
976 }
977 *p = 0;
978
979 return 1;
4be44fcd 980
1da177e4
LT
981}
982
983__setup("acpi_os_name=", acpi_os_name_setup);
984
d4b7dc49
LB
985static void __init set_osi_linux(unsigned int enable)
986{
987 if (osi_linux.enable != enable) {
988 osi_linux.enable = enable;
989 printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
990 enable ? "Add": "Delet");
991 }
992 return;
993}
994
995static void __init acpi_cmdline_osi_linux(unsigned int enable)
996{
997 osi_linux.cmdline = 1; /* cmdline set the default */
998 set_osi_linux(enable);
999
1000 return;
1001}
1002
1003void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
1004{
1005 osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
1006
1007 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
1008
1009 if (enable == -1)
1010 return;
1011
1012 osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
f507654d 1013
d4b7dc49 1014 set_osi_linux(enable);
f507654d 1015
f507654d
LB
1016 return;
1017}
1018
1da177e4 1019/*
ae00d812
LB
1020 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
1021 *
1da177e4 1022 * empty string disables _OSI
ae00d812
LB
1023 * string starting with '!' disables that string
1024 * otherwise string is added to list, augmenting built-in strings
1da177e4 1025 */
46c1fbdb 1026int __init acpi_osi_setup(char *str)
1da177e4
LT
1027{
1028 if (str == NULL || *str == '\0') {
1029 printk(KERN_INFO PREFIX "_OSI method disabled\n");
1030 acpi_gbl_create_osi_method = FALSE;
aa2e09da 1031 } else if (!strcmp("!Linux", str)) {
d4b7dc49 1032 acpi_cmdline_osi_linux(0); /* !enable */
ae00d812
LB
1033 } else if (*str == '!') {
1034 if (acpi_osi_invalidate(++str) == AE_OK)
1035 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
f507654d 1036 } else if (!strcmp("Linux", str)) {
d4b7dc49 1037 acpi_cmdline_osi_linux(1); /* enable */
ae00d812
LB
1038 } else if (*osi_additional_string == '\0') {
1039 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
1040 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
1da177e4
LT
1041 }
1042
1043 return 1;
1044}
1045
1046__setup("acpi_osi=", acpi_osi_setup);
1047
1048/* enable serialization to combat AE_ALREADY_EXISTS errors */
4be44fcd 1049static int __init acpi_serialize_setup(char *str)
1da177e4
LT
1050{
1051 printk(KERN_INFO PREFIX "serialize enabled\n");
1052
1053 acpi_gbl_all_methods_serialized = TRUE;
1054
1055 return 1;
1056}
1057
1058__setup("acpi_serialize", acpi_serialize_setup);
1059
1060/*
1061 * Wake and Run-Time GPES are expected to be separate.
1062 * We disable wake-GPEs at run-time to prevent spurious
1063 * interrupts.
1064 *
1065 * However, if a system exists that shares Wake and
1066 * Run-time events on the same GPE this flag is available
1067 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1068 */
4be44fcd 1069static int __init acpi_wake_gpes_always_on_setup(char *str)
1da177e4
LT
1070{
1071 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1072
1073 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1074
1075 return 1;
1076}
1077
1078__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1079
df92e695
TR
1080/* Check of resource interference between native drivers and ACPI
1081 * OperationRegions (SystemIO and System Memory only).
1082 * IO ports and memory declared in ACPI might be used by the ACPI subsystem
1083 * in arbitrary AML code and can interfere with legacy drivers.
1084 * acpi_enforce_resources= can be set to:
1085 *
7e90560c 1086 * - strict (default) (2)
df92e695 1087 * -> further driver trying to access the resources will not load
7e90560c 1088 * - lax (1)
df92e695
TR
1089 * -> further driver trying to access the resources will load, but you
1090 * get a system message that something might go wrong...
1091 *
1092 * - no (0)
1093 * -> ACPI Operation Region resources will not be registered
1094 *
1095 */
1096#define ENFORCE_RESOURCES_STRICT 2
1097#define ENFORCE_RESOURCES_LAX 1
1098#define ENFORCE_RESOURCES_NO 0
1099
7e90560c 1100static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
df92e695
TR
1101
1102static int __init acpi_enforce_resources_setup(char *str)
1103{
1104 if (str == NULL || *str == '\0')
1105 return 0;
1106
1107 if (!strcmp("strict", str))
1108 acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1109 else if (!strcmp("lax", str))
1110 acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
1111 else if (!strcmp("no", str))
1112 acpi_enforce_resources = ENFORCE_RESOURCES_NO;
1113
1114 return 1;
1115}
1116
1117__setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
1118
1119/* Check for resource conflicts between ACPI OperationRegions and native
1120 * drivers */
443dea72 1121int acpi_check_resource_conflict(struct resource *res)
df92e695
TR
1122{
1123 struct acpi_res_list *res_list_elem;
1124 int ioport;
1125 int clash = 0;
1126
1127 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1128 return 0;
1129 if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
1130 return 0;
1131
1132 ioport = res->flags & IORESOURCE_IO;
1133
1134 spin_lock(&acpi_res_lock);
1135 list_for_each_entry(res_list_elem, &resource_list_head,
1136 resource_list) {
1137 if (ioport && (res_list_elem->resource_type
1138 != ACPI_ADR_SPACE_SYSTEM_IO))
1139 continue;
1140 if (!ioport && (res_list_elem->resource_type
1141 != ACPI_ADR_SPACE_SYSTEM_MEMORY))
1142 continue;
1143
1144 if (res->end < res_list_elem->start
1145 || res_list_elem->end < res->start)
1146 continue;
1147 clash = 1;
1148 break;
1149 }
1150 spin_unlock(&acpi_res_lock);
1151
1152 if (clash) {
1153 if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
bd12935f 1154 printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
df92e695
TR
1155 " conflicts with ACPI region %s"
1156 " [0x%llx-0x%llx]\n",
1157 acpi_enforce_resources == ENFORCE_RESOURCES_LAX
1158 ? KERN_WARNING : KERN_ERR,
1159 ioport ? "I/O" : "Memory", res->name,
1160 (long long) res->start, (long long) res->end,
1161 res_list_elem->name,
1162 (long long) res_list_elem->start,
1163 (long long) res_list_elem->end);
1164 printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
1165 }
1166 if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
1167 return -EBUSY;
1168 }
1169 return 0;
1170}
443dea72 1171EXPORT_SYMBOL(acpi_check_resource_conflict);
df92e695
TR
1172
1173int acpi_check_region(resource_size_t start, resource_size_t n,
1174 const char *name)
1175{
1176 struct resource res = {
1177 .start = start,
1178 .end = start + n - 1,
1179 .name = name,
1180 .flags = IORESOURCE_IO,
1181 };
1182
1183 return acpi_check_resource_conflict(&res);
1184}
1185EXPORT_SYMBOL(acpi_check_region);
1186
1187int acpi_check_mem_region(resource_size_t start, resource_size_t n,
1188 const char *name)
1189{
1190 struct resource res = {
1191 .start = start,
1192 .end = start + n - 1,
1193 .name = name,
1194 .flags = IORESOURCE_MEM,
1195 };
1196
1197 return acpi_check_resource_conflict(&res);
1198
1199}
1200EXPORT_SYMBOL(acpi_check_mem_region);
1201
73459f73
RM
1202/*
1203 * Acquire a spinlock.
1204 *
1205 * handle is a pointer to the spinlock_t.
73459f73
RM
1206 */
1207
967440e3 1208acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
73459f73 1209{
b8e4d893 1210 acpi_cpu_flags flags;
967440e3 1211 spin_lock_irqsave(lockp, flags);
73459f73
RM
1212 return flags;
1213}
1214
1215/*
1216 * Release a spinlock. See above.
1217 */
1218
967440e3 1219void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
73459f73 1220{
967440e3 1221 spin_unlock_irqrestore(lockp, flags);
73459f73
RM
1222}
1223
73459f73
RM
1224#ifndef ACPI_USE_LOCAL_CACHE
1225
1226/*******************************************************************************
1227 *
1228 * FUNCTION: acpi_os_create_cache
1229 *
b229cf92
BM
1230 * PARAMETERS: name - Ascii name for the cache
1231 * size - Size of each cached object
1232 * depth - Maximum depth of the cache (in objects) <ignored>
1233 * cache - Where the new cache object is returned
73459f73 1234 *
b229cf92 1235 * RETURN: status
73459f73
RM
1236 *
1237 * DESCRIPTION: Create a cache object
1238 *
1239 ******************************************************************************/
1240
1241acpi_status
4be44fcd 1242acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
73459f73 1243{
20c2df83 1244 *cache = kmem_cache_create(name, size, 0, 0, NULL);
a6fdbf90 1245 if (*cache == NULL)
b229cf92
BM
1246 return AE_ERROR;
1247 else
1248 return AE_OK;
73459f73
RM
1249}
1250
1251/*******************************************************************************
1252 *
1253 * FUNCTION: acpi_os_purge_cache
1254 *
1255 * PARAMETERS: Cache - Handle to cache object
1256 *
1257 * RETURN: Status
1258 *
1259 * DESCRIPTION: Free all objects within the requested cache.
1260 *
1261 ******************************************************************************/
1262
4be44fcd 1263acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
73459f73 1264{
50dd0969 1265 kmem_cache_shrink(cache);
4be44fcd 1266 return (AE_OK);
73459f73
RM
1267}
1268
1269/*******************************************************************************
1270 *
1271 * FUNCTION: acpi_os_delete_cache
1272 *
1273 * PARAMETERS: Cache - Handle to cache object
1274 *
1275 * RETURN: Status
1276 *
1277 * DESCRIPTION: Free all objects within the requested cache and delete the
1278 * cache object.
1279 *
1280 ******************************************************************************/
1281
4be44fcd 1282acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
73459f73 1283{
1a1d92c1 1284 kmem_cache_destroy(cache);
4be44fcd 1285 return (AE_OK);
73459f73
RM
1286}
1287
1288/*******************************************************************************
1289 *
1290 * FUNCTION: acpi_os_release_object
1291 *
1292 * PARAMETERS: Cache - Handle to cache object
1293 * Object - The object to be released
1294 *
1295 * RETURN: None
1296 *
1297 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1298 * the object is deleted.
1299 *
1300 ******************************************************************************/
1301
4be44fcd 1302acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
73459f73 1303{
4be44fcd
LB
1304 kmem_cache_free(cache, object);
1305 return (AE_OK);
73459f73
RM
1306}
1307
b229cf92
BM
1308/******************************************************************************
1309 *
1310 * FUNCTION: acpi_os_validate_interface
1311 *
1312 * PARAMETERS: interface - Requested interface to be validated
1313 *
1314 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1315 *
1316 * DESCRIPTION: Match an interface string to the interfaces supported by the
1317 * host. Strings originate from an AML call to the _OSI method.
1318 *
1319 *****************************************************************************/
1320
1321acpi_status
1322acpi_os_validate_interface (char *interface)
1323{
ae00d812
LB
1324 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1325 return AE_OK;
f507654d 1326 if (!strcmp("Linux", interface)) {
d4b7dc49 1327
f40cd6fd 1328 printk(KERN_NOTICE PREFIX
d4b7dc49
LB
1329 "BIOS _OSI(Linux) query %s%s\n",
1330 osi_linux.enable ? "honored" : "ignored",
1331 osi_linux.cmdline ? " via cmdline" :
1332 osi_linux.dmi ? " via DMI" : "");
1333
d4b7dc49 1334 if (osi_linux.enable)
f507654d
LB
1335 return AE_OK;
1336 }
ae00d812 1337 return AE_SUPPORT;
b229cf92
BM
1338}
1339
a5fe1a03
LM
1340static inline int acpi_res_list_add(struct acpi_res_list *res)
1341{
1342 struct acpi_res_list *res_list_elem;
1343
1344 list_for_each_entry(res_list_elem, &resource_list_head,
1345 resource_list) {
1346
1347 if (res->resource_type == res_list_elem->resource_type &&
1348 res->start == res_list_elem->start &&
1349 res->end == res_list_elem->end) {
1350
1351 /*
1352 * The Region(addr,len) already exist in the list,
1353 * just increase the count
1354 */
1355
1356 res_list_elem->count++;
1357 return 0;
1358 }
1359 }
1360
1361 res->count = 1;
1362 list_add(&res->resource_list, &resource_list_head);
1363 return 1;
1364}
1365
1366static inline void acpi_res_list_del(struct acpi_res_list *res)
1367{
1368 struct acpi_res_list *res_list_elem;
1369
1370 list_for_each_entry(res_list_elem, &resource_list_head,
1371 resource_list) {
1372
1373 if (res->resource_type == res_list_elem->resource_type &&
1374 res->start == res_list_elem->start &&
1375 res->end == res_list_elem->end) {
1376
1377 /*
1378 * If the res count is decreased to 0,
1379 * remove and free it
1380 */
1381
1382 if (--res_list_elem->count == 0) {
1383 list_del(&res_list_elem->resource_list);
1384 kfree(res_list_elem);
1385 }
1386 return;
1387 }
1388 }
1389}
1390
1391acpi_status
1392acpi_os_invalidate_address(
1393 u8 space_id,
1394 acpi_physical_address address,
1395 acpi_size length)
1396{
1397 struct acpi_res_list res;
1398
1399 switch (space_id) {
1400 case ACPI_ADR_SPACE_SYSTEM_IO:
1401 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1402 /* Only interference checks against SystemIO and SytemMemory
1403 are needed */
1404 res.start = address;
1405 res.end = address + length - 1;
1406 res.resource_type = space_id;
1407 spin_lock(&acpi_res_lock);
1408 acpi_res_list_del(&res);
1409 spin_unlock(&acpi_res_lock);
1410 break;
1411 case ACPI_ADR_SPACE_PCI_CONFIG:
1412 case ACPI_ADR_SPACE_EC:
1413 case ACPI_ADR_SPACE_SMBUS:
1414 case ACPI_ADR_SPACE_CMOS:
1415 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1416 case ACPI_ADR_SPACE_DATA_TABLE:
1417 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1418 break;
1419 }
1420 return AE_OK;
1421}
1422
b229cf92
BM
1423/******************************************************************************
1424 *
1425 * FUNCTION: acpi_os_validate_address
1426 *
1427 * PARAMETERS: space_id - ACPI space ID
1428 * address - Physical address
1429 * length - Address length
1430 *
1431 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1432 * should return AE_AML_ILLEGAL_ADDRESS.
1433 *
1434 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1435 * the addresses accessed by AML operation regions.
1436 *
1437 *****************************************************************************/
1438
1439acpi_status
1440acpi_os_validate_address (
1441 u8 space_id,
1442 acpi_physical_address address,
df92e695
TR
1443 acpi_size length,
1444 char *name)
b229cf92 1445{
df92e695 1446 struct acpi_res_list *res;
a5fe1a03 1447 int added;
df92e695
TR
1448 if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
1449 return AE_OK;
b229cf92 1450
df92e695
TR
1451 switch (space_id) {
1452 case ACPI_ADR_SPACE_SYSTEM_IO:
1453 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1454 /* Only interference checks against SystemIO and SytemMemory
1455 are needed */
1456 res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
1457 if (!res)
1458 return AE_OK;
1459 /* ACPI names are fixed to 4 bytes, still better use strlcpy */
1460 strlcpy(res->name, name, 5);
1461 res->start = address;
1462 res->end = address + length - 1;
1463 res->resource_type = space_id;
1464 spin_lock(&acpi_res_lock);
a5fe1a03 1465 added = acpi_res_list_add(res);
df92e695 1466 spin_unlock(&acpi_res_lock);
a5fe1a03
LM
1467 pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
1468 "name: %s\n", added ? "Added" : "Already exist",
1469 (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
df92e695
TR
1470 ? "SystemIO" : "System Memory",
1471 (unsigned long long)res->start,
1472 (unsigned long long)res->end,
1473 res->name);
a5fe1a03
LM
1474 if (!added)
1475 kfree(res);
df92e695
TR
1476 break;
1477 case ACPI_ADR_SPACE_PCI_CONFIG:
1478 case ACPI_ADR_SPACE_EC:
1479 case ACPI_ADR_SPACE_SMBUS:
1480 case ACPI_ADR_SPACE_CMOS:
1481 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1482 case ACPI_ADR_SPACE_DATA_TABLE:
1483 case ACPI_ADR_SPACE_FIXED_HARDWARE:
1484 break;
1485 }
1486 return AE_OK;
b229cf92
BM
1487}
1488
73459f73 1489#endif