]>
Commit | Line | Data |
---|---|---|
1c837cd5 | 1 | /** @file\r |
2 | \r | |
da9d39c2 | 3 | Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>\r |
1c837cd5 | 4 | \r |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions\r | |
7 | of the BSD License which accompanies this distribution. The\r | |
8 | full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include <PiSmm.h>\r | |
17 | #include <Library/SmmServicesTableLib.h>\r | |
18 | #include <Library/BaseLib.h>\r | |
19 | #include <Library/BaseMemoryLib.h>\r | |
20 | #include <Library/LockBoxLib.h>\r | |
21 | #include <Library/DebugLib.h>\r | |
22 | #include <Guid/SmmLockBox.h>\r | |
23 | \r | |
24 | #include "SmmLockBoxLibPrivate.h"\r | |
25 | \r | |
26 | /**\r | |
27 | We need handle this library carefully. Only one library instance will construct the environment.\r | |
28 | Below 2 global variable can only be used in constructor. They should NOT be used in any other library functions.\r | |
29 | **/\r | |
30 | SMM_LOCK_BOX_CONTEXT mSmmLockBoxContext;\r | |
31 | LIST_ENTRY mLockBoxQueue = INITIALIZE_LIST_HEAD_VARIABLE (mLockBoxQueue);\r | |
32 | \r | |
738df706 SZ |
33 | BOOLEAN mSmmConfigurationTableInstalled = FALSE;\r |
34 | \r | |
1c837cd5 | 35 | /**\r |
36 | This function return SmmLockBox context from SMST.\r | |
37 | \r | |
38 | @return SmmLockBox context from SMST.\r | |
39 | **/\r | |
40 | SMM_LOCK_BOX_CONTEXT *\r | |
41 | InternalGetSmmLockBoxContext (\r | |
42 | VOID\r | |
43 | )\r | |
44 | {\r | |
45 | UINTN Index;\r | |
46 | \r | |
47 | //\r | |
48 | // Check if gEfiSmmLockBoxCommunicationGuid is installed by someone\r | |
49 | //\r | |
50 | for (Index = 0; Index < gSmst->NumberOfTableEntries; Index++) {\r | |
51 | if (CompareGuid (&gSmst->SmmConfigurationTable[Index].VendorGuid, &gEfiSmmLockBoxCommunicationGuid)) {\r | |
52 | //\r | |
53 | // Found. That means some other library instance is already run.\r | |
54 | // No need to install again, just return.\r | |
55 | //\r | |
56 | return (SMM_LOCK_BOX_CONTEXT *)gSmst->SmmConfigurationTable[Index].VendorTable;\r | |
57 | }\r | |
58 | }\r | |
59 | \r | |
60 | //\r | |
61 | // Not found.\r | |
62 | //\r | |
63 | return NULL;\r | |
64 | }\r | |
65 | \r | |
66 | /**\r | |
67 | Constructor for SmmLockBox library.\r | |
68 | This is used to set SmmLockBox context, which will be used in PEI phase in S3 boot path later.\r | |
69 | \r | |
70 | @param[in] ImageHandle Image handle of this driver.\r | |
71 | @param[in] SystemTable A Pointer to the EFI System Table.\r | |
72 | \r | |
73 | @retval EFI_SUCEESS \r | |
74 | @return Others Some error occurs.\r | |
75 | **/\r | |
76 | EFI_STATUS\r | |
77 | EFIAPI\r | |
da9d39c2 | 78 | SmmLockBoxSmmConstructor (\r |
1c837cd5 | 79 | IN EFI_HANDLE ImageHandle,\r |
80 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
81 | )\r | |
82 | {\r | |
83 | EFI_STATUS Status;\r | |
84 | SMM_LOCK_BOX_CONTEXT *SmmLockBoxContext;\r | |
85 | \r | |
da9d39c2 | 86 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmConstructor - Enter\n"));\r |
1c837cd5 | 87 | \r |
88 | //\r | |
89 | // Check if gEfiSmmLockBoxCommunicationGuid is installed by someone\r | |
90 | //\r | |
91 | SmmLockBoxContext = InternalGetSmmLockBoxContext ();\r | |
92 | if (SmmLockBoxContext != NULL) {\r | |
93 | //\r | |
94 | // Find it. That means some other library instance is already run.\r | |
95 | // No need to install again, just return.\r | |
96 | //\r | |
97 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SmmLockBoxContext - already installed\n"));\r | |
da9d39c2 | 98 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmConstructor - Exit\n"));\r |
1c837cd5 | 99 | return EFI_SUCCESS;\r |
100 | }\r | |
101 | \r | |
102 | //\r | |
103 | // If no one install this, it means this is first instance. Install it.\r | |
104 | //\r | |
105 | if (sizeof(UINTN) == sizeof(UINT64)) {\r | |
106 | mSmmLockBoxContext.Signature = SMM_LOCK_BOX_SIGNATURE_64;\r | |
107 | } else {\r | |
108 | mSmmLockBoxContext.Signature = SMM_LOCK_BOX_SIGNATURE_32;\r | |
109 | }\r | |
110 | mSmmLockBoxContext.LockBoxDataAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)&mLockBoxQueue;\r | |
111 | \r | |
112 | Status = gSmst->SmmInstallConfigurationTable (\r | |
113 | gSmst,\r | |
114 | &gEfiSmmLockBoxCommunicationGuid,\r | |
115 | &mSmmLockBoxContext,\r | |
116 | sizeof(mSmmLockBoxContext)\r | |
117 | );\r | |
118 | ASSERT_EFI_ERROR (Status);\r | |
738df706 | 119 | mSmmConfigurationTableInstalled = TRUE;\r |
1c837cd5 | 120 | \r |
121 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SmmLockBoxContext - %x\n", (UINTN)&mSmmLockBoxContext));\r | |
122 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib LockBoxDataAddress - %x\n", (UINTN)&mLockBoxQueue));\r | |
da9d39c2 | 123 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmConstructor - Exit\n"));\r |
1c837cd5 | 124 | \r |
125 | return Status;\r | |
126 | }\r | |
127 | \r | |
738df706 SZ |
128 | /**\r |
129 | Destructor for SmmLockBox library.\r | |
130 | This is used to uninstall SmmLockBoxCommunication configuration table\r | |
131 | if it has been installed in Constructor.\r | |
132 | \r | |
133 | @param[in] ImageHandle Image handle of this driver.\r | |
134 | @param[in] SystemTable A Pointer to the EFI System Table.\r | |
135 | \r | |
136 | @retval EFI_SUCEESS The destructor always returns EFI_SUCCESS.\r | |
137 | \r | |
138 | **/\r | |
139 | EFI_STATUS\r | |
140 | EFIAPI\r | |
141 | SmmLockBoxSmmDestructor (\r | |
142 | IN EFI_HANDLE ImageHandle,\r | |
143 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
144 | )\r | |
145 | {\r | |
146 | EFI_STATUS Status;\r | |
147 | \r | |
148 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmDestructor in %a module\n", gEfiCallerBaseName));\r | |
149 | \r | |
150 | if (mSmmConfigurationTableInstalled) {\r | |
151 | Status = gSmst->SmmInstallConfigurationTable (\r | |
152 | gSmst,\r | |
153 | &gEfiSmmLockBoxCommunicationGuid,\r | |
154 | NULL,\r | |
155 | 0\r | |
156 | );\r | |
157 | ASSERT_EFI_ERROR (Status);\r | |
158 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib uninstall SmmLockBoxCommunication configuration table\n"));\r | |
159 | }\r | |
160 | \r | |
161 | return EFI_SUCCESS;\r | |
162 | }\r | |
163 | \r | |
1c837cd5 | 164 | /**\r |
165 | This function return SmmLockBox queue address.\r | |
166 | \r | |
167 | @return SmmLockBox queue address.\r | |
168 | **/\r | |
169 | LIST_ENTRY *\r | |
170 | InternalGetLockBoxQueue (\r | |
171 | VOID\r | |
172 | )\r | |
173 | {\r | |
174 | SMM_LOCK_BOX_CONTEXT *SmmLockBoxContext;\r | |
175 | \r | |
176 | SmmLockBoxContext = InternalGetSmmLockBoxContext ();\r | |
177 | ASSERT (SmmLockBoxContext != NULL);\r | |
178 | if (SmmLockBoxContext == NULL) {\r | |
179 | return NULL;\r | |
180 | }\r | |
181 | return (LIST_ENTRY *)(UINTN)SmmLockBoxContext->LockBoxDataAddress;\r | |
182 | }\r | |
183 | \r | |
184 | /**\r | |
185 | This function find LockBox by GUID.\r | |
186 | \r | |
187 | @param Guid The guid to indentify the LockBox\r | |
188 | \r | |
189 | @return LockBoxData\r | |
190 | **/\r | |
191 | SMM_LOCK_BOX_DATA *\r | |
192 | InternalFindLockBoxByGuid (\r | |
193 | IN EFI_GUID *Guid\r | |
194 | )\r | |
195 | {\r | |
196 | LIST_ENTRY *Link;\r | |
197 | SMM_LOCK_BOX_DATA *LockBox;\r | |
198 | LIST_ENTRY *LockBoxQueue;\r | |
199 | \r | |
200 | LockBoxQueue = InternalGetLockBoxQueue ();\r | |
201 | ASSERT (LockBoxQueue != NULL);\r | |
202 | \r | |
203 | for (Link = LockBoxQueue->ForwardLink;\r | |
204 | Link != LockBoxQueue;\r | |
205 | Link = Link->ForwardLink) {\r | |
206 | LockBox = BASE_CR (\r | |
207 | Link,\r | |
208 | SMM_LOCK_BOX_DATA,\r | |
209 | Link\r | |
210 | );\r | |
211 | if (CompareGuid (&LockBox->Guid, Guid)) {\r | |
212 | return LockBox;\r | |
213 | }\r | |
214 | }\r | |
215 | return NULL;\r | |
216 | }\r | |
217 | \r | |
218 | /**\r | |
219 | This function will save confidential information to lockbox.\r | |
220 | \r | |
221 | @param Guid the guid to identify the confidential information\r | |
222 | @param Buffer the address of the confidential information\r | |
223 | @param Length the length of the confidential information\r | |
224 | \r | |
225 | @retval RETURN_SUCCESS the information is saved successfully.\r | |
226 | @retval RETURN_INVALID_PARAMETER the Guid is NULL, or Buffer is NULL, or Length is 0\r | |
227 | @retval RETURN_ALREADY_STARTED the requested GUID already exist.\r | |
228 | @retval RETURN_OUT_OF_RESOURCES no enough resource to save the information.\r | |
229 | @retval RETURN_ACCESS_DENIED it is too late to invoke this interface\r | |
230 | @retval RETURN_NOT_STARTED it is too early to invoke this interface\r | |
231 | @retval RETURN_UNSUPPORTED the service is not supported by implementaion.\r | |
232 | **/\r | |
233 | RETURN_STATUS\r | |
234 | EFIAPI\r | |
235 | SaveLockBox (\r | |
236 | IN GUID *Guid,\r | |
237 | IN VOID *Buffer,\r | |
238 | IN UINTN Length\r | |
239 | )\r | |
240 | {\r | |
241 | SMM_LOCK_BOX_DATA *LockBox;\r | |
242 | EFI_PHYSICAL_ADDRESS SmramBuffer;\r | |
243 | EFI_STATUS Status;\r | |
244 | LIST_ENTRY *LockBoxQueue;\r | |
245 | \r | |
246 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SaveLockBox - Enter\n"));\r | |
247 | \r | |
248 | //\r | |
249 | // Basic check\r | |
250 | //\r | |
251 | if ((Guid == NULL) || (Buffer == NULL) || (Length == 0)) {\r | |
252 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_INVALID_PARAMETER));\r | |
253 | return EFI_INVALID_PARAMETER;\r | |
254 | }\r | |
255 | \r | |
256 | //\r | |
257 | // Find LockBox\r | |
258 | //\r | |
259 | LockBox = InternalFindLockBoxByGuid (Guid);\r | |
260 | if (LockBox != NULL) {\r | |
261 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_ALREADY_STARTED));\r | |
262 | return EFI_ALREADY_STARTED;\r | |
263 | }\r | |
264 | \r | |
265 | //\r | |
266 | // Allocate SMRAM buffer\r | |
267 | //\r | |
268 | Status = gSmst->SmmAllocatePages (\r | |
269 | AllocateAnyPages,\r | |
270 | EfiRuntimeServicesData,\r | |
271 | EFI_SIZE_TO_PAGES (Length),\r | |
272 | &SmramBuffer\r | |
273 | );\r | |
274 | ASSERT_EFI_ERROR (Status);\r | |
275 | if (EFI_ERROR (Status)) {\r | |
276 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_OUT_OF_RESOURCES));\r | |
277 | return EFI_OUT_OF_RESOURCES;\r | |
278 | }\r | |
279 | \r | |
280 | //\r | |
281 | // Allocate LockBox\r | |
282 | //\r | |
283 | Status = gSmst->SmmAllocatePool (\r | |
284 | EfiRuntimeServicesData,\r | |
285 | sizeof(*LockBox),\r | |
286 | (VOID **)&LockBox\r | |
287 | );\r | |
288 | ASSERT_EFI_ERROR (Status);\r | |
289 | if (EFI_ERROR (Status)) {\r | |
290 | gSmst->SmmFreePages (SmramBuffer, EFI_SIZE_TO_PAGES (Length));\r | |
291 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_OUT_OF_RESOURCES));\r | |
292 | return EFI_OUT_OF_RESOURCES;\r | |
293 | }\r | |
294 | \r | |
295 | //\r | |
296 | // Save data\r | |
297 | //\r | |
298 | CopyMem ((VOID *)(UINTN)SmramBuffer, (VOID *)(UINTN)Buffer, Length);\r | |
299 | \r | |
300 | //\r | |
301 | // Insert LockBox to queue\r | |
302 | //\r | |
303 | LockBox->Signature = SMM_LOCK_BOX_DATA_SIGNATURE;\r | |
304 | CopyMem (&LockBox->Guid, Guid, sizeof(EFI_GUID));\r | |
305 | LockBox->Buffer = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer;\r | |
306 | LockBox->Length = (UINT64)Length;\r | |
05ca95e2 | 307 | LockBox->Attributes = 0;\r |
1c837cd5 | 308 | LockBox->SmramBuffer = SmramBuffer;\r |
ef96ba3c SZ |
309 | \r |
310 | DEBUG ((\r | |
311 | EFI_D_INFO,\r | |
312 | "LockBoxGuid - %g, SmramBuffer - 0x%lx, Length - 0x%lx\n",\r | |
313 | &LockBox->Guid,\r | |
314 | LockBox->SmramBuffer,\r | |
315 | LockBox->Length\r | |
316 | ));\r | |
317 | \r | |
1c837cd5 | 318 | LockBoxQueue = InternalGetLockBoxQueue ();\r |
319 | ASSERT (LockBoxQueue != NULL);\r | |
320 | InsertTailList (LockBoxQueue, &LockBox->Link);\r | |
321 | \r | |
322 | //\r | |
323 | // Done\r | |
324 | //\r | |
325 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_SUCCESS));\r | |
326 | return EFI_SUCCESS;\r | |
327 | }\r | |
328 | \r | |
329 | /**\r | |
330 | This function will set lockbox attributes.\r | |
331 | \r | |
332 | @param Guid the guid to identify the confidential information\r | |
333 | @param Attributes the attributes of the lockbox\r | |
334 | \r | |
335 | @retval RETURN_SUCCESS the information is saved successfully.\r | |
336 | @retval RETURN_INVALID_PARAMETER attributes is invalid.\r | |
337 | @retval RETURN_NOT_FOUND the requested GUID not found.\r | |
338 | @retval RETURN_ACCESS_DENIED it is too late to invoke this interface\r | |
339 | @retval RETURN_NOT_STARTED it is too early to invoke this interface\r | |
340 | @retval RETURN_UNSUPPORTED the service is not supported by implementaion.\r | |
341 | **/\r | |
342 | RETURN_STATUS\r | |
343 | EFIAPI\r | |
344 | SetLockBoxAttributes (\r | |
345 | IN GUID *Guid,\r | |
346 | IN UINT64 Attributes\r | |
347 | )\r | |
348 | {\r | |
349 | SMM_LOCK_BOX_DATA *LockBox;\r | |
350 | \r | |
351 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SetLockBoxAttributes - Enter\n"));\r | |
352 | \r | |
353 | //\r | |
354 | // Basic check\r | |
355 | //\r | |
356 | if ((Guid == NULL) ||\r | |
357 | ((Attributes & ~LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0)) {\r | |
358 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SetLockBoxAttributes - Exit (%r)\n", EFI_INVALID_PARAMETER));\r | |
359 | return EFI_INVALID_PARAMETER;\r | |
360 | }\r | |
361 | \r | |
362 | //\r | |
363 | // Find LockBox\r | |
364 | //\r | |
365 | LockBox = InternalFindLockBoxByGuid (Guid);\r | |
366 | if (LockBox == NULL) {\r | |
367 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SetLockBoxAttributes - Exit (%r)\n", EFI_NOT_FOUND));\r | |
368 | return EFI_NOT_FOUND;\r | |
369 | }\r | |
370 | \r | |
371 | //\r | |
372 | // Update data\r | |
373 | //\r | |
374 | LockBox->Attributes = Attributes;\r | |
375 | \r | |
376 | //\r | |
377 | // Done\r | |
378 | //\r | |
379 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SetLockBoxAttributes - Exit (%r)\n", EFI_SUCCESS));\r | |
380 | return EFI_SUCCESS;\r | |
381 | }\r | |
382 | \r | |
383 | /**\r | |
384 | This function will update confidential information to lockbox.\r | |
385 | \r | |
386 | @param Guid the guid to identify the original confidential information\r | |
387 | @param Offset the offset of the original confidential information\r | |
388 | @param Buffer the address of the updated confidential information\r | |
389 | @param Length the length of the updated confidential information\r | |
390 | \r | |
391 | @retval RETURN_SUCCESS the information is saved successfully.\r | |
392 | @retval RETURN_INVALID_PARAMETER the Guid is NULL, or Buffer is NULL, or Length is 0.\r | |
393 | @retval RETURN_NOT_FOUND the requested GUID not found.\r | |
394 | @retval RETURN_BUFFER_TOO_SMALL the original buffer to too small to hold new information.\r | |
395 | @retval RETURN_ACCESS_DENIED it is too late to invoke this interface\r | |
396 | @retval RETURN_NOT_STARTED it is too early to invoke this interface\r | |
397 | @retval RETURN_UNSUPPORTED the service is not supported by implementaion.\r | |
398 | **/\r | |
399 | RETURN_STATUS\r | |
400 | EFIAPI\r | |
401 | UpdateLockBox (\r | |
402 | IN GUID *Guid,\r | |
403 | IN UINTN Offset,\r | |
404 | IN VOID *Buffer,\r | |
405 | IN UINTN Length\r | |
406 | )\r | |
407 | {\r | |
408 | SMM_LOCK_BOX_DATA *LockBox;\r | |
409 | \r | |
410 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib UpdateLockBox - Enter\n"));\r | |
411 | \r | |
412 | //\r | |
413 | // Basic check\r | |
414 | //\r | |
415 | if ((Guid == NULL) || (Buffer == NULL) || (Length == 0)) {\r | |
416 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_INVALID_PARAMETER));\r | |
417 | return EFI_INVALID_PARAMETER;\r | |
418 | }\r | |
419 | \r | |
420 | //\r | |
421 | // Find LockBox\r | |
422 | //\r | |
423 | LockBox = InternalFindLockBoxByGuid (Guid);\r | |
424 | if (LockBox == NULL) {\r | |
425 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_NOT_FOUND));\r | |
426 | return EFI_NOT_FOUND;\r | |
427 | }\r | |
428 | \r | |
429 | //\r | |
430 | // Update data\r | |
431 | //\r | |
432 | if (LockBox->Length < Offset + Length) {\r | |
433 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_BUFFER_TOO_SMALL));\r | |
434 | return EFI_BUFFER_TOO_SMALL;\r | |
435 | }\r | |
579b5ef2 | 436 | ASSERT ((UINTN)LockBox->SmramBuffer <= (MAX_ADDRESS - Offset));\r |
1c837cd5 | 437 | CopyMem ((VOID *)((UINTN)LockBox->SmramBuffer + Offset), Buffer, Length);\r |
438 | \r | |
439 | //\r | |
440 | // Done\r | |
441 | //\r | |
442 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_SUCCESS));\r | |
443 | return EFI_SUCCESS;\r | |
444 | }\r | |
445 | \r | |
446 | /**\r | |
447 | This function will restore confidential information from lockbox.\r | |
448 | \r | |
449 | @param Guid the guid to identify the confidential information\r | |
450 | @param Buffer the address of the restored confidential information\r | |
451 | NULL means restored to original address, Length MUST be NULL at same time.\r | |
452 | @param Length the length of the restored confidential information\r | |
453 | \r | |
454 | @retval RETURN_SUCCESS the information is restored successfully.\r | |
455 | @retval RETURN_INVALID_PARAMETER the Guid is NULL, or one of Buffer and Length is NULL.\r | |
456 | @retval RETURN_WRITE_PROTECTED Buffer and Length are NULL, but the LockBox has no \r | |
457 | LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE attribute.\r | |
458 | @retval RETURN_BUFFER_TOO_SMALL the Length is too small to hold the confidential information.\r | |
459 | @retval RETURN_NOT_FOUND the requested GUID not found.\r | |
460 | @retval RETURN_NOT_STARTED it is too early to invoke this interface\r | |
461 | @retval RETURN_ACCESS_DENIED not allow to restore to the address\r | |
462 | @retval RETURN_UNSUPPORTED the service is not supported by implementaion.\r | |
463 | **/\r | |
464 | RETURN_STATUS\r | |
465 | EFIAPI\r | |
466 | RestoreLockBox (\r | |
467 | IN GUID *Guid,\r | |
468 | IN VOID *Buffer, OPTIONAL\r | |
469 | IN OUT UINTN *Length OPTIONAL\r | |
470 | )\r | |
471 | {\r | |
472 | SMM_LOCK_BOX_DATA *LockBox;\r | |
473 | VOID *RestoreBuffer;\r | |
474 | \r | |
475 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib RestoreLockBox - Enter\n"));\r | |
476 | \r | |
477 | //\r | |
478 | // Restore this, Buffer and Length MUST be both NULL or both non-NULL\r | |
479 | //\r | |
480 | if ((Guid == NULL) ||\r | |
481 | ((Buffer == NULL) && (Length != NULL)) ||\r | |
482 | ((Buffer != NULL) && (Length == NULL))) {\r | |
483 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_INVALID_PARAMETER));\r | |
484 | return EFI_INVALID_PARAMETER;\r | |
485 | }\r | |
486 | \r | |
487 | //\r | |
488 | // Find LockBox\r | |
489 | //\r | |
490 | LockBox = InternalFindLockBoxByGuid (Guid);\r | |
491 | if (LockBox == NULL) {\r | |
492 | //\r | |
493 | // Not found\r | |
494 | //\r | |
495 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_NOT_FOUND));\r | |
496 | return EFI_NOT_FOUND;\r | |
497 | }\r | |
498 | \r | |
499 | //\r | |
500 | // Set RestoreBuffer\r | |
501 | //\r | |
502 | if (Buffer != NULL) {\r | |
503 | //\r | |
504 | // restore to new buffer\r | |
505 | //\r | |
506 | RestoreBuffer = Buffer;\r | |
507 | } else {\r | |
508 | //\r | |
509 | // restore to original buffer\r | |
510 | //\r | |
511 | if ((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) == 0) {\r | |
512 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_WRITE_PROTECTED));\r | |
513 | return EFI_WRITE_PROTECTED;\r | |
514 | }\r | |
515 | RestoreBuffer = (VOID *)(UINTN)LockBox->Buffer;\r | |
516 | }\r | |
517 | \r | |
518 | //\r | |
519 | // Set RestoreLength\r | |
520 | //\r | |
521 | if (Length != NULL) {\r | |
522 | if (*Length < (UINTN)LockBox->Length) {\r | |
523 | //\r | |
524 | // Input buffer is too small to hold all data.\r | |
525 | //\r | |
526 | *Length = (UINTN)LockBox->Length;\r | |
527 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_BUFFER_TOO_SMALL));\r | |
528 | return EFI_BUFFER_TOO_SMALL;\r | |
529 | }\r | |
530 | *Length = (UINTN)LockBox->Length;\r | |
531 | }\r | |
532 | \r | |
533 | //\r | |
534 | // Restore data\r | |
535 | //\r | |
536 | CopyMem (RestoreBuffer, (VOID *)(UINTN)LockBox->SmramBuffer, (UINTN)LockBox->Length);\r | |
537 | \r | |
538 | //\r | |
539 | // Done\r | |
540 | //\r | |
541 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_SUCCESS));\r | |
542 | return EFI_SUCCESS;\r | |
543 | }\r | |
544 | \r | |
545 | /**\r | |
546 | This function will restore confidential information from all lockbox which have RestoreInPlace attribute.\r | |
547 | \r | |
548 | @retval RETURN_SUCCESS the information is restored successfully.\r | |
549 | @retval RETURN_NOT_STARTED it is too early to invoke this interface\r | |
550 | @retval RETURN_UNSUPPORTED the service is not supported by implementaion.\r | |
551 | **/\r | |
552 | RETURN_STATUS\r | |
553 | EFIAPI\r | |
554 | RestoreAllLockBoxInPlace (\r | |
555 | VOID\r | |
556 | )\r | |
557 | {\r | |
558 | SMM_LOCK_BOX_DATA *LockBox;\r | |
559 | LIST_ENTRY *Link;\r | |
560 | LIST_ENTRY *LockBoxQueue;\r | |
561 | \r | |
562 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib RestoreAllLockBoxInPlace - Enter\n"));\r | |
563 | \r | |
564 | LockBoxQueue = InternalGetLockBoxQueue ();\r | |
565 | ASSERT (LockBoxQueue != NULL);\r | |
566 | \r | |
567 | //\r | |
568 | // Restore all, Buffer and Length MUST be NULL\r | |
569 | //\r | |
570 | for (Link = LockBoxQueue->ForwardLink;\r | |
571 | Link != LockBoxQueue;\r | |
572 | Link = Link->ForwardLink) {\r | |
573 | LockBox = BASE_CR (\r | |
574 | Link,\r | |
575 | SMM_LOCK_BOX_DATA,\r | |
576 | Link\r | |
577 | );\r | |
578 | if ((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0) {\r | |
579 | //\r | |
580 | // Restore data\r | |
581 | //\r | |
582 | CopyMem ((VOID *)(UINTN)LockBox->Buffer, (VOID *)(UINTN)LockBox->SmramBuffer, (UINTN)LockBox->Length);\r | |
583 | }\r | |
584 | }\r | |
585 | //\r | |
586 | // Done\r | |
587 | //\r | |
588 | DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib RestoreAllLockBoxInPlace - Exit (%r)\n", EFI_SUCCESS));\r | |
589 | return EFI_SUCCESS;\r | |
590 | }\r | |
591 | \r |