1 | /** @file
|
---|
2 |
|
---|
3 | Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
4 |
|
---|
5 | This program and the accompanying materials
|
---|
6 | are licensed and made available under the terms and conditions
|
---|
7 | of the BSD License which accompanies this distribution. The
|
---|
8 | full text of the license may be found at
|
---|
9 | http://opensource.org/licenses/bsd-license.php
|
---|
10 |
|
---|
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
13 |
|
---|
14 | **/
|
---|
15 |
|
---|
16 | #include <PiDxe.h>
|
---|
17 | #include <Library/UefiBootServicesTableLib.h>
|
---|
18 | #include <Library/UefiRuntimeServicesTableLib.h>
|
---|
19 | #include <Library/BaseLib.h>
|
---|
20 | #include <Library/BaseMemoryLib.h>
|
---|
21 | #include <Library/LockBoxLib.h>
|
---|
22 | #include <Library/DebugLib.h>
|
---|
23 | #include <Library/UefiLib.h>
|
---|
24 | #include <Protocol/SmmCommunication.h>
|
---|
25 | #include <Guid/SmmLockBox.h>
|
---|
26 | #include <Guid/PiSmmCommunicationRegionTable.h>
|
---|
27 |
|
---|
28 | #include "SmmLockBoxLibPrivate.h"
|
---|
29 |
|
---|
30 | EFI_SMM_COMMUNICATION_PROTOCOL *mLockBoxSmmCommProtocol = NULL;
|
---|
31 | UINT8 *mLockBoxSmmCommBuffer = NULL;
|
---|
32 |
|
---|
33 | /**
|
---|
34 | Get smm communication protocol for lockbox.
|
---|
35 |
|
---|
36 | @return Pointer to smm communication protocol, NULL if not found.
|
---|
37 |
|
---|
38 | **/
|
---|
39 | EFI_SMM_COMMUNICATION_PROTOCOL *
|
---|
40 | LockBoxGetSmmCommProtocol (
|
---|
41 | VOID
|
---|
42 | )
|
---|
43 | {
|
---|
44 | EFI_STATUS Status;
|
---|
45 |
|
---|
46 | //
|
---|
47 | // If the protocol has been got previously, return it.
|
---|
48 | //
|
---|
49 | if (mLockBoxSmmCommProtocol != NULL) {
|
---|
50 | return mLockBoxSmmCommProtocol;
|
---|
51 | }
|
---|
52 |
|
---|
53 | Status = gBS->LocateProtocol (
|
---|
54 | &gEfiSmmCommunicationProtocolGuid,
|
---|
55 | NULL,
|
---|
56 | (VOID **)&mLockBoxSmmCommProtocol
|
---|
57 | );
|
---|
58 | if (EFI_ERROR (Status)) {
|
---|
59 | mLockBoxSmmCommProtocol = NULL;
|
---|
60 | }
|
---|
61 | return mLockBoxSmmCommProtocol;
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | Get smm communication buffer for lockbox.
|
---|
66 |
|
---|
67 | @return Pointer to smm communication buffer, NULL if not found.
|
---|
68 |
|
---|
69 | **/
|
---|
70 | UINT8 *
|
---|
71 | LockBoxGetSmmCommBuffer (
|
---|
72 | VOID
|
---|
73 | )
|
---|
74 | {
|
---|
75 | EFI_STATUS Status;
|
---|
76 | UINTN MinimalSizeNeeded;
|
---|
77 | EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable;
|
---|
78 | UINT32 Index;
|
---|
79 | EFI_MEMORY_DESCRIPTOR *Entry;
|
---|
80 | UINTN Size;
|
---|
81 |
|
---|
82 | //
|
---|
83 | // If the buffer has been got previously, return it.
|
---|
84 | //
|
---|
85 | if (mLockBoxSmmCommBuffer != NULL) {
|
---|
86 | return mLockBoxSmmCommBuffer;
|
---|
87 | }
|
---|
88 |
|
---|
89 | MinimalSizeNeeded = sizeof (EFI_GUID) +
|
---|
90 | sizeof (UINTN) +
|
---|
91 | MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SAVE),
|
---|
92 | MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES),
|
---|
93 | MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_UPDATE),
|
---|
94 | MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE),
|
---|
95 | sizeof (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)))));
|
---|
96 |
|
---|
97 | Status = EfiGetSystemConfigurationTable (
|
---|
98 | &gEdkiiPiSmmCommunicationRegionTableGuid,
|
---|
99 | (VOID **) &PiSmmCommunicationRegionTable
|
---|
100 | );
|
---|
101 | if (EFI_ERROR (Status)) {
|
---|
102 | mLockBoxSmmCommBuffer = NULL;
|
---|
103 | return mLockBoxSmmCommBuffer;
|
---|
104 | }
|
---|
105 | ASSERT (PiSmmCommunicationRegionTable != NULL);
|
---|
106 | Entry = (EFI_MEMORY_DESCRIPTOR *) (PiSmmCommunicationRegionTable + 1);
|
---|
107 | Size = 0;
|
---|
108 | for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) {
|
---|
109 | if (Entry->Type == EfiConventionalMemory) {
|
---|
110 | Size = EFI_PAGES_TO_SIZE ((UINTN) Entry->NumberOfPages);
|
---|
111 | if (Size >= MinimalSizeNeeded) {
|
---|
112 | break;
|
---|
113 | }
|
---|
114 | }
|
---|
115 | Entry = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) Entry + PiSmmCommunicationRegionTable->DescriptorSize);
|
---|
116 | }
|
---|
117 | if (Index >= PiSmmCommunicationRegionTable->NumberOfEntries) {
|
---|
118 | mLockBoxSmmCommBuffer = NULL;
|
---|
119 | } else {
|
---|
120 | mLockBoxSmmCommBuffer = (UINT8 *) (UINTN) Entry->PhysicalStart;
|
---|
121 | }
|
---|
122 | return mLockBoxSmmCommBuffer;
|
---|
123 | }
|
---|
124 |
|
---|
125 | /**
|
---|
126 | This function will save confidential information to lockbox.
|
---|
127 |
|
---|
128 | @param Guid the guid to identify the confidential information
|
---|
129 | @param Buffer the address of the confidential information
|
---|
130 | @param Length the length of the confidential information
|
---|
131 |
|
---|
132 | @retval RETURN_SUCCESS the information is saved successfully.
|
---|
133 | @retval RETURN_INVALID_PARAMETER the Guid is NULL, or Buffer is NULL, or Length is 0
|
---|
134 | @retval RETURN_ALREADY_STARTED the requested GUID already exist.
|
---|
135 | @retval RETURN_OUT_OF_RESOURCES no enough resource to save the information.
|
---|
136 | @retval RETURN_ACCESS_DENIED it is too late to invoke this interface
|
---|
137 | @retval RETURN_NOT_STARTED it is too early to invoke this interface
|
---|
138 | @retval RETURN_UNSUPPORTED the service is not supported by implementaion.
|
---|
139 | **/
|
---|
140 | RETURN_STATUS
|
---|
141 | EFIAPI
|
---|
142 | SaveLockBox (
|
---|
143 | IN GUID *Guid,
|
---|
144 | IN VOID *Buffer,
|
---|
145 | IN UINTN Length
|
---|
146 | )
|
---|
147 | {
|
---|
148 | EFI_STATUS Status;
|
---|
149 | EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication;
|
---|
150 | EFI_SMM_LOCK_BOX_PARAMETER_SAVE *LockBoxParameterSave;
|
---|
151 | EFI_SMM_COMMUNICATE_HEADER *CommHeader;
|
---|
152 | UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)];
|
---|
153 | UINT8 *CommBuffer;
|
---|
154 | UINTN CommSize;
|
---|
155 |
|
---|
156 | DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib SaveLockBox - Enter\n"));
|
---|
157 |
|
---|
158 | //
|
---|
159 | // Basic check
|
---|
160 | //
|
---|
161 | if ((Guid == NULL) || (Buffer == NULL) || (Length == 0)) {
|
---|
162 | return EFI_INVALID_PARAMETER;
|
---|
163 | }
|
---|
164 |
|
---|
165 | SmmCommunication = LockBoxGetSmmCommProtocol ();
|
---|
166 | if (SmmCommunication == NULL) {
|
---|
167 | return EFI_NOT_STARTED;
|
---|
168 | }
|
---|
169 |
|
---|
170 | //
|
---|
171 | // Prepare parameter
|
---|
172 | //
|
---|
173 | CommBuffer = LockBoxGetSmmCommBuffer ();
|
---|
174 | if (CommBuffer == NULL) {
|
---|
175 | CommBuffer = &TempCommBuffer[0];
|
---|
176 | }
|
---|
177 | CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
|
---|
178 | CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
|
---|
179 | CommHeader->MessageLength = sizeof(*LockBoxParameterSave);
|
---|
180 |
|
---|
181 | LockBoxParameterSave = (EFI_SMM_LOCK_BOX_PARAMETER_SAVE *)&CommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)];
|
---|
182 | LockBoxParameterSave->Header.Command = EFI_SMM_LOCK_BOX_COMMAND_SAVE;
|
---|
183 | LockBoxParameterSave->Header.DataLength = sizeof(*LockBoxParameterSave);
|
---|
184 | LockBoxParameterSave->Header.ReturnStatus = (UINT64)-1;
|
---|
185 | CopyMem (&LockBoxParameterSave->Guid, Guid, sizeof(*Guid));
|
---|
186 | LockBoxParameterSave->Buffer = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer;
|
---|
187 | LockBoxParameterSave->Length = (UINT64)Length;
|
---|
188 |
|
---|
189 | //
|
---|
190 | // Send command
|
---|
191 | //
|
---|
192 | CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE);
|
---|
193 | Status = SmmCommunication->Communicate (
|
---|
194 | SmmCommunication,
|
---|
195 | &CommBuffer[0],
|
---|
196 | &CommSize
|
---|
197 | );
|
---|
198 | ASSERT_EFI_ERROR (Status);
|
---|
199 |
|
---|
200 | Status = (EFI_STATUS)LockBoxParameterSave->Header.ReturnStatus;
|
---|
201 |
|
---|
202 | DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib SaveLockBox - Exit (%r)\n", Status));
|
---|
203 |
|
---|
204 | //
|
---|
205 | // Done
|
---|
206 | //
|
---|
207 | return Status;
|
---|
208 | }
|
---|
209 |
|
---|
210 | /**
|
---|
211 | This function will set lockbox attributes.
|
---|
212 |
|
---|
213 | @param Guid the guid to identify the confidential information
|
---|
214 | @param Attributes the attributes of the lockbox
|
---|
215 |
|
---|
216 | @retval RETURN_SUCCESS the information is saved successfully.
|
---|
217 | @retval RETURN_INVALID_PARAMETER attributes is invalid.
|
---|
218 | @retval RETURN_NOT_FOUND the requested GUID not found.
|
---|
219 | @retval RETURN_ACCESS_DENIED it is too late to invoke this interface
|
---|
220 | @retval RETURN_NOT_STARTED it is too early to invoke this interface
|
---|
221 | @retval RETURN_UNSUPPORTED the service is not supported by implementaion.
|
---|
222 | **/
|
---|
223 | RETURN_STATUS
|
---|
224 | EFIAPI
|
---|
225 | SetLockBoxAttributes (
|
---|
226 | IN GUID *Guid,
|
---|
227 | IN UINT64 Attributes
|
---|
228 | )
|
---|
229 | {
|
---|
230 | EFI_STATUS Status;
|
---|
231 | EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication;
|
---|
232 | EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES *LockBoxParameterSetAttributes;
|
---|
233 | EFI_SMM_COMMUNICATE_HEADER *CommHeader;
|
---|
234 | UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)];
|
---|
235 | UINT8 *CommBuffer;
|
---|
236 | UINTN CommSize;
|
---|
237 |
|
---|
238 | DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib SetLockBoxAttributes - Enter\n"));
|
---|
239 |
|
---|
240 | //
|
---|
241 | // Basic check
|
---|
242 | //
|
---|
243 | if ((Guid == NULL) ||
|
---|
244 | ((Attributes & ~(LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE | LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY)) != 0)) {
|
---|
245 | return EFI_INVALID_PARAMETER;
|
---|
246 | }
|
---|
247 |
|
---|
248 | SmmCommunication = LockBoxGetSmmCommProtocol ();
|
---|
249 | if (SmmCommunication == NULL) {
|
---|
250 | return EFI_NOT_STARTED;
|
---|
251 | }
|
---|
252 |
|
---|
253 | //
|
---|
254 | // Prepare parameter
|
---|
255 | //
|
---|
256 | CommBuffer = LockBoxGetSmmCommBuffer ();
|
---|
257 | if (CommBuffer == NULL) {
|
---|
258 | CommBuffer = &TempCommBuffer[0];
|
---|
259 | }
|
---|
260 | CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
|
---|
261 | CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
|
---|
262 | CommHeader->MessageLength = sizeof(*LockBoxParameterSetAttributes);
|
---|
263 |
|
---|
264 | LockBoxParameterSetAttributes = (EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES *)&CommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)];
|
---|
265 | LockBoxParameterSetAttributes->Header.Command = EFI_SMM_LOCK_BOX_COMMAND_SET_ATTRIBUTES;
|
---|
266 | LockBoxParameterSetAttributes->Header.DataLength = sizeof(*LockBoxParameterSetAttributes);
|
---|
267 | LockBoxParameterSetAttributes->Header.ReturnStatus = (UINT64)-1;
|
---|
268 | CopyMem (&LockBoxParameterSetAttributes->Guid, Guid, sizeof(*Guid));
|
---|
269 | LockBoxParameterSetAttributes->Attributes = (UINT64)Attributes;
|
---|
270 |
|
---|
271 | //
|
---|
272 | // Send command
|
---|
273 | //
|
---|
274 | CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES);
|
---|
275 | Status = SmmCommunication->Communicate (
|
---|
276 | SmmCommunication,
|
---|
277 | &CommBuffer[0],
|
---|
278 | &CommSize
|
---|
279 | );
|
---|
280 | ASSERT_EFI_ERROR (Status);
|
---|
281 |
|
---|
282 | Status = (EFI_STATUS)LockBoxParameterSetAttributes->Header.ReturnStatus;
|
---|
283 |
|
---|
284 | DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib SetLockBoxAttributes - Exit (%r)\n", Status));
|
---|
285 |
|
---|
286 | //
|
---|
287 | // Done
|
---|
288 | //
|
---|
289 | return Status;
|
---|
290 | }
|
---|
291 |
|
---|
292 | /**
|
---|
293 | This function will update confidential information to lockbox.
|
---|
294 |
|
---|
295 | @param Guid the guid to identify the original confidential information
|
---|
296 | @param Offset the offset of the original confidential information
|
---|
297 | @param Buffer the address of the updated confidential information
|
---|
298 | @param Length the length of the updated confidential information
|
---|
299 |
|
---|
300 | @retval RETURN_SUCCESS the information is saved successfully.
|
---|
301 | @retval RETURN_INVALID_PARAMETER the Guid is NULL, or Buffer is NULL, or Length is 0.
|
---|
302 | @retval RETURN_NOT_FOUND the requested GUID not found.
|
---|
303 | @retval RETURN_BUFFER_TOO_SMALL the original buffer to too small to hold new information.
|
---|
304 | @retval RETURN_ACCESS_DENIED it is too late to invoke this interface
|
---|
305 | @retval RETURN_NOT_STARTED it is too early to invoke this interface
|
---|
306 | @retval RETURN_UNSUPPORTED the service is not supported by implementaion.
|
---|
307 | **/
|
---|
308 | RETURN_STATUS
|
---|
309 | EFIAPI
|
---|
310 | UpdateLockBox (
|
---|
311 | IN GUID *Guid,
|
---|
312 | IN UINTN Offset,
|
---|
313 | IN VOID *Buffer,
|
---|
314 | IN UINTN Length
|
---|
315 | )
|
---|
316 | {
|
---|
317 | EFI_STATUS Status;
|
---|
318 | EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication;
|
---|
319 | EFI_SMM_LOCK_BOX_PARAMETER_UPDATE *LockBoxParameterUpdate;
|
---|
320 | EFI_SMM_COMMUNICATE_HEADER *CommHeader;
|
---|
321 | UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)];
|
---|
322 | UINT8 *CommBuffer;
|
---|
323 | UINTN CommSize;
|
---|
324 |
|
---|
325 | DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib UpdateLockBox - Enter\n"));
|
---|
326 |
|
---|
327 | //
|
---|
328 | // Basic check
|
---|
329 | //
|
---|
330 | if ((Guid == NULL) || (Buffer == NULL) || (Length == 0)) {
|
---|
331 | return EFI_INVALID_PARAMETER;
|
---|
332 | }
|
---|
333 |
|
---|
334 | SmmCommunication = LockBoxGetSmmCommProtocol ();
|
---|
335 | if (SmmCommunication == NULL) {
|
---|
336 | return EFI_NOT_STARTED;
|
---|
337 | }
|
---|
338 |
|
---|
339 | //
|
---|
340 | // Prepare parameter
|
---|
341 | //
|
---|
342 | CommBuffer = LockBoxGetSmmCommBuffer ();
|
---|
343 | if (CommBuffer == NULL) {
|
---|
344 | CommBuffer = &TempCommBuffer[0];
|
---|
345 | }
|
---|
346 | CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
|
---|
347 | CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
|
---|
348 | CommHeader->MessageLength = sizeof(*LockBoxParameterUpdate);
|
---|
349 |
|
---|
350 | LockBoxParameterUpdate = (EFI_SMM_LOCK_BOX_PARAMETER_UPDATE *)(UINTN)&CommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)];
|
---|
351 | LockBoxParameterUpdate->Header.Command = EFI_SMM_LOCK_BOX_COMMAND_UPDATE;
|
---|
352 | LockBoxParameterUpdate->Header.DataLength = sizeof(*LockBoxParameterUpdate);
|
---|
353 | LockBoxParameterUpdate->Header.ReturnStatus = (UINT64)-1;
|
---|
354 | CopyMem (&LockBoxParameterUpdate->Guid, Guid, sizeof(*Guid));
|
---|
355 | LockBoxParameterUpdate->Offset = (UINT64)Offset;
|
---|
356 | LockBoxParameterUpdate->Buffer = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer;
|
---|
357 | LockBoxParameterUpdate->Length = (UINT64)Length;
|
---|
358 |
|
---|
359 | //
|
---|
360 | // Send command
|
---|
361 | //
|
---|
362 | CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE);
|
---|
363 | Status = SmmCommunication->Communicate (
|
---|
364 | SmmCommunication,
|
---|
365 | &CommBuffer[0],
|
---|
366 | &CommSize
|
---|
367 | );
|
---|
368 | ASSERT_EFI_ERROR (Status);
|
---|
369 |
|
---|
370 | Status = (EFI_STATUS)LockBoxParameterUpdate->Header.ReturnStatus;
|
---|
371 |
|
---|
372 | DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib UpdateLockBox - Exit (%r)\n", Status));
|
---|
373 |
|
---|
374 | //
|
---|
375 | // Done
|
---|
376 | //
|
---|
377 | return Status;
|
---|
378 | }
|
---|
379 |
|
---|
380 | /**
|
---|
381 | This function will restore confidential information from lockbox.
|
---|
382 |
|
---|
383 | @param Guid the guid to identify the confidential information
|
---|
384 | @param Buffer the address of the restored confidential information
|
---|
385 | NULL means restored to original address, Length MUST be NULL at same time.
|
---|
386 | @param Length the length of the restored confidential information
|
---|
387 |
|
---|
388 | @retval RETURN_SUCCESS the information is restored successfully.
|
---|
389 | @retval RETURN_INVALID_PARAMETER the Guid is NULL, or one of Buffer and Length is NULL.
|
---|
390 | @retval RETURN_WRITE_PROTECTED Buffer and Length are NULL, but the LockBox has no
|
---|
391 | LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE attribute.
|
---|
392 | @retval RETURN_BUFFER_TOO_SMALL the Length is too small to hold the confidential information.
|
---|
393 | @retval RETURN_NOT_FOUND the requested GUID not found.
|
---|
394 | @retval RETURN_NOT_STARTED it is too early to invoke this interface
|
---|
395 | @retval RETURN_ACCESS_DENIED not allow to restore to the address
|
---|
396 | @retval RETURN_UNSUPPORTED the service is not supported by implementaion.
|
---|
397 | **/
|
---|
398 | RETURN_STATUS
|
---|
399 | EFIAPI
|
---|
400 | RestoreLockBox (
|
---|
401 | IN GUID *Guid,
|
---|
402 | IN VOID *Buffer, OPTIONAL
|
---|
403 | IN OUT UINTN *Length OPTIONAL
|
---|
404 | )
|
---|
405 | {
|
---|
406 | EFI_STATUS Status;
|
---|
407 | EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication;
|
---|
408 | EFI_SMM_LOCK_BOX_PARAMETER_RESTORE *LockBoxParameterRestore;
|
---|
409 | EFI_SMM_COMMUNICATE_HEADER *CommHeader;
|
---|
410 | UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)];
|
---|
411 | UINT8 *CommBuffer;
|
---|
412 | UINTN CommSize;
|
---|
413 |
|
---|
414 | DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib RestoreLockBox - Enter\n"));
|
---|
415 |
|
---|
416 | //
|
---|
417 | // Basic check
|
---|
418 | //
|
---|
419 | if ((Guid == NULL) ||
|
---|
420 | ((Buffer == NULL) && (Length != NULL)) ||
|
---|
421 | ((Buffer != NULL) && (Length == NULL))) {
|
---|
422 | return EFI_INVALID_PARAMETER;
|
---|
423 | }
|
---|
424 |
|
---|
425 | SmmCommunication = LockBoxGetSmmCommProtocol ();
|
---|
426 | if (SmmCommunication == NULL) {
|
---|
427 | return EFI_NOT_STARTED;
|
---|
428 | }
|
---|
429 |
|
---|
430 | //
|
---|
431 | // Prepare parameter
|
---|
432 | //
|
---|
433 | CommBuffer = LockBoxGetSmmCommBuffer ();
|
---|
434 | if (CommBuffer == NULL) {
|
---|
435 | CommBuffer = &TempCommBuffer[0];
|
---|
436 | }
|
---|
437 | CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
|
---|
438 | CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
|
---|
439 | CommHeader->MessageLength = sizeof(*LockBoxParameterRestore);
|
---|
440 |
|
---|
441 | LockBoxParameterRestore = (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE *)&CommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)];
|
---|
442 | LockBoxParameterRestore->Header.Command = EFI_SMM_LOCK_BOX_COMMAND_RESTORE;
|
---|
443 | LockBoxParameterRestore->Header.DataLength = sizeof(*LockBoxParameterRestore);
|
---|
444 | LockBoxParameterRestore->Header.ReturnStatus = (UINT64)-1;
|
---|
445 | CopyMem (&LockBoxParameterRestore->Guid, Guid, sizeof(*Guid));
|
---|
446 | LockBoxParameterRestore->Buffer = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer;
|
---|
447 | if (Length != NULL) {
|
---|
448 | LockBoxParameterRestore->Length = (EFI_PHYSICAL_ADDRESS)*Length;
|
---|
449 | } else {
|
---|
450 | LockBoxParameterRestore->Length = 0;
|
---|
451 | }
|
---|
452 |
|
---|
453 | //
|
---|
454 | // Send command
|
---|
455 | //
|
---|
456 | CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE);
|
---|
457 | Status = SmmCommunication->Communicate (
|
---|
458 | SmmCommunication,
|
---|
459 | &CommBuffer[0],
|
---|
460 | &CommSize
|
---|
461 | );
|
---|
462 | ASSERT_EFI_ERROR (Status);
|
---|
463 |
|
---|
464 | if (Length != NULL) {
|
---|
465 | *Length = (UINTN)LockBoxParameterRestore->Length;
|
---|
466 | }
|
---|
467 |
|
---|
468 | Status = (EFI_STATUS)LockBoxParameterRestore->Header.ReturnStatus;
|
---|
469 |
|
---|
470 | DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib RestoreLockBox - Exit (%r)\n", Status));
|
---|
471 |
|
---|
472 | //
|
---|
473 | // Done
|
---|
474 | //
|
---|
475 | return Status;
|
---|
476 | }
|
---|
477 |
|
---|
478 | /**
|
---|
479 | This function will restore confidential information from all lockbox which have RestoreInPlace attribute.
|
---|
480 |
|
---|
481 | @retval RETURN_SUCCESS the information is restored successfully.
|
---|
482 | @retval RETURN_NOT_STARTED it is too early to invoke this interface
|
---|
483 | @retval RETURN_UNSUPPORTED the service is not supported by implementaion.
|
---|
484 | **/
|
---|
485 | RETURN_STATUS
|
---|
486 | EFIAPI
|
---|
487 | RestoreAllLockBoxInPlace (
|
---|
488 | VOID
|
---|
489 | )
|
---|
490 | {
|
---|
491 | EFI_STATUS Status;
|
---|
492 | EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication;
|
---|
493 | EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE *LockBoxParameterRestoreAllInPlace;
|
---|
494 | EFI_SMM_COMMUNICATE_HEADER *CommHeader;
|
---|
495 | UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)];
|
---|
496 | UINT8 *CommBuffer;
|
---|
497 | UINTN CommSize;
|
---|
498 |
|
---|
499 | DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib RestoreAllLockBoxInPlace - Enter\n"));
|
---|
500 |
|
---|
501 | SmmCommunication = LockBoxGetSmmCommProtocol ();
|
---|
502 | if (SmmCommunication == NULL) {
|
---|
503 | return EFI_NOT_STARTED;
|
---|
504 | }
|
---|
505 |
|
---|
506 | //
|
---|
507 | // Prepare parameter
|
---|
508 | //
|
---|
509 | CommBuffer = LockBoxGetSmmCommBuffer ();
|
---|
510 | if (CommBuffer == NULL) {
|
---|
511 | CommBuffer = &TempCommBuffer[0];
|
---|
512 | }
|
---|
513 | CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
|
---|
514 | CopyMem (&CommHeader->HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof(gEfiSmmLockBoxCommunicationGuid));
|
---|
515 | CommHeader->MessageLength = sizeof(*LockBoxParameterRestoreAllInPlace);
|
---|
516 |
|
---|
517 | LockBoxParameterRestoreAllInPlace = (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE *)&CommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)];
|
---|
518 | LockBoxParameterRestoreAllInPlace->Header.Command = EFI_SMM_LOCK_BOX_COMMAND_RESTORE_ALL_IN_PLACE;
|
---|
519 | LockBoxParameterRestoreAllInPlace->Header.DataLength = sizeof(*LockBoxParameterRestoreAllInPlace);
|
---|
520 | LockBoxParameterRestoreAllInPlace->Header.ReturnStatus = (UINT64)-1;
|
---|
521 |
|
---|
522 | //
|
---|
523 | // Send command
|
---|
524 | //
|
---|
525 | CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE);
|
---|
526 | Status = SmmCommunication->Communicate (
|
---|
527 | SmmCommunication,
|
---|
528 | &CommBuffer[0],
|
---|
529 | &CommSize
|
---|
530 | );
|
---|
531 | ASSERT_EFI_ERROR (Status);
|
---|
532 |
|
---|
533 | Status = (EFI_STATUS)LockBoxParameterRestoreAllInPlace->Header.ReturnStatus;
|
---|
534 |
|
---|
535 | DEBUG ((EFI_D_INFO, "SmmLockBoxDxeLib RestoreAllLockBoxInPlace - Exit (%r)\n", Status));
|
---|
536 |
|
---|
537 | //
|
---|
538 | // Done
|
---|
539 | //
|
---|
540 | return Status;
|
---|
541 | }
|
---|
542 |
|
---|