1 /******************************************************************************
3 * Name: hwxfsleep.c - ACPI Hardware Sleep/Wake External Interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2017, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define EXPORT_ACPI_INTERFACES
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
49 #define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME ("hwxfsleep")
52 /* Local prototypes */
54 #if (!ACPI_REDUCED_HARDWARE)
56 AcpiHwSetFirmwareWakingVector (
57 ACPI_TABLE_FACS *Facs,
58 ACPI_PHYSICAL_ADDRESS PhysicalAddress,
59 ACPI_PHYSICAL_ADDRESS PhysicalAddress64);
68 * Dispatch table used to efficiently branch to the various sleep
71 #define ACPI_SLEEP_FUNCTION_ID 0
72 #define ACPI_WAKE_PREP_FUNCTION_ID 1
73 #define ACPI_WAKE_FUNCTION_ID 2
75 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
77 static ACPI_SLEEP_FUNCTIONS AcpiSleepDispatch[] =
79 {ACPI_HW_OPTIONAL_FUNCTION (AcpiHwLegacySleep), AcpiHwExtendedSleep},
80 {ACPI_HW_OPTIONAL_FUNCTION (AcpiHwLegacyWakePrep), AcpiHwExtendedWakePrep},
81 {ACPI_HW_OPTIONAL_FUNCTION (AcpiHwLegacyWake), AcpiHwExtendedWake}
86 * These functions are removed for the ACPI_REDUCED_HARDWARE case:
87 * AcpiSetFirmwareWakingVector
88 * AcpiEnterSleepStateS4bios
91 #if (!ACPI_REDUCED_HARDWARE)
92 /*******************************************************************************
94 * FUNCTION: AcpiHwSetFirmwareWakingVector
96 * PARAMETERS: Facs - Pointer to FACS table
97 * PhysicalAddress - 32-bit physical address of ACPI real mode
99 * PhysicalAddress64 - 64-bit physical address of ACPI protected
104 * DESCRIPTION: Sets the FirmwareWakingVector fields of the FACS
106 ******************************************************************************/
109 AcpiHwSetFirmwareWakingVector (
110 ACPI_TABLE_FACS *Facs,
111 ACPI_PHYSICAL_ADDRESS PhysicalAddress,
112 ACPI_PHYSICAL_ADDRESS PhysicalAddress64)
114 ACPI_FUNCTION_TRACE (AcpiHwSetFirmwareWakingVector);
118 * According to the ACPI specification 2.0c and later, the 64-bit
119 * waking vector should be cleared and the 32-bit waking vector should
120 * be used, unless we want the wake-up code to be called by the BIOS in
121 * Protected Mode. Some systems (for example HP dv5-1004nr) are known
122 * to fail to resume if the 64-bit vector is used.
125 /* Set the 32-bit vector */
127 Facs->FirmwareWakingVector = (UINT32) PhysicalAddress;
129 if (Facs->Length > 32)
131 if (Facs->Version >= 1)
133 /* Set the 64-bit vector */
135 Facs->XFirmwareWakingVector = PhysicalAddress64;
139 /* Clear the 64-bit vector if it exists */
141 Facs->XFirmwareWakingVector = 0;
145 return_ACPI_STATUS (AE_OK);
149 /*******************************************************************************
151 * FUNCTION: AcpiSetFirmwareWakingVector
153 * PARAMETERS: PhysicalAddress - 32-bit physical address of ACPI real mode
155 * PhysicalAddress64 - 64-bit physical address of ACPI protected
160 * DESCRIPTION: Sets the FirmwareWakingVector fields of the FACS
162 ******************************************************************************/
165 AcpiSetFirmwareWakingVector (
166 ACPI_PHYSICAL_ADDRESS PhysicalAddress,
167 ACPI_PHYSICAL_ADDRESS PhysicalAddress64)
170 ACPI_FUNCTION_TRACE (AcpiSetFirmwareWakingVector);
174 (void) AcpiHwSetFirmwareWakingVector (AcpiGbl_FACS,
175 PhysicalAddress, PhysicalAddress64);
178 return_ACPI_STATUS (AE_OK);
181 ACPI_EXPORT_SYMBOL (AcpiSetFirmwareWakingVector)
184 /*******************************************************************************
186 * FUNCTION: AcpiEnterSleepStateS4bios
192 * DESCRIPTION: Perform a S4 bios request.
193 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
195 ******************************************************************************/
198 AcpiEnterSleepStateS4bios (
205 ACPI_FUNCTION_TRACE (AcpiEnterSleepStateS4bios);
208 /* Clear the wake status bit (PM1) */
210 Status = AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS);
211 if (ACPI_FAILURE (Status))
213 return_ACPI_STATUS (Status);
216 Status = AcpiHwClearAcpiStatus ();
217 if (ACPI_FAILURE (Status))
219 return_ACPI_STATUS (Status);
223 * 1) Disable/Clear all GPEs
224 * 2) Enable all wakeup GPEs
226 Status = AcpiHwDisableAllGpes ();
227 if (ACPI_FAILURE (Status))
229 return_ACPI_STATUS (Status);
231 AcpiGbl_SystemAwakeAndRunning = FALSE;
233 Status = AcpiHwEnableAllWakeupGpes ();
234 if (ACPI_FAILURE (Status))
236 return_ACPI_STATUS (Status);
239 ACPI_FLUSH_CPU_CACHE ();
241 Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand,
242 (UINT32) AcpiGbl_FADT.S4BiosRequest, 8);
245 AcpiOsStall (ACPI_USEC_PER_MSEC);
246 Status = AcpiReadBitRegister (ACPI_BITREG_WAKE_STATUS, &InValue);
247 if (ACPI_FAILURE (Status))
249 return_ACPI_STATUS (Status);
254 return_ACPI_STATUS (AE_OK);
257 ACPI_EXPORT_SYMBOL (AcpiEnterSleepStateS4bios)
259 #endif /* !ACPI_REDUCED_HARDWARE */
262 /*******************************************************************************
264 * FUNCTION: AcpiHwSleepDispatch
266 * PARAMETERS: SleepState - Which sleep state to enter/exit
267 * FunctionId - Sleep, WakePrep, or Wake
269 * RETURN: Status from the invoked sleep handling function.
271 * DESCRIPTION: Dispatch a sleep/wake request to the appropriate handling
274 ******************************************************************************/
277 AcpiHwSleepDispatch (
282 ACPI_SLEEP_FUNCTIONS *SleepFunctions = &AcpiSleepDispatch[FunctionId];
285 #if (!ACPI_REDUCED_HARDWARE)
287 * If the Hardware Reduced flag is set (from the FADT), we must
288 * use the extended sleep registers (FADT). Note: As per the ACPI
289 * specification, these extended registers are to be used for HW-reduced
290 * platforms only. They are not general-purpose replacements for the
291 * legacy PM register sleep support.
293 if (AcpiGbl_ReducedHardware)
295 Status = SleepFunctions->ExtendedFunction (SleepState);
301 Status = SleepFunctions->LegacyFunction (SleepState);
308 * For the case where reduced-hardware-only code is being generated,
309 * we know that only the extended sleep registers are available
311 Status = SleepFunctions->ExtendedFunction (SleepState);
314 #endif /* !ACPI_REDUCED_HARDWARE */
318 /*******************************************************************************
320 * FUNCTION: AcpiEnterSleepStatePrep
322 * PARAMETERS: SleepState - Which sleep state to enter
326 * DESCRIPTION: Prepare to enter a system sleep state.
327 * This function must execute with interrupts enabled.
328 * We break sleeping into 2 stages so that OSPM can handle
329 * various OS-specific tasks between the two steps.
331 ******************************************************************************/
334 AcpiEnterSleepStatePrep (
338 ACPI_OBJECT_LIST ArgList;
343 ACPI_FUNCTION_TRACE (AcpiEnterSleepStatePrep);
346 Status = AcpiGetSleepTypeData (SleepState,
347 &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB);
348 if (ACPI_FAILURE (Status))
350 return_ACPI_STATUS (Status);
353 /* Execute the _PTS method (Prepare To Sleep) */
356 ArgList.Pointer = &Arg;
357 Arg.Type = ACPI_TYPE_INTEGER;
358 Arg.Integer.Value = SleepState;
360 Status = AcpiEvaluateObject (NULL, METHOD_PATHNAME__PTS, &ArgList, NULL);
361 if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND)
363 return_ACPI_STATUS (Status);
366 /* Setup the argument to the _SST method (System STatus) */
372 SstValue = ACPI_SST_WORKING;
379 SstValue = ACPI_SST_SLEEPING;
384 SstValue = ACPI_SST_SLEEP_CONTEXT;
389 SstValue = ACPI_SST_INDICATOR_OFF; /* Default is off */
394 * Set the system indicators to show the desired sleep state.
395 * _SST is an optional method (return no error if not found)
397 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__SST, SstValue);
398 return_ACPI_STATUS (AE_OK);
401 ACPI_EXPORT_SYMBOL (AcpiEnterSleepStatePrep)
404 /*******************************************************************************
406 * FUNCTION: AcpiEnterSleepState
408 * PARAMETERS: SleepState - Which sleep state to enter
412 * DESCRIPTION: Enter a system sleep state
413 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
415 ******************************************************************************/
418 AcpiEnterSleepState (
424 ACPI_FUNCTION_TRACE (AcpiEnterSleepState);
427 if ((AcpiGbl_SleepTypeA > ACPI_SLEEP_TYPE_MAX) ||
428 (AcpiGbl_SleepTypeB > ACPI_SLEEP_TYPE_MAX))
430 ACPI_ERROR ((AE_INFO, "Sleep values out of range: A=0x%X B=0x%X",
431 AcpiGbl_SleepTypeA, AcpiGbl_SleepTypeB));
432 return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
435 Status = AcpiHwSleepDispatch (SleepState, ACPI_SLEEP_FUNCTION_ID);
436 return_ACPI_STATUS (Status);
439 ACPI_EXPORT_SYMBOL (AcpiEnterSleepState)
442 /*******************************************************************************
444 * FUNCTION: AcpiLeaveSleepStatePrep
446 * PARAMETERS: SleepState - Which sleep state we are exiting
450 * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
451 * sleep. Called with interrupts DISABLED.
452 * We break wake/resume into 2 stages so that OSPM can handle
453 * various OS-specific tasks between the two steps.
455 ******************************************************************************/
458 AcpiLeaveSleepStatePrep (
464 ACPI_FUNCTION_TRACE (AcpiLeaveSleepStatePrep);
467 Status = AcpiHwSleepDispatch (SleepState, ACPI_WAKE_PREP_FUNCTION_ID);
468 return_ACPI_STATUS (Status);
471 ACPI_EXPORT_SYMBOL (AcpiLeaveSleepStatePrep)
474 /*******************************************************************************
476 * FUNCTION: AcpiLeaveSleepState
478 * PARAMETERS: SleepState - Which sleep state we are exiting
482 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
483 * Called with interrupts ENABLED.
485 ******************************************************************************/
488 AcpiLeaveSleepState (
494 ACPI_FUNCTION_TRACE (AcpiLeaveSleepState);
497 Status = AcpiHwSleepDispatch (SleepState, ACPI_WAKE_FUNCTION_ID);
498 return_ACPI_STATUS (Status);
501 ACPI_EXPORT_SYMBOL (AcpiLeaveSleepState)