ReactOS  0.4.15-dev-439-g292f67a
hwsleep.c File Reference
#include "acpi.h"
#include "accommon.h"
Include dependency graph for hwsleep.c:

Go to the source code of this file.

Macros

#define _COMPONENT   ACPI_HARDWARE
 

Functions

ACPI_STATUS AcpiHwLegacySleep (UINT8 SleepState)
 
ACPI_STATUS AcpiHwLegacyWakePrep (UINT8 SleepState)
 
ACPI_STATUS AcpiHwLegacyWake (UINT8 SleepState)
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_HARDWARE

Definition at line 48 of file hwsleep.c.

Function Documentation

◆ AcpiHwLegacySleep()

ACPI_STATUS AcpiHwLegacySleep ( UINT8  SleepState)

Definition at line 67 of file hwsleep.c.

69 {
70  ACPI_BIT_REGISTER_INFO *SleepTypeRegInfo;
71  ACPI_BIT_REGISTER_INFO *SleepEnableRegInfo;
72  UINT32 Pm1aControl;
73  UINT32 Pm1bControl;
74  UINT32 InValue;
76 
77 
78  ACPI_FUNCTION_TRACE (HwLegacySleep);
79 
80 
83 
84  /* Clear wake status */
85 
88  if (ACPI_FAILURE (Status))
89  {
91  }
92 
93  /* Disable all GPEs */
94 
96  if (ACPI_FAILURE (Status))
97  {
99  }
101  if (ACPI_FAILURE(Status))
102  {
104  }
105  AcpiGbl_SystemAwakeAndRunning = FALSE;
106 
107  /* Enable all wakeup GPEs */
108 
110  if (ACPI_FAILURE (Status))
111  {
113  }
114 
115  /* Get current value of PM1A control */
116 
118  &Pm1aControl);
119  if (ACPI_FAILURE (Status))
120  {
122  }
124  "Entering sleep state [S%u]\n", SleepState));
125 
126  /* Clear the SLP_EN and SLP_TYP fields */
127 
128  Pm1aControl &= ~(SleepTypeRegInfo->AccessBitMask |
129  SleepEnableRegInfo->AccessBitMask);
130  Pm1bControl = Pm1aControl;
131 
132  /* Insert the SLP_TYP bits */
133 
134  Pm1aControl |= (AcpiGbl_SleepTypeA << SleepTypeRegInfo->BitPosition);
135  Pm1bControl |= (AcpiGbl_SleepTypeB << SleepTypeRegInfo->BitPosition);
136 
137  /*
138  * We split the writes of SLP_TYP and SLP_EN to workaround
139  * poorly implemented hardware.
140  */
141 
142  /* Write #1: write the SLP_TYP data to the PM1 Control registers */
143 
144  Status = AcpiHwWritePm1Control (Pm1aControl, Pm1bControl);
145  if (ACPI_FAILURE (Status))
146  {
148  }
149 
150  /* Insert the sleep enable (SLP_EN) bit */
151 
152  Pm1aControl |= SleepEnableRegInfo->AccessBitMask;
153  Pm1bControl |= SleepEnableRegInfo->AccessBitMask;
154 
155  /* Flush caches, as per ACPI specification */
156 
158 
159  Status = AcpiOsEnterSleep (SleepState, Pm1aControl, Pm1bControl);
160  if (Status == AE_CTRL_TERMINATE)
161  {
163  }
164  if (ACPI_FAILURE (Status))
165  {
167  }
168 
169  /* Write #2: Write both SLP_TYP + SLP_EN */
170 
171  Status = AcpiHwWritePm1Control (Pm1aControl, Pm1bControl);
172  if (ACPI_FAILURE (Status))
173  {
175  }
176 
177  if (SleepState > ACPI_STATE_S3)
178  {
179  /*
180  * We wanted to sleep > S3, but it didn't happen (by virtue of the
181  * fact that we are still executing!)
182  *
183  * Wait ten seconds, then try again. This is to get S4/S5 to work on
184  * all machines.
185  *
186  * We wait so long to allow chipsets that poll this reg very slowly
187  * to still read the right value. Ideally, this block would go
188  * away entirely.
189  */
191 
193  SleepEnableRegInfo->AccessBitMask);
194  if (ACPI_FAILURE (Status))
195  {
197  }
198  }
199 
200  /* Wait for transition back to Working State */
201 
202  do
203  {
205  if (ACPI_FAILURE (Status))
206  {
208  }
209 
210  } while (!InValue);
211 
213 }
ACPI_STATUS AcpiHwDisableAllGpes(void)
Definition: hwgpe.c:595
ACPI_STATUS AcpiHwClearAcpiStatus(void)
Definition: hwregs.c:452
#define ACPI_BITREG_SLEEP_TYPE
Definition: actypes.h:917
ACPI_STATUS AcpiWriteBitRegister(UINT32 RegisterId, UINT32 Value)
Definition: hwxface.c:282
#define ACPI_CLEAR_STATUS
Definition: actypes.h:930
void AcpiOsStall(UINT32 Microseconds)
Definition: osl.c:264
ACPI_STATUS AcpiOsEnterSleep(UINT8 SleepState, UINT32 RegaValue, UINT32 RegbValue)
Definition: osl.c:932
#define ACPI_USEC_PER_SEC
Definition: actypes.h:471
#define ACPI_REGISTER_PM1_CONTROL
Definition: aclocal.h:1186
UINT32 ACPI_STATUS
Definition: actypes.h:460
ACPI_STATUS AcpiHwRegisterRead(UINT32 RegisterId, UINT32 *ReturnValue)
Definition: hwregs.c:574
ACPI_BIT_REGISTER_INFO * AcpiHwGetBitRegisterInfo(UINT32 RegisterId)
Definition: hwregs.c:502
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_CTRL_TERMINATE
Definition: acexcep.h:226
unsigned int UINT32
#define ACPI_FLUSH_CPU_CACHE()
Definition: accygwin.h:53
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_BITREG_SLEEP_ENABLE
Definition: actypes.h:918
ACPI_STATUS AcpiHwEnableAllWakeupGpes(void)
Definition: hwgpe.c:649
ACPI_STATUS AcpiReadBitRegister(UINT32 RegisterId, UINT32 *ReturnValue)
Definition: hwxface.c:213
Status
Definition: gdiplustypes.h:24
#define ACPI_DB_INIT
Definition: acoutput.h:151
#define ACPI_BITREG_WAKE_STATUS
Definition: actypes.h:900
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
ACPI_STATUS AcpiHwRegisterWrite(UINT32 RegisterId, UINT32 Value)
Definition: hwregs.c:684
ACPI_STATUS AcpiHwWritePm1Control(UINT32 Pm1aControl, UINT32 Pm1bControl)
Definition: hwregs.c:536
#define ACPI_STATE_S3
Definition: actypes.h:619
#define AE_OK
Definition: acexcep.h:97

