Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/evbmips/mipssim Add VirtIO devices to the MIPSSIM t...
details: https://anonhg.NetBSD.org/src/rev/dc2e7472a6c5
branches: trunk
changeset: 952726:dc2e7472a6c5
user: reinoud <reinoud%NetBSD.org@localhost>
date: Mon Feb 15 22:39:46 2021 +0000
description:
Add VirtIO devices to the MIPSSIM target for use in Qemu. Its supported by a
local patch starting at Qemu-5.1.0nb12
diffstat:
sys/arch/evbmips/mipssim/autoconf.h | 3 +-
sys/arch/evbmips/mipssim/machdep.c | 13 +-
sys/arch/evbmips/mipssim/mainbus.c | 16 ++-
sys/arch/evbmips/mipssim/mipssim_bus_io.c | 8 +-
sys/arch/evbmips/mipssim/mipssim_dma.c | 63 ++++++++++
sys/arch/evbmips/mipssim/mipssim_intr.c | 45 ++++--
sys/arch/evbmips/mipssim/mipssimreg.h | 18 ++-
sys/arch/evbmips/mipssim/mipssimvar.h | 8 +-
sys/arch/evbmips/mipssim/virtio_mainbus.c | 172 ++++++++++++++++++++++++++++++
9 files changed, 312 insertions(+), 34 deletions(-)
diffs (truncated from 573 to 300 lines):
diff -r 9da0551bd135 -r dc2e7472a6c5 sys/arch/evbmips/mipssim/autoconf.h
--- a/sys/arch/evbmips/mipssim/autoconf.h Mon Feb 15 19:49:17 2021 +0000
+++ b/sys/arch/evbmips/mipssim/autoconf.h Mon Feb 15 22:39:46 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: autoconf.h,v 1.1 2021/01/27 05:24:16 simonb Exp $ */
+/* $NetBSD: autoconf.h,v 1.2 2021/02/15 22:39:46 reinoud Exp $ */
/*
* Copyright 2002 Wasabi Systems, Inc.
@@ -42,4 +42,5 @@
unsigned long ma_addr;
int ma_irq;
bus_space_tag_t ma_iot;
+ bus_dma_tag_t ma_dmat;
};
diff -r 9da0551bd135 -r dc2e7472a6c5 sys/arch/evbmips/mipssim/machdep.c
--- a/sys/arch/evbmips/mipssim/machdep.c Mon Feb 15 19:49:17 2021 +0000
+++ b/sys/arch/evbmips/mipssim/machdep.c Mon Feb 15 22:39:46 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.1 2021/01/27 05:24:16 simonb Exp $ */
+/* $NetBSD: machdep.c,v 1.2 2021/02/15 22:39:46 reinoud Exp $ */
/*-
* Copyright (c) 2001,2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.1 2021/01/27 05:24:16 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.2 2021/02/15 22:39:46 reinoud Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@@ -113,8 +113,11 @@
{
uint32_t cntfreq;
- /* Pick a random clock frequency. XXX Any better way? */
- cntfreq = curcpu()->ci_cpu_freq = 10 * 1000 * 1000;
+ /*
+ * Qemu seems to default to 200 MHz; wall clock looks the right speed
+ * but we don't have an RTC to check.
+ */
+ cntfreq = curcpu()->ci_cpu_freq = 200 * 1000 * 1000;
if (mips_options.mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
cntfreq /= 2;
@@ -157,6 +160,8 @@
* Initialize bus space tags and bring up the main console.
*/
mipssim_bus_io_init(&mcp->mc_iot, mcp);
+ mipssim_dma_init(mcp);
+
if (comcnattach(&mcp->mc_iot, MIPSSIM_UART0_ADDR, COMCNRATE,
COM_FREQ, COM_TYPE_NORMAL,
(TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8) != 0)
diff -r 9da0551bd135 -r dc2e7472a6c5 sys/arch/evbmips/mipssim/mainbus.c
--- a/sys/arch/evbmips/mipssim/mainbus.c Mon Feb 15 19:49:17 2021 +0000
+++ b/sys/arch/evbmips/mipssim/mainbus.c Mon Feb 15 22:39:46 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.c,v 1.1 2021/01/27 05:24:16 simonb Exp $ */
+/* $NetBSD: mainbus.c,v 1.2 2021/02/15 22:39:46 reinoud Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.1 2021/01/27 05:24:16 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.2 2021/02/15 22:39:46 reinoud Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -84,11 +84,23 @@
mainbus_found = 1;
printf("\n");
+ /* attach children */
for (md = mainbusdevs; md->md_name != NULL; md++) {
maa.ma_name = md->md_name;
maa.ma_addr = md->md_addr;
maa.ma_irq = md->md_irq;
maa.ma_iot = &mcp->mc_iot;
+ maa.ma_dmat = &mcp->mc_dmat;
+ config_found_ia(self, "mainbus", &maa, mainbus_print);
+ }
+
+ /* attach virtio children */
+ for (int i = 0; i < VIRTIO_NUM_TRANSPORTS; i++) {
+ maa.ma_name = "virtio";
+ maa.ma_addr = MIPSSIM_VIRTIO_ADDR + VIRTIO_STRIDE * i;
+ maa.ma_irq = 1;
+ maa.ma_iot = &mcp->mc_iot;
+ maa.ma_dmat = &mcp->mc_dmat;
config_found_ia(self, "mainbus", &maa, mainbus_print);
}
}
diff -r 9da0551bd135 -r dc2e7472a6c5 sys/arch/evbmips/mipssim/mipssim_bus_io.c
--- a/sys/arch/evbmips/mipssim/mipssim_bus_io.c Mon Feb 15 19:49:17 2021 +0000
+++ b/sys/arch/evbmips/mipssim/mipssim_bus_io.c Mon Feb 15 22:39:46 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mipssim_bus_io.c,v 1.1 2021/01/27 05:24:16 simonb Exp $ */
+/* $NetBSD: mipssim_bus_io.c,v 1.2 2021/02/15 22:39:46 reinoud Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mipssim_bus_io.c,v 1.1 2021/01/27 05:24:16 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mipssim_bus_io.c,v 1.2 2021/02/15 22:39:46 reinoud Exp $");
#include <sys/param.h>
@@ -49,8 +49,8 @@
/* IO region 1 */
#define CHIP_W1_BUS_START(v) 0
-#define CHIP_W1_BUS_END(v) MIPSSIM_ISA_IO_SIZE
+#define CHIP_W1_BUS_END(v) (MIPSSIM_ISA_IO_SIZE + MIPSSIM_VIRTIO_IO_SIZE)
#define CHIP_W1_SYS_START(v) MIPSSIM_ISA_IO_BASE
-#define CHIP_W1_SYS_END(v) (CHIP_W1_SYS_START(v) + CHIP_W1_SYS_START(v))
+#define CHIP_W1_SYS_END(v) (CHIP_W1_SYS_START(v) + CHIP_W1_BUS_END(v))
#include <mips/mips/bus_space_alignstride_chipdep.c>
diff -r 9da0551bd135 -r dc2e7472a6c5 sys/arch/evbmips/mipssim/mipssim_dma.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/evbmips/mipssim/mipssim_dma.c Mon Feb 15 22:39:46 2021 +0000
@@ -0,0 +1,63 @@
+/* $NetBSD: mipssim_dma.c,v 1.1 2021/02/15 22:39:46 reinoud Exp $ */
+
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Platform-specific DMA support for the mipssim.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: mipssim_dma.c,v 1.1 2021/02/15 22:39:46 reinoud Exp $");
+
+#include <sys/param.h>
+#include <sys/device.h>
+
+#define _MIPS_BUS_DMA_PRIVATE
+#include <sys/bus.h>
+
+#include <dev/isa/isavar.h>
+
+#include <evbmips/mipssim/mipssimreg.h>
+#include <evbmips/mipssim/mipssimvar.h>
+
+void
+mipssim_dma_init(struct mipssim_config *mcp)
+{
+ bus_dma_tag_t t;
+
+ t = &mcp->mc_dmat;
+ t->_cookie = mcp;
+ t->_wbase = MIPSSIM_DMA_BASE;
+ t->_bounce_alloc_lo = MIPSSIM_DMA_PHYSBASE;
+ t->_bounce_alloc_hi = MIPSSIM_DMA_PHYSBASE + MIPSSIM_DMA_SIZE;
+ t->_dmamap_ops = mips_bus_dmamap_ops;
+ t->_dmamem_ops = mips_bus_dmamem_ops;
+ t->_dmatag_ops = mips_bus_dmatag_ops;
+}
diff -r 9da0551bd135 -r dc2e7472a6c5 sys/arch/evbmips/mipssim/mipssim_intr.c
--- a/sys/arch/evbmips/mipssim/mipssim_intr.c Mon Feb 15 19:49:17 2021 +0000
+++ b/sys/arch/evbmips/mipssim/mipssim_intr.c Mon Feb 15 22:39:46 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mipssim_intr.c,v 1.1 2021/01/27 05:24:16 simonb Exp $ */
+/* $NetBSD: mipssim_intr.c,v 1.2 2021/02/15 22:39:46 reinoud Exp $ */
/*-
* Copyright (c) 2014 Michael Lorenz
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mipssim_intr.c,v 1.1 2021/01/27 05:24:16 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mipssim_intr.c,v 1.2 2021/02/15 22:39:46 reinoud Exp $");
#define __INTR_PRIVATE
@@ -35,6 +35,7 @@
#include <sys/cpu.h>
#include <sys/kernel.h>
#include <sys/systm.h>
+#include <sys/kmem.h>
#include <mips/locore.h>
#include <machine/intr.h>
@@ -49,10 +50,11 @@
[IPL_SOFTCLOCK] = MIPS_SOFT_INT_MASK_0,
[IPL_SOFTNET] = MIPS_SOFT_INT_MASK,
[IPL_VM] = MIPS_SOFT_INT_MASK
- | MIPS_INT_MASK_0 | MIPS_INT_MASK_2,
+ | MIPS_INT_MASK_0 | MIPS_INT_MASK_1
+ | MIPS_INT_MASK_2,
[IPL_SCHED] = MIPS_SOFT_INT_MASK
- | MIPS_INT_MASK_0 | MIPS_INT_MASK_2
- | MIPS_INT_MASK_5,
+ | MIPS_INT_MASK_0 | MIPS_INT_MASK_1
+ | MIPS_INT_MASK_2 | MIPS_INT_MASK_5,
[IPL_DDB] = MIPS_INT_MASK,
[IPL_HIGH] = MIPS_INT_MASK,
},
@@ -61,7 +63,6 @@
/* XXX - add evcnt bits to <machine/intr.h> struct evbmips_intrhand */
struct intrhand {
LIST_ENTRY(intrhand) ih_q;
- struct evcnt ih_count;
int (*ih_func)(void *);
void *ih_arg;
int ih_irq;
@@ -74,10 +75,12 @@
*/
#define NINTR 5 /* MIPS INT0 - INT4 */
-struct intrhand intrs[NINTR];
+LIST_HEAD(intrlist, intrhand) intrs[NINTR];
+struct evcnt ih_count[NINTR];
+
const char * const intrnames[NINTR] = {
"int 0 (mipsnet)",
- "int 1 (unused)",
+ "int 1 (virtio)",
"int 2 (uart)",
"int 3 (unused)",
"int 4 (unused)",
@@ -94,10 +97,8 @@
/* zero all handlers */
for (i = 0; i < NINTR; i++) {
- intrs[i].ih_func = NULL;
- intrs[i].ih_arg = NULL;
- intrs[i].ih_irq = i;
- evcnt_attach_dynamic(&intrs[i].ih_count, EVCNT_TYPE_INTR,
+ LIST_INIT(&intrs[i]);
+ evcnt_attach_dynamic(&ih_count[i], EVCNT_TYPE_INTR,
NULL, "cpu", intrnames[i]);
}
}
@@ -105,6 +106,7 @@
void
evbmips_iointr(int ipl, uint32_t ipending, struct clockframe *cf)
{
+ struct intrlist *list;
for (int level = NINTR - 1; level >= 0; level--) {
struct intrhand *ih;
@@ -112,11 +114,13 @@
if ((ipending & (MIPS_INT_MASK_0 << level)) == 0)
continue;
- ih = &intrs[level];
+ ih_count[level].ev_count++;
+ list = &intrs[level];
- ih->ih_count.ev_count++;
- if (ih->ih_func) {
- (*ih->ih_func)(ih->ih_arg);
+ LIST_FOREACH(ih, list, ih_q) {
+ if (ih->ih_func) {
+ (*ih->ih_func)(ih->ih_arg);
+ }
}
}
}
@@ -124,6 +128,7 @@
void *
evbmips_intr_establish(int irq, int (*func)(void *), void *arg)
Home |
Main Index |
Thread Index |
Old Index