]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/NvmExpressDxe: Correct Prp list creation algorithm.
authorFeng Tian <feng.tian@intel.com>
Mon, 27 Apr 2015 05:36:16 +0000 (05:36 +0000)
committererictian <erictian@Edk2>
Mon, 27 Apr 2015 05:36:16 +0000 (05:36 +0000)
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 <feng.tian@intel.com>
Reviewed-by: Baban Devkate <baban.devkate@seagate.com>
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

index 468785807f5491bc26642dba3a2418bb220a8c78..d752ec2bd5a8e0200060190bbbb76520d001c7e1 100644 (file)
@@ -3,7 +3,7 @@
   NVM Express specification.\r
 \r
   (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -256,9 +256,15 @@ NvmeCreatePrpList (
   //\r
   // Calculate total PrpList number.\r
   //\r
-  *PrpListNo = (UINTN)DivU64x64Remainder ((UINT64)Pages, (UINT64)PrpEntryNo, &Remainder);\r
-  if (Remainder != 0) {\r
+  *PrpListNo = (UINTN)DivU64x64Remainder ((UINT64)Pages, (UINT64)PrpEntryNo - 1, &Remainder);\r
+  if (*PrpListNo == 0) {\r
+    *PrpListNo = 1;\r
+  } else if (Remainder != 0) && (Remainder != 1) {\r
     *PrpListNo += 1;\r
+  } else if (Remainder == 1) {\r
+    Remainder = PrpEntryNo;\r
+  } else if (Remainder == 0) {\r
+    Remainder = PrpEntryNo - 1;\r
   }\r
 \r
   Status = PciIo->AllocateBuffer (\r
@@ -293,7 +299,7 @@ NvmeCreatePrpList (
   //\r
   ZeroMem (*PrpListHost, Bytes);\r
   for (PrpListIndex = 0; PrpListIndex < *PrpListNo - 1; ++PrpListIndex) {\r
-    PrpListBase = *(UINT8*)PrpListHost + PrpListIndex * EFI_PAGE_SIZE;\r
+    PrpListBase = *(UINT64*)PrpListHost + PrpListIndex * EFI_PAGE_SIZE;\r
 \r
     for (PrpEntryIndex = 0; PrpEntryIndex < PrpEntryNo; ++PrpEntryIndex) {\r
       if (PrpEntryIndex != PrpEntryNo - 1) {\r
@@ -314,7 +320,7 @@ NvmeCreatePrpList (
   // Fill last PRP list.\r
   //\r
   PrpListBase = *(UINT64*)PrpListHost + PrpListIndex * EFI_PAGE_SIZE;\r
-  for (PrpEntryIndex = 0; PrpEntryIndex < ((Remainder != 0) ? Remainder : PrpEntryNo); ++PrpEntryIndex) {\r
+  for (PrpEntryIndex = 0; PrpEntryIndex < Remainder; ++PrpEntryIndex) {\r
     *((UINT64*)(UINTN)PrpListBase + PrpEntryIndex) = PhysicalAddr;\r
     PhysicalAddr += EFI_PAGE_SIZE;\r
   }\r