1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2010, 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>
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME("evxfevnt")
53 /* Local prototypes */
55 acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
56 struct acpi_gpe_block_info
*gpe_block
, void *context
);
58 /*******************************************************************************
60 * FUNCTION: acpi_enable
66 * DESCRIPTION: Transfers the system into ACPI mode.
68 ******************************************************************************/
70 acpi_status
acpi_enable(void)
72 acpi_status status
= AE_OK
;
74 ACPI_FUNCTION_TRACE(acpi_enable
);
76 /* ACPI tables must be present */
78 if (!acpi_tb_tables_loaded()) {
79 return_ACPI_STATUS(AE_NO_ACPI_TABLES
);
82 /* Check current mode */
84 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI
) {
85 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
86 "System is already in ACPI mode\n"));
88 /* Transition to ACPI mode */
90 status
= acpi_hw_set_mode(ACPI_SYS_MODE_ACPI
);
91 if (ACPI_FAILURE(status
)) {
93 "Could not transition to ACPI mode"));
94 return_ACPI_STATUS(status
);
97 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
98 "Transition to ACPI mode successful\n"));
101 return_ACPI_STATUS(status
);
104 ACPI_EXPORT_SYMBOL(acpi_enable
)
106 /*******************************************************************************
108 * FUNCTION: acpi_disable
114 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
116 ******************************************************************************/
117 acpi_status
acpi_disable(void)
119 acpi_status status
= AE_OK
;
121 ACPI_FUNCTION_TRACE(acpi_disable
);
123 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY
) {
124 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
125 "System is already in legacy (non-ACPI) mode\n"));
127 /* Transition to LEGACY mode */
129 status
= acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY
);
131 if (ACPI_FAILURE(status
)) {
133 "Could not exit ACPI mode to legacy mode"));
134 return_ACPI_STATUS(status
);
137 ACPI_DEBUG_PRINT((ACPI_DB_INIT
, "ACPI mode disabled\n"));
140 return_ACPI_STATUS(status
);
143 ACPI_EXPORT_SYMBOL(acpi_disable
)
145 /*******************************************************************************
147 * FUNCTION: acpi_enable_event
149 * PARAMETERS: Event - The fixed eventto be enabled
154 * DESCRIPTION: Enable an ACPI event (fixed)
156 ******************************************************************************/
157 acpi_status
acpi_enable_event(u32 event
, u32 flags
)
159 acpi_status status
= AE_OK
;
162 ACPI_FUNCTION_TRACE(acpi_enable_event
);
164 /* Decode the Fixed Event */
166 if (event
> ACPI_EVENT_MAX
) {
167 return_ACPI_STATUS(AE_BAD_PARAMETER
);
171 * Enable the requested fixed event (by writing a one to the enable
175 acpi_write_bit_register(acpi_gbl_fixed_event_info
[event
].
176 enable_register_id
, ACPI_ENABLE_EVENT
);
177 if (ACPI_FAILURE(status
)) {
178 return_ACPI_STATUS(status
);
181 /* Make sure that the hardware responded */
184 acpi_read_bit_register(acpi_gbl_fixed_event_info
[event
].
185 enable_register_id
, &value
);
186 if (ACPI_FAILURE(status
)) {
187 return_ACPI_STATUS(status
);
192 "Could not enable %s event",
193 acpi_ut_get_event_name(event
)));
194 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE
);
197 return_ACPI_STATUS(status
);
200 ACPI_EXPORT_SYMBOL(acpi_enable_event
)
202 /*******************************************************************************
204 * FUNCTION: acpi_clear_and_enable_gpe
206 * PARAMETERS: gpe_event_info - GPE to enable
210 * DESCRIPTION: Clear the given GPE from stale events and enable it.
212 ******************************************************************************/
214 acpi_clear_and_enable_gpe(struct acpi_gpe_event_info
*gpe_event_info
)
219 * We will only allow a GPE to be enabled if it has either an
220 * associated method (_Lxx/_Exx) or a handler. Otherwise, the
221 * GPE will be immediately disabled by acpi_ev_gpe_dispatch the
222 * first time it fires.
224 if (!(gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
)) {
225 return_ACPI_STATUS(AE_NO_HANDLER
);
228 /* Clear the GPE (of stale events) */
229 status
= acpi_hw_clear_gpe(gpe_event_info
);
230 if (ACPI_FAILURE(status
)) {
231 return_ACPI_STATUS(status
);
234 /* Enable the requested GPE */
235 status
= acpi_hw_low_set_gpe(gpe_event_info
, ACPI_GPE_ENABLE
);
237 return_ACPI_STATUS(status
);
240 /*******************************************************************************
242 * FUNCTION: acpi_set_gpe
244 * PARAMETERS: gpe_device - Parent GPE Device
245 * gpe_number - GPE level within the GPE block
246 * action - Enable or disable
247 * Called from ISR or not
251 * DESCRIPTION: Enable or disable an ACPI event (general purpose)
253 ******************************************************************************/
254 acpi_status
acpi_set_gpe(acpi_handle gpe_device
, u32 gpe_number
, u8 action
)
256 acpi_status status
= AE_OK
;
257 acpi_cpu_flags flags
;
258 struct acpi_gpe_event_info
*gpe_event_info
;
260 ACPI_FUNCTION_TRACE(acpi_set_gpe
);
262 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
264 /* Ensure that we have a valid GPE number */
266 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
267 if (!gpe_event_info
) {
268 status
= AE_BAD_PARAMETER
;
269 goto unlock_and_exit
;
272 /* Perform the action */
275 case ACPI_GPE_ENABLE
:
276 status
= acpi_clear_and_enable_gpe(gpe_event_info
);
279 case ACPI_GPE_DISABLE
:
280 status
= acpi_hw_low_set_gpe(gpe_event_info
, ACPI_GPE_DISABLE
);
284 ACPI_ERROR((AE_INFO
, "Invalid action\n"));
285 status
= AE_BAD_PARAMETER
;
290 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
291 return_ACPI_STATUS(status
);
294 ACPI_EXPORT_SYMBOL(acpi_set_gpe
)
296 /*******************************************************************************
298 * FUNCTION: acpi_enable_gpe
300 * PARAMETERS: gpe_device - Parent GPE Device
301 * gpe_number - GPE level within the GPE block
302 * type - Purpose the GPE will be used for
306 * DESCRIPTION: Take a reference to a GPE and enable it if necessary
308 ******************************************************************************/
309 acpi_status
acpi_enable_gpe(acpi_handle gpe_device
, u32 gpe_number
, u8 type
)
311 acpi_status status
= AE_OK
;
312 acpi_cpu_flags flags
;
313 struct acpi_gpe_event_info
*gpe_event_info
;
315 ACPI_FUNCTION_TRACE(acpi_enable_gpe
);
317 if (type
& ~ACPI_GPE_TYPE_WAKE_RUN
)
318 return_ACPI_STATUS(AE_BAD_PARAMETER
);
320 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
322 /* Ensure that we have a valid GPE number */
324 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
325 if (!gpe_event_info
) {
326 status
= AE_BAD_PARAMETER
;
327 goto unlock_and_exit
;
330 if (type
& ACPI_GPE_TYPE_RUNTIME
) {
331 if (++gpe_event_info
->runtime_count
== 1) {
332 status
= acpi_ev_update_gpe_enable_masks(gpe_event_info
);
333 if (ACPI_SUCCESS(status
)) {
334 status
= acpi_clear_and_enable_gpe(gpe_event_info
);
336 if (ACPI_FAILURE(status
)) {
337 gpe_event_info
->runtime_count
--;
342 if (type
& ACPI_GPE_TYPE_WAKE
) {
343 if (!(gpe_event_info
->flags
& ACPI_GPE_CAN_WAKE
)) {
344 status
= AE_BAD_PARAMETER
;
345 goto unlock_and_exit
;
349 * Wake-up GPEs are only enabled right prior to putting the
350 * system into a sleep state.
352 if (++gpe_event_info
->wakeup_count
== 1)
353 status
= acpi_ev_update_gpe_enable_masks(gpe_event_info
);
357 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
358 return_ACPI_STATUS(status
);
360 ACPI_EXPORT_SYMBOL(acpi_enable_gpe
)
362 /*******************************************************************************
364 * FUNCTION: acpi_disable_gpe
366 * PARAMETERS: gpe_device - Parent GPE Device
367 * gpe_number - GPE level within the GPE block
368 * type - Purpose the GPE won't be used for any more
372 * DESCRIPTION: Release a reference to a GPE and disable it if necessary
374 ******************************************************************************/
375 acpi_status
acpi_disable_gpe(acpi_handle gpe_device
, u32 gpe_number
, u8 type
)
377 acpi_status status
= AE_OK
;
378 acpi_cpu_flags flags
;
379 struct acpi_gpe_event_info
*gpe_event_info
;
381 ACPI_FUNCTION_TRACE(acpi_disable_gpe
);
383 if (type
& ~ACPI_GPE_TYPE_WAKE_RUN
)
384 return_ACPI_STATUS(AE_BAD_PARAMETER
);
386 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
387 /* Ensure that we have a valid GPE number */
389 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
390 if (!gpe_event_info
) {
391 status
= AE_BAD_PARAMETER
;
392 goto unlock_and_exit
;
395 if ((type
& ACPI_GPE_TYPE_RUNTIME
) && gpe_event_info
->runtime_count
) {
396 if (--gpe_event_info
->runtime_count
== 0) {
397 status
= acpi_ev_update_gpe_enable_masks(gpe_event_info
);
398 if (ACPI_SUCCESS(status
)) {
399 status
= acpi_hw_low_set_gpe(gpe_event_info
,
402 if (ACPI_FAILURE(status
)) {
403 gpe_event_info
->runtime_count
++;
408 if ((type
& ACPI_GPE_TYPE_WAKE
) && gpe_event_info
->wakeup_count
) {
410 * Wake-up GPEs are not enabled after leaving system sleep
411 * states, so we don't need to disable them here.
413 if (--gpe_event_info
->wakeup_count
== 0)
414 status
= acpi_ev_update_gpe_enable_masks(gpe_event_info
);
418 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
419 return_ACPI_STATUS(status
);
421 ACPI_EXPORT_SYMBOL(acpi_disable_gpe
)
423 /*******************************************************************************
425 * FUNCTION: acpi_disable_event
427 * PARAMETERS: Event - The fixed eventto be enabled
432 * DESCRIPTION: Disable an ACPI event (fixed)
434 ******************************************************************************/
435 acpi_status
acpi_disable_event(u32 event
, u32 flags
)
437 acpi_status status
= AE_OK
;
440 ACPI_FUNCTION_TRACE(acpi_disable_event
);
442 /* Decode the Fixed Event */
444 if (event
> ACPI_EVENT_MAX
) {
445 return_ACPI_STATUS(AE_BAD_PARAMETER
);
449 * Disable the requested fixed event (by writing a zero to the enable
453 acpi_write_bit_register(acpi_gbl_fixed_event_info
[event
].
454 enable_register_id
, ACPI_DISABLE_EVENT
);
455 if (ACPI_FAILURE(status
)) {
456 return_ACPI_STATUS(status
);
460 acpi_read_bit_register(acpi_gbl_fixed_event_info
[event
].
461 enable_register_id
, &value
);
462 if (ACPI_FAILURE(status
)) {
463 return_ACPI_STATUS(status
);
468 "Could not disable %s events",
469 acpi_ut_get_event_name(event
)));
470 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE
);
473 return_ACPI_STATUS(status
);
476 ACPI_EXPORT_SYMBOL(acpi_disable_event
)
478 /*******************************************************************************
480 * FUNCTION: acpi_clear_event
482 * PARAMETERS: Event - The fixed event to be cleared
486 * DESCRIPTION: Clear an ACPI event (fixed)
488 ******************************************************************************/
489 acpi_status
acpi_clear_event(u32 event
)
491 acpi_status status
= AE_OK
;
493 ACPI_FUNCTION_TRACE(acpi_clear_event
);
495 /* Decode the Fixed Event */
497 if (event
> ACPI_EVENT_MAX
) {
498 return_ACPI_STATUS(AE_BAD_PARAMETER
);
502 * Clear the requested fixed event (By writing a one to the status
506 acpi_write_bit_register(acpi_gbl_fixed_event_info
[event
].
507 status_register_id
, ACPI_CLEAR_STATUS
);
509 return_ACPI_STATUS(status
);
512 ACPI_EXPORT_SYMBOL(acpi_clear_event
)
514 /*******************************************************************************
516 * FUNCTION: acpi_clear_gpe
518 * PARAMETERS: gpe_device - Parent GPE Device
519 * gpe_number - GPE level within the GPE block
520 * Flags - Called from an ISR or not
524 * DESCRIPTION: Clear an ACPI event (general purpose)
526 ******************************************************************************/
527 acpi_status
acpi_clear_gpe(acpi_handle gpe_device
, u32 gpe_number
, u32 flags
)
529 acpi_status status
= AE_OK
;
530 struct acpi_gpe_event_info
*gpe_event_info
;
532 ACPI_FUNCTION_TRACE(acpi_clear_gpe
);
534 /* Use semaphore lock if not executing at interrupt level */
536 if (flags
& ACPI_NOT_ISR
) {
537 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
538 if (ACPI_FAILURE(status
)) {
539 return_ACPI_STATUS(status
);
543 /* Ensure that we have a valid GPE number */
545 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
546 if (!gpe_event_info
) {
547 status
= AE_BAD_PARAMETER
;
548 goto unlock_and_exit
;
551 status
= acpi_hw_clear_gpe(gpe_event_info
);
554 if (flags
& ACPI_NOT_ISR
) {
555 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
557 return_ACPI_STATUS(status
);
560 ACPI_EXPORT_SYMBOL(acpi_clear_gpe
)
561 /*******************************************************************************
563 * FUNCTION: acpi_get_event_status
565 * PARAMETERS: Event - The fixed event
566 * event_status - Where the current status of the event will
571 * DESCRIPTION: Obtains and returns the current status of the event
573 ******************************************************************************/
574 acpi_status
acpi_get_event_status(u32 event
, acpi_event_status
* event_status
)
576 acpi_status status
= AE_OK
;
579 ACPI_FUNCTION_TRACE(acpi_get_event_status
);
582 return_ACPI_STATUS(AE_BAD_PARAMETER
);
585 /* Decode the Fixed Event */
587 if (event
> ACPI_EVENT_MAX
) {
588 return_ACPI_STATUS(AE_BAD_PARAMETER
);
591 /* Get the status of the requested fixed event */
594 acpi_read_bit_register(acpi_gbl_fixed_event_info
[event
].
595 enable_register_id
, &value
);
596 if (ACPI_FAILURE(status
))
597 return_ACPI_STATUS(status
);
599 *event_status
= value
;
602 acpi_read_bit_register(acpi_gbl_fixed_event_info
[event
].
603 status_register_id
, &value
);
604 if (ACPI_FAILURE(status
))
605 return_ACPI_STATUS(status
);
608 *event_status
|= ACPI_EVENT_FLAG_SET
;
610 if (acpi_gbl_fixed_event_handlers
[event
].handler
)
611 *event_status
|= ACPI_EVENT_FLAG_HANDLE
;
613 return_ACPI_STATUS(status
);
616 ACPI_EXPORT_SYMBOL(acpi_get_event_status
)
618 /*******************************************************************************
620 * FUNCTION: acpi_get_gpe_status
622 * PARAMETERS: gpe_device - Parent GPE Device
623 * gpe_number - GPE level within the GPE block
624 * Flags - Called from an ISR or not
625 * event_status - Where the current status of the event will
630 * DESCRIPTION: Get status of an event (general purpose)
632 ******************************************************************************/
634 acpi_get_gpe_status(acpi_handle gpe_device
,
635 u32 gpe_number
, u32 flags
, acpi_event_status
* event_status
)
637 acpi_status status
= AE_OK
;
638 struct acpi_gpe_event_info
*gpe_event_info
;
640 ACPI_FUNCTION_TRACE(acpi_get_gpe_status
);
642 /* Use semaphore lock if not executing at interrupt level */
644 if (flags
& ACPI_NOT_ISR
) {
645 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
646 if (ACPI_FAILURE(status
)) {
647 return_ACPI_STATUS(status
);
651 /* Ensure that we have a valid GPE number */
653 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
654 if (!gpe_event_info
) {
655 status
= AE_BAD_PARAMETER
;
656 goto unlock_and_exit
;
659 /* Obtain status on the requested GPE number */
661 status
= acpi_hw_get_gpe_status(gpe_event_info
, event_status
);
663 if (gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
)
664 *event_status
|= ACPI_EVENT_FLAG_HANDLE
;
667 if (flags
& ACPI_NOT_ISR
) {
668 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
670 return_ACPI_STATUS(status
);
673 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status
)
674 /*******************************************************************************
676 * FUNCTION: acpi_install_gpe_block
678 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
679 * gpe_block_address - Address and space_iD
680 * register_count - Number of GPE register pairs in the block
681 * interrupt_number - H/W interrupt for the block
685 * DESCRIPTION: Create and Install a block of GPE registers
687 ******************************************************************************/
689 acpi_install_gpe_block(acpi_handle gpe_device
,
690 struct acpi_generic_address
*gpe_block_address
,
691 u32 register_count
, u32 interrupt_number
)
694 union acpi_operand_object
*obj_desc
;
695 struct acpi_namespace_node
*node
;
696 struct acpi_gpe_block_info
*gpe_block
;
698 ACPI_FUNCTION_TRACE(acpi_install_gpe_block
);
700 if ((!gpe_device
) || (!gpe_block_address
) || (!register_count
)) {
701 return_ACPI_STATUS(AE_BAD_PARAMETER
);
704 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
705 if (ACPI_FAILURE(status
)) {
709 node
= acpi_ns_validate_handle(gpe_device
);
711 status
= AE_BAD_PARAMETER
;
712 goto unlock_and_exit
;
716 * For user-installed GPE Block Devices, the gpe_block_base_number
720 acpi_ev_create_gpe_block(node
, gpe_block_address
, register_count
, 0,
721 interrupt_number
, &gpe_block
);
722 if (ACPI_FAILURE(status
)) {
723 goto unlock_and_exit
;
726 /* Run the _PRW methods and enable the GPEs */
728 status
= acpi_ev_initialize_gpe_block(node
, gpe_block
);
729 if (ACPI_FAILURE(status
)) {
730 goto unlock_and_exit
;
733 /* Get the device_object attached to the node */
735 obj_desc
= acpi_ns_get_attached_object(node
);
738 /* No object, create a new one */
740 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_DEVICE
);
742 status
= AE_NO_MEMORY
;
743 goto unlock_and_exit
;
747 acpi_ns_attach_object(node
, obj_desc
, ACPI_TYPE_DEVICE
);
749 /* Remove local reference to the object */
751 acpi_ut_remove_reference(obj_desc
);
753 if (ACPI_FAILURE(status
)) {
754 goto unlock_and_exit
;
758 /* Install the GPE block in the device_object */
760 obj_desc
->device
.gpe_block
= gpe_block
;
763 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
764 return_ACPI_STATUS(status
);
767 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block
)
769 /*******************************************************************************
771 * FUNCTION: acpi_remove_gpe_block
773 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
777 * DESCRIPTION: Remove a previously installed block of GPE registers
779 ******************************************************************************/
780 acpi_status
acpi_remove_gpe_block(acpi_handle gpe_device
)
782 union acpi_operand_object
*obj_desc
;
784 struct acpi_namespace_node
*node
;
786 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block
);
789 return_ACPI_STATUS(AE_BAD_PARAMETER
);
792 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
793 if (ACPI_FAILURE(status
)) {
797 node
= acpi_ns_validate_handle(gpe_device
);
799 status
= AE_BAD_PARAMETER
;
800 goto unlock_and_exit
;
803 /* Get the device_object attached to the node */
805 obj_desc
= acpi_ns_get_attached_object(node
);
806 if (!obj_desc
|| !obj_desc
->device
.gpe_block
) {
807 return_ACPI_STATUS(AE_NULL_OBJECT
);
810 /* Delete the GPE block (but not the device_object) */
812 status
= acpi_ev_delete_gpe_block(obj_desc
->device
.gpe_block
);
813 if (ACPI_SUCCESS(status
)) {
814 obj_desc
->device
.gpe_block
= NULL
;
818 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
819 return_ACPI_STATUS(status
);
822 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block
)
824 /*******************************************************************************
826 * FUNCTION: acpi_get_gpe_device
828 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
829 * gpe_device - Where the parent GPE Device is returned
833 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
834 * gpe device indicates that the gpe number is contained in one of
835 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
837 ******************************************************************************/
839 acpi_get_gpe_device(u32 index
, acpi_handle
*gpe_device
)
841 struct acpi_gpe_device_info info
;
844 ACPI_FUNCTION_TRACE(acpi_get_gpe_device
);
847 return_ACPI_STATUS(AE_BAD_PARAMETER
);
850 if (index
>= acpi_current_gpe_count
) {
851 return_ACPI_STATUS(AE_NOT_EXIST
);
854 /* Setup and walk the GPE list */
857 info
.status
= AE_NOT_EXIST
;
858 info
.gpe_device
= NULL
;
859 info
.next_block_base_index
= 0;
861 status
= acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device
, &info
);
862 if (ACPI_FAILURE(status
)) {
863 return_ACPI_STATUS(status
);
866 *gpe_device
= info
.gpe_device
;
867 return_ACPI_STATUS(info
.status
);
870 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device
)
872 /*******************************************************************************
874 * FUNCTION: acpi_ev_get_gpe_device
876 * PARAMETERS: GPE_WALK_CALLBACK
880 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
881 * block device. NULL if the GPE is one of the FADT-defined GPEs.
883 ******************************************************************************/
885 acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info
*gpe_xrupt_info
,
886 struct acpi_gpe_block_info
*gpe_block
, void *context
)
888 struct acpi_gpe_device_info
*info
= context
;
890 /* Increment Index by the number of GPEs in this block */
892 info
->next_block_base_index
+=
893 (gpe_block
->register_count
* ACPI_GPE_REGISTER_WIDTH
);
895 if (info
->index
< info
->next_block_base_index
) {
897 * The GPE index is within this block, get the node. Leave the node
898 * NULL for the FADT-defined GPEs
900 if ((gpe_block
->node
)->type
== ACPI_TYPE_DEVICE
) {
901 info
->gpe_device
= gpe_block
->node
;
904 info
->status
= AE_OK
;
905 return (AE_CTRL_END
);
911 /******************************************************************************
913 * FUNCTION: acpi_disable_all_gpes
919 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
921 ******************************************************************************/
923 acpi_status
acpi_disable_all_gpes(void)
927 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes
);
929 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
930 if (ACPI_FAILURE(status
)) {
931 return_ACPI_STATUS(status
);
934 status
= acpi_hw_disable_all_gpes();
935 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
937 return_ACPI_STATUS(status
);
940 /******************************************************************************
942 * FUNCTION: acpi_enable_all_runtime_gpes
948 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
950 ******************************************************************************/
952 acpi_status
acpi_enable_all_runtime_gpes(void)
956 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes
);
958 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
959 if (ACPI_FAILURE(status
)) {
960 return_ACPI_STATUS(status
);
963 status
= acpi_hw_enable_all_runtime_gpes();
964 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
966 return_ACPI_STATUS(status
);