hwsleep.c revision 193251
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 "acpi.h" 119#include "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 138ACPI_STATUS 139AcpiSetFirmwareWakingVector ( 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 178ACPI_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 195ACPI_STATUS 196AcpiGetFirmwareWakingVector ( 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 242ACPI_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 260ACPI_STATUS 261AcpiEnterSleepStatePrep ( 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 338ACPI_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 354ACPI_STATUS 355AcpiEnterSleepState ( 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 ACPI_STATUS Status; 364 365 366 ACPI_FUNCTION_TRACE (AcpiEnterSleepState); 367 368 369 if ((AcpiGbl_SleepTypeA > ACPI_SLEEP_TYPE_MAX) || 370 (AcpiGbl_SleepTypeB > ACPI_SLEEP_TYPE_MAX)) 371 { 372 ACPI_ERROR ((AE_INFO, "Sleep values out of range: A=%X B=%X", 373 AcpiGbl_SleepTypeA, AcpiGbl_SleepTypeB)); 374 return_ACPI_STATUS (AE_AML_OPERAND_VALUE); 375 } 376 377 SleepTypeRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_TYPE_A); 378 SleepEnableRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_ENABLE); 379 380 /* Clear wake status */ 381 382 Status = AcpiSetRegister (ACPI_BITREG_WAKE_STATUS, 1); 383 if (ACPI_FAILURE (Status)) 384 { 385 return_ACPI_STATUS (Status); 386 } 387 388 /* Clear all fixed and general purpose status bits */ 389 390 Status = AcpiHwClearAcpiStatus (); 391 if (ACPI_FAILURE (Status)) 392 { 393 return_ACPI_STATUS (Status); 394 } 395 396 if (SleepState != ACPI_STATE_S5) 397 { 398 /* Disable BM arbitration */ 399 400 Status = AcpiSetRegister (ACPI_BITREG_ARB_DISABLE, 1); 401 if (ACPI_FAILURE (Status)) 402 { 403 return_ACPI_STATUS (Status); 404 } 405 } 406 407 /* 408 * 1) Disable/Clear all GPEs 409 * 2) Enable all wakeup GPEs 410 */ 411 Status = AcpiHwDisableAllGpes (); 412 if (ACPI_FAILURE (Status)) 413 { 414 return_ACPI_STATUS (Status); 415 } 416 AcpiGbl_SystemAwakeAndRunning = FALSE; 417 418 Status = AcpiHwEnableAllWakeupGpes (); 419 if (ACPI_FAILURE (Status)) 420 { 421 return_ACPI_STATUS (Status); 422 } 423 424 /* Get current value of PM1A control */ 425 426 Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK, 427 ACPI_REGISTER_PM1_CONTROL, &PM1AControl); 428 if (ACPI_FAILURE (Status)) 429 { 430 return_ACPI_STATUS (Status); 431 } 432 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, 433 "Entering sleep state [S%d]\n", SleepState)); 434 435 /* Clear SLP_EN and SLP_TYP fields */ 436 437 PM1AControl &= ~(SleepTypeRegInfo->AccessBitMask | 438 SleepEnableRegInfo->AccessBitMask); 439 PM1BControl = PM1AControl; 440 441 /* Insert SLP_TYP bits */ 442 443 PM1AControl |= (AcpiGbl_SleepTypeA << SleepTypeRegInfo->BitPosition); 444 PM1BControl |= (AcpiGbl_SleepTypeB << SleepTypeRegInfo->BitPosition); 445 446 /* 447 * We split the writes of SLP_TYP and SLP_EN to workaround 448 * poorly implemented hardware. 449 */ 450 451 /* Write #1: fill in SLP_TYP data */ 452 453 Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 454 ACPI_REGISTER_PM1A_CONTROL, PM1AControl); 455 if (ACPI_FAILURE (Status)) 456 { 457 return_ACPI_STATUS (Status); 458 } 459 460 Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 461 ACPI_REGISTER_PM1B_CONTROL, PM1BControl); 462 if (ACPI_FAILURE (Status)) 463 { 464 return_ACPI_STATUS (Status); 465 } 466 467 /* Insert SLP_ENABLE bit */ 468 469 PM1AControl |= SleepEnableRegInfo->AccessBitMask; 470 PM1BControl |= SleepEnableRegInfo->AccessBitMask; 471 472 /* Write #2: SLP_TYP + SLP_EN */ 473 474 ACPI_FLUSH_CPU_CACHE (); 475 476 Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 477 ACPI_REGISTER_PM1A_CONTROL, PM1AControl); 478 if (ACPI_FAILURE (Status)) 479 { 480 return_ACPI_STATUS (Status); 481 } 482 483 Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 484 ACPI_REGISTER_PM1B_CONTROL, PM1BControl); 485 if (ACPI_FAILURE (Status)) 486 { 487 return_ACPI_STATUS (Status); 488 } 489 490 if (SleepState > ACPI_STATE_S3) 491 { 492 /* 493 * We wanted to sleep > S3, but it didn't happen (by virtue of the 494 * fact that we are still executing!) 495 * 496 * Wait ten seconds, then try again. This is to get S4/S5 to work on 497 * all machines. 498 * 499 * We wait so long to allow chipsets that poll this reg very slowly to 500 * still read the right value. Ideally, this block would go 501 * away entirely. 502 */ 503 AcpiOsStall (10000000); 504 505 Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 506 ACPI_REGISTER_PM1_CONTROL, 507 SleepEnableRegInfo->AccessBitMask); 508 if (ACPI_FAILURE (Status)) 509 { 510 return_ACPI_STATUS (Status); 511 } 512 } 513 514 /* Wait until we enter sleep state */ 515 516 do 517 { 518 Status = AcpiGetRegister (ACPI_BITREG_WAKE_STATUS, &InValue); 519 if (ACPI_FAILURE (Status)) 520 { 521 return_ACPI_STATUS (Status); 522 } 523 524 /* Spin until we wake */ 525 526 } while (!InValue); 527 528 return_ACPI_STATUS (AE_OK); 529} 530 531ACPI_EXPORT_SYMBOL (AcpiEnterSleepState) 532 533 534/******************************************************************************* 535 * 536 * FUNCTION: AcpiEnterSleepStateS4bios 537 * 538 * PARAMETERS: None 539 * 540 * RETURN: Status 541 * 542 * DESCRIPTION: Perform a S4 bios request. 543 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED 544 * 545 ******************************************************************************/ 546 547ACPI_STATUS 548AcpiEnterSleepStateS4bios ( 549 void) 550{ 551 UINT32 InValue; 552 ACPI_STATUS Status; 553 554 555 ACPI_FUNCTION_TRACE (AcpiEnterSleepStateS4bios); 556 557 558 Status = AcpiSetRegister (ACPI_BITREG_WAKE_STATUS, 1); 559 if (ACPI_FAILURE (Status)) 560 { 561 return_ACPI_STATUS (Status); 562 } 563 564 Status = AcpiHwClearAcpiStatus (); 565 if (ACPI_FAILURE (Status)) 566 { 567 return_ACPI_STATUS (Status); 568 } 569 570 /* 571 * 1) Disable/Clear all GPEs 572 * 2) Enable all wakeup GPEs 573 */ 574 Status = AcpiHwDisableAllGpes (); 575 if (ACPI_FAILURE (Status)) 576 { 577 return_ACPI_STATUS (Status); 578 } 579 AcpiGbl_SystemAwakeAndRunning = FALSE; 580 581 Status = AcpiHwEnableAllWakeupGpes (); 582 if (ACPI_FAILURE (Status)) 583 { 584 return_ACPI_STATUS (Status); 585 } 586 587 ACPI_FLUSH_CPU_CACHE (); 588 589 Status = AcpiOsWritePort (AcpiGbl_FADT.SmiCommand, 590 (UINT32) AcpiGbl_FADT.S4BiosRequest, 8); 591 592 do { 593 AcpiOsStall(1000); 594 Status = AcpiGetRegister (ACPI_BITREG_WAKE_STATUS, &InValue); 595 if (ACPI_FAILURE (Status)) 596 { 597 return_ACPI_STATUS (Status); 598 } 599 } while (!InValue); 600 601 return_ACPI_STATUS (AE_OK); 602} 603 604ACPI_EXPORT_SYMBOL (AcpiEnterSleepStateS4bios) 605 606 607/******************************************************************************* 608 * 609 * FUNCTION: AcpiLeaveSleepState 610 * 611 * PARAMETERS: SleepState - Which sleep state we just exited 612 * 613 * RETURN: Status 614 * 615 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep 616 * Called with interrupts ENABLED. 617 * 618 ******************************************************************************/ 619 620ACPI_STATUS 621AcpiLeaveSleepState ( 622 UINT8 SleepState) 623{ 624 ACPI_OBJECT_LIST ArgList; 625 ACPI_OBJECT Arg; 626 ACPI_STATUS Status; 627 ACPI_BIT_REGISTER_INFO *SleepTypeRegInfo; 628 ACPI_BIT_REGISTER_INFO *SleepEnableRegInfo; 629 UINT32 PM1AControl; 630 UINT32 PM1BControl; 631 632 633 ACPI_FUNCTION_TRACE (AcpiLeaveSleepState); 634 635 636 /* 637 * Set SLP_TYPE and SLP_EN to state S0. 638 * This is unclear from the ACPI Spec, but it is required 639 * by some machines. 640 */ 641 Status = AcpiGetSleepTypeData (ACPI_STATE_S0, 642 &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB); 643 if (ACPI_SUCCESS (Status)) 644 { 645 SleepTypeRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_TYPE_A); 646 SleepEnableRegInfo = AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_ENABLE); 647 648 /* Get current value of PM1A control */ 649 650 Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK, 651 ACPI_REGISTER_PM1_CONTROL, &PM1AControl); 652 if (ACPI_SUCCESS (Status)) 653 { 654 /* Clear SLP_EN and SLP_TYP fields */ 655 656 PM1AControl &= ~(SleepTypeRegInfo->AccessBitMask | 657 SleepEnableRegInfo->AccessBitMask); 658 PM1BControl = PM1AControl; 659 660 /* Insert SLP_TYP bits */ 661 662 PM1AControl |= (AcpiGbl_SleepTypeA << SleepTypeRegInfo->BitPosition); 663 PM1BControl |= (AcpiGbl_SleepTypeB << SleepTypeRegInfo->BitPosition); 664 665 /* Just ignore any errors */ 666 667 (void) AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 668 ACPI_REGISTER_PM1A_CONTROL, PM1AControl); 669 (void) AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 670 ACPI_REGISTER_PM1B_CONTROL, PM1BControl); 671 } 672 } 673 674 /* Ensure EnterSleepStatePrep -> EnterSleepState ordering */ 675 676 AcpiGbl_SleepTypeA = ACPI_SLEEP_TYPE_INVALID; 677 678 /* Setup parameter object */ 679 680 ArgList.Count = 1; 681 ArgList.Pointer = &Arg; 682 Arg.Type = ACPI_TYPE_INTEGER; 683 684 /* Ignore any errors from these methods */ 685 686 Arg.Integer.Value = ACPI_SST_WAKING; 687 Status = AcpiEvaluateObject (NULL, METHOD_NAME__SST, &ArgList, NULL); 688 if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 689 { 690 ACPI_EXCEPTION ((AE_INFO, Status, "During Method _SST")); 691 } 692 693 Arg.Integer.Value = SleepState; 694 Status = AcpiEvaluateObject (NULL, METHOD_NAME__BFS, &ArgList, NULL); 695 if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 696 { 697 ACPI_EXCEPTION ((AE_INFO, Status, "During Method _BFS")); 698 } 699 700 Status = AcpiEvaluateObject (NULL, METHOD_NAME__WAK, &ArgList, NULL); 701 if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 702 { 703 ACPI_EXCEPTION ((AE_INFO, Status, "During Method _WAK")); 704 } 705 /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */ 706 707 /* 708 * Restore the GPEs: 709 * 1) Disable/Clear all GPEs 710 * 2) Enable all runtime GPEs 711 */ 712 Status = AcpiHwDisableAllGpes (); 713 if (ACPI_FAILURE (Status)) 714 { 715 return_ACPI_STATUS (Status); 716 } 717 AcpiGbl_SystemAwakeAndRunning = TRUE; 718 719 Status = AcpiHwEnableAllRuntimeGpes (); 720 if (ACPI_FAILURE (Status)) 721 { 722 return_ACPI_STATUS (Status); 723 } 724 725 /* Enable power button */ 726 727 (void) AcpiSetRegister( 728 AcpiGbl_FixedEventInfo[ACPI_EVENT_POWER_BUTTON].EnableRegisterId, 1); 729 730 (void) AcpiSetRegister( 731 AcpiGbl_FixedEventInfo[ACPI_EVENT_POWER_BUTTON].StatusRegisterId, 1); 732 733 /* Enable BM arbitration */ 734 735 Status = AcpiSetRegister (ACPI_BITREG_ARB_DISABLE, 0); 736 if (ACPI_FAILURE (Status)) 737 { 738 return_ACPI_STATUS (Status); 739 } 740 741 Arg.Integer.Value = ACPI_SST_WORKING; 742 Status = AcpiEvaluateObject (NULL, METHOD_NAME__SST, &ArgList, NULL); 743 if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 744 { 745 ACPI_EXCEPTION ((AE_INFO, Status, "During Method _SST")); 746 } 747 748 return_ACPI_STATUS (Status); 749} 750 751ACPI_EXPORT_SYMBOL (AcpiLeaveSleepState) 752 753