]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelSiliconPkg/Feature/VTd/IntelVTdDxe/TranslationTable.c
IntelSiliconPkg IntelVTdDxe: Fix flush cache issue
[mirror_edk2.git] / IntelSiliconPkg / Feature / VTd / IntelVTdDxe / TranslationTable.c
index cecb5d23efbf36aa4d3c578db276cb9bcf8e3e1d..bce5a45105d2f97eba408f5209b073f453fc2616 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2017 - 2018, 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
@@ -226,7 +226,7 @@ CreateSecondLevelPagingEntryTable (
 \r
     Lvl3Start = RShiftU64 (BaseAddress, 30) & 0x1FF;\r
     if (ALIGN_VALUE_LOW(BaseAddress + SIZE_1GB, SIZE_1GB) <= EndAddress) {\r
-      Lvl3End = SIZE_4KB/sizeof(VTD_SECOND_LEVEL_PAGING_ENTRY);\r
+      Lvl3End = SIZE_4KB/sizeof(VTD_SECOND_LEVEL_PAGING_ENTRY) - 1;\r
     } else {\r
       Lvl3End = RShiftU64 (EndAddress - 1, 30) & 0x1FF;\r
     }\r
@@ -252,16 +252,21 @@ CreateSecondLevelPagingEntryTable (
         Lvl2PtEntry[Index2].Bits.PageSize = 1;\r
         BaseAddress += SIZE_2MB;\r
         if (BaseAddress >= MemoryLimit) {\r
-          goto Done;\r
+          break;\r
         }\r
       }\r
       FlushPageTableMemory (VtdIndex, (UINTN)Lvl2PtEntry, SIZE_4KB);\r
+      if (BaseAddress >= MemoryLimit) {\r
+        break;\r
+      }\r
     }\r
     FlushPageTableMemory (VtdIndex, (UINTN)&Lvl3PtEntry[Lvl3Start], (UINTN)&Lvl3PtEntry[Lvl3End + 1] - (UINTN)&Lvl3PtEntry[Lvl3Start]);\r
+    if (BaseAddress >= MemoryLimit) {\r
+      break;\r
+    }\r
   }\r
   FlushPageTableMemory (VtdIndex, (UINTN)&Lvl4PtEntry[Lvl4Start], (UINTN)&Lvl4PtEntry[Lvl4End + 1] - (UINTN)&Lvl4PtEntry[Lvl4Start]);\r
 \r
-Done:\r
   return SecondLevelPagingEntry;\r
 }\r
 \r
@@ -286,9 +291,13 @@ CreateSecondLevelPagingEntry (
   if (SecondLevelPagingEntry == NULL) {\r
     return NULL;\r
   }\r
-  SecondLevelPagingEntry = CreateSecondLevelPagingEntryTable (VtdIndex, SecondLevelPagingEntry, SIZE_4GB, mAbove4GMemoryLimit, IoMmuAccess);\r
-  if (SecondLevelPagingEntry == NULL) {\r
-    return NULL;\r
+\r
+  if (mAbove4GMemoryLimit != 0) {\r
+    ASSERT (mAbove4GMemoryLimit > BASE_4GB);\r
+    SecondLevelPagingEntry = CreateSecondLevelPagingEntryTable (VtdIndex, SecondLevelPagingEntry, SIZE_4GB, mAbove4GMemoryLimit, IoMmuAccess);\r
+    if (SecondLevelPagingEntry == NULL) {\r
+      return NULL;\r
+    }\r
   }\r
 \r
   return SecondLevelPagingEntry;\r