]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtPkg/QemuFwCfgLib: use DMA for QemuFwCfgWriteBytes() if available
authorLaszlo Ersek <lersek@redhat.com>
Fri, 27 Jan 2017 06:29:12 +0000 (07:29 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Mon, 30 Jan 2017 23:14:39 +0000 (00:14 +0100)
We use the "InternalQemuFwCfgReadBytes" static function pointer to
dispatch the reading of fw_cfg bytes between MMIO and DMA. This pointer is
initialized to MMIO, and we set it to DMA in the library constructor if
DMA is available.

Unlike the above, we write fw_cfg bytes only with MMIO at the moment.
Extend the write functionality so that it follows the read pattern:
- introduce the new function typedef WRITE_BYTES_FUNCTION,
- extract the current (MMIO-only) write internals from
  QemuFwCfgWriteBytes() to MmioWriteBytes(),
- provide a DMA-based implementation in DmaWriteBytes() -- a thin wrapper
  around DmaTransferBytes(),
- set the new static function pointer "InternalQemuFwCfgWriteBytes"
  according to the DMA feature provided by QEMU,
- In QemuFwCfgWriteBytes(), call the best available method through
  "InternalQemuFwCfgWriteBytes".

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=359
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c

index bd0f34720eec3465b7d4cef68d0de1dc241b7643..56db908f5c91a73a51b14af93b86dd0963b5c0d4 100644 (file)
@@ -42,16 +42,32 @@ VOID (EFIAPI READ_BYTES_FUNCTION) (
   IN VOID  *Buffer OPTIONAL\r
   );\r
 \r
+/**\r
+  Writes bytes from a buffer to firmware configuration\r
+\r
+  @param[in] Size    Size in bytes to write\r
+  @param[in] Buffer  Buffer to transfer data from (OPTIONAL if Size is 0)\r
+\r
+**/\r
+typedef\r
+VOID (EFIAPI WRITE_BYTES_FUNCTION) (\r
+  IN UINTN Size,\r
+  IN VOID  *Buffer OPTIONAL\r
+  );\r
+\r
 //\r
 // Forward declaration of the two implementations we have.\r
 //\r
 STATIC READ_BYTES_FUNCTION MmioReadBytes;\r
+STATIC WRITE_BYTES_FUNCTION MmioWriteBytes;\r
 STATIC READ_BYTES_FUNCTION DmaReadBytes;\r
+STATIC WRITE_BYTES_FUNCTION DmaWriteBytes;\r
 \r
 //\r
-// This points to the one we detect at runtime.\r
+// These correspond to the implementation we detect at runtime.\r
 //\r
 STATIC READ_BYTES_FUNCTION *InternalQemuFwCfgReadBytes = MmioReadBytes;\r
+STATIC WRITE_BYTES_FUNCTION *InternalQemuFwCfgWriteBytes = MmioWriteBytes;\r
 \r
 \r
 /**\r
@@ -166,6 +182,7 @@ QemuFwCfgInitialize (
         if ((Features & FW_CFG_F_DMA) != 0) {\r
           mFwCfgDmaAddress = FwCfgDmaAddress;\r
           InternalQemuFwCfgReadBytes = DmaReadBytes;\r
+          InternalQemuFwCfgWriteBytes = DmaWriteBytes;\r
         }\r
       }\r
     } else {\r
@@ -358,6 +375,41 @@ QemuFwCfgReadBytes (
   }\r
 }\r
 \r
+\r
+/**\r
+  Slow WRITE_BYTES_FUNCTION.\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+MmioWriteBytes (\r
+  IN UINTN Size,\r
+  IN VOID  *Buffer OPTIONAL\r
+  )\r
+{\r
+  UINTN Idx;\r
+\r
+  for (Idx = 0; Idx < Size; ++Idx) {\r
+    MmioWrite8 (mFwCfgDataAddress, ((UINT8 *)Buffer)[Idx]);\r
+  }\r
+}\r
+\r
+\r
+/**\r
+  Fast WRITE_BYTES_FUNCTION.\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+DmaWriteBytes (\r
+  IN UINTN Size,\r
+  IN VOID  *Buffer OPTIONAL\r
+  )\r
+{\r
+  DmaTransferBytes (Size, Buffer, FW_CFG_DMA_CTL_WRITE);\r
+}\r
+\r
+\r
 /**\r
   Write firmware configuration bytes from a buffer\r
 \r
@@ -376,11 +428,7 @@ QemuFwCfgWriteBytes (
   )\r
 {\r
   if (QemuFwCfgIsAvailable ()) {\r
-    UINTN Idx;\r
-\r
-    for (Idx = 0; Idx < Size; ++Idx) {\r
-      MmioWrite8 (mFwCfgDataAddress, ((UINT8 *)Buffer)[Idx]);\r
-    }\r
+    InternalQemuFwCfgWriteBytes (Size, Buffer);\r
   }\r
 }\r
 \r