Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Name: hwesleep.c - ACPI Hardware Sleep/Wake Support functions for the |
| 4 | * extended FADT-V5 sleep registers. |
| 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
Bob Moore | 25f044e | 2013-01-25 05:38:56 +0000 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2013, Intel Corp. |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions, and the following disclaimer, |
| 17 | * without modification. |
| 18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 19 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 20 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 21 | * including a substantially similar Disclaimer requirement for further |
| 22 | * binary redistribution. |
| 23 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 24 | * of any contributors may be used to endorse or promote products derived |
| 25 | * from this software without specific prior written permission. |
| 26 | * |
| 27 | * Alternatively, this software may be distributed under the terms of the |
| 28 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 29 | * Software Foundation. |
| 30 | * |
| 31 | * NO WARRANTY |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 42 | * POSSIBILITY OF SUCH DAMAGES. |
| 43 | */ |
| 44 | |
| 45 | #include <acpi/acpi.h> |
| 46 | #include "accommon.h" |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 47 | |
| 48 | #define _COMPONENT ACPI_HARDWARE |
| 49 | ACPI_MODULE_NAME("hwesleep") |
| 50 | |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 51 | /******************************************************************************* |
| 52 | * |
| 53 | * FUNCTION: acpi_hw_execute_sleep_method |
| 54 | * |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 55 | * PARAMETERS: method_pathname - Pathname of method to execute |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 56 | * integer_argument - Argument to pass to the method |
| 57 | * |
| 58 | * RETURN: None |
| 59 | * |
| 60 | * DESCRIPTION: Execute a sleep/wake related method with one integer argument |
| 61 | * and no return value. |
| 62 | * |
| 63 | ******************************************************************************/ |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 64 | void acpi_hw_execute_sleep_method(char *method_pathname, u32 integer_argument) |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 65 | { |
| 66 | struct acpi_object_list arg_list; |
| 67 | union acpi_object arg; |
| 68 | acpi_status status; |
| 69 | |
| 70 | ACPI_FUNCTION_TRACE(hw_execute_sleep_method); |
| 71 | |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 72 | /* One argument, integer_argument; No return value expected */ |
| 73 | |
| 74 | arg_list.count = 1; |
| 75 | arg_list.pointer = &arg; |
| 76 | arg.type = ACPI_TYPE_INTEGER; |
| 77 | arg.integer.value = (u64)integer_argument; |
| 78 | |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 79 | status = acpi_evaluate_object(NULL, method_pathname, &arg_list, NULL); |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 80 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 81 | ACPI_EXCEPTION((AE_INFO, status, "While executing method %s", |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 82 | method_pathname)); |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | return_VOID; |
| 86 | } |
| 87 | |
| 88 | /******************************************************************************* |
| 89 | * |
| 90 | * FUNCTION: acpi_hw_extended_sleep |
| 91 | * |
| 92 | * PARAMETERS: sleep_state - Which sleep state to enter |
| 93 | * |
| 94 | * RETURN: Status |
| 95 | * |
| 96 | * DESCRIPTION: Enter a system sleep state via the extended FADT sleep |
| 97 | * registers (V5 FADT). |
| 98 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED |
| 99 | * |
| 100 | ******************************************************************************/ |
| 101 | |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 102 | acpi_status acpi_hw_extended_sleep(u8 sleep_state) |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 103 | { |
| 104 | acpi_status status; |
| 105 | u8 sleep_type_value; |
| 106 | u64 sleep_status; |
| 107 | |
| 108 | ACPI_FUNCTION_TRACE(hw_extended_sleep); |
| 109 | |
| 110 | /* Extended sleep registers must be valid */ |
| 111 | |
| 112 | if (!acpi_gbl_FADT.sleep_control.address || |
| 113 | !acpi_gbl_FADT.sleep_status.address) { |
| 114 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 115 | } |
| 116 | |
| 117 | /* Clear wake status (WAK_STS) */ |
| 118 | |
Bob Moore | 5134abf | 2012-05-03 09:43:21 +0800 | [diff] [blame] | 119 | status = |
| 120 | acpi_write((u64)ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status); |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 121 | if (ACPI_FAILURE(status)) { |
| 122 | return_ACPI_STATUS(status); |
| 123 | } |
| 124 | |
| 125 | acpi_gbl_system_awake_and_running = FALSE; |
| 126 | |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 127 | /* Flush caches, as per ACPI specification */ |
| 128 | |
| 129 | ACPI_FLUSH_CPU_CACHE(); |
| 130 | |
| 131 | /* |
| 132 | * Set the SLP_TYP and SLP_EN bits. |
| 133 | * |
| 134 | * Note: We only use the first value returned by the \_Sx method |
| 135 | * (acpi_gbl_sleep_type_a) - As per ACPI specification. |
| 136 | */ |
| 137 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
| 138 | "Entering sleep state [S%u]\n", sleep_state)); |
| 139 | |
| 140 | sleep_type_value = |
| 141 | ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) & |
| 142 | ACPI_X_SLEEP_TYPE_MASK); |
| 143 | |
Bob Moore | 5134abf | 2012-05-03 09:43:21 +0800 | [diff] [blame] | 144 | status = acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE), |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 145 | &acpi_gbl_FADT.sleep_control); |
| 146 | if (ACPI_FAILURE(status)) { |
| 147 | return_ACPI_STATUS(status); |
| 148 | } |
| 149 | |
| 150 | /* Wait for transition back to Working State */ |
| 151 | |
| 152 | do { |
| 153 | status = acpi_read(&sleep_status, &acpi_gbl_FADT.sleep_status); |
| 154 | if (ACPI_FAILURE(status)) { |
| 155 | return_ACPI_STATUS(status); |
| 156 | } |
| 157 | |
| 158 | } while (!(((u8)sleep_status) & ACPI_X_WAKE_STATUS)); |
| 159 | |
| 160 | return_ACPI_STATUS(AE_OK); |
| 161 | } |
| 162 | |
| 163 | /******************************************************************************* |
| 164 | * |
| 165 | * FUNCTION: acpi_hw_extended_wake_prep |
| 166 | * |
| 167 | * PARAMETERS: sleep_state - Which sleep state we just exited |
| 168 | * |
| 169 | * RETURN: Status |
| 170 | * |
| 171 | * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after |
| 172 | * a sleep. Called with interrupts ENABLED. |
| 173 | * |
| 174 | ******************************************************************************/ |
| 175 | |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 176 | acpi_status acpi_hw_extended_wake_prep(u8 sleep_state) |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 177 | { |
| 178 | acpi_status status; |
| 179 | u8 sleep_type_value; |
| 180 | |
| 181 | ACPI_FUNCTION_TRACE(hw_extended_wake_prep); |
| 182 | |
| 183 | status = acpi_get_sleep_type_data(ACPI_STATE_S0, |
| 184 | &acpi_gbl_sleep_type_a, |
| 185 | &acpi_gbl_sleep_type_b); |
| 186 | if (ACPI_SUCCESS(status)) { |
| 187 | sleep_type_value = |
| 188 | ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) & |
| 189 | ACPI_X_SLEEP_TYPE_MASK); |
| 190 | |
Bob Moore | 5134abf | 2012-05-03 09:43:21 +0800 | [diff] [blame] | 191 | (void)acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE), |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 192 | &acpi_gbl_FADT.sleep_control); |
| 193 | } |
| 194 | |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 195 | return_ACPI_STATUS(AE_OK); |
| 196 | } |
| 197 | |
| 198 | /******************************************************************************* |
| 199 | * |
| 200 | * FUNCTION: acpi_hw_extended_wake |
| 201 | * |
| 202 | * PARAMETERS: sleep_state - Which sleep state we just exited |
| 203 | * |
| 204 | * RETURN: Status |
| 205 | * |
| 206 | * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep |
| 207 | * Called with interrupts ENABLED. |
| 208 | * |
| 209 | ******************************************************************************/ |
| 210 | |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 211 | acpi_status acpi_hw_extended_wake(u8 sleep_state) |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 212 | { |
| 213 | ACPI_FUNCTION_TRACE(hw_extended_wake); |
| 214 | |
| 215 | /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */ |
| 216 | |
| 217 | acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID; |
| 218 | |
| 219 | /* Execute the wake methods */ |
| 220 | |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 221 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WAKING); |
| 222 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK, sleep_state); |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 223 | |
| 224 | /* |
| 225 | * Some BIOS code assumes that WAK_STS will be cleared on resume |
| 226 | * and use it to determine whether the system is rebooting or |
| 227 | * resuming. Clear WAK_STS for compatibility. |
| 228 | */ |
Bob Moore | 5134abf | 2012-05-03 09:43:21 +0800 | [diff] [blame] | 229 | (void)acpi_write((u64)ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status); |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 230 | acpi_gbl_system_awake_and_running = TRUE; |
| 231 | |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 232 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING); |
Bob Moore | 70958576 | 2012-02-14 18:47:42 +0800 | [diff] [blame] | 233 | return_ACPI_STATUS(AE_OK); |
| 234 | } |