1 /******************************************************************************
3 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define EXPORT_ACPI_INTERFACES
46 #include <acpi/acpi.h>
51 #define _COMPONENT ACPI_EVENTS
52 ACPI_MODULE_NAME("evxfgpe")
54 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
55 /*******************************************************************************
57 * FUNCTION: acpi_update_all_gpes
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.)
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
75 ******************************************************************************/
77 acpi_status
acpi_update_all_gpes(void)
81 ACPI_FUNCTION_TRACE(acpi_update_all_gpes
);
83 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
84 if (ACPI_FAILURE(status
)) {
85 return_ACPI_STATUS(status
);
88 if (acpi_gbl_all_gpes_initialized
) {
92 status
= acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block
, NULL
);
93 if (ACPI_SUCCESS(status
)) {
94 acpi_gbl_all_gpes_initialized
= TRUE
;
98 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
100 return_ACPI_STATUS(status
);
103 ACPI_EXPORT_SYMBOL(acpi_update_all_gpes
)
105 /*******************************************************************************
107 * FUNCTION: acpi_enable_gpe
109 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
110 * gpe_number - GPE level within the GPE block
114 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
117 ******************************************************************************/
119 acpi_status
acpi_enable_gpe(acpi_handle gpe_device
, u32 gpe_number
)
121 acpi_status status
= AE_BAD_PARAMETER
;
122 struct acpi_gpe_event_info
*gpe_event_info
;
123 acpi_cpu_flags flags
;
125 ACPI_FUNCTION_TRACE(acpi_enable_gpe
);
127 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
129 /* Ensure that we have a valid GPE number */
131 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
132 if (gpe_event_info
) {
133 status
= acpi_ev_add_gpe_reference(gpe_event_info
);
136 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
137 return_ACPI_STATUS(status
);
139 ACPI_EXPORT_SYMBOL(acpi_enable_gpe
)
141 /*******************************************************************************
143 * FUNCTION: acpi_disable_gpe
145 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
146 * gpe_number - GPE level within the GPE block
150 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
151 * removed, only then is the GPE disabled (for runtime GPEs), or
152 * the GPE mask bit disabled (for wake GPEs)
154 ******************************************************************************/
156 acpi_status
acpi_disable_gpe(acpi_handle gpe_device
, u32 gpe_number
)
158 acpi_status status
= AE_BAD_PARAMETER
;
159 struct acpi_gpe_event_info
*gpe_event_info
;
160 acpi_cpu_flags flags
;
162 ACPI_FUNCTION_TRACE(acpi_disable_gpe
);
164 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
166 /* Ensure that we have a valid GPE number */
168 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
169 if (gpe_event_info
) {
170 status
= acpi_ev_remove_gpe_reference(gpe_event_info
) ;
173 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
174 return_ACPI_STATUS(status
);
177 ACPI_EXPORT_SYMBOL(acpi_disable_gpe
)
180 /*******************************************************************************
182 * FUNCTION: acpi_setup_gpe_for_wake
184 * PARAMETERS: wake_device - Device associated with the GPE (via _PRW)
185 * gpe_device - Parent GPE Device. NULL for GPE0/GPE1
186 * gpe_number - GPE level within the GPE block
190 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
191 * interface is intended to be used as the host executes the
192 * _PRW methods (Power Resources for Wake) in the system tables.
193 * Each _PRW appears under a Device Object (The wake_device), and
194 * contains the info for the wake GPE associated with the
197 ******************************************************************************/
199 acpi_setup_gpe_for_wake(acpi_handle wake_device
,
200 acpi_handle gpe_device
, u32 gpe_number
)
203 struct acpi_gpe_event_info
*gpe_event_info
;
204 struct acpi_namespace_node
*device_node
;
205 struct acpi_gpe_notify_info
*notify
;
206 struct acpi_gpe_notify_info
*new_notify
;
207 acpi_cpu_flags flags
;
209 ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake
);
211 /* Parameter Validation */
215 * By forcing wake_device to be valid, we automatically enable the
216 * implicit notify feature on all hosts.
218 return_ACPI_STATUS(AE_BAD_PARAMETER
);
221 /* Handle root object case */
223 if (wake_device
== ACPI_ROOT_OBJECT
) {
224 device_node
= acpi_gbl_root_node
;
227 ACPI_CAST_PTR(struct acpi_namespace_node
, wake_device
);
230 /* Validate wake_device is of type Device */
232 if (device_node
->type
!= ACPI_TYPE_DEVICE
) {
233 return_ACPI_STATUS (AE_BAD_PARAMETER
);
237 * Allocate a new notify object up front, in case it is needed.
238 * Memory allocation while holding a spinlock is a big no-no
241 new_notify
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_notify_info
));
243 return_ACPI_STATUS(AE_NO_MEMORY
);
246 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
248 /* Ensure that we have a valid GPE number */
250 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
251 if (!gpe_event_info
) {
252 status
= AE_BAD_PARAMETER
;
253 goto unlock_and_exit
;
257 * If there is no method or handler for this GPE, then the
258 * wake_device will be notified whenever this GPE fires. This is
259 * known as an "implicit notify". Note: The GPE is assumed to be
260 * level-triggered (for windows compatibility).
262 if ((gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
) ==
263 ACPI_GPE_DISPATCH_NONE
) {
265 * This is the first device for implicit notify on this GPE.
266 * Just set the flags here, and enter the NOTIFY block below.
268 gpe_event_info
->flags
=
269 (ACPI_GPE_DISPATCH_NOTIFY
| ACPI_GPE_LEVEL_TRIGGERED
);
273 * If we already have an implicit notify on this GPE, add
274 * this device to the notify list.
276 if ((gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
) ==
277 ACPI_GPE_DISPATCH_NOTIFY
) {
279 /* Ensure that the device is not already in the list */
281 notify
= gpe_event_info
->dispatch
.notify_list
;
283 if (notify
->device_node
== device_node
) {
284 status
= AE_ALREADY_EXISTS
;
285 goto unlock_and_exit
;
287 notify
= notify
->next
;
290 /* Add this device to the notify list for this GPE */
292 new_notify
->device_node
= device_node
;
293 new_notify
->next
= gpe_event_info
->dispatch
.notify_list
;
294 gpe_event_info
->dispatch
.notify_list
= new_notify
;
298 /* Mark the GPE as a possible wake event */
300 gpe_event_info
->flags
|= ACPI_GPE_CAN_WAKE
;
304 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
306 /* Delete the notify object if it was not used above */
309 ACPI_FREE(new_notify
);
311 return_ACPI_STATUS(status
);
313 ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake
)
315 /*******************************************************************************
317 * FUNCTION: acpi_set_gpe_wake_mask
319 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
320 * gpe_number - GPE level within the GPE block
321 * action - Enable or Disable
325 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
326 * already be marked as a WAKE GPE.
328 ******************************************************************************/
331 acpi_set_gpe_wake_mask(acpi_handle gpe_device
, u32 gpe_number
, u8 action
)
333 acpi_status status
= AE_OK
;
334 struct acpi_gpe_event_info
*gpe_event_info
;
335 struct acpi_gpe_register_info
*gpe_register_info
;
336 acpi_cpu_flags flags
;
339 ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask
);
341 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
344 * Ensure that we have a valid GPE number and that this GPE is in
347 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
348 if (!gpe_event_info
) {
349 status
= AE_BAD_PARAMETER
;
350 goto unlock_and_exit
;
353 if (!(gpe_event_info
->flags
& ACPI_GPE_CAN_WAKE
)) {
355 goto unlock_and_exit
;
358 gpe_register_info
= gpe_event_info
->register_info
;
359 if (!gpe_register_info
) {
360 status
= AE_NOT_EXIST
;
361 goto unlock_and_exit
;
364 register_bit
= acpi_hw_get_gpe_register_bit(gpe_event_info
);
366 /* Perform the action */
369 case ACPI_GPE_ENABLE
:
371 ACPI_SET_BIT(gpe_register_info
->enable_for_wake
,
375 case ACPI_GPE_DISABLE
:
377 ACPI_CLEAR_BIT(gpe_register_info
->enable_for_wake
,
383 ACPI_ERROR((AE_INFO
, "%u, Invalid action", action
));
384 status
= AE_BAD_PARAMETER
;
389 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
390 return_ACPI_STATUS(status
);
393 ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask
)
395 /*******************************************************************************
397 * FUNCTION: acpi_clear_gpe
399 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
400 * gpe_number - GPE level within the GPE block
404 * DESCRIPTION: Clear an ACPI event (general purpose)
406 ******************************************************************************/
407 acpi_status
acpi_clear_gpe(acpi_handle gpe_device
, u32 gpe_number
)
409 acpi_status status
= AE_OK
;
410 struct acpi_gpe_event_info
*gpe_event_info
;
411 acpi_cpu_flags flags
;
413 ACPI_FUNCTION_TRACE(acpi_clear_gpe
);
415 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
417 /* Ensure that we have a valid GPE number */
419 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
420 if (!gpe_event_info
) {
421 status
= AE_BAD_PARAMETER
;
422 goto unlock_and_exit
;
425 status
= acpi_hw_clear_gpe(gpe_event_info
);
428 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
429 return_ACPI_STATUS(status
);
432 ACPI_EXPORT_SYMBOL(acpi_clear_gpe
)
434 /*******************************************************************************
436 * FUNCTION: acpi_get_gpe_status
438 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
439 * gpe_number - GPE level within the GPE block
440 * event_status - Where the current status of the event
445 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
447 ******************************************************************************/
449 acpi_get_gpe_status(acpi_handle gpe_device
,
450 u32 gpe_number
, acpi_event_status
*event_status
)
452 acpi_status status
= AE_OK
;
453 struct acpi_gpe_event_info
*gpe_event_info
;
454 acpi_cpu_flags flags
;
456 ACPI_FUNCTION_TRACE(acpi_get_gpe_status
);
458 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
460 /* Ensure that we have a valid GPE number */
462 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
463 if (!gpe_event_info
) {
464 status
= AE_BAD_PARAMETER
;
465 goto unlock_and_exit
;
468 /* Obtain status on the requested GPE number */
470 status
= acpi_hw_get_gpe_status(gpe_event_info
, event_status
);
472 if (gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
)
473 *event_status
|= ACPI_EVENT_FLAG_HANDLE
;
476 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
477 return_ACPI_STATUS(status
);
480 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status
)
482 /******************************************************************************
484 * FUNCTION: acpi_disable_all_gpes
490 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
492 ******************************************************************************/
494 acpi_status
acpi_disable_all_gpes(void)
498 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes
);
500 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
501 if (ACPI_FAILURE(status
)) {
502 return_ACPI_STATUS(status
);
505 status
= acpi_hw_disable_all_gpes();
506 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
508 return_ACPI_STATUS(status
);
511 ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes
)
513 /******************************************************************************
515 * FUNCTION: acpi_enable_all_runtime_gpes
521 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
523 ******************************************************************************/
525 acpi_status
acpi_enable_all_runtime_gpes(void)
529 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes
);
531 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
532 if (ACPI_FAILURE(status
)) {
533 return_ACPI_STATUS(status
);
536 status
= acpi_hw_enable_all_runtime_gpes();
537 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
539 return_ACPI_STATUS(status
);
542 ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes
)
544 /*******************************************************************************
546 * FUNCTION: acpi_install_gpe_block
548 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
549 * gpe_block_address - Address and space_ID
550 * register_count - Number of GPE register pairs in the block
551 * interrupt_number - H/W interrupt for the block
555 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
558 ******************************************************************************/
560 acpi_install_gpe_block(acpi_handle gpe_device
,
561 struct acpi_generic_address
*gpe_block_address
,
562 u32 register_count
, u32 interrupt_number
)
565 union acpi_operand_object
*obj_desc
;
566 struct acpi_namespace_node
*node
;
567 struct acpi_gpe_block_info
*gpe_block
;
569 ACPI_FUNCTION_TRACE(acpi_install_gpe_block
);
571 if ((!gpe_device
) || (!gpe_block_address
) || (!register_count
)) {
572 return_ACPI_STATUS(AE_BAD_PARAMETER
);
575 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
576 if (ACPI_FAILURE(status
)) {
577 return_ACPI_STATUS(status
);
580 node
= acpi_ns_validate_handle(gpe_device
);
582 status
= AE_BAD_PARAMETER
;
583 goto unlock_and_exit
;
587 * For user-installed GPE Block Devices, the gpe_block_base_number
591 acpi_ev_create_gpe_block(node
, gpe_block_address
, register_count
, 0,
592 interrupt_number
, &gpe_block
);
593 if (ACPI_FAILURE(status
)) {
594 goto unlock_and_exit
;
597 /* Install block in the device_object attached to the node */
599 obj_desc
= acpi_ns_get_attached_object(node
);
603 * No object, create a new one (Device nodes do not always have
604 * an attached object)
606 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_DEVICE
);
608 status
= AE_NO_MEMORY
;
609 goto unlock_and_exit
;
613 acpi_ns_attach_object(node
, obj_desc
, ACPI_TYPE_DEVICE
);
615 /* Remove local reference to the object */
617 acpi_ut_remove_reference(obj_desc
);
619 if (ACPI_FAILURE(status
)) {
620 goto unlock_and_exit
;
624 /* Now install the GPE block in the device_object */
626 obj_desc
->device
.gpe_block
= gpe_block
;
629 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
630 return_ACPI_STATUS(status
);
633 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block
)
635 /*******************************************************************************
637 * FUNCTION: acpi_remove_gpe_block
639 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
643 * DESCRIPTION: Remove a previously installed block of GPE registers
645 ******************************************************************************/
646 acpi_status
acpi_remove_gpe_block(acpi_handle gpe_device
)
648 union acpi_operand_object
*obj_desc
;
650 struct acpi_namespace_node
*node
;
652 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block
);
655 return_ACPI_STATUS(AE_BAD_PARAMETER
);
658 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
659 if (ACPI_FAILURE(status
)) {
660 return_ACPI_STATUS(status
);
663 node
= acpi_ns_validate_handle(gpe_device
);
665 status
= AE_BAD_PARAMETER
;
666 goto unlock_and_exit
;
669 /* Get the device_object attached to the node */
671 obj_desc
= acpi_ns_get_attached_object(node
);
672 if (!obj_desc
|| !obj_desc
->device
.gpe_block
) {
673 return_ACPI_STATUS(AE_NULL_OBJECT
);
676 /* Delete the GPE block (but not the device_object) */
678 status
= acpi_ev_delete_gpe_block(obj_desc
->device
.gpe_block
);
679 if (ACPI_SUCCESS(status
)) {
680 obj_desc
->device
.gpe_block
= NULL
;
684 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
685 return_ACPI_STATUS(status
);
688 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block
)
690 /*******************************************************************************
692 * FUNCTION: acpi_get_gpe_device
694 * PARAMETERS: index - System GPE index (0-current_gpe_count)
695 * gpe_device - Where the parent GPE Device is returned
699 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
700 * gpe device indicates that the gpe number is contained in one of
701 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
703 ******************************************************************************/
704 acpi_status
acpi_get_gpe_device(u32 index
, acpi_handle
* gpe_device
)
706 struct acpi_gpe_device_info info
;
709 ACPI_FUNCTION_TRACE(acpi_get_gpe_device
);
712 return_ACPI_STATUS(AE_BAD_PARAMETER
);
715 if (index
>= acpi_current_gpe_count
) {
716 return_ACPI_STATUS(AE_NOT_EXIST
);
719 /* Setup and walk the GPE list */
722 info
.status
= AE_NOT_EXIST
;
723 info
.gpe_device
= NULL
;
724 info
.next_block_base_index
= 0;
726 status
= acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device
, &info
);
727 if (ACPI_FAILURE(status
)) {
728 return_ACPI_STATUS(status
);
731 *gpe_device
= ACPI_CAST_PTR(acpi_handle
, info
.gpe_device
);
732 return_ACPI_STATUS(info
.status
);
735 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device
)
736 #endif /* !ACPI_REDUCED_HARDWARE */