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, register_bit);
358 case ACPI_GPE_DISABLE:
359 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
364 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
365 status = AE_BAD_PARAMETER;
370 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
371 return_ACPI_STATUS(status);
374 ACPI_EXPORT_SYMBOL(acpi_gpe_wakeup)
376 /*******************************************************************************
378 * FUNCTION: acpi_enable_gpe
380 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
381 * gpe_number - GPE level within the GPE block
382 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
387 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
388 * hardware-enabled (for runtime GPEs), or the GPE register mask
389 * is updated (for wake GPEs).
391 ******************************************************************************/
392 acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
394 acpi_status status = AE_OK;
395 struct acpi_gpe_event_info *gpe_event_info;
396 acpi_cpu_flags flags;
398 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
400 /* Parameter validation */
402 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
403 return_ACPI_STATUS(AE_BAD_PARAMETER);
406 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
408 /* Ensure that we have a valid GPE number */
410 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
411 if (!gpe_event_info) {
412 status = AE_BAD_PARAMETER;
413 goto unlock_and_exit;
416 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
417 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
418 status = AE_LIMIT; /* Too many references */
419 goto unlock_and_exit;
422 gpe_event_info->runtime_count++;
423 if (gpe_event_info->runtime_count == 1) {
424 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
425 if (ACPI_SUCCESS(status)) {
426 status = acpi_clear_and_enable_gpe(gpe_event_info);
429 if (ACPI_FAILURE(status)) {
430 gpe_event_info->runtime_count--;
431 goto unlock_and_exit;
436 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
437 /* The GPE must have the ability to wake the system */
439 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
441 goto unlock_and_exit;
444 if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) {
445 status = AE_LIMIT; /* Too many references */
446 goto unlock_and_exit;
450 * Update the enable mask on the first wakeup reference. Wake GPEs
451 * are only hardware-enabled just before sleeping.
453 gpe_event_info->wakeup_count++;
454 if (gpe_event_info->wakeup_count == 1) {
455 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
460 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
461 return_ACPI_STATUS(status);
463 ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
465 /*******************************************************************************
467 * FUNCTION: acpi_disable_gpe
469 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
470 * gpe_number - GPE level within the GPE block
471 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
476 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
477 * removed, only then is the GPE disabled (for runtime GPEs), or
478 * the GPE mask bit disabled (for wake GPEs)
480 ******************************************************************************/
481 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
483 acpi_status status = AE_OK;
484 struct acpi_gpe_event_info *gpe_event_info;
485 acpi_cpu_flags flags;
487 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
489 /* Parameter validation */
491 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
492 return_ACPI_STATUS(AE_BAD_PARAMETER);
495 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
497 /* Ensure that we have a valid GPE number */
499 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
500 if (!gpe_event_info) {
501 status = AE_BAD_PARAMETER;
502 goto unlock_and_exit;
505 /* Hardware-disable a runtime GPE on removal of the last reference */
507 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
508 if (!gpe_event_info->runtime_count) {
509 status = AE_LIMIT; /* There are no references to remove */
510 goto unlock_and_exit;
513 gpe_event_info->runtime_count--;
514 if (!gpe_event_info->runtime_count) {
515 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
516 if (ACPI_SUCCESS(status)) {
517 status = acpi_hw_low_set_gpe(gpe_event_info,
521 if (ACPI_FAILURE(status)) {
522 gpe_event_info->runtime_count++;
523 goto unlock_and_exit;
529 * Update masks for wake GPE on removal of the last reference.
530 * No need to hardware-disable wake GPEs here, they are not currently
533 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
534 if (!gpe_event_info->wakeup_count) {
535 status = AE_LIMIT; /* There are no references to remove */
536 goto unlock_and_exit;
539 gpe_event_info->wakeup_count--;
540 if (!gpe_event_info->wakeup_count) {
541 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
546 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
547 return_ACPI_STATUS(status);
549 ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
551 /*******************************************************************************
553 * FUNCTION: acpi_disable_event
555 * PARAMETERS: Event - The fixed eventto be enabled
560 * DESCRIPTION: Disable an ACPI event (fixed)
562 ******************************************************************************/
563 acpi_status acpi_disable_event(u32 event, u32 flags)
565 acpi_status status = AE_OK;
568 ACPI_FUNCTION_TRACE(acpi_disable_event);
570 /* Decode the Fixed Event */
572 if (event > ACPI_EVENT_MAX) {
573 return_ACPI_STATUS(AE_BAD_PARAMETER);
577 * Disable the requested fixed event (by writing a zero to the enable
581 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
582 enable_register_id, ACPI_DISABLE_EVENT);
583 if (ACPI_FAILURE(status)) {
584 return_ACPI_STATUS(status);
588 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
589 enable_register_id, &value);
590 if (ACPI_FAILURE(status)) {
591 return_ACPI_STATUS(status);
596 "Could not disable %s events",
597 acpi_ut_get_event_name(event)));
598 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
601 return_ACPI_STATUS(status);
604 ACPI_EXPORT_SYMBOL(acpi_disable_event)
606 /*******************************************************************************
608 * FUNCTION: acpi_clear_event
610 * PARAMETERS: Event - The fixed event to be cleared
614 * DESCRIPTION: Clear an ACPI event (fixed)
616 ******************************************************************************/
617 acpi_status acpi_clear_event(u32 event)
619 acpi_status status = AE_OK;
621 ACPI_FUNCTION_TRACE(acpi_clear_event);
623 /* Decode the Fixed Event */
625 if (event > ACPI_EVENT_MAX) {
626 return_ACPI_STATUS(AE_BAD_PARAMETER);
630 * Clear the requested fixed event (By writing a one to the status
634 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
635 status_register_id, ACPI_CLEAR_STATUS);
637 return_ACPI_STATUS(status);
640 ACPI_EXPORT_SYMBOL(acpi_clear_event)
642 /*******************************************************************************
644 * FUNCTION: acpi_clear_gpe
646 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
647 * gpe_number - GPE level within the GPE block
651 * DESCRIPTION: Clear an ACPI event (general purpose)
653 ******************************************************************************/
654 acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
656 acpi_status status = AE_OK;
657 struct acpi_gpe_event_info *gpe_event_info;
658 acpi_cpu_flags flags;
660 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
662 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
664 /* Ensure that we have a valid GPE number */
666 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
667 if (!gpe_event_info) {
668 status = AE_BAD_PARAMETER;
669 goto unlock_and_exit;
672 status = acpi_hw_clear_gpe(gpe_event_info);
675 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
676 return_ACPI_STATUS(status);
679 ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
680 /*******************************************************************************
682 * FUNCTION: acpi_get_event_status
684 * PARAMETERS: Event - The fixed event
685 * event_status - Where the current status of the event will
690 * DESCRIPTION: Obtains and returns the current status of the event
692 ******************************************************************************/
693 acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
695 acpi_status status = AE_OK;
698 ACPI_FUNCTION_TRACE(acpi_get_event_status);
701 return_ACPI_STATUS(AE_BAD_PARAMETER);
704 /* Decode the Fixed Event */
706 if (event > ACPI_EVENT_MAX) {
707 return_ACPI_STATUS(AE_BAD_PARAMETER);
710 /* Get the status of the requested fixed event */
713 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
714 enable_register_id, &value);
715 if (ACPI_FAILURE(status))
716 return_ACPI_STATUS(status);
718 *event_status = value;
721 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
722 status_register_id, &value);
723 if (ACPI_FAILURE(status))
724 return_ACPI_STATUS(status);
727 *event_status |= ACPI_EVENT_FLAG_SET;
729 if (acpi_gbl_fixed_event_handlers[event].handler)
730 *event_status |= ACPI_EVENT_FLAG_HANDLE;
732 return_ACPI_STATUS(status);
735 ACPI_EXPORT_SYMBOL(acpi_get_event_status)
737 /*******************************************************************************
739 * FUNCTION: acpi_get_gpe_status
741 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
742 * gpe_number - GPE level within the GPE block
743 * event_status - Where the current status of the event will
748 * DESCRIPTION: Get status of an event (general purpose)
750 ******************************************************************************/
752 acpi_get_gpe_status(acpi_handle gpe_device,
753 u32 gpe_number, acpi_event_status *event_status)
755 acpi_status status = AE_OK;
756 struct acpi_gpe_event_info *gpe_event_info;
757 acpi_cpu_flags flags;
759 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
761 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
763 /* Ensure that we have a valid GPE number */
765 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
766 if (!gpe_event_info) {
767 status = AE_BAD_PARAMETER;
768 goto unlock_and_exit;
771 /* Obtain status on the requested GPE number */
773 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
775 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
776 *event_status |= ACPI_EVENT_FLAG_HANDLE;
779 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
780 return_ACPI_STATUS(status);
783 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
784 /*******************************************************************************
786 * FUNCTION: acpi_install_gpe_block
788 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
789 * gpe_block_address - Address and space_iD
790 * register_count - Number of GPE register pairs in the block
791 * interrupt_number - H/W interrupt for the block
795 * DESCRIPTION: Create and Install a block of GPE registers
797 ******************************************************************************/
799 acpi_install_gpe_block(acpi_handle gpe_device,
800 struct acpi_generic_address *gpe_block_address,
801 u32 register_count, u32 interrupt_number)
804 union acpi_operand_object *obj_desc;
805 struct acpi_namespace_node *node;
806 struct acpi_gpe_block_info *gpe_block;
808 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
810 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
811 return_ACPI_STATUS(AE_BAD_PARAMETER);
814 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
815 if (ACPI_FAILURE(status)) {
819 node = acpi_ns_validate_handle(gpe_device);
821 status = AE_BAD_PARAMETER;
822 goto unlock_and_exit;
826 * For user-installed GPE Block Devices, the gpe_block_base_number
830 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
831 interrupt_number, &gpe_block);
832 if (ACPI_FAILURE(status)) {
833 goto unlock_and_exit;
836 /* Install block in the device_object attached to the node */
838 obj_desc = acpi_ns_get_attached_object(node);
842 * No object, create a new one (Device nodes do not always have
843 * an attached object)
845 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
847 status = AE_NO_MEMORY;
848 goto unlock_and_exit;
852 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
854 /* Remove local reference to the object */
856 acpi_ut_remove_reference(obj_desc);
858 if (ACPI_FAILURE(status)) {
859 goto unlock_and_exit;
863 /* Now install the GPE block in the device_object */
865 obj_desc->device.gpe_block = gpe_block;
867 /* Run the _PRW methods and enable the runtime GPEs in the new block */
869 status = acpi_ev_initialize_gpe_block(node, gpe_block);
872 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
873 return_ACPI_STATUS(status);
876 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
878 /*******************************************************************************
880 * FUNCTION: acpi_remove_gpe_block
882 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
886 * DESCRIPTION: Remove a previously installed block of GPE registers
888 ******************************************************************************/
889 acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
891 union acpi_operand_object *obj_desc;
893 struct acpi_namespace_node *node;
895 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
898 return_ACPI_STATUS(AE_BAD_PARAMETER);
901 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
902 if (ACPI_FAILURE(status)) {
906 node = acpi_ns_validate_handle(gpe_device);
908 status = AE_BAD_PARAMETER;
909 goto unlock_and_exit;
912 /* Get the device_object attached to the node */
914 obj_desc = acpi_ns_get_attached_object(node);
915 if (!obj_desc || !obj_desc->device.gpe_block) {
916 return_ACPI_STATUS(AE_NULL_OBJECT);
919 /* Delete the GPE block (but not the device_object) */
921 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
922 if (ACPI_SUCCESS(status)) {
923 obj_desc->device.gpe_block = NULL;
927 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
928 return_ACPI_STATUS(status);
931 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
933 /*******************************************************************************
935 * FUNCTION: acpi_get_gpe_device
937 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
938 * gpe_device - Where the parent GPE Device is returned
942 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
943 * gpe device indicates that the gpe number is contained in one of
944 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
946 ******************************************************************************/
948 acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
950 struct acpi_gpe_device_info info;
953 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
956 return_ACPI_STATUS(AE_BAD_PARAMETER);
959 if (index >= acpi_current_gpe_count) {
960 return_ACPI_STATUS(AE_NOT_EXIST);
963 /* Setup and walk the GPE list */
966 info.status = AE_NOT_EXIST;
967 info.gpe_device = NULL;
968 info.next_block_base_index = 0;
970 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
971 if (ACPI_FAILURE(status)) {
972 return_ACPI_STATUS(status);
975 *gpe_device = info.gpe_device;
976 return_ACPI_STATUS(info.status);
979 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
981 /*******************************************************************************
983 * FUNCTION: acpi_ev_get_gpe_device
985 * PARAMETERS: GPE_WALK_CALLBACK
989 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
990 * block device. NULL if the GPE is one of the FADT-defined GPEs.
992 ******************************************************************************/
994 acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
995 struct acpi_gpe_block_info *gpe_block, void *context)
997 struct acpi_gpe_device_info *info = context;
999 /* Increment Index by the number of GPEs in this block */
1001 info->next_block_base_index += gpe_block->gpe_count;
1003 if (info->index < info->next_block_base_index) {
1005 * The GPE index is within this block, get the node. Leave the node
1006 * NULL for the FADT-defined GPEs
1008 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
1009 info->gpe_device = gpe_block->node;
1012 info->status = AE_OK;
1013 return (AE_CTRL_END);
1019 /******************************************************************************
1021 * FUNCTION: acpi_disable_all_gpes
1027 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
1029 ******************************************************************************/
1031 acpi_status acpi_disable_all_gpes(void)
1035 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
1037 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
1038 if (ACPI_FAILURE(status)) {
1039 return_ACPI_STATUS(status);
1042 status = acpi_hw_disable_all_gpes();
1043 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1045 return_ACPI_STATUS(status);
1048 /******************************************************************************
1050 * FUNCTION: acpi_enable_all_runtime_gpes
1056 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
1058 ******************************************************************************/
1060 acpi_status acpi_enable_all_runtime_gpes(void)
1064 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
1066 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
1067 if (ACPI_FAILURE(status)) {
1068 return_ACPI_STATUS(status);
1071 status = acpi_hw_enable_all_runtime_gpes();
1072 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1074 return_ACPI_STATUS(status);