blob: 14e48add32fa0ede706a120b87d3a885e8ecbf0f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evxface - External interfaces for ACPI events
4 *
5 *****************************************************************************/
6
7/*
Bob Moorea8357b02010-01-22 19:07:36 +08008 * Copyright (C) 2000 - 2010, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acnamesp.h"
47#include "acevents.h"
48#include "acinterp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("evxface")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_install_exception_handler
56 *
57 * PARAMETERS: Handler - Pointer to the handler function for the
58 * event
59 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: Saves the pointer to the handler function
63 *
64 ******************************************************************************/
65#ifdef ACPI_FUTURE_USAGE
Len Brown4be44fc2005-08-05 00:44:28 -040066acpi_status acpi_install_exception_handler(acpi_exception_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Len Brown4be44fc2005-08-05 00:44:28 -040068 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Bob Mooreb229cf92006-04-21 17:15:00 -040070 ACPI_FUNCTION_TRACE(acpi_install_exception_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Len Brown4be44fc2005-08-05 00:44:28 -040072 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
73 if (ACPI_FAILURE(status)) {
74 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
76
77 /* Don't allow two handlers. */
78
79 if (acpi_gbl_exception_handler) {
80 status = AE_ALREADY_EXISTS;
81 goto cleanup;
82 }
83
84 /* Install the handler */
85
86 acpi_gbl_exception_handler = handler;
87
Len Brown4be44fc2005-08-05 00:44:28 -040088 cleanup:
89 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
90 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
Bob Moore83135242006-10-03 00:00:00 -040092
93ACPI_EXPORT_SYMBOL(acpi_install_exception_handler)
Len Brown4be44fc2005-08-05 00:44:28 -040094#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095/*******************************************************************************
96 *
97 * FUNCTION: acpi_install_fixed_event_handler
98 *
99 * PARAMETERS: Event - Event type to enable.
100 * Handler - Pointer to the handler function for the
101 * event
102 * Context - Value passed to the handler on each GPE
103 *
104 * RETURN: Status
105 *
106 * DESCRIPTION: Saves the pointer to the handler function and then enables the
107 * event.
108 *
109 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400111acpi_install_fixed_event_handler(u32 event,
112 acpi_event_handler handler, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
Len Brown4be44fc2005-08-05 00:44:28 -0400114 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Bob Mooreb229cf92006-04-21 17:15:00 -0400116 ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 /* Parameter validation */
119
120 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400121 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123
Len Brown4be44fc2005-08-05 00:44:28 -0400124 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
125 if (ACPI_FAILURE(status)) {
126 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128
129 /* Don't allow two handlers. */
130
131 if (NULL != acpi_gbl_fixed_event_handlers[event].handler) {
132 status = AE_ALREADY_EXISTS;
133 goto cleanup;
134 }
135
136 /* Install the handler before enabling the event */
137
138 acpi_gbl_fixed_event_handlers[event].handler = handler;
139 acpi_gbl_fixed_event_handlers[event].context = context;
140
Len Brown4be44fc2005-08-05 00:44:28 -0400141 status = acpi_clear_event(event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400143 status = acpi_enable_event(event, 0);
144 if (ACPI_FAILURE(status)) {
Bob Mooref6a22b02010-03-05 17:56:40 +0800145 ACPI_WARNING((AE_INFO, "Could not enable fixed event 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500146 event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 /* Remove the handler */
149
150 acpi_gbl_fixed_event_handlers[event].handler = NULL;
151 acpi_gbl_fixed_event_handlers[event].context = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400152 } else {
153 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
154 "Enabled fixed event %X, Handler=%p\n", event,
155 handler));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
Len Brown4be44fc2005-08-05 00:44:28 -0400158 cleanup:
159 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
160 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Bob Moore83135242006-10-03 00:00:00 -0400163ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165/*******************************************************************************
166 *
167 * FUNCTION: acpi_remove_fixed_event_handler
168 *
169 * PARAMETERS: Event - Event type to disable.
170 * Handler - Address of the handler
171 *
172 * RETURN: Status
173 *
174 * DESCRIPTION: Disables the event and unregisters the event handler.
175 *
176 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400178acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
Len Brown4be44fc2005-08-05 00:44:28 -0400180 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Bob Mooreb229cf92006-04-21 17:15:00 -0400182 ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 /* Parameter validation */
185
186 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400187 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
189
Len Brown4be44fc2005-08-05 00:44:28 -0400190 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
191 if (ACPI_FAILURE(status)) {
192 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 }
194
195 /* Disable the event before removing the handler */
196
Len Brown4be44fc2005-08-05 00:44:28 -0400197 status = acpi_disable_event(event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199 /* Always Remove the handler */
200
201 acpi_gbl_fixed_event_handlers[event].handler = NULL;
202 acpi_gbl_fixed_event_handlers[event].context = NULL;
203
Len Brown4be44fc2005-08-05 00:44:28 -0400204 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500205 ACPI_WARNING((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800206 "Could not write to fixed event enable register 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500207 event));
Len Brown4be44fc2005-08-05 00:44:28 -0400208 } else {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500209 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Disabled fixed event %X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400210 event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
212
Len Brown4be44fc2005-08-05 00:44:28 -0400213 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
214 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Bob Moore83135242006-10-03 00:00:00 -0400217ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219/*******************************************************************************
220 *
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100221 * FUNCTION: acpi_populate_handler_object
222 *
223 * PARAMETERS: handler_obj - Handler object to populate
224 * handler_type - The type of handler:
225 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
226 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
227 * ACPI_ALL_NOTIFY: both system and device
228 * handler - Address of the handler
229 * context - Value passed to the handler on each GPE
230 * next - Address of a handler object to link to
231 *
232 * RETURN: None
233 *
234 * DESCRIPTION: Populate a handler object.
235 *
236 ******************************************************************************/
237static void
238acpi_populate_handler_object(struct acpi_object_notify_handler *handler_obj,
239 u32 handler_type,
240 acpi_notify_handler handler, void *context,
241 struct acpi_object_notify_handler *next)
242{
243 handler_obj->handler_type = handler_type;
244 handler_obj->handler = handler;
245 handler_obj->context = context;
246 handler_obj->next = next;
247}
248
249/*******************************************************************************
250 *
251 * FUNCTION: acpi_add_handler_object
252 *
253 * PARAMETERS: parent_obj - Parent of the new object
254 * handler - Address of the handler
255 * context - Value passed to the handler on each GPE
256 *
257 * RETURN: Status
258 *
259 * DESCRIPTION: Create a new handler object and populate it.
260 *
261 ******************************************************************************/
262static acpi_status
263acpi_add_handler_object(struct acpi_object_notify_handler *parent_obj,
264 acpi_notify_handler handler, void *context)
265{
266 struct acpi_object_notify_handler *handler_obj;
267
268 /* The parent must not be a defice notify handler object. */
269 if (parent_obj->handler_type & ACPI_DEVICE_NOTIFY)
270 return AE_BAD_PARAMETER;
271
272 handler_obj = ACPI_ALLOCATE_ZEROED(sizeof(*handler_obj));
273 if (!handler_obj)
274 return AE_NO_MEMORY;
275
276 acpi_populate_handler_object(handler_obj,
277 ACPI_SYSTEM_NOTIFY,
278 handler, context,
279 parent_obj->next);
280 parent_obj->next = handler_obj;
281
282 return AE_OK;
283}
284
285/*******************************************************************************
286 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 * FUNCTION: acpi_install_notify_handler
288 *
289 * PARAMETERS: Device - The device for which notifies will be handled
290 * handler_type - The type of handler:
291 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
292 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
293 * ACPI_ALL_NOTIFY: both system and device
294 * Handler - Address of the handler
295 * Context - Value passed to the handler on each GPE
296 *
297 * RETURN: Status
298 *
299 * DESCRIPTION: Install a handler for notifies on an ACPI device
300 *
301 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400303acpi_install_notify_handler(acpi_handle device,
304 u32 handler_type,
305 acpi_notify_handler handler, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
Len Brown4be44fc2005-08-05 00:44:28 -0400307 union acpi_operand_object *obj_desc;
308 union acpi_operand_object *notify_obj;
309 struct acpi_namespace_node *node;
310 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Bob Mooreb229cf92006-04-21 17:15:00 -0400312 ACPI_FUNCTION_TRACE(acpi_install_notify_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 /* Parameter validation */
315
Len Brown4be44fc2005-08-05 00:44:28 -0400316 if ((!device) ||
317 (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
318 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 }
320
Len Brown4be44fc2005-08-05 00:44:28 -0400321 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
322 if (ACPI_FAILURE(status)) {
323 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 }
325
326 /* Convert and validate the device handle */
327
Bob Mooref24b6642009-12-11 14:57:00 +0800328 node = acpi_ns_validate_handle(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 if (!node) {
330 status = AE_BAD_PARAMETER;
331 goto unlock_and_exit;
332 }
333
334 /*
335 * Root Object:
336 * Registering a notify handler on the root object indicates that the
Bob Moore9f15fc62008-11-12 16:01:56 +0800337 * caller wishes to receive notifications for all objects. Note that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 * only one <external> global handler can be regsitered (per notify type).
339 */
340 if (device == ACPI_ROOT_OBJECT) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 /* Make sure the handler is not already installed */
343
344 if (((handler_type & ACPI_SYSTEM_NOTIFY) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400345 acpi_gbl_system_notify.handler) ||
346 ((handler_type & ACPI_DEVICE_NOTIFY) &&
347 acpi_gbl_device_notify.handler)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 status = AE_ALREADY_EXISTS;
349 goto unlock_and_exit;
350 }
351
352 if (handler_type & ACPI_SYSTEM_NOTIFY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400353 acpi_gbl_system_notify.node = node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 acpi_gbl_system_notify.handler = handler;
355 acpi_gbl_system_notify.context = context;
356 }
357
358 if (handler_type & ACPI_DEVICE_NOTIFY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400359 acpi_gbl_device_notify.node = node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 acpi_gbl_device_notify.handler = handler;
361 acpi_gbl_device_notify.context = context;
362 }
363
364 /* Global notify handler installed */
365 }
366
367 /*
368 * All Other Objects:
369 * Caller will only receive notifications specific to the target object.
370 * Note that only certain object types can receive notifications.
371 */
372 else {
373 /* Notifies allowed on this object? */
374
Len Brown4be44fc2005-08-05 00:44:28 -0400375 if (!acpi_ev_is_notify_object(node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 status = AE_TYPE;
377 goto unlock_and_exit;
378 }
379
380 /* Check for an existing internal object */
381
Len Brown4be44fc2005-08-05 00:44:28 -0400382 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 if (obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400384
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100385 /* Object exists. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100387 /* For a device notify, make sure there's no handler. */
388 if ((handler_type & ACPI_DEVICE_NOTIFY) &&
389 obj_desc->common_notify.device_notify) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 status = AE_ALREADY_EXISTS;
391 goto unlock_and_exit;
392 }
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100393
394 /* System notifies may have more handlers installed. */
395 notify_obj = obj_desc->common_notify.system_notify;
396
397 if ((handler_type & ACPI_SYSTEM_NOTIFY) && notify_obj) {
398 struct acpi_object_notify_handler *parent_obj;
399
400 if (handler_type & ACPI_DEVICE_NOTIFY) {
401 status = AE_ALREADY_EXISTS;
402 goto unlock_and_exit;
403 }
404
405 parent_obj = &notify_obj->notify;
406 status = acpi_add_handler_object(parent_obj,
407 handler,
408 context);
409 goto unlock_and_exit;
410 }
Len Brown4be44fc2005-08-05 00:44:28 -0400411 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 /* Create a new object */
413
Len Brown4be44fc2005-08-05 00:44:28 -0400414 obj_desc = acpi_ut_create_internal_object(node->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 if (!obj_desc) {
416 status = AE_NO_MEMORY;
417 goto unlock_and_exit;
418 }
419
420 /* Attach new object to the Node */
421
Len Brown4be44fc2005-08-05 00:44:28 -0400422 status =
423 acpi_ns_attach_object(device, obj_desc, node->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 /* Remove local reference to the object */
426
Len Brown4be44fc2005-08-05 00:44:28 -0400427 acpi_ut_remove_reference(obj_desc);
428 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 goto unlock_and_exit;
430 }
431 }
432
433 /* Install the handler */
434
Len Brown4be44fc2005-08-05 00:44:28 -0400435 notify_obj =
436 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 if (!notify_obj) {
438 status = AE_NO_MEMORY;
439 goto unlock_and_exit;
440 }
441
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100442 acpi_populate_handler_object(&notify_obj->notify,
443 handler_type,
444 handler, context,
445 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 if (handler_type & ACPI_SYSTEM_NOTIFY) {
448 obj_desc->common_notify.system_notify = notify_obj;
449 }
450
451 if (handler_type & ACPI_DEVICE_NOTIFY) {
452 obj_desc->common_notify.device_notify = notify_obj;
453 }
454
455 if (handler_type == ACPI_ALL_NOTIFY) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 /* Extra ref if installed in both */
458
Len Brown4be44fc2005-08-05 00:44:28 -0400459 acpi_ut_add_reference(notify_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 }
461 }
462
Len Brown4be44fc2005-08-05 00:44:28 -0400463 unlock_and_exit:
464 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
465 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Bob Moore83135242006-10-03 00:00:00 -0400468ACPI_EXPORT_SYMBOL(acpi_install_notify_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470/*******************************************************************************
471 *
472 * FUNCTION: acpi_remove_notify_handler
473 *
474 * PARAMETERS: Device - The device for which notifies will be handled
475 * handler_type - The type of handler:
476 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
477 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
478 * ACPI_ALL_NOTIFY: both system and device
479 * Handler - Address of the handler
480 *
481 * RETURN: Status
482 *
483 * DESCRIPTION: Remove a handler for notifies on an ACPI device
484 *
485 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400487acpi_remove_notify_handler(acpi_handle device,
488 u32 handler_type, acpi_notify_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
Len Brown4be44fc2005-08-05 00:44:28 -0400490 union acpi_operand_object *notify_obj;
491 union acpi_operand_object *obj_desc;
492 struct acpi_namespace_node *node;
493 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Bob Mooreb229cf92006-04-21 17:15:00 -0400495 ACPI_FUNCTION_TRACE(acpi_remove_notify_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 /* Parameter validation */
498
Len Brown4be44fc2005-08-05 00:44:28 -0400499 if ((!device) ||
500 (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
Thomas Renningere8406b42006-06-02 15:58:00 -0400501 status = AE_BAD_PARAMETER;
502 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 }
504
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100505
506 /* Make sure all deferred tasks are completed */
507 acpi_os_wait_events_complete(NULL);
508
Len Brown4be44fc2005-08-05 00:44:28 -0400509 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
510 if (ACPI_FAILURE(status)) {
Thomas Renningere8406b42006-06-02 15:58:00 -0400511 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 }
513
514 /* Convert and validate the device handle */
515
Bob Mooref24b6642009-12-11 14:57:00 +0800516 node = acpi_ns_validate_handle(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 if (!node) {
518 status = AE_BAD_PARAMETER;
Bob Mooref6dd9222006-07-07 20:44:38 -0400519 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
521
522 /* Root Object */
523
524 if (device == ACPI_ROOT_OBJECT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400525 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Moore4a90c7e2006-01-13 16:22:00 -0500526 "Removing notify handler for namespace root object\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 if (((handler_type & ACPI_SYSTEM_NOTIFY) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400529 !acpi_gbl_system_notify.handler) ||
530 ((handler_type & ACPI_DEVICE_NOTIFY) &&
531 !acpi_gbl_device_notify.handler)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 status = AE_NOT_EXIST;
Bob Mooref6dd9222006-07-07 20:44:38 -0400533 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 if (handler_type & ACPI_SYSTEM_NOTIFY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400537 acpi_gbl_system_notify.node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 acpi_gbl_system_notify.handler = NULL;
539 acpi_gbl_system_notify.context = NULL;
540 }
541
542 if (handler_type & ACPI_DEVICE_NOTIFY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400543 acpi_gbl_device_notify.node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 acpi_gbl_device_notify.handler = NULL;
545 acpi_gbl_device_notify.context = NULL;
546 }
547 }
548
549 /* All Other Objects */
550
551 else {
552 /* Notifies allowed on this object? */
553
Len Brown4be44fc2005-08-05 00:44:28 -0400554 if (!acpi_ev_is_notify_object(node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 status = AE_TYPE;
Bob Mooref6dd9222006-07-07 20:44:38 -0400556 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558
559 /* Check for an existing internal object */
560
Len Brown4be44fc2005-08-05 00:44:28 -0400561 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (!obj_desc) {
563 status = AE_NOT_EXIST;
Bob Mooref6dd9222006-07-07 20:44:38 -0400564 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 }
566
567 /* Object exists - make sure there's an existing handler */
568
569 if (handler_type & ACPI_SYSTEM_NOTIFY) {
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100570 struct acpi_object_notify_handler *handler_obj;
571 struct acpi_object_notify_handler *parent_obj;
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 notify_obj = obj_desc->common_notify.system_notify;
Bob Mooref6dd9222006-07-07 20:44:38 -0400574 if (!notify_obj) {
575 status = AE_NOT_EXIST;
576 goto unlock_and_exit;
577 }
578
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100579 handler_obj = &notify_obj->notify;
580 parent_obj = NULL;
581 while (handler_obj->handler != handler) {
582 if (handler_obj->next) {
583 parent_obj = handler_obj;
584 handler_obj = handler_obj->next;
585 } else {
586 break;
587 }
588 }
589
590 if (handler_obj->handler != handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 status = AE_BAD_PARAMETER;
Bob Mooref6dd9222006-07-07 20:44:38 -0400592 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100595 /*
596 * Remove the handler. There are three possible cases.
597 * First, we may need to remove a non-embedded object.
598 * Second, we may need to remove the embedded object's
599 * handler data, while non-embedded objects exist.
600 * Finally, we may need to remove the embedded object
601 * entirely along with its container.
602 */
603 if (parent_obj) {
604 /* Non-embedded object is being removed. */
605 parent_obj->next = handler_obj->next;
606 ACPI_FREE(handler_obj);
607 } else if (notify_obj->notify.next) {
608 /*
609 * The handler matches the embedded object, but
610 * there are more handler objects in the list.
611 * Replace the embedded object's data with the
612 * first next object's data and remove that
613 * object.
614 */
615 parent_obj = &notify_obj->notify;
616 handler_obj = notify_obj->notify.next;
617 *parent_obj = *handler_obj;
618 ACPI_FREE(handler_obj);
619 } else {
620 /* No more handler objects in the list. */
621 obj_desc->common_notify.system_notify = NULL;
622 acpi_ut_remove_reference(notify_obj);
Len Brown4be44fc2005-08-05 00:44:28 -0400623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 }
625
626 if (handler_type & ACPI_DEVICE_NOTIFY) {
627 notify_obj = obj_desc->common_notify.device_notify;
Bob Mooref6dd9222006-07-07 20:44:38 -0400628 if (!notify_obj) {
629 status = AE_NOT_EXIST;
630 goto unlock_and_exit;
631 }
632
633 if (notify_obj->notify.handler != handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 status = AE_BAD_PARAMETER;
Bob Mooref6dd9222006-07-07 20:44:38 -0400635 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
638 /* Remove the handler */
639 obj_desc->common_notify.device_notify = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400640 acpi_ut_remove_reference(notify_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 }
642 }
643
Bob Mooref6dd9222006-07-07 20:44:38 -0400644 unlock_and_exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400645 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Bob Mooref6dd9222006-07-07 20:44:38 -0400646 exit:
Thomas Renningere8406b42006-06-02 15:58:00 -0400647 if (ACPI_FAILURE(status))
648 ACPI_EXCEPTION((AE_INFO, status, "Removing notify handler"));
Len Brown4be44fc2005-08-05 00:44:28 -0400649 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Bob Moore83135242006-10-03 00:00:00 -0400652ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654/*******************************************************************************
655 *
656 * FUNCTION: acpi_install_gpe_handler
657 *
Robert Moore44f6c012005-04-18 22:49:35 -0400658 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
659 * defined GPEs)
660 * gpe_number - The GPE number within the GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 * Type - Whether this GPE should be treated as an
662 * edge- or level-triggered interrupt.
663 * Address - Address of the handler
664 * Context - Value passed to the handler on each GPE
665 *
666 * RETURN: Status
667 *
668 * DESCRIPTION: Install a handler for a General Purpose Event.
669 *
670 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400672acpi_install_gpe_handler(acpi_handle gpe_device,
673 u32 gpe_number,
674 u32 type, acpi_event_handler address, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675{
Len Brown4be44fc2005-08-05 00:44:28 -0400676 struct acpi_gpe_event_info *gpe_event_info;
677 struct acpi_handler_info *handler;
678 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500679 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Bob Mooreb229cf92006-04-21 17:15:00 -0400681 ACPI_FUNCTION_TRACE(acpi_install_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683 /* Parameter validation */
684
Lin Ming0f849d22010-04-06 14:52:37 +0800685 if ((!address) || (type & ~ACPI_GPE_XRUPT_TYPE_MASK)) {
686 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 }
688
Len Brown4be44fc2005-08-05 00:44:28 -0400689 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
690 if (ACPI_FAILURE(status)) {
Lin Ming0f849d22010-04-06 14:52:37 +0800691 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 }
693
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200694 /* Allocate memory for the handler object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Bob Moore83135242006-10-03 00:00:00 -0400696 handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_handler_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 if (!handler) {
698 status = AE_NO_MEMORY;
Bob Mooref6dd9222006-07-07 20:44:38 -0400699 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200702 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
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 free_and_exit;
710 }
711
712 /* Make sure that there isn't a handler there already */
713
714 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
715 ACPI_GPE_DISPATCH_HANDLER) {
716 status = AE_ALREADY_EXISTS;
717 goto free_and_exit;
718 }
719
720 /* Allocate and init handler object */
721
Len Brown4be44fc2005-08-05 00:44:28 -0400722 handler->address = address;
723 handler->context = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 handler->method_node = gpe_event_info->dispatch.method_node;
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200725 handler->orig_flags = gpe_event_info->flags &
726 (ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
727
728 /*
729 * If the GPE is associated with a method and it cannot wake up the
730 * system from sleep states, it was enabled automatically during
731 * initialization, so it has to be disabled now to avoid spurious
732 * execution of the handler.
733 */
734
735 if ((handler->orig_flags & ACPI_GPE_DISPATCH_METHOD)
736 && !(gpe_event_info->flags & ACPI_GPE_CAN_WAKE))
737 (void)acpi_raw_disable_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 /* Install the handler */
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 gpe_event_info->dispatch.handler = handler;
742
743 /* Setup up dispatch flags to indicate handler (vs. method) */
744
Bob Moored4913dc2009-03-06 10:05:18 +0800745 gpe_event_info->flags &=
746 ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER);
748
Len Brown4be44fc2005-08-05 00:44:28 -0400749 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Lin Ming0f849d22010-04-06 14:52:37 +0800751unlock_and_exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400752 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
753 return_ACPI_STATUS(status);
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200754
755free_and_exit:
756 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
757 ACPI_FREE(handler);
758 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Bob Moore83135242006-10-03 00:00:00 -0400761ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763/*******************************************************************************
764 *
765 * FUNCTION: acpi_remove_gpe_handler
766 *
Robert Moore44f6c012005-04-18 22:49:35 -0400767 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
768 * defined GPEs)
769 * gpe_number - The event to remove a handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 * Address - Address of the handler
771 *
772 * RETURN: Status
773 *
774 * DESCRIPTION: Remove a handler for a General Purpose acpi_event.
775 *
776 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400778acpi_remove_gpe_handler(acpi_handle gpe_device,
779 u32 gpe_number, acpi_event_handler address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
Len Brown4be44fc2005-08-05 00:44:28 -0400781 struct acpi_gpe_event_info *gpe_event_info;
782 struct acpi_handler_info *handler;
783 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500784 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Bob Mooreb229cf92006-04-21 17:15:00 -0400786 ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
788 /* Parameter validation */
789
790 if (!address) {
Len Brown4be44fc2005-08-05 00:44:28 -0400791 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 }
793
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200794 /* Make sure all deferred tasks are completed */
795
796 acpi_os_wait_events_complete(NULL);
797
Len Brown4be44fc2005-08-05 00:44:28 -0400798 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
799 if (ACPI_FAILURE(status)) {
800 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 }
802
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200803 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 /* Ensure that we have a valid GPE number */
806
Len Brown4be44fc2005-08-05 00:44:28 -0400807 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 if (!gpe_event_info) {
809 status = AE_BAD_PARAMETER;
810 goto unlock_and_exit;
811 }
812
813 /* Make sure that a handler is indeed installed */
814
Len Brown4be44fc2005-08-05 00:44:28 -0400815 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) !=
816 ACPI_GPE_DISPATCH_HANDLER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 status = AE_NOT_EXIST;
818 goto unlock_and_exit;
819 }
820
821 /* Make sure that the installed handler is the same */
822
823 if (gpe_event_info->dispatch.handler->address != address) {
824 status = AE_BAD_PARAMETER;
825 goto unlock_and_exit;
826 }
827
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 /* Remove the handler */
829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 handler = gpe_event_info->dispatch.handler;
831
832 /* Restore Method node (if any), set dispatch flags */
833
834 gpe_event_info->dispatch.method_node = handler->method_node;
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200835 gpe_event_info->flags &=
836 ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
837 gpe_event_info->flags |= handler->orig_flags;
838
839 /*
840 * If the GPE was previously associated with a method and it cannot wake
841 * up the system from sleep states, it should be enabled at this point
842 * to restore the post-initialization configuration.
843 */
844
845 if ((handler->orig_flags & ACPI_GPE_DISPATCH_METHOD)
846 && !(gpe_event_info->flags & ACPI_GPE_CAN_WAKE))
847 (void)acpi_raw_enable_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
849 /* Now we can free the handler object */
850
Bob Moore83135242006-10-03 00:00:00 -0400851 ACPI_FREE(handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200853unlock_and_exit:
854 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
855
Len Brown4be44fc2005-08-05 00:44:28 -0400856 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
857 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Bob Moore83135242006-10-03 00:00:00 -0400860ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862/*******************************************************************************
863 *
864 * FUNCTION: acpi_acquire_global_lock
865 *
866 * PARAMETERS: Timeout - How long the caller is willing to wait
Robert Moore44f6c012005-04-18 22:49:35 -0400867 * Handle - Where the handle to the lock is returned
868 * (if acquired)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 *
870 * RETURN: Status
871 *
872 * DESCRIPTION: Acquire the ACPI Global Lock
873 *
Bob Mooreba886cd2008-04-10 19:06:37 +0400874 * Note: Allows callers with the same thread ID to acquire the global lock
875 * multiple times. In other words, externally, the behavior of the global lock
876 * is identical to an AML mutex. On the first acquire, a new handle is
877 * returned. On any subsequent calls to acquire by the same thread, the same
878 * handle is returned.
879 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400881acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882{
Len Brown4be44fc2005-08-05 00:44:28 -0400883 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
885 if (!handle) {
886 return (AE_BAD_PARAMETER);
887 }
888
Len Brown4d2acd92007-05-09 22:56:38 -0400889 /* Must lock interpreter to prevent race conditions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
Len Brown4d2acd92007-05-09 22:56:38 -0400891 acpi_ex_enter_interpreter();
Bob Mooreba886cd2008-04-10 19:06:37 +0400892
893 status = acpi_ex_acquire_mutex_object(timeout,
894 acpi_gbl_global_lock_mutex,
895 acpi_os_get_thread_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Len Brown4be44fc2005-08-05 00:44:28 -0400897 if (ACPI_SUCCESS(status)) {
Bob Mooreba886cd2008-04-10 19:06:37 +0400898
Bob Mooree5567af2008-04-10 19:06:38 +0400899 /* Return the global lock handle (updated in acpi_ev_acquire_global_lock) */
Bob Mooreba886cd2008-04-10 19:06:37 +0400900
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 *handle = acpi_gbl_global_lock_handle;
902 }
903
Bob Mooreba886cd2008-04-10 19:06:37 +0400904 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 return (status);
906}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Bob Moore83135242006-10-03 00:00:00 -0400908ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910/*******************************************************************************
911 *
912 * FUNCTION: acpi_release_global_lock
913 *
914 * PARAMETERS: Handle - Returned from acpi_acquire_global_lock
915 *
916 * RETURN: Status
917 *
Robert Moore44f6c012005-04-18 22:49:35 -0400918 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 *
920 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400921acpi_status acpi_release_global_lock(u32 handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922{
Len Brown4be44fc2005-08-05 00:44:28 -0400923 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Bob Mooref02e9fa2008-04-10 19:06:37 +0400925 if (!handle || (handle != acpi_gbl_global_lock_handle)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 return (AE_NOT_ACQUIRED);
927 }
928
Bob Mooreba886cd2008-04-10 19:06:37 +0400929 status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 return (status);
931}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
Bob Moore83135242006-10-03 00:00:00 -0400933ACPI_EXPORT_SYMBOL(acpi_release_global_lock)