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