public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v4 0/7] add support for virtio-mmio 1.0
@ 2021-08-19  7:25 Gerd Hoffmann
  2021-08-19  7:25 ` [PATCH v4 1/7] OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines Gerd Hoffmann
                   ` (9 more replies)
  0 siblings, 10 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2021-08-19  7:25 UTC (permalink / raw)
  To: devel; +Cc: Gerd Hoffmann

This little series adds virtio 1.0 support for the virtio-mmio
transport.  For the mmio transport the difference between 0.9.5 and 1.0
is rather small (when compared to the pci transport), it is just a bunch
of new registers for the changed virtio queue initialization.  So the
patch series is small too ...

v2 changes:
 - Added review tags for patches #1 + #2.
 - Add a patch to make sure we have a valid QueueNum.
 - Add a patch to support all 64 virtio 1.0 feature bits.
v3 changes:
 - Add #defines for virtio-mmio version field.
v4 changes:
 - split patches into smaller ones.
 - enable virtio 1.0 at the end when everything is in place.

take care,
  Gerd

Gerd Hoffmann (7):
  OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines
  OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection.
  OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize.
  OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress
  OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum
  OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling
  OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0

 OvmfPkg/Include/IndustryStandard/Virtio10.h   | 12 ++++
 .../VirtioMmioDeviceLib/VirtioMmioDevice.h    |  5 ++
 .../VirtioMmioDeviceLib/VirtioMmioDevice.c    | 17 +++--
 .../VirtioMmioDeviceFunctions.c               | 71 ++++++++++++++++---
 4 files changed, 92 insertions(+), 13 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v4 1/7] OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines
  2021-08-19  7:25 [PATCH v4 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
@ 2021-08-19  7:25 ` Gerd Hoffmann
  2021-08-19  7:25 ` [PATCH v4 2/7] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection Gerd Hoffmann
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2021-08-19  7:25 UTC (permalink / raw)
  To: devel; +Cc: Gerd Hoffmann, Philippe Mathieu-Daude

Add defines for the config space offsets for virtio 1.0 mmio transport.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
---
 OvmfPkg/Include/IndustryStandard/Virtio10.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/OvmfPkg/Include/IndustryStandard/Virtio10.h b/OvmfPkg/Include/IndustryStandard/Virtio10.h
index 2c60be2b7c0c..a1712247e054 100644
--- a/OvmfPkg/Include/IndustryStandard/Virtio10.h
+++ b/OvmfPkg/Include/IndustryStandard/Virtio10.h
@@ -81,4 +81,16 @@ typedef struct {
 #define VIRTIO_F_VERSION_1      BIT32
 #define VIRTIO_F_IOMMU_PLATFORM BIT33
 
+//
+// MMIO VirtIo Header Offsets
+//
+#define VIRTIO_MMIO_OFFSET_QUEUE_READY                0x44
+#define VIRTIO_MMIO_OFFSET_QUEUE_DESC_LO              0x80
+#define VIRTIO_MMIO_OFFSET_QUEUE_DESC_HI              0x84
+#define VIRTIO_MMIO_OFFSET_QUEUE_AVAIL_LO             0x90
+#define VIRTIO_MMIO_OFFSET_QUEUE_AVAIL_HI             0x94
+#define VIRTIO_MMIO_OFFSET_QUEUE_USED_LO              0xa0
+#define VIRTIO_MMIO_OFFSET_QUEUE_USED_HI              0xa4
+#define VIRTIO_MMIO_OFFSET_CONFIG_GENERATION          0xfc
+
 #endif // _VIRTIO_1_0_H_
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 2/7] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection.
  2021-08-19  7:25 [PATCH v4 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
  2021-08-19  7:25 ` [PATCH v4 1/7] OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines Gerd Hoffmann
@ 2021-08-19  7:25 ` Gerd Hoffmann
  2021-08-19  7:25 ` [PATCH v4 3/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize Gerd Hoffmann
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2021-08-19  7:25 UTC (permalink / raw)
  To: devel; +Cc: Gerd Hoffmann

Add #defines for the Version field.  Read and store the version,
log the version found as info message.

Continue to return UNSUPPORTED for now, we need some more patches
to complete virtio 1.0 support first.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 .../VirtioMmioDeviceLib/VirtioMmioDevice.h      |  4 ++++
 .../VirtioMmioDeviceLib/VirtioMmioDevice.c      | 17 +++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
index ab53b90d51c9..0c2f99633c46 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
@@ -23,9 +23,13 @@
 #include <Library/MemoryAllocationLib.h>
 
 #define VIRTIO_MMIO_DEVICE_SIGNATURE  SIGNATURE_32 ('V', 'M', 'I', 'O')
+#define VIRTIO_MMIO_DEVICE_VERSION_0_95  1
+#define VIRTIO_MMIO_DEVICE_VERSION_1_00  2
+
 
 typedef struct {
   UINT32                 Signature;
+  UINT32                 Version;
   VIRTIO_DEVICE_PROTOCOL VirtioDevice;
   PHYSICAL_ADDRESS       BaseAddress;
 } VIRTIO_MMIO_DEVICE;
diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
index 6dbbba008c75..0c92f5373151 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
@@ -58,7 +58,6 @@ VirtioMmioInit (
   )
 {
   UINT32     MagicValue;
-  UINT32     Version;
 
   //
   // Initialize VirtIo Mmio Device
@@ -66,7 +65,6 @@ VirtioMmioInit (
   CopyMem (&Device->VirtioDevice, &mMmioDeviceProtocolTemplate,
         sizeof (VIRTIO_DEVICE_PROTOCOL));
   Device->BaseAddress = BaseAddress;
-  Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (0, 9, 5);
   Device->VirtioDevice.SubSystemDeviceId =
           MmioRead32 (BaseAddress + VIRTIO_MMIO_OFFSET_DEVICE_ID);
 
@@ -78,8 +76,19 @@ VirtioMmioInit (
     return EFI_UNSUPPORTED;
   }
 
-  Version = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_VERSION);
-  if (Version != 1) {
+  Device->Version = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_VERSION);
+  switch (Device->Version) {
+  case VIRTIO_MMIO_DEVICE_VERSION_0_95:
+    DEBUG ((DEBUG_INFO, "%a virtio 0.9.5, id %d\n", __FUNCTION__,
+            Device->VirtioDevice.SubSystemDeviceId));
+    Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (0, 9, 5);
+    break;
+  case VIRTIO_MMIO_DEVICE_VERSION_1_00:
+    DEBUG ((DEBUG_INFO, "%a virtio 1.0, id %d\n", __FUNCTION__,
+            Device->VirtioDevice.SubSystemDeviceId));
+    Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (1, 0, 0);
+    return EFI_UNSUPPORTED;
+  default:
     return EFI_UNSUPPORTED;
   }
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 3/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize.
  2021-08-19  7:25 [PATCH v4 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
  2021-08-19  7:25 ` [PATCH v4 1/7] OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines Gerd Hoffmann
  2021-08-19  7:25 ` [PATCH v4 2/7] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection Gerd Hoffmann
@ 2021-08-19  7:25 ` Gerd Hoffmann
  2021-08-19  7:25 ` [PATCH v4 4/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress Gerd Hoffmann
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2021-08-19  7:25 UTC (permalink / raw)
  To: devel; +Cc: Gerd Hoffmann

Nothing to do here for virtio 1.0 devices.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 .../Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c   | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
index b0d75fb1dd24..50a4fd2100ee 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
@@ -151,7 +151,9 @@ VirtioMmioSetPageSize (
 
   Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
 
-  VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_PAGE_SIZE, PageSize);
+  if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_PAGE_SIZE, PageSize);
+  }
 
   return EFI_SUCCESS;
 }
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 4/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress
  2021-08-19  7:25 [PATCH v4 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2021-08-19  7:25 ` [PATCH v4 3/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize Gerd Hoffmann
@ 2021-08-19  7:25 ` Gerd Hoffmann
  2021-08-19  7:25 ` [PATCH v4 5/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum Gerd Hoffmann
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2021-08-19  7:25 UTC (permalink / raw)
  To: devel; +Cc: Gerd Hoffmann

Virtio 1.0 allows a more flexible virtio ring layout, so we have to set
addresses for descriptors avail flags and use flags separately.  We
continue to use a ring layout compatible with virtio 0.9.5 though, so no
other changes are needed to setup the virtio queues.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 .../VirtioMmioDeviceFunctions.c               | 27 +++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
index 50a4fd2100ee..a0ee8e5f3c86 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
@@ -183,13 +183,36 @@ VirtioMmioSetQueueAddress (
   )
 {
   VIRTIO_MMIO_DEVICE *Device;
+  UINT64 Address;
 
   ASSERT (RingBaseShift == 0);
 
   Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
 
-  VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN,
-    (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT));
+  if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN,
+      (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT));
+  } else {
+    Address = (UINT64)Ring->Base;
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_DESC_LO,
+                      (UINT32)Address);
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_DESC_HI,
+                      (UINT32)RShiftU64(Address, 32));
+
+    Address = (UINT64)Ring->Avail.Flags;
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_AVAIL_LO,
+                      (UINT32)Address);
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_AVAIL_HI,
+                      (UINT32)RShiftU64(Address, 32));
+
+    Address = (UINT64)Ring->Used.Flags;
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_USED_LO,
+                      (UINT32)Address);
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_USED_HI,
+                      (UINT32)RShiftU64(Address, 32));
+
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_READY, 1);
+  }
 
   return EFI_SUCCESS;
 }
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 5/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum
  2021-08-19  7:25 [PATCH v4 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2021-08-19  7:25 ` [PATCH v4 4/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress Gerd Hoffmann
@ 2021-08-19  7:25 ` Gerd Hoffmann
  2021-08-19  7:25 ` [PATCH v4 6/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling Gerd Hoffmann
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2021-08-19  7:25 UTC (permalink / raw)
  To: devel; +Cc: Gerd Hoffmann

Use QueueNumMax as QueueNum default for drivers which do not
explicitly call VIRTIO_DEVICE_PROTOCOL->SetQueueSize().

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 .../Library/VirtioMmioDeviceLib/VirtioMmioDevice.h   |  1 +
 .../VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c  | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
index 0c2f99633c46..5ad951f4154a 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
@@ -30,6 +30,7 @@
 typedef struct {
   UINT32                 Signature;
   UINT32                 Version;
+  UINT16                 QueueNum;
   VIRTIO_DEVICE_PROTOCOL VirtioDevice;
   PHYSICAL_ADDRESS       BaseAddress;
 } VIRTIO_MMIO_DEVICE;
diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
index a0ee8e5f3c86..b4711f9b42e6 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
@@ -83,7 +83,11 @@ VirtioMmioSetQueueSize (
 
   Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
 
-  VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM, QueueSize);
+  if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM, QueueSize);
+  } else {
+    Device->QueueNum = QueueSize;
+  }
 
   return EFI_SUCCESS;
 }
@@ -171,6 +175,10 @@ VirtioMmioSetQueueSel (
 
   VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_SEL, Sel);
 
+  if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
+    Device->QueueNum = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM_MAX) & 0xFFFF;
+  }
+
   return EFI_SUCCESS;
 }
 
@@ -193,6 +201,8 @@ VirtioMmioSetQueueAddress (
     VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN,
       (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT));
   } else {
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM, Device->QueueNum);
+
     Address = (UINT64)Ring->Base;
     VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_DESC_LO,
                       (UINT32)Address);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 6/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling
  2021-08-19  7:25 [PATCH v4 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (4 preceding siblings ...)
  2021-08-19  7:25 ` [PATCH v4 5/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum Gerd Hoffmann
@ 2021-08-19  7:25 ` Gerd Hoffmann
  2021-08-19  7:25 ` [PATCH v4 7/7] OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0 Gerd Hoffmann
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2021-08-19  7:25 UTC (permalink / raw)
  To: devel; +Cc: Gerd Hoffmann

virtio 1.0 has 64 feature bits instead of 32.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 .../VirtioMmioDeviceFunctions.c               | 28 +++++++++++++++----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
index b4711f9b42e6..c6b7b45dc792 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
@@ -20,6 +20,7 @@ VirtioMmioGetDeviceFeatures (
   )
 {
   VIRTIO_MMIO_DEVICE *Device;
+  UINT32  LowBits, HighBits;
 
   if (DeviceFeatures == NULL) {
     return EFI_INVALID_PARAMETER;
@@ -27,7 +28,15 @@ VirtioMmioGetDeviceFeatures (
 
   Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
 
-  *DeviceFeatures = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES);
+  if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
+    *DeviceFeatures = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES);
+  } else {
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES_SEL, 0);
+    LowBits = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES);
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES_SEL, 1);
+    HighBits = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES);
+    *DeviceFeatures = LShiftU64(HighBits, 32) | LowBits;
+  }
 
   return EFI_SUCCESS;
 }
