]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
IntelSiliconPkg/IntelVTdDxe: Do global invalidation before boot
[mirror_edk2.git] / IntelSiliconPkg / Feature / VTd / IntelVTdDxe / DmaProtection.h
index 0886647ea673296fe004df991d030c75c9810f4d..a3331db8f76b8f65aeaff346e51d4d55c7e96dfe 100644 (file)
@@ -1,13 +1,7 @@
 /** @file\r
 \r
-  Copyright (c) 2017, 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
+  Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -28,6 +22,7 @@
 #include <Library/CacheMaintenanceLib.h>\r
 #include <Library/PerformanceLib.h>\r
 #include <Library/PrintLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
 \r
 #include <Guid/EventGroup.h>\r
 #include <Guid/Acpi.h>\r
@@ -48,6 +43,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
@@ -82,6 +79,21 @@ typedef struct {
   PCI_DEVICE_INFORMATION           PciDeviceInfo;\r
 } VTD_UNIT_INFORMATION;\r
 \r
+//\r
+// This is the initial max ACCESS request.\r
+// The number may be enlarged later.\r
+//\r
+#define MAX_VTD_ACCESS_REQUEST      0x100\r
+\r
+typedef struct {\r
+  UINT16                Segment;\r
+  VTD_SOURCE_ID         SourceId;\r
+  UINT64                BaseAddress;\r
+  UINT64                Length;\r
+  UINT64                IoMmuAccess;\r
+} VTD_ACCESS_REQUEST;\r
+\r
+\r
 /**\r
   The scan bus callback function.\r
 \r
@@ -107,7 +119,6 @@ EFI_STATUS
 \r
 extern EFI_ACPI_DMAR_HEADER  *mAcpiDmarTable;\r
 \r
-extern UINT64                           mVtdHostAddressWidthMask;\r
 extern UINTN                            mVtdUnitNumber;\r
 extern VTD_UNIT_INFORMATION             *mVtdUnitInformation;\r
 \r
@@ -157,6 +168,36 @@ DisableDmar (
   VOID\r
   );\r
 \r
+/**\r
+  Flush VTd engine write buffer.\r
+\r
+  @param[in]  VtdIndex          The index used to identify a VTd engine.\r
+**/\r
+VOID\r
+FlushWriteBuffer (\r
+  IN UINTN  VtdIndex\r
+  );\r
+\r
+/**\r
+  Invalidate VTd context cache.\r
+\r
+  @param[in]  VtdIndex          The index used to identify a VTd engine.\r
+**/\r
+EFI_STATUS\r
+InvalidateContextCache (\r
+  IN UINTN  VtdIndex\r
+  );\r
+\r
+/**\r
+  Invalidate VTd IOTLB.\r
+\r
+  @param[in]  VtdIndex          The index used to identify a VTd engine.\r
+**/\r
+EFI_STATUS\r
+InvalidateIOTLB (\r
+  IN UINTN  VtdIndex\r
+  );\r
+\r
 /**\r
   Invalid VTd global IOTLB.\r
 \r
@@ -302,8 +343,9 @@ FindVtdIndexByPciDevice (
 /**\r
   Get the DMAR ACPI table.\r
 \r
-  @retval EFI_SUCCESS    The DMAR ACPI table is got.\r
-  @retval EFI_NOT_FOUND  The DMAR ACPI table is not found.\r
+  @retval EFI_SUCCESS           The DMAR ACPI table is got.\r
+  @retval EFI_ALREADY_STARTED   The DMAR ACPI table has been got previously.\r
+  @retval EFI_NOT_FOUND         The DMAR ACPI table is not found.\r
 **/\r
 EFI_STATUS\r
 GetDmarAcpiTable (\r
@@ -558,4 +600,33 @@ GetPciBusDeviceFunction (
   OUT UINT8                                       *Function\r
   );\r
 \r
+/**\r
+  Append VTd Access Request to global.\r
+\r
+  @param[in]  Segment           The Segment used to identify a VTd engine.\r
+  @param[in]  SourceId          The SourceId used to identify a VTd engine and table entry.\r
+  @param[in]  BaseAddress       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
+  @retval EFI_SUCCESS           The IoMmuAccess is set for the memory range specified by BaseAddress and Length.\r
+  @retval EFI_INVALID_PARAMETER BaseAddress is not IoMmu Page size aligned.\r
+  @retval EFI_INVALID_PARAMETER Length is not IoMmu Page size aligned.\r
+  @retval EFI_INVALID_PARAMETER Length is 0.\r
+  @retval EFI_INVALID_PARAMETER IoMmuAccess specified an illegal combination of access.\r
+  @retval EFI_UNSUPPORTED       The bit mask of IoMmuAccess is not supported by the IOMMU.\r
+  @retval EFI_UNSUPPORTED       The IOMMU does not support the memory range specified by BaseAddress and Length.\r
+  @retval EFI_OUT_OF_RESOURCES  There are not enough resources available to modify the IOMMU access.\r
+  @retval EFI_DEVICE_ERROR      The IOMMU device reported an error while attempting the operation.\r
+\r
+**/\r
+EFI_STATUS\r
+RequestAccessAttribute (\r
+  IN UINT16                 Segment,\r
+  IN VTD_SOURCE_ID          SourceId,\r
+  IN UINT64                 BaseAddress,\r
+  IN UINT64                 Length,\r
+  IN UINT64                 IoMmuAccess\r
+  );\r
+\r
 #endif\r