]>
Commit | Line | Data |
---|---|---|
f70b071e LE |
1 | /** @file\r |
2 | S3 support for QEMU fw_cfg\r | |
3 | \r | |
4 | This library class enables driver modules (a) to query whether S3 support was\r | |
5 | enabled on the QEMU command line, (b) to produce fw_cfg DMA operations that\r | |
6 | are to be replayed at S3 resume time.\r | |
7 | \r | |
8 | Copyright (C) 2017, Red Hat, Inc.\r | |
9 | \r | |
b26f0cf9 | 10 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
f70b071e LE |
11 | **/\r |
12 | \r | |
13 | #ifndef __FW_CFG_S3_LIB__\r | |
14 | #define __FW_CFG_S3_LIB__\r | |
15 | \r | |
06a265b9 LE |
16 | #include <Base.h>\r |
17 | \r | |
f70b071e LE |
18 | /**\r |
19 | Determine if S3 support is explicitly enabled.\r | |
20 | \r | |
21 | @retval TRUE If S3 support is explicitly enabled. Other functions in this\r | |
22 | library may be called (subject to their individual\r | |
23 | restrictions).\r | |
24 | \r | |
25 | FALSE Otherwise. This includes unavailability of the firmware\r | |
26 | configuration interface. No other function in this library\r | |
27 | must be called.\r | |
28 | **/\r | |
29 | BOOLEAN\r | |
30 | EFIAPI\r | |
31 | QemuFwCfgS3Enabled (\r | |
32 | VOID\r | |
33 | );\r | |
34 | \r | |
06a265b9 LE |
35 | \r |
36 | /**\r | |
37 | Prototype for the callback function that the client module provides.\r | |
38 | \r | |
39 | In the callback function, the client module calls the\r | |
40 | QemuFwCfgS3ScriptWriteBytes(), QemuFwCfgS3ScriptReadBytes(),\r | |
41 | QemuFwCfgS3ScriptSkipBytes(), and QemuFwCfgS3ScriptCheckValue() functions.\r | |
42 | Those functions produce ACPI S3 Boot Script opcodes that will perform fw_cfg\r | |
43 | DMA operations, and will check any desired values that were read, during S3\r | |
44 | resume.\r | |
45 | \r | |
46 | The callback function is invoked when the production of ACPI S3 Boot Script\r | |
47 | opcodes becomes possible. This may occur directly on the call stack of\r | |
48 | QemuFwCfgS3CallWhenBootScriptReady() (see below), or after\r | |
49 | QemuFwCfgS3CallWhenBootScriptReady() has successfully returned.\r | |
50 | \r | |
51 | The callback function must not return if it fails -- in the general case,\r | |
52 | there is noone to propagate any errors to. Therefore, on error, an error\r | |
53 | message should be logged, and CpuDeadLoop() must be called.\r | |
54 | \r | |
55 | @param[in,out] Context Carries information from the client module\r | |
56 | itself (i.e., from the invocation of\r | |
57 | QemuFwCfgS3CallWhenBootScriptReady()) to the\r | |
58 | callback function.\r | |
59 | \r | |
60 | If Context points to dynamically allocated\r | |
61 | storage, then the callback function must\r | |
62 | release it.\r | |
63 | \r | |
64 | @param[in,out] ScratchBuffer Points to reserved memory, allocated by\r | |
65 | QemuFwCfgS3CallWhenBootScriptReady()\r | |
66 | internally.\r | |
67 | \r | |
68 | ScratchBuffer is typed and sized by the client\r | |
69 | module when it calls\r | |
70 | QemuFwCfgS3CallWhenBootScriptReady(). The\r | |
71 | client module defines a union type of\r | |
72 | structures for ScratchBuffer such that the\r | |
73 | union can hold client data for any desired\r | |
74 | fw_cfg DMA read and write operations, and value\r | |
75 | checking.\r | |
76 | \r | |
77 | The callback function casts ScratchBuffer to\r | |
78 | the union type described above. It passes union\r | |
79 | member sizes as NumberOfBytes to\r | |
80 | QemuFwCfgS3ScriptReadBytes() and\r | |
81 | QemuFwCfgS3ScriptWriteBytes(). It passes field\r | |
82 | addresses and sizes in structures in the union\r | |
83 | as ScratchData and ValueSize to\r | |
84 | QemuFwCfgS3ScriptCheckValue().\r | |
85 | \r | |
86 | ScratchBuffer is aligned at 8 bytes.\r | |
87 | **/\r | |
88 | typedef\r | |
89 | VOID (EFIAPI FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION) (\r | |
90 | IN OUT VOID *Context, OPTIONAL\r | |
91 | IN OUT VOID *ScratchBuffer\r | |
92 | );\r | |
93 | \r | |
94 | \r | |
95 | /**\r | |
96 | Install the client module's FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION callback for\r | |
97 | when the production of ACPI S3 Boot Script opcodes becomes possible.\r | |
98 | \r | |
99 | Take ownership of the client-provided Context, and pass it to the callback\r | |
100 | function, when the latter is invoked.\r | |
101 | \r | |
102 | Allocate scratch space for those ACPI S3 Boot Script opcodes to work upon\r | |
103 | that the client will produce in the callback function.\r | |
104 | \r | |
105 | @param[in] Callback FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION to invoke\r | |
106 | when the production of ACPI S3 Boot Script\r | |
107 | opcodes becomes possible. Callback() may be\r | |
108 | called immediately from\r | |
109 | QemuFwCfgS3CallWhenBootScriptReady().\r | |
110 | \r | |
111 | @param[in,out] Context Client-provided data structure for the\r | |
112 | Callback() callback function to consume.\r | |
113 | \r | |
114 | If Context points to dynamically allocated\r | |
115 | memory, then Callback() must release it.\r | |
116 | \r | |
117 | If Context points to dynamically allocated\r | |
118 | memory, and\r | |
119 | QemuFwCfgS3CallWhenBootScriptReady() returns\r | |
120 | successfully, then the caller of\r | |
121 | QemuFwCfgS3CallWhenBootScriptReady() must\r | |
122 | neither dereference nor even evaluate Context\r | |
123 | any longer, as ownership of the referenced area\r | |
124 | has been transferred to Callback().\r | |
125 | \r | |
126 | @param[in] ScratchBufferSize The size of the scratch buffer that will hold,\r | |
127 | in reserved memory, all client data read,\r | |
128 | written, and checked by the ACPI S3 Boot Script\r | |
129 | opcodes produced by Callback().\r | |
130 | \r | |
131 | @retval RETURN_UNSUPPORTED The library instance does not support this\r | |
132 | function.\r | |
133 | \r | |
134 | @retval RETURN_NOT_FOUND The fw_cfg DMA interface to QEMU is\r | |
135 | unavailable.\r | |
136 | \r | |
137 | @retval RETURN_BAD_BUFFER_SIZE ScratchBufferSize is too large.\r | |
138 | \r | |
139 | @retval RETURN_OUT_OF_RESOURCES Memory allocation failed.\r | |
140 | \r | |
141 | @retval RETURN_SUCCESS Callback() has been installed, and the\r | |
142 | ownership of Context has been transferred.\r | |
143 | Reserved memory has been allocated for the\r | |
144 | scratch buffer.\r | |
145 | \r | |
146 | A successful invocation of\r | |
147 | QemuFwCfgS3CallWhenBootScriptReady() cannot\r | |
148 | be rolled back.\r | |
149 | \r | |
150 | @return Error codes from underlying functions.\r | |
151 | **/\r | |
06a265b9 | 152 | RETURN_STATUS\r |
08bed3fb | 153 | EFIAPI\r |
06a265b9 LE |
154 | QemuFwCfgS3CallWhenBootScriptReady (\r |
155 | IN FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION *Callback,\r | |
156 | IN OUT VOID *Context, OPTIONAL\r | |
157 | IN UINTN ScratchBufferSize\r | |
158 | );\r | |
159 | \r | |
160 | \r | |
161 | /**\r | |
162 | Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg item,\r | |
163 | and transfer data to it.\r | |
164 | \r | |
165 | The opcodes produced by QemuFwCfgS3ScriptWriteBytes() will first restore\r | |
166 | NumberOfBytes bytes in ScratchBuffer in-place, in reserved memory, then write\r | |
167 | them to fw_cfg using DMA.\r | |
168 | \r | |
169 | If the operation fails during S3 resume, the boot script will hang.\r | |
170 | \r | |
171 | This function may only be called from the client module's\r | |
172 | FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION, which was passed to\r | |
173 | QemuFwCfgS3CallWhenBootScriptReady() as Callback.\r | |
174 | \r | |
175 | @param[in] FirmwareConfigItem The UINT16 selector key of the firmware config\r | |
176 | item to write, expressed as INT32. If\r | |
177 | FirmwareConfigItem is -1, no selection is\r | |
178 | made, the write will occur to the currently\r | |
179 | selected item, at its currently selected\r | |
180 | offset. Otherwise, the specified item will be\r | |
181 | selected, and the write will occur at offset\r | |
182 | 0.\r | |
183 | \r | |
184 | @param[in] NumberOfBytes Size of the data to restore in ScratchBuffer,\r | |
185 | and to write from ScratchBuffer, during S3\r | |
186 | resume. NumberOfBytes must not exceed\r | |
187 | ScratchBufferSize, which was passed to\r | |
188 | QemuFwCfgS3CallWhenBootScriptReady().\r | |
189 | \r | |
190 | @retval RETURN_SUCCESS The opcodes were appended to the ACPI S3\r | |
191 | Boot Script successfully. There is no way\r | |
192 | to undo this action.\r | |
193 | \r | |
194 | @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid.\r | |
195 | \r | |
196 | @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is larger than\r | |
197 | ScratchBufferSize.\r | |
198 | \r | |
199 | @return Error codes from underlying functions.\r | |
200 | **/\r | |
06a265b9 | 201 | RETURN_STATUS\r |
08bed3fb | 202 | EFIAPI\r |
06a265b9 LE |
203 | QemuFwCfgS3ScriptWriteBytes (\r |
204 | IN INT32 FirmwareConfigItem,\r | |
205 | IN UINTN NumberOfBytes\r | |
206 | );\r | |
207 | \r | |
208 | \r | |
209 | /**\r | |
210 | Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg item,\r | |
211 | and transfer data from it.\r | |
212 | \r | |
213 | The opcodes produced by QemuFwCfgS3ScriptReadBytes() will read NumberOfBytes\r | |
214 | bytes from fw_cfg using DMA, storing the result in ScratchBuffer, in reserved\r | |
215 | memory.\r | |
216 | \r | |
217 | If the operation fails during S3 resume, the boot script will hang.\r | |
218 | \r | |
219 | This function may only be called from the client module's\r | |
220 | FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION, which was passed to\r | |
221 | QemuFwCfgS3CallWhenBootScriptReady() as Callback.\r | |
222 | \r | |
223 | @param[in] FirmwareConfigItem The UINT16 selector key of the firmware config\r | |
224 | item to read, expressed as INT32. If\r | |
225 | FirmwareConfigItem is -1, no selection is\r | |
226 | made, the read will occur from the currently\r | |
227 | selected item, from its currently selected\r | |
228 | offset. Otherwise, the specified item will be\r | |
229 | selected, and the read will occur from offset\r | |
230 | 0.\r | |
231 | \r | |
232 | @param[in] NumberOfBytes Size of the data to read during S3 resume.\r | |
233 | NumberOfBytes must not exceed\r | |
234 | ScratchBufferSize, which was passed to\r | |
235 | QemuFwCfgS3CallWhenBootScriptReady().\r | |
236 | \r | |
237 | @retval RETURN_SUCCESS The opcodes were appended to the ACPI S3\r | |
238 | Boot Script successfully. There is no way\r | |
239 | to undo this action.\r | |
240 | \r | |
241 | @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid.\r | |
242 | \r | |
243 | @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is larger than\r | |
244 | ScratchBufferSize.\r | |
245 | \r | |
246 | @return Error codes from underlying functions.\r | |
247 | **/\r | |
06a265b9 | 248 | RETURN_STATUS\r |
08bed3fb | 249 | EFIAPI\r |
06a265b9 LE |
250 | QemuFwCfgS3ScriptReadBytes (\r |
251 | IN INT32 FirmwareConfigItem,\r | |
252 | IN UINTN NumberOfBytes\r | |
253 | );\r | |
254 | \r | |
255 | \r | |
256 | /**\r | |
257 | Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg item,\r | |
258 | and increase its offset.\r | |
259 | \r | |
260 | If the operation fails during S3 resume, the boot script will hang.\r | |
261 | \r | |
262 | This function may only be called from the client module's\r | |
263 | FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION, which was passed to\r | |
264 | QemuFwCfgS3CallWhenBootScriptReady() as Callback.\r | |
265 | \r | |
266 | @param[in] FirmwareConfigItem The UINT16 selector key of the firmware config\r | |
267 | item to advance the offset of, expressed as\r | |
268 | INT32. If FirmwareConfigItem is -1, no\r | |
269 | selection is made, and the offset for the\r | |
270 | currently selected item is increased.\r | |
271 | Otherwise, the specified item will be\r | |
272 | selected, and the offset increment will occur\r | |
273 | from offset 0.\r | |
274 | \r | |
275 | @param[in] NumberOfBytes The number of bytes to skip in the subject\r | |
276 | fw_cfg item.\r | |
277 | \r | |
278 | @retval RETURN_SUCCESS The opcodes were appended to the ACPI S3\r | |
279 | Boot Script successfully. There is no way\r | |
280 | to undo this action.\r | |
281 | \r | |
282 | @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid.\r | |
283 | \r | |
284 | @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is too large.\r | |
285 | \r | |
286 | @return Error codes from underlying functions.\r | |
287 | **/\r | |
06a265b9 | 288 | RETURN_STATUS\r |
08bed3fb | 289 | EFIAPI\r |
06a265b9 LE |
290 | QemuFwCfgS3ScriptSkipBytes (\r |
291 | IN INT32 FirmwareConfigItem,\r | |
292 | IN UINTN NumberOfBytes\r | |
293 | );\r | |
294 | \r | |
295 | \r | |
296 | /**\r | |
297 | Produce ACPI S3 Boot Script opcodes that check a value in ScratchBuffer.\r | |
298 | \r | |
299 | If the check fails during S3 resume, the boot script will hang.\r | |
300 | \r | |
301 | This function may only be called from the client module's\r | |
302 | FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION, which was passed to\r | |
303 | QemuFwCfgS3CallWhenBootScriptReady() as Callback.\r | |
304 | \r | |
305 | @param[in] ScratchData Pointer to the UINT8, UINT16, UINT32 or UINT64 field\r | |
306 | in ScratchBuffer that should be checked. The caller\r | |
307 | is responsible for populating the field during S3\r | |
308 | resume, by calling QemuFwCfgS3ScriptReadBytes() ahead\r | |
309 | of QemuFwCfgS3ScriptCheckValue().\r | |
310 | \r | |
311 | ScratchData must point into ScratchBuffer, which was\r | |
312 | allocated, and passed to Callback(), by\r | |
313 | QemuFwCfgS3CallWhenBootScriptReady().\r | |
314 | \r | |
315 | ScratchData must be aligned at ValueSize bytes.\r | |
316 | \r | |
317 | @param[in] ValueSize One of 1, 2, 4 or 8, specifying the size of the field\r | |
318 | to check.\r | |
319 | \r | |
320 | @param[in] ValueMask The value read from ScratchData is binarily AND-ed\r | |
321 | with ValueMask, and the result is compared against\r | |
322 | Value. If the masked data equals Value, the check\r | |
323 | passes, and the boot script can proceed. Otherwise,\r | |
324 | the check fails, and the boot script hangs.\r | |
325 | \r | |
326 | @param[in] Value Refer to ValueMask.\r | |
327 | \r | |
328 | @retval RETURN_SUCCESS The opcodes were appended to the ACPI S3\r | |
329 | Boot Script successfully. There is no way\r | |
330 | to undo this action.\r | |
331 | \r | |
332 | @retval RETURN_INVALID_PARAMETER ValueSize is invalid.\r | |
333 | \r | |
334 | @retval RETURN_INVALID_PARAMETER ValueMask or Value cannot be represented in\r | |
335 | ValueSize bytes.\r | |
336 | \r | |
337 | @retval RETURN_INVALID_PARAMETER ScratchData is not aligned at ValueSize\r | |
338 | bytes.\r | |
339 | \r | |
340 | @retval RETURN_BAD_BUFFER_SIZE The ValueSize bytes at ScratchData aren't\r | |
341 | wholly contained in the ScratchBufferSize\r | |
342 | bytes at ScratchBuffer.\r | |
343 | \r | |
344 | @return Error codes from underlying functions.\r | |
345 | **/\r | |
06a265b9 | 346 | RETURN_STATUS\r |
08bed3fb | 347 | EFIAPI\r |
06a265b9 LE |
348 | QemuFwCfgS3ScriptCheckValue (\r |
349 | IN VOID *ScratchData,\r | |
350 | IN UINT8 ValueSize,\r | |
351 | IN UINT64 ValueMask,\r | |
352 | IN UINT64 Value\r | |
353 | );\r | |
354 | \r | |
f70b071e | 355 | #endif\r |