hwacpi.c revision 250838
167754Smsmith/****************************************************************************** 267754Smsmith * 371867Smsmith * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface 467754Smsmith * 567754Smsmith *****************************************************************************/ 667754Smsmith 7217365Sjkim/* 8245582Sjkim * Copyright (C) 2000 - 2013, Intel Corp. 970243Smsmith * All rights reserved. 1067754Smsmith * 11217365Sjkim * Redistribution and use in source and binary forms, with or without 12217365Sjkim * modification, are permitted provided that the following conditions 13217365Sjkim * are met: 14217365Sjkim * 1. Redistributions of source code must retain the above copyright 15217365Sjkim * notice, this list of conditions, and the following disclaimer, 16217365Sjkim * without modification. 17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20217365Sjkim * including a substantially similar Disclaimer requirement for further 21217365Sjkim * binary redistribution. 22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23217365Sjkim * of any contributors may be used to endorse or promote products derived 24217365Sjkim * from this software without specific prior written permission. 2567754Smsmith * 26217365Sjkim * Alternatively, this software may be distributed under the terms of the 27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28217365Sjkim * Software Foundation. 2967754Smsmith * 30217365Sjkim * NO WARRANTY 31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 42217365Sjkim */ 4367754Smsmith 4467754Smsmith#define __HWACPI_C__ 4567754Smsmith 46193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 47193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 4867754Smsmith 4967754Smsmith 5077424Smsmith#define _COMPONENT ACPI_HARDWARE 5191116Smsmith ACPI_MODULE_NAME ("hwacpi") 5267754Smsmith 5367754Smsmith 54231844Sjkim#if (!ACPI_REDUCED_HARDWARE) /* Entire module */ 5567754Smsmith/****************************************************************************** 5667754Smsmith * 5767754Smsmith * FUNCTION: AcpiHwSetMode 5867754Smsmith * 5967754Smsmith * PARAMETERS: Mode - SYS_MODE_ACPI or SYS_MODE_LEGACY 6067754Smsmith * 6167754Smsmith * RETURN: Status 6267754Smsmith * 6391116Smsmith * DESCRIPTION: Transitions the system into the requested mode. 6467754Smsmith * 6567754Smsmith ******************************************************************************/ 6667754Smsmith 6767754SmsmithACPI_STATUS 6867754SmsmithAcpiHwSetMode ( 6967754Smsmith UINT32 Mode) 7067754Smsmith{ 7167754Smsmith 7299679Siwasaki ACPI_STATUS Status; 7399679Siwasaki UINT32 Retry; 7467754Smsmith 7583174Smsmith 76167802Sjkim ACPI_FUNCTION_TRACE (HwSetMode); 7767754Smsmith 78246849Sjkim 79246849Sjkim /* If the Hardware Reduced flag is set, machine is always in acpi mode */ 80246849Sjkim 81246849Sjkim if (AcpiGbl_ReducedHardware) 82246849Sjkim { 83246849Sjkim return_ACPI_STATUS (AE_OK); 84246849Sjkim } 85246849Sjkim 86102550Siwasaki /* 87102550Siwasaki * ACPI 2.0 clarified that if SMI_CMD in FADT is zero, 88102550Siwasaki * system does not support mode transition. 89102550Siwasaki */ 90167802Sjkim if (!AcpiGbl_FADT.SmiCommand) 91102550Siwasaki { 92167802Sjkim ACPI_ERROR ((AE_INFO, "No SMI_CMD in FADT, mode transition failed")); 93102550Siwasaki return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); 94102550Siwasaki } 95102550Siwasaki 96102550Siwasaki /* 97102550Siwasaki * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE 98102550Siwasaki * in FADT: If it is zero, enabling or disabling is not supported. 99102550Siwasaki * As old systems may have used zero for mode transition, 100102550Siwasaki * we make sure both the numbers are zero to determine these 101102550Siwasaki * transitions are not supported. 102102550Siwasaki */ 103167802Sjkim if (!AcpiGbl_FADT.AcpiEnable && !AcpiGbl_FADT.AcpiDisable) 104102550Siwasaki { 105167802Sjkim ACPI_ERROR ((AE_INFO, 106193267Sjkim "No ACPI mode transition supported in this system " 107193267Sjkim "(enable/disable both zero)")); 108102550Siwasaki return_ACPI_STATUS (AE_OK); 109102550Siwasaki } 110102550Siwasaki 11199679Siwasaki switch (Mode) 11299679Siwasaki { 11399679Siwasaki case ACPI_SYS_MODE_ACPI: 11467754Smsmith 11567754Smsmith /* BIOS should have disabled ALL fixed and GP events */ 11667754Smsmith 117193267Sjkim Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand, 118167802Sjkim (UINT32) AcpiGbl_FADT.AcpiEnable, 8); 11982367Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Attempting to enable ACPI mode\n")); 12099679Siwasaki break; 12199679Siwasaki 12299679Siwasaki case ACPI_SYS_MODE_LEGACY: 12367754Smsmith /* 12467754Smsmith * BIOS should clear all fixed status bits and restore fixed event 12567754Smsmith * enable bits to default 12667754Smsmith */ 127193267Sjkim Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand, 128167802Sjkim (UINT32) AcpiGbl_FADT.AcpiDisable, 8); 12982367Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 13082367Smsmith "Attempting to enable Legacy (non-ACPI) mode\n")); 13199679Siwasaki break; 13299679Siwasaki 13399679Siwasaki default: 134250838Sjkim 13599679Siwasaki return_ACPI_STATUS (AE_BAD_PARAMETER); 13667754Smsmith } 13767754Smsmith 13899679Siwasaki if (ACPI_FAILURE (Status)) 13999679Siwasaki { 140167802Sjkim ACPI_EXCEPTION ((AE_INFO, Status, 141167802Sjkim "Could not write ACPI mode change")); 14299679Siwasaki return_ACPI_STATUS (Status); 14399679Siwasaki } 14483174Smsmith 14599679Siwasaki /* 14699679Siwasaki * Some hardware takes a LONG time to switch modes. Give them 3 sec to 14799679Siwasaki * do so, but allow faster systems to proceed more quickly. 14899679Siwasaki */ 14999679Siwasaki Retry = 3000; 15099679Siwasaki while (Retry) 15199679Siwasaki { 152245582Sjkim if (AcpiHwGetMode () == Mode) 153102550Siwasaki { 154151937Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n", 155151937Sjkim Mode)); 156123315Snjl return_ACPI_STATUS (AE_OK); 15799679Siwasaki } 158245582Sjkim AcpiOsStall (ACPI_USEC_PER_MSEC); 15999679Siwasaki Retry--; 16067754Smsmith } 16167754Smsmith 162167802Sjkim ACPI_ERROR ((AE_INFO, "Hardware did not change modes")); 163123315Snjl return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); 16467754Smsmith} 16567754Smsmith 16667754Smsmith 167151937Sjkim/******************************************************************************* 16867754Smsmith * 16967754Smsmith * FUNCTION: AcpiHwGetMode 17067754Smsmith * 17167754Smsmith * PARAMETERS: none 17267754Smsmith * 17367754Smsmith * RETURN: SYS_MODE_ACPI or SYS_MODE_LEGACY 17467754Smsmith * 175241973Sjkim * DESCRIPTION: Return current operating state of system. Determined by 17667754Smsmith * querying the SCI_EN bit. 17767754Smsmith * 17867754Smsmith ******************************************************************************/ 17967754Smsmith 18067754SmsmithUINT32 181151937SjkimAcpiHwGetMode ( 182151937Sjkim void) 18367754Smsmith{ 18499679Siwasaki ACPI_STATUS Status; 18599679Siwasaki UINT32 Value; 18667754Smsmith 18799679Siwasaki 188167802Sjkim ACPI_FUNCTION_TRACE (HwGetMode); 18967754Smsmith 190123315Snjl 191246849Sjkim /* If the Hardware Reduced flag is set, machine is always in acpi mode */ 192246849Sjkim 193246849Sjkim if (AcpiGbl_ReducedHardware) 194246849Sjkim { 195246849Sjkim return_UINT32 (ACPI_SYS_MODE_ACPI); 196246849Sjkim } 197246849Sjkim 198123315Snjl /* 199123315Snjl * ACPI 2.0 clarified that if SMI_CMD in FADT is zero, 200123315Snjl * system does not support mode transition. 201123315Snjl */ 202167802Sjkim if (!AcpiGbl_FADT.SmiCommand) 203123315Snjl { 204246849Sjkim return_UINT32 (ACPI_SYS_MODE_ACPI); 205123315Snjl } 206123315Snjl 207193267Sjkim Status = AcpiReadBitRegister (ACPI_BITREG_SCI_ENABLE, &Value); 20899679Siwasaki if (ACPI_FAILURE (Status)) 20999679Siwasaki { 210246849Sjkim return_UINT32 (ACPI_SYS_MODE_LEGACY); 21199679Siwasaki } 21267754Smsmith 21399679Siwasaki if (Value) 21467754Smsmith { 215246849Sjkim return_UINT32 (ACPI_SYS_MODE_ACPI); 21667754Smsmith } 21767754Smsmith else 21867754Smsmith { 219246849Sjkim return_UINT32 (ACPI_SYS_MODE_LEGACY); 22067754Smsmith } 22167754Smsmith} 222231844Sjkim 223231844Sjkim#endif /* !ACPI_REDUCED_HARDWARE */ 224