From de36f822ef9cbe28d3ef09dd1015b7d13999924e Mon Sep 17 00:00:00 2001 From: jsg Date: Sat, 6 Aug 2016 00:30:47 +0000 Subject: [PATCH] Dynamically attach virtio(4) using the FDT. ok kettenis@ patrick@ --- sys/arch/armv7/conf/GENERIC | 4 +- sys/arch/armv7/conf/RAMDISK | 4 +- sys/arch/armv7/vexpress/files.vexpress | 4 +- sys/arch/armv7/vexpress/vexpress.c | 6 +-- sys/arch/armv7/vexpress/virtio_mmio.c | 58 +++++++------------------- 5 files changed, 23 insertions(+), 53 deletions(-) diff --git a/sys/arch/armv7/conf/GENERIC b/sys/arch/armv7/conf/GENERIC index 58c66056405..455a4913651 100644 --- a/sys/arch/armv7/conf/GENERIC +++ b/sys/arch/armv7/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.36 2016/08/05 21:45:37 kettenis Exp $ +# $OpenBSD: GENERIC,v 1.37 2016/08/06 00:30:47 jsg Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -105,7 +105,7 @@ vexpress0 at mainbus? sysreg* at vexpress? pluart* at vexpress? plrtc* at vexpress? -virtio* at vexpress? +virtio* at fdt? # Exynos exynos0 at mainbus? diff --git a/sys/arch/armv7/conf/RAMDISK b/sys/arch/armv7/conf/RAMDISK index 156956a1438..6bbab8c8776 100644 --- a/sys/arch/armv7/conf/RAMDISK +++ b/sys/arch/armv7/conf/RAMDISK @@ -1,4 +1,4 @@ -# $OpenBSD: RAMDISK,v 1.33 2016/08/05 21:45:37 kettenis Exp $ +# $OpenBSD: RAMDISK,v 1.34 2016/08/06 00:30:47 jsg Exp $ machine armv7 arm @@ -104,7 +104,7 @@ vexpress0 at mainbus? sysreg* at vexpress? pluart* at vexpress? plrtc* at vexpress? -virtio* at vexpress? +virtio* at fdt? # Exynos exynos0 at mainbus? diff --git a/sys/arch/armv7/vexpress/files.vexpress b/sys/arch/armv7/vexpress/files.vexpress index a06d39415fc..f78e779a3cb 100644 --- a/sys/arch/armv7/vexpress/files.vexpress +++ b/sys/arch/armv7/vexpress/files.vexpress @@ -1,4 +1,4 @@ -# $OpenBSD: files.vexpress,v 1.3 2016/05/02 08:15:55 patrick Exp $ +# $OpenBSD: files.vexpress,v 1.4 2016/08/06 00:30:47 jsg Exp $ define vexpress {} device vexpress: vexpress @@ -16,7 +16,7 @@ device plrtc attach plrtc at vexpress file arch/armv7/vexpress/pl031.c plrtc -attach virtio at vexpress with virtio_mmio +attach virtio at fdt with virtio_mmio file arch/armv7/vexpress/virtio_mmio.c virtio_mmio device sysreg diff --git a/sys/arch/armv7/vexpress/vexpress.c b/sys/arch/armv7/vexpress/vexpress.c index 422e16fa0c7..21635a0b66f 100644 --- a/sys/arch/armv7/vexpress/vexpress.c +++ b/sys/arch/armv7/vexpress/vexpress.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vexpress.c,v 1.5 2016/06/04 18:09:16 jsg Exp $ */ +/* $OpenBSD: vexpress.c,v 1.6 2016/08/06 00:30:47 jsg Exp $ */ /* * Copyright (c) 2015 Jonathan Gray @@ -42,10 +42,6 @@ struct board_dev vexpress_devs[] = { { "sysreg", 0 }, { "pluart", 0 }, { "plrtc", 0 }, - { "virtio", 0 }, - { "virtio", 1 }, - { "virtio", 2 }, - { "virtio", 3 }, { NULL, 0 } }; diff --git a/sys/arch/armv7/vexpress/virtio_mmio.c b/sys/arch/armv7/vexpress/virtio_mmio.c index 911fada8dc6..b0b1392ca30 100644 --- a/sys/arch/armv7/vexpress/virtio_mmio.c +++ b/sys/arch/armv7/vexpress/virtio_mmio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio_mmio.c,v 1.4 2016/07/26 22:10:10 patrick Exp $ */ +/* $OpenBSD: virtio_mmio.c,v 1.5 2016/08/06 00:30:47 jsg Exp $ */ /* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */ /* @@ -37,11 +37,12 @@ #include #include -#if NFDT > 0 #include -#endif #include +#include +#include + #define VIRTIO_MMIO_MAGIC ('v' | 'i' << 8 | 'r' << 16 | 't' << 24) #define VIRTIO_MMIO_MAGIC_VALUE 0x000 @@ -181,56 +182,29 @@ virtio_mmio_set_status(struct virtio_softc *vsc, int status) int virtio_mmio_match(struct device *parent, void *cfdata, void *aux) { -#if NFDT > 0 - struct armv7_attach_args *aa = aux; - - if (fdt_node_compatible("virtio,mmio", aa->aa_node)) - return 1; -#endif + struct fdt_attach_args *faa = aux; - return 0; + return OF_is_compatible(faa->fa_node, "virtio,mmio"); } void virtio_mmio_attach(struct device *parent, struct device *self, void *aux) { - struct armv7_attach_args *aa = aux; + struct fdt_attach_args *faa = aux; struct virtio_mmio_softc *sc = (struct virtio_mmio_softc *)self; struct virtio_softc *vsc = &sc->sc_sc; - struct armv7mem mem; uint32_t id, magic, version; - int irq; - -#if NFDT > 0 - if (aa->aa_node) { - struct fdt_reg reg; - uint32_t ints[3]; - if (fdt_get_reg(aa->aa_node, 0, ®)) - panic("%s: could not extract memory data from FDT", __func__); - - if (fdt_node_property_ints(aa->aa_node, "interrupts", - ints, 3) != 3) - panic("%s: could not extract interrupt data from FDT", - __func__); - - mem.addr = reg.addr; - mem.size = reg.size; - - irq = ints[1]; - } else -#endif - { - mem.addr = aa->aa_dev->mem[0].addr; - mem.size = aa->aa_dev->mem[0].size; - - irq = aa->aa_dev->irq[0]; + if (faa->fa_nreg < 1) { + printf(": no register data\n"); + return; } - sc->sc_iosize = mem.size; - sc->sc_iot = aa->aa_iot; - sc->sc_dmat = aa->aa_dmat; - if (bus_space_map(sc->sc_iot, mem.addr, mem.size, 0, &sc->sc_ioh)) + sc->sc_iosize = faa->fa_reg[0].size; + sc->sc_iot = faa->fa_iot; + sc->sc_dmat = faa->fa_dmat; + if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, faa->fa_reg[0].size, + 0, &sc->sc_ioh)) panic("%s: bus_space_map failed!", __func__); magic = bus_space_read_4(sc->sc_iot, sc->sc_ioh, @@ -281,7 +255,7 @@ virtio_mmio_attach(struct device *parent, struct device *self, void *aux) goto fail_1; } - sc->sc_ih = arm_intr_establish(irq, vsc->sc_ipl, + sc->sc_ih = arm_intr_establish_fdt(faa->fa_node, vsc->sc_ipl, virtio_mmio_intr, sc, vsc->sc_dev.dv_xname); if (sc->sc_ih == NULL) { printf("%s: couldn't establish interrupt\n", -- 2.20.1