Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #define EXPORT_ACPI_INTERFACES
0011 
0012 #include <acpi/acpi.h>
0013 #include "accommon.h"
0014 #include "actables.h"
0015 
0016 #define _COMPONENT          ACPI_EVENTS
0017 ACPI_MODULE_NAME("evxfevnt")
0018 
0019 #if (!ACPI_REDUCED_HARDWARE)    /* Entire module */
0020 /*******************************************************************************
0021  *
0022  * FUNCTION:    acpi_enable
0023  *
0024  * PARAMETERS:  None
0025  *
0026  * RETURN:      Status
0027  *
0028  * DESCRIPTION: Transfers the system into ACPI mode.
0029  *
0030  ******************************************************************************/
0031 acpi_status acpi_enable(void)
0032 {
0033     acpi_status status;
0034     int retry;
0035 
0036     ACPI_FUNCTION_TRACE(acpi_enable);
0037 
0038     /* ACPI tables must be present */
0039 
0040     if (acpi_gbl_fadt_index == ACPI_INVALID_TABLE_INDEX) {
0041         return_ACPI_STATUS(AE_NO_ACPI_TABLES);
0042     }
0043 
0044     /* If the Hardware Reduced flag is set, machine is always in acpi mode */
0045 
0046     if (acpi_gbl_reduced_hardware) {
0047         return_ACPI_STATUS(AE_OK);
0048     }
0049 
0050     /* Check current mode */
0051 
0052     if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
0053         ACPI_DEBUG_PRINT((ACPI_DB_INIT,
0054                   "System is already in ACPI mode\n"));
0055         return_ACPI_STATUS(AE_OK);
0056     }
0057 
0058     /* Transition to ACPI mode */
0059 
0060     status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
0061     if (ACPI_FAILURE(status)) {
0062         ACPI_ERROR((AE_INFO,
0063                 "Could not transition to ACPI mode"));
0064         return_ACPI_STATUS(status);
0065     }
0066 
0067     /* Sanity check that transition succeeded */
0068 
0069     for (retry = 0; retry < 30000; ++retry) {
0070         if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
0071             if (retry != 0)
0072                 ACPI_WARNING((AE_INFO,
0073                 "Platform took > %d00 usec to enter ACPI mode", retry));
0074             return_ACPI_STATUS(AE_OK);
0075         }
0076         acpi_os_stall(100); /* 100 usec */
0077     }
0078 
0079     ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
0080     return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
0081 }
0082 
0083 ACPI_EXPORT_SYMBOL(acpi_enable)
0084 
0085 /*******************************************************************************
0086  *
0087  * FUNCTION:    acpi_disable
0088  *
0089  * PARAMETERS:  None
0090  *
0091  * RETURN:      Status
0092  *
0093  * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
0094  *
0095  ******************************************************************************/
0096 acpi_status acpi_disable(void)
0097 {
0098     acpi_status status = AE_OK;
0099 
0100     ACPI_FUNCTION_TRACE(acpi_disable);
0101 
0102     /* If the Hardware Reduced flag is set, machine is always in acpi mode */
0103 
0104     if (acpi_gbl_reduced_hardware) {
0105         return_ACPI_STATUS(AE_OK);
0106     }
0107 
0108     if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
0109         ACPI_DEBUG_PRINT((ACPI_DB_INIT,
0110                   "System is already in legacy (non-ACPI) mode\n"));
0111     } else {
0112         /* Transition to LEGACY mode */
0113 
0114         status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
0115 
0116         if (ACPI_FAILURE(status)) {
0117             ACPI_ERROR((AE_INFO,
0118                     "Could not exit ACPI mode to legacy mode"));
0119             return_ACPI_STATUS(status);
0120         }
0121 
0122         ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
0123     }
0124 
0125     return_ACPI_STATUS(status);
0126 }
0127 
0128 ACPI_EXPORT_SYMBOL(acpi_disable)
0129 
0130 /*******************************************************************************
0131  *
0132  * FUNCTION:    acpi_enable_event
0133  *
0134  * PARAMETERS:  event           - The fixed eventto be enabled
0135  *              flags           - Reserved
0136  *
0137  * RETURN:      Status
0138  *
0139  * DESCRIPTION: Enable an ACPI event (fixed)
0140  *
0141  ******************************************************************************/
0142 acpi_status acpi_enable_event(u32 event, u32 flags)
0143 {
0144     acpi_status status = AE_OK;
0145     u32 value;
0146 
0147     ACPI_FUNCTION_TRACE(acpi_enable_event);
0148 
0149     /* If Hardware Reduced flag is set, there are no fixed events */
0150 
0151     if (acpi_gbl_reduced_hardware) {
0152         return_ACPI_STATUS(AE_OK);
0153     }
0154 
0155     /* Decode the Fixed Event */
0156 
0157     if (event > ACPI_EVENT_MAX) {
0158         return_ACPI_STATUS(AE_BAD_PARAMETER);
0159     }
0160 
0161     /*
0162      * Enable the requested fixed event (by writing a one to the enable
0163      * register bit)
0164      */
0165     status =
0166         acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
0167                     enable_register_id, ACPI_ENABLE_EVENT);
0168     if (ACPI_FAILURE(status)) {
0169         return_ACPI_STATUS(status);
0170     }
0171 
0172     /* Make sure that the hardware responded */
0173 
0174     status =
0175         acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
0176                    enable_register_id, &value);
0177     if (ACPI_FAILURE(status)) {
0178         return_ACPI_STATUS(status);
0179     }
0180 
0181     if (value != 1) {
0182         ACPI_ERROR((AE_INFO,
0183                 "Could not enable %s event",
0184                 acpi_ut_get_event_name(event)));
0185         return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
0186     }
0187 
0188     return_ACPI_STATUS(status);
0189 }
0190 
0191 ACPI_EXPORT_SYMBOL(acpi_enable_event)
0192 
0193 /*******************************************************************************
0194  *
0195  * FUNCTION:    acpi_disable_event
0196  *
0197  * PARAMETERS:  event           - The fixed event to be disabled
0198  *              flags           - Reserved
0199  *
0200  * RETURN:      Status
0201  *
0202  * DESCRIPTION: Disable an ACPI event (fixed)
0203  *
0204  ******************************************************************************/
0205 acpi_status acpi_disable_event(u32 event, u32 flags)
0206 {
0207     acpi_status status = AE_OK;
0208     u32 value;
0209 
0210     ACPI_FUNCTION_TRACE(acpi_disable_event);
0211 
0212     /* If Hardware Reduced flag is set, there are no fixed events */
0213 
0214     if (acpi_gbl_reduced_hardware) {
0215         return_ACPI_STATUS(AE_OK);
0216     }
0217 
0218     /* Decode the Fixed Event */
0219 
0220     if (event > ACPI_EVENT_MAX) {
0221         return_ACPI_STATUS(AE_BAD_PARAMETER);
0222     }
0223 
0224     /*
0225      * Disable the requested fixed event (by writing a zero to the enable
0226      * register bit)
0227      */
0228     status =
0229         acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
0230                     enable_register_id, ACPI_DISABLE_EVENT);
0231     if (ACPI_FAILURE(status)) {
0232         return_ACPI_STATUS(status);
0233     }
0234 
0235     status =
0236         acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
0237                    enable_register_id, &value);
0238     if (ACPI_FAILURE(status)) {
0239         return_ACPI_STATUS(status);
0240     }
0241 
0242     if (value != 0) {
0243         ACPI_ERROR((AE_INFO,
0244                 "Could not disable %s events",
0245                 acpi_ut_get_event_name(event)));
0246         return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
0247     }
0248 
0249     return_ACPI_STATUS(status);
0250 }
0251 
0252 ACPI_EXPORT_SYMBOL(acpi_disable_event)
0253 
0254 /*******************************************************************************
0255  *
0256  * FUNCTION:    acpi_clear_event
0257  *
0258  * PARAMETERS:  event           - The fixed event to be cleared
0259  *
0260  * RETURN:      Status
0261  *
0262  * DESCRIPTION: Clear an ACPI event (fixed)
0263  *
0264  ******************************************************************************/
0265 acpi_status acpi_clear_event(u32 event)
0266 {
0267     acpi_status status = AE_OK;
0268 
0269     ACPI_FUNCTION_TRACE(acpi_clear_event);
0270 
0271     /* If Hardware Reduced flag is set, there are no fixed events */
0272 
0273     if (acpi_gbl_reduced_hardware) {
0274         return_ACPI_STATUS(AE_OK);
0275     }
0276 
0277     /* Decode the Fixed Event */
0278 
0279     if (event > ACPI_EVENT_MAX) {
0280         return_ACPI_STATUS(AE_BAD_PARAMETER);
0281     }
0282 
0283     /*
0284      * Clear the requested fixed event (By writing a one to the status
0285      * register bit)
0286      */
0287     status =
0288         acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
0289                     status_register_id, ACPI_CLEAR_STATUS);
0290 
0291     return_ACPI_STATUS(status);
0292 }
0293 
0294 ACPI_EXPORT_SYMBOL(acpi_clear_event)
0295 
0296 /*******************************************************************************
0297  *
0298  * FUNCTION:    acpi_get_event_status
0299  *
0300  * PARAMETERS:  event           - The fixed event
0301  *              event_status    - Where the current status of the event will
0302  *                                be returned
0303  *
0304  * RETURN:      Status
0305  *
0306  * DESCRIPTION: Obtains and returns the current status of the event
0307  *
0308  ******************************************************************************/
0309 acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
0310 {
0311     acpi_status status;
0312     acpi_event_status local_event_status = 0;
0313     u32 in_byte;
0314 
0315     ACPI_FUNCTION_TRACE(acpi_get_event_status);
0316 
0317     if (!event_status) {
0318         return_ACPI_STATUS(AE_BAD_PARAMETER);
0319     }
0320 
0321     /* Decode the Fixed Event */
0322 
0323     if (event > ACPI_EVENT_MAX) {
0324         return_ACPI_STATUS(AE_BAD_PARAMETER);
0325     }
0326 
0327     /* Fixed event currently can be dispatched? */
0328 
0329     if (acpi_gbl_fixed_event_handlers[event].handler) {
0330         local_event_status |= ACPI_EVENT_FLAG_HAS_HANDLER;
0331     }
0332 
0333     /* Fixed event currently enabled? */
0334 
0335     status =
0336         acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
0337                    enable_register_id, &in_byte);
0338     if (ACPI_FAILURE(status)) {
0339         return_ACPI_STATUS(status);
0340     }
0341 
0342     if (in_byte) {
0343         local_event_status |=
0344             (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET);
0345     }
0346 
0347     /* Fixed event currently active? */
0348 
0349     status =
0350         acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
0351                    status_register_id, &in_byte);
0352     if (ACPI_FAILURE(status)) {
0353         return_ACPI_STATUS(status);
0354     }
0355 
0356     if (in_byte) {
0357         local_event_status |= ACPI_EVENT_FLAG_STATUS_SET;
0358     }
0359 
0360     (*event_status) = local_event_status;
0361     return_ACPI_STATUS(AE_OK);
0362 }
0363 
0364 ACPI_EXPORT_SYMBOL(acpi_get_event_status)
0365 #endif              /* !ACPI_REDUCED_HARDWARE */