]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelSiliconPkg/Feature/VTd/IntelVTdDxe/IntelVTdDxe.c
IntelSiliconPkg/Vtd: Add MapHandleInfo in VtdDxe.
[mirror_edk2.git] / IntelSiliconPkg / Feature / VTd / IntelVTdDxe / IntelVTdDxe.c
index 570b47cf73647a8b0e7e270a5f07847b2649c001..25d7c80af1d421edb6e37daab50d72309aea7be5 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Intel VTd driver.\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
@@ -113,6 +113,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
@@ -231,18 +249,35 @@ VTdSetAttribute (
   DEBUG ((DEBUG_VERBOSE, "PCI(S%x.B%x.D%x.F%x) ", Segment, SourceId.Bits.Bus, SourceId.Bits.Device, SourceId.Bits.Function));\r
   DEBUG ((DEBUG_VERBOSE, "(0x%lx~0x%lx) - %lx\n", DeviceAddress, Length, IoMmuAccess));\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
+  if (mAcpiDmarTable == NULL) {\r
+    //\r
+    // Record the entry to driver global variable.\r
+    // As such once VTd is activated, the setting can be adopted.\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
-    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