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 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 @param[in] Event Event whose notification function is being invoked
27 @param[in] Context Pointer to the notification function's context
40 if (MOR_CLEAR_MEMORY_VALUE (mMorControl
) == 0x0) {
42 // MorControl is expected, directly return to avoid unnecessary variable operation
47 // Clear MOR_CLEAR_MEMORY_BIT
49 DEBUG ((EFI_D_INFO
, "TcgMor: Clear MorClearMemory bit\n"));
52 DataSize
= sizeof (mMorControl
);
53 Status
= gRT
->SetVariable (
54 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
55 &gEfiMemoryOverwriteControlDataGuid
,
56 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
60 if (EFI_ERROR (Status
)) {
61 DEBUG ((EFI_D_ERROR
, "TcgMor: Clear MOR_CLEAR_MEMORY_BIT failure, Status = %r\n"));
66 Send TPer Reset command to reset eDrive to lock all protected bands.
67 Typically, there are 2 mechanism for resetting eDrive. They are:
68 1. TPer Reset through IEEE 1667 protocol.
69 2. TPer Reset through native TCG protocol.
70 This routine will detect what protocol the attached eDrive comform to, TCG or
71 IEEE 1667 protocol. Then send out TPer Reset command separately.
73 @param[in] Ssp The pointer to EFI_STORAGE_SECURITY_COMMAND_PROTOCOL instance.
74 @param[in] MediaId ID of the medium to receive data from or send data to.
79 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Ssp
,
91 SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*Data
;
98 // ATA8-ACS 7.57.6.1 indicates the Transfer Length field requirements a multiple of 512.
99 // If the length of the TRUSTED RECEIVE parameter data is greater than the Transfer Length,
100 // then the device shall return the TRUSTED RECEIVE parameter data truncated to the requested Transfer Length.
102 Len
= ROUNDUP512(sizeof(SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
));
103 Buffer
= AllocateZeroPool(Len
);
105 if (Buffer
== NULL
) {
110 // When the Security Protocol field is set to 00h, and SP Specific is set to 0000h in a TRUSTED RECEIVE
111 // command, the device basic information data shall be returned.
113 Status
= Ssp
->ReceiveData (
116 100000000, // Timeout 10-sec
117 0, // SecurityProtocol
118 0, // SecurityProtocolSpecifcData
119 Len
, // PayloadBufferSize,
120 Buffer
, // PayloadBuffer
123 if (EFI_ERROR (Status
)) {
128 // In returned data, the ListLength field indicates the total length, in bytes,
129 // of the supported security protocol list.
131 Data
= (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*)Buffer
;
132 Len
= ROUNDUP512(sizeof (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
) +
133 (Data
->SupportedSecurityListLength
[0] << 8) +
134 (Data
->SupportedSecurityListLength
[1])
138 // Free original buffer and allocate new buffer.
141 Buffer
= AllocateZeroPool(Len
);
142 if (Buffer
== NULL
) {
147 // Read full supported security protocol list from device.
149 Status
= Ssp
->ReceiveData (
152 100000000, // Timeout 10-sec
153 0, // SecurityProtocol
154 0, // SecurityProtocolSpecifcData
155 Len
, // PayloadBufferSize,
156 Buffer
, // PayloadBuffer
160 if (EFI_ERROR (Status
)) {
164 Data
= (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA
*)Buffer
;
165 Len
= (Data
->SupportedSecurityListLength
[0] << 8) + Data
->SupportedSecurityListLength
[1];
168 // Iterate full supported security protocol list to check if TCG or IEEE 1667 protocol
171 for (Index
= 0; Index
< Len
; Index
++) {
172 if (Data
->SupportedSecurityProtocol
[Index
] == SECURITY_PROTOCOL_TCG
) {
174 // Found a TCG device.
177 DEBUG ((EFI_D_INFO
, "This device is a TCG protocol device\n"));
181 if (Data
->SupportedSecurityProtocol
[Index
] == SECURITY_PROTOCOL_IEEE1667
) {
183 // Found a IEEE 1667 device.
186 DEBUG ((EFI_D_INFO
, "This device is a IEEE 1667 protocol device\n"));
191 if (!TcgFlag
&& !IeeeFlag
) {
192 DEBUG ((EFI_D_INFO
, "Neither a TCG nor IEEE 1667 protocol device is found\n"));
198 // As long as TCG protocol is supported, send out a TPer Reset
199 // TCG command to the device via the TrustedSend command with a non-zero Transfer Length.
201 Status
= Ssp
->SendData (
204 100000000, // Timeout 10-sec
205 SECURITY_PROTOCOL_TCG
, // SecurityProtocol
206 0x0400, // SecurityProtocolSpecifcData
207 512, // PayloadBufferSize,
208 Buffer
// PayloadBuffer
211 if (!EFI_ERROR (Status
)) {
212 DEBUG ((EFI_D_INFO
, "Send TPer Reset Command Successfully !\n"));
214 DEBUG ((EFI_D_INFO
, "Send TPer Reset Command Fail !\n"));
220 // TBD : Perform a TPer Reset via IEEE 1667 Protocol
222 DEBUG ((EFI_D_INFO
, "IEEE 1667 Protocol didn't support yet!\n"));
227 if (Buffer
!= NULL
) {
233 Notification function of END_OF_DXE.
235 @param[in] Event Event whose notification function is being invoked.
236 @param[in] Context Pointer to the notification function's context.
241 TPerResetAtEndOfDxe (
246 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Ssp
;
247 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
250 EFI_HANDLE
*HandleBuffer
;
254 // Locate all SSP protocol instances.
259 Status
= gBS
->LocateHandleBuffer (
261 &gEfiStorageSecurityCommandProtocolGuid
,
267 if (EFI_ERROR (Status
) || (HandleCount
== 0) || (HandleBuffer
== NULL
)) {
271 for (Index
= 0; Index
< HandleCount
; Index
++) {
273 // Get the SSP interface.
275 Status
= gBS
->HandleProtocol(
277 &gEfiStorageSecurityCommandProtocolGuid
,
281 if (EFI_ERROR (Status
)) {
285 Status
= gBS
->HandleProtocol(
287 &gEfiBlockIoProtocolGuid
,
291 if (EFI_ERROR (Status
)) {
295 InitiateTPerReset (Ssp
, BlockIo
->Media
->MediaId
);
298 FreePool (HandleBuffer
);
302 Entry Point for TCG MOR Control driver.
304 @param[in] ImageHandle Image handle of this driver.
305 @param[in] SystemTable A Pointer to the EFI System Table.
308 @return Others Some error occurs.
312 MorDriverEntryPoint (
313 IN EFI_HANDLE ImageHandle
,
314 IN EFI_SYSTEM_TABLE
*SystemTable
322 /// The firmware is required to create the MemoryOverwriteRequestControl UEFI variable.
325 DataSize
= sizeof (mMorControl
);
326 Status
= gRT
->GetVariable (
327 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
328 &gEfiMemoryOverwriteControlDataGuid
,
333 if (EFI_ERROR (Status
)) {
335 // Set default value to 0
338 Status
= gRT
->SetVariable (
339 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
340 &gEfiMemoryOverwriteControlDataGuid
,
341 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
345 DEBUG ((EFI_D_INFO
, "TcgMor: Create MOR variable! Status = %r\n", Status
));
348 // Create a Ready To Boot Event and Clear the MorControl bit in the call back function.
350 DEBUG ((EFI_D_INFO
, "TcgMor: Create ReadyToBoot Event for MorControl Bit cleanning!\n"));
351 Status
= EfiCreateEventReadyToBootEx (
357 if (EFI_ERROR (Status
)) {
362 // Register EFI_END_OF_DXE_EVENT_GROUP_GUID event.
364 DEBUG ((EFI_D_INFO
, "TcgMor: Create EndofDxe Event for Mor TPer Reset!\n"));
365 Status
= gBS
->CreateEventEx (
370 &gEfiEndOfDxeEventGroupGuid
,
373 if (EFI_ERROR (Status
)) {