]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Include/Ppi/IoMmu.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Include / Ppi / IoMmu.h
CommitLineData
2b620ee1
JY
1/** @file\r
2 PEI IOMMU PPI.\r
3\r
20b58eb8 4Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
2b620ee1
JY
6\r
7**/\r
8\r
2b620ee1
JY
9#ifndef __PEI_IOMMU_H__\r
10#define __PEI_IOMMU_H__\r
11\r
12//\r
13// for EFI_ALLOCATE_TYPE\r
14//\r
15#include <Uefi.h>\r
16\r
17//\r
18// Include protocol for common definition\r
19// EDKII_IOMMU_ACCESS_xxx\r
20// EDKII_IOMMU_OPERATION\r
21//\r
22#include <Protocol/IoMmu.h>\r
23\r
24//\r
25// IOMMU Ppi GUID value\r
26//\r
27#define EDKII_IOMMU_PPI_GUID \\r
28 { \\r
29 0x70b0af26, 0xf847, 0x4bb6, { 0xaa, 0xb9, 0xcd, 0xe8, 0x4f, 0xc6, 0x14, 0x31 } \\r
30 }\r
31\r
32//\r
33// Forward reference for pure ANSI compatability\r
34//\r
1436aea4 35typedef struct _EDKII_IOMMU_PPI EDKII_IOMMU_PPI;\r
2b620ee1
JY
36\r
37//\r
38// Revision The revision to which the IOMMU interface adheres.\r
39// All future revisions must be backwards compatible.\r
40// If a future version is not back wards compatible it is not the same GUID.\r
41//\r
1436aea4 42#define EDKII_IOMMU_PPI_REVISION 0x00010000\r
2b620ee1
JY
43\r
44/**\r
45 Set IOMMU attribute for a system memory.\r
46\r
47 If the IOMMU PPI exists, the system memory cannot be used\r
48 for DMA by default.\r
49\r
50 When a device requests a DMA access for a system memory,\r
51 the device driver need use SetAttribute() to update the IOMMU\r
52 attribute to request DMA access (read and/or write).\r
53\r
54 @param[in] This The PPI instance pointer.\r
55 @param[in] Mapping The mapping value returned from Map().\r
56 @param[in] IoMmuAccess The IOMMU access.\r
57\r
58 @retval EFI_SUCCESS The IoMmuAccess is set for the memory range specified by DeviceAddress and Length.\r
59 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().\r
60 @retval EFI_INVALID_PARAMETER IoMmuAccess specified an illegal combination of access.\r
61 @retval EFI_UNSUPPORTED The bit mask of IoMmuAccess is not supported by the IOMMU.\r
62 @retval EFI_UNSUPPORTED The IOMMU does not support the memory range specified by Mapping.\r
63 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to modify the IOMMU access.\r
64 @retval EFI_DEVICE_ERROR The IOMMU device reported an error while attempting the operation.\r
20b58eb8
SZ
65 @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA buffer are\r
66 not available to be allocated yet.\r
2b620ee1
JY
67\r
68**/\r
69typedef\r
70EFI_STATUS\r
71(EFIAPI *EDKII_PEI_IOMMU_SET_ATTRIBUTE)(\r
72 IN EDKII_IOMMU_PPI *This,\r
73 IN VOID *Mapping,\r
74 IN UINT64 IoMmuAccess\r
75 );\r
76\r
77/**\r
78 Provides the controller-specific addresses required to access system memory from a\r
79 DMA bus master.\r
80\r
81 @param This The PPI instance pointer.\r
82 @param Operation Indicates if the bus master is going to read or write to system memory.\r
83 @param HostAddress The system memory address to map to the PCI controller.\r
84 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes\r
85 that were mapped.\r
86 @param DeviceAddress The resulting map address for the bus master PCI controller to use to\r
87 access the hosts HostAddress.\r
88 @param Mapping A resulting value to pass to Unmap().\r
89\r
90 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r
91 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.\r
92 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
93 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
94 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r
20b58eb8
SZ
95 @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA buffer are\r
96 not available to be allocated yet.\r
2b620ee1
JY
97\r
98**/\r
99typedef\r
100EFI_STATUS\r
101(EFIAPI *EDKII_PEI_IOMMU_MAP)(\r
102 IN EDKII_IOMMU_PPI *This,\r
103 IN EDKII_IOMMU_OPERATION Operation,\r
104 IN VOID *HostAddress,\r
105 IN OUT UINTN *NumberOfBytes,\r
106 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
107 OUT VOID **Mapping\r
108 );\r
109\r
110/**\r
111 Completes the Map() operation and releases any corresponding resources.\r
112\r
113 @param This The PPI instance pointer.\r
114 @param Mapping The mapping value returned from Map().\r
115\r
116 @retval EFI_SUCCESS The range was unmapped.\r
117 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().\r
118 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r
20b58eb8
SZ
119 @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA buffer are\r
120 not available to be allocated yet.\r
121\r
2b620ee1
JY
122**/\r
123typedef\r
124EFI_STATUS\r
125(EFIAPI *EDKII_PEI_IOMMU_UNMAP)(\r
126 IN EDKII_IOMMU_PPI *This,\r
127 IN VOID *Mapping\r
128 );\r
129\r
130/**\r
131 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or\r
132 OperationBusMasterCommonBuffer64 mapping.\r
133\r
134 @param This The PPI instance pointer.\r
135 @param MemoryType The type of memory to allocate, EfiBootServicesData or\r
136 EfiRuntimeServicesData.\r
137 @param Pages The number of pages to allocate.\r
138 @param HostAddress A pointer to store the base system memory address of the\r
139 allocated range.\r
140 @param Attributes The requested bit mask of attributes for the allocated range.\r
141\r
142 @retval EFI_SUCCESS The requested memory pages were allocated.\r
143 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r
b02f14f3 144 MEMORY_WRITE_COMBINE, MEMORY_CACHED and DUAL_ADDRESS_CYCLE.\r
2b620ee1
JY
145 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
146 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r
20b58eb8
SZ
147 @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA buffer are\r
148 not available to be allocated yet.\r
2b620ee1
JY
149\r
150**/\r
151typedef\r
152EFI_STATUS\r
153(EFIAPI *EDKII_PEI_IOMMU_ALLOCATE_BUFFER)(\r
154 IN EDKII_IOMMU_PPI *This,\r
155 IN EFI_MEMORY_TYPE MemoryType,\r
156 IN UINTN Pages,\r
157 IN OUT VOID **HostAddress,\r
158 IN UINT64 Attributes\r
159 );\r
160\r
161/**\r
162 Frees memory that was allocated with AllocateBuffer().\r
163\r
20b58eb8 164 @param This The PPI instance pointer.\r
2b620ee1
JY
165 @param Pages The number of pages to free.\r
166 @param HostAddress The base system memory address of the allocated range.\r
167\r
168 @retval EFI_SUCCESS The requested memory pages were freed.\r
169 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
170 was not allocated with AllocateBuffer().\r
20b58eb8
SZ
171 @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA buffer are\r
172 not available to be allocated yet.\r
2b620ee1
JY
173\r
174**/\r
175typedef\r
176EFI_STATUS\r
177(EFIAPI *EDKII_PEI_IOMMU_FREE_BUFFER)(\r
178 IN EDKII_IOMMU_PPI *This,\r
179 IN UINTN Pages,\r
180 IN VOID *HostAddress\r
181 );\r
182\r
183///\r
184/// IOMMU PPI structure.\r
185///\r
186struct _EDKII_IOMMU_PPI {\r
1436aea4
MK
187 UINT64 Revision;\r
188 EDKII_PEI_IOMMU_SET_ATTRIBUTE SetAttribute;\r
189 EDKII_PEI_IOMMU_MAP Map;\r
190 EDKII_PEI_IOMMU_UNMAP Unmap;\r
191 EDKII_PEI_IOMMU_ALLOCATE_BUFFER AllocateBuffer;\r
192 EDKII_PEI_IOMMU_FREE_BUFFER FreeBuffer;\r
2b620ee1
JY
193};\r
194\r
195///\r
196/// IOMMU PPI GUID variable.\r
197///\r
1436aea4 198extern EFI_GUID gEdkiiIoMmuPpiGuid;\r
2b620ee1
JY
199\r
200#endif\r