1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2008, 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>
45 #include <acpi/acevents.h>
46 #include <acpi/acnamesp.h>
47 #include <acpi/actables.h>
49 #define _COMPONENT ACPI_EVENTS
50 ACPI_MODULE_NAME("evxfevnt")
52 /*******************************************************************************
54 * FUNCTION: acpi_enable
60 * DESCRIPTION: Transfers the system into ACPI mode.
62 ******************************************************************************/
63 acpi_status
acpi_enable(void)
65 acpi_status status
= AE_OK
;
67 ACPI_FUNCTION_TRACE(acpi_enable
);
69 /* ACPI tables must be present */
71 if (!acpi_tb_tables_loaded()) {
72 return_ACPI_STATUS(AE_NO_ACPI_TABLES
);
75 /* Check current mode */
77 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI
) {
78 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
79 "System is already in ACPI mode\n"));
81 /* Transition to ACPI mode */
83 status
= acpi_hw_set_mode(ACPI_SYS_MODE_ACPI
);
84 if (ACPI_FAILURE(status
)) {
86 "Could not transition to ACPI mode"));
87 return_ACPI_STATUS(status
);
90 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
91 "Transition to ACPI mode successful\n"));
94 return_ACPI_STATUS(status
);
97 ACPI_EXPORT_SYMBOL(acpi_enable
)
99 /*******************************************************************************
101 * FUNCTION: acpi_disable
107 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
109 ******************************************************************************/
110 acpi_status
acpi_disable(void)
112 acpi_status status
= AE_OK
;
114 ACPI_FUNCTION_TRACE(acpi_disable
);
116 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY
) {
117 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
118 "System is already in legacy (non-ACPI) mode\n"));
120 /* Transition to LEGACY mode */
122 status
= acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY
);
124 if (ACPI_FAILURE(status
)) {
126 "Could not exit ACPI mode to legacy mode"));
127 return_ACPI_STATUS(status
);
130 ACPI_DEBUG_PRINT((ACPI_DB_INIT
, "ACPI mode disabled\n"));
133 return_ACPI_STATUS(status
);
136 ACPI_EXPORT_SYMBOL(acpi_disable
)
138 /*******************************************************************************
140 * FUNCTION: acpi_enable_event
142 * PARAMETERS: Event - The fixed eventto be enabled
147 * DESCRIPTION: Enable an ACPI event (fixed)
149 ******************************************************************************/
150 acpi_status
acpi_enable_event(u32 event
, u32 flags
)
152 acpi_status status
= AE_OK
;
155 ACPI_FUNCTION_TRACE(acpi_enable_event
);
157 /* Decode the Fixed Event */
159 if (event
> ACPI_EVENT_MAX
) {
160 return_ACPI_STATUS(AE_BAD_PARAMETER
);
164 * Enable the requested fixed event (by writing a one to the
165 * enable register bit)
168 acpi_set_register(acpi_gbl_fixed_event_info
[event
].
169 enable_register_id
, 1);
170 if (ACPI_FAILURE(status
)) {
171 return_ACPI_STATUS(status
);
174 /* Make sure that the hardware responded */
177 acpi_get_register(acpi_gbl_fixed_event_info
[event
].
178 enable_register_id
, &value
);
179 if (ACPI_FAILURE(status
)) {
180 return_ACPI_STATUS(status
);
185 "Could not enable %s event",
186 acpi_ut_get_event_name(event
)));
187 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE
);
190 return_ACPI_STATUS(status
);
193 ACPI_EXPORT_SYMBOL(acpi_enable_event
)
195 /*******************************************************************************
197 * FUNCTION: acpi_set_gpe_type
199 * PARAMETERS: gpe_device - Parent GPE Device
200 * gpe_number - GPE level within the GPE block
201 * Type - New GPE type
205 * DESCRIPTION: Set the type of an individual GPE
207 ******************************************************************************/
208 acpi_status
acpi_set_gpe_type(acpi_handle gpe_device
, u32 gpe_number
, u8 type
)
210 acpi_status status
= AE_OK
;
211 struct acpi_gpe_event_info
*gpe_event_info
;
213 ACPI_FUNCTION_TRACE(acpi_set_gpe_type
);
215 /* Ensure that we have a valid GPE number */
217 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
218 if (!gpe_event_info
) {
219 status
= AE_BAD_PARAMETER
;
220 goto unlock_and_exit
;
223 if ((gpe_event_info
->flags
& ACPI_GPE_TYPE_MASK
) == type
) {
224 return_ACPI_STATUS(AE_OK
);
227 /* Set the new type (will disable GPE if currently enabled) */
229 status
= acpi_ev_set_gpe_type(gpe_event_info
, type
);
232 return_ACPI_STATUS(status
);
235 ACPI_EXPORT_SYMBOL(acpi_set_gpe_type
)
237 /*******************************************************************************
239 * FUNCTION: acpi_enable_gpe
241 * PARAMETERS: gpe_device - Parent GPE Device
242 * gpe_number - GPE level within the GPE block
243 * Flags - Just enable, or also wake enable?
244 * Called from ISR or not
248 * DESCRIPTION: Enable an ACPI event (general purpose)
250 ******************************************************************************/
251 acpi_status
acpi_enable_gpe(acpi_handle gpe_device
, u32 gpe_number
)
253 acpi_status status
= AE_OK
;
254 acpi_cpu_flags flags
;
255 struct acpi_gpe_event_info
*gpe_event_info
;
257 ACPI_FUNCTION_TRACE(acpi_enable_gpe
);
259 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
261 /* Ensure that we have a valid GPE number */
263 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
264 if (!gpe_event_info
) {
265 status
= AE_BAD_PARAMETER
;
266 goto unlock_and_exit
;
269 /* Perform the enable */
271 status
= acpi_ev_enable_gpe(gpe_event_info
, TRUE
);
274 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
275 return_ACPI_STATUS(status
);
278 ACPI_EXPORT_SYMBOL(acpi_enable_gpe
)
280 /*******************************************************************************
282 * FUNCTION: acpi_disable_gpe
284 * PARAMETERS: gpe_device - Parent GPE Device
285 * gpe_number - GPE level within the GPE block
286 * Flags - Just disable, or also wake disable?
287 * Called from ISR or not
291 * DESCRIPTION: Disable an ACPI event (general purpose)
293 ******************************************************************************/
294 acpi_status
acpi_disable_gpe(acpi_handle gpe_device
, u32 gpe_number
)
296 acpi_status status
= AE_OK
;
297 acpi_cpu_flags flags
;
298 struct acpi_gpe_event_info
*gpe_event_info
;
300 ACPI_FUNCTION_TRACE(acpi_disable_gpe
);
302 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 status
= acpi_ev_disable_gpe(gpe_event_info
);
314 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
315 return_ACPI_STATUS(status
);
318 ACPI_EXPORT_SYMBOL(acpi_disable_gpe
)
320 /*******************************************************************************
322 * FUNCTION: acpi_disable_event
324 * PARAMETERS: Event - The fixed eventto be enabled
329 * DESCRIPTION: Disable an ACPI event (fixed)
331 ******************************************************************************/
332 acpi_status
acpi_disable_event(u32 event
, u32 flags
)
334 acpi_status status
= AE_OK
;
337 ACPI_FUNCTION_TRACE(acpi_disable_event
);
339 /* Decode the Fixed Event */
341 if (event
> ACPI_EVENT_MAX
) {
342 return_ACPI_STATUS(AE_BAD_PARAMETER
);
346 * Disable the requested fixed event (by writing a zero to the
347 * enable register bit)
350 acpi_set_register(acpi_gbl_fixed_event_info
[event
].
351 enable_register_id
, 0);
352 if (ACPI_FAILURE(status
)) {
353 return_ACPI_STATUS(status
);
357 acpi_get_register(acpi_gbl_fixed_event_info
[event
].
358 enable_register_id
, &value
);
359 if (ACPI_FAILURE(status
)) {
360 return_ACPI_STATUS(status
);
365 "Could not disable %s events",
366 acpi_ut_get_event_name(event
)));
367 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE
);
370 return_ACPI_STATUS(status
);
373 ACPI_EXPORT_SYMBOL(acpi_disable_event
)
375 /*******************************************************************************
377 * FUNCTION: acpi_clear_event
379 * PARAMETERS: Event - The fixed event to be cleared
383 * DESCRIPTION: Clear an ACPI event (fixed)
385 ******************************************************************************/
386 acpi_status
acpi_clear_event(u32 event
)
388 acpi_status status
= AE_OK
;
390 ACPI_FUNCTION_TRACE(acpi_clear_event
);
392 /* Decode the Fixed Event */
394 if (event
> ACPI_EVENT_MAX
) {
395 return_ACPI_STATUS(AE_BAD_PARAMETER
);
399 * Clear the requested fixed event (By writing a one to the
400 * status register bit)
403 acpi_set_register(acpi_gbl_fixed_event_info
[event
].
404 status_register_id
, 1);
406 return_ACPI_STATUS(status
);
409 ACPI_EXPORT_SYMBOL(acpi_clear_event
)
411 /*******************************************************************************
413 * FUNCTION: acpi_clear_gpe
415 * PARAMETERS: gpe_device - Parent GPE Device
416 * gpe_number - GPE level within the GPE block
417 * Flags - Called from an ISR or not
421 * DESCRIPTION: Clear an ACPI event (general purpose)
423 ******************************************************************************/
424 acpi_status
acpi_clear_gpe(acpi_handle gpe_device
, u32 gpe_number
, u32 flags
)
426 acpi_status status
= AE_OK
;
427 struct acpi_gpe_event_info
*gpe_event_info
;
429 ACPI_FUNCTION_TRACE(acpi_clear_gpe
);
431 /* Use semaphore lock if not executing at interrupt level */
433 if (flags
& ACPI_NOT_ISR
) {
434 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
435 if (ACPI_FAILURE(status
)) {
436 return_ACPI_STATUS(status
);
440 /* Ensure that we have a valid GPE number */
442 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
443 if (!gpe_event_info
) {
444 status
= AE_BAD_PARAMETER
;
445 goto unlock_and_exit
;
448 status
= acpi_hw_clear_gpe(gpe_event_info
);
451 if (flags
& ACPI_NOT_ISR
) {
452 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
454 return_ACPI_STATUS(status
);
457 ACPI_EXPORT_SYMBOL(acpi_clear_gpe
)
458 /*******************************************************************************
460 * FUNCTION: acpi_get_event_status
462 * PARAMETERS: Event - The fixed event
463 * event_status - Where the current status of the event will
468 * DESCRIPTION: Obtains and returns the current status of the event
470 ******************************************************************************/
471 acpi_status
acpi_get_event_status(u32 event
, acpi_event_status
* event_status
)
473 acpi_status status
= AE_OK
;
476 ACPI_FUNCTION_TRACE(acpi_get_event_status
);
479 return_ACPI_STATUS(AE_BAD_PARAMETER
);
482 /* Decode the Fixed Event */
484 if (event
> ACPI_EVENT_MAX
) {
485 return_ACPI_STATUS(AE_BAD_PARAMETER
);
488 /* Get the status of the requested fixed event */
491 acpi_get_register(acpi_gbl_fixed_event_info
[event
].
492 enable_register_id
, &value
);
493 if (ACPI_FAILURE(status
))
494 return_ACPI_STATUS(status
);
496 *event_status
= value
;
499 acpi_get_register(acpi_gbl_fixed_event_info
[event
].
500 status_register_id
, &value
);
501 if (ACPI_FAILURE(status
))
502 return_ACPI_STATUS(status
);
505 *event_status
|= ACPI_EVENT_FLAG_SET
;
507 return_ACPI_STATUS(status
);
510 ACPI_EXPORT_SYMBOL(acpi_get_event_status
)
512 /*******************************************************************************
514 * FUNCTION: acpi_get_gpe_status
516 * PARAMETERS: gpe_device - Parent GPE Device
517 * gpe_number - GPE level within the GPE block
518 * Flags - Called from an ISR or not
519 * event_status - Where the current status of the event will
524 * DESCRIPTION: Get status of an event (general purpose)
526 ******************************************************************************/
528 acpi_get_gpe_status(acpi_handle gpe_device
,
529 u32 gpe_number
, u32 flags
, acpi_event_status
* event_status
)
531 acpi_status status
= AE_OK
;
532 struct acpi_gpe_event_info
*gpe_event_info
;
534 ACPI_FUNCTION_TRACE(acpi_get_gpe_status
);
536 /* Use semaphore lock if not executing at interrupt level */
538 if (flags
& ACPI_NOT_ISR
) {
539 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
540 if (ACPI_FAILURE(status
)) {
541 return_ACPI_STATUS(status
);
545 /* Ensure that we have a valid GPE number */
547 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
548 if (!gpe_event_info
) {
549 status
= AE_BAD_PARAMETER
;
550 goto unlock_and_exit
;
553 /* Obtain status on the requested GPE number */
555 status
= acpi_hw_get_gpe_status(gpe_event_info
, event_status
);
558 if (flags
& ACPI_NOT_ISR
) {
559 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
561 return_ACPI_STATUS(status
);
564 ACPI_EXPORT_SYMBOL(acpi_get_gpe_status
)
565 /*******************************************************************************
567 * FUNCTION: acpi_install_gpe_block
569 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
570 * gpe_block_address - Address and space_iD
571 * register_count - Number of GPE register pairs in the block
572 * interrupt_number - H/W interrupt for the block
576 * DESCRIPTION: Create and Install a block of GPE registers
578 ******************************************************************************/
580 acpi_install_gpe_block(acpi_handle gpe_device
,
581 struct acpi_generic_address
*gpe_block_address
,
582 u32 register_count
, u32 interrupt_number
)
585 union acpi_operand_object
*obj_desc
;
586 struct acpi_namespace_node
*node
;
587 struct acpi_gpe_block_info
*gpe_block
;
589 ACPI_FUNCTION_TRACE(acpi_install_gpe_block
);
591 if ((!gpe_device
) || (!gpe_block_address
) || (!register_count
)) {
592 return_ACPI_STATUS(AE_BAD_PARAMETER
);
595 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
596 if (ACPI_FAILURE(status
)) {
600 node
= acpi_ns_map_handle_to_node(gpe_device
);
602 status
= AE_BAD_PARAMETER
;
603 goto unlock_and_exit
;
607 * For user-installed GPE Block Devices, the gpe_block_base_number
611 acpi_ev_create_gpe_block(node
, gpe_block_address
, register_count
, 0,
612 interrupt_number
, &gpe_block
);
613 if (ACPI_FAILURE(status
)) {
614 goto unlock_and_exit
;
617 /* Run the _PRW methods and enable the GPEs */
619 status
= acpi_ev_initialize_gpe_block(node
, gpe_block
);
620 if (ACPI_FAILURE(status
)) {
621 goto unlock_and_exit
;
624 /* Get the device_object attached to the node */
626 obj_desc
= acpi_ns_get_attached_object(node
);
629 /* No object, create a new one */
631 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_DEVICE
);
633 status
= AE_NO_MEMORY
;
634 goto unlock_and_exit
;
638 acpi_ns_attach_object(node
, obj_desc
, ACPI_TYPE_DEVICE
);
640 /* Remove local reference to the object */
642 acpi_ut_remove_reference(obj_desc
);
644 if (ACPI_FAILURE(status
)) {
645 goto unlock_and_exit
;
649 /* Install the GPE block in the device_object */
651 obj_desc
->device
.gpe_block
= gpe_block
;
654 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
655 return_ACPI_STATUS(status
);
658 ACPI_EXPORT_SYMBOL(acpi_install_gpe_block
)
660 /*******************************************************************************
662 * FUNCTION: acpi_remove_gpe_block
664 * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
668 * DESCRIPTION: Remove a previously installed block of GPE registers
670 ******************************************************************************/
671 acpi_status
acpi_remove_gpe_block(acpi_handle gpe_device
)
673 union acpi_operand_object
*obj_desc
;
675 struct acpi_namespace_node
*node
;
677 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block
);
680 return_ACPI_STATUS(AE_BAD_PARAMETER
);
683 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
684 if (ACPI_FAILURE(status
)) {
688 node
= acpi_ns_map_handle_to_node(gpe_device
);
690 status
= AE_BAD_PARAMETER
;
691 goto unlock_and_exit
;
694 /* Get the device_object attached to the node */
696 obj_desc
= acpi_ns_get_attached_object(node
);
697 if (!obj_desc
|| !obj_desc
->device
.gpe_block
) {
698 return_ACPI_STATUS(AE_NULL_OBJECT
);
701 /* Delete the GPE block (but not the device_object) */
703 status
= acpi_ev_delete_gpe_block(obj_desc
->device
.gpe_block
);
704 if (ACPI_SUCCESS(status
)) {
705 obj_desc
->device
.gpe_block
= NULL
;
709 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
710 return_ACPI_STATUS(status
);
713 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block
)