1 /** @file 2 The definition for DMA access Library. 3 4 Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR> 5 SPDX-License-Identifier: BSD-2-Clause-Patent 6 7 **/ 8 9 #ifndef __DMA_ACCESS_LIB_H__ 10 #define __DMA_ACCESS_LIB_H__ 11 12 typedef struct { 13 EFI_ACPI_DMAR_HEADER *AcpiDmarTable; 14 UINT64 EngineMask; 15 UINT8 HostAddressWidth; 16 UINTN VTdEngineCount; 17 UINT64 VTdEngineAddress[1]; 18 } VTD_INFO; 19 20 /** 21 Set DMA protected region. 22 23 @param VTdInfo The VTd engine context information. 24 @param EngineMask The mask of the VTd engine to be accessed. 25 @param LowMemoryBase The protected low memory region base. 26 @param LowMemoryLength The protected low memory region length. 27 @param HighMemoryBase The protected high memory region base. 28 @param HighMemoryLength The protected high memory region length. 29 30 @retval EFI_SUCCESS The DMA protection is set. 31 @retval EFI_UNSUPPORTED The DMA protection is not set. 32 **/ 33 EFI_STATUS 34 SetDmaProtectedRange ( 35 IN VTD_INFO *VTdInfo, 36 IN UINT64 EngineMask, 37 IN UINT32 LowMemoryBase, 38 IN UINT32 LowMemoryLength, 39 IN UINT64 HighMemoryBase, 40 IN UINT64 HighMemoryLength 41 ); 42 43 /** 44 Diable DMA protection. 45 46 @param VTdInfo The VTd engine context information. 47 @param EngineMask The mask of the VTd engine to be accessed. 48 49 @retval DMA protection is disabled. 50 **/ 51 EFI_STATUS 52 DisableDmaProtection ( 53 IN VTD_INFO *VTdInfo, 54 IN UINT64 EngineMask 55 ); 56 57 /** 58 Return if the DMA protection is enabled. 59 60 @param VTdInfo The VTd engine context information. 61 @param EngineMask The mask of the VTd engine to be accessed. 62 63 @retval TRUE DMA protection is enabled in at least one VTd engine. 64 @retval FALSE DMA protection is disabled in all VTd engines. 65 **/ 66 UINT64 67 GetDmaProtectionEnabledEngineMask ( 68 IN VTD_INFO *VTdInfo, 69 IN UINT64 EngineMask 70 ); 71 72 /** 73 Get protected low memory alignment. 74 75 @param VTdInfo The VTd engine context information. 76 @param EngineMask The mask of the VTd engine to be accessed. 77 78 @return protected low memory alignment. 79 **/ 80 UINT32 81 GetLowMemoryAlignment ( 82 IN VTD_INFO *VTdInfo, 83 IN UINT64 EngineMask 84 ); 85 86 /** 87 Get protected high memory alignment. 88 89 @param VTdInfo The VTd engine context information. 90 @param EngineMask The mask of the VTd engine to be accessed. 91 92 @return protected high memory alignment. 93 **/ 94 UINT64 95 GetHighMemoryAlignment ( 96 IN VTD_INFO *VTdInfo, 97 IN UINT64 EngineMask 98 ); 99 100 /** 101 Enable VTd translation table protection. 102 103 @param VTdInfo The VTd engine context information. 104 @param EngineMask The mask of the VTd engine to be accessed. 105 **/ 106 VOID 107 EnableVTdTranslationProtection ( 108 IN VTD_INFO *VTdInfo, 109 IN UINT64 EngineMask 110 ); 111 112 /** 113 Disable VTd translation table protection. 114 115 @param VTdInfo The VTd engine context information. 116 @param EngineMask The mask of the VTd engine to be accessed. 117 **/ 118 VOID 119 DisableVTdTranslationProtection ( 120 IN VTD_INFO *VTdInfo, 121 IN UINT64 EngineMask 122 ); 123 124 /** 125 Parse DMAR DRHD table. 126 127 @param[in] AcpiDmarTable DMAR ACPI table 128 129 @return EFI_SUCCESS The DMAR DRHD table is parsed. 130 **/ 131 EFI_STATUS 132 ParseDmarAcpiTableDrhd ( 133 IN EFI_ACPI_DMAR_HEADER *AcpiDmarTable 134 ); 135 136 /** 137 Parse DMAR DRHD table. 138 139 @param VTdInfo The VTd engine context information. 140 **/ 141 VOID 142 ParseDmarAcpiTableRmrr ( 143 IN VTD_INFO *VTdInfo 144 ); 145 146 /** 147 Dump DMAR ACPI table. 148 149 @param[in] Dmar DMAR ACPI table 150 **/ 151 VOID 152 DumpAcpiDMAR ( 153 IN EFI_ACPI_DMAR_HEADER *Dmar 154 ); 155 156 extern EFI_GUID mVTdInfoGuid; 157 158 #endif 159 160