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