]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: evxface - External interfaces for ACPI events | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
77848130 | 8 | * Copyright (C) 2000 - 2012, Intel Corp. |
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 | ||
214f2c90 | 44 | #include <linux/export.h> |
1da177e4 | 45 | #include <acpi/acpi.h> |
e2f7a777 LB |
46 | #include "accommon.h" |
47 | #include "acnamesp.h" | |
48 | #include "acevents.h" | |
49 | #include "acinterp.h" | |
1da177e4 LT |
50 | |
51 | #define _COMPONENT ACPI_EVENTS | |
4be44fcd | 52 | ACPI_MODULE_NAME("evxface") |
1da177e4 | 53 | |
1da177e4 LT |
54 | |
55 | /******************************************************************************* | |
56 | * | |
57 | * FUNCTION: acpi_install_notify_handler | |
58 | * | |
59 | * PARAMETERS: Device - The device for which notifies will be handled | |
60 | * handler_type - The type of handler: | |
86ed4bc8 BM |
61 | * ACPI_SYSTEM_NOTIFY: System Handler (00-7F) |
62 | * ACPI_DEVICE_NOTIFY: Device Handler (80-FF) | |
63 | * ACPI_ALL_NOTIFY: Both System and Device | |
1da177e4 LT |
64 | * Handler - Address of the handler |
65 | * Context - Value passed to the handler on each GPE | |
66 | * | |
67 | * RETURN: Status | |
68 | * | |
86ed4bc8 BM |
69 | * DESCRIPTION: Install a handler for notifications on an ACPI Device, |
70 | * thermal_zone, or Processor object. | |
71 | * | |
72 | * NOTES: The Root namespace object may have only one handler for each | |
73 | * type of notify (System/Device). Device/Thermal/Processor objects | |
74 | * may have one device notify handler, and multiple system notify | |
75 | * handlers. | |
1da177e4 LT |
76 | * |
77 | ******************************************************************************/ | |
1da177e4 | 78 | acpi_status |
4be44fcd LB |
79 | acpi_install_notify_handler(acpi_handle device, |
80 | u32 handler_type, | |
81 | acpi_notify_handler handler, void *context) | |
1da177e4 | 82 | { |
86ed4bc8 BM |
83 | struct acpi_namespace_node *node = |
84 | ACPI_CAST_PTR(struct acpi_namespace_node, device); | |
4be44fcd | 85 | union acpi_operand_object *obj_desc; |
86ed4bc8 | 86 | union acpi_operand_object *handler_obj; |
4be44fcd | 87 | acpi_status status; |
86ed4bc8 | 88 | u32 i; |
1da177e4 | 89 | |
b229cf92 | 90 | ACPI_FUNCTION_TRACE(acpi_install_notify_handler); |
1da177e4 LT |
91 | |
92 | /* Parameter validation */ | |
93 | ||
86ed4bc8 BM |
94 | if ((!device) || (!handler) || (!handler_type) || |
95 | (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { | |
4be44fcd | 96 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
97 | } |
98 | ||
4be44fcd LB |
99 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
100 | if (ACPI_FAILURE(status)) { | |
101 | return_ACPI_STATUS(status); | |
1da177e4 LT |
102 | } |
103 | ||
1da177e4 LT |
104 | /* |
105 | * Root Object: | |
106 | * Registering a notify handler on the root object indicates that the | |
9f15fc66 | 107 | * caller wishes to receive notifications for all objects. Note that |
86ed4bc8 BM |
108 | * only one global handler can be registered per notify type. |
109 | * Ensure that a handler is not already installed. | |
1da177e4 LT |
110 | */ |
111 | if (device == ACPI_ROOT_OBJECT) { | |
86ed4bc8 BM |
112 | for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { |
113 | if (handler_type & (i + 1)) { | |
114 | if (acpi_gbl_global_notify[i].handler) { | |
115 | status = AE_ALREADY_EXISTS; | |
116 | goto unlock_and_exit; | |
117 | } | |
52fc0b02 | 118 | |
86ed4bc8 BM |
119 | acpi_gbl_global_notify[i].handler = handler; |
120 | acpi_gbl_global_notify[i].context = context; | |
121 | } | |
1da177e4 LT |
122 | } |
123 | ||
86ed4bc8 | 124 | goto unlock_and_exit; /* Global notify handler installed, all done */ |
1da177e4 LT |
125 | } |
126 | ||
127 | /* | |
128 | * All Other Objects: | |
86ed4bc8 BM |
129 | * Caller will only receive notifications specific to the target |
130 | * object. Note that only certain object types are allowed to | |
131 | * receive notifications. | |
1da177e4 | 132 | */ |
1da177e4 | 133 | |
86ed4bc8 | 134 | /* Are Notifies allowed on this object? */ |
1da177e4 | 135 | |
86ed4bc8 BM |
136 | if (!acpi_ev_is_notify_object(node)) { |
137 | status = AE_TYPE; | |
138 | goto unlock_and_exit; | |
139 | } | |
1da177e4 | 140 | |
86ed4bc8 | 141 | /* Check for an existing internal object, might not exist */ |
52fc0b02 | 142 | |
86ed4bc8 BM |
143 | obj_desc = acpi_ns_get_attached_object(node); |
144 | if (!obj_desc) { | |
1da177e4 | 145 | |
86ed4bc8 BM |
146 | /* Create a new object */ |
147 | ||
148 | obj_desc = acpi_ut_create_internal_object(node->type); | |
149 | if (!obj_desc) { | |
150 | status = AE_NO_MEMORY; | |
151 | goto unlock_and_exit; | |
152 | } | |
3f0be671 | 153 | |
86ed4bc8 | 154 | /* Attach new object to the Node, remove local reference */ |
3f0be671 | 155 | |
86ed4bc8 BM |
156 | status = acpi_ns_attach_object(device, obj_desc, node->type); |
157 | acpi_ut_remove_reference(obj_desc); | |
158 | if (ACPI_FAILURE(status)) { | |
159 | goto unlock_and_exit; | |
160 | } | |
161 | } | |
3f0be671 | 162 | |
86ed4bc8 BM |
163 | /* Ensure that the handler is not already installed in the lists */ |
164 | ||
165 | for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { | |
166 | if (handler_type & (i + 1)) { | |
167 | handler_obj = obj_desc->common_notify.notify_list[i]; | |
168 | while (handler_obj) { | |
169 | if (handler_obj->notify.handler == handler) { | |
3f0be671 RW |
170 | status = AE_ALREADY_EXISTS; |
171 | goto unlock_and_exit; | |
172 | } | |
173 | ||
86ed4bc8 | 174 | handler_obj = handler_obj->notify.next[i]; |
1da177e4 LT |
175 | } |
176 | } | |
86ed4bc8 | 177 | } |
1da177e4 | 178 | |
86ed4bc8 | 179 | /* Create and populate a new notify handler object */ |
1da177e4 | 180 | |
86ed4bc8 BM |
181 | handler_obj = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY); |
182 | if (!handler_obj) { | |
183 | status = AE_NO_MEMORY; | |
184 | goto unlock_and_exit; | |
185 | } | |
1da177e4 | 186 | |
86ed4bc8 BM |
187 | handler_obj->notify.node = node; |
188 | handler_obj->notify.handler_type = handler_type; | |
189 | handler_obj->notify.handler = handler; | |
190 | handler_obj->notify.context = context; | |
1da177e4 | 191 | |
86ed4bc8 | 192 | /* Install the handler at the list head(s) */ |
1da177e4 | 193 | |
86ed4bc8 BM |
194 | for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { |
195 | if (handler_type & (i + 1)) { | |
196 | handler_obj->notify.next[i] = | |
197 | obj_desc->common_notify.notify_list[i]; | |
1da177e4 | 198 | |
86ed4bc8 BM |
199 | obj_desc->common_notify.notify_list[i] = handler_obj; |
200 | } | |
201 | } | |
52fc0b02 | 202 | |
86ed4bc8 | 203 | /* Add an extra reference if handler was installed in both lists */ |
1da177e4 | 204 | |
86ed4bc8 BM |
205 | if (handler_type == ACPI_ALL_NOTIFY) { |
206 | acpi_ut_add_reference(handler_obj); | |
1da177e4 LT |
207 | } |
208 | ||
86ed4bc8 | 209 | unlock_and_exit: |
4be44fcd LB |
210 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
211 | return_ACPI_STATUS(status); | |
1da177e4 | 212 | } |
1da177e4 | 213 | |
8313524a | 214 | ACPI_EXPORT_SYMBOL(acpi_install_notify_handler) |
1da177e4 LT |
215 | |
216 | /******************************************************************************* | |
217 | * | |
218 | * FUNCTION: acpi_remove_notify_handler | |
219 | * | |
86ed4bc8 | 220 | * PARAMETERS: Device - The device for which the handler is installed |
1da177e4 | 221 | * handler_type - The type of handler: |
86ed4bc8 BM |
222 | * ACPI_SYSTEM_NOTIFY: System Handler (00-7F) |
223 | * ACPI_DEVICE_NOTIFY: Device Handler (80-FF) | |
224 | * ACPI_ALL_NOTIFY: Both System and Device | |
1da177e4 LT |
225 | * Handler - Address of the handler |
226 | * | |
227 | * RETURN: Status | |
228 | * | |
229 | * DESCRIPTION: Remove a handler for notifies on an ACPI device | |
230 | * | |
231 | ******************************************************************************/ | |
1da177e4 | 232 | acpi_status |
4be44fcd LB |
233 | acpi_remove_notify_handler(acpi_handle device, |
234 | u32 handler_type, acpi_notify_handler handler) | |
1da177e4 | 235 | { |
86ed4bc8 BM |
236 | struct acpi_namespace_node *node = |
237 | ACPI_CAST_PTR(struct acpi_namespace_node, device); | |
4be44fcd | 238 | union acpi_operand_object *obj_desc; |
86ed4bc8 BM |
239 | union acpi_operand_object *handler_obj; |
240 | union acpi_operand_object *previous_handler_obj; | |
4be44fcd | 241 | acpi_status status; |
86ed4bc8 | 242 | u32 i; |
1da177e4 | 243 | |
b229cf92 | 244 | ACPI_FUNCTION_TRACE(acpi_remove_notify_handler); |
1da177e4 LT |
245 | |
246 | /* Parameter validation */ | |
247 | ||
86ed4bc8 BM |
248 | if ((!device) || (!handler) || (!handler_type) || |
249 | (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { | |
250 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
1da177e4 | 251 | } |
3f0be671 | 252 | /* Make sure all deferred tasks are completed */ |
86ed4bc8 | 253 | |
bd6f10a5 | 254 | acpi_os_wait_events_complete(); |
3f0be671 | 255 | |
4be44fcd LB |
256 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
257 | if (ACPI_FAILURE(status)) { | |
86ed4bc8 | 258 | return_ACPI_STATUS(status); |
1da177e4 LT |
259 | } |
260 | ||
86ed4bc8 | 261 | /* Root Object. Global handlers are removed here */ |
1da177e4 LT |
262 | |
263 | if (device == ACPI_ROOT_OBJECT) { | |
86ed4bc8 BM |
264 | for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { |
265 | if (handler_type & (i + 1)) { | |
266 | if (!acpi_gbl_global_notify[i].handler || | |
267 | (acpi_gbl_global_notify[i].handler != | |
268 | handler)) { | |
269 | status = AE_NOT_EXIST; | |
270 | goto unlock_and_exit; | |
271 | } | |
1da177e4 | 272 | |
86ed4bc8 BM |
273 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
274 | "Removing global notify handler\n")); | |
1da177e4 | 275 | |
86ed4bc8 BM |
276 | acpi_gbl_global_notify[i].handler = NULL; |
277 | acpi_gbl_global_notify[i].context = NULL; | |
278 | } | |
1da177e4 | 279 | } |
1da177e4 | 280 | |
86ed4bc8 BM |
281 | goto unlock_and_exit; |
282 | } | |
1da177e4 | 283 | |
86ed4bc8 | 284 | /* All other objects: Are Notifies allowed on this object? */ |
1da177e4 | 285 | |
86ed4bc8 BM |
286 | if (!acpi_ev_is_notify_object(node)) { |
287 | status = AE_TYPE; | |
288 | goto unlock_and_exit; | |
289 | } | |
1da177e4 | 290 | |
86ed4bc8 | 291 | /* Must have an existing internal object */ |
1da177e4 | 292 | |
86ed4bc8 BM |
293 | obj_desc = acpi_ns_get_attached_object(node); |
294 | if (!obj_desc) { | |
295 | status = AE_NOT_EXIST; | |
296 | goto unlock_and_exit; | |
297 | } | |
1da177e4 | 298 | |
86ed4bc8 | 299 | /* Internal object exists. Find the handler and remove it */ |
1da177e4 | 300 | |
86ed4bc8 BM |
301 | for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { |
302 | if (handler_type & (i + 1)) { | |
303 | handler_obj = obj_desc->common_notify.notify_list[i]; | |
304 | previous_handler_obj = NULL; | |
3f0be671 | 305 | |
86ed4bc8 | 306 | /* Attempt to find the handler in the handler list */ |
f6dd9221 | 307 | |
86ed4bc8 BM |
308 | while (handler_obj && |
309 | (handler_obj->notify.handler != handler)) { | |
310 | previous_handler_obj = handler_obj; | |
311 | handler_obj = handler_obj->notify.next[i]; | |
3f0be671 RW |
312 | } |
313 | ||
86ed4bc8 BM |
314 | if (!handler_obj) { |
315 | status = AE_NOT_EXIST; | |
f6dd9221 | 316 | goto unlock_and_exit; |
1da177e4 | 317 | } |
1da177e4 | 318 | |
86ed4bc8 | 319 | /* Remove the handler object from the list */ |
1da177e4 | 320 | |
86ed4bc8 BM |
321 | if (previous_handler_obj) { /* Handler is not at the list head */ |
322 | previous_handler_obj->notify.next[i] = | |
323 | handler_obj->notify.next[i]; | |
324 | } else { /* Handler is at the list head */ | |
f6dd9221 | 325 | |
86ed4bc8 BM |
326 | obj_desc->common_notify.notify_list[i] = |
327 | handler_obj->notify.next[i]; | |
1da177e4 | 328 | } |
1da177e4 | 329 | |
86ed4bc8 | 330 | acpi_ut_remove_reference(handler_obj); |
1da177e4 LT |
331 | } |
332 | } | |
333 | ||
86ed4bc8 | 334 | unlock_and_exit: |
4be44fcd LB |
335 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
336 | return_ACPI_STATUS(status); | |
1da177e4 | 337 | } |
1da177e4 | 338 | |
8313524a | 339 | ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler) |
1da177e4 | 340 | |
33620c54 BM |
341 | /******************************************************************************* |
342 | * | |
343 | * FUNCTION: acpi_install_exception_handler | |
344 | * | |
345 | * PARAMETERS: Handler - Pointer to the handler function for the | |
346 | * event | |
347 | * | |
348 | * RETURN: Status | |
349 | * | |
350 | * DESCRIPTION: Saves the pointer to the handler function | |
351 | * | |
352 | ******************************************************************************/ | |
353 | #ifdef ACPI_FUTURE_USAGE | |
354 | acpi_status acpi_install_exception_handler(acpi_exception_handler handler) | |
355 | { | |
356 | acpi_status status; | |
357 | ||
358 | ACPI_FUNCTION_TRACE(acpi_install_exception_handler); | |
359 | ||
360 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | |
361 | if (ACPI_FAILURE(status)) { | |
362 | return_ACPI_STATUS(status); | |
363 | } | |
364 | ||
365 | /* Don't allow two handlers. */ | |
366 | ||
367 | if (acpi_gbl_exception_handler) { | |
368 | status = AE_ALREADY_EXISTS; | |
369 | goto cleanup; | |
370 | } | |
371 | ||
372 | /* Install the handler */ | |
373 | ||
374 | acpi_gbl_exception_handler = handler; | |
375 | ||
376 | cleanup: | |
377 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | |
378 | return_ACPI_STATUS(status); | |
379 | } | |
380 | ||
381 | ACPI_EXPORT_SYMBOL(acpi_install_exception_handler) | |
382 | #endif /* ACPI_FUTURE_USAGE */ | |
383 | ||
384 | #if (!ACPI_REDUCED_HARDWARE) | |
385 | /******************************************************************************* | |
386 | * | |
387 | * FUNCTION: acpi_install_global_event_handler | |
388 | * | |
389 | * PARAMETERS: Handler - Pointer to the global event handler function | |
390 | * Context - Value passed to the handler on each event | |
391 | * | |
392 | * RETURN: Status | |
393 | * | |
394 | * DESCRIPTION: Saves the pointer to the handler function. The global handler | |
395 | * is invoked upon each incoming GPE and Fixed Event. It is | |
396 | * invoked at interrupt level at the time of the event dispatch. | |
397 | * Can be used to update event counters, etc. | |
398 | * | |
399 | ******************************************************************************/ | |
400 | acpi_status | |
401 | acpi_install_global_event_handler(ACPI_GBL_EVENT_HANDLER handler, void *context) | |
402 | { | |
403 | acpi_status status; | |
404 | ||
405 | ACPI_FUNCTION_TRACE(acpi_install_global_event_handler); | |
406 | ||
407 | /* Parameter validation */ | |
408 | ||
409 | if (!handler) { | |
410 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
411 | } | |
412 | ||
413 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | |
414 | if (ACPI_FAILURE(status)) { | |
415 | return_ACPI_STATUS(status); | |
416 | } | |
417 | ||
418 | /* Don't allow two handlers. */ | |
419 | ||
420 | if (acpi_gbl_global_event_handler) { | |
421 | status = AE_ALREADY_EXISTS; | |
422 | goto cleanup; | |
423 | } | |
424 | ||
425 | acpi_gbl_global_event_handler = handler; | |
426 | acpi_gbl_global_event_handler_context = context; | |
427 | ||
428 | cleanup: | |
429 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | |
430 | return_ACPI_STATUS(status); | |
431 | } | |
432 | ||
433 | ACPI_EXPORT_SYMBOL(acpi_install_global_event_handler) | |
434 | ||
435 | /******************************************************************************* | |
436 | * | |
437 | * FUNCTION: acpi_install_fixed_event_handler | |
438 | * | |
439 | * PARAMETERS: Event - Event type to enable. | |
440 | * Handler - Pointer to the handler function for the | |
441 | * event | |
442 | * Context - Value passed to the handler on each GPE | |
443 | * | |
444 | * RETURN: Status | |
445 | * | |
446 | * DESCRIPTION: Saves the pointer to the handler function and then enables the | |
447 | * event. | |
448 | * | |
449 | ******************************************************************************/ | |
450 | acpi_status | |
451 | acpi_install_fixed_event_handler(u32 event, | |
452 | acpi_event_handler handler, void *context) | |
453 | { | |
454 | acpi_status status; | |
455 | ||
456 | ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler); | |
457 | ||
458 | /* Parameter validation */ | |
459 | ||
460 | if (event > ACPI_EVENT_MAX) { | |
461 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
462 | } | |
463 | ||
464 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | |
465 | if (ACPI_FAILURE(status)) { | |
466 | return_ACPI_STATUS(status); | |
467 | } | |
468 | ||
469 | /* Don't allow two handlers. */ | |
470 | ||
471 | if (NULL != acpi_gbl_fixed_event_handlers[event].handler) { | |
472 | status = AE_ALREADY_EXISTS; | |
473 | goto cleanup; | |
474 | } | |
475 | ||
476 | /* Install the handler before enabling the event */ | |
477 | ||
478 | acpi_gbl_fixed_event_handlers[event].handler = handler; | |
479 | acpi_gbl_fixed_event_handlers[event].context = context; | |
480 | ||
481 | status = acpi_clear_event(event); | |
482 | if (ACPI_SUCCESS(status)) | |
483 | status = acpi_enable_event(event, 0); | |
484 | if (ACPI_FAILURE(status)) { | |
485 | ACPI_WARNING((AE_INFO, "Could not enable fixed event 0x%X", | |
486 | event)); | |
487 | ||
488 | /* Remove the handler */ | |
489 | ||
490 | acpi_gbl_fixed_event_handlers[event].handler = NULL; | |
491 | acpi_gbl_fixed_event_handlers[event].context = NULL; | |
492 | } else { | |
493 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
494 | "Enabled fixed event %X, Handler=%p\n", event, | |
495 | handler)); | |
496 | } | |
497 | ||
498 | cleanup: | |
499 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | |
500 | return_ACPI_STATUS(status); | |
501 | } | |
502 | ||
503 | ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler) | |
504 | ||
505 | /******************************************************************************* | |
506 | * | |
507 | * FUNCTION: acpi_remove_fixed_event_handler | |
508 | * | |
509 | * PARAMETERS: Event - Event type to disable. | |
510 | * Handler - Address of the handler | |
511 | * | |
512 | * RETURN: Status | |
513 | * | |
514 | * DESCRIPTION: Disables the event and unregisters the event handler. | |
515 | * | |
516 | ******************************************************************************/ | |
517 | acpi_status | |
518 | acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler) | |
519 | { | |
520 | acpi_status status = AE_OK; | |
521 | ||
522 | ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler); | |
523 | ||
524 | /* Parameter validation */ | |
525 | ||
526 | if (event > ACPI_EVENT_MAX) { | |
527 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
528 | } | |
529 | ||
530 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | |
531 | if (ACPI_FAILURE(status)) { | |
532 | return_ACPI_STATUS(status); | |
533 | } | |
534 | ||
535 | /* Disable the event before removing the handler */ | |
536 | ||
537 | status = acpi_disable_event(event, 0); | |
538 | ||
539 | /* Always Remove the handler */ | |
540 | ||
541 | acpi_gbl_fixed_event_handlers[event].handler = NULL; | |
542 | acpi_gbl_fixed_event_handlers[event].context = NULL; | |
543 | ||
544 | if (ACPI_FAILURE(status)) { | |
545 | ACPI_WARNING((AE_INFO, | |
546 | "Could not write to fixed event enable register 0x%X", | |
547 | event)); | |
548 | } else { | |
549 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Disabled fixed event %X\n", | |
550 | event)); | |
551 | } | |
552 | ||
553 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | |
554 | return_ACPI_STATUS(status); | |
555 | } | |
556 | ||
557 | ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler) | |
558 | ||
1da177e4 LT |
559 | /******************************************************************************* |
560 | * | |
561 | * FUNCTION: acpi_install_gpe_handler | |
562 | * | |
44f6c012 RM |
563 | * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT |
564 | * defined GPEs) | |
565 | * gpe_number - The GPE number within the GPE block | |
1da177e4 LT |
566 | * Type - Whether this GPE should be treated as an |
567 | * edge- or level-triggered interrupt. | |
568 | * Address - Address of the handler | |
569 | * Context - Value passed to the handler on each GPE | |
570 | * | |
571 | * RETURN: Status | |
572 | * | |
573 | * DESCRIPTION: Install a handler for a General Purpose Event. | |
574 | * | |
575 | ******************************************************************************/ | |
1da177e4 | 576 | acpi_status |
4be44fcd LB |
577 | acpi_install_gpe_handler(acpi_handle gpe_device, |
578 | u32 gpe_number, | |
8b6cd8ad | 579 | u32 type, acpi_gpe_handler address, void *context) |
1da177e4 | 580 | { |
4be44fcd | 581 | struct acpi_gpe_event_info *gpe_event_info; |
8b6cd8ad | 582 | struct acpi_gpe_handler_info *handler; |
4be44fcd | 583 | acpi_status status; |
b8e4d893 | 584 | acpi_cpu_flags flags; |
1da177e4 | 585 | |
b229cf92 | 586 | ACPI_FUNCTION_TRACE(acpi_install_gpe_handler); |
1da177e4 LT |
587 | |
588 | /* Parameter validation */ | |
589 | ||
0f849d2c LM |
590 | if ((!address) || (type & ~ACPI_GPE_XRUPT_TYPE_MASK)) { |
591 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
1da177e4 LT |
592 | } |
593 | ||
4be44fcd LB |
594 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
595 | if (ACPI_FAILURE(status)) { | |
0f849d2c | 596 | return_ACPI_STATUS(status); |
1da177e4 LT |
597 | } |
598 | ||
28f4f8a9 RW |
599 | /* Allocate memory for the handler object */ |
600 | ||
8b6cd8ad | 601 | handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_handler_info)); |
28f4f8a9 RW |
602 | if (!handler) { |
603 | status = AE_NO_MEMORY; | |
604 | goto unlock_and_exit; | |
605 | } | |
606 | ||
607 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); | |
608 | ||
1da177e4 LT |
609 | /* Ensure that we have a valid GPE number */ |
610 | ||
4be44fcd | 611 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
612 | if (!gpe_event_info) { |
613 | status = AE_BAD_PARAMETER; | |
28f4f8a9 | 614 | goto free_and_exit; |
1da177e4 LT |
615 | } |
616 | ||
617 | /* Make sure that there isn't a handler there already */ | |
618 | ||
4be44fcd LB |
619 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
620 | ACPI_GPE_DISPATCH_HANDLER) { | |
1da177e4 | 621 | status = AE_ALREADY_EXISTS; |
28f4f8a9 | 622 | goto free_and_exit; |
1da177e4 LT |
623 | } |
624 | ||
625 | /* Allocate and init handler object */ | |
626 | ||
4be44fcd LB |
627 | handler->address = address; |
628 | handler->context = context; | |
1da177e4 | 629 | handler->method_node = gpe_event_info->dispatch.method_node; |
3a37898d | 630 | handler->original_flags = gpe_event_info->flags & |
28f4f8a9 RW |
631 | (ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); |
632 | ||
633 | /* | |
a2100801 RW |
634 | * If the GPE is associated with a method, it might have been enabled |
635 | * automatically during initialization, in which case it has to be | |
636 | * disabled now to avoid spurious execution of the handler. | |
28f4f8a9 RW |
637 | */ |
638 | ||
3a37898d | 639 | if ((handler->original_flags & ACPI_GPE_DISPATCH_METHOD) |
a2100801 | 640 | && gpe_event_info->runtime_count) { |
3a37898d LM |
641 | handler->originally_enabled = 1; |
642 | (void)acpi_ev_remove_gpe_reference(gpe_event_info); | |
a2100801 | 643 | } |
1da177e4 | 644 | |
1da177e4 LT |
645 | /* Install the handler */ |
646 | ||
1da177e4 LT |
647 | gpe_event_info->dispatch.handler = handler; |
648 | ||
649 | /* Setup up dispatch flags to indicate handler (vs. method) */ | |
650 | ||
d4913dc6 BM |
651 | gpe_event_info->flags &= |
652 | ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); | |
1da177e4 LT |
653 | gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER); |
654 | ||
4be44fcd | 655 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
1da177e4 | 656 | |
0f849d2c | 657 | unlock_and_exit: |
4be44fcd LB |
658 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
659 | return_ACPI_STATUS(status); | |
28f4f8a9 RW |
660 | |
661 | free_and_exit: | |
662 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); | |
663 | ACPI_FREE(handler); | |
664 | goto unlock_and_exit; | |
1da177e4 | 665 | } |
1da177e4 | 666 | |
8313524a | 667 | ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler) |
1da177e4 LT |
668 | |
669 | /******************************************************************************* | |
670 | * | |
671 | * FUNCTION: acpi_remove_gpe_handler | |
672 | * | |
44f6c012 RM |
673 | * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT |
674 | * defined GPEs) | |
675 | * gpe_number - The event to remove a handler | |
1da177e4 LT |
676 | * Address - Address of the handler |
677 | * | |
678 | * RETURN: Status | |
679 | * | |
680 | * DESCRIPTION: Remove a handler for a General Purpose acpi_event. | |
681 | * | |
682 | ******************************************************************************/ | |
1da177e4 | 683 | acpi_status |
4be44fcd | 684 | acpi_remove_gpe_handler(acpi_handle gpe_device, |
8b6cd8ad | 685 | u32 gpe_number, acpi_gpe_handler address) |
1da177e4 | 686 | { |
4be44fcd | 687 | struct acpi_gpe_event_info *gpe_event_info; |
8b6cd8ad | 688 | struct acpi_gpe_handler_info *handler; |
4be44fcd | 689 | acpi_status status; |
b8e4d893 | 690 | acpi_cpu_flags flags; |
1da177e4 | 691 | |
b229cf92 | 692 | ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler); |
1da177e4 LT |
693 | |
694 | /* Parameter validation */ | |
695 | ||
696 | if (!address) { | |
4be44fcd | 697 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
698 | } |
699 | ||
28f4f8a9 RW |
700 | /* Make sure all deferred tasks are completed */ |
701 | ||
bd6f10a5 | 702 | acpi_os_wait_events_complete(); |
28f4f8a9 | 703 | |
4be44fcd LB |
704 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
705 | if (ACPI_FAILURE(status)) { | |
706 | return_ACPI_STATUS(status); | |
1da177e4 LT |
707 | } |
708 | ||
28f4f8a9 RW |
709 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
710 | ||
1da177e4 LT |
711 | /* Ensure that we have a valid GPE number */ |
712 | ||
4be44fcd | 713 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
714 | if (!gpe_event_info) { |
715 | status = AE_BAD_PARAMETER; | |
716 | goto unlock_and_exit; | |
717 | } | |
718 | ||
719 | /* Make sure that a handler is indeed installed */ | |
720 | ||
4be44fcd LB |
721 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) != |
722 | ACPI_GPE_DISPATCH_HANDLER) { | |
1da177e4 LT |
723 | status = AE_NOT_EXIST; |
724 | goto unlock_and_exit; | |
725 | } | |
726 | ||
727 | /* Make sure that the installed handler is the same */ | |
728 | ||
729 | if (gpe_event_info->dispatch.handler->address != address) { | |
730 | status = AE_BAD_PARAMETER; | |
731 | goto unlock_and_exit; | |
732 | } | |
733 | ||
1da177e4 LT |
734 | /* Remove the handler */ |
735 | ||
1da177e4 LT |
736 | handler = gpe_event_info->dispatch.handler; |
737 | ||
738 | /* Restore Method node (if any), set dispatch flags */ | |
739 | ||
740 | gpe_event_info->dispatch.method_node = handler->method_node; | |
28f4f8a9 RW |
741 | gpe_event_info->flags &= |
742 | ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); | |
3a37898d | 743 | gpe_event_info->flags |= handler->original_flags; |
28f4f8a9 RW |
744 | |
745 | /* | |
a2100801 RW |
746 | * If the GPE was previously associated with a method and it was |
747 | * enabled, it should be enabled at this point to restore the | |
748 | * post-initialization configuration. | |
28f4f8a9 RW |
749 | */ |
750 | ||
3a37898d LM |
751 | if ((handler->original_flags & ACPI_GPE_DISPATCH_METHOD) |
752 | && handler->originally_enabled) | |
753 | (void)acpi_ev_add_gpe_reference(gpe_event_info); | |
1da177e4 LT |
754 | |
755 | /* Now we can free the handler object */ | |
756 | ||
8313524a | 757 | ACPI_FREE(handler); |
1da177e4 | 758 | |
28f4f8a9 RW |
759 | unlock_and_exit: |
760 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); | |
761 | ||
4be44fcd LB |
762 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
763 | return_ACPI_STATUS(status); | |
1da177e4 | 764 | } |
1da177e4 | 765 | |
8313524a | 766 | ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler) |
1da177e4 LT |
767 | |
768 | /******************************************************************************* | |
769 | * | |
770 | * FUNCTION: acpi_acquire_global_lock | |
771 | * | |
772 | * PARAMETERS: Timeout - How long the caller is willing to wait | |
44f6c012 RM |
773 | * Handle - Where the handle to the lock is returned |
774 | * (if acquired) | |
1da177e4 LT |
775 | * |
776 | * RETURN: Status | |
777 | * | |
778 | * DESCRIPTION: Acquire the ACPI Global Lock | |
779 | * | |
ba886cd4 BM |
780 | * Note: Allows callers with the same thread ID to acquire the global lock |
781 | * multiple times. In other words, externally, the behavior of the global lock | |
782 | * is identical to an AML mutex. On the first acquire, a new handle is | |
783 | * returned. On any subsequent calls to acquire by the same thread, the same | |
784 | * handle is returned. | |
785 | * | |
1da177e4 | 786 | ******************************************************************************/ |
4be44fcd | 787 | acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle) |
1da177e4 | 788 | { |
4be44fcd | 789 | acpi_status status; |
1da177e4 LT |
790 | |
791 | if (!handle) { | |
792 | return (AE_BAD_PARAMETER); | |
793 | } | |
794 | ||
4d2acd9e | 795 | /* Must lock interpreter to prevent race conditions */ |
1da177e4 | 796 | |
4d2acd9e | 797 | acpi_ex_enter_interpreter(); |
ba886cd4 BM |
798 | |
799 | status = acpi_ex_acquire_mutex_object(timeout, | |
800 | acpi_gbl_global_lock_mutex, | |
801 | acpi_os_get_thread_id()); | |
1da177e4 | 802 | |
4be44fcd | 803 | if (ACPI_SUCCESS(status)) { |
ba886cd4 | 804 | |
e5567afa | 805 | /* Return the global lock handle (updated in acpi_ev_acquire_global_lock) */ |
ba886cd4 | 806 | |
1da177e4 LT |
807 | *handle = acpi_gbl_global_lock_handle; |
808 | } | |
809 | ||
ba886cd4 | 810 | acpi_ex_exit_interpreter(); |
1da177e4 LT |
811 | return (status); |
812 | } | |
1da177e4 | 813 | |
8313524a | 814 | ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock) |
1da177e4 LT |
815 | |
816 | /******************************************************************************* | |
817 | * | |
818 | * FUNCTION: acpi_release_global_lock | |
819 | * | |
820 | * PARAMETERS: Handle - Returned from acpi_acquire_global_lock | |
821 | * | |
822 | * RETURN: Status | |
823 | * | |
44f6c012 | 824 | * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid. |
1da177e4 LT |
825 | * |
826 | ******************************************************************************/ | |
4be44fcd | 827 | acpi_status acpi_release_global_lock(u32 handle) |
1da177e4 | 828 | { |
4be44fcd | 829 | acpi_status status; |
1da177e4 | 830 | |
f02e9fa1 | 831 | if (!handle || (handle != acpi_gbl_global_lock_handle)) { |
1da177e4 LT |
832 | return (AE_NOT_ACQUIRED); |
833 | } | |
834 | ||
ba886cd4 | 835 | status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex); |
1da177e4 LT |
836 | return (status); |
837 | } | |
1da177e4 | 838 | |
8313524a | 839 | ACPI_EXPORT_SYMBOL(acpi_release_global_lock) |
33620c54 | 840 | #endif /* !ACPI_REDUCED_HARDWARE */ |