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