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