Merge branch 'for-linus' of git://oss.sgi.com/xfs/xfs
[linux/fpc-iii.git] / drivers / acpi / acpica / evxfevnt.c
blobd5a5efc043bf7a43ac446c815370576deaa5b096
1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2010, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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>
45 #include "accommon.h"
46 #include "acevents.h"
47 #include "acnamesp.h"
48 #include "actables.h"
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME("evxfevnt")
53 /* Local prototypes */
54 static acpi_status
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
62 * PARAMETERS: None
64 * RETURN: Status
66 * DESCRIPTION: Transfers the system into ACPI mode.
68 ******************************************************************************/
70 acpi_status acpi_enable(void)
72 acpi_status status;
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)) {
94 ACPI_ERROR((AE_INFO,
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) {
102 ACPI_ERROR((AE_INFO,
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
119 * PARAMETERS: None
121 * RETURN: Status
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"));
135 } else {
136 /* Transition to LEGACY mode */
138 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
140 if (ACPI_FAILURE(status)) {
141 ACPI_ERROR((AE_INFO,
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
159 * Flags - Reserved
161 * RETURN: Status
163 * DESCRIPTION: Enable an ACPI event (fixed)
165 ******************************************************************************/
166 acpi_status acpi_enable_event(u32 event, u32 flags)
168 acpi_status status = AE_OK;
169 u32 value;
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
181 * register bit)
183 status =
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 */
192 status =
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);
199 if (value != 1) {
200 ACPI_ERROR((AE_INFO,
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_set_gpe
215 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
216 * gpe_number - GPE level within the GPE block
217 * action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
219 * RETURN: Status
221 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
222 * the reference count mechanism used in the acpi_enable_gpe and
223 * acpi_disable_gpe interfaces -- and should be used with care.
225 * Note: Typically used to disable a runtime GPE for short period of time,
226 * then re-enable it, without disturbing the existing reference counts. This
227 * is useful, for example, in the Embedded Controller (EC) driver.
229 ******************************************************************************/
230 acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
232 struct acpi_gpe_event_info *gpe_event_info;
233 acpi_status status;
234 acpi_cpu_flags flags;
236 ACPI_FUNCTION_TRACE(acpi_set_gpe);
238 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
240 /* Ensure that we have a valid GPE number */
242 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
243 if (!gpe_event_info) {
244 status = AE_BAD_PARAMETER;
245 goto unlock_and_exit;
248 /* Perform the action */
250 switch (action) {
251 case ACPI_GPE_ENABLE:
252 status = acpi_ev_enable_gpe(gpe_event_info);
253 break;
255 case ACPI_GPE_DISABLE:
256 status = acpi_ev_disable_gpe(gpe_event_info);
257 break;
259 default:
260 status = AE_BAD_PARAMETER;
261 break;
264 unlock_and_exit:
265 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
266 return_ACPI_STATUS(status);
269 ACPI_EXPORT_SYMBOL(acpi_set_gpe)
271 /*******************************************************************************
273 * FUNCTION: acpi_enable_gpe
275 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
276 * gpe_number - GPE level within the GPE block
277 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
278 * or both
280 * RETURN: Status
282 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
283 * hardware-enabled (for runtime GPEs), or the GPE register mask
284 * is updated (for wake GPEs).
286 ******************************************************************************/
287 acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
289 acpi_status status = AE_OK;
290 struct acpi_gpe_event_info *gpe_event_info;
291 acpi_cpu_flags flags;
293 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
295 /* Parameter validation */
297 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
298 return_ACPI_STATUS(AE_BAD_PARAMETER);
301 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
303 /* Ensure that we have a valid GPE number */
305 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
306 if (!gpe_event_info) {
307 status = AE_BAD_PARAMETER;
308 goto unlock_and_exit;
311 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
312 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
313 status = AE_LIMIT; /* Too many references */
314 goto unlock_and_exit;
317 gpe_event_info->runtime_count++;
318 if (gpe_event_info->runtime_count == 1) {
319 status = acpi_ev_enable_gpe(gpe_event_info);
320 if (ACPI_FAILURE(status)) {
321 gpe_event_info->runtime_count--;
322 goto unlock_and_exit;
327 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
328 /* The GPE must have the ability to wake the system */
330 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
331 status = AE_TYPE;
332 goto unlock_and_exit;
335 if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) {
336 status = AE_LIMIT; /* Too many references */
337 goto unlock_and_exit;
341 * Update the enable mask on the first wakeup reference. Wake GPEs
342 * are only hardware-enabled just before sleeping.
344 gpe_event_info->wakeup_count++;
345 if (gpe_event_info->wakeup_count == 1) {
346 (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
350 unlock_and_exit:
351 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
352 return_ACPI_STATUS(status);
354 ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
356 /*******************************************************************************
358 * FUNCTION: acpi_disable_gpe
360 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
361 * gpe_number - GPE level within the GPE block
362 * gpe_type - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
363 * or both
365 * RETURN: Status
367 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
368 * removed, only then is the GPE disabled (for runtime GPEs), or
369 * the GPE mask bit disabled (for wake GPEs)
371 ******************************************************************************/
372 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
374 acpi_status status = AE_OK;
375 struct acpi_gpe_event_info *gpe_event_info;
376 acpi_cpu_flags flags;
378 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
380 /* Parameter validation */
382 if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
383 return_ACPI_STATUS(AE_BAD_PARAMETER);
386 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
388 /* Ensure that we have a valid GPE number */
390 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
391 if (!gpe_event_info) {
392 status = AE_BAD_PARAMETER;
393 goto unlock_and_exit;
396 /* Hardware-disable a runtime GPE on removal of the last reference */
398 if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
399 if (!gpe_event_info->runtime_count) {
400 status = AE_LIMIT; /* There are no references to remove */
401 goto unlock_and_exit;
404 gpe_event_info->runtime_count--;
405 if (!gpe_event_info->runtime_count) {
406 status = acpi_ev_disable_gpe(gpe_event_info);
407 if (ACPI_FAILURE(status)) {
408 gpe_event_info->runtime_count++;
409 goto unlock_and_exit;
415 * Update masks for wake GPE on removal of the last reference.
416 * No need to hardware-disable wake GPEs here, they are not currently
417 * enabled.
419 if (gpe_type & ACPI_GPE_TYPE_WAKE) {
420 if (!gpe_event_info->wakeup_count) {
421 status = AE_LIMIT; /* There are no references to remove */
422 goto unlock_and_exit;
425 gpe_event_info->wakeup_count--;
426 if (!gpe_event_info->wakeup_count) {
427 (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
431 unlock_and_exit:
432 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
433 return_ACPI_STATUS(status);
435 ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
437 /*******************************************************************************
439 * FUNCTION: acpi_disable_event
441 * PARAMETERS: Event - The fixed eventto be enabled
442 * Flags - Reserved
444 * RETURN: Status
446 * DESCRIPTION: Disable an ACPI event (fixed)
448 ******************************************************************************/
449 acpi_status acpi_disable_event(u32 event, u32 flags)
451 acpi_status status = AE_OK;
452 u32 value;
454 ACPI_FUNCTION_TRACE(acpi_disable_event);
456 /* Decode the Fixed Event */
458 if (event > ACPI_EVENT_MAX) {
459 return_ACPI_STATUS(AE_BAD_PARAMETER);
463 * Disable the requested fixed event (by writing a zero to the enable
464 * register bit)
466 status =
467 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
468 enable_register_id, ACPI_DISABLE_EVENT);
469 if (ACPI_FAILURE(status)) {
470 return_ACPI_STATUS(status);
473 status =
474 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
475 enable_register_id, &value);
476 if (ACPI_FAILURE(status)) {
477 return_ACPI_STATUS(status);
480 if (value != 0) {
481 ACPI_ERROR((AE_INFO,
482 "Could not disable %s events",
483 acpi_ut_get_event_name(event)));
484 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
487 return_ACPI_STATUS(status);
490 ACPI_EXPORT_SYMBOL(acpi_disable_event)
492 /*******************************************************************************
494 * FUNCTION: acpi_clear_event
496 * PARAMETERS: Event - The fixed event to be cleared
498 * RETURN: Status
500 * DESCRIPTION: Clear an ACPI event (fixed)
502 ******************************************************************************/
503 acpi_status acpi_clear_event(u32 event)
505 acpi_status status = AE_OK;
507 ACPI_FUNCTION_TRACE(acpi_clear_event);
509 /* Decode the Fixed Event */
511 if (event > ACPI_EVENT_MAX) {
512 return_ACPI_STATUS(AE_BAD_PARAMETER);
516 * Clear the requested fixed event (By writing a one to the status
517 * register bit)
519 status =
520 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
521 status_register_id, ACPI_CLEAR_STATUS);
523 return_ACPI_STATUS(status);
526 ACPI_EXPORT_SYMBOL(acpi_clear_event)
528 /*******************************************************************************
530 * FUNCTION: acpi_clear_gpe
532 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
533 * gpe_number - GPE level within the GPE block
535 * RETURN: Status
537 * DESCRIPTION: Clear an ACPI event (general purpose)
539 ******************************************************************************/
540 acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
542 acpi_status status = AE_OK;
543 struct acpi_gpe_event_info *gpe_event_info;
544 acpi_cpu_flags flags;
546 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
548 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
550 /* Ensure that we have a valid GPE number */
552 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
553 if (!gpe_event_info) {
554 status = AE_BAD_PARAMETER;
555 goto unlock_and_exit;
558 status = acpi_hw_clear_gpe(gpe_event_info);
560 unlock_and_exit:
561 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
562 return_ACPI_STATUS(status);
565 ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
566 /*******************************************************************************
568 * FUNCTION: acpi_get_event_status
570 * PARAMETERS: Event - The fixed event
571 * event_status - Where the current status of the event will
572 * be returned
574 * RETURN: Status
576 * DESCRIPTION: Obtains and returns the current status of the event
578 ******************************************************************************/
579 acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
581 acpi_status status = AE_OK;
582 u32 value;
584 ACPI_FUNCTION_TRACE(acpi_get_event_status);
586 if (!event_status) {
587 return_ACPI_STATUS(AE_BAD_PARAMETER);
590 /* Decode the Fixed Event */
592 if (event > ACPI_EVENT_MAX) {
593 return_ACPI_STATUS(AE_BAD_PARAMETER);
596 /* Get the status of the requested fixed event */
598 status =
599 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
600 enable_register_id, &value);
601 if (ACPI_FAILURE(status))
602 return_ACPI_STATUS(status);
604 *event_status = value;
606 status =
607 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
608 status_register_id, &value);
609 if (ACPI_FAILURE(status))
610 return_ACPI_STATUS(status);
612 if (value)
613 *event_status |= ACPI_EVENT_FLAG_SET;
615 if (acpi_gbl_fixed_event_handlers[event].handler)
616 *event_status |= ACPI_EVENT_FLAG_HANDLE;
618 return_ACPI_STATUS(status);
621 ACPI_EXPORT_SYMBOL(acpi_get_event_status)
623 /*******************************************************************************
625 * FUNCTION: acpi_get_gpe_status
627 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
628 * gpe_number - GPE level within the GPE block
629 * event_status - Where the current status of the event will
630 * be returned
632 * RETURN: Status
634 * DESCRIPTION: Get status of an event (general purpose)
636 ******************************************************************************/
637 acpi_status
638 acpi_get_gpe_status(acpi_handle gpe_device,
639 u32 gpe_number, acpi_event_status *event_status)
641 acpi_status status = AE_OK;
642 struct acpi_gpe_event_info *gpe_event_info;
643 acpi_cpu_flags flags;
645 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
647 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
649 /* Ensure that we have a valid GPE number */
651 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
652 if (!gpe_event_info) {
653 status = AE_BAD_PARAMETER;
654 goto unlock_and_exit;
657 /* Obtain status on the requested GPE number */
659 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
661 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
662 *event_status |= ACPI_EVENT_FLAG_HANDLE;
664 unlock_and_exit:
665 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
666 return_ACPI_STATUS(status);
669 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
670 /*******************************************************************************
672 * FUNCTION: acpi_install_gpe_block
674 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
675 * gpe_block_address - Address and space_iD
676 * register_count - Number of GPE register pairs in the block
677 * interrupt_number - H/W interrupt for the block
679 * RETURN: Status
681 * DESCRIPTION: Create and Install a block of GPE registers
683 ******************************************************************************/
684 acpi_status
685 acpi_install_gpe_block(acpi_handle gpe_device,
686 struct acpi_generic_address *gpe_block_address,
687 u32 register_count, u32 interrupt_number)
689 acpi_status status;
690 union acpi_operand_object *obj_desc;
691 struct acpi_namespace_node *node;
692 struct acpi_gpe_block_info *gpe_block;
694 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
696 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
697 return_ACPI_STATUS(AE_BAD_PARAMETER);
700 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
701 if (ACPI_FAILURE(status)) {
702 return (status);
705 node = acpi_ns_validate_handle(gpe_device);
706 if (!node) {
707 status = AE_BAD_PARAMETER;
708 goto unlock_and_exit;
712 * For user-installed GPE Block Devices, the gpe_block_base_number
713 * is always zero
715 status =
716 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
717 interrupt_number, &gpe_block);
718 if (ACPI_FAILURE(status)) {
719 goto unlock_and_exit;
722 /* Install block in the device_object attached to the node */
724 obj_desc = acpi_ns_get_attached_object(node);
725 if (!obj_desc) {
728 * No object, create a new one (Device nodes do not always have
729 * an attached object)
731 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
732 if (!obj_desc) {
733 status = AE_NO_MEMORY;
734 goto unlock_and_exit;
737 status =
738 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
740 /* Remove local reference to the object */
742 acpi_ut_remove_reference(obj_desc);
744 if (ACPI_FAILURE(status)) {
745 goto unlock_and_exit;
749 /* Now install the GPE block in the device_object */
751 obj_desc->device.gpe_block = gpe_block;
753 /* Run the _PRW methods and enable the runtime GPEs in the new block */
755 status = acpi_ev_initialize_gpe_block(node, gpe_block);
757 unlock_and_exit:
758 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
759 return_ACPI_STATUS(status);
762 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
764 /*******************************************************************************
766 * FUNCTION: acpi_remove_gpe_block
768 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
770 * RETURN: Status
772 * DESCRIPTION: Remove a previously installed block of GPE registers
774 ******************************************************************************/
775 acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
777 union acpi_operand_object *obj_desc;
778 acpi_status status;
779 struct acpi_namespace_node *node;
781 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
783 if (!gpe_device) {
784 return_ACPI_STATUS(AE_BAD_PARAMETER);
787 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
788 if (ACPI_FAILURE(status)) {
789 return (status);
792 node = acpi_ns_validate_handle(gpe_device);
793 if (!node) {
794 status = AE_BAD_PARAMETER;
795 goto unlock_and_exit;
798 /* Get the device_object attached to the node */
800 obj_desc = acpi_ns_get_attached_object(node);
801 if (!obj_desc || !obj_desc->device.gpe_block) {
802 return_ACPI_STATUS(AE_NULL_OBJECT);
805 /* Delete the GPE block (but not the device_object) */
807 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
808 if (ACPI_SUCCESS(status)) {
809 obj_desc->device.gpe_block = NULL;
812 unlock_and_exit:
813 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
814 return_ACPI_STATUS(status);
817 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
819 /*******************************************************************************
821 * FUNCTION: acpi_get_gpe_device
823 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
824 * gpe_device - Where the parent GPE Device is returned
826 * RETURN: Status
828 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
829 * gpe device indicates that the gpe number is contained in one of
830 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
832 ******************************************************************************/
833 acpi_status
834 acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
836 struct acpi_gpe_device_info info;
837 acpi_status status;
839 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
841 if (!gpe_device) {
842 return_ACPI_STATUS(AE_BAD_PARAMETER);
845 if (index >= acpi_current_gpe_count) {
846 return_ACPI_STATUS(AE_NOT_EXIST);
849 /* Setup and walk the GPE list */
851 info.index = index;
852 info.status = AE_NOT_EXIST;
853 info.gpe_device = NULL;
854 info.next_block_base_index = 0;
856 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
857 if (ACPI_FAILURE(status)) {
858 return_ACPI_STATUS(status);
861 *gpe_device = info.gpe_device;
862 return_ACPI_STATUS(info.status);
865 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
867 /*******************************************************************************
869 * FUNCTION: acpi_ev_get_gpe_device
871 * PARAMETERS: GPE_WALK_CALLBACK
873 * RETURN: Status
875 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
876 * block device. NULL if the GPE is one of the FADT-defined GPEs.
878 ******************************************************************************/
879 static acpi_status
880 acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
881 struct acpi_gpe_block_info *gpe_block, void *context)
883 struct acpi_gpe_device_info *info = context;
885 /* Increment Index by the number of GPEs in this block */
887 info->next_block_base_index += gpe_block->gpe_count;
889 if (info->index < info->next_block_base_index) {
891 * The GPE index is within this block, get the node. Leave the node
892 * NULL for the FADT-defined GPEs
894 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
895 info->gpe_device = gpe_block->node;
898 info->status = AE_OK;
899 return (AE_CTRL_END);
902 return (AE_OK);
905 /******************************************************************************
907 * FUNCTION: acpi_disable_all_gpes
909 * PARAMETERS: None
911 * RETURN: Status
913 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
915 ******************************************************************************/
917 acpi_status acpi_disable_all_gpes(void)
919 acpi_status status;
921 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
923 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
924 if (ACPI_FAILURE(status)) {
925 return_ACPI_STATUS(status);
928 status = acpi_hw_disable_all_gpes();
929 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
931 return_ACPI_STATUS(status);
934 /******************************************************************************
936 * FUNCTION: acpi_enable_all_runtime_gpes
938 * PARAMETERS: None
940 * RETURN: Status
942 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
944 ******************************************************************************/
946 acpi_status acpi_enable_all_runtime_gpes(void)
948 acpi_status status;
950 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
952 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
953 if (ACPI_FAILURE(status)) {
954 return_ACPI_STATUS(status);
957 status = acpi_hw_enable_all_runtime_gpes();
958 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
960 return_ACPI_STATUS(status);