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

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.
v5 changes:
 - Added review tags.
 - Fixed 32bit arm build failure.

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] 13+ messages in thread

* [PATCH v5 1/7] OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines
  2021-08-27 13:44 [PATCH v5 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
@ 2021-08-27 13:44 ` Gerd Hoffmann
  2021-08-27 13:44 ` [PATCH v5 2/7] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection Gerd Hoffmann
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2021-08-27 13:44 UTC (permalink / raw)
  To: devel
  Cc: Jiewen Yao, Gerd Hoffmann, Ard Biesheuvel, Jordan Justen,
	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] 13+ messages in thread

* [PATCH v5 2/7] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection.
  2021-08-27 13:44 [PATCH v5 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
  2021-08-27 13:44 ` [PATCH v5 1/7] OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines Gerd Hoffmann
@ 2021-08-27 13:44 ` Gerd Hoffmann
  2021-08-27 13:44 ` [PATCH v5 3/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize Gerd Hoffmann
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2021-08-27 13:44 UTC (permalink / raw)
  To: devel
  Cc: Jiewen Yao, Gerd Hoffmann, Ard Biesheuvel, Jordan Justen,
	Philippe Mathieu-Daude

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>
Reviewed-by: Philippe Mathieu-Daude <philmd@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] 13+ messages in thread

* [PATCH v5 3/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize.
  2021-08-27 13:44 [PATCH v5 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
  2021-08-27 13:44 ` [PATCH v5 1/7] OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines Gerd Hoffmann
  2021-08-27 13:44 ` [PATCH v5 2/7] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection Gerd Hoffmann
@ 2021-08-27 13:44 ` Gerd Hoffmann
  2021-08-27 13:44 ` [PATCH v5 4/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress Gerd Hoffmann
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2021-08-27 13:44 UTC (permalink / raw)
  To: devel
  Cc: Jiewen Yao, Gerd Hoffmann, Ard Biesheuvel, Jordan Justen,
	Philippe Mathieu-Daude

Nothing to do here for virtio 1.0 devices.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@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] 13+ messages in thread

* [PATCH v5 4/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress
  2021-08-27 13:44 [PATCH v5 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2021-08-27 13:44 ` [PATCH v5 3/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize Gerd Hoffmann
@ 2021-08-27 13:44 ` Gerd Hoffmann
  2021-08-27 13:44 ` [PATCH v5 5/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum Gerd Hoffmann
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2021-08-27 13:44 UTC (permalink / raw)
  To: devel
  Cc: Jiewen Yao, Gerd Hoffmann, Ard Biesheuvel, Jordan Justen,
	Philippe Mathieu-Daude

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>
Reviewed-by: Philippe Mathieu-Daude <philmd@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..cb1f9358eabd 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 = (UINTN)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 = (UINTN)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 = (UINTN)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] 13+ messages in thread

* [PATCH v5 5/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum
  2021-08-27 13:44 [PATCH v5 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2021-08-27 13:44 ` [PATCH v5 4/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress Gerd Hoffmann
@ 2021-08-27 13:44 ` Gerd Hoffmann
  2021-08-27 13:44 ` [PATCH v5 6/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling Gerd Hoffmann
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2021-08-27 13:44 UTC (permalink / raw)
  To: devel
  Cc: Jiewen Yao, Gerd Hoffmann, Ard Biesheuvel, Jordan Justen,
	Philippe Mathieu-Daude

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

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@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 cb1f9358eabd..436da2a2b497 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 = (UINTN)Ring->Base;
     VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_DESC_LO,
                       (UINT32)Address);
-- 
2.31.1


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

* [PATCH v5 6/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling
  2021-08-27 13:44 [PATCH v5 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (4 preceding siblings ...)
  2021-08-27 13:44 ` [PATCH v5 5/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum Gerd Hoffmann
@ 2021-08-27 13:44 ` Gerd Hoffmann
  2021-08-27 13:44 ` [PATCH v5 7/7] OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0 Gerd Hoffmann
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2021-08-27 13:44 UTC (permalink / raw)
  To: devel
  Cc: Jiewen Yao, Gerd Hoffmann, Ard Biesheuvel, Jordan Justen,
	Philippe Mathieu-Daude

virtio 1.0 has 64 feature bits instead of 32.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@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 436da2a2b497..b43850e69da9 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] 13+ messages in thread

* [PATCH v5 7/7] OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0
  2021-08-27 13:44 [PATCH v5 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (5 preceding siblings ...)
  2021-08-27 13:44 ` [PATCH v5 6/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling Gerd Hoffmann
@ 2021-08-27 13:44 ` Gerd Hoffmann
  2021-08-28  1:49 ` [PATCH v5 0/7] add support for virtio-mmio 1.0 Yao, Jiewen
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2021-08-27 13:44 UTC (permalink / raw)
  To: devel
  Cc: Jiewen Yao, Gerd Hoffmann, Ard Biesheuvel, Jordan Justen,
	Philippe Mathieu-Daude

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

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@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] 13+ messages in thread

* Re: [PATCH v5 0/7] add support for virtio-mmio 1.0
  2021-08-27 13:44 [PATCH v5 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (6 preceding siblings ...)
  2021-08-27 13:44 ` [PATCH v5 7/7] OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0 Gerd Hoffmann
@ 2021-08-28  1:49 ` Yao, Jiewen
  2021-08-30  1:20 ` Yao, Jiewen
  2021-08-30  1:21 ` Yao, Jiewen
  9 siblings, 0 replies; 13+ messages in thread
From: Yao, Jiewen @ 2021-08-28  1:49 UTC (permalink / raw)
  To: Gerd Hoffmann, devel@edk2.groups.io; +Cc: Ard Biesheuvel, Justen, Jordan L

Hi Gerd
Have you run CI and ensure this patch series can pass CI ?

> -----Original Message-----
> From: Gerd Hoffmann <kraxel@redhat.com>
> Sent: Friday, August 27, 2021 9:45 PM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen <jiewen.yao@intel.com>; Gerd Hoffmann
> <kraxel@redhat.com>; Ard Biesheuvel <ardb+tianocore@kernel.org>; Justen,
> Jordan L <jordan.l.justen@intel.com>
> Subject: [PATCH v5 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.
> v5 changes:
>  - Added review tags.
>  - Fixed 32bit arm build failure.
> 
> 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] 13+ messages in thread

* Re: [PATCH v5 0/7] add support for virtio-mmio 1.0
  2021-08-27 13:44 [PATCH v5 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (7 preceding siblings ...)
  2021-08-28  1:49 ` [PATCH v5 0/7] add support for virtio-mmio 1.0 Yao, Jiewen
@ 2021-08-30  1:20 ` Yao, Jiewen
  2021-08-30  1:21 ` Yao, Jiewen
  9 siblings, 0 replies; 13+ messages in thread
From: Yao, Jiewen @ 2021-08-30  1:20 UTC (permalink / raw)
  To: Gerd Hoffmann, devel@edk2.groups.io; +Cc: Ard Biesheuvel, Justen, Jordan L

Series: reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>

> -----Original Message-----
> From: Gerd Hoffmann <kraxel@redhat.com>
> Sent: Friday, August 27, 2021 9:45 PM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen <jiewen.yao@intel.com>; Gerd Hoffmann
> <kraxel@redhat.com>; Ard Biesheuvel <ardb+tianocore@kernel.org>; Justen,
> Jordan L <jordan.l.justen@intel.com>
> Subject: [PATCH v5 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.
> v5 changes:
>  - Added review tags.
>  - Fixed 32bit arm build failure.
> 
> 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] 13+ messages in thread

* Re: [PATCH v5 0/7] add support for virtio-mmio 1.0
  2021-08-27 13:44 [PATCH v5 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
                   ` (8 preceding siblings ...)
  2021-08-30  1:20 ` Yao, Jiewen
@ 2021-08-30  1:21 ` Yao, Jiewen
  2021-08-30  3:17   ` 回复: [edk2-devel] " gaoliming
  9 siblings, 1 reply; 13+ messages in thread
From: Yao, Jiewen @ 2021-08-30  1:21 UTC (permalink / raw)
  To: Gerd Hoffmann, devel@edk2.groups.io; +Cc: Ard Biesheuvel, Justen, Jordan L

Pushed 94e465e5cbb65c47d9e98f5c4c61f3a5e008ee5d..77d5fa80246e8784f89e109ff9dadfeb7089ff85

PR: https://github.com/tianocore/edk2/pull/1926

> -----Original Message-----
> From: Gerd Hoffmann <kraxel@redhat.com>
> Sent: Friday, August 27, 2021 9:45 PM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen <jiewen.yao@intel.com>; Gerd Hoffmann
> <kraxel@redhat.com>; Ard Biesheuvel <ardb+tianocore@kernel.org>; Justen,
> Jordan L <jordan.l.justen@intel.com>
> Subject: [PATCH v5 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.
> v5 changes:
>  - Added review tags.
>  - Fixed 32bit arm build failure.
> 
> 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] 13+ messages in thread

* 回复: [edk2-devel] [PATCH v5 0/7] add support for virtio-mmio 1.0
  2021-08-30  1:21 ` Yao, Jiewen
@ 2021-08-30  3:17   ` gaoliming
  2021-08-30  7:54     ` Gerd Hoffmann
  0 siblings, 1 reply; 13+ messages in thread
From: gaoliming @ 2021-08-30  3:17 UTC (permalink / raw)
  To: devel, jiewen.yao, 'Gerd Hoffmann'
  Cc: 'Ard Biesheuvel', 'Justen, Jordan L'

Gerd:
  This is a new feature. Can you submit BZ (https://bugzilla.tianocore.org/ ) for it? Then, I can add it to edk2 feature list. 

Thanks
Liming
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Yao, Jiewen
> 发送时间: 2021年8月30日 9:22
> 收件人: Gerd Hoffmann <kraxel@redhat.com>; devel@edk2.groups.io
> 抄送: Ard Biesheuvel <ardb+tianocore@kernel.org>; Justen, Jordan L
> <jordan.l.justen@intel.com>
> 主题: Re: [edk2-devel] [PATCH v5 0/7] add support for virtio-mmio 1.0
> 
> Pushed
> 94e465e5cbb65c47d9e98f5c4c61f3a5e008ee5d..77d5fa80246e8784f89e109
> ff9dadfeb7089ff85
> 
> PR: https://github.com/tianocore/edk2/pull/1926
> 
> > -----Original Message-----
> > From: Gerd Hoffmann <kraxel@redhat.com>
> > Sent: Friday, August 27, 2021 9:45 PM
> > To: devel@edk2.groups.io
> > Cc: Yao, Jiewen <jiewen.yao@intel.com>; Gerd Hoffmann
> > <kraxel@redhat.com>; Ard Biesheuvel <ardb+tianocore@kernel.org>;
> Justen,
> > Jordan L <jordan.l.justen@intel.com>
> > Subject: [PATCH v5 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.
> > v5 changes:
> >  - Added review tags.
> >  - Fixed 32bit arm build failure.
> >
> > 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] 13+ messages in thread

* Re: 回复: [edk2-devel] [PATCH v5 0/7] add support for virtio-mmio 1.0
  2021-08-30  3:17   ` 回复: [edk2-devel] " gaoliming
@ 2021-08-30  7:54     ` Gerd Hoffmann
  0 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2021-08-30  7:54 UTC (permalink / raw)
  To: devel, gaoliming
  Cc: jiewen.yao, 'Ard Biesheuvel', 'Justen, Jordan L'

On Mon, Aug 30, 2021 at 11:17:21AM +0800, gaoliming wrote:

> This is a new feature. Can you submit BZ (https://bugzilla.tianocore.org/ ) for it? Then, I can add it to edk2 feature list. 

https://bugzilla.tianocore.org/show_bug.cgi?id=3597

take care,
  Gerd


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

end of thread, other threads:[~2021-08-30  7:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-27 13:44 [PATCH v5 0/7] add support for virtio-mmio 1.0 Gerd Hoffmann
2021-08-27 13:44 ` [PATCH v5 1/7] OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines Gerd Hoffmann
2021-08-27 13:44 ` [PATCH v5 2/7] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 detection Gerd Hoffmann
2021-08-27 13:44 ` [PATCH v5 3/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetPageSize Gerd Hoffmann
2021-08-27 13:44 ` [PATCH v5 4/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress Gerd Hoffmann
2021-08-27 13:44 ` [PATCH v5 5/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Add default QueueNum Gerd Hoffmann
2021-08-27 13:44 ` [PATCH v5 6/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling Gerd Hoffmann
2021-08-27 13:44 ` [PATCH v5 7/7] OvmfPkg/VirtioMmioDeviceLib: enable virtio 1.0 Gerd Hoffmann
2021-08-28  1:49 ` [PATCH v5 0/7] add support for virtio-mmio 1.0 Yao, Jiewen
2021-08-30  1:20 ` Yao, Jiewen
2021-08-30  1:21 ` Yao, Jiewen
2021-08-30  3:17   ` 回复: [edk2-devel] " gaoliming
2021-08-30  7:54     ` Gerd Hoffmann

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