Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface |
| 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
Bob Moore | 7784813 | 2012-01-12 13:27:23 +0800 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2012, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 46 | #include "accommon.h" |
| 47 | #include "actables.h" |
Shane Wang | 69575d3 | 2009-09-01 18:25:07 -0700 | [diff] [blame] | 48 | #include <linux/tboot.h> |
Paul Gortmaker | cc4b859 | 2011-07-01 14:30:49 -0400 | [diff] [blame] | 49 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #define _COMPONENT ACPI_HARDWARE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("hwsleep") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 54 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * |
| 56 | * FUNCTION: acpi_set_firmware_waking_vector |
| 57 | * |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 58 | * PARAMETERS: physical_address - 32-bit physical address of ACPI real mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | * entry point. |
| 60 | * |
| 61 | * RETURN: Status |
| 62 | * |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 63 | * DESCRIPTION: Sets the 32-bit firmware_waking_vector field of the FACS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | * |
| 65 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | acpi_status |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 67 | acpi_set_firmware_waking_vector(u32 physical_address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 69 | ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 71 | |
Rafael J. Wysocki | a662910 | 2008-09-06 13:13:01 +0200 | [diff] [blame] | 72 | /* |
| 73 | * According to the ACPI specification 2.0c and later, the 64-bit |
| 74 | * waking vector should be cleared and the 32-bit waking vector should |
| 75 | * be used, unless we want the wake-up code to be called by the BIOS in |
| 76 | * Protected Mode. Some systems (for example HP dv5-1004nr) are known |
| 77 | * to fail to resume if the 64-bit vector is used. |
| 78 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 80 | /* Set the 32-bit vector */ |
| 81 | |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 82 | acpi_gbl_FACS->firmware_waking_vector = physical_address; |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 83 | |
| 84 | /* Clear the 64-bit vector if it exists */ |
| 85 | |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 86 | if ((acpi_gbl_FACS->length > 32) && (acpi_gbl_FACS->version >= 1)) { |
| 87 | acpi_gbl_FACS->xfirmware_waking_vector = 0; |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 88 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 90 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 93 | ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector) |
| 94 | |
Bob Moore | 4f70e37 | 2009-02-18 14:52:43 +0800 | [diff] [blame] | 95 | #if ACPI_MACHINE_WIDTH == 64 |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 96 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | * |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 98 | * FUNCTION: acpi_set_firmware_waking_vector64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | * |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 100 | * PARAMETERS: physical_address - 64-bit physical address of ACPI protected |
| 101 | * mode entry point. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | * |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 103 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | * |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 105 | * DESCRIPTION: Sets the 64-bit X_firmware_waking_vector field of the FACS, if |
Bob Moore | 4f70e37 | 2009-02-18 14:52:43 +0800 | [diff] [blame] | 106 | * it exists in the table. This function is intended for use with |
| 107 | * 64-bit host operating systems. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * |
| 109 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | acpi_status |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 111 | acpi_set_firmware_waking_vector64(u64 physical_address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 113 | ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 116 | /* Determine if the 64-bit vector actually exists */ |
| 117 | |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 118 | if ((acpi_gbl_FACS->length <= 32) || (acpi_gbl_FACS->version < 1)) { |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 119 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 120 | } |
| 121 | |
| 122 | /* Clear 32-bit vector, set the 64-bit X_ vector */ |
| 123 | |
Bob Moore | 009c4cbe | 2008-11-12 15:34:52 +0800 | [diff] [blame] | 124 | acpi_gbl_FACS->firmware_waking_vector = 0; |
| 125 | acpi_gbl_FACS->xfirmware_waking_vector = physical_address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 129 | |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 130 | ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector64) |
Bob Moore | 4f70e37 | 2009-02-18 14:52:43 +0800 | [diff] [blame] | 131 | #endif |
Bob Moore | d85988f | 2008-11-12 14:54:05 +0800 | [diff] [blame] | 132 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 133 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | * |
| 135 | * FUNCTION: acpi_enter_sleep_state_prep |
| 136 | * |
| 137 | * PARAMETERS: sleep_state - Which sleep state to enter |
| 138 | * |
| 139 | * RETURN: Status |
| 140 | * |
| 141 | * DESCRIPTION: Prepare to enter a system sleep state (see ACPI 2.0 spec p 231) |
| 142 | * This function must execute with interrupts enabled. |
| 143 | * We break sleeping into 2 stages so that OSPM can handle |
| 144 | * various OS-specific tasks between the two steps. |
| 145 | * |
| 146 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | acpi_status acpi_enter_sleep_state_prep(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | acpi_status status; |
| 150 | struct acpi_object_list arg_list; |
| 151 | union acpi_object arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 153 | ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 155 | /* _PSW methods could be run here to enable wake-on keyboard, LAN, etc. */ |
| 156 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | status = acpi_get_sleep_type_data(sleep_state, |
| 158 | &acpi_gbl_sleep_type_a, |
| 159 | &acpi_gbl_sleep_type_b); |
| 160 | if (ACPI_FAILURE(status)) { |
| 161 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /* Setup parameter object */ |
| 165 | |
| 166 | arg_list.count = 1; |
| 167 | arg_list.pointer = &arg; |
| 168 | |
| 169 | arg.type = ACPI_TYPE_INTEGER; |
| 170 | arg.integer.value = sleep_state; |
| 171 | |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 172 | /* Run the _PTS method */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | status = acpi_evaluate_object(NULL, METHOD_NAME__PTS, &arg_list, NULL); |
| 175 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 176 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* Setup the argument to _SST */ |
| 180 | |
| 181 | switch (sleep_state) { |
| 182 | case ACPI_STATE_S0: |
| 183 | arg.integer.value = ACPI_SST_WORKING; |
| 184 | break; |
| 185 | |
| 186 | case ACPI_STATE_S1: |
| 187 | case ACPI_STATE_S2: |
| 188 | case ACPI_STATE_S3: |
| 189 | arg.integer.value = ACPI_SST_SLEEPING; |
| 190 | break; |
| 191 | |
| 192 | case ACPI_STATE_S4: |
| 193 | arg.integer.value = ACPI_SST_SLEEP_CONTEXT; |
| 194 | break; |
| 195 | |
| 196 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 197 | arg.integer.value = ACPI_SST_INDICATOR_OFF; /* Default is off */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | break; |
| 199 | } |
| 200 | |
Bob Moore | d52c79a | 2008-06-10 14:26:57 +0800 | [diff] [blame] | 201 | /* |
| 202 | * Set the system indicators to show the desired sleep state. |
| 203 | * _SST is an optional method (return no error if not found) |
| 204 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 205 | status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); |
| 206 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 207 | ACPI_EXCEPTION((AE_INFO, status, |
| 208 | "While executing method _SST")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Bob Moore | d52c79a | 2008-06-10 14:26:57 +0800 | [diff] [blame] | 211 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 214 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep) |
| 215 | |
Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 216 | static unsigned int gts, bfs; |
| 217 | module_param(gts, uint, 0644); |
| 218 | module_param(bfs, uint, 0644); |
| 219 | MODULE_PARM_DESC(gts, "Enable evaluation of _GTS on suspend."); |
| 220 | MODULE_PARM_DESC(bfs, "Enable evaluation of _BFS on resume".); |
| 221 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 222 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | * |
| 224 | * FUNCTION: acpi_enter_sleep_state |
| 225 | * |
| 226 | * PARAMETERS: sleep_state - Which sleep state to enter |
| 227 | * |
| 228 | * RETURN: Status |
| 229 | * |
| 230 | * DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231) |
| 231 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED |
| 232 | * |
| 233 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 234 | acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 236 | u32 pm1a_control; |
| 237 | u32 pm1b_control; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 238 | struct acpi_bit_register_info *sleep_type_reg_info; |
| 239 | struct acpi_bit_register_info *sleep_enable_reg_info; |
| 240 | u32 in_value; |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 241 | struct acpi_object_list arg_list; |
| 242 | union acpi_object arg; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 245 | ACPI_FUNCTION_TRACE(acpi_enter_sleep_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | if ((acpi_gbl_sleep_type_a > ACPI_SLEEP_TYPE_MAX) || |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | (acpi_gbl_sleep_type_b > ACPI_SLEEP_TYPE_MAX)) { |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 249 | ACPI_ERROR((AE_INFO, "Sleep values out of range: A=0x%X B=0x%X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 250 | acpi_gbl_sleep_type_a, acpi_gbl_sleep_type_b)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 251 | return_ACPI_STATUS(AE_AML_OPERAND_VALUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 254 | sleep_type_reg_info = |
Bob Moore | 82d79b8 | 2009-02-18 14:31:05 +0800 | [diff] [blame] | 255 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 256 | sleep_enable_reg_info = |
| 257 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | /* Clear wake status */ |
| 260 | |
Bob Moore | 768aaaf | 2009-03-06 09:49:25 +0800 | [diff] [blame] | 261 | status = |
| 262 | acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 263 | if (ACPI_FAILURE(status)) { |
| 264 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /* Clear all fixed and general purpose status bits */ |
| 268 | |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 269 | status = acpi_hw_clear_acpi_status(); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | if (ACPI_FAILURE(status)) { |
| 271 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* |
Pavel Machek | 23b168d | 2008-02-05 19:27:12 +0100 | [diff] [blame] | 275 | * 1) Disable/Clear all GPEs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | * 2) Enable all wakeup GPEs |
| 277 | */ |
Alexey Starikovskiy | 1d99967 | 2007-03-12 14:49:26 -0400 | [diff] [blame] | 278 | status = acpi_hw_disable_all_gpes(); |
| 279 | if (ACPI_FAILURE(status)) { |
| 280 | return_ACPI_STATUS(status); |
| 281 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | acpi_gbl_system_awake_and_running = FALSE; |
| 283 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 284 | status = acpi_hw_enable_all_wakeup_gpes(); |
| 285 | if (ACPI_FAILURE(status)) { |
| 286 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 289 | if (gts) { |
| 290 | /* Execute the _GTS method */ |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 291 | |
Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 292 | arg_list.count = 1; |
| 293 | arg_list.pointer = &arg; |
| 294 | arg.type = ACPI_TYPE_INTEGER; |
| 295 | arg.integer.value = sleep_state; |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 296 | |
Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 297 | status = acpi_evaluate_object(NULL, METHOD_NAME__GTS, &arg_list, NULL); |
| 298 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 299 | return_ACPI_STATUS(status); |
| 300 | } |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 301 | } |
| 302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | /* Get current value of PM1A control */ |
| 304 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 305 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
| 306 | &pm1a_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | if (ACPI_FAILURE(status)) { |
| 308 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 310 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
Bob Moore | b27d659 | 2010-05-26 11:47:13 +0800 | [diff] [blame] | 311 | "Entering sleep state [S%u]\n", sleep_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 313 | /* Clear the SLP_EN and SLP_TYP fields */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 315 | pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | |
| 316 | sleep_enable_reg_info->access_bit_mask); |
| 317 | pm1b_control = pm1a_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 319 | /* Insert the SLP_TYP bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 321 | pm1a_control |= |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position); |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 323 | pm1b_control |= |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 324 | (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | /* |
| 327 | * We split the writes of SLP_TYP and SLP_EN to workaround |
| 328 | * poorly implemented hardware. |
| 329 | */ |
| 330 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 331 | /* Write #1: write the SLP_TYP data to the PM1 Control registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 333 | status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 334 | if (ACPI_FAILURE(status)) { |
| 335 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 338 | /* Insert the sleep enable (SLP_EN) bit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 340 | pm1a_control |= sleep_enable_reg_info->access_bit_mask; |
| 341 | pm1b_control |= sleep_enable_reg_info->access_bit_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 343 | /* Flush caches, as per ACPI specification */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 345 | ACPI_FLUSH_CPU_CACHE(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Joseph Cihula | 86886e5 | 2009-06-30 19:31:07 -0700 | [diff] [blame] | 347 | tboot_sleep(sleep_state, pm1a_control, pm1b_control); |
| 348 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 349 | /* Write #2: Write both SLP_TYP + SLP_EN */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 351 | status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 352 | if (ACPI_FAILURE(status)) { |
| 353 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | if (sleep_state > ACPI_STATE_S3) { |
| 357 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 358 | * We wanted to sleep > S3, but it didn't happen (by virtue of the |
| 359 | * fact that we are still executing!) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 361 | * Wait ten seconds, then try again. This is to get S4/S5 to work on |
| 362 | * all machines. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | * |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 364 | * We wait so long to allow chipsets that poll this reg very slowly |
| 365 | * to still read the right value. Ideally, this block would go |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | * away entirely. |
| 367 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | acpi_os_stall(10000000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 370 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 371 | sleep_enable_reg_info-> |
| 372 | access_bit_mask); |
| 373 | if (ACPI_FAILURE(status)) { |
| 374 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | |
| 378 | /* Wait until we enter sleep state */ |
| 379 | |
| 380 | do { |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 381 | status = acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS, |
Alexey Starikovskiy | 2d571b3 | 2007-09-30 22:39:42 +0400 | [diff] [blame] | 382 | &in_value); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 383 | if (ACPI_FAILURE(status)) { |
| 384 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /* Spin until we wake */ |
| 388 | |
| 389 | } while (!in_value); |
| 390 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 391 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 394 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 396 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | * |
| 398 | * FUNCTION: acpi_enter_sleep_state_s4bios |
| 399 | * |
| 400 | * PARAMETERS: None |
| 401 | * |
| 402 | * RETURN: Status |
| 403 | * |
| 404 | * DESCRIPTION: Perform a S4 bios request. |
| 405 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED |
| 406 | * |
| 407 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 408 | acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 410 | u32 in_value; |
| 411 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 413 | ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Bob Moore | 768aaaf | 2009-03-06 09:49:25 +0800 | [diff] [blame] | 415 | /* Clear the wake status bit (PM1) */ |
| 416 | |
| 417 | status = |
| 418 | acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 419 | if (ACPI_FAILURE(status)) { |
| 420 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Bob Moore | d8c71b6 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 423 | status = acpi_hw_clear_acpi_status(); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 424 | if (ACPI_FAILURE(status)) { |
| 425 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /* |
| 429 | * 1) Disable/Clear all GPEs |
| 430 | * 2) Enable all wakeup GPEs |
| 431 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 432 | status = acpi_hw_disable_all_gpes(); |
| 433 | if (ACPI_FAILURE(status)) { |
| 434 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
| 436 | acpi_gbl_system_awake_and_running = FALSE; |
| 437 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 438 | status = acpi_hw_enable_all_wakeup_gpes(); |
| 439 | if (ACPI_FAILURE(status)) { |
| 440 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 443 | ACPI_FLUSH_CPU_CACHE(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Bob Moore | 7f07190 | 2009-03-19 09:37:47 +0800 | [diff] [blame] | 445 | status = acpi_hw_write_port(acpi_gbl_FADT.smi_command, |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 446 | (u32) acpi_gbl_FADT.S4bios_request, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | do { |
| 449 | acpi_os_stall(1000); |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 450 | status = |
| 451 | acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS, &in_value); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 452 | if (ACPI_FAILURE(status)) { |
| 453 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | } while (!in_value); |
| 456 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 457 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 460 | ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 462 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | * |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 464 | * FUNCTION: acpi_leave_sleep_state_prep |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | * |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 466 | * PARAMETERS: sleep_state - Which sleep state we are exiting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | * |
| 468 | * RETURN: Status |
| 469 | * |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 470 | * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a |
| 471 | * sleep. |
| 472 | * Called with interrupts DISABLED. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | * |
| 474 | ******************************************************************************/ |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 475 | acpi_status acpi_leave_sleep_state_prep(u8 sleep_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 477 | struct acpi_object_list arg_list; |
| 478 | union acpi_object arg; |
| 479 | acpi_status status; |
| 480 | struct acpi_bit_register_info *sleep_type_reg_info; |
| 481 | struct acpi_bit_register_info *sleep_enable_reg_info; |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 482 | u32 pm1a_control; |
| 483 | u32 pm1b_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 485 | ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
| 487 | /* |
| 488 | * Set SLP_TYPE and SLP_EN to state S0. |
| 489 | * This is unclear from the ACPI Spec, but it is required |
| 490 | * by some machines. |
| 491 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 492 | status = acpi_get_sleep_type_data(ACPI_STATE_S0, |
| 493 | &acpi_gbl_sleep_type_a, |
| 494 | &acpi_gbl_sleep_type_b); |
| 495 | if (ACPI_SUCCESS(status)) { |
| 496 | sleep_type_reg_info = |
Bob Moore | 82d79b8 | 2009-02-18 14:31:05 +0800 | [diff] [blame] | 497 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 498 | sleep_enable_reg_info = |
| 499 | acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
| 501 | /* Get current value of PM1A control */ |
| 502 | |
Alexey Starikovskiy | d30dc9ab | 2007-09-30 22:39:36 +0400 | [diff] [blame] | 503 | status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 504 | &pm1a_control); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 505 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 506 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 507 | /* Clear the SLP_EN and SLP_TYP fields */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 509 | pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | |
| 510 | sleep_enable_reg_info-> |
| 511 | access_bit_mask); |
| 512 | pm1b_control = pm1a_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 514 | /* Insert the SLP_TYP bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 516 | pm1a_control |= (acpi_gbl_sleep_type_a << |
| 517 | sleep_type_reg_info->bit_position); |
| 518 | pm1b_control |= (acpi_gbl_sleep_type_b << |
| 519 | sleep_type_reg_info->bit_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 521 | /* Write the control registers and ignore any errors */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Bob Moore | 32c9ef9 | 2009-02-18 14:36:05 +0800 | [diff] [blame] | 523 | (void)acpi_hw_write_pm1_control(pm1a_control, |
| 524 | pm1b_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 528 | if (bfs) { |
| 529 | /* Execute the _BFS method */ |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 530 | |
Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 531 | arg_list.count = 1; |
| 532 | arg_list.pointer = &arg; |
| 533 | arg.type = ACPI_TYPE_INTEGER; |
| 534 | arg.integer.value = sleep_state; |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 535 | |
Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 536 | status = acpi_evaluate_object(NULL, METHOD_NAME__BFS, &arg_list, NULL); |
| 537 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 538 | ACPI_EXCEPTION((AE_INFO, status, "During Method _BFS")); |
| 539 | } |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 540 | } |
Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 541 | return_ACPI_STATUS(status); |
| 542 | } |
| 543 | |
| 544 | /******************************************************************************* |
| 545 | * |
| 546 | * FUNCTION: acpi_leave_sleep_state |
| 547 | * |
| 548 | * PARAMETERS: sleep_state - Which sleep state we just exited |
| 549 | * |
| 550 | * RETURN: Status |
| 551 | * |
| 552 | * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep |
| 553 | * Called with interrupts ENABLED. |
| 554 | * |
| 555 | ******************************************************************************/ |
| 556 | acpi_status acpi_leave_sleep_state(u8 sleep_state) |
| 557 | { |
| 558 | struct acpi_object_list arg_list; |
| 559 | union acpi_object arg; |
| 560 | acpi_status status; |
| 561 | |
| 562 | ACPI_FUNCTION_TRACE(acpi_leave_sleep_state); |
| 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */ |
| 565 | |
| 566 | acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID; |
| 567 | |
| 568 | /* Setup parameter object */ |
| 569 | |
| 570 | arg_list.count = 1; |
| 571 | arg_list.pointer = &arg; |
| 572 | arg.type = ACPI_TYPE_INTEGER; |
| 573 | |
| 574 | /* Ignore any errors from these methods */ |
| 575 | |
| 576 | arg.integer.value = ACPI_SST_WAKING; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 577 | status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); |
| 578 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 579 | ACPI_EXCEPTION((AE_INFO, status, "During Method _SST")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | /* |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 583 | * GPEs must be enabled before _WAK is called as GPEs |
| 584 | * might get fired there |
| 585 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | * Restore the GPEs: |
| 587 | * 1) Disable/Clear all GPEs |
| 588 | * 2) Enable all runtime GPEs |
| 589 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 590 | status = acpi_hw_disable_all_gpes(); |
| 591 | if (ACPI_FAILURE(status)) { |
| 592 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 594 | status = acpi_hw_enable_all_runtime_gpes(); |
| 595 | if (ACPI_FAILURE(status)) { |
| 596 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Rafael J. Wysocki | 314ccd6 | 2008-02-13 00:32:16 +0100 | [diff] [blame] | 599 | arg.integer.value = sleep_state; |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 600 | status = acpi_evaluate_object(NULL, METHOD_NAME__WAK, &arg_list, NULL); |
| 601 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 602 | ACPI_EXCEPTION((AE_INFO, status, "During Method _WAK")); |
| 603 | } |
| 604 | /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */ |
| 605 | |
Matthew Garrett | a68823e | 2008-08-06 19:12:04 +0100 | [diff] [blame] | 606 | /* |
| 607 | * Some BIOSes assume that WAK_STS will be cleared on resume and use |
| 608 | * it to determine whether the system is rebooting or resuming. Clear |
| 609 | * it for compatibility. |
| 610 | */ |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 611 | acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, 1); |
Matthew Garrett | a68823e | 2008-08-06 19:12:04 +0100 | [diff] [blame] | 612 | |
Thomas Renninger | 79d2dfa | 2007-08-24 01:24:47 -0400 | [diff] [blame] | 613 | acpi_gbl_system_awake_and_running = TRUE; |
| 614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | /* Enable power button */ |
| 616 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 617 | (void) |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 618 | acpi_write_bit_register(acpi_gbl_fixed_event_info |
Bob Moore | 768aaaf | 2009-03-06 09:49:25 +0800 | [diff] [blame] | 619 | [ACPI_EVENT_POWER_BUTTON]. |
| 620 | enable_register_id, ACPI_ENABLE_EVENT); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 621 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 622 | (void) |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 623 | acpi_write_bit_register(acpi_gbl_fixed_event_info |
Bob Moore | 768aaaf | 2009-03-06 09:49:25 +0800 | [diff] [blame] | 624 | [ACPI_EVENT_POWER_BUTTON]. |
| 625 | status_register_id, ACPI_CLEAR_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
| 627 | arg.integer.value = ACPI_SST_WORKING; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 628 | status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); |
| 629 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 630 | ACPI_EXCEPTION((AE_INFO, status, "During Method _SST")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 633 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 635 | |
| 636 | ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state) |