◆ AcpiHwLegacyWake()

ACPI_STATUS AcpiHwLegacyWake ( UINT8  SleepState)

Definition at line 300 of file hwsleep.c.

302 {
304 
305 
306  ACPI_FUNCTION_TRACE (HwLegacyWake);
307 
308 
309  /* Ensure EnterSleepStatePrep -> EnterSleepState ordering */
310 
311  AcpiGbl_SleepTypeA = ACPI_SLEEP_TYPE_INVALID;
313 
314  /*
315  * GPEs must be enabled before _WAK is called as GPEs
316  * might get fired there
317  *
318  * Restore the GPEs:
319  * 1) Disable all GPEs
320  * 2) Enable all runtime GPEs
321  */
323  if (ACPI_FAILURE (Status))
324  {
326  }
327 
329  if (ACPI_FAILURE (Status))
330  {
332  }
333 
334  /*
335  * Now we can execute _WAK, etc. Some machines require that the GPEs
336  * are enabled before the wake methods are executed.
337  */
339 
340  /*
341  * Some BIOS code assumes that WAK_STS will be cleared on resume
342  * and use it to determine whether the system is rebooting or
343  * resuming. Clear WAK_STS for compatibility.
344  */
347  AcpiGbl_SystemAwakeAndRunning = TRUE;
348 
349  /* Enable power button */
350 
354 
358 
359  /* Enable sleep button */
360 
364 
368 
371 }
ACPI_STATUS AcpiHwDisableAllGpes(void)
Definition: hwgpe.c:595
#define TRUE
Definition: types.h:120
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
#define ACPI_CLEAR_STATUS
Definition: actypes.h:930
void AcpiHwExecuteSleepMethod(char *MethodPathname, UINT32 IntegerArgument)
Definition: hwesleep.c:67
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_ENABLE_EVENT
Definition: actypes.h:934
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define METHOD_PATHNAME__WAK
Definition: acnames.h:81
#define ACPI_SST_WORKING
Definition: achware.h:51
ACPI_STATUS AcpiHwEnableAllRuntimeGpes(void)
Definition: hwgpe.c:622
ACPI_FIXED_EVENT_INFO AcpiGbl_FixedEventInfo[ACPI_NUM_FIXED_EVENTS]
Definition: utglobal.c:175
#define ACPI_SST_WAKING
Definition: achware.h:52
#define METHOD_PATHNAME__SST
Definition: acnames.h:80
Status
Definition: gdiplustypes.h:24
#define ACPI_BITREG_WAKE_STATUS
Definition: actypes.h:900
#define ACPI_SLEEP_TYPE_INVALID
Definition: actypes.h:643
#define ACPI_EVENT_POWER_BUTTON
Definition: actypes.h:757
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_EVENT_SLEEP_BUTTON
Definition: actypes.h:758

