1 /******************************************************************************
3 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, 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 <linux/export.h>
45 #include <acpi/acpi.h>
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME("evxfgpe")
53 /******************************************************************************
55 * FUNCTION: acpi_update_all_gpes
61 * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
62 * associated _Lxx or _Exx methods and are not pointed to by any
63 * device _PRW methods (this indicates that these GPEs are
64 * generally intended for system or device wakeup. Such GPEs
65 * have to be enabled directly when the devices whose _PRW
66 * methods point to them are set up for wakeup signaling.)
68 * NOTE: Should be called after any GPEs are added to the system. Primarily,
69 * after the system _PRW methods have been run, but also after a GPE Block
70 * Device has been added or if any new GPE methods have been added via a
73 ******************************************************************************/
75 acpi_status
acpi_update_all_gpes(void)
79 ACPI_FUNCTION_TRACE(acpi_update_all_gpes
);
81 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
82 if (ACPI_FAILURE(status
)) {
83 return_ACPI_STATUS(status
);
86 if (acpi_gbl_all_gpes_initialized
) {
90 status
= acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block
, NULL
);
91 if (ACPI_SUCCESS(status
)) {
92 acpi_gbl_all_gpes_initialized
= TRUE
;
96 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
98 return_ACPI_STATUS(status
);
101 ACPI_EXPORT_SYMBOL(acpi_update_all_gpes
)
103 /*******************************************************************************
105 * FUNCTION: acpi_enable_gpe
107 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
108 * gpe_number - GPE level within the GPE block
112 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
115 ******************************************************************************/
117 acpi_status
acpi_enable_gpe(acpi_handle gpe_device
, u32 gpe_number
)
119 acpi_status status
= AE_BAD_PARAMETER
;
120 struct acpi_gpe_event_info
*gpe_event_info
;
121 acpi_cpu_flags flags
;
123 ACPI_FUNCTION_TRACE(acpi_enable_gpe
);
125 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
127 /* Ensure that we have a valid GPE number */
129 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
130 if (gpe_event_info
) {
131 status
= acpi_ev_add_gpe_reference(gpe_event_info
);
134 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
135 return_ACPI_STATUS(status
);
137 ACPI_EXPORT_SYMBOL(acpi_enable_gpe
)
139 /*******************************************************************************
141 * FUNCTION: acpi_disable_gpe
143 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
144 * gpe_number - GPE level within the GPE block
148 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
149 * removed, only then is the GPE disabled (for runtime GPEs), or
150 * the GPE mask bit disabled (for wake GPEs)
152 ******************************************************************************/
154 acpi_status
acpi_disable_gpe(acpi_handle gpe_device
, u32 gpe_number
)
156 acpi_status status
= AE_BAD_PARAMETER
;
157 struct acpi_gpe_event_info
*gpe_event_info
;
158 acpi_cpu_flags flags
;
160 ACPI_FUNCTION_TRACE(acpi_disable_gpe
);
162 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
164 /* Ensure that we have a valid GPE number */
166 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
167 if (gpe_event_info
) {
168 status
= acpi_ev_remove_gpe_reference(gpe_event_info
) ;
171 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
172 return_ACPI_STATUS(status
);
174 ACPI_EXPORT_SYMBOL(acpi_disable_gpe
)
177 /*******************************************************************************
179 * FUNCTION: acpi_setup_gpe_for_wake
181 * PARAMETERS: wake_device - Device associated with the GPE (via _PRW)
182 * gpe_device - Parent GPE Device. NULL for GPE0/GPE1
183 * gpe_number - GPE level within the GPE block
187 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
188 * interface is intended to be used as the host executes the
189 * _PRW methods (Power Resources for Wake) in the system tables.
190 * Each _PRW appears under a Device Object (The wake_device), and
191 * contains the info for the wake GPE associated with the
194 ******************************************************************************/
196 acpi_setup_gpe_for_wake(acpi_handle wake_device
,
197 acpi_handle gpe_device
, u32 gpe_number
)
199 acpi_status status
= AE_BAD_PARAMETER
;
200 struct acpi_gpe_event_info
*gpe_event_info
;
201 struct acpi_namespace_node
*device_node
;
202 struct acpi_gpe_notify_object
*notify_object
;
203 acpi_cpu_flags flags
;
204 u8 gpe_dispatch_mask
;
206 ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake
);
208 /* Parameter Validation */
212 * By forcing wake_device to be valid, we automatically enable the
213 * implicit notify feature on all hosts.
215 return_ACPI_STATUS(AE_BAD_PARAMETER
);
218 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
220 /* Ensure that we have a valid GPE number */
222 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
223 if (!gpe_event_info
) {
224 goto unlock_and_exit
;
227 if (wake_device
== ACPI_ROOT_OBJECT
) {
232 * If there is no method or handler for this GPE, then the
233 * wake_device will be notified whenever this GPE fires (aka
234 * "implicit notify") Note: The GPE is assumed to be
235 * level-triggered (for windows compatibility).
237 gpe_dispatch_mask
= gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
;
238 if (gpe_dispatch_mask
!= ACPI_GPE_DISPATCH_NONE
239 && gpe_dispatch_mask
!= ACPI_GPE_DISPATCH_NOTIFY
) {
243 /* Validate wake_device is of type Device */
245 device_node
= ACPI_CAST_PTR(struct acpi_namespace_node
, wake_device
);
246 if (device_node
->type
!= ACPI_TYPE_DEVICE
) {
247 goto unlock_and_exit
;
250 if (gpe_dispatch_mask
== ACPI_GPE_DISPATCH_NONE
) {
251 gpe_event_info
->flags
= (ACPI_GPE_DISPATCH_NOTIFY
|
252 ACPI_GPE_LEVEL_TRIGGERED
);
253 gpe_event_info
->dispatch
.device
.node
= device_node
;
254 gpe_event_info
->dispatch
.device
.next
= NULL
;
256 /* There are multiple devices to notify implicitly. */
258 notify_object
= ACPI_ALLOCATE_ZEROED(sizeof(*notify_object
));
259 if (!notify_object
) {
260 status
= AE_NO_MEMORY
;
261 goto unlock_and_exit
;
264 notify_object
->node
= device_node
;
265 notify_object
->next
= gpe_event_info
->dispatch
.device
.next
;
266 gpe_event_info
->dispatch
.device
.next
= notify_object
;
270 gpe_event_info
->flags
|= ACPI_GPE_CAN_WAKE
;
274 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
275 return_ACPI_STATUS(status
);
277 ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake
)
279 /*******************************************************************************
281 * FUNCTION: acpi_set_gpe_wake_mask
283 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
284 * gpe_number - GPE level within the GPE block
285 * Action - Enable or Disable
289 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
290 * already be marked as a WAKE GPE.
292 ******************************************************************************/
294 acpi_status
acpi_set_gpe_wake_mask(acpi_handle gpe_device
, u32 gpe_number
, u8 action
)
296 acpi_status status
= AE_OK
;
297 struct acpi_gpe_event_info
*gpe_event_info
;
298 struct acpi_gpe_register_info
*gpe_register_info
;
299 acpi_cpu_flags flags
;
302 ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask
);
304 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
307 * Ensure that we have a valid GPE number and that this GPE is in
310 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
311 if (!gpe_event_info
) {
312 status
= AE_BAD_PARAMETER
;
313 goto unlock_and_exit
;
316 if (!(gpe_event_info
->flags
& ACPI_GPE_CAN_WAKE
)) {
318 goto unlock_and_exit
;
321 gpe_register_info
= gpe_event_info
->register_info
;
322 if (!gpe_register_info
) {
323 status
= AE_NOT_EXIST
;
324 goto unlock_and_exit
;
328 acpi_hw_get_gpe_register_bit(gpe_event_info
, gpe_register_info
);
330 /* Perform the action */
333 case ACPI_GPE_ENABLE
:
334 ACPI_SET_BIT(gpe_register_info
->enable_for_wake
,
338 case ACPI_GPE_DISABLE
:
339 ACPI_CLEAR_BIT(gpe_register_info
->enable_for_wake
,
344 ACPI_ERROR((AE_INFO
, "%u, Invalid action", action
));
345 status
= AE_BAD_PARAMETER
;
350 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
351 return_ACPI_STATUS(status
);
354 ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask
)
356 /*******************************************************************************
358 * FUNCTION: acpi_clear_gpe
360 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
361 * gpe_number - GPE level within the GPE block
365 * DESCRIPTION: Clear an ACPI event (general purpose)
367 ******************************************************************************/
368 acpi_status
acpi_clear_gpe(acpi_handle gpe_device
, u32 gpe_number
)
370 acpi_status status
= AE_OK
;
371 struct acpi_gpe_event_info
*gpe_event_info
;
372 acpi_cpu_flags flags
;
374 ACPI_FUNCTION_TRACE(acpi_clear_gpe
);
376 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
378 /* Ensure that we have a valid GPE number */
380 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
381 if (!gpe_event_info
) {
382 status
= AE_BAD_PARAMETER
;
383 goto unlock_and_exit
;
386 status
= acpi_hw_clear_gpe(gpe_event_info
);
389 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
390 return_ACPI_STATUS(status
);
393 ACPI_EXPORT_SYMBOL(acpi_clear_gpe
)
395 /*******************************************************************************
397 * FUNCTION: acpi_get_gpe_status
399 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
400 * gpe_number - GPE level within the GPE block
401 * event_status - Where the current status of the event will
406 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
408 ******************************************************************************/
410 acpi_get_gpe_status(acpi_handle gpe_device
,
411 u32 gpe_number
, acpi_event_status
*event_status
)
413 acpi_status status
= AE_OK
;
414 struct acpi_gpe_event_info
*gpe_event_info
;
415 acpi_cpu_flags flags
;
417 ACPI_FUNCTION_TRACE(acpi_get_gpe_status
);
419 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
421 /* Ensure that we have a valid GPE number */
423 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
424 if (!gpe_event_info
) {
425 status
= AE_BAD_PARAMETER
;
426 goto unlock_and_exit
;
429 /* Obtain status on the requested GPE number */
431 status
= acpi_hw_get_gpe_status(gpe_event_info
, event_status
);
433 if (gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
)
434 *event_status
|= ACPI_EVENT_FLAG_HANDLE
;
437 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
438 return_ACPI_STATUS(status
);
441 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status
)
443 /******************************************************************************
445 * FUNCTION: acpi_disable_all_gpes
451 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
453 ******************************************************************************/
455 acpi_status
acpi_disable_all_gpes(void)
459 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes
);
461 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
462 if (ACPI_FAILURE(status
)) {
463 return_ACPI_STATUS(status
);
466 status
= acpi_hw_disable_all_gpes();
467 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
469 return_ACPI_STATUS(status
);
472 ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes
)
474 /******************************************************************************
476 * FUNCTION: acpi_enable_all_runtime_gpes
482 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
484 ******************************************************************************/
486 acpi_status
acpi_enable_all_runtime_gpes(void)
490 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes
);
492 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
493 if (ACPI_FAILURE(status
)) {
494 return_ACPI_STATUS(status
);
497 status
= acpi_hw_enable_all_runtime_gpes();
498 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
500 return_ACPI_STATUS(status
);
503 ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes
)
505 /*******************************************************************************
507 * FUNCTION: acpi_install_gpe_block
509 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
510 * gpe_block_address - Address and space_iD
511 * register_count - Number of GPE register pairs in the block
512 * interrupt_number - H/W interrupt for the block
516 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
519 ******************************************************************************/
521 acpi_install_gpe_block(acpi_handle gpe_device
,
522 struct acpi_generic_address
*gpe_block_address
,
523 u32 register_count
, u32 interrupt_number
)
526 union acpi_operand_object
*obj_desc
;
527 struct acpi_namespace_node
*node
;
528 struct acpi_gpe_block_info
*gpe_block
;
530 ACPI_FUNCTION_TRACE(acpi_install_gpe_block
);
532 if ((!gpe_device
) || (!gpe_block_address
) || (!register_count
)) {
533 return_ACPI_STATUS(AE_BAD_PARAMETER
);
536 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
537 if (ACPI_FAILURE(status
)) {
541 node
= acpi_ns_validate_handle(gpe_device
);
543 status
= AE_BAD_PARAMETER
;
544 goto unlock_and_exit
;
548 * For user-installed GPE Block Devices, the gpe_block_base_number
552 acpi_ev_create_gpe_block(node
, gpe_block_address
, register_count
, 0,
553 interrupt_number
, &gpe_block
);
554 if (ACPI_FAILURE(status
)) {
555 goto unlock_and_exit
;
558 /* Install block in the device_object attached to the node */
560 obj_desc
= acpi_ns_get_attached_object(node
);
564 * No object, create a new one (Device nodes do not always have
565 * an attached object)
567 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_DEVICE
);
569 status
= AE_NO_MEMORY
;
570 goto unlock_and_exit
;
574 acpi_ns_attach_object(node
, obj_desc
, ACPI_TYPE_DEVICE
);
576 /* Remove local reference to the object */
578 acpi_ut_remove_reference(obj_desc
);
580 if (ACPI_FAILURE(status
)) {
581 goto unlock_and_exit
;
585 /* Now install the GPE block in the device_object */
587 obj_desc
->device
.gpe_block
= gpe_block
;
590 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
591 return_ACPI_STATUS(status
);
594 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block
)
596 /*******************************************************************************
598 * FUNCTION: acpi_remove_gpe_block
600 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
604 * DESCRIPTION: Remove a previously installed block of GPE registers
606 ******************************************************************************/
607 acpi_status
acpi_remove_gpe_block(acpi_handle gpe_device
)
609 union acpi_operand_object
*obj_desc
;
611 struct acpi_namespace_node
*node
;
613 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block
);
616 return_ACPI_STATUS(AE_BAD_PARAMETER
);
619 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
620 if (ACPI_FAILURE(status
)) {
624 node
= acpi_ns_validate_handle(gpe_device
);
626 status
= AE_BAD_PARAMETER
;
627 goto unlock_and_exit
;
630 /* Get the device_object attached to the node */
632 obj_desc
= acpi_ns_get_attached_object(node
);
633 if (!obj_desc
|| !obj_desc
->device
.gpe_block
) {
634 return_ACPI_STATUS(AE_NULL_OBJECT
);
637 /* Delete the GPE block (but not the device_object) */
639 status
= acpi_ev_delete_gpe_block(obj_desc
->device
.gpe_block
);
640 if (ACPI_SUCCESS(status
)) {
641 obj_desc
->device
.gpe_block
= NULL
;
645 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
646 return_ACPI_STATUS(status
);
649 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block
)
651 /*******************************************************************************
653 * FUNCTION: acpi_get_gpe_device
655 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
656 * gpe_device - Where the parent GPE Device is returned
660 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
661 * gpe device indicates that the gpe number is contained in one of
662 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
664 ******************************************************************************/
666 acpi_get_gpe_device(u32 index
, acpi_handle
*gpe_device
)
668 struct acpi_gpe_device_info info
;
671 ACPI_FUNCTION_TRACE(acpi_get_gpe_device
);
674 return_ACPI_STATUS(AE_BAD_PARAMETER
);
677 if (index
>= acpi_current_gpe_count
) {
678 return_ACPI_STATUS(AE_NOT_EXIST
);
681 /* Setup and walk the GPE list */
684 info
.status
= AE_NOT_EXIST
;
685 info
.gpe_device
= NULL
;
686 info
.next_block_base_index
= 0;
688 status
= acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device
, &info
);
689 if (ACPI_FAILURE(status
)) {
690 return_ACPI_STATUS(status
);
693 *gpe_device
= ACPI_CAST_PTR(acpi_handle
, info
.gpe_device
);
694 return_ACPI_STATUS(info
.status
);
697 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device
)