]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelSiliconPkg/Feature/VTd/IntelVTdDxe/IntelVTdDxe.c
IntelSiliconPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelSiliconPkg / Feature / VTd / IntelVTdDxe / IntelVTdDxe.c
index 841a5a9264aa9b6f040502fcd772be9923d57daa..a6287be2cfd2799d4676f446ce571636acace823 100644 (file)
@@ -2,13 +2,7 @@
   Intel VTd driver.\r
 \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
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -113,6 +107,24 @@ IoMmuFreeBuffer (
   IN  VOID                                     *HostAddress\r
   );\r
 \r
+/**\r
+  This function fills DeviceHandle/IoMmuAccess to the MAP_HANDLE_INFO,\r
+  based upon the DeviceAddress.\r
+\r
+  @param[in]  DeviceHandle      The device who initiates the DMA access request.\r
+  @param[in]  DeviceAddress     The base of device memory address to be used as the DMA memory.\r
+  @param[in]  Length            The length of device memory address to be used as the DMA memory.\r
+  @param[in]  IoMmuAccess       The IOMMU access.\r
+\r
+**/\r
+VOID\r
+SyncDeviceHandleToMapInfo (\r
+  IN EFI_HANDLE            DeviceHandle,\r
+  IN EFI_PHYSICAL_ADDRESS  DeviceAddress,\r
+  IN UINT64                Length,\r
+  IN UINT64                IoMmuAccess\r
+  );\r
+\r
 /**\r
   Convert the DeviceHandle to SourceId and Segment.\r
 \r
@@ -236,21 +248,37 @@ VTdSetAttribute (
     // Record the entry to driver global variable.\r
     // As such once VTd is activated, the setting can be adopted.\r
     //\r
-    return RequestAccessAttribute (Segment, SourceId, DeviceAddress, Length, IoMmuAccess);\r
+    if ((PcdGet8 (PcdVTdPolicyPropertyMask) & BIT2) != 0) {\r
+      //\r
+      // Force no IOMMU access attribute request recording before DMAR table is installed.\r
+      //\r
+      ASSERT_EFI_ERROR (EFI_NOT_READY);\r
+      return EFI_NOT_READY;\r
+    }\r
+    Status = RequestAccessAttribute (Segment, SourceId, DeviceAddress, Length, IoMmuAccess);\r
+  } else {\r
+    PERF_CODE (\r
+      AsciiSPrint (PerfToken, sizeof(PerfToken), "S%04xB%02xD%02xF%01x", Segment, SourceId.Bits.Bus, SourceId.Bits.Device, SourceId.Bits.Function);\r
+      Identifier = (Segment << 16) | SourceId.Uint16;\r
+      PERF_START_EX (gImageHandle, PerfToken, "IntelVTD", 0, Identifier);\r
+    );\r
+\r
+    Status = SetAccessAttribute (Segment, SourceId, DeviceAddress, Length, IoMmuAccess);\r
+\r
+    PERF_CODE (\r
+      Identifier = (Segment << 16) | SourceId.Uint16;\r
+      PERF_END_EX (gImageHandle, PerfToken, "IntelVTD", 0, Identifier);\r
+    );\r
   }\r
 \r
-  PERF_CODE (\r
-    AsciiSPrint (PerfToken, sizeof(PerfToken), "S%04xB%02xD%02xF%01x", Segment, SourceId.Bits.Bus, SourceId.Bits.Device, SourceId.Bits.Function);\r
-    Identifier = (Segment << 16) | SourceId.Uint16;\r
-    PERF_START_EX (gImageHandle, PerfToken, "IntelVTD", 0, Identifier);\r
-  );\r
-\r
-  Status = SetAccessAttribute (Segment, SourceId, DeviceAddress, Length, IoMmuAccess);\r
-\r
-  PERF_CODE (\r
-    Identifier = (Segment << 16) | SourceId.Uint16;\r
-    PERF_END_EX (gImageHandle, PerfToken, "IntelVTD", 0, Identifier);\r
-  );\r
+  if (!EFI_ERROR(Status)) {\r
+    SyncDeviceHandleToMapInfo (\r
+      DeviceHandle,\r
+      DeviceAddress,\r
+      Length,\r
+      IoMmuAccess\r
+      );\r
+  }\r
 \r
   return Status;\r
 }\r