ReactOS  0.4.14-dev-323-g6fe6a88
hwxfsleep.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Name: hwxfsleep.c - ACPI Hardware Sleep/Wake External Interfaces
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2019, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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.
25  *
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.
29  *
30  * NO WARRANTY
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.
42  */
43 
44 #define EXPORT_ACPI_INTERFACES
45 
46 #include "acpi.h"
47 #include "accommon.h"
48 
49 #define _COMPONENT ACPI_HARDWARE
50  ACPI_MODULE_NAME ("hwxfsleep")
51 
52 /* Local prototypes */
53 
54 #if (!ACPI_REDUCED_HARDWARE)
55 static ACPI_STATUS
57  ACPI_TABLE_FACS *Facs,
58  ACPI_PHYSICAL_ADDRESS PhysicalAddress,
59  ACPI_PHYSICAL_ADDRESS PhysicalAddress64);
60 #endif
61 
62 static ACPI_STATUS
64  UINT8 SleepState,
65  UINT32 FunctionId);
66 
67 /*
68  * Dispatch table used to efficiently branch to the various sleep
69  * functions.
70  */
71 #define ACPI_SLEEP_FUNCTION_ID 0
72 #define ACPI_WAKE_PREP_FUNCTION_ID 1
73 #define ACPI_WAKE_FUNCTION_ID 2
74 
75 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
76 
78 {
79  {ACPI_STRUCT_INIT (LegacyFunction,
81  ACPI_STRUCT_INIT (ExtendedFunction,
83  {ACPI_STRUCT_INIT (LegacyFunction,
85  ACPI_STRUCT_INIT (ExtendedFunction,
87  {ACPI_STRUCT_INIT (Legacy_function,
89  ACPI_STRUCT_INIT (ExtendedFunction,
91 };
92 
93 
94 /*
95  * These functions are removed for the ACPI_REDUCED_HARDWARE case:
96  * AcpiSetFirmwareWakingVector
97  * AcpiEnterSleepStateS4bios
98  */
99 
100 #if (!ACPI_REDUCED_HARDWARE)
101 /*******************************************************************************
102  *
103  * FUNCTION: AcpiHwSetFirmwareWakingVector
104  *
105  * PARAMETERS: Facs - Pointer to FACS table
106  * PhysicalAddress - 32-bit physical address of ACPI real mode
107  * entry point
108  * PhysicalAddress64 - 64-bit physical address of ACPI protected
109  * mode entry point
110  *
111  * RETURN: Status
112  *
113  * DESCRIPTION: Sets the FirmwareWakingVector fields of the FACS
114  *
115  ******************************************************************************/
116 
117 static ACPI_STATUS
119  ACPI_TABLE_FACS *Facs,
120  ACPI_PHYSICAL_ADDRESS PhysicalAddress,
121  ACPI_PHYSICAL_ADDRESS PhysicalAddress64)
122 {
124 
125 
126  /*
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.
132  */
133 
134  /* Set the 32-bit vector */
135 
137 
138  if (Facs->Length > 32)
139  {
140  if (Facs->Version >= 1)
141  {
142  /* Set the 64-bit vector */
143 
144  Facs->XFirmwareWakingVector = PhysicalAddress64;
145  }
146  else
147  {
148  /* Clear the 64-bit vector if it exists */
149 
150  Facs->XFirmwareWakingVector = 0;
151  }
152  }
153 
155 }
156 
157 
158 /*******************************************************************************
159  *
160  * FUNCTION: AcpiSetFirmwareWakingVector
161  *
162  * PARAMETERS: PhysicalAddress - 32-bit physical address of ACPI real mode
163  * entry point
164  * PhysicalAddress64 - 64-bit physical address of ACPI protected
165  * mode entry point
166  *
167  * RETURN: Status
168  *
169  * DESCRIPTION: Sets the FirmwareWakingVector fields of the FACS
170  *
171  ******************************************************************************/
172 
175  ACPI_PHYSICAL_ADDRESS PhysicalAddress,
176  ACPI_PHYSICAL_ADDRESS PhysicalAddress64)
177 {
178 
180 
181  if (AcpiGbl_FACS)
182  {
183  (void) AcpiHwSetFirmwareWakingVector (AcpiGbl_FACS,
184  PhysicalAddress, PhysicalAddress64);
185  }
186 
188 }
189 
191 
192 
193 /*******************************************************************************
194  *
195  * FUNCTION: AcpiEnterSleepStateS4bios
196  *
197  * PARAMETERS: None
198  *
199  * RETURN: Status
200  *
201  * DESCRIPTION: Perform a S4 bios request.
202  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
203  *
204  ******************************************************************************/
205 
208  void)
209 {
210  UINT32 InValue;
212 
213 
215 
216 
217  /* Clear the wake status bit (PM1) */
218 
220  if (ACPI_FAILURE (Status))
221  {
223  }
224 
226  if (ACPI_FAILURE (Status))
227  {
229  }
230 
231  /*
232  * 1) Disable all GPEs
233  * 2) Enable all wakeup GPEs
234  */
236  if (ACPI_FAILURE (Status))
237  {
239  }
240  AcpiGbl_SystemAwakeAndRunning = FALSE;
241 
243  if (ACPI_FAILURE (Status))
244  {
246  }
247 
249 
250  Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand,
251  (UINT32) AcpiGbl_FADT.S4BiosRequest, 8);
252 
253  do {
256  if (ACPI_FAILURE (Status))
257  {
259  }
260 
261  } while (!InValue);
262 
264 }
265 
267 
268 #endif /* !ACPI_REDUCED_HARDWARE */
269 
270 
271 /*******************************************************************************
272  *
273  * FUNCTION: AcpiHwSleepDispatch
274  *
275  * PARAMETERS: SleepState - Which sleep state to enter/exit
276  * FunctionId - Sleep, WakePrep, or Wake
277  *
278  * RETURN: Status from the invoked sleep handling function.
279  *
280  * DESCRIPTION: Dispatch a sleep/wake request to the appropriate handling
281  * function.
282  *
283  ******************************************************************************/
284 
285 static ACPI_STATUS
287  UINT8 SleepState,
288  UINT32 FunctionId)
289 {
291  ACPI_SLEEP_FUNCTIONS *SleepFunctions = &AcpiSleepDispatch[FunctionId];
292 
293 
294 #if (!ACPI_REDUCED_HARDWARE)
295  /*
296  * If the Hardware Reduced flag is set (from the FADT), we must
297  * use the extended sleep registers (FADT). Note: As per the ACPI
298  * specification, these extended registers are to be used for HW-reduced
299  * platforms only. They are not general-purpose replacements for the
300  * legacy PM register sleep support.
301  */
302  if (AcpiGbl_ReducedHardware)
303  {
304  Status = SleepFunctions->ExtendedFunction (SleepState);
305  }
306  else
307  {
308  /* Legacy sleep */
309 
310  Status = SleepFunctions->LegacyFunction (SleepState);
311  }
312 
313  return (Status);
314 
315 #else
316  /*
317  * For the case where reduced-hardware-only code is being generated,
318  * we know that only the extended sleep registers are available
319  */
320  Status = SleepFunctions->ExtendedFunction (SleepState);
321  return (Status);
322 
323 #endif /* !ACPI_REDUCED_HARDWARE */
324 }
325 
326 
327 /*******************************************************************************
328  *
329  * FUNCTION: AcpiEnterSleepStatePrep
330  *
331  * PARAMETERS: SleepState - Which sleep state to enter
332  *
333  * RETURN: Status
334  *
335  * DESCRIPTION: Prepare to enter a system sleep state.
336  * This function must execute with interrupts enabled.
337  * We break sleeping into 2 stages so that OSPM can handle
338  * various OS-specific tasks between the two steps.
339  *
340  ******************************************************************************/
341 
344  UINT8 SleepState)
345 {
347  ACPI_OBJECT_LIST ArgList;
348  ACPI_OBJECT Arg;
349  UINT32 SstValue;
350 
351 
353 
354 
355  Status = AcpiGetSleepTypeData (SleepState,
356  &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB);
357  if (ACPI_FAILURE (Status))
358  {
360  }
361 
362  /* Execute the _PTS method (Prepare To Sleep) */
363 
364  ArgList.Count = 1;
365  ArgList.Pointer = &Arg;
366  Arg.Type = ACPI_TYPE_INTEGER;
367  Arg.Integer.Value = SleepState;
368 
371  {
373  }
374 
375  /* Setup the argument to the _SST method (System STatus) */
376 
377  switch (SleepState)
378  {
379  case ACPI_STATE_S0:
380 
381  SstValue = ACPI_SST_WORKING;
382  break;
383 
384  case ACPI_STATE_S1:
385  case ACPI_STATE_S2:
386  case ACPI_STATE_S3:
387 
388  SstValue = ACPI_SST_SLEEPING;
389  break;
390 
391  case ACPI_STATE_S4:
392 
393  SstValue = ACPI_SST_SLEEP_CONTEXT;
394  break;
395 
396  default:
397 
398  SstValue = ACPI_SST_INDICATOR_OFF; /* Default is off */
399  break;
400  }
401 
402  /*
403  * Set the system indicators to show the desired sleep state.
404  * _SST is an optional method (return no error if not found)
405  */
408 }
409 
411 
412 
413 /*******************************************************************************
414  *
415  * FUNCTION: AcpiEnterSleepState
416  *
417  * PARAMETERS: SleepState - Which sleep state to enter
418  *
419  * RETURN: Status
420  *
421  * DESCRIPTION: Enter a system sleep state
422  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
423  *
424  ******************************************************************************/
425 
428  UINT8 SleepState)
429 {
431 
432 
434 
435 
436  if ((AcpiGbl_SleepTypeA > ACPI_SLEEP_TYPE_MAX) ||
437  (AcpiGbl_SleepTypeB > ACPI_SLEEP_TYPE_MAX))
438  {
439  ACPI_ERROR ((AE_INFO, "Sleep values out of range: A=0x%X B=0x%X",
440  AcpiGbl_SleepTypeA, AcpiGbl_SleepTypeB));
442  }
443 
446 }
447 
449 
450 
451 /*******************************************************************************
452  *
453  * FUNCTION: AcpiLeaveSleepStatePrep
454  *
455  * PARAMETERS: SleepState - Which sleep state we are exiting
456  *
457  * RETURN: Status
458  *
459  * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
460  * sleep. Called with interrupts DISABLED.
461  * We break wake/resume into 2 stages so that OSPM can handle
462  * various OS-specific tasks between the two steps.
463  *
464  ******************************************************************************/
465 
468  UINT8 SleepState)
469 {
471 
472 
474 
475 
478 }
479 
481 
482 
483 /*******************************************************************************
484  *
485  * FUNCTION: AcpiLeaveSleepState
486  *
487  * PARAMETERS: SleepState - Which sleep state we are exiting
488  *
489  * RETURN: Status
490  *
491  * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
492  * Called with interrupts ENABLED.
493  *
494  ******************************************************************************/
495 
498  UINT8 SleepState)
499 {
501 
502 
504 
505 
508 }
509 
ACPI_STATUS AcpiHwDisableAllGpes(void)
Definition: hwgpe.c:543
static ACPI_SLEEP_FUNCTIONS AcpiSleepDispatch[]
Definition: hwxfsleep.c:77
ACPI_STATUS AcpiHwClearAcpiStatus(void)
Definition: hwregs.c:452
#define ACPI_WAKE_FUNCTION_ID
Definition: hwxfsleep.c:73
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
ACPI_STATUS AcpiWriteBitRegister(UINT32 RegisterId, UINT32 Value)
Definition: hwxface.c:282
ACPI_STATUS AcpiHwLegacySleep(UINT8 SleepState)
Definition: hwsleep.c:67
#define ACPI_CLEAR_STATUS
Definition: actypes.h:928
void AcpiOsStall(UINT32 Microseconds)
Definition: osl.c:264
#define ACPI_TYPE_INTEGER
Definition: actypes.h:679
#define AE_AML_OPERAND_VALUE
Definition: acexcep.h:183
#define METHOD_PATHNAME__PTS
Definition: acnames.h:79
void AcpiHwExecuteSleepMethod(char *MethodPathname, UINT32 IntegerArgument)
Definition: hwesleep.c:67
ACPI_STATUS AcpiSetFirmwareWakingVector(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_PHYSICAL_ADDRESS PhysicalAddress64)
Definition: hwxfsleep.c:174
struct acpi_object::@600 Integer
ACPI_STATUS AcpiHwLegacyWake(UINT8 SleepState)
Definition: hwsleep.c:300
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_SLEEP_TYPE_MAX
Definition: actypes.h:641
ACPI_STATUS AcpiGetSleepTypeData(UINT8 SleepState, UINT8 *SleepTypeA, UINT8 *SleepTypeB)
Definition: hwxface.c:411
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
unsigned int UINT32
ACPI_STATUS AcpiHwLegacyWakePrep(UINT8 SleepState)
Definition: hwsleep.c:231
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
#define ACPI_HW_OPTIONAL_FUNCTION(addr)
Definition: acmacros.h:483
ACPI_STATUS AcpiHwWritePort(ACPI_IO_ADDRESS Address, UINT32 Value, UINT32 Width)
Definition: hwvalid.c:312
#define ACPI_SST_WORKING
Definition: achware.h:51
#define ACPI_EXPORT_SYMBOL(Symbol)
Definition: actypes.h:343
#define AE_INFO
Definition: acoutput.h:230
smooth NULL
Definition: ftsmooth.c:416
#define ACPI_STATE_S4
Definition: actypes.h:619
UINT32 Length
Definition: actbl.h:221
#define ACPI_FLUSH_CPU_CACHE()
Definition: accygwin.h:53
#define ACPI_USEC_PER_MSEC
Definition: actypes.h:470
UINT8 Version
Definition: actbl.h:227
#define ACPI_SST_SLEEPING
Definition: achware.h:53
static ACPI_STATUS AcpiHwSetFirmwareWakingVector(ACPI_TABLE_FACS *Facs, ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_PHYSICAL_ADDRESS PhysicalAddress64)
Definition: hwxfsleep.c:118
#define ACPI_SLEEP_FUNCTION_ID
Definition: hwxfsleep.c:71
ACPI_SLEEP_FUNCTION LegacyFunction
Definition: actypes.h:943
static ACPI_STATUS AcpiHwSleepDispatch(UINT8 SleepState, UINT32 FunctionId)
Definition: hwxfsleep.c:286
#define AE_NOT_FOUND
Definition: acexcep.h:113
#define ACPI_SST_SLEEP_CONTEXT
Definition: achware.h:54
ACPI_STATUS AcpiHwEnableAllWakeupGpes(void)
Definition: hwgpe.c:597
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1061
#define ACPI_STATE_S0
Definition: actypes.h:615
#define METHOD_PATHNAME__SST
Definition: acnames.h:80
ACPI_STATUS AcpiReadBitRegister(UINT32 RegisterId, UINT32 *ReturnValue)
Definition: hwxface.c:213
ACPI_SLEEP_FUNCTION ExtendedFunction
Definition: actypes.h:944
Status
Definition: gdiplustypes.h:24
#define ACPI_BITREG_WAKE_STATUS
Definition: actypes.h:898
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
ACPI_STATUS AcpiEvaluateObject(ACPI_HANDLE Handle, ACPI_STRING Pathname, ACPI_OBJECT_LIST *ExternalParams, ACPI_BUFFER *ReturnBuffer)
Definition: nsxfeval.c:217
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_STRUCT_INIT(field, value)
Definition: acenv.h:299
ACPI_STATUS AcpiEnterSleepStateS4bios(void)
Definition: hwxfsleep.c:207
#define ACPI_STATE_S1
Definition: actypes.h:616
#define ACPI_STATE_S2
Definition: actypes.h:617
ACPI_STATUS AcpiHwExtendedWake(UINT8 SleepState)
Definition: hwesleep.c:243
ACPI_OBJECT * Pointer
Definition: actypes.h:1018
ACPI_STATUS AcpiHwExtendedWakePrep(UINT8 SleepState)
Definition: hwesleep.c:204
ACPI_STATUS AcpiHwExtendedSleep(UINT8 SleepState)
Definition: hwesleep.c:112
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
UINT64 XFirmwareWakingVector
Definition: actbl.h:226
ACPI_OBJECT_TYPE Type
Definition: actypes.h:959
#define ACPI_STATE_S3
Definition: actypes.h:618
#define ACPI_SST_INDICATOR_OFF
Definition: achware.h:50
unsigned char UINT8
ACPI_STATUS AcpiLeaveSleepState(UINT8 SleepState)
Definition: hwxfsleep.c:497
#define AE_OK
Definition: acexcep.h:97
ACPI_STATUS AcpiLeaveSleepStatePrep(UINT8 SleepState)
Definition: hwxfsleep.c:467
ACPI_STATUS AcpiEnterSleepStatePrep(UINT8 SleepState)
Definition: hwxfsleep.c:343
ACPI_STATUS AcpiEnterSleepState(UINT8 SleepState)
Definition: hwxfsleep.c:427
#define ACPI_WAKE_PREP_FUNCTION_ID
Definition: hwxfsleep.c:72
UINT32 FirmwareWakingVector
Definition: actbl.h:223