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 struct acpi_gpe_notify_object
*notify_object
;
202 acpi_cpu_flags flags
;
203 u8 gpe_dispatch_mask
;
205 ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake
);
207 /* Parameter Validation */
211 * By forcing wake_device to be valid, we automatically enable the
212 * implicit notify feature on all hosts.
214 return_ACPI_STATUS(AE_BAD_PARAMETER
);
217 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
219 /* Ensure that we have a valid GPE number */
221 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
222 if (!gpe_event_info
) {
223 goto unlock_and_exit
;
226 if (wake_device
== ACPI_ROOT_OBJECT
) {
231 * If there is no method or handler for this GPE, then the
232 * wake_device will be notified whenever this GPE fires (aka
233 * "implicit notify") Note: The GPE is assumed to be
234 * level-triggered (for windows compatibility).
236 gpe_dispatch_mask
= gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
;
237 if (gpe_dispatch_mask
!= ACPI_GPE_DISPATCH_NONE
238 && gpe_dispatch_mask
!= ACPI_GPE_DISPATCH_NOTIFY
) {
242 /* Validate wake_device is of type Device */
244 device_node
= ACPI_CAST_PTR(struct acpi_namespace_node
, wake_device
);
245 if (device_node
->type
!= ACPI_TYPE_DEVICE
) {
246 goto unlock_and_exit
;
249 if (gpe_dispatch_mask
== ACPI_GPE_DISPATCH_NONE
) {
250 gpe_event_info
->flags
= (ACPI_GPE_DISPATCH_NOTIFY
|
251 ACPI_GPE_LEVEL_TRIGGERED
);
252 gpe_event_info
->dispatch
.device
.node
= device_node
;
253 gpe_event_info
->dispatch
.device
.next
= NULL
;
255 /* There are multiple devices to notify implicitly. */
257 notify_object
= ACPI_ALLOCATE_ZEROED(sizeof(*notify_object
));
258 if (!notify_object
) {
259 status
= AE_NO_MEMORY
;
260 goto unlock_and_exit
;
263 notify_object
->node
= device_node
;
264 notify_object
->next
= gpe_event_info
->dispatch
.device
.next
;
265 gpe_event_info
->dispatch
.device
.next
= notify_object
;
269 gpe_event_info
->flags
|= ACPI_GPE_CAN_WAKE
;
273 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
274 return_ACPI_STATUS(status
);
276 ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake
)
278 /*******************************************************************************
280 * FUNCTION: acpi_set_gpe_wake_mask
282 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
283 * gpe_number - GPE level within the GPE block
284 * Action - Enable or Disable
288 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
289 * already be marked as a WAKE GPE.
291 ******************************************************************************/
293 acpi_status
acpi_set_gpe_wake_mask(acpi_handle gpe_device
, u32 gpe_number
, u8 action
)
295 acpi_status status
= AE_OK
;
296 struct acpi_gpe_event_info
*gpe_event_info
;
297 struct acpi_gpe_register_info
*gpe_register_info
;
298 acpi_cpu_flags flags
;
301 ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask
);
303 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
306 * Ensure that we have a valid GPE number and that this GPE is in
309 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
310 if (!gpe_event_info
) {
311 status
= AE_BAD_PARAMETER
;
312 goto unlock_and_exit
;
315 if (!(gpe_event_info
->flags
& ACPI_GPE_CAN_WAKE
)) {
317 goto unlock_and_exit
;
320 gpe_register_info
= gpe_event_info
->register_info
;
321 if (!gpe_register_info
) {
322 status
= AE_NOT_EXIST
;
323 goto unlock_and_exit
;
327 acpi_hw_get_gpe_register_bit(gpe_event_info
, gpe_register_info
);
329 /* Perform the action */
332 case ACPI_GPE_ENABLE
:
333 ACPI_SET_BIT(gpe_register_info
->enable_for_wake
,
337 case ACPI_GPE_DISABLE
:
338 ACPI_CLEAR_BIT(gpe_register_info
->enable_for_wake
,
343 ACPI_ERROR((AE_INFO
, "%u, Invalid action", action
));
344 status
= AE_BAD_PARAMETER
;
349 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
350 return_ACPI_STATUS(status
);
353 ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask
)
355 /*******************************************************************************
357 * FUNCTION: acpi_clear_gpe
359 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
360 * gpe_number - GPE level within the GPE block
364 * DESCRIPTION: Clear an ACPI event (general purpose)
366 ******************************************************************************/
367 acpi_status
acpi_clear_gpe(acpi_handle gpe_device
, u32 gpe_number
)
369 acpi_status status
= AE_OK
;
370 struct acpi_gpe_event_info
*gpe_event_info
;
371 acpi_cpu_flags flags
;
373 ACPI_FUNCTION_TRACE(acpi_clear_gpe
);
375 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
377 /* Ensure that we have a valid GPE number */
379 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
380 if (!gpe_event_info
) {
381 status
= AE_BAD_PARAMETER
;
382 goto unlock_and_exit
;
385 status
= acpi_hw_clear_gpe(gpe_event_info
);
388 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
389 return_ACPI_STATUS(status
);
392 ACPI_EXPORT_SYMBOL(acpi_clear_gpe
)
394 /*******************************************************************************
396 * FUNCTION: acpi_get_gpe_status
398 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
399 * gpe_number - GPE level within the GPE block
400 * event_status - Where the current status of the event will
405 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
407 ******************************************************************************/
409 acpi_get_gpe_status(acpi_handle gpe_device
,
410 u32 gpe_number
, acpi_event_status
*event_status
)
412 acpi_status status
= AE_OK
;
413 struct acpi_gpe_event_info
*gpe_event_info
;
414 acpi_cpu_flags flags
;
416 ACPI_FUNCTION_TRACE(acpi_get_gpe_status
);
418 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
420 /* Ensure that we have a valid GPE number */
422 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
423 if (!gpe_event_info
) {
424 status
= AE_BAD_PARAMETER
;
425 goto unlock_and_exit
;
428 /* Obtain status on the requested GPE number */
430 status
= acpi_hw_get_gpe_status(gpe_event_info
, event_status
);
432 if (gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
)
433 *event_status
|= ACPI_EVENT_FLAG_HANDLE
;
436 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
437 return_ACPI_STATUS(status
);
440 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status
)
442 /******************************************************************************
444 * FUNCTION: acpi_disable_all_gpes
450 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
452 ******************************************************************************/
454 acpi_status
acpi_disable_all_gpes(void)
458 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes
);
460 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
461 if (ACPI_FAILURE(status
)) {
462 return_ACPI_STATUS(status
);
465 status
= acpi_hw_disable_all_gpes();
466 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
468 return_ACPI_STATUS(status
);
471 ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes
)
473 /******************************************************************************
475 * FUNCTION: acpi_enable_all_runtime_gpes
481 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
483 ******************************************************************************/
485 acpi_status
acpi_enable_all_runtime_gpes(void)
489 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes
);
491 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
492 if (ACPI_FAILURE(status
)) {
493 return_ACPI_STATUS(status
);
496 status
= acpi_hw_enable_all_runtime_gpes();
497 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
499 return_ACPI_STATUS(status
);
502 ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes
)
504 /*******************************************************************************
506 * FUNCTION: acpi_install_gpe_block
508 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
509 * gpe_block_address - Address and space_iD
510 * register_count - Number of GPE register pairs in the block
511 * interrupt_number - H/W interrupt for the block
515 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
518 ******************************************************************************/
520 acpi_install_gpe_block(acpi_handle gpe_device
,
521 struct acpi_generic_address
*gpe_block_address
,
522 u32 register_count
, u32 interrupt_number
)
525 union acpi_operand_object
*obj_desc
;
526 struct acpi_namespace_node
*node
;
527 struct acpi_gpe_block_info
*gpe_block
;
529 ACPI_FUNCTION_TRACE(acpi_install_gpe_block
);
531 if ((!gpe_device
) || (!gpe_block_address
) || (!register_count
)) {
532 return_ACPI_STATUS(AE_BAD_PARAMETER
);
535 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
536 if (ACPI_FAILURE(status
)) {
540 node
= acpi_ns_validate_handle(gpe_device
);
542 status
= AE_BAD_PARAMETER
;
543 goto unlock_and_exit
;
547 * For user-installed GPE Block Devices, the gpe_block_base_number
551 acpi_ev_create_gpe_block(node
, gpe_block_address
, register_count
, 0,
552 interrupt_number
, &gpe_block
);
553 if (ACPI_FAILURE(status
)) {
554 goto unlock_and_exit
;
557 /* Install block in the device_object attached to the node */
559 obj_desc
= acpi_ns_get_attached_object(node
);
563 * No object, create a new one (Device nodes do not always have
564 * an attached object)
566 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_DEVICE
);
568 status
= AE_NO_MEMORY
;
569 goto unlock_and_exit
;
573 acpi_ns_attach_object(node
, obj_desc
, ACPI_TYPE_DEVICE
);
575 /* Remove local reference to the object */
577 acpi_ut_remove_reference(obj_desc
);
579 if (ACPI_FAILURE(status
)) {
580 goto unlock_and_exit
;
584 /* Now install the GPE block in the device_object */
586 obj_desc
->device
.gpe_block
= gpe_block
;
589 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
590 return_ACPI_STATUS(status
);
593 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block
)
595 /*******************************************************************************
597 * FUNCTION: acpi_remove_gpe_block
599 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
603 * DESCRIPTION: Remove a previously installed block of GPE registers
605 ******************************************************************************/
606 acpi_status
acpi_remove_gpe_block(acpi_handle gpe_device
)
608 union acpi_operand_object
*obj_desc
;
610 struct acpi_namespace_node
*node
;
612 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block
);
615 return_ACPI_STATUS(AE_BAD_PARAMETER
);
618 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
619 if (ACPI_FAILURE(status
)) {
623 node
= acpi_ns_validate_handle(gpe_device
);
625 status
= AE_BAD_PARAMETER
;
626 goto unlock_and_exit
;
629 /* Get the device_object attached to the node */
631 obj_desc
= acpi_ns_get_attached_object(node
);
632 if (!obj_desc
|| !obj_desc
->device
.gpe_block
) {
633 return_ACPI_STATUS(AE_NULL_OBJECT
);
636 /* Delete the GPE block (but not the device_object) */
638 status
= acpi_ev_delete_gpe_block(obj_desc
->device
.gpe_block
);
639 if (ACPI_SUCCESS(status
)) {
640 obj_desc
->device
.gpe_block
= NULL
;
644 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
645 return_ACPI_STATUS(status
);
648 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block
)
650 /*******************************************************************************
652 * FUNCTION: acpi_get_gpe_device
654 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
655 * gpe_device - Where the parent GPE Device is returned
659 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
660 * gpe device indicates that the gpe number is contained in one of
661 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
663 ******************************************************************************/
665 acpi_get_gpe_device(u32 index
, acpi_handle
*gpe_device
)
667 struct acpi_gpe_device_info info
;
670 ACPI_FUNCTION_TRACE(acpi_get_gpe_device
);
673 return_ACPI_STATUS(AE_BAD_PARAMETER
);
676 if (index
>= acpi_current_gpe_count
) {
677 return_ACPI_STATUS(AE_NOT_EXIST
);
680 /* Setup and walk the GPE list */
683 info
.status
= AE_NOT_EXIST
;
684 info
.gpe_device
= NULL
;
685 info
.next_block_base_index
= 0;
687 status
= acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device
, &info
);
688 if (ACPI_FAILURE(status
)) {
689 return_ACPI_STATUS(status
);
692 *gpe_device
= ACPI_CAST_PTR(acpi_handle
, info
.gpe_device
);
693 return_ACPI_STATUS(info
.status
);
696 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device
)