Skip to contentSkip to conversation

Add virtio-mmio support to m68k virt machine

PATCH Superseded Daniel Palmer 3 participants 20 messages Apr 6 – Apr 8

Subsystems (2)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 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.

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' trust me. :)

Daniel Palmer (5):
sysreset: qemu virt: Use __raw_writel()
m68k: Fix writew(), writel(), readw(), readl() endianness
virtio: mmio: Keep vendor id little endian
virtio: mmio: Allow instantiation via platform data
board: qemu: m68k: Create virtio mmio instances

 arch/m68k/Kconfig                          | 14 ++++---
 arch/m68k/include/asm/io.h                 | 17 +++-----
 board/emulation/qemu-m68k/qemu-m68k.c      | 47 ++++++++++++++++++++++
 drivers/sysreset/sysreset_qemu_virt_ctrl.c |  2 +-
 drivers/virtio/virtio_mmio.c               | 29 ++++++++-----
 include/virtio_mmio.h                      | 12 ++++++
 6 files changed, 92 insertions(+), 29 deletions(-)
 create mode 100644 include/virtio_mmio.h
Signature · 1 line
2.51.0
#1 lore raw

PATCH v2 1/5 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
Acked-by on v2 1/5
#2 lore raw

Re: [PATCH v2 1/5] sysreset: qemu virt: Use __raw_writel()

Quoted 7 lines · Daniel Palmer

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.

Regards,
Kuan-Wei

Quoted 20 lines
---
 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
#3 lore raw

Re: [PATCH v2 1/5] sysreset: qemu virt: Use __raw_writel()

In reply to Daniel Palmer

Hi,

Quoted 3 lines · Daniel Palmer

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

Still not clear why writel should be currently broken, it works fine in bigendian for m68k.

Quoted 13 lines

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 +0 -0
index e7cacc9b6e98..5ab16001922b 100644

drivers/sysreset/sysreset_qemu_virt_ctrl.c static int qemu_virt_ctrl_request(struct udevice *dev, enum sysreset_t type) · line 44

Quoted 8 lines
drivers/sysreset/sysreset_qemu_virt_ctrl.c +1 -1
@@ -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;
 }

Regards,

-- Angelo

#4 lore raw

PATCH v2 2/5 m68k: Fix writew(), writel(), readw(), readl() endianness

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 borken and prevents virtio-mmio from functioning.

---
 arch/m68k/include/asm/io.h | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
arch/m68k/include/asm/io.h +5 -12
index 35ad4a1c0444..f4877b0446cf 100644
@@ -24,18 +24,11 @@
 #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))
