[PATCH] fix semaphore handling in __unregister_chrdev_region
[linux/fpc-iii.git] / drivers / acpi / events / evxface.c
blob0bfec10a5f1e90dc11e4b1616117b0244760671a
1 /******************************************************************************
3 * Module Name: evxface - External interfaces for ACPI events
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
44 #include <linux/module.h>
46 #include <acpi/acpi.h>
47 #include <acpi/acnamesp.h>
48 #include <acpi/acevents.h>
49 #include <acpi/acinterp.h>
51 #define _COMPONENT ACPI_EVENTS
52 ACPI_MODULE_NAME ("evxface")
55 /*******************************************************************************
57 * FUNCTION: acpi_install_exception_handler
59 * PARAMETERS: Handler - Pointer to the handler function for the
60 * event
62 * RETURN: Status
64 * DESCRIPTION: Saves the pointer to the handler function
66 ******************************************************************************/
67 #ifdef ACPI_FUTURE_USAGE
68 acpi_status
69 acpi_install_exception_handler (
70 acpi_exception_handler handler)
72 acpi_status status;
75 ACPI_FUNCTION_TRACE ("acpi_install_exception_handler");
78 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
79 if (ACPI_FAILURE (status)) {
80 return_ACPI_STATUS (status);
83 /* Don't allow two handlers. */
85 if (acpi_gbl_exception_handler) {
86 status = AE_ALREADY_EXISTS;
87 goto cleanup;
90 /* Install the handler */
92 acpi_gbl_exception_handler = handler;
94 cleanup:
95 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
96 return_ACPI_STATUS (status);
98 #endif /* ACPI_FUTURE_USAGE */
101 /*******************************************************************************
103 * FUNCTION: acpi_install_fixed_event_handler
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
110 * RETURN: Status
112 * DESCRIPTION: Saves the pointer to the handler function and then enables the
113 * event.
115 ******************************************************************************/
117 acpi_status
118 acpi_install_fixed_event_handler (
119 u32 event,
120 acpi_event_handler handler,
121 void *context)
123 acpi_status status;
126 ACPI_FUNCTION_TRACE ("acpi_install_fixed_event_handler");
129 /* Parameter validation */
131 if (event > ACPI_EVENT_MAX) {
132 return_ACPI_STATUS (AE_BAD_PARAMETER);
135 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
136 if (ACPI_FAILURE (status)) {
137 return_ACPI_STATUS (status);
140 /* Don't allow two handlers. */
142 if (NULL != acpi_gbl_fixed_event_handlers[event].handler) {
143 status = AE_ALREADY_EXISTS;
144 goto cleanup;
147 /* Install the handler before enabling the event */
149 acpi_gbl_fixed_event_handlers[event].handler = handler;
150 acpi_gbl_fixed_event_handlers[event].context = context;
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"));
158 /* Remove the handler */
160 acpi_gbl_fixed_event_handlers[event].handler = NULL;
161 acpi_gbl_fixed_event_handlers[event].context = NULL;
163 else {
164 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
165 "Enabled fixed event %X, Handler=%p\n", event, handler));
169 cleanup:
170 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
171 return_ACPI_STATUS (status);
173 EXPORT_SYMBOL(acpi_install_fixed_event_handler);
176 /*******************************************************************************
178 * FUNCTION: acpi_remove_fixed_event_handler
180 * PARAMETERS: Event - Event type to disable.
181 * Handler - Address of the handler
183 * RETURN: Status
185 * DESCRIPTION: Disables the event and unregisters the event handler.
187 ******************************************************************************/
189 acpi_status
190 acpi_remove_fixed_event_handler (
191 u32 event,
192 acpi_event_handler handler)
194 acpi_status status = AE_OK;
197 ACPI_FUNCTION_TRACE ("acpi_remove_fixed_event_handler");
200 /* Parameter validation */
202 if (event > ACPI_EVENT_MAX) {
203 return_ACPI_STATUS (AE_BAD_PARAMETER);
206 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
207 if (ACPI_FAILURE (status)) {
208 return_ACPI_STATUS (status);
211 /* Disable the event before removing the handler */
213 status = acpi_disable_event (event, 0);
215 /* Always Remove the handler */
217 acpi_gbl_fixed_event_handlers[event].handler = NULL;
218 acpi_gbl_fixed_event_handlers[event].context = NULL;
220 if (ACPI_FAILURE (status)) {
221 ACPI_DEBUG_PRINT ((ACPI_DB_WARN,
222 "Could not write to fixed event enable register.\n"));
224 else {
225 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Disabled fixed event %X.\n", event));
228 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
229 return_ACPI_STATUS (status);
231 EXPORT_SYMBOL(acpi_remove_fixed_event_handler);
234 /*******************************************************************************
236 * FUNCTION: acpi_install_notify_handler
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
246 * RETURN: Status
248 * DESCRIPTION: Install a handler for notifies on an ACPI device
250 ******************************************************************************/
252 acpi_status
253 acpi_install_notify_handler (
254 acpi_handle device,
255 u32 handler_type,
256 acpi_notify_handler handler,
257 void *context)
259 union acpi_operand_object *obj_desc;
260 union acpi_operand_object *notify_obj;
261 struct acpi_namespace_node *node;
262 acpi_status status;
265 ACPI_FUNCTION_TRACE ("acpi_install_notify_handler");
268 /* Parameter validation */
270 if ((!device) ||
271 (!handler) ||
272 (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
273 return_ACPI_STATUS (AE_BAD_PARAMETER);
276 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
277 if (ACPI_FAILURE (status)) {
278 return_ACPI_STATUS (status);
281 /* Convert and validate the device handle */
283 node = acpi_ns_map_handle_to_node (device);
284 if (!node) {
285 status = AE_BAD_PARAMETER;
286 goto unlock_and_exit;
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).
295 if (device == ACPI_ROOT_OBJECT) {
296 /* Make sure the handler is not already installed */
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;
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;
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;
318 /* Global notify handler installed */
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.
326 else {
327 /* Notifies allowed on this object? */
329 if (!acpi_ev_is_notify_object (node)) {
330 status = AE_TYPE;
331 goto unlock_and_exit;
334 /* Check for an existing internal object */
336 obj_desc = acpi_ns_get_attached_object (node);
337 if (obj_desc) {
338 /* Object exists - make sure there's no handler */
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;
348 else {
349 /* Create a new object */
351 obj_desc = acpi_ut_create_internal_object (node->type);
352 if (!obj_desc) {
353 status = AE_NO_MEMORY;
354 goto unlock_and_exit;
357 /* Attach new object to the Node */
359 status = acpi_ns_attach_object (device, obj_desc, node->type);
361 /* Remove local reference to the object */
363 acpi_ut_remove_reference (obj_desc);
364 if (ACPI_FAILURE (status)) {
365 goto unlock_and_exit;
369 /* Install the handler */
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;
377 notify_obj->notify.node = node;
378 notify_obj->notify.handler = handler;
379 notify_obj->notify.context = context;
381 if (handler_type & ACPI_SYSTEM_NOTIFY) {
382 obj_desc->common_notify.system_notify = notify_obj;
385 if (handler_type & ACPI_DEVICE_NOTIFY) {
386 obj_desc->common_notify.device_notify = notify_obj;
389 if (handler_type == ACPI_ALL_NOTIFY) {
390 /* Extra ref if installed in both */
392 acpi_ut_add_reference (notify_obj);
397 unlock_and_exit:
398 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
399 return_ACPI_STATUS (status);
401 EXPORT_SYMBOL(acpi_install_notify_handler);
404 /*******************************************************************************
406 * FUNCTION: acpi_remove_notify_handler
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
415 * RETURN: Status
417 * DESCRIPTION: Remove a handler for notifies on an ACPI device
419 ******************************************************************************/
421 acpi_status
422 acpi_remove_notify_handler (
423 acpi_handle device,
424 u32 handler_type,
425 acpi_notify_handler handler)
427 union acpi_operand_object *notify_obj;
428 union acpi_operand_object *obj_desc;
429 struct acpi_namespace_node *node;
430 acpi_status status;
433 ACPI_FUNCTION_TRACE ("acpi_remove_notify_handler");
436 /* Parameter validation */
438 if ((!device) ||
439 (!handler) ||
440 (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
441 return_ACPI_STATUS (AE_BAD_PARAMETER);
444 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
445 if (ACPI_FAILURE (status)) {
446 return_ACPI_STATUS (status);
449 /* Convert and validate the device handle */
451 node = acpi_ns_map_handle_to_node (device);
452 if (!node) {
453 status = AE_BAD_PARAMETER;
454 goto unlock_and_exit;
457 /* Root Object */
459 if (device == ACPI_ROOT_OBJECT) {
460 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Removing notify handler for ROOT object.\n"));
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;
470 /* Make sure all deferred tasks are completed */
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);
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;
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;
492 /* All Other Objects */
494 else {
495 /* Notifies allowed on this object? */
497 if (!acpi_ev_is_notify_object (node)) {
498 status = AE_TYPE;
499 goto unlock_and_exit;
502 /* Check for an existing internal object */
504 obj_desc = acpi_ns_get_attached_object (node);
505 if (!obj_desc) {
506 status = AE_NOT_EXIST;
507 goto unlock_and_exit;
510 /* Object exists - make sure there's an existing handler */
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;
519 /* Make sure all deferred tasks are completed */
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);
528 /* Remove the handler */
529 obj_desc->common_notify.system_notify = NULL;
530 acpi_ut_remove_reference (notify_obj);
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;
540 /* Make sure all deferred tasks are completed */
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);
549 /* Remove the handler */
550 obj_desc->common_notify.device_notify = NULL;
551 acpi_ut_remove_reference (notify_obj);
556 unlock_and_exit:
557 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
558 return_ACPI_STATUS (status);
560 EXPORT_SYMBOL(acpi_remove_notify_handler);
563 /*******************************************************************************
565 * FUNCTION: acpi_install_gpe_handler
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
574 * RETURN: Status
576 * DESCRIPTION: Install a handler for a General Purpose Event.
578 ******************************************************************************/
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)
588 struct acpi_gpe_event_info *gpe_event_info;
589 struct acpi_handler_info *handler;
590 acpi_status status;
593 ACPI_FUNCTION_TRACE ("acpi_install_gpe_handler");
596 /* Parameter validation */
598 if ((!address) || (type > ACPI_GPE_XRUPT_TYPE_MASK)) {
599 return_ACPI_STATUS (AE_BAD_PARAMETER);
602 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
603 if (ACPI_FAILURE (status)) {
604 return_ACPI_STATUS (status);
607 /* Ensure that we have a valid GPE number */
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;
615 /* Make sure that there isn't a handler there already */
617 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_HANDLER) {
618 status = AE_ALREADY_EXISTS;
619 goto unlock_and_exit;
622 /* Allocate and init handler object */
624 handler = ACPI_MEM_CALLOCATE (sizeof (struct acpi_handler_info));
625 if (!handler) {
626 status = AE_NO_MEMORY;
627 goto unlock_and_exit;
630 handler->address = address;
631 handler->context = context;
632 handler->method_node = gpe_event_info->dispatch.method_node;
634 /* Disable the GPE before installing the handler */
636 status = acpi_ev_disable_gpe (gpe_event_info);
637 if (ACPI_FAILURE (status)) {
638 goto unlock_and_exit;
641 /* Install the handler */
643 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
644 gpe_event_info->dispatch.handler = handler;
646 /* Setup up dispatch flags to indicate handler (vs. method) */
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);
651 acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
654 unlock_and_exit:
655 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
656 return_ACPI_STATUS (status);
658 EXPORT_SYMBOL(acpi_install_gpe_handler);
661 /*******************************************************************************
663 * FUNCTION: acpi_remove_gpe_handler
665 * PARAMETERS: gpe_number - The event to remove a handler
666 * gpe_block - GPE block (NULL == FADT GPEs)
667 * Address - Address of the handler
669 * RETURN: Status
671 * DESCRIPTION: Remove a handler for a General Purpose acpi_event.
673 ******************************************************************************/
675 acpi_status
676 acpi_remove_gpe_handler (
677 acpi_handle gpe_device,
678 u32 gpe_number,
679 acpi_event_handler address)
681 struct acpi_gpe_event_info *gpe_event_info;
682 struct acpi_handler_info *handler;
683 acpi_status status;
686 ACPI_FUNCTION_TRACE ("acpi_remove_gpe_handler");
689 /* Parameter validation */
691 if (!address) {
692 return_ACPI_STATUS (AE_BAD_PARAMETER);
695 status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
696 if (ACPI_FAILURE (status)) {
697 return_ACPI_STATUS (status);
700 /* Ensure that we have a valid GPE number */
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;
708 /* Make sure that a handler is indeed installed */
710 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) != ACPI_GPE_DISPATCH_HANDLER) {
711 status = AE_NOT_EXIST;
712 goto unlock_and_exit;
715 /* Make sure that the installed handler is the same */
717 if (gpe_event_info->dispatch.handler->address != address) {
718 status = AE_BAD_PARAMETER;
719 goto unlock_and_exit;
722 /* Disable the GPE before removing the handler */
724 status = acpi_ev_disable_gpe (gpe_event_info);
725 if (ACPI_FAILURE (status)) {
726 goto unlock_and_exit;
729 /* Make sure all deferred tasks are completed */
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);
738 /* Remove the handler */
740 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
741 handler = gpe_event_info->dispatch.handler;
743 /* Restore Method node (if any), set dispatch flags */
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;
750 acpi_os_release_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
752 /* Now we can free the handler object */
754 ACPI_MEM_FREE (handler);
757 unlock_and_exit:
758 (void) acpi_ut_release_mutex (ACPI_MTX_EVENTS);
759 return_ACPI_STATUS (status);
761 EXPORT_SYMBOL(acpi_remove_gpe_handler);
764 /*******************************************************************************
766 * FUNCTION: acpi_acquire_global_lock
768 * PARAMETERS: Timeout - How long the caller is willing to wait
769 * out_handle - A handle to the lock if acquired
771 * RETURN: Status
773 * DESCRIPTION: Acquire the ACPI Global Lock
775 ******************************************************************************/
777 acpi_status
778 acpi_acquire_global_lock (
779 u16 timeout,
780 u32 *handle)
782 acpi_status status;
785 if (!handle) {
786 return (AE_BAD_PARAMETER);
789 status = acpi_ex_enter_interpreter ();
790 if (ACPI_FAILURE (status)) {
791 return (status);
794 status = acpi_ev_acquire_global_lock (timeout);
795 acpi_ex_exit_interpreter ();
797 if (ACPI_SUCCESS (status)) {
798 acpi_gbl_global_lock_handle++;
799 *handle = acpi_gbl_global_lock_handle;
802 return (status);
804 EXPORT_SYMBOL(acpi_acquire_global_lock);
807 /*******************************************************************************
809 * FUNCTION: acpi_release_global_lock
811 * PARAMETERS: Handle - Returned from acpi_acquire_global_lock
813 * RETURN: Status
815 * DESCRIPTION: Release the ACPI Global Lock
817 ******************************************************************************/
819 acpi_status
820 acpi_release_global_lock (
821 u32 handle)
823 acpi_status status;
826 if (handle != acpi_gbl_global_lock_handle) {
827 return (AE_NOT_ACQUIRED);
830 status = acpi_ev_release_global_lock ();
831 return (status);
833 EXPORT_SYMBOL(acpi_release_global_lock);