◆ AcpiHwLegacyWakePrep()

ACPI_STATUS AcpiHwLegacyWakePrep ( UINT8  SleepState)

Definition at line 231 of file hwsleep.c.

233 {
235  ACPI_BIT_REGISTER_INFO *SleepTypeRegInfo;
236  ACPI_BIT_REGISTER_INFO *SleepEnableRegInfo;
237  UINT32 Pm1aControl;
238  UINT32 Pm1bControl;
239 
240 
241  ACPI_FUNCTION_TRACE (HwLegacyWakePrep);
242 
243  /*
244  * Set SLP_TYPE and SLP_EN to state S0.
245  * This is unclear from the ACPI Spec, but it is required
246  * by some machines.
247  */
249  &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB);
250  if (ACPI_SUCCESS (Status))
251  {
252  SleepTypeRegInfo =
254  SleepEnableRegInfo =
256 
257  /* Get current value of PM1A control */
258 
260  &Pm1aControl);
261  if (ACPI_SUCCESS (Status))
262  {
263  /* Clear the SLP_EN and SLP_TYP fields */
264 
265  Pm1aControl &= ~(SleepTypeRegInfo->AccessBitMask |
266  SleepEnableRegInfo->AccessBitMask);
267  Pm1bControl = Pm1aControl;
268 
269  /* Insert the SLP_TYP bits */
270 
271  Pm1aControl |= (AcpiGbl_SleepTypeA <<
272  SleepTypeRegInfo->BitPosition);
273  Pm1bControl |= (AcpiGbl_SleepTypeB <<
274  SleepTypeRegInfo->BitPosition);
275 
276  /* Write the control registers and ignore any errors */
277 
278  (void) AcpiHwWritePm1Control (Pm1aControl, Pm1bControl);
279  }
280  }
281 
283 }
#define ACPI_BITREG_SLEEP_TYPE
Definition: actypes.h:917
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define ACPI_REGISTER_PM1_CONTROL
Definition: aclocal.h:1186
UINT32 ACPI_STATUS
Definition: actypes.h:460
ACPI_STATUS AcpiHwRegisterRead(UINT32 RegisterId, UINT32 *ReturnValue)
Definition: hwregs.c:574
ACPI_STATUS AcpiGetSleepTypeData(UINT8 SleepState, UINT8 *SleepTypeA, UINT8 *SleepTypeB)
Definition: hwxface.c:411
ACPI_BIT_REGISTER_INFO * AcpiHwGetBitRegisterInfo(UINT32 RegisterId)
Definition: hwregs.c:502
unsigned int UINT32
#define ACPI_BITREG_SLEEP_ENABLE
Definition: actypes.h:918
#define ACPI_STATE_S0
Definition: actypes.h:616
Status
Definition: gdiplustypes.h:24
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
ACPI_STATUS AcpiHwWritePm1Control(UINT32 Pm1aControl, UINT32 Pm1bControl)
Definition: hwregs.c:536