-#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))
-#endif
+#define writeb(b, addr)		out_8((volatile u8 *)(addr), (b))
+#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))
 
 /*
  * The insw/outsw/insl/outsl macros don't do byte-swapping.
Signature · 1 line
2.51.0
#5 lore raw

Re: [PATCH v2 2/5] m68k: Fix writew(), writel(), readw(), readl() endianness

Hi Daniel,

Quoted 26 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 borken and prevents virtio-mmio from functioning.

---
 arch/m68k/include/asm/io.h | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
arch/m68k/include/asm/io.h +0 -7
index 35ad4a1c0444..f4877b0446cf 100644
@@ -24,18 +24,11 @@
 #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))
-#else

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

Quoted 10 lines
arch/m68k/include/asm/io.h +5 -5
-#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
+#define writeb(b, addr)		out_8((volatile u8 *)(addr), (b))
+#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))

Just wondering could this global change break some drivers on coldfire?

I originally thought you were planning to split these IO macros between coldfire and classic m68k.

Of course, if you've found that this doesn't actually break coldfire, then this global approach is definitely ideal.

Regards,
Kuan-Wei

Quoted 6 lines
arch/m68k/include/asm/io.h +0 -0
 /*
  * The insw/outsw/insl/outsl macros don't do byte-swapping.
Signature · 1 line
2.51.0
#6 lore raw

Re: [PATCH v2 2/5] m68k: Fix writew(), writel(), readw(), readl() endianness

Hi Kuan-Wei,

Quoted 1 line · Kuan-Wei Chiu

Just wondering could this global change break some drivers on coldfire?

It might. Really I'd like Angelo to see if it still works. Hopefully it doesn't break anything or it's just one or two things that need to be fixed to make it work again.
In Linux the range for the in-chip registers uses the current behaviour and everything else uses the "correct" behaviour. I think we want to avoid having that hack if possible.

Quoted 2 lines

I originally thought you were planning to split these IO macros between coldfire and classic m68k.

Yeah, but then we have to fix it again if a coldfire virt machine happens. If it breaks coldfire so badly it's difficult to fix I'll split them.

Quoted 2 lines

Of course, if you've found that this doesn't actually break coldfire, then this global approach is definitely ideal.

Yep. I forgot that there is actually a coldfire machine in qemu so I will build and test this on that a bit later.

Cheers,

Daniel

#7 lore raw

Re: [PATCH v2 2/5] m68k: Fix writew(), writel(), readw(), readl() endianness

In reply to Daniel Palmer

Hi Daniel,

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 borken and prevents virtio-mmio from functioning.

mmm, "currently broken" ?

If you remove bigendian read/write the driver framework will fail to work with coldfire/m68k stuff.

I tested the patchset over master in stmark2 board, seems this patch is breaking dspi cs init:

stmark2 $ saveenv
Saving Environment to SPIFlash... *** Warning - spi_flash_probe_bus_cs() failed, using default environment

Failed (-1)
stmark2 $ sf probe
spi_coldfire dspi@fc05c000: Invalid chip select 0:0 (err=-19) Failed to initialize SPI flash at 0:0 (error -19) stmark2 $

Please find a different solution, that may be using "xxx_le" stuff directly from your code.

Quoted 23 lines
---
 arch/m68k/include/asm/io.h | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
arch/m68k/include/asm/io.h +0 -10
index 35ad4a1c0444..f4877b0446cf 100644
@@ -24,18 +24,11 @@
 #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))
-#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))

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

Quoted 10 lines
arch/m68k/include/asm/io.h +5 -2
-#define writel(b,addr)		out_be32((volatile u32 *)(addr),(b))
-#endif
+#define writeb(b, addr)		out_8((volatile u8 *)(addr), (b))
+#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))
 
 /*
  * The insw/outsw/insl/outsl macros don't do byte-swapping.

Regards,

-- Angelo

#8 lore raw

Re: [PATCH v2 2/5] m68k: Fix writew(), writel(), readw(), readl() endianness

Hi Angelo.

Quoted 3 lines · Angelo Dureghello

mmm, "currently broken" ?
If you remove bigendian read/write the driver framework will fail to work with coldfire/m68k stuff.

I'm not sure who/what decided this but in Linux at least these are meant to be read little endian and convert to cpu endian. Classic m68k in linux works like that. Coldfire in Linux is currently the same as u-boot on internal registers and but everything else has the "correct" behaviour. I think that is so PCI can work.

Quoted 2 lines

I tested the patchset over master in stmark2 board, seems this patch is breaking dspi cs init:

Thank you for checking and sorry for the breakage.

Quoted 2 lines

Please find a different solution, that may be using "xxx_le" stuff directly from your code.

mmm so I did try that for nommu classic m68k in Linux because it's also "broken" there and got told to fix readl() etc.

Would putting this in some #ifdefs so coldfire keeps the current behaviour and classic m68k matches Linux be acceptable?

Thanks,

Daniel

#9 lore raw

Re: [PATCH v2 2/5] m68k: Fix writew(), writel(), readw(), readl() endianness

Hi Daniel,

Quoted 13 lines · Daniel Palmer

Hi Angelo.

Quoted 3 lines · Angelo Dureghello

mmm, "currently broken" ?
If you remove bigendian read/write the driver framework will fail to work with coldfire/m68k stuff.

I'm not sure who/what decided this but in Linux at least these are meant to be read little endian and convert to cpu endian. Classic m68k in linux works like that. Coldfire in Linux is currently the same as u-boot on internal registers and but everything else has the "correct" behaviour. I think that is so PCI can work.

Quoted 5 lines
Quoted 2 lines

I tested the patchset over master in stmark2 board, seems this patch is breaking dspi cs init:

Thank you for checking and sorry for the breakage.

no problem.

Quoted 9 lines
Quoted 2 lines

Please find a different solution, that may be using "xxx_le" stuff directly from your code.

mmm so I did try that for nommu classic m68k in Linux because it's also "broken" there and got told to fix readl() etc.

Would putting this in some #ifdefs so coldfire keeps the current behaviour and classic m68k matches Linux be acceptable?

yes, thanks, please try to find a solution protecting coldfire for now.

I will try to understand better why Linux operates differently from u-boot, i think pci was involved here but actually i don't remember, need to study this deeper.

Quoted 3 lines

Thanks,

Daniel

Regards,
-- Angelo

#10 lore raw

Re: [PATCH v2 2/5] m68k: Fix writew(), writel(), readw(), readl() endianness

Hi Angelo,

Quoted 1 line · Angelo Dureghello

yes, thanks, please try to find a solution protecting coldfire for now.

So for now I have put #ifdefs in so coldfire retains its current behaviour.

Quoted 3 lines

I will try to understand better why Linux operates differently from u-boot, i think pci was involved here but actually i don't remember, need to study this deeper.

I thought maybe this change in m68k might be recent but in Linux it seems to have been there since the import into git 22 years ago.

In the linux docs (https://docs.kernel.org/driver-api/device-io.html)
it says this:

Note: On some architectures, the normal readl()/writel() functions traditionally assume that devices are the same endianness as the CPU, while using a hardware byte-reverse on the PCI bus when running a big-endian kernel. Drivers that use readl()/writel() this way are generally not portable, but tend to be limited to a particular SoC.

So I think maybe coldfire got a "reads native endian, no swap" readl()/writel() and then when PCI support was added a hack was needed. But somehow normal m68k got it the other way around. <shrug>

Anyhow, sorry again for breaking your board.

Cheers,

Daniel

#11 lore raw

Re: [PATCH v2 2/5] m68k: Fix writew(), writel(), readw(), readl() endianness

Hi Daniel,

Quoted 23 lines · Daniel Palmer

Hi Angelo,

Quoted 1 line · Angelo Dureghello

yes, thanks, please try to find a solution protecting coldfire for now.

So for now I have put #ifdefs in so coldfire retains its current behaviour.

Quoted 3 lines

I will try to understand better why Linux operates differently from u-boot, i think pci was involved here but actually i don't remember, need to study this deeper.

I thought maybe this change in m68k might be recent but in Linux it seems to have been there since the import into git 22 years ago.

In the linux docs (https://docs.kernel.org/driver-api/device-io.html)
it says this:

Note: On some architectures, the normal readl()/writel() functions traditionally assume that devices are the same endianness as the CPU, while using a hardware byte-reverse on the PCI bus when running a big-endian kernel. Drivers that use readl()/writel() this way are generally not portable, but tend to be limited to a particular SoC.

Quoted 3 lines

So I think maybe coldfire got a "reads native endian, no swap" readl()/writel() and then when PCI support was added a hack was needed. But somehow normal m68k got it the other way around. <shrug>

mmm, so from a fast look:

apart for M5235EVB_defconfig:CONFIG_CMD_PCI=y
but this board has no PCI bus, so it should be some config copy/paste,

there is no other board using pci for coldfire, maybe either no pci driver working (NXP driver may work ?) or tested for them, so there was never any need for swapping LE for pci. But just an assumption, i can be totally wrong since some nxp board has been removed and some coldfire have pci.

So this part

#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))
#else

is probably non functional from a pci driver since still "be" r/w. Should be replaced with _le stuff. But should go deeper when i have some time.

Quoted 3 lines

Anyhow, sorry again for breaking your board.

as i said, no problem. We tested it before, that's ok.

Quoted 3 lines

Cheers,

Daniel

Regards,
-- Angelo

#12 lore raw

PATCH v2 3/5 virtio: mmio: Keep vendor id little endian

In reply to Daniel Palmer

The vendor id is used as a little endian value but it gets swapped to the CPU endian in readl(). Swap it back to le to avoid the below weird output from virtio info.

Device 0: UMEQ VirtIO Block Device
Type: Hard Disk
Capacity: 1.0 MB = 0.0 GB (2056 x 512)

---
 drivers/virtio/virtio_mmio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_mmio.c +1 -1
index 1cd737aca249..ddf873fa96fb 100644
@@ -374,7 +374,7 @@ static int virtio_mmio_probe(struct udevice *udev)
 		 */
 		return 0;
 	}
