1 /****************************************************************************** 2 * 3 * Name: hwesleep.c - ACPI Hardware Sleep/Wake Support functions for the 4 * extended FADT-V5 sleep registers. 5 * 6 *****************************************************************************/ 7 8 /* 9 * Copyright (C) 2000 - 2012, Intel Corp. 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions, and the following disclaimer, 17 * without modification. 18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 19 * substantially similar to the "NO WARRANTY" disclaimer below 20 * ("Disclaimer") and any redistribution must be conditioned upon 21 * including a substantially similar Disclaimer requirement for further 22 * binary redistribution. 23 * 3. Neither the names of the above-listed copyright holders nor the names 24 * of any contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * Alternatively, this software may be distributed under the terms of the 28 * GNU General Public License ("GPL") version 2 as published by the Free 29 * Software Foundation. 30 * 31 * NO WARRANTY 32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42 * POSSIBILITY OF SUCH DAMAGES. 43 */ 44 45 #include <contrib/dev/acpica/include/acpi.h> 46 #include <contrib/dev/acpica/include/accommon.h> 47 48 #define _COMPONENT ACPI_HARDWARE 49 ACPI_MODULE_NAME ("hwesleep") 50 51 52 /******************************************************************************* 53 * 54 * FUNCTION: AcpiHwExecuteSleepMethod 55 * 56 * PARAMETERS: MethodPathname - Pathname of method to execute 57 * IntegerArgument - Argument to pass to the method 58 * 59 * RETURN: None 60 * 61 * DESCRIPTION: Execute a sleep/wake related method with one integer argument 62 * and no return value. 63 * 64 ******************************************************************************/ 65 66 void 67 AcpiHwExecuteSleepMethod ( 68 char *MethodPathname, 69 UINT32 IntegerArgument) 70 { 71 ACPI_OBJECT_LIST ArgList; 72 ACPI_OBJECT Arg; 73 ACPI_STATUS Status; 74 75 76 ACPI_FUNCTION_TRACE (HwExecuteSleepMethod); 77 78 79 /* One argument, IntegerArgument; No return value expected */ 80 81 ArgList.Count = 1; 82 ArgList.Pointer = &Arg; 83 Arg.Type = ACPI_TYPE_INTEGER; 84 Arg.Integer.Value = (UINT64) IntegerArgument; 85 86 Status = AcpiEvaluateObject (NULL, MethodPathname, &ArgList, NULL); 87 if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 88 { 89 ACPI_EXCEPTION ((AE_INFO, Status, "While executing method %s", 90 MethodPathname)); 91 } 92 93 return_VOID; 94 } 95 96 97 /******************************************************************************* 98 * 99 * FUNCTION: AcpiHwExtendedSleep 100 * 101 * PARAMETERS: SleepState - Which sleep state to enter 102 * Flags - ACPI_EXECUTE_GTS to run optional method 103 * 104 * RETURN: Status 105 * 106 * DESCRIPTION: Enter a system sleep state via the extended FADT sleep 107 * registers (V5 FADT). 108 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED 109 * 110 ******************************************************************************/ 111 112 ACPI_STATUS 113 AcpiHwExtendedSleep ( 114 UINT8 SleepState, 115 UINT8 Flags) 116 { 117 ACPI_STATUS Status; 118 UINT8 SleepTypeValue; 119 UINT64 SleepStatus; 120 121 122 ACPI_FUNCTION_TRACE (HwExtendedSleep); 123 124 125 /* Extended sleep registers must be valid */ 126 127 if (!AcpiGbl_FADT.SleepControl.Address || 128 !AcpiGbl_FADT.SleepStatus.Address) 129 { 130 return_ACPI_STATUS (AE_NOT_EXIST); 131 } 132 133 /* Clear wake status (WAK_STS) */ 134 135 Status = AcpiWrite ((UINT64) ACPI_X_WAKE_STATUS, &AcpiGbl_FADT.SleepStatus); 136 if (ACPI_FAILURE (Status)) 137 { 138 return_ACPI_STATUS (Status); 139 } 140 141 AcpiGbl_SystemAwakeAndRunning = FALSE; 142 143 /* Optionally execute _GTS (Going To Sleep) */ 144 145 if (Flags & ACPI_EXECUTE_GTS) 146 { 147 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__GTS, SleepState); 148 } 149 150 /* Flush caches, as per ACPI specification */ 151 152 ACPI_FLUSH_CPU_CACHE (); 153 154 /* 155 * Set the SLP_TYP and SLP_EN bits. 156 * 157 * Note: We only use the first value returned by the \_Sx method 158 * (AcpiGbl_SleepTypeA) - As per ACPI specification. 159 */ 160 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, 161 "Entering sleep state [S%u]\n", SleepState)); 162 163 SleepTypeValue = ((AcpiGbl_SleepTypeA << ACPI_X_SLEEP_TYPE_POSITION) & 164 ACPI_X_SLEEP_TYPE_MASK); 165 166 Status = AcpiWrite ((UINT64) (SleepTypeValue | ACPI_X_SLEEP_ENABLE), 167 &AcpiGbl_FADT.SleepControl); 168 if (ACPI_FAILURE (Status)) 169 { 170 return_ACPI_STATUS (Status); 171 } 172 173 /* Wait for transition back to Working State */ 174 175 do 176 { 177 Status = AcpiRead (&SleepStatus, &AcpiGbl_FADT.SleepStatus); 178 if (ACPI_FAILURE (Status)) 179 { 180 return_ACPI_STATUS (Status); 181 } 182 183 } while (!(((UINT8) SleepStatus) & ACPI_X_WAKE_STATUS)); 184 185 return_ACPI_STATUS (AE_OK); 186 } 187 188 189 /******************************************************************************* 190 * 191 * FUNCTION: AcpiHwExtendedWakePrep 192 * 193 * PARAMETERS: SleepState - Which sleep state we just exited 194 * Flags - ACPI_EXECUTE_BFS to run optional method 195 * 196 * RETURN: Status 197 * 198 * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after 199 * a sleep. Called with interrupts ENABLED. 200 * 201 ******************************************************************************/ 202 203 ACPI_STATUS 204 AcpiHwExtendedWakePrep ( 205 UINT8 SleepState, 206 UINT8 Flags) 207 { 208 ACPI_STATUS Status; 209 UINT8 SleepTypeValue; 210 211 212 ACPI_FUNCTION_TRACE (HwExtendedWakePrep); 213 214 215 Status = AcpiGetSleepTypeData (ACPI_STATE_S0, 216 &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB); 217 if (ACPI_SUCCESS (Status)) 218 { 219 SleepTypeValue = ((AcpiGbl_SleepTypeA << ACPI_X_SLEEP_TYPE_POSITION) & 220 ACPI_X_SLEEP_TYPE_MASK); 221 222 (void) AcpiWrite ((UINT64) (SleepTypeValue | ACPI_X_SLEEP_ENABLE), 223 &AcpiGbl_FADT.SleepControl); 224 } 225 226 /* Optionally execute _BFS (Back From Sleep) */ 227 228 if (Flags & ACPI_EXECUTE_BFS) 229 { 230 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__BFS, SleepState); 231 } 232 return_ACPI_STATUS (AE_OK); 233 } 234 235 236 /******************************************************************************* 237 * 238 * FUNCTION: AcpiHwExtendedWake 239 * 240 * PARAMETERS: SleepState - Which sleep state we just exited 241 * Flags - Reserved, set to zero 242 * 243 * RETURN: Status 244 * 245 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep 246 * Called with interrupts ENABLED. 247 * 248 ******************************************************************************/ 249 250 ACPI_STATUS 251 AcpiHwExtendedWake ( 252 UINT8 SleepState, 253 UINT8 Flags) 254 { 255 ACPI_FUNCTION_TRACE (HwExtendedWake); 256 257 258 /* Ensure EnterSleepStatePrep -> EnterSleepState ordering */ 259 260 AcpiGbl_SleepTypeA = ACPI_SLEEP_TYPE_INVALID; 261 262 /* Execute the wake methods */ 263 264 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__SST, ACPI_SST_WAKING); 265 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__WAK, SleepState); 266 267 /* 268 * Some BIOS code assumes that WAK_STS will be cleared on resume 269 * and use it to determine whether the system is rebooting or 270 * resuming. Clear WAK_STS for compatibility. 271 */ 272 (void) AcpiWrite ((UINT64) ACPI_X_WAKE_STATUS, &AcpiGbl_FADT.SleepStatus); 273 AcpiGbl_SystemAwakeAndRunning = TRUE; 274 275 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__SST, ACPI_SST_WORKING); 276 return_ACPI_STATUS (AE_OK); 277 } 278