]>
Commit | Line | Data |
---|---|---|
c049fc99 JY |
1 | /** @file\r |
2 | \r | |
0bc94c74 | 3 | Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>\r |
8f7a05e1 | 4 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
c049fc99 JY |
5 | \r |
6 | **/\r | |
7 | \r | |
8 | #ifndef _DMAR_PROTECTION_H_\r | |
9 | #define _DMAR_PROTECTION_H_\r | |
10 | \r | |
11 | #include <Uefi.h>\r | |
12 | #include <PiDxe.h>\r | |
13 | \r | |
14 | #include <Library/BaseLib.h>\r | |
15 | #include <Library/BaseMemoryLib.h>\r | |
16 | #include <Library/MemoryAllocationLib.h>\r | |
17 | #include <Library/UefiBootServicesTableLib.h>\r | |
18 | #include <Library/IoLib.h>\r | |
19 | #include <Library/PciSegmentLib.h>\r | |
20 | #include <Library/DebugLib.h>\r | |
21 | #include <Library/UefiLib.h>\r | |
4ad5f597 JY |
22 | #include <Library/CacheMaintenanceLib.h>\r |
23 | #include <Library/PerformanceLib.h>\r | |
24 | #include <Library/PrintLib.h>\r | |
27bf6712 | 25 | #include <Library/ReportStatusCodeLib.h>\r |
c049fc99 JY |
26 | \r |
27 | #include <Guid/EventGroup.h>\r | |
28 | #include <Guid/Acpi.h>\r | |
29 | \r | |
30 | #include <Protocol/DxeSmmReadyToLock.h>\r | |
31 | #include <Protocol/PciRootBridgeIo.h>\r | |
32 | #include <Protocol/PciIo.h>\r | |
33 | #include <Protocol/PciEnumerationComplete.h>\r | |
c049fc99 JY |
34 | #include <Protocol/PlatformVtdPolicy.h>\r |
35 | #include <Protocol/IoMmu.h>\r | |
36 | \r | |
37 | #include <IndustryStandard/Pci.h>\r | |
38 | #include <IndustryStandard/DmaRemappingReportingTable.h>\r | |
39 | #include <IndustryStandard/Vtd.h>\r | |
40 | \r | |
76c6f69c SZ |
41 | #define VTD_64BITS_ADDRESS(Lo, Hi) (LShiftU64 (Lo, 12) | LShiftU64 (Hi, 32))\r |
42 | \r | |
c049fc99 JY |
43 | #define ALIGN_VALUE_UP(Value, Alignment) (((Value) + (Alignment) - 1) & (~((Alignment) - 1)))\r |
44 | #define ALIGN_VALUE_LOW(Value, Alignment) ((Value) & (~((Alignment) - 1)))\r | |
45 | \r | |
3a716706 SZ |
46 | #define VTD_TPL_LEVEL TPL_NOTIFY\r |
47 | \r | |
c049fc99 | 48 | //\r |
f77d35c7 | 49 | // This is the initial max PCI DATA number.\r |
c049fc99 JY |
50 | // The number may be enlarged later.\r |
51 | //\r | |
f77d35c7 | 52 | #define MAX_VTD_PCI_DATA_NUMBER 0x100\r |
c049fc99 JY |
53 | \r |
54 | typedef struct {\r | |
f77d35c7 JY |
55 | UINT8 DeviceType;\r |
56 | VTD_SOURCE_ID PciSourceId;\r | |
57 | EDKII_PLATFORM_VTD_PCI_DEVICE_ID PciDeviceId;\r | |
4ad5f597 | 58 | // for statistic analysis\r |
f77d35c7 JY |
59 | UINTN AccessCount;\r |
60 | } PCI_DEVICE_DATA;\r | |
61 | \r | |
62 | typedef struct {\r | |
63 | BOOLEAN IncludeAllFlag;\r | |
64 | UINTN PciDeviceDataNumber;\r | |
65 | UINTN PciDeviceDataMaxNumber;\r | |
66 | PCI_DEVICE_DATA *PciDeviceData;\r | |
c049fc99 JY |
67 | } PCI_DEVICE_INFORMATION;\r |
68 | \r | |
69 | typedef struct {\r | |
70 | UINTN VtdUnitBaseAddress;\r | |
71 | UINT16 Segment;\r | |
72 | VTD_CAP_REG CapReg;\r | |
73 | VTD_ECAP_REG ECapReg;\r | |
74 | VTD_ROOT_ENTRY *RootEntryTable;\r | |
75 | VTD_EXT_ROOT_ENTRY *ExtRootEntryTable;\r | |
76 | VTD_SECOND_LEVEL_PAGING_ENTRY *FixedSecondLevelPagingEntry;\r | |
4ad5f597 | 77 | BOOLEAN HasDirtyContext;\r |
c049fc99 JY |
78 | BOOLEAN HasDirtyPages;\r |
79 | PCI_DEVICE_INFORMATION PciDeviceInfo;\r | |
80 | } VTD_UNIT_INFORMATION;\r | |
81 | \r | |
0bc94c74 SZ |
82 | //\r |
83 | // This is the initial max ACCESS request.\r | |
84 | // The number may be enlarged later.\r | |
85 | //\r | |
86 | #define MAX_VTD_ACCESS_REQUEST 0x100\r | |
87 | \r | |
88 | typedef struct {\r | |
89 | UINT16 Segment;\r | |
90 | VTD_SOURCE_ID SourceId;\r | |
91 | UINT64 BaseAddress;\r | |
92 | UINT64 Length;\r | |
93 | UINT64 IoMmuAccess;\r | |
94 | } VTD_ACCESS_REQUEST;\r | |
95 | \r | |
96 | \r | |
f77d35c7 JY |
97 | /**\r |
98 | The scan bus callback function.\r | |
99 | \r | |
100 | It is called in PCI bus scan for each PCI device under the bus.\r | |
101 | \r | |
102 | @param[in] Context The context of the callback.\r | |
103 | @param[in] Segment The segment of the source.\r | |
104 | @param[in] Bus The bus of the source.\r | |
105 | @param[in] Device The device of the source.\r | |
106 | @param[in] Function The function of the source.\r | |
107 | \r | |
108 | @retval EFI_SUCCESS The specific PCI device is processed in the callback.\r | |
109 | **/\r | |
110 | typedef\r | |
111 | EFI_STATUS\r | |
112 | (EFIAPI *SCAN_BUS_FUNC_CALLBACK_FUNC) (\r | |
113 | IN VOID *Context,\r | |
114 | IN UINT16 Segment,\r | |
115 | IN UINT8 Bus,\r | |
116 | IN UINT8 Device,\r | |
117 | IN UINT8 Function\r | |
118 | );\r | |
119 | \r | |
c049fc99 JY |
120 | extern EFI_ACPI_DMAR_HEADER *mAcpiDmarTable;\r |
121 | \r | |
c049fc99 JY |
122 | extern UINTN mVtdUnitNumber;\r |
123 | extern VTD_UNIT_INFORMATION *mVtdUnitInformation;\r | |
124 | \r | |
125 | extern UINT64 mBelow4GMemoryLimit;\r | |
126 | extern UINT64 mAbove4GMemoryLimit;\r | |
127 | \r | |
128 | extern EDKII_PLATFORM_VTD_POLICY_PROTOCOL *mPlatformVTdPolicy;\r | |
129 | \r | |
130 | /**\r | |
131 | Prepare VTD configuration.\r | |
132 | **/\r | |
133 | VOID\r | |
134 | PrepareVtdConfig (\r | |
135 | VOID\r | |
136 | );\r | |
137 | \r | |
138 | /**\r | |
139 | Setup VTd translation table.\r | |
140 | \r | |
141 | @retval EFI_SUCCESS Setup translation table successfully.\r | |
142 | @retval EFI_OUT_OF_RESOURCE Setup translation table fail.\r | |
143 | **/\r | |
144 | EFI_STATUS\r | |
145 | SetupTranslationTable (\r | |
146 | VOID\r | |
147 | );\r | |
148 | \r | |
149 | /**\r | |
150 | Enable DMAR translation.\r | |
151 | \r | |
152 | @retval EFI_SUCCESS DMAR translation is enabled.\r | |
153 | @retval EFI_DEVICE_ERROR DMAR translation is not enabled.\r | |
154 | **/\r | |
155 | EFI_STATUS\r | |
156 | EnableDmar (\r | |
157 | VOID\r | |
158 | );\r | |
159 | \r | |
160 | /**\r | |
161 | Disable DMAR translation.\r | |
162 | \r | |
163 | @retval EFI_SUCCESS DMAR translation is disabled.\r | |
164 | @retval EFI_DEVICE_ERROR DMAR translation is not disabled.\r | |
165 | **/\r | |
166 | EFI_STATUS\r | |
167 | DisableDmar (\r | |
168 | VOID\r | |
169 | );\r | |
170 | \r | |
c049fc99 JY |
171 | /**\r |
172 | Invalid VTd global IOTLB.\r | |
173 | \r | |
174 | @param[in] VtdIndex The index of VTd engine.\r | |
175 | \r | |
176 | @retval EFI_SUCCESS VTd global IOTLB is invalidated.\r | |
177 | @retval EFI_DEVICE_ERROR VTd global IOTLB is not invalidated.\r | |
178 | **/\r | |
179 | EFI_STATUS\r | |
180 | InvalidateVtdIOTLBGlobal (\r | |
181 | IN UINTN VtdIndex\r | |
182 | );\r | |
183 | \r | |
184 | /**\r | |
185 | Dump VTd registers.\r | |
186 | \r | |
187 | @param[in] VtdIndex The index of VTd engine.\r | |
188 | **/\r | |
189 | VOID\r | |
190 | DumpVtdRegs (\r | |
191 | IN UINTN VtdIndex\r | |
192 | );\r | |
193 | \r | |
194 | /**\r | |
195 | Dump VTd registers for all VTd engine.\r | |
196 | **/\r | |
197 | VOID\r | |
198 | DumpVtdRegsAll (\r | |
199 | VOID\r | |
200 | );\r | |
201 | \r | |
202 | /**\r | |
203 | Dump VTd capability registers.\r | |
204 | \r | |
205 | @param[in] CapReg The capability register.\r | |
206 | **/\r | |
207 | VOID\r | |
208 | DumpVtdCapRegs (\r | |
209 | IN VTD_CAP_REG *CapReg\r | |
210 | );\r | |
211 | \r | |
212 | /**\r | |
213 | Dump VTd extended capability registers.\r | |
214 | \r | |
215 | @param[in] ECapReg The extended capability register.\r | |
216 | **/\r | |
217 | VOID\r | |
218 | DumpVtdECapRegs (\r | |
219 | IN VTD_ECAP_REG *ECapReg\r | |
220 | );\r | |
221 | \r | |
222 | /**\r | |
f77d35c7 | 223 | Register PCI device to VTd engine.\r |
c049fc99 JY |
224 | \r |
225 | @param[in] VtdIndex The index of VTd engine.\r | |
226 | @param[in] Segment The segment of the source.\r | |
227 | @param[in] SourceId The SourceId of the source.\r | |
f77d35c7 | 228 | @param[in] DeviceType The DMAR device scope type.\r |
c049fc99 JY |
229 | @param[in] CheckExist TRUE: ERROR will be returned if the PCI device is already registered.\r |
230 | FALSE: SUCCESS will be returned if the PCI device is registered.\r | |
231 | \r | |
232 | @retval EFI_SUCCESS The PCI device is registered.\r | |
233 | @retval EFI_OUT_OF_RESOURCES No enough resource to register a new PCI device.\r | |
234 | @retval EFI_ALREADY_STARTED The device is already registered.\r | |
235 | **/\r | |
236 | EFI_STATUS\r | |
237 | RegisterPciDevice (\r | |
238 | IN UINTN VtdIndex,\r | |
239 | IN UINT16 Segment,\r | |
240 | IN VTD_SOURCE_ID SourceId,\r | |
f77d35c7 | 241 | IN UINT8 DeviceType,\r |
c049fc99 JY |
242 | IN BOOLEAN CheckExist\r |
243 | );\r | |
244 | \r | |
245 | /**\r | |
f77d35c7 | 246 | The scan bus callback function to always enable page attribute.\r |
c049fc99 | 247 | \r |
f77d35c7 | 248 | @param[in] Context The context of the callback.\r |
c049fc99 JY |
249 | @param[in] Segment The segment of the source.\r |
250 | @param[in] Bus The bus of the source.\r | |
f77d35c7 JY |
251 | @param[in] Device The device of the source.\r |
252 | @param[in] Function The function of the source.\r | |
c049fc99 | 253 | \r |
f77d35c7 | 254 | @retval EFI_SUCCESS The VTd entry is updated to always enable all DMA access for the specific device.\r |
c049fc99 JY |
255 | **/\r |
256 | EFI_STATUS\r | |
f77d35c7 JY |
257 | EFIAPI\r |
258 | ScanBusCallbackRegisterPciDevice (\r | |
259 | IN VOID *Context,\r | |
c049fc99 | 260 | IN UINT16 Segment,\r |
f77d35c7 JY |
261 | IN UINT8 Bus,\r |
262 | IN UINT8 Device,\r | |
263 | IN UINT8 Function\r | |
264 | );\r | |
265 | \r | |
266 | /**\r | |
267 | Scan PCI bus and invoke callback function for each PCI devices under the bus.\r | |
268 | \r | |
269 | @param[in] Context The context of the callback function.\r | |
270 | @param[in] Segment The segment of the source.\r | |
271 | @param[in] Bus The bus of the source.\r | |
272 | @param[in] Callback The callback function in PCI scan.\r | |
273 | \r | |
274 | @retval EFI_SUCCESS The PCI devices under the bus are scaned.\r | |
275 | **/\r | |
276 | EFI_STATUS\r | |
277 | ScanPciBus (\r | |
278 | IN VOID *Context,\r | |
279 | IN UINT16 Segment,\r | |
280 | IN UINT8 Bus,\r | |
281 | IN SCAN_BUS_FUNC_CALLBACK_FUNC Callback\r | |
c049fc99 JY |
282 | );\r |
283 | \r | |
284 | /**\r | |
285 | Dump the PCI device information managed by this VTd engine.\r | |
286 | \r | |
287 | @param[in] VtdIndex The index of VTd engine.\r | |
288 | **/\r | |
289 | VOID\r | |
290 | DumpPciDeviceInfo (\r | |
291 | IN UINTN VtdIndex\r | |
292 | );\r | |
293 | \r | |
294 | /**\r | |
295 | Find the VTd index by the Segment and SourceId.\r | |
296 | \r | |
297 | @param[in] Segment The segment of the source.\r | |
298 | @param[in] SourceId The SourceId of the source.\r | |
299 | @param[out] ExtContextEntry The ExtContextEntry of the source.\r | |
300 | @param[out] ContextEntry The ContextEntry of the source.\r | |
301 | \r | |
f77d35c7 JY |
302 | @return The index of the VTd engine.\r |
303 | @retval (UINTN)-1 The VTd engine is not found.\r | |
c049fc99 JY |
304 | **/\r |
305 | UINTN\r | |
306 | FindVtdIndexByPciDevice (\r | |
307 | IN UINT16 Segment,\r | |
308 | IN VTD_SOURCE_ID SourceId,\r | |
309 | OUT VTD_EXT_CONTEXT_ENTRY **ExtContextEntry,\r | |
310 | OUT VTD_CONTEXT_ENTRY **ContextEntry\r | |
311 | );\r | |
312 | \r | |
313 | /**\r | |
314 | Get the DMAR ACPI table.\r | |
315 | \r | |
7729e3c4 SZ |
316 | @retval EFI_SUCCESS The DMAR ACPI table is got.\r |
317 | @retval EFI_ALREADY_STARTED The DMAR ACPI table has been got previously.\r | |
318 | @retval EFI_NOT_FOUND The DMAR ACPI table is not found.\r | |
c049fc99 JY |
319 | **/\r |
320 | EFI_STATUS\r | |
321 | GetDmarAcpiTable (\r | |
322 | VOID\r | |
323 | );\r | |
324 | \r | |
325 | /**\r | |
326 | Parse DMAR DRHD table.\r | |
327 | \r | |
328 | @return EFI_SUCCESS The DMAR DRHD table is parsed.\r | |
329 | **/\r | |
330 | EFI_STATUS\r | |
331 | ParseDmarAcpiTableDrhd (\r | |
332 | VOID\r | |
333 | );\r | |
334 | \r | |
335 | /**\r | |
336 | Parse DMAR RMRR table.\r | |
337 | \r | |
338 | @return EFI_SUCCESS The DMAR RMRR table is parsed.\r | |
339 | **/\r | |
340 | EFI_STATUS\r | |
341 | ParseDmarAcpiTableRmrr (\r | |
342 | VOID\r | |
343 | );\r | |
344 | \r | |
345 | /**\r | |
346 | Dump DMAR context entry table.\r | |
347 | \r | |
348 | @param[in] RootEntry DMAR root entry.\r | |
349 | **/\r | |
350 | VOID\r | |
351 | DumpDmarContextEntryTable (\r | |
352 | IN VTD_ROOT_ENTRY *RootEntry\r | |
353 | );\r | |
354 | \r | |
355 | /**\r | |
356 | Dump DMAR extended context entry table.\r | |
357 | \r | |
358 | @param[in] ExtRootEntry DMAR extended root entry.\r | |
359 | **/\r | |
360 | VOID\r | |
361 | DumpDmarExtContextEntryTable (\r | |
362 | IN VTD_EXT_ROOT_ENTRY *ExtRootEntry\r | |
363 | );\r | |
364 | \r | |
365 | /**\r | |
366 | Dump DMAR second level paging entry.\r | |
367 | \r | |
368 | @param[in] SecondLevelPagingEntry The second level paging entry.\r | |
369 | **/\r | |
370 | VOID\r | |
371 | DumpSecondLevelPagingEntry (\r | |
372 | IN VOID *SecondLevelPagingEntry\r | |
373 | );\r | |
374 | \r | |
375 | /**\r | |
376 | Set VTd attribute for a system memory.\r | |
377 | \r | |
378 | @param[in] VtdIndex The index used to identify a VTd engine.\r | |
d654bf85 | 379 | @param[in] DomainIdentifier The domain ID of the source.\r |
c049fc99 JY |
380 | @param[in] SecondLevelPagingEntry The second level paging entry in VTd table for the device.\r |
381 | @param[in] BaseAddress The base of device memory address to be used as the DMA memory.\r | |
382 | @param[in] Length The length of device memory address to be used as the DMA memory.\r | |
383 | @param[in] IoMmuAccess The IOMMU access.\r | |
384 | \r | |
385 | @retval EFI_SUCCESS The IoMmuAccess is set for the memory range specified by BaseAddress and Length.\r | |
386 | @retval EFI_INVALID_PARAMETER BaseAddress is not IoMmu Page size aligned.\r | |
387 | @retval EFI_INVALID_PARAMETER Length is not IoMmu Page size aligned.\r | |
388 | @retval EFI_INVALID_PARAMETER Length is 0.\r | |
389 | @retval EFI_INVALID_PARAMETER IoMmuAccess specified an illegal combination of access.\r | |
390 | @retval EFI_UNSUPPORTED The bit mask of IoMmuAccess is not supported by the IOMMU.\r | |
391 | @retval EFI_UNSUPPORTED The IOMMU does not support the memory range specified by BaseAddress and Length.\r | |
392 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to modify the IOMMU access.\r | |
393 | @retval EFI_DEVICE_ERROR The IOMMU device reported an error while attempting the operation.\r | |
394 | **/\r | |
395 | EFI_STATUS\r | |
396 | SetPageAttribute (\r | |
397 | IN UINTN VtdIndex,\r | |
4ad5f597 | 398 | IN UINT16 DomainIdentifier,\r |
c049fc99 JY |
399 | IN VTD_SECOND_LEVEL_PAGING_ENTRY *SecondLevelPagingEntry,\r |
400 | IN UINT64 BaseAddress,\r | |
401 | IN UINT64 Length,\r | |
402 | IN UINT64 IoMmuAccess\r | |
403 | );\r | |
404 | \r | |
405 | /**\r | |
406 | Set VTd attribute for a system memory.\r | |
407 | \r | |
408 | @param[in] Segment The Segment used to identify a VTd engine.\r | |
409 | @param[in] SourceId The SourceId used to identify a VTd engine and table entry.\r | |
410 | @param[in] BaseAddress The base of device memory address to be used as the DMA memory.\r | |
411 | @param[in] Length The length of device memory address to be used as the DMA memory.\r | |
412 | @param[in] IoMmuAccess The IOMMU access.\r | |
413 | \r | |
414 | @retval EFI_SUCCESS The IoMmuAccess is set for the memory range specified by BaseAddress and Length.\r | |
415 | @retval EFI_INVALID_PARAMETER BaseAddress is not IoMmu Page size aligned.\r | |
416 | @retval EFI_INVALID_PARAMETER Length is not IoMmu Page size aligned.\r | |
417 | @retval EFI_INVALID_PARAMETER Length is 0.\r | |
418 | @retval EFI_INVALID_PARAMETER IoMmuAccess specified an illegal combination of access.\r | |
419 | @retval EFI_UNSUPPORTED The bit mask of IoMmuAccess is not supported by the IOMMU.\r | |
420 | @retval EFI_UNSUPPORTED The IOMMU does not support the memory range specified by BaseAddress and Length.\r | |
421 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to modify the IOMMU access.\r | |
422 | @retval EFI_DEVICE_ERROR The IOMMU device reported an error while attempting the operation.\r | |
423 | **/\r | |
424 | EFI_STATUS\r | |
425 | SetAccessAttribute (\r | |
426 | IN UINT16 Segment,\r | |
427 | IN VTD_SOURCE_ID SourceId,\r | |
428 | IN UINT64 BaseAddress,\r | |
429 | IN UINT64 Length,\r | |
430 | IN UINT64 IoMmuAccess\r | |
431 | );\r | |
432 | \r | |
433 | /**\r | |
f77d35c7 | 434 | Return the index of PCI data.\r |
c049fc99 JY |
435 | \r |
436 | @param[in] VtdIndex The index used to identify a VTd engine.\r | |
437 | @param[in] Segment The Segment used to identify a VTd engine.\r | |
438 | @param[in] SourceId The SourceId used to identify a VTd engine and table entry.\r | |
439 | \r | |
f77d35c7 JY |
440 | @return The index of the PCI data.\r |
441 | @retval (UINTN)-1 The PCI data is not found.\r | |
c049fc99 JY |
442 | **/\r |
443 | UINTN\r | |
f77d35c7 | 444 | GetPciDataIndex (\r |
c049fc99 JY |
445 | IN UINTN VtdIndex,\r |
446 | IN UINT16 Segment,\r | |
447 | IN VTD_SOURCE_ID SourceId\r | |
448 | );\r | |
449 | \r | |
450 | /**\r | |
451 | Dump VTd registers if there is error.\r | |
452 | **/\r | |
453 | VOID\r | |
454 | DumpVtdIfError (\r | |
455 | VOID\r | |
456 | );\r | |
457 | \r | |
458 | /**\r | |
459 | Initialize platform VTd policy.\r | |
460 | **/\r | |
461 | VOID\r | |
462 | InitializePlatformVTdPolicy (\r | |
463 | VOID\r | |
464 | );\r | |
465 | \r | |
466 | /**\r | |
467 | Always enable the VTd page attribute for the device.\r | |
468 | \r | |
469 | @param[in] Segment The Segment used to identify a VTd engine.\r | |
470 | @param[in] SourceId The SourceId used to identify a VTd engine and table entry.\r | |
471 | \r | |
472 | @retval EFI_SUCCESS The VTd entry is updated to always enable all DMA access for the specific device.\r | |
473 | **/\r | |
474 | EFI_STATUS\r | |
475 | AlwaysEnablePageAttribute (\r | |
476 | IN UINT16 Segment,\r | |
477 | IN VTD_SOURCE_ID SourceId\r | |
478 | );\r | |
479 | \r | |
480 | /**\r | |
481 | Convert the DeviceHandle to SourceId and Segment.\r | |
482 | \r | |
483 | @param[in] DeviceHandle The device who initiates the DMA access request.\r | |
484 | @param[out] Segment The Segment used to identify a VTd engine.\r | |
485 | @param[out] SourceId The SourceId used to identify a VTd engine and table entry.\r | |
486 | \r | |
487 | @retval EFI_SUCCESS The Segment and SourceId are returned.\r | |
488 | @retval EFI_INVALID_PARAMETER DeviceHandle is an invalid handle.\r | |
489 | @retval EFI_UNSUPPORTED DeviceHandle is unknown by the IOMMU.\r | |
490 | **/\r | |
491 | EFI_STATUS\r | |
492 | DeviceHandleToSourceId (\r | |
493 | IN EFI_HANDLE DeviceHandle,\r | |
494 | OUT UINT16 *Segment,\r | |
495 | OUT VTD_SOURCE_ID *SourceId\r | |
496 | );\r | |
497 | \r | |
498 | /**\r | |
499 | Get device information from mapping.\r | |
500 | \r | |
501 | @param[in] Mapping The mapping.\r | |
502 | @param[out] DeviceAddress The device address of the mapping.\r | |
503 | @param[out] NumberOfPages The number of pages of the mapping.\r | |
504 | \r | |
505 | @retval EFI_SUCCESS The device information is returned.\r | |
506 | @retval EFI_INVALID_PARAMETER The mapping is invalid.\r | |
507 | **/\r | |
508 | EFI_STATUS\r | |
509 | GetDeviceInfoFromMapping (\r | |
510 | IN VOID *Mapping,\r | |
511 | OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r | |
512 | OUT UINTN *NumberOfPages\r | |
513 | );\r | |
514 | \r | |
515 | /**\r | |
516 | Initialize DMA protection.\r | |
517 | **/\r | |
518 | VOID\r | |
519 | InitializeDmaProtection (\r | |
520 | VOID\r | |
521 | );\r | |
522 | \r | |
523 | /**\r | |
524 | Allocate zero pages.\r | |
525 | \r | |
526 | @param[in] Pages the number of pages.\r | |
527 | \r | |
528 | @return the page address.\r | |
529 | @retval NULL No resource to allocate pages.\r | |
530 | **/\r | |
531 | VOID *\r | |
532 | EFIAPI\r | |
533 | AllocateZeroPages (\r | |
534 | IN UINTN Pages\r | |
535 | );\r | |
536 | \r | |
4ad5f597 JY |
537 | /**\r |
538 | Flush VTD page table and context table memory.\r | |
539 | \r | |
540 | This action is to make sure the IOMMU engine can get final data in memory.\r | |
541 | \r | |
542 | @param[in] VtdIndex The index used to identify a VTd engine.\r | |
543 | @param[in] Base The base address of memory to be flushed.\r | |
544 | @param[in] Size The size of memory in bytes to be flushed.\r | |
545 | **/\r | |
546 | VOID\r | |
547 | FlushPageTableMemory (\r | |
548 | IN UINTN VtdIndex,\r | |
549 | IN UINTN Base,\r | |
550 | IN UINTN Size\r | |
551 | );\r | |
552 | \r | |
f77d35c7 JY |
553 | /**\r |
554 | Get PCI device information from DMAR DevScopeEntry.\r | |
555 | \r | |
556 | @param[in] Segment The segment number.\r | |
557 | @param[in] DmarDevScopeEntry DMAR DevScopeEntry\r | |
558 | @param[out] Bus The bus number.\r | |
559 | @param[out] Device The device number.\r | |
560 | @param[out] Function The function number.\r | |
561 | \r | |
562 | @retval EFI_SUCCESS The PCI device information is returned.\r | |
563 | **/\r | |
564 | EFI_STATUS\r | |
565 | GetPciBusDeviceFunction (\r | |
566 | IN UINT16 Segment,\r | |
567 | IN EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *DmarDevScopeEntry,\r | |
568 | OUT UINT8 *Bus,\r | |
569 | OUT UINT8 *Device,\r | |
570 | OUT UINT8 *Function\r | |
571 | );\r | |
572 | \r | |
0bc94c74 SZ |
573 | /**\r |
574 | Append VTd Access Request to global.\r | |
575 | \r | |
576 | @param[in] Segment The Segment used to identify a VTd engine.\r | |
577 | @param[in] SourceId The SourceId used to identify a VTd engine and table entry.\r | |
578 | @param[in] BaseAddress The base of device memory address to be used as the DMA memory.\r | |
579 | @param[in] Length The length of device memory address to be used as the DMA memory.\r | |
580 | @param[in] IoMmuAccess The IOMMU access.\r | |
581 | \r | |
582 | @retval EFI_SUCCESS The IoMmuAccess is set for the memory range specified by BaseAddress and Length.\r | |
583 | @retval EFI_INVALID_PARAMETER BaseAddress is not IoMmu Page size aligned.\r | |
584 | @retval EFI_INVALID_PARAMETER Length is not IoMmu Page size aligned.\r | |
585 | @retval EFI_INVALID_PARAMETER Length is 0.\r | |
586 | @retval EFI_INVALID_PARAMETER IoMmuAccess specified an illegal combination of access.\r | |
587 | @retval EFI_UNSUPPORTED The bit mask of IoMmuAccess is not supported by the IOMMU.\r | |
588 | @retval EFI_UNSUPPORTED The IOMMU does not support the memory range specified by BaseAddress and Length.\r | |
589 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to modify the IOMMU access.\r | |
590 | @retval EFI_DEVICE_ERROR The IOMMU device reported an error while attempting the operation.\r | |
591 | \r | |
592 | **/\r | |
593 | EFI_STATUS\r | |
594 | RequestAccessAttribute (\r | |
595 | IN UINT16 Segment,\r | |
596 | IN VTD_SOURCE_ID SourceId,\r | |
597 | IN UINT64 BaseAddress,\r | |
598 | IN UINT64 Length,\r | |
599 | IN UINT64 IoMmuAccess\r | |
600 | );\r | |
601 | \r | |
c049fc99 | 602 | #endif\r |