1 /******************************************************************************
3 * Name: hwxfsleep.c - ACPI Hardware Sleep/Wake External Interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2019, 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
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_STRUCT_INIT (LegacyFunction
,
80 ACPI_HW_OPTIONAL_FUNCTION (AcpiHwLegacySleep
)),
81 ACPI_STRUCT_INIT (ExtendedFunction
,
82 AcpiHwExtendedSleep
) },
83 {ACPI_STRUCT_INIT (LegacyFunction
,
84 ACPI_HW_OPTIONAL_FUNCTION (AcpiHwLegacyWakePrep
)),
85 ACPI_STRUCT_INIT (ExtendedFunction
,
86 AcpiHwExtendedWakePrep
) },
87 {ACPI_STRUCT_INIT (Legacy_function
,
88 ACPI_HW_OPTIONAL_FUNCTION (AcpiHwLegacyWake
)),
89 ACPI_STRUCT_INIT (ExtendedFunction
,
95 * These functions are removed for the ACPI_REDUCED_HARDWARE case:
96 * AcpiSetFirmwareWakingVector
97 * AcpiEnterSleepStateS4bios
100 #if (!ACPI_REDUCED_HARDWARE)
101 /*******************************************************************************
103 * FUNCTION: AcpiHwSetFirmwareWakingVector
105 * PARAMETERS: Facs - Pointer to FACS table
106 * PhysicalAddress - 32-bit physical address of ACPI real mode
108 * PhysicalAddress64 - 64-bit physical address of ACPI protected
113 * DESCRIPTION: Sets the FirmwareWakingVector fields of the FACS
115 ******************************************************************************/
118 AcpiHwSetFirmwareWakingVector (
119 ACPI_TABLE_FACS
*Facs
,
120 ACPI_PHYSICAL_ADDRESS PhysicalAddress
,
121 ACPI_PHYSICAL_ADDRESS PhysicalAddress64
)
123 ACPI_FUNCTION_TRACE (AcpiHwSetFirmwareWakingVector
);
127 * According to the ACPI specification 2.0c and later, the 64-bit
128 * waking vector should be cleared and the 32-bit waking vector should
129 * be used, unless we want the wake-up code to be called by the BIOS in
130 * Protected Mode. Some systems (for example HP dv5-1004nr) are known
131 * to fail to resume if the 64-bit vector is used.
134 /* Set the 32-bit vector */
136 Facs
->FirmwareWakingVector
= (UINT32
) PhysicalAddress
;
138 if (Facs
->Length
> 32)
140 if (Facs
->Version
>= 1)
142 /* Set the 64-bit vector */
144 Facs
->XFirmwareWakingVector
= PhysicalAddress64
;
148 /* Clear the 64-bit vector if it exists */
150 Facs
->XFirmwareWakingVector
= 0;
154 return_ACPI_STATUS (AE_OK
);
158 /*******************************************************************************
160 * FUNCTION: AcpiSetFirmwareWakingVector
162 * PARAMETERS: PhysicalAddress - 32-bit physical address of ACPI real mode
164 * PhysicalAddress64 - 64-bit physical address of ACPI protected
169 * DESCRIPTION: Sets the FirmwareWakingVector fields of the FACS
171 ******************************************************************************/
174 AcpiSetFirmwareWakingVector (
175 ACPI_PHYSICAL_ADDRESS PhysicalAddress
,
176 ACPI_PHYSICAL_ADDRESS PhysicalAddress64
)
179 ACPI_FUNCTION_TRACE (AcpiSetFirmwareWakingVector
);
183 (void) AcpiHwSetFirmwareWakingVector (AcpiGbl_FACS
,
184 PhysicalAddress
, PhysicalAddress64
);
187 return_ACPI_STATUS (AE_OK
);
190 ACPI_EXPORT_SYMBOL (AcpiSetFirmwareWakingVector
)
193 /*******************************************************************************
195 * FUNCTION: AcpiEnterSleepStateS4bios
201 * DESCRIPTION: Perform a S4 bios request.
202 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
204 ******************************************************************************/
207 AcpiEnterSleepStateS4bios (
214 ACPI_FUNCTION_TRACE (AcpiEnterSleepStateS4bios
);
217 /* Clear the wake status bit (PM1) */
219 Status
= AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS
, ACPI_CLEAR_STATUS
);
220 if (ACPI_FAILURE (Status
))
222 return_ACPI_STATUS (Status
);
225 Status
= AcpiHwClearAcpiStatus ();
226 if (ACPI_FAILURE (Status
))
228 return_ACPI_STATUS (Status
);
232 * 1) Disable all GPEs
233 * 2) Enable all wakeup GPEs
235 Status
= AcpiHwDisableAllGpes ();
236 if (ACPI_FAILURE (Status
))
238 return_ACPI_STATUS (Status
);
240 AcpiGbl_SystemAwakeAndRunning
= FALSE
;
242 Status
= AcpiHwEnableAllWakeupGpes ();
243 if (ACPI_FAILURE (Status
))
245 return_ACPI_STATUS (Status
);
248 ACPI_FLUSH_CPU_CACHE ();
250 Status
= AcpiHwWritePort (AcpiGbl_FADT
.SmiCommand
,
251 (UINT32
) AcpiGbl_FADT
.S4BiosRequest
, 8);
252 if (ACPI_FAILURE (Status
))
254 return_ACPI_STATUS (Status
);
258 AcpiOsStall (ACPI_USEC_PER_MSEC
);
259 Status
= AcpiReadBitRegister (ACPI_BITREG_WAKE_STATUS
, &InValue
);
260 if (ACPI_FAILURE (Status
))
262 return_ACPI_STATUS (Status
);
267 return_ACPI_STATUS (AE_OK
);
270 ACPI_EXPORT_SYMBOL (AcpiEnterSleepStateS4bios
)
272 #endif /* !ACPI_REDUCED_HARDWARE */
275 /*******************************************************************************
277 * FUNCTION: AcpiHwSleepDispatch
279 * PARAMETERS: SleepState - Which sleep state to enter/exit
280 * FunctionId - Sleep, WakePrep, or Wake
282 * RETURN: Status from the invoked sleep handling function.
284 * DESCRIPTION: Dispatch a sleep/wake request to the appropriate handling
287 ******************************************************************************/
290 AcpiHwSleepDispatch (
295 ACPI_SLEEP_FUNCTIONS
*SleepFunctions
= &AcpiSleepDispatch
[FunctionId
];
298 #if (!ACPI_REDUCED_HARDWARE)
300 * If the Hardware Reduced flag is set (from the FADT), we must
301 * use the extended sleep registers (FADT). Note: As per the ACPI
302 * specification, these extended registers are to be used for HW-reduced
303 * platforms only. They are not general-purpose replacements for the
304 * legacy PM register sleep support.
306 if (AcpiGbl_ReducedHardware
)
308 Status
= SleepFunctions
->ExtendedFunction (SleepState
);
314 Status
= SleepFunctions
->LegacyFunction (SleepState
);
321 * For the case where reduced-hardware-only code is being generated,
322 * we know that only the extended sleep registers are available
324 Status
= SleepFunctions
->ExtendedFunction (SleepState
);
327 #endif /* !ACPI_REDUCED_HARDWARE */
331 /*******************************************************************************
333 * FUNCTION: AcpiEnterSleepStatePrep
335 * PARAMETERS: SleepState - Which sleep state to enter
339 * DESCRIPTION: Prepare to enter a system sleep state.
340 * This function must execute with interrupts enabled.
341 * We break sleeping into 2 stages so that OSPM can handle
342 * various OS-specific tasks between the two steps.
344 ******************************************************************************/
347 AcpiEnterSleepStatePrep (
351 ACPI_OBJECT_LIST ArgList
;
356 ACPI_FUNCTION_TRACE (AcpiEnterSleepStatePrep
);
359 Status
= AcpiGetSleepTypeData (SleepState
,
360 &AcpiGbl_SleepTypeA
, &AcpiGbl_SleepTypeB
);
361 if (ACPI_FAILURE (Status
))
363 return_ACPI_STATUS (Status
);
366 /* Execute the _PTS method (Prepare To Sleep) */
369 ArgList
.Pointer
= &Arg
;
370 Arg
.Type
= ACPI_TYPE_INTEGER
;
371 Arg
.Integer
.Value
= SleepState
;
373 Status
= AcpiEvaluateObject (NULL
, METHOD_PATHNAME__PTS
, &ArgList
, NULL
);
374 if (ACPI_FAILURE (Status
) && Status
!= AE_NOT_FOUND
)
376 return_ACPI_STATUS (Status
);
379 /* Setup the argument to the _SST method (System STatus) */
385 SstValue
= ACPI_SST_WORKING
;
392 SstValue
= ACPI_SST_SLEEPING
;
397 SstValue
= ACPI_SST_SLEEP_CONTEXT
;
402 SstValue
= ACPI_SST_INDICATOR_OFF
; /* Default is off */
407 * Set the system indicators to show the desired sleep state.
408 * _SST is an optional method (return no error if not found)
410 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__SST
, SstValue
);
411 return_ACPI_STATUS (AE_OK
);
414 ACPI_EXPORT_SYMBOL (AcpiEnterSleepStatePrep
)
417 /*******************************************************************************
419 * FUNCTION: AcpiEnterSleepState
421 * PARAMETERS: SleepState - Which sleep state to enter
425 * DESCRIPTION: Enter a system sleep state
426 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
428 ******************************************************************************/
431 AcpiEnterSleepState (
437 ACPI_FUNCTION_TRACE (AcpiEnterSleepState
);
440 if ((AcpiGbl_SleepTypeA
> ACPI_SLEEP_TYPE_MAX
) ||
441 (AcpiGbl_SleepTypeB
> ACPI_SLEEP_TYPE_MAX
))
443 ACPI_ERROR ((AE_INFO
, "Sleep values out of range: A=0x%X B=0x%X",
444 AcpiGbl_SleepTypeA
, AcpiGbl_SleepTypeB
));
445 return_ACPI_STATUS (AE_AML_OPERAND_VALUE
);
448 Status
= AcpiHwSleepDispatch (SleepState
, ACPI_SLEEP_FUNCTION_ID
);
449 return_ACPI_STATUS (Status
);
452 ACPI_EXPORT_SYMBOL (AcpiEnterSleepState
)
455 /*******************************************************************************
457 * FUNCTION: AcpiLeaveSleepStatePrep
459 * PARAMETERS: SleepState - Which sleep state we are exiting
463 * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
464 * sleep. Called with interrupts DISABLED.
465 * We break wake/resume into 2 stages so that OSPM can handle
466 * various OS-specific tasks between the two steps.
468 ******************************************************************************/
471 AcpiLeaveSleepStatePrep (
477 ACPI_FUNCTION_TRACE (AcpiLeaveSleepStatePrep
);
480 Status
= AcpiHwSleepDispatch (SleepState
, ACPI_WAKE_PREP_FUNCTION_ID
);
481 return_ACPI_STATUS (Status
);
484 ACPI_EXPORT_SYMBOL (AcpiLeaveSleepStatePrep
)
487 /*******************************************************************************
489 * FUNCTION: AcpiLeaveSleepState
491 * PARAMETERS: SleepState - Which sleep state we are exiting
495 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
496 * Called with interrupts ENABLED.
498 ******************************************************************************/
501 AcpiLeaveSleepState (
507 ACPI_FUNCTION_TRACE (AcpiLeaveSleepState
);
510 Status
= AcpiHwSleepDispatch (SleepState
, ACPI_WAKE_FUNCTION_ID
);
511 return_ACPI_STATUS (Status
);
514 ACPI_EXPORT_SYMBOL (AcpiLeaveSleepState
)