1 /******************************************************************************
3 * Name: hwxfsleep.c - ACPI Hardware Sleep/Wake External Interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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 #define EXPORT_ACPI_INTERFACES
46 #include <acpi/acpi.h>
49 #define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME("hwxfsleep")
52 /* Local prototypes */
53 #if (!ACPI_REDUCED_HARDWARE)
55 acpi_hw_set_firmware_waking_vectors(struct acpi_table_facs
*facs
,
56 acpi_physical_address physical_address
,
57 acpi_physical_address physical_address64
);
60 static acpi_status
acpi_hw_sleep_dispatch(u8 sleep_state
, u32 function_id
);
63 * Dispatch table used to efficiently branch to the various sleep
66 #define ACPI_SLEEP_FUNCTION_ID 0
67 #define ACPI_WAKE_PREP_FUNCTION_ID 1
68 #define ACPI_WAKE_FUNCTION_ID 2
70 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
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
}
81 * These functions are removed for the ACPI_REDUCED_HARDWARE case:
82 * acpi_set_firmware_waking_vectors
83 * acpi_set_firmware_waking_vector
84 * acpi_set_firmware_waking_vector64
85 * acpi_enter_sleep_state_s4bios
88 #if (!ACPI_REDUCED_HARDWARE)
89 /*******************************************************************************
91 * FUNCTION: acpi_hw_set_firmware_waking_vectors
93 * PARAMETERS: facs - Pointer to FACS table
94 * physical_address - 32-bit physical address of ACPI real mode
96 * physical_address64 - 64-bit physical address of ACPI protected
101 * DESCRIPTION: Sets the firmware_waking_vector fields of the FACS
103 ******************************************************************************/
106 acpi_hw_set_firmware_waking_vectors(struct acpi_table_facs
*facs
,
107 acpi_physical_address physical_address
,
108 acpi_physical_address physical_address64
)
110 ACPI_FUNCTION_TRACE(acpi_hw_set_firmware_waking_vectors
);
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.
121 /* Set the 32-bit vector */
123 facs
->firmware_waking_vector
= (u32
)physical_address
;
125 if (facs
->length
> 32) {
126 if (facs
->version
>= 1) {
128 /* Set the 64-bit vector */
130 facs
->xfirmware_waking_vector
= physical_address64
;
132 /* Clear the 64-bit vector if it exists */
134 facs
->xfirmware_waking_vector
= 0;
138 return_ACPI_STATUS(AE_OK
);
141 /*******************************************************************************
143 * FUNCTION: acpi_set_firmware_waking_vectors
145 * PARAMETERS: physical_address - 32-bit physical address of ACPI real mode
147 * physical_address64 - 64-bit physical address of ACPI protected
152 * DESCRIPTION: Sets the firmware_waking_vector fields of the FACS
154 ******************************************************************************/
157 acpi_set_firmware_waking_vectors(acpi_physical_address physical_address
,
158 acpi_physical_address physical_address64
)
161 ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vectors
);
163 /* If Hardware Reduced flag is set, there is no FACS */
165 if (acpi_gbl_reduced_hardware
) {
166 return_ACPI_STATUS (AE_OK
);
169 if (acpi_gbl_facs32
) {
170 (void)acpi_hw_set_firmware_waking_vectors(acpi_gbl_facs32
,
174 if (acpi_gbl_facs64
) {
175 (void)acpi_hw_set_firmware_waking_vectors(acpi_gbl_facs64
,
180 return_ACPI_STATUS(AE_OK
);
183 ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vectors
)
185 /*******************************************************************************
187 * FUNCTION: acpi_set_firmware_waking_vector
189 * PARAMETERS: physical_address - 32-bit physical address of ACPI real mode
194 * DESCRIPTION: Sets the 32-bit firmware_waking_vector field of the FACS
196 ******************************************************************************/
197 acpi_status
acpi_set_firmware_waking_vector(u32 physical_address
)
201 ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector
);
203 status
= acpi_set_firmware_waking_vectors((acpi_physical_address
)
204 physical_address
, 0);
206 return_ACPI_STATUS(status
);
209 ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector
)
211 #if ACPI_MACHINE_WIDTH == 64
212 /*******************************************************************************
214 * FUNCTION: acpi_set_firmware_waking_vector64
216 * PARAMETERS: physical_address - 64-bit physical address of ACPI protected
221 * DESCRIPTION: Sets the 64-bit X_firmware_waking_vector field of the FACS, if
222 * it exists in the table. This function is intended for use with
223 * 64-bit host operating systems.
225 ******************************************************************************/
226 acpi_status
acpi_set_firmware_waking_vector64(u64 physical_address
)
230 ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector64
);
232 status
= acpi_set_firmware_waking_vectors(0,
233 (acpi_physical_address
)
236 return_ACPI_STATUS(status
);
239 ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector64
)
241 /*******************************************************************************
243 * FUNCTION: acpi_enter_sleep_state_s4bios
249 * DESCRIPTION: Perform a S4 bios request.
250 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
252 ******************************************************************************/
253 acpi_status
acpi_enter_sleep_state_s4bios(void)
258 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios
);
260 /* Clear the wake status bit (PM1) */
263 acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS
, ACPI_CLEAR_STATUS
);
264 if (ACPI_FAILURE(status
)) {
265 return_ACPI_STATUS(status
);
268 status
= acpi_hw_clear_acpi_status();
269 if (ACPI_FAILURE(status
)) {
270 return_ACPI_STATUS(status
);
274 * 1) Disable/Clear all GPEs
275 * 2) Enable all wakeup GPEs
277 status
= acpi_hw_disable_all_gpes();
278 if (ACPI_FAILURE(status
)) {
279 return_ACPI_STATUS(status
);
281 acpi_gbl_system_awake_and_running
= FALSE
;
283 status
= acpi_hw_enable_all_wakeup_gpes();
284 if (ACPI_FAILURE(status
)) {
285 return_ACPI_STATUS(status
);
288 ACPI_FLUSH_CPU_CACHE();
290 status
= acpi_hw_write_port(acpi_gbl_FADT
.smi_command
,
291 (u32
)acpi_gbl_FADT
.s4_bios_request
, 8);
294 acpi_os_stall(ACPI_USEC_PER_MSEC
);
296 acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS
, &in_value
);
297 if (ACPI_FAILURE(status
)) {
298 return_ACPI_STATUS(status
);
302 return_ACPI_STATUS(AE_OK
);
305 ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios
)
306 #endif /* !ACPI_REDUCED_HARDWARE */
307 /*******************************************************************************
309 * FUNCTION: acpi_hw_sleep_dispatch
311 * PARAMETERS: sleep_state - Which sleep state to enter/exit
312 * function_id - Sleep, wake_prep, or Wake
314 * RETURN: Status from the invoked sleep handling function.
316 * DESCRIPTION: Dispatch a sleep/wake request to the appropriate handling
319 ******************************************************************************/
320 static acpi_status
acpi_hw_sleep_dispatch(u8 sleep_state
, u32 function_id
)
323 struct acpi_sleep_functions
*sleep_functions
=
324 &acpi_sleep_dispatch
[function_id
];
326 #if (!ACPI_REDUCED_HARDWARE)
328 * If the Hardware Reduced flag is set (from the FADT), we must
329 * use the extended sleep registers (FADT). Note: As per the ACPI
330 * specification, these extended registers are to be used for HW-reduced
331 * platforms only. They are not general-purpose replacements for the
332 * legacy PM register sleep support.
334 if (acpi_gbl_reduced_hardware
) {
335 status
= sleep_functions
->extended_function(sleep_state
);
339 status
= sleep_functions
->legacy_function(sleep_state
);
346 * For the case where reduced-hardware-only code is being generated,
347 * we know that only the extended sleep registers are available
349 status
= sleep_functions
->extended_function(sleep_state
);
352 #endif /* !ACPI_REDUCED_HARDWARE */
355 /*******************************************************************************
357 * FUNCTION: acpi_enter_sleep_state_prep
359 * PARAMETERS: sleep_state - Which sleep state to enter
363 * DESCRIPTION: Prepare to enter a system sleep state.
364 * This function must execute with interrupts enabled.
365 * We break sleeping into 2 stages so that OSPM can handle
366 * various OS-specific tasks between the two steps.
368 ******************************************************************************/
370 acpi_status
acpi_enter_sleep_state_prep(u8 sleep_state
)
373 struct acpi_object_list arg_list
;
374 union acpi_object arg
;
377 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep
);
379 status
= acpi_get_sleep_type_data(sleep_state
,
380 &acpi_gbl_sleep_type_a
,
381 &acpi_gbl_sleep_type_b
);
382 if (ACPI_FAILURE(status
)) {
383 return_ACPI_STATUS(status
);
386 /* Execute the _PTS method (Prepare To Sleep) */
389 arg_list
.pointer
= &arg
;
390 arg
.type
= ACPI_TYPE_INTEGER
;
391 arg
.integer
.value
= sleep_state
;
394 acpi_evaluate_object(NULL
, METHOD_PATHNAME__PTS
, &arg_list
, NULL
);
395 if (ACPI_FAILURE(status
) && status
!= AE_NOT_FOUND
) {
396 return_ACPI_STATUS(status
);
399 /* Setup the argument to the _SST method (System STatus) */
401 switch (sleep_state
) {
404 sst_value
= ACPI_SST_WORKING
;
411 sst_value
= ACPI_SST_SLEEPING
;
416 sst_value
= ACPI_SST_SLEEP_CONTEXT
;
421 sst_value
= ACPI_SST_INDICATOR_OFF
; /* Default is off */
426 * Set the system indicators to show the desired sleep state.
427 * _SST is an optional method (return no error if not found)
429 acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST
, sst_value
);
430 return_ACPI_STATUS(AE_OK
);
433 ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep
)
435 /*******************************************************************************
437 * FUNCTION: acpi_enter_sleep_state
439 * PARAMETERS: sleep_state - Which sleep state to enter
443 * DESCRIPTION: Enter a system sleep state
444 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
446 ******************************************************************************/
447 acpi_status
acpi_enter_sleep_state(u8 sleep_state
)
451 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state
);
453 if ((acpi_gbl_sleep_type_a
> ACPI_SLEEP_TYPE_MAX
) ||
454 (acpi_gbl_sleep_type_b
> ACPI_SLEEP_TYPE_MAX
)) {
455 ACPI_ERROR((AE_INFO
, "Sleep values out of range: A=0x%X B=0x%X",
456 acpi_gbl_sleep_type_a
, acpi_gbl_sleep_type_b
));
457 return_ACPI_STATUS(AE_AML_OPERAND_VALUE
);
460 status
= acpi_hw_sleep_dispatch(sleep_state
, ACPI_SLEEP_FUNCTION_ID
);
461 return_ACPI_STATUS(status
);
464 ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state
)
466 /*******************************************************************************
468 * FUNCTION: acpi_leave_sleep_state_prep
470 * PARAMETERS: sleep_state - Which sleep state we are exiting
474 * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
475 * sleep. Called with interrupts DISABLED.
476 * We break wake/resume into 2 stages so that OSPM can handle
477 * various OS-specific tasks between the two steps.
479 ******************************************************************************/
480 acpi_status
acpi_leave_sleep_state_prep(u8 sleep_state
)
484 ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep
);
487 acpi_hw_sleep_dispatch(sleep_state
, ACPI_WAKE_PREP_FUNCTION_ID
);
488 return_ACPI_STATUS(status
);
491 ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state_prep
)
493 /*******************************************************************************
495 * FUNCTION: acpi_leave_sleep_state
497 * PARAMETERS: sleep_state - Which sleep state we are exiting
501 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
502 * Called with interrupts ENABLED.
504 ******************************************************************************/
505 acpi_status
acpi_leave_sleep_state(u8 sleep_state
)
509 ACPI_FUNCTION_TRACE(acpi_leave_sleep_state
);
511 status
= acpi_hw_sleep_dispatch(sleep_state
, ACPI_WAKE_FUNCTION_ID
);
512 return_ACPI_STATUS(status
);
515 ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state
)