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