@@ -238,11 +247,20 @@ VirtioMmioSetGuestFeatures (
 
   Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
 
-  if (Features > MAX_UINT32) {
-    return EFI_UNSUPPORTED;
+  if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) {
+    if (Features > MAX_UINT32) {
+      return EFI_UNSUPPORTED;
+    }
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES,
+                      (UINT32)Features);
+  } else {
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES_SEL, 0);
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES,
+                      (UINT32)Features);
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES_SEL, 1);
+    VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES,
+                      (UINT32)RShiftU64(Features, 32));
   }
-  VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES,
-    (UINT32)Features);
 
   return EFI_SUCCESS;
 }
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 7/7] OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0
  2021-08-19  7:25 [PATCH v4 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (5 preceding siblings ...)
  2021-08-19  7:25 ` [PATCH v4 6/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling Gerd Hoffmann
@ 2021-08-19  7:25 ` Gerd Hoffmann
  2021-08-19  9:26 ` [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0 Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2021-08-19  7:25 UTC (permalink / raw)
  To: devel; +Cc: Gerd Hoffmann

Now with everything in place for virtio 1.0 devices we can let
VirtioMmioInit() return SUCCESS.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
index 0c92f5373151..a97ef9352d0f 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
@@ -87,7 +87,7 @@ VirtioMmioInit (
     DEBUG ((DEBUG_INFO, "%a virtio 1.0, id %d\n", __FUNCTION__,
             Device->VirtioDevice.SubSystemDeviceId));
     Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (1, 0, 0);
-    return EFI_UNSUPPORTED;
+    break;
   default:
     return EFI_UNSUPPORTED;
   }
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0
  2021-08-19  7:25 [PATCH v4 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (6 preceding siblings ...)
  2021-08-19  7:25 ` [PATCH v4 7/7] OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0 Gerd Hoffmann
@ 2021-08-19  9:26 ` Philippe Mathieu-Daudé
  2021-08-20  7:20   ` Yao, Jiewen
  2021-08-27 10:35 ` Yao, Jiewen
       [not found] ` <169F236B4CC08BB7.32747@groups.io>
  9 siblings, 1 reply; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-08-19  9:26 UTC (permalink / raw)
  To: devel, kraxel

On 8/19/21 9:25 AM, Gerd Hoffmann wrote:
> This little series adds virtio 1.0 support for the virtio-mmio
> transport.  For the mmio transport the difference between 0.9.5 and 1.0
> is rather small (when compared to the pci transport), it is just a bunch
> of new registers for the changed virtio queue initialization.  So the
> patch series is small too ...

> Gerd Hoffmann (7):
>   OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines
>   OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection.
>   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize.
>   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress
>   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum
>   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling
>   OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0

Series:
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0
  2021-08-19  9:26 ` [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0 Philippe Mathieu-Daudé
@ 2021-08-20  7:20   ` Yao, Jiewen
  0 siblings, 0 replies; 15+ messages in thread
From: Yao, Jiewen @ 2021-08-20  7:20 UTC (permalink / raw)
  To: devel@edk2.groups.io, philmd@redhat.com, kraxel@redhat.com

Series Reviewed-by: Jiewen Yao <Jiewen.yao@Intel.com>

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Philippe
> Mathieu-Daudé
> Sent: Thursday, August 19, 2021 5:26 PM
> To: devel@edk2.groups.io; kraxel@redhat.com
> Subject: Re: [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0
> 
> On 8/19/21 9:25 AM, Gerd Hoffmann wrote:
> > This little series adds virtio 1.0 support for the virtio-mmio
> > transport.  For the mmio transport the difference between 0.9.5 and 1.0
> > is rather small (when compared to the pci transport), it is just a bunch
> > of new registers for the changed virtio queue initialization.  So the
> > patch series is small too ...
> 
> > Gerd Hoffmann (7):
> >   OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines
> >   OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection.
> >   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize.
> >   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress
> >   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum
> >   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling
> >   OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0
> 
> Series:
> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0
  2021-08-19  7:25 [PATCH v4 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (7 preceding siblings ...)
  2021-08-19  9:26 ` [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0 Philippe Mathieu-Daudé
@ 2021-08-27 10:35 ` Yao, Jiewen
       [not found] ` <169F236B4CC08BB7.32747@groups.io>
  9 siblings, 0 replies; 15+ messages in thread
From: Yao, Jiewen @ 2021-08-27 10:35 UTC (permalink / raw)
  To: devel@edk2.groups.io, kraxel@redhat.com

Hi Gerd
I create a PR but it fails. I am not able to merge.

https://github.com/tianocore/edk2/pull/1917

Would you please take a look, fix it and resubmit V5?


> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Gerd
> Hoffmann
> Sent: Thursday, August 19, 2021 3:25 PM
> To: devel@edk2.groups.io
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Subject: [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0
> 
> This little series adds virtio 1.0 support for the virtio-mmio
> transport.  For the mmio transport the difference between 0.9.5 and 1.0
> is rather small (when compared to the pci transport), it is just a bunch
> of new registers for the changed virtio queue initialization.  So the
> patch series is small too ...
> 
> v2 changes:
>  - Added review tags for patches #1 + #2.
>  - Add a patch to make sure we have a valid QueueNum.
>  - Add a patch to support all 64 virtio 1.0 feature bits.
> v3 changes:
>  - Add #defines for virtio-mmio version field.
> v4 changes:
>  - split patches into smaller ones.
>  - enable virtio 1.0 at the end when everything is in place.
> 
> take care,
>   Gerd
> 
> Gerd Hoffmann (7):
>   OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines
>   OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection.
>   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize.
>   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress
>   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum
>   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling
>   OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0
> 
>  OvmfPkg/Include/IndustryStandard/Virtio10.h   | 12 ++++
>  .../VirtioMmioDeviceLib/VirtioMmioDevice.h    |  5 ++
>  .../VirtioMmioDeviceLib/VirtioMmioDevice.c    | 17 +++--
>  .../VirtioMmioDeviceFunctions.c               | 71 ++++++++++++++++---
>  4 files changed, 92 insertions(+), 13 deletions(-)
> 
> --
> 2.31.1
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0
       [not found] ` <169F236B4CC08BB7.32747@groups.io>
@ 2021-08-27 11:35   ` Yao, Jiewen
  2021-08-27 13:42     ` Gerd Hoffmann
  0 siblings, 1 reply; 15+ messages in thread
From: Yao, Jiewen @ 2021-08-27 11:35 UTC (permalink / raw)
  To: devel@edk2.groups.io, Yao, Jiewen, kraxel@redhat.com

I am sorry, I mess up https://github.com/tianocore/edk2/pull/1917, please ignore that.

This pull request is re-created at https://github.com/tianocore/edk2/pull/1918.

Please take a look at 1918.


> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Yao, Jiewen
> Sent: Friday, August 27, 2021 6:35 PM
> To: devel@edk2.groups.io; kraxel@redhat.com
> Subject: Re: [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0
> 
> Hi Gerd
> I create a PR but it fails. I am not able to merge.
> 
> https://github.com/tianocore/edk2/pull/1917
> 
> Would you please take a look, fix it and resubmit V5?
> 
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Gerd
> > Hoffmann
> > Sent: Thursday, August 19, 2021 3:25 PM
> > To: devel@edk2.groups.io
> > Cc: Gerd Hoffmann <kraxel@redhat.com>
> > Subject: [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0
> >
> > This little series adds virtio 1.0 support for the virtio-mmio
> > transport.  For the mmio transport the difference between 0.9.5 and 1.0
> > is rather small (when compared to the pci transport), it is just a bunch
> > of new registers for the changed virtio queue initialization.  So the
> > patch series is small too ...
> >
> > v2 changes:
> >  - Added review tags for patches #1 + #2.
> >  - Add a patch to make sure we have a valid QueueNum.
> >  - Add a patch to support all 64 virtio 1.0 feature bits.
> > v3 changes:
> >  - Add #defines for virtio-mmio version field.
> > v4 changes:
> >  - split patches into smaller ones.
> >  - enable virtio 1.0 at the end when everything is in place.
> >
> > take care,
> >   Gerd
> >
> > Gerd Hoffmann (7):
> >   OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines
> >   OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection.
> >   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize.
> >   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress
> >   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum
> >   OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling
> >   OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0
> >
> >  OvmfPkg/Include/IndustryStandard/Virtio10.h   | 12 ++++
> >  .../VirtioMmioDeviceLib/VirtioMmioDevice.h    |  5 ++
> >  .../VirtioMmioDeviceLib/VirtioMmioDevice.c    | 17 +++--
> >  .../VirtioMmioDeviceFunctions.c               | 71 ++++++++++++++++---
> >  4 files changed, 92 insertions(+), 13 deletions(-)
> >
> > --
> > 2.31.1
> >
> >
> >
> >
> >
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0
  2021-08-27 11:35   ` Yao, Jiewen
@ 2021-08-27 13:42     ` Gerd Hoffmann
  2021-08-27 13:45       ` Yao, Jiewen
  2021-08-27 13:46       ` Ard Biesheuvel
  0 siblings, 2 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2021-08-27 13:42 UTC (permalink / raw)
  To: Yao, Jiewen; +Cc: devel@edk2.groups.io

On Fri, Aug 27, 2021 at 11:35:42AM +0000, Yao, Jiewen wrote:
> I am sorry, I mess up https://github.com/tianocore/edk2/pull/1917, please ignore that.
> 
> This pull request is re-created at https://github.com/tianocore/edk2/pull/1918.
> 
> Please take a look at 1918.

Is there some way to run the CI before posting the patches?

I could probably create a dummy pull request for that and delete it when
the CI is done.  That'll probably make gitlab send out a bunch of
annoying notifications though ...

thanks,
  Gerd


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0
  2021-08-27 13:42     ` Gerd Hoffmann
@ 2021-08-27 13:45       ` Yao, Jiewen
  2021-08-27 13:46       ` Ard Biesheuvel
  1 sibling, 0 replies; 15+ messages in thread
From: Yao, Jiewen @ 2021-08-27 13:45 UTC (permalink / raw)
  To: devel@edk2.groups.io, kraxel@redhat.com; +Cc: Yao, Jiewen

Yes, please.
Feel free to submit your own PR.

As long as you did not label - PUSH, this CI just shows the test result. It will NOT merge automatically.

Thank you
Yao Jiewen

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Gerd
> Hoffmann
> Sent: Friday, August 27, 2021 9:43 PM
> To: Yao, Jiewen <jiewen.yao@intel.com>
> Cc: devel@edk2.groups.io
> Subject: Re: [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0
> 
> On Fri, Aug 27, 2021 at 11:35:42AM +0000, Yao, Jiewen wrote:
> > I am sorry, I mess up https://github.com/tianocore/edk2/pull/1917, please
> ignore that.
> >
> > This pull request is re-created at https://github.com/tianocore/edk2/pull/1918.
> >
> > Please take a look at 1918.
> 
> Is there some way to run the CI before posting the patches?
> 
> I could probably create a dummy pull request for that and delete it when
> the CI is done.  That'll probably make gitlab send out a bunch of
> annoying notifications though ...
> 
> thanks,
>   Gerd
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0
  2021-08-27 13:42     ` Gerd Hoffmann
  2021-08-27 13:45       ` Yao, Jiewen
@ 2021-08-27 13:46       ` Ard Biesheuvel
  1 sibling, 0 replies; 15+ messages in thread
From: Ard Biesheuvel @ 2021-08-27 13:46 UTC (permalink / raw)
  To: edk2-devel-groups-io, Gerd Hoffmann; +Cc: Yao, Jiewen

On Fri, 27 Aug 2021 at 15:42, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> On Fri, Aug 27, 2021 at 11:35:42AM +0000, Yao, Jiewen wrote:
> > I am sorry, I mess up https://github.com/tianocore/edk2/pull/1917, please ignore that.
> >
> > This pull request is re-created at https://github.com/tianocore/edk2/pull/1918.
> >
> > Please take a look at 1918.
>
> Is there some way to run the CI before posting the patches?
>
> I could probably create a dummy pull request for that and delete it when
> the CI is done.  That'll probably make gitlab send out a bunch of
> annoying notifications though ...
>

FYI this is actually a supported and recommended way of doing things:
any user can send PRs and the CI will run on them. Only maintainers
can do so and set the 'pull' label, in which case the PR will get
merged if all CI checks pass.

>
>
>
> 
>
>

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-08-27 13:46 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-19  7:25 [PATCH v4 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
2021-08-19  7:25 ` [PATCH v4 1/7] OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines Gerd Hoffmann
2021-08-19  7:25 ` [PATCH v4 2/7] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection Gerd Hoffmann
2021-08-19  7:25 ` [PATCH v4 3/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize Gerd Hoffmann
2021-08-19  7:25 ` [PATCH v4 4/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress Gerd Hoffmann
2021-08-19  7:25 ` [PATCH v4 5/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum Gerd Hoffmann
2021-08-19  7:25 ` [PATCH v4 6/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling Gerd Hoffmann
2021-08-19  7:25 ` [PATCH v4 7/7] OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0 Gerd Hoffmann
2021-08-19  9:26 ` [edk2-devel] [PATCH v4 0/7] add support for virtio-mmio 1.0 Philippe Mathieu-Daudé
2021-08-20  7:20   ` Yao, Jiewen
2021-08-27 10:35 ` Yao, Jiewen
     [not found] ` <169F236B4CC08BB7.32747@groups.io>
2021-08-27 11:35   ` Yao, Jiewen
2021-08-27 13:42     ` Gerd Hoffmann
2021-08-27 13:45       ` Yao, Jiewen
2021-08-27 13:46       ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox