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