Skip to contentSkip to conversation

Add virtio-mmio support to m68k virt machine

PATCH Superseded Daniel Palmer 5 participants 22 messages Apr 13 – Apr 16

Subsystems (3)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add virtio-mmio support to m68k virt machine

Lets start making the m68k virt machine support useful.

First we need to fix some m68k endian issues.

Then allow virtio mmio driver instances to be created with platform data and fix a minor endian issue.

Finally, add the code for the board to create the instances.

v4:
- Small changes to "board: qemu: m68k: Create virtio mmio instances" requested by Simon.
- Add another patch to make the virtio cmd depend on CONFIG_VIRTIO_BLK as the build breaks if it isn't selected.

v3:
- Fix the bug with the vendor string in virtio-blk properly, this removes the last endian hack in virtio-mmio
- Leave the current behaviour for readl() for coldfire as it breaks thing.

v2:
- Added patch to fix readl() etc on m68k, hopefully this doesn't break everything. This should match Linux now.
- Added patch to fix sys reset which is broken by the above
- Hacks to virtio-mmio are gone because they aren't needed anymore, just one minor endian fix now.
- Removed RFC because it looks good to me*.

* I wouldn't trust me. :)

Daniel Palmer (6):
sysreset: qemu virt: Use __raw_writel()
m68k: Fix writew(), writel(), readw(), readl() endianness for classic

    m68k

virtio: mmio: Allow instantiation via platform data
virtio: cmd: Depend on VIRTIO_BLK
virtio: blk: Fix converting the vendor id to a string
board: qemu: m68k: Create virtio mmio instances

 arch/m68k/Kconfig                          | 14 ++++---
 arch/m68k/include/asm/io.h                 | 31 +++++++++------
 board/emulation/qemu-m68k/qemu-m68k.c      | 45 ++++++++++++++++++++++
 cmd/Kconfig                                |  4 +-
 drivers/sysreset/sysreset_qemu_virt_ctrl.c |  2 +-
 drivers/virtio/virtio_blk.c                | 11 ++----
 drivers/virtio/virtio_mmio.c               | 27 ++++++++-----
 include/virtio.h                           |  3 ++
 include/virtio_mmio.h                      | 12 ++++++
 9 files changed, 113 insertions(+), 36 deletions(-)
 create mode 100644 include/virtio_mmio.h
Signature · 1 line
2.51.0
#1 lore raw

PATCH v4 1/6 sysreset: qemu virt: Use __raw_writel()

The virt ctrl register seems to be native endian, currently this driver uses writel(), which works by luck because its currently broken on m68k.

Use __raw_writel() instead to avoid breaking this driver when the endianness of writel() is fixed.

---
 drivers/sysreset/sysreset_qemu_virt_ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/sysreset/sysreset_qemu_virt_ctrl.c +1 -1
index e7cacc9b6e98..5ab16001922b 100644
@@ -38,7 +38,7 @@ static int qemu_virt_ctrl_request(struct udevice *dev, enum sysreset_t type)
 		return -EPROTONOSUPPORT;
 	}
 
-	writel(val, plat->reg + VIRT_CTRL_REG_CMD);
+	__raw_writel(val, plat->reg + VIRT_CTRL_REG_CMD);
 
 	return -EINPROGRESS;
 }
Signature · 1 line
2.51.0
#2 lore raw

PATCH v4 2/6 m68k: Fix writew(), writel(), readw(), readl() endianness for classic m68k

In reply to Daniel Palmer

In Linux these are meant to read a little-endian value and swap to the CPU endian.

In u-boot for m68k this is currently broken and prevents virtio-mmio from functioning.

This change is only for classic m68k. Coldfire has read big-endian, no swap for these in u-boot and Linux and existing drivers probably depend on this.

---
 arch/m68k/include/asm/io.h | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
arch/m68k/include/asm/io.h +20 -11
index 35ad4a1c0444..2577081d8363 100644
@@ -23,18 +23,27 @@
 #define __raw_writew(w,addr) ((*(volatile u16 *) (addr)) = (w))
 #define __raw_writel(l,addr) ((*(volatile u32 *) (addr)) = (l))
 
-#define readb(addr)		in_8((volatile u8 *)(addr))
-#define writeb(b,addr)		out_8((volatile u8 *)(addr), (b))
-#if !defined(__BIG_ENDIAN)
-#define readw(addr)		(*(volatile u16 *) (addr))
-#define readl(addr)		(*(volatile u32 *) (addr))
-#define writew(b,addr)		((*(volatile u16 *) (addr)) = (b))
-#define writel(b,addr)		((*(volatile u32 *) (addr)) = (b))
+#define readb(addr)	in_8((volatile u8 *)(addr))
+#define writeb(b, addr)	out_8((volatile u8 *)(addr), (b))
+#ifdef CONFIG_M680x0
+/*
+ * For classic m68k these work the same way as Linux:
+ * Read a little endian value, swap to the CPU endian.
+ */
+#define readw(addr)	in_le16((volatile u16 *)(addr))
+#define readl(addr)	in_le32((volatile u32 *)(addr))
+#define writew(b, addr)	out_le16((volatile u16 *)(addr), (b))
+#define writel(b, addr)	out_le32((volatile u32 *)(addr), (b))
 #else
