diff mbox

[edk2,wave,3,03/15] OvmfPkg: VIRTIO_DEVICE_PROTOCOL: pass VRING object to SetQueueAddress()

Message ID 1457960012-29481-4-git-send-email-lersek@redhat.com
State Superseded
Headers show

Commit Message

Laszlo Ersek March 14, 2016, 12:53 p.m. UTC
In virtio-1.0, it is not enough to pass the base address of the virtio
queue to the hypervisor (as a frame number); instead it will want the
addresses of the descriptor table, the available ring, and the used ring
separately. Pass the VRING object to the SetQueueAddress() member
function; this will enable a virtio-1.0 implementation. Convert the
current producers and consumers to this prototype.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>

---
 OvmfPkg/Include/Protocol/VirtioDevice.h                         | 12 ++++++------
 OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h          |  4 ++--
 OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h                    |  4 ++--
 OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c |  7 ++++---
 OvmfPkg/VirtioBlkDxe/VirtioBlk.c                                |  3 +--
 OvmfPkg/VirtioNetDxe/SnpInitialize.c                            |  3 +--
 OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c                 |  6 +++---
 OvmfPkg/VirtioRngDxe/VirtioRng.c                                |  3 +--
 OvmfPkg/VirtioScsiDxe/VirtioScsi.c                              |  3 +--
 9 files changed, 21 insertions(+), 24 deletions(-)

-- 
1.8.3.1


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox

Patch

diff --git a/OvmfPkg/Include/Protocol/VirtioDevice.h b/OvmfPkg/Include/Protocol/VirtioDevice.h
index f8afa7120a4c..910a4866e7ac 100644
--- a/OvmfPkg/Include/Protocol/VirtioDevice.h
+++ b/OvmfPkg/Include/Protocol/VirtioDevice.h
@@ -15,14 +15,16 @@ 
   WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 **/
 
 #ifndef __VIRTIO_DEVICE_H__
 #define __VIRTIO_DEVICE_H__
 
+#include <IndustryStandard/Virtio.h>
+
 // VirtIo Specification Revision: Major[31:24].Minor[23:16].Revision[15:0
 #define VIRTIO_SPEC_REVISION(major,minor,revision) \
   ((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | ((revision) & 0xFFFF))
 
 #define VIRTIO_DEVICE_PROTOCOL_GUID { \
   0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a }\
   }
