/** @file\r
Intel VTd driver.\r
\r
- Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
\r
**/\r
\r
-#include <PiDxe.h>\r
-\r
-#include <Protocol/IoMmu.h>\r
-#include <Protocol/PciIo.h>\r
-\r
-#include <Library/IoLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-\r
#include "DmaProtection.h"\r
\r
/**\r
\r
@retval EFI_SUCCESS The requested memory pages were allocated.\r
@retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r
- MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
+ MEMORY_WRITE_COMBINE, MEMORY_CACHED and DUAL_ADDRESS_CYCLE.\r
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
@retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r
\r
IN VOID *HostAddress\r
);\r
\r
+/**\r
+ This function fills DeviceHandle/IoMmuAccess to the MAP_HANDLE_INFO,\r
+ based upon the DeviceAddress.\r
+\r
+ @param[in] DeviceHandle The device who initiates the DMA access request.\r
+ @param[in] DeviceAddress The base of device memory address to be used as the DMA memory.\r
+ @param[in] Length The length of device memory address to be used as the DMA memory.\r
+ @param[in] IoMmuAccess The IOMMU access.\r
+\r
+**/\r
+VOID\r
+SyncDeviceHandleToMapInfo (\r
+ IN EFI_HANDLE DeviceHandle,\r
+ IN EFI_PHYSICAL_ADDRESS DeviceAddress,\r
+ IN UINT64 Length,\r
+ IN UINT64 IoMmuAccess\r
+ );\r
+\r
/**\r
Convert the DeviceHandle to SourceId and Segment.\r
\r
DEBUG ((DEBUG_VERBOSE, "PCI(S%x.B%x.D%x.F%x) ", Segment, SourceId.Bits.Bus, SourceId.Bits.Device, SourceId.Bits.Function));\r
DEBUG ((DEBUG_VERBOSE, "(0x%lx~0x%lx) - %lx\n", DeviceAddress, Length, IoMmuAccess));\r
\r
- PERF_CODE (\r
- AsciiSPrint (PerfToken, sizeof(PerfToken), "S%04xB%02xD%02xF%01x", Segment, SourceId.Bits.Bus, SourceId.Bits.Device, SourceId.Bits.Function);\r
- Identifier = (Segment << 16) | SourceId.Uint16;\r
- PERF_START_EX (gImageHandle, PerfToken, "IntelVTD", 0, Identifier);\r
- );\r
-\r
- Status = SetAccessAttribute (Segment, SourceId, DeviceAddress, Length, IoMmuAccess);\r
+ if (mAcpiDmarTable == NULL) {\r
+ //\r
+ // Record the entry to driver global variable.\r
+ // As such once VTd is activated, the setting can be adopted.\r
+ //\r
+ Status = RequestAccessAttribute (Segment, SourceId, DeviceAddress, Length, IoMmuAccess);\r
+ } else {\r
+ PERF_CODE (\r
+ AsciiSPrint (PerfToken, sizeof(PerfToken), "S%04xB%02xD%02xF%01x", Segment, SourceId.Bits.Bus, SourceId.Bits.Device, SourceId.Bits.Function);\r
+ Identifier = (Segment << 16) | SourceId.Uint16;\r
+ PERF_START_EX (gImageHandle, PerfToken, "IntelVTD", 0, Identifier);\r
+ );\r
+\r
+ Status = SetAccessAttribute (Segment, SourceId, DeviceAddress, Length, IoMmuAccess);\r
+\r
+ PERF_CODE (\r
+ Identifier = (Segment << 16) | SourceId.Uint16;\r
+ PERF_END_EX (gImageHandle, PerfToken, "IntelVTD", 0, Identifier);\r
+ );\r
+ }\r
\r
- PERF_CODE (\r
- Identifier = (Segment << 16) | SourceId.Uint16;\r
- PERF_END_EX (gImageHandle, PerfToken, "IntelVTD", 0, Identifier);\r
- );\r
+ if (!EFI_ERROR(Status)) {\r
+ SyncDeviceHandleToMapInfo (\r
+ DeviceHandle,\r
+ DeviceAddress,\r
+ Length,\r
+ IoMmuAccess\r
+ );\r
+ }\r
\r
return Status;\r
}\r
EFI_STATUS Status;\r
EFI_PHYSICAL_ADDRESS DeviceAddress;\r
UINTN NumberOfPages;\r
+ EFI_TPL OriginalTpl;\r
+\r
+ OriginalTpl = gBS->RaiseTPL (VTD_TPL_LEVEL);\r
\r
Status = GetDeviceInfoFromMapping (Mapping, &DeviceAddress, &NumberOfPages);\r
- if (EFI_ERROR(Status)) {\r
- return Status;\r
+ if (!EFI_ERROR(Status)) {\r
+ Status = VTdSetAttribute (\r
+ This,\r
+ DeviceHandle,\r
+ DeviceAddress,\r
+ EFI_PAGES_TO_SIZE(NumberOfPages),\r
+ IoMmuAccess\r
+ );\r
}\r
- Status = VTdSetAttribute (\r
- This,\r
- DeviceHandle,\r
- DeviceAddress,\r
- EFI_PAGES_TO_SIZE(NumberOfPages),\r
- IoMmuAccess\r
- );\r
+\r
+ gBS->RestoreTPL (OriginalTpl);\r
\r
return Status;\r
}\r