MAINTAINERS: Update qib and ipath entries from QLogic to Intel
[linux/fpc-iii.git] / drivers / acpi / acpica / hwxfsleep.c
blob762d059bb508af7bd05f14829beea233e039bfd8
1 /******************************************************************************
3 * Name: hwxfsleep.c - ACPI Hardware Sleep/Wake External Interfaces
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2012, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include <linux/module.h>
48 #define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME("hwxfsleep")
51 /* Local prototypes */
52 static acpi_status
53 acpi_hw_sleep_dispatch(u8 sleep_state, u8 flags, u32 function_id);
56 * Dispatch table used to efficiently branch to the various sleep
57 * functions.
59 #define ACPI_SLEEP_FUNCTION_ID 0
60 #define ACPI_WAKE_PREP_FUNCTION_ID 1
61 #define ACPI_WAKE_FUNCTION_ID 2
63 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
65 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
66 {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
67 acpi_hw_extended_sleep},
68 {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
69 acpi_hw_extended_wake_prep},
70 {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
74 * These functions are removed for the ACPI_REDUCED_HARDWARE case:
75 * acpi_set_firmware_waking_vector
76 * acpi_set_firmware_waking_vector64
77 * acpi_enter_sleep_state_s4bios
80 #if (!ACPI_REDUCED_HARDWARE)
81 /*******************************************************************************
83 * FUNCTION: acpi_set_firmware_waking_vector
85 * PARAMETERS: physical_address - 32-bit physical address of ACPI real mode
86 * entry point.
88 * RETURN: Status
90 * DESCRIPTION: Sets the 32-bit firmware_waking_vector field of the FACS
92 ******************************************************************************/
94 acpi_status acpi_set_firmware_waking_vector(u32 physical_address)
96 ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector);
100 * According to the ACPI specification 2.0c and later, the 64-bit
101 * waking vector should be cleared and the 32-bit waking vector should
102 * be used, unless we want the wake-up code to be called by the BIOS in
103 * Protected Mode. Some systems (for example HP dv5-1004nr) are known
104 * to fail to resume if the 64-bit vector is used.
107 /* Set the 32-bit vector */
109 acpi_gbl_FACS->firmware_waking_vector = physical_address;
111 /* Clear the 64-bit vector if it exists */
113 if ((acpi_gbl_FACS->length > 32) && (acpi_gbl_FACS->version >= 1)) {
114 acpi_gbl_FACS->xfirmware_waking_vector = 0;
117 return_ACPI_STATUS(AE_OK);
120 ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector)
122 #if ACPI_MACHINE_WIDTH == 64
123 /*******************************************************************************
125 * FUNCTION: acpi_set_firmware_waking_vector64
127 * PARAMETERS: physical_address - 64-bit physical address of ACPI protected
128 * mode entry point.
130 * RETURN: Status
132 * DESCRIPTION: Sets the 64-bit X_firmware_waking_vector field of the FACS, if
133 * it exists in the table. This function is intended for use with
134 * 64-bit host operating systems.
136 ******************************************************************************/
137 acpi_status acpi_set_firmware_waking_vector64(u64 physical_address)
139 ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector64);
142 /* Determine if the 64-bit vector actually exists */
144 if ((acpi_gbl_FACS->length <= 32) || (acpi_gbl_FACS->version < 1)) {
145 return_ACPI_STATUS(AE_NOT_EXIST);
148 /* Clear 32-bit vector, set the 64-bit X_ vector */
150 acpi_gbl_FACS->firmware_waking_vector = 0;
151 acpi_gbl_FACS->xfirmware_waking_vector = physical_address;
152 return_ACPI_STATUS(AE_OK);
155 ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector64)
156 #endif
158 /*******************************************************************************
160 * FUNCTION: acpi_enter_sleep_state_s4bios
162 * PARAMETERS: None
164 * RETURN: Status
166 * DESCRIPTION: Perform a S4 bios request.
167 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
169 ******************************************************************************/
170 acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void)
172 u32 in_value;
173 acpi_status status;
175 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios);
177 /* Clear the wake status bit (PM1) */
179 status =
180 acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS);
181 if (ACPI_FAILURE(status)) {
182 return_ACPI_STATUS(status);
185 status = acpi_hw_clear_acpi_status();
186 if (ACPI_FAILURE(status)) {
187 return_ACPI_STATUS(status);
191 * 1) Disable/Clear all GPEs
192 * 2) Enable all wakeup GPEs
194 status = acpi_hw_disable_all_gpes();
195 if (ACPI_FAILURE(status)) {
196 return_ACPI_STATUS(status);
198 acpi_gbl_system_awake_and_running = FALSE;
200 status = acpi_hw_enable_all_wakeup_gpes();
201 if (ACPI_FAILURE(status)) {
202 return_ACPI_STATUS(status);
205 ACPI_FLUSH_CPU_CACHE();
207 status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
208 (u32)acpi_gbl_FADT.S4bios_request, 8);
210 do {
211 acpi_os_stall(1000);
212 status =
213 acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS, &in_value);
214 if (ACPI_FAILURE(status)) {
215 return_ACPI_STATUS(status);
217 } while (!in_value);
219 return_ACPI_STATUS(AE_OK);
222 ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios)
223 #endif /* !ACPI_REDUCED_HARDWARE */
224 /*******************************************************************************
226 * FUNCTION: acpi_hw_sleep_dispatch
228 * PARAMETERS: sleep_state - Which sleep state to enter/exit
229 * function_id - Sleep, wake_prep, or Wake
231 * RETURN: Status from the invoked sleep handling function.
233 * DESCRIPTION: Dispatch a sleep/wake request to the appropriate handling
234 * function.
236 ******************************************************************************/
237 static acpi_status
238 acpi_hw_sleep_dispatch(u8 sleep_state, u8 flags, u32 function_id)
240 acpi_status status;
241 struct acpi_sleep_functions *sleep_functions =
242 &acpi_sleep_dispatch[function_id];
244 #if (!ACPI_REDUCED_HARDWARE)
247 * If the Hardware Reduced flag is set (from the FADT), we must
248 * use the extended sleep registers
250 if (acpi_gbl_reduced_hardware || acpi_gbl_FADT.sleep_control.address) {
251 status = sleep_functions->extended_function(sleep_state, flags);
252 } else {
253 /* Legacy sleep */
255 status = sleep_functions->legacy_function(sleep_state, flags);
258 return (status);
260 #else
262 * For the case where reduced-hardware-only code is being generated,
263 * we know that only the extended sleep registers are available
265 status = sleep_functions->extended_function(sleep_state, flags);
266 return (status);
268 #endif /* !ACPI_REDUCED_HARDWARE */
271 /*******************************************************************************
273 * FUNCTION: acpi_enter_sleep_state_prep
275 * PARAMETERS: sleep_state - Which sleep state to enter
277 * RETURN: Status
279 * DESCRIPTION: Prepare to enter a system sleep state.
280 * This function must execute with interrupts enabled.
281 * We break sleeping into 2 stages so that OSPM can handle
282 * various OS-specific tasks between the two steps.
284 ******************************************************************************/
286 acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
288 acpi_status status;
289 struct acpi_object_list arg_list;
290 union acpi_object arg;
291 u32 sst_value;
293 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep);
295 status = acpi_get_sleep_type_data(sleep_state,
296 &acpi_gbl_sleep_type_a,
297 &acpi_gbl_sleep_type_b);
298 if (ACPI_FAILURE(status)) {
299 return_ACPI_STATUS(status);
302 /* Execute the _PTS method (Prepare To Sleep) */
304 arg_list.count = 1;
305 arg_list.pointer = &arg;
306 arg.type = ACPI_TYPE_INTEGER;
307 arg.integer.value = sleep_state;
309 status =
310 acpi_evaluate_object(NULL, METHOD_PATHNAME__PTS, &arg_list, NULL);
311 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
312 return_ACPI_STATUS(status);
315 /* Setup the argument to the _SST method (System STatus) */
317 switch (sleep_state) {
318 case ACPI_STATE_S0:
319 sst_value = ACPI_SST_WORKING;
320 break;
322 case ACPI_STATE_S1:
323 case ACPI_STATE_S2:
324 case ACPI_STATE_S3:
325 sst_value = ACPI_SST_SLEEPING;
326 break;
328 case ACPI_STATE_S4:
329 sst_value = ACPI_SST_SLEEP_CONTEXT;
330 break;
332 default:
333 sst_value = ACPI_SST_INDICATOR_OFF; /* Default is off */
334 break;
338 * Set the system indicators to show the desired sleep state.
339 * _SST is an optional method (return no error if not found)
341 acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, sst_value);
342 return_ACPI_STATUS(AE_OK);
345 ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep)
347 /*******************************************************************************
349 * FUNCTION: acpi_enter_sleep_state
351 * PARAMETERS: sleep_state - Which sleep state to enter
352 * Flags - ACPI_EXECUTE_GTS to run optional method
354 * RETURN: Status
356 * DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231)
357 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
359 ******************************************************************************/
360 acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state, u8 flags)
362 acpi_status status;
364 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state);
366 if ((acpi_gbl_sleep_type_a > ACPI_SLEEP_TYPE_MAX) ||
367 (acpi_gbl_sleep_type_b > ACPI_SLEEP_TYPE_MAX)) {
368 ACPI_ERROR((AE_INFO, "Sleep values out of range: A=0x%X B=0x%X",
369 acpi_gbl_sleep_type_a, acpi_gbl_sleep_type_b));
370 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
373 status =
374 acpi_hw_sleep_dispatch(sleep_state, flags, ACPI_SLEEP_FUNCTION_ID);
375 return_ACPI_STATUS(status);
378 ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state)
380 /*******************************************************************************
382 * FUNCTION: acpi_leave_sleep_state_prep
384 * PARAMETERS: sleep_state - Which sleep state we are exiting
385 * Flags - ACPI_EXECUTE_BFS to run optional method
387 * RETURN: Status
389 * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
390 * sleep.
391 * Called with interrupts DISABLED.
393 ******************************************************************************/
394 acpi_status acpi_leave_sleep_state_prep(u8 sleep_state, u8 flags)
396 acpi_status status;
398 ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep);
400 status =
401 acpi_hw_sleep_dispatch(sleep_state, flags,
402 ACPI_WAKE_PREP_FUNCTION_ID);
403 return_ACPI_STATUS(status);
406 ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state_prep)
408 /*******************************************************************************
410 * FUNCTION: acpi_leave_sleep_state
412 * PARAMETERS: sleep_state - Which sleep state we are exiting
414 * RETURN: Status
416 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
417 * Called with interrupts ENABLED.
419 ******************************************************************************/
420 acpi_status acpi_leave_sleep_state(u8 sleep_state)
422 acpi_status status;
424 ACPI_FUNCTION_TRACE(acpi_leave_sleep_state);
427 status = acpi_hw_sleep_dispatch(sleep_state, 0, ACPI_WAKE_FUNCTION_ID);
428 return_ACPI_STATUS(status);
431 ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state)