28STATIC BOOLEAN mQemuFwCfgDmaSupported;
64 mQemuFwCfgSupported =
TRUE;
65 mQemuFwCfgDmaSupported =
FALSE;
69 DEBUG ((DEBUG_INFO,
"FW CFG Signature: 0x%x\n", Signature));
72 DEBUG ((DEBUG_INFO,
"FW CFG Revision: 0x%x\n", Revision));
77 DEBUG ((DEBUG_INFO,
"QemuFwCfg interface not supported.\n"));
78 mQemuFwCfgSupported =
FALSE;
82 if ((Revision & FW_CFG_F_DMA) == 0) {
83 DEBUG ((DEBUG_INFO,
"QemuFwCfg interface (IO Port) is supported.\n"));
85 mQemuFwCfgDmaSupported =
TRUE;
86 DEBUG ((DEBUG_INFO,
"QemuFwCfg interface (DMA) is supported.\n"));
96 Status =
gBS->LocateProtocol (
99 (VOID **)&mIoMmuProtocol
101 if (EFI_ERROR (Status)) {
104 "QemuFwCfgDma %a:%a Failed to locate IOMMU protocol.\n",
130 return mQemuFwCfgSupported;
145 return mQemuFwCfgDmaSupported;
176 Status = mIoMmuProtocol->AllocateBuffer (
182 EDKII_IOMMU_ATTRIBUTE_DUAL_ADDRESS_CYCLE
184 if (EFI_ERROR (Status)) {
187 "%a:%a failed to allocate FW_CFG_DMA_ACCESS\n",
204 Status = mIoMmuProtocol->Map (
212 if (EFI_ERROR (Status)) {
213 mIoMmuProtocol->FreeBuffer (mIoMmuProtocol, NumPages, HostAddress);
216 "%a:%a failed to Map() FW_CFG_DMA_ACCESS\n",
225 mIoMmuProtocol->Unmap (mIoMmuProtocol, Mapping);
226 mIoMmuProtocol->FreeBuffer (mIoMmuProtocol, NumPages, HostAddress);
229 "%a:%a failed to Map() - requested 0x%Lx got 0x%Lx\n",
239 *Access = HostAddress;
260 Status = mIoMmuProtocol->Unmap (mIoMmuProtocol, Mapping);
261 if (EFI_ERROR (Status)) {
264 "%a:%a failed to UnMap() Mapping 0x%Lx\n",
267 (UINT64)(
UINTN)Mapping
273 Status = mIoMmuProtocol->FreeBuffer (mIoMmuProtocol, NumPages, Access);
274 if (EFI_ERROR (Status)) {
277 "%a:%a failed to Free() 0x%Lx\n",
280 (UINT64)(
UINTN)Access
296 IN VOID *HostAddress,
307 NumberOfBytes = Size;
308 Status = mIoMmuProtocol->Map (
318 if (EFI_ERROR (Status)) {
321 "%a:%a failed to Map() Address 0x%Lx Size 0x%Lx\n",
324 (UINT64)(
UINTN)HostAddress,
331 if (NumberOfBytes < Size) {
332 mIoMmuProtocol->Unmap (mIoMmuProtocol, Mapping);
335 "%a:%a failed to Map() - requested 0x%x got 0x%Lx\n",
339 (UINT64)NumberOfBytes
345 *DeviceAddress = PhysicalAddress;
351UnmapFwCfgDmaDataBuffer (
357 Status = mIoMmuProtocol->Unmap (mIoMmuProtocol, Mapping);
358 if (EFI_ERROR (Status)) {
361 "%a:%a failed to UnMap() Mapping 0x%Lx\n",
364 (UINT64)(
UINTN)Mapping
389 IN OUT VOID *Buffer OPTIONAL,
395 UINT32 AccessHigh, AccessLow;
397 VOID *AccessMapping, *DataMapping;
401 Control == FW_CFG_DMA_CTL_WRITE || Control == FW_CFG_DMA_CTL_READ ||
402 Control == FW_CFG_DMA_CTL_SKIP
409 Access = &LocalAccess;
410 AccessMapping =
NULL;
427 Access = AccessBuffer;
432 if (Control != FW_CFG_DMA_CTL_SKIP) {
434 Control == FW_CFG_DMA_CTL_WRITE,
441 DataBuffer = (VOID *)(
UINTN)DataBufferAddress;
459 AccessLow = (UINT32)(
UINTN)Access;
473 ASSERT ((Status & FW_CFG_DMA_CTL_ERROR) == 0);
474 }
while (Status != 0);
484 if (AccessMapping !=
NULL) {
491 if (DataMapping !=
NULL) {
492 UnmapFwCfgDmaDataBuffer (DataMapping);
VOID EFIAPI CpuDeadLoop(VOID)
VOID EFIAPI MemoryFence(VOID)
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
UINT64 EFIAPI SwapBytes64(IN UINT64 Value)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
UINT32 EFIAPI IoWrite32(IN UINTN Port, IN UINT32 Value)
#define SIGNATURE_32(A, B, C, D)
#define DEBUG(Expression)
BOOLEAN EFIAPI MemEncryptSevIsEnabled(VOID)
BOOLEAN EFIAPI MemEncryptTdxIsEnabled(VOID)
EFI_GUID gEdkiiIoMmuProtocolGuid
@ EdkiiIoMmuOperationBusMasterWrite64
@ EdkiiIoMmuOperationBusMasterRead64
@ EdkiiIoMmuOperationBusMasterCommonBuffer64
STATIC VOID MapFwCfgDmaDataBuffer(IN BOOLEAN IsWrite, IN VOID *HostAddress, IN UINT32 Size, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **MapInfo)
STATIC VOID FreeFwCfgDmaAccessBuffer(IN VOID *Access, IN VOID *Mapping)
BOOLEAN InternalQemuFwCfgIsAvailable(VOID)
VOID InternalQemuFwCfgDmaBytes(IN UINT32 Size, IN OUT VOID *Buffer OPTIONAL, IN UINT32 Control)
STATIC VOID AllocFwCfgDmaAccessBuffer(OUT VOID **Access, OUT VOID **MapInfo)
BOOLEAN InternalQemuFwCfgDmaIsAvailable(VOID)
BOOLEAN EFIAPI QemuFwCfgIsAvailable(VOID)
UINT32 EFIAPI QemuFwCfgRead32(VOID)
VOID EFIAPI QemuFwCfgSelectItem(IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_SIZE_TO_PAGES(Size)