Add virtio-mmio support to m68k virt machine
Subsystems (2)
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
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
@@ -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
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 ofwritel()is fixed.Signed-off-by Daniel Palmer <[email protected]>
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@@ -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
Re: [PATCH v2 1/5] sysreset: qemu virt: Use __raw_writel()
In reply to Daniel PalmerHi,
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 ofwritel()is fixed.Signed-off-by Daniel Palmer <[email protected]>--- drivers/sysreset/sysreset_qemu_virt_ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/sysreset/sysreset_qemu_virt_ctrl.c +0
-0
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
PATCH v2 2/5 m68k: Fix writew(), writel(), readw(), readl() endianness
In reply to Daniel PalmerIn 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
@@ -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
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.
Signed-off-by Daniel Palmer <[email protected]>--- arch/m68k/include/asm/io.h | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)arch/m68k/include/asm/io.h +0
-7@@ -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
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
Re: [PATCH v2 2/5] m68k: Fix writew(), writel(), readw(), readl() endianness
In reply to Daniel PalmerHi 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 probespi_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
Signed-off-by Daniel Palmer <[email protected]>--- arch/m68k/include/asm/io.h | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)arch/m68k/include/asm/io.h +0
-10@@ -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
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
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
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
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
PATCH v2 3/5 virtio: mmio: Keep vendor id little endian
In reply to Daniel PalmerThe 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
@@ -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
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 fromvirtio info.Device 0: UMEQ VirtIO Block Device
Type: Hard Disk
Capacity: 1.0 MB = 0.0 GB (2056 x 512)Signed-off-by Daniel Palmer <[email protected]>--- drivers/virtio/virtio_mmio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/virtio/virtio_mmio.c +0
-0
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
@@ -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
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
Re: [PATCH v2 3/5] virtio: mmio: Keep vendor id little endian
In reply to Kuan-Wei ChiuHi 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
PATCH v2 4/5 virtio: mmio: Allow instantiation via platform data
In reply to Daniel PalmerThe 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
@@ -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
@@ -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
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.
Signed-off-by Daniel Palmer <[email protected]>--- drivers/virtio/virtio_mmio.c | 27 ++++++++++++++++++--------- include/virtio_mmio.h | 12 ++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 include/virtio_mmio.hdrivers/virtio/virtio_mmio.c +11
-3@@ -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@@ -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
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
PATCH v2 5/5 board: qemu: m68k: Create virtio mmio instances
In reply to Daniel PalmerSo 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
@@ -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