]>
Commit | Line | Data |
---|---|---|
64d14edf | 1 | /** @file\r |
2 | Save the S3 data to S3 boot script. \r | |
3 | \r | |
ce68d3bc | 4 | Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r |
64d14edf | 5 | \r |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions\r | |
8 | of the BSD License which accompanies this distribution. The\r | |
9 | full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | #include "InternalBootScriptLib.h"\r | |
17 | \r | |
18 | /**\r | |
19 | \r | |
20 | Data structure usage:\r | |
21 | \r | |
22 | +------------------------------+<-- PcdS3BootScriptTablePrivateDataPtr\r | |
23 | | SCRIPT_TABLE_PRIVATE_DATA |\r | |
24 | | TableBase |---\r | |
25 | | TableLength |--|--\r | |
26 | | AtRuntime | | |\r | |
27 | | InSmm | | |\r | |
28 | +------------------------------+ | |\r | |
29 | | |\r | |
30 | +------------------------------+<-- |\r | |
31 | | EFI_BOOT_SCRIPT_TABLE_HEADER | |\r | |
32 | | TableLength |----|--\r | |
33 | +------------------------------+ | |\r | |
34 | | ...... | | |\r | |
35 | +------------------------------+<---- |\r | |
36 | | EFI_BOOT_SCRIPT_TERMINATE | |\r | |
37 | +------------------------------+<------\r | |
38 | \r | |
39 | **/\r | |
40 | \r | |
41 | SCRIPT_TABLE_PRIVATE_DATA *mS3BootScriptTablePtr;\r | |
42 | EFI_EVENT mEnterRuntimeEvent;\r | |
43 | //\r | |
44 | // Allocate local copy in SMM because we can not use mS3BootScriptTablePtr when we AtRuntime in InSmm.\r | |
45 | //\r | |
46 | SCRIPT_TABLE_PRIVATE_DATA mS3BootScriptTable;\r | |
47 | UINTN mLockBoxLength;\r | |
48 | \r | |
49 | EFI_GUID mBootScriptDataGuid = {\r | |
ce68d3bc | 50 | 0xaea6b965, 0xdcf5, 0x4311, { 0xb4, 0xb8, 0xf, 0x12, 0x46, 0x44, 0x94, 0xd2 }\r |
64d14edf | 51 | };\r |
52 | \r | |
53 | EFI_GUID mBootScriptHeaderDataGuid = {\r | |
ce68d3bc | 54 | 0x1810ab4a, 0x2314, 0x4df6, { 0x81, 0xeb, 0x67, 0xc6, 0xec, 0x5, 0x85, 0x91 }\r |
64d14edf | 55 | };\r |
56 | \r | |
f6ec0c77 | 57 | EFI_GUID mBootScriptInformationGuid = {\r |
ce68d3bc | 58 | 0x2c680508, 0x2b87, 0x46ab, { 0xb9, 0x8a, 0x49, 0xfc, 0x23, 0xf9, 0xf5, 0x95 }\r |
f6ec0c77 JY |
59 | };\r |
60 | \r | |
64d14edf | 61 | /**\r |
62 | This is an internal function to add a terminate node the entry, recalculate the table \r | |
63 | length and fill into the table. \r | |
64 | \r | |
65 | @return the base address of the boot script tble. \r | |
66 | **/\r | |
67 | UINT8*\r | |
68 | S3BootScriptInternalCloseTable (\r | |
69 | VOID\r | |
70 | )\r | |
71 | {\r | |
72 | UINT8 *S3TableBase;\r | |
73 | EFI_BOOT_SCRIPT_TERMINATE ScriptTerminate;\r | |
74 | EFI_BOOT_SCRIPT_TABLE_HEADER *ScriptTableInfo;\r | |
75 | S3TableBase = mS3BootScriptTablePtr->TableBase;\r | |
76 | \r | |
77 | if (S3TableBase == NULL) {\r | |
78 | //\r | |
79 | // the table is not exist\r | |
80 | //\r | |
81 | return S3TableBase;\r | |
82 | }\r | |
83 | //\r | |
84 | // Append the termination entry.\r | |
85 | //\r | |
86 | ScriptTerminate.OpCode = S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE;\r | |
87 | ScriptTerminate.Length = (UINT8) sizeof (EFI_BOOT_SCRIPT_TERMINATE);\r | |
88 | CopyMem (mS3BootScriptTablePtr->TableBase + mS3BootScriptTablePtr->TableLength, &ScriptTerminate, sizeof (EFI_BOOT_SCRIPT_TERMINATE));\r | |
89 | //\r | |
90 | // fill the table length\r | |
91 | //\r | |
92 | ScriptTableInfo = (EFI_BOOT_SCRIPT_TABLE_HEADER*)(mS3BootScriptTablePtr->TableBase);\r | |
93 | ScriptTableInfo->TableLength = mS3BootScriptTablePtr->TableLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE);\r | |
94 | \r | |
95 | \r | |
96 | \r | |
97 | return S3TableBase;\r | |
98 | //\r | |
99 | // NOTE: Here we did NOT adjust the mS3BootScriptTablePtr->TableLength to \r | |
100 | // mS3BootScriptTablePtr->TableLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE). Because \r | |
101 | // maybe in runtime, we still need add entries into the table, and the runtime entry should be\r | |
102 | // added start before this TERMINATE node.\r | |
103 | //\r | |
104 | } \r | |
105 | \r | |
f6ec0c77 JY |
106 | /**\r |
107 | This function return the total size of INFORMATION OPCODE in boot script table.\r | |
108 | \r | |
109 | @return InformationBufferSize The total size of INFORMATION OPCODE in boot script table.\r | |
110 | **/\r | |
111 | UINTN\r | |
112 | GetBootScriptInformationBufferSize (\r | |
113 | VOID\r | |
114 | )\r | |
115 | {\r | |
116 | UINT8 *S3TableBase;\r | |
117 | UINT8 *Script;\r | |
118 | UINTN TableLength;\r | |
119 | EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader;\r | |
120 | EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader;\r | |
121 | EFI_BOOT_SCRIPT_INFORMATION Information;\r | |
122 | UINTN InformationBufferSize;\r | |
123 | \r | |
124 | InformationBufferSize = 0;\r | |
125 | \r | |
126 | S3TableBase = mS3BootScriptTablePtr->TableBase;\r | |
127 | Script = S3TableBase;\r | |
128 | CopyMem ((VOID*)&TableHeader, Script, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER));\r | |
129 | TableLength = TableHeader.TableLength;\r | |
130 | \r | |
131 | //\r | |
132 | // Go through the ScriptTable\r | |
133 | //\r | |
134 | while ((UINTN) Script < (UINTN) (S3TableBase + TableLength)) {\r | |
135 | CopyMem ((VOID*)&ScriptHeader, Script, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER));\r | |
136 | switch (ScriptHeader.OpCode) {\r | |
137 | case EFI_BOOT_SCRIPT_INFORMATION_OPCODE:\r | |
138 | CopyMem ((VOID*)&Information, (VOID*)Script, sizeof(Information));\r | |
139 | InformationBufferSize += Information.InformationLength;\r | |
140 | break;\r | |
141 | default:\r | |
142 | break;\r | |
143 | }\r | |
144 | Script = Script + ScriptHeader.Length;\r | |
145 | }\r | |
146 | \r | |
147 | return InformationBufferSize;\r | |
148 | }\r | |
149 | \r | |
150 | /**\r | |
151 | This function fix INFORMATION OPCODE in boot script table.\r | |
152 | Originally, the Information buffer is pointer to EfiRuntimeServicesCode,\r | |
153 | EfiRuntimeServicesData, or EfiACPIMemoryNVS. They are seperated.\r | |
154 | Now, in order to save it to LockBox, we allocate a big EfiACPIMemoryNVS,\r | |
155 | and fix the pointer for INFORMATION opcode InformationBuffer.\r | |
156 | \r | |
157 | @param InformationBuffer The address of new Information buffer.\r | |
158 | @param InformationBufferSize The size of new Information buffer.\r | |
159 | **/\r | |
160 | VOID\r | |
161 | FixBootScriptInformation (\r | |
162 | IN VOID *InformationBuffer,\r | |
163 | IN UINTN InformationBufferSize\r | |
164 | )\r | |
165 | {\r | |
166 | UINT8 *S3TableBase;\r | |
167 | UINT8 *Script;\r | |
168 | UINTN TableLength;\r | |
169 | EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader;\r | |
170 | EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader;\r | |
171 | EFI_BOOT_SCRIPT_INFORMATION Information;\r | |
172 | UINTN FixedInformationBufferSize;\r | |
173 | \r | |
174 | FixedInformationBufferSize = 0;\r | |
175 | \r | |
176 | S3TableBase = mS3BootScriptTablePtr->TableBase;\r | |
177 | Script = S3TableBase;\r | |
178 | CopyMem ((VOID*)&TableHeader, Script, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER));\r | |
179 | TableLength = TableHeader.TableLength;\r | |
180 | \r | |
181 | //\r | |
182 | // Go through the ScriptTable\r | |
183 | //\r | |
184 | while ((UINTN) Script < (UINTN) (S3TableBase + TableLength)) {\r | |
185 | CopyMem ((VOID*)&ScriptHeader, Script, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER));\r | |
186 | switch (ScriptHeader.OpCode) {\r | |
187 | case EFI_BOOT_SCRIPT_INFORMATION_OPCODE:\r | |
188 | CopyMem ((VOID*)&Information, (VOID*)Script, sizeof(Information));\r | |
189 | \r | |
190 | CopyMem (\r | |
191 | (VOID *)((UINTN)InformationBuffer + FixedInformationBufferSize),\r | |
192 | (VOID *)(UINTN)Information.Information,\r | |
193 | Information.InformationLength\r | |
194 | );\r | |
195 | gBS->FreePool ((VOID *)(UINTN)Information.Information);\r | |
196 | Information.Information = (EFI_PHYSICAL_ADDRESS)((UINTN)InformationBuffer + FixedInformationBufferSize);\r | |
197 | \r | |
198 | CopyMem ((VOID*)Script, (VOID*)&Information, sizeof(Information));\r | |
199 | \r | |
200 | FixedInformationBufferSize += Information.InformationLength;\r | |
201 | break;\r | |
202 | default:\r | |
203 | break;\r | |
204 | }\r | |
205 | Script = Script + ScriptHeader.Length;\r | |
206 | }\r | |
207 | \r | |
208 | ASSERT (FixedInformationBufferSize == InformationBufferSize);\r | |
209 | \r | |
210 | return ;\r | |
211 | }\r | |
212 | \r | |
64d14edf | 213 | /**\r |
214 | This function save boot script data to LockBox.\r | |
215 | 1. BootSriptPrivate data, BootScript data - Image and DispatchContext are handled by platform.\r | |
216 | 2. BootScriptExecutor, BootScriptExecutor context\r | |
217 | - ACPI variable - (PI version) sould be handled by SMM driver. S3 Page table is handled here.\r | |
218 | - ACPI variable - framework version is already handled by Framework CPU driver.\r | |
219 | **/\r | |
220 | VOID\r | |
221 | SaveBootScriptDataToLockBox (\r | |
222 | VOID\r | |
223 | )\r | |
224 | {\r | |
f6ec0c77 JY |
225 | EFI_STATUS Status;\r |
226 | EFI_PHYSICAL_ADDRESS InformationBuffer;\r | |
227 | UINTN InformationBufferSize;\r | |
228 | \r | |
229 | //\r | |
230 | // We need save BootScriptInformation to LockBox, because it is in\r | |
231 | // EfiRuntimeServicesCode, EfiRuntimeServicesData, or EfiACPIMemoryNVS.\r | |
232 | // \r | |
233 | //\r | |
234 | InformationBufferSize = GetBootScriptInformationBufferSize ();\r | |
235 | if (InformationBufferSize != 0) {\r | |
236 | InformationBuffer = 0xFFFFFFFF;\r | |
237 | Status = gBS->AllocatePages (\r | |
238 | AllocateMaxAddress,\r | |
239 | EfiACPIMemoryNVS,\r | |
240 | EFI_SIZE_TO_PAGES(InformationBufferSize),\r | |
241 | &InformationBuffer\r | |
242 | );\r | |
243 | ASSERT_EFI_ERROR (Status);\r | |
244 | \r | |
245 | //\r | |
246 | // Fix BootScript information pointer\r | |
247 | //\r | |
248 | FixBootScriptInformation ((VOID *)(UINTN)InformationBuffer, InformationBufferSize);\r | |
249 | \r | |
250 | //\r | |
251 | // Save BootScript information to lockbox\r | |
252 | //\r | |
253 | Status = SaveLockBox (\r | |
254 | &mBootScriptInformationGuid,\r | |
255 | (VOID *)(UINTN)InformationBuffer,\r | |
256 | InformationBufferSize\r | |
257 | );\r | |
258 | ASSERT_EFI_ERROR (Status);\r | |
259 | \r | |
260 | Status = SetLockBoxAttributes (&mBootScriptInformationGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE);\r | |
261 | ASSERT_EFI_ERROR (Status);\r | |
262 | }\r | |
263 | \r | |
64d14edf | 264 | //\r |
265 | // mS3BootScriptTablePtr->TableLength does not include EFI_BOOT_SCRIPT_TERMINATE, because we need add entry at runtime.\r | |
266 | // Save all info here, just in case that no one will add boot script entry in SMM.\r | |
267 | //\r | |
268 | Status = SaveLockBox (\r | |
269 | &mBootScriptDataGuid,\r | |
270 | (VOID *)mS3BootScriptTablePtr->TableBase,\r | |
271 | mS3BootScriptTablePtr->TableLength + sizeof(EFI_BOOT_SCRIPT_TERMINATE)\r | |
272 | );\r | |
273 | ASSERT_EFI_ERROR (Status);\r | |
274 | \r | |
275 | Status = SetLockBoxAttributes (&mBootScriptDataGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE);\r | |
276 | ASSERT_EFI_ERROR (Status);\r | |
277 | \r | |
278 | //\r | |
279 | // Just need save TableBase.\r | |
280 | // Do not update other field because they will NOT be used in S3.\r | |
281 | //\r | |
282 | Status = SaveLockBox (\r | |
283 | &mBootScriptHeaderDataGuid,\r | |
284 | (VOID *)&mS3BootScriptTablePtr->TableBase,\r | |
285 | sizeof(mS3BootScriptTablePtr->TableBase)\r | |
286 | );\r | |
287 | ASSERT_EFI_ERROR (Status);\r | |
288 | \r | |
289 | Status = SetLockBoxAttributes (&mBootScriptHeaderDataGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE);\r | |
290 | ASSERT_EFI_ERROR (Status);\r | |
291 | }\r | |
292 | \r | |
293 | /**\r | |
294 | This is the Event call back function to notify the Library the system is entering\r | |
295 | run time phase.\r | |
296 | \r | |
297 | @param Event Pointer to this event\r | |
298 | @param Context Event hanlder private data \r | |
299 | **/\r | |
300 | VOID\r | |
301 | EFIAPI\r | |
302 | S3BootScriptEventCallBack (\r | |
303 | IN EFI_EVENT Event,\r | |
304 | IN VOID *Context\r | |
305 | )\r | |
306 | {\r | |
307 | EFI_STATUS Status;\r | |
308 | VOID *Interface;\r | |
309 | \r | |
310 | //\r | |
311 | // Try to locate it because EfiCreateProtocolNotifyEvent will trigger it once when registration.\r | |
312 | // Just return if it is not found.\r | |
313 | //\r | |
314 | Status = gBS->LocateProtocol (\r | |
315 | &gEfiDxeSmmReadyToLockProtocolGuid,\r | |
316 | NULL,\r | |
317 | &Interface\r | |
318 | );\r | |
319 | if (EFI_ERROR (Status)) {\r | |
320 | return ;\r | |
321 | }\r | |
322 | \r | |
323 | //\r | |
324 | // Here we should tell the library that we are enter into runtime phase. and \r | |
325 | // the memory page number occupied by the table should not grow anymore.\r | |
326 | //\r | |
327 | if (!mS3BootScriptTablePtr->AtRuntime) {\r | |
328 | //\r | |
329 | // In boot time, we need not write the terminate node when adding a node to boot scipt table\r | |
330 | // or else, that will impact the performance. However, in runtime, we should append terminate\r | |
331 | // node on every add to boot script table\r | |
332 | //\r | |
333 | S3BootScriptInternalCloseTable ();\r | |
334 | mS3BootScriptTablePtr->AtRuntime = TRUE;\r | |
335 | \r | |
336 | //\r | |
337 | // Save BootScript data to lockbox\r | |
338 | //\r | |
339 | SaveBootScriptDataToLockBox ();\r | |
340 | }\r | |
341 | } \r | |
342 | /**\r | |
343 | This is the Event call back function is triggered in SMM to notify the Library the system is entering\r | |
344 | run time phase and set InSmm flag.\r | |
345 | \r | |
346 | @param Protocol Points to the protocol's unique identifier\r | |
347 | @param Interface Points to the interface instance\r | |
348 | @param Handle The handle on which the interface was installed\r | |
349 | \r | |
350 | @retval EFI_SUCCESS SmmEventCallback runs successfully\r | |
351 | **/\r | |
352 | EFI_STATUS\r | |
353 | EFIAPI\r | |
354 | S3BootScriptSmmEventCallBack (\r | |
355 | IN CONST EFI_GUID *Protocol,\r | |
356 | IN VOID *Interface,\r | |
357 | IN EFI_HANDLE Handle\r | |
358 | )\r | |
359 | {\r | |
360 | //\r | |
361 | // Check if it is already done\r | |
362 | //\r | |
363 | if (mS3BootScriptTablePtr == &mS3BootScriptTable) {\r | |
364 | return EFI_SUCCESS;\r | |
365 | }\r | |
366 | \r | |
367 | //\r | |
368 | // Last chance to call-out, just make sure AtRuntime is set\r | |
369 | //\r | |
370 | S3BootScriptEventCallBack (NULL, NULL);\r | |
371 | \r | |
372 | //\r | |
373 | // Save a local copy\r | |
374 | //\r | |
375 | CopyMem (&mS3BootScriptTable, mS3BootScriptTablePtr, sizeof(*mS3BootScriptTablePtr));\r | |
376 | //\r | |
377 | // We should not use ACPINvs copy, because it is not safe.\r | |
378 | //\r | |
379 | mS3BootScriptTablePtr = &mS3BootScriptTable;\r | |
380 | \r | |
381 | //\r | |
382 | // Set InSmm, we allow boot script update when InSmm, but not allow boot script outside SMM.\r | |
383 | // InSmm will only be checked if AtRuntime is TRUE.\r | |
384 | //\r | |
385 | mS3BootScriptTablePtr->InSmm = TRUE;\r | |
386 | \r | |
387 | //\r | |
388 | // Record LockBoxLength\r | |
389 | //\r | |
390 | mLockBoxLength = mS3BootScriptTable.TableLength + sizeof(EFI_BOOT_SCRIPT_TERMINATE);\r | |
391 | \r | |
392 | return EFI_SUCCESS;\r | |
393 | }\r | |
394 | \r | |
395 | /**\r | |
396 | Library Constructor.\r | |
397 | this function just identify it is a smm driver or non-smm driver linked against \r | |
398 | with the library \r | |
399 | \r | |
400 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
401 | @param SystemTable A pointer to the EFI System Table.\r | |
402 | \r | |
403 | @retval RETURN_SUCCESS Allocate the global memory space to store S3 boot script table private data\r | |
404 | @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.\r | |
405 | **/\r | |
406 | RETURN_STATUS\r | |
407 | EFIAPI\r | |
408 | S3BootScriptLibInitialize (\r | |
409 | IN EFI_HANDLE ImageHandle,\r | |
410 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
411 | )\r | |
412 | {\r | |
413 | EFI_STATUS Status;\r | |
414 | SCRIPT_TABLE_PRIVATE_DATA *S3TablePtr;\r | |
415 | VOID *Registration;\r | |
416 | EFI_SMM_BASE2_PROTOCOL *SmmBase2;\r | |
417 | BOOLEAN InSmm;\r | |
418 | EFI_SMM_SYSTEM_TABLE2 *Smst;\r | |
419 | EFI_PHYSICAL_ADDRESS Buffer;\r | |
420 | \r | |
421 | S3TablePtr = (SCRIPT_TABLE_PRIVATE_DATA*)(UINTN)PcdGet64(PcdS3BootScriptTablePrivateDataPtr);\r | |
422 | //\r | |
423 | // The Boot script private data is not be initialized. create it\r | |
424 | //\r | |
425 | if (S3TablePtr == 0) {\r | |
426 | Buffer = SIZE_4GB - 1;\r | |
427 | Status = gBS->AllocatePages (\r | |
428 | AllocateMaxAddress,\r | |
429 | EfiACPIMemoryNVS,\r | |
430 | EFI_SIZE_TO_PAGES(sizeof(SCRIPT_TABLE_PRIVATE_DATA)),\r | |
431 | &Buffer\r | |
432 | );\r | |
433 | if (EFI_ERROR (Status)) {\r | |
434 | return RETURN_OUT_OF_RESOURCES;\r | |
435 | }\r | |
436 | S3TablePtr = (VOID *) (UINTN) Buffer;\r | |
437 | \r | |
438 | PcdSet64 (PcdS3BootScriptTablePrivateDataPtr, (UINT64) (UINTN)S3TablePtr); \r | |
439 | ZeroMem (S3TablePtr, sizeof(SCRIPT_TABLE_PRIVATE_DATA)); \r | |
440 | //\r | |
441 | // create event to notify the library system enter the runtime phase\r | |
442 | //\r | |
443 | mEnterRuntimeEvent = EfiCreateProtocolNotifyEvent (\r | |
444 | &gEfiDxeSmmReadyToLockProtocolGuid,\r | |
445 | TPL_CALLBACK,\r | |
446 | S3BootScriptEventCallBack,\r | |
447 | NULL,\r | |
448 | &Registration\r | |
449 | );\r | |
450 | ASSERT (mEnterRuntimeEvent != NULL);\r | |
451 | } \r | |
452 | mS3BootScriptTablePtr = S3TablePtr;\r | |
453 | \r | |
454 | //\r | |
455 | // Get InSmm, we need to register SmmReadyToLock if this library is linked to SMM driver.\r | |
456 | //\r | |
457 | Status = gBS->LocateProtocol (&gEfiSmmBase2ProtocolGuid, NULL, (VOID**) &SmmBase2);\r | |
458 | if (EFI_ERROR (Status)) {\r | |
459 | return RETURN_SUCCESS;\r | |
460 | }\r | |
461 | Status = SmmBase2->InSmm (SmmBase2, &InSmm);\r | |
462 | if (EFI_ERROR (Status)) {\r | |
463 | return RETURN_SUCCESS;\r | |
464 | }\r | |
465 | if (!InSmm) {\r | |
466 | return RETURN_SUCCESS;\r | |
467 | }\r | |
468 | //\r | |
469 | // Good, we are in SMM\r | |
470 | //\r | |
471 | Status = SmmBase2->GetSmstLocation (SmmBase2, &Smst);\r | |
472 | if (EFI_ERROR (Status)) {\r | |
473 | return RETURN_SUCCESS;\r | |
474 | }\r | |
475 | \r | |
476 | //\r | |
477 | // Then register event after lock\r | |
478 | //\r | |
479 | Registration = NULL;\r | |
480 | Status = Smst->SmmRegisterProtocolNotify (\r | |
481 | &gEfiSmmReadyToLockProtocolGuid,\r | |
482 | S3BootScriptSmmEventCallBack,\r | |
483 | &Registration\r | |
484 | );\r | |
485 | ASSERT_EFI_ERROR (Status);\r | |
486 | \r | |
487 | return RETURN_SUCCESS;\r | |
488 | }\r | |
489 | /**\r | |
490 | To get the start address from which a new boot time s3 boot script entry will write into.\r | |
491 | If the table is not exist, the functio will first allocate a buffer for the table\r | |
492 | If the table buffer is not enough for the new entry, in non-smm mode, the funtion will \r | |
493 | invoke reallocate to enlarge buffer.\r | |
494 | \r | |
495 | @param EntryLength the new entry length.\r | |
496 | \r | |
497 | @retval the address from which the a new s3 boot script entry will write into \r | |
498 | **/\r | |
499 | UINT8*\r | |
500 | S3BootScriptGetBootTimeEntryAddAddress (\r | |
501 | UINT8 EntryLength\r | |
502 | )\r | |
503 | {\r | |
504 | EFI_PHYSICAL_ADDRESS S3TableBase;\r | |
505 | EFI_PHYSICAL_ADDRESS NewS3TableBase;\r | |
506 | UINT8 *NewEntryPtr;\r | |
507 | UINT32 TableLength;\r | |
508 | UINT16 PageNumber;\r | |
509 | EFI_STATUS Status;\r | |
510 | EFI_BOOT_SCRIPT_TABLE_HEADER *ScriptTableInfo;\r | |
511 | \r | |
512 | S3TableBase = (EFI_PHYSICAL_ADDRESS)(UINTN)(mS3BootScriptTablePtr->TableBase);\r | |
513 | if (S3TableBase == 0) {\r | |
514 | // The table is not exist. This is the first to add entry. \r | |
515 | // Allocate ACPI script table space under 4G memory. We need it to save\r | |
516 | // some settings done by CSM, which runs after normal script table closed\r | |
517 | //\r | |
518 | S3TableBase = 0xffffffff;\r | |
519 | Status = gBS->AllocatePages (\r | |
520 | AllocateMaxAddress,\r | |
521 | EfiACPIMemoryNVS,\r | |
522 | 2 + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber),\r | |
523 | (EFI_PHYSICAL_ADDRESS*)&S3TableBase\r | |
524 | );\r | |
525 | \r | |
526 | if (EFI_ERROR(Status)) {\r | |
527 | ASSERT_EFI_ERROR (Status);\r | |
528 | return 0;\r | |
529 | }\r | |
530 | //\r | |
531 | // Fill Table Header\r | |
532 | //\r | |
533 | ScriptTableInfo = (EFI_BOOT_SCRIPT_TABLE_HEADER*)(UINTN)S3TableBase;\r | |
534 | ScriptTableInfo->OpCode = S3_BOOT_SCRIPT_LIB_TABLE_OPCODE;\r | |
535 | ScriptTableInfo->Length = (UINT8) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER);\r | |
536 | ScriptTableInfo->TableLength = 0; // will be calculate at CloseTable\r | |
537 | mS3BootScriptTablePtr->TableLength = sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER);\r | |
538 | mS3BootScriptTablePtr->TableBase = (UINT8*)(UINTN)S3TableBase;\r | |
539 | mS3BootScriptTablePtr->TableMemoryPageNumber = (UINT16)(2 + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber));\r | |
540 | }\r | |
541 | \r | |
542 | // Here we do not count the reserved memory for runtime script table.\r | |
543 | PageNumber = (UINT16)(mS3BootScriptTablePtr->TableMemoryPageNumber - PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber)); \r | |
544 | TableLength = mS3BootScriptTablePtr->TableLength;\r | |
545 | if ((UINT32)(PageNumber * EFI_PAGE_SIZE) < (TableLength + EntryLength)) {\r | |
546 | // \r | |
547 | // The buffer is too small to hold the table, Reallocate the buffer\r | |
548 | //\r | |
549 | NewS3TableBase = 0xffffffff;\r | |
550 | Status = gBS->AllocatePages (\r | |
551 | AllocateMaxAddress,\r | |
552 | EfiACPIMemoryNVS,\r | |
553 | 2 + PageNumber + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber),\r | |
554 | (EFI_PHYSICAL_ADDRESS*)&NewS3TableBase\r | |
555 | );\r | |
556 | \r | |
557 | if (EFI_ERROR(Status)) {\r | |
558 | ASSERT_EFI_ERROR (Status);\r | |
559 | return 0;\r | |
560 | }\r | |
561 | \r | |
562 | CopyMem ((VOID*)(UINTN)NewS3TableBase, (VOID*)(UINTN)S3TableBase, TableLength);\r | |
563 | gBS->FreePages (S3TableBase, mS3BootScriptTablePtr->TableMemoryPageNumber);\r | |
564 | \r | |
565 | mS3BootScriptTablePtr->TableBase = (UINT8*)(UINTN)NewS3TableBase;\r | |
566 | mS3BootScriptTablePtr->TableMemoryPageNumber = (UINT16) (2 + PageNumber + PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber)); \r | |
567 | }\r | |
568 | //\r | |
569 | // calculate the the start address for the new entry. \r | |
570 | //\r | |
571 | NewEntryPtr = mS3BootScriptTablePtr->TableBase + TableLength;\r | |
572 | \r | |
573 | //\r | |
574 | // update the table lenghth\r | |
575 | //\r | |
576 | mS3BootScriptTablePtr->TableLength = TableLength + EntryLength;\r | |
577 | \r | |
578 | //\r | |
579 | // In the boot time, we will not append the termination entry to the boot script\r | |
580 | // table until the callers think there is no boot time data that should be added and \r | |
581 | // it is caller's responsibility to explicit call the CloseTable. \r | |
582 | //\r | |
583 | //\r | |
584 | \r | |
585 | return NewEntryPtr; \r | |
586 | }\r | |
587 | /**\r | |
588 | To get the start address from which a new runtime s3 boot script entry will write into.\r | |
589 | In this case, it should be ensured that there is enough buffer to hold the entry.\r | |
590 | \r | |
591 | @param EntryLength the new entry length.\r | |
592 | \r | |
593 | @retval the address from which the a new s3 runtime script entry will write into\r | |
594 | **/\r | |
595 | UINT8*\r | |
596 | S3BootScriptGetRuntimeEntryAddAddress (\r | |
597 | UINT8 EntryLength\r | |
598 | )\r | |
599 | {\r | |
600 | UINT8 *NewEntryPtr;\r | |
601 | \r | |
602 | NewEntryPtr = NULL; \r | |
603 | //\r | |
604 | // Check if the memory range reserved for S3 Boot Script table is large enough to hold the node. \r | |
605 | //\r | |
606 | if (mS3BootScriptTablePtr->TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE) <= EFI_PAGES_TO_SIZE((UINT32)(mS3BootScriptTablePtr->TableMemoryPageNumber))) {\r | |
607 | NewEntryPtr = mS3BootScriptTablePtr->TableBase + mS3BootScriptTablePtr->TableLength; \r | |
608 | mS3BootScriptTablePtr->TableLength = mS3BootScriptTablePtr->TableLength + EntryLength;\r | |
609 | //\r | |
610 | // Append a terminate node on every insert\r | |
611 | //\r | |
612 | S3BootScriptInternalCloseTable ();\r | |
613 | }\r | |
614 | return (UINT8*)NewEntryPtr; \r | |
615 | }\r | |
616 | /**\r | |
617 | To get the start address from which a new s3 boot script entry will write into.\r | |
618 | \r | |
619 | @param EntryLength the new entry length.\r | |
620 | \r | |
621 | @retval the address from which the a new s3 runtime script entry will write into \r | |
622 | **/ \r | |
623 | UINT8* \r | |
624 | S3BootScriptGetEntryAddAddress (\r | |
625 | UINT8 EntryLength\r | |
626 | )\r | |
627 | {\r | |
628 | UINT8* NewEntryPtr;\r | |
629 | EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader;\r | |
630 | EFI_STATUS Status;\r | |
631 | \r | |
632 | if (mS3BootScriptTablePtr->AtRuntime) {\r | |
633 | //\r | |
634 | // We need check InSmm when AtRuntime, because after SmmReadyToLock, only SMM driver is allowed to write boot script.\r | |
635 | //\r | |
636 | if (!mS3BootScriptTablePtr->InSmm) {\r | |
637 | //\r | |
638 | // Add DEBUG ERROR, so that we can find it at boot time.\r | |
639 | // Do not use ASSERT, because we may have test invoke this interface.\r | |
640 | //\r | |
641 | DEBUG ((EFI_D_ERROR, "FATAL ERROR: Set boot script after ReadyToLock!!!\n"));\r | |
642 | return NULL;\r | |
643 | }\r | |
644 | \r | |
645 | //\r | |
646 | // NOTE: OS will restore ACPINvs data. After S3, the table length in mS3BootScriptTable (SMM) is different with\r | |
647 | // table length in BootScriptTable header (ACPINvs).\r | |
648 | // So here we need sync them. We choose ACPINvs table length, because we want to override the boot script saved\r | |
649 | // in SMM every time.\r | |
650 | //\r | |
651 | ASSERT (mS3BootScriptTablePtr == &mS3BootScriptTable);\r | |
652 | CopyMem ((VOID*)&TableHeader, (VOID*)mS3BootScriptTablePtr->TableBase, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER));\r | |
653 | if (mS3BootScriptTablePtr->TableLength + sizeof(EFI_BOOT_SCRIPT_TERMINATE) != TableHeader.TableLength) {\r | |
654 | //\r | |
655 | // Restore it to use original value\r | |
656 | //\r | |
657 | RestoreLockBox (&mBootScriptDataGuid, NULL, NULL);\r | |
658 | //\r | |
659 | // Copy it again to get original value\r | |
660 | // NOTE: We should NOT use TableHeader.TableLength, because it is already updated to be whole length.\r | |
661 | //\r | |
662 | mS3BootScriptTablePtr->TableLength = (UINT32)(mLockBoxLength - sizeof(EFI_BOOT_SCRIPT_TERMINATE));\r | |
663 | }\r | |
664 | \r | |
665 | NewEntryPtr = S3BootScriptGetRuntimeEntryAddAddress (EntryLength);\r | |
666 | //\r | |
667 | // Now the length field is updated, need sync to lockbox.\r | |
668 | // So in S3 resume, the data can be restored correctly.\r | |
669 | //\r | |
670 | CopyMem ((VOID*)&TableHeader, (VOID*)mS3BootScriptTablePtr->TableBase, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER));\r | |
671 | Status = UpdateLockBox (\r | |
672 | &mBootScriptDataGuid,\r | |
673 | OFFSET_OF(EFI_BOOT_SCRIPT_TABLE_HEADER, TableLength),\r | |
674 | &TableHeader.TableLength,\r | |
675 | sizeof(TableHeader.TableLength)\r | |
676 | );\r | |
677 | ASSERT_EFI_ERROR (Status);\r | |
678 | } else { \r | |
679 | NewEntryPtr = S3BootScriptGetBootTimeEntryAddAddress (EntryLength);\r | |
680 | } \r | |
681 | return NewEntryPtr;\r | |
682 | \r | |
683 | } \r | |
684 | \r | |
685 | /**\r | |
686 | Sync BootScript LockBox data.\r | |
687 | **/\r | |
688 | VOID\r | |
689 | SyncBootScript (\r | |
690 | VOID\r | |
691 | )\r | |
692 | {\r | |
693 | EFI_STATUS Status;\r | |
694 | \r | |
695 | if (!mS3BootScriptTablePtr->AtRuntime || !mS3BootScriptTablePtr->InSmm) {\r | |
696 | return ;\r | |
697 | }\r | |
698 | //\r | |
699 | // Update Terminate\r | |
700 | // So in S3 resume, the data can be restored correctly.\r | |
701 | //\r | |
702 | Status = UpdateLockBox (\r | |
703 | &mBootScriptDataGuid,\r | |
704 | mLockBoxLength - sizeof(EFI_BOOT_SCRIPT_TERMINATE),\r | |
705 | (VOID *)((UINTN)mS3BootScriptTablePtr->TableBase + mLockBoxLength - sizeof(EFI_BOOT_SCRIPT_TERMINATE)),\r | |
706 | sizeof(EFI_BOOT_SCRIPT_TERMINATE)\r | |
707 | );\r | |
708 | ASSERT_EFI_ERROR (Status);\r | |
709 | }\r | |
710 | \r | |
711 | /** \r | |
712 | This is an function to close the S3 boot script table. The function could only be called in \r | |
713 | BOOT time phase. To comply with the Framework spec definition on \r | |
714 | EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable(), this function will fulfill following things:\r | |
715 | 1. Closes the specified boot script table\r | |
716 | 2. It allocates a new memory pool to duplicate all the boot scripts in the specified table. \r | |
717 | Once this function is called, the table maintained by the library will be destroyed \r | |
718 | after it is copied into the allocated pool.\r | |
719 | 3. Any attempts to add a script record after calling this function will cause a new table \r | |
720 | to be created by the library.\r | |
721 | 4. The base address of the allocated pool will be returned in Address. Note that after \r | |
722 | using the boot script table, the CALLER is responsible for freeing the pool that is allocated\r | |
723 | by this function. \r | |
724 | \r | |
725 | In Spec PI1.1, this EFI_BOOT_SCRIPT_SAVE_PROTOCOL.CloseTable() is retired. To provides this API for now is \r | |
726 | for Framework Spec compatibility.\r | |
727 | \r | |
728 | If anyone does call CloseTable() on a real platform, then the caller is responsible for figuring out \r | |
729 | how to get the script to run on an S3 resume because the boot script maintained by the lib will be \r | |
730 | destroyed.\r | |
731 | \r | |
732 | @return the base address of the new copy of the boot script tble. \r | |
733 | @note this function could only called in boot time phase\r | |
734 | \r | |
735 | **/\r | |
736 | UINT8*\r | |
737 | EFIAPI\r | |
738 | S3BootScriptCloseTable (\r | |
739 | VOID\r | |
740 | )\r | |
741 | {\r | |
742 | UINT8 *S3TableBase;\r | |
743 | UINT32 TableLength;\r | |
744 | UINT8 *Buffer;\r | |
745 | EFI_STATUS Status;\r | |
746 | EFI_BOOT_SCRIPT_TABLE_HEADER *ScriptTableInfo;\r | |
747 | \r | |
748 | S3TableBase = mS3BootScriptTablePtr->TableBase; \r | |
749 | if (S3TableBase == 0) {\r | |
750 | return 0; \r | |
751 | }\r | |
752 | //\r | |
753 | // Append the termination record the S3 boot script table\r | |
754 | //\r | |
755 | S3BootScriptInternalCloseTable();\r | |
756 | TableLength = mS3BootScriptTablePtr->TableLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE);\r | |
757 | //\r | |
758 | // Allocate the buffer and copy the boot script to the buffer. \r | |
759 | //\r | |
760 | Status = gBS->AllocatePool (\r | |
761 | EfiBootServicesData,\r | |
762 | (UINTN)TableLength,\r | |
763 | (VOID **) &Buffer\r | |
764 | );\r | |
765 | if (EFI_ERROR (Status)) {\r | |
766 | return 0; \r | |
767 | }\r | |
768 | CopyMem (Buffer, S3TableBase, TableLength);\r | |
769 | \r | |
770 | //\r | |
771 | // Destroy the table maintained by the library so that the next write operation \r | |
772 | // will write the record to the first entry of the table.\r | |
773 | //\r | |
774 | // Fill the table header.\r | |
775 | ScriptTableInfo = (EFI_BOOT_SCRIPT_TABLE_HEADER*)S3TableBase;\r | |
776 | ScriptTableInfo->OpCode = S3_BOOT_SCRIPT_LIB_TABLE_OPCODE;\r | |
777 | ScriptTableInfo->Length = (UINT8) sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER);\r | |
778 | ScriptTableInfo->TableLength = 0; // will be calculate at close the table\r | |
779 | \r | |
780 | mS3BootScriptTablePtr->TableLength = sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER);\r | |
781 | return Buffer;\r | |
782 | }\r | |
783 | /**\r | |
784 | Save I/O write to boot script \r | |
785 | \r | |
786 | @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.\r | |
787 | @param Address The base address of the I/O operations.\r | |
788 | @param Count The number of I/O operations to perform.\r | |
789 | @param Buffer The source buffer from which to write data.\r | |
790 | \r | |
791 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
792 | @retval RETURN_SUCCESS Opcode is added.\r | |
793 | **/\r | |
794 | RETURN_STATUS\r | |
795 | EFIAPI\r | |
796 | S3BootScriptSaveIoWrite (\r | |
797 | IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r | |
798 | IN UINT64 Address,\r | |
799 | IN UINTN Count,\r | |
800 | IN VOID *Buffer\r | |
801 | )\r | |
802 | \r | |
803 | {\r | |
804 | UINT8 Length;\r | |
805 | UINT8 *Script;\r | |
806 | UINT8 WidthInByte;\r | |
807 | EFI_BOOT_SCRIPT_IO_WRITE ScriptIoWrite;\r | |
808 | \r | |
809 | WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r | |
810 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_IO_WRITE) + (WidthInByte * Count));\r | |
811 | \r | |
812 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
813 | if (Script == NULL) {\r | |
814 | return RETURN_OUT_OF_RESOURCES;\r | |
815 | }\r | |
816 | //\r | |
817 | // save script data\r | |
818 | //\r | |
819 | ScriptIoWrite.OpCode = EFI_BOOT_SCRIPT_IO_WRITE_OPCODE;\r | |
820 | ScriptIoWrite.Length = Length;\r | |
821 | ScriptIoWrite.Width = Width;\r | |
822 | ScriptIoWrite.Address = Address;\r | |
823 | ScriptIoWrite.Count = (UINT32) Count;\r | |
824 | CopyMem ((VOID*)Script, (VOID*)&ScriptIoWrite, sizeof(EFI_BOOT_SCRIPT_IO_WRITE));\r | |
825 | CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_IO_WRITE)), Buffer, WidthInByte * Count);\r | |
826 | \r | |
827 | SyncBootScript ();\r | |
828 | \r | |
829 | return RETURN_SUCCESS;\r | |
830 | }\r | |
831 | \r | |
832 | /**\r | |
833 | Adds a record for an I/O modify operation into a S3 boot script table\r | |
834 | \r | |
835 | @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.\r | |
836 | @param Address The base address of the I/O operations.\r | |
837 | @param Data A pointer to the data to be OR-ed.\r | |
838 | @param DataMask A pointer to the data mask to be AND-ed with the data read from the register\r | |
839 | \r | |
840 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
841 | @retval RETURN_SUCCESS Opcode is added.\r | |
842 | **/\r | |
843 | RETURN_STATUS\r | |
844 | EFIAPI\r | |
845 | S3BootScriptSaveIoReadWrite (\r | |
846 | IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r | |
847 | IN UINT64 Address,\r | |
848 | IN VOID *Data,\r | |
849 | IN VOID *DataMask\r | |
850 | )\r | |
851 | {\r | |
852 | UINT8 Length;\r | |
853 | UINT8 *Script;\r | |
854 | UINT8 WidthInByte;\r | |
855 | EFI_BOOT_SCRIPT_IO_READ_WRITE ScriptIoReadWrite;\r | |
856 | \r | |
857 | WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r | |
858 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE) + (WidthInByte * 2));\r | |
859 | \r | |
860 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
861 | if (Script == NULL) {\r | |
862 | return RETURN_OUT_OF_RESOURCES;\r | |
863 | }\r | |
864 | //\r | |
865 | // Build script data\r | |
866 | //\r | |
867 | ScriptIoReadWrite.OpCode = EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE;\r | |
868 | ScriptIoReadWrite.Length = Length;\r | |
869 | ScriptIoReadWrite.Width = Width;\r | |
870 | ScriptIoReadWrite.Address = Address;\r | |
871 | \r | |
872 | CopyMem ((VOID*)Script, (VOID*)&ScriptIoReadWrite, sizeof(EFI_BOOT_SCRIPT_IO_READ_WRITE));\r | |
873 | CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE)), Data, WidthInByte);\r | |
874 | CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE) + WidthInByte), DataMask, WidthInByte);\r | |
875 | \r | |
876 | SyncBootScript ();\r | |
877 | \r | |
878 | return RETURN_SUCCESS;\r | |
879 | }\r | |
880 | /**\r | |
881 | Adds a record for a memory write operation into a specified boot script table.\r | |
882 | \r | |
883 | @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.\r | |
884 | @param Address The base address of the memory operations\r | |
885 | @param Count The number of memory operations to perform.\r | |
886 | @param Buffer The source buffer from which to write the data.\r | |
887 | \r | |
888 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
889 | @retval RETURN_SUCCESS Opcode is added.\r | |
890 | **/\r | |
891 | RETURN_STATUS\r | |
892 | EFIAPI\r | |
893 | S3BootScriptSaveMemWrite (\r | |
894 | IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r | |
895 | IN UINT64 Address,\r | |
896 | IN UINTN Count,\r | |
897 | IN VOID *Buffer\r | |
898 | )\r | |
899 | {\r | |
900 | UINT8 Length;\r | |
901 | UINT8 *Script;\r | |
902 | UINT8 WidthInByte;\r | |
903 | EFI_BOOT_SCRIPT_MEM_WRITE ScriptMemWrite;\r | |
904 | \r | |
905 | WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r | |
906 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_MEM_WRITE) + (WidthInByte * Count));\r | |
907 | \r | |
908 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
909 | if (Script == NULL) {\r | |
910 | return RETURN_OUT_OF_RESOURCES;\r | |
911 | } \r | |
912 | //\r | |
913 | // Build script data\r | |
914 | //\r | |
915 | ScriptMemWrite.OpCode = EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE;\r | |
916 | ScriptMemWrite.Length = Length;\r | |
917 | ScriptMemWrite.Width = Width;\r | |
918 | ScriptMemWrite.Address = Address;\r | |
919 | ScriptMemWrite.Count = (UINT32) Count;\r | |
920 | \r | |
921 | CopyMem ((VOID*)Script, (VOID*)&ScriptMemWrite, sizeof(EFI_BOOT_SCRIPT_MEM_WRITE));\r | |
922 | CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_MEM_WRITE)), Buffer, WidthInByte * Count);\r | |
923 | \r | |
924 | SyncBootScript ();\r | |
925 | \r | |
926 | return RETURN_SUCCESS;\r | |
927 | }\r | |
928 | /**\r | |
929 | Adds a record for a memory modify operation into a specified boot script table.\r | |
930 | \r | |
931 | @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.\r | |
932 | @param Address The base address of the memory operations. Address needs alignment if required\r | |
933 | @param Data A pointer to the data to be OR-ed.\r | |
934 | @param DataMask A pointer to the data mask to be AND-ed with the data read from the register.\r | |
935 | \r | |
936 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
937 | @retval RETURN_SUCCESS Opcode is added.\r | |
938 | **/\r | |
939 | RETURN_STATUS\r | |
940 | EFIAPI\r | |
941 | S3BootScriptSaveMemReadWrite (\r | |
942 | IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r | |
943 | IN UINT64 Address,\r | |
944 | IN VOID *Data,\r | |
945 | IN VOID *DataMask\r | |
946 | )\r | |
947 | {\r | |
948 | UINT8 Length;\r | |
949 | UINT8 *Script;\r | |
950 | UINT8 WidthInByte;\r | |
951 | EFI_BOOT_SCRIPT_MEM_READ_WRITE ScriptMemReadWrite;\r | |
952 | \r | |
953 | WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r | |
954 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE) + (WidthInByte * 2));\r | |
955 | \r | |
956 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
957 | if (Script == NULL) {\r | |
958 | return RETURN_OUT_OF_RESOURCES;\r | |
959 | } \r | |
960 | //\r | |
961 | // Build script data\r | |
962 | // \r | |
963 | ScriptMemReadWrite.OpCode = EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE;\r | |
964 | ScriptMemReadWrite.Length = Length;\r | |
965 | ScriptMemReadWrite.Width = Width;\r | |
966 | ScriptMemReadWrite.Address = Address;\r | |
967 | \r | |
968 | CopyMem ((VOID*)Script, (VOID*)&ScriptMemReadWrite , sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE));\r | |
969 | CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE)), Data, WidthInByte);\r | |
970 | CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE) + WidthInByte), DataMask, WidthInByte);\r | |
971 | \r | |
972 | SyncBootScript ();\r | |
973 | \r | |
974 | return RETURN_SUCCESS;\r | |
975 | }\r | |
976 | /**\r | |
977 | Adds a record for a PCI configuration space write operation into a specified boot script table.\r | |
978 | \r | |
979 | @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.\r | |
980 | @param Address The address within the PCI configuration space.\r | |
981 | @param Count The number of PCI operations to perform.\r | |
982 | @param Buffer The source buffer from which to write the data.\r | |
983 | \r | |
984 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
985 | @retval RETURN_SUCCESS Opcode is added.\r | |
986 | **/\r | |
987 | RETURN_STATUS\r | |
988 | EFIAPI\r | |
989 | S3BootScriptSavePciCfgWrite (\r | |
990 | IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r | |
991 | IN UINT64 Address,\r | |
992 | IN UINTN Count,\r | |
993 | IN VOID *Buffer\r | |
994 | )\r | |
995 | {\r | |
996 | UINT8 Length;\r | |
997 | UINT8 *Script;\r | |
998 | UINT8 WidthInByte;\r | |
999 | EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE ScriptPciWrite;\r | |
1000 | \r | |
1001 | WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r | |
1002 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE) + (WidthInByte * Count));\r | |
1003 | \r | |
1004 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1005 | if (Script == NULL) {\r | |
1006 | return RETURN_OUT_OF_RESOURCES;\r | |
1007 | } \r | |
1008 | //\r | |
1009 | // Build script data\r | |
1010 | //\r | |
1011 | ScriptPciWrite.OpCode = EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE;\r | |
1012 | ScriptPciWrite.Length = Length;\r | |
1013 | ScriptPciWrite.Width = Width;\r | |
1014 | ScriptPciWrite.Address = Address;\r | |
1015 | ScriptPciWrite.Count = (UINT32) Count;\r | |
1016 | \r | |
1017 | CopyMem ((VOID*)Script, (VOID*)&ScriptPciWrite, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE));\r | |
1018 | CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE)), Buffer, WidthInByte * Count);\r | |
1019 | \r | |
1020 | SyncBootScript ();\r | |
1021 | \r | |
1022 | return RETURN_SUCCESS;\r | |
1023 | }\r | |
1024 | /**\r | |
1025 | Adds a record for a PCI configuration space modify operation into a specified boot script table.\r | |
1026 | \r | |
1027 | @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.\r | |
1028 | @param Address The address within the PCI configuration space.\r | |
1029 | @param Data A pointer to the data to be OR-ed.The size depends on Width.\r | |
1030 | @param DataMask A pointer to the data mask to be AND-ed.\r | |
1031 | \r | |
1032 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1033 | @retval RETURN__SUCCESS Opcode is added.\r | |
1034 | **/\r | |
1035 | RETURN_STATUS\r | |
1036 | EFIAPI\r | |
1037 | S3BootScriptSavePciCfgReadWrite (\r | |
1038 | IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r | |
1039 | IN UINT64 Address,\r | |
1040 | IN VOID *Data,\r | |
1041 | IN VOID *DataMask\r | |
1042 | )\r | |
1043 | {\r | |
1044 | UINT8 Length;\r | |
1045 | UINT8 *Script;\r | |
1046 | UINT8 WidthInByte;\r | |
1047 | EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE ScriptPciReadWrite;\r | |
1048 | \r | |
1049 | WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r | |
1050 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE) + (WidthInByte * 2));\r | |
1051 | \r | |
1052 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1053 | if (Script == NULL) {\r | |
1054 | return RETURN_OUT_OF_RESOURCES;\r | |
1055 | } \r | |
1056 | //\r | |
1057 | // Build script data\r | |
1058 | // \r | |
1059 | ScriptPciReadWrite.OpCode = EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE;\r | |
1060 | ScriptPciReadWrite.Length = Length;\r | |
1061 | ScriptPciReadWrite.Width = Width;\r | |
1062 | ScriptPciReadWrite.Address = Address;\r | |
1063 | \r | |
1064 | CopyMem ((VOID*)Script, (VOID*)&ScriptPciReadWrite, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE));\r | |
1065 | CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE)), Data, WidthInByte);\r | |
1066 | CopyMem (\r | |
1067 | (VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE) + WidthInByte),\r | |
1068 | DataMask,\r | |
1069 | WidthInByte\r | |
1070 | );\r | |
1071 | \r | |
1072 | SyncBootScript ();\r | |
1073 | \r | |
1074 | return RETURN_SUCCESS;\r | |
1075 | }\r | |
1076 | /**\r | |
1077 | Adds a record for a PCI configuration space modify operation into a specified boot script table.\r | |
1078 | \r | |
1079 | @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.\r | |
1080 | @param Segment The PCI segment number for Address.\r | |
1081 | @param Address The address within the PCI configuration space.\r | |
1082 | @param Count The number of PCI operations to perform.\r | |
1083 | @param Buffer The source buffer from which to write the data.\r | |
1084 | \r | |
1085 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1086 | @retval RETURN_SUCCESS Opcode is added.\r | |
1087 | **/\r | |
1088 | RETURN_STATUS\r | |
1089 | EFIAPI\r | |
1090 | S3BootScriptSavePciCfg2Write (\r | |
1091 | IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r | |
1092 | IN UINT16 Segment,\r | |
1093 | IN UINT64 Address,\r | |
1094 | IN UINTN Count,\r | |
1095 | IN VOID *Buffer\r | |
1096 | )\r | |
1097 | {\r | |
1098 | UINT8 Length;\r | |
1099 | UINT8 *Script;\r | |
1100 | UINT8 WidthInByte;\r | |
1101 | EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE ScriptPciWrite2;\r | |
1102 | \r | |
1103 | WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r | |
1104 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE) + (WidthInByte * Count));\r | |
1105 | \r | |
1106 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1107 | if (Script == NULL) {\r | |
1108 | return RETURN_OUT_OF_RESOURCES;\r | |
1109 | } \r | |
1110 | //\r | |
1111 | // Build script data\r | |
1112 | //\r | |
1113 | ScriptPciWrite2.OpCode = EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE;\r | |
1114 | ScriptPciWrite2.Length = Length;\r | |
1115 | ScriptPciWrite2.Width = Width;\r | |
1116 | ScriptPciWrite2.Address = Address;\r | |
1117 | ScriptPciWrite2.Segment = Segment;\r | |
1118 | ScriptPciWrite2.Count = (UINT32)Count;\r | |
1119 | \r | |
1120 | CopyMem ((VOID*)Script, (VOID*)&ScriptPciWrite2, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE));\r | |
1121 | CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE)), Buffer, WidthInByte * Count);\r | |
1122 | \r | |
1123 | SyncBootScript ();\r | |
1124 | \r | |
1125 | return RETURN_SUCCESS;\r | |
1126 | }\r | |
1127 | /**\r | |
1128 | Adds a record for a PCI configuration space modify operation into a specified boot script table.\r | |
1129 | \r | |
1130 | @param Width The width of the I/O operations.Enumerated in S3_BOOT_SCRIPT_LIB_WIDTH.\r | |
1131 | @param Segment The PCI segment number for Address.\r | |
1132 | @param Address The address within the PCI configuration space.\r | |
1133 | @param Data A pointer to the data to be OR-ed. The size depends on Width.\r | |
1134 | @param DataMask A pointer to the data mask to be AND-ed.\r | |
1135 | \r | |
1136 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1137 | @retval RETURN_SUCCESS Opcode is added.\r | |
1138 | **/\r | |
1139 | RETURN_STATUS\r | |
1140 | EFIAPI\r | |
1141 | S3BootScriptSavePciCfg2ReadWrite (\r | |
1142 | IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r | |
1143 | IN UINT16 Segment,\r | |
1144 | IN UINT64 Address,\r | |
1145 | IN VOID *Data,\r | |
1146 | IN VOID *DataMask\r | |
1147 | )\r | |
1148 | {\r | |
1149 | UINT8 Length;\r | |
1150 | UINT8 *Script;\r | |
1151 | UINT8 WidthInByte;\r | |
1152 | EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE ScriptPciReadWrite2;\r | |
1153 | \r | |
1154 | WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r | |
1155 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE) + (WidthInByte * 2));\r | |
1156 | \r | |
1157 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1158 | if (Script == NULL) {\r | |
1159 | return RETURN_OUT_OF_RESOURCES;\r | |
1160 | } \r | |
1161 | //\r | |
1162 | // Build script data\r | |
1163 | //\r | |
1164 | ScriptPciReadWrite2.OpCode = EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE;\r | |
1165 | ScriptPciReadWrite2.Length = Length;\r | |
1166 | ScriptPciReadWrite2.Width = Width;\r | |
1167 | ScriptPciReadWrite2.Segment = Segment;\r | |
1168 | ScriptPciReadWrite2.Address = Address;\r | |
1169 | \r | |
1170 | CopyMem ((VOID*)Script, (VOID*)&ScriptPciReadWrite2, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE));\r | |
1171 | CopyMem ((VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE)), Data, WidthInByte);\r | |
1172 | CopyMem (\r | |
1173 | (VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE) + WidthInByte),\r | |
1174 | DataMask,\r | |
1175 | WidthInByte\r | |
1176 | );\r | |
1177 | \r | |
1178 | SyncBootScript ();\r | |
1179 | \r | |
1180 | return RETURN_SUCCESS;\r | |
1181 | }\r | |
1182 | /**\r | |
1183 | Adds a record for an SMBus command execution into a specified boot script table.\r | |
1184 | \r | |
1185 | @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, and PEC.\r | |
1186 | @param Operation Indicates which particular SMBus protocol it will use to execute the SMBus\r | |
1187 | transactions.\r | |
1188 | @param Length A pointer to signify the number of bytes that this operation will do.\r | |
1189 | @param Buffer Contains the value of data to execute to the SMBUS slave device.\r | |
1190 | \r | |
1191 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1192 | @retval RETURN_SUCCESS Opcode is added.\r | |
1193 | **/\r | |
1194 | RETURN_STATUS\r | |
1195 | EFIAPI\r | |
1196 | S3BootScriptSaveSmbusExecute (\r | |
1197 | IN UINTN SmBusAddress, \r | |
1198 | IN EFI_SMBUS_OPERATION Operation,\r | |
1199 | IN UINTN *Length,\r | |
1200 | IN VOID *Buffer\r | |
1201 | )\r | |
1202 | {\r | |
1203 | UINT8 DataSize;\r | |
1204 | UINT8 *Script;\r | |
1205 | EFI_BOOT_SCRIPT_SMBUS_EXECUTE ScriptSmbusExecute;\r | |
1206 | \r | |
1207 | DataSize = (UINT8)(sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE) + (*Length));\r | |
1208 | \r | |
1209 | Script = S3BootScriptGetEntryAddAddress (DataSize);\r | |
1210 | if (Script == NULL) {\r | |
1211 | return RETURN_OUT_OF_RESOURCES;\r | |
1212 | }\r | |
1213 | //\r | |
1214 | // Build script data\r | |
1215 | //\r | |
1216 | ScriptSmbusExecute.OpCode = EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE;\r | |
1217 | ScriptSmbusExecute.Length = DataSize;\r | |
1218 | ScriptSmbusExecute.SmBusAddress = (UINT64) SmBusAddress;\r | |
1219 | ScriptSmbusExecute.Operation = Operation;\r | |
1220 | ScriptSmbusExecute.DataSize = (UINT32) *Length;\r | |
1221 | \r | |
1222 | CopyMem ((VOID*)Script, (VOID*)&ScriptSmbusExecute, sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE));\r | |
1223 | CopyMem (\r | |
1224 | (VOID*)(Script + sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE)),\r | |
1225 | Buffer,\r | |
1226 | (*Length)\r | |
1227 | );\r | |
1228 | \r | |
1229 | SyncBootScript ();\r | |
1230 | \r | |
1231 | return RETURN_SUCCESS;\r | |
1232 | }\r | |
1233 | /**\r | |
1234 | Adds a record for an execution stall on the processor into a specified boot script table.\r | |
1235 | \r | |
1236 | @param Duration Duration in microseconds of the stall\r | |
1237 | \r | |
1238 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1239 | @retval RETURN_SUCCESS Opcode is added.\r | |
1240 | **/\r | |
1241 | RETURN_STATUS\r | |
1242 | EFIAPI\r | |
1243 | S3BootScriptSaveStall (\r | |
1244 | IN UINTN Duration\r | |
1245 | )\r | |
1246 | {\r | |
1247 | UINT8 Length;\r | |
1248 | UINT8 *Script;\r | |
1249 | EFI_BOOT_SCRIPT_STALL ScriptStall;\r | |
1250 | \r | |
1251 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_STALL));\r | |
1252 | \r | |
1253 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1254 | if (Script == NULL) {\r | |
1255 | return RETURN_OUT_OF_RESOURCES;\r | |
1256 | } \r | |
1257 | //\r | |
1258 | // Build script data\r | |
1259 | //\r | |
1260 | ScriptStall.OpCode = EFI_BOOT_SCRIPT_STALL_OPCODE;\r | |
1261 | ScriptStall.Length = Length;\r | |
1262 | ScriptStall.Duration = Duration;\r | |
1263 | \r | |
1264 | CopyMem ((VOID*)Script, (VOID*)&ScriptStall, sizeof (EFI_BOOT_SCRIPT_STALL));\r | |
1265 | \r | |
1266 | SyncBootScript ();\r | |
1267 | \r | |
1268 | return RETURN_SUCCESS;\r | |
1269 | }\r | |
1270 | /**\r | |
1271 | Adds a record for an execution stall on the processor into a specified boot script table.\r | |
1272 | \r | |
1273 | @param EntryPoint Entry point of the code to be dispatched.\r | |
1274 | @param Context Argument to be passed into the EntryPoint of the code to be dispatched.\r | |
1275 | \r | |
1276 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1277 | @retval RETURN_SUCCESS Opcode is added.\r | |
1278 | **/\r | |
1279 | RETURN_STATUS\r | |
1280 | EFIAPI\r | |
1281 | S3BootScriptSaveDispatch2 (\r | |
1282 | IN VOID *EntryPoint,\r | |
1283 | IN VOID *Context\r | |
1284 | )\r | |
1285 | {\r | |
1286 | UINT8 Length;\r | |
1287 | UINT8 *Script;\r | |
1288 | EFI_BOOT_SCRIPT_DISPATCH_2 ScriptDispatch2;\r | |
1289 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_DISPATCH_2));\r | |
1290 | \r | |
1291 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1292 | if (Script == NULL) {\r | |
1293 | return RETURN_OUT_OF_RESOURCES;\r | |
1294 | } \r | |
1295 | //\r | |
1296 | // Build script data\r | |
1297 | //\r | |
1298 | ScriptDispatch2.OpCode = EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE;\r | |
1299 | ScriptDispatch2.Length = Length;\r | |
1300 | ScriptDispatch2.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)EntryPoint;\r | |
1301 | ScriptDispatch2.Context = (EFI_PHYSICAL_ADDRESS)(UINTN)Context;\r | |
1302 | \r | |
1303 | CopyMem ((VOID*)Script, (VOID*)&ScriptDispatch2, sizeof (EFI_BOOT_SCRIPT_DISPATCH_2));\r | |
1304 | \r | |
1305 | SyncBootScript ();\r | |
1306 | \r | |
1307 | return RETURN_SUCCESS;\r | |
1308 | \r | |
1309 | }\r | |
1310 | /**\r | |
1311 | Adds a record for memory reads of the memory location and continues when the exit criteria is\r | |
1312 | satisfied or after a defined duration.\r | |
1313 | \r | |
1314 | @param Width The width of the memory operations.\r | |
1315 | @param Address The base address of the memory operations.\r | |
1316 | @param BitMask A pointer to the bit mask to be AND-ed with the data read from the register.\r | |
1317 | @param BitValue A pointer to the data value after to be Masked.\r | |
1318 | @param Duration Duration in microseconds of the stall.\r | |
1319 | @param LoopTimes The times of the register polling.\r | |
1320 | \r | |
1321 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1322 | @retval RETURN_SUCCESS Opcode is added.\r | |
1323 | \r | |
1324 | **/\r | |
1325 | RETURN_STATUS\r | |
1326 | EFIAPI\r | |
1327 | S3BootScriptSaveMemPoll (\r | |
1328 | IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r | |
1329 | IN UINT64 Address,\r | |
1330 | IN VOID *BitMask,\r | |
1331 | IN VOID *BitValue,\r | |
1332 | IN UINTN Duration,\r | |
1333 | IN UINTN LoopTimes\r | |
1334 | )\r | |
1335 | {\r | |
1336 | UINT8 Length;\r | |
1337 | UINT8 *Script;\r | |
1338 | UINT8 WidthInByte; \r | |
1339 | EFI_BOOT_SCRIPT_MEM_POLL ScriptMemPoll; \r | |
1340 | \r | |
1341 | WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r | |
1342 | \r | |
1343 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_MEM_POLL) + (WidthInByte * 2));\r | |
1344 | \r | |
1345 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1346 | if (Script == NULL) {\r | |
1347 | return RETURN_OUT_OF_RESOURCES;\r | |
1348 | }\r | |
1349 | //\r | |
1350 | // Build script data\r | |
1351 | //\r | |
1352 | ScriptMemPoll.OpCode = EFI_BOOT_SCRIPT_MEM_POLL_OPCODE;\r | |
1353 | ScriptMemPoll.Length = Length;\r | |
1354 | ScriptMemPoll.Width = Width; \r | |
1355 | ScriptMemPoll.Address = Address;\r | |
1356 | ScriptMemPoll.Duration = Duration;\r | |
1357 | ScriptMemPoll.LoopTimes = LoopTimes;\r | |
1358 | \r | |
1359 | CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_MEM_POLL)), BitValue, WidthInByte);\r | |
1360 | CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_MEM_POLL) + WidthInByte), BitMask, WidthInByte);\r | |
1361 | CopyMem ((VOID*)Script, (VOID*)&ScriptMemPoll, sizeof (EFI_BOOT_SCRIPT_MEM_POLL)); \r | |
1362 | \r | |
1363 | SyncBootScript ();\r | |
1364 | \r | |
1365 | return RETURN_SUCCESS;\r | |
1366 | }\r | |
1367 | /**\r | |
1368 | Store arbitrary information in the boot script table. This opcode is a no-op on dispatch and is only\r | |
1369 | used for debugging script issues.\r | |
1370 | \r | |
1371 | @param InformationLength Length of the data in bytes\r | |
1372 | @param Information Information to be logged in the boot scrpit\r | |
1373 | \r | |
1374 | @retval RETURN_UNSUPPORTED If entering runtime, this method will not support.\r | |
1375 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1376 | @retval RETURN_SUCCESS Opcode is added.\r | |
1377 | \r | |
1378 | **/\r | |
1379 | RETURN_STATUS\r | |
1380 | EFIAPI\r | |
1381 | S3BootScriptSaveInformation (\r | |
1382 | IN UINT32 InformationLength, \r | |
1383 | IN VOID *Information\r | |
1384 | )\r | |
1385 | {\r | |
1386 | RETURN_STATUS Status;\r | |
1387 | UINT8 Length;\r | |
1388 | UINT8 *Script;\r | |
f6ec0c77 | 1389 | VOID *Buffer;\r |
64d14edf | 1390 | EFI_BOOT_SCRIPT_INFORMATION ScriptInformation;\r |
1391 | \r | |
1392 | if (mS3BootScriptTablePtr->AtRuntime) {\r | |
1393 | return RETURN_UNSUPPORTED;\r | |
1394 | }\r | |
1395 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_INFORMATION));\r | |
1396 | \r | |
f6ec0c77 JY |
1397 | //\r |
1398 | // Use BootServicesData to hold the data, just in case caller free it.\r | |
1399 | // It will be copied into ACPINvs later.\r | |
1400 | //\r | |
1401 | Status = gBS->AllocatePool (\r | |
1402 | EfiBootServicesData,\r | |
1403 | InformationLength,\r | |
64d14edf | 1404 | &Buffer\r |
1405 | );\r | |
1406 | if (EFI_ERROR (Status)) {\r | |
1407 | return RETURN_OUT_OF_RESOURCES;\r | |
1408 | }\r | |
1409 | \r | |
1410 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1411 | if (Script == NULL) {\r | |
1412 | return RETURN_OUT_OF_RESOURCES;\r | |
1413 | }\r | |
1414 | //\r | |
1415 | // Build script data\r | |
1416 | //\r | |
1417 | ScriptInformation.OpCode = EFI_BOOT_SCRIPT_INFORMATION_OPCODE;\r | |
1418 | ScriptInformation.Length = Length;\r | |
1419 | \r | |
1420 | \r | |
1421 | ScriptInformation.InformationLength = InformationLength; \r | |
1422 | \r | |
1423 | CopyMem ((VOID *)(UINTN)Buffer, Information,(UINTN) InformationLength); \r | |
1424 | ScriptInformation.Information = (EFI_PHYSICAL_ADDRESS) (UINTN) Buffer;\r | |
1425 | \r | |
1426 | CopyMem ((VOID*)Script, (VOID*)&ScriptInformation, sizeof (EFI_BOOT_SCRIPT_INFORMATION)); \r | |
1427 | return RETURN_SUCCESS;\r | |
1428 | \r | |
1429 | }\r | |
1430 | /**\r | |
1431 | Store a string in the boot script table. This opcode is a no-op on dispatch and is only\r | |
1432 | used for debugging script issues.\r | |
1433 | \r | |
1434 | @param String The string to save to boot script table\r | |
1435 | \r | |
1436 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1437 | @retval RETURN_SUCCESS Opcode is added.\r | |
1438 | \r | |
1439 | **/\r | |
1440 | RETURN_STATUS\r | |
1441 | EFIAPI\r | |
1442 | S3BootScriptSaveInformationAsciiString (\r | |
1443 | IN CONST CHAR8 *String\r | |
1444 | )\r | |
1445 | {\r | |
1446 | return S3BootScriptSaveInformation ( \r | |
1447 | (UINT32) AsciiStrLen (String) + 1, \r | |
1448 | (VOID*) String\r | |
1449 | );\r | |
1450 | }\r | |
1451 | /**\r | |
1452 | Adds a record for dispatching specified arbitrary code into a specified boot script table.\r | |
1453 | \r | |
1454 | @param EntryPoint Entry point of the code to be dispatched.\r | |
1455 | \r | |
1456 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1457 | @retval RETURN_SUCCESS Opcode is added.\r | |
1458 | **/\r | |
1459 | RETURN_STATUS\r | |
1460 | EFIAPI\r | |
1461 | S3BootScriptSaveDispatch (\r | |
1462 | IN VOID *EntryPoint\r | |
1463 | )\r | |
1464 | {\r | |
1465 | UINT8 Length;\r | |
1466 | UINT8 *Script;\r | |
1467 | EFI_BOOT_SCRIPT_DISPATCH ScriptDispatch;\r | |
1468 | \r | |
1469 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_DISPATCH));\r | |
1470 | \r | |
1471 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1472 | if (Script == NULL) {\r | |
1473 | return RETURN_OUT_OF_RESOURCES;\r | |
1474 | } \r | |
1475 | //\r | |
1476 | // Build script data\r | |
1477 | //\r | |
1478 | ScriptDispatch.OpCode = EFI_BOOT_SCRIPT_DISPATCH_OPCODE;\r | |
1479 | ScriptDispatch.Length = Length;\r | |
1480 | ScriptDispatch.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)EntryPoint;\r | |
1481 | \r | |
1482 | CopyMem ((VOID*)Script, (VOID*)&ScriptDispatch, sizeof (EFI_BOOT_SCRIPT_DISPATCH)); \r | |
1483 | \r | |
1484 | SyncBootScript ();\r | |
1485 | \r | |
1486 | return RETURN_SUCCESS;\r | |
1487 | \r | |
1488 | }\r | |
1489 | /**\r | |
1490 | Adds a record for I/O reads the I/O location and continues when the exit criteria is satisfied or after a\r | |
1491 | defined duration.\r | |
1492 | \r | |
1493 | @param Width The width of the I/O operations. \r | |
1494 | @param Address The base address of the I/O operations.\r | |
1495 | @param Data The comparison value used for the polling exit criteria.\r | |
1496 | @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero\r | |
1497 | in Data are ignored when polling the memory address.\r | |
1498 | @param Delay The number of 100ns units to poll. Note that timer available may be of poorer\r | |
1499 | granularity so the delay may be longer.\r | |
1500 | \r | |
1501 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1502 | @retval RETURN_SUCCESS Opcode is added.\r | |
1503 | \r | |
1504 | **/\r | |
1505 | RETURN_STATUS\r | |
1506 | EFIAPI\r | |
1507 | S3BootScriptSaveIoPoll (\r | |
1508 | IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r | |
1509 | IN UINT64 Address,\r | |
1510 | IN VOID *Data,\r | |
1511 | IN VOID *DataMask, \r | |
1512 | IN UINT64 Delay \r | |
1513 | )\r | |
1514 | {\r | |
1515 | UINT8 WidthInByte; \r | |
1516 | UINT8 *Script;\r | |
1517 | UINT8 Length;\r | |
1518 | EFI_BOOT_SCRIPT_IO_POLL ScriptIoPoll;\r | |
1519 | \r | |
1520 | \r | |
1521 | WidthInByte = (UINT8) (0x01 << (Width & 0x03)); \r | |
1522 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_IO_POLL) + (WidthInByte * 2));\r | |
1523 | \r | |
1524 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1525 | if (Script == NULL) {\r | |
1526 | return RETURN_OUT_OF_RESOURCES;\r | |
1527 | } \r | |
1528 | //\r | |
1529 | // Build script data\r | |
1530 | //\r | |
1531 | ScriptIoPoll.OpCode = EFI_BOOT_SCRIPT_IO_POLL_OPCODE;\r | |
1532 | ScriptIoPoll.Length = (UINT8) (sizeof (EFI_BOOT_SCRIPT_IO_POLL) + (WidthInByte * 2));\r | |
1533 | ScriptIoPoll.Width = Width; \r | |
1534 | ScriptIoPoll.Address = Address;\r | |
1535 | ScriptIoPoll.Delay = Delay;\r | |
1536 | \r | |
1537 | CopyMem ((VOID*)Script, (VOID*)&ScriptIoPoll, sizeof (EFI_BOOT_SCRIPT_IO_POLL)); \r | |
1538 | CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_IO_POLL)), Data, WidthInByte);\r | |
1539 | CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_IO_POLL) + WidthInByte), DataMask, WidthInByte);\r | |
1540 | \r | |
1541 | SyncBootScript ();\r | |
1542 | \r | |
1543 | return RETURN_SUCCESS;\r | |
1544 | }\r | |
1545 | \r | |
1546 | /**\r | |
1547 | Adds a record for PCI configuration space reads and continues when the exit criteria is satisfied or\r | |
1548 | after a defined duration.\r | |
1549 | \r | |
1550 | @param Width The width of the I/O operations. \r | |
1551 | @param Address The address within the PCI configuration space.\r | |
1552 | @param Data The comparison value used for the polling exit criteria.\r | |
1553 | @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero\r | |
1554 | in Data are ignored when polling the memory address\r | |
1555 | @param Delay The number of 100ns units to poll. Note that timer available may be of poorer\r | |
1556 | granularity so the delay may be longer.\r | |
1557 | \r | |
1558 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1559 | @retval RETURN_SUCCESS Opcode is added.\r | |
1560 | \r | |
1561 | **/\r | |
1562 | RETURN_STATUS\r | |
1563 | EFIAPI\r | |
1564 | S3BootScriptSavePciPoll (\r | |
1565 | IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r | |
1566 | IN UINT64 Address,\r | |
1567 | IN VOID *Data,\r | |
1568 | IN VOID *DataMask,\r | |
1569 | IN UINT64 Delay\r | |
1570 | )\r | |
1571 | {\r | |
1572 | UINT8 *Script;\r | |
1573 | UINT8 WidthInByte; \r | |
1574 | UINT8 Length;\r | |
1575 | EFI_BOOT_SCRIPT_PCI_CONFIG_POLL ScriptPciPoll;\r | |
1576 | \r | |
1577 | WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r | |
1578 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL) + (WidthInByte * 2));\r | |
1579 | \r | |
1580 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1581 | if (Script == NULL) {\r | |
1582 | return RETURN_OUT_OF_RESOURCES;\r | |
1583 | }\r | |
1584 | //\r | |
1585 | // Build script data\r | |
1586 | //\r | |
1587 | ScriptPciPoll.OpCode = EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE;\r | |
1588 | ScriptPciPoll.Length = (UINT8) (sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL) + (WidthInByte * 2));\r | |
1589 | ScriptPciPoll.Width = Width; \r | |
1590 | ScriptPciPoll.Address = Address;\r | |
1591 | ScriptPciPoll.Delay = Delay;\r | |
1592 | \r | |
1593 | CopyMem ((VOID*)Script, (VOID*)&ScriptPciPoll, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL));\r | |
1594 | CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL)), Data, WidthInByte);\r | |
1595 | CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL) + WidthInByte), DataMask, WidthInByte);\r | |
1596 | \r | |
1597 | SyncBootScript ();\r | |
1598 | \r | |
1599 | return RETURN_SUCCESS;\r | |
1600 | }\r | |
1601 | /**\r | |
1602 | Adds a record for PCI configuration space reads and continues when the exit criteria is satisfied or\r | |
1603 | after a defined duration.\r | |
1604 | \r | |
1605 | @param Width The width of the I/O operations. \r | |
1606 | @param Segment The PCI segment number for Address.\r | |
1607 | @param Address The address within the PCI configuration space.\r | |
1608 | @param Data The comparison value used for the polling exit criteria.\r | |
1609 | @param DataMask Mask used for the polling criteria. The bits in the bytes below Width which are zero\r | |
1610 | in Data are ignored when polling the memory address\r | |
1611 | @param Delay The number of 100ns units to poll. Note that timer available may be of poorer\r | |
1612 | granularity so the delay may be longer.\r | |
1613 | \r | |
1614 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1615 | @retval RETURN_SUCCESS Opcode is added.\r | |
1616 | @note A known Limitations in the implementation: When interpreting the opcode EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE\r | |
1617 | EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE and EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE, the 'Segment' parameter is assumed as \r | |
1618 | Zero, or else, assert.\r | |
1619 | **/\r | |
1620 | RETURN_STATUS\r | |
1621 | EFIAPI\r | |
1622 | S3BootScriptSavePci2Poll (\r | |
1623 | IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r | |
1624 | IN UINT16 Segment,\r | |
1625 | IN UINT64 Address,\r | |
1626 | IN VOID *Data,\r | |
1627 | IN VOID *DataMask,\r | |
1628 | IN UINT64 Delay\r | |
1629 | )\r | |
1630 | {\r | |
1631 | UINT8 WidthInByte; \r | |
1632 | UINT8 *Script;\r | |
1633 | UINT8 Length;\r | |
1634 | EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL ScriptPci2Poll;\r | |
1635 | \r | |
1636 | WidthInByte = (UINT8) (0x01 << (Width & 0x03));\r | |
1637 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL) + (WidthInByte * 2));\r | |
1638 | \r | |
1639 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1640 | if (Script == NULL) {\r | |
1641 | return RETURN_OUT_OF_RESOURCES;\r | |
1642 | } \r | |
1643 | //\r | |
1644 | // Build script data\r | |
1645 | //\r | |
1646 | ScriptPci2Poll.OpCode = EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE;\r | |
1647 | ScriptPci2Poll.Length = (UINT8) (sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL) + (WidthInByte * 2));\r | |
1648 | ScriptPci2Poll.Width = Width; \r | |
1649 | ScriptPci2Poll.Segment = Segment;\r | |
1650 | ScriptPci2Poll.Address = Address;\r | |
1651 | ScriptPci2Poll.Delay = Delay;\r | |
1652 | \r | |
1653 | CopyMem ((VOID*)Script, (VOID*)&ScriptPci2Poll, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL));\r | |
1654 | CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL)), Data, WidthInByte);\r | |
1655 | CopyMem ((UINT8 *) (Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL) + WidthInByte), DataMask, WidthInByte);\r | |
1656 | \r | |
1657 | SyncBootScript ();\r | |
1658 | \r | |
1659 | return RETURN_SUCCESS;\r | |
1660 | }\r | |
1661 | /**\r | |
1662 | Do the calculation of start address from which a new s3 boot script entry will write into.\r | |
1663 | \r | |
1664 | @param EntryLength The new entry length.\r | |
1665 | @param Position specifies the position in the boot script table where the opcode will be\r | |
1666 | inserted, either before or after, depending on BeforeOrAfter. \r | |
1667 | @param BeforeOrAfter The flag to indicate to insert the nod before or after the position.\r | |
1668 | This parameter is effective when InsertFlag is TRUE\r | |
1669 | @param Script return out the position from which the a new s3 boot script entry will write into\r | |
1670 | **/\r | |
1671 | VOID\r | |
1672 | S3BootScriptCalculateInsertAddress (\r | |
1673 | IN UINT8 EntryLength,\r | |
1674 | IN VOID *Position OPTIONAL,\r | |
1675 | IN BOOLEAN BeforeOrAfter OPTIONAL,\r | |
1676 | OUT UINT8 **Script \r | |
1677 | )\r | |
1678 | {\r | |
1679 | UINTN TableLength;\r | |
1680 | UINT8 *S3TableBase;\r | |
1681 | UINTN PositionOffset; \r | |
1682 | EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader;\r | |
1683 | //\r | |
1684 | // The entry inserting to table is already added to the end of the table\r | |
1685 | //\r | |
1686 | TableLength = mS3BootScriptTablePtr->TableLength - EntryLength;\r | |
1687 | S3TableBase = mS3BootScriptTablePtr->TableBase ;\r | |
1688 | // \r | |
1689 | // calculate the Position offset\r | |
1690 | //\r | |
1691 | if (Position != NULL) {\r | |
1692 | PositionOffset = (UINTN) ((UINT8 *)Position - S3TableBase);\r | |
1693 | \r | |
1694 | //\r | |
1695 | // If the BeforeOrAfter is FALSE, that means to insert the node right after the node.\r | |
1696 | //\r | |
1697 | if (!BeforeOrAfter) {\r | |
1698 | CopyMem ((VOID*)&ScriptHeader, Position, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER)); \r | |
1699 | PositionOffset += (ScriptHeader.Length);\r | |
1700 | }\r | |
1701 | // \r | |
1702 | // Insert the node before the adjusted Position\r | |
1703 | //\r | |
1704 | CopyMem (S3TableBase+PositionOffset+EntryLength, S3TableBase+PositionOffset, TableLength - PositionOffset); \r | |
1705 | //\r | |
1706 | // calculate the the start address for the new entry. \r | |
1707 | //\r | |
1708 | *Script = S3TableBase + PositionOffset;\r | |
1709 | \r | |
1710 | } else {\r | |
1711 | if (!BeforeOrAfter) {\r | |
1712 | //\r | |
1713 | // Insert the node to the end of the table\r | |
1714 | //\r | |
1715 | *Script = S3TableBase + TableLength; \r | |
1716 | } else {\r | |
1717 | // \r | |
1718 | // Insert the node to the beginning of the table\r | |
1719 | //\r | |
1720 | PositionOffset = (UINTN) sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER);\r | |
1721 | CopyMem (S3TableBase+PositionOffset+EntryLength, S3TableBase+PositionOffset, TableLength - PositionOffset); \r | |
1722 | *Script = S3TableBase + PositionOffset; \r | |
1723 | }\r | |
1724 | } \r | |
1725 | }\r | |
1726 | /**\r | |
1727 | Move the last boot script entry to the position \r | |
1728 | \r | |
1729 | @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position\r | |
1730 | in the boot script table specified by Position. If Position is NULL or points to\r | |
1731 | NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end\r | |
1732 | of the table (if FALSE).\r | |
1733 | @param Position On entry, specifies the position in the boot script table where the opcode will be\r | |
1734 | inserted, either before or after, depending on BeforeOrAfter. On exit, specifies\r | |
1735 | the position of the inserted opcode in the boot script table.\r | |
1736 | \r | |
1737 | @retval RETURN_OUT_OF_RESOURCES The table is not available.\r | |
1738 | @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the boot script table.\r | |
1739 | @retval RETURN_SUCCESS Opcode is inserted.\r | |
1740 | **/\r | |
1741 | RETURN_STATUS\r | |
1742 | EFIAPI\r | |
1743 | S3BootScriptMoveLastOpcode (\r | |
1744 | IN BOOLEAN BeforeOrAfter,\r | |
1745 | IN OUT VOID **Position OPTIONAL\r | |
1746 | )\r | |
1747 | {\r | |
1748 | UINT8* Script;\r | |
1749 | VOID *TempPosition; \r | |
1750 | UINTN StartAddress;\r | |
1751 | UINT32 TableLength;\r | |
1752 | EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader;\r | |
1753 | BOOLEAN ValidatePosition;\r | |
1754 | UINT8* LastOpcode;\r | |
1755 | UINT8 TempBootScriptEntry[BOOT_SCRIPT_NODE_MAX_LENGTH];\r | |
1756 | \r | |
1757 | ValidatePosition = FALSE;\r | |
1758 | TempPosition = (Position == NULL) ? NULL:(*Position);\r | |
1759 | Script = mS3BootScriptTablePtr->TableBase;\r | |
1760 | if (Script == 0) { \r | |
1761 | return EFI_OUT_OF_RESOURCES;\r | |
1762 | }\r | |
1763 | StartAddress = (UINTN) Script;\r | |
1764 | TableLength = mS3BootScriptTablePtr->TableLength;\r | |
1765 | Script = Script + sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER);\r | |
1766 | LastOpcode = Script;\r | |
1767 | //\r | |
1768 | // Find the last boot Script Entry which is not the terminate node\r | |
1769 | //\r | |
1770 | while ((UINTN) Script < (UINTN) (StartAddress + TableLength)) { \r | |
1771 | CopyMem ((VOID*)&ScriptHeader, Script, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER)); \r | |
1772 | if (TempPosition != NULL && TempPosition == Script) {\r | |
1773 | //\r | |
1774 | // If the position is specified, the position must be pointed to a boot script entry start address. \r | |
1775 | //\r | |
1776 | ValidatePosition = TRUE;\r | |
1777 | }\r | |
1778 | if (ScriptHeader.OpCode != S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE) {\r | |
1779 | LastOpcode = Script;\r | |
1780 | } \r | |
1781 | Script = Script + ScriptHeader.Length;\r | |
1782 | }\r | |
1783 | //\r | |
1784 | // If the position is specified, but not the start of a boot script entry, it is a invalid input\r | |
1785 | //\r | |
1786 | if (TempPosition != NULL && !ValidatePosition) {\r | |
1787 | return RETURN_INVALID_PARAMETER;\r | |
1788 | }\r | |
1789 | \r | |
1790 | CopyMem ((VOID*)&ScriptHeader, LastOpcode, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER)); \r | |
1791 | \r | |
1792 | CopyMem((VOID*)TempBootScriptEntry, LastOpcode, ScriptHeader.Length); \r | |
1793 | //\r | |
1794 | // Find the right position to write the node in\r | |
1795 | //\r | |
1796 | S3BootScriptCalculateInsertAddress (\r | |
1797 | ScriptHeader.Length,\r | |
1798 | TempPosition,\r | |
1799 | BeforeOrAfter,\r | |
1800 | &Script \r | |
1801 | );\r | |
1802 | //\r | |
1803 | // Copy the node to Boot script table\r | |
1804 | //\r | |
1805 | CopyMem((VOID*)Script, (VOID*)TempBootScriptEntry, ScriptHeader.Length); \r | |
1806 | //\r | |
1807 | // return out the Position\r | |
1808 | //\r | |
1809 | if (Position != NULL) {\r | |
1810 | *Position = Script;\r | |
1811 | }\r | |
1812 | return RETURN_SUCCESS;\r | |
1813 | }\r | |
1814 | /**\r | |
1815 | Create a Label node in the boot script table. \r | |
1816 | \r | |
1817 | @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE) or after (FALSE) the position\r | |
1818 | in the boot script table specified by Position. If Position is NULL or points to\r | |
1819 | NULL then the new opcode is inserted at the beginning of the table (if TRUE) or end\r | |
1820 | of the table (if FALSE).\r | |
1821 | @param Position On entry, specifies the position in the boot script table where the opcode will be\r | |
1822 | inserted, either before or after, depending on BeforeOrAfter. On exit, specifies\r | |
1823 | the position of the inserted opcode in the boot script table. \r | |
1824 | @param InformationLength Length of the label in bytes\r | |
1825 | @param Information Label to be logged in the boot scrpit\r | |
1826 | \r | |
1827 | @retval RETURN_INVALID_PARAMETER The Position is not a valid position in the boot script table.\r | |
1828 | @retval RETURN_OUT_OF_RESOURCES Not enough memory for the table do operation.\r | |
1829 | @retval RETURN_SUCCESS Opcode is added.\r | |
1830 | \r | |
1831 | **/\r | |
1832 | RETURN_STATUS\r | |
1833 | EFIAPI\r | |
1834 | S3BootScriptLabelInternal (\r | |
1835 | IN BOOLEAN BeforeOrAfter,\r | |
1836 | IN OUT VOID **Position OPTIONAL, \r | |
1837 | IN UINT32 InformationLength, \r | |
1838 | IN CONST CHAR8 *Information\r | |
1839 | )\r | |
1840 | {\r | |
1841 | UINT8 Length;\r | |
1842 | UINT8 *Script;\r | |
1843 | VOID *Buffer;\r | |
1844 | EFI_BOOT_SCRIPT_INFORMATION ScriptInformation;\r | |
1845 | \r | |
1846 | Length = (UINT8)(sizeof (EFI_BOOT_SCRIPT_INFORMATION) + InformationLength);\r | |
1847 | \r | |
1848 | Script = S3BootScriptGetEntryAddAddress (Length);\r | |
1849 | if (Script == NULL) {\r | |
1850 | return RETURN_OUT_OF_RESOURCES;\r | |
1851 | }\r | |
1852 | Buffer = Script + sizeof (EFI_BOOT_SCRIPT_INFORMATION);\r | |
1853 | //\r | |
1854 | // Build script data\r | |
1855 | //\r | |
1856 | ScriptInformation.OpCode = S3_BOOT_SCRIPT_LIB_LABEL_OPCODE;\r | |
1857 | ScriptInformation.Length = Length;\r | |
1858 | \r | |
1859 | \r | |
1860 | ScriptInformation.InformationLength = InformationLength; \r | |
1861 | \r | |
1862 | AsciiStrnCpy (Buffer, Information,(UINTN) InformationLength); \r | |
1863 | ScriptInformation.Information = (EFI_PHYSICAL_ADDRESS) (UINTN) Buffer;\r | |
1864 | \r | |
1865 | CopyMem ((VOID*)Script, (VOID*)&ScriptInformation, sizeof (EFI_BOOT_SCRIPT_INFORMATION)); \r | |
1866 | \r | |
1867 | return S3BootScriptMoveLastOpcode (BeforeOrAfter, Position);\r | |
1868 | \r | |
1869 | }\r | |
1870 | /**\r | |
1871 | Find a label within the boot script table and, if not present, optionally create it.\r | |
1872 | \r | |
1873 | @param BeforeOrAfter Specifies whether the opcode is stored before (TRUE)\r | |
1874 | or after (FALSE) the position in the boot script table \r | |
1875 | specified by Position.\r | |
1876 | @param CreateIfNotFound Specifies whether the label will be created if the label \r | |
1877 | does not exists (TRUE) or not (FALSE).\r | |
1878 | @param Position On entry, specifies the position in the boot script table\r | |
1879 | where the opcode will be inserted, either before or after,\r | |
1880 | depending on BeforeOrAfter. On exit, specifies the position\r | |
1881 | of the inserted opcode in the boot script table.\r | |
1882 | @param Label Points to the label which will be inserted in the boot script table.\r | |
1883 | \r | |
1884 | @retval EFI_SUCCESS The operation succeeded. A record was added into the\r | |
1885 | specified script table.\r | |
1886 | @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.\r | |
1887 | If the opcode is unknow or not supported because of the PCD \r | |
1888 | Feature Flags.\r | |
1889 | @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.\r | |
1890 | \r | |
1891 | **/\r | |
1892 | RETURN_STATUS\r | |
1893 | EFIAPI \r | |
1894 | S3BootScriptLabel (\r | |
1895 | IN BOOLEAN BeforeOrAfter,\r | |
1896 | IN BOOLEAN CreateIfNotFound,\r | |
1897 | IN OUT VOID **Position OPTIONAL,\r | |
1898 | IN CONST CHAR8 *Label\r | |
1899 | )\r | |
1900 | {\r | |
1901 | UINT8* Script;\r | |
1902 | UINTN StartAddress;\r | |
1903 | UINT32 TableLength;\r | |
1904 | EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader;\r | |
1905 | EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader;\r | |
1906 | UINT32 LabelLength;\r | |
1907 | //\r | |
96072947 | 1908 | // Check NULL Label\r |
64d14edf | 1909 | //\r |
96072947 JY |
1910 | if (Label == NULL) {\r |
1911 | return EFI_INVALID_PARAMETER;\r | |
1912 | }\r | |
1913 | //\r | |
1914 | // Check empty Label\r | |
1915 | //\r | |
1916 | if (Label[0] == '\0') {\r | |
64d14edf | 1917 | return EFI_INVALID_PARAMETER;\r |
1918 | }\r | |
1919 | \r | |
1920 | //\r | |
1921 | // Check that the script is initialized without adding an entry to the script.\r | |
1922 | // The code must search for the label first befor it knows if a new entry needs\r | |
1923 | // to be added.\r | |
1924 | //\r | |
1925 | Script = S3BootScriptGetEntryAddAddress (0);\r | |
1926 | if (Script == NULL) {\r | |
1927 | return RETURN_OUT_OF_RESOURCES;\r | |
1928 | }\r | |
1929 | \r | |
1930 | //\r | |
1931 | // Check the header and search for existing label.\r | |
1932 | // \r | |
1933 | Script = mS3BootScriptTablePtr->TableBase;\r | |
1934 | CopyMem ((VOID*)&TableHeader, Script, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER));\r | |
1935 | if (TableHeader.OpCode != S3_BOOT_SCRIPT_LIB_TABLE_OPCODE) {\r | |
1936 | return EFI_INVALID_PARAMETER;\r | |
1937 | }\r | |
1938 | StartAddress = (UINTN) Script;\r | |
1939 | TableLength = mS3BootScriptTablePtr->TableLength;\r | |
1940 | Script = Script + TableHeader.Length;\r | |
1941 | while ((UINTN) Script < (UINTN) (StartAddress + TableLength)) {\r | |
1942 | \r | |
1943 | CopyMem ((VOID*)&ScriptHeader, Script, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER)); \r | |
1944 | if (ScriptHeader.OpCode == S3_BOOT_SCRIPT_LIB_LABEL_OPCODE) {\r | |
1945 | if (AsciiStrCmp ((CHAR8 *)(UINTN)(Script+sizeof(EFI_BOOT_SCRIPT_INFORMATION)), Label) == 0) {\r | |
1946 | (*Position) = Script; \r | |
1947 | return EFI_SUCCESS;\r | |
1948 | }\r | |
1949 | } \r | |
1950 | Script = Script + ScriptHeader.Length;\r | |
1951 | }\r | |
1952 | if (CreateIfNotFound) {\r | |
1953 | LabelLength = (UINT32)AsciiStrSize(Label);\r | |
1954 | return S3BootScriptLabelInternal (BeforeOrAfter,Position, LabelLength, Label); \r | |
1955 | } else {\r | |
1956 | return EFI_NOT_FOUND;\r | |
1957 | } \r | |
1958 | }\r | |
1959 | \r | |
1960 | /**\r | |
1961 | Compare two positions in the boot script table and return their relative position.\r | |
1962 | @param Position1 The positions in the boot script table to compare\r | |
1963 | @param Position2 The positions in the boot script table to compare\r | |
1964 | @param RelativePosition On return, points to the result of the comparison\r | |
1965 | \r | |
1966 | @retval EFI_SUCCESS The operation succeeded. A record was added into the\r | |
1967 | specified script table.\r | |
1968 | @retval EFI_INVALID_PARAMETER The parameter is illegal or the given boot script is not supported.\r | |
1969 | If the opcode is unknow or not supported because of the PCD \r | |
1970 | Feature Flags.\r | |
1971 | @retval EFI_OUT_OF_RESOURCES There is insufficient memory to store the boot script.\r | |
1972 | \r | |
1973 | **/\r | |
1974 | RETURN_STATUS\r | |
1975 | EFIAPI \r | |
1976 | S3BootScriptCompare (\r | |
1977 | IN UINT8 *Position1,\r | |
1978 | IN UINT8 *Position2,\r | |
1979 | OUT UINTN *RelativePosition\r | |
1980 | )\r | |
1981 | {\r | |
1982 | UINT8* Script;\r | |
1983 | UINT32 TableLength; \r | |
1984 | \r | |
1985 | Script = mS3BootScriptTablePtr->TableBase;\r | |
1986 | if (Script == NULL) {\r | |
1987 | return EFI_OUT_OF_RESOURCES;\r | |
1988 | }\r | |
1989 | if (RelativePosition == NULL) {\r | |
1990 | return EFI_INVALID_PARAMETER;\r | |
1991 | }\r | |
1992 | TableLength = ((EFI_BOOT_SCRIPT_TABLE_HEADER*)Script)->TableLength;\r | |
1993 | //\r | |
1994 | // If in boot time, TableLength does not include the termination node. so add it up \r | |
1995 | //\r | |
1996 | if (!mS3BootScriptTablePtr->AtRuntime) {\r | |
1997 | TableLength += sizeof(EFI_BOOT_SCRIPT_TERMINATE);\r | |
1998 | }\r | |
1999 | if (Position1 < Script || Position1 > Script+TableLength) {\r | |
2000 | return EFI_INVALID_PARAMETER;\r | |
2001 | }\r | |
2002 | if (Position2 < Script || Position2 > Script+TableLength) {\r | |
2003 | return EFI_INVALID_PARAMETER;\r | |
2004 | }\r | |
2005 | *RelativePosition = (Position1 < Position2)?-1:((Position1 == Position2)?0:1);\r | |
2006 | \r | |
2007 | return EFI_SUCCESS;\r | |
2008 | }\r | |
2009 | \r |