hwsleep.c revision 126372
171867Smsmith 271867Smsmith/****************************************************************************** 371867Smsmith * 471867Smsmith * Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface 5126372Snjl * $Revision: 65 $ 671867Smsmith * 771867Smsmith *****************************************************************************/ 871867Smsmith 971867Smsmith/****************************************************************************** 1071867Smsmith * 1171867Smsmith * 1. Copyright Notice 1271867Smsmith * 13126372Snjl * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp. 1471867Smsmith * All rights reserved. 1571867Smsmith * 1671867Smsmith * 2. License 1771867Smsmith * 1871867Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property 1971867Smsmith * rights. You may have additional license terms from the party that provided 2071867Smsmith * you this software, covering your right to use that party's intellectual 2171867Smsmith * property rights. 2271867Smsmith * 2371867Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2471867Smsmith * copy of the source code appearing in this file ("Covered Code") an 2571867Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2671867Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy, 2771867Smsmith * make derivatives, distribute, use and display any portion of the Covered 2871867Smsmith * Code in any form, with the right to sublicense such rights; and 2971867Smsmith * 3071867Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 3171867Smsmith * license (with the right to sublicense), under only those claims of Intel 3271867Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell, 3371867Smsmith * offer to sell, and import the Covered Code and derivative works thereof 3471867Smsmith * solely to the minimum extent necessary to exercise the above copyright 3571867Smsmith * license, and in no event shall the patent license extend to any additions 3671867Smsmith * to or modifications of the Original Intel Code. No other license or right 3771867Smsmith * is granted directly or by implication, estoppel or otherwise; 3871867Smsmith * 3971867Smsmith * The above copyright and patent license is granted only if the following 4071867Smsmith * conditions are met: 4171867Smsmith * 4271867Smsmith * 3. Conditions 4371867Smsmith * 4471867Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4571867Smsmith * Redistribution of source code of any substantial portion of the Covered 4671867Smsmith * Code or modification with rights to further distribute source must include 4771867Smsmith * the above Copyright Notice, the above License, this list of Conditions, 4871867Smsmith * and the following Disclaimer and Export Compliance provision. In addition, 4971867Smsmith * Licensee must cause all Covered Code to which Licensee contributes to 5071867Smsmith * contain a file documenting the changes Licensee made to create that Covered 5171867Smsmith * Code and the date of any change. Licensee must include in that file the 5271867Smsmith * documentation of any changes made by any predecessor Licensee. Licensee 5371867Smsmith * must include a prominent statement that the modification is derived, 5471867Smsmith * directly or indirectly, from Original Intel Code. 5571867Smsmith * 5671867Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5771867Smsmith * Redistribution of source code of any substantial portion of the Covered 5871867Smsmith * Code or modification without rights to further distribute source must 5971867Smsmith * include the following Disclaimer and Export Compliance provision in the 6071867Smsmith * documentation and/or other materials provided with distribution. In 6171867Smsmith * addition, Licensee may not authorize further sublicense of source of any 6271867Smsmith * portion of the Covered Code, and must include terms to the effect that the 6371867Smsmith * license from Licensee to its licensee is limited to the intellectual 6471867Smsmith * property embodied in the software Licensee provides to its licensee, and 6571867Smsmith * not to intellectual property embodied in modifications its licensee may 6671867Smsmith * make. 6771867Smsmith * 6871867Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any 6971867Smsmith * substantial portion of the Covered Code or modification must reproduce the 7071867Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance 7171867Smsmith * provision in the documentation and/or other materials provided with the 7271867Smsmith * distribution. 7371867Smsmith * 7471867Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original 7571867Smsmith * Intel Code. 7671867Smsmith * 7771867Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7871867Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or 7971867Smsmith * other dealings in products derived from or relating to the Covered Code 8071867Smsmith * without prior written authorization from Intel. 8171867Smsmith * 8271867Smsmith * 4. Disclaimer and Export Compliance 8371867Smsmith * 8471867Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8571867Smsmith * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8671867Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8771867Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8871867Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8971867Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 9071867Smsmith * PARTICULAR PURPOSE. 9171867Smsmith * 9271867Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9371867Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9471867Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9571867Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 9671867Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9771867Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9871867Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9971867Smsmith * LIMITED REMEDY. 10071867Smsmith * 10171867Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this 10271867Smsmith * software or system incorporating such software without first obtaining any 10371867Smsmith * required license or other approval from the U. S. Department of Commerce or 10471867Smsmith * any other agency or department of the United States Government. In the 10571867Smsmith * event Licensee exports any such software from the United States or 10671867Smsmith * re-exports any such software from a foreign destination, Licensee shall 10771867Smsmith * ensure that the distribution and export/re-export of the software is in 10871867Smsmith * compliance with all laws, regulations, orders, or other restrictions of the 10971867Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor 11071867Smsmith * any of its subsidiaries will export/re-export any technical data, process, 11171867Smsmith * software, or service, directly or indirectly, to any country for which the 11271867Smsmith * United States government or any agency thereof requires an export license, 11371867Smsmith * other governmental approval, or letter of assurance, without first obtaining 11471867Smsmith * such license, approval or letter. 11571867Smsmith * 11671867Smsmith *****************************************************************************/ 11771867Smsmith 11871867Smsmith#include "acpi.h" 11971867Smsmith 12077424Smsmith#define _COMPONENT ACPI_HARDWARE 12191116Smsmith ACPI_MODULE_NAME ("hwsleep") 12271867Smsmith 12371867Smsmith 124126372Snjl#define METHOD_NAME__BFS "\\_BFS" 125126372Snjl#define METHOD_NAME__GTS "\\_GTS" 126126372Snjl#define METHOD_NAME__PTS "\\_PTS" 127126372Snjl#define METHOD_NAME__SST "\\_SI._SST" 128126372Snjl#define METHOD_NAME__WAK "\\_WAK" 129126372Snjl 130126372Snjl#define ACPI_SST_INDICATOR_OFF 0 131126372Snjl#define ACPI_SST_WORKING 1 132126372Snjl#define ACPI_SST_WAKING 2 133126372Snjl#define ACPI_SST_SLEEPING 3 134126372Snjl#define ACPI_SST_SLEEP_CONTEXT 4 135126372Snjl 136126372Snjl 13771867Smsmith/****************************************************************************** 13871867Smsmith * 13971867Smsmith * FUNCTION: AcpiSetFirmwareWakingVector 14071867Smsmith * 14171867Smsmith * PARAMETERS: PhysicalAddress - Physical address of ACPI real mode 14271867Smsmith * entry point. 14371867Smsmith * 14491116Smsmith * RETURN: Status 14571867Smsmith * 14671867Smsmith * DESCRIPTION: Access function for dFirmwareWakingVector field in FACS 14771867Smsmith * 14871867Smsmith ******************************************************************************/ 14971867Smsmith 15071867SmsmithACPI_STATUS 15171867SmsmithAcpiSetFirmwareWakingVector ( 15271867Smsmith ACPI_PHYSICAL_ADDRESS PhysicalAddress) 15371867Smsmith{ 15471867Smsmith 15591116Smsmith ACPI_FUNCTION_TRACE ("AcpiSetFirmwareWakingVector"); 15671867Smsmith 15771867Smsmith 15871867Smsmith /* Set the vector */ 15971867Smsmith 16091116Smsmith if (AcpiGbl_CommonFACS.VectorWidth == 32) 16171867Smsmith { 162102550Siwasaki *(ACPI_CAST_PTR (UINT32, AcpiGbl_CommonFACS.FirmwareWakingVector)) 16399679Siwasaki = (UINT32) PhysicalAddress; 16471867Smsmith } 16571867Smsmith else 16671867Smsmith { 167102550Siwasaki *AcpiGbl_CommonFACS.FirmwareWakingVector 16899679Siwasaki = PhysicalAddress; 16971867Smsmith } 17071867Smsmith 17171867Smsmith return_ACPI_STATUS (AE_OK); 17271867Smsmith} 17371867Smsmith 17471867Smsmith 17571867Smsmith/****************************************************************************** 17671867Smsmith * 17771867Smsmith * FUNCTION: AcpiGetFirmwareWakingVector 17871867Smsmith * 17971867Smsmith * PARAMETERS: *PhysicalAddress - Output buffer where contents of 18071867Smsmith * the FirmwareWakingVector field of 18171867Smsmith * the FACS will be stored. 18271867Smsmith * 18371867Smsmith * RETURN: Status 18471867Smsmith * 18591116Smsmith * DESCRIPTION: Access function for FirmwareWakingVector field in FACS 18671867Smsmith * 18771867Smsmith ******************************************************************************/ 18871867Smsmith 18971867SmsmithACPI_STATUS 19071867SmsmithAcpiGetFirmwareWakingVector ( 19171867Smsmith ACPI_PHYSICAL_ADDRESS *PhysicalAddress) 19271867Smsmith{ 19371867Smsmith 19491116Smsmith ACPI_FUNCTION_TRACE ("AcpiGetFirmwareWakingVector"); 19571867Smsmith 19671867Smsmith 19771867Smsmith if (!PhysicalAddress) 19871867Smsmith { 19971867Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 20071867Smsmith } 20171867Smsmith 20271867Smsmith /* Get the vector */ 20371867Smsmith 20491116Smsmith if (AcpiGbl_CommonFACS.VectorWidth == 32) 20571867Smsmith { 206102550Siwasaki *PhysicalAddress = (ACPI_PHYSICAL_ADDRESS) 20799679Siwasaki *(ACPI_CAST_PTR (UINT32, AcpiGbl_CommonFACS.FirmwareWakingVector)); 20871867Smsmith } 20971867Smsmith else 21071867Smsmith { 211102550Siwasaki *PhysicalAddress = 21299679Siwasaki *AcpiGbl_CommonFACS.FirmwareWakingVector; 21371867Smsmith } 21471867Smsmith 21571867Smsmith return_ACPI_STATUS (AE_OK); 21671867Smsmith} 21771867Smsmith 21887031Smsmith 21971867Smsmith/****************************************************************************** 22071867Smsmith * 22187031Smsmith * FUNCTION: AcpiEnterSleepStatePrep 22271867Smsmith * 22371867Smsmith * PARAMETERS: SleepState - Which sleep state to enter 22471867Smsmith * 22571867Smsmith * RETURN: Status 22671867Smsmith * 22787031Smsmith * DESCRIPTION: Prepare to enter a system sleep state (see ACPI 2.0 spec p 231) 22887031Smsmith * This function must execute with interrupts enabled. 22987031Smsmith * We break sleeping into 2 stages so that OSPM can handle 23087031Smsmith * various OS-specific tasks between the two steps. 23171867Smsmith * 23271867Smsmith ******************************************************************************/ 23371867Smsmith 23471867SmsmithACPI_STATUS 23587031SmsmithAcpiEnterSleepStatePrep ( 23677424Smsmith UINT8 SleepState) 23771867Smsmith{ 23877424Smsmith ACPI_STATUS Status; 23977424Smsmith ACPI_OBJECT_LIST ArgList; 24077424Smsmith ACPI_OBJECT Arg; 24171867Smsmith 24277424Smsmith 24391116Smsmith ACPI_FUNCTION_TRACE ("AcpiEnterSleepStatePrep"); 24491116Smsmith 24591116Smsmith 24671867Smsmith /* 24771867Smsmith * _PSW methods could be run here to enable wake-on keyboard, LAN, etc. 24871867Smsmith */ 24999679Siwasaki Status = AcpiGetSleepTypeData (SleepState, 25091116Smsmith &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB); 25191116Smsmith if (ACPI_FAILURE (Status)) 25271867Smsmith { 25387031Smsmith return_ACPI_STATUS (Status); 25471867Smsmith } 25571867Smsmith 25691116Smsmith /* Setup parameter object */ 25777424Smsmith 25871867Smsmith ArgList.Count = 1; 25971867Smsmith ArgList.Pointer = &Arg; 26071867Smsmith 26171867Smsmith Arg.Type = ACPI_TYPE_INTEGER; 26271867Smsmith Arg.Integer.Value = SleepState; 26371867Smsmith 26491116Smsmith /* Run the _PTS and _GTS methods */ 26577424Smsmith 266126372Snjl Status = AcpiEvaluateObject (NULL, METHOD_NAME__PTS, &ArgList, NULL); 26791116Smsmith if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 26891116Smsmith { 26991116Smsmith return_ACPI_STATUS (Status); 27091116Smsmith } 27191116Smsmith 272126372Snjl Status = AcpiEvaluateObject (NULL, METHOD_NAME__GTS, &ArgList, NULL); 27391116Smsmith if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 27491116Smsmith { 27591116Smsmith return_ACPI_STATUS (Status); 27691116Smsmith } 27791116Smsmith 278126372Snjl /* Setup the argument to _SST */ 279126372Snjl 280126372Snjl switch (SleepState) 281126372Snjl { 282126372Snjl case ACPI_STATE_S0: 283126372Snjl Arg.Integer.Value = ACPI_SST_WORKING; 284126372Snjl break; 285126372Snjl 286126372Snjl case ACPI_STATE_S1: 287126372Snjl case ACPI_STATE_S2: 288126372Snjl case ACPI_STATE_S3: 289126372Snjl Arg.Integer.Value = ACPI_SST_SLEEPING; 290126372Snjl break; 291126372Snjl 292126372Snjl case ACPI_STATE_S4: 293126372Snjl Arg.Integer.Value = ACPI_SST_SLEEP_CONTEXT; 294126372Snjl break; 295126372Snjl 296126372Snjl default: 297126372Snjl Arg.Integer.Value = ACPI_SST_INDICATOR_OFF; /* Default is indicator off */ 298126372Snjl break; 299126372Snjl } 300126372Snjl 301123315Snjl /* Set the system indicators to show the desired sleep state. */ 302123315Snjl 303126372Snjl Status = AcpiEvaluateObject (NULL, METHOD_NAME__SST, &ArgList, NULL); 304123315Snjl if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 305123315Snjl { 306123315Snjl ACPI_REPORT_ERROR (("Method _SST failed, %s\n", AcpiFormatException (Status))); 307123315Snjl } 308123315Snjl 30987031Smsmith return_ACPI_STATUS (AE_OK); 31087031Smsmith} 31187031Smsmith 31287031Smsmith 31387031Smsmith/****************************************************************************** 31487031Smsmith * 31587031Smsmith * FUNCTION: AcpiEnterSleepState 31687031Smsmith * 31787031Smsmith * PARAMETERS: SleepState - Which sleep state to enter 31887031Smsmith * 31987031Smsmith * RETURN: Status 32087031Smsmith * 32187031Smsmith * DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231) 32287031Smsmith * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED 32387031Smsmith * 32487031Smsmith ******************************************************************************/ 32587031Smsmith 32687031SmsmithACPI_STATUS 32787031SmsmithAcpiEnterSleepState ( 32891116Smsmith UINT8 SleepState) 32987031Smsmith{ 33099679Siwasaki UINT32 PM1AControl; 33199679Siwasaki UINT32 PM1BControl; 33291116Smsmith ACPI_BIT_REGISTER_INFO *SleepTypeRegInfo; 33391116Smsmith ACPI_BIT_REGISTER_INFO *SleepEnableRegInfo; 33499679Siwasaki UINT32 InValue; 33599679Siwasaki ACPI_STATUS Status; 33687031Smsmith 33787031Smsmith 33891116Smsmith ACPI_FUNCTION_TRACE ("AcpiEnterSleepState"); 33987031Smsmith 34091116Smsmith 34191116Smsmith if ((AcpiGbl_SleepTypeA > ACPI_SLEEP_TYPE_MAX) || 34291116Smsmith (AcpiGbl_SleepTypeB > ACPI_SLEEP_TYPE_MAX)) 34387031Smsmith { 34499679Siwasaki ACPI_REPORT_ERROR (("Sleep values out of range: A=%X B=%X\n", 34591116Smsmith AcpiGbl_SleepTypeA, AcpiGbl_SleepTypeB)); 34691116Smsmith return_ACPI_STATUS (AE_AML_OPERAND_VALUE); 34787031Smsmith } 34887031Smsmith 34991116Smsmith SleepTypeRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_TYPE_A); 35091116Smsmith SleepEnableRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_ENABLE); 35171867Smsmith 352123315Snjl if (SleepState != ACPI_STATE_S5) 35399679Siwasaki { 354123315Snjl /* Clear wake status */ 35578986Smsmith 356123315Snjl Status = AcpiSetRegister (ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK); 357123315Snjl if (ACPI_FAILURE (Status)) 358123315Snjl { 359123315Snjl return_ACPI_STATUS (Status); 360123315Snjl } 36187031Smsmith 362123315Snjl Status = AcpiHwClearAcpiStatus (ACPI_MTX_DO_NOT_LOCK); 363123315Snjl if (ACPI_FAILURE (Status)) 364123315Snjl { 365123315Snjl return_ACPI_STATUS (Status); 366123315Snjl } 36771867Smsmith 368123315Snjl /* Disable BM arbitration */ 369123315Snjl 370123315Snjl Status = AcpiSetRegister (ACPI_BITREG_ARB_DISABLE, 1, ACPI_MTX_DO_NOT_LOCK); 371123315Snjl if (ACPI_FAILURE (Status)) 372123315Snjl { 373123315Snjl return_ACPI_STATUS (Status); 374123315Snjl } 37599679Siwasaki } 37699679Siwasaki 377126372Snjl Status = AcpiHwDisableNonWakeupGpes (); 37899679Siwasaki if (ACPI_FAILURE (Status)) 37999679Siwasaki { 38099679Siwasaki return_ACPI_STATUS (Status); 38199679Siwasaki } 38299679Siwasaki 38391116Smsmith /* Get current value of PM1A control */ 38478986Smsmith 385114237Snjl Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_CONTROL, &PM1AControl); 38699679Siwasaki if (ACPI_FAILURE (Status)) 38799679Siwasaki { 38899679Siwasaki return_ACPI_STATUS (Status); 38999679Siwasaki } 390114237Snjl ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Entering sleep state [S%d]\n", SleepState)); 39182367Smsmith 39291116Smsmith /* Clear SLP_EN and SLP_TYP fields */ 39382367Smsmith 39491116Smsmith PM1AControl &= ~(SleepTypeRegInfo->AccessBitMask | SleepEnableRegInfo->AccessBitMask); 39571867Smsmith PM1BControl = PM1AControl; 39671867Smsmith 39791116Smsmith /* Insert SLP_TYP bits */ 39882367Smsmith 39991116Smsmith PM1AControl |= (AcpiGbl_SleepTypeA << SleepTypeRegInfo->BitPosition); 40091116Smsmith PM1BControl |= (AcpiGbl_SleepTypeB << SleepTypeRegInfo->BitPosition); 40171867Smsmith 402126372Snjl /* 403126372Snjl * We split the writes of SLP_TYP and SLP_EN to workaround 404126372Snjl * poorly implemented hardware. 405126372Snjl */ 406126372Snjl 40791116Smsmith /* Write #1: fill in SLP_TYP data */ 40871867Smsmith 409114237Snjl Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1AControl); 41099679Siwasaki if (ACPI_FAILURE (Status)) 41199679Siwasaki { 41299679Siwasaki return_ACPI_STATUS (Status); 41399679Siwasaki } 41482367Smsmith 415114237Snjl Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1BControl); 41699679Siwasaki if (ACPI_FAILURE (Status)) 41799679Siwasaki { 41899679Siwasaki return_ACPI_STATUS (Status); 41999679Siwasaki } 42099679Siwasaki 42191116Smsmith /* Insert SLP_ENABLE bit */ 42282367Smsmith 42391116Smsmith PM1AControl |= SleepEnableRegInfo->AccessBitMask; 42491116Smsmith PM1BControl |= SleepEnableRegInfo->AccessBitMask; 42571867Smsmith 42691116Smsmith /* Write #2: SLP_TYP + SLP_EN */ 42771867Smsmith 42899679Siwasaki ACPI_FLUSH_CPU_CACHE (); 42980062Smsmith 430114237Snjl Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1AControl); 43199679Siwasaki if (ACPI_FAILURE (Status)) 43299679Siwasaki { 43399679Siwasaki return_ACPI_STATUS (Status); 43499679Siwasaki } 43599679Siwasaki 436114237Snjl Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1BControl); 43799679Siwasaki if (ACPI_FAILURE (Status)) 43899679Siwasaki { 43999679Siwasaki return_ACPI_STATUS (Status); 44099679Siwasaki } 44199679Siwasaki 44282367Smsmith if (SleepState > ACPI_STATE_S3) 44382367Smsmith { 44499679Siwasaki /* 445123315Snjl * We wanted to sleep > S3, but it didn't happen (by virtue of the fact that 446123315Snjl * we are still executing!) 447123315Snjl * 448123315Snjl * Wait ten seconds, then try again. This is to get S4/S5 to work on all machines. 449123315Snjl * 45099679Siwasaki * We wait so long to allow chipsets that poll this reg very slowly to 451126372Snjl * still read the right value. Ideally, this block would go 45299679Siwasaki * away entirely. 45399679Siwasaki */ 45499679Siwasaki AcpiOsStall (10000000); 45582367Smsmith 456114237Snjl Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_CONTROL, 45799679Siwasaki SleepEnableRegInfo->AccessBitMask); 45899679Siwasaki if (ACPI_FAILURE (Status)) 45999679Siwasaki { 46099679Siwasaki return_ACPI_STATUS (Status); 46199679Siwasaki } 46280357Speter } 46380062Smsmith 46491116Smsmith /* Wait until we enter sleep state */ 46571867Smsmith 466102550Siwasaki do 46783174Smsmith { 468114237Snjl Status = AcpiGetRegister (ACPI_BITREG_WAKE_STATUS, &InValue, ACPI_MTX_DO_NOT_LOCK); 46999679Siwasaki if (ACPI_FAILURE (Status)) 47099679Siwasaki { 47199679Siwasaki return_ACPI_STATUS (Status); 47299679Siwasaki } 47399679Siwasaki 47491116Smsmith /* Spin until we wake */ 47582367Smsmith 47699679Siwasaki } while (!InValue); 47799679Siwasaki 47871867Smsmith return_ACPI_STATUS (AE_OK); 47971867Smsmith} 48082367Smsmith 481114237Snjl 48282367Smsmith/****************************************************************************** 48382367Smsmith * 484114237Snjl * FUNCTION: AcpiEnterSleepStateS4bios 485114237Snjl * 486114237Snjl * PARAMETERS: None 487114237Snjl * 488114237Snjl * RETURN: Status 489114237Snjl * 490114237Snjl * DESCRIPTION: Perform a S4 bios request. 491114237Snjl * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED 492114237Snjl * 493114237Snjl ******************************************************************************/ 494114237Snjl 495114237SnjlACPI_STATUS 496114237SnjlAcpiEnterSleepStateS4bios ( 497114237Snjl void) 498114237Snjl{ 499114237Snjl UINT32 InValue; 500114237Snjl ACPI_STATUS Status; 501114237Snjl 502114237Snjl 503114237Snjl ACPI_FUNCTION_TRACE ("AcpiEnterSleepStateS4bios"); 504114237Snjl 505123315Snjl 506126372Snjl Status = AcpiSetRegister (ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK); 507126372Snjl if (ACPI_FAILURE (Status)) 508126372Snjl { 509126372Snjl return_ACPI_STATUS (Status); 510126372Snjl } 511114237Snjl 512126372Snjl Status = AcpiHwClearAcpiStatus (ACPI_MTX_DO_NOT_LOCK); 513126372Snjl if (ACPI_FAILURE (Status)) 514126372Snjl { 515126372Snjl return_ACPI_STATUS (Status); 516126372Snjl } 517114237Snjl 518126372Snjl Status = AcpiHwDisableNonWakeupGpes (); 519126372Snjl if (ACPI_FAILURE (Status)) 520126372Snjl { 521126372Snjl return_ACPI_STATUS (Status); 522126372Snjl } 523114237Snjl 524126372Snjl ACPI_FLUSH_CPU_CACHE (); 525126372Snjl 526117521Snjl Status = AcpiOsWritePort (AcpiGbl_FADT->SmiCmd, (UINT32) AcpiGbl_FADT->S4BiosReq, 8); 527114237Snjl 528114237Snjl do { 529114237Snjl AcpiOsStall(1000); 530114237Snjl Status = AcpiGetRegister (ACPI_BITREG_WAKE_STATUS, &InValue, ACPI_MTX_DO_NOT_LOCK); 531114237Snjl if (ACPI_FAILURE (Status)) 532114237Snjl { 533114237Snjl return_ACPI_STATUS (Status); 534114237Snjl } 535114237Snjl } while (!InValue); 536114237Snjl 537114237Snjl return_ACPI_STATUS (AE_OK); 538114237Snjl} 539114237Snjl 540114237Snjl 541114237Snjl/****************************************************************************** 542114237Snjl * 54382367Smsmith * FUNCTION: AcpiLeaveSleepState 54482367Smsmith * 54582367Smsmith * PARAMETERS: SleepState - Which sleep state we just exited 54682367Smsmith * 54782367Smsmith * RETURN: Status 54882367Smsmith * 54982367Smsmith * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep 55082367Smsmith * 55182367Smsmith ******************************************************************************/ 55282367Smsmith 55382367SmsmithACPI_STATUS 55482367SmsmithAcpiLeaveSleepState ( 555123315Snjl UINT8 SleepState) 55682367Smsmith{ 557123315Snjl ACPI_OBJECT_LIST ArgList; 558123315Snjl ACPI_OBJECT Arg; 559123315Snjl ACPI_STATUS Status; 560123315Snjl ACPI_BIT_REGISTER_INFO *SleepTypeRegInfo; 561123315Snjl ACPI_BIT_REGISTER_INFO *SleepEnableRegInfo; 562126372Snjl UINT32 PM1AControl; 563126372Snjl UINT32 PM1BControl; 56482367Smsmith 56583174Smsmith 56691116Smsmith ACPI_FUNCTION_TRACE ("AcpiLeaveSleepState"); 56782367Smsmith 56891116Smsmith 569126372Snjl /* 570126372Snjl * Set SLP_TYPE and SLP_EN to state S0. 571126372Snjl * This is unclear from the ACPI Spec, but it is required 572126372Snjl * by some machines. 573126372Snjl */ 574126372Snjl Status = AcpiGetSleepTypeData (ACPI_STATE_S0, 575126372Snjl &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB); 576123315Snjl if (ACPI_SUCCESS (Status)) 577123315Snjl { 578126372Snjl SleepTypeRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_TYPE_A); 579126372Snjl SleepEnableRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_ENABLE); 580123315Snjl 581126372Snjl /* Get current value of PM1A control */ 582123315Snjl 583126372Snjl Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK, 584126372Snjl ACPI_REGISTER_PM1_CONTROL, &PM1AControl); 585126372Snjl if (ACPI_SUCCESS (Status)) 586126372Snjl { 587126372Snjl /* Clear SLP_EN and SLP_TYP fields */ 588126372Snjl 589126372Snjl PM1AControl &= ~(SleepTypeRegInfo->AccessBitMask | 590126372Snjl SleepEnableRegInfo->AccessBitMask); 591126372Snjl PM1BControl = PM1AControl; 592126372Snjl 593126372Snjl /* Insert SLP_TYP bits */ 594126372Snjl 595126372Snjl PM1AControl |= (AcpiGbl_SleepTypeA << SleepTypeRegInfo->BitPosition); 596126372Snjl PM1BControl |= (AcpiGbl_SleepTypeB << SleepTypeRegInfo->BitPosition); 597126372Snjl 598126372Snjl /* Just ignore any errors */ 599126372Snjl 600126372Snjl (void) AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 601126372Snjl ACPI_REGISTER_PM1A_CONTROL, PM1AControl); 602126372Snjl (void) AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 603126372Snjl ACPI_REGISTER_PM1B_CONTROL, PM1BControl); 604126372Snjl } 605123315Snjl } 606123315Snjl 60787031Smsmith /* Ensure EnterSleepStatePrep -> EnterSleepState ordering */ 60882367Smsmith 60991116Smsmith AcpiGbl_SleepTypeA = ACPI_SLEEP_TYPE_INVALID; 61091116Smsmith 61191116Smsmith /* Setup parameter object */ 61291116Smsmith 61382367Smsmith ArgList.Count = 1; 61482367Smsmith ArgList.Pointer = &Arg; 61582367Smsmith Arg.Type = ACPI_TYPE_INTEGER; 61682367Smsmith 61791116Smsmith /* Ignore any errors from these methods */ 61883174Smsmith 619126372Snjl Arg.Integer.Value = ACPI_SST_WAKING; 620126372Snjl Status = AcpiEvaluateObject (NULL, METHOD_NAME__SST, &ArgList, NULL); 621123315Snjl if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 622123315Snjl { 623123315Snjl ACPI_REPORT_ERROR (("Method _SST failed, %s\n", AcpiFormatException (Status))); 624123315Snjl } 625123315Snjl 626123315Snjl Arg.Integer.Value = SleepState; 627126372Snjl Status = AcpiEvaluateObject (NULL, METHOD_NAME__BFS, &ArgList, NULL); 62891116Smsmith if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 62991116Smsmith { 63091116Smsmith ACPI_REPORT_ERROR (("Method _BFS failed, %s\n", AcpiFormatException (Status))); 63191116Smsmith } 63291116Smsmith 633126372Snjl Status = AcpiEvaluateObject (NULL, METHOD_NAME__WAK, &ArgList, NULL); 63491116Smsmith if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 63591116Smsmith { 63691116Smsmith ACPI_REPORT_ERROR (("Method _WAK failed, %s\n", AcpiFormatException (Status))); 63791116Smsmith } 63891116Smsmith 63982367Smsmith /* _WAK returns stuff - do we want to look at it? */ 64082367Smsmith 641126372Snjl Status = AcpiHwEnableNonWakeupGpes (); 64299679Siwasaki if (ACPI_FAILURE (Status)) 64399679Siwasaki { 64499679Siwasaki return_ACPI_STATUS (Status); 64599679Siwasaki } 64682367Smsmith 647126372Snjl /* Enable power button */ 648126372Snjl 649126372Snjl AcpiSetRegister(AcpiGbl_FixedEventInfo[ACPI_EVENT_POWER_BUTTON].EnableRegisterId, 650126372Snjl 1, ACPI_MTX_DO_NOT_LOCK); 651126372Snjl AcpiSetRegister(AcpiGbl_FixedEventInfo[ACPI_EVENT_POWER_BUTTON].StatusRegisterId, 652126372Snjl 1, ACPI_MTX_DO_NOT_LOCK); 653126372Snjl 654123315Snjl /* Enable BM arbitration */ 655123315Snjl 65699679Siwasaki Status = AcpiSetRegister (ACPI_BITREG_ARB_DISABLE, 0, ACPI_MTX_LOCK); 657126372Snjl if (ACPI_FAILURE (Status)) 658126372Snjl { 659126372Snjl return_ACPI_STATUS (Status); 660126372Snjl } 661126372Snjl 662126372Snjl Arg.Integer.Value = ACPI_SST_WORKING; 663126372Snjl Status = AcpiEvaluateObject (NULL, METHOD_NAME__SST, &ArgList, NULL); 664126372Snjl if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 665126372Snjl { 666126372Snjl ACPI_REPORT_ERROR (("Method _SST failed, %s\n", AcpiFormatException (Status))); 667126372Snjl } 668126372Snjl 66999679Siwasaki return_ACPI_STATUS (Status); 67082367Smsmith} 671