]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/VirtioLib/VirtioLib.c
OvmfPkg: Make the VirtIo devices use the new VIRTIO_DEVICE_PROTOCOL
[mirror_edk2.git] / OvmfPkg / Library / VirtioLib / VirtioLib.c
index 959bc5da87682f0fb743a51612c29bfbff02f803..503d4adffc8c24722d0b123baded1f43f9960568 100644 (file)
@@ -3,6 +3,7 @@
   Utility functions used by virtio device drivers.\r
 \r
   Copyright (C) 2012, Red Hat, Inc.\r
+  Portion of Copyright (C) 2013, ARM Ltd.\r
 \r
   This program and the accompanying materials are licensed and made available\r
   under the terms and conditions of the BSD License which accompanies this\r
@@ -14,7 +15,6 @@
 \r
 **/\r
 \r
-#include <IndustryStandard/Pci22.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
 \r
 /**\r
 \r
-  Write a word into Region 0 of the device specified by PciIo.\r
+  Write a word into Region 0 of the device specified by VirtIo.\r
 \r
   Region 0 must be an iomem region. This is an internal function for the\r
   driver-specific VIRTIO_CFG_WRITE() macros.\r
 \r
-  @param[in] PciIo        Target PCI device.\r
+  @param[in] VirtIo       Target VirtIo device.\r
 \r
   @param[in] FieldOffset  Destination offset.\r
 \r
                           The least significant FieldSize bytes will be used.\r
 \r
 \r
-  @return  Status code returned by PciIo->Io.Write().\r
+  @return  Status code returned by VirtIo->Io.Write().\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-VirtioWrite (\r
-  IN EFI_PCI_IO_PROTOCOL *PciIo,\r
-  IN UINTN               FieldOffset,\r
-  IN UINTN               FieldSize,\r
-  IN UINT64              Value\r
+VirtioWriteDevice (\r
+  IN VIRTIO_DEVICE_PROTOCOL *VirtIo,\r
+  IN UINTN                  FieldOffset,\r
+  IN UINTN                  FieldSize,\r
+  IN UINT64                 Value\r
   )\r
 {\r
-  UINTN                     Count;\r
-  EFI_PCI_IO_PROTOCOL_WIDTH Width;\r
-\r
-  Count = 1;\r
-  switch (FieldSize) {\r
-    case 1:\r
-      Width = EfiPciIoWidthUint8;\r
-      break;\r
-\r
-    case 2:\r
-      Width = EfiPciIoWidthUint16;\r
-      break;\r
-\r
-    case 8:\r
-      Count = 2;\r
-      // fall through\r
-\r
-    case 4:\r
-      Width = EfiPciIoWidthUint32;\r
-      break;\r
-\r
-    default:\r
-      ASSERT (FALSE);\r
-      return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  return PciIo->Io.Write (\r
-                     PciIo,\r
-                     Width,\r
-                     PCI_BAR_IDX0,\r
-                     FieldOffset,\r
-                     Count,\r
-                     &Value\r
-                     );\r
+  return VirtIo->WriteDevice (VirtIo, FieldOffset, FieldSize, Value);\r
 }\r
 \r
 \r
 /**\r
 \r
-  Read a word from Region 0 of the device specified by PciIo.\r
+  Read a word from Region 0 of the device specified by VirtIo.\r
 \r
   Region 0 must be an iomem region. This is an internal function for the\r
   driver-specific VIRTIO_CFG_READ() macros.\r
 \r
-  @param[in] PciIo        Source PCI device.\r
+  @param[in] VirtIo       Source VirtIo device.\r
 \r
   @param[in] FieldOffset  Source offset.\r
 \r
@@ -109,55 +76,20 @@ VirtioWrite (
   @param[out] Buffer      Target buffer.\r
 \r
 \r
-  @return  Status code returned by PciIo->Io.Read().\r
+  @return  Status code returned by VirtIo->Io.Read().\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-VirtioRead (\r
-  IN  EFI_PCI_IO_PROTOCOL *PciIo,\r
-  IN  UINTN               FieldOffset,\r
-  IN  UINTN               FieldSize,\r
-  IN  UINTN               BufferSize,\r
-  OUT VOID                *Buffer\r
+VirtioReadDevice (\r
+  IN  VIRTIO_DEVICE_PROTOCOL *VirtIo,\r
+  IN  UINTN                  FieldOffset,\r
+  IN  UINTN                  FieldSize,\r
+  IN  UINTN                  BufferSize,\r
+  OUT VOID                   *Buffer\r
   )\r
 {\r
-  UINTN                     Count;\r
-  EFI_PCI_IO_PROTOCOL_WIDTH Width;\r
-\r
-  ASSERT (FieldSize == BufferSize);\r
-\r
-  Count = 1;\r
-  switch (FieldSize) {\r
-    case 1:\r
-      Width = EfiPciIoWidthUint8;\r
-      break;\r
-\r
-    case 2:\r
-      Width = EfiPciIoWidthUint16;\r
-      break;\r
-\r
-    case 8:\r
-      Count = 2;\r
-      // fall through\r
-\r
-    case 4:\r
-      Width = EfiPciIoWidthUint32;\r
-      break;\r
-\r
-    default:\r
-      ASSERT (FALSE);\r
-      return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  return PciIo->Io.Read (\r
-                     PciIo,\r
-                     Width,\r
-                     PCI_BAR_IDX0,\r
-                     FieldOffset,\r
-                     Count,\r
-                     Buffer\r
-                     );\r
+  return VirtIo->ReadDevice (VirtIo, FieldOffset, FieldSize, BufferSize, Buffer);\r
 }\r
 \r
 \r
@@ -376,7 +308,7 @@ VirtioAppendDesc (
   Notify the host about the descriptor chain just built, and wait until the\r
   host processes it.\r
 \r
-  @param[in] PciIo        The target virtio PCI device to notify.\r
+  @param[in] VirtIo       The target virtio device to notify.\r
 \r
   @param[in] VirtQueueId  Identifies the queue for the target device.\r
 \r
@@ -387,7 +319,7 @@ VirtioAppendDesc (
                           of the descriptor chain.\r
 \r
 \r
-  @return              Error code from VirtioWrite() if it fails.\r
+  @return              Error code from VirtIo->SetQueueNotify() if it fails.\r
 \r
   @retval EFI_SUCCESS  Otherwise, the host processed all descriptors.\r
 \r
@@ -395,10 +327,10 @@ VirtioAppendDesc (
 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
+  IN     VIRTIO_DEVICE_PROTOCOL *VirtIo,\r
+  IN     UINT16                 VirtQueueId,\r
+  IN OUT VRING                  *Ring,\r
+  IN     DESC_INDICES           *Indices\r
   )\r
 {\r
   UINT16     NextAvailIdx;\r
@@ -427,12 +359,7 @@ VirtioFlush (
   // OK.\r
   //\r
   MemoryFence();\r
-  Status = VirtioWrite (\r
-             PciIo,\r
-             OFFSET_OF (VIRTIO_HDR, VhdrQueueNotify),\r
-             sizeof (UINT16),\r
-             VirtQueueId\r
-             );\r
+  Status = VirtIo->SetQueueNotify (VirtIo, VirtQueueId);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r