blob: 44bef5744ebb159f383f6b19515cf6346f656582 [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 Moore77848132012-01-12 13:27:23 +08008 * Copyright (C) 2000 - 2012, 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
Paul Gortmaker214f2c92011-10-26 16:22:14 -040044#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050046#include "accommon.h"
47#include "acnamesp.h"
48#include "acevents.h"
49#include "acinterp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040052ACPI_MODULE_NAME("evxface")
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/*******************************************************************************
56 *
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +010057 * FUNCTION: acpi_populate_handler_object
58 *
59 * PARAMETERS: handler_obj - Handler object to populate
60 * handler_type - The type of handler:
61 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
62 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
63 * ACPI_ALL_NOTIFY: both system and device
64 * handler - Address of the handler
65 * context - Value passed to the handler on each GPE
66 * next - Address of a handler object to link to
67 *
68 * RETURN: None
69 *
70 * DESCRIPTION: Populate a handler object.
71 *
72 ******************************************************************************/
73static void
74acpi_populate_handler_object(struct acpi_object_notify_handler *handler_obj,
75 u32 handler_type,
76 acpi_notify_handler handler, void *context,
77 struct acpi_object_notify_handler *next)
78{
79 handler_obj->handler_type = handler_type;
80 handler_obj->handler = handler;
81 handler_obj->context = context;
82 handler_obj->next = next;
83}
84
85/*******************************************************************************
86 *
87 * FUNCTION: acpi_add_handler_object
88 *
89 * PARAMETERS: parent_obj - Parent of the new object
90 * handler - Address of the handler
91 * context - Value passed to the handler on each GPE
92 *
93 * RETURN: Status
94 *
95 * DESCRIPTION: Create a new handler object and populate it.
96 *
97 ******************************************************************************/
98static acpi_status
99acpi_add_handler_object(struct acpi_object_notify_handler *parent_obj,
100 acpi_notify_handler handler, void *context)
101{
102 struct acpi_object_notify_handler *handler_obj;
103
104 /* The parent must not be a defice notify handler object. */
105 if (parent_obj->handler_type & ACPI_DEVICE_NOTIFY)
106 return AE_BAD_PARAMETER;
107
108 handler_obj = ACPI_ALLOCATE_ZEROED(sizeof(*handler_obj));
109 if (!handler_obj)
110 return AE_NO_MEMORY;
111
112 acpi_populate_handler_object(handler_obj,
113 ACPI_SYSTEM_NOTIFY,
114 handler, context,
115 parent_obj->next);
116 parent_obj->next = handler_obj;
117
118 return AE_OK;
119}
120
Bob Moore33620c52012-02-14 18:14:27 +0800121
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100122/*******************************************************************************
123 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 * FUNCTION: acpi_install_notify_handler
125 *
126 * PARAMETERS: Device - The device for which notifies will be handled
127 * handler_type - The type of handler:
128 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
129 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
130 * ACPI_ALL_NOTIFY: both system and device
131 * Handler - Address of the handler
132 * Context - Value passed to the handler on each GPE
133 *
134 * RETURN: Status
135 *
136 * DESCRIPTION: Install a handler for notifies on an ACPI device
137 *
138 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400140acpi_install_notify_handler(acpi_handle device,
141 u32 handler_type,
142 acpi_notify_handler handler, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Len Brown4be44fc2005-08-05 00:44:28 -0400144 union acpi_operand_object *obj_desc;
145 union acpi_operand_object *notify_obj;
146 struct acpi_namespace_node *node;
147 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Bob Mooreb229cf92006-04-21 17:15:00 -0400149 ACPI_FUNCTION_TRACE(acpi_install_notify_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151 /* Parameter validation */
152
Len Brown4be44fc2005-08-05 00:44:28 -0400153 if ((!device) ||
154 (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
155 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
Len Brown4be44fc2005-08-05 00:44:28 -0400158 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
159 if (ACPI_FAILURE(status)) {
160 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162
163 /* Convert and validate the device handle */
164
Bob Mooref24b6642009-12-11 14:57:00 +0800165 node = acpi_ns_validate_handle(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 if (!node) {
167 status = AE_BAD_PARAMETER;
168 goto unlock_and_exit;
169 }
170
171 /*
172 * Root Object:
173 * Registering a notify handler on the root object indicates that the
Bob Moore9f15fc62008-11-12 16:01:56 +0800174 * caller wishes to receive notifications for all objects. Note that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 * only one <external> global handler can be regsitered (per notify type).
176 */
177 if (device == ACPI_ROOT_OBJECT) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 /* Make sure the handler is not already installed */
180
181 if (((handler_type & ACPI_SYSTEM_NOTIFY) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400182 acpi_gbl_system_notify.handler) ||
183 ((handler_type & ACPI_DEVICE_NOTIFY) &&
184 acpi_gbl_device_notify.handler)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 status = AE_ALREADY_EXISTS;
186 goto unlock_and_exit;
187 }
188
189 if (handler_type & ACPI_SYSTEM_NOTIFY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400190 acpi_gbl_system_notify.node = node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 acpi_gbl_system_notify.handler = handler;
192 acpi_gbl_system_notify.context = context;
193 }
194
195 if (handler_type & ACPI_DEVICE_NOTIFY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400196 acpi_gbl_device_notify.node = node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 acpi_gbl_device_notify.handler = handler;
198 acpi_gbl_device_notify.context = context;
199 }
200
201 /* Global notify handler installed */
202 }
203
204 /*
205 * All Other Objects:
206 * Caller will only receive notifications specific to the target object.
207 * Note that only certain object types can receive notifications.
208 */
209 else {
210 /* Notifies allowed on this object? */
211
Len Brown4be44fc2005-08-05 00:44:28 -0400212 if (!acpi_ev_is_notify_object(node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 status = AE_TYPE;
214 goto unlock_and_exit;
215 }
216
217 /* Check for an existing internal object */
218
Len Brown4be44fc2005-08-05 00:44:28 -0400219 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 if (obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400221
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100222 /* Object exists. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100224 /* For a device notify, make sure there's no handler. */
225 if ((handler_type & ACPI_DEVICE_NOTIFY) &&
226 obj_desc->common_notify.device_notify) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 status = AE_ALREADY_EXISTS;
228 goto unlock_and_exit;
229 }
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100230
231 /* System notifies may have more handlers installed. */
232 notify_obj = obj_desc->common_notify.system_notify;
233
234 if ((handler_type & ACPI_SYSTEM_NOTIFY) && notify_obj) {
235 struct acpi_object_notify_handler *parent_obj;
236
237 if (handler_type & ACPI_DEVICE_NOTIFY) {
238 status = AE_ALREADY_EXISTS;
239 goto unlock_and_exit;
240 }
241
242 parent_obj = &notify_obj->notify;
243 status = acpi_add_handler_object(parent_obj,
244 handler,
245 context);
246 goto unlock_and_exit;
247 }
Len Brown4be44fc2005-08-05 00:44:28 -0400248 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 /* Create a new object */
250
Len Brown4be44fc2005-08-05 00:44:28 -0400251 obj_desc = acpi_ut_create_internal_object(node->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 if (!obj_desc) {
253 status = AE_NO_MEMORY;
254 goto unlock_and_exit;
255 }
256
257 /* Attach new object to the Node */
258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 status =
260 acpi_ns_attach_object(device, obj_desc, node->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 /* Remove local reference to the object */
263
Len Brown4be44fc2005-08-05 00:44:28 -0400264 acpi_ut_remove_reference(obj_desc);
265 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 goto unlock_and_exit;
267 }
268 }
269
270 /* Install the handler */
271
Len Brown4be44fc2005-08-05 00:44:28 -0400272 notify_obj =
273 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (!notify_obj) {
275 status = AE_NO_MEMORY;
276 goto unlock_and_exit;
277 }
278
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100279 acpi_populate_handler_object(&notify_obj->notify,
280 handler_type,
281 handler, context,
282 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 if (handler_type & ACPI_SYSTEM_NOTIFY) {
285 obj_desc->common_notify.system_notify = notify_obj;
286 }
287
288 if (handler_type & ACPI_DEVICE_NOTIFY) {
289 obj_desc->common_notify.device_notify = notify_obj;
290 }
291
292 if (handler_type == ACPI_ALL_NOTIFY) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 /* Extra ref if installed in both */
295
Len Brown4be44fc2005-08-05 00:44:28 -0400296 acpi_ut_add_reference(notify_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 }
298 }
299
Len Brown4be44fc2005-08-05 00:44:28 -0400300 unlock_and_exit:
301 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
302 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Bob Moore83135242006-10-03 00:00:00 -0400305ACPI_EXPORT_SYMBOL(acpi_install_notify_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307/*******************************************************************************
308 *
309 * FUNCTION: acpi_remove_notify_handler
310 *
311 * PARAMETERS: Device - The device for which notifies will be handled
312 * handler_type - The type of handler:
313 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
314 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
315 * ACPI_ALL_NOTIFY: both system and device
316 * Handler - Address of the handler
317 *
318 * RETURN: Status
319 *
320 * DESCRIPTION: Remove a handler for notifies on an ACPI device
321 *
322 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400324acpi_remove_notify_handler(acpi_handle device,
325 u32 handler_type, acpi_notify_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
Len Brown4be44fc2005-08-05 00:44:28 -0400327 union acpi_operand_object *notify_obj;
328 union acpi_operand_object *obj_desc;
329 struct acpi_namespace_node *node;
330 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Bob Mooreb229cf92006-04-21 17:15:00 -0400332 ACPI_FUNCTION_TRACE(acpi_remove_notify_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 /* Parameter validation */
335
Len Brown4be44fc2005-08-05 00:44:28 -0400336 if ((!device) ||
337 (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
Thomas Renningere8406b42006-06-02 15:58:00 -0400338 status = AE_BAD_PARAMETER;
339 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
341
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100342
343 /* Make sure all deferred tasks are completed */
344 acpi_os_wait_events_complete(NULL);
345
Len Brown4be44fc2005-08-05 00:44:28 -0400346 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
347 if (ACPI_FAILURE(status)) {
Thomas Renningere8406b42006-06-02 15:58:00 -0400348 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350
351 /* Convert and validate the device handle */
352
Bob Mooref24b6642009-12-11 14:57:00 +0800353 node = acpi_ns_validate_handle(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 if (!node) {
355 status = AE_BAD_PARAMETER;
Bob Mooref6dd9222006-07-07 20:44:38 -0400356 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 }
358
359 /* Root Object */
360
361 if (device == ACPI_ROOT_OBJECT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400362 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Moore4a90c7e2006-01-13 16:22:00 -0500363 "Removing notify handler for namespace root object\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
365 if (((handler_type & ACPI_SYSTEM_NOTIFY) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400366 !acpi_gbl_system_notify.handler) ||
367 ((handler_type & ACPI_DEVICE_NOTIFY) &&
368 !acpi_gbl_device_notify.handler)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 status = AE_NOT_EXIST;
Bob Mooref6dd9222006-07-07 20:44:38 -0400370 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 }
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 if (handler_type & ACPI_SYSTEM_NOTIFY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400374 acpi_gbl_system_notify.node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 acpi_gbl_system_notify.handler = NULL;
376 acpi_gbl_system_notify.context = NULL;
377 }
378
379 if (handler_type & ACPI_DEVICE_NOTIFY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400380 acpi_gbl_device_notify.node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 acpi_gbl_device_notify.handler = NULL;
382 acpi_gbl_device_notify.context = NULL;
383 }
384 }
385
386 /* All Other Objects */
387
388 else {
389 /* Notifies allowed on this object? */
390
Len Brown4be44fc2005-08-05 00:44:28 -0400391 if (!acpi_ev_is_notify_object(node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 status = AE_TYPE;
Bob Mooref6dd9222006-07-07 20:44:38 -0400393 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 }
395
396 /* Check for an existing internal object */
397
Len Brown4be44fc2005-08-05 00:44:28 -0400398 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (!obj_desc) {
400 status = AE_NOT_EXIST;
Bob Mooref6dd9222006-07-07 20:44:38 -0400401 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403
404 /* Object exists - make sure there's an existing handler */
405
406 if (handler_type & ACPI_SYSTEM_NOTIFY) {
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100407 struct acpi_object_notify_handler *handler_obj;
408 struct acpi_object_notify_handler *parent_obj;
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 notify_obj = obj_desc->common_notify.system_notify;
Bob Mooref6dd9222006-07-07 20:44:38 -0400411 if (!notify_obj) {
412 status = AE_NOT_EXIST;
413 goto unlock_and_exit;
414 }
415
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100416 handler_obj = &notify_obj->notify;
417 parent_obj = NULL;
418 while (handler_obj->handler != handler) {
419 if (handler_obj->next) {
420 parent_obj = handler_obj;
421 handler_obj = handler_obj->next;
422 } else {
423 break;
424 }
425 }
426
427 if (handler_obj->handler != handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 status = AE_BAD_PARAMETER;
Bob Mooref6dd9222006-07-07 20:44:38 -0400429 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100432 /*
433 * Remove the handler. There are three possible cases.
434 * First, we may need to remove a non-embedded object.
435 * Second, we may need to remove the embedded object's
436 * handler data, while non-embedded objects exist.
437 * Finally, we may need to remove the embedded object
438 * entirely along with its container.
439 */
440 if (parent_obj) {
441 /* Non-embedded object is being removed. */
442 parent_obj->next = handler_obj->next;
443 ACPI_FREE(handler_obj);
444 } else if (notify_obj->notify.next) {
445 /*
446 * The handler matches the embedded object, but
447 * there are more handler objects in the list.
448 * Replace the embedded object's data with the
449 * first next object's data and remove that
450 * object.
451 */
452 parent_obj = &notify_obj->notify;
453 handler_obj = notify_obj->notify.next;
454 *parent_obj = *handler_obj;
455 ACPI_FREE(handler_obj);
456 } else {
457 /* No more handler objects in the list. */
458 obj_desc->common_notify.system_notify = NULL;
459 acpi_ut_remove_reference(notify_obj);
Len Brown4be44fc2005-08-05 00:44:28 -0400460 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462
463 if (handler_type & ACPI_DEVICE_NOTIFY) {
464 notify_obj = obj_desc->common_notify.device_notify;
Bob Mooref6dd9222006-07-07 20:44:38 -0400465 if (!notify_obj) {
466 status = AE_NOT_EXIST;
467 goto unlock_and_exit;
468 }
469
470 if (notify_obj->notify.handler != handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 status = AE_BAD_PARAMETER;
Bob Mooref6dd9222006-07-07 20:44:38 -0400472 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 /* Remove the handler */
476 obj_desc->common_notify.device_notify = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400477 acpi_ut_remove_reference(notify_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 }
479 }
480
Bob Mooref6dd9222006-07-07 20:44:38 -0400481 unlock_and_exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400482 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Bob Mooref6dd9222006-07-07 20:44:38 -0400483 exit:
Thomas Renningere8406b42006-06-02 15:58:00 -0400484 if (ACPI_FAILURE(status))
485 ACPI_EXCEPTION((AE_INFO, status, "Removing notify handler"));
Len Brown4be44fc2005-08-05 00:44:28 -0400486 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Bob Moore83135242006-10-03 00:00:00 -0400489ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491/*******************************************************************************
492 *
Bob Moore33620c52012-02-14 18:14:27 +0800493 * FUNCTION: acpi_install_exception_handler
494 *
495 * PARAMETERS: Handler - Pointer to the handler function for the
496 * event
497 *
498 * RETURN: Status
499 *
500 * DESCRIPTION: Saves the pointer to the handler function
501 *
502 ******************************************************************************/
503#ifdef ACPI_FUTURE_USAGE
504acpi_status acpi_install_exception_handler(acpi_exception_handler handler)
505{
506 acpi_status status;
507
508 ACPI_FUNCTION_TRACE(acpi_install_exception_handler);
509
510 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
511 if (ACPI_FAILURE(status)) {
512 return_ACPI_STATUS(status);
513 }
514
515 /* Don't allow two handlers. */
516
517 if (acpi_gbl_exception_handler) {
518 status = AE_ALREADY_EXISTS;
519 goto cleanup;
520 }
521
522 /* Install the handler */
523
524 acpi_gbl_exception_handler = handler;
525
526 cleanup:
527 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
528 return_ACPI_STATUS(status);
529}
530
531ACPI_EXPORT_SYMBOL(acpi_install_exception_handler)
532#endif /* ACPI_FUTURE_USAGE */
533
534#if (!ACPI_REDUCED_HARDWARE)
535/*******************************************************************************
536 *
537 * FUNCTION: acpi_install_global_event_handler
538 *
539 * PARAMETERS: Handler - Pointer to the global event handler function
540 * Context - Value passed to the handler on each event
541 *
542 * RETURN: Status
543 *
544 * DESCRIPTION: Saves the pointer to the handler function. The global handler
545 * is invoked upon each incoming GPE and Fixed Event. It is
546 * invoked at interrupt level at the time of the event dispatch.
547 * Can be used to update event counters, etc.
548 *
549 ******************************************************************************/
550acpi_status
551acpi_install_global_event_handler(ACPI_GBL_EVENT_HANDLER handler, void *context)
552{
553 acpi_status status;
554
555 ACPI_FUNCTION_TRACE(acpi_install_global_event_handler);
556
557 /* Parameter validation */
558
559 if (!handler) {
560 return_ACPI_STATUS(AE_BAD_PARAMETER);
561 }
562
563 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
564 if (ACPI_FAILURE(status)) {
565 return_ACPI_STATUS(status);
566 }
567
568 /* Don't allow two handlers. */
569
570 if (acpi_gbl_global_event_handler) {
571 status = AE_ALREADY_EXISTS;
572 goto cleanup;
573 }
574
575 acpi_gbl_global_event_handler = handler;
576 acpi_gbl_global_event_handler_context = context;
577
578 cleanup:
579 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
580 return_ACPI_STATUS(status);
581}
582
583ACPI_EXPORT_SYMBOL(acpi_install_global_event_handler)
584
585/*******************************************************************************
586 *
587 * FUNCTION: acpi_install_fixed_event_handler
588 *
589 * PARAMETERS: Event - Event type to enable.
590 * Handler - Pointer to the handler function for the
591 * event
592 * Context - Value passed to the handler on each GPE
593 *
594 * RETURN: Status
595 *
596 * DESCRIPTION: Saves the pointer to the handler function and then enables the
597 * event.
598 *
599 ******************************************************************************/
600acpi_status
601acpi_install_fixed_event_handler(u32 event,
602 acpi_event_handler handler, void *context)
603{
604 acpi_status status;
605
606 ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler);
607
608 /* Parameter validation */
609
610 if (event > ACPI_EVENT_MAX) {
611 return_ACPI_STATUS(AE_BAD_PARAMETER);
612 }
613
614 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
615 if (ACPI_FAILURE(status)) {
616 return_ACPI_STATUS(status);
617 }
618
619 /* Don't allow two handlers. */
620
621 if (NULL != acpi_gbl_fixed_event_handlers[event].handler) {
622 status = AE_ALREADY_EXISTS;
623 goto cleanup;
624 }
625
626 /* Install the handler before enabling the event */
627
628 acpi_gbl_fixed_event_handlers[event].handler = handler;
629 acpi_gbl_fixed_event_handlers[event].context = context;
630
631 status = acpi_clear_event(event);
632 if (ACPI_SUCCESS(status))
633 status = acpi_enable_event(event, 0);
634 if (ACPI_FAILURE(status)) {
635 ACPI_WARNING((AE_INFO, "Could not enable fixed event 0x%X",
636 event));
637
638 /* Remove the handler */
639
640 acpi_gbl_fixed_event_handlers[event].handler = NULL;
641 acpi_gbl_fixed_event_handlers[event].context = NULL;
642 } else {
643 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
644 "Enabled fixed event %X, Handler=%p\n", event,
645 handler));
646 }
647
648 cleanup:
649 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
650 return_ACPI_STATUS(status);
651}
652
653ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler)
654
655/*******************************************************************************
656 *
657 * FUNCTION: acpi_remove_fixed_event_handler
658 *
659 * PARAMETERS: Event - Event type to disable.
660 * Handler - Address of the handler
661 *
662 * RETURN: Status
663 *
664 * DESCRIPTION: Disables the event and unregisters the event handler.
665 *
666 ******************************************************************************/
667acpi_status
668acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler)
669{
670 acpi_status status = AE_OK;
671
672 ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler);
673
674 /* Parameter validation */
675
676 if (event > ACPI_EVENT_MAX) {
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 /* Disable the event before removing the handler */
686
687 status = acpi_disable_event(event, 0);
688
689 /* Always Remove the handler */
690
691 acpi_gbl_fixed_event_handlers[event].handler = NULL;
692 acpi_gbl_fixed_event_handlers[event].context = NULL;
693
694 if (ACPI_FAILURE(status)) {
695 ACPI_WARNING((AE_INFO,
696 "Could not write to fixed event enable register 0x%X",
697 event));
698 } else {
699 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Disabled fixed event %X\n",
700 event));
701 }
702
703 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
704 return_ACPI_STATUS(status);
705}
706
707ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler)
708
709/*******************************************************************************
710 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 * FUNCTION: acpi_install_gpe_handler
712 *
Robert Moore44f6c012005-04-18 22:49:35 -0400713 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
714 * defined GPEs)
715 * gpe_number - The GPE number within the GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 * Type - Whether this GPE should be treated as an
717 * edge- or level-triggered interrupt.
718 * Address - Address of the handler
719 * Context - Value passed to the handler on each GPE
720 *
721 * RETURN: Status
722 *
723 * DESCRIPTION: Install a handler for a General Purpose Event.
724 *
725 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400727acpi_install_gpe_handler(acpi_handle gpe_device,
728 u32 gpe_number,
Lin Ming8b6cd8a2010-12-13 13:38:46 +0800729 u32 type, acpi_gpe_handler address, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
Len Brown4be44fc2005-08-05 00:44:28 -0400731 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming8b6cd8a2010-12-13 13:38:46 +0800732 struct acpi_gpe_handler_info *handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400733 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500734 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Bob Mooreb229cf92006-04-21 17:15:00 -0400736 ACPI_FUNCTION_TRACE(acpi_install_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 /* Parameter validation */
739
Lin Ming0f849d22010-04-06 14:52:37 +0800740 if ((!address) || (type & ~ACPI_GPE_XRUPT_TYPE_MASK)) {
741 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 }
743
Len Brown4be44fc2005-08-05 00:44:28 -0400744 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
745 if (ACPI_FAILURE(status)) {
Lin Ming0f849d22010-04-06 14:52:37 +0800746 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 }
748
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200749 /* Allocate memory for the handler object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Lin Ming8b6cd8a2010-12-13 13:38:46 +0800751 handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_handler_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 if (!handler) {
753 status = AE_NO_MEMORY;
Bob Mooref6dd9222006-07-07 20:44:38 -0400754 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 }
756
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200757 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
758
759 /* Ensure that we have a valid GPE number */
760
761 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
762 if (!gpe_event_info) {
763 status = AE_BAD_PARAMETER;
764 goto free_and_exit;
765 }
766
767 /* Make sure that there isn't a handler there already */
768
769 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
770 ACPI_GPE_DISPATCH_HANDLER) {
771 status = AE_ALREADY_EXISTS;
772 goto free_and_exit;
773 }
774
775 /* Allocate and init handler object */
776
Len Brown4be44fc2005-08-05 00:44:28 -0400777 handler->address = address;
778 handler->context = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 handler->method_node = gpe_event_info->dispatch.method_node;
Lin Ming3a378982010-12-13 13:36:15 +0800780 handler->original_flags = gpe_event_info->flags &
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200781 (ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
782
783 /*
Rafael J. Wysockia2100802010-09-16 00:30:43 +0200784 * If the GPE is associated with a method, it might have been enabled
785 * automatically during initialization, in which case it has to be
786 * disabled now to avoid spurious execution of the handler.
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200787 */
788
Lin Ming3a378982010-12-13 13:36:15 +0800789 if ((handler->original_flags & ACPI_GPE_DISPATCH_METHOD)
Rafael J. Wysockia2100802010-09-16 00:30:43 +0200790 && gpe_event_info->runtime_count) {
Lin Ming3a378982010-12-13 13:36:15 +0800791 handler->originally_enabled = 1;
792 (void)acpi_ev_remove_gpe_reference(gpe_event_info);
Rafael J. Wysockia2100802010-09-16 00:30:43 +0200793 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 /* Install the handler */
796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 gpe_event_info->dispatch.handler = handler;
798
799 /* Setup up dispatch flags to indicate handler (vs. method) */
800
Bob Moored4913dc2009-03-06 10:05:18 +0800801 gpe_event_info->flags &=
802 ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER);
804
Len Brown4be44fc2005-08-05 00:44:28 -0400805 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Lin Ming0f849d22010-04-06 14:52:37 +0800807unlock_and_exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400808 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
809 return_ACPI_STATUS(status);
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200810
811free_and_exit:
812 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
813 ACPI_FREE(handler);
814 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Bob Moore83135242006-10-03 00:00:00 -0400817ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819/*******************************************************************************
820 *
821 * FUNCTION: acpi_remove_gpe_handler
822 *
Robert Moore44f6c012005-04-18 22:49:35 -0400823 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
824 * defined GPEs)
825 * gpe_number - The event to remove a handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 * Address - Address of the handler
827 *
828 * RETURN: Status
829 *
830 * DESCRIPTION: Remove a handler for a General Purpose acpi_event.
831 *
832 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400834acpi_remove_gpe_handler(acpi_handle gpe_device,
Lin Ming8b6cd8a2010-12-13 13:38:46 +0800835 u32 gpe_number, acpi_gpe_handler address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836{
Len Brown4be44fc2005-08-05 00:44:28 -0400837 struct acpi_gpe_event_info *gpe_event_info;
Lin Ming8b6cd8a2010-12-13 13:38:46 +0800838 struct acpi_gpe_handler_info *handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400839 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500840 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Bob Mooreb229cf92006-04-21 17:15:00 -0400842 ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
844 /* Parameter validation */
845
846 if (!address) {
Len Brown4be44fc2005-08-05 00:44:28 -0400847 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 }
849
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200850 /* Make sure all deferred tasks are completed */
851
852 acpi_os_wait_events_complete(NULL);
853
Len Brown4be44fc2005-08-05 00:44:28 -0400854 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
855 if (ACPI_FAILURE(status)) {
856 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 }
858
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200859 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 /* Ensure that we have a valid GPE number */
862
Len Brown4be44fc2005-08-05 00:44:28 -0400863 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 if (!gpe_event_info) {
865 status = AE_BAD_PARAMETER;
866 goto unlock_and_exit;
867 }
868
869 /* Make sure that a handler is indeed installed */
870
Len Brown4be44fc2005-08-05 00:44:28 -0400871 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) !=
872 ACPI_GPE_DISPATCH_HANDLER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 status = AE_NOT_EXIST;
874 goto unlock_and_exit;
875 }
876
877 /* Make sure that the installed handler is the same */
878
879 if (gpe_event_info->dispatch.handler->address != address) {
880 status = AE_BAD_PARAMETER;
881 goto unlock_and_exit;
882 }
883
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 /* Remove the handler */
885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 handler = gpe_event_info->dispatch.handler;
887
888 /* Restore Method node (if any), set dispatch flags */
889
890 gpe_event_info->dispatch.method_node = handler->method_node;
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200891 gpe_event_info->flags &=
892 ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
Lin Ming3a378982010-12-13 13:36:15 +0800893 gpe_event_info->flags |= handler->original_flags;
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200894
895 /*
Rafael J. Wysockia2100802010-09-16 00:30:43 +0200896 * If the GPE was previously associated with a method and it was
897 * enabled, it should be enabled at this point to restore the
898 * post-initialization configuration.
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200899 */
900
Lin Ming3a378982010-12-13 13:36:15 +0800901 if ((handler->original_flags & ACPI_GPE_DISPATCH_METHOD)
902 && handler->originally_enabled)
903 (void)acpi_ev_add_gpe_reference(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905 /* Now we can free the handler object */
906
Bob Moore83135242006-10-03 00:00:00 -0400907 ACPI_FREE(handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200909unlock_and_exit:
910 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
911
Len Brown4be44fc2005-08-05 00:44:28 -0400912 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
913 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Bob Moore83135242006-10-03 00:00:00 -0400916ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
918/*******************************************************************************
919 *
920 * FUNCTION: acpi_acquire_global_lock
921 *
922 * PARAMETERS: Timeout - How long the caller is willing to wait
Robert Moore44f6c012005-04-18 22:49:35 -0400923 * Handle - Where the handle to the lock is returned
924 * (if acquired)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 *
926 * RETURN: Status
927 *
928 * DESCRIPTION: Acquire the ACPI Global Lock
929 *
Bob Mooreba886cd2008-04-10 19:06:37 +0400930 * Note: Allows callers with the same thread ID to acquire the global lock
931 * multiple times. In other words, externally, the behavior of the global lock
932 * is identical to an AML mutex. On the first acquire, a new handle is
933 * returned. On any subsequent calls to acquire by the same thread, the same
934 * handle is returned.
935 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400937acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
Len Brown4be44fc2005-08-05 00:44:28 -0400939 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 if (!handle) {
942 return (AE_BAD_PARAMETER);
943 }
944
Len Brown4d2acd92007-05-09 22:56:38 -0400945 /* Must lock interpreter to prevent race conditions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
Len Brown4d2acd92007-05-09 22:56:38 -0400947 acpi_ex_enter_interpreter();
Bob Mooreba886cd2008-04-10 19:06:37 +0400948
949 status = acpi_ex_acquire_mutex_object(timeout,
950 acpi_gbl_global_lock_mutex,
951 acpi_os_get_thread_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Len Brown4be44fc2005-08-05 00:44:28 -0400953 if (ACPI_SUCCESS(status)) {
Bob Mooreba886cd2008-04-10 19:06:37 +0400954
Bob Mooree5567af2008-04-10 19:06:38 +0400955 /* Return the global lock handle (updated in acpi_ev_acquire_global_lock) */
Bob Mooreba886cd2008-04-10 19:06:37 +0400956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 *handle = acpi_gbl_global_lock_handle;
958 }
959
Bob Mooreba886cd2008-04-10 19:06:37 +0400960 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 return (status);
962}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Bob Moore83135242006-10-03 00:00:00 -0400964ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
966/*******************************************************************************
967 *
968 * FUNCTION: acpi_release_global_lock
969 *
970 * PARAMETERS: Handle - Returned from acpi_acquire_global_lock
971 *
972 * RETURN: Status
973 *
Robert Moore44f6c012005-04-18 22:49:35 -0400974 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 *
976 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400977acpi_status acpi_release_global_lock(u32 handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
Len Brown4be44fc2005-08-05 00:44:28 -0400979 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Bob Mooref02e9fa2008-04-10 19:06:37 +0400981 if (!handle || (handle != acpi_gbl_global_lock_handle)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 return (AE_NOT_ACQUIRED);
983 }
984
Bob Mooreba886cd2008-04-10 19:06:37 +0400985 status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 return (status);
987}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Bob Moore83135242006-10-03 00:00:00 -0400989ACPI_EXPORT_SYMBOL(acpi_release_global_lock)
Bob Moore33620c52012-02-14 18:14:27 +0800990#endif /* !ACPI_REDUCED_HARDWARE */