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