1 | /** @file
|
---|
2 | EFI IOMMU Protocol.
|
---|
3 |
|
---|
4 | Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
---|
5 | This program and the accompanying materials are licensed and made available under
|
---|
6 | the terms and conditions of the BSD License that accompanies this distribution.
|
---|
7 | The full text of the license may be found at
|
---|
8 | http://opensource.org/licenses/bsd-license.php.
|
---|
9 |
|
---|
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
12 |
|
---|
13 | **/
|
---|
14 |
|
---|
15 |
|
---|
16 | #ifndef __IOMMU_H__
|
---|
17 | #define __IOMMU_H__
|
---|
18 |
|
---|
19 | //
|
---|
20 | // IOMMU Protocol GUID value
|
---|
21 | //
|
---|
22 | #define EDKII_IOMMU_PROTOCOL_GUID \
|
---|
23 | { \
|
---|
24 | 0x4e939de9, 0xd948, 0x4b0f, { 0x88, 0xed, 0xe6, 0xe1, 0xce, 0x51, 0x7c, 0x1e } \
|
---|
25 | }
|
---|
26 |
|
---|
27 | //
|
---|
28 | // Forward reference for pure ANSI compatability
|
---|
29 | //
|
---|
30 | typedef struct _EDKII_IOMMU_PROTOCOL EDKII_IOMMU_PROTOCOL;
|
---|
31 |
|
---|
32 | //
|
---|
33 | // Revision The revision to which the IOMMU interface adheres.
|
---|
34 | // All future revisions must be backwards compatible.
|
---|
35 | // If a future version is not back wards compatible it is not the same GUID.
|
---|
36 | //
|
---|
37 | #define EDKII_IOMMU_PROTOCOL_REVISION 0x00010000
|
---|
38 |
|
---|
39 | //
|
---|
40 | // IOMMU Access for SetAttribute
|
---|
41 | //
|
---|
42 | // These types can be "ORed" together as needed.
|
---|
43 | // Any undefined bits are reserved and must be zero.
|
---|
44 | //
|
---|
45 | #define EDKII_IOMMU_ACCESS_READ 0x1
|
---|
46 | #define EDKII_IOMMU_ACCESS_WRITE 0x2
|
---|
47 |
|
---|
48 | //
|
---|
49 | // IOMMU Operation for Map
|
---|
50 | //
|
---|
51 | typedef enum {
|
---|
52 | ///
|
---|
53 | /// A read operation from system memory by a bus master that is not capable of producing
|
---|
54 | /// PCI dual address cycles.
|
---|
55 | ///
|
---|
56 | EdkiiIoMmuOperationBusMasterRead,
|
---|
57 | ///
|
---|
58 | /// A write operation from system memory by a bus master that is not capable of producing
|
---|
59 | /// PCI dual address cycles.
|
---|
60 | ///
|
---|
61 | EdkiiIoMmuOperationBusMasterWrite,
|
---|
62 | ///
|
---|
63 | /// Provides both read and write access to system memory by both the processor and a bus
|
---|
64 | /// master that is not capable of producing PCI dual address cycles.
|
---|
65 | ///
|
---|
66 | EdkiiIoMmuOperationBusMasterCommonBuffer,
|
---|
67 | ///
|
---|
68 | /// A read operation from system memory by a bus master that is capable of producing PCI
|
---|
69 | /// dual address cycles.
|
---|
70 | ///
|
---|
71 | EdkiiIoMmuOperationBusMasterRead64,
|
---|
72 | ///
|
---|
73 | /// A write operation to system memory by a bus master that is capable of producing PCI
|
---|
74 | /// dual address cycles.
|
---|
75 | ///
|
---|
76 | EdkiiIoMmuOperationBusMasterWrite64,
|
---|
77 | ///
|
---|
78 | /// Provides both read and write access to system memory by both the processor and a bus
|
---|
79 | /// master that is capable of producing PCI dual address cycles.
|
---|
80 | ///
|
---|
81 | EdkiiIoMmuOperationBusMasterCommonBuffer64,
|
---|
82 | EdkiiIoMmuOperationMaximum
|
---|
83 | } EDKII_IOMMU_OPERATION;
|
---|
84 |
|
---|
85 | //
|
---|
86 | // IOMMU attribute for AllocateBuffer
|
---|
87 | // Any undefined bits are reserved and must be zero.
|
---|
88 | //
|
---|
89 | #define EDKII_IOMMU_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
|
---|
90 | #define EDKII_IOMMU_ATTRIBUTE_MEMORY_CACHED 0x0800
|
---|
91 | #define EDKII_IOMMU_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
|
---|
92 |
|
---|
93 | #define EDKII_IOMMU_ATTRIBUTE_VALID_FOR_ALLOCATE_BUFFER (EDKII_IOMMU_ATTRIBUTE_MEMORY_WRITE_COMBINE | EDKII_IOMMU_ATTRIBUTE_MEMORY_CACHED | EDKII_IOMMU_ATTRIBUTE_DUAL_ADDRESS_CYCLE)
|
---|
94 |
|
---|
95 | #define EDKII_IOMMU_ATTRIBUTE_INVALID_FOR_ALLOCATE_BUFFER (~EDKII_IOMMU_ATTRIBUTE_VALID_FOR_ALLOCATE_BUFFER)
|
---|
96 |
|
---|
97 | /**
|
---|
98 | Set IOMMU attribute for a system memory.
|
---|
99 |
|
---|
100 | If the IOMMU protocol exists, the system memory cannot be used
|
---|
101 | for DMA by default.
|
---|
102 |
|
---|
103 | When a device requests a DMA access for a system memory,
|
---|
104 | the device driver need use SetAttribute() to update the IOMMU
|
---|
105 | attribute to request DMA access (read and/or write).
|
---|
106 |
|
---|
107 | The DeviceHandle is used to identify which device submits the request.
|
---|
108 | The IOMMU implementation need translate the device path to an IOMMU device ID,
|
---|
109 | and set IOMMU hardware register accordingly.
|
---|
110 | 1) DeviceHandle can be a standard PCI device.
|
---|
111 | The memory for BusMasterRead need set EDKII_IOMMU_ACCESS_READ.
|
---|
112 | The memory for BusMasterWrite need set EDKII_IOMMU_ACCESS_WRITE.
|
---|
113 | The memory for BusMasterCommonBuffer need set EDKII_IOMMU_ACCESS_READ|EDKII_IOMMU_ACCESS_WRITE.
|
---|
114 | After the memory is used, the memory need set 0 to keep it being protected.
|
---|
115 | 2) DeviceHandle can be an ACPI device (ISA, I2C, SPI, etc).
|
---|
116 | The memory for DMA access need set EDKII_IOMMU_ACCESS_READ and/or EDKII_IOMMU_ACCESS_WRITE.
|
---|
117 |
|
---|
118 | @param[in] This The protocol instance pointer.
|
---|
119 | @param[in] DeviceHandle The device who initiates the DMA access request.
|
---|
120 | @param[in] Mapping The mapping value returned from Map().
|
---|
121 | @param[in] IoMmuAccess The IOMMU access.
|
---|
122 |
|
---|
123 | @retval EFI_SUCCESS The IoMmuAccess is set for the memory range specified by DeviceAddress and Length.
|
---|
124 | @retval EFI_INVALID_PARAMETER DeviceHandle is an invalid handle.
|
---|
125 | @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
|
---|
126 | @retval EFI_INVALID_PARAMETER IoMmuAccess specified an illegal combination of access.
|
---|
127 | @retval EFI_UNSUPPORTED DeviceHandle is unknown by the IOMMU.
|
---|
128 | @retval EFI_UNSUPPORTED The bit mask of IoMmuAccess is not supported by the IOMMU.
|
---|
129 | @retval EFI_UNSUPPORTED The IOMMU does not support the memory range specified by Mapping.
|
---|
130 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to modify the IOMMU access.
|
---|
131 | @retval EFI_DEVICE_ERROR The IOMMU device reported an error while attempting the operation.
|
---|
132 |
|
---|
133 | **/
|
---|
134 | typedef
|
---|
135 | EFI_STATUS
|
---|
136 | (EFIAPI *EDKII_IOMMU_SET_ATTRIBUTE)(
|
---|
137 | IN EDKII_IOMMU_PROTOCOL *This,
|
---|
138 | IN EFI_HANDLE DeviceHandle,
|
---|
139 | IN VOID *Mapping,
|
---|
140 | IN UINT64 IoMmuAccess
|
---|
141 | );
|
---|
142 |
|
---|
143 | /**
|
---|
144 | Provides the controller-specific addresses required to access system memory from a
|
---|
145 | DMA bus master.
|
---|
146 |
|
---|
147 | @param This The protocol instance pointer.
|
---|
148 | @param Operation Indicates if the bus master is going to read or write to system memory.
|
---|
149 | @param HostAddress The system memory address to map to the PCI controller.
|
---|
150 | @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
|
---|
151 | that were mapped.
|
---|
152 | @param DeviceAddress The resulting map address for the bus master PCI controller to use to
|
---|
153 | access the hosts HostAddress.
|
---|
154 | @param Mapping A resulting value to pass to Unmap().
|
---|
155 |
|
---|
156 | @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
|
---|
157 | @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
|
---|
158 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
---|
159 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
|
---|
160 | @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
|
---|
161 |
|
---|
162 | **/
|
---|
163 | typedef
|
---|
164 | EFI_STATUS
|
---|
165 | (EFIAPI *EDKII_IOMMU_MAP)(
|
---|
166 | IN EDKII_IOMMU_PROTOCOL *This,
|
---|
167 | IN EDKII_IOMMU_OPERATION Operation,
|
---|
168 | IN VOID *HostAddress,
|
---|
169 | IN OUT UINTN *NumberOfBytes,
|
---|
170 | OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
|
---|
171 | OUT VOID **Mapping
|
---|
172 | );
|
---|
173 |
|
---|
174 | /**
|
---|
175 | Completes the Map() operation and releases any corresponding resources.
|
---|
176 |
|
---|
177 | @param This The protocol instance pointer.
|
---|
178 | @param Mapping The mapping value returned from Map().
|
---|
179 |
|
---|
180 | @retval EFI_SUCCESS The range was unmapped.
|
---|
181 | @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
|
---|
182 | @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
|
---|
183 | **/
|
---|
184 | typedef
|
---|
185 | EFI_STATUS
|
---|
186 | (EFIAPI *EDKII_IOMMU_UNMAP)(
|
---|
187 | IN EDKII_IOMMU_PROTOCOL *This,
|
---|
188 | IN VOID *Mapping
|
---|
189 | );
|
---|
190 |
|
---|
191 | /**
|
---|
192 | Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
|
---|
193 | OperationBusMasterCommonBuffer64 mapping.
|
---|
194 |
|
---|
195 | @param This The protocol instance pointer.
|
---|
196 | @param Type This parameter is not used and must be ignored.
|
---|
197 | @param MemoryType The type of memory to allocate, EfiBootServicesData or
|
---|
198 | EfiRuntimeServicesData.
|
---|
199 | @param Pages The number of pages to allocate.
|
---|
200 | @param HostAddress A pointer to store the base system memory address of the
|
---|
201 | allocated range.
|
---|
202 | @param Attributes The requested bit mask of attributes for the allocated range.
|
---|
203 |
|
---|
204 | @retval EFI_SUCCESS The requested memory pages were allocated.
|
---|
205 | @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
|
---|
206 | MEMORY_WRITE_COMBINE, MEMORY_CACHED and DUAL_ADDRESS_CYCLE.
|
---|
207 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
---|
208 | @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
|
---|
209 |
|
---|
210 | **/
|
---|
211 | typedef
|
---|
212 | EFI_STATUS
|
---|
213 | (EFIAPI *EDKII_IOMMU_ALLOCATE_BUFFER)(
|
---|
214 | IN EDKII_IOMMU_PROTOCOL *This,
|
---|
215 | IN EFI_ALLOCATE_TYPE Type,
|
---|
216 | IN EFI_MEMORY_TYPE MemoryType,
|
---|
217 | IN UINTN Pages,
|
---|
218 | IN OUT VOID **HostAddress,
|
---|
219 | IN UINT64 Attributes
|
---|
220 | );
|
---|
221 |
|
---|
222 | /**
|
---|
223 | Frees memory that was allocated with AllocateBuffer().
|
---|
224 |
|
---|
225 | @param This The protocol instance pointer.
|
---|
226 | @param Pages The number of pages to free.
|
---|
227 | @param HostAddress The base system memory address of the allocated range.
|
---|
228 |
|
---|
229 | @retval EFI_SUCCESS The requested memory pages were freed.
|
---|
230 | @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
|
---|
231 | was not allocated with AllocateBuffer().
|
---|
232 |
|
---|
233 | **/
|
---|
234 | typedef
|
---|
235 | EFI_STATUS
|
---|
236 | (EFIAPI *EDKII_IOMMU_FREE_BUFFER)(
|
---|
237 | IN EDKII_IOMMU_PROTOCOL *This,
|
---|
238 | IN UINTN Pages,
|
---|
239 | IN VOID *HostAddress
|
---|
240 | );
|
---|
241 |
|
---|
242 | ///
|
---|
243 | /// IOMMU Protocol structure.
|
---|
244 | ///
|
---|
245 | struct _EDKII_IOMMU_PROTOCOL {
|
---|
246 | UINT64 Revision;
|
---|
247 | EDKII_IOMMU_SET_ATTRIBUTE SetAttribute;
|
---|
248 | EDKII_IOMMU_MAP Map;
|
---|
249 | EDKII_IOMMU_UNMAP Unmap;
|
---|
250 | EDKII_IOMMU_ALLOCATE_BUFFER AllocateBuffer;
|
---|
251 | EDKII_IOMMU_FREE_BUFFER FreeBuffer;
|
---|
252 | };
|
---|
253 |
|
---|
254 | ///
|
---|
255 | /// IOMMU Protocol GUID variable.
|
---|
256 | ///
|
---|
257 | extern EFI_GUID gEdkiiIoMmuProtocolGuid;
|
---|
258 |
|
---|
259 | #endif
|
---|