ACPICA: Events: Introduce acpi_set_gpe()/acpi_finish_gpe() to reduce divergences
[deliverable/linux.git] / drivers / acpi / acpica / evxfgpe.c
CommitLineData
3cfd53d5
LM
1/******************************************************************************
2 *
3 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
4 *
5 *****************************************************************************/
6
7/*
82a80941 8 * Copyright (C) 2000 - 2015, Intel Corp.
3cfd53d5
LM
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
839e928f
LZ
44#define EXPORT_ACPI_INTERFACES
45
3cfd53d5
LM
46#include <acpi/acpi.h>
47#include "accommon.h"
48#include "acevents.h"
49#include "acnamesp.h"
50
51#define _COMPONENT ACPI_EVENTS
52ACPI_MODULE_NAME("evxfgpe")
53
33620c54 54#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
75c8044f 55/*******************************************************************************
3cfd53d5 56 *
3a37898d 57 * FUNCTION: acpi_update_all_gpes
3cfd53d5
LM
58 *
59 * PARAMETERS: None
60 *
da503373
LM
61 * RETURN: Status
62 *
63 * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
64 * associated _Lxx or _Exx methods and are not pointed to by any
65 * device _PRW methods (this indicates that these GPEs are
66 * generally intended for system or device wakeup. Such GPEs
67 * have to be enabled directly when the devices whose _PRW
68 * methods point to them are set up for wakeup signaling.)
3cfd53d5 69 *
da503373
LM
70 * NOTE: Should be called after any GPEs are added to the system. Primarily,
71 * after the system _PRW methods have been run, but also after a GPE Block
72 * Device has been added or if any new GPE methods have been added via a
73 * dynamic table load.
3cfd53d5
LM
74 *
75 ******************************************************************************/
76
3a37898d 77acpi_status acpi_update_all_gpes(void)
3cfd53d5
LM
78{
79 acpi_status status;
80
3a37898d 81 ACPI_FUNCTION_TRACE(acpi_update_all_gpes);
3cfd53d5
LM
82
83 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
84 if (ACPI_FAILURE(status)) {
85 return_ACPI_STATUS(status);
3a37898d
LM
86 }
87
88 if (acpi_gbl_all_gpes_initialized) {
89 goto unlock_and_exit;
3cfd53d5
LM
90 }
91
92 status = acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block, NULL);
93 if (ACPI_SUCCESS(status)) {
3a37898d 94 acpi_gbl_all_gpes_initialized = TRUE;
3cfd53d5
LM
95 }
96
3a37898d 97unlock_and_exit:
3cfd53d5
LM
98 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
99
100 return_ACPI_STATUS(status);
101}
102
3a37898d
LM
103ACPI_EXPORT_SYMBOL(acpi_update_all_gpes)
104
3cfd53d5
LM
105/*******************************************************************************
106 *
107 * FUNCTION: acpi_enable_gpe
108 *
f19f1a7e
LZ
109 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
110 * gpe_number - GPE level within the GPE block
3cfd53d5
LM
111 *
112 * RETURN: Status
113 *
114 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
115 * hardware-enabled.
116 *
117 ******************************************************************************/
3cfd53d5
LM
118acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
119{
120 acpi_status status = AE_BAD_PARAMETER;
121 struct acpi_gpe_event_info *gpe_event_info;
122 acpi_cpu_flags flags;
123
124 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
125
126 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
127
b9ca3d7b
RW
128 /*
129 * Ensure that we have a valid GPE number and that there is some way
130 * of handling the GPE (handler or a GPE method). In other words, we
131 * won't allow a valid GPE to be enabled if there is no way to handle it.
132 */
3cfd53d5
LM
133 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
134 if (gpe_event_info) {
7c43312a 135 if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) !=
b9ca3d7b
RW
136 ACPI_GPE_DISPATCH_NONE) {
137 status = acpi_ev_add_gpe_reference(gpe_event_info);
138 } else {
139 status = AE_NO_HANDLER;
140 }
3cfd53d5
LM
141 }
142
143 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
144 return_ACPI_STATUS(status);
145}
146ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
147
148/*******************************************************************************
149 *
150 * FUNCTION: acpi_disable_gpe
151 *
152 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
153 * gpe_number - GPE level within the GPE block
154 *
155 * RETURN: Status
156 *
157 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
158 * removed, only then is the GPE disabled (for runtime GPEs), or
159 * the GPE mask bit disabled (for wake GPEs)
160 *
161 ******************************************************************************/
162
163acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
164{
165 acpi_status status = AE_BAD_PARAMETER;
166 struct acpi_gpe_event_info *gpe_event_info;
167 acpi_cpu_flags flags;
168
169 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
170
171 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
172
173 /* Ensure that we have a valid GPE number */
174
175 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
176 if (gpe_event_info) {
3a37898d 177 status = acpi_ev_remove_gpe_reference(gpe_event_info) ;
3cfd53d5
LM
178 }
179
180 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
181 return_ACPI_STATUS(status);
182}
3e8214e5 183
3cfd53d5
LM
184ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
185
eb3d80f7
LZ
186/*******************************************************************************
187 *
188 * FUNCTION: acpi_set_gpe
189 *
190 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
191 * gpe_number - GPE level within the GPE block
192 * action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
193 *
194 * RETURN: Status
195 *
196 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
197 * the reference count mechanism used in the acpi_enable_gpe and
198 * acpi_disable_gpe interfaces -- and should be used with care.
199 *
200 * Note: Typically used to disable a runtime GPE for short period of time,
201 * then re-enable it, without disturbing the existing reference counts. This
202 * is useful, for example, in the Embedded Controller (EC) driver.
203 *
204 ******************************************************************************/
205acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
206{
207 struct acpi_gpe_event_info *gpe_event_info;
208 acpi_status status;
209 acpi_cpu_flags flags;
210
211 ACPI_FUNCTION_TRACE(acpi_set_gpe);
212
213 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
214
215 /* Ensure that we have a valid GPE number */
216
217 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
218 if (!gpe_event_info) {
219 status = AE_BAD_PARAMETER;
220 goto unlock_and_exit;
221 }
222
223 /* Perform the action */
224
225 switch (action) {
226 case ACPI_GPE_ENABLE:
227
228 status = acpi_ev_enable_gpe(gpe_event_info);
229 break;
230
231 case ACPI_GPE_DISABLE:
232
233 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
234 break;
235
236 default:
237
238 status = AE_BAD_PARAMETER;
239 break;
240 }
241
242unlock_and_exit:
243 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
244 return_ACPI_STATUS(status);
245}
246
247ACPI_EXPORT_SYMBOL(acpi_set_gpe)
bba63a29 248
c12f07d1
RW
249/*******************************************************************************
250 *
251 * FUNCTION: acpi_mark_gpe_for_wake
252 *
253 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
254 * gpe_number - GPE level within the GPE block
255 *
256 * RETURN: Status
257 *
258 * DESCRIPTION: Mark a GPE as having the ability to wake the system. Simply
259 * sets the ACPI_GPE_CAN_WAKE flag.
260 *
261 * Some potential callers of acpi_setup_gpe_for_wake may know in advance that
262 * there won't be any notify handlers installed for device wake notifications
263 * from the given GPE (one example is a button GPE in Linux). For these cases,
264 * acpi_mark_gpe_for_wake should be used instead of acpi_setup_gpe_for_wake.
265 * This will set the ACPI_GPE_CAN_WAKE flag for the GPE without trying to
266 * setup implicit wake notification for it (since there's no handler method).
267 *
268 ******************************************************************************/
269acpi_status acpi_mark_gpe_for_wake(acpi_handle gpe_device, u32 gpe_number)
270{
271 struct acpi_gpe_event_info *gpe_event_info;
272 acpi_status status = AE_BAD_PARAMETER;
273 acpi_cpu_flags flags;
274
275 ACPI_FUNCTION_TRACE(acpi_mark_gpe_for_wake);
276
277 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
278
279 /* Ensure that we have a valid GPE number */
280
281 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
282 if (gpe_event_info) {
283
284 /* Mark the GPE as a possible wake event */
285
286 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
287 status = AE_OK;
288 }
289
290 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
291 return_ACPI_STATUS(status);
292}
293
294ACPI_EXPORT_SYMBOL(acpi_mark_gpe_for_wake)
295
3cfd53d5
LM
296/*******************************************************************************
297 *
3a37898d 298 * FUNCTION: acpi_setup_gpe_for_wake
3cfd53d5 299 *
bba63a29
LM
300 * PARAMETERS: wake_device - Device associated with the GPE (via _PRW)
301 * gpe_device - Parent GPE Device. NULL for GPE0/GPE1
302 * gpe_number - GPE level within the GPE block
3cfd53d5
LM
303 *
304 * RETURN: Status
305 *
bba63a29
LM
306 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
307 * interface is intended to be used as the host executes the
308 * _PRW methods (Power Resources for Wake) in the system tables.
309 * Each _PRW appears under a Device Object (The wake_device), and
310 * contains the info for the wake GPE associated with the
311 * wake_device.
3cfd53d5
LM
312 *
313 ******************************************************************************/
bba63a29
LM
314acpi_status
315acpi_setup_gpe_for_wake(acpi_handle wake_device,
316 acpi_handle gpe_device, u32 gpe_number)
3cfd53d5 317{
5816b343 318 acpi_status status;
3cfd53d5 319 struct acpi_gpe_event_info *gpe_event_info;
bba63a29 320 struct acpi_namespace_node *device_node;
5816b343
BM
321 struct acpi_gpe_notify_info *notify;
322 struct acpi_gpe_notify_info *new_notify;
3cfd53d5
LM
323 acpi_cpu_flags flags;
324
3a37898d 325 ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake);
3cfd53d5 326
bba63a29
LM
327 /* Parameter Validation */
328
329 if (!wake_device) {
330 /*
331 * By forcing wake_device to be valid, we automatically enable the
332 * implicit notify feature on all hosts.
333 */
334 return_ACPI_STATUS(AE_BAD_PARAMETER);
335 }
336
5816b343
BM
337 /* Handle root object case */
338
339 if (wake_device == ACPI_ROOT_OBJECT) {
340 device_node = acpi_gbl_root_node;
341 } else {
1f86e8c1
LZ
342 device_node =
343 ACPI_CAST_PTR(struct acpi_namespace_node, wake_device);
5816b343
BM
344 }
345
75c8044f 346 /* Validate wake_device is of type Device */
5816b343
BM
347
348 if (device_node->type != ACPI_TYPE_DEVICE) {
349 return_ACPI_STATUS (AE_BAD_PARAMETER);
350 }
351
352 /*
353 * Allocate a new notify object up front, in case it is needed.
354 * Memory allocation while holding a spinlock is a big no-no
355 * on some hosts.
356 */
357 new_notify = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_notify_info));
358 if (!new_notify) {
359 return_ACPI_STATUS(AE_NO_MEMORY);
360 }
361
3cfd53d5
LM
362 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
363
364 /* Ensure that we have a valid GPE number */
365
366 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
2d559513 367 if (!gpe_event_info) {
5816b343 368 status = AE_BAD_PARAMETER;
2d559513
RW
369 goto unlock_and_exit;
370 }
bba63a29 371
2d559513
RW
372 /*
373 * If there is no method or handler for this GPE, then the
5816b343
BM
374 * wake_device will be notified whenever this GPE fires. This is
375 * known as an "implicit notify". Note: The GPE is assumed to be
2d559513
RW
376 * level-triggered (for windows compatibility).
377 */
7c43312a 378 if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
5816b343
BM
379 ACPI_GPE_DISPATCH_NONE) {
380 /*
381 * This is the first device for implicit notify on this GPE.
382 * Just set the flags here, and enter the NOTIFY block below.
383 */
384 gpe_event_info->flags =
385 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
981858bd
RW
386 }
387
5816b343
BM
388 /*
389 * If we already have an implicit notify on this GPE, add
390 * this device to the notify list.
391 */
7c43312a 392 if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
5816b343
BM
393 ACPI_GPE_DISPATCH_NOTIFY) {
394
395 /* Ensure that the device is not already in the list */
396
397 notify = gpe_event_info->dispatch.notify_list;
398 while (notify) {
399 if (notify->device_node == device_node) {
400 status = AE_ALREADY_EXISTS;
401 goto unlock_and_exit;
402 }
403 notify = notify->next;
981858bd
RW
404 }
405
5816b343
BM
406 /* Add this device to the notify list for this GPE */
407
408 new_notify->device_node = device_node;
409 new_notify->next = gpe_event_info->dispatch.notify_list;
410 gpe_event_info->dispatch.notify_list = new_notify;
411 new_notify = NULL;
3cfd53d5
LM
412 }
413
5816b343
BM
414 /* Mark the GPE as a possible wake event */
415
2d559513
RW
416 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
417 status = AE_OK;
418
5816b343 419unlock_and_exit:
3cfd53d5 420 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
5816b343
BM
421
422 /* Delete the notify object if it was not used above */
423
424 if (new_notify) {
425 ACPI_FREE(new_notify);
426 }
3cfd53d5
LM
427 return_ACPI_STATUS(status);
428}
3a37898d 429ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
3cfd53d5
LM
430
431/*******************************************************************************
432 *
3a37898d 433 * FUNCTION: acpi_set_gpe_wake_mask
3cfd53d5
LM
434 *
435 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
436 * gpe_number - GPE level within the GPE block
ba494bee 437 * action - Enable or Disable
3cfd53d5
LM
438 *
439 * RETURN: Status
440 *
da503373
LM
441 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
442 * already be marked as a WAKE GPE.
3cfd53d5
LM
443 *
444 ******************************************************************************/
445
1f86e8c1
LZ
446acpi_status
447acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
3cfd53d5
LM
448{
449 acpi_status status = AE_OK;
450 struct acpi_gpe_event_info *gpe_event_info;
451 struct acpi_gpe_register_info *gpe_register_info;
452 acpi_cpu_flags flags;
453 u32 register_bit;
454
3a37898d 455 ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
3cfd53d5
LM
456
457 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
458
da503373
LM
459 /*
460 * Ensure that we have a valid GPE number and that this GPE is in
461 * fact a wake GPE
462 */
3cfd53d5 463 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
3a37898d 464 if (!gpe_event_info) {
3cfd53d5
LM
465 status = AE_BAD_PARAMETER;
466 goto unlock_and_exit;
467 }
468
3a37898d
LM
469 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
470 status = AE_TYPE;
471 goto unlock_and_exit;
472 }
473
3cfd53d5
LM
474 gpe_register_info = gpe_event_info->register_info;
475 if (!gpe_register_info) {
476 status = AE_NOT_EXIST;
477 goto unlock_and_exit;
478 }
479
1d94e1e8 480 register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
3cfd53d5
LM
481
482 /* Perform the action */
483
484 switch (action) {
485 case ACPI_GPE_ENABLE:
1d1ea1b7 486
3cfd53d5
LM
487 ACPI_SET_BIT(gpe_register_info->enable_for_wake,
488 (u8)register_bit);
489 break;
490
491 case ACPI_GPE_DISABLE:
1d1ea1b7 492
3cfd53d5
LM
493 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
494 (u8)register_bit);
495 break;
496
497 default:
1d1ea1b7 498
3cfd53d5
LM
499 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
500 status = AE_BAD_PARAMETER;
501 break;
502 }
503
504unlock_and_exit:
505 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
506 return_ACPI_STATUS(status);
507}
508
3a37898d 509ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
3cfd53d5
LM
510
511/*******************************************************************************
512 *
513 * FUNCTION: acpi_clear_gpe
514 *
515 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
516 * gpe_number - GPE level within the GPE block
517 *
518 * RETURN: Status
519 *
520 * DESCRIPTION: Clear an ACPI event (general purpose)
521 *
522 ******************************************************************************/
523acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
524{
525 acpi_status status = AE_OK;
526 struct acpi_gpe_event_info *gpe_event_info;
527 acpi_cpu_flags flags;
528
529 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
530
531 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
532
533 /* Ensure that we have a valid GPE number */
534
535 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
536 if (!gpe_event_info) {
537 status = AE_BAD_PARAMETER;
538 goto unlock_and_exit;
539 }
540
541 status = acpi_hw_clear_gpe(gpe_event_info);
542
543 unlock_and_exit:
544 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
545 return_ACPI_STATUS(status);
546}
547
548ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
549
550/*******************************************************************************
551 *
552 * FUNCTION: acpi_get_gpe_status
553 *
f19f1a7e
LZ
554 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
555 * gpe_number - GPE level within the GPE block
75c8044f
LZ
556 * event_status - Where the current status of the event
557 * will be returned
3cfd53d5
LM
558 *
559 * RETURN: Status
560 *
da503373 561 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
3cfd53d5
LM
562 *
563 ******************************************************************************/
564acpi_status
565acpi_get_gpe_status(acpi_handle gpe_device,
566 u32 gpe_number, acpi_event_status *event_status)
567{
568 acpi_status status = AE_OK;
569 struct acpi_gpe_event_info *gpe_event_info;
570 acpi_cpu_flags flags;
571
572 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
573
574 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
575
576 /* Ensure that we have a valid GPE number */
577
578 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
579 if (!gpe_event_info) {
580 status = AE_BAD_PARAMETER;
581 goto unlock_and_exit;
582 }
583
584 /* Obtain status on the requested GPE number */
585
586 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
587
10622bf8 588unlock_and_exit:
3cfd53d5
LM
589 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
590 return_ACPI_STATUS(status);
591}
592
593ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
594
eb3d80f7
LZ
595/*******************************************************************************
596 *
597 * FUNCTION: acpi_finish_gpe
598 *
599 * PARAMETERS: gpe_device - Namespace node for the GPE Block
600 * (NULL for FADT defined GPEs)
601 * gpe_number - GPE level within the GPE block
602 *
603 * RETURN: Status
604 *
605 * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
606 * processing. Intended for use by asynchronous host-installed
607 * GPE handlers. The GPE is only reenabled if the enable_for_run bit
608 * is set in the GPE info.
609 *
610 ******************************************************************************/
611acpi_status acpi_finish_gpe(acpi_handle gpe_device, u32 gpe_number)
612{
613 struct acpi_gpe_event_info *gpe_event_info;
614 acpi_status status;
615 acpi_cpu_flags flags;
616
617 ACPI_FUNCTION_TRACE(acpi_finish_gpe);
618
619 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
620
621 /* Ensure that we have a valid GPE number */
622
623 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
624 if (!gpe_event_info) {
625 status = AE_BAD_PARAMETER;
626 goto unlock_and_exit;
627 }
628
629 status = acpi_ev_finish_gpe(gpe_event_info);
630
631unlock_and_exit:
632 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
633 return_ACPI_STATUS(status);
634}
635
636ACPI_EXPORT_SYMBOL(acpi_finish_gpe)
637
3cfd53d5
LM
638/******************************************************************************
639 *
640 * FUNCTION: acpi_disable_all_gpes
641 *
642 * PARAMETERS: None
643 *
644 * RETURN: Status
645 *
646 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
647 *
648 ******************************************************************************/
649
650acpi_status acpi_disable_all_gpes(void)
651{
652 acpi_status status;
653
654 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
655
656 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
657 if (ACPI_FAILURE(status)) {
658 return_ACPI_STATUS(status);
659 }
660
661 status = acpi_hw_disable_all_gpes();
662 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
663
664 return_ACPI_STATUS(status);
665}
666
3a37898d
LM
667ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
668
3cfd53d5
LM
669/******************************************************************************
670 *
671 * FUNCTION: acpi_enable_all_runtime_gpes
672 *
673 * PARAMETERS: None
674 *
675 * RETURN: Status
676 *
677 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
678 *
679 ******************************************************************************/
680
681acpi_status acpi_enable_all_runtime_gpes(void)
682{
683 acpi_status status;
684
685 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
686
687 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
688 if (ACPI_FAILURE(status)) {
689 return_ACPI_STATUS(status);
690 }
691
692 status = acpi_hw_enable_all_runtime_gpes();
693 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
694
695 return_ACPI_STATUS(status);
696}
697
3a37898d
LM
698ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
699
e0fa975d
RW
700/******************************************************************************
701 *
702 * FUNCTION: acpi_enable_all_wakeup_gpes
703 *
704 * PARAMETERS: None
705 *
706 * RETURN: Status
707 *
708 * DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in
709 * all GPE blocks.
710 *
711 ******************************************************************************/
e0fa975d
RW
712acpi_status acpi_enable_all_wakeup_gpes(void)
713{
714 acpi_status status;
715
716 ACPI_FUNCTION_TRACE(acpi_enable_all_wakeup_gpes);
717
718 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
719 if (ACPI_FAILURE(status)) {
720 return_ACPI_STATUS(status);
721 }
722
723 status = acpi_hw_enable_all_wakeup_gpes();
724 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
725
726 return_ACPI_STATUS(status);
727}
728
729ACPI_EXPORT_SYMBOL(acpi_enable_all_wakeup_gpes)
730
3cfd53d5
LM
731/*******************************************************************************
732 *
733 * FUNCTION: acpi_install_gpe_block
734 *
735 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
ba494bee 736 * gpe_block_address - Address and space_ID
3cfd53d5
LM
737 * register_count - Number of GPE register pairs in the block
738 * interrupt_number - H/W interrupt for the block
739 *
740 * RETURN: Status
741 *
da503373
LM
742 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
743 * enabled here.
3cfd53d5
LM
744 *
745 ******************************************************************************/
746acpi_status
747acpi_install_gpe_block(acpi_handle gpe_device,
748 struct acpi_generic_address *gpe_block_address,
749 u32 register_count, u32 interrupt_number)
750{
3a37898d 751 acpi_status status;
3cfd53d5
LM
752 union acpi_operand_object *obj_desc;
753 struct acpi_namespace_node *node;
754 struct acpi_gpe_block_info *gpe_block;
755
756 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
757
758 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
759 return_ACPI_STATUS(AE_BAD_PARAMETER);
760 }
761
762 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
763 if (ACPI_FAILURE(status)) {
68aafc35 764 return_ACPI_STATUS(status);
3cfd53d5
LM
765 }
766
767 node = acpi_ns_validate_handle(gpe_device);
768 if (!node) {
769 status = AE_BAD_PARAMETER;
770 goto unlock_and_exit;
771 }
772
9186fb58
BM
773 /* Validate the parent device */
774
775 if (node->type != ACPI_TYPE_DEVICE) {
776 status = AE_TYPE;
777 goto unlock_and_exit;
778 }
779
780 if (node->object) {
781 status = AE_ALREADY_EXISTS;
782 goto unlock_and_exit;
783 }
784
3cfd53d5
LM
785 /*
786 * For user-installed GPE Block Devices, the gpe_block_base_number
787 * is always zero
788 */
7505da4c
BM
789 status = acpi_ev_create_gpe_block(node, gpe_block_address->address,
790 gpe_block_address->space_id,
791 register_count, 0, interrupt_number,
792 &gpe_block);
3cfd53d5
LM
793 if (ACPI_FAILURE(status)) {
794 goto unlock_and_exit;
795 }
796
797 /* Install block in the device_object attached to the node */
798
799 obj_desc = acpi_ns_get_attached_object(node);
800 if (!obj_desc) {
801
802 /*
803 * No object, create a new one (Device nodes do not always have
804 * an attached object)
805 */
806 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
807 if (!obj_desc) {
808 status = AE_NO_MEMORY;
809 goto unlock_and_exit;
810 }
811
812 status =
813 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
814
815 /* Remove local reference to the object */
816
817 acpi_ut_remove_reference(obj_desc);
818
819 if (ACPI_FAILURE(status)) {
820 goto unlock_and_exit;
821 }
822 }
823
824 /* Now install the GPE block in the device_object */
825
826 obj_desc->device.gpe_block = gpe_block;
827
10622bf8 828unlock_and_exit:
3cfd53d5
LM
829 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
830 return_ACPI_STATUS(status);
831}
832
833ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
834
835/*******************************************************************************
836 *
837 * FUNCTION: acpi_remove_gpe_block
838 *
839 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
840 *
841 * RETURN: Status
842 *
843 * DESCRIPTION: Remove a previously installed block of GPE registers
844 *
845 ******************************************************************************/
846acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
847{
848 union acpi_operand_object *obj_desc;
849 acpi_status status;
850 struct acpi_namespace_node *node;
851
852 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
853
854 if (!gpe_device) {
855 return_ACPI_STATUS(AE_BAD_PARAMETER);
856 }
857
858 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
859 if (ACPI_FAILURE(status)) {
68aafc35 860 return_ACPI_STATUS(status);
3cfd53d5
LM
861 }
862
863 node = acpi_ns_validate_handle(gpe_device);
864 if (!node) {
865 status = AE_BAD_PARAMETER;
866 goto unlock_and_exit;
867 }
868
9186fb58
BM
869 /* Validate the parent device */
870
871 if (node->type != ACPI_TYPE_DEVICE) {
872 status = AE_TYPE;
873 goto unlock_and_exit;
874 }
875
3cfd53d5
LM
876 /* Get the device_object attached to the node */
877
878 obj_desc = acpi_ns_get_attached_object(node);
879 if (!obj_desc || !obj_desc->device.gpe_block) {
880 return_ACPI_STATUS(AE_NULL_OBJECT);
881 }
882
883 /* Delete the GPE block (but not the device_object) */
884
885 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
886 if (ACPI_SUCCESS(status)) {
887 obj_desc->device.gpe_block = NULL;
888 }
889
10622bf8 890unlock_and_exit:
3cfd53d5
LM
891 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
892 return_ACPI_STATUS(status);
893}
894
895ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
896
897/*******************************************************************************
898 *
899 * FUNCTION: acpi_get_gpe_device
900 *
ba494bee 901 * PARAMETERS: index - System GPE index (0-current_gpe_count)
3cfd53d5
LM
902 * gpe_device - Where the parent GPE Device is returned
903 *
904 * RETURN: Status
905 *
906 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
907 * gpe device indicates that the gpe number is contained in one of
908 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
909 *
910 ******************************************************************************/
1f86e8c1 911acpi_status acpi_get_gpe_device(u32 index, acpi_handle * gpe_device)
3cfd53d5
LM
912{
913 struct acpi_gpe_device_info info;
914 acpi_status status;
915
916 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
917
918 if (!gpe_device) {
919 return_ACPI_STATUS(AE_BAD_PARAMETER);
920 }
921
922 if (index >= acpi_current_gpe_count) {
923 return_ACPI_STATUS(AE_NOT_EXIST);
924 }
925
926 /* Setup and walk the GPE list */
927
928 info.index = index;
929 info.status = AE_NOT_EXIST;
930 info.gpe_device = NULL;
931 info.next_block_base_index = 0;
932
933 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
934 if (ACPI_FAILURE(status)) {
935 return_ACPI_STATUS(status);
936 }
937
3a37898d 938 *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
3cfd53d5
LM
939 return_ACPI_STATUS(info.status);
940}
941
942ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
33620c54 943#endif /* !ACPI_REDUCED_HARDWARE */
This page took 0.301397 seconds and 5 git commands to generate.