Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Name: hwxfsleep.c - ACPI Hardware Sleep/Wake External Interfaces |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
David E. Box | 82a8094 | 2015-02-05 15:20:45 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2015, Intel Corp. |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
Lv Zheng | 839e928 | 2013-10-29 09:29:51 +0800 | [diff] [blame] | 44 | #define EXPORT_ACPI_INTERFACES |
| 45 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 46 | #include <acpi/acpi.h> |
| 47 | #include "accommon.h" |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 48 | |
| 49 | #define _COMPONENT ACPI_HARDWARE |
| 50 | ACPI_MODULE_NAME("hwxfsleep") |
| 51 | |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 52 | /* Local prototypes */ |
Lv Zheng | f06147f | 2015-07-01 14:43:18 +0800 | [diff] [blame] | 53 | #if (!ACPI_REDUCED_HARDWARE) |
| 54 | static acpi_status |
| 55 | acpi_hw_set_firmware_waking_vectors(struct acpi_table_facs *facs, |
| 56 | acpi_physical_address physical_address, |
| 57 | acpi_physical_address physical_address64); |
| 58 | #endif |
| 59 | |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 60 | static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id); |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * Dispatch table used to efficiently branch to the various sleep |
| 64 | * functions. |
| 65 | */ |
Lin Ming | 8a73b17 | 2012-03-21 10:01:49 +0800 | [diff] [blame] | 66 | #define ACPI_SLEEP_FUNCTION_ID 0 |
| 67 | #define ACPI_WAKE_PREP_FUNCTION_ID 1 |
| 68 | #define ACPI_WAKE_FUNCTION_ID 2 |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 69 | |
| 70 | /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */ |
| 71 | |
| 72 | static struct acpi_sleep_functions acpi_sleep_dispatch[] = { |
| 73 | {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep), |
| 74 | acpi_hw_extended_sleep}, |
| 75 | {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep), |
| 76 | acpi_hw_extended_wake_prep}, |
| 77 | {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake} |
| 78 | }; |
| 79 | |
| 80 | /* |
| 81 | * These functions are removed for the ACPI_REDUCED_HARDWARE case: |
Lv Zheng | aca2a5d | 2015-07-01 14:43:04 +0800 | [diff] [blame] | 82 | * acpi_set_firmware_waking_vectors |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 83 | * acpi_set_firmware_waking_vector |
| 84 | * acpi_set_firmware_waking_vector64 |
| 85 | * acpi_enter_sleep_state_s4bios |
| 86 | */ |
| 87 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 88 | #if (!ACPI_REDUCED_HARDWARE) |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 89 | /******************************************************************************* |
| 90 | * |
Lv Zheng | f06147f | 2015-07-01 14:43:18 +0800 | [diff] [blame] | 91 | * FUNCTION: acpi_hw_set_firmware_waking_vectors |
| 92 | * |
| 93 | * PARAMETERS: facs - Pointer to FACS table |
| 94 | * physical_address - 32-bit physical address of ACPI real mode |
| 95 | * entry point. |
| 96 | * physical_address64 - 64-bit physical address of ACPI protected |
| 97 | * mode entry point. |
| 98 | * |
| 99 | * RETURN: Status |
| 100 | * |
| 101 | * DESCRIPTION: Sets the firmware_waking_vector fields of the FACS |
| 102 | * |
| 103 | ******************************************************************************/ |
| 104 | |
| 105 | static acpi_status |
| 106 | acpi_hw_set_firmware_waking_vectors(struct acpi_table_facs *facs, |
| 107 | acpi_physical_address physical_address, |
| 108 | acpi_physical_address physical_address64) |
| 109 | { |
| 110 | ACPI_FUNCTION_TRACE(acpi_hw_set_firmware_waking_vectors); |
| 111 | |
| 112 | |
| 113 | /* |
| 114 | * According to the ACPI specification 2.0c and later, the 64-bit |
| 115 | * waking vector should be cleared and the 32-bit waking vector should |
| 116 | * be used, unless we want the wake-up code to be called by the BIOS in |
| 117 | * Protected Mode. Some systems (for example HP dv5-1004nr) are known |
| 118 | * to fail to resume if the 64-bit vector is used. |
| 119 | */ |
| 120 | |
| 121 | /* Set the 32-bit vector */ |
| 122 | |
| 123 | facs->firmware_waking_vector = (u32)physical_address; |
| 124 | |
| 125 | if (facs->length > 32) { |
| 126 | if (facs->version >= 1) { |
| 127 | |
| 128 | /* Set the 64-bit vector */ |
| 129 | |
| 130 | facs->xfirmware_waking_vector = physical_address64; |
| 131 | } else { |
| 132 | /* Clear the 64-bit vector if it exists */ |
| 133 | |
| 134 | facs->xfirmware_waking_vector = 0; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | return_ACPI_STATUS(AE_OK); |
| 139 | } |
| 140 | |
| 141 | /******************************************************************************* |
| 142 | * |
Lv Zheng | aca2a5d | 2015-07-01 14:43:04 +0800 | [diff] [blame] | 143 | * FUNCTION: acpi_set_firmware_waking_vectors |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 144 | * |
| 145 | * PARAMETERS: physical_address - 32-bit physical address of ACPI real mode |
| 146 | * entry point. |
Lv Zheng | aca2a5d | 2015-07-01 14:43:04 +0800 | [diff] [blame] | 147 | * physical_address64 - 64-bit physical address of ACPI protected |
| 148 | * mode entry point. |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 149 | * |
| 150 | * RETURN: Status |
| 151 | * |
Lv Zheng | aca2a5d | 2015-07-01 14:43:04 +0800 | [diff] [blame] | 152 | * DESCRIPTION: Sets the firmware_waking_vector fields of the FACS |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 153 | * |
| 154 | ******************************************************************************/ |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 155 | |
Lv Zheng | aca2a5d | 2015-07-01 14:43:04 +0800 | [diff] [blame] | 156 | acpi_status |
| 157 | acpi_set_firmware_waking_vectors(acpi_physical_address physical_address, |
| 158 | acpi_physical_address physical_address64) |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 159 | { |
Lv Zheng | f06147f | 2015-07-01 14:43:18 +0800 | [diff] [blame] | 160 | |
Lv Zheng | aca2a5d | 2015-07-01 14:43:04 +0800 | [diff] [blame] | 161 | ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vectors); |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 162 | |
Lv Zheng | 7484619 | 2015-08-25 10:29:08 +0800 | [diff] [blame] | 163 | if (acpi_gbl_FACS) { |
| 164 | (void)acpi_hw_set_firmware_waking_vectors(acpi_gbl_FACS, |
Lv Zheng | f06147f | 2015-07-01 14:43:18 +0800 | [diff] [blame] | 165 | physical_address, |
| 166 | physical_address64); |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | return_ACPI_STATUS(AE_OK); |
| 170 | } |
| 171 | |
Lv Zheng | aca2a5d | 2015-07-01 14:43:04 +0800 | [diff] [blame] | 172 | ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vectors) |
| 173 | |
| 174 | /******************************************************************************* |
| 175 | * |
| 176 | * FUNCTION: acpi_set_firmware_waking_vector |
| 177 | * |
| 178 | * PARAMETERS: physical_address - 32-bit physical address of ACPI real mode |
| 179 | * entry point. |
| 180 | * |
| 181 | * RETURN: Status |
| 182 | * |
| 183 | * DESCRIPTION: Sets the 32-bit firmware_waking_vector field of the FACS |
| 184 | * |
| 185 | ******************************************************************************/ |
| 186 | acpi_status acpi_set_firmware_waking_vector(u32 physical_address) |
| 187 | { |
| 188 | acpi_status status; |
| 189 | |
| 190 | ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector); |
| 191 | |
| 192 | status = acpi_set_firmware_waking_vectors((acpi_physical_address) |
| 193 | physical_address, 0); |
| 194 | |
| 195 | return_ACPI_STATUS(status); |
| 196 | } |
| 197 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 198 | ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector) |
| 199 | |
| 200 | #if ACPI_MACHINE_WIDTH == 64 |
| 201 | /******************************************************************************* |
| 202 | * |
| 203 | * FUNCTION: acpi_set_firmware_waking_vector64 |
| 204 | * |
| 205 | * PARAMETERS: physical_address - 64-bit physical address of ACPI protected |
| 206 | * mode entry point. |
| 207 | * |
| 208 | * RETURN: Status |
| 209 | * |
| 210 | * DESCRIPTION: Sets the 64-bit X_firmware_waking_vector field of the FACS, if |
| 211 | * it exists in the table. This function is intended for use with |
| 212 | * 64-bit host operating systems. |
| 213 | * |
| 214 | ******************************************************************************/ |
| 215 | acpi_status acpi_set_firmware_waking_vector64(u64 physical_address) |
| 216 | { |
Lv Zheng | aca2a5d | 2015-07-01 14:43:04 +0800 | [diff] [blame] | 217 | acpi_status status; |
| 218 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 219 | ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector64); |
| 220 | |
Lv Zheng | aca2a5d | 2015-07-01 14:43:04 +0800 | [diff] [blame] | 221 | status = acpi_set_firmware_waking_vectors(0, |
| 222 | (acpi_physical_address) |
| 223 | physical_address); |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 224 | |
Lv Zheng | aca2a5d | 2015-07-01 14:43:04 +0800 | [diff] [blame] | 225 | return_ACPI_STATUS(status); |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector64) |
| 229 | #endif |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 230 | /******************************************************************************* |
| 231 | * |
| 232 | * FUNCTION: acpi_enter_sleep_state_s4bios |
| 233 | * |
| 234 | * PARAMETERS: None |
| 235 | * |
| 236 | * RETURN: Status |
| 237 | * |
| 238 | * DESCRIPTION: Perform a S4 bios request. |
| 239 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED |
| 240 | * |
| 241 | ******************************************************************************/ |
Lv Zheng | 40bce10 | 2013-10-31 09:31:18 +0800 | [diff] [blame] | 242 | acpi_status acpi_enter_sleep_state_s4bios(void) |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 243 | { |
| 244 | u32 in_value; |
| 245 | acpi_status status; |
| 246 | |
| 247 | ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios); |
| 248 | |
| 249 | /* Clear the wake status bit (PM1) */ |
| 250 | |
| 251 | status = |
| 252 | acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS); |
| 253 | if (ACPI_FAILURE(status)) { |
| 254 | return_ACPI_STATUS(status); |
| 255 | } |
| 256 | |
| 257 | status = acpi_hw_clear_acpi_status(); |
| 258 | if (ACPI_FAILURE(status)) { |
| 259 | return_ACPI_STATUS(status); |
| 260 | } |
| 261 | |
| 262 | /* |
| 263 | * 1) Disable/Clear all GPEs |
| 264 | * 2) Enable all wakeup GPEs |
| 265 | */ |
| 266 | status = acpi_hw_disable_all_gpes(); |
| 267 | if (ACPI_FAILURE(status)) { |
| 268 | return_ACPI_STATUS(status); |
| 269 | } |
| 270 | acpi_gbl_system_awake_and_running = FALSE; |
| 271 | |
| 272 | status = acpi_hw_enable_all_wakeup_gpes(); |
| 273 | if (ACPI_FAILURE(status)) { |
| 274 | return_ACPI_STATUS(status); |
| 275 | } |
| 276 | |
| 277 | ACPI_FLUSH_CPU_CACHE(); |
| 278 | |
| 279 | status = acpi_hw_write_port(acpi_gbl_FADT.smi_command, |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 280 | (u32)acpi_gbl_FADT.s4_bios_request, 8); |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 281 | |
| 282 | do { |
Bob Moore | c41679a | 2012-12-31 00:05:46 +0000 | [diff] [blame] | 283 | acpi_os_stall(ACPI_USEC_PER_MSEC); |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 284 | status = |
| 285 | acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS, &in_value); |
| 286 | if (ACPI_FAILURE(status)) { |
| 287 | return_ACPI_STATUS(status); |
| 288 | } |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame^] | 289 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 290 | } while (!in_value); |
| 291 | |
| 292 | return_ACPI_STATUS(AE_OK); |
| 293 | } |
| 294 | |
| 295 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios) |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 296 | #endif /* !ACPI_REDUCED_HARDWARE */ |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 297 | /******************************************************************************* |
| 298 | * |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 299 | * FUNCTION: acpi_hw_sleep_dispatch |
| 300 | * |
| 301 | * PARAMETERS: sleep_state - Which sleep state to enter/exit |
| 302 | * function_id - Sleep, wake_prep, or Wake |
| 303 | * |
| 304 | * RETURN: Status from the invoked sleep handling function. |
| 305 | * |
| 306 | * DESCRIPTION: Dispatch a sleep/wake request to the appropriate handling |
| 307 | * function. |
| 308 | * |
| 309 | ******************************************************************************/ |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 310 | static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id) |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 311 | { |
| 312 | acpi_status status; |
| 313 | struct acpi_sleep_functions *sleep_functions = |
| 314 | &acpi_sleep_dispatch[function_id]; |
| 315 | |
| 316 | #if (!ACPI_REDUCED_HARDWARE) |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 317 | /* |
| 318 | * If the Hardware Reduced flag is set (from the FADT), we must |
Lv Zheng | 7cec704 | 2013-06-08 00:59:18 +0000 | [diff] [blame] | 319 | * use the extended sleep registers (FADT). Note: As per the ACPI |
| 320 | * specification, these extended registers are to be used for HW-reduced |
| 321 | * platforms only. They are not general-purpose replacements for the |
| 322 | * legacy PM register sleep support. |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 323 | */ |
Lv Zheng | 7cec704 | 2013-06-08 00:59:18 +0000 | [diff] [blame] | 324 | if (acpi_gbl_reduced_hardware) { |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 325 | status = sleep_functions->extended_function(sleep_state); |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 326 | } else { |
| 327 | /* Legacy sleep */ |
| 328 | |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 329 | status = sleep_functions->legacy_function(sleep_state); |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | return (status); |
| 333 | |
| 334 | #else |
| 335 | /* |
| 336 | * For the case where reduced-hardware-only code is being generated, |
| 337 | * we know that only the extended sleep registers are available |
| 338 | */ |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 339 | status = sleep_functions->extended_function(sleep_state); |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 340 | return (status); |
| 341 | |
| 342 | #endif /* !ACPI_REDUCED_HARDWARE */ |
| 343 | } |
| 344 | |
| 345 | /******************************************************************************* |
| 346 | * |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 347 | * FUNCTION: acpi_enter_sleep_state_prep |
| 348 | * |
| 349 | * PARAMETERS: sleep_state - Which sleep state to enter |
| 350 | * |
| 351 | * RETURN: Status |
| 352 | * |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 353 | * DESCRIPTION: Prepare to enter a system sleep state. |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 354 | * This function must execute with interrupts enabled. |
| 355 | * We break sleeping into 2 stages so that OSPM can handle |
| 356 | * various OS-specific tasks between the two steps. |
| 357 | * |
| 358 | ******************************************************************************/ |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 359 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 360 | acpi_status acpi_enter_sleep_state_prep(u8 sleep_state) |
| 361 | { |
| 362 | acpi_status status; |
| 363 | struct acpi_object_list arg_list; |
| 364 | union acpi_object arg; |
| 365 | u32 sst_value; |
| 366 | |
| 367 | ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep); |
| 368 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 369 | status = acpi_get_sleep_type_data(sleep_state, |
| 370 | &acpi_gbl_sleep_type_a, |
| 371 | &acpi_gbl_sleep_type_b); |
| 372 | if (ACPI_FAILURE(status)) { |
| 373 | return_ACPI_STATUS(status); |
| 374 | } |
| 375 | |
| 376 | /* Execute the _PTS method (Prepare To Sleep) */ |
| 377 | |
| 378 | arg_list.count = 1; |
| 379 | arg_list.pointer = &arg; |
| 380 | arg.type = ACPI_TYPE_INTEGER; |
| 381 | arg.integer.value = sleep_state; |
| 382 | |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 383 | status = |
| 384 | acpi_evaluate_object(NULL, METHOD_PATHNAME__PTS, &arg_list, NULL); |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 385 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 386 | return_ACPI_STATUS(status); |
| 387 | } |
| 388 | |
| 389 | /* Setup the argument to the _SST method (System STatus) */ |
| 390 | |
| 391 | switch (sleep_state) { |
| 392 | case ACPI_STATE_S0: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 393 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 394 | sst_value = ACPI_SST_WORKING; |
| 395 | break; |
| 396 | |
| 397 | case ACPI_STATE_S1: |
| 398 | case ACPI_STATE_S2: |
| 399 | case ACPI_STATE_S3: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 400 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 401 | sst_value = ACPI_SST_SLEEPING; |
| 402 | break; |
| 403 | |
| 404 | case ACPI_STATE_S4: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 405 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 406 | sst_value = ACPI_SST_SLEEP_CONTEXT; |
| 407 | break; |
| 408 | |
| 409 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 410 | |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 411 | sst_value = ACPI_SST_INDICATOR_OFF; /* Default is off */ |
| 412 | break; |
| 413 | } |
| 414 | |
| 415 | /* |
| 416 | * Set the system indicators to show the desired sleep state. |
| 417 | * _SST is an optional method (return no error if not found) |
| 418 | */ |
Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 419 | acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, sst_value); |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 420 | return_ACPI_STATUS(AE_OK); |
| 421 | } |
| 422 | |
| 423 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep) |
| 424 | |
| 425 | /******************************************************************************* |
| 426 | * |
| 427 | * FUNCTION: acpi_enter_sleep_state |
| 428 | * |
| 429 | * PARAMETERS: sleep_state - Which sleep state to enter |
| 430 | * |
| 431 | * RETURN: Status |
| 432 | * |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 433 | * DESCRIPTION: Enter a system sleep state |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 434 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED |
| 435 | * |
| 436 | ******************************************************************************/ |
Lv Zheng | 40bce10 | 2013-10-31 09:31:18 +0800 | [diff] [blame] | 437 | acpi_status acpi_enter_sleep_state(u8 sleep_state) |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 438 | { |
| 439 | acpi_status status; |
| 440 | |
| 441 | ACPI_FUNCTION_TRACE(acpi_enter_sleep_state); |
| 442 | |
| 443 | if ((acpi_gbl_sleep_type_a > ACPI_SLEEP_TYPE_MAX) || |
| 444 | (acpi_gbl_sleep_type_b > ACPI_SLEEP_TYPE_MAX)) { |
| 445 | ACPI_ERROR((AE_INFO, "Sleep values out of range: A=0x%X B=0x%X", |
| 446 | acpi_gbl_sleep_type_a, acpi_gbl_sleep_type_b)); |
| 447 | return_ACPI_STATUS(AE_AML_OPERAND_VALUE); |
| 448 | } |
| 449 | |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 450 | status = acpi_hw_sleep_dispatch(sleep_state, ACPI_SLEEP_FUNCTION_ID); |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 451 | return_ACPI_STATUS(status); |
| 452 | } |
| 453 | |
| 454 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state) |
| 455 | |
| 456 | /******************************************************************************* |
| 457 | * |
| 458 | * FUNCTION: acpi_leave_sleep_state_prep |
| 459 | * |
| 460 | * PARAMETERS: sleep_state - Which sleep state we are exiting |
| 461 | * |
| 462 | * RETURN: Status |
| 463 | * |
| 464 | * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 465 | * sleep. Called with interrupts DISABLED. |
| 466 | * We break wake/resume into 2 stages so that OSPM can handle |
| 467 | * various OS-specific tasks between the two steps. |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 468 | * |
| 469 | ******************************************************************************/ |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 470 | acpi_status acpi_leave_sleep_state_prep(u8 sleep_state) |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 471 | { |
| 472 | acpi_status status; |
| 473 | |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 474 | ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep); |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 475 | |
Lin Ming | 8a73b17 | 2012-03-21 10:01:49 +0800 | [diff] [blame] | 476 | status = |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 477 | acpi_hw_sleep_dispatch(sleep_state, ACPI_WAKE_PREP_FUNCTION_ID); |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 478 | return_ACPI_STATUS(status); |
| 479 | } |
| 480 | |
| 481 | ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state_prep) |
| 482 | |
| 483 | /******************************************************************************* |
| 484 | * |
| 485 | * FUNCTION: acpi_leave_sleep_state |
| 486 | * |
Bob Moore | 72a8887 | 2012-02-14 18:57:13 +0800 | [diff] [blame] | 487 | * PARAMETERS: sleep_state - Which sleep state we are exiting |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 488 | * |
| 489 | * RETURN: Status |
| 490 | * |
| 491 | * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep |
| 492 | * Called with interrupts ENABLED. |
| 493 | * |
| 494 | ******************************************************************************/ |
| 495 | acpi_status acpi_leave_sleep_state(u8 sleep_state) |
| 496 | { |
| 497 | acpi_status status; |
| 498 | |
| 499 | ACPI_FUNCTION_TRACE(acpi_leave_sleep_state); |
| 500 | |
Len Brown | 3f6f49c | 2012-07-26 20:08:54 -0400 | [diff] [blame] | 501 | status = acpi_hw_sleep_dispatch(sleep_state, ACPI_WAKE_FUNCTION_ID); |
Bob Moore | 2feec47 | 2012-02-14 15:00:53 +0800 | [diff] [blame] | 502 | return_ACPI_STATUS(status); |
| 503 | } |
| 504 | |
| 505 | ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state) |