From 769402ef68f1fa611f8bcc9b7a15a5ed13ea4edc Mon Sep 17 00:00:00 2001 From: Feng Tian Date: Mon, 27 Apr 2015 05:36:16 +0000 Subject: MdeModulePkg/NvmExpressDxe: Correct Prp list creation algorithm. The number of the Prp lists and the number of the entries in last Prp list may be calculated wrongly. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Feng Tian Reviewed-by: Baban Devkate git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17208 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'MdeModulePkg/Bus/Pci') diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c index 4687858..d752ec2 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c @@ -3,7 +3,7 @@ NVM Express specification. (C) Copyright 2014 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2013, Intel Corporation. All rights reserved.
+ Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -256,9 +256,15 @@ NvmeCreatePrpList ( // // Calculate total PrpList number. // - *PrpListNo = (UINTN)DivU64x64Remainder ((UINT64)Pages, (UINT64)PrpEntryNo, &Remainder); - if (Remainder != 0) { + *PrpListNo = (UINTN)DivU64x64Remainder ((UINT64)Pages, (UINT64)PrpEntryNo - 1, &Remainder); + if (*PrpListNo == 0) { + *PrpListNo = 1; + } else if (Remainder != 0) && (Remainder != 1) { *PrpListNo += 1; + } else if (Remainder == 1) { + Remainder = PrpEntryNo; + } else if (Remainder == 0) { + Remainder = PrpEntryNo - 1; } Status = PciIo->AllocateBuffer ( @@ -293,7 +299,7 @@ NvmeCreatePrpList ( // ZeroMem (*PrpListHost, Bytes); for (PrpListIndex = 0; PrpListIndex < *PrpListNo - 1; ++PrpListIndex) { - PrpListBase = *(UINT8*)PrpListHost + PrpListIndex * EFI_PAGE_SIZE; + PrpListBase = *(UINT64*)PrpListHost + PrpListIndex * EFI_PAGE_SIZE; for (PrpEntryIndex = 0; PrpEntryIndex < PrpEntryNo; ++PrpEntryIndex) { if (PrpEntryIndex != PrpEntryNo - 1) { @@ -314,7 +320,7 @@ NvmeCreatePrpList ( // Fill last PRP list. // PrpListBase = *(UINT64*)PrpListHost + PrpListIndex * EFI_PAGE_SIZE; - for (PrpEntryIndex = 0; PrpEntryIndex < ((Remainder != 0) ? Remainder : PrpEntryNo); ++PrpEntryIndex) { + for (PrpEntryIndex = 0; PrpEntryIndex < Remainder; ++PrpEntryIndex) { *((UINT64*)(UINTN)PrpListBase + PrpEntryIndex) = PhysicalAddr; PhysicalAddr += EFI_PAGE_SIZE; } -- cgit v1.1