Skip to contentSkip to conversation

virtio: Implement Virtio Backend for SD/MMC in QEMU

PATCH Superseded Mikhail Krasheninnikov 3 participants 7 messages Jul 3, 2024 – Jul 4, 2024 Arm/Amlogic Meson SoC support

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 virtio: Implement Virtio Backend for SD/MMC in QEMU

From: Mi <[email protected]>

Add a Virtio backend for SD/MMC devices. Confirmed interoperability with Linux.

Linux patch link: https://lore.kernel.org/linux-mmc/[email protected]/

CC Matwey Kornilov <[email protected]>
CC Michael S. Tsirkin <[email protected]>
CC Kevin Wolf <[email protected]>
CC Stefan Hajnoczi <[email protected]>

---

Thanks for the feedback!

Changes from v2:
- Renamed virtio-mmc to virtio-sdhci
- Added a link to linux patch with corresponding driver in commit message
- Moved variable declaration to function prologue
- Removed duplicate defines
- Changed #pragma once

Michael, I couldn't find any simular structs to those in virtio-sdhci.c in Linux uapi, I'll be very grateful if you could point them out to me!

 hw/block/Kconfig                            |   6 +
 hw/block/meson.build                        |   1 +
 hw/block/virtio-sdhci.c                     | 169 ++++++++++++++++++++
 hw/virtio/meson.build                       |   1 +
 hw/virtio/virtio-sdhci-pci.c                |  86 ++++++++++
 hw/virtio/virtio.c                          |   3 +-
 include/hw/virtio/virtio-sdhci.h            |  22 +++
 include/standard-headers/linux/virtio_ids.h |   1 +
 8 files changed, 288 insertions(+), 1 deletion(-)
 create mode 100644 hw/block/virtio-sdhci.c
 create mode 100644 hw/virtio/virtio-sdhci-pci.c
 create mode 100644 include/hw/virtio/virtio-sdhci.h
hw/block/Kconfig +6 -0
index 9e8f28f982..5b5363da01 100644
@@ -44,3 +44,9 @@ config VHOST_USER_BLK
 
 config SWIM
     bool
+
+config VIRTIO_SDHCI
+    bool
+    default y
+    select SD
+    depends on VIRTIO
hw/block/meson.build +1 -0
index 8aa4dc3893..82356c264e 100644
@@ -19,5 +19,6 @@ system_ss.add(when: 'CONFIG_TC58128', if_true: files('tc58128.c'))
 
 specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c', 'virtio-blk-common.c'))
 specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk.c', 'virtio-blk-common.c'))
+specific_ss.add(when: 'CONFIG_VIRTIO_SDHCI', if_true: files('virtio-sdhci.c'))
 
 subdir('dataplane')
hw/block/virtio-sdhci.c new file +169 -0

169 lines not on this page · raw message

hw/virtio/meson.build +1 -0
index 47baf00366..c7a8707ba6 100644
@@ -68,6 +68,7 @@ virtio_pci_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu-pci.
 virtio_pci_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VIRTIO_MD', if_true: files('virtio-md-pci.c'))
+virtio_pci_ss.add(when: 'CONFIG_VIRTIO_SDHCI', if_true: files('virtio-sdhci-pci.c'))
 
 specific_virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss)
 
hw/virtio/virtio-sdhci-pci.c new file +86 -0

86 lines not on this page · raw message

hw/virtio/virtio.c +2 -1
index 7549094154..90a346dfc0 100644
@@ -193,7 +193,8 @@ const char *virtio_device_names[] = {
     [VIRTIO_ID_PARAM_SERV] = "virtio-param-serv",
     [VIRTIO_ID_AUDIO_POLICY] = "virtio-audio-pol",
     [VIRTIO_ID_BT] = "virtio-bluetooth",
-    [VIRTIO_ID_GPIO] = "virtio-gpio"
+    [VIRTIO_ID_GPIO] = "virtio-gpio",
+    [VIRTIO_ID_SDHCI] = "virtio-sdhci",
 };
 
 static const char *virtio_id_to_name(uint16_t device_id)
include/hw/virtio/virtio-sdhci.h new file +22 -0
new file mode 100644
index 0000000000..0d91f4a973
@@ -0,0 +1,22 @@
+#ifndef QEMU_VIRTIO_SDHCI_H
+#define QEMU_VIRTIO_SDHCI_H
+
+#include "hw/virtio/virtio.h"
+#include "hw/sd/sd.h"
+#include "qemu/typedefs.h"
+
+#define TYPE_VIRTIO_SDHCI "virtio-sdhci-device"
+#define VIRTIO_SDHCI(obj) \
+    OBJECT_CHECK(VirtIOSDHCI, (obj), TYPE_VIRTIO_SDHCI)
+#define VIRTIO_SDHCI_GET_PARENT_CLASS(obj) \
+    OBJECT_GET_PARENT_CLASS(VIRTIO_SDHCI(obj), TYPE_VIRTIO_SDHCI)
+
+typedef struct VirtIOSDHCI {
+    VirtIODevice parent_obj;
+
+    VirtQueue *vq;
+    SDBus sdbus;
+    BlockBackend *blk;
+} VirtIOSDHCI;
+
+#endif
include/standard-headers/linux/virtio_ids.h +1 -0
index 7aa2eb7662..7f13999359 100644
@@ -68,6 +68,7 @@
 #define VIRTIO_ID_AUDIO_POLICY		39 /* virtio audio policy */
 #define VIRTIO_ID_BT			40 /* virtio bluetooth */
 #define VIRTIO_ID_GPIO			41 /* virtio gpio */
