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