TianoCore EDK2 master
Loading...
Searching...
No Matches
NvmExpressPeiStorageSecurity.c
Go to the documentation of this file.
1
11#include "NvmExpressPei.h"
12
51 IN OUT VOID *Buffer,
52 IN UINT8 SecurityProtocolId,
53 IN UINT16 SecurityProtocolSpecificData,
54 IN UINTN TransferLength,
55 IN BOOLEAN IsTrustSend,
56 IN UINT64 Timeout,
57 OUT UINTN *TransferLengthOut
58 )
59{
63 EFI_STATUS Status;
64 UINT16 SpecificData;
66
67 NvmePassThru = &Private->NvmePassThruPpi;
68 ZeroMem (&CommandPacket, sizeof (EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET));
69 ZeroMem (&Command, sizeof (EFI_NVM_EXPRESS_COMMAND));
70 ZeroMem (&Completion, sizeof (EFI_NVM_EXPRESS_COMPLETION));
71
72 CommandPacket.NvmeCmd = &Command;
73 CommandPacket.NvmeCompletion = &Completion;
74
75 //
76 // Change Endianness of SecurityProtocolSpecificData
77 //
78 SpecificData = (((SecurityProtocolSpecificData << 8) & 0xFF00) | (SecurityProtocolSpecificData >> 8));
79
80 if (IsTrustSend) {
81 Command.Cdw0.Opcode = NVME_ADMIN_SECURITY_SEND_CMD;
82 CommandPacket.TransferBuffer = Buffer;
83 CommandPacket.TransferLength = (UINT32)TransferLength;
84 CommandPacket.NvmeCmd->Cdw10 = (UINT32)((SecurityProtocolId << 24) | (SpecificData << 8));
85 CommandPacket.NvmeCmd->Cdw11 = (UINT32)TransferLength;
86 } else {
87 Command.Cdw0.Opcode = NVME_ADMIN_SECURITY_RECEIVE_CMD;
88 CommandPacket.TransferBuffer = Buffer;
89 CommandPacket.TransferLength = (UINT32)TransferLength;
90 CommandPacket.NvmeCmd->Cdw10 = (UINT32)((SecurityProtocolId << 24) | (SpecificData << 8));
91 CommandPacket.NvmeCmd->Cdw11 = (UINT32)TransferLength;
92 }
93
94 CommandPacket.NvmeCmd->Flags = CDW10_VALID | CDW11_VALID;
95 CommandPacket.NvmeCmd->Nsid = NVME_CONTROLLER_NSID;
96 CommandPacket.CommandTimeout = Timeout;
97 CommandPacket.QueueType = NVME_ADMIN_QUEUE;
98
99 Status = NvmePassThru->PassThru (
101 NVME_CONTROLLER_NSID,
102 &CommandPacket
103 );
104
105 if (!IsTrustSend) {
106 if (EFI_ERROR (Status)) {
107 *TransferLengthOut = 0;
108 } else {
109 *TransferLengthOut = (UINTN)TransferLength;
110 }
111 }
112
113 return Status;
114}
115
127EFIAPI
130 OUT UINTN *NumberofDevices
131 )
132{
134
135 if ((This == NULL) || (NumberofDevices == NULL)) {
136 return EFI_INVALID_PARAMETER;
137 }
138
139 Private = GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_STROAGE_SECURITY (This);
140 *NumberofDevices = Private->ActiveNamespaceNum;
141
142 return EFI_SUCCESS;
143}
144
171EFIAPI
174 IN UINTN DeviceIndex,
175 OUT UINTN *DevicePathLength,
176 OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
177 )
178{
180
181 if ((This == NULL) || (DevicePathLength == NULL) || (DevicePath == NULL)) {
182 return EFI_INVALID_PARAMETER;
183 }
184
185 Private = GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_STROAGE_SECURITY (This);
186 if ((DeviceIndex == 0) || (DeviceIndex > Private->ActiveNamespaceNum)) {
187 return EFI_INVALID_PARAMETER;
188 }
189
190 return NvmeBuildDevicePath (
191 Private,
192 Private->NamespaceInfo[DeviceIndex-1].NamespaceId,
193 Private->NamespaceInfo[DeviceIndex-1].NamespaceUuid,
194 DevicePathLength,
195 DevicePath
196 );
197}
198
286EFIAPI
289 IN UINTN DeviceIndex,
290 IN UINT64 Timeout,
291 IN UINT8 SecurityProtocolId,
292 IN UINT16 SecurityProtocolSpecificData,
293 IN UINTN PayloadBufferSize,
294 OUT VOID *PayloadBuffer,
295 OUT UINTN *PayloadTransferSize
296 )
297{
299 EFI_STATUS Status;
300
301 if ((PayloadBuffer == NULL) || (PayloadTransferSize == NULL) || (PayloadBufferSize == 0)) {
302 return EFI_INVALID_PARAMETER;
303 }
304
305 Private = GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_STROAGE_SECURITY (This);
306
307 Status = TrustTransferNvmeDevice (
308 Private,
309 PayloadBuffer,
310 SecurityProtocolId,
311 SecurityProtocolSpecificData,
312 PayloadBufferSize,
313 FALSE,
314 Timeout,
315 PayloadTransferSize
316 );
317
318 return Status;
319}
320
386EFIAPI
389 IN UINTN DeviceIndex,
390 IN UINT64 Timeout,
391 IN UINT8 SecurityProtocolId,
392 IN UINT16 SecurityProtocolSpecificData,
393 IN UINTN PayloadBufferSize,
394 IN VOID *PayloadBuffer
395 )
396{
398 EFI_STATUS Status;
399
400 if ((PayloadBuffer == NULL) && (PayloadBufferSize != 0)) {
401 return EFI_INVALID_PARAMETER;
402 }
403
404 Private = GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_STROAGE_SECURITY (This);
405
406 Status = TrustTransferNvmeDevice (
407 Private,
408 PayloadBuffer,
409 SecurityProtocolId,
410 SecurityProtocolSpecificData,
411 PayloadBufferSize,
412 TRUE,
413 Timeout,
414 NULL
415 );
416
417 return Status;
418}
UINT64 UINTN
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS NvmeBuildDevicePath(IN PEI_NVME_CONTROLLER_PRIVATE_DATA *Private, IN UINT32 NamespaceId, IN UINT64 NamespaceUuid, OUT UINTN *DevicePathLength, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
Definition: DevicePath.c:177
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI NvmePassThru(IN EDKII_PEI_NVM_EXPRESS_PASS_THRU_PPI *This, IN UINT32 NamespaceId, IN OUT EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *Packet)
EFI_STATUS EFIAPI NvmeStorageSecurityGetDeviceNo(IN EDKII_PEI_STORAGE_SECURITY_CMD_PPI *This, OUT UINTN *NumberofDevices)
EFI_STATUS EFIAPI NvmeStorageSecurityGetDevicePath(IN EDKII_PEI_STORAGE_SECURITY_CMD_PPI *This, IN UINTN DeviceIndex, OUT UINTN *DevicePathLength, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
EFI_STATUS EFIAPI NvmeStorageSecuritySendData(IN EDKII_PEI_STORAGE_SECURITY_CMD_PPI *This, IN UINTN DeviceIndex, IN UINT64 Timeout, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN PayloadBufferSize, IN VOID *PayloadBuffer)
EFI_STATUS EFIAPI NvmeStorageSecurityReceiveData(IN EDKII_PEI_STORAGE_SECURITY_CMD_PPI *This, IN UINTN DeviceIndex, IN UINT64 Timeout, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN PayloadBufferSize, OUT VOID *PayloadBuffer, OUT UINTN *PayloadTransferSize)
EFI_STATUS TrustTransferNvmeDevice(IN PEI_NVME_CONTROLLER_PRIVATE_DATA *Private, IN OUT VOID *Buffer, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN TransferLength, IN BOOLEAN IsTrustSend, IN UINT64 Timeout, OUT UINTN *TransferLengthOut)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112