-#define readw(addr)		in_be16((volatile u16 *)(addr))
-#define readl(addr)		in_be32((volatile u32 *)(addr))
-#define writew(b,addr)		out_be16((volatile u16 *)(addr),(b))
-#define writel(b,addr)		out_be32((volatile u32 *)(addr),(b))
+/*
+ * For coldfire these read a big endian value and use it
+ * as-is. This means that for little endian devices on the
+ * bus like PCI device these won't work as expected currently.
+ */
+#define readw(addr)	in_be16((volatile u16 *)(addr))
+#define readl(addr)	in_be32((volatile u32 *)(addr))
+#define writew(b, addr)	out_be16((volatile u16 *)(addr), (b))
+#define writel(b, addr)	out_be32((volatile u32 *)(addr), (b))
 #endif
 
 /*
Signature · 1 line
2.51.0
Acked-by on v4 2/6
#3 lore raw

Re: [PATCH v4 2/6] m68k: Fix writew(), writel(), readw(), readl() endianness for classic m68k

Hi Daniel,

actually, i can build all m68k boards without errors, and have stmark2 up and running without any issue.

I will try to fix better this endian thing asap, thanks for the comment.

Quoted 50 lines · Daniel Palmer

In Linux these are meant to read a little-endian value and swap to the CPU endian.

In u-boot for m68k this is currently broken and prevents virtio-mmio from functioning.

This change is only for classic m68k. Coldfire has read big-endian, no swap for these in u-boot and Linux and existing drivers probably depend on this.

---
 arch/m68k/include/asm/io.h | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
arch/m68k/include/asm/io.h +13 -11
index 35ad4a1c0444..2577081d8363 100644
@@ -23,18 +23,27 @@
 #define __raw_writew(w,addr) ((*(volatile u16 *) (addr)) = (w))
 #define __raw_writel(l,addr) ((*(volatile u32 *) (addr)) = (l))
 
-#define readb(addr)		in_8((volatile u8 *)(addr))
-#define writeb(b,addr)		out_8((volatile u8 *)(addr), (b))
-#if !defined(__BIG_ENDIAN)
-#define readw(addr)		(*(volatile u16 *) (addr))
-#define readl(addr)		(*(volatile u32 *) (addr))
-#define writew(b,addr)		((*(volatile u16 *) (addr)) = (b))
-#define writel(b,addr)		((*(volatile u32 *) (addr)) = (b))
+#define readb(addr)	in_8((volatile u8 *)(addr))
+#define writeb(b, addr)	out_8((volatile u8 *)(addr), (b))
+#ifdef CONFIG_M680x0
+/*
+ * For classic m68k these work the same way as Linux:
+ * Read a little endian value, swap to the CPU endian.
+ */
+#define readw(addr)	in_le16((volatile u16 *)(addr))
+#define readl(addr)	in_le32((volatile u32 *)(addr))
+#define writew(b, addr)	out_le16((volatile u16 *)(addr), (b))
+#define writel(b, addr)	out_le32((volatile u32 *)(addr), (b))
 #else
-#define readw(addr)		in_be16((volatile u16 *)(addr))
-#define readl(addr)		in_be32((volatile u32 *)(addr))
-#define writew(b,addr)		out_be16((volatile u16 *)(addr),(b))
-#define writel(b,addr)		out_be32((volatile u32 *)(addr),(b))
+/*
+ * For coldfire these read a big endian value and use it

arch/m68k/include/asm/io.h line 49

Quoted 10 lines
arch/m68k/include/asm/io.h +7 -0
+ * as-is. This means that for little endian devices on the
+ * bus like PCI device these won't work as expected currently.
+ */
+#define readw(addr)	in_be16((volatile u16 *)(addr))
+#define readl(addr)	in_be32((volatile u32 *)(addr))
+#define writew(b, addr)	out_be16((volatile u16 *)(addr), (b))
+#define writel(b, addr)	out_be32((volatile u32 *)(addr), (b))
 #endif
 
 /*

-- Angelo

#4 lore raw

Re: [PATCH v4 2/6] m68k: Fix writew(), writel(), readw(), readl() endianness for classic m68k

Hi Angelo,

Quoted 7 lines · Angelo Dureghello

Hi Daniel,

actually, i can build all m68k boards without errors, and have stmark2 up and running without any issue.

I will try to fix better this endian thing asap, thanks for the comment.

A heads up: The linux versions of these might change for CF ->
https://lore.kernel.org/linux-m68k/[email protected]/T/#mdb1f285ce91df7e94f1c2a1fb3b137f3f8e21a79

Cheers,

Daniel

Acked-by on v4 2/6
#5 lore raw

Re: [PATCH v4 2/6] m68k: Fix writew(), writel(), readw(), readl() endianness for classic m68k

In reply to Daniel Palmer
Quoted 6 lines · Daniel Palmer

In Linux these are meant to read a little-endian value and swap to the CPU endian.

In u-boot for m68k this is currently broken and prevents virtio-mmio from functioning.

Quoted 7 lines

This change is only for classic m68k. Coldfire has read big-endian, no swap for these in u-boot and Linux and existing drivers probably depend on this.

Regards,
Kuan-Wei

Quoted 50 lines
---
 arch/m68k/include/asm/io.h | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
arch/m68k/include/asm/io.h +20 -11
index 35ad4a1c0444..2577081d8363 100644
@@ -23,18 +23,27 @@
 #define __raw_writew(w,addr) ((*(volatile u16 *) (addr)) = (w))
 #define __raw_writel(l,addr) ((*(volatile u32 *) (addr)) = (l))
 
-#define readb(addr)		in_8((volatile u8 *)(addr))
-#define writeb(b,addr)		out_8((volatile u8 *)(addr), (b))
-#if !defined(__BIG_ENDIAN)
-#define readw(addr)		(*(volatile u16 *) (addr))
-#define readl(addr)		(*(volatile u32 *) (addr))
-#define writew(b,addr)		((*(volatile u16 *) (addr)) = (b))
-#define writel(b,addr)		((*(volatile u32 *) (addr)) = (b))
+#define readb(addr)	in_8((volatile u8 *)(addr))
+#define writeb(b, addr)	out_8((volatile u8 *)(addr), (b))
+#ifdef CONFIG_M680x0
+/*
+ * For classic m68k these work the same way as Linux:
+ * Read a little endian value, swap to the CPU endian.
+ */
+#define readw(addr)	in_le16((volatile u16 *)(addr))
+#define readl(addr)	in_le32((volatile u32 *)(addr))
+#define writew(b, addr)	out_le16((volatile u16 *)(addr), (b))
+#define writel(b, addr)	out_le32((volatile u32 *)(addr), (b))
 #else
