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 - 2018, Intel Corporation. All rights reserved.<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
18 Ready to Boot Event notification handler.
20 @param[in] Event Event whose notification function is being invoked
21 @param[in] Context Pointer to the notification function's context
34 if (MOR_CLEAR_MEMORY_VALUE (mMorControl
) == 0x0) {
36 // MorControl is expected, directly return to avoid unnecessary variable operation
41 // Clear MOR_CLEAR_MEMORY_BIT
43 DEBUG ((EFI_D_INFO
, "TcgMor: Clear MorClearMemory bit\n"));
46 DataSize
= sizeof (mMorControl
);
47 Status
= gRT
->SetVariable (
48 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
49 &gEfiMemoryOverwriteControlDataGuid
,
50 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
54 if (EFI_ERROR (Status
)) {
55 DEBUG ((EFI_D_ERROR
, "TcgMor: Clear MOR_CLEAR_MEMORY_BIT failure, Status = %r\n"));
60 Send TPer Reset command to reset eDrive to lock all protected bands.
61 Typically, there are 2 mechanism for resetting eDrive. They are:
62 1. TPer Reset through IEEE 1667 protocol.
63 2. TPer Reset through native TCG protocol.
64 This routine will detect what protocol the attached eDrive comform to, TCG or
65 IEEE 1667 protocol. Then send out TPer Reset command separately.
67 @param[in] Ssp The pointer to EFI_STORAGE_SECURITY_COMMAND_PROTOCOL instance.
68 @param[in] MediaId ID of the medium to receive data from or send data to.
73 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Ssp
,
85 SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*Data
;
92 // ATA8-ACS 7.57.6.1 indicates the Transfer Length field requirements a multiple of 512.
93 // If the length of the TRUSTED RECEIVE parameter data is greater than the Transfer Length,
94 // then the device shall return the TRUSTED RECEIVE parameter data truncated to the requested Transfer Length.
96 Len
= ROUNDUP512(sizeof(SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
));
97 Buffer
= AllocateZeroPool(Len
);
104 // When the Security Protocol field is set to 00h, and SP Specific is set to 0000h in a TRUSTED RECEIVE
105 // command, the device basic information data shall be returned.
107 Status
= Ssp
->ReceiveData (
110 100000000, // Timeout 10-sec
111 0, // SecurityProtocol
112 0, // SecurityProtocolSpecifcData
113 Len
, // PayloadBufferSize,
114 Buffer
, // PayloadBuffer
117 if (EFI_ERROR (Status
)) {
122 // In returned data, the ListLength field indicates the total length, in bytes,
123 // of the supported security protocol list.
125 Data
= (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*)Buffer
;
126 Len
= ROUNDUP512(sizeof (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
) +
127 (Data
->SupportedSecurityListLength
[0] << 8) +
128 (Data
->SupportedSecurityListLength
[1])
132 // Free original buffer and allocate new buffer.
135 Buffer
= AllocateZeroPool(Len
);
136 if (Buffer
== NULL
) {
141 // Read full supported security protocol list from device.
143 Status
= Ssp
->ReceiveData (
146 100000000, // Timeout 10-sec
147 0, // SecurityProtocol
148 0, // SecurityProtocolSpecifcData
149 Len
, // PayloadBufferSize,
150 Buffer
, // PayloadBuffer
154 if (EFI_ERROR (Status
)) {
158 Data
= (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*)Buffer
;
159 Len
= (Data
->SupportedSecurityListLength
[0] << 8) + Data
->SupportedSecurityListLength
[1];
162 // Iterate full supported security protocol list to check if TCG or IEEE 1667 protocol
165 for (Index
= 0; Index
< Len
; Index
++) {
166 if (Data
->SupportedSecurityProtocol
[Index
] == SECURITY_PROTOCOL_TCG
) {
168 // Found a TCG device.
171 DEBUG ((EFI_D_INFO
, "This device is a TCG protocol device\n"));
175 if (Data
->SupportedSecurityProtocol
[Index
] == SECURITY_PROTOCOL_IEEE1667
) {
177 // Found a IEEE 1667 device.
180 DEBUG ((EFI_D_INFO
, "This device is a IEEE 1667 protocol device\n"));
185 if (!TcgFlag
&& !IeeeFlag
) {
186 DEBUG ((EFI_D_INFO
, "Neither a TCG nor IEEE 1667 protocol device is found\n"));
192 // As long as TCG protocol is supported, send out a TPer Reset
193 // TCG command to the device via the TrustedSend command with a non-zero Transfer Length.
195 Status
= Ssp
->SendData (
198 100000000, // Timeout 10-sec
199 SECURITY_PROTOCOL_TCG
, // SecurityProtocol
200 0x0400, // SecurityProtocolSpecifcData
201 512, // PayloadBufferSize,
202 Buffer
// PayloadBuffer
205 if (!EFI_ERROR (Status
)) {
206 DEBUG ((EFI_D_INFO
, "Send TPer Reset Command Successfully !\n"));
208 DEBUG ((EFI_D_INFO
, "Send TPer Reset Command Fail !\n"));
214 // TBD : Perform a TPer Reset via IEEE 1667 Protocol
216 DEBUG ((EFI_D_INFO
, "IEEE 1667 Protocol didn't support yet!\n"));
221 if (Buffer
!= NULL
) {
227 Notification function of END_OF_DXE.
229 @param[in] Event Event whose notification function is being invoked.
230 @param[in] Context Pointer to the notification function's context.
235 TPerResetAtEndOfDxe (
240 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Ssp
;
241 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
244 EFI_HANDLE
*HandleBuffer
;
248 // Locate all SSP protocol instances.
253 Status
= gBS
->LocateHandleBuffer (
255 &gEfiStorageSecurityCommandProtocolGuid
,
261 if (EFI_ERROR (Status
) || (HandleCount
== 0) || (HandleBuffer
== NULL
)) {
265 for (Index
= 0; Index
< HandleCount
; Index
++) {
267 // Get the SSP interface.
269 Status
= gBS
->HandleProtocol(
271 &gEfiStorageSecurityCommandProtocolGuid
,
275 if (EFI_ERROR (Status
)) {
279 Status
= gBS
->HandleProtocol(
281 &gEfiBlockIoProtocolGuid
,
285 if (EFI_ERROR (Status
)) {
289 InitiateTPerReset (Ssp
, BlockIo
->Media
->MediaId
);
292 FreePool (HandleBuffer
);
296 Entry Point for TCG MOR Control driver.
298 @param[in] ImageHandle Image handle of this driver.
299 @param[in] SystemTable A Pointer to the EFI System Table.
302 @return Others Some error occurs.
306 MorDriverEntryPoint (
307 IN EFI_HANDLE ImageHandle
,
308 IN EFI_SYSTEM_TABLE
*SystemTable
316 /// The firmware is required to create the MemoryOverwriteRequestControl UEFI variable.
319 DataSize
= sizeof (mMorControl
);
320 Status
= gRT
->GetVariable (
321 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
322 &gEfiMemoryOverwriteControlDataGuid
,
327 if (EFI_ERROR (Status
)) {
329 // Set default value to 0
332 Status
= gRT
->SetVariable (
333 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
334 &gEfiMemoryOverwriteControlDataGuid
,
335 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
339 DEBUG ((EFI_D_INFO
, "TcgMor: Create MOR variable! Status = %r\n", Status
));
342 // Create a Ready To Boot Event and Clear the MorControl bit in the call back function.
344 DEBUG ((DEBUG_INFO
, "TcgMor: Create ReadyToBoot Event for MorControl Bit cleanning!\n"));
345 Status
= EfiCreateEventReadyToBootEx (
351 if (EFI_ERROR (Status
)) {
356 // Register EFI_END_OF_DXE_EVENT_GROUP_GUID event.
358 DEBUG ((EFI_D_INFO
, "TcgMor: Create EndofDxe Event for Mor TPer Reset!\n"));
359 Status
= gBS
->CreateEventEx (
364 &gEfiEndOfDxeEventGroupGuid
,
367 if (EFI_ERROR (Status
)) {