ACPI: extend "acpi_osi=" boot option
[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>
7 *
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 *
26 */
27
1da177e4
LT
28#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/slab.h>
31#include <linux/mm.h>
32#include <linux/pci.h>
1da177e4
LT
33#include <linux/interrupt.h>
34#include <linux/kmod.h>
35#include <linux/delay.h>
36#include <linux/workqueue.h>
37#include <linux/nmi.h>
ad71860a 38#include <linux/acpi.h>
1da177e4
LT
39#include <acpi/acpi.h>
40#include <asm/io.h>
41#include <acpi/acpi_bus.h>
42#include <acpi/processor.h>
43#include <asm/uaccess.h>
44
45#include <linux/efi.h>
46
1da177e4 47#define _COMPONENT ACPI_OS_SERVICES
f52fd66d 48ACPI_MODULE_NAME("osl");
1da177e4 49#define PREFIX "ACPI: "
4be44fcd
LB
50struct acpi_os_dpc {
51 acpi_osd_exec_callback function;
52 void *context;
65f27f38 53 struct work_struct work;
1da177e4
LT
54};
55
56#ifdef CONFIG_ACPI_CUSTOM_DSDT
57#include CONFIG_ACPI_CUSTOM_DSDT_FILE
58#endif
59
60#ifdef ENABLE_DEBUGGER
61#include <linux/kdb.h>
62
63/* stuff for debugger support */
64int acpi_in_debugger;
65EXPORT_SYMBOL(acpi_in_debugger);
66
67extern char line_buf[80];
4be44fcd 68#endif /*ENABLE_DEBUGGER */
1da177e4
LT
69
70static unsigned int acpi_irq_irq;
71static acpi_osd_handler acpi_irq_handler;
72static void *acpi_irq_context;
73static struct workqueue_struct *kacpid_wq;
88db5e14 74static struct workqueue_struct *kacpi_notify_wq;
1da177e4 75
ae00d812
LB
76#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
77static char osi_additional_string[OSI_STRING_LENGTH_MAX];
78
9a47cdb1
BH
79static void __init acpi_request_region (struct acpi_generic_address *addr,
80 unsigned int length, char *desc)
81{
82 struct resource *res;
83
84 if (!addr->address || !length)
85 return;
86
eee3c859 87 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
9a47cdb1 88 res = request_region(addr->address, length, desc);
eee3c859 89 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
9a47cdb1
BH
90 res = request_mem_region(addr->address, length, desc);
91}
92
93static int __init acpi_reserve_resources(void)
94{
eee3c859 95 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
9a47cdb1
BH
96 "ACPI PM1a_EVT_BLK");
97
eee3c859 98 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
9a47cdb1
BH
99 "ACPI PM1b_EVT_BLK");
100
eee3c859 101 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
9a47cdb1
BH
102 "ACPI PM1a_CNT_BLK");
103
eee3c859 104 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
9a47cdb1
BH
105 "ACPI PM1b_CNT_BLK");
106
eee3c859
LB
107 if (acpi_gbl_FADT.pm_timer_length == 4)
108 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
9a47cdb1 109
eee3c859 110 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
9a47cdb1
BH
111 "ACPI PM2_CNT_BLK");
112
113 /* Length of GPE blocks must be a non-negative multiple of 2 */
114
eee3c859
LB
115 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
116 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
117 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
9a47cdb1 118
eee3c859
LB
119 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
120 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
121 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
9a47cdb1
BH
122
123 return 0;
124}
125device_initcall(acpi_reserve_resources);
126
4be44fcd 127acpi_status acpi_os_initialize(void)
1da177e4
LT
128{
129 return AE_OK;
130}
131
4be44fcd 132acpi_status acpi_os_initialize1(void)
1da177e4
LT
133{
134 /*
135 * Initialize PCI configuration space access, as we'll need to access
136 * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
137 */
1da177e4 138 if (!raw_pci_ops) {
4be44fcd
LB
139 printk(KERN_ERR PREFIX
140 "Access to PCI configuration space unavailable\n");
1da177e4
LT
141 return AE_NULL_ENTRY;
142 }
1da177e4 143 kacpid_wq = create_singlethread_workqueue("kacpid");
88db5e14 144 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
1da177e4 145 BUG_ON(!kacpid_wq);
88db5e14 146 BUG_ON(!kacpi_notify_wq);
1da177e4
LT
147 return AE_OK;
148}
149
4be44fcd 150acpi_status acpi_os_terminate(void)
1da177e4
LT
151{
152 if (acpi_irq_handler) {
153 acpi_os_remove_interrupt_handler(acpi_irq_irq,
154 acpi_irq_handler);
155 }
156
157 destroy_workqueue(kacpid_wq);
88db5e14 158 destroy_workqueue(kacpi_notify_wq);
1da177e4
LT
159
160 return AE_OK;
161}
162
4be44fcd 163void acpi_os_printf(const char *fmt, ...)
1da177e4
LT
164{
165 va_list args;
166 va_start(args, fmt);
167 acpi_os_vprintf(fmt, args);
168 va_end(args);
169}
4be44fcd 170
1da177e4
LT
171EXPORT_SYMBOL(acpi_os_printf);
172
4be44fcd 173void acpi_os_vprintf(const char *fmt, va_list args)
1da177e4
LT
174{
175 static char buffer[512];
4be44fcd 176
1da177e4
LT
177 vsprintf(buffer, fmt, args);
178
179#ifdef ENABLE_DEBUGGER
180 if (acpi_in_debugger) {
181 kdb_printf("%s", buffer);
182 } else {
183 printk("%s", buffer);
184 }
185#else
186 printk("%s", buffer);
187#endif
188}
189
ad71860a 190acpi_physical_address __init acpi_os_get_root_pointer(void)
1da177e4
LT
191{
192 if (efi_enabled) {
b2c99e3c 193 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
ad71860a 194 return efi.acpi20;
b2c99e3c 195 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
ad71860a 196 return efi.acpi;
1da177e4 197 else {
4be44fcd
LB
198 printk(KERN_ERR PREFIX
199 "System description tables not found\n");
ad71860a 200 return 0;
1da177e4 201 }
ad71860a
AS
202 } else
203 return acpi_find_rsdp();
1da177e4
LT
204}
205
ad71860a 206void __iomem *acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
1da177e4 207{
9f4fd61f
BH
208 if (phys > ULONG_MAX) {
209 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
70c0846e 210 return NULL;
1da177e4 211 }
ad71860a
AS
212 if (acpi_gbl_permanent_mmap)
213 /*
214 * ioremap checks to ensure this is in reserved space
215 */
216 return ioremap((unsigned long)phys, size);
217 else
218 return __acpi_map_table((unsigned long)phys, size);
1da177e4 219}
55a82ab3 220EXPORT_SYMBOL_GPL(acpi_os_map_memory);
1da177e4 221
4be44fcd 222void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
1da177e4 223{
ad71860a
AS
224 if (acpi_gbl_permanent_mmap) {
225 iounmap(virt);
226 }
1da177e4 227}
55a82ab3 228EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
1da177e4
LT
229
230#ifdef ACPI_FUTURE_USAGE
231acpi_status
4be44fcd 232acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
1da177e4 233{
4be44fcd 234 if (!phys || !virt)
1da177e4
LT
235 return AE_BAD_PARAMETER;
236
237 *phys = virt_to_phys(virt);
238
239 return AE_OK;
240}
241#endif
242
243#define ACPI_MAX_OVERRIDE_LEN 100
244
245static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
246
247acpi_status
4be44fcd
LB
248acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
249 acpi_string * new_val)
1da177e4
LT
250{
251 if (!init_val || !new_val)
252 return AE_BAD_PARAMETER;
253
254 *new_val = NULL;
4be44fcd 255 if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
1da177e4 256 printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
4be44fcd 257 acpi_os_name);
1da177e4
LT
258 *new_val = acpi_os_name;
259 }
260
261 return AE_OK;
262}
263
264acpi_status
4be44fcd
LB
265acpi_os_table_override(struct acpi_table_header * existing_table,
266 struct acpi_table_header ** new_table)
1da177e4
LT
267{
268 if (!existing_table || !new_table)
269 return AE_BAD_PARAMETER;
270
271#ifdef CONFIG_ACPI_CUSTOM_DSDT
272 if (strncmp(existing_table->signature, "DSDT", 4) == 0)
4be44fcd 273 *new_table = (struct acpi_table_header *)AmlCode;
1da177e4
LT
274 else
275 *new_table = NULL;
276#else
277 *new_table = NULL;
278#endif
279 return AE_OK;
280}
281
7d12e780 282static irqreturn_t acpi_irq(int irq, void *dev_id)
1da177e4 283{
4be44fcd 284 return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE;
1da177e4
LT
285}
286
287acpi_status
4be44fcd
LB
288acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
289 void *context)
1da177e4
LT
290{
291 unsigned int irq;
292
293 /*
294 * Ignore the GSI from the core, and use the value in our copy of the
295 * FADT. It may not be the same if an interrupt source override exists
296 * for the SCI.
297 */
cee324b1 298 gsi = acpi_gbl_FADT.sci_interrupt;
1da177e4
LT
299 if (acpi_gsi_to_irq(gsi, &irq) < 0) {
300 printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
301 gsi);
302 return AE_OK;
303 }
304
305 acpi_irq_handler = handler;
306 acpi_irq_context = context;
dace1453 307 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
1da177e4
LT
308 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
309 return AE_NOT_ACQUIRED;
310 }
311 acpi_irq_irq = irq;
312
313 return AE_OK;
314}
315
4be44fcd 316acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
1da177e4
LT
317{
318 if (irq) {
319 free_irq(irq, acpi_irq);
320 acpi_irq_handler = NULL;
321 acpi_irq_irq = 0;
322 }
323
324 return AE_OK;
325}
326
327/*
328 * Running in interpreter thread context, safe to sleep
329 */
330
4be44fcd 331void acpi_os_sleep(acpi_integer ms)
1da177e4 332{
01a527ec 333 schedule_timeout_interruptible(msecs_to_jiffies(ms));
1da177e4 334}
4be44fcd 335
1da177e4
LT
336EXPORT_SYMBOL(acpi_os_sleep);
337
4be44fcd 338void acpi_os_stall(u32 us)
1da177e4
LT
339{
340 while (us) {
341 u32 delay = 1000;
342
343 if (delay > us)
344 delay = us;
345 udelay(delay);
346 touch_nmi_watchdog();
347 us -= delay;
348 }
349}
4be44fcd 350
1da177e4
LT
351EXPORT_SYMBOL(acpi_os_stall);
352
353/*
354 * Support ACPI 3.0 AML Timer operand
355 * Returns 64-bit free-running, monotonically increasing timer
356 * with 100ns granularity
357 */
4be44fcd 358u64 acpi_os_get_timer(void)
1da177e4
LT
359{
360 static u64 t;
361
362#ifdef CONFIG_HPET
363 /* TBD: use HPET if available */
364#endif
365
366#ifdef CONFIG_X86_PM_TIMER
367 /* TBD: default to PM timer if HPET was not available */
368#endif
369 if (!t)
370 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
371
372 return ++t;
373}
374
4be44fcd 375acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
1da177e4
LT
376{
377 u32 dummy;
378
379 if (!value)
380 value = &dummy;
381
4be44fcd 382 switch (width) {
1da177e4 383 case 8:
4be44fcd 384 *(u8 *) value = inb(port);
1da177e4
LT
385 break;
386 case 16:
4be44fcd 387 *(u16 *) value = inw(port);
1da177e4
LT
388 break;
389 case 32:
4be44fcd 390 *(u32 *) value = inl(port);
1da177e4
LT
391 break;
392 default:
393 BUG();
394 }
395
396 return AE_OK;
397}
4be44fcd 398
1da177e4
LT
399EXPORT_SYMBOL(acpi_os_read_port);
400
4be44fcd 401acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
1da177e4 402{
4be44fcd 403 switch (width) {
1da177e4
LT
404 case 8:
405 outb(value, port);
406 break;
407 case 16:
408 outw(value, port);
409 break;
410 case 32:
411 outl(value, port);
412 break;
413 default:
414 BUG();
415 }
416
417 return AE_OK;
418}
4be44fcd 419
1da177e4
LT
420EXPORT_SYMBOL(acpi_os_write_port);
421
422acpi_status
4be44fcd 423acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
1da177e4 424{
4be44fcd
LB
425 u32 dummy;
426 void __iomem *virt_addr;
1da177e4 427
9f4fd61f 428 virt_addr = ioremap(phys_addr, width);
1da177e4
LT
429 if (!value)
430 value = &dummy;
431
432 switch (width) {
433 case 8:
4be44fcd 434 *(u8 *) value = readb(virt_addr);
1da177e4
LT
435 break;
436 case 16:
4be44fcd 437 *(u16 *) value = readw(virt_addr);
1da177e4
LT
438 break;
439 case 32:
4be44fcd 440 *(u32 *) value = readl(virt_addr);
1da177e4
LT
441 break;
442 default:
443 BUG();
444 }
445
9f4fd61f 446 iounmap(virt_addr);
1da177e4
LT
447
448 return AE_OK;
449}
450
451acpi_status
4be44fcd 452acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
1da177e4 453{
4be44fcd 454 void __iomem *virt_addr;
1da177e4 455
9f4fd61f 456 virt_addr = ioremap(phys_addr, width);
1da177e4
LT
457
458 switch (width) {
459 case 8:
460 writeb(value, virt_addr);
461 break;
462 case 16:
463 writew(value, virt_addr);
464 break;
465 case 32:
466 writel(value, virt_addr);
467 break;
468 default:
469 BUG();
470 }
471
9f4fd61f 472 iounmap(virt_addr);
1da177e4
LT
473
474 return AE_OK;
475}
476
1da177e4 477acpi_status
4be44fcd
LB
478acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
479 void *value, u32 width)
1da177e4
LT
480{
481 int result, size;
482
483 if (!value)
484 return AE_BAD_PARAMETER;
485
486 switch (width) {
487 case 8:
488 size = 1;
489 break;
490 case 16:
491 size = 2;
492 break;
493 case 32:
494 size = 4;
495 break;
496 default:
497 return AE_ERROR;
498 }
499
500 BUG_ON(!raw_pci_ops);
501
502 result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
4be44fcd
LB
503 PCI_DEVFN(pci_id->device, pci_id->function),
504 reg, size, value);
1da177e4
LT
505
506 return (result ? AE_ERROR : AE_OK);
507}
4be44fcd 508
1da177e4
LT
509EXPORT_SYMBOL(acpi_os_read_pci_configuration);
510
511acpi_status
4be44fcd
LB
512acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
513 acpi_integer value, u32 width)
1da177e4
LT
514{
515 int result, size;
516
517 switch (width) {
518 case 8:
519 size = 1;
520 break;
521 case 16:
522 size = 2;
523 break;
524 case 32:
525 size = 4;
526 break;
527 default:
528 return AE_ERROR;
529 }
530
531 BUG_ON(!raw_pci_ops);
532
533 result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
4be44fcd
LB
534 PCI_DEVFN(pci_id->device, pci_id->function),
535 reg, size, value);
1da177e4
LT
536
537 return (result ? AE_ERROR : AE_OK);
538}
539
540/* TODO: Change code to take advantage of driver model more */
4be44fcd
LB
541static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
542 acpi_handle chandle, /* current node */
543 struct acpi_pci_id **id,
544 int *is_bridge, u8 * bus_number)
1da177e4 545{
4be44fcd
LB
546 acpi_handle handle;
547 struct acpi_pci_id *pci_id = *id;
548 acpi_status status;
549 unsigned long temp;
550 acpi_object_type type;
551 u8 tu8;
1da177e4
LT
552
553 acpi_get_parent(chandle, &handle);
554 if (handle != rhandle) {
4be44fcd
LB
555 acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
556 bus_number);
1da177e4
LT
557
558 status = acpi_get_type(handle, &type);
4be44fcd 559 if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
1da177e4
LT
560 return;
561
4be44fcd
LB
562 status =
563 acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
564 &temp);
1da177e4 565 if (ACPI_SUCCESS(status)) {
4be44fcd
LB
566 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
567 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
1da177e4
LT
568
569 if (*is_bridge)
570 pci_id->bus = *bus_number;
571
572 /* any nicer way to get bus number of bridge ? */
4be44fcd
LB
573 status =
574 acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
575 8);
576 if (ACPI_SUCCESS(status)
577 && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
578 status =
579 acpi_os_read_pci_configuration(pci_id, 0x18,
580 &tu8, 8);
1da177e4
LT
581 if (!ACPI_SUCCESS(status)) {
582 /* Certainly broken... FIX ME */
583 return;
584 }
585 *is_bridge = 1;
586 pci_id->bus = tu8;
4be44fcd
LB
587 status =
588 acpi_os_read_pci_configuration(pci_id, 0x19,
589 &tu8, 8);
1da177e4
LT
590 if (ACPI_SUCCESS(status)) {
591 *bus_number = tu8;
592 }
593 } else
594 *is_bridge = 0;
595 }
596 }
597}
598
4be44fcd
LB
599void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
600 acpi_handle chandle, /* current node */
601 struct acpi_pci_id **id)
1da177e4
LT
602{
603 int is_bridge = 1;
604 u8 bus_number = (*id)->bus;
605
606 acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
607}
608
65f27f38 609static void acpi_os_execute_deferred(struct work_struct *work)
88db5e14
AS
610{
611 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
612 if (!dpc) {
613 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
614 return;
615 }
616
617 dpc->function(dpc->context);
618 kfree(dpc);
619
620 /* Yield cpu to notify thread */
621 cond_resched();
622
623 return;
624}
625
626static void acpi_os_execute_notify(struct work_struct *work)
1da177e4 627{
65f27f38 628 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
1da177e4 629
1da177e4 630 if (!dpc) {
6468463a 631 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
d550d98d 632 return;
1da177e4
LT
633 }
634
635 dpc->function(dpc->context);
636
637 kfree(dpc);
638
d550d98d 639 return;
1da177e4
LT
640}
641
b8d35192
AS
642/*******************************************************************************
643 *
644 * FUNCTION: acpi_os_execute
645 *
646 * PARAMETERS: Type - Type of the callback
647 * Function - Function to be executed
648 * Context - Function parameters
649 *
650 * RETURN: Status
651 *
652 * DESCRIPTION: Depending on type, either queues function for deferred execution or
653 * immediately executes function on a separate thread.
654 *
655 ******************************************************************************/
656
657acpi_status acpi_os_execute(acpi_execute_type type,
4be44fcd 658 acpi_osd_exec_callback function, void *context)
1da177e4 659{
4be44fcd
LB
660 acpi_status status = AE_OK;
661 struct acpi_os_dpc *dpc;
72945b2b 662
72945b2b
LB
663 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
664 "Scheduling function [%p(%p)] for deferred execution.\n",
665 function, context));
1da177e4
LT
666
667 if (!function)
88db5e14 668 return AE_BAD_PARAMETER;
72945b2b 669
1da177e4
LT
670 /*
671 * Allocate/initialize DPC structure. Note that this memory will be
65f27f38 672 * freed by the callee. The kernel handles the work_struct list in a
1da177e4
LT
673 * way that allows us to also free its memory inside the callee.
674 * Because we may want to schedule several tasks with different
675 * parameters we can't use the approach some kernel code uses of
65f27f38 676 * having a static work_struct.
1da177e4 677 */
72945b2b 678
65f27f38 679 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
1da177e4 680 if (!dpc)
b976fe19
LT
681 return_ACPI_STATUS(AE_NO_MEMORY);
682
1da177e4
LT
683 dpc->function = function;
684 dpc->context = context;
b976fe19 685
88db5e14
AS
686 if (type == OSL_NOTIFY_HANDLER) {
687 INIT_WORK(&dpc->work, acpi_os_execute_notify);
688 if (!queue_work(kacpi_notify_wq, &dpc->work)) {
689 status = AE_ERROR;
690 kfree(dpc);
691 }
692 } else {
693 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
694 if (!queue_work(kacpid_wq, &dpc->work)) {
695 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
b976fe19 696 "Call to queue_work() failed.\n"));
88db5e14
AS
697 status = AE_ERROR;
698 kfree(dpc);
699 }
1da177e4 700 }
b976fe19 701 return_ACPI_STATUS(status);
1da177e4 702}
4be44fcd 703
b8d35192 704EXPORT_SYMBOL(acpi_os_execute);
1da177e4 705
4be44fcd 706void acpi_os_wait_events_complete(void *context)
1da177e4
LT
707{
708 flush_workqueue(kacpid_wq);
709}
4be44fcd 710
1da177e4
LT
711EXPORT_SYMBOL(acpi_os_wait_events_complete);
712
713/*
714 * Allocate the memory for a spinlock and initialize it.
715 */
967440e3 716acpi_status acpi_os_create_lock(acpi_spinlock * handle)
1da177e4 717{
967440e3 718 spin_lock_init(*handle);
1da177e4 719
d550d98d 720 return AE_OK;
1da177e4
LT
721}
722
1da177e4
LT
723/*
724 * Deallocate the memory for a spinlock.
725 */
967440e3 726void acpi_os_delete_lock(acpi_spinlock handle)
1da177e4 727{
d550d98d 728 return;
1da177e4
LT
729}
730
1da177e4 731acpi_status
4be44fcd 732acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
1da177e4 733{
4be44fcd 734 struct semaphore *sem = NULL;
1da177e4 735
1da177e4
LT
736
737 sem = acpi_os_allocate(sizeof(struct semaphore));
738 if (!sem)
d550d98d 739 return AE_NO_MEMORY;
1da177e4
LT
740 memset(sem, 0, sizeof(struct semaphore));
741
742 sema_init(sem, initial_units);
743
4be44fcd 744 *handle = (acpi_handle *) sem;
1da177e4 745
4be44fcd
LB
746 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
747 *handle, initial_units));
1da177e4 748
d550d98d 749 return AE_OK;
1da177e4 750}
1da177e4 751
4be44fcd 752EXPORT_SYMBOL(acpi_os_create_semaphore);
1da177e4
LT
753
754/*
755 * TODO: A better way to delete semaphores? Linux doesn't have a
756 * 'delete_semaphore()' function -- may result in an invalid
757 * pointer dereference for non-synchronized consumers. Should
758 * we at least check for blocked threads and signal/cancel them?
759 */
760
4be44fcd 761acpi_status acpi_os_delete_semaphore(acpi_handle handle)
1da177e4 762{
4be44fcd 763 struct semaphore *sem = (struct semaphore *)handle;
1da177e4 764
1da177e4
LT
765
766 if (!sem)
d550d98d 767 return AE_BAD_PARAMETER;
1da177e4 768
4be44fcd 769 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
1da177e4 770
02438d87 771 kfree(sem);
4be44fcd 772 sem = NULL;
1da177e4 773
d550d98d 774 return AE_OK;
1da177e4 775}
1da177e4 776
4be44fcd 777EXPORT_SYMBOL(acpi_os_delete_semaphore);
1da177e4
LT
778
779/*
780 * TODO: The kernel doesn't have a 'down_timeout' function -- had to
781 * improvise. The process is to sleep for one scheduler quantum
782 * until the semaphore becomes available. Downside is that this
783 * may result in starvation for timeout-based waits when there's
784 * lots of semaphore activity.
785 *
786 * TODO: Support for units > 1?
787 */
4be44fcd 788acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
1da177e4 789{
4be44fcd
LB
790 acpi_status status = AE_OK;
791 struct semaphore *sem = (struct semaphore *)handle;
792 int ret = 0;
1da177e4 793
1da177e4
LT
794
795 if (!sem || (units < 1))
d550d98d 796 return AE_BAD_PARAMETER;
1da177e4
LT
797
798 if (units > 1)
d550d98d 799 return AE_SUPPORT;
1da177e4 800
4be44fcd
LB
801 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
802 handle, units, timeout));
1da177e4 803
d68909f4
LB
804 /*
805 * This can be called during resume with interrupts off.
806 * Like boot-time, we should be single threaded and will
807 * always get the lock if we try -- timeout or not.
808 * If this doesn't succeed, then we will oops courtesy of
809 * might_sleep() in down().
810 */
811 if (!down_trylock(sem))
812 return AE_OK;
813
4be44fcd 814 switch (timeout) {
1da177e4
LT
815 /*
816 * No Wait:
817 * --------
818 * A zero timeout value indicates that we shouldn't wait - just
819 * acquire the semaphore if available otherwise return AE_TIME
820 * (a.k.a. 'would block').
821 */
4be44fcd
LB
822 case 0:
823 if (down_trylock(sem))
1da177e4
LT
824 status = AE_TIME;
825 break;
826
827 /*
828 * Wait Indefinitely:
829 * ------------------
830 */
4be44fcd 831 case ACPI_WAIT_FOREVER:
1da177e4
LT
832 down(sem);
833 break;
834
835 /*
836 * Wait w/ Timeout:
837 * ----------------
838 */
4be44fcd 839 default:
1da177e4
LT
840 // TODO: A better timeout algorithm?
841 {
842 int i = 0;
4be44fcd 843 static const int quantum_ms = 1000 / HZ;
1da177e4
LT
844
845 ret = down_trylock(sem);
dacd9b80 846 for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
01a527ec 847 schedule_timeout_interruptible(1);
1da177e4
LT
848 ret = down_trylock(sem);
849 }
4be44fcd 850
1da177e4
LT
851 if (ret != 0)
852 status = AE_TIME;
853 }
854 break;
855 }
856
857 if (ACPI_FAILURE(status)) {
9e7e2c04 858 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
a6fc6720 859 "Failed to acquire semaphore[%p|%d|%d], %s",
4be44fcd
LB
860 handle, units, timeout,
861 acpi_format_exception(status)));
862 } else {
863 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
a6fc6720 864 "Acquired semaphore[%p|%d|%d]", handle,
4be44fcd 865 units, timeout));
1da177e4
LT
866 }
867
d550d98d 868 return status;
1da177e4 869}
1da177e4 870
4be44fcd 871EXPORT_SYMBOL(acpi_os_wait_semaphore);
1da177e4
LT
872
873/*
874 * TODO: Support for units > 1?
875 */
4be44fcd 876acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
1da177e4 877{
4be44fcd 878 struct semaphore *sem = (struct semaphore *)handle;
1da177e4 879
1da177e4
LT
880
881 if (!sem || (units < 1))
d550d98d 882 return AE_BAD_PARAMETER;
1da177e4
LT
883
884 if (units > 1)
d550d98d 885 return AE_SUPPORT;
1da177e4 886
4be44fcd
LB
887 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
888 units));
1da177e4
LT
889
890 up(sem);
891
d550d98d 892 return AE_OK;
1da177e4 893}
4be44fcd 894
1da177e4
LT
895EXPORT_SYMBOL(acpi_os_signal_semaphore);
896
897#ifdef ACPI_FUTURE_USAGE
4be44fcd 898u32 acpi_os_get_line(char *buffer)
1da177e4
LT
899{
900
901#ifdef ENABLE_DEBUGGER
902 if (acpi_in_debugger) {
903 u32 chars;
904
905 kdb_read(buffer, sizeof(line_buf));
906
907 /* remove the CR kdb includes */
908 chars = strlen(buffer) - 1;
909 buffer[chars] = '\0';
910 }
911#endif
912
913 return 0;
914}
4be44fcd 915#endif /* ACPI_FUTURE_USAGE */
1da177e4 916
4be44fcd 917acpi_status acpi_os_signal(u32 function, void *info)
1da177e4 918{
4be44fcd 919 switch (function) {
1da177e4
LT
920 case ACPI_SIGNAL_FATAL:
921 printk(KERN_ERR PREFIX "Fatal opcode executed\n");
922 break;
923 case ACPI_SIGNAL_BREAKPOINT:
924 /*
925 * AML Breakpoint
926 * ACPI spec. says to treat it as a NOP unless
927 * you are debugging. So if/when we integrate
928 * AML debugger into the kernel debugger its
929 * hook will go here. But until then it is
930 * not useful to print anything on breakpoints.
931 */
932 break;
933 default:
934 break;
935 }
936
937 return AE_OK;
938}
4be44fcd 939
1da177e4
LT
940EXPORT_SYMBOL(acpi_os_signal);
941
4be44fcd 942static int __init acpi_os_name_setup(char *str)
1da177e4
LT
943{
944 char *p = acpi_os_name;
4be44fcd 945 int count = ACPI_MAX_OVERRIDE_LEN - 1;
1da177e4
LT
946
947 if (!str || !*str)
948 return 0;
949
950 for (; count-- && str && *str; str++) {
951 if (isalnum(*str) || *str == ' ' || *str == ':')
952 *p++ = *str;
953 else if (*str == '\'' || *str == '"')
954 continue;
955 else
956 break;
957 }
958 *p = 0;
959
960 return 1;
4be44fcd 961
1da177e4
LT
962}
963
964__setup("acpi_os_name=", acpi_os_name_setup);
965
966/*
ae00d812
LB
967 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
968 *
1da177e4 969 * empty string disables _OSI
ae00d812
LB
970 * string starting with '!' disables that string
971 * otherwise string is added to list, augmenting built-in strings
1da177e4 972 */
4be44fcd 973static int __init acpi_osi_setup(char *str)
1da177e4
LT
974{
975 if (str == NULL || *str == '\0') {
976 printk(KERN_INFO PREFIX "_OSI method disabled\n");
977 acpi_gbl_create_osi_method = FALSE;
ae00d812
LB
978 } else if (*str == '!') {
979 if (acpi_osi_invalidate(++str) == AE_OK)
980 printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
981 } else if (*osi_additional_string == '\0') {
982 strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
983 printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
1da177e4
LT
984 }
985
986 return 1;
987}
988
989__setup("acpi_osi=", acpi_osi_setup);
990
991/* enable serialization to combat AE_ALREADY_EXISTS errors */
4be44fcd 992static int __init acpi_serialize_setup(char *str)
1da177e4
LT
993{
994 printk(KERN_INFO PREFIX "serialize enabled\n");
995
996 acpi_gbl_all_methods_serialized = TRUE;
997
998 return 1;
999}
1000
1001__setup("acpi_serialize", acpi_serialize_setup);
1002
1003/*
1004 * Wake and Run-Time GPES are expected to be separate.
1005 * We disable wake-GPEs at run-time to prevent spurious
1006 * interrupts.
1007 *
1008 * However, if a system exists that shares Wake and
1009 * Run-time events on the same GPE this flag is available
1010 * to tell Linux to keep the wake-time GPEs enabled at run-time.
1011 */
4be44fcd 1012static int __init acpi_wake_gpes_always_on_setup(char *str)
1da177e4
LT
1013{
1014 printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
1015
1016 acpi_gbl_leave_wake_gpes_disabled = FALSE;
1017
1018 return 1;
1019}
1020
1021__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1022
1023/*
1024 * max_cstate is defined in the base kernel so modules can
1025 * change it w/o depending on the state of the processor module.
1026 */
1027unsigned int max_cstate = ACPI_PROCESSOR_MAX_POWER;
1028
1da177e4 1029EXPORT_SYMBOL(max_cstate);
73459f73
RM
1030
1031/*
1032 * Acquire a spinlock.
1033 *
1034 * handle is a pointer to the spinlock_t.
73459f73
RM
1035 */
1036
967440e3 1037acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
73459f73 1038{
b8e4d893 1039 acpi_cpu_flags flags;
967440e3 1040 spin_lock_irqsave(lockp, flags);
73459f73
RM
1041 return flags;
1042}
1043
1044/*
1045 * Release a spinlock. See above.
1046 */
1047
967440e3 1048void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
73459f73 1049{
967440e3 1050 spin_unlock_irqrestore(lockp, flags);
73459f73
RM
1051}
1052
73459f73
RM
1053#ifndef ACPI_USE_LOCAL_CACHE
1054
1055/*******************************************************************************
1056 *
1057 * FUNCTION: acpi_os_create_cache
1058 *
b229cf92
BM
1059 * PARAMETERS: name - Ascii name for the cache
1060 * size - Size of each cached object
1061 * depth - Maximum depth of the cache (in objects) <ignored>
1062 * cache - Where the new cache object is returned
73459f73 1063 *
b229cf92 1064 * RETURN: status
73459f73
RM
1065 *
1066 * DESCRIPTION: Create a cache object
1067 *
1068 ******************************************************************************/
1069
1070acpi_status
4be44fcd 1071acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
73459f73 1072{
4be44fcd 1073 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
a6fdbf90 1074 if (*cache == NULL)
b229cf92
BM
1075 return AE_ERROR;
1076 else
1077 return AE_OK;
73459f73
RM
1078}
1079
1080/*******************************************************************************
1081 *
1082 * FUNCTION: acpi_os_purge_cache
1083 *
1084 * PARAMETERS: Cache - Handle to cache object
1085 *
1086 * RETURN: Status
1087 *
1088 * DESCRIPTION: Free all objects within the requested cache.
1089 *
1090 ******************************************************************************/
1091
4be44fcd 1092acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
73459f73 1093{
50dd0969 1094 kmem_cache_shrink(cache);
4be44fcd 1095 return (AE_OK);
73459f73
RM
1096}
1097
1098/*******************************************************************************
1099 *
1100 * FUNCTION: acpi_os_delete_cache
1101 *
1102 * PARAMETERS: Cache - Handle to cache object
1103 *
1104 * RETURN: Status
1105 *
1106 * DESCRIPTION: Free all objects within the requested cache and delete the
1107 * cache object.
1108 *
1109 ******************************************************************************/
1110
4be44fcd 1111acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
73459f73 1112{
1a1d92c1 1113 kmem_cache_destroy(cache);
4be44fcd 1114 return (AE_OK);
73459f73
RM
1115}
1116
1117/*******************************************************************************
1118 *
1119 * FUNCTION: acpi_os_release_object
1120 *
1121 * PARAMETERS: Cache - Handle to cache object
1122 * Object - The object to be released
1123 *
1124 * RETURN: None
1125 *
1126 * DESCRIPTION: Release an object to the specified cache. If cache is full,
1127 * the object is deleted.
1128 *
1129 ******************************************************************************/
1130
4be44fcd 1131acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
73459f73 1132{
4be44fcd
LB
1133 kmem_cache_free(cache, object);
1134 return (AE_OK);
73459f73
RM
1135}
1136
b229cf92
BM
1137/******************************************************************************
1138 *
1139 * FUNCTION: acpi_os_validate_interface
1140 *
1141 * PARAMETERS: interface - Requested interface to be validated
1142 *
1143 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1144 *
1145 * DESCRIPTION: Match an interface string to the interfaces supported by the
1146 * host. Strings originate from an AML call to the _OSI method.
1147 *
1148 *****************************************************************************/
1149
1150acpi_status
1151acpi_os_validate_interface (char *interface)
1152{
ae00d812
LB
1153 if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
1154 return AE_OK;
1155 return AE_SUPPORT;
b229cf92
BM
1156}
1157
b229cf92
BM
1158/******************************************************************************
1159 *
1160 * FUNCTION: acpi_os_validate_address
1161 *
1162 * PARAMETERS: space_id - ACPI space ID
1163 * address - Physical address
1164 * length - Address length
1165 *
1166 * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
1167 * should return AE_AML_ILLEGAL_ADDRESS.
1168 *
1169 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1170 * the addresses accessed by AML operation regions.
1171 *
1172 *****************************************************************************/
1173
1174acpi_status
1175acpi_os_validate_address (
1176 u8 space_id,
1177 acpi_physical_address address,
1178 acpi_size length)
1179{
1180
1181 return AE_OK;
1182}
1183
1184
73459f73 1185#endif
This page took 0.333468 seconds and 5 git commands to generate.