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_enable_gpe
313 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
314 * gpe_number - GPE level within the GPE block
315 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
320 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
321 * hardware-enabled (for runtime GPEs), or the GPE register mask
322 * is updated (for wake GPEs).
324 ******************************************************************************/
325 acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
327 acpi_status status = AE_OK;
328 struct acpi_gpe_event_info *gpe_event_info;
329 acpi_cpu_flags flags;
331 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
333 /* Parameter validation */
335 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
336 return_ACPI_STATUS(AE_BAD_PARAMETER);
339 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
341 /* Ensure that we have a valid GPE number */
343 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
344 if (!gpe_event_info) {
345 status = AE_BAD_PARAMETER;
346 goto unlock_and_exit;
349 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
350 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
351 status = AE_LIMIT; /* Too many references */
352 goto unlock_and_exit;
355 gpe_event_info->runtime_count++;
356 if (gpe_event_info->runtime_count == 1) {
357 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
358 if (ACPI_SUCCESS(status)) {
359 status = acpi_clear_and_enable_gpe(gpe_event_info);
362 if (ACPI_FAILURE(status)) {
363 gpe_event_info->runtime_count--;
364 goto unlock_and_exit;
369 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
370 /* The GPE must have the ability to wake the system */
372 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
374 goto unlock_and_exit;
377 if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) {
378 status = AE_LIMIT; /* Too many references */
379 goto unlock_and_exit;
383 * Update the enable mask on the first wakeup reference. Wake GPEs
384 * are only hardware-enabled just before sleeping.
386 gpe_event_info->wakeup_count++;
387 if (gpe_event_info->wakeup_count == 1) {
388 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
393 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
394 return_ACPI_STATUS(status);
396 ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
398 /*******************************************************************************
400 * FUNCTION: acpi_disable_gpe
402 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
403 * gpe_number - GPE level within the GPE block
404 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
409 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
410 * removed, only then is the GPE disabled (for runtime GPEs), or
411 * the GPE mask bit disabled (for wake GPEs)
413 ******************************************************************************/
414 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
416 acpi_status status = AE_OK;
417 struct acpi_gpe_event_info *gpe_event_info;
418 acpi_cpu_flags flags;
420 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
422 /* Parameter validation */
424 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
425 return_ACPI_STATUS(AE_BAD_PARAMETER);
428 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
430 /* Ensure that we have a valid GPE number */
432 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
433 if (!gpe_event_info) {
434 status = AE_BAD_PARAMETER;
435 goto unlock_and_exit;
438 /* Hardware-disable a runtime GPE on removal of the last reference */
440 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
441 if (!gpe_event_info->runtime_count) {
442 status = AE_LIMIT; /* There are no references to remove */
443 goto unlock_and_exit;
446 gpe_event_info->runtime_count--;
447 if (!gpe_event_info->runtime_count) {
448 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
449 if (ACPI_SUCCESS(status)) {
450 status = acpi_hw_low_set_gpe(gpe_event_info,
454 if (ACPI_FAILURE(status)) {
455 gpe_event_info->runtime_count++;
456 goto unlock_and_exit;
462 * Update masks for wake GPE on removal of the last reference.
463 * No need to hardware-disable wake GPEs here, they are not currently
466 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
467 if (!gpe_event_info->wakeup_count) {
468 status = AE_LIMIT; /* There are no references to remove */
469 goto unlock_and_exit;
472 gpe_event_info->wakeup_count--;
473 if (!gpe_event_info->wakeup_count) {
474 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
479 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
480 return_ACPI_STATUS(status);
482 ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
484 /*******************************************************************************
486 * FUNCTION: acpi_disable_event
488 * PARAMETERS: Event - The fixed eventto be enabled
493 * DESCRIPTION: Disable an ACPI event (fixed)
495 ******************************************************************************/
496 acpi_status acpi_disable_event(u32 event, u32 flags)
498 acpi_status status = AE_OK;
501 ACPI_FUNCTION_TRACE(acpi_disable_event);
503 /* Decode the Fixed Event */
505 if (event > ACPI_EVENT_MAX) {
506 return_ACPI_STATUS(AE_BAD_PARAMETER);
510 * Disable the requested fixed event (by writing a zero to the enable
514 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
515 enable_register_id, ACPI_DISABLE_EVENT);
516 if (ACPI_FAILURE(status)) {
517 return_ACPI_STATUS(status);
521 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
522 enable_register_id, &value);
523 if (ACPI_FAILURE(status)) {
524 return_ACPI_STATUS(status);
529 "Could not disable %s events",
530 acpi_ut_get_event_name(event)));
531 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
534 return_ACPI_STATUS(status);
537 ACPI_EXPORT_SYMBOL(acpi_disable_event)
539 /*******************************************************************************
541 * FUNCTION: acpi_clear_event
543 * PARAMETERS: Event - The fixed event to be cleared
547 * DESCRIPTION: Clear an ACPI event (fixed)
549 ******************************************************************************/
550 acpi_status acpi_clear_event(u32 event)
552 acpi_status status = AE_OK;
554 ACPI_FUNCTION_TRACE(acpi_clear_event);
556 /* Decode the Fixed Event */
558 if (event > ACPI_EVENT_MAX) {
559 return_ACPI_STATUS(AE_BAD_PARAMETER);
563 * Clear the requested fixed event (By writing a one to the status
567 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
568 status_register_id, ACPI_CLEAR_STATUS);
570 return_ACPI_STATUS(status);
573 ACPI_EXPORT_SYMBOL(acpi_clear_event)
575 /*******************************************************************************
577 * FUNCTION: acpi_clear_gpe
579 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
580 * gpe_number - GPE level within the GPE block
584 * DESCRIPTION: Clear an ACPI event (general purpose)
586 ******************************************************************************/
587 acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
589 acpi_status status = AE_OK;
590 struct acpi_gpe_event_info *gpe_event_info;
591 acpi_cpu_flags flags;
593 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
595 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
597 /* Ensure that we have a valid GPE number */
599 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
600 if (!gpe_event_info) {
601 status = AE_BAD_PARAMETER;
602 goto unlock_and_exit;
605 status = acpi_hw_clear_gpe(gpe_event_info);
608 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
609 return_ACPI_STATUS(status);
612 ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
613 /*******************************************************************************
615 * FUNCTION: acpi_get_event_status
617 * PARAMETERS: Event - The fixed event
618 * event_status - Where the current status of the event will
623 * DESCRIPTION: Obtains and returns the current status of the event
625 ******************************************************************************/
626 acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
628 acpi_status status = AE_OK;
631 ACPI_FUNCTION_TRACE(acpi_get_event_status);
634 return_ACPI_STATUS(AE_BAD_PARAMETER);
637 /* Decode the Fixed Event */
639 if (event > ACPI_EVENT_MAX) {
640 return_ACPI_STATUS(AE_BAD_PARAMETER);
643 /* Get the status of the requested fixed event */
646 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
647 enable_register_id, &value);
648 if (ACPI_FAILURE(status))
649 return_ACPI_STATUS(status);
651 *event_status = value;
654 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
655 status_register_id, &value);
656 if (ACPI_FAILURE(status))
657 return_ACPI_STATUS(status);
660 *event_status |= ACPI_EVENT_FLAG_SET;
662 if (acpi_gbl_fixed_event_handlers[event].handler)
663 *event_status |= ACPI_EVENT_FLAG_HANDLE;
665 return_ACPI_STATUS(status);
668 ACPI_EXPORT_SYMBOL(acpi_get_event_status)
670 /*******************************************************************************
672 * FUNCTION: acpi_get_gpe_status
674 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
675 * gpe_number - GPE level within the GPE block
676 * event_status - Where the current status of the event will
681 * DESCRIPTION: Get status of an event (general purpose)
683 ******************************************************************************/
685 acpi_get_gpe_status(acpi_handle gpe_device,
686 u32 gpe_number, acpi_event_status *event_status)
688 acpi_status status = AE_OK;
689 struct acpi_gpe_event_info *gpe_event_info;
690 acpi_cpu_flags flags;
692 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
694 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
696 /* Ensure that we have a valid GPE number */
698 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
699 if (!gpe_event_info) {
700 status = AE_BAD_PARAMETER;
701 goto unlock_and_exit;
704 /* Obtain status on the requested GPE number */
706 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
708 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
709 *event_status |= ACPI_EVENT_FLAG_HANDLE;
712 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
713 return_ACPI_STATUS(status);
716 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
717 /*******************************************************************************
719 * FUNCTION: acpi_install_gpe_block
721 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
722 * gpe_block_address - Address and space_iD
723 * register_count - Number of GPE register pairs in the block
724 * interrupt_number - H/W interrupt for the block
728 * DESCRIPTION: Create and Install a block of GPE registers
730 ******************************************************************************/
732 acpi_install_gpe_block(acpi_handle gpe_device,
733 struct acpi_generic_address *gpe_block_address,
734 u32 register_count, u32 interrupt_number)
737 union acpi_operand_object *obj_desc;
738 struct acpi_namespace_node *node;
739 struct acpi_gpe_block_info *gpe_block;
741 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
743 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
744 return_ACPI_STATUS(AE_BAD_PARAMETER);
747 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
748 if (ACPI_FAILURE(status)) {
752 node = acpi_ns_validate_handle(gpe_device);
754 status = AE_BAD_PARAMETER;
755 goto unlock_and_exit;
759 * For user-installed GPE Block Devices, the gpe_block_base_number
763 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
764 interrupt_number, &gpe_block);
765 if (ACPI_FAILURE(status)) {
766 goto unlock_and_exit;
769 /* Install block in the device_object attached to the node */
771 obj_desc = acpi_ns_get_attached_object(node);
775 * No object, create a new one (Device nodes do not always have
776 * an attached object)
778 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
780 status = AE_NO_MEMORY;
781 goto unlock_and_exit;
785 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
787 /* Remove local reference to the object */
789 acpi_ut_remove_reference(obj_desc);
791 if (ACPI_FAILURE(status)) {
792 goto unlock_and_exit;
796 /* Now install the GPE block in the device_object */
798 obj_desc->device.gpe_block = gpe_block;
800 /* Run the _PRW methods and enable the runtime GPEs in the new block */
802 status = acpi_ev_initialize_gpe_block(node, gpe_block);
805 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
806 return_ACPI_STATUS(status);
809 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
811 /*******************************************************************************
813 * FUNCTION: acpi_remove_gpe_block
815 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
819 * DESCRIPTION: Remove a previously installed block of GPE registers
821 ******************************************************************************/
822 acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
824 union acpi_operand_object *obj_desc;
826 struct acpi_namespace_node *node;
828 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
831 return_ACPI_STATUS(AE_BAD_PARAMETER);
834 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
835 if (ACPI_FAILURE(status)) {
839 node = acpi_ns_validate_handle(gpe_device);
841 status = AE_BAD_PARAMETER;
842 goto unlock_and_exit;
845 /* Get the device_object attached to the node */
847 obj_desc = acpi_ns_get_attached_object(node);
848 if (!obj_desc || !obj_desc->device.gpe_block) {
849 return_ACPI_STATUS(AE_NULL_OBJECT);
852 /* Delete the GPE block (but not the device_object) */
854 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
855 if (ACPI_SUCCESS(status)) {
856 obj_desc->device.gpe_block = NULL;
860 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
861 return_ACPI_STATUS(status);
864 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
866 /*******************************************************************************
868 * FUNCTION: acpi_get_gpe_device
870 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
871 * gpe_device - Where the parent GPE Device is returned
875 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
876 * gpe device indicates that the gpe number is contained in one of
877 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
879 ******************************************************************************/
881 acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
883 struct acpi_gpe_device_info info;
886 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
889 return_ACPI_STATUS(AE_BAD_PARAMETER);
892 if (index >= acpi_current_gpe_count) {
893 return_ACPI_STATUS(AE_NOT_EXIST);
896 /* Setup and walk the GPE list */
899 info.status = AE_NOT_EXIST;
900 info.gpe_device = NULL;
901 info.next_block_base_index = 0;
903 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
904 if (ACPI_FAILURE(status)) {
905 return_ACPI_STATUS(status);
908 *gpe_device = info.gpe_device;
909 return_ACPI_STATUS(info.status);
912 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
914 /*******************************************************************************
916 * FUNCTION: acpi_ev_get_gpe_device
918 * PARAMETERS: GPE_WALK_CALLBACK
922 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
923 * block device. NULL if the GPE is one of the FADT-defined GPEs.
925 ******************************************************************************/
927 acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
928 struct acpi_gpe_block_info *gpe_block, void *context)
930 struct acpi_gpe_device_info *info = context;
932 /* Increment Index by the number of GPEs in this block */
934 info->next_block_base_index += gpe_block->gpe_count;
936 if (info->index < info->next_block_base_index) {
938 * The GPE index is within this block, get the node. Leave the node
939 * NULL for the FADT-defined GPEs
941 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
942 info->gpe_device = gpe_block->node;
945 info->status = AE_OK;
946 return (AE_CTRL_END);
952 /******************************************************************************
954 * FUNCTION: acpi_disable_all_gpes
960 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
962 ******************************************************************************/
964 acpi_status acpi_disable_all_gpes(void)
968 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
970 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
971 if (ACPI_FAILURE(status)) {
972 return_ACPI_STATUS(status);
975 status = acpi_hw_disable_all_gpes();
976 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
978 return_ACPI_STATUS(status);
981 /******************************************************************************
983 * FUNCTION: acpi_enable_all_runtime_gpes
989 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
991 ******************************************************************************/
993 acpi_status acpi_enable_all_runtime_gpes(void)
997 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
999 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
1000 if (ACPI_FAILURE(status)) {
1001 return_ACPI_STATUS(status);
1004 status = acpi_hw_enable_all_runtime_gpes();
1005 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1007 return_ACPI_STATUS(status);