42 Private = NamespaceInfo->Controller;
44 BlockSize = NamespaceInfo->Media.BlockSize;
45 Bytes = Blocks * BlockSize;
51 CommandPacket.NvmeCmd = &Command;
52 CommandPacket.NvmeCompletion = &Completion;
54 CommandPacket.NvmeCmd->Cdw0.Opcode = NVME_IO_READ_OPC;
55 CommandPacket.NvmeCmd->Nsid = NamespaceInfo->NamespaceId;
56 CommandPacket.TransferBuffer = (VOID *)Buffer;
58 CommandPacket.TransferLength = Bytes;
59 CommandPacket.CommandTimeout = NVME_GENERIC_TIMEOUT;
60 CommandPacket.QueueType = NVME_IO_QUEUE;
62 CommandPacket.NvmeCmd->Cdw10 = (UINT32)Lba;
63 CommandPacket.NvmeCmd->Cdw11 = (UINT32)
RShiftU64 (Lba, 32);
64 CommandPacket.NvmeCmd->Cdw12 = (Blocks - 1) & 0xFFFF;
66 CommandPacket.NvmeCmd->Flags = CDW10_VALID | CDW11_VALID | CDW12_VALID;
70 NamespaceInfo->NamespaceId,
101 UINT32 MaxTransferBlocks;
106 Private = NamespaceInfo->Controller;
107 BlockSize = NamespaceInfo->Media.BlockSize;
108 OrginalBlocks = Blocks;
110 if (Private->ControllerData->Mdts != 0) {
111 MaxTransferBlocks = (1 << (Private->ControllerData->Mdts)) * (1 << (Private->Cap.Mpsmin + 12)) / BlockSize;
113 MaxTransferBlocks = 1024;
121 Blocks > MaxTransferBlocks ? MaxTransferBlocks : (UINT32)Blocks
123 if (EFI_ERROR (Status)) {
125 MaxTransferBlocks = MaxTransferBlocks >> 1;
127 if ((Retries > NVME_READ_MAX_RETRY) || (MaxTransferBlocks < 1)) {
128 DEBUG ((DEBUG_ERROR,
"%a: ReadSectors fail, Status - %r\n", __func__, Status));
134 "%a: ReadSectors fail, retry with smaller transfer block number - 0x%x\n",
141 if (Blocks > MaxTransferBlocks) {
142 Blocks -= MaxTransferBlocks;
143 Buffer += (MaxTransferBlocks * BlockSize);
144 Lba += MaxTransferBlocks;
152 "%a: Lba = 0x%08Lx, Original = 0x%08Lx, "
153 "Remaining = 0x%08Lx, BlockSize = 0x%x, Status = %r\n",
156 (UINT64)OrginalBlocks,
190 if ((This ==
NULL) || (NumberBlockDevices ==
NULL)) {
191 return EFI_INVALID_PARAMETER;
194 Private = GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO (This);
195 *NumberBlockDevices = Private->ActiveNamespaceNum;
252 if ((This ==
NULL) || (MediaInfo ==
NULL)) {
253 return EFI_INVALID_PARAMETER;
256 Private = GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO (This);
258 if ((DeviceIndex == 0) || (DeviceIndex > Private->ActiveNamespaceNum)) {
259 return EFI_INVALID_PARAMETER;
263 MediaInfo->MediaPresent =
TRUE;
264 MediaInfo->LastBlock = (
UINTN)Private->NamespaceInfo[DeviceIndex-1].Media.
LastBlock;
265 MediaInfo->BlockSize = Private->NamespaceInfo[DeviceIndex-1].Media.
BlockSize;
318 UINTN NumberOfBlocks;
320 Private = GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO (This);
325 if ((This ==
NULL) || (Buffer ==
NULL)) {
326 return EFI_INVALID_PARAMETER;
329 if (BufferSize == 0) {
333 if ((DeviceIndex == 0) || (DeviceIndex > Private->ActiveNamespaceNum)) {
334 return EFI_INVALID_PARAMETER;
340 NamespaceInfo = &(Private->NamespaceInfo[DeviceIndex - 1]);
341 BlockSize = NamespaceInfo->Media.
BlockSize;
342 if (BufferSize % BlockSize != 0) {
343 return EFI_BAD_BUFFER_SIZE;
346 if (StartLBA > NamespaceInfo->Media.
LastBlock) {
347 return EFI_INVALID_PARAMETER;
350 NumberOfBlocks = BufferSize / BlockSize;
351 if (NumberOfBlocks - 1 > NamespaceInfo->Media.
LastBlock - StartLBA) {
352 return EFI_INVALID_PARAMETER;
355 return NvmeRead (NamespaceInfo, (
UINTN)Buffer, StartLBA, NumberOfBlocks);
384 if ((This ==
NULL) || (NumberBlockDevices ==
NULL)) {
385 return EFI_INVALID_PARAMETER;
388 Private = GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO2 (This);
389 *NumberBlockDevices = Private->ActiveNamespaceNum;
448 if ((This ==
NULL) || (MediaInfo ==
NULL)) {
449 return EFI_INVALID_PARAMETER;
452 Private = GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO2 (This);
460 if (EFI_ERROR (Status)) {
466 &(Private->NamespaceInfo[DeviceIndex - 1].Media),
521 return EFI_INVALID_PARAMETER;
524 Private = GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO2 (This);
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define DEBUG(Expression)
EFI_PEI_BLOCK_DEVICE_TYPE
EFI_STATUS EFIAPI NvmeBlockIoPeimReadBlocks(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, IN UINTN DeviceIndex, IN EFI_PEI_LBA StartLBA, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS EFIAPI NvmeBlockIoPeimGetMediaInfo(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, IN UINTN DeviceIndex, OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo)
EFI_STATUS EFIAPI NvmeBlockIoPeimGetMediaInfo2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, IN UINTN DeviceIndex, OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo)
EFI_STATUS EFIAPI NvmeBlockIoPeimReadBlocks2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, IN UINTN DeviceIndex, IN EFI_PEI_LBA StartLBA, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS ReadSectors(IN PEI_NVME_NAMESPACE_INFO *NamespaceInfo, OUT UINTN Buffer, IN UINT64 Lba, IN UINT32 Blocks)
EFI_STATUS EFIAPI NvmeBlockIoPeimGetDeviceNo(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, OUT UINTN *NumberBlockDevices)
EFI_STATUS EFIAPI NvmeBlockIoPeimGetDeviceNo2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, OUT UINTN *NumberBlockDevices)
EFI_STATUS NvmeRead(IN PEI_NVME_NAMESPACE_INFO *NamespaceInfo, OUT UINTN Buffer, IN UINT64 Lba, IN UINTN Blocks)
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)