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