]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Include/Library/VirtioLib.h
OvmfPkg: librarize reusable bits from VirtioBlkDxe's SynchronousRequest()
[mirror_edk2.git] / OvmfPkg / Include / Library / VirtioLib.h
index eff66da6b3d16c8ca7a01db91f9919dd31475c2f..07e4add7844cd29a63bbc4346cb7df41cc97c379 100644 (file)
@@ -135,6 +135,36 @@ VirtioRingUninit (
   );\r
 \r
 \r
+//\r
+// Internal use structure for tracking the submission of a multi-descriptor\r
+// request.\r
+//\r
+typedef struct {\r
+  UINT16 HeadIdx;\r
+  UINT16 NextAvailIdx;\r
+} DESC_INDICES;\r
+\r
+\r
+/**\r
+\r
+  Turn off interrupt notifications from the host, and prepare for appending\r
+  multiple descriptors to the virtio ring.\r
+\r
+  The calling driver must be in VSTAT_DRIVER_OK state.\r
+\r
+  @param[in out] Ring  The virtio ring we intend to append descriptors to.\r
+\r
+  @param[out] Indices  The DESC_INDICES structure to initialize.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+VirtioPrepare (\r
+  IN OUT VRING        *Ring,\r
+  OUT    DESC_INDICES *Indices\r
+  );\r
+\r
+\r
 /**\r
 \r
   Append a contiguous buffer for transmission / reception via the virtio ring.\r
@@ -148,6 +178,9 @@ VirtioRingUninit (
   request submission. It is the calling driver's responsibility to verify the\r
   ring size in advance.\r
 \r
+  The caller is responsible for initializing *Indices with VirtioPrepare()\r
+  first.\r
+\r
   @param[in out] Ring           The virtio ring to append the buffer to, as a\r
                                 descriptor.\r
 \r
@@ -164,6 +197,8 @@ VirtioRingUninit (
                                 host only interprets it dependent on\r
                                 VRING_DESC_F_NEXT.\r
 \r
+  In *Indices:\r
+\r
   @param [in] HeadIdx           The index identifying the head buffer (first\r
                                 buffer appended) belonging to this same\r
                                 request.\r
@@ -176,12 +211,41 @@ VirtioRingUninit (
 VOID\r
 EFIAPI\r
 VirtioAppendDesc (\r
-  IN OUT VRING  *Ring,\r
-  IN     UINTN  BufferPhysAddr,\r
-  IN     UINT32 BufferSize,\r
-  IN     UINT16 Flags,\r
-  IN     UINT16 HeadIdx,\r
-  IN OUT UINT16 *NextAvailIdx\r
+  IN OUT VRING        *Ring,\r
+  IN     UINTN        BufferPhysAddr,\r
+  IN     UINT32       BufferSize,\r
+  IN     UINT16       Flags,\r
+  IN OUT DESC_INDICES *Indices\r
+  );\r
+\r
+\r
+/**\r
+\r
+  Notify the host about appended descriptors and wait until it processes the\r
+  last one (ie. all of them).\r
+\r
+  @param[in] PciIo        The target virtio PCI device to notify.\r
+\r
+  @param[in] VirtQueueId  Identifies the queue for the target device.\r
+\r
+  @param[in out] Ring     The virtio ring with descriptors to submit.\r
+\r
+  @param[in] Indices      The function waits until the host processes\r
+                          descriptors up to Indices->NextAvailIdx.\r
+\r
+\r
+  @return              Error code from VirtioWrite() if it fails.\r
+\r
+  @retval EFI_SUCCESS  Otherwise, the host processed all descriptors.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioFlush (\r
+  IN     EFI_PCI_IO_PROTOCOL *PciIo,\r
+  IN     UINT16              VirtQueueId,\r
+  IN OUT VRING               *Ring,\r
+  IN     DESC_INDICES        *Indices\r
   );\r
 \r
 #endif // _VIRTIO_LIB_H_\r