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