ALSA: hda - Add quirk for Dell Vostro 1220
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / acpi / acpica / evxfevnt.c
blob47c1aac07202fbb87b4f7c8bb5e01323cd17be09
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 = 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"));
87 } else {
88 /* Transition to ACPI mode */
90 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
91 if (ACPI_FAILURE(status)) {
92 ACPI_ERROR((AE_INFO,
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
110 * PARAMETERS: None
112 * RETURN: Status
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"));
126 } else {
127 /* Transition to LEGACY mode */
129 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
131 if (ACPI_FAILURE(status)) {
132 ACPI_ERROR((AE_INFO,
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
150 * Flags - Reserved
152 * RETURN: Status
154 * DESCRIPTION: Enable an ACPI event (fixed)
156 ******************************************************************************/
157 acpi_status acpi_enable_event(u32 event, u32 flags)
159 acpi_status status = AE_OK;
160 u32 value;
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
172 * register bit)
174 status =
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 */
183 status =
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);
190 if (value != 1) {
191 ACPI_ERROR((AE_INFO,
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
208 * RETURN: Status
210 * DESCRIPTION: Clear the given GPE from stale events and enable it.
212 ******************************************************************************/
213 static acpi_status
214 acpi_clear_and_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
216 acpi_status status;
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
245 * gpe_number - GPE level within the GPE block
246 * action - Enable or disable
247 * Called from ISR or not
249 * RETURN: Status
251 * DESCRIPTION: Enable or disable an ACPI event (general purpose)
253 ******************************************************************************/
254 acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
256 acpi_status status = AE_OK;
257 acpi_cpu_flags flags;
258 struct acpi_gpe_event_info *gpe_event_info;
260 ACPI_FUNCTION_TRACE(acpi_set_gpe);
262 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
264 /* Ensure that we have a valid GPE number */
266 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
267 if (!gpe_event_info) {
268 status = AE_BAD_PARAMETER;
269 goto unlock_and_exit;
272 /* Perform the action */
274 switch (action) {
275 case ACPI_GPE_ENABLE:
276 status = acpi_clear_and_enable_gpe(gpe_event_info);
277 break;
279 case ACPI_GPE_DISABLE:
280 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
281 break;
283 default:
284 ACPI_ERROR((AE_INFO, "Invalid action\n"));
285 status = AE_BAD_PARAMETER;
286 break;
289 unlock_and_exit:
290 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
291 return_ACPI_STATUS(status);
294 ACPI_EXPORT_SYMBOL(acpi_set_gpe)
296 /*******************************************************************************
298 * FUNCTION: acpi_enable_gpe
300 * PARAMETERS: gpe_device - Parent GPE Device
301 * gpe_number - GPE level within the GPE block
302 * type - Purpose the GPE will be used for
304 * RETURN: Status
306 * DESCRIPTION: Take a reference to a GPE and enable it if necessary
308 ******************************************************************************/
309 acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
311 acpi_status status = AE_OK;
312 acpi_cpu_flags flags;
313 struct acpi_gpe_event_info *gpe_event_info;
315 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
317 if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
318 return_ACPI_STATUS(AE_BAD_PARAMETER);
320 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
322 /* Ensure that we have a valid GPE number */
324 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
325 if (!gpe_event_info) {
326 status = AE_BAD_PARAMETER;
327 goto unlock_and_exit;
330 if (type & ACPI_GPE_TYPE_RUNTIME) {
331 if (++gpe_event_info->runtime_count == 1) {
332 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
333 if (ACPI_SUCCESS(status)) {
334 status = acpi_clear_and_enable_gpe(gpe_event_info);
336 if (ACPI_FAILURE(status)) {
337 gpe_event_info->runtime_count--;
342 if (type & ACPI_GPE_TYPE_WAKE) {
343 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
344 status = AE_BAD_PARAMETER;
345 goto unlock_and_exit;
349 * Wake-up GPEs are only enabled right prior to putting the
350 * system into a sleep state.
352 if (++gpe_event_info->wakeup_count == 1)
353 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
356 unlock_and_exit:
357 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
358 return_ACPI_STATUS(status);
360 ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
362 /*******************************************************************************
364 * FUNCTION: acpi_disable_gpe
366 * PARAMETERS: gpe_device - Parent GPE Device
367 * gpe_number - GPE level within the GPE block
368 * type - Purpose the GPE won't be used for any more
370 * RETURN: Status
372 * DESCRIPTION: Release a reference to a GPE and disable it if necessary
374 ******************************************************************************/
375 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
377 acpi_status status = AE_OK;
378 acpi_cpu_flags flags;
379 struct acpi_gpe_event_info *gpe_event_info;
381 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
383 if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
384 return_ACPI_STATUS(AE_BAD_PARAMETER);
386 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
387 /* Ensure that we have a valid GPE number */
389 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
390 if (!gpe_event_info) {
391 status = AE_BAD_PARAMETER;
392 goto unlock_and_exit;
395 if ((type & ACPI_GPE_TYPE_RUNTIME) && gpe_event_info->runtime_count) {
396 if (--gpe_event_info->runtime_count == 0) {
397 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
398 if (ACPI_SUCCESS(status)) {
399 status = acpi_hw_low_set_gpe(gpe_event_info,
400 ACPI_GPE_DISABLE);
402 if (ACPI_FAILURE(status)) {
403 gpe_event_info->runtime_count++;
408 if ((type & ACPI_GPE_TYPE_WAKE) && gpe_event_info->wakeup_count) {
410 * Wake-up GPEs are not enabled after leaving system sleep
411 * states, so we don't need to disable them here.
413 if (--gpe_event_info->wakeup_count == 0)
414 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
417 unlock_and_exit:
418 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
419 return_ACPI_STATUS(status);
421 ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
423 /*******************************************************************************
425 * FUNCTION: acpi_disable_event
427 * PARAMETERS: Event - The fixed eventto be enabled
428 * Flags - Reserved
430 * RETURN: Status
432 * DESCRIPTION: Disable an ACPI event (fixed)
434 ******************************************************************************/
435 acpi_status acpi_disable_event(u32 event, u32 flags)
437 acpi_status status = AE_OK;
438 u32 value;
440 ACPI_FUNCTION_TRACE(acpi_disable_event);
442 /* Decode the Fixed Event */
444 if (event > ACPI_EVENT_MAX) {
445 return_ACPI_STATUS(AE_BAD_PARAMETER);
449 * Disable the requested fixed event (by writing a zero to the enable
450 * register bit)
452 status =
453 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
454 enable_register_id, ACPI_DISABLE_EVENT);
455 if (ACPI_FAILURE(status)) {
456 return_ACPI_STATUS(status);
459 status =
460 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
461 enable_register_id, &value);
462 if (ACPI_FAILURE(status)) {
463 return_ACPI_STATUS(status);
466 if (value != 0) {
467 ACPI_ERROR((AE_INFO,
468 "Could not disable %s events",
469 acpi_ut_get_event_name(event)));
470 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
473 return_ACPI_STATUS(status);
476 ACPI_EXPORT_SYMBOL(acpi_disable_event)
478 /*******************************************************************************
480 * FUNCTION: acpi_clear_event
482 * PARAMETERS: Event - The fixed event to be cleared
484 * RETURN: Status
486 * DESCRIPTION: Clear an ACPI event (fixed)
488 ******************************************************************************/
489 acpi_status acpi_clear_event(u32 event)
491 acpi_status status = AE_OK;
493 ACPI_FUNCTION_TRACE(acpi_clear_event);
495 /* Decode the Fixed Event */
497 if (event > ACPI_EVENT_MAX) {
498 return_ACPI_STATUS(AE_BAD_PARAMETER);
502 * Clear the requested fixed event (By writing a one to the status
503 * register bit)
505 status =
506 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
507 status_register_id, ACPI_CLEAR_STATUS);
509 return_ACPI_STATUS(status);
512 ACPI_EXPORT_SYMBOL(acpi_clear_event)
514 /*******************************************************************************
516 * FUNCTION: acpi_clear_gpe
518 * PARAMETERS: gpe_device - Parent GPE Device
519 * gpe_number - GPE level within the GPE block
520 * Flags - Called from an ISR or not
522 * RETURN: Status
524 * DESCRIPTION: Clear an ACPI event (general purpose)
526 ******************************************************************************/
527 acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
529 acpi_status status = AE_OK;
530 struct acpi_gpe_event_info *gpe_event_info;
532 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
534 /* Use semaphore lock if not executing at interrupt level */
536 if (flags & ACPI_NOT_ISR) {
537 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
538 if (ACPI_FAILURE(status)) {
539 return_ACPI_STATUS(status);
543 /* Ensure that we have a valid GPE number */
545 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
546 if (!gpe_event_info) {
547 status = AE_BAD_PARAMETER;
548 goto unlock_and_exit;
551 status = acpi_hw_clear_gpe(gpe_event_info);
553 unlock_and_exit:
554 if (flags & ACPI_NOT_ISR) {
555 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
557 return_ACPI_STATUS(status);
560 ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
561 /*******************************************************************************
563 * FUNCTION: acpi_get_event_status
565 * PARAMETERS: Event - The fixed event
566 * event_status - Where the current status of the event will
567 * be returned
569 * RETURN: Status
571 * DESCRIPTION: Obtains and returns the current status of the event
573 ******************************************************************************/
574 acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
576 acpi_status status = AE_OK;
577 u32 value;
579 ACPI_FUNCTION_TRACE(acpi_get_event_status);
581 if (!event_status) {
582 return_ACPI_STATUS(AE_BAD_PARAMETER);
585 /* Decode the Fixed Event */
587 if (event > ACPI_EVENT_MAX) {
588 return_ACPI_STATUS(AE_BAD_PARAMETER);
591 /* Get the status of the requested fixed event */
593 status =
594 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
595 enable_register_id, &value);
596 if (ACPI_FAILURE(status))
597 return_ACPI_STATUS(status);
599 *event_status = value;
601 status =
602 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
603 status_register_id, &value);
604 if (ACPI_FAILURE(status))
605 return_ACPI_STATUS(status);
607 if (value)
608 *event_status |= ACPI_EVENT_FLAG_SET;
610 if (acpi_gbl_fixed_event_handlers[event].handler)
611 *event_status |= ACPI_EVENT_FLAG_HANDLE;
613 return_ACPI_STATUS(status);
616 ACPI_EXPORT_SYMBOL(acpi_get_event_status)
618 /*******************************************************************************
620 * FUNCTION: acpi_get_gpe_status
622 * PARAMETERS: gpe_device - Parent GPE Device
623 * gpe_number - GPE level within the GPE block
624 * Flags - Called from an ISR or not
625 * event_status - Where the current status of the event will
626 * be returned
628 * RETURN: Status
630 * DESCRIPTION: Get status of an event (general purpose)
632 ******************************************************************************/
633 acpi_status
634 acpi_get_gpe_status(acpi_handle gpe_device,
635 u32 gpe_number, u32 flags, acpi_event_status * event_status)
637 acpi_status status = AE_OK;
638 struct acpi_gpe_event_info *gpe_event_info;
640 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
642 /* Use semaphore lock if not executing at interrupt level */
644 if (flags & ACPI_NOT_ISR) {
645 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
646 if (ACPI_FAILURE(status)) {
647 return_ACPI_STATUS(status);
651 /* Ensure that we have a valid GPE number */
653 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
654 if (!gpe_event_info) {
655 status = AE_BAD_PARAMETER;
656 goto unlock_and_exit;
659 /* Obtain status on the requested GPE number */
661 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
663 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
664 *event_status |= ACPI_EVENT_FLAG_HANDLE;
666 unlock_and_exit:
667 if (flags & ACPI_NOT_ISR) {
668 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
670 return_ACPI_STATUS(status);
673 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
674 /*******************************************************************************
676 * FUNCTION: acpi_install_gpe_block
678 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
679 * gpe_block_address - Address and space_iD
680 * register_count - Number of GPE register pairs in the block
681 * interrupt_number - H/W interrupt for the block
683 * RETURN: Status
685 * DESCRIPTION: Create and Install a block of GPE registers
687 ******************************************************************************/
688 acpi_status
689 acpi_install_gpe_block(acpi_handle gpe_device,
690 struct acpi_generic_address *gpe_block_address,
691 u32 register_count, u32 interrupt_number)
693 acpi_status status;
694 union acpi_operand_object *obj_desc;
695 struct acpi_namespace_node *node;
696 struct acpi_gpe_block_info *gpe_block;
698 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
700 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
701 return_ACPI_STATUS(AE_BAD_PARAMETER);
704 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
705 if (ACPI_FAILURE(status)) {
706 return (status);
709 node = acpi_ns_validate_handle(gpe_device);
710 if (!node) {
711 status = AE_BAD_PARAMETER;
712 goto unlock_and_exit;
716 * For user-installed GPE Block Devices, the gpe_block_base_number
717 * is always zero
719 status =
720 acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
721 interrupt_number, &gpe_block);
722 if (ACPI_FAILURE(status)) {
723 goto unlock_and_exit;
726 /* Run the _PRW methods and enable the GPEs */
728 status = acpi_ev_initialize_gpe_block(node, gpe_block);
729 if (ACPI_FAILURE(status)) {
730 goto unlock_and_exit;
733 /* Get the device_object attached to the node */
735 obj_desc = acpi_ns_get_attached_object(node);
736 if (!obj_desc) {
738 /* No object, create a new one */
740 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
741 if (!obj_desc) {
742 status = AE_NO_MEMORY;
743 goto unlock_and_exit;
746 status =
747 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
749 /* Remove local reference to the object */
751 acpi_ut_remove_reference(obj_desc);
753 if (ACPI_FAILURE(status)) {
754 goto unlock_and_exit;
758 /* Install the GPE block in the device_object */
760 obj_desc->device.gpe_block = gpe_block;
762 unlock_and_exit:
763 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
764 return_ACPI_STATUS(status);
767 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
769 /*******************************************************************************
771 * FUNCTION: acpi_remove_gpe_block
773 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
775 * RETURN: Status
777 * DESCRIPTION: Remove a previously installed block of GPE registers
779 ******************************************************************************/
780 acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
782 union acpi_operand_object *obj_desc;
783 acpi_status status;
784 struct acpi_namespace_node *node;
786 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
788 if (!gpe_device) {
789 return_ACPI_STATUS(AE_BAD_PARAMETER);
792 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
793 if (ACPI_FAILURE(status)) {
794 return (status);
797 node = acpi_ns_validate_handle(gpe_device);
798 if (!node) {
799 status = AE_BAD_PARAMETER;
800 goto unlock_and_exit;
803 /* Get the device_object attached to the node */
805 obj_desc = acpi_ns_get_attached_object(node);
806 if (!obj_desc || !obj_desc->device.gpe_block) {
807 return_ACPI_STATUS(AE_NULL_OBJECT);
810 /* Delete the GPE block (but not the device_object) */
812 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
813 if (ACPI_SUCCESS(status)) {
814 obj_desc->device.gpe_block = NULL;
817 unlock_and_exit:
818 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
819 return_ACPI_STATUS(status);
822 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
824 /*******************************************************************************
826 * FUNCTION: acpi_get_gpe_device
828 * PARAMETERS: Index - System GPE index (0-current_gpe_count)
829 * gpe_device - Where the parent GPE Device is returned
831 * RETURN: Status
833 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
834 * gpe device indicates that the gpe number is contained in one of
835 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
837 ******************************************************************************/
838 acpi_status
839 acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
841 struct acpi_gpe_device_info info;
842 acpi_status status;
844 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
846 if (!gpe_device) {
847 return_ACPI_STATUS(AE_BAD_PARAMETER);
850 if (index >= acpi_current_gpe_count) {
851 return_ACPI_STATUS(AE_NOT_EXIST);
854 /* Setup and walk the GPE list */
856 info.index = index;
857 info.status = AE_NOT_EXIST;
858 info.gpe_device = NULL;
859 info.next_block_base_index = 0;
861 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
862 if (ACPI_FAILURE(status)) {
863 return_ACPI_STATUS(status);
866 *gpe_device = info.gpe_device;
867 return_ACPI_STATUS(info.status);
870 ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
872 /*******************************************************************************
874 * FUNCTION: acpi_ev_get_gpe_device
876 * PARAMETERS: GPE_WALK_CALLBACK
878 * RETURN: Status
880 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
881 * block device. NULL if the GPE is one of the FADT-defined GPEs.
883 ******************************************************************************/
884 static acpi_status
885 acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
886 struct acpi_gpe_block_info *gpe_block, void *context)
888 struct acpi_gpe_device_info *info = context;
890 /* Increment Index by the number of GPEs in this block */
892 info->next_block_base_index +=
893 (gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH);
895 if (info->index < info->next_block_base_index) {
897 * The GPE index is within this block, get the node. Leave the node
898 * NULL for the FADT-defined GPEs
900 if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
901 info->gpe_device = gpe_block->node;
904 info->status = AE_OK;
905 return (AE_CTRL_END);
908 return (AE_OK);
911 /******************************************************************************
913 * FUNCTION: acpi_disable_all_gpes
915 * PARAMETERS: None
917 * RETURN: Status
919 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
921 ******************************************************************************/
923 acpi_status acpi_disable_all_gpes(void)
925 acpi_status status;
927 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
929 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
930 if (ACPI_FAILURE(status)) {
931 return_ACPI_STATUS(status);
934 status = acpi_hw_disable_all_gpes();
935 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
937 return_ACPI_STATUS(status);
940 /******************************************************************************
942 * FUNCTION: acpi_enable_all_runtime_gpes
944 * PARAMETERS: None
946 * RETURN: Status
948 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
950 ******************************************************************************/
952 acpi_status acpi_enable_all_runtime_gpes(void)
954 acpi_status status;
956 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
958 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
959 if (ACPI_FAILURE(status)) {
960 return_ACPI_STATUS(status);
963 status = acpi_hw_enable_all_runtime_gpes();
964 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
966 return_ACPI_STATUS(status);