xref: /onnv-gate/usr/src/uts/intel/io/acpica/hardware/hwsleep.c (revision 3446:5903aece022d)
1*3446Smrj 
2*3446Smrj /******************************************************************************
3*3446Smrj  *
4*3446Smrj  * Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface
5*3446Smrj  *              $Revision: 1.82 $
6*3446Smrj  *
7*3446Smrj  *****************************************************************************/
8*3446Smrj 
9*3446Smrj /******************************************************************************
10*3446Smrj  *
11*3446Smrj  * 1. Copyright Notice
12*3446Smrj  *
13*3446Smrj  * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
14*3446Smrj  * All rights reserved.
15*3446Smrj  *
16*3446Smrj  * 2. License
17*3446Smrj  *
18*3446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
19*3446Smrj  * rights.  You may have additional license terms from the party that provided
20*3446Smrj  * you this software, covering your right to use that party's intellectual
21*3446Smrj  * property rights.
22*3446Smrj  *
23*3446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24*3446Smrj  * copy of the source code appearing in this file ("Covered Code") an
25*3446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26*3446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
27*3446Smrj  * make derivatives, distribute, use and display any portion of the Covered
28*3446Smrj  * Code in any form, with the right to sublicense such rights; and
29*3446Smrj  *
30*3446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31*3446Smrj  * license (with the right to sublicense), under only those claims of Intel
32*3446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
33*3446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
34*3446Smrj  * solely to the minimum extent necessary to exercise the above copyright
35*3446Smrj  * license, and in no event shall the patent license extend to any additions
36*3446Smrj  * to or modifications of the Original Intel Code.  No other license or right
37*3446Smrj  * is granted directly or by implication, estoppel or otherwise;
38*3446Smrj  *
39*3446Smrj  * The above copyright and patent license is granted only if the following
40*3446Smrj  * conditions are met:
41*3446Smrj  *
42*3446Smrj  * 3. Conditions
43*3446Smrj  *
44*3446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45*3446Smrj  * Redistribution of source code of any substantial portion of the Covered
46*3446Smrj  * Code or modification with rights to further distribute source must include
47*3446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
48*3446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
49*3446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
50*3446Smrj  * contain a file documenting the changes Licensee made to create that Covered
51*3446Smrj  * Code and the date of any change.  Licensee must include in that file the
52*3446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
53*3446Smrj  * must include a prominent statement that the modification is derived,
54*3446Smrj  * directly or indirectly, from Original Intel Code.
55*3446Smrj  *
56*3446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57*3446Smrj  * Redistribution of source code of any substantial portion of the Covered
58*3446Smrj  * Code or modification without rights to further distribute source must
59*3446Smrj  * include the following Disclaimer and Export Compliance provision in the
60*3446Smrj  * documentation and/or other materials provided with distribution.  In
61*3446Smrj  * addition, Licensee may not authorize further sublicense of source of any
62*3446Smrj  * portion of the Covered Code, and must include terms to the effect that the
63*3446Smrj  * license from Licensee to its licensee is limited to the intellectual
64*3446Smrj  * property embodied in the software Licensee provides to its licensee, and
65*3446Smrj  * not to intellectual property embodied in modifications its licensee may
66*3446Smrj  * make.
67*3446Smrj  *
68*3446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
69*3446Smrj  * substantial portion of the Covered Code or modification must reproduce the
70*3446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
71*3446Smrj  * provision in the documentation and/or other materials provided with the
72*3446Smrj  * distribution.
73*3446Smrj  *
74*3446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
75*3446Smrj  * Intel Code.
76*3446Smrj  *
77*3446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78*3446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
79*3446Smrj  * other dealings in products derived from or relating to the Covered Code
80*3446Smrj  * without prior written authorization from Intel.
81*3446Smrj  *
82*3446Smrj  * 4. Disclaimer and Export Compliance
83*3446Smrj  *
84*3446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85*3446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86*3446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87*3446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88*3446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89*3446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90*3446Smrj  * PARTICULAR PURPOSE.
91*3446Smrj  *
92*3446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93*3446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94*3446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95*3446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96*3446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97*3446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98*3446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99*3446Smrj  * LIMITED REMEDY.
100*3446Smrj  *
101*3446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
102*3446Smrj  * software or system incorporating such software without first obtaining any
103*3446Smrj  * required license or other approval from the U. S. Department of Commerce or
104*3446Smrj  * any other agency or department of the United States Government.  In the
105*3446Smrj  * event Licensee exports any such software from the United States or
106*3446Smrj  * re-exports any such software from a foreign destination, Licensee shall
107*3446Smrj  * ensure that the distribution and export/re-export of the software is in
108*3446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
109*3446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110*3446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
111*3446Smrj  * software, or service, directly or indirectly, to any country for which the
112*3446Smrj  * United States government or any agency thereof requires an export license,
113*3446Smrj  * other governmental approval, or letter of assurance, without first obtaining
114*3446Smrj  * such license, approval or letter.
115*3446Smrj  *
116*3446Smrj  *****************************************************************************/
117*3446Smrj 
118*3446Smrj #include "acpi.h"
119*3446Smrj 
120*3446Smrj #define _COMPONENT          ACPI_HARDWARE
121*3446Smrj         ACPI_MODULE_NAME    ("hwsleep")
122*3446Smrj 
123*3446Smrj 
124*3446Smrj /*******************************************************************************
125*3446Smrj  *
126*3446Smrj  * FUNCTION:    AcpiSetFirmwareWakingVector
127*3446Smrj  *
128*3446Smrj  * PARAMETERS:  PhysicalAddress     - Physical address of ACPI real mode
129*3446Smrj  *                                    entry point.
130*3446Smrj  *
131*3446Smrj  * RETURN:      Status
132*3446Smrj  *
133*3446Smrj  * DESCRIPTION: Access function for the FirmwareWakingVector field in FACS
134*3446Smrj  *
135*3446Smrj  ******************************************************************************/
136*3446Smrj 
137*3446Smrj ACPI_STATUS
138*3446Smrj AcpiSetFirmwareWakingVector (
139*3446Smrj     ACPI_PHYSICAL_ADDRESS PhysicalAddress)
140*3446Smrj {
141*3446Smrj 
142*3446Smrj     ACPI_FUNCTION_TRACE (AcpiSetFirmwareWakingVector);
143*3446Smrj 
144*3446Smrj 
145*3446Smrj     /* Set the vector */
146*3446Smrj 
147*3446Smrj     if (AcpiGbl_CommonFACS.VectorWidth == 32)
148*3446Smrj     {
149*3446Smrj         *(ACPI_CAST_PTR (UINT32, AcpiGbl_CommonFACS.FirmwareWakingVector))
150*3446Smrj                 = (UINT32) PhysicalAddress;
151*3446Smrj     }
152*3446Smrj     else
153*3446Smrj     {
154*3446Smrj         *AcpiGbl_CommonFACS.FirmwareWakingVector
155*3446Smrj                 = PhysicalAddress;
156*3446Smrj     }
157*3446Smrj 
158*3446Smrj     return_ACPI_STATUS (AE_OK);
159*3446Smrj }
160*3446Smrj 
161*3446Smrj ACPI_EXPORT_SYMBOL (AcpiSetFirmwareWakingVector)
162*3446Smrj 
163*3446Smrj 
164*3446Smrj /*******************************************************************************
165*3446Smrj  *
166*3446Smrj  * FUNCTION:    AcpiGetFirmwareWakingVector
167*3446Smrj  *
168*3446Smrj  * PARAMETERS:  *PhysicalAddress    - Where the contents of
169*3446Smrj  *                                    the FirmwareWakingVector field of
170*3446Smrj  *                                    the FACS will be returned.
171*3446Smrj  *
172*3446Smrj  * RETURN:      Status, vector
173*3446Smrj  *
174*3446Smrj  * DESCRIPTION: Access function for the FirmwareWakingVector field in FACS
175*3446Smrj  *
176*3446Smrj  ******************************************************************************/
177*3446Smrj 
178*3446Smrj ACPI_STATUS
179*3446Smrj AcpiGetFirmwareWakingVector (
180*3446Smrj     ACPI_PHYSICAL_ADDRESS *PhysicalAddress)
181*3446Smrj {
182*3446Smrj 
183*3446Smrj     ACPI_FUNCTION_TRACE (AcpiGetFirmwareWakingVector);
184*3446Smrj 
185*3446Smrj 
186*3446Smrj     if (!PhysicalAddress)
187*3446Smrj     {
188*3446Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
189*3446Smrj     }
190*3446Smrj 
191*3446Smrj     /* Get the vector */
192*3446Smrj 
193*3446Smrj     if (AcpiGbl_CommonFACS.VectorWidth == 32)
194*3446Smrj     {
195*3446Smrj         *PhysicalAddress = (ACPI_PHYSICAL_ADDRESS)
196*3446Smrj             *(ACPI_CAST_PTR (UINT32, AcpiGbl_CommonFACS.FirmwareWakingVector));
197*3446Smrj     }
198*3446Smrj     else
199*3446Smrj     {
200*3446Smrj         *PhysicalAddress =
201*3446Smrj             *AcpiGbl_CommonFACS.FirmwareWakingVector;
202*3446Smrj     }
203*3446Smrj 
204*3446Smrj     return_ACPI_STATUS (AE_OK);
205*3446Smrj }
206*3446Smrj 
207*3446Smrj ACPI_EXPORT_SYMBOL (AcpiGetFirmwareWakingVector)
208*3446Smrj 
209*3446Smrj 
210*3446Smrj /*******************************************************************************
211*3446Smrj  *
212*3446Smrj  * FUNCTION:    AcpiEnterSleepStatePrep
213*3446Smrj  *
214*3446Smrj  * PARAMETERS:  SleepState          - Which sleep state to enter
215*3446Smrj  *
216*3446Smrj  * RETURN:      Status
217*3446Smrj  *
218*3446Smrj  * DESCRIPTION: Prepare to enter a system sleep state (see ACPI 2.0 spec p 231)
219*3446Smrj  *              This function must execute with interrupts enabled.
220*3446Smrj  *              We break sleeping into 2 stages so that OSPM can handle
221*3446Smrj  *              various OS-specific tasks between the two steps.
222*3446Smrj  *
223*3446Smrj  ******************************************************************************/
224*3446Smrj 
225*3446Smrj ACPI_STATUS
226*3446Smrj AcpiEnterSleepStatePrep (
227*3446Smrj     UINT8               SleepState)
228*3446Smrj {
229*3446Smrj     ACPI_STATUS         Status;
230*3446Smrj     ACPI_OBJECT_LIST    ArgList;
231*3446Smrj     ACPI_OBJECT         Arg;
232*3446Smrj 
233*3446Smrj 
234*3446Smrj     ACPI_FUNCTION_TRACE (AcpiEnterSleepStatePrep);
235*3446Smrj 
236*3446Smrj 
237*3446Smrj     /*
238*3446Smrj      * _PSW methods could be run here to enable wake-on keyboard, LAN, etc.
239*3446Smrj      */
240*3446Smrj     Status = AcpiGetSleepTypeData (SleepState,
241*3446Smrj                     &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB);
242*3446Smrj     if (ACPI_FAILURE (Status))
243*3446Smrj     {
244*3446Smrj         return_ACPI_STATUS (Status);
245*3446Smrj     }
246*3446Smrj 
247*3446Smrj     /* Setup parameter object */
248*3446Smrj 
249*3446Smrj     ArgList.Count = 1;
250*3446Smrj     ArgList.Pointer = &Arg;
251*3446Smrj 
252*3446Smrj     Arg.Type = ACPI_TYPE_INTEGER;
253*3446Smrj     Arg.Integer.Value = SleepState;
254*3446Smrj 
255*3446Smrj     /* Run the _PTS and _GTS methods */
256*3446Smrj 
257*3446Smrj     Status = AcpiEvaluateObject (NULL, METHOD_NAME__PTS, &ArgList, NULL);
258*3446Smrj     if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND)
259*3446Smrj     {
260*3446Smrj         return_ACPI_STATUS (Status);
261*3446Smrj     }
262*3446Smrj 
263*3446Smrj     Status = AcpiEvaluateObject (NULL, METHOD_NAME__GTS, &ArgList, NULL);
264*3446Smrj     if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND)
265*3446Smrj     {
266*3446Smrj         return_ACPI_STATUS (Status);
267*3446Smrj     }
268*3446Smrj 
269*3446Smrj     /* Setup the argument to _SST */
270*3446Smrj 
271*3446Smrj     switch (SleepState)
272*3446Smrj     {
273*3446Smrj     case ACPI_STATE_S0:
274*3446Smrj         Arg.Integer.Value = ACPI_SST_WORKING;
275*3446Smrj         break;
276*3446Smrj 
277*3446Smrj     case ACPI_STATE_S1:
278*3446Smrj     case ACPI_STATE_S2:
279*3446Smrj     case ACPI_STATE_S3:
280*3446Smrj         Arg.Integer.Value = ACPI_SST_SLEEPING;
281*3446Smrj         break;
282*3446Smrj 
283*3446Smrj     case ACPI_STATE_S4:
284*3446Smrj         Arg.Integer.Value = ACPI_SST_SLEEP_CONTEXT;
285*3446Smrj         break;
286*3446Smrj 
287*3446Smrj     default:
288*3446Smrj         Arg.Integer.Value = ACPI_SST_INDICATOR_OFF; /* Default is off */
289*3446Smrj         break;
290*3446Smrj     }
291*3446Smrj 
292*3446Smrj     /* Set the system indicators to show the desired sleep state. */
293*3446Smrj 
294*3446Smrj     Status = AcpiEvaluateObject (NULL, METHOD_NAME__SST, &ArgList, NULL);
295*3446Smrj     if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND)
296*3446Smrj     {
297*3446Smrj         ACPI_EXCEPTION ((AE_INFO, Status, "While executing method _SST"));
298*3446Smrj     }
299*3446Smrj 
300*3446Smrj     return_ACPI_STATUS (AE_OK);
301*3446Smrj }
302*3446Smrj 
303*3446Smrj ACPI_EXPORT_SYMBOL (AcpiEnterSleepStatePrep)
304*3446Smrj 
305*3446Smrj 
306*3446Smrj /*******************************************************************************
307*3446Smrj  *
308*3446Smrj  * FUNCTION:    AcpiEnterSleepState
309*3446Smrj  *
310*3446Smrj  * PARAMETERS:  SleepState          - Which sleep state to enter
311*3446Smrj  *
312*3446Smrj  * RETURN:      Status
313*3446Smrj  *
314*3446Smrj  * DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231)
315*3446Smrj  *              THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
316*3446Smrj  *
317*3446Smrj  ******************************************************************************/
318*3446Smrj 
319*3446Smrj ACPI_STATUS
320*3446Smrj AcpiEnterSleepState (
321*3446Smrj     UINT8                   SleepState)
322*3446Smrj {
323*3446Smrj     UINT32                  PM1AControl;
324*3446Smrj     UINT32                  PM1BControl;
325*3446Smrj     ACPI_BIT_REGISTER_INFO  *SleepTypeRegInfo;
326*3446Smrj     ACPI_BIT_REGISTER_INFO  *SleepEnableRegInfo;
327*3446Smrj     UINT32                  InValue;
328*3446Smrj     ACPI_STATUS             Status;
329*3446Smrj 
330*3446Smrj 
331*3446Smrj     ACPI_FUNCTION_TRACE (AcpiEnterSleepState);
332*3446Smrj 
333*3446Smrj 
334*3446Smrj     if ((AcpiGbl_SleepTypeA > ACPI_SLEEP_TYPE_MAX) ||
335*3446Smrj         (AcpiGbl_SleepTypeB > ACPI_SLEEP_TYPE_MAX))
336*3446Smrj     {
337*3446Smrj         ACPI_ERROR ((AE_INFO, "Sleep values out of range: A=%X B=%X",
338*3446Smrj             AcpiGbl_SleepTypeA, AcpiGbl_SleepTypeB));
339*3446Smrj         return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
340*3446Smrj     }
341*3446Smrj 
342*3446Smrj     SleepTypeRegInfo   = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_TYPE_A);
343*3446Smrj     SleepEnableRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_ENABLE);
344*3446Smrj 
345*3446Smrj     /* Clear wake status */
346*3446Smrj 
347*3446Smrj     Status = AcpiSetRegister (ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK);
348*3446Smrj     if (ACPI_FAILURE (Status))
349*3446Smrj     {
350*3446Smrj         return_ACPI_STATUS (Status);
351*3446Smrj     }
352*3446Smrj 
353*3446Smrj     /* Clear all fixed and general purpose status bits */
354*3446Smrj 
355*3446Smrj     Status = AcpiHwClearAcpiStatus (ACPI_MTX_DO_NOT_LOCK);
356*3446Smrj     if (ACPI_FAILURE (Status))
357*3446Smrj     {
358*3446Smrj         return_ACPI_STATUS (Status);
359*3446Smrj     }
360*3446Smrj 
361*3446Smrj     if (SleepState != ACPI_STATE_S5)
362*3446Smrj     {
363*3446Smrj         /* Disable BM arbitration */
364*3446Smrj 
365*3446Smrj         Status = AcpiSetRegister (ACPI_BITREG_ARB_DISABLE,
366*3446Smrj                     1, ACPI_MTX_DO_NOT_LOCK);
367*3446Smrj         if (ACPI_FAILURE (Status))
368*3446Smrj         {
369*3446Smrj             return_ACPI_STATUS (Status);
370*3446Smrj         }
371*3446Smrj     }
372*3446Smrj 
373*3446Smrj     /*
374*3446Smrj      * 1) Disable/Clear all GPEs
375*3446Smrj      * 2) Enable all wakeup GPEs
376*3446Smrj      */
377*3446Smrj     Status = AcpiHwDisableAllGpes ();
378*3446Smrj     if (ACPI_FAILURE (Status))
379*3446Smrj     {
380*3446Smrj         return_ACPI_STATUS (Status);
381*3446Smrj     }
382*3446Smrj     AcpiGbl_SystemAwakeAndRunning = FALSE;
383*3446Smrj 
384*3446Smrj     Status = AcpiHwEnableAllWakeupGpes ();
385*3446Smrj     if (ACPI_FAILURE (Status))
386*3446Smrj     {
387*3446Smrj         return_ACPI_STATUS (Status);
388*3446Smrj     }
389*3446Smrj 
390*3446Smrj     /* Get current value of PM1A control */
391*3446Smrj 
392*3446Smrj     Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK,
393*3446Smrj                 ACPI_REGISTER_PM1_CONTROL, &PM1AControl);
394*3446Smrj     if (ACPI_FAILURE (Status))
395*3446Smrj     {
396*3446Smrj         return_ACPI_STATUS (Status);
397*3446Smrj     }
398*3446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
399*3446Smrj         "Entering sleep state [S%d]\n", SleepState));
400*3446Smrj 
401*3446Smrj     /* Clear SLP_EN and SLP_TYP fields */
402*3446Smrj 
403*3446Smrj     PM1AControl &= ~(SleepTypeRegInfo->AccessBitMask |
404*3446Smrj                      SleepEnableRegInfo->AccessBitMask);
405*3446Smrj     PM1BControl = PM1AControl;
406*3446Smrj 
407*3446Smrj     /* Insert SLP_TYP bits */
408*3446Smrj 
409*3446Smrj     PM1AControl |= (AcpiGbl_SleepTypeA << SleepTypeRegInfo->BitPosition);
410*3446Smrj     PM1BControl |= (AcpiGbl_SleepTypeB << SleepTypeRegInfo->BitPosition);
411*3446Smrj 
412*3446Smrj     /*
413*3446Smrj      * We split the writes of SLP_TYP and SLP_EN to workaround
414*3446Smrj      * poorly implemented hardware.
415*3446Smrj      */
416*3446Smrj 
417*3446Smrj     /* Write #1: fill in SLP_TYP data */
418*3446Smrj 
419*3446Smrj     Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK,
420*3446Smrj                 ACPI_REGISTER_PM1A_CONTROL, PM1AControl);
421*3446Smrj     if (ACPI_FAILURE (Status))
422*3446Smrj     {
423*3446Smrj         return_ACPI_STATUS (Status);
424*3446Smrj     }
425*3446Smrj 
426*3446Smrj     Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK,
427*3446Smrj                 ACPI_REGISTER_PM1B_CONTROL, PM1BControl);
428*3446Smrj     if (ACPI_FAILURE (Status))
429*3446Smrj     {
430*3446Smrj         return_ACPI_STATUS (Status);
431*3446Smrj     }
432*3446Smrj 
433*3446Smrj     /* Insert SLP_ENABLE bit */
434*3446Smrj 
435*3446Smrj     PM1AControl |= SleepEnableRegInfo->AccessBitMask;
436*3446Smrj     PM1BControl |= SleepEnableRegInfo->AccessBitMask;
437*3446Smrj 
438*3446Smrj     /* Write #2: SLP_TYP + SLP_EN */
439*3446Smrj 
440*3446Smrj     ACPI_FLUSH_CPU_CACHE ();
441*3446Smrj 
442*3446Smrj     Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK,
443*3446Smrj                 ACPI_REGISTER_PM1A_CONTROL, PM1AControl);
444*3446Smrj     if (ACPI_FAILURE (Status))
445*3446Smrj     {
446*3446Smrj         return_ACPI_STATUS (Status);
447*3446Smrj     }
448*3446Smrj 
449*3446Smrj     Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK,
450*3446Smrj                 ACPI_REGISTER_PM1B_CONTROL, PM1BControl);
451*3446Smrj     if (ACPI_FAILURE (Status))
452*3446Smrj     {
453*3446Smrj         return_ACPI_STATUS (Status);
454*3446Smrj     }
455*3446Smrj 
456*3446Smrj     if (SleepState > ACPI_STATE_S3)
457*3446Smrj     {
458*3446Smrj         /*
459*3446Smrj          * We wanted to sleep > S3, but it didn't happen (by virtue of the
460*3446Smrj          * fact that we are still executing!)
461*3446Smrj          *
462*3446Smrj          * Wait ten seconds, then try again. This is to get S4/S5 to work on
463*3446Smrj          * all machines.
464*3446Smrj          *
465*3446Smrj          * We wait so long to allow chipsets that poll this reg very slowly to
466*3446Smrj          * still read the right value. Ideally, this block would go
467*3446Smrj          * away entirely.
468*3446Smrj          */
469*3446Smrj         AcpiOsStall (10000000);
470*3446Smrj 
471*3446Smrj         Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK,
472*3446Smrj                     ACPI_REGISTER_PM1_CONTROL,
473*3446Smrj                     SleepEnableRegInfo->AccessBitMask);
474*3446Smrj         if (ACPI_FAILURE (Status))
475*3446Smrj         {
476*3446Smrj             return_ACPI_STATUS (Status);
477*3446Smrj         }
478*3446Smrj     }
479*3446Smrj 
480*3446Smrj     /* Wait until we enter sleep state */
481*3446Smrj 
482*3446Smrj     do
483*3446Smrj     {
484*3446Smrj         Status = AcpiGetRegister (ACPI_BITREG_WAKE_STATUS, &InValue,
485*3446Smrj             ACPI_MTX_DO_NOT_LOCK);
486*3446Smrj         if (ACPI_FAILURE (Status))
487*3446Smrj         {
488*3446Smrj             return_ACPI_STATUS (Status);
489*3446Smrj         }
490*3446Smrj 
491*3446Smrj         /* Spin until we wake */
492*3446Smrj 
493*3446Smrj     } while (!InValue);
494*3446Smrj 
495*3446Smrj     return_ACPI_STATUS (AE_OK);
496*3446Smrj }
497*3446Smrj 
498*3446Smrj ACPI_EXPORT_SYMBOL (AcpiEnterSleepState)
499*3446Smrj 
500*3446Smrj 
501*3446Smrj /*******************************************************************************
502*3446Smrj  *
503*3446Smrj  * FUNCTION:    AcpiEnterSleepStateS4bios
504*3446Smrj  *
505*3446Smrj  * PARAMETERS:  None
506*3446Smrj  *
507*3446Smrj  * RETURN:      Status
508*3446Smrj  *
509*3446Smrj  * DESCRIPTION: Perform a S4 bios request.
510*3446Smrj  *              THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
511*3446Smrj  *
512*3446Smrj  ******************************************************************************/
513*3446Smrj 
514*3446Smrj ACPI_STATUS
515*3446Smrj AcpiEnterSleepStateS4bios (
516*3446Smrj     void)
517*3446Smrj {
518*3446Smrj     UINT32                  InValue;
519*3446Smrj     ACPI_STATUS             Status;
520*3446Smrj 
521*3446Smrj 
522*3446Smrj     ACPI_FUNCTION_TRACE (AcpiEnterSleepStateS4bios);
523*3446Smrj 
524*3446Smrj 
525*3446Smrj     Status = AcpiSetRegister (ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK);
526*3446Smrj     if (ACPI_FAILURE (Status))
527*3446Smrj     {
528*3446Smrj         return_ACPI_STATUS (Status);
529*3446Smrj     }
530*3446Smrj 
531*3446Smrj     Status = AcpiHwClearAcpiStatus (ACPI_MTX_DO_NOT_LOCK);
532*3446Smrj     if (ACPI_FAILURE (Status))
533*3446Smrj     {
534*3446Smrj         return_ACPI_STATUS (Status);
535*3446Smrj     }
536*3446Smrj 
537*3446Smrj     /*
538*3446Smrj      * 1) Disable/Clear all GPEs
539*3446Smrj      * 2) Enable all wakeup GPEs
540*3446Smrj      */
541*3446Smrj     Status = AcpiHwDisableAllGpes ();
542*3446Smrj     if (ACPI_FAILURE (Status))
543*3446Smrj     {
544*3446Smrj         return_ACPI_STATUS (Status);
545*3446Smrj     }
546*3446Smrj     AcpiGbl_SystemAwakeAndRunning = FALSE;
547*3446Smrj 
548*3446Smrj     Status = AcpiHwEnableAllWakeupGpes ();
549*3446Smrj     if (ACPI_FAILURE (Status))
550*3446Smrj     {
551*3446Smrj         return_ACPI_STATUS (Status);
552*3446Smrj     }
553*3446Smrj 
554*3446Smrj     ACPI_FLUSH_CPU_CACHE ();
555*3446Smrj 
556*3446Smrj     Status = AcpiOsWritePort (AcpiGbl_FADT->SmiCmd,
557*3446Smrj                 (UINT32) AcpiGbl_FADT->S4BiosReq, 8);
558*3446Smrj 
559*3446Smrj     do {
560*3446Smrj         AcpiOsStall(1000);
561*3446Smrj         Status = AcpiGetRegister (ACPI_BITREG_WAKE_STATUS, &InValue,
562*3446Smrj             ACPI_MTX_DO_NOT_LOCK);
563*3446Smrj         if (ACPI_FAILURE (Status))
564*3446Smrj         {
565*3446Smrj             return_ACPI_STATUS (Status);
566*3446Smrj         }
567*3446Smrj     } while (!InValue);
568*3446Smrj 
569*3446Smrj     return_ACPI_STATUS (AE_OK);
570*3446Smrj }
571*3446Smrj 
572*3446Smrj ACPI_EXPORT_SYMBOL (AcpiEnterSleepStateS4bios)
573*3446Smrj 
574*3446Smrj 
575*3446Smrj /*******************************************************************************
576*3446Smrj  *
577*3446Smrj  * FUNCTION:    AcpiLeaveSleepState
578*3446Smrj  *
579*3446Smrj  * PARAMETERS:  SleepState          - Which sleep state we just exited
580*3446Smrj  *
581*3446Smrj  * RETURN:      Status
582*3446Smrj  *
583*3446Smrj  * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
584*3446Smrj  *              Called with interrupts ENABLED.
585*3446Smrj  *
586*3446Smrj  ******************************************************************************/
587*3446Smrj 
588*3446Smrj ACPI_STATUS
589*3446Smrj AcpiLeaveSleepState (
590*3446Smrj     UINT8                   SleepState)
591*3446Smrj {
592*3446Smrj     ACPI_OBJECT_LIST        ArgList;
593*3446Smrj     ACPI_OBJECT             Arg;
594*3446Smrj     ACPI_STATUS             Status;
595*3446Smrj     ACPI_BIT_REGISTER_INFO  *SleepTypeRegInfo;
596*3446Smrj     ACPI_BIT_REGISTER_INFO  *SleepEnableRegInfo;
597*3446Smrj     UINT32                  PM1AControl;
598*3446Smrj     UINT32                  PM1BControl;
599*3446Smrj 
600*3446Smrj 
601*3446Smrj     ACPI_FUNCTION_TRACE (AcpiLeaveSleepState);
602*3446Smrj 
603*3446Smrj 
604*3446Smrj     /*
605*3446Smrj      * Set SLP_TYPE and SLP_EN to state S0.
606*3446Smrj      * This is unclear from the ACPI Spec, but it is required
607*3446Smrj      * by some machines.
608*3446Smrj      */
609*3446Smrj     Status = AcpiGetSleepTypeData (ACPI_STATE_S0,
610*3446Smrj                     &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB);
611*3446Smrj     if (ACPI_SUCCESS (Status))
612*3446Smrj     {
613*3446Smrj         SleepTypeRegInfo   = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_TYPE_A);
614*3446Smrj         SleepEnableRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_ENABLE);
615*3446Smrj 
616*3446Smrj         /* Get current value of PM1A control */
617*3446Smrj 
618*3446Smrj         Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK,
619*3446Smrj                     ACPI_REGISTER_PM1_CONTROL, &PM1AControl);
620*3446Smrj         if (ACPI_SUCCESS (Status))
621*3446Smrj         {
622*3446Smrj             /* Clear SLP_EN and SLP_TYP fields */
623*3446Smrj 
624*3446Smrj             PM1AControl &= ~(SleepTypeRegInfo->AccessBitMask |
625*3446Smrj                              SleepEnableRegInfo->AccessBitMask);
626*3446Smrj             PM1BControl = PM1AControl;
627*3446Smrj 
628*3446Smrj             /* Insert SLP_TYP bits */
629*3446Smrj 
630*3446Smrj             PM1AControl |= (AcpiGbl_SleepTypeA << SleepTypeRegInfo->BitPosition);
631*3446Smrj             PM1BControl |= (AcpiGbl_SleepTypeB << SleepTypeRegInfo->BitPosition);
632*3446Smrj 
633*3446Smrj             /* Just ignore any errors */
634*3446Smrj 
635*3446Smrj             (void) AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK,
636*3446Smrj                             ACPI_REGISTER_PM1A_CONTROL, PM1AControl);
637*3446Smrj             (void) AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK,
638*3446Smrj                             ACPI_REGISTER_PM1B_CONTROL, PM1BControl);
639*3446Smrj         }
640*3446Smrj     }
641*3446Smrj 
642*3446Smrj     /* Ensure EnterSleepStatePrep -> EnterSleepState ordering */
643*3446Smrj 
644*3446Smrj     AcpiGbl_SleepTypeA = ACPI_SLEEP_TYPE_INVALID;
645*3446Smrj 
646*3446Smrj     /* Setup parameter object */
647*3446Smrj 
648*3446Smrj     ArgList.Count = 1;
649*3446Smrj     ArgList.Pointer = &Arg;
650*3446Smrj     Arg.Type = ACPI_TYPE_INTEGER;
651*3446Smrj 
652*3446Smrj     /* Ignore any errors from these methods */
653*3446Smrj 
654*3446Smrj     Arg.Integer.Value = ACPI_SST_WAKING;
655*3446Smrj     Status = AcpiEvaluateObject (NULL, METHOD_NAME__SST, &ArgList, NULL);
656*3446Smrj     if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND)
657*3446Smrj     {
658*3446Smrj         ACPI_EXCEPTION ((AE_INFO, Status, "During Method _SST"));
659*3446Smrj     }
660*3446Smrj 
661*3446Smrj     Arg.Integer.Value = SleepState;
662*3446Smrj     Status = AcpiEvaluateObject (NULL, METHOD_NAME__BFS, &ArgList, NULL);
663*3446Smrj     if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND)
664*3446Smrj     {
665*3446Smrj         ACPI_EXCEPTION ((AE_INFO, Status, "During Method _BFS"));
666*3446Smrj     }
667*3446Smrj 
668*3446Smrj     Status = AcpiEvaluateObject (NULL, METHOD_NAME__WAK, &ArgList, NULL);
669*3446Smrj     if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND)
670*3446Smrj     {
671*3446Smrj         ACPI_EXCEPTION ((AE_INFO, Status, "During Method _WAK"));
672*3446Smrj     }
673*3446Smrj     /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */
674*3446Smrj 
675*3446Smrj     /*
676*3446Smrj      * Restore the GPEs:
677*3446Smrj      * 1) Disable/Clear all GPEs
678*3446Smrj      * 2) Enable all runtime GPEs
679*3446Smrj      */
680*3446Smrj     Status = AcpiHwDisableAllGpes ();
681*3446Smrj     if (ACPI_FAILURE (Status))
682*3446Smrj     {
683*3446Smrj         return_ACPI_STATUS (Status);
684*3446Smrj     }
685*3446Smrj     AcpiGbl_SystemAwakeAndRunning = TRUE;
686*3446Smrj 
687*3446Smrj     Status = AcpiHwEnableAllRuntimeGpes ();
688*3446Smrj     if (ACPI_FAILURE (Status))
689*3446Smrj     {
690*3446Smrj         return_ACPI_STATUS (Status);
691*3446Smrj     }
692*3446Smrj 
693*3446Smrj     /* Enable power button */
694*3446Smrj 
695*3446Smrj     (void) AcpiSetRegister(
696*3446Smrj             AcpiGbl_FixedEventInfo[ACPI_EVENT_POWER_BUTTON].EnableRegisterId,
697*3446Smrj             1, ACPI_MTX_DO_NOT_LOCK);
698*3446Smrj 
699*3446Smrj     (void) AcpiSetRegister(
700*3446Smrj             AcpiGbl_FixedEventInfo[ACPI_EVENT_POWER_BUTTON].StatusRegisterId,
701*3446Smrj             1, ACPI_MTX_DO_NOT_LOCK);
702*3446Smrj 
703*3446Smrj     /* Enable BM arbitration */
704*3446Smrj 
705*3446Smrj     Status = AcpiSetRegister (ACPI_BITREG_ARB_DISABLE, 0, ACPI_MTX_LOCK);
706*3446Smrj     if (ACPI_FAILURE (Status))
707*3446Smrj     {
708*3446Smrj         return_ACPI_STATUS (Status);
709*3446Smrj     }
710*3446Smrj 
711*3446Smrj     Arg.Integer.Value = ACPI_SST_WORKING;
712*3446Smrj     Status = AcpiEvaluateObject (NULL, METHOD_NAME__SST, &ArgList, NULL);
713*3446Smrj     if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND)
714*3446Smrj     {
715*3446Smrj         ACPI_EXCEPTION ((AE_INFO, Status, "During Method _SST"));
716*3446Smrj     }
717*3446Smrj 
718*3446Smrj     return_ACPI_STATUS (Status);
719*3446Smrj }
720*3446Smrj 
721*3446Smrj ACPI_EXPORT_SYMBOL (AcpiLeaveSleepState)
722*3446Smrj 
723