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