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