hwacpi.c revision 151937
167967Sasmodai 214053Smpp/****************************************************************************** 314053Smpp * 414053Smpp * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface 514053Smpp * $Revision: 1.70 $ 614053Smpp * 714053Smpp *****************************************************************************/ 814053Smpp 914053Smpp/****************************************************************************** 1014053Smpp * 1114053Smpp * 1. Copyright Notice 1214053Smpp * 1314053Smpp * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp. 1414053Smpp * All rights reserved. 1514053Smpp * 1614053Smpp * 2. License 1714053Smpp * 1814053Smpp * 2.1. This is your license from Intel Corp. under its intellectual property 1914053Smpp * rights. You may have additional license terms from the party that provided 2014053Smpp * you this software, covering your right to use that party's intellectual 2114053Smpp * property rights. 2214053Smpp * 2314053Smpp * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2414053Smpp * copy of the source code appearing in this file ("Covered Code") an 2514053Smpp * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2614053Smpp * base code distributed originally by Intel ("Original Intel Code") to copy, 2714053Smpp * make derivatives, distribute, use and display any portion of the Covered 2814053Smpp * Code in any form, with the right to sublicense such rights; and 2914053Smpp * 3014053Smpp * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 3150476Speter * license (with the right to sublicense), under only those claims of Intel 3231370Sbde * patents that are infringed by the Original Intel Code, to make, use, sell, 3314053Smpp * offer to sell, and import the Covered Code and derivative works thereof 34195656Strasz * solely to the minimum extent necessary to exercise the above copyright 35195656Strasz * license, and in no event shall the patent license extend to any additions 3679531Sru * to or modifications of the Original Intel Code. No other license or right 3714053Smpp * is granted directly or by implication, estoppel or otherwise; 3814053Smpp * 3914053Smpp * The above copyright and patent license is granted only if the following 4059460Sphantom * conditions are met: 4159460Sphantom * 4214053Smpp * 3. Conditions 4384306Sru * 4484306Sru * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4584306Sru * Redistribution of source code of any substantial portion of the Covered 4614053Smpp * Code or modification with rights to further distribute source must include 4714053Smpp * the above Copyright Notice, the above License, this list of Conditions, 4814053Smpp * and the following Disclaimer and Export Compliance provision. In addition, 4967967Sasmodai * Licensee must cause all Covered Code to which Licensee contributes to 5014053Smpp * contain a file documenting the changes Licensee made to create that Covered 5114053Smpp * Code and the date of any change. Licensee must include in that file the 5214053Smpp * documentation of any changes made by any predecessor Licensee. Licensee 5314053Smpp * must include a prominent statement that the modification is derived, 5414053Smpp * directly or indirectly, from Original Intel Code. 5514053Smpp * 5614053Smpp * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5714053Smpp * Redistribution of source code of any substantial portion of the Covered 5814053Smpp * Code or modification without rights to further distribute source must 5914053Smpp * include the following Disclaimer and Export Compliance provision in the 6024093Smpp * documentation and/or other materials provided with distribution. In 6114053Smpp * addition, Licensee may not authorize further sublicense of source of any 6214053Smpp * portion of the Covered Code, and must include terms to the effect that the 6314053Smpp * license from Licensee to its licensee is limited to the intellectual 6424093Smpp * property embodied in the software Licensee provides to its licensee, and 6524093Smpp * not to intellectual property embodied in modifications its licensee may 6624093Smpp * make. 6714053Smpp * 6814053Smpp * 3.3. Redistribution of Executable. Redistribution in executable form of any 6914053Smpp * substantial portion of the Covered Code or modification must reproduce the 7014053Smpp * above Copyright Notice, and the following Disclaimer and Export Compliance 7114053Smpp * provision in the documentation and/or other materials provided with the 72108087Sru * distribution. 7314053Smpp * 74108087Sru * 3.4. Intel retains all right, title, and interest in and to the Original 75131504Sru * Intel Code. 76131504Sru * 7714053Smpp * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7814053Smpp * Intel shall be used in advertising or otherwise to promote the sale, use or 7914053Smpp * other dealings in products derived from or relating to the Covered Code 80108087Sru * without prior written authorization from Intel. 8114053Smpp * 82108087Sru * 4. Disclaimer and Export Compliance 83131504Sru * 84131504Sru * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8514053Smpp * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 86108087Sru * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8714053Smpp * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 88108087Sru * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 89131504Sru * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 90131504Sru * PARTICULAR PURPOSE. 9114053Smpp * 9214053Smpp * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9314053Smpp * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9414053Smpp * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9524093Smpp * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 96108087Sru * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9714053Smpp * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 98108087Sru * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9957686Ssheldonh * LIMITED REMEDY. 10057686Ssheldonh * 10114053Smpp * 4.3. Licensee shall not export, either directly or indirectly, any of this 10214053Smpp * software or system incorporating such software without first obtaining any 10324093Smpp * required license or other approval from the U. S. Department of Commerce or 10424093Smpp * any other agency or department of the United States Government. In the 10524093Smpp * event Licensee exports any such software from the United States or 10614053Smpp * re-exports any such software from a foreign destination, Licensee shall 10714053Smpp * ensure that the distribution and export/re-export of the software is in 10824093Smpp * compliance with all laws, regulations, orders, or other restrictions of the 10914053Smpp * U.S. Export Administration Regulations. Licensee agrees that neither it nor 11014053Smpp * any of its subsidiaries will export/re-export any technical data, process, 11114053Smpp * software, or service, directly or indirectly, to any country for which the 11214053Smpp * United States government or any agency thereof requires an export license, 11324093Smpp * other governmental approval, or letter of assurance, without first obtaining 11424093Smpp * such license, approval or letter. 11524093Smpp * 11614053Smpp *****************************************************************************/ 11757686Ssheldonh 11857686Ssheldonh#define __HWACPI_C__ 11924093Smpp 12024093Smpp#include <contrib/dev/acpica/acpi.h> 12114053Smpp 12214053Smpp 12314053Smpp#define _COMPONENT ACPI_HARDWARE 12424093Smpp ACPI_MODULE_NAME ("hwacpi") 125147368Sru 12624093Smpp 12724093Smpp/****************************************************************************** 12824093Smpp * 12914053Smpp * FUNCTION: AcpiHwInitialize 13014053Smpp * 13114053Smpp * PARAMETERS: None 13214053Smpp * 13314053Smpp * RETURN: Status 13414053Smpp * 13514053Smpp * DESCRIPTION: Initialize and validate the various ACPI registers defined in 13624093Smpp * the FADT. 13724093Smpp * 13814053Smpp ******************************************************************************/ 139131504Sru 140131504SruACPI_STATUS 14114053SmppAcpiHwInitialize ( 14224093Smpp void) 14324093Smpp{ 14414053Smpp ACPI_STATUS Status; 14524093Smpp 14614053Smpp 14714053Smpp ACPI_FUNCTION_TRACE ("HwInitialize"); 14814053Smpp 14914053Smpp 15014053Smpp /* We must have the ACPI tables by the time we get here */ 15114053Smpp 15214053Smpp if (!AcpiGbl_FADT) 15314053Smpp { 15414053Smpp ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No FADT is present\n")); 15514053Smpp 15614053Smpp return_ACPI_STATUS (AE_NO_ACPI_TABLES); 15714053Smpp } 15814053Smpp 15914053Smpp /* Sanity check the FADT for valid values */ 16014053Smpp 16114053Smpp Status = AcpiUtValidateFadt (); 16270481Sru if (ACPI_FAILURE (Status)) 16314053Smpp { 16414053Smpp return_ACPI_STATUS (Status); 16514053Smpp } 16614053Smpp 16714053Smpp return_ACPI_STATUS (AE_OK); 16814053Smpp} 16914053Smpp 17014053Smpp 17114053Smpp/****************************************************************************** 17214053Smpp * 17314053Smpp * FUNCTION: AcpiHwSetMode 174108030Sru * 17514053Smpp * PARAMETERS: Mode - SYS_MODE_ACPI or SYS_MODE_LEGACY 176108030Sru * 17714053Smpp * RETURN: Status 17814053Smpp * 17914053Smpp * DESCRIPTION: Transitions the system into the requested mode. 180108087Sru * 18114053Smpp ******************************************************************************/ 182108087Sru 18324093SmppACPI_STATUS 18424093SmppAcpiHwSetMode ( 18514053Smpp UINT32 Mode) 18614053Smpp{ 18714053Smpp 18824093Smpp ACPI_STATUS Status; 189108087Sru UINT32 Retry; 19014053Smpp 191108087Sru 19214053Smpp ACPI_FUNCTION_TRACE ("HwSetMode"); 19314053Smpp 19414053Smpp /* 19514053Smpp * ACPI 2.0 clarified that if SMI_CMD in FADT is zero, 19624093Smpp * system does not support mode transition. 19724093Smpp */ 19824093Smpp if (!AcpiGbl_FADT->SmiCmd) 19914053Smpp { 20031370Sbde ACPI_REPORT_ERROR (("No SMI_CMD in FADT, mode transition failed.\n")); 20114053Smpp return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); 20214053Smpp } 203108087Sru 20414053Smpp /* 205108087Sru * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE 20614053Smpp * in FADT: If it is zero, enabling or disabling is not supported. 20714053Smpp * As old systems may have used zero for mode transition, 20814053Smpp * we make sure both the numbers are zero to determine these 209147368Sru * transitions are not supported. 21014053Smpp */ 21124093Smpp if (!AcpiGbl_FADT->AcpiEnable && !AcpiGbl_FADT->AcpiDisable) 21224093Smpp { 21324093Smpp ACPI_REPORT_ERROR (( 21414053Smpp "No ACPI mode transition supported in this system (enable/disable both zero)\n")); 21570481Sru return_ACPI_STATUS (AE_OK); 21614053Smpp } 217195656Strasz 218195656Strasz switch (Mode) 219195656Strasz { 22014053Smpp case ACPI_SYS_MODE_ACPI: 22124093Smpp 22249266Smpp /* BIOS should have disabled ALL fixed and GP events */ 223 224 Status = AcpiOsWritePort (AcpiGbl_FADT->SmiCmd, 225 (UINT32) AcpiGbl_FADT->AcpiEnable, 8); 226 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Attempting to enable ACPI mode\n")); 227 break; 228 229 case ACPI_SYS_MODE_LEGACY: 230 231 /* 232 * BIOS should clear all fixed status bits and restore fixed event 233 * enable bits to default 234 */ 235 Status = AcpiOsWritePort (AcpiGbl_FADT->SmiCmd, 236 (UINT32) AcpiGbl_FADT->AcpiDisable, 8); 237 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 238 "Attempting to enable Legacy (non-ACPI) mode\n")); 239 break; 240 241 default: 242 return_ACPI_STATUS (AE_BAD_PARAMETER); 243 } 244 245 if (ACPI_FAILURE (Status)) 246 { 247 ACPI_REPORT_ERROR (("Could not write mode change, %s\n", 248 AcpiFormatException (Status))); 249 return_ACPI_STATUS (Status); 250 } 251 252 /* 253 * Some hardware takes a LONG time to switch modes. Give them 3 sec to 254 * do so, but allow faster systems to proceed more quickly. 255 */ 256 Retry = 3000; 257 while (Retry) 258 { 259 if (AcpiHwGetMode() == Mode) 260 { 261 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n", 262 Mode)); 263 return_ACPI_STATUS (AE_OK); 264 } 265 AcpiOsStall(1000); 266 Retry--; 267 } 268 269 ACPI_REPORT_ERROR (("Hardware never changed modes\n")); 270 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); 271} 272 273 274/******************************************************************************* 275 * 276 * FUNCTION: AcpiHwGetMode 277 * 278 * PARAMETERS: none 279 * 280 * RETURN: SYS_MODE_ACPI or SYS_MODE_LEGACY 281 * 282 * DESCRIPTION: Return current operating state of system. Determined by 283 * querying the SCI_EN bit. 284 * 285 ******************************************************************************/ 286 287UINT32 288AcpiHwGetMode ( 289 void) 290{ 291 ACPI_STATUS Status; 292 UINT32 Value; 293 294 295 ACPI_FUNCTION_TRACE ("HwGetMode"); 296 297 298 /* 299 * ACPI 2.0 clarified that if SMI_CMD in FADT is zero, 300 * system does not support mode transition. 301 */ 302 if (!AcpiGbl_FADT->SmiCmd) 303 { 304 return_UINT32 (ACPI_SYS_MODE_ACPI); 305 } 306 307 Status = AcpiGetRegister (ACPI_BITREG_SCI_ENABLE, &Value, ACPI_MTX_LOCK); 308 if (ACPI_FAILURE (Status)) 309 { 310 return_UINT32 (ACPI_SYS_MODE_LEGACY); 311 } 312 313 if (Value) 314 { 315 return_UINT32 (ACPI_SYS_MODE_ACPI); 316 } 317 else 318 { 319 return_UINT32 (ACPI_SYS_MODE_LEGACY); 320 } 321} 322