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. NULL for GPE0/GPE1
245 * gpe_number - GPE level within the GPE block
246 * action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
250 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
251 * the reference count mechanism used in the acpi_enable_gpe and
252 * acpi_disable_gpe interfaces -- and should be used with care.
254 * Note: Typically used to disable a runtime GPE for short period of time,
255 * then re-enable it, without disturbing the existing reference counts. This
256 * is useful, for example, in the Embedded Controller (EC) driver.
258 ******************************************************************************/
259 acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
261 struct acpi_gpe_event_info *gpe_event_info;
263 acpi_cpu_flags flags;
265 ACPI_FUNCTION_TRACE(acpi_set_gpe);
267 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
269 /* Ensure that we have a valid GPE number */
271 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
272 if (!gpe_event_info) {
273 status = AE_BAD_PARAMETER;
274 goto unlock_and_exit;
277 /* Perform the action */
280 case ACPI_GPE_ENABLE:
281 status = acpi_clear_and_enable_gpe(gpe_event_info);
284 case ACPI_GPE_DISABLE:
285 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
289 status = AE_BAD_PARAMETER;
294 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
295 return_ACPI_STATUS(status);
298 ACPI_EXPORT_SYMBOL(acpi_set_gpe)
300 /*******************************************************************************
302 * FUNCTION: acpi_enable_gpe
304 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
305 * gpe_number - GPE level within the GPE block
306 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
311 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
312 * hardware-enabled (for runtime GPEs), or the GPE register mask
313 * is updated (for wake GPEs).
315 ******************************************************************************/
316 acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
318 acpi_status status = AE_OK;
319 struct acpi_gpe_event_info *gpe_event_info;
320 acpi_cpu_flags flags;
322 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
324 /* Parameter validation */
326 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
327 return_ACPI_STATUS(AE_BAD_PARAMETER);
330 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
332 /* Ensure that we have a valid GPE number */
334 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
335 if (!gpe_event_info) {
336 status = AE_BAD_PARAMETER;
337 goto unlock_and_exit;
340 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
341 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
342 status = AE_LIMIT; /* Too many references */
343 goto unlock_and_exit;
346 gpe_event_info->runtime_count++;
347 if (gpe_event_info->runtime_count == 1) {
348 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
349 if (ACPI_SUCCESS(status)) {
350 status = acpi_clear_and_enable_gpe(gpe_event_info);
353 if (ACPI_FAILURE(status)) {
354 gpe_event_info->runtime_count--;
355 goto unlock_and_exit;
360 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
361 /* The GPE must have the ability to wake the system */
363 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
365 goto unlock_and_exit;
368 if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) {
369 status = AE_LIMIT; /* Too many references */
370 goto unlock_and_exit;
374 * Update the enable mask on the first wakeup reference. Wake GPEs
375 * are only hardware-enabled just before sleeping.
377 gpe_event_info->wakeup_count++;
378 if (gpe_event_info->wakeup_count == 1) {
379 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
384 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
385 return_ACPI_STATUS(status);
387 ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
389 /*******************************************************************************
391 * FUNCTION: acpi_disable_gpe
393 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
394 * gpe_number - GPE level within the GPE block
395 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
400 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
401 * removed, only then is the GPE disabled (for runtime GPEs), or
402 * the GPE mask bit disabled (for wake GPEs)
404 ******************************************************************************/
405 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
407 acpi_status status = AE_OK;
408 struct acpi_gpe_event_info *gpe_event_info;
409 acpi_cpu_flags flags;
411 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
413 /* Parameter validation */
415 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
416 return_ACPI_STATUS(AE_BAD_PARAMETER);
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 /* Hardware-disable a runtime GPE on removal of the last reference */
431 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
432 if (!gpe_event_info->runtime_count) {
433 status = AE_LIMIT; /* There are no references to remove */
434 goto unlock_and_exit;
437 gpe_event_info->runtime_count--;
438 if (!gpe_event_info->runtime_count) {
439 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
440 if (ACPI_SUCCESS(status)) {
441 status = acpi_hw_low_set_gpe(gpe_event_info,
445 if (ACPI_FAILURE(status)) {
446 gpe_event_info->runtime_count++;
447 goto unlock_and_exit;
453 * Update masks for wake GPE on removal of the last reference.
454 * No need to hardware-disable wake GPEs here, they are not currently
457 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
458 if (!gpe_event_info->wakeup_count) {
459 status = AE_LIMIT; /* There are no references to remove */
460 goto unlock_and_exit;
463 gpe_event_info->wakeup_count--;
464 if (!gpe_event_info->wakeup_count) {
465 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
470 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
471 return_ACPI_STATUS(status);
473 ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
475 /*******************************************************************************
477 * FUNCTION: acpi_disable_event
479 * PARAMETERS: Event - The fixed eventto be enabled
484 * DESCRIPTION: Disable an ACPI event (fixed)
486 ******************************************************************************/
487 acpi_status acpi_disable_event(u32 event, u32 flags)
489 acpi_status status = AE_OK;
492 ACPI_FUNCTION_TRACE(acpi_disable_event);
494 /* Decode the Fixed Event */
496 if (event > ACPI_EVENT_MAX) {
497 return_ACPI_STATUS(AE_BAD_PARAMETER);
501 * Disable the requested fixed event (by writing a zero to the enable
505 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
506 enable_register_id, ACPI_DISABLE_EVENT);
507 if (ACPI_FAILURE(status)) {
508 return_ACPI_STATUS(status);
512 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
513 enable_register_id, &value);
514 if (ACPI_FAILURE(status)) {
515 return_ACPI_STATUS(status);
520 "Could not disable %s events",
521 acpi_ut_get_event_name(event)));
522 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
525 return_ACPI_STATUS(status);
528 ACPI_EXPORT_SYMBOL(acpi_disable_event)
530 /*******************************************************************************
532 * FUNCTION: acpi_clear_event
534 * PARAMETERS: Event - The fixed event to be cleared
538 * DESCRIPTION: Clear an ACPI event (fixed)
540 ******************************************************************************/
541 acpi_status acpi_clear_event(u32 event)
543 acpi_status status = AE_OK;
545 ACPI_FUNCTION_TRACE(acpi_clear_event);
547 /* Decode the Fixed Event */
549 if (event > ACPI_EVENT_MAX) {
550 return_ACPI_STATUS(AE_BAD_PARAMETER);
554 * Clear the requested fixed event (By writing a one to the status
558 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
559 status_register_id, ACPI_CLEAR_STATUS);
561 return_ACPI_STATUS(status);
564 ACPI_EXPORT_SYMBOL(acpi_clear_event)
566 /*******************************************************************************
568 * FUNCTION: acpi_clear_gpe
570 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
571 * gpe_number - GPE level within the GPE block
575 * DESCRIPTION: Clear an ACPI event (general purpose)
577 ******************************************************************************/
578 acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
580 acpi_status status = AE_OK;
581 struct acpi_gpe_event_info *gpe_event_info;
582 acpi_cpu_flags flags;
584 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
586 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
588 /* Ensure that we have a valid GPE number */
590 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
591 if (!gpe_event_info) {
592 status = AE_BAD_PARAMETER;
593 goto unlock_and_exit;
596 status = acpi_hw_clear_gpe(gpe_event_info);
599 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
600 return_ACPI_STATUS(status);
603 ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
604 /*******************************************************************************
606 * FUNCTION: acpi_get_event_status
608 * PARAMETERS: Event - The fixed event
609 * event_status - Where the current status of the event will
614 * DESCRIPTION: Obtains and returns the current status of the event
616 ******************************************************************************/
617 acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
619 acpi_status status = AE_OK;
622 ACPI_FUNCTION_TRACE(acpi_get_event_status);
625 return_ACPI_STATUS(AE_BAD_PARAMETER);
628 /* Decode the Fixed Event */
630 if (event > ACPI_EVENT_MAX) {
631 return_ACPI_STATUS(AE_BAD_PARAMETER);
634 /* Get the status of the requested fixed event */
637 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
638 enable_register_id, &value);
639 if (ACPI_FAILURE(status))
640 return_ACPI_STATUS(status);
642 *event_status = value;
645 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
646 status_register_id, &value);
647 if (ACPI_FAILURE(status))
648 return_ACPI_STATUS(status);
651 *event_status |= ACPI_EVENT_FLAG_SET;
653 if (acpi_gbl_fixed_event_handlers[event].handler)
654 *event_status |= ACPI_EVENT_FLAG_HANDLE;
656 return_ACPI_STATUS(status);
659 ACPI_EXPORT_SYMBOL(acpi_get_event_status)
661 /*******************************************************************************
663 * FUNCTION: acpi_get_gpe_status
665 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
666 * gpe_number - GPE level within the GPE block
667 * event_status - Where the current status of the event will
672 * DESCRIPTION: Get status of an event (general purpose)
674 ******************************************************************************/
676 acpi_get_gpe_status(acpi_handle gpe_device,
677 u32 gpe_number, acpi_event_status *event_status)
679 acpi_status status = AE_OK;
680 struct acpi_gpe_event_info *gpe_event_info;
681 acpi_cpu_flags flags;
683 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
685 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
687 /* Ensure that we have a valid GPE number */
689 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
690 if (!gpe_event_info) {
691 status = AE_BAD_PARAMETER;
692 goto unlock_and_exit;
695 /* Obtain status on the requested GPE number */
697 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
699 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
700 *event_status |= ACPI_EVENT_FLAG_HANDLE;
703 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
704 return_ACPI_STATUS(status);
707 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
708 /*******************************************************************************
710 * FUNCTION: acpi_install_gpe_block
712 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
713 * gpe_block_address - Address and space_iD
714 * register_count - Number of GPE register pairs in the block
715 * interrupt_number - H/W interrupt for the block
719 * DESCRIPTION: Create and Install a block of GPE registers
721 ******************************************************************************/
723 acpi_install_gpe_block(acpi_handle gpe_device,
724 struct acpi_generic_address *gpe_block_address,
725 u32 register_count, u32 interrupt_number)
728 union acpi_operand_object *obj_desc;
729 struct acpi_namespace_node *node;
730 struct acpi_gpe_block_info *gpe_block;
732 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
734 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
735 return_ACPI_STATUS(AE_BAD_PARAMETER);
738 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
739 if (ACPI_FAILURE(status)) {
743 node = acpi_ns_validate_handle(gpe_device);
745 status = AE_BAD_PARAMETER;
746 goto unlock_and_exit;
750 * For user-installed GPE Block Devices, the gpe_block_base_number
754 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
755 interrupt_number, &gpe_block);
756 if (ACPI_FAILURE(status)) {
757 goto unlock_and_exit;
760 /* Install block in the device_object attached to the node */
762 obj_desc = acpi_ns_get_attached_object(node);
766 * No object, create a new one (Device nodes do not always have
767 * an attached object)
769 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
771 status = AE_NO_MEMORY;
772 goto unlock_and_exit;
776 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
778 /* Remove local reference to the object */
780 acpi_ut_remove_reference(obj_desc);
782 if (ACPI_FAILURE(status)) {
783 goto unlock_and_exit;
787 /* Now install the GPE block in the device_object */
789 obj_desc->device.gpe_block = gpe_block;
791 /* Run the _PRW methods and enable the runtime GPEs in the new block */
793 status = acpi_ev_initialize_gpe_block(node, gpe_block);
796 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
797 return_ACPI_STATUS(status);
800 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
802 /*******************************************************************************
804 * FUNCTION: acpi_remove_gpe_block
806 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
810 * DESCRIPTION: Remove a previously installed block of GPE registers
812 ******************************************************************************/
813 acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
815 union acpi_operand_object *obj_desc;
817 struct acpi_namespace_node *node;
819 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
822 return_ACPI_STATUS(AE_BAD_PARAMETER);
825 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
826 if (ACPI_FAILURE(status)) {
830 node = acpi_ns_validate_handle(gpe_device);
832 status = AE_BAD_PARAMETER;
833 goto unlock_and_exit;
836 /* Get the device_object attached to the node */
838 obj_desc = acpi_ns_get_attached_object(node);
839 if (!obj_desc || !obj_desc->device.gpe_block) {
840 return_ACPI_STATUS(AE_NULL_OBJECT);
843 /* Delete the GPE block (but not the device_object) */
845 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
846 if (ACPI_SUCCESS(status)) {
847 obj_desc->device.gpe_block = NULL;
851 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
852 return_ACPI_STATUS(status);
855 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
857 /*******************************************************************************
859 * FUNCTION: acpi_get_gpe_device
861 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
862 * gpe_device - Where the parent GPE Device is returned
866 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
867 * gpe device indicates that the gpe number is contained in one of
868 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
870 ******************************************************************************/
872 acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
874 struct acpi_gpe_device_info info;
877 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
880 return_ACPI_STATUS(AE_BAD_PARAMETER);
883 if (index >= acpi_current_gpe_count) {
884 return_ACPI_STATUS(AE_NOT_EXIST);
887 /* Setup and walk the GPE list */
890 info.status = AE_NOT_EXIST;
891 info.gpe_device = NULL;
892 info.next_block_base_index = 0;
894 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
895 if (ACPI_FAILURE(status)) {
896 return_ACPI_STATUS(status);
899 *gpe_device = info.gpe_device;
900 return_ACPI_STATUS(info.status);
903 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
905 /*******************************************************************************
907 * FUNCTION: acpi_ev_get_gpe_device
909 * PARAMETERS: GPE_WALK_CALLBACK
913 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
914 * block device. NULL if the GPE is one of the FADT-defined GPEs.
916 ******************************************************************************/
918 acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
919 struct acpi_gpe_block_info *gpe_block, void *context)
921 struct acpi_gpe_device_info *info = context;
923 /* Increment Index by the number of GPEs in this block */
925 info->next_block_base_index += gpe_block->gpe_count;
927 if (info->index < info->next_block_base_index) {
929 * The GPE index is within this block, get the node. Leave the node
930 * NULL for the FADT-defined GPEs
932 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
933 info->gpe_device = gpe_block->node;
936 info->status = AE_OK;
937 return (AE_CTRL_END);
943 /******************************************************************************
945 * FUNCTION: acpi_disable_all_gpes
951 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
953 ******************************************************************************/
955 acpi_status acpi_disable_all_gpes(void)
959 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
961 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
962 if (ACPI_FAILURE(status)) {
963 return_ACPI_STATUS(status);
966 status = acpi_hw_disable_all_gpes();
967 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
969 return_ACPI_STATUS(status);
972 /******************************************************************************
974 * FUNCTION: acpi_enable_all_runtime_gpes
980 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
982 ******************************************************************************/
984 acpi_status acpi_enable_all_runtime_gpes(void)
988 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
990 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
991 if (ACPI_FAILURE(status)) {
992 return_ACPI_STATUS(status);
995 status = acpi_hw_enable_all_runtime_gpes();
996 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
998 return_ACPI_STATUS(status);