]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelSiliconPkg/Feature/VTd/IntelVTdDxe/BmDma.c
IntelSiliconPkg IntelVTdDxe: Use TPL to protect list/engine operation
[mirror_edk2.git] / IntelSiliconPkg / Feature / VTd / IntelVTdDxe / BmDma.c
index e8685666e79a1c44efb3f1a024a5de8fe2904a95..57e086a64dbc98b3c554fb85b6cbca76e860dac9 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   BmDma related function\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
 \r
 **/\r
 \r
-#include <PiDxe.h>\r
-\r
-#include <Protocol/IoMmu.h>\r
-\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
+#include "DmaProtection.h"\r
 \r
 // TBD: May make it a policy\r
 #define DMA_MEMORY_TOP          MAX_UINTN\r
@@ -76,6 +68,7 @@ IoMmuMap (
   MAP_INFO                                          *MapInfo;\r
   EFI_PHYSICAL_ADDRESS                              DmaMemoryTop;\r
   BOOLEAN                                           NeedRemap;\r
+  EFI_TPL                                           OriginalTpl;\r
 \r
   if (NumberOfBytes == NULL || DeviceAddress == NULL ||\r
       Mapping == NULL) {\r
@@ -198,7 +191,9 @@ IoMmuMap (
     MapInfo->DeviceAddress = MapInfo->HostAddress;\r
   }\r
 \r
+  OriginalTpl = gBS->RaiseTPL (VTD_TPL_LEVEL);\r
   InsertTailList (&gMaps, &MapInfo->Link);\r
+  gBS->RestoreTPL (OriginalTpl);\r
 \r
   //\r
   // The DeviceAddress is the address of the maped buffer below 4GB\r
@@ -233,6 +228,7 @@ IoMmuUnmap (
 {\r
   MAP_INFO                 *MapInfo;\r
   LIST_ENTRY               *Link;\r
+  EFI_TPL                  OriginalTpl;\r
 \r
   DEBUG ((DEBUG_VERBOSE, "IoMmuUnmap: 0x%08x\n", Mapping));\r
 \r
@@ -241,6 +237,7 @@ IoMmuUnmap (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  OriginalTpl = gBS->RaiseTPL (VTD_TPL_LEVEL);\r
   MapInfo = NULL;\r
   for (Link = GetFirstNode (&gMaps)\r
        ; !IsNull (&gMaps, Link)\r
@@ -255,10 +252,12 @@ IoMmuUnmap (
   // Mapping is not a valid value returned by Map()\r
   //\r
   if (MapInfo != Mapping) {\r
+    gBS->RestoreTPL (OriginalTpl);\r
     DEBUG ((DEBUG_ERROR, "IoMmuUnmap: %r\n", EFI_INVALID_PARAMETER));\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   RemoveEntryList (&MapInfo->Link);\r
+  gBS->RestoreTPL (OriginalTpl);\r
 \r
   if (MapInfo->DeviceAddress != MapInfo->HostAddress) {\r
     //\r