1 /******************************************************************************
3 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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 #include <acpi/acpi.h>
49 #define _COMPONENT ACPI_EVENTS
50 ACPI_MODULE_NAME("evxfgpe")
52 /******************************************************************************
54 * FUNCTION: acpi_update_all_gpes
60 * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
61 * associated _Lxx or _Exx methods and are not pointed to by any
62 * device _PRW methods (this indicates that these GPEs are
63 * generally intended for system or device wakeup. Such GPEs
64 * have to be enabled directly when the devices whose _PRW
65 * methods point to them are set up for wakeup signaling.)
67 * NOTE: Should be called after any GPEs are added to the system. Primarily,
68 * after the system _PRW methods have been run, but also after a GPE Block
69 * Device has been added or if any new GPE methods have been added via a
72 ******************************************************************************/
74 acpi_status
acpi_update_all_gpes(void)
78 ACPI_FUNCTION_TRACE(acpi_update_all_gpes
);
80 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
81 if (ACPI_FAILURE(status
)) {
82 return_ACPI_STATUS(status
);
85 if (acpi_gbl_all_gpes_initialized
) {
89 status
= acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block
, NULL
);
90 if (ACPI_SUCCESS(status
)) {
91 acpi_gbl_all_gpes_initialized
= TRUE
;
95 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
97 return_ACPI_STATUS(status
);
100 ACPI_EXPORT_SYMBOL(acpi_update_all_gpes
)
102 /*******************************************************************************
104 * FUNCTION: acpi_enable_gpe
106 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
107 * gpe_number - GPE level within the GPE block
111 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
114 ******************************************************************************/
116 acpi_status
acpi_enable_gpe(acpi_handle gpe_device
, u32 gpe_number
)
118 acpi_status status
= AE_BAD_PARAMETER
;
119 struct acpi_gpe_event_info
*gpe_event_info
;
120 acpi_cpu_flags flags
;
122 ACPI_FUNCTION_TRACE(acpi_enable_gpe
);
124 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
126 /* Ensure that we have a valid GPE number */
128 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
129 if (gpe_event_info
) {
130 status
= acpi_ev_add_gpe_reference(gpe_event_info
);
133 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
134 return_ACPI_STATUS(status
);
136 ACPI_EXPORT_SYMBOL(acpi_enable_gpe
)
138 /*******************************************************************************
140 * FUNCTION: acpi_disable_gpe
142 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
143 * gpe_number - GPE level within the GPE block
147 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
148 * removed, only then is the GPE disabled (for runtime GPEs), or
149 * the GPE mask bit disabled (for wake GPEs)
151 ******************************************************************************/
153 acpi_status
acpi_disable_gpe(acpi_handle gpe_device
, u32 gpe_number
)
155 acpi_status status
= AE_BAD_PARAMETER
;
156 struct acpi_gpe_event_info
*gpe_event_info
;
157 acpi_cpu_flags flags
;
159 ACPI_FUNCTION_TRACE(acpi_disable_gpe
);
161 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
163 /* Ensure that we have a valid GPE number */
165 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
166 if (gpe_event_info
) {
167 status
= acpi_ev_remove_gpe_reference(gpe_event_info
) ;
170 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
171 return_ACPI_STATUS(status
);
173 ACPI_EXPORT_SYMBOL(acpi_disable_gpe
)
176 /*******************************************************************************
178 * FUNCTION: acpi_setup_gpe_for_wake
180 * PARAMETERS: wake_device - Device associated with the GPE (via _PRW)
181 * gpe_device - Parent GPE Device. NULL for GPE0/GPE1
182 * gpe_number - GPE level within the GPE block
186 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
187 * interface is intended to be used as the host executes the
188 * _PRW methods (Power Resources for Wake) in the system tables.
189 * Each _PRW appears under a Device Object (The wake_device), and
190 * contains the info for the wake GPE associated with the
193 ******************************************************************************/
195 acpi_setup_gpe_for_wake(acpi_handle wake_device
,
196 acpi_handle gpe_device
, u32 gpe_number
)
198 acpi_status status
= AE_BAD_PARAMETER
;
199 struct acpi_gpe_event_info
*gpe_event_info
;
200 struct acpi_namespace_node
*device_node
;
201 acpi_cpu_flags flags
;
203 ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake
);
205 /* Parameter Validation */
209 * By forcing wake_device to be valid, we automatically enable the
210 * implicit notify feature on all hosts.
212 return_ACPI_STATUS(AE_BAD_PARAMETER
);
215 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
217 /* Ensure that we have a valid GPE number */
219 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
220 if (!gpe_event_info
) {
221 goto unlock_and_exit
;
225 * If there is no method or handler for this GPE, then the
226 * wake_device will be notified whenever this GPE fires (aka
227 * "implicit notify") Note: The GPE is assumed to be
228 * level-triggered (for windows compatibility).
230 if (((gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
) ==
231 ACPI_GPE_DISPATCH_NONE
) && (wake_device
!= ACPI_ROOT_OBJECT
)) {
233 /* Validate wake_device is of type Device */
235 device_node
= ACPI_CAST_PTR(struct acpi_namespace_node
,
237 if (device_node
->type
!= ACPI_TYPE_DEVICE
) {
238 goto unlock_and_exit
;
240 gpe_event_info
->flags
= (ACPI_GPE_DISPATCH_NOTIFY
|
241 ACPI_GPE_LEVEL_TRIGGERED
);
242 gpe_event_info
->dispatch
.device_node
= device_node
;
245 gpe_event_info
->flags
|= ACPI_GPE_CAN_WAKE
;
249 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
250 return_ACPI_STATUS(status
);
252 ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake
)
254 /*******************************************************************************
256 * FUNCTION: acpi_set_gpe_wake_mask
258 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
259 * gpe_number - GPE level within the GPE block
260 * Action - Enable or Disable
264 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
265 * already be marked as a WAKE GPE.
267 ******************************************************************************/
269 acpi_status
acpi_set_gpe_wake_mask(acpi_handle gpe_device
, u32 gpe_number
, u8 action
)
271 acpi_status status
= AE_OK
;
272 struct acpi_gpe_event_info
*gpe_event_info
;
273 struct acpi_gpe_register_info
*gpe_register_info
;
274 acpi_cpu_flags flags
;
277 ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask
);
279 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
282 * Ensure that we have a valid GPE number and that this GPE is in
285 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
286 if (!gpe_event_info
) {
287 status
= AE_BAD_PARAMETER
;
288 goto unlock_and_exit
;
291 if (!(gpe_event_info
->flags
& ACPI_GPE_CAN_WAKE
)) {
293 goto unlock_and_exit
;
296 gpe_register_info
= gpe_event_info
->register_info
;
297 if (!gpe_register_info
) {
298 status
= AE_NOT_EXIST
;
299 goto unlock_and_exit
;
303 acpi_hw_get_gpe_register_bit(gpe_event_info
, gpe_register_info
);
305 /* Perform the action */
308 case ACPI_GPE_ENABLE
:
309 ACPI_SET_BIT(gpe_register_info
->enable_for_wake
,
313 case ACPI_GPE_DISABLE
:
314 ACPI_CLEAR_BIT(gpe_register_info
->enable_for_wake
,
319 ACPI_ERROR((AE_INFO
, "%u, Invalid action", action
));
320 status
= AE_BAD_PARAMETER
;
325 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
326 return_ACPI_STATUS(status
);
329 ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask
)
331 /*******************************************************************************
333 * FUNCTION: acpi_clear_gpe
335 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
336 * gpe_number - GPE level within the GPE block
340 * DESCRIPTION: Clear an ACPI event (general purpose)
342 ******************************************************************************/
343 acpi_status
acpi_clear_gpe(acpi_handle gpe_device
, u32 gpe_number
)
345 acpi_status status
= AE_OK
;
346 struct acpi_gpe_event_info
*gpe_event_info
;
347 acpi_cpu_flags flags
;
349 ACPI_FUNCTION_TRACE(acpi_clear_gpe
);
351 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
353 /* Ensure that we have a valid GPE number */
355 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
356 if (!gpe_event_info
) {
357 status
= AE_BAD_PARAMETER
;
358 goto unlock_and_exit
;
361 status
= acpi_hw_clear_gpe(gpe_event_info
);
364 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
365 return_ACPI_STATUS(status
);
368 ACPI_EXPORT_SYMBOL(acpi_clear_gpe
)
370 /*******************************************************************************
372 * FUNCTION: acpi_get_gpe_status
374 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
375 * gpe_number - GPE level within the GPE block
376 * event_status - Where the current status of the event will
381 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
383 ******************************************************************************/
385 acpi_get_gpe_status(acpi_handle gpe_device
,
386 u32 gpe_number
, acpi_event_status
*event_status
)
388 acpi_status status
= AE_OK
;
389 struct acpi_gpe_event_info
*gpe_event_info
;
390 acpi_cpu_flags flags
;
392 ACPI_FUNCTION_TRACE(acpi_get_gpe_status
);
394 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
396 /* Ensure that we have a valid GPE number */
398 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
399 if (!gpe_event_info
) {
400 status
= AE_BAD_PARAMETER
;
401 goto unlock_and_exit
;
404 /* Obtain status on the requested GPE number */
406 status
= acpi_hw_get_gpe_status(gpe_event_info
, event_status
);
408 if (gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
)
409 *event_status
|= ACPI_EVENT_FLAG_HANDLE
;
412 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
413 return_ACPI_STATUS(status
);
416 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status
)
418 /******************************************************************************
420 * FUNCTION: acpi_disable_all_gpes
426 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
428 ******************************************************************************/
430 acpi_status
acpi_disable_all_gpes(void)
434 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes
);
436 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
437 if (ACPI_FAILURE(status
)) {
438 return_ACPI_STATUS(status
);
441 status
= acpi_hw_disable_all_gpes();
442 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
444 return_ACPI_STATUS(status
);
447 ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes
)
449 /******************************************************************************
451 * FUNCTION: acpi_enable_all_runtime_gpes
457 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
459 ******************************************************************************/
461 acpi_status
acpi_enable_all_runtime_gpes(void)
465 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes
);
467 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
468 if (ACPI_FAILURE(status
)) {
469 return_ACPI_STATUS(status
);
472 status
= acpi_hw_enable_all_runtime_gpes();
473 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
475 return_ACPI_STATUS(status
);
478 ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes
)
480 /*******************************************************************************
482 * FUNCTION: acpi_install_gpe_block
484 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
485 * gpe_block_address - Address and space_iD
486 * register_count - Number of GPE register pairs in the block
487 * interrupt_number - H/W interrupt for the block
491 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
494 ******************************************************************************/
496 acpi_install_gpe_block(acpi_handle gpe_device
,
497 struct acpi_generic_address
*gpe_block_address
,
498 u32 register_count
, u32 interrupt_number
)
501 union acpi_operand_object
*obj_desc
;
502 struct acpi_namespace_node
*node
;
503 struct acpi_gpe_block_info
*gpe_block
;
505 ACPI_FUNCTION_TRACE(acpi_install_gpe_block
);
507 if ((!gpe_device
) || (!gpe_block_address
) || (!register_count
)) {
508 return_ACPI_STATUS(AE_BAD_PARAMETER
);
511 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
512 if (ACPI_FAILURE(status
)) {
516 node
= acpi_ns_validate_handle(gpe_device
);
518 status
= AE_BAD_PARAMETER
;
519 goto unlock_and_exit
;
523 * For user-installed GPE Block Devices, the gpe_block_base_number
527 acpi_ev_create_gpe_block(node
, gpe_block_address
, register_count
, 0,
528 interrupt_number
, &gpe_block
);
529 if (ACPI_FAILURE(status
)) {
530 goto unlock_and_exit
;
533 /* Install block in the device_object attached to the node */
535 obj_desc
= acpi_ns_get_attached_object(node
);
539 * No object, create a new one (Device nodes do not always have
540 * an attached object)
542 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_DEVICE
);
544 status
= AE_NO_MEMORY
;
545 goto unlock_and_exit
;
549 acpi_ns_attach_object(node
, obj_desc
, ACPI_TYPE_DEVICE
);
551 /* Remove local reference to the object */
553 acpi_ut_remove_reference(obj_desc
);
555 if (ACPI_FAILURE(status
)) {
556 goto unlock_and_exit
;
560 /* Now install the GPE block in the device_object */
562 obj_desc
->device
.gpe_block
= gpe_block
;
565 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
566 return_ACPI_STATUS(status
);
569 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block
)
571 /*******************************************************************************
573 * FUNCTION: acpi_remove_gpe_block
575 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
579 * DESCRIPTION: Remove a previously installed block of GPE registers
581 ******************************************************************************/
582 acpi_status
acpi_remove_gpe_block(acpi_handle gpe_device
)
584 union acpi_operand_object
*obj_desc
;
586 struct acpi_namespace_node
*node
;
588 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block
);
591 return_ACPI_STATUS(AE_BAD_PARAMETER
);
594 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
595 if (ACPI_FAILURE(status
)) {
599 node
= acpi_ns_validate_handle(gpe_device
);
601 status
= AE_BAD_PARAMETER
;
602 goto unlock_and_exit
;
605 /* Get the device_object attached to the node */
607 obj_desc
= acpi_ns_get_attached_object(node
);
608 if (!obj_desc
|| !obj_desc
->device
.gpe_block
) {
609 return_ACPI_STATUS(AE_NULL_OBJECT
);
612 /* Delete the GPE block (but not the device_object) */
614 status
= acpi_ev_delete_gpe_block(obj_desc
->device
.gpe_block
);
615 if (ACPI_SUCCESS(status
)) {
616 obj_desc
->device
.gpe_block
= NULL
;
620 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
621 return_ACPI_STATUS(status
);
624 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block
)
626 /*******************************************************************************
628 * FUNCTION: acpi_get_gpe_device
630 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
631 * gpe_device - Where the parent GPE Device is returned
635 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
636 * gpe device indicates that the gpe number is contained in one of
637 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
639 ******************************************************************************/
641 acpi_get_gpe_device(u32 index
, acpi_handle
*gpe_device
)
643 struct acpi_gpe_device_info info
;
646 ACPI_FUNCTION_TRACE(acpi_get_gpe_device
);
649 return_ACPI_STATUS(AE_BAD_PARAMETER
);
652 if (index
>= acpi_current_gpe_count
) {
653 return_ACPI_STATUS(AE_NOT_EXIST
);
656 /* Setup and walk the GPE list */
659 info
.status
= AE_NOT_EXIST
;
660 info
.gpe_device
= NULL
;
661 info
.next_block_base_index
= 0;
663 status
= acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device
, &info
);
664 if (ACPI_FAILURE(status
)) {
665 return_ACPI_STATUS(status
);
668 *gpe_device
= ACPI_CAST_PTR(acpi_handle
, info
.gpe_device
);
669 return_ACPI_STATUS(info
.status
);
672 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device
)