1 /******************************************************************************
3 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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 ******************************************************************************/
118 acpi_status
acpi_enable_gpe(acpi_handle gpe_device
, u32 gpe_number
)
120 acpi_status status
= AE_BAD_PARAMETER
;
121 struct acpi_gpe_event_info
*gpe_event_info
;
122 acpi_cpu_flags flags
;
124 ACPI_FUNCTION_TRACE(acpi_enable_gpe
);
126 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
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.
133 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
134 if (gpe_event_info
) {
135 if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info
->flags
) !=
136 ACPI_GPE_DISPATCH_NONE
) {
137 status
= acpi_ev_add_gpe_reference(gpe_event_info
);
139 status
= AE_NO_HANDLER
;
143 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
144 return_ACPI_STATUS(status
);
146 ACPI_EXPORT_SYMBOL(acpi_enable_gpe
)
148 /*******************************************************************************
150 * FUNCTION: acpi_disable_gpe
152 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
153 * gpe_number - GPE level within the GPE block
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)
161 ******************************************************************************/
163 acpi_status
acpi_disable_gpe(acpi_handle gpe_device
, u32 gpe_number
)
165 acpi_status status
= AE_BAD_PARAMETER
;
166 struct acpi_gpe_event_info
*gpe_event_info
;
167 acpi_cpu_flags flags
;
169 ACPI_FUNCTION_TRACE(acpi_disable_gpe
);
171 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
173 /* Ensure that we have a valid GPE number */
175 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
176 if (gpe_event_info
) {
177 status
= acpi_ev_remove_gpe_reference(gpe_event_info
) ;
180 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
181 return_ACPI_STATUS(status
);
184 ACPI_EXPORT_SYMBOL(acpi_disable_gpe
)
186 /*******************************************************************************
188 * FUNCTION: acpi_set_gpe
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
196 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
197 * the reference count mechanism used in the acpi_enable_gpe(),
198 * acpi_disable_gpe() interfaces.
199 * This API is typically used by the GPE raw handler mode driver
200 * to switch between the polling mode and the interrupt mode after
201 * the driver has enabled the GPE.
202 * The APIs should be invoked in this order:
203 * acpi_enable_gpe() <- Ensure the reference count > 0
204 * acpi_set_gpe(ACPI_GPE_DISABLE) <- Enter polling mode
205 * acpi_set_gpe(ACPI_GPE_ENABLE) <- Leave polling mode
206 * acpi_disable_gpe() <- Decrease the reference count
208 * Note: If a GPE is shared by 2 silicon components, then both the drivers
209 * should support GPE polling mode or disabling the GPE for long period
210 * for one driver may break the other. So use it with care since all
211 * firmware _Lxx/_Exx handlers currently rely on the GPE interrupt mode.
213 ******************************************************************************/
214 acpi_status
acpi_set_gpe(acpi_handle gpe_device
, u32 gpe_number
, u8 action
)
216 struct acpi_gpe_event_info
*gpe_event_info
;
218 acpi_cpu_flags flags
;
220 ACPI_FUNCTION_TRACE(acpi_set_gpe
);
222 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
224 /* Ensure that we have a valid GPE number */
226 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
227 if (!gpe_event_info
) {
228 status
= AE_BAD_PARAMETER
;
229 goto unlock_and_exit
;
232 /* Perform the action */
235 case ACPI_GPE_ENABLE
:
237 status
= acpi_hw_low_set_gpe(gpe_event_info
, ACPI_GPE_ENABLE
);
238 gpe_event_info
->disable_for_dispatch
= FALSE
;
241 case ACPI_GPE_DISABLE
:
243 status
= acpi_hw_low_set_gpe(gpe_event_info
, ACPI_GPE_DISABLE
);
244 gpe_event_info
->disable_for_dispatch
= TRUE
;
249 status
= AE_BAD_PARAMETER
;
254 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
255 return_ACPI_STATUS(status
);
258 ACPI_EXPORT_SYMBOL(acpi_set_gpe
)
260 /*******************************************************************************
262 * FUNCTION: acpi_mask_gpe
264 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
265 * gpe_number - GPE level within the GPE block
266 * is_masked - Whether the GPE is masked or not
270 * DESCRIPTION: Unconditionally mask/unmask the an individual GPE, ex., to
271 * prevent a GPE flooding.
273 ******************************************************************************/
274 acpi_status
acpi_mask_gpe(acpi_handle gpe_device
, u32 gpe_number
, u8 is_masked
)
276 struct acpi_gpe_event_info
*gpe_event_info
;
278 acpi_cpu_flags flags
;
280 ACPI_FUNCTION_TRACE(acpi_mask_gpe
);
282 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
284 /* Ensure that we have a valid GPE number */
286 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
287 if (!gpe_event_info
) {
288 status
= AE_BAD_PARAMETER
;
289 goto unlock_and_exit
;
292 status
= acpi_ev_mask_gpe(gpe_event_info
, is_masked
);
295 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
296 return_ACPI_STATUS(status
);
299 ACPI_EXPORT_SYMBOL(acpi_mask_gpe
)
301 /*******************************************************************************
303 * FUNCTION: acpi_mark_gpe_for_wake
305 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
306 * gpe_number - GPE level within the GPE block
310 * DESCRIPTION: Mark a GPE as having the ability to wake the system. Simply
311 * sets the ACPI_GPE_CAN_WAKE flag.
313 * Some potential callers of acpi_setup_gpe_for_wake may know in advance that
314 * there won't be any notify handlers installed for device wake notifications
315 * from the given GPE (one example is a button GPE in Linux). For these cases,
316 * acpi_mark_gpe_for_wake should be used instead of acpi_setup_gpe_for_wake.
317 * This will set the ACPI_GPE_CAN_WAKE flag for the GPE without trying to
318 * setup implicit wake notification for it (since there's no handler method).
320 ******************************************************************************/
321 acpi_status
acpi_mark_gpe_for_wake(acpi_handle gpe_device
, u32 gpe_number
)
323 struct acpi_gpe_event_info
*gpe_event_info
;
324 acpi_status status
= AE_BAD_PARAMETER
;
325 acpi_cpu_flags flags
;
327 ACPI_FUNCTION_TRACE(acpi_mark_gpe_for_wake
);
329 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
331 /* Ensure that we have a valid GPE number */
333 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
334 if (gpe_event_info
) {
336 /* Mark the GPE as a possible wake event */
338 gpe_event_info
->flags
|= ACPI_GPE_CAN_WAKE
;
342 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
343 return_ACPI_STATUS(status
);
346 ACPI_EXPORT_SYMBOL(acpi_mark_gpe_for_wake
)
348 /*******************************************************************************
350 * FUNCTION: acpi_setup_gpe_for_wake
352 * PARAMETERS: wake_device - Device associated with the GPE (via _PRW)
353 * gpe_device - Parent GPE Device. NULL for GPE0/GPE1
354 * gpe_number - GPE level within the GPE block
358 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
359 * interface is intended to be used as the host executes the
360 * _PRW methods (Power Resources for Wake) in the system tables.
361 * Each _PRW appears under a Device Object (The wake_device), and
362 * contains the info for the wake GPE associated with the
365 ******************************************************************************/
367 acpi_setup_gpe_for_wake(acpi_handle wake_device
,
368 acpi_handle gpe_device
, u32 gpe_number
)
371 struct acpi_gpe_event_info
*gpe_event_info
;
372 struct acpi_namespace_node
*device_node
;
373 struct acpi_gpe_notify_info
*notify
;
374 struct acpi_gpe_notify_info
*new_notify
;
375 acpi_cpu_flags flags
;
377 ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake
);
379 /* Parameter Validation */
383 * By forcing wake_device to be valid, we automatically enable the
384 * implicit notify feature on all hosts.
386 return_ACPI_STATUS(AE_BAD_PARAMETER
);
389 /* Handle root object case */
391 if (wake_device
== ACPI_ROOT_OBJECT
) {
392 device_node
= acpi_gbl_root_node
;
395 ACPI_CAST_PTR(struct acpi_namespace_node
, wake_device
);
398 /* Validate wake_device is of type Device */
400 if (device_node
->type
!= ACPI_TYPE_DEVICE
) {
401 return_ACPI_STATUS (AE_BAD_PARAMETER
);
405 * Allocate a new notify object up front, in case it is needed.
406 * Memory allocation while holding a spinlock is a big no-no
409 new_notify
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_notify_info
));
411 return_ACPI_STATUS(AE_NO_MEMORY
);
414 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
416 /* Ensure that we have a valid GPE number */
418 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
419 if (!gpe_event_info
) {
420 status
= AE_BAD_PARAMETER
;
421 goto unlock_and_exit
;
425 * If there is no method or handler for this GPE, then the
426 * wake_device will be notified whenever this GPE fires. This is
427 * known as an "implicit notify". Note: The GPE is assumed to be
428 * level-triggered (for windows compatibility).
430 if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info
->flags
) ==
431 ACPI_GPE_DISPATCH_NONE
) {
433 * This is the first device for implicit notify on this GPE.
434 * Just set the flags here, and enter the NOTIFY block below.
436 gpe_event_info
->flags
=
437 (ACPI_GPE_DISPATCH_NOTIFY
| ACPI_GPE_LEVEL_TRIGGERED
);
441 * If we already have an implicit notify on this GPE, add
442 * this device to the notify list.
444 if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info
->flags
) ==
445 ACPI_GPE_DISPATCH_NOTIFY
) {
447 /* Ensure that the device is not already in the list */
449 notify
= gpe_event_info
->dispatch
.notify_list
;
451 if (notify
->device_node
== device_node
) {
452 status
= AE_ALREADY_EXISTS
;
453 goto unlock_and_exit
;
455 notify
= notify
->next
;
458 /* Add this device to the notify list for this GPE */
460 new_notify
->device_node
= device_node
;
461 new_notify
->next
= gpe_event_info
->dispatch
.notify_list
;
462 gpe_event_info
->dispatch
.notify_list
= new_notify
;
466 /* Mark the GPE as a possible wake event */
468 gpe_event_info
->flags
|= ACPI_GPE_CAN_WAKE
;
472 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
474 /* Delete the notify object if it was not used above */
477 ACPI_FREE(new_notify
);
479 return_ACPI_STATUS(status
);
481 ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake
)
483 /*******************************************************************************
485 * FUNCTION: acpi_set_gpe_wake_mask
487 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
488 * gpe_number - GPE level within the GPE block
489 * action - Enable or Disable
493 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
494 * already be marked as a WAKE GPE.
496 ******************************************************************************/
499 acpi_set_gpe_wake_mask(acpi_handle gpe_device
, u32 gpe_number
, u8 action
)
501 acpi_status status
= AE_OK
;
502 struct acpi_gpe_event_info
*gpe_event_info
;
503 struct acpi_gpe_register_info
*gpe_register_info
;
504 acpi_cpu_flags flags
;
507 ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask
);
509 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
512 * Ensure that we have a valid GPE number and that this GPE is in
515 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
516 if (!gpe_event_info
) {
517 status
= AE_BAD_PARAMETER
;
518 goto unlock_and_exit
;
521 if (!(gpe_event_info
->flags
& ACPI_GPE_CAN_WAKE
)) {
523 goto unlock_and_exit
;
526 gpe_register_info
= gpe_event_info
->register_info
;
527 if (!gpe_register_info
) {
528 status
= AE_NOT_EXIST
;
529 goto unlock_and_exit
;
532 register_bit
= acpi_hw_get_gpe_register_bit(gpe_event_info
);
534 /* Perform the action */
537 case ACPI_GPE_ENABLE
:
539 ACPI_SET_BIT(gpe_register_info
->enable_for_wake
,
543 case ACPI_GPE_DISABLE
:
545 ACPI_CLEAR_BIT(gpe_register_info
->enable_for_wake
,
551 ACPI_ERROR((AE_INFO
, "%u, Invalid action", action
));
552 status
= AE_BAD_PARAMETER
;
557 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
558 return_ACPI_STATUS(status
);
561 ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask
)
563 /*******************************************************************************
565 * FUNCTION: acpi_clear_gpe
567 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
568 * gpe_number - GPE level within the GPE block
572 * DESCRIPTION: Clear an ACPI event (general purpose)
574 ******************************************************************************/
575 acpi_status
acpi_clear_gpe(acpi_handle gpe_device
, u32 gpe_number
)
577 acpi_status status
= AE_OK
;
578 struct acpi_gpe_event_info
*gpe_event_info
;
579 acpi_cpu_flags flags
;
581 ACPI_FUNCTION_TRACE(acpi_clear_gpe
);
583 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
585 /* Ensure that we have a valid GPE number */
587 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
588 if (!gpe_event_info
) {
589 status
= AE_BAD_PARAMETER
;
590 goto unlock_and_exit
;
593 status
= acpi_hw_clear_gpe(gpe_event_info
);
596 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
597 return_ACPI_STATUS(status
);
600 ACPI_EXPORT_SYMBOL(acpi_clear_gpe
)
602 /*******************************************************************************
604 * FUNCTION: acpi_get_gpe_status
606 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
607 * gpe_number - GPE level within the GPE block
608 * event_status - Where the current status of the event
613 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
615 ******************************************************************************/
617 acpi_get_gpe_status(acpi_handle gpe_device
,
618 u32 gpe_number
, acpi_event_status
*event_status
)
620 acpi_status status
= AE_OK
;
621 struct acpi_gpe_event_info
*gpe_event_info
;
622 acpi_cpu_flags flags
;
624 ACPI_FUNCTION_TRACE(acpi_get_gpe_status
);
626 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
628 /* Ensure that we have a valid GPE number */
630 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
631 if (!gpe_event_info
) {
632 status
= AE_BAD_PARAMETER
;
633 goto unlock_and_exit
;
636 /* Obtain status on the requested GPE number */
638 status
= acpi_hw_get_gpe_status(gpe_event_info
, event_status
);
641 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
642 return_ACPI_STATUS(status
);
645 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status
)
647 /*******************************************************************************
649 * FUNCTION: acpi_finish_gpe
651 * PARAMETERS: gpe_device - Namespace node for the GPE Block
652 * (NULL for FADT defined GPEs)
653 * gpe_number - GPE level within the GPE block
657 * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
658 * processing. Intended for use by asynchronous host-installed
659 * GPE handlers. The GPE is only reenabled if the enable_for_run bit
660 * is set in the GPE info.
662 ******************************************************************************/
663 acpi_status
acpi_finish_gpe(acpi_handle gpe_device
, u32 gpe_number
)
665 struct acpi_gpe_event_info
*gpe_event_info
;
667 acpi_cpu_flags flags
;
669 ACPI_FUNCTION_TRACE(acpi_finish_gpe
);
671 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
673 /* Ensure that we have a valid GPE number */
675 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
676 if (!gpe_event_info
) {
677 status
= AE_BAD_PARAMETER
;
678 goto unlock_and_exit
;
681 status
= acpi_ev_finish_gpe(gpe_event_info
);
684 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
685 return_ACPI_STATUS(status
);
688 ACPI_EXPORT_SYMBOL(acpi_finish_gpe
)
690 /******************************************************************************
692 * FUNCTION: acpi_disable_all_gpes
698 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
700 ******************************************************************************/
702 acpi_status
acpi_disable_all_gpes(void)
706 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes
);
708 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
709 if (ACPI_FAILURE(status
)) {
710 return_ACPI_STATUS(status
);
713 status
= acpi_hw_disable_all_gpes();
714 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
716 return_ACPI_STATUS(status
);
719 ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes
)
721 /******************************************************************************
723 * FUNCTION: acpi_enable_all_runtime_gpes
729 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
731 ******************************************************************************/
733 acpi_status
acpi_enable_all_runtime_gpes(void)
737 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes
);
739 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
740 if (ACPI_FAILURE(status
)) {
741 return_ACPI_STATUS(status
);
744 status
= acpi_hw_enable_all_runtime_gpes();
745 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
747 return_ACPI_STATUS(status
);
750 ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes
)
752 /******************************************************************************
754 * FUNCTION: acpi_enable_all_wakeup_gpes
760 * DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in
763 ******************************************************************************/
764 acpi_status
acpi_enable_all_wakeup_gpes(void)
768 ACPI_FUNCTION_TRACE(acpi_enable_all_wakeup_gpes
);
770 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
771 if (ACPI_FAILURE(status
)) {
772 return_ACPI_STATUS(status
);
775 status
= acpi_hw_enable_all_wakeup_gpes();
776 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
778 return_ACPI_STATUS(status
);
781 ACPI_EXPORT_SYMBOL(acpi_enable_all_wakeup_gpes
)
783 /*******************************************************************************
785 * FUNCTION: acpi_install_gpe_block
787 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
788 * gpe_block_address - Address and space_ID
789 * register_count - Number of GPE register pairs in the block
790 * interrupt_number - H/W interrupt for the block
794 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
797 ******************************************************************************/
799 acpi_install_gpe_block(acpi_handle gpe_device
,
800 struct acpi_generic_address
*gpe_block_address
,
801 u32 register_count
, u32 interrupt_number
)
804 union acpi_operand_object
*obj_desc
;
805 struct acpi_namespace_node
*node
;
806 struct acpi_gpe_block_info
*gpe_block
;
808 ACPI_FUNCTION_TRACE(acpi_install_gpe_block
);
810 if ((!gpe_device
) || (!gpe_block_address
) || (!register_count
)) {
811 return_ACPI_STATUS(AE_BAD_PARAMETER
);
814 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
815 if (ACPI_FAILURE(status
)) {
816 return_ACPI_STATUS(status
);
819 node
= acpi_ns_validate_handle(gpe_device
);
821 status
= AE_BAD_PARAMETER
;
822 goto unlock_and_exit
;
825 /* Validate the parent device */
827 if (node
->type
!= ACPI_TYPE_DEVICE
) {
829 goto unlock_and_exit
;
833 status
= AE_ALREADY_EXISTS
;
834 goto unlock_and_exit
;
838 * For user-installed GPE Block Devices, the gpe_block_base_number
841 status
= acpi_ev_create_gpe_block(node
, gpe_block_address
->address
,
842 gpe_block_address
->space_id
,
843 register_count
, 0, interrupt_number
,
845 if (ACPI_FAILURE(status
)) {
846 goto unlock_and_exit
;
849 /* Install block in the device_object attached to the node */
851 obj_desc
= acpi_ns_get_attached_object(node
);
855 * No object, create a new one (Device nodes do not always have
856 * an attached object)
858 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_DEVICE
);
860 status
= AE_NO_MEMORY
;
861 goto unlock_and_exit
;
865 acpi_ns_attach_object(node
, obj_desc
, ACPI_TYPE_DEVICE
);
867 /* Remove local reference to the object */
869 acpi_ut_remove_reference(obj_desc
);
871 if (ACPI_FAILURE(status
)) {
872 goto unlock_and_exit
;
876 /* Now install the GPE block in the device_object */
878 obj_desc
->device
.gpe_block
= gpe_block
;
881 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
882 return_ACPI_STATUS(status
);
885 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block
)
887 /*******************************************************************************
889 * FUNCTION: acpi_remove_gpe_block
891 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
895 * DESCRIPTION: Remove a previously installed block of GPE registers
897 ******************************************************************************/
898 acpi_status
acpi_remove_gpe_block(acpi_handle gpe_device
)
900 union acpi_operand_object
*obj_desc
;
902 struct acpi_namespace_node
*node
;
904 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block
);
907 return_ACPI_STATUS(AE_BAD_PARAMETER
);
910 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
911 if (ACPI_FAILURE(status
)) {
912 return_ACPI_STATUS(status
);
915 node
= acpi_ns_validate_handle(gpe_device
);
917 status
= AE_BAD_PARAMETER
;
918 goto unlock_and_exit
;
921 /* Validate the parent device */
923 if (node
->type
!= ACPI_TYPE_DEVICE
) {
925 goto unlock_and_exit
;
928 /* Get the device_object attached to the node */
930 obj_desc
= acpi_ns_get_attached_object(node
);
931 if (!obj_desc
|| !obj_desc
->device
.gpe_block
) {
932 return_ACPI_STATUS(AE_NULL_OBJECT
);
935 /* Delete the GPE block (but not the device_object) */
937 status
= acpi_ev_delete_gpe_block(obj_desc
->device
.gpe_block
);
938 if (ACPI_SUCCESS(status
)) {
939 obj_desc
->device
.gpe_block
= NULL
;
943 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
944 return_ACPI_STATUS(status
);
947 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block
)
949 /*******************************************************************************
951 * FUNCTION: acpi_get_gpe_device
953 * PARAMETERS: index - System GPE index (0-current_gpe_count)
954 * gpe_device - Where the parent GPE Device is returned
958 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
959 * gpe device indicates that the gpe number is contained in one of
960 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
962 ******************************************************************************/
963 acpi_status
acpi_get_gpe_device(u32 index
, acpi_handle
*gpe_device
)
965 struct acpi_gpe_device_info info
;
968 ACPI_FUNCTION_TRACE(acpi_get_gpe_device
);
971 return_ACPI_STATUS(AE_BAD_PARAMETER
);
974 if (index
>= acpi_current_gpe_count
) {
975 return_ACPI_STATUS(AE_NOT_EXIST
);
978 /* Setup and walk the GPE list */
981 info
.status
= AE_NOT_EXIST
;
982 info
.gpe_device
= NULL
;
983 info
.next_block_base_index
= 0;
985 status
= acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device
, &info
);
986 if (ACPI_FAILURE(status
)) {
987 return_ACPI_STATUS(status
);
990 *gpe_device
= ACPI_CAST_PTR(acpi_handle
, info
.gpe_device
);
991 return_ACPI_STATUS(info
.status
);
994 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device
)
995 #endif /* !ACPI_REDUCED_HARDWARE */