virtio: Implement Virtio Backend for SD/MMC in QEMU
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]/
---
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Quoted 7 lines · Mikhail Krasheninnikov
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]/
Is there a corresponding patch to the VirtIO specification?
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
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 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
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.
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
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
MSTQuoted 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!