-	uc_priv->vendor = readl(priv->base + VIRTIO_MMIO_VENDOR_ID);
+	uc_priv->vendor = cpu_to_le32(readl(priv->base + VIRTIO_MMIO_VENDOR_ID));
 
 	if (priv->version == 1)
 		writel(PAGE_SIZE, priv->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
Signature · 1 line
2.51.0
#13 lore raw

Re: [PATCH v2 3/5] virtio: mmio: Keep vendor id little endian

Hi Daniel,

Quoted 18 lines · Daniel Palmer

The vendor id is used as a little endian value but it gets swapped to the CPU endian in readl(). Swap it back to le to avoid the below weird output from virtio info.

Device 0: UMEQ VirtIO Block Device
Type: Hard Disk
Capacity: 1.0 MB = 0.0 GB (2056 x 512)

---
 drivers/virtio/virtio_mmio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_mmio.c +0 -0
index 1cd737aca249..ddf873fa96fb 100644

drivers/virtio/virtio_mmio.c static int virtio_mmio_probe(struct udevice *udev) · line 377

Quoted 5 lines
drivers/virtio/virtio_mmio.c +1 -1
@@ -374,7 +374,7 @@ static int virtio_mmio_probe(struct udevice *udev)
 		 */
 		return 0;
 	}
-	uc_priv->vendor = readl(priv->base + VIRTIO_MMIO_VENDOR_ID);
+	uc_priv->vendor = cpu_to_le32(readl(priv->base + VIRTIO_MMIO_VENDOR_ID));

