+/**\r
+ Transfer an array of bytes using the DMA interface.\r
+\r
+ @param[in] Size Size in bytes to transfer.\r
+ @param[in,out] Buffer Buffer to read data into or write data from. May be\r
+ NULL if Size is zero.\r
+ @param[in] Write TRUE if writing to fw_cfg from Buffer, FALSE if\r
+ reading from fw_cfg into Buffer.\r
+**/\r
+VOID\r
+InternalQemuFwCfgDmaBytes (\r
+ IN UINT32 Size,\r
+ IN OUT VOID *Buffer OPTIONAL,\r
+ IN BOOLEAN Write\r
+ )\r
+{\r
+ volatile FW_CFG_DMA_ACCESS Access;\r
+ UINT32 AccessHigh, AccessLow;\r
+ UINT32 Status;\r
+\r
+ if (Size == 0) {\r
+ return;\r
+ }\r
+\r
+ Access.Control = SwapBytes32 (\r
+ Write ? FW_CFG_DMA_CTL_WRITE : FW_CFG_DMA_CTL_READ\r
+ );\r
+ Access.Length = SwapBytes32 (Size);\r
+ Access.Address = SwapBytes64 ((UINTN)Buffer);\r
+\r
+ //\r
+ // Delimit the transfer from (a) modifications to Access, (b) in case of a\r
+ // write, from writes to Buffer by the caller.\r
+ //\r
+ MemoryFence ();\r
+\r
+ //\r
+ // Start the transfer.\r
+ //\r
+ AccessHigh = (UINT32)RShiftU64 ((UINTN)&Access, 32);\r
+ AccessLow = (UINT32)(UINTN)&Access;\r
+ IoWrite32 (0x514, SwapBytes32 (AccessHigh));\r
+ IoWrite32 (0x518, SwapBytes32 (AccessLow));\r
+\r
+ //\r
+ // Don't look at Access.Control before starting the transfer.\r
+ //\r
+ MemoryFence ();\r
+\r
+ //\r
+ // Wait for the transfer to complete.\r
+ //\r
+ do {\r
+ Status = SwapBytes32 (Access.Control);\r
+ ASSERT ((Status & FW_CFG_DMA_CTL_ERROR) == 0);\r
+ } while (Status != 0);\r
+\r
+ //\r
+ // After a read, the caller will want to use Buffer.\r
+ //\r
+ MemoryFence ();\r
+}\r
+\r
+\r