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