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