1a159c266SJung-uk Kim /****************************************************************************** 2a159c266SJung-uk Kim * 3a159c266SJung-uk Kim * Name: hwxfsleep.c - ACPI Hardware Sleep/Wake External Interfaces 4a159c266SJung-uk Kim * 5a159c266SJung-uk Kim *****************************************************************************/ 6a159c266SJung-uk Kim 7*0d84335fSJung-uk Kim /****************************************************************************** 8*0d84335fSJung-uk Kim * 9*0d84335fSJung-uk Kim * 1. Copyright Notice 10*0d84335fSJung-uk Kim * 11*0d84335fSJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12a159c266SJung-uk Kim * All rights reserved. 13a159c266SJung-uk Kim * 14*0d84335fSJung-uk Kim * 2. License 15*0d84335fSJung-uk Kim * 16*0d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property 17*0d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided 18*0d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual 19*0d84335fSJung-uk Kim * property rights. 20*0d84335fSJung-uk Kim * 21*0d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22*0d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an 23*0d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24*0d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy, 25*0d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered 26*0d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and 27*0d84335fSJung-uk Kim * 28*0d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29*0d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel 30*0d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell, 31*0d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof 32*0d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright 33*0d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions 34*0d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right 35*0d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise; 36*0d84335fSJung-uk Kim * 37*0d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following 38*0d84335fSJung-uk Kim * conditions are met: 39*0d84335fSJung-uk Kim * 40*0d84335fSJung-uk Kim * 3. Conditions 41*0d84335fSJung-uk Kim * 42*0d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43*0d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 44*0d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include 45*0d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions, 46*0d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition, 47*0d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to 48*0d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered 49*0d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the 50*0d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee 51*0d84335fSJung-uk Kim * must include a prominent statement that the modification is derived, 52*0d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code. 53*0d84335fSJung-uk Kim * 54*0d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55*0d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 56*0d84335fSJung-uk Kim * Code or modification without rights to further distribute source must 57*0d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the 58*0d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In 59*0d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any 60*0d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the 61*0d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual 62*0d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and 63*0d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may 64*0d84335fSJung-uk Kim * make. 65*0d84335fSJung-uk Kim * 66*0d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67*0d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the 68*0d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance 69*0d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the 70*0d84335fSJung-uk Kim * distribution. 71*0d84335fSJung-uk Kim * 72*0d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original 73*0d84335fSJung-uk Kim * Intel Code. 74*0d84335fSJung-uk Kim * 75*0d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76*0d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or 77*0d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code 78*0d84335fSJung-uk Kim * without prior written authorization from Intel. 79*0d84335fSJung-uk Kim * 80*0d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance 81*0d84335fSJung-uk Kim * 82*0d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83*0d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84*0d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85*0d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86*0d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87*0d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88*0d84335fSJung-uk Kim * PARTICULAR PURPOSE. 89*0d84335fSJung-uk Kim * 90*0d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91*0d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92*0d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93*0d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94*0d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95*0d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96*0d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97*0d84335fSJung-uk Kim * LIMITED REMEDY. 98*0d84335fSJung-uk Kim * 99*0d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100*0d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any 101*0d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or 102*0d84335fSJung-uk Kim * any other agency or department of the United States Government. In the 103*0d84335fSJung-uk Kim * event Licensee exports any such software from the United States or 104*0d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall 105*0d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in 106*0d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the 107*0d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108*0d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process, 109*0d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the 110*0d84335fSJung-uk Kim * United States government or any agency thereof requires an export license, 111*0d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining 112*0d84335fSJung-uk Kim * such license, approval or letter. 113*0d84335fSJung-uk Kim * 114*0d84335fSJung-uk Kim ***************************************************************************** 115*0d84335fSJung-uk Kim * 116*0d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 117*0d84335fSJung-uk Kim * following license: 118*0d84335fSJung-uk Kim * 119a159c266SJung-uk Kim * Redistribution and use in source and binary forms, with or without 120a159c266SJung-uk Kim * modification, are permitted provided that the following conditions 121a159c266SJung-uk Kim * are met: 122a159c266SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 123a159c266SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 124a159c266SJung-uk Kim * without modification. 125a159c266SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126a159c266SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 127a159c266SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 128a159c266SJung-uk Kim * including a substantially similar Disclaimer requirement for further 129a159c266SJung-uk Kim * binary redistribution. 130a159c266SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 131a159c266SJung-uk Kim * of any contributors may be used to endorse or promote products derived 132a159c266SJung-uk Kim * from this software without specific prior written permission. 133a159c266SJung-uk Kim * 134*0d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135*0d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136*0d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137*0d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138*0d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139*0d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140*0d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141*0d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142*0d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143*0d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144*0d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145*0d84335fSJung-uk Kim * 146*0d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 147a159c266SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 148a159c266SJung-uk Kim * Software Foundation. 149a159c266SJung-uk Kim * 150*0d84335fSJung-uk Kim *****************************************************************************/ 151a159c266SJung-uk Kim 152313a0c13SJung-uk Kim #define EXPORT_ACPI_INTERFACES 153313a0c13SJung-uk Kim 154a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h> 155a159c266SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h> 156a159c266SJung-uk Kim 157a159c266SJung-uk Kim #define _COMPONENT ACPI_HARDWARE 158a159c266SJung-uk Kim ACPI_MODULE_NAME ("hwxfsleep") 159a159c266SJung-uk Kim 160a159c266SJung-uk Kim /* Local prototypes */ 161a159c266SJung-uk Kim 1625ef50723SJung-uk Kim #if (!ACPI_REDUCED_HARDWARE) 1635ef50723SJung-uk Kim static ACPI_STATUS 1645ef50723SJung-uk Kim AcpiHwSetFirmwareWakingVector ( 1655ef50723SJung-uk Kim ACPI_TABLE_FACS *Facs, 1665ef50723SJung-uk Kim ACPI_PHYSICAL_ADDRESS PhysicalAddress, 1675ef50723SJung-uk Kim ACPI_PHYSICAL_ADDRESS PhysicalAddress64); 1685ef50723SJung-uk Kim #endif 1695ef50723SJung-uk Kim 170a159c266SJung-uk Kim static ACPI_STATUS 171a159c266SJung-uk Kim AcpiHwSleepDispatch ( 172a159c266SJung-uk Kim UINT8 SleepState, 173a159c266SJung-uk Kim UINT32 FunctionId); 174a159c266SJung-uk Kim 175a159c266SJung-uk Kim /* 176a159c266SJung-uk Kim * Dispatch table used to efficiently branch to the various sleep 177a159c266SJung-uk Kim * functions. 178a159c266SJung-uk Kim */ 179a159c266SJung-uk Kim #define ACPI_SLEEP_FUNCTION_ID 0 180a159c266SJung-uk Kim #define ACPI_WAKE_PREP_FUNCTION_ID 1 181a159c266SJung-uk Kim #define ACPI_WAKE_FUNCTION_ID 2 182a159c266SJung-uk Kim 183a159c266SJung-uk Kim /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */ 184a159c266SJung-uk Kim 185a159c266SJung-uk Kim static ACPI_SLEEP_FUNCTIONS AcpiSleepDispatch[] = 186a159c266SJung-uk Kim { 187a159c266SJung-uk Kim {ACPI_HW_OPTIONAL_FUNCTION (AcpiHwLegacySleep), AcpiHwExtendedSleep}, 188a159c266SJung-uk Kim {ACPI_HW_OPTIONAL_FUNCTION (AcpiHwLegacyWakePrep), AcpiHwExtendedWakePrep}, 189a159c266SJung-uk Kim {ACPI_HW_OPTIONAL_FUNCTION (AcpiHwLegacyWake), AcpiHwExtendedWake} 190a159c266SJung-uk Kim }; 191a159c266SJung-uk Kim 192a159c266SJung-uk Kim 193a159c266SJung-uk Kim /* 194a159c266SJung-uk Kim * These functions are removed for the ACPI_REDUCED_HARDWARE case: 195a159c266SJung-uk Kim * AcpiSetFirmwareWakingVector 196a159c266SJung-uk Kim * AcpiEnterSleepStateS4bios 197a159c266SJung-uk Kim */ 198a159c266SJung-uk Kim 199a159c266SJung-uk Kim #if (!ACPI_REDUCED_HARDWARE) 200a159c266SJung-uk Kim /******************************************************************************* 201a159c266SJung-uk Kim * 2025ef50723SJung-uk Kim * FUNCTION: AcpiHwSetFirmwareWakingVector 203a159c266SJung-uk Kim * 2045ef50723SJung-uk Kim * PARAMETERS: Facs - Pointer to FACS table 2055ef50723SJung-uk Kim * PhysicalAddress - 32-bit physical address of ACPI real mode 2065ef50723SJung-uk Kim * entry point 2075ef50723SJung-uk Kim * PhysicalAddress64 - 64-bit physical address of ACPI protected 208f8146b88SJung-uk Kim * mode entry point 209a159c266SJung-uk Kim * 210a159c266SJung-uk Kim * RETURN: Status 211a159c266SJung-uk Kim * 2125ef50723SJung-uk Kim * DESCRIPTION: Sets the FirmwareWakingVector fields of the FACS 213a159c266SJung-uk Kim * 214a159c266SJung-uk Kim ******************************************************************************/ 215a159c266SJung-uk Kim 2165ef50723SJung-uk Kim static ACPI_STATUS 2175ef50723SJung-uk Kim AcpiHwSetFirmwareWakingVector ( 2185ef50723SJung-uk Kim ACPI_TABLE_FACS *Facs, 2195ef50723SJung-uk Kim ACPI_PHYSICAL_ADDRESS PhysicalAddress, 2205ef50723SJung-uk Kim ACPI_PHYSICAL_ADDRESS PhysicalAddress64) 221a159c266SJung-uk Kim { 2225ef50723SJung-uk Kim ACPI_FUNCTION_TRACE (AcpiHwSetFirmwareWakingVector); 223a159c266SJung-uk Kim 224a159c266SJung-uk Kim 225e8241eabSJung-uk Kim /* 226e8241eabSJung-uk Kim * According to the ACPI specification 2.0c and later, the 64-bit 227e8241eabSJung-uk Kim * waking vector should be cleared and the 32-bit waking vector should 228e8241eabSJung-uk Kim * be used, unless we want the wake-up code to be called by the BIOS in 229e8241eabSJung-uk Kim * Protected Mode. Some systems (for example HP dv5-1004nr) are known 230e8241eabSJung-uk Kim * to fail to resume if the 64-bit vector is used. 231e8241eabSJung-uk Kim */ 232e8241eabSJung-uk Kim 233a159c266SJung-uk Kim /* Set the 32-bit vector */ 234a159c266SJung-uk Kim 2355ef50723SJung-uk Kim Facs->FirmwareWakingVector = (UINT32) PhysicalAddress; 236a159c266SJung-uk Kim 2375ef50723SJung-uk Kim if (Facs->Length > 32) 2385ef50723SJung-uk Kim { 2395ef50723SJung-uk Kim if (Facs->Version >= 1) 2405ef50723SJung-uk Kim { 2415ef50723SJung-uk Kim /* Set the 64-bit vector */ 2425ef50723SJung-uk Kim 2435ef50723SJung-uk Kim Facs->XFirmwareWakingVector = PhysicalAddress64; 2445ef50723SJung-uk Kim } 2455ef50723SJung-uk Kim else 2465ef50723SJung-uk Kim { 247a159c266SJung-uk Kim /* Clear the 64-bit vector if it exists */ 248a159c266SJung-uk Kim 2495ef50723SJung-uk Kim Facs->XFirmwareWakingVector = 0; 2505ef50723SJung-uk Kim } 2515ef50723SJung-uk Kim } 2525ef50723SJung-uk Kim 2535ef50723SJung-uk Kim return_ACPI_STATUS (AE_OK); 2545ef50723SJung-uk Kim } 2555ef50723SJung-uk Kim 2565ef50723SJung-uk Kim 2575ef50723SJung-uk Kim /******************************************************************************* 2585ef50723SJung-uk Kim * 2595ef50723SJung-uk Kim * FUNCTION: AcpiSetFirmwareWakingVector 2605ef50723SJung-uk Kim * 2615ef50723SJung-uk Kim * PARAMETERS: PhysicalAddress - 32-bit physical address of ACPI real mode 2625ef50723SJung-uk Kim * entry point 2635ef50723SJung-uk Kim * PhysicalAddress64 - 64-bit physical address of ACPI protected 264f8146b88SJung-uk Kim * mode entry point 2655ef50723SJung-uk Kim * 2665ef50723SJung-uk Kim * RETURN: Status 2675ef50723SJung-uk Kim * 2685ef50723SJung-uk Kim * DESCRIPTION: Sets the FirmwareWakingVector fields of the FACS 2695ef50723SJung-uk Kim * 2705ef50723SJung-uk Kim ******************************************************************************/ 2715ef50723SJung-uk Kim 2725ef50723SJung-uk Kim ACPI_STATUS 2735ef50723SJung-uk Kim AcpiSetFirmwareWakingVector ( 2745ef50723SJung-uk Kim ACPI_PHYSICAL_ADDRESS PhysicalAddress, 2755ef50723SJung-uk Kim ACPI_PHYSICAL_ADDRESS PhysicalAddress64) 276a159c266SJung-uk Kim { 2775ef50723SJung-uk Kim 2785ef50723SJung-uk Kim ACPI_FUNCTION_TRACE (AcpiSetFirmwareWakingVector); 2795ef50723SJung-uk Kim 28070e6ab8fSJung-uk Kim if (AcpiGbl_FACS) 2815ef50723SJung-uk Kim { 28270e6ab8fSJung-uk Kim (void) AcpiHwSetFirmwareWakingVector (AcpiGbl_FACS, 2835ef50723SJung-uk Kim PhysicalAddress, PhysicalAddress64); 284a159c266SJung-uk Kim } 285a159c266SJung-uk Kim 286a159c266SJung-uk Kim return_ACPI_STATUS (AE_OK); 287a159c266SJung-uk Kim } 288a159c266SJung-uk Kim 289a159c266SJung-uk Kim ACPI_EXPORT_SYMBOL (AcpiSetFirmwareWakingVector) 290a159c266SJung-uk Kim 291a159c266SJung-uk Kim 292a159c266SJung-uk Kim /******************************************************************************* 293a159c266SJung-uk Kim * 294a159c266SJung-uk Kim * FUNCTION: AcpiEnterSleepStateS4bios 295a159c266SJung-uk Kim * 296a159c266SJung-uk Kim * PARAMETERS: None 297a159c266SJung-uk Kim * 298a159c266SJung-uk Kim * RETURN: Status 299a159c266SJung-uk Kim * 300a159c266SJung-uk Kim * DESCRIPTION: Perform a S4 bios request. 301a159c266SJung-uk Kim * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED 302a159c266SJung-uk Kim * 303a159c266SJung-uk Kim ******************************************************************************/ 304a159c266SJung-uk Kim 305a159c266SJung-uk Kim ACPI_STATUS 306a159c266SJung-uk Kim AcpiEnterSleepStateS4bios ( 307a159c266SJung-uk Kim void) 308a159c266SJung-uk Kim { 309a159c266SJung-uk Kim UINT32 InValue; 310a159c266SJung-uk Kim ACPI_STATUS Status; 311a159c266SJung-uk Kim 312a159c266SJung-uk Kim 313a159c266SJung-uk Kim ACPI_FUNCTION_TRACE (AcpiEnterSleepStateS4bios); 314a159c266SJung-uk Kim 315a159c266SJung-uk Kim 316a159c266SJung-uk Kim /* Clear the wake status bit (PM1) */ 317a159c266SJung-uk Kim 318a159c266SJung-uk Kim Status = AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS); 319a159c266SJung-uk Kim if (ACPI_FAILURE (Status)) 320a159c266SJung-uk Kim { 321a159c266SJung-uk Kim return_ACPI_STATUS (Status); 322a159c266SJung-uk Kim } 323a159c266SJung-uk Kim 324a159c266SJung-uk Kim Status = AcpiHwClearAcpiStatus (); 325a159c266SJung-uk Kim if (ACPI_FAILURE (Status)) 326a159c266SJung-uk Kim { 327a159c266SJung-uk Kim return_ACPI_STATUS (Status); 328a159c266SJung-uk Kim } 329a159c266SJung-uk Kim 330a159c266SJung-uk Kim /* 331a159c266SJung-uk Kim * 1) Disable/Clear all GPEs 332a159c266SJung-uk Kim * 2) Enable all wakeup GPEs 333a159c266SJung-uk Kim */ 334a159c266SJung-uk Kim Status = AcpiHwDisableAllGpes (); 335a159c266SJung-uk Kim if (ACPI_FAILURE (Status)) 336a159c266SJung-uk Kim { 337a159c266SJung-uk Kim return_ACPI_STATUS (Status); 338a159c266SJung-uk Kim } 339a159c266SJung-uk Kim AcpiGbl_SystemAwakeAndRunning = FALSE; 340a159c266SJung-uk Kim 341a159c266SJung-uk Kim Status = AcpiHwEnableAllWakeupGpes (); 342a159c266SJung-uk Kim if (ACPI_FAILURE (Status)) 343a159c266SJung-uk Kim { 344a159c266SJung-uk Kim return_ACPI_STATUS (Status); 345a159c266SJung-uk Kim } 346a159c266SJung-uk Kim 347a159c266SJung-uk Kim ACPI_FLUSH_CPU_CACHE (); 348a159c266SJung-uk Kim 349a159c266SJung-uk Kim Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand, 350a159c266SJung-uk Kim (UINT32) AcpiGbl_FADT.S4BiosRequest, 8); 351a159c266SJung-uk Kim 352a159c266SJung-uk Kim do { 353efcc2a30SJung-uk Kim AcpiOsStall (ACPI_USEC_PER_MSEC); 354a159c266SJung-uk Kim Status = AcpiReadBitRegister (ACPI_BITREG_WAKE_STATUS, &InValue); 355a159c266SJung-uk Kim if (ACPI_FAILURE (Status)) 356a159c266SJung-uk Kim { 357a159c266SJung-uk Kim return_ACPI_STATUS (Status); 358a159c266SJung-uk Kim } 359f8146b88SJung-uk Kim 360a159c266SJung-uk Kim } while (!InValue); 361a159c266SJung-uk Kim 362a159c266SJung-uk Kim return_ACPI_STATUS (AE_OK); 363a159c266SJung-uk Kim } 364a159c266SJung-uk Kim 365a159c266SJung-uk Kim ACPI_EXPORT_SYMBOL (AcpiEnterSleepStateS4bios) 366a159c266SJung-uk Kim 367a159c266SJung-uk Kim #endif /* !ACPI_REDUCED_HARDWARE */ 368a159c266SJung-uk Kim 369a159c266SJung-uk Kim 370a159c266SJung-uk Kim /******************************************************************************* 371a159c266SJung-uk Kim * 372a159c266SJung-uk Kim * FUNCTION: AcpiHwSleepDispatch 373a159c266SJung-uk Kim * 374a159c266SJung-uk Kim * PARAMETERS: SleepState - Which sleep state to enter/exit 375a159c266SJung-uk Kim * FunctionId - Sleep, WakePrep, or Wake 376a159c266SJung-uk Kim * 377a159c266SJung-uk Kim * RETURN: Status from the invoked sleep handling function. 378a159c266SJung-uk Kim * 379a159c266SJung-uk Kim * DESCRIPTION: Dispatch a sleep/wake request to the appropriate handling 380a159c266SJung-uk Kim * function. 381a159c266SJung-uk Kim * 382a159c266SJung-uk Kim ******************************************************************************/ 383a159c266SJung-uk Kim 384a159c266SJung-uk Kim static ACPI_STATUS 385a159c266SJung-uk Kim AcpiHwSleepDispatch ( 386a159c266SJung-uk Kim UINT8 SleepState, 387a159c266SJung-uk Kim UINT32 FunctionId) 388a159c266SJung-uk Kim { 389a159c266SJung-uk Kim ACPI_STATUS Status; 390a159c266SJung-uk Kim ACPI_SLEEP_FUNCTIONS *SleepFunctions = &AcpiSleepDispatch[FunctionId]; 391a159c266SJung-uk Kim 392a159c266SJung-uk Kim 393a159c266SJung-uk Kim #if (!ACPI_REDUCED_HARDWARE) 394a159c266SJung-uk Kim /* 395a159c266SJung-uk Kim * If the Hardware Reduced flag is set (from the FADT), we must 396a9d8d09cSJung-uk Kim * use the extended sleep registers (FADT). Note: As per the ACPI 397a9d8d09cSJung-uk Kim * specification, these extended registers are to be used for HW-reduced 398a9d8d09cSJung-uk Kim * platforms only. They are not general-purpose replacements for the 399a9d8d09cSJung-uk Kim * legacy PM register sleep support. 400a159c266SJung-uk Kim */ 401a9d8d09cSJung-uk Kim if (AcpiGbl_ReducedHardware) 402a159c266SJung-uk Kim { 4031df130f1SJung-uk Kim Status = SleepFunctions->ExtendedFunction (SleepState); 404a159c266SJung-uk Kim } 405a159c266SJung-uk Kim else 406a159c266SJung-uk Kim { 407a159c266SJung-uk Kim /* Legacy sleep */ 408a159c266SJung-uk Kim 4091df130f1SJung-uk Kim Status = SleepFunctions->LegacyFunction (SleepState); 410a159c266SJung-uk Kim } 411a159c266SJung-uk Kim 412a159c266SJung-uk Kim return (Status); 413a159c266SJung-uk Kim 414a159c266SJung-uk Kim #else 415a159c266SJung-uk Kim /* 416a159c266SJung-uk Kim * For the case where reduced-hardware-only code is being generated, 417a159c266SJung-uk Kim * we know that only the extended sleep registers are available 418a159c266SJung-uk Kim */ 4191df130f1SJung-uk Kim Status = SleepFunctions->ExtendedFunction (SleepState); 420a159c266SJung-uk Kim return (Status); 421a159c266SJung-uk Kim 422a159c266SJung-uk Kim #endif /* !ACPI_REDUCED_HARDWARE */ 423a159c266SJung-uk Kim } 424a159c266SJung-uk Kim 425a159c266SJung-uk Kim 426a159c266SJung-uk Kim /******************************************************************************* 427a159c266SJung-uk Kim * 428a159c266SJung-uk Kim * FUNCTION: AcpiEnterSleepStatePrep 429a159c266SJung-uk Kim * 430a159c266SJung-uk Kim * PARAMETERS: SleepState - Which sleep state to enter 431a159c266SJung-uk Kim * 432a159c266SJung-uk Kim * RETURN: Status 433a159c266SJung-uk Kim * 434a159c266SJung-uk Kim * DESCRIPTION: Prepare to enter a system sleep state. 435a159c266SJung-uk Kim * This function must execute with interrupts enabled. 436a159c266SJung-uk Kim * We break sleeping into 2 stages so that OSPM can handle 437a159c266SJung-uk Kim * various OS-specific tasks between the two steps. 438a159c266SJung-uk Kim * 439a159c266SJung-uk Kim ******************************************************************************/ 440a159c266SJung-uk Kim 441a159c266SJung-uk Kim ACPI_STATUS 442a159c266SJung-uk Kim AcpiEnterSleepStatePrep ( 443a159c266SJung-uk Kim UINT8 SleepState) 444a159c266SJung-uk Kim { 445a159c266SJung-uk Kim ACPI_STATUS Status; 446a159c266SJung-uk Kim ACPI_OBJECT_LIST ArgList; 447a159c266SJung-uk Kim ACPI_OBJECT Arg; 448a159c266SJung-uk Kim UINT32 SstValue; 449a159c266SJung-uk Kim 450a159c266SJung-uk Kim 451a159c266SJung-uk Kim ACPI_FUNCTION_TRACE (AcpiEnterSleepStatePrep); 452a159c266SJung-uk Kim 453a159c266SJung-uk Kim 454a159c266SJung-uk Kim Status = AcpiGetSleepTypeData (SleepState, 455a159c266SJung-uk Kim &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB); 456a159c266SJung-uk Kim if (ACPI_FAILURE (Status)) 457a159c266SJung-uk Kim { 458a159c266SJung-uk Kim return_ACPI_STATUS (Status); 459a159c266SJung-uk Kim } 460a159c266SJung-uk Kim 461a159c266SJung-uk Kim /* Execute the _PTS method (Prepare To Sleep) */ 462a159c266SJung-uk Kim 463a159c266SJung-uk Kim ArgList.Count = 1; 464a159c266SJung-uk Kim ArgList.Pointer = &Arg; 465a159c266SJung-uk Kim Arg.Type = ACPI_TYPE_INTEGER; 466a159c266SJung-uk Kim Arg.Integer.Value = SleepState; 467a159c266SJung-uk Kim 4684c52cad2SJung-uk Kim Status = AcpiEvaluateObject (NULL, METHOD_PATHNAME__PTS, &ArgList, NULL); 469a159c266SJung-uk Kim if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND) 470a159c266SJung-uk Kim { 471a159c266SJung-uk Kim return_ACPI_STATUS (Status); 472a159c266SJung-uk Kim } 473a159c266SJung-uk Kim 474a159c266SJung-uk Kim /* Setup the argument to the _SST method (System STatus) */ 475a159c266SJung-uk Kim 476a159c266SJung-uk Kim switch (SleepState) 477a159c266SJung-uk Kim { 478a159c266SJung-uk Kim case ACPI_STATE_S0: 479a9d8d09cSJung-uk Kim 480a159c266SJung-uk Kim SstValue = ACPI_SST_WORKING; 481a159c266SJung-uk Kim break; 482a159c266SJung-uk Kim 483a159c266SJung-uk Kim case ACPI_STATE_S1: 484a159c266SJung-uk Kim case ACPI_STATE_S2: 485a159c266SJung-uk Kim case ACPI_STATE_S3: 486a9d8d09cSJung-uk Kim 487a159c266SJung-uk Kim SstValue = ACPI_SST_SLEEPING; 488a159c266SJung-uk Kim break; 489a159c266SJung-uk Kim 490a159c266SJung-uk Kim case ACPI_STATE_S4: 491a9d8d09cSJung-uk Kim 492a159c266SJung-uk Kim SstValue = ACPI_SST_SLEEP_CONTEXT; 493a159c266SJung-uk Kim break; 494a159c266SJung-uk Kim 495a159c266SJung-uk Kim default: 496a9d8d09cSJung-uk Kim 497a159c266SJung-uk Kim SstValue = ACPI_SST_INDICATOR_OFF; /* Default is off */ 498a159c266SJung-uk Kim break; 499a159c266SJung-uk Kim } 500a159c266SJung-uk Kim 501a159c266SJung-uk Kim /* 502a159c266SJung-uk Kim * Set the system indicators to show the desired sleep state. 503a159c266SJung-uk Kim * _SST is an optional method (return no error if not found) 504a159c266SJung-uk Kim */ 5054c52cad2SJung-uk Kim AcpiHwExecuteSleepMethod (METHOD_PATHNAME__SST, SstValue); 506a159c266SJung-uk Kim return_ACPI_STATUS (AE_OK); 507a159c266SJung-uk Kim } 508a159c266SJung-uk Kim 509a159c266SJung-uk Kim ACPI_EXPORT_SYMBOL (AcpiEnterSleepStatePrep) 510a159c266SJung-uk Kim 511a159c266SJung-uk Kim 512a159c266SJung-uk Kim /******************************************************************************* 513a159c266SJung-uk Kim * 514a159c266SJung-uk Kim * FUNCTION: AcpiEnterSleepState 515a159c266SJung-uk Kim * 516a159c266SJung-uk Kim * PARAMETERS: SleepState - Which sleep state to enter 517a159c266SJung-uk Kim * 518a159c266SJung-uk Kim * RETURN: Status 519a159c266SJung-uk Kim * 520a159c266SJung-uk Kim * DESCRIPTION: Enter a system sleep state 521a159c266SJung-uk Kim * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED 522a159c266SJung-uk Kim * 523a159c266SJung-uk Kim ******************************************************************************/ 524a159c266SJung-uk Kim 525a159c266SJung-uk Kim ACPI_STATUS 526a159c266SJung-uk Kim AcpiEnterSleepState ( 5271df130f1SJung-uk Kim UINT8 SleepState) 528a159c266SJung-uk Kim { 529a159c266SJung-uk Kim ACPI_STATUS Status; 530a159c266SJung-uk Kim 531a159c266SJung-uk Kim 532a159c266SJung-uk Kim ACPI_FUNCTION_TRACE (AcpiEnterSleepState); 533a159c266SJung-uk Kim 534a159c266SJung-uk Kim 535a159c266SJung-uk Kim if ((AcpiGbl_SleepTypeA > ACPI_SLEEP_TYPE_MAX) || 536a159c266SJung-uk Kim (AcpiGbl_SleepTypeB > ACPI_SLEEP_TYPE_MAX)) 537a159c266SJung-uk Kim { 538a159c266SJung-uk Kim ACPI_ERROR ((AE_INFO, "Sleep values out of range: A=0x%X B=0x%X", 539a159c266SJung-uk Kim AcpiGbl_SleepTypeA, AcpiGbl_SleepTypeB)); 540a159c266SJung-uk Kim return_ACPI_STATUS (AE_AML_OPERAND_VALUE); 541a159c266SJung-uk Kim } 542a159c266SJung-uk Kim 5431df130f1SJung-uk Kim Status = AcpiHwSleepDispatch (SleepState, ACPI_SLEEP_FUNCTION_ID); 544a159c266SJung-uk Kim return_ACPI_STATUS (Status); 545a159c266SJung-uk Kim } 546a159c266SJung-uk Kim 547a159c266SJung-uk Kim ACPI_EXPORT_SYMBOL (AcpiEnterSleepState) 548a159c266SJung-uk Kim 549a159c266SJung-uk Kim 550a159c266SJung-uk Kim /******************************************************************************* 551a159c266SJung-uk Kim * 552a159c266SJung-uk Kim * FUNCTION: AcpiLeaveSleepStatePrep 553a159c266SJung-uk Kim * 554a159c266SJung-uk Kim * PARAMETERS: SleepState - Which sleep state we are exiting 555a159c266SJung-uk Kim * 556a159c266SJung-uk Kim * RETURN: Status 557a159c266SJung-uk Kim * 558a159c266SJung-uk Kim * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a 559a159c266SJung-uk Kim * sleep. Called with interrupts DISABLED. 560a159c266SJung-uk Kim * We break wake/resume into 2 stages so that OSPM can handle 561a159c266SJung-uk Kim * various OS-specific tasks between the two steps. 562a159c266SJung-uk Kim * 563a159c266SJung-uk Kim ******************************************************************************/ 564a159c266SJung-uk Kim 565a159c266SJung-uk Kim ACPI_STATUS 566a159c266SJung-uk Kim AcpiLeaveSleepStatePrep ( 5671df130f1SJung-uk Kim UINT8 SleepState) 568a159c266SJung-uk Kim { 569a159c266SJung-uk Kim ACPI_STATUS Status; 570a159c266SJung-uk Kim 571a159c266SJung-uk Kim 572a159c266SJung-uk Kim ACPI_FUNCTION_TRACE (AcpiLeaveSleepStatePrep); 573a159c266SJung-uk Kim 574a159c266SJung-uk Kim 5751df130f1SJung-uk Kim Status = AcpiHwSleepDispatch (SleepState, ACPI_WAKE_PREP_FUNCTION_ID); 576a159c266SJung-uk Kim return_ACPI_STATUS (Status); 577a159c266SJung-uk Kim } 578a159c266SJung-uk Kim 579a159c266SJung-uk Kim ACPI_EXPORT_SYMBOL (AcpiLeaveSleepStatePrep) 580a159c266SJung-uk Kim 581a159c266SJung-uk Kim 582a159c266SJung-uk Kim /******************************************************************************* 583a159c266SJung-uk Kim * 584a159c266SJung-uk Kim * FUNCTION: AcpiLeaveSleepState 585a159c266SJung-uk Kim * 586a159c266SJung-uk Kim * PARAMETERS: SleepState - Which sleep state we are exiting 587a159c266SJung-uk Kim * 588a159c266SJung-uk Kim * RETURN: Status 589a159c266SJung-uk Kim * 590a159c266SJung-uk Kim * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep 591a159c266SJung-uk Kim * Called with interrupts ENABLED. 592a159c266SJung-uk Kim * 593a159c266SJung-uk Kim ******************************************************************************/ 594a159c266SJung-uk Kim 595a159c266SJung-uk Kim ACPI_STATUS 596a159c266SJung-uk Kim AcpiLeaveSleepState ( 597a159c266SJung-uk Kim UINT8 SleepState) 598a159c266SJung-uk Kim { 599a159c266SJung-uk Kim ACPI_STATUS Status; 600a159c266SJung-uk Kim 601a159c266SJung-uk Kim 602a159c266SJung-uk Kim ACPI_FUNCTION_TRACE (AcpiLeaveSleepState); 603a159c266SJung-uk Kim 604a159c266SJung-uk Kim 6051df130f1SJung-uk Kim Status = AcpiHwSleepDispatch (SleepState, ACPI_WAKE_FUNCTION_ID); 606a159c266SJung-uk Kim return_ACPI_STATUS (Status); 607a159c266SJung-uk Kim } 608a159c266SJung-uk Kim 609a159c266SJung-uk Kim ACPI_EXPORT_SYMBOL (AcpiLeaveSleepState) 610