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)
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"));
87 return_ACPI_STATUS(AE_OK);
90 /* Transition to ACPI mode */
92 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
93 if (ACPI_FAILURE(status)) {
95 "Could not transition to ACPI mode"));
96 return_ACPI_STATUS(status);
99 /* Sanity check that transition succeeded */
101 if (acpi_hw_get_mode() != ACPI_SYS_MODE_ACPI) {
103 "Hardware did not enter ACPI mode"));
104 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
107 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
108 "Transition to ACPI mode successful\n"));
110 return_ACPI_STATUS(AE_OK);
113 ACPI_EXPORT_SYMBOL(acpi_enable)
115 /*******************************************************************************
117 * FUNCTION: acpi_disable
123 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
125 ******************************************************************************/
126 acpi_status acpi_disable(void)
128 acpi_status status = AE_OK;
130 ACPI_FUNCTION_TRACE(acpi_disable);
132 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
133 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
134 "System is already in legacy (non-ACPI) mode\n"));
136 /* Transition to LEGACY mode */
138 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
140 if (ACPI_FAILURE(status)) {
142 "Could not exit ACPI mode to legacy mode"));
143 return_ACPI_STATUS(status);
146 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
149 return_ACPI_STATUS(status);
152 ACPI_EXPORT_SYMBOL(acpi_disable)
154 /*******************************************************************************
156 * FUNCTION: acpi_enable_event
158 * PARAMETERS: Event - The fixed eventto be enabled
163 * DESCRIPTION: Enable an ACPI event (fixed)
165 ******************************************************************************/
166 acpi_status acpi_enable_event(u32 event, u32 flags)
168 acpi_status status = AE_OK;
171 ACPI_FUNCTION_TRACE(acpi_enable_event);
173 /* Decode the Fixed Event */
175 if (event > ACPI_EVENT_MAX) {
176 return_ACPI_STATUS(AE_BAD_PARAMETER);
180 * Enable the requested fixed event (by writing a one to the enable
184 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
185 enable_register_id, ACPI_ENABLE_EVENT);
186 if (ACPI_FAILURE(status)) {
187 return_ACPI_STATUS(status);
190 /* Make sure that the hardware responded */
193 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
194 enable_register_id, &value);
195 if (ACPI_FAILURE(status)) {
196 return_ACPI_STATUS(status);
201 "Could not enable %s event",
202 acpi_ut_get_event_name(event)));
203 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
206 return_ACPI_STATUS(status);
209 ACPI_EXPORT_SYMBOL(acpi_enable_event)
211 /*******************************************************************************
213 * FUNCTION: acpi_clear_and_enable_gpe
215 * PARAMETERS: gpe_event_info - GPE to enable
219 * DESCRIPTION: Clear the given GPE from stale events and enable it.
221 ******************************************************************************/
223 acpi_clear_and_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
228 * We will only allow a GPE to be enabled if it has either an
229 * associated method (_Lxx/_Exx) or a handler. Otherwise, the
230 * GPE will be immediately disabled by acpi_ev_gpe_dispatch the
231 * first time it fires.
233 if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)) {
234 return_ACPI_STATUS(AE_NO_HANDLER);
237 /* Clear the GPE (of stale events) */
238 status = acpi_hw_clear_gpe(gpe_event_info);
239 if (ACPI_FAILURE(status)) {
240 return_ACPI_STATUS(status);
243 /* Enable the requested GPE */
244 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE);
246 return_ACPI_STATUS(status);
249 /*******************************************************************************
251 * FUNCTION: acpi_set_gpe
253 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
254 * gpe_number - GPE level within the GPE block
255 * action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
259 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
260 * the reference count mechanism used in the acpi_enable_gpe and
261 * acpi_disable_gpe interfaces -- and should be used with care.
263 * Note: Typically used to disable a runtime GPE for short period of time,
264 * then re-enable it, without disturbing the existing reference counts. This
265 * is useful, for example, in the Embedded Controller (EC) driver.
267 ******************************************************************************/
268 acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
270 struct acpi_gpe_event_info *gpe_event_info;
272 acpi_cpu_flags flags;
274 ACPI_FUNCTION_TRACE(acpi_set_gpe);
276 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
278 /* Ensure that we have a valid GPE number */
280 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
281 if (!gpe_event_info) {
282 status = AE_BAD_PARAMETER;
283 goto unlock_and_exit;
286 /* Perform the action */
289 case ACPI_GPE_ENABLE:
290 status = acpi_clear_and_enable_gpe(gpe_event_info);
293 case ACPI_GPE_DISABLE:
294 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
298 status = AE_BAD_PARAMETER;
303 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
304 return_ACPI_STATUS(status);
307 ACPI_EXPORT_SYMBOL(acpi_set_gpe)
309 /*******************************************************************************
311 * FUNCTION: acpi_gpe_wakeup
313 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
314 * gpe_number - GPE level within the GPE block
315 * Action - Enable or Disable
319 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit.
321 ******************************************************************************/
322 acpi_status acpi_gpe_wakeup(acpi_handle gpe_device, u32 gpe_number, u8 action)
324 acpi_status status = AE_OK;
325 struct acpi_gpe_event_info *gpe_event_info;
326 struct acpi_gpe_register_info *gpe_register_info;
327 acpi_cpu_flags flags;
330 ACPI_FUNCTION_TRACE(acpi_gpe_wakeup);
332 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
334 /* Ensure that we have a valid GPE number */
336 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
337 if (!gpe_event_info) {
338 status = AE_BAD_PARAMETER;
339 goto unlock_and_exit;
342 gpe_register_info = gpe_event_info->register_info;
343 if (!gpe_register_info) {
344 status = AE_NOT_EXIST;
345 goto unlock_and_exit;
349 acpi_hw_get_gpe_register_bit(gpe_event_info, gpe_register_info);
351 /* Perform the action */
354 case ACPI_GPE_ENABLE:
355 ACPI_SET_BIT(gpe_register_info->enable_for_wake,
359 case ACPI_GPE_DISABLE:
360 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
365 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
366 status = AE_BAD_PARAMETER;
371 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
372 return_ACPI_STATUS(status);
375 ACPI_EXPORT_SYMBOL(acpi_gpe_wakeup)
377 /*******************************************************************************
379 * FUNCTION: acpi_enable_gpe
381 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
382 * gpe_number - GPE level within the GPE block
386 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
389 ******************************************************************************/
390 acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
392 acpi_status status = AE_OK;
393 struct acpi_gpe_event_info *gpe_event_info;
394 acpi_cpu_flags flags;
396 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
398 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
400 /* Ensure that we have a valid GPE number */
402 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
403 if (!gpe_event_info) {
404 status = AE_BAD_PARAMETER;
405 goto unlock_and_exit;
408 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
409 status = AE_LIMIT; /* Too many references */
410 goto unlock_and_exit;
413 gpe_event_info->runtime_count++;
414 if (gpe_event_info->runtime_count == 1) {
415 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
416 if (ACPI_SUCCESS(status)) {
417 status = acpi_clear_and_enable_gpe(gpe_event_info);
419 if (ACPI_FAILURE(status)) {
420 gpe_event_info->runtime_count--;
425 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
426 return_ACPI_STATUS(status);
428 ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
430 /*******************************************************************************
432 * FUNCTION: acpi_disable_gpe
434 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
435 * gpe_number - GPE level within the GPE block
439 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
440 * removed, only then is the GPE disabled (for runtime GPEs), or
441 * the GPE mask bit disabled (for wake GPEs)
443 ******************************************************************************/
444 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
446 acpi_status status = AE_OK;
447 struct acpi_gpe_event_info *gpe_event_info;
448 acpi_cpu_flags flags;
450 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
452 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
454 /* Ensure that we have a valid GPE number */
456 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
457 if (!gpe_event_info) {
458 status = AE_BAD_PARAMETER;
459 goto unlock_and_exit;
462 /* Hardware-disable a runtime GPE on removal of the last reference */
464 if (!gpe_event_info->runtime_count) {
465 status = AE_LIMIT; /* There are no references to remove */
466 goto unlock_and_exit;
469 gpe_event_info->runtime_count--;
470 if (!gpe_event_info->runtime_count) {
471 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
472 if (ACPI_SUCCESS(status)) {
474 acpi_hw_low_set_gpe(gpe_event_info,
477 if (ACPI_FAILURE(status)) {
478 gpe_event_info->runtime_count++;
483 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
484 return_ACPI_STATUS(status);
486 ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
488 /*******************************************************************************
490 * FUNCTION: acpi_disable_event
492 * PARAMETERS: Event - The fixed eventto be enabled
497 * DESCRIPTION: Disable an ACPI event (fixed)
499 ******************************************************************************/
500 acpi_status acpi_disable_event(u32 event, u32 flags)
502 acpi_status status = AE_OK;
505 ACPI_FUNCTION_TRACE(acpi_disable_event);
507 /* Decode the Fixed Event */
509 if (event > ACPI_EVENT_MAX) {
510 return_ACPI_STATUS(AE_BAD_PARAMETER);
514 * Disable the requested fixed event (by writing a zero to the enable
518 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
519 enable_register_id, ACPI_DISABLE_EVENT);
520 if (ACPI_FAILURE(status)) {
521 return_ACPI_STATUS(status);
525 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
526 enable_register_id, &value);
527 if (ACPI_FAILURE(status)) {
528 return_ACPI_STATUS(status);
533 "Could not disable %s events",
534 acpi_ut_get_event_name(event)));
535 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
538 return_ACPI_STATUS(status);
541 ACPI_EXPORT_SYMBOL(acpi_disable_event)
543 /*******************************************************************************
545 * FUNCTION: acpi_clear_event
547 * PARAMETERS: Event - The fixed event to be cleared
551 * DESCRIPTION: Clear an ACPI event (fixed)
553 ******************************************************************************/
554 acpi_status acpi_clear_event(u32 event)
556 acpi_status status = AE_OK;
558 ACPI_FUNCTION_TRACE(acpi_clear_event);
560 /* Decode the Fixed Event */
562 if (event > ACPI_EVENT_MAX) {
563 return_ACPI_STATUS(AE_BAD_PARAMETER);
567 * Clear the requested fixed event (By writing a one to the status
571 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
572 status_register_id, ACPI_CLEAR_STATUS);
574 return_ACPI_STATUS(status);
577 ACPI_EXPORT_SYMBOL(acpi_clear_event)
579 /*******************************************************************************
581 * FUNCTION: acpi_clear_gpe
583 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
584 * gpe_number - GPE level within the GPE block
588 * DESCRIPTION: Clear an ACPI event (general purpose)
590 ******************************************************************************/
591 acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
593 acpi_status status = AE_OK;
594 struct acpi_gpe_event_info *gpe_event_info;
595 acpi_cpu_flags flags;
597 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
599 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
601 /* Ensure that we have a valid GPE number */
603 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
604 if (!gpe_event_info) {
605 status = AE_BAD_PARAMETER;
606 goto unlock_and_exit;
609 status = acpi_hw_clear_gpe(gpe_event_info);
612 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
613 return_ACPI_STATUS(status);
616 ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
617 /*******************************************************************************
619 * FUNCTION: acpi_get_event_status
621 * PARAMETERS: Event - The fixed event
622 * event_status - Where the current status of the event will
627 * DESCRIPTION: Obtains and returns the current status of the event
629 ******************************************************************************/
630 acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
632 acpi_status status = AE_OK;
635 ACPI_FUNCTION_TRACE(acpi_get_event_status);
638 return_ACPI_STATUS(AE_BAD_PARAMETER);
641 /* Decode the Fixed Event */
643 if (event > ACPI_EVENT_MAX) {
644 return_ACPI_STATUS(AE_BAD_PARAMETER);
647 /* Get the status of the requested fixed event */
650 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
651 enable_register_id, &value);
652 if (ACPI_FAILURE(status))
653 return_ACPI_STATUS(status);
655 *event_status = value;
658 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
659 status_register_id, &value);
660 if (ACPI_FAILURE(status))
661 return_ACPI_STATUS(status);
664 *event_status |= ACPI_EVENT_FLAG_SET;
666 if (acpi_gbl_fixed_event_handlers[event].handler)
667 *event_status |= ACPI_EVENT_FLAG_HANDLE;
669 return_ACPI_STATUS(status);
672 ACPI_EXPORT_SYMBOL(acpi_get_event_status)
674 /*******************************************************************************
676 * FUNCTION: acpi_get_gpe_status
678 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
679 * gpe_number - GPE level within the GPE block
680 * event_status - Where the current status of the event will
685 * DESCRIPTION: Get status of an event (general purpose)
687 ******************************************************************************/
689 acpi_get_gpe_status(acpi_handle gpe_device,
690 u32 gpe_number, acpi_event_status *event_status)
692 acpi_status status = AE_OK;
693 struct acpi_gpe_event_info *gpe_event_info;
694 acpi_cpu_flags flags;
696 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
698 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
700 /* Ensure that we have a valid GPE number */
702 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
703 if (!gpe_event_info) {
704 status = AE_BAD_PARAMETER;
705 goto unlock_and_exit;
708 /* Obtain status on the requested GPE number */
710 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
712 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
713 *event_status |= ACPI_EVENT_FLAG_HANDLE;
716 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
717 return_ACPI_STATUS(status);
720 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
721 /*******************************************************************************
723 * FUNCTION: acpi_install_gpe_block
725 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
726 * gpe_block_address - Address and space_iD
727 * register_count - Number of GPE register pairs in the block
728 * interrupt_number - H/W interrupt for the block
732 * DESCRIPTION: Create and Install a block of GPE registers
734 ******************************************************************************/
736 acpi_install_gpe_block(acpi_handle gpe_device,
737 struct acpi_generic_address *gpe_block_address,
738 u32 register_count, u32 interrupt_number)
741 union acpi_operand_object *obj_desc;
742 struct acpi_namespace_node *node;
743 struct acpi_gpe_block_info *gpe_block;
745 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
747 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
748 return_ACPI_STATUS(AE_BAD_PARAMETER);
751 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
752 if (ACPI_FAILURE(status)) {
756 node = acpi_ns_validate_handle(gpe_device);
758 status = AE_BAD_PARAMETER;
759 goto unlock_and_exit;
763 * For user-installed GPE Block Devices, the gpe_block_base_number
767 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
768 interrupt_number, &gpe_block);
769 if (ACPI_FAILURE(status)) {
770 goto unlock_and_exit;
773 /* Install block in the device_object attached to the node */
775 obj_desc = acpi_ns_get_attached_object(node);
779 * No object, create a new one (Device nodes do not always have
780 * an attached object)
782 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
784 status = AE_NO_MEMORY;
785 goto unlock_and_exit;
789 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
791 /* Remove local reference to the object */
793 acpi_ut_remove_reference(obj_desc);
795 if (ACPI_FAILURE(status)) {
796 goto unlock_and_exit;
800 /* Now install the GPE block in the device_object */
802 obj_desc->device.gpe_block = gpe_block;
804 /* Run the _PRW methods and enable the runtime GPEs in the new block */
806 status = acpi_ev_initialize_gpe_block(node, gpe_block);
809 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
810 return_ACPI_STATUS(status);
813 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
815 /*******************************************************************************
817 * FUNCTION: acpi_remove_gpe_block
819 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
823 * DESCRIPTION: Remove a previously installed block of GPE registers
825 ******************************************************************************/
826 acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
828 union acpi_operand_object *obj_desc;
830 struct acpi_namespace_node *node;
832 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
835 return_ACPI_STATUS(AE_BAD_PARAMETER);
838 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
839 if (ACPI_FAILURE(status)) {
843 node = acpi_ns_validate_handle(gpe_device);
845 status = AE_BAD_PARAMETER;
846 goto unlock_and_exit;
849 /* Get the device_object attached to the node */
851 obj_desc = acpi_ns_get_attached_object(node);
852 if (!obj_desc || !obj_desc->device.gpe_block) {
853 return_ACPI_STATUS(AE_NULL_OBJECT);
856 /* Delete the GPE block (but not the device_object) */
858 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
859 if (ACPI_SUCCESS(status)) {
860 obj_desc->device.gpe_block = NULL;
864 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
865 return_ACPI_STATUS(status);
868 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
870 /*******************************************************************************
872 * FUNCTION: acpi_get_gpe_device
874 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
875 * gpe_device - Where the parent GPE Device is returned
879 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
880 * gpe device indicates that the gpe number is contained in one of
881 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
883 ******************************************************************************/
885 acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
887 struct acpi_gpe_device_info info;
890 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
893 return_ACPI_STATUS(AE_BAD_PARAMETER);
896 if (index >= acpi_current_gpe_count) {
897 return_ACPI_STATUS(AE_NOT_EXIST);
900 /* Setup and walk the GPE list */
903 info.status = AE_NOT_EXIST;
904 info.gpe_device = NULL;
905 info.next_block_base_index = 0;
907 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
908 if (ACPI_FAILURE(status)) {
909 return_ACPI_STATUS(status);
912 *gpe_device = info.gpe_device;
913 return_ACPI_STATUS(info.status);
916 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
918 /*******************************************************************************
920 * FUNCTION: acpi_ev_get_gpe_device
922 * PARAMETERS: GPE_WALK_CALLBACK
926 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
927 * block device. NULL if the GPE is one of the FADT-defined GPEs.
929 ******************************************************************************/
931 acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
932 struct acpi_gpe_block_info *gpe_block, void *context)
934 struct acpi_gpe_device_info *info = context;
936 /* Increment Index by the number of GPEs in this block */
938 info->next_block_base_index += gpe_block->gpe_count;
940 if (info->index < info->next_block_base_index) {
942 * The GPE index is within this block, get the node. Leave the node
943 * NULL for the FADT-defined GPEs
945 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
946 info->gpe_device = gpe_block->node;
949 info->status = AE_OK;
950 return (AE_CTRL_END);
956 /******************************************************************************
958 * FUNCTION: acpi_disable_all_gpes
964 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
966 ******************************************************************************/
968 acpi_status acpi_disable_all_gpes(void)
972 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
974 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
975 if (ACPI_FAILURE(status)) {
976 return_ACPI_STATUS(status);
979 status = acpi_hw_disable_all_gpes();
980 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
982 return_ACPI_STATUS(status);
985 /******************************************************************************
987 * FUNCTION: acpi_enable_all_runtime_gpes
993 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
995 ******************************************************************************/
997 acpi_status acpi_enable_all_runtime_gpes(void)
1001 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
1003 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
1004 if (ACPI_FAILURE(status)) {
1005 return_ACPI_STATUS(status);
1008 status = acpi_hw_enable_all_runtime_gpes();
1009 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1011 return_ACPI_STATUS(status);