@@ -123,32 +125,30 @@  typedef
 EFI_STATUS
 (EFIAPI *VIRTIO_SET_GUEST_FEATURES) (
   IN VIRTIO_DEVICE_PROTOCOL  *This,
   IN UINT64                   Features
   );
 
 /**
-  Write the queue address field in the Virtio Header.
-
-  The parameter Address must be the base address of the virtqueue divided
-  by 4096.
+  Write the queue address field(s) in the Virtio Header.
 
   @param[in] This             This instance of VIRTIO_DEVICE_PROTOCOL
 
-  @param[in] Address          The 32-bit Queue Address field
+  @param[in] Ring             The initialized VRING object to take the
+                              addresses from.
 
   @retval EFI_SUCCESS         The data was written successfully.
   @retval EFI_UNSUPPORTED     The underlying IO device doesn't support the
                               provided address offset and write size.
 **/
 typedef
 EFI_STATUS
 (EFIAPI *VIRTIO_SET_QUEUE_ADDRESS) (
   IN VIRTIO_DEVICE_PROTOCOL  *This,
-  IN UINT32                   Address
+  IN VRING                   *Ring
   );
 
 /**
 
   Write the queue select field in the Virtio Header.
 
   Writing to the queue select field sets the index of the queue to which
diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
index 3b1e90ba9f3b..4130dbc043df 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
@@ -108,16 +108,16 @@  EFIAPI
 VirtioMmioSetQueueSel (
   VIRTIO_DEVICE_PROTOCOL *This,
   UINT16                  Sel
   );
 
 EFI_STATUS
 VirtioMmioSetQueueAddress (
-  VIRTIO_DEVICE_PROTOCOL *This,
-  UINT32                  Address
+  IN VIRTIO_DEVICE_PROTOCOL  *This,
+  IN VRING                   *Ring
   );
 
 EFI_STATUS
 EFIAPI
 VirtioMmioSetQueueAlignment (
   VIRTIO_DEVICE_PROTOCOL *This,
   UINT32                  Alignment
diff --git a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h
index 95f82611e295..8f17a16c88f5 100644
--- a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h
+++ b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h
@@ -120,16 +120,16 @@  VirtioPciSetGuestFeatures (
   IN VIRTIO_DEVICE_PROTOCOL  *This,
   IN UINT64                   Features
   );
 
 EFI_STATUS
 EFIAPI
 VirtioPciSetQueueAddress (
-  VIRTIO_DEVICE_PROTOCOL         *This,
-  UINT32                         Address
+  IN VIRTIO_DEVICE_PROTOCOL  *This,
+  IN VRING                   *Ring
   );
 
 EFI_STATUS
 EFIAPI
 VirtioPciSetQueueSel (
   VIRTIO_DEVICE_PROTOCOL         *This,
   UINT16                         Sel
diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
index 2cd293ab88d9..53c734f6b1af 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
@@ -176,23 +176,24 @@  VirtioMmioSetQueueSel (
   VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_SEL, Sel);
 
   return EFI_SUCCESS;
 }
 
 EFI_STATUS
 VirtioMmioSetQueueAddress (
-  VIRTIO_DEVICE_PROTOCOL *This,
-  UINT32                  Address
+  IN VIRTIO_DEVICE_PROTOCOL  *This,
+  IN VRING                   *Ring
   )
 {
   VIRTIO_MMIO_DEVICE *Device;
 
   Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
 
-  VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN, Address);
+  VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN,
+    (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT));
 
   return EFI_SUCCESS;
 }
 
 EFI_STATUS
 EFIAPI
 VirtioMmioSetGuestFeatures (
diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
index b35f60c9d233..daccc7a5d06b 100644
--- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
+++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
@@ -726,16 +726,15 @@  VirtioBlkInit (
   if (EFI_ERROR (Status)) {
     goto ReleaseQueue;
   }
 
   //
   // step 4c -- Report GPFN (guest-physical frame number) of queue.
   //
-  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
-      (UINT32) ((UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT));
+  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring);
   if (EFI_ERROR (Status)) {
     goto ReleaseQueue;
   }
 
 
   //
   // step 5 -- Report understood features. There are no virtio-blk specific
diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c
index 71b67fa52df9..f06b0a5a5742 100644
--- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c
+++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c
@@ -91,16 +91,15 @@  VirtioNetInitRing (
   if (EFI_ERROR (Status)) {
     goto ReleaseQueue;
   }
 
   //
   // step 4c -- report GPFN (guest-physical frame number) of queue
   //
-  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
-      (UINT32) ((UINTN) Ring->Base >> EFI_PAGE_SHIFT));
+  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, Ring);
   if (EFI_ERROR (Status)) {
     goto ReleaseQueue;
   }
 
   return EFI_SUCCESS;
 
 ReleaseQueue:
diff --git a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c
index 4ba37a2d1ceb..243aa14c2421 100644
--- a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c
+++ b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c
@@ -177,24 +177,24 @@  VirtioPciSetGuestFeatures (
   return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_GUEST_FEATURES,
       sizeof (UINT32), Features);
 }
 
 EFI_STATUS
 EFIAPI
 VirtioPciSetQueueAddress (
-  VIRTIO_DEVICE_PROTOCOL    *This,
-  UINT32                    Address
+  IN VIRTIO_DEVICE_PROTOCOL  *This,
+  IN VRING                   *Ring
   )
 {
   VIRTIO_PCI_DEVICE *Dev;
 
   Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
 
   return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_QUEUE_ADDRESS, sizeof (UINT32),
-      Address);
+      (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT));
 }
 
 EFI_STATUS
 EFIAPI
 VirtioPciSetQueueSel (
   VIRTIO_DEVICE_PROTOCOL    *This,
   UINT16                    Sel
diff --git a/OvmfPkg/VirtioRngDxe/VirtioRng.c b/OvmfPkg/VirtioRngDxe/VirtioRng.c
index de4afefe7000..290bddeeecae 100644
--- a/OvmfPkg/VirtioRngDxe/VirtioRng.c
+++ b/OvmfPkg/VirtioRngDxe/VirtioRng.c
@@ -280,16 +280,15 @@  VirtioRngInit (
   if (EFI_ERROR (Status)) {
     goto ReleaseQueue;
   }
 
   //
   // step 4c -- Report GPFN (guest-physical frame number) of queue.
   //
-  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
-      (UINT32) ((UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT));
+  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring);
   if (EFI_ERROR (Status)) {
     goto ReleaseQueue;
   }
 
   //
   // step 5 -- Report understood features and guest-tuneables. None are
   // currently defined for VirtioRng, and no generic features are needed by
diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
index 52952886226b..162577bcb961 100644
--- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
+++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
@@ -837,16 +837,15 @@  VirtioScsiInit (
   if (EFI_ERROR (Status)) {
     goto ReleaseQueue;
   }
 
   //
   // step 4c -- Report GPFN (guest-physical frame number) of queue.
   //
-  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
-      (UINT32) ((UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT));
+  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring);
   if (EFI_ERROR (Status)) {
     goto ReleaseQueue;
   }
 
   //
   // step 5 -- Report understood features and guest-tuneables. We want none of
   // the known (or unknown) VIRTIO_SCSI_F_* or VIRTIO_F_* capabilities (see