2 TCG MOR (Memory Overwrite Request) Control Driver.
4 This driver initilize MemoryOverwriteRequestControl variable. It
5 will clear MOR_CLEAR_MEMORY_BIT bit if it is set. It will also do TPer Reset for
6 those encrypted drives through EFI_STORAGE_SECURITY_COMMAND_PROTOCOL at EndOfDxe.
8 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 Ready to Boot Event notification handler.
26 Sequence of OS boot events is measured in this event notification handler.
28 @param[in] Event Event whose notification function is being invoked
29 @param[in] Context Pointer to the notification function's context
42 if (MOR_CLEAR_MEMORY_VALUE (mMorControl
) == 0x0) {
44 // MorControl is expected, directly return to avoid unnecessary variable operation
49 // Clear MOR_CLEAR_MEMORY_BIT
51 DEBUG ((EFI_D_INFO
, "TcgMor: Clear MorClearMemory bit\n"));
54 DataSize
= sizeof (mMorControl
);
55 Status
= gRT
->SetVariable (
56 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
57 &gEfiMemoryOverwriteControlDataGuid
,
58 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
62 if (EFI_ERROR (Status
)) {
63 DEBUG ((EFI_D_ERROR
, "TcgMor: Clear MOR_CLEAR_MEMORY_BIT failure, Status = %r\n"));
68 Send TPer Reset command to reset eDrive to lock all protected bands.
69 Typically, there are 2 mechanism for resetting eDrive. They are:
70 1. TPer Reset through IEEE 1667 protocol.
71 2. TPer Reset through native TCG protocol.
72 This routine will detect what protocol the attached eDrive comform to, TCG or
73 IEEE 1667 protocol. Then send out TPer Reset command separately.
75 @param[in] Ssp The pointer to EFI_STORAGE_SECURITY_COMMAND_PROTOCOL instance.
76 @param[in] MediaId ID of the medium to receive data from or send data to.
81 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Ssp
,
93 SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*Data
;
100 // ATA8-ACS 7.57.6.1 indicates the Transfer Length field requirements a multiple of 512.
101 // If the length of the TRUSTED RECEIVE parameter data is greater than the Transfer Length,
102 // then the device shall return the TRUSTED RECEIVE parameter data truncated to the requested Transfer Length.
104 Len
= ROUNDUP512(sizeof(SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
));
105 Buffer
= AllocateZeroPool(Len
);
107 if (Buffer
== NULL
) {
112 // When the Security Protocol field is set to 00h, and SP Specific is set to 0000h in a TRUSTED RECEIVE
113 // command, the device basic information data shall be returned.
115 Status
= Ssp
->ReceiveData (
118 100000000, // Timeout 10-sec
119 0, // SecurityProtocol
120 0, // SecurityProtocolSpecifcData
121 Len
, // PayloadBufferSize,
122 Buffer
, // PayloadBuffer
125 if (EFI_ERROR (Status
)) {
130 // In returned data, the ListLength field indicates the total length, in bytes,
131 // of the supported security protocol list.
133 Data
= (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*)Buffer
;
134 Len
= ROUNDUP512(sizeof (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
) +
135 (Data
->SupportedSecurityListLength
[0] << 8) +
136 (Data
->SupportedSecurityListLength
[1])
140 // Free original buffer and allocate new buffer.
143 Buffer
= AllocateZeroPool(Len
);
144 if (Buffer
== NULL
) {
149 // Read full supported security protocol list from device.
151 Status
= Ssp
->ReceiveData (
154 100000000, // Timeout 10-sec
155 0, // SecurityProtocol
156 0, // SecurityProtocolSpecifcData
157 Len
, // PayloadBufferSize,
158 Buffer
, // PayloadBuffer
162 if (EFI_ERROR (Status
)) {
166 Data
= (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*)Buffer
;
167 Len
= (Data
->SupportedSecurityListLength
[0] << 8) + Data
->SupportedSecurityListLength
[1];
170 // Iterate full supported security protocol list to check if TCG or IEEE 1667 protocol
173 for (Index
= 0; Index
< Len
; Index
++) {
174 if (Data
->SupportedSecurityProtocol
[Index
] == SECURITY_PROTOCOL_TCG
) {
176 // Found a TCG device.
179 DEBUG ((EFI_D_INFO
, "This device is a TCG protocol device\n"));
183 if (Data
->SupportedSecurityProtocol
[Index
] == SECURITY_PROTOCOL_IEEE1667
) {
185 // Found a IEEE 1667 device.
188 DEBUG ((EFI_D_INFO
, "This device is a IEEE 1667 protocol device\n"));
193 if (!TcgFlag
&& !IeeeFlag
) {
194 DEBUG ((EFI_D_INFO
, "Neither a TCG nor IEEE 1667 protocol device is found\n"));
200 // As long as TCG protocol is supported, send out a TPer Reset
201 // TCG command to the device via the TrustedSend command with a non-zero Transfer Length.
203 Status
= Ssp
->SendData (
206 100000000, // Timeout 10-sec
207 SECURITY_PROTOCOL_TCG
, // SecurityProtocol
208 0x0400, // SecurityProtocolSpecifcData
209 512, // PayloadBufferSize,
210 Buffer
// PayloadBuffer
213 if (!EFI_ERROR (Status
)) {
214 DEBUG ((EFI_D_INFO
, "Send TPer Reset Command Successfully !\n"));
216 DEBUG ((EFI_D_INFO
, "Send TPer Reset Command Fail !\n"));
222 // TBD : Perform a TPer Reset via IEEE 1667 Protocol
224 DEBUG ((EFI_D_INFO
, "IEEE 1667 Protocol didn't support yet!\n"));
229 if (Buffer
!= NULL
) {
235 Notification function of END_OF_DXE.
237 This is a notification function registered on END_OF_DXE event.
238 It is to get VarCheckPcdBin.
240 @param[in] Event Event whose notification function is being invoked.
241 @param[in] Context Pointer to the notification function's context.
246 TPerResetAtEndOfDxe (
251 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Ssp
;
252 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
255 EFI_HANDLE
*HandleBuffer
;
259 // Locate all SSP protocol instances.
264 Status
= gBS
->LocateHandleBuffer (
266 &gEfiStorageSecurityCommandProtocolGuid
,
272 if (EFI_ERROR (Status
) || (HandleCount
== 0) || (HandleBuffer
== NULL
)) {
276 for (Index
= 0; Index
< HandleCount
; Index
++) {
278 // Get the SSP interface.
280 Status
= gBS
->HandleProtocol(
282 &gEfiStorageSecurityCommandProtocolGuid
,
286 if (EFI_ERROR (Status
)) {
290 Status
= gBS
->HandleProtocol(
292 &gEfiBlockIoProtocolGuid
,
296 if (EFI_ERROR (Status
)) {
300 InitiateTPerReset (Ssp
, BlockIo
->Media
->MediaId
);
305 Entry Point for TCG MOR Control driver.
307 @param[in] ImageHandle Image handle of this driver.
308 @param[in] SystemTable A Pointer to the EFI System Table.
311 @return Others Some error occurs.
315 MorDriverEntryPoint (
316 IN EFI_HANDLE ImageHandle
,
317 IN EFI_SYSTEM_TABLE
*SystemTable
325 /// The firmware is required to create the MemoryOverwriteRequestControl UEFI variable.
328 DataSize
= sizeof (mMorControl
);
329 Status
= gRT
->GetVariable (
330 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
331 &gEfiMemoryOverwriteControlDataGuid
,
336 if (EFI_ERROR (Status
)) {
338 // Set default value to 0
341 Status
= gRT
->SetVariable (
342 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
343 &gEfiMemoryOverwriteControlDataGuid
,
344 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
348 DEBUG ((EFI_D_INFO
, "TcgMor: Create MOR variable! Status = %r\n", Status
));
351 // Create a Ready To Boot Event and Clear the MorControl bit in the call back function.
353 DEBUG ((EFI_D_INFO
, "TcgMor: Create ReadyToBoot Event for MorControl Bit cleanning!\n"));
354 Status
= EfiCreateEventReadyToBootEx (
360 if (EFI_ERROR (Status
)) {
365 // Register EFI_END_OF_DXE_EVENT_GROUP_GUID event.
367 DEBUG ((EFI_D_INFO
, "TcgMor: Create EndofDxe Event for Mor TPer Reset!\n"));
368 Status
= gBS
->CreateEventEx (
373 &gEfiEndOfDxeEventGroupGuid
,
376 if (EFI_ERROR (Status
)) {