1
2
3
4
5
6
7
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
20
21
22
23
24
25
26
27
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
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
57
58
59
60
61
62
63
64
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
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
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
95
96
97
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
106
107 ACPI_FLUSH_CPU_CACHE();
108
109 status = acpi_os_enter_sleep(sleep_state, sleep_control, 0);
110 if (status == AE_CTRL_TERMINATE) {
111 return_ACPI_STATUS(AE_OK);
112 }
113 if (ACPI_FAILURE(status)) {
114 return_ACPI_STATUS(status);
115 }
116
117 status = acpi_write((u64)sleep_control, &acpi_gbl_FADT.sleep_control);
118 if (ACPI_FAILURE(status)) {
119 return_ACPI_STATUS(status);
120 }
121
122
123
124 do {
125 status = acpi_read(&sleep_status, &acpi_gbl_FADT.sleep_status);
126 if (ACPI_FAILURE(status)) {
127 return_ACPI_STATUS(status);
128 }
129
130 } while (!(((u8)sleep_status) & ACPI_X_WAKE_STATUS));
131
132 return_ACPI_STATUS(AE_OK);
133}
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148acpi_status acpi_hw_extended_wake_prep(u8 sleep_state)
149{
150 acpi_status status;
151 u8 sleep_type_value;
152
153 ACPI_FUNCTION_TRACE(hw_extended_wake_prep);
154
155 status = acpi_get_sleep_type_data(ACPI_STATE_S0,
156 &acpi_gbl_sleep_type_a,
157 &acpi_gbl_sleep_type_b);
158 if (ACPI_SUCCESS(status)) {
159 sleep_type_value =
160 ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
161 ACPI_X_SLEEP_TYPE_MASK);
162
163 (void)acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE),
164 &acpi_gbl_FADT.sleep_control);
165 }
166
167 return_ACPI_STATUS(AE_OK);
168}
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183acpi_status acpi_hw_extended_wake(u8 sleep_state)
184{
185 ACPI_FUNCTION_TRACE(hw_extended_wake);
186
187
188
189 acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
190
191
192
193 acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WAKING);
194 acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK, sleep_state);
195
196
197
198
199
200
201 (void)acpi_write((u64)ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
202 acpi_gbl_system_awake_and_running = TRUE;
203
204 acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING);
205 return_ACPI_STATUS(AE_OK);
206}
207