Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: evxface - External interfaces for ACPI events | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
4a90c7e8 | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
1da177e4 LT |
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 | ||
1da177e4 LT |
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 | |
4be44fcd | 50 | ACPI_MODULE_NAME("evxface") |
1da177e4 LT |
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 | |
4be44fcd | 65 | acpi_status acpi_install_exception_handler(acpi_exception_handler handler) |
1da177e4 | 66 | { |
4be44fcd | 67 | acpi_status status; |
1da177e4 | 68 | |
b229cf92 | 69 | ACPI_FUNCTION_TRACE(acpi_install_exception_handler); |
1da177e4 | 70 | |
4be44fcd LB |
71 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
72 | if (ACPI_FAILURE(status)) { | |
73 | return_ACPI_STATUS(status); | |
1da177e4 LT |
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 | ||
4be44fcd LB |
87 | cleanup: |
88 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | |
89 | return_ACPI_STATUS(status); | |
1da177e4 | 90 | } |
8313524a BM |
91 | |
92 | ACPI_EXPORT_SYMBOL(acpi_install_exception_handler) | |
4be44fcd | 93 | #endif /* ACPI_FUTURE_USAGE */ |
1da177e4 LT |
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 | ******************************************************************************/ | |
1da177e4 | 110 | acpi_status |
4be44fcd LB |
111 | acpi_install_fixed_event_handler(u32 event, |
112 | acpi_event_handler handler, void *context) | |
1da177e4 | 113 | { |
4be44fcd | 114 | acpi_status status; |
1da177e4 | 115 | |
b229cf92 | 116 | ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler); |
1da177e4 LT |
117 | |
118 | /* Parameter validation */ | |
119 | ||
120 | if (event > ACPI_EVENT_MAX) { | |
4be44fcd | 121 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
122 | } |
123 | ||
4be44fcd LB |
124 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
125 | if (ACPI_FAILURE(status)) { | |
126 | return_ACPI_STATUS(status); | |
1da177e4 LT |
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 | ||
4be44fcd | 141 | status = acpi_clear_event(event); |
1da177e4 | 142 | if (ACPI_SUCCESS(status)) |
4be44fcd LB |
143 | status = acpi_enable_event(event, 0); |
144 | if (ACPI_FAILURE(status)) { | |
b8e4d893 BM |
145 | ACPI_WARNING((AE_INFO, "Could not enable fixed event %X", |
146 | event)); | |
1da177e4 LT |
147 | |
148 | /* Remove the handler */ | |
149 | ||
150 | acpi_gbl_fixed_event_handlers[event].handler = NULL; | |
151 | acpi_gbl_fixed_event_handlers[event].context = NULL; | |
4be44fcd LB |
152 | } else { |
153 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
154 | "Enabled fixed event %X, Handler=%p\n", event, | |
155 | handler)); | |
1da177e4 LT |
156 | } |
157 | ||
4be44fcd LB |
158 | cleanup: |
159 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | |
160 | return_ACPI_STATUS(status); | |
1da177e4 | 161 | } |
1da177e4 | 162 | |
8313524a | 163 | ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler) |
1da177e4 LT |
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 | ******************************************************************************/ | |
1da177e4 | 177 | acpi_status |
4be44fcd | 178 | acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler) |
1da177e4 | 179 | { |
4be44fcd | 180 | acpi_status status = AE_OK; |
1da177e4 | 181 | |
b229cf92 | 182 | ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler); |
1da177e4 LT |
183 | |
184 | /* Parameter validation */ | |
185 | ||
186 | if (event > ACPI_EVENT_MAX) { | |
4be44fcd | 187 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
188 | } |
189 | ||
4be44fcd LB |
190 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
191 | if (ACPI_FAILURE(status)) { | |
192 | return_ACPI_STATUS(status); | |
1da177e4 LT |
193 | } |
194 | ||
195 | /* Disable the event before removing the handler */ | |
196 | ||
4be44fcd | 197 | status = acpi_disable_event(event, 0); |
1da177e4 LT |
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 | ||
4be44fcd | 204 | if (ACPI_FAILURE(status)) { |
b8e4d893 BM |
205 | ACPI_WARNING((AE_INFO, |
206 | "Could not write to fixed event enable register %X", | |
207 | event)); | |
4be44fcd | 208 | } else { |
4a90c7e8 | 209 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Disabled fixed event %X\n", |
4be44fcd | 210 | event)); |
1da177e4 LT |
211 | } |
212 | ||
4be44fcd LB |
213 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
214 | return_ACPI_STATUS(status); | |
1da177e4 | 215 | } |
1da177e4 | 216 | |
8313524a | 217 | ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler) |
1da177e4 LT |
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 | ******************************************************************************/ | |
1da177e4 | 236 | acpi_status |
4be44fcd LB |
237 | acpi_install_notify_handler(acpi_handle device, |
238 | u32 handler_type, | |
239 | acpi_notify_handler handler, void *context) | |
1da177e4 | 240 | { |
4be44fcd LB |
241 | union acpi_operand_object *obj_desc; |
242 | union acpi_operand_object *notify_obj; | |
243 | struct acpi_namespace_node *node; | |
244 | acpi_status status; | |
1da177e4 | 245 | |
b229cf92 | 246 | ACPI_FUNCTION_TRACE(acpi_install_notify_handler); |
1da177e4 LT |
247 | |
248 | /* Parameter validation */ | |
249 | ||
4be44fcd LB |
250 | if ((!device) || |
251 | (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { | |
252 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
1da177e4 LT |
253 | } |
254 | ||
4be44fcd LB |
255 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
256 | if (ACPI_FAILURE(status)) { | |
257 | return_ACPI_STATUS(status); | |
1da177e4 LT |
258 | } |
259 | ||
260 | /* Convert and validate the device handle */ | |
261 | ||
4be44fcd | 262 | node = acpi_ns_map_handle_to_node(device); |
1da177e4 LT |
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) { | |
52fc0b02 | 275 | |
1da177e4 LT |
276 | /* Make sure the handler is not already installed */ |
277 | ||
278 | if (((handler_type & ACPI_SYSTEM_NOTIFY) && | |
4be44fcd LB |
279 | acpi_gbl_system_notify.handler) || |
280 | ((handler_type & ACPI_DEVICE_NOTIFY) && | |
281 | acpi_gbl_device_notify.handler)) { | |
1da177e4 LT |
282 | status = AE_ALREADY_EXISTS; |
283 | goto unlock_and_exit; | |
284 | } | |
285 | ||
286 | if (handler_type & ACPI_SYSTEM_NOTIFY) { | |
4be44fcd | 287 | acpi_gbl_system_notify.node = node; |
1da177e4 LT |
288 | acpi_gbl_system_notify.handler = handler; |
289 | acpi_gbl_system_notify.context = context; | |
290 | } | |
291 | ||
292 | if (handler_type & ACPI_DEVICE_NOTIFY) { | |
4be44fcd | 293 | acpi_gbl_device_notify.node = node; |
1da177e4 LT |
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 | ||
4be44fcd | 309 | if (!acpi_ev_is_notify_object(node)) { |
1da177e4 LT |
310 | status = AE_TYPE; |
311 | goto unlock_and_exit; | |
312 | } | |
313 | ||
314 | /* Check for an existing internal object */ | |
315 | ||
4be44fcd | 316 | obj_desc = acpi_ns_get_attached_object(node); |
1da177e4 | 317 | if (obj_desc) { |
52fc0b02 | 318 | |
1da177e4 LT |
319 | /* Object exists - make sure there's no handler */ |
320 | ||
321 | if (((handler_type & ACPI_SYSTEM_NOTIFY) && | |
4be44fcd LB |
322 | obj_desc->common_notify.system_notify) || |
323 | ((handler_type & ACPI_DEVICE_NOTIFY) && | |
324 | obj_desc->common_notify.device_notify)) { | |
1da177e4 LT |
325 | status = AE_ALREADY_EXISTS; |
326 | goto unlock_and_exit; | |
327 | } | |
4be44fcd | 328 | } else { |
1da177e4 LT |
329 | /* Create a new object */ |
330 | ||
4be44fcd | 331 | obj_desc = acpi_ut_create_internal_object(node->type); |
1da177e4 LT |
332 | if (!obj_desc) { |
333 | status = AE_NO_MEMORY; | |
334 | goto unlock_and_exit; | |
335 | } | |
336 | ||
337 | /* Attach new object to the Node */ | |
338 | ||
4be44fcd LB |
339 | status = |
340 | acpi_ns_attach_object(device, obj_desc, node->type); | |
1da177e4 LT |
341 | |
342 | /* Remove local reference to the object */ | |
343 | ||
4be44fcd LB |
344 | acpi_ut_remove_reference(obj_desc); |
345 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
346 | goto unlock_and_exit; |
347 | } | |
348 | } | |
349 | ||
350 | /* Install the handler */ | |
351 | ||
4be44fcd LB |
352 | notify_obj = |
353 | acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY); | |
1da177e4 LT |
354 | if (!notify_obj) { |
355 | status = AE_NO_MEMORY; | |
356 | goto unlock_and_exit; | |
357 | } | |
358 | ||
4be44fcd | 359 | notify_obj->notify.node = node; |
1da177e4 LT |
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) { | |
52fc0b02 | 372 | |
1da177e4 LT |
373 | /* Extra ref if installed in both */ |
374 | ||
4be44fcd | 375 | acpi_ut_add_reference(notify_obj); |
1da177e4 LT |
376 | } |
377 | } | |
378 | ||
4be44fcd LB |
379 | unlock_and_exit: |
380 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | |
381 | return_ACPI_STATUS(status); | |
1da177e4 | 382 | } |
1da177e4 | 383 | |
8313524a | 384 | ACPI_EXPORT_SYMBOL(acpi_install_notify_handler) |
1da177e4 LT |
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 | ******************************************************************************/ | |
1da177e4 | 402 | acpi_status |
4be44fcd LB |
403 | acpi_remove_notify_handler(acpi_handle device, |
404 | u32 handler_type, acpi_notify_handler handler) | |
1da177e4 | 405 | { |
4be44fcd LB |
406 | union acpi_operand_object *notify_obj; |
407 | union acpi_operand_object *obj_desc; | |
408 | struct acpi_namespace_node *node; | |
409 | acpi_status status; | |
1da177e4 | 410 | |
b229cf92 | 411 | ACPI_FUNCTION_TRACE(acpi_remove_notify_handler); |
1da177e4 LT |
412 | |
413 | /* Parameter validation */ | |
414 | ||
4be44fcd LB |
415 | if ((!device) || |
416 | (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { | |
417 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
1da177e4 LT |
418 | } |
419 | ||
4be44fcd LB |
420 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
421 | if (ACPI_FAILURE(status)) { | |
422 | return_ACPI_STATUS(status); | |
1da177e4 LT |
423 | } |
424 | ||
425 | /* Convert and validate the device handle */ | |
426 | ||
4be44fcd | 427 | node = acpi_ns_map_handle_to_node(device); |
1da177e4 LT |
428 | if (!node) { |
429 | status = AE_BAD_PARAMETER; | |
430 | goto unlock_and_exit; | |
431 | } | |
432 | ||
433 | /* Root Object */ | |
434 | ||
435 | if (device == ACPI_ROOT_OBJECT) { | |
4be44fcd | 436 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
4a90c7e8 | 437 | "Removing notify handler for namespace root object\n")); |
1da177e4 LT |
438 | |
439 | if (((handler_type & ACPI_SYSTEM_NOTIFY) && | |
4be44fcd LB |
440 | !acpi_gbl_system_notify.handler) || |
441 | ((handler_type & ACPI_DEVICE_NOTIFY) && | |
442 | !acpi_gbl_device_notify.handler)) { | |
1da177e4 LT |
443 | status = AE_NOT_EXIST; |
444 | goto unlock_and_exit; | |
445 | } | |
446 | ||
447 | /* Make sure all deferred tasks are completed */ | |
448 | ||
4be44fcd | 449 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
1da177e4 | 450 | acpi_os_wait_events_complete(NULL); |
4be44fcd LB |
451 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
452 | if (ACPI_FAILURE(status)) { | |
453 | return_ACPI_STATUS(status); | |
454 | } | |
1da177e4 LT |
455 | |
456 | if (handler_type & ACPI_SYSTEM_NOTIFY) { | |
4be44fcd | 457 | acpi_gbl_system_notify.node = NULL; |
1da177e4 LT |
458 | acpi_gbl_system_notify.handler = NULL; |
459 | acpi_gbl_system_notify.context = NULL; | |
460 | } | |
461 | ||
462 | if (handler_type & ACPI_DEVICE_NOTIFY) { | |
4be44fcd | 463 | acpi_gbl_device_notify.node = NULL; |
1da177e4 LT |
464 | acpi_gbl_device_notify.handler = NULL; |
465 | acpi_gbl_device_notify.context = NULL; | |
466 | } | |
467 | } | |
468 | ||
469 | /* All Other Objects */ | |
470 | ||
471 | else { | |
472 | /* Notifies allowed on this object? */ | |
473 | ||
4be44fcd | 474 | if (!acpi_ev_is_notify_object(node)) { |
1da177e4 LT |
475 | status = AE_TYPE; |
476 | goto unlock_and_exit; | |
477 | } | |
478 | ||
479 | /* Check for an existing internal object */ | |
480 | ||
4be44fcd | 481 | obj_desc = acpi_ns_get_attached_object(node); |
1da177e4 LT |
482 | if (!obj_desc) { |
483 | status = AE_NOT_EXIST; | |
484 | goto unlock_and_exit; | |
485 | } | |
486 | ||
487 | /* Object exists - make sure there's an existing handler */ | |
488 | ||
489 | if (handler_type & ACPI_SYSTEM_NOTIFY) { | |
490 | notify_obj = obj_desc->common_notify.system_notify; | |
491 | if ((!notify_obj) || | |
4be44fcd | 492 | (notify_obj->notify.handler != handler)) { |
1da177e4 LT |
493 | status = AE_BAD_PARAMETER; |
494 | goto unlock_and_exit; | |
495 | } | |
496 | /* Make sure all deferred tasks are completed */ | |
497 | ||
4be44fcd | 498 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
1da177e4 | 499 | acpi_os_wait_events_complete(NULL); |
4be44fcd LB |
500 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
501 | if (ACPI_FAILURE(status)) { | |
502 | return_ACPI_STATUS(status); | |
503 | } | |
1da177e4 LT |
504 | |
505 | /* Remove the handler */ | |
506 | obj_desc->common_notify.system_notify = NULL; | |
4be44fcd | 507 | acpi_ut_remove_reference(notify_obj); |
1da177e4 LT |
508 | } |
509 | ||
510 | if (handler_type & ACPI_DEVICE_NOTIFY) { | |
511 | notify_obj = obj_desc->common_notify.device_notify; | |
512 | if ((!notify_obj) || | |
4be44fcd | 513 | (notify_obj->notify.handler != handler)) { |
1da177e4 LT |
514 | status = AE_BAD_PARAMETER; |
515 | goto unlock_and_exit; | |
516 | } | |
517 | /* Make sure all deferred tasks are completed */ | |
518 | ||
4be44fcd | 519 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
1da177e4 | 520 | acpi_os_wait_events_complete(NULL); |
4be44fcd LB |
521 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
522 | if (ACPI_FAILURE(status)) { | |
523 | return_ACPI_STATUS(status); | |
524 | } | |
1da177e4 LT |
525 | |
526 | /* Remove the handler */ | |
527 | obj_desc->common_notify.device_notify = NULL; | |
4be44fcd | 528 | acpi_ut_remove_reference(notify_obj); |
1da177e4 LT |
529 | } |
530 | } | |
531 | ||
4be44fcd LB |
532 | unlock_and_exit: |
533 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | |
534 | return_ACPI_STATUS(status); | |
1da177e4 | 535 | } |
1da177e4 | 536 | |
8313524a | 537 | ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler) |
1da177e4 LT |
538 | |
539 | /******************************************************************************* | |
540 | * | |
541 | * FUNCTION: acpi_install_gpe_handler | |
542 | * | |
44f6c012 RM |
543 | * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT |
544 | * defined GPEs) | |
545 | * gpe_number - The GPE number within the GPE block | |
1da177e4 LT |
546 | * Type - Whether this GPE should be treated as an |
547 | * edge- or level-triggered interrupt. | |
548 | * Address - Address of the handler | |
549 | * Context - Value passed to the handler on each GPE | |
550 | * | |
551 | * RETURN: Status | |
552 | * | |
553 | * DESCRIPTION: Install a handler for a General Purpose Event. | |
554 | * | |
555 | ******************************************************************************/ | |
1da177e4 | 556 | acpi_status |
4be44fcd LB |
557 | acpi_install_gpe_handler(acpi_handle gpe_device, |
558 | u32 gpe_number, | |
559 | u32 type, acpi_event_handler address, void *context) | |
1da177e4 | 560 | { |
4be44fcd LB |
561 | struct acpi_gpe_event_info *gpe_event_info; |
562 | struct acpi_handler_info *handler; | |
563 | acpi_status status; | |
b8e4d893 | 564 | acpi_cpu_flags flags; |
1da177e4 | 565 | |
b229cf92 | 566 | ACPI_FUNCTION_TRACE(acpi_install_gpe_handler); |
1da177e4 LT |
567 | |
568 | /* Parameter validation */ | |
569 | ||
570 | if ((!address) || (type > ACPI_GPE_XRUPT_TYPE_MASK)) { | |
4be44fcd | 571 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
572 | } |
573 | ||
4be44fcd LB |
574 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
575 | if (ACPI_FAILURE(status)) { | |
576 | return_ACPI_STATUS(status); | |
1da177e4 LT |
577 | } |
578 | ||
579 | /* Ensure that we have a valid GPE number */ | |
580 | ||
4be44fcd | 581 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
582 | if (!gpe_event_info) { |
583 | status = AE_BAD_PARAMETER; | |
584 | goto unlock_and_exit; | |
585 | } | |
586 | ||
587 | /* Make sure that there isn't a handler there already */ | |
588 | ||
4be44fcd LB |
589 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
590 | ACPI_GPE_DISPATCH_HANDLER) { | |
1da177e4 LT |
591 | status = AE_ALREADY_EXISTS; |
592 | goto unlock_and_exit; | |
593 | } | |
594 | ||
595 | /* Allocate and init handler object */ | |
596 | ||
8313524a | 597 | handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_handler_info)); |
1da177e4 LT |
598 | if (!handler) { |
599 | status = AE_NO_MEMORY; | |
600 | goto unlock_and_exit; | |
601 | } | |
602 | ||
4be44fcd LB |
603 | handler->address = address; |
604 | handler->context = context; | |
1da177e4 LT |
605 | handler->method_node = gpe_event_info->dispatch.method_node; |
606 | ||
607 | /* Disable the GPE before installing the handler */ | |
608 | ||
4be44fcd LB |
609 | status = acpi_ev_disable_gpe(gpe_event_info); |
610 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
611 | goto unlock_and_exit; |
612 | } | |
613 | ||
614 | /* Install the handler */ | |
615 | ||
4be44fcd | 616 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
1da177e4 LT |
617 | gpe_event_info->dispatch.handler = handler; |
618 | ||
619 | /* Setup up dispatch flags to indicate handler (vs. method) */ | |
620 | ||
4be44fcd | 621 | gpe_event_info->flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); /* Clear bits */ |
1da177e4 LT |
622 | gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER); |
623 | ||
4be44fcd | 624 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
1da177e4 | 625 | |
4be44fcd LB |
626 | unlock_and_exit: |
627 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | |
628 | return_ACPI_STATUS(status); | |
1da177e4 | 629 | } |
1da177e4 | 630 | |
8313524a | 631 | ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler) |
1da177e4 LT |
632 | |
633 | /******************************************************************************* | |
634 | * | |
635 | * FUNCTION: acpi_remove_gpe_handler | |
636 | * | |
44f6c012 RM |
637 | * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT |
638 | * defined GPEs) | |
639 | * gpe_number - The event to remove a handler | |
1da177e4 LT |
640 | * Address - Address of the handler |
641 | * | |
642 | * RETURN: Status | |
643 | * | |
644 | * DESCRIPTION: Remove a handler for a General Purpose acpi_event. | |
645 | * | |
646 | ******************************************************************************/ | |
1da177e4 | 647 | acpi_status |
4be44fcd LB |
648 | acpi_remove_gpe_handler(acpi_handle gpe_device, |
649 | u32 gpe_number, acpi_event_handler address) | |
1da177e4 | 650 | { |
4be44fcd LB |
651 | struct acpi_gpe_event_info *gpe_event_info; |
652 | struct acpi_handler_info *handler; | |
653 | acpi_status status; | |
b8e4d893 | 654 | acpi_cpu_flags flags; |
1da177e4 | 655 | |
b229cf92 | 656 | ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler); |
1da177e4 LT |
657 | |
658 | /* Parameter validation */ | |
659 | ||
660 | if (!address) { | |
4be44fcd | 661 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
662 | } |
663 | ||
4be44fcd LB |
664 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
665 | if (ACPI_FAILURE(status)) { | |
666 | return_ACPI_STATUS(status); | |
1da177e4 LT |
667 | } |
668 | ||
669 | /* Ensure that we have a valid GPE number */ | |
670 | ||
4be44fcd | 671 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
672 | if (!gpe_event_info) { |
673 | status = AE_BAD_PARAMETER; | |
674 | goto unlock_and_exit; | |
675 | } | |
676 | ||
677 | /* Make sure that a handler is indeed installed */ | |
678 | ||
4be44fcd LB |
679 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) != |
680 | ACPI_GPE_DISPATCH_HANDLER) { | |
1da177e4 LT |
681 | status = AE_NOT_EXIST; |
682 | goto unlock_and_exit; | |
683 | } | |
684 | ||
685 | /* Make sure that the installed handler is the same */ | |
686 | ||
687 | if (gpe_event_info->dispatch.handler->address != address) { | |
688 | status = AE_BAD_PARAMETER; | |
689 | goto unlock_and_exit; | |
690 | } | |
691 | ||
692 | /* Disable the GPE before removing the handler */ | |
693 | ||
4be44fcd LB |
694 | status = acpi_ev_disable_gpe(gpe_event_info); |
695 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
696 | goto unlock_and_exit; |
697 | } | |
698 | ||
699 | /* Make sure all deferred tasks are completed */ | |
700 | ||
4be44fcd | 701 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
1da177e4 | 702 | acpi_os_wait_events_complete(NULL); |
4be44fcd LB |
703 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
704 | if (ACPI_FAILURE(status)) { | |
705 | return_ACPI_STATUS(status); | |
706 | } | |
1da177e4 LT |
707 | |
708 | /* Remove the handler */ | |
709 | ||
4be44fcd | 710 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
1da177e4 LT |
711 | handler = gpe_event_info->dispatch.handler; |
712 | ||
713 | /* Restore Method node (if any), set dispatch flags */ | |
714 | ||
715 | gpe_event_info->dispatch.method_node = handler->method_node; | |
4be44fcd | 716 | gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK; /* Clear bits */ |
1da177e4 LT |
717 | if (handler->method_node) { |
718 | gpe_event_info->flags |= ACPI_GPE_DISPATCH_METHOD; | |
719 | } | |
4be44fcd | 720 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
1da177e4 LT |
721 | |
722 | /* Now we can free the handler object */ | |
723 | ||
8313524a | 724 | ACPI_FREE(handler); |
1da177e4 | 725 | |
4be44fcd LB |
726 | unlock_and_exit: |
727 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | |
728 | return_ACPI_STATUS(status); | |
1da177e4 | 729 | } |
1da177e4 | 730 | |
8313524a | 731 | ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler) |
1da177e4 LT |
732 | |
733 | /******************************************************************************* | |
734 | * | |
735 | * FUNCTION: acpi_acquire_global_lock | |
736 | * | |
737 | * PARAMETERS: Timeout - How long the caller is willing to wait | |
44f6c012 RM |
738 | * Handle - Where the handle to the lock is returned |
739 | * (if acquired) | |
1da177e4 LT |
740 | * |
741 | * RETURN: Status | |
742 | * | |
743 | * DESCRIPTION: Acquire the ACPI Global Lock | |
744 | * | |
745 | ******************************************************************************/ | |
4be44fcd | 746 | acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle) |
1da177e4 | 747 | { |
4be44fcd | 748 | acpi_status status; |
1da177e4 LT |
749 | |
750 | if (!handle) { | |
751 | return (AE_BAD_PARAMETER); | |
752 | } | |
753 | ||
4be44fcd LB |
754 | status = acpi_ex_enter_interpreter(); |
755 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
756 | return (status); |
757 | } | |
758 | ||
4be44fcd LB |
759 | status = acpi_ev_acquire_global_lock(timeout); |
760 | acpi_ex_exit_interpreter(); | |
1da177e4 | 761 | |
4be44fcd | 762 | if (ACPI_SUCCESS(status)) { |
1da177e4 LT |
763 | acpi_gbl_global_lock_handle++; |
764 | *handle = acpi_gbl_global_lock_handle; | |
765 | } | |
766 | ||
767 | return (status); | |
768 | } | |
1da177e4 | 769 | |
8313524a | 770 | ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock) |
1da177e4 LT |
771 | |
772 | /******************************************************************************* | |
773 | * | |
774 | * FUNCTION: acpi_release_global_lock | |
775 | * | |
776 | * PARAMETERS: Handle - Returned from acpi_acquire_global_lock | |
777 | * | |
778 | * RETURN: Status | |
779 | * | |
44f6c012 | 780 | * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid. |
1da177e4 LT |
781 | * |
782 | ******************************************************************************/ | |
4be44fcd | 783 | acpi_status acpi_release_global_lock(u32 handle) |
1da177e4 | 784 | { |
4be44fcd | 785 | acpi_status status; |
1da177e4 LT |
786 | |
787 | if (handle != acpi_gbl_global_lock_handle) { | |
788 | return (AE_NOT_ACQUIRED); | |
789 | } | |
790 | ||
4be44fcd | 791 | status = acpi_ev_release_global_lock(); |
1da177e4 LT |
792 | return (status); |
793 | } | |
1da177e4 | 794 | |
8313524a | 795 | ACPI_EXPORT_SYMBOL(acpi_release_global_lock) |