3 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
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
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.
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 <Protocol/SmmCommunication.h>
24 #include <Guid/SmmLockBox.h>
26 #include "SmmLockBoxLibPrivate.h"
29 This function will save confidential information to lockbox.
31 @param Guid the guid to identify the confidential information
32 @param Buffer the address of the confidential information
33 @param Length the length of the confidential information
35 @retval RETURN_SUCCESS the information is saved successfully.
36 @retval RETURN_INVALID_PARAMETER the Guid is NULL, or Buffer is NULL, or Length is 0
37 @retval RETURN_ALREADY_STARTED the requested GUID already exist.
38 @retval RETURN_OUT_OF_RESOURCES no enough resource to save the information.
39 @retval RETURN_ACCESS_DENIED it is too late to invoke this interface
40 @retval RETURN_NOT_STARTED it is too early to invoke this interface
41 @retval RETURN_UNSUPPORTED the service is not supported by implementaion.
52 EFI_SMM_COMMUNICATION_PROTOCOL
*SmmCommunication
;
53 EFI_SMM_LOCK_BOX_PARAMETER_SAVE
*LockBoxParameterSave
;
54 EFI_SMM_COMMUNICATE_HEADER
*CommHeader
;
55 UINT8 CommBuffer
[sizeof(EFI_GUID
) + sizeof(UINTN
) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE
)];
58 DEBUG ((EFI_D_INFO
, "SmmLockBoxDxeLib SaveLockBox - Enter\n"));
63 if ((Guid
== NULL
) || (Buffer
== NULL
) || (Length
== 0)) {
64 return EFI_INVALID_PARAMETER
;
68 // Get needed resource
70 Status
= gBS
->LocateProtocol (
71 &gEfiSmmCommunicationProtocolGuid
,
73 (VOID
**)&SmmCommunication
75 if (EFI_ERROR (Status
)) {
76 return EFI_NOT_STARTED
;
82 CommHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)&CommBuffer
[0];
83 CopyMem (&CommHeader
->HeaderGuid
, &gEfiSmmLockBoxCommunicationGuid
, sizeof(gEfiSmmLockBoxCommunicationGuid
));
84 CommHeader
->MessageLength
= sizeof(*LockBoxParameterSave
);
86 LockBoxParameterSave
= (EFI_SMM_LOCK_BOX_PARAMETER_SAVE
*)&CommBuffer
[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
)];
87 LockBoxParameterSave
->Header
.Command
= EFI_SMM_LOCK_BOX_COMMAND_SAVE
;
88 LockBoxParameterSave
->Header
.DataLength
= sizeof(*LockBoxParameterSave
);
89 LockBoxParameterSave
->Header
.ReturnStatus
= (UINT64
)-1;
90 CopyMem (&LockBoxParameterSave
->Guid
, Guid
, sizeof(*Guid
));
91 LockBoxParameterSave
->Buffer
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)Buffer
;
92 LockBoxParameterSave
->Length
= (UINT64
)Length
;
97 CommSize
= sizeof(CommBuffer
);
98 Status
= SmmCommunication
->Communicate (
103 ASSERT_EFI_ERROR (Status
);
105 Status
= (EFI_STATUS
)LockBoxParameterSave
->Header
.ReturnStatus
;
107 DEBUG ((EFI_D_INFO
, "SmmLockBoxDxeLib SaveLockBox - Exit (%r)\n", Status
));
116 This function will set lockbox attributes.
118 @param Guid the guid to identify the confidential information
119 @param Attributes the attributes of the lockbox
121 @retval RETURN_SUCCESS the information is saved successfully.
122 @retval RETURN_INVALID_PARAMETER attributes is invalid.
123 @retval RETURN_NOT_FOUND the requested GUID not found.
124 @retval RETURN_ACCESS_DENIED it is too late to invoke this interface
125 @retval RETURN_NOT_STARTED it is too early to invoke this interface
126 @retval RETURN_UNSUPPORTED the service is not supported by implementaion.
130 SetLockBoxAttributes (
136 EFI_SMM_COMMUNICATION_PROTOCOL
*SmmCommunication
;
137 EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES
*LockBoxParameterSetAttributes
;
138 EFI_SMM_COMMUNICATE_HEADER
*CommHeader
;
139 UINT8 CommBuffer
[sizeof(EFI_GUID
) + sizeof(UINTN
) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES
)];
142 DEBUG ((EFI_D_INFO
, "SmmLockBoxDxeLib SetLockBoxAttributes - Enter\n"));
147 if ((Guid
== NULL
) ||
148 ((Attributes
& ~LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE
) != 0)) {
149 return EFI_INVALID_PARAMETER
;
153 // Get needed resource
155 Status
= gBS
->LocateProtocol (
156 &gEfiSmmCommunicationProtocolGuid
,
158 (VOID
**)&SmmCommunication
160 if (EFI_ERROR (Status
)) {
161 return EFI_NOT_STARTED
;
167 CommHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)&CommBuffer
[0];
168 CopyMem (&CommHeader
->HeaderGuid
, &gEfiSmmLockBoxCommunicationGuid
, sizeof(gEfiSmmLockBoxCommunicationGuid
));
169 CommHeader
->MessageLength
= sizeof(*LockBoxParameterSetAttributes
);
171 LockBoxParameterSetAttributes
= (EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES
*)&CommBuffer
[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
)];
172 LockBoxParameterSetAttributes
->Header
.Command
= EFI_SMM_LOCK_BOX_COMMAND_SET_ATTRIBUTES
;
173 LockBoxParameterSetAttributes
->Header
.DataLength
= sizeof(*LockBoxParameterSetAttributes
);
174 LockBoxParameterSetAttributes
->Header
.ReturnStatus
= (UINT64
)-1;
175 CopyMem (&LockBoxParameterSetAttributes
->Guid
, Guid
, sizeof(*Guid
));
176 LockBoxParameterSetAttributes
->Attributes
= (UINT64
)Attributes
;
181 CommSize
= sizeof(CommBuffer
);
182 Status
= SmmCommunication
->Communicate (
187 ASSERT_EFI_ERROR (Status
);
189 Status
= (EFI_STATUS
)LockBoxParameterSetAttributes
->Header
.ReturnStatus
;
191 DEBUG ((EFI_D_INFO
, "SmmLockBoxDxeLib SetLockBoxAttributes - Exit (%r)\n", Status
));
200 This function will update confidential information to lockbox.
202 @param Guid the guid to identify the original confidential information
203 @param Offset the offset of the original confidential information
204 @param Buffer the address of the updated confidential information
205 @param Length the length of the updated confidential information
207 @retval RETURN_SUCCESS the information is saved successfully.
208 @retval RETURN_INVALID_PARAMETER the Guid is NULL, or Buffer is NULL, or Length is 0.
209 @retval RETURN_NOT_FOUND the requested GUID not found.
210 @retval RETURN_BUFFER_TOO_SMALL the original buffer to too small to hold new information.
211 @retval RETURN_ACCESS_DENIED it is too late to invoke this interface
212 @retval RETURN_NOT_STARTED it is too early to invoke this interface
213 @retval RETURN_UNSUPPORTED the service is not supported by implementaion.
225 EFI_SMM_COMMUNICATION_PROTOCOL
*SmmCommunication
;
226 EFI_SMM_LOCK_BOX_PARAMETER_UPDATE
*LockBoxParameterUpdate
;
227 EFI_SMM_COMMUNICATE_HEADER
*CommHeader
;
228 UINT8 CommBuffer
[sizeof(EFI_GUID
) + sizeof(UINTN
) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE
)];
231 DEBUG ((EFI_D_INFO
, "SmmLockBoxDxeLib UpdateLockBox - Enter\n"));
236 if ((Guid
== NULL
) || (Buffer
== NULL
) || (Length
== 0)) {
237 return EFI_INVALID_PARAMETER
;
241 // Get needed resource
243 Status
= gBS
->LocateProtocol (
244 &gEfiSmmCommunicationProtocolGuid
,
246 (VOID
**)&SmmCommunication
248 if (EFI_ERROR (Status
)) {
249 return EFI_NOT_STARTED
;
255 CommHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)&CommBuffer
[0];
256 CopyMem (&CommHeader
->HeaderGuid
, &gEfiSmmLockBoxCommunicationGuid
, sizeof(gEfiSmmLockBoxCommunicationGuid
));
257 CommHeader
->MessageLength
= sizeof(*LockBoxParameterUpdate
);
259 LockBoxParameterUpdate
= (EFI_SMM_LOCK_BOX_PARAMETER_UPDATE
*)(UINTN
)&CommBuffer
[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
)];
260 LockBoxParameterUpdate
->Header
.Command
= EFI_SMM_LOCK_BOX_COMMAND_UPDATE
;
261 LockBoxParameterUpdate
->Header
.DataLength
= sizeof(*LockBoxParameterUpdate
);
262 LockBoxParameterUpdate
->Header
.ReturnStatus
= (UINT64
)-1;
263 CopyMem (&LockBoxParameterUpdate
->Guid
, Guid
, sizeof(*Guid
));
264 LockBoxParameterUpdate
->Offset
= (UINT64
)Offset
;
265 LockBoxParameterUpdate
->Buffer
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)Buffer
;
266 LockBoxParameterUpdate
->Length
= (UINT64
)Length
;
271 CommSize
= sizeof(CommBuffer
);
272 Status
= SmmCommunication
->Communicate (
277 ASSERT_EFI_ERROR (Status
);
279 Status
= (EFI_STATUS
)LockBoxParameterUpdate
->Header
.ReturnStatus
;
281 DEBUG ((EFI_D_INFO
, "SmmLockBoxDxeLib UpdateLockBox - Exit (%r)\n", Status
));
290 This function will restore confidential information from lockbox.
292 @param Guid the guid to identify the confidential information
293 @param Buffer the address of the restored confidential information
294 NULL means restored to original address, Length MUST be NULL at same time.
295 @param Length the length of the restored confidential information
297 @retval RETURN_SUCCESS the information is restored successfully.
298 @retval RETURN_INVALID_PARAMETER the Guid is NULL, or one of Buffer and Length is NULL.
299 @retval RETURN_WRITE_PROTECTED Buffer and Length are NULL, but the LockBox has no
300 LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE attribute.
301 @retval RETURN_BUFFER_TOO_SMALL the Length is too small to hold the confidential information.
302 @retval RETURN_NOT_FOUND the requested GUID not found.
303 @retval RETURN_NOT_STARTED it is too early to invoke this interface
304 @retval RETURN_ACCESS_DENIED not allow to restore to the address
305 @retval RETURN_UNSUPPORTED the service is not supported by implementaion.
311 IN VOID
*Buffer
, OPTIONAL
312 IN OUT UINTN
*Length OPTIONAL
316 EFI_SMM_COMMUNICATION_PROTOCOL
*SmmCommunication
;
317 EFI_SMM_LOCK_BOX_PARAMETER_RESTORE
*LockBoxParameterRestore
;
318 EFI_SMM_COMMUNICATE_HEADER
*CommHeader
;
319 UINT8 CommBuffer
[sizeof(EFI_GUID
) + sizeof(UINTN
) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE
)];
322 DEBUG ((EFI_D_INFO
, "SmmLockBoxDxeLib RestoreLockBox - Enter\n"));
327 if ((Guid
== NULL
) ||
328 ((Buffer
== NULL
) && (Length
!= NULL
)) ||
329 ((Buffer
!= NULL
) && (Length
== NULL
))) {
330 return EFI_INVALID_PARAMETER
;
334 // Get needed resource
336 Status
= gBS
->LocateProtocol (
337 &gEfiSmmCommunicationProtocolGuid
,
339 (VOID
**)&SmmCommunication
341 if (EFI_ERROR (Status
)) {
342 return EFI_NOT_STARTED
;
348 CommHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)&CommBuffer
[0];
349 CopyMem (&CommHeader
->HeaderGuid
, &gEfiSmmLockBoxCommunicationGuid
, sizeof(gEfiSmmLockBoxCommunicationGuid
));
350 CommHeader
->MessageLength
= sizeof(*LockBoxParameterRestore
);
352 LockBoxParameterRestore
= (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE
*)&CommBuffer
[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
)];
353 LockBoxParameterRestore
->Header
.Command
= EFI_SMM_LOCK_BOX_COMMAND_RESTORE
;
354 LockBoxParameterRestore
->Header
.DataLength
= sizeof(*LockBoxParameterRestore
);
355 LockBoxParameterRestore
->Header
.ReturnStatus
= (UINT64
)-1;
356 CopyMem (&LockBoxParameterRestore
->Guid
, Guid
, sizeof(*Guid
));
357 LockBoxParameterRestore
->Buffer
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)Buffer
;
358 if (Length
!= NULL
) {
359 LockBoxParameterRestore
->Length
= (EFI_PHYSICAL_ADDRESS
)*Length
;
361 LockBoxParameterRestore
->Length
= 0;
367 CommSize
= sizeof(CommBuffer
);
368 Status
= SmmCommunication
->Communicate (
373 ASSERT_EFI_ERROR (Status
);
375 if (Length
!= NULL
) {
376 *Length
= (UINTN
)LockBoxParameterRestore
->Length
;
379 Status
= (EFI_STATUS
)LockBoxParameterRestore
->Header
.ReturnStatus
;
381 DEBUG ((EFI_D_INFO
, "SmmLockBoxDxeLib RestoreLockBox - Exit (%r)\n", Status
));
390 This function will restore confidential information from all lockbox which have RestoreInPlace attribute.
392 @retval RETURN_SUCCESS the information is restored successfully.
393 @retval RETURN_NOT_STARTED it is too early to invoke this interface
394 @retval RETURN_UNSUPPORTED the service is not supported by implementaion.
398 RestoreAllLockBoxInPlace (
403 EFI_SMM_COMMUNICATION_PROTOCOL
*SmmCommunication
;
404 EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE
*LockBoxParameterRestoreAllInPlace
;
405 EFI_SMM_COMMUNICATE_HEADER
*CommHeader
;
406 UINT8 CommBuffer
[sizeof(EFI_GUID
) + sizeof(UINTN
) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE
)];
409 DEBUG ((EFI_D_INFO
, "SmmLockBoxDxeLib RestoreAllLockBoxInPlace - Enter\n"));
412 // Get needed resource
414 Status
= gBS
->LocateProtocol (
415 &gEfiSmmCommunicationProtocolGuid
,
417 (VOID
**)&SmmCommunication
419 if (EFI_ERROR (Status
)) {
420 return EFI_NOT_STARTED
;
426 CommHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)&CommBuffer
[0];
427 CopyMem (&CommHeader
->HeaderGuid
, &gEfiSmmLockBoxCommunicationGuid
, sizeof(gEfiSmmLockBoxCommunicationGuid
));
428 CommHeader
->MessageLength
= sizeof(*LockBoxParameterRestoreAllInPlace
);
430 LockBoxParameterRestoreAllInPlace
= (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE
*)&CommBuffer
[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
)];
431 LockBoxParameterRestoreAllInPlace
->Header
.Command
= EFI_SMM_LOCK_BOX_COMMAND_RESTORE_ALL_IN_PLACE
;
432 LockBoxParameterRestoreAllInPlace
->Header
.DataLength
= sizeof(*LockBoxParameterRestoreAllInPlace
);
433 LockBoxParameterRestoreAllInPlace
->Header
.ReturnStatus
= (UINT64
)-1;
438 CommSize
= sizeof(CommBuffer
);
439 Status
= SmmCommunication
->Communicate (
444 ASSERT_EFI_ERROR (Status
);
446 Status
= (EFI_STATUS
)LockBoxParameterRestoreAllInPlace
->Header
.ReturnStatus
;
448 DEBUG ((EFI_D_INFO
, "SmmLockBoxDxeLib RestoreAllLockBoxInPlace - Exit (%r)\n", Status
));