hwsleep.c revision 99679
10SN/A 216536Sssadetsky/****************************************************************************** 30SN/A * 40SN/A * Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface 50SN/A * $Revision: 45 $ 60SN/A * 72362SN/A *****************************************************************************/ 80SN/A 92362SN/A/****************************************************************************** 100SN/A * 110SN/A * 1. Copyright Notice 120SN/A * 130SN/A * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp. 140SN/A * All rights reserved. 150SN/A * 160SN/A * 2. License 170SN/A * 180SN/A * 2.1. This is your license from Intel Corp. under its intellectual property 190SN/A * rights. You may have additional license terms from the party that provided 200SN/A * you this software, covering your right to use that party's intellectual 212362SN/A * property rights. 222362SN/A * 232362SN/A * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 240SN/A * copy of the source code appearing in this file ("Covered Code") an 250SN/A * irrevocable, perpetual, worldwide license under Intel's copyrights in the 260SN/A * base code distributed originally by Intel ("Original Intel Code") to copy, 270SN/A * make derivatives, distribute, use and display any portion of the Covered 280SN/A * Code in any form, with the right to sublicense such rights; and 290SN/A * 300SN/A * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 310SN/A * license (with the right to sublicense), under only those claims of Intel 321696SN/A * patents that are infringed by the Original Intel Code, to make, use, sell, 335768SN/A * offer to sell, and import the Covered Code and derivative works thereof 340SN/A * solely to the minimum extent necessary to exercise the above copyright 350SN/A * license, and in no event shall the patent license extend to any additions 360SN/A * to or modifications of the Original Intel Code. No other license or right 370SN/A * is granted directly or by implication, estoppel or otherwise; 380SN/A * 390SN/A * The above copyright and patent license is granted only if the following 400SN/A * conditions are met: 410SN/A * 420SN/A * 3. Conditions 431696SN/A * 440SN/A * 3.1. Redistribution of Source with Rights to Further Distribute Source. 450SN/A * Redistribution of source code of any substantial portion of the Covered 460SN/A * Code or modification with rights to further distribute source must include 470SN/A * the above Copyright Notice, the above License, this list of Conditions, 480SN/A * and the following Disclaimer and Export Compliance provision. In addition, 490SN/A * Licensee must cause all Covered Code to which Licensee contributes to 500SN/A * contain a file documenting the changes Licensee made to create that Covered 510SN/A * Code and the date of any change. Licensee must include in that file the 520SN/A * documentation of any changes made by any predecessor Licensee. Licensee 530SN/A * must include a prominent statement that the modification is derived, 540SN/A * directly or indirectly, from Original Intel Code. 550SN/A * 560SN/A * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 570SN/A * Redistribution of source code of any substantial portion of the Covered 580SN/A * Code or modification without rights to further distribute source must 5912839Sprr * include the following Disclaimer and Export Compliance provision in the 6012839Sprr * documentation and/or other materials provided with distribution. In 6112839Sprr * addition, Licensee may not authorize further sublicense of source of any 6212839Sprr * portion of the Covered Code, and must include terms to the effect that the 6312839Sprr * license from Licensee to its licensee is limited to the intellectual 6412839Sprr * property embodied in the software Licensee provides to its licensee, and 6512839Sprr * not to intellectual property embodied in modifications its licensee may 6612839Sprr * make. 6712839Sprr * 680SN/A * 3.3. Redistribution of Executable. Redistribution in executable form of any 690SN/A * substantial portion of the Covered Code or modification must reproduce the 700SN/A * above Copyright Notice, and the following Disclaimer and Export Compliance 710SN/A * provision in the documentation and/or other materials provided with the 720SN/A * distribution. 730SN/A * 740SN/A * 3.4. Intel retains all right, title, and interest in and to the Original 750SN/A * Intel Code. 760SN/A * 770SN/A * 3.5. Neither the name Intel nor any other trademark owned or controlled by 780SN/A * Intel shall be used in advertising or otherwise to promote the sale, use or 790SN/A * other dealings in products derived from or relating to the Covered Code 800SN/A * without prior written authorization from Intel. 810SN/A * 820SN/A * 4. Disclaimer and Export Compliance 830SN/A * 840SN/A * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 850SN/A * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 860SN/A * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 870SN/A * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 880SN/A * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 890SN/A * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 900SN/A * PARTICULAR PURPOSE. 910SN/A * 920SN/A * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 930SN/A * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 940SN/A * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 950SN/A * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 960SN/A * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 970SN/A * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 980SN/A * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 990SN/A * LIMITED REMEDY. 1000SN/A * 1010SN/A * 4.3. Licensee shall not export, either directly or indirectly, any of this 1020SN/A * software or system incorporating such software without first obtaining any 1030SN/A * required license or other approval from the U. S. Department of Commerce or 1040SN/A * any other agency or department of the United States Government. In the 1050SN/A * event Licensee exports any such software from the United States or 1060SN/A * re-exports any such software from a foreign destination, Licensee shall 1070SN/A * ensure that the distribution and export/re-export of the software is in 1080SN/A * compliance with all laws, regulations, orders, or other restrictions of the 1090SN/A * U.S. Export Administration Regulations. Licensee agrees that neither it nor 1100SN/A * any of its subsidiaries will export/re-export any technical data, process, 1110SN/A * software, or service, directly or indirectly, to any country for which the 1120SN/A * United States government or any agency thereof requires an export license, 1130SN/A * other governmental approval, or letter of assurance, without first obtaining 1140SN/A * such license, approval or letter. 1150SN/A * 1160SN/A *****************************************************************************/ 1170SN/A 1180SN/A#include "acpi.h" 1190SN/A 1200SN/A#define _COMPONENT ACPI_HARDWARE 1210SN/A ACPI_MODULE_NAME ("hwsleep") 1220SN/A 1230SN/A 1240SN/A/****************************************************************************** 1250SN/A * 1260SN/A * FUNCTION: AcpiSetFirmwareWakingVector 1270SN/A * 1280SN/A * PARAMETERS: PhysicalAddress - Physical address of ACPI real mode 1290SN/A * entry point. 1300SN/A * 1310SN/A * RETURN: Status 1320SN/A * 1330SN/A * DESCRIPTION: Access function for dFirmwareWakingVector field in FACS 1340SN/A * 1350SN/A ******************************************************************************/ 1360SN/A 1370SN/AACPI_STATUS 1380SN/AAcpiSetFirmwareWakingVector ( 1390SN/A ACPI_PHYSICAL_ADDRESS PhysicalAddress) 1400SN/A{ 1410SN/A 1420SN/A ACPI_FUNCTION_TRACE ("AcpiSetFirmwareWakingVector"); 1430SN/A 1440SN/A 1450SN/A /* Set the vector */ 1460SN/A 1470SN/A if (AcpiGbl_CommonFACS.VectorWidth == 32) 1480SN/A { 1490SN/A *(ACPI_CAST_PTR (UINT32, AcpiGbl_CommonFACS.FirmwareWakingVector)) 1500SN/A = (UINT32) PhysicalAddress; 1510SN/A } 1520SN/A else 1530SN/A { 1540SN/A *AcpiGbl_CommonFACS.FirmwareWakingVector 1550SN/A = PhysicalAddress; 1560SN/A } 1570SN/A 1580SN/A return_ACPI_STATUS (AE_OK); 1590SN/A} 1600SN/A 1610SN/A 1620SN/A/****************************************************************************** 1630SN/A * 1640SN/A * FUNCTION: AcpiGetFirmwareWakingVector 1650SN/A * 1660SN/A * PARAMETERS: *PhysicalAddress - Output buffer where contents of 16711926Sserb * the FirmwareWakingVector field of 1680SN/A * the FACS will be stored. 1690SN/A * 1700SN/A * RETURN: Status 1710SN/A * 1720SN/A * DESCRIPTION: Access function for FirmwareWakingVector field in FACS 1730SN/A * 1740SN/A ******************************************************************************/ 1750SN/A 1760SN/AACPI_STATUS 1770SN/AAcpiGetFirmwareWakingVector ( 1780SN/A ACPI_PHYSICAL_ADDRESS *PhysicalAddress) 1790SN/A{ 1800SN/A 1810SN/A ACPI_FUNCTION_TRACE ("AcpiGetFirmwareWakingVector"); 1820SN/A 1830SN/A 18411926Sserb if (!PhysicalAddress) 1850SN/A { 1860SN/A return_ACPI_STATUS (AE_BAD_PARAMETER); 1870SN/A } 1880SN/A 1890SN/A /* Get the vector */ 1900SN/A 1910SN/A if (AcpiGbl_CommonFACS.VectorWidth == 32) 1920SN/A { 1930SN/A *PhysicalAddress = (ACPI_PHYSICAL_ADDRESS) 1940SN/A *(ACPI_CAST_PTR (UINT32, AcpiGbl_CommonFACS.FirmwareWakingVector)); 1950SN/A } 1960SN/A else 1975768SN/A { 1989970SN/A *PhysicalAddress = 1999970SN/A *AcpiGbl_CommonFACS.FirmwareWakingVector; 2005768SN/A } 2019970SN/A 2025768SN/A return_ACPI_STATUS (AE_OK); 2030SN/A} 2040SN/A 2050SN/A 2060SN/A/****************************************************************************** 2070SN/A * 2080SN/A * FUNCTION: AcpiEnterSleepStatePrep 2090SN/A * 2100SN/A * PARAMETERS: SleepState - Which sleep state to enter 2110SN/A * 2120SN/A * RETURN: Status 2130SN/A * 2140SN/A * DESCRIPTION: Prepare to enter a system sleep state (see ACPI 2.0 spec p 231) 2150SN/A * This function must execute with interrupts enabled. 2160SN/A * We break sleeping into 2 stages so that OSPM can handle 2170SN/A * various OS-specific tasks between the two steps. 2180SN/A * 2190SN/A ******************************************************************************/ 2200SN/A 2210SN/AACPI_STATUS 2220SN/AAcpiEnterSleepStatePrep ( 2230SN/A UINT8 SleepState) 2240SN/A{ 22512116Sserb ACPI_STATUS Status; 2260SN/A ACPI_OBJECT_LIST ArgList; 2270SN/A ACPI_OBJECT Arg; 2280SN/A 2290SN/A 2300SN/A ACPI_FUNCTION_TRACE ("AcpiEnterSleepStatePrep"); 2310SN/A 2320SN/A 2330SN/A /* 2340SN/A * _PSW methods could be run here to enable wake-on keyboard, LAN, etc. 2350SN/A */ 2360SN/A Status = AcpiGetSleepTypeData (SleepState, 2370SN/A &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB); 2380SN/A if (ACPI_FAILURE (Status)) 2390SN/A { 2400SN/A return_ACPI_STATUS (Status); 2410SN/A } 2420SN/A 2430SN/A /* Setup parameter object */ 2440SN/A 2450SN/A ArgList.Count = 1; 2460SN/A ArgList.Pointer = &Arg; 2470SN/A 2480SN/A Arg.Type = ACPI_TYPE_INTEGER; 2490SN/A Arg.Integer.Value = SleepState; 2500SN/A 25116536Sssadetsky /* Run the _PTS and _GTS methods */ 25216536Sssadetsky 25316536Sssadetsky Status = AcpiEvaluateObject (NULL, "\\_PTS", &ArgList, NULL); 25416536Sssadetsky if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 25516536Sssadetsky { 2560SN/A return_ACPI_STATUS (Status); 2570SN/A } 2580SN/A 2590SN/A Status = AcpiEvaluateObject (NULL, "\\_GTS", &ArgList, NULL); 2600SN/A if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 2610SN/A { 2620SN/A return_ACPI_STATUS (Status); 2630SN/A } 2640SN/A 26516536Sssadetsky return_ACPI_STATUS (AE_OK); 26616536Sssadetsky} 26716536Sssadetsky 2680SN/A 2690SN/A/****************************************************************************** 2700SN/A * 2710SN/A * FUNCTION: AcpiEnterSleepState 2720SN/A * 2730SN/A * PARAMETERS: SleepState - Which sleep state to enter 2740SN/A * 2750SN/A * RETURN: Status 2760SN/A * 2770SN/A * DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231) 2780SN/A * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED 2790SN/A * 2800SN/A ******************************************************************************/ 2810SN/A 2820SN/AACPI_STATUS 2830SN/AAcpiEnterSleepState ( 2840SN/A UINT8 SleepState) 2850SN/A{ 2860SN/A UINT32 PM1AControl; 2870SN/A UINT32 PM1BControl; 2880SN/A ACPI_BIT_REGISTER_INFO *SleepTypeRegInfo; 2890SN/A ACPI_BIT_REGISTER_INFO *SleepEnableRegInfo; 2900SN/A UINT32 InValue; 2910SN/A ACPI_STATUS Status; 2920SN/A 2930SN/A 2940SN/A ACPI_FUNCTION_TRACE ("AcpiEnterSleepState"); 2950SN/A 2960SN/A 29712116Sserb if ((AcpiGbl_SleepTypeA > ACPI_SLEEP_TYPE_MAX) || 2980SN/A (AcpiGbl_SleepTypeB > ACPI_SLEEP_TYPE_MAX)) 2990SN/A { 3000SN/A ACPI_REPORT_ERROR (("Sleep values out of range: A=%X B=%X\n", 30116932Sserb AcpiGbl_SleepTypeA, AcpiGbl_SleepTypeB)); 3020SN/A return_ACPI_STATUS (AE_AML_OPERAND_VALUE); 30316932Sserb } 3040SN/A 3050SN/A 3060SN/A SleepTypeRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_TYPE_A); 30716932Sserb SleepEnableRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_ENABLE); 3080SN/A 3090SN/A /* Clear wake status */ 3100SN/A 31116932Sserb Status = AcpiSetRegister (ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_LOCK); 3120SN/A if (ACPI_FAILURE (Status)) 3130SN/A { 3140SN/A return_ACPI_STATUS (Status); 31516932Sserb } 3160SN/A 3170SN/A Status = AcpiHwClearAcpiStatus(); 3180SN/A if (ACPI_FAILURE (Status)) 31916932Sserb { 3200SN/A return_ACPI_STATUS (Status); 3210SN/A } 3220SN/A 3230SN/A /* Disable BM arbitration */ 3240SN/A 3250SN/A Status = AcpiSetRegister (ACPI_BITREG_ARB_DISABLE, 1, ACPI_MTX_LOCK); 3260SN/A if (ACPI_FAILURE (Status)) 3270SN/A { 3280SN/A return_ACPI_STATUS (Status); 3290SN/A } 3300SN/A 3310SN/A Status = AcpiHwDisableNonWakeupGpes(); 3320SN/A if (ACPI_FAILURE (Status)) 3330SN/A { 3340SN/A return_ACPI_STATUS (Status); 3350SN/A } 3360SN/A 3370SN/A /* Get current value of PM1A control */ 3380SN/A 3390SN/A Status = AcpiHwRegisterRead (ACPI_MTX_LOCK, ACPI_REGISTER_PM1_CONTROL, &PM1AControl); 3400SN/A if (ACPI_FAILURE (Status)) 3410SN/A { 3420SN/A return_ACPI_STATUS (Status); 3430SN/A } 3440SN/A ACPI_DEBUG_PRINT ((ACPI_DB_OK, "Entering S%d\n", SleepState)); 3450SN/A 3460SN/A /* Clear SLP_EN and SLP_TYP fields */ 3470SN/A 3480SN/A PM1AControl &= ~(SleepTypeRegInfo->AccessBitMask | SleepEnableRegInfo->AccessBitMask); 3490SN/A PM1BControl = PM1AControl; 3500SN/A 3510SN/A /* Insert SLP_TYP bits */ 3520SN/A 3530SN/A PM1AControl |= (AcpiGbl_SleepTypeA << SleepTypeRegInfo->BitPosition); 3540SN/A PM1BControl |= (AcpiGbl_SleepTypeB << SleepTypeRegInfo->BitPosition); 3550SN/A 3560SN/A /* Write #1: fill in SLP_TYP data */ 3570SN/A 3580SN/A Status = AcpiHwRegisterWrite (ACPI_MTX_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1AControl); 3590SN/A if (ACPI_FAILURE (Status)) 3600SN/A { 3610SN/A return_ACPI_STATUS (Status); 3620SN/A } 3630SN/A 3640SN/A Status = AcpiHwRegisterWrite (ACPI_MTX_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1BControl); 3650SN/A if (ACPI_FAILURE (Status)) 3660SN/A { 36712116Sserb return_ACPI_STATUS (Status); 3680SN/A } 3690SN/A 3700SN/A /* Insert SLP_ENABLE bit */ 3710SN/A 3720SN/A PM1AControl |= SleepEnableRegInfo->AccessBitMask; 3730SN/A PM1BControl |= SleepEnableRegInfo->AccessBitMask; 3740SN/A 3750SN/A /* Write #2: SLP_TYP + SLP_EN */ 3760SN/A 3770SN/A ACPI_FLUSH_CPU_CACHE (); 3780SN/A 3790SN/A Status = AcpiHwRegisterWrite (ACPI_MTX_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1AControl); 3800SN/A if (ACPI_FAILURE (Status)) 3810SN/A { 3820SN/A return_ACPI_STATUS (Status); 3830SN/A } 3840SN/A 3850SN/A Status = AcpiHwRegisterWrite (ACPI_MTX_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1BControl); 3860SN/A if (ACPI_FAILURE (Status)) 3870SN/A { 3880SN/A return_ACPI_STATUS (Status); 3890SN/A } 3900SN/A 3910SN/A /* 3920SN/A * Wait a second, then try again. This is to get S4/5 to work on all machines. 39312116Sserb */ 3940SN/A if (SleepState > ACPI_STATE_S3) 3950SN/A { 3960SN/A /* 3970SN/A * We wait so long to allow chipsets that poll this reg very slowly to 3980SN/A * still read the right value. Ideally, this entire block would go 3990SN/A * away entirely. 4000SN/A */ 4010SN/A AcpiOsStall (10000000); 4020SN/A 4030SN/A Status = AcpiHwRegisterWrite (ACPI_MTX_LOCK, ACPI_REGISTER_PM1_CONTROL, 4040SN/A SleepEnableRegInfo->AccessBitMask); 4050SN/A if (ACPI_FAILURE (Status)) 4064398SN/A { 4070SN/A return_ACPI_STATUS (Status); 4080SN/A } 4090SN/A } 4100SN/A 4110SN/A /* Wait until we enter sleep state */ 4120SN/A 4130SN/A do 4140SN/A { 4150SN/A Status = AcpiGetRegister (ACPI_BITREG_WAKE_STATUS, &InValue, ACPI_MTX_LOCK); 4160SN/A if (ACPI_FAILURE (Status)) 4170SN/A { 4180SN/A return_ACPI_STATUS (Status); 4190SN/A } 4200SN/A 4210SN/A /* Spin until we wake */ 4220SN/A 4230SN/A } while (!InValue); 4240SN/A 4250SN/A return_ACPI_STATUS (AE_OK); 4260SN/A} 4270SN/A 4280SN/A/****************************************************************************** 4290SN/A * 4300SN/A * FUNCTION: AcpiLeaveSleepState 4310SN/A * 4320SN/A * PARAMETERS: SleepState - Which sleep state we just exited 4330SN/A * 4340SN/A * RETURN: Status 4350SN/A * 4360SN/A * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep 4370SN/A * 4380SN/A ******************************************************************************/ 4390SN/A 4400SN/AACPI_STATUS 4410SN/AAcpiLeaveSleepState ( 4420SN/A UINT8 SleepState) 4430SN/A{ 4440SN/A ACPI_OBJECT_LIST ArgList; 4450SN/A ACPI_OBJECT Arg; 4460SN/A ACPI_STATUS Status; 4470SN/A 4480SN/A 4490SN/A ACPI_FUNCTION_TRACE ("AcpiLeaveSleepState"); 4500SN/A 4510SN/A 4520SN/A /* Ensure EnterSleepStatePrep -> EnterSleepState ordering */ 4530SN/A 4540SN/A AcpiGbl_SleepTypeA = ACPI_SLEEP_TYPE_INVALID; 4550SN/A 4560SN/A /* Setup parameter object */ 4570SN/A 4580SN/A ArgList.Count = 1; 4590SN/A ArgList.Pointer = &Arg; 4600SN/A 4610SN/A Arg.Type = ACPI_TYPE_INTEGER; 4620SN/A Arg.Integer.Value = SleepState; 4630SN/A 4640SN/A /* Ignore any errors from these methods */ 4650SN/A 4660SN/A Status = AcpiEvaluateObject (NULL, "\\_BFS", &ArgList, NULL); 4670SN/A if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 4680SN/A { 4690SN/A ACPI_REPORT_ERROR (("Method _BFS failed, %s\n", AcpiFormatException (Status))); 4700SN/A } 4710SN/A 4720SN/A Status = AcpiEvaluateObject (NULL, "\\_WAK", &ArgList, NULL); 4730SN/A if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 4740SN/A { 4750SN/A ACPI_REPORT_ERROR (("Method _WAK failed, %s\n", AcpiFormatException (Status))); 4760SN/A } 4770SN/A 4780SN/A /* _WAK returns stuff - do we want to look at it? */ 4790SN/A 4800SN/A Status = AcpiHwEnableNonWakeupGpes(); 4810SN/A if (ACPI_FAILURE (Status)) 4820SN/A { 4830SN/A return_ACPI_STATUS (Status); 4840SN/A } 4850SN/A 4860SN/A /* Disable BM arbitration */ 4870SN/A Status = AcpiSetRegister (ACPI_BITREG_ARB_DISABLE, 0, ACPI_MTX_LOCK); 4880SN/A 4890SN/A return_ACPI_STATUS (Status); 4900SN/A} 4910SN/A