| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** | 
 | 2 |  * | 
 | 3 |  * Module Name: evxface - External interfaces for ACPI events | 
 | 4 |  * | 
 | 5 |  *****************************************************************************/ | 
 | 6 |  | 
 | 7 | /* | 
| Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 8 |  * Copyright (C) 2000 - 2006, R. Byron Moore | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 |  * All rights reserved. | 
 | 10 |  * | 
 | 11 |  * Redistribution and use in source and binary forms, with or without | 
 | 12 |  * modification, are permitted provided that the following conditions | 
 | 13 |  * are met: | 
 | 14 |  * 1. Redistributions of source code must retain the above copyright | 
 | 15 |  *    notice, this list of conditions, and the following disclaimer, | 
 | 16 |  *    without modification. | 
 | 17 |  * 2. Redistributions in binary form must reproduce at minimum a disclaimer | 
 | 18 |  *    substantially similar to the "NO WARRANTY" disclaimer below | 
 | 19 |  *    ("Disclaimer") and any redistribution must be conditioned upon | 
 | 20 |  *    including a substantially similar Disclaimer requirement for further | 
 | 21 |  *    binary redistribution. | 
 | 22 |  * 3. Neither the names of the above-listed copyright holders nor the names | 
 | 23 |  *    of any contributors may be used to endorse or promote products derived | 
 | 24 |  *    from this software without specific prior written permission. | 
 | 25 |  * | 
 | 26 |  * Alternatively, this software may be distributed under the terms of the | 
 | 27 |  * GNU General Public License ("GPL") version 2 as published by the Free | 
 | 28 |  * Software Foundation. | 
 | 29 |  * | 
 | 30 |  * NO WARRANTY | 
 | 31 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
 | 32 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
 | 33 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | 
 | 34 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
 | 35 |  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
 | 36 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 
 | 37 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 
 | 38 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 
 | 39 |  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | 
 | 40 |  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 
 | 41 |  * POSSIBILITY OF SUCH DAMAGES. | 
 | 42 |  */ | 
 | 43 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> | 
 | 45 | #include <acpi/acnamesp.h> | 
 | 46 | #include <acpi/acevents.h> | 
 | 47 | #include <acpi/acinterp.h> | 
 | 48 |  | 
 | 49 | #define _COMPONENT          ACPI_EVENTS | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("evxface") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 |  | 
 | 52 | /******************************************************************************* | 
 | 53 |  * | 
 | 54 |  * FUNCTION:    acpi_install_exception_handler | 
 | 55 |  * | 
 | 56 |  * PARAMETERS:  Handler         - Pointer to the handler function for the | 
 | 57 |  *                                event | 
 | 58 |  * | 
 | 59 |  * RETURN:      Status | 
 | 60 |  * | 
 | 61 |  * DESCRIPTION: Saves the pointer to the handler function | 
 | 62 |  * | 
 | 63 |  ******************************************************************************/ | 
 | 64 | #ifdef ACPI_FUTURE_USAGE | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 65 | acpi_status acpi_install_exception_handler(acpi_exception_handler handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 67 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 69 | 	ACPI_FUNCTION_TRACE(acpi_install_exception_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 71 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | 
 | 72 | 	if (ACPI_FAILURE(status)) { | 
 | 73 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | 	} | 
 | 75 |  | 
 | 76 | 	/* Don't allow two handlers. */ | 
 | 77 |  | 
 | 78 | 	if (acpi_gbl_exception_handler) { | 
 | 79 | 		status = AE_ALREADY_EXISTS; | 
 | 80 | 		goto cleanup; | 
 | 81 | 	} | 
 | 82 |  | 
 | 83 | 	/* Install the handler */ | 
 | 84 |  | 
 | 85 | 	acpi_gbl_exception_handler = handler; | 
 | 86 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 |       cleanup: | 
 | 88 | 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | 
 | 89 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 91 |  | 
 | 92 | ACPI_EXPORT_SYMBOL(acpi_install_exception_handler) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | #endif				/*  ACPI_FUTURE_USAGE  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 |  | 
 | 95 | /******************************************************************************* | 
 | 96 |  * | 
 | 97 |  * FUNCTION:    acpi_install_fixed_event_handler | 
 | 98 |  * | 
 | 99 |  * PARAMETERS:  Event           - Event type to enable. | 
 | 100 |  *              Handler         - Pointer to the handler function for the | 
 | 101 |  *                                event | 
 | 102 |  *              Context         - Value passed to the handler on each GPE | 
 | 103 |  * | 
 | 104 |  * RETURN:      Status | 
 | 105 |  * | 
 | 106 |  * DESCRIPTION: Saves the pointer to the handler function and then enables the | 
 | 107 |  *              event. | 
 | 108 |  * | 
 | 109 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | acpi_install_fixed_event_handler(u32 event, | 
 | 112 | 				 acpi_event_handler handler, void *context) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 114 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 116 | 	ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 |  | 
 | 118 | 	/* Parameter validation */ | 
 | 119 |  | 
 | 120 | 	if (event > ACPI_EVENT_MAX) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 121 | 		return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | 	} | 
 | 123 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 124 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | 
 | 125 | 	if (ACPI_FAILURE(status)) { | 
 | 126 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | 	} | 
 | 128 |  | 
 | 129 | 	/* Don't allow two handlers. */ | 
 | 130 |  | 
 | 131 | 	if (NULL != acpi_gbl_fixed_event_handlers[event].handler) { | 
 | 132 | 		status = AE_ALREADY_EXISTS; | 
 | 133 | 		goto cleanup; | 
 | 134 | 	} | 
 | 135 |  | 
 | 136 | 	/* Install the handler before enabling the event */ | 
 | 137 |  | 
 | 138 | 	acpi_gbl_fixed_event_handlers[event].handler = handler; | 
 | 139 | 	acpi_gbl_fixed_event_handlers[event].context = context; | 
 | 140 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | 	status = acpi_clear_event(event); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | 	if (ACPI_SUCCESS(status)) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | 		status = acpi_enable_event(event, 0); | 
 | 144 | 	if (ACPI_FAILURE(status)) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 145 | 		ACPI_WARNING((AE_INFO, "Could not enable fixed event %X", | 
 | 146 | 			      event)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 |  | 
 | 148 | 		/* Remove the handler */ | 
 | 149 |  | 
 | 150 | 		acpi_gbl_fixed_event_handlers[event].handler = NULL; | 
 | 151 | 		acpi_gbl_fixed_event_handlers[event].context = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 152 | 	} else { | 
 | 153 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 154 | 				  "Enabled fixed event %X, Handler=%p\n", event, | 
 | 155 | 				  handler)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | 	} | 
 | 157 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 158 |       cleanup: | 
 | 159 | 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | 
 | 160 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 163 | ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 |  | 
 | 165 | /******************************************************************************* | 
 | 166 |  * | 
 | 167 |  * FUNCTION:    acpi_remove_fixed_event_handler | 
 | 168 |  * | 
 | 169 |  * PARAMETERS:  Event           - Event type to disable. | 
 | 170 |  *              Handler         - Address of the handler | 
 | 171 |  * | 
 | 172 |  * RETURN:      Status | 
 | 173 |  * | 
 | 174 |  * DESCRIPTION: Disables the event and unregisters the event handler. | 
 | 175 |  * | 
 | 176 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 178 | acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 180 | 	acpi_status status = AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 182 | 	ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 |  | 
 | 184 | 	/* Parameter validation */ | 
 | 185 |  | 
 | 186 | 	if (event > ACPI_EVENT_MAX) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 187 | 		return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | 	} | 
 | 189 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 190 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | 
 | 191 | 	if (ACPI_FAILURE(status)) { | 
 | 192 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | 	} | 
 | 194 |  | 
 | 195 | 	/* Disable the event before removing the handler */ | 
 | 196 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 197 | 	status = acpi_disable_event(event, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 |  | 
 | 199 | 	/* Always Remove the handler */ | 
 | 200 |  | 
 | 201 | 	acpi_gbl_fixed_event_handlers[event].handler = NULL; | 
 | 202 | 	acpi_gbl_fixed_event_handlers[event].context = NULL; | 
 | 203 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | 	if (ACPI_FAILURE(status)) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 205 | 		ACPI_WARNING((AE_INFO, | 
 | 206 | 			      "Could not write to fixed event enable register %X", | 
 | 207 | 			      event)); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | 	} else { | 
| Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 209 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Disabled fixed event %X\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 210 | 				  event)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | 	} | 
 | 212 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | 
 | 214 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 217 | ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 |  | 
 | 219 | /******************************************************************************* | 
 | 220 |  * | 
 | 221 |  * FUNCTION:    acpi_install_notify_handler | 
 | 222 |  * | 
 | 223 |  * PARAMETERS:  Device          - The device for which notifies will be handled | 
 | 224 |  *              handler_type    - The type of handler: | 
 | 225 |  *                                  ACPI_SYSTEM_NOTIFY: system_handler (00-7f) | 
 | 226 |  *                                  ACPI_DEVICE_NOTIFY: driver_handler (80-ff) | 
 | 227 |  *                                  ACPI_ALL_NOTIFY:  both system and device | 
 | 228 |  *              Handler         - Address of the handler | 
 | 229 |  *              Context         - Value passed to the handler on each GPE | 
 | 230 |  * | 
 | 231 |  * RETURN:      Status | 
 | 232 |  * | 
 | 233 |  * DESCRIPTION: Install a handler for notifies on an ACPI device | 
 | 234 |  * | 
 | 235 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 237 | acpi_install_notify_handler(acpi_handle device, | 
 | 238 | 			    u32 handler_type, | 
 | 239 | 			    acpi_notify_handler handler, void *context) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 241 | 	union acpi_operand_object *obj_desc; | 
 | 242 | 	union acpi_operand_object *notify_obj; | 
 | 243 | 	struct acpi_namespace_node *node; | 
 | 244 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 246 | 	ACPI_FUNCTION_TRACE(acpi_install_notify_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 |  | 
 | 248 | 	/* Parameter validation */ | 
 | 249 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | 	if ((!device) || | 
 | 251 | 	    (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { | 
 | 252 | 		return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | 	} | 
 | 254 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 255 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 256 | 	if (ACPI_FAILURE(status)) { | 
 | 257 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | 	} | 
 | 259 |  | 
 | 260 | 	/* Convert and validate the device handle */ | 
 | 261 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 262 | 	node = acpi_ns_map_handle_to_node(device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | 	if (!node) { | 
 | 264 | 		status = AE_BAD_PARAMETER; | 
 | 265 | 		goto unlock_and_exit; | 
 | 266 | 	} | 
 | 267 |  | 
 | 268 | 	/* | 
 | 269 | 	 * Root Object: | 
 | 270 | 	 * Registering a notify handler on the root object indicates that the | 
 | 271 | 	 * caller wishes to receive notifications for all objects.  Note that | 
 | 272 | 	 * only one <external> global handler can be regsitered (per notify type). | 
 | 273 | 	 */ | 
 | 274 | 	if (device == ACPI_ROOT_OBJECT) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 275 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | 		/* Make sure the handler is not already installed */ | 
 | 277 |  | 
 | 278 | 		if (((handler_type & ACPI_SYSTEM_NOTIFY) && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 279 | 		     acpi_gbl_system_notify.handler) || | 
 | 280 | 		    ((handler_type & ACPI_DEVICE_NOTIFY) && | 
 | 281 | 		     acpi_gbl_device_notify.handler)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | 			status = AE_ALREADY_EXISTS; | 
 | 283 | 			goto unlock_and_exit; | 
 | 284 | 		} | 
 | 285 |  | 
 | 286 | 		if (handler_type & ACPI_SYSTEM_NOTIFY) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 287 | 			acpi_gbl_system_notify.node = node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | 			acpi_gbl_system_notify.handler = handler; | 
 | 289 | 			acpi_gbl_system_notify.context = context; | 
 | 290 | 		} | 
 | 291 |  | 
 | 292 | 		if (handler_type & ACPI_DEVICE_NOTIFY) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | 			acpi_gbl_device_notify.node = node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | 			acpi_gbl_device_notify.handler = handler; | 
 | 295 | 			acpi_gbl_device_notify.context = context; | 
 | 296 | 		} | 
 | 297 |  | 
 | 298 | 		/* Global notify handler installed */ | 
 | 299 | 	} | 
 | 300 |  | 
 | 301 | 	/* | 
 | 302 | 	 * All Other Objects: | 
 | 303 | 	 * Caller will only receive notifications specific to the target object. | 
 | 304 | 	 * Note that only certain object types can receive notifications. | 
 | 305 | 	 */ | 
 | 306 | 	else { | 
 | 307 | 		/* Notifies allowed on this object? */ | 
 | 308 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 309 | 		if (!acpi_ev_is_notify_object(node)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | 			status = AE_TYPE; | 
 | 311 | 			goto unlock_and_exit; | 
 | 312 | 		} | 
 | 313 |  | 
 | 314 | 		/* Check for an existing internal object */ | 
 | 315 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 316 | 		obj_desc = acpi_ns_get_attached_object(node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | 		if (obj_desc) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 318 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | 			/* Object exists - make sure there's no handler */ | 
 | 320 |  | 
 | 321 | 			if (((handler_type & ACPI_SYSTEM_NOTIFY) && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | 			     obj_desc->common_notify.system_notify) || | 
 | 323 | 			    ((handler_type & ACPI_DEVICE_NOTIFY) && | 
 | 324 | 			     obj_desc->common_notify.device_notify)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | 				status = AE_ALREADY_EXISTS; | 
 | 326 | 				goto unlock_and_exit; | 
 | 327 | 			} | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 328 | 		} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | 			/* Create a new object */ | 
 | 330 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 331 | 			obj_desc = acpi_ut_create_internal_object(node->type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | 			if (!obj_desc) { | 
 | 333 | 				status = AE_NO_MEMORY; | 
 | 334 | 				goto unlock_and_exit; | 
 | 335 | 			} | 
 | 336 |  | 
 | 337 | 			/* Attach new object to the Node */ | 
 | 338 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 339 | 			status = | 
 | 340 | 			    acpi_ns_attach_object(device, obj_desc, node->type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 |  | 
 | 342 | 			/* Remove local reference to the object */ | 
 | 343 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 344 | 			acpi_ut_remove_reference(obj_desc); | 
 | 345 | 			if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | 				goto unlock_and_exit; | 
 | 347 | 			} | 
 | 348 | 		} | 
 | 349 |  | 
 | 350 | 		/* Install the handler */ | 
 | 351 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 352 | 		notify_obj = | 
 | 353 | 		    acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | 		if (!notify_obj) { | 
 | 355 | 			status = AE_NO_MEMORY; | 
 | 356 | 			goto unlock_and_exit; | 
 | 357 | 		} | 
 | 358 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 359 | 		notify_obj->notify.node = node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | 		notify_obj->notify.handler = handler; | 
 | 361 | 		notify_obj->notify.context = context; | 
 | 362 |  | 
 | 363 | 		if (handler_type & ACPI_SYSTEM_NOTIFY) { | 
 | 364 | 			obj_desc->common_notify.system_notify = notify_obj; | 
 | 365 | 		} | 
 | 366 |  | 
 | 367 | 		if (handler_type & ACPI_DEVICE_NOTIFY) { | 
 | 368 | 			obj_desc->common_notify.device_notify = notify_obj; | 
 | 369 | 		} | 
 | 370 |  | 
 | 371 | 		if (handler_type == ACPI_ALL_NOTIFY) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 372 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | 			/* Extra ref if installed in both */ | 
 | 374 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 375 | 			acpi_ut_add_reference(notify_obj); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | 		} | 
 | 377 | 	} | 
 | 378 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 379 |       unlock_and_exit: | 
 | 380 | 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
 | 381 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 384 | ACPI_EXPORT_SYMBOL(acpi_install_notify_handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 |  | 
 | 386 | /******************************************************************************* | 
 | 387 |  * | 
 | 388 |  * FUNCTION:    acpi_remove_notify_handler | 
 | 389 |  * | 
 | 390 |  * PARAMETERS:  Device          - The device for which notifies will be handled | 
 | 391 |  *              handler_type    - The type of handler: | 
 | 392 |  *                                  ACPI_SYSTEM_NOTIFY: system_handler (00-7f) | 
 | 393 |  *                                  ACPI_DEVICE_NOTIFY: driver_handler (80-ff) | 
 | 394 |  *                                  ACPI_ALL_NOTIFY:  both system and device | 
 | 395 |  *              Handler         - Address of the handler | 
 | 396 |  * | 
 | 397 |  * RETURN:      Status | 
 | 398 |  * | 
 | 399 |  * DESCRIPTION: Remove a handler for notifies on an ACPI device | 
 | 400 |  * | 
 | 401 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 403 | acpi_remove_notify_handler(acpi_handle device, | 
 | 404 | 			   u32 handler_type, acpi_notify_handler handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | 	union acpi_operand_object *notify_obj; | 
 | 407 | 	union acpi_operand_object *obj_desc; | 
 | 408 | 	struct acpi_namespace_node *node; | 
 | 409 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 411 | 	ACPI_FUNCTION_TRACE(acpi_remove_notify_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 |  | 
 | 413 | 	/* Parameter validation */ | 
 | 414 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 415 | 	if ((!device) || | 
 | 416 | 	    (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 417 | 		status = AE_BAD_PARAMETER; | 
 | 418 | 		goto exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | 	} | 
 | 420 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 421 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 422 | 	if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 423 | 		goto exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | 	} | 
 | 425 |  | 
 | 426 | 	/* Convert and validate the device handle */ | 
 | 427 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 428 | 	node = acpi_ns_map_handle_to_node(device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | 	if (!node) { | 
 | 430 | 		status = AE_BAD_PARAMETER; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 431 | 		goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | 	} | 
 | 433 |  | 
 | 434 | 	/* Root Object */ | 
 | 435 |  | 
 | 436 | 	if (device == ACPI_ROOT_OBJECT) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 437 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 438 | 				  "Removing notify handler for namespace root object\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 |  | 
 | 440 | 		if (((handler_type & ACPI_SYSTEM_NOTIFY) && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 441 | 		     !acpi_gbl_system_notify.handler) || | 
 | 442 | 		    ((handler_type & ACPI_DEVICE_NOTIFY) && | 
 | 443 | 		     !acpi_gbl_device_notify.handler)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | 			status = AE_NOT_EXIST; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 445 | 			goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | 		} | 
 | 447 |  | 
 | 448 | 		/* Make sure all deferred tasks are completed */ | 
 | 449 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | 		(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | 		acpi_os_wait_events_complete(NULL); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 452 | 		status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 453 | 		if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 454 | 			goto exit; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 455 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 |  | 
 | 457 | 		if (handler_type & ACPI_SYSTEM_NOTIFY) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 458 | 			acpi_gbl_system_notify.node = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | 			acpi_gbl_system_notify.handler = NULL; | 
 | 460 | 			acpi_gbl_system_notify.context = NULL; | 
 | 461 | 		} | 
 | 462 |  | 
 | 463 | 		if (handler_type & ACPI_DEVICE_NOTIFY) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 464 | 			acpi_gbl_device_notify.node = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | 			acpi_gbl_device_notify.handler = NULL; | 
 | 466 | 			acpi_gbl_device_notify.context = NULL; | 
 | 467 | 		} | 
 | 468 | 	} | 
 | 469 |  | 
 | 470 | 	/* All Other Objects */ | 
 | 471 |  | 
 | 472 | 	else { | 
 | 473 | 		/* Notifies allowed on this object? */ | 
 | 474 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 475 | 		if (!acpi_ev_is_notify_object(node)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | 			status = AE_TYPE; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 477 | 			goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | 		} | 
 | 479 |  | 
 | 480 | 		/* Check for an existing internal object */ | 
 | 481 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 482 | 		obj_desc = acpi_ns_get_attached_object(node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | 		if (!obj_desc) { | 
 | 484 | 			status = AE_NOT_EXIST; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 485 | 			goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | 		} | 
 | 487 |  | 
 | 488 | 		/* Object exists - make sure there's an existing handler */ | 
 | 489 |  | 
 | 490 | 		if (handler_type & ACPI_SYSTEM_NOTIFY) { | 
 | 491 | 			notify_obj = obj_desc->common_notify.system_notify; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 492 | 			if (!notify_obj) { | 
 | 493 | 				status = AE_NOT_EXIST; | 
 | 494 | 				goto unlock_and_exit; | 
 | 495 | 			} | 
 | 496 |  | 
 | 497 | 			if (notify_obj->notify.handler != handler) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | 				status = AE_BAD_PARAMETER; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 499 | 				goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | 			} | 
 | 501 | 			/* Make sure all deferred tasks are completed */ | 
 | 502 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 503 | 			(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | 			acpi_os_wait_events_complete(NULL); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 505 | 			status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 506 | 			if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 507 | 				goto exit; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 508 | 			} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 |  | 
 | 510 | 			/* Remove the handler */ | 
 | 511 | 			obj_desc->common_notify.system_notify = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 512 | 			acpi_ut_remove_reference(notify_obj); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | 		} | 
 | 514 |  | 
 | 515 | 		if (handler_type & ACPI_DEVICE_NOTIFY) { | 
 | 516 | 			notify_obj = obj_desc->common_notify.device_notify; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 517 | 			if (!notify_obj) { | 
 | 518 | 				status = AE_NOT_EXIST; | 
 | 519 | 				goto unlock_and_exit; | 
 | 520 | 			} | 
 | 521 |  | 
 | 522 | 			if (notify_obj->notify.handler != handler) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | 				status = AE_BAD_PARAMETER; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 524 | 				goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | 			} | 
 | 526 | 			/* Make sure all deferred tasks are completed */ | 
 | 527 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 528 | 			(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | 			acpi_os_wait_events_complete(NULL); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 530 | 			status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 531 | 			if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 532 | 				goto exit; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 533 | 			} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 |  | 
 | 535 | 			/* Remove the handler */ | 
 | 536 | 			obj_desc->common_notify.device_notify = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 537 | 			acpi_ut_remove_reference(notify_obj); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | 		} | 
 | 539 | 	} | 
 | 540 |  | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 541 |       unlock_and_exit: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 542 | 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 543 |       exit: | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 544 | 	if (ACPI_FAILURE(status)) | 
 | 545 | 		ACPI_EXCEPTION((AE_INFO, status, "Removing notify handler")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 546 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 549 | ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 |  | 
 | 551 | /******************************************************************************* | 
 | 552 |  * | 
 | 553 |  * FUNCTION:    acpi_install_gpe_handler | 
 | 554 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 555 |  * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for FADT | 
 | 556 |  *                                defined GPEs) | 
 | 557 |  *              gpe_number      - The GPE number within the GPE block | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 |  *              Type            - Whether this GPE should be treated as an | 
 | 559 |  *                                edge- or level-triggered interrupt. | 
 | 560 |  *              Address         - Address of the handler | 
 | 561 |  *              Context         - Value passed to the handler on each GPE | 
 | 562 |  * | 
 | 563 |  * RETURN:      Status | 
 | 564 |  * | 
 | 565 |  * DESCRIPTION: Install a handler for a General Purpose Event. | 
 | 566 |  * | 
 | 567 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 569 | acpi_install_gpe_handler(acpi_handle gpe_device, | 
 | 570 | 			 u32 gpe_number, | 
 | 571 | 			 u32 type, acpi_event_handler address, void *context) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 573 | 	struct acpi_gpe_event_info *gpe_event_info; | 
 | 574 | 	struct acpi_handler_info *handler; | 
 | 575 | 	acpi_status status; | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 576 | 	acpi_cpu_flags flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 578 | 	ACPI_FUNCTION_TRACE(acpi_install_gpe_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 |  | 
 | 580 | 	/* Parameter validation */ | 
 | 581 |  | 
 | 582 | 	if ((!address) || (type > ACPI_GPE_XRUPT_TYPE_MASK)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 583 | 		status = AE_BAD_PARAMETER; | 
 | 584 | 		goto exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | 	} | 
 | 586 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 587 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | 
 | 588 | 	if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 589 | 		goto exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | 	} | 
 | 591 |  | 
 | 592 | 	/* Ensure that we have a valid GPE number */ | 
 | 593 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 594 | 	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | 	if (!gpe_event_info) { | 
 | 596 | 		status = AE_BAD_PARAMETER; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 597 | 		goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | 	} | 
 | 599 |  | 
 | 600 | 	/* Make sure that there isn't a handler there already */ | 
 | 601 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 602 | 	if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == | 
 | 603 | 	    ACPI_GPE_DISPATCH_HANDLER) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | 		status = AE_ALREADY_EXISTS; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 605 | 		goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | 	} | 
 | 607 |  | 
 | 608 | 	/* Allocate and init handler object */ | 
 | 609 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 610 | 	handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_handler_info)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | 	if (!handler) { | 
 | 612 | 		status = AE_NO_MEMORY; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 613 | 		goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | 	} | 
 | 615 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 616 | 	handler->address = address; | 
 | 617 | 	handler->context = context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | 	handler->method_node = gpe_event_info->dispatch.method_node; | 
 | 619 |  | 
 | 620 | 	/* Disable the GPE before installing the handler */ | 
 | 621 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 622 | 	status = acpi_ev_disable_gpe(gpe_event_info); | 
 | 623 | 	if (ACPI_FAILURE(status)) { | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 624 | 		goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | 	} | 
 | 626 |  | 
 | 627 | 	/* Install the handler */ | 
 | 628 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 629 | 	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | 	gpe_event_info->dispatch.handler = handler; | 
 | 631 |  | 
 | 632 | 	/* Setup up dispatch flags to indicate handler (vs. method) */ | 
 | 633 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 634 | 	gpe_event_info->flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);	/* Clear bits */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | 	gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER); | 
 | 636 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 637 | 	acpi_os_release_lock(acpi_gbl_gpe_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 |  | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 639 |       unlock_and_exit: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 640 | 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 641 |       exit: | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 642 | 	if (ACPI_FAILURE(status)) | 
 | 643 | 		ACPI_EXCEPTION((AE_INFO, status, | 
 | 644 | 				"Installing notify handler failed")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 645 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 648 | ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 |  | 
 | 650 | /******************************************************************************* | 
 | 651 |  * | 
 | 652 |  * FUNCTION:    acpi_remove_gpe_handler | 
 | 653 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 654 |  * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for FADT | 
 | 655 |  *                                defined GPEs) | 
 | 656 |  *              gpe_number      - The event to remove a handler | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 |  *              Address         - Address of the handler | 
 | 658 |  * | 
 | 659 |  * RETURN:      Status | 
 | 660 |  * | 
 | 661 |  * DESCRIPTION: Remove a handler for a General Purpose acpi_event. | 
 | 662 |  * | 
 | 663 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 665 | acpi_remove_gpe_handler(acpi_handle gpe_device, | 
 | 666 | 			u32 gpe_number, acpi_event_handler address) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 668 | 	struct acpi_gpe_event_info *gpe_event_info; | 
 | 669 | 	struct acpi_handler_info *handler; | 
 | 670 | 	acpi_status status; | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 671 | 	acpi_cpu_flags flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 673 | 	ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 |  | 
 | 675 | 	/* Parameter validation */ | 
 | 676 |  | 
 | 677 | 	if (!address) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 678 | 		return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | 	} | 
 | 680 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 681 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | 
 | 682 | 	if (ACPI_FAILURE(status)) { | 
 | 683 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | 	} | 
 | 685 |  | 
 | 686 | 	/* Ensure that we have a valid GPE number */ | 
 | 687 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 688 | 	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | 	if (!gpe_event_info) { | 
 | 690 | 		status = AE_BAD_PARAMETER; | 
 | 691 | 		goto unlock_and_exit; | 
 | 692 | 	} | 
 | 693 |  | 
 | 694 | 	/* Make sure that a handler is indeed installed */ | 
 | 695 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 696 | 	if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) != | 
 | 697 | 	    ACPI_GPE_DISPATCH_HANDLER) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | 		status = AE_NOT_EXIST; | 
 | 699 | 		goto unlock_and_exit; | 
 | 700 | 	} | 
 | 701 |  | 
 | 702 | 	/* Make sure that the installed handler is the same */ | 
 | 703 |  | 
 | 704 | 	if (gpe_event_info->dispatch.handler->address != address) { | 
 | 705 | 		status = AE_BAD_PARAMETER; | 
 | 706 | 		goto unlock_and_exit; | 
 | 707 | 	} | 
 | 708 |  | 
 | 709 | 	/* Disable the GPE before removing the handler */ | 
 | 710 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 711 | 	status = acpi_ev_disable_gpe(gpe_event_info); | 
 | 712 | 	if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | 		goto unlock_and_exit; | 
 | 714 | 	} | 
 | 715 |  | 
 | 716 | 	/* Make sure all deferred tasks are completed */ | 
 | 717 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 718 | 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | 	acpi_os_wait_events_complete(NULL); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 720 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | 
 | 721 | 	if (ACPI_FAILURE(status)) { | 
 | 722 | 		return_ACPI_STATUS(status); | 
 | 723 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 |  | 
 | 725 | 	/* Remove the handler */ | 
 | 726 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 727 | 	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | 	handler = gpe_event_info->dispatch.handler; | 
 | 729 |  | 
 | 730 | 	/* Restore Method node (if any), set dispatch flags */ | 
 | 731 |  | 
 | 732 | 	gpe_event_info->dispatch.method_node = handler->method_node; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 733 | 	gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK;	/* Clear bits */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | 	if (handler->method_node) { | 
 | 735 | 		gpe_event_info->flags |= ACPI_GPE_DISPATCH_METHOD; | 
 | 736 | 	} | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 737 | 	acpi_os_release_lock(acpi_gbl_gpe_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 |  | 
 | 739 | 	/* Now we can free the handler object */ | 
 | 740 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 741 | 	ACPI_FREE(handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 743 |       unlock_and_exit: | 
 | 744 | 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | 
 | 745 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 748 | ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 |  | 
 | 750 | /******************************************************************************* | 
 | 751 |  * | 
 | 752 |  * FUNCTION:    acpi_acquire_global_lock | 
 | 753 |  * | 
 | 754 |  * PARAMETERS:  Timeout         - How long the caller is willing to wait | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 755 |  *              Handle          - Where the handle to the lock is returned | 
 | 756 |  *                                (if acquired) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 |  * | 
 | 758 |  * RETURN:      Status | 
 | 759 |  * | 
 | 760 |  * DESCRIPTION: Acquire the ACPI Global Lock | 
 | 761 |  * | 
 | 762 |  ******************************************************************************/ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 763 | acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 765 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 |  | 
 | 767 | 	if (!handle) { | 
 | 768 | 		return (AE_BAD_PARAMETER); | 
 | 769 | 	} | 
 | 770 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 771 | 	status = acpi_ex_enter_interpreter(); | 
 | 772 | 	if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | 		return (status); | 
 | 774 | 	} | 
 | 775 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 776 | 	status = acpi_ev_acquire_global_lock(timeout); | 
 | 777 | 	acpi_ex_exit_interpreter(); | 
| 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 | 	if (ACPI_SUCCESS(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | 		acpi_gbl_global_lock_handle++; | 
 | 781 | 		*handle = acpi_gbl_global_lock_handle; | 
 | 782 | 	} | 
 | 783 |  | 
 | 784 | 	return (status); | 
 | 785 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 787 | ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 |  | 
 | 789 | /******************************************************************************* | 
 | 790 |  * | 
 | 791 |  * FUNCTION:    acpi_release_global_lock | 
 | 792 |  * | 
 | 793 |  * PARAMETERS:  Handle      - Returned from acpi_acquire_global_lock | 
 | 794 |  * | 
 | 795 |  * RETURN:      Status | 
 | 796 |  * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 797 |  * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 |  * | 
 | 799 |  ******************************************************************************/ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 800 | acpi_status acpi_release_global_lock(u32 handle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 802 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 |  | 
 | 804 | 	if (handle != acpi_gbl_global_lock_handle) { | 
 | 805 | 		return (AE_NOT_ACQUIRED); | 
 | 806 | 	} | 
 | 807 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 808 | 	status = acpi_ev_release_global_lock(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | 	return (status); | 
 | 810 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 812 | ACPI_EXPORT_SYMBOL(acpi_release_global_lock) |