Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 
0013 #define _COMPONENT          ACPI_HARDWARE
0014 ACPI_MODULE_NAME("hwacpi")
0015 
0016 #if (!ACPI_REDUCED_HARDWARE)    /* Entire module */
0017 /******************************************************************************
0018  *
0019  * FUNCTION:    acpi_hw_set_mode
0020  *
0021  * PARAMETERS:  mode            - SYS_MODE_ACPI or SYS_MODE_LEGACY
0022  *
0023  * RETURN:      Status
0024  *
0025  * DESCRIPTION: Transitions the system into the requested mode.
0026  *
0027  ******************************************************************************/
0028 acpi_status acpi_hw_set_mode(u32 mode)
0029 {
0030 
0031     acpi_status status;
0032 
0033     ACPI_FUNCTION_TRACE(hw_set_mode);
0034 
0035     /* If the Hardware Reduced flag is set, machine is always in acpi mode */
0036 
0037     if (acpi_gbl_reduced_hardware) {
0038         return_ACPI_STATUS(AE_OK);
0039     }
0040 
0041     /*
0042      * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
0043      * system does not support mode transition.
0044      */
0045     if (!acpi_gbl_FADT.smi_command) {
0046         ACPI_ERROR((AE_INFO,
0047                 "No SMI_CMD in FADT, mode transition failed"));
0048         return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
0049     }
0050 
0051     /*
0052      * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE
0053      * in FADT: If it is zero, enabling or disabling is not supported.
0054      * As old systems may have used zero for mode transition,
0055      * we make sure both the numbers are zero to determine these
0056      * transitions are not supported.
0057      */
0058     if (!acpi_gbl_FADT.acpi_enable && !acpi_gbl_FADT.acpi_disable) {
0059         ACPI_ERROR((AE_INFO,
0060                 "No ACPI mode transition supported in this system "
0061                 "(enable/disable both zero)"));
0062         return_ACPI_STATUS(AE_OK);
0063     }
0064 
0065     switch (mode) {
0066     case ACPI_SYS_MODE_ACPI:
0067 
0068         /* BIOS should have disabled ALL fixed and GP events */
0069 
0070         status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
0071                         (u32) acpi_gbl_FADT.acpi_enable, 8);
0072         ACPI_DEBUG_PRINT((ACPI_DB_INFO,
0073                   "Attempting to enable ACPI mode\n"));
0074         break;
0075 
0076     case ACPI_SYS_MODE_LEGACY:
0077         /*
0078          * BIOS should clear all fixed status bits and restore fixed event
0079          * enable bits to default
0080          */
0081         status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
0082                         (u32)acpi_gbl_FADT.acpi_disable, 8);
0083         ACPI_DEBUG_PRINT((ACPI_DB_INFO,
0084                   "Attempting to enable Legacy (non-ACPI) mode\n"));
0085         break;
0086 
0087     default:
0088 
0089         return_ACPI_STATUS(AE_BAD_PARAMETER);
0090     }
0091 
0092     if (ACPI_FAILURE(status)) {
0093         ACPI_EXCEPTION((AE_INFO, status,
0094                 "Could not write ACPI mode change"));
0095         return_ACPI_STATUS(status);
0096     }
0097 
0098     return_ACPI_STATUS(AE_OK);
0099 }
0100 
0101 /*******************************************************************************
0102  *
0103  * FUNCTION:    acpi_hw_get_mode
0104  *
0105  * PARAMETERS:  none
0106  *
0107  * RETURN:      SYS_MODE_ACPI or SYS_MODE_LEGACY
0108  *
0109  * DESCRIPTION: Return current operating state of system. Determined by
0110  *              querying the SCI_EN bit.
0111  *
0112  ******************************************************************************/
0113 
0114 u32 acpi_hw_get_mode(void)
0115 {
0116     acpi_status status;
0117     u32 value;
0118 
0119     ACPI_FUNCTION_TRACE(hw_get_mode);
0120 
0121     /* If the Hardware Reduced flag is set, machine is always in acpi mode */
0122 
0123     if (acpi_gbl_reduced_hardware) {
0124         return_UINT32(ACPI_SYS_MODE_ACPI);
0125     }
0126 
0127     /*
0128      * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
0129      * system does not support mode transition.
0130      */
0131     if (!acpi_gbl_FADT.smi_command) {
0132         return_UINT32(ACPI_SYS_MODE_ACPI);
0133     }
0134 
0135     status = acpi_read_bit_register(ACPI_BITREG_SCI_ENABLE, &value);
0136     if (ACPI_FAILURE(status)) {
0137         return_UINT32(ACPI_SYS_MODE_LEGACY);
0138     }
0139 
0140     if (value) {
0141         return_UINT32(ACPI_SYS_MODE_ACPI);
0142     } else {
0143         return_UINT32(ACPI_SYS_MODE_LEGACY);
0144     }
0145 }
0146 
0147 #endif              /* !ACPI_REDUCED_HARDWARE */