/** @file\r
\r
- The protocol provides support to allocate, free, map and umap a DMA buffer for\r
- bus master (e.g PciHostBridge). When SEV is enabled, the DMA operations must\r
- be performed on unencrypted buffer hence we use a bounce buffer to map the guest\r
- buffer into an unencrypted DMA buffer.\r
+ The protocol provides support to allocate, free, map and umap a DMA buffer\r
+ for bus master (e.g PciHostBridge). When SEV is enabled, the DMA operations\r
+ must be performed on unencrypted buffer hence we use a bounce buffer to map\r
+ the guest buffer into an unencrypted DMA buffer.\r
\r
Copyright (c) 2017, AMD Inc. All rights reserved.<BR>\r
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
#define NO_MAPPING (VOID *) (UINTN) -1\r
\r
/**\r
- Provides the controller-specific addresses required to access system memory from a\r
- DMA bus master. On SEV guest, the DMA operations must be performed on shared\r
- buffer hence we allocate a bounce buffer to map the HostAddress to a DeviceAddress.\r
- The Encryption attribute is removed from the DeviceAddress buffer.\r
+ Provides the controller-specific addresses required to access system memory\r
+ from a DMA bus master. On SEV guest, the DMA operations must be performed on\r
+ shared buffer hence we allocate a bounce buffer to map the HostAddress to a\r
+ DeviceAddress. The Encryption attribute is removed from the DeviceAddress\r
+ buffer.\r
\r
@param This The protocol instance pointer.\r
@param Operation Indicates if the bus master is going to read or\r
write to system memory.\r
- @param HostAddress The system memory address to map to the PCI controller.\r
+ @param HostAddress The system memory address to map to the PCI\r
+ controller.\r
@param NumberOfBytes On input the number of bytes to map. On output\r
- the number of bytes\r
- that were mapped.\r
- @param DeviceAddress The resulting map address for the bus master PCI\r
- controller to use to\r
- access the hosts HostAddress.\r
+ the number of bytes that were mapped.\r
+ @param DeviceAddress The resulting map address for the bus master\r
+ PCI controller to use to access the hosts\r
+ HostAddress.\r
@param Mapping A resulting value to pass to Unmap().\r
\r
- @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r
- @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.\r
+ @retval EFI_SUCCESS The range was mapped for the returned\r
+ NumberOfBytes.\r
+ @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common\r
+ buffer.\r
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack\r
- of resources.\r
- @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a\r
+ lack of resources.\r
+ @retval EFI_DEVICE_ERROR The system hardware could not map the requested\r
+ address.\r
\r
**/\r
EFI_STATUS\r
Operation == EdkiiIoMmuOperationBusMasterCommonBuffer64) {\r
//\r
// Common Buffer operations can not be remapped. If the common buffer\r
- // if above 4GB, then it is not possible to generate a mapping, so return\r
- // an error.\r
+ // if above 4GB, then it is not possible to generate a mapping, so\r
+ // return an error.\r
//\r
return EFI_UNSUPPORTED;\r
}\r
//\r
// Clear the memory encryption mask from the device buffer\r
//\r
- Status = MemEncryptSevClearPageEncMask (0, MapInfo->DeviceAddress, MapInfo->NumberOfPages, TRUE);\r
+ Status = MemEncryptSevClearPageEncMask (\r
+ 0,\r
+ MapInfo->DeviceAddress,\r
+ MapInfo->NumberOfPages,\r
+ TRUE\r
+ );\r
ASSERT_EFI_ERROR(Status);\r
\r
//\r
//\r
*Mapping = MapInfo;\r
\r
- DEBUG ((DEBUG_VERBOSE, "%a Device 0x%Lx Host 0x%Lx Pages 0x%Lx Bytes 0x%Lx\n",\r
- __FUNCTION__, MapInfo->DeviceAddress, MapInfo->HostAddress,\r
- MapInfo->NumberOfPages, MapInfo->NumberOfBytes));\r
+ DEBUG ((\r
+ DEBUG_VERBOSE,\r
+ "%a Device 0x%Lx Host 0x%Lx Pages 0x%Lx Bytes 0x%Lx\n",\r
+ __FUNCTION__,\r
+ MapInfo->DeviceAddress,\r
+ MapInfo->HostAddress,\r
+ MapInfo->NumberOfPages,\r
+ MapInfo->NumberOfBytes\r
+ ));\r
\r
return EFI_SUCCESS;\r
}\r
@param Mapping The mapping value returned from Map().\r
\r
@retval EFI_SUCCESS The range was unmapped.\r
- @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().\r
- @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r
+ @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by\r
+ Map().\r
+ @retval EFI_DEVICE_ERROR The data was not committed to the target system\r
+ memory.\r
**/\r
EFI_STATUS\r
EFIAPI\r
);\r
}\r
\r
- DEBUG ((DEBUG_VERBOSE, "%a Device 0x%Lx Host 0x%Lx Pages 0x%Lx Bytes 0x%Lx\n",\r
- __FUNCTION__, MapInfo->DeviceAddress, MapInfo->HostAddress,\r
- MapInfo->NumberOfPages, MapInfo->NumberOfBytes));\r
+ DEBUG ((\r
+ DEBUG_VERBOSE,\r
+ "%a Device 0x%Lx Host 0x%Lx Pages 0x%Lx Bytes 0x%Lx\n",\r
+ __FUNCTION__,\r
+ MapInfo->DeviceAddress,\r
+ MapInfo->HostAddress,\r
+ MapInfo->NumberOfPages,\r
+ MapInfo->NumberOfBytes\r
+ ));\r
//\r
// Restore the memory encryption mask\r
//\r
- Status = MemEncryptSevSetPageEncMask (0, MapInfo->DeviceAddress, MapInfo->NumberOfPages, TRUE);\r
+ Status = MemEncryptSevSetPageEncMask (\r
+ 0,\r
+ MapInfo->DeviceAddress,\r
+ MapInfo->NumberOfPages,\r
+ TRUE\r
+ );\r
ASSERT_EFI_ERROR(Status);\r
\r
//\r
\r
@param This The protocol instance pointer.\r
@param Type This parameter is not used and must be ignored.\r
- @param MemoryType The type of memory to allocate, EfiBootServicesData\r
- or EfiRuntimeServicesData.\r
+ @param MemoryType The type of memory to allocate,\r
+ EfiBootServicesData or EfiRuntimeServicesData.\r
@param Pages The number of pages to allocate.\r
- @param HostAddress A pointer to store the base system memory address\r
- of the allocated range.\r
- @param Attributes The requested bit mask of attributes for the allocated range.\r
+ @param HostAddress A pointer to store the base system memory\r
+ address of the allocated range.\r
+ @param Attributes The requested bit mask of attributes for the\r
+ allocated range.\r
\r
@retval EFI_SUCCESS The requested memory pages were allocated.\r
- @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute\r
- bits are MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
+ @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal\r
+ attribute bits are MEMORY_WRITE_COMBINE and\r
+ MEMORY_CACHED.\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
ASSERT_EFI_ERROR(Status);\r
}\r
\r
- DEBUG ((DEBUG_VERBOSE, "%a Address 0x%Lx Pages 0x%Lx\n", __FUNCTION__, PhysicalAddress, Pages));\r
+ DEBUG ((\r
+ DEBUG_VERBOSE,\r
+ "%a Address 0x%Lx Pages 0x%Lx\n",\r
+ __FUNCTION__,\r
+ PhysicalAddress,\r
+ Pages\r
+ ));\r
return Status;\r
}\r
\r
\r
@param This The protocol instance pointer.\r
@param Pages The number of pages to free.\r
- @param HostAddress The base system memory address of the allocated range.\r
+ @param HostAddress The base system memory address of the allocated\r
+ range.\r
\r
@retval EFI_SUCCESS The requested memory pages were freed.\r
- @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
- was not allocated with AllocateBuffer().\r
+ @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and\r
+ Pages was not allocated with AllocateBuffer().\r
\r
**/\r
EFI_STATUS\r
//\r
// Set memory encryption mask\r
//\r
- Status = MemEncryptSevSetPageEncMask (0, (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress, Pages, TRUE);\r
+ Status = MemEncryptSevSetPageEncMask (\r
+ 0,\r
+ (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress,\r
+ Pages,\r
+ TRUE\r
+ );\r
ASSERT_EFI_ERROR(Status);\r
\r
- DEBUG ((DEBUG_VERBOSE, "%a Address 0x%Lx Pages 0x%Lx\n", __FUNCTION__, (UINTN)HostAddress, Pages));\r
+ DEBUG ((\r
+ DEBUG_VERBOSE,\r
+ "%a Address 0x%Lx Pages 0x%Lx\n",\r
+ __FUNCTION__,\r
+ (UINTN)HostAddress,\r
+ Pages\r
+ ));\r
return gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress, Pages);\r
}\r
\r
attribute to request DMA access (read and/or write).\r
\r
The DeviceHandle is used to identify which device submits the request.\r
- The IOMMU implementation need translate the device path to an IOMMU device ID,\r
- and set IOMMU hardware register accordingly.\r
+ The IOMMU implementation need translate the device path to an IOMMU device\r
+ ID, and set IOMMU hardware register accordingly.\r
1) DeviceHandle can be a standard PCI device.\r
The memory for BusMasterRead need set EDKII_IOMMU_ACCESS_READ.\r
The memory for BusMasterWrite need set EDKII_IOMMU_ACCESS_WRITE.\r
- The memory for BusMasterCommonBuffer need set EDKII_IOMMU_ACCESS_READ|EDKII_IOMMU_ACCESS_WRITE.\r
- After the memory is used, the memory need set 0 to keep it being protected.\r
+ The memory for BusMasterCommonBuffer need set\r
+ EDKII_IOMMU_ACCESS_READ|EDKII_IOMMU_ACCESS_WRITE.\r
+ After the memory is used, the memory need set 0 to keep it being\r
+ protected.\r
2) DeviceHandle can be an ACPI device (ISA, I2C, SPI, etc).\r
- The memory for DMA access need set EDKII_IOMMU_ACCESS_READ and/or EDKII_IOMMU_ACCESS_WRITE.\r
+ The memory for DMA access need set EDKII_IOMMU_ACCESS_READ and/or\r
+ EDKII_IOMMU_ACCESS_WRITE.\r
\r
@param[in] This The protocol instance pointer.\r
- @param[in] DeviceHandle The device who initiates the DMA access request.\r
+ @param[in] DeviceHandle The device who initiates the DMA access\r
+ request.\r
@param[in] Mapping The mapping value returned from Map().\r
@param[in] IoMmuAccess The IOMMU access.\r
\r
- @retval EFI_SUCCESS The IoMmuAccess is set for the memory range specified by DeviceAddress and Length.\r
+ @retval EFI_SUCCESS The IoMmuAccess is set for the memory range\r
+ specified by DeviceAddress and Length.\r
@retval EFI_INVALID_PARAMETER DeviceHandle is an invalid handle.\r
- @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().\r
- @retval EFI_INVALID_PARAMETER IoMmuAccess specified an illegal combination of access.\r
+ @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by\r
+ Map().\r
+ @retval EFI_INVALID_PARAMETER IoMmuAccess specified an illegal combination\r
+ of access.\r
@retval EFI_UNSUPPORTED DeviceHandle is unknown by the IOMMU.\r
- @retval EFI_UNSUPPORTED The bit mask of IoMmuAccess is not supported by the IOMMU.\r
- @retval EFI_UNSUPPORTED The IOMMU does not support the memory range specified by Mapping.\r
- @retval EFI_OUT_OF_RESOURCES There are not enough resources available to modify the IOMMU access.\r
- @retval EFI_DEVICE_ERROR The IOMMU device reported an error while attempting the operation.\r
+ @retval EFI_UNSUPPORTED The bit mask of IoMmuAccess is not supported\r
+ by the IOMMU.\r
+ @retval EFI_UNSUPPORTED The IOMMU does not support the memory range\r
+ specified by Mapping.\r
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources available to\r
+ modify the IOMMU access.\r
+ @retval EFI_DEVICE_ERROR The IOMMU device reported an error while\r
+ attempting the operation.\r
\r
**/\r
EFI_STATUS\r