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