2 TCG MOR (Memory Overwrite Request) Control Driver.
4 This driver initialize 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
42 // Clear MOR_CLEAR_MEMORY_BIT
44 DEBUG ((DEBUG_INFO
, "TcgMor: Clear MorClearMemory bit\n"));
47 DataSize
= sizeof (mMorControl
);
48 Status
= gRT
->SetVariable (
49 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
50 &gEfiMemoryOverwriteControlDataGuid
,
51 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
55 if (EFI_ERROR (Status
)) {
56 DEBUG ((DEBUG_ERROR
, "TcgMor: Clear MOR_CLEAR_MEMORY_BIT failure, Status = %r\n", Status
));
61 Send TPer Reset command to reset eDrive to lock all protected bands.
62 Typically, there are 2 mechanism for resetting eDrive. They are:
63 1. TPer Reset through IEEE 1667 protocol.
64 2. TPer Reset through native TCG protocol.
65 This routine will detect what protocol the attached eDrive conform to, TCG or
66 IEEE 1667 protocol. Then send out TPer Reset command separately.
68 @param[in] Ssp The pointer to EFI_STORAGE_SECURITY_COMMAND_PROTOCOL instance.
69 @param[in] MediaId ID of the medium to receive data from or send data to.
74 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, // SecurityProtocolSpecificData
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
;
127 sizeof (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
) +
128 (Data
->SupportedSecurityListLength
[0] << 8) +
129 (Data
->SupportedSecurityListLength
[1])
133 // Free original buffer and allocate new buffer.
136 Buffer
= AllocateZeroPool (Len
);
137 if (Buffer
== NULL
) {
142 // Read full supported security protocol list from device.
144 Status
= Ssp
->ReceiveData (
147 100000000, // Timeout 10-sec
148 0, // SecurityProtocol
149 0, // SecurityProtocolSpecificData
150 Len
, // PayloadBufferSize,
151 Buffer
, // PayloadBuffer
155 if (EFI_ERROR (Status
)) {
159 Data
= (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*)Buffer
;
160 Len
= (Data
->SupportedSecurityListLength
[0] << 8) + Data
->SupportedSecurityListLength
[1];
163 // Iterate full supported security protocol list to check if TCG or IEEE 1667 protocol
166 for (Index
= 0; Index
< Len
; Index
++) {
167 if (Data
->SupportedSecurityProtocol
[Index
] == SECURITY_PROTOCOL_TCG
) {
169 // Found a TCG device.
172 DEBUG ((DEBUG_INFO
, "This device is a TCG protocol device\n"));
176 if (Data
->SupportedSecurityProtocol
[Index
] == SECURITY_PROTOCOL_IEEE1667
) {
178 // Found a IEEE 1667 device.
181 DEBUG ((DEBUG_INFO
, "This device is a IEEE 1667 protocol device\n"));
186 if (!TcgFlag
&& !IeeeFlag
) {
187 DEBUG ((DEBUG_INFO
, "Neither a TCG nor IEEE 1667 protocol device is found\n"));
193 // As long as TCG protocol is supported, send out a TPer Reset
194 // TCG command to the device via the TrustedSend command with a non-zero Transfer Length.
196 Status
= Ssp
->SendData (
199 100000000, // Timeout 10-sec
200 SECURITY_PROTOCOL_TCG
, // SecurityProtocol
201 0x0400, // SecurityProtocolSpecificData
202 512, // PayloadBufferSize,
203 Buffer
// PayloadBuffer
206 if (!EFI_ERROR (Status
)) {
207 DEBUG ((DEBUG_INFO
, "Send TPer Reset Command Successfully !\n"));
209 DEBUG ((DEBUG_INFO
, "Send TPer Reset Command Fail !\n"));
215 // TBD : Perform a TPer Reset via IEEE 1667 Protocol
217 DEBUG ((DEBUG_INFO
, "IEEE 1667 Protocol didn't support yet!\n"));
222 if (Buffer
!= NULL
) {
228 Notification function of END_OF_DXE.
230 @param[in] Event Event whose notification function is being invoked.
231 @param[in] Context Pointer to the notification function's context.
236 TPerResetAtEndOfDxe (
241 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Ssp
;
242 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
245 EFI_HANDLE
*HandleBuffer
;
249 // Locate all SSP protocol instances.
254 Status
= gBS
->LocateHandleBuffer (
256 &gEfiStorageSecurityCommandProtocolGuid
,
262 if (EFI_ERROR (Status
) || (HandleCount
== 0) || (HandleBuffer
== NULL
)) {
266 for (Index
= 0; Index
< HandleCount
; Index
++) {
268 // Get the SSP interface.
270 Status
= gBS
->HandleProtocol (
272 &gEfiStorageSecurityCommandProtocolGuid
,
276 if (EFI_ERROR (Status
)) {
280 Status
= gBS
->HandleProtocol (
282 &gEfiBlockIoProtocolGuid
,
286 if (EFI_ERROR (Status
)) {
290 InitiateTPerReset (Ssp
, BlockIo
->Media
->MediaId
);
293 FreePool (HandleBuffer
);
297 Entry Point for TCG MOR Control driver.
299 @param[in] ImageHandle Image handle of this driver.
300 @param[in] SystemTable A Pointer to the EFI System Table.
303 @return Others Some error occurs.
307 MorDriverEntryPoint (
308 IN EFI_HANDLE ImageHandle
,
309 IN EFI_SYSTEM_TABLE
*SystemTable
317 /// The firmware is required to create the MemoryOverwriteRequestControl UEFI variable.
320 DataSize
= sizeof (mMorControl
);
321 Status
= gRT
->GetVariable (
322 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
323 &gEfiMemoryOverwriteControlDataGuid
,
328 if (EFI_ERROR (Status
)) {
330 // Set default value to 0
333 Status
= gRT
->SetVariable (
334 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
335 &gEfiMemoryOverwriteControlDataGuid
,
336 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
340 DEBUG ((DEBUG_INFO
, "TcgMor: Create MOR variable! Status = %r\n", Status
));
343 // Create a Ready To Boot Event and Clear the MorControl bit in the call back function.
345 DEBUG ((DEBUG_INFO
, "TcgMor: Create ReadyToBoot Event for MorControl Bit cleaning!\n"));
346 Status
= EfiCreateEventReadyToBootEx (
352 if (EFI_ERROR (Status
)) {
357 // Register EFI_END_OF_DXE_EVENT_GROUP_GUID event.
359 DEBUG ((DEBUG_INFO
, "TcgMor: Create EndofDxe Event for Mor TPer Reset!\n"));
360 Status
= gBS
->CreateEventEx (
365 &gEfiEndOfDxeEventGroupGuid
,
368 if (EFI_ERROR (Status
)) {