+#define VIRTIO_ID_SDHCI			42 /* virtio sdhci */
 
 /*
  * Virtio Transitional IDs
Signature · 1 line
2.34.1
#2 lore raw

Hello, Alex!

No, there's no patch to the VirtIO specification yet. This is proof-of-concept solution since I'm not sure that I did everything correct with the design (and as folks' reviews show, for a good reason). As soon as most obvious issues would be out of the way, I think I'll submit a patch.

#3 lore raw
Quoted 8 lines · Mikhail Krasheninnikov

Hello, Alex!

No, there's no patch to the VirtIO specification yet. This is proof-of-concept solution since I'm not sure that I did everything correct with the design (and as folks' reviews show, for a good reason). As soon as most obvious issues would be out of the way, I think I'll submit a patch.

Mikhail, if you want people to review your patches but not merge them yet, pls use an RFC tag in the subject to avoid confusion.

Thanks,

Signature · 1 line
MST
#4 lore raw
Quoted 11 lines · Michael S. Tsirkin
Quoted 8 lines · Mikhail Krasheninnikov

Hello, Alex!

No, there's no patch to the VirtIO specification yet. This is proof-of-concept solution since I'm not sure that I did everything correct with the design (and as folks' reviews show, for a good reason). As soon as most obvious issues would be out of the way, I think I'll submit a patch.

Quoted 9 lines

Mikhail, if you want people to review your patches but not merge them yet, pls use an RFC tag in the subject to avoid confusion.

Thanks,

Signature · 1 line
MST

Hello, Michael!

I was planning to submit three patches: to the kernel, emulator and Virtio specification around the same time - as soon as the obvious bugs are fixed, I'll submit a patch to the specification. I thought it wasn't necessary to use the RFC tag in that case, but if you think it is, I'll include it with the next version of the patch.

#5 lore raw
Quoted 24 lines · Mikhail Krasheninnikov
Quoted 11 lines · Michael S. Tsirkin
Quoted 8 lines · Mikhail Krasheninnikov

Hello, Alex!

No, there's no patch to the VirtIO specification yet. This is proof-of-concept solution since I'm not sure that I did everything correct with the design (and as folks' reviews show, for a good reason). As soon as most obvious issues would be out of the way, I think I'll submit a patch.

Quoted 9 lines

Mikhail, if you want people to review your patches but not merge them yet, pls use an RFC tag in the subject to avoid confusion.

Thanks,

Signature · 1 line
MST
Quoted 7 lines

Hello, Michael!

I was planning to submit three patches: to the kernel, emulator and Virtio specification around the same time - as soon as the obvious bugs are fixed, I'll submit a patch to the specification. I thought it wasn't necessary to use the RFC tag in that case, but if you think it is, I'll include it with the next version of the patch.

RFC means "this is proof of concept". On the one hand some people won't bother reviewing then. On the other your patch will be judged less harshly. If your code still has debugging printks, it's clearly an RFC at best.

Signature · 1 line
MST
author
#6 lore raw
Quoted 36 lines

4 июля 2024 г., в 10:38, Michael S. Tsirkin <[email protected]> написал(а):

Quoted 24 lines · Mikhail Krasheninnikov
Quoted 11 lines · Michael S. Tsirkin
Quoted 8 lines · Mikhail Krasheninnikov

Hello, Alex!

No, there's no patch to the VirtIO specification yet. This is proof-of-concept solution since I'm not sure that I did everything correct with the design (and as folks' reviews show, for a good reason). As soon as most obvious issues would be out of the way, I think I'll submit a patch.

Quoted 9 lines

Mikhail, if you want people to review your patches but not merge them yet, pls use an RFC tag in the subject to avoid confusion.

Thanks,

Signature · 1 line
MST
Quoted 7 lines

Hello, Michael!

I was planning to submit three patches: to the kernel, emulator and Virtio specification around the same time - as soon as the obvious bugs are fixed, I'll submit a patch to the specification. I thought it wasn't necessary to use the RFC tag in that case, but if you think it is, I'll include it with the next version of the patch.

Quoted 8 lines

RFC means "this is proof of concept". On the one hand some people won't bother reviewing then. On the other your patch will be judged less harshly. If your code still has debugging printks, it's clearly an RFC at best.

Signature · 1 line
MST

I apologize for the debug printks in other patch, I’m not really sure how I gazed over it.. If it makes my situation better, it’s my first series of patches. I’ll make sure to triple-check next time. Thanks for the feedback!