-#define readw(addr)		in_be16((volatile u16 *)(addr))
-#define readl(addr)		in_be32((volatile u32 *)(addr))
-#define writew(b,addr)		out_be16((volatile u16 *)(addr),(b))
-#define writel(b,addr)		out_be32((volatile u32 *)(addr),(b))
+/*
+ * For coldfire these read a big endian value and use it
+ * as-is. This means that for little endian devices on the
+ * bus like PCI device these won't work as expected currently.
+ */
+#define readw(addr)	in_be16((volatile u16 *)(addr))
+#define readl(addr)	in_be32((volatile u32 *)(addr))
+#define writew(b, addr)	out_be16((volatile u16 *)(addr), (b))
+#define writel(b, addr)	out_be32((volatile u32 *)(addr), (b))
 #endif
 
 /*
Signature · 1 line
2.51.0
#6 lore raw

PATCH v4 3/6 virtio: mmio: Allow instantiation via platform data

In reply to Daniel Palmer

The m68k QEMU virt machine doesn't use devicetree, yet, so allow it to create virtio-mmio instances via platform data.

---
 drivers/virtio/virtio_mmio.c | 27 ++++++++++++++++++---------
 include/virtio_mmio.h        | 12 ++++++++++++
 2 files changed, 30 insertions(+), 9 deletions(-)
 create mode 100644 include/virtio_mmio.h
drivers/virtio/virtio_mmio.c +18 -9
index 1cd737aca249..28b46ab66238 100644
@@ -12,6 +12,7 @@
 #include <virtio_types.h>
 #include <virtio.h>
 #include <virtio_ring.h>
+#include <virtio_mmio.h>
 #include <linux/bug.h>
 #include <linux/compat.h>
 #include <linux/err.h>
@@ -335,21 +336,28 @@ static int virtio_mmio_notify(struct udevice *udev, struct virtqueue *vq)
 
 static int virtio_mmio_of_to_plat(struct udevice *udev)
 {
-	struct virtio_mmio_priv *priv = dev_get_priv(udev);
+	struct virtio_mmio_plat *plat = dev_get_plat(udev);
+	fdt_addr_t addr;
+
+	addr = dev_read_addr(udev);
 
-	priv->base = (void __iomem *)(ulong)dev_read_addr(udev);
-	if (priv->base == (void __iomem *)FDT_ADDR_T_NONE)
+	if (addr == FDT_ADDR_T_NONE)
 		return -EINVAL;
 
+	plat->base = addr;
+
 	return 0;
 }
 
 static int virtio_mmio_probe(struct udevice *udev)
 {
+	struct virtio_mmio_plat *plat = dev_get_plat(udev);
 	struct virtio_mmio_priv *priv = dev_get_priv(udev);
 	struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(udev);
 	u32 magic;
 
+	priv->base = (void __iomem *)plat->base;
+
 	/* Check magic value */
 	magic = readl(priv->base + VIRTIO_MMIO_MAGIC_VALUE);
 	if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
@@ -405,11 +413,12 @@ static const struct udevice_id virtio_mmio_ids[] = {
 };
 
 U_BOOT_DRIVER(virtio_mmio) = {
-	.name	= "virtio-mmio",
-	.id	= UCLASS_VIRTIO,
-	.of_match = virtio_mmio_ids,
-	.ops	= &virtio_mmio_ops,
-	.probe	= virtio_mmio_probe,
+	.name       = "virtio-mmio",
+	.id         = UCLASS_VIRTIO,
+	.of_match   = virtio_mmio_ids,
+	.ops        = &virtio_mmio_ops,
+	.probe      = virtio_mmio_probe,
 	.of_to_plat = virtio_mmio_of_to_plat,
-	.priv_auto	= sizeof(struct virtio_mmio_priv),
+	.priv_auto  = sizeof(struct virtio_mmio_priv),
+	.plat_auto  = sizeof(struct virtio_mmio_plat),
 };
include/virtio_mmio.h new file +12 -0
new file mode 100644
index 000000000000..8c072826db55
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#ifndef __VIRTIO_MMIO_H__
+#define __VIRTIO_MMIO_H__
+
+#include <linux/types.h>
+
+struct virtio_mmio_plat {
+	phys_addr_t base;
+};
+
+#endif /* __VIRTIO_MMIO_H__ */
Signature · 1 line
2.51.0
Reviewed-by on v4 3/6
#7 lore raw

Re: [PATCH v4 3/6] virtio: mmio: Allow instantiation via platform data

Quoted 82 lines · Daniel Palmer

The m68k QEMU virt machine doesn't use devicetree, yet, so allow it to create virtio-mmio instances via platform data.

---
 drivers/virtio/virtio_mmio.c | 27 ++++++++++++++++++---------
 include/virtio_mmio.h        | 12 ++++++++++++
 2 files changed, 30 insertions(+), 9 deletions(-)
 create mode 100644 include/virtio_mmio.h
drivers/virtio/virtio_mmio.c +18 -9
index 1cd737aca249..28b46ab66238 100644
@@ -12,6 +12,7 @@
 #include <virtio_types.h>
 #include <virtio.h>
 #include <virtio_ring.h>
+#include <virtio_mmio.h>
 #include <linux/bug.h>
 #include <linux/compat.h>
 #include <linux/err.h>