Hi Daniel,

Thanks for the patch!

While using cpu_to_le32() here does fix the visual output, it feels a bit hacky because it alters the actual core data value just to satisfy a display quirk.

For example, if someone in the future writes hardware specific logic like if (uc_priv->vendor == 0x554D4551), it would silently fail on m68k.

It looks more like a issue in virtio-blk driver to me. The code currently does this:

sprintf(desc->vendor, "%s", (char *)&uc_priv->vendor);

This direct memory cast relies on little endian byte ordering to spell "QEMU". On big endian machines, the memory layout naturally spells "UMEQ".

So maybe we can extract the characters safely using bitwise shifts like this?

drivers/virtio/virtio_blk.c +8 -3
index 3dd0cf36268..af61939270d 100644
@@ -168,10 +168,15 @@ static int virtio_blk_bind(struct udevice *dev)
         * 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);
-       else
+       if (uc_priv->vendor >> 16) {
+               desc->vendor[0] = (uc_priv->vendor >>  0) & 0xff;
+               desc->vendor[1] = (uc_priv->vendor >>  8) & 0xff;
+               desc->vendor[2] = (uc_priv->vendor >> 16) & 0xff;
+               desc->vendor[3] = (uc_priv->vendor >> 24) & 0xff;
+               desc->vendor[4] = '\0';
+       } else {
                sprintf(desc->vendor, "%04x", uc_priv->vendor);
+       }
        desc->bdev = dev;
 
        /* Indicate what driver features we support */

Regards,
Kuan-Wei

#14 lore raw

Re: [PATCH v2 3/5] virtio: mmio: Keep vendor id little endian

Hi Kuan-Wei,

Quoted 3 lines · Kuan-Wei Chiu

For example, if someone in the future writes hardware specific logic like if (uc_priv->vendor == 0x554D4551), it would silently fail on m68k.

Yeah, you're totally right. I did think "hmmm, maybe it's actually just an issue with whatever is doing the printing" right after sending the patch. :)
I will move the fix to virtio-blk for v3.

Thanks

Daniel

#15 lore raw

Re: [PATCH v2 3/5] virtio: mmio: Keep vendor id little endian

In reply to Kuan-Wei Chiu

Hi Kuan-Wei,

Quoted 6 lines · Kuan-Wei Chiu

This direct memory cast relies on little endian byte ordering to spell "QEMU". On big endian machines, the memory layout naturally spells "UMEQ".

So maybe we can extract the characters safely using bitwise shifts like this?

I think this has uncovered a more important bug..

/*
* 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);

The comment makes no sense. uc_priv->vendor is a u32. The id might be ASCII chars but it's not a C-string. It's only working right now because by luck after the chars in the u32 there is a 0.

Anyhow, I think I've fixed this properly so I will send that in v3.

Cheers,

Daniel

#16 lore raw

PATCH v2 4/5 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 ddf873fa96fb..51ef90c768af 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
#17 lore raw

Re: [PATCH v2 4/5] virtio: mmio: Allow instantiation via platform data

Hi Daniel,

Quoted 58 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 +11 -3
index ddf873fa96fb..51ef90c768af 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) = {

drivers/virtio/virtio_mmio.c static const struct udevice_id virtio_mmio_ids[] = { · line 420

Quoted 10 lines
drivers/virtio/virtio_mmio.c +5 -5
-	.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,

Just realized this didn't send earlier.

The patch looks good overall.
However, I noticed some changes involving tabs vs. spaces. Do we have a specific style rule requiring spaces instead of tabs here?

Regards,
Kuan-Wei

Quoted 26 lines
drivers/virtio/virtio_mmio.c +2 -1
 	.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
#18 lore raw

Re: [PATCH v2 4/5] virtio: mmio: Allow instantiation via platform data

Hi Kuan-Wei,

Quoted 13 lines · Kuan-Wei Chiu

drivers/virtio/virtio_mmio.c static const struct udevice_id virtio_mmio_ids[] = { · line 420

Quoted 12 lines

U_BOOT_DRIVER(virtio_mmio) = {

drivers/virtio/virtio_mmio.c +5 -5
-     .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,
Quoted 5 lines

Just realized this didn't send earlier.

The patch looks good overall.
However, I noticed some changes involving tabs vs. spaces. Do we have a specific style rule requiring spaces instead of tabs here?

From memory, when I aligned it using tabs it didn't look very nice so aligning with spaces worked out better.

Cheers,

Daniel

#19 lore raw

PATCH v2 5/5 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 | 47 +++++++++++++++++++++++++++
 2 files changed, 55 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 +47 -0

74 lines not on this page · raw message

Signature · 1 line
2.51.0