IntelSiliconPkg IntelVTdDxe: Use TPL to protect list/engine operation
authorStar Zeng <star.zeng@intel.com>
Thu, 4 Jan 2018 02:33:42 +0000 (10:33 +0800)
committerStar Zeng <star.zeng@intel.com>
Fri, 5 Jan 2018 02:26:33 +0000 (10:26 +0800)
Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
IntelSiliconPkg/Feature/VTd/IntelVTdDxe/BmDma.c
IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c
IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
IntelSiliconPkg/Feature/VTd/IntelVTdDxe/IntelVTdDxe.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
index 648f64c20b7751690d8cda38cc25bf93c1b57c90..d9b8885d7ace66f5793aef3b2055c9e74bed9197 100644 (file)
@@ -478,7 +478,7 @@ InitializeDmaProtection (
   \r
   Status = gBS->CreateEventEx (\r
                   EVT_NOTIFY_SIGNAL,\r
-                  TPL_CALLBACK,\r
+                  VTD_TPL_LEVEL,\r
                   AcpiNotificationFunc,\r
                   NULL,\r
                   &gEfiAcpi10TableGuid,\r
@@ -488,7 +488,7 @@ InitializeDmaProtection (
 \r
   Status = gBS->CreateEventEx (\r
                   EVT_NOTIFY_SIGNAL,\r
-                  TPL_CALLBACK,\r
+                  VTD_TPL_LEVEL,\r
                   AcpiNotificationFunc,\r
                   NULL,\r
                   &gEfiAcpi20TableGuid,\r
index 519a5ab004505e15fb5441321d76de3192ddf870..bc14ff9a6631fa3b214c5cc86cc370951bc180c7 100644 (file)
@@ -48,6 +48,8 @@
 #define ALIGN_VALUE_UP(Value, Alignment)  (((Value) + (Alignment) - 1) & (~((Alignment) - 1)))\r
 #define ALIGN_VALUE_LOW(Value, Alignment) ((Value) & (~((Alignment) - 1)))\r
 \r
+#define VTD_TPL_LEVEL TPL_NOTIFY\r
+\r
 //\r
 // This is the initial max PCI DATA number.\r
 // The number may be enlarged later.\r
index 89d9bea3fc0fdd5086ad6189e6ec87be36d39dd8..570b47cf73647a8b0e7e270a5f07847b2649c001 100644 (file)
 \r
 **/\r
 \r
-#include <PiDxe.h>\r
-\r
-#include <Protocol/IoMmu.h>\r
-#include <Protocol/PciIo.h>\r
-\r
-#include <Library/IoLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-\r
 #include "DmaProtection.h"\r
 \r
 /**\r
@@ -306,18 +296,22 @@ IoMmuSetAttribute (
   EFI_STATUS            Status;\r
   EFI_PHYSICAL_ADDRESS  DeviceAddress;\r
   UINTN                 NumberOfPages;\r
+  EFI_TPL               OriginalTpl;\r
+\r
+  OriginalTpl = gBS->RaiseTPL (VTD_TPL_LEVEL);\r
 \r
   Status = GetDeviceInfoFromMapping (Mapping, &DeviceAddress, &NumberOfPages);\r
-  if (EFI_ERROR(Status)) {\r
-    return Status;\r
+  if (!EFI_ERROR(Status)) {\r
+    Status = VTdSetAttribute (\r
+               This,\r
+               DeviceHandle,\r
+               DeviceAddress,\r
+               EFI_PAGES_TO_SIZE(NumberOfPages),\r
+               IoMmuAccess\r
+               );\r
   }\r
-  Status = VTdSetAttribute (\r
-             This,\r
-             DeviceHandle,\r
-             DeviceAddress,\r
-             EFI_PAGES_TO_SIZE(NumberOfPages),\r
-             IoMmuAccess\r
-             );\r
+\r
+  gBS->RestoreTPL (OriginalTpl);\r
 \r
   return Status;\r
 }\r