@@ -335,21 +336,28 @@ static int virtio_mmio_notify(struct udevice *udev, struct virtqueue *vq)
 
 static int virtio_mmio_of_to_plat(struct udevice *udev)
 {
-	struct virtio_mmio_priv *priv = dev_get_priv(udev);
+	struct virtio_mmio_plat *plat = dev_get_plat(udev);
+	fdt_addr_t addr;
+
+	addr = dev_read_addr(udev);
 
-	priv->base = (void __iomem *)(ulong)dev_read_addr(udev);
-	if (priv->base == (void __iomem *)FDT_ADDR_T_NONE)
+	if (addr == FDT_ADDR_T_NONE)
 		return -EINVAL;
 
+	plat->base = addr;
+
 	return 0;
 }
 
 static int virtio_mmio_probe(struct udevice *udev)
 {
+	struct virtio_mmio_plat *plat = dev_get_plat(udev);
 	struct virtio_mmio_priv *priv = dev_get_priv(udev);
 	struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(udev);
 	u32 magic;
 
+	priv->base = (void __iomem *)plat->base;
+
 	/* Check magic value */
 	magic = readl(priv->base + VIRTIO_MMIO_MAGIC_VALUE);
 	if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
@@ -405,11 +413,12 @@ static const struct udevice_id virtio_mmio_ids[] = {
 };
 
 U_BOOT_DRIVER(virtio_mmio) = {
-	.name	= "virtio-mmio",
-	.id	= UCLASS_VIRTIO,
-	.of_match = virtio_mmio_ids,
-	.ops	= &virtio_mmio_ops,
-	.probe	= virtio_mmio_probe,
+	.name       = "virtio-mmio",
+	.id         = UCLASS_VIRTIO,
+	.of_match   = virtio_mmio_ids,
+	.ops        = &virtio_mmio_ops,
+	.probe      = virtio_mmio_probe,
 	.of_to_plat = virtio_mmio_of_to_plat,
-	.priv_auto	= sizeof(struct virtio_mmio_priv),
+	.priv_auto  = sizeof(struct virtio_mmio_priv),
+	.plat_auto  = sizeof(struct virtio_mmio_plat),
 };
include/virtio_mmio.h new file +2 -0
new file mode 100644
index 000000000000..8c072826db55
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+

include/virtio_mmio.h line 12

Quoted 10 lines
include/virtio_mmio.h new file +10 -0
+#ifndef __VIRTIO_MMIO_H__
+#define __VIRTIO_MMIO_H__
+
+#include <linux/types.h>
+
+struct virtio_mmio_plat {
+	phys_addr_t base;
+};
+
+#endif /* __VIRTIO_MMIO_H__ */

-- Angelo

Reviewed-by on v4 3/6
#8 lore raw

Re: [PATCH v4 3/6] virtio: mmio: Allow instantiation via platform data

In reply to Daniel Palmer
Quoted 5 lines · Daniel Palmer

The m68k QEMU virt machine doesn't use devicetree, yet, so allow it to create virtio-mmio instances via platform data.

Regards,
Kuan-Wei

Quoted 90 lines
---
 drivers/virtio/virtio_mmio.c | 27 ++++++++++++++++++---------
 include/virtio_mmio.h        | 12 ++++++++++++
 2 files changed, 30 insertions(+), 9 deletions(-)
 create mode 100644 include/virtio_mmio.h
drivers/virtio/virtio_mmio.c +18 -9
index 1cd737aca249..28b46ab66238 100644
@@ -12,6 +12,7 @@
 #include <virtio_types.h>
 #include <virtio.h>
 #include <virtio_ring.h>
+#include <virtio_mmio.h>
 #include <linux/bug.h>
 #include <linux/compat.h>
 #include <linux/err.h>
@@ -335,21 +336,28 @@ static int virtio_mmio_notify(struct udevice *udev, struct virtqueue *vq)
 
 static int virtio_mmio_of_to_plat(struct udevice *udev)
 {
-	struct virtio_mmio_priv *priv = dev_get_priv(udev);
+	struct virtio_mmio_plat *plat = dev_get_plat(udev);
+	fdt_addr_t addr;
+
+	addr = dev_read_addr(udev);
 
-	priv->base = (void __iomem *)(ulong)dev_read_addr(udev);
-	if (priv->base == (void __iomem *)FDT_ADDR_T_NONE)
+	if (addr == FDT_ADDR_T_NONE)
 		return -EINVAL;
 
+	plat->base = addr;
+
 	return 0;
 }
 
 static int virtio_mmio_probe(struct udevice *udev)
 {
+	struct virtio_mmio_plat *plat = dev_get_plat(udev);
 	struct virtio_mmio_priv *priv = dev_get_priv(udev);
 	struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(udev);
 	u32 magic;
 
+	priv->base = (void __iomem *)plat->base;
+
 	/* Check magic value */
 	magic = readl(priv->base + VIRTIO_MMIO_MAGIC_VALUE);
 	if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
@@ -405,11 +413,12 @@ static const struct udevice_id virtio_mmio_ids[] = {
 };
 
 U_BOOT_DRIVER(virtio_mmio) = {
-	.name	= "virtio-mmio",
-	.id	= UCLASS_VIRTIO,
-	.of_match = virtio_mmio_ids,
-	.ops	= &virtio_mmio_ops,
-	.probe	= virtio_mmio_probe,
+	.name       = "virtio-mmio",
+	.id         = UCLASS_VIRTIO,
+	.of_match   = virtio_mmio_ids,
+	.ops        = &virtio_mmio_ops,
+	.probe      = virtio_mmio_probe,
 	.of_to_plat = virtio_mmio_of_to_plat,
-	.priv_auto	= sizeof(struct virtio_mmio_priv),
+	.priv_auto  = sizeof(struct virtio_mmio_priv),
+	.plat_auto  = sizeof(struct virtio_mmio_plat),
 };
include/virtio_mmio.h new file +12 -0
new file mode 100644
index 000000000000..8c072826db55
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#ifndef __VIRTIO_MMIO_H__
+#define __VIRTIO_MMIO_H__
+
+#include <linux/types.h>
+
+struct virtio_mmio_plat {
+	phys_addr_t base;
+};
+
+#endif /* __VIRTIO_MMIO_H__ */
Signature · 1 line
2.51.0
#9 lore raw

PATCH v4 4/6 virtio: cmd: Depend on VIRTIO_BLK

In reply to Daniel Palmer

The virtio command is calling virtio blk functions but currently depends on CONFIG_VIRTIO only. This means disabling CONFIG_VIRTIO_BLK causes the final link to fail.

Since CONFIG_VIRTIO_BLK depends on CONFIG_VIRTIO switch to depending on just CONFIG_VIRTIO_BLK

---
 cmd/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
cmd/Kconfig +2 -2
index 7bbeaad04ff4..7c86164ddb20 100644
@@ -1863,8 +1863,8 @@ config CMD_PVBLOCK
 
 config CMD_VIRTIO
 	bool "virtio"
-	depends on VIRTIO
-	default y if VIRTIO
+	depends on VIRTIO_BLK
+	default y if VIRTIO_BLK
 	help
 	  VirtIO block device support
 
Signature · 1 line
2.51.0
Reviewed-by on v4 4/6
#10 lore raw

Re: [PATCH v4 4/6] virtio: cmd: Depend on VIRTIO_BLK

Quoted 6 lines · Daniel Palmer

virtio: cmd: Depend on VIRTIO_BLK

The virtio command is calling virtio blk functions but currently depends on CONFIG_VIRTIO only. This means disabling CONFIG_VIRTIO_BLK causes the final link to fail.

Quoted 7 lines

Since CONFIG_VIRTIO_BLK depends on CONFIG_VIRTIO switch to depending on just CONFIG_VIRTIO_BLK

cmd/Kconfig | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by on v4 4/6
#11 lore raw

Re: [PATCH v4 4/6] virtio: cmd: Depend on VIRTIO_BLK

In reply to Daniel Palmer
Quoted 8 lines · Daniel Palmer

The virtio command is calling virtio blk functions but currently depends on CONFIG_VIRTIO only. This means disabling CONFIG_VIRTIO_BLK causes the final link to fail.

Since CONFIG_VIRTIO_BLK depends on CONFIG_VIRTIO switch to depending on just CONFIG_VIRTIO_BLK

Signature · 1 line
Tom
Reviewed-by on v4 4/6
#12 lore raw

Re: [PATCH v4 4/6] virtio: cmd: Depend on VIRTIO_BLK

In reply to Daniel Palmer
Quoted 17 lines · Daniel Palmer

The virtio command is calling virtio blk functions but currently depends on CONFIG_VIRTIO only. This means disabling CONFIG_VIRTIO_BLK causes the final link to fail.

Since CONFIG_VIRTIO_BLK depends on CONFIG_VIRTIO switch to depending on just CONFIG_VIRTIO_BLK

---
 cmd/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
cmd/Kconfig +0 -0
index 7bbeaad04ff4..7c86164ddb20 100644

cmd/Kconfig config CMD_PVBLOCK · line 1870

Quoted 10 lines
cmd/Kconfig +2 -2
@@ -1863,8 +1863,8 @@ config CMD_PVBLOCK
 
 config CMD_VIRTIO
 	bool "virtio"
-	depends on VIRTIO
-	default y if VIRTIO
+	depends on VIRTIO_BLK
+	default y if VIRTIO_BLK
 	help
 	  VirtIO block device support
 

-- Angelo

Reviewed-by on v4 4/6
#13 lore raw

Re: [PATCH v4 4/6] virtio: cmd: Depend on VIRTIO_BLK

In reply to Daniel Palmer
Quoted 8 lines · Daniel Palmer

The virtio command is calling virtio blk functions but currently depends on CONFIG_VIRTIO only. This means disabling CONFIG_VIRTIO_BLK causes the final link to fail.

Since CONFIG_VIRTIO_BLK depends on CONFIG_VIRTIO switch to depending on just CONFIG_VIRTIO_BLK

Regards,
Kuan-Wei

Quoted 22 lines
---
 cmd/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
cmd/Kconfig +2 -2
index 7bbeaad04ff4..7c86164ddb20 100644
@@ -1863,8 +1863,8 @@ config CMD_PVBLOCK
 
 config CMD_VIRTIO
 	bool "virtio"
-	depends on VIRTIO
-	default y if VIRTIO
+	depends on VIRTIO_BLK
+	default y if VIRTIO_BLK
 	help
 	  VirtIO block device support
 
Signature · 1 line
2.51.0
#14 lore raw

PATCH v4 5/6 virtio: blk: Fix converting the vendor id to a string

In reply to Daniel Palmer

Currently we are trying to work out if the vendor id is from a virtio-mmio device and then casting a u32 to a char* and using it as a C-string. By chance there is usually a zero after the u32 and it works.

Since the vendor id we are trying to convert to a string is QEMU's just define a value for the QEMU vendor id, check if the vendor id matches and then use a predefined string for "QEMU".

I don't think we should have been assumming all virtio-mmio vendor ids are printable ASCII chars in the first place so do this special casing just for QEMU. If the vendor id isn't QEMU print the hex value of it.

---
 drivers/virtio/virtio_blk.c | 11 ++++-------
 include/virtio.h            |  3 +++
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/virtio/virtio_blk.c +4 -7
index 3dd0cf36268b..e70cf6a776b2 100644
@@ -164,14 +164,11 @@ static int virtio_blk_bind(struct udevice *dev)
 		return devnum;
 	desc->devnum = devnum;
 	desc->part_type = PART_TYPE_UNKNOWN;
-	/*
-	 * virtio mmio transport supplies string identification for us,
-	 * while pci trnasport uses a 2-byte subvendor value.
-	 */
-	if (uc_priv->vendor >> 16)
-		sprintf(desc->vendor, "%s", (char *)&uc_priv->vendor);
+
+	if (uc_priv->vendor == VIRTIO_VENDOR_QEMU)
+		strcpy(desc->vendor, "QEMU");
 	else
-		sprintf(desc->vendor, "%04x", uc_priv->vendor);
+		sprintf(desc->vendor, "%08x", uc_priv->vendor);
 	desc->bdev = dev;
 
 	/* Indicate what driver features we support */
include/virtio.h +3 -0
index 17f894a79e31..3edf023463d7 100644
@@ -25,6 +25,9 @@
 #include <linux/bitops.h>
 #include <linux/bug.h>
 #include <linux/typecheck.h>
+
+#define VIRTIO_VENDOR_QEMU	0x554d4551
+
 #define VIRTIO_ID_NET		1 /* virtio net */
 #define VIRTIO_ID_BLOCK		2 /* virtio block */
 #define VIRTIO_ID_RNG		4 /* virtio rng */
Signature · 1 line
2.51.0
Reviewed-by on v4 5/6
#15 lore raw

Re: [PATCH v4 5/6] virtio: blk: Fix converting the vendor id to a string

Quoted 9 lines · Daniel Palmer

Currently we are trying to work out if the vendor id is from a virtio-mmio device and then casting a u32 to a char* and using it as a C-string. By chance there is usually a zero after the u32 and it works.

Since the vendor id we are trying to convert to a string is QEMU's just define a value for the QEMU vendor id, check if the vendor id matches and then use a predefined string for "QEMU".

Quoted 7 lines

I don't think we should have been assumming all virtio-mmio vendor ids are printable ASCII chars in the first place so do this special casing just for QEMU. If the vendor id isn't QEMU print the hex value of it.

Regards,
Kuan-Wei

Quoted 45 lines
---
 drivers/virtio/virtio_blk.c | 11 ++++-------
 include/virtio.h            |  3 +++
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/virtio/virtio_blk.c +4 -7
index 3dd0cf36268b..e70cf6a776b2 100644
@@ -164,14 +164,11 @@ static int virtio_blk_bind(struct udevice *dev)
 		return devnum;
 	desc->devnum = devnum;
 	desc->part_type = PART_TYPE_UNKNOWN;
-	/*
-	 * virtio mmio transport supplies string identification for us,
-	 * while pci trnasport uses a 2-byte subvendor value.
-	 */
-	if (uc_priv->vendor >> 16)
-		sprintf(desc->vendor, "%s", (char *)&uc_priv->vendor);
+
+	if (uc_priv->vendor == VIRTIO_VENDOR_QEMU)
+		strcpy(desc->vendor, "QEMU");
 	else
-		sprintf(desc->vendor, "%04x", uc_priv->vendor);
+		sprintf(desc->vendor, "%08x", uc_priv->vendor);
 	desc->bdev = dev;
 
 	/* Indicate what driver features we support */
include/virtio.h +3 -0
index 17f894a79e31..3edf023463d7 100644
@@ -25,6 +25,9 @@
 #include <linux/bitops.h>
 #include <linux/bug.h>
 #include <linux/typecheck.h>
+
+#define VIRTIO_VENDOR_QEMU	0x554d4551
+
 #define VIRTIO_ID_NET		1 /* virtio net */
 #define VIRTIO_ID_BLOCK		2 /* virtio block */
 #define VIRTIO_ID_RNG		4 /* virtio rng */
Signature · 1 line
2.51.0
#16 lore raw

PATCH v4 6/6 board: qemu: m68k: Create virtio mmio instances

In reply to Daniel Palmer

So that you can use virtio network, block etc create the virtio mmio instances. There are 128 of these even if they are not all used, a single mmio base value is passed via bootinfo.

---
 arch/m68k/Kconfig                     | 14 +++++----
 board/emulation/qemu-m68k/qemu-m68k.c | 45 +++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 6 deletions(-)
arch/m68k/Kconfig +8 -6
index 6ce8f577e3a1..20a112880c87 100644
@@ -195,12 +195,14 @@ config TARGET_STMARK2
         select M54418
 
 config TARGET_QEMU_M68K
-    bool "Support QEMU m68k virt"
-    select M68040
-    imply CMD_DM
-    help
-      This target supports the QEMU m68k virtual machine (-M virt).
-      It simulates a Motorola 68040 CPU with Goldfish peripherals.
+	bool "Support QEMU m68k virt"
+	select M68040
+	select BOARD_EARLY_INIT_R
+	select VIRTIO_MMIO
+	imply CMD_DM
+	help
+	  This target supports the QEMU m68k virtual machine (-M virt).
+	  It simulates a Motorola 68040 CPU with Goldfish peripherals.
 
 endchoice
 
board/emulation/qemu-m68k/qemu-m68k.c +45 -0

72 lines not on this page · raw message

Signature · 1 line
2.51.0
Reviewed-by on v4 6/6
#17 lore raw

Re: [PATCH v4 6/6] board: qemu: m68k: Create virtio mmio instances

Hi Daniel,

Quoted 14 lines · Daniel Palmer

board: qemu: m68k: Create virtio mmio instances

So that you can use virtio network, block etc create the virtio mmio instances. There are 128 of these even if they are not all used, a single mmio base value is passed via bootinfo.

arch/m68k/Kconfig | 14 ++++++-----

 board/emulation/qemu-m68k/qemu-m68k.c | 45 +++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 6 deletions(-)

board/emulation/qemu-m68k/qemu-m68k.c line 46

Quoted 7 lines
board/emulation/qemu-m68k/qemu-m68k.c +7 -0
@@ -40,6 +40,38 @@
+static int create_virtio_mmios(void)
+{
+     struct driver *drv;
+     int i, ret;
+
+     if (!virtio_mmio_base)
+             return -ENODEV;
Reviewed-by on v4 6/6
#18 lore raw

Re: [PATCH v4 6/6] board: qemu: m68k: Create virtio mmio instances

In reply to Daniel Palmer
Quoted 105 lines · Daniel Palmer

So that you can use virtio network, block etc create the virtio mmio instances. There are 128 of these even if they are not all used, a single mmio base value is passed via bootinfo.

---
 arch/m68k/Kconfig                     | 14 +++++----
 board/emulation/qemu-m68k/qemu-m68k.c | 45 +++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 6 deletions(-)
arch/m68k/Kconfig +8 -6
index 6ce8f577e3a1..20a112880c87 100644
@@ -195,12 +195,14 @@ config TARGET_STMARK2
         select M54418
 
 config TARGET_QEMU_M68K
-    bool "Support QEMU m68k virt"
-    select M68040
-    imply CMD_DM
-    help
-      This target supports the QEMU m68k virtual machine (-M virt).
-      It simulates a Motorola 68040 CPU with Goldfish peripherals.
+	bool "Support QEMU m68k virt"
+	select M68040
+	select BOARD_EARLY_INIT_R
+	select VIRTIO_MMIO
+	imply CMD_DM
+	help
+	  This target supports the QEMU m68k virtual machine (-M virt).
+	  It simulates a Motorola 68040 CPU with Goldfish peripherals.
 
 endchoice
 
board/emulation/qemu-m68k/qemu-m68k.c +40 -0
index d3527aee1128..a19b23a28ce3 100644
@@ -14,9 +14,14 @@
 #include <asm/bootinfo.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+#include <dm/lists.h>
 #include <dm/platdata.h>
+#include <dm/root.h>
 #include <linux/errno.h>
 #include <linux/sizes.h>
+#include <virtio_mmio.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -25,6 +30,38 @@ static struct goldfish_rtc_plat rtc_plat;
 static struct goldfish_timer_plat timer_plat;
 static struct qemu_virt_ctrl_plat reset_plat;
 
+#define VIRTIO_MMIO_NUM	128
+#define VIRTIO_MMIO_SZ	0x200
+
+static struct virtio_mmio_plat virtio_mmio_plat[VIRTIO_MMIO_NUM];
+static char virtio_mmio_names[VIRTIO_MMIO_NUM][11];
+static phys_addr_t virtio_mmio_base;
+
+static int create_virtio_mmios(void)
+{
+	struct driver *drv;
+	int i, ret;
+
+	if (!virtio_mmio_base)
+		return -ENODEV;
+
+	drv = lists_driver_lookup_name("virtio-mmio");
+	if (!drv)
+		return -ENOENT;
+
+	for (i = 0; i < VIRTIO_MMIO_NUM; i++) {
+		virtio_mmio_plat[i].base = virtio_mmio_base + (VIRTIO_MMIO_SZ * i);
+		sprintf(virtio_mmio_names[i], "virtio-%d", i);
+
+		ret = device_bind(dm_root(), drv, virtio_mmio_names[i],
+				  &virtio_mmio_plat[i], ofnode_null(), NULL);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 /*
  * Theoretical limit derivation:
  * Max Bootinfo Size (Standard Page) = 4096 bytes
@@ -65,6 +102,9 @@ static void parse_bootinfo(void)
 		case BI_VIRT_CTRL_BASE:
 			reset_plat.reg = base;
 			break;
+		case BI_VIRT_VIRTIO_BASE:
+			virtio_mmio_base = base;
+			break;
 		case BI_MEMCHUNK:
 			gd->ram_size = record->data[1];
 			break;
@@ -80,6 +120,11 @@ int board_early_init_f(void)
 	return 0;

board/emulation/qemu-m68k/qemu-m68k.c int board_early_init_f(void) · line 130

Quoted 10 lines
board/emulation/qemu-m68k/qemu-m68k.c +5 -0
 }
 
+int board_early_init_r(void)
+{
+	return create_virtio_mmios();
+}
+
 int checkboard(void)
 {
 	puts("Board: QEMU m68k virt\n");

-- Angelo

Reviewed-by Tested-by on v4 6/6
#19 lore raw

Re: [PATCH v4 6/6] board: qemu: m68k: Create virtio mmio instances

In reply to Daniel Palmer
Quoted 5 lines · Daniel Palmer

So that you can use virtio network, block etc create the virtio mmio instances. There are 128 of these even if they are not all used, a single mmio base value is passed via bootinfo.

Regards,
Kuan-Wei

Quoted 113 lines
---
 arch/m68k/Kconfig                     | 14 +++++----
 board/emulation/qemu-m68k/qemu-m68k.c | 45 +++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 6 deletions(-)
arch/m68k/Kconfig +8 -6
index 6ce8f577e3a1..20a112880c87 100644
@@ -195,12 +195,14 @@ config TARGET_STMARK2
         select M54418
 
 config TARGET_QEMU_M68K
-    bool "Support QEMU m68k virt"
-    select M68040
-    imply CMD_DM
-    help
-      This target supports the QEMU m68k virtual machine (-M virt).
-      It simulates a Motorola 68040 CPU with Goldfish peripherals.
+	bool "Support QEMU m68k virt"
+	select M68040
+	select BOARD_EARLY_INIT_R
+	select VIRTIO_MMIO
+	imply CMD_DM
+	help
+	  This target supports the QEMU m68k virtual machine (-M virt).
+	  It simulates a Motorola 68040 CPU with Goldfish peripherals.
 
 endchoice
 
board/emulation/qemu-m68k/qemu-m68k.c +45 -0
index d3527aee1128..a19b23a28ce3 100644
@@ -14,9 +14,14 @@
 #include <asm/bootinfo.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+#include <dm/lists.h>
 #include <dm/platdata.h>
+#include <dm/root.h>
 #include <linux/errno.h>
 #include <linux/sizes.h>
+#include <virtio_mmio.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -25,6 +30,38 @@ static struct goldfish_rtc_plat rtc_plat;
 static struct goldfish_timer_plat timer_plat;
 static struct qemu_virt_ctrl_plat reset_plat;
 
+#define VIRTIO_MMIO_NUM	128
+#define VIRTIO_MMIO_SZ	0x200
+
+static struct virtio_mmio_plat virtio_mmio_plat[VIRTIO_MMIO_NUM];
+static char virtio_mmio_names[VIRTIO_MMIO_NUM][11];
+static phys_addr_t virtio_mmio_base;
+
+static int create_virtio_mmios(void)
+{
+	struct driver *drv;
+	int i, ret;
+
+	if (!virtio_mmio_base)
+		return -ENODEV;
+
+	drv = lists_driver_lookup_name("virtio-mmio");
+	if (!drv)
+		return -ENOENT;
+
+	for (i = 0; i < VIRTIO_MMIO_NUM; i++) {
+		virtio_mmio_plat[i].base = virtio_mmio_base + (VIRTIO_MMIO_SZ * i);
+		sprintf(virtio_mmio_names[i], "virtio-%d", i);
+
+		ret = device_bind(dm_root(), drv, virtio_mmio_names[i],
+				  &virtio_mmio_plat[i], ofnode_null(), NULL);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 /*
  * Theoretical limit derivation:
  * Max Bootinfo Size (Standard Page) = 4096 bytes
@@ -65,6 +102,9 @@ static void parse_bootinfo(void)
 		case BI_VIRT_CTRL_BASE:
 			reset_plat.reg = base;
 			break;
+		case BI_VIRT_VIRTIO_BASE:
+			virtio_mmio_base = base;
+			break;
 		case BI_MEMCHUNK:
 			gd->ram_size = record->data[1];
 			break;
@@ -80,6 +120,11 @@ int board_early_init_f(void)
 	return 0;
 }
 
+int board_early_init_r(void)
+{
+	return create_virtio_mmios();
+}
+
 int checkboard(void)
 {
 	puts("Board: QEMU m68k virt\n");
Signature · 1 line
2.51.0
#20 lore raw
In reply to Daniel Palmer

Hi Daniel,

Quoted 9 lines · Daniel Palmer

Lets start making the m68k virt machine support useful.

First we need to fix some m68k endian issues.

Then allow virtio mmio driver instances to be created with platform data and fix a minor endian issue.

Finally, add the code for the board to create the instances.

While testing and playing around with it on the qemu m68k virt machine, I noticed that the date and sleep commands are broken after applying these changes.

We will need the following two fixes to address this issue by using __raw_readl and __raw_writel in goldfish_rtc/timer driver.

Could you please include them in your patchset, placing them before the io macro changes?

From ffe017353f91e2a068f3a900e815cc11f388163c Mon Sep 17 00:00:00 2001
From: Kuan-Wei Chiu <[email protected]>
Date: Thu, 16 Apr 2026 06:45:09 +0000
Subject: [PATCH 1/2] rtc: goldfish: Use __raw_readl() and __raw_writel()

In QEMU, the Goldfish RTC is explicitly instantiated as a big-endian device on the m68k virt machine (via the 'big-endian=true' property). Currently, this driver uses ioread32() and iowrite32(), which works by luck because the underlying readl() and writel() are currently broken on m68k.

Use __raw_readl() and __raw_writel() instead to avoid breaking this driver when the endianness of readl() and writel() is fixed.

---
 drivers/rtc/goldfish_rtc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/rtc/goldfish_rtc.c +4 -4
index d2991ca6719..4892a63f8d8 100644
@@ -40,8 +40,8 @@ static int goldfish_rtc_get(struct udevice *dev, struct rtc_time *time)
 	u64 time_low;
 	u64 now;
 
-	time_low = ioread32(base + GOLDFISH_TIME_LOW);
-	time_high = ioread32(base + GOLDFISH_TIME_HIGH);
+	time_low = __raw_readl(base + GOLDFISH_TIME_LOW);
+	time_high = __raw_readl(base + GOLDFISH_TIME_HIGH);
 	now = (time_high << 32) | time_low;
 
 	do_div(now, 1000000000U);
@@ -62,8 +62,8 @@ static int goldfish_rtc_set(struct udevice *dev, const struct rtc_time *time)
 		return -EINVAL;
 
 	now = rtc_mktime(time) * 1000000000ULL;
-	iowrite32(now >> 32, base + GOLDFISH_TIME_HIGH);
-	iowrite32(now, base + GOLDFISH_TIME_LOW);
+	__raw_writel(now >> 32, base + GOLDFISH_TIME_HIGH);
+	__raw_writel(now, base + GOLDFISH_TIME_LOW);
 
 	if (time->tm_isdst > 0)
 		priv->isdst = 1;

--
2.54.0.rc1.513.gad8abe7a5a-goog

From 42f0b7a003be36c633cfcf37a90ebdb28e1b377e Mon Sep 17 00:00:00 2001
From: Kuan-Wei Chiu <[email protected]>
Date: Thu, 16 Apr 2026 06:45:42 +0000
Subject: [PATCH 2/2] timer: goldfish: Use __raw_readl()

The Goldfish timer registers are native endian, so they act as big-endian on the m68k virt machine. Currently, this driver uses readl(), which works by luck because it's currently broken on m68k.

Use __raw_readl() instead to avoid breaking this driver when the endianness of readl() is fixed.

---
 drivers/timer/goldfish_timer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/timer/goldfish_timer.c +2 -2
index 70673bbd93c..91277d7932a 100644
@@ -31,8 +31,8 @@ static u64 goldfish_timer_get_count(struct udevice *dev)
 	 * We must read LOW before HIGH to latch the high 32-bit value
 	 * and ensure a consistent 64-bit timestamp.
 	 */
-	low = readl(priv->base + TIMER_TIME_LOW);
-	high = readl(priv->base + TIMER_TIME_HIGH);
+	low = __raw_readl(priv->base + TIMER_TIME_LOW);
+	high = __raw_readl(priv->base + TIMER_TIME_HIGH);
 
 	time = ((u64)high << 32) | low;
 

--
2.54.0.rc1.513.gad8abe7a5a-goog

#21 lore raw

Hi Kuan-Wei,

Quoted 3 lines · Kuan-Wei Chiu

While testing and playing around with it on the qemu m68k virt machine, I noticed that the date and sleep commands are broken after applying these changes.

Thanks for testing. I'll put your changes into v5. I think we are pretty close now.