Linux Audio

Check our new training course

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