Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/fdt Instead of requiring drivers to be explicit abou...
details: https://anonhg.NetBSD.org/src/rev/31dc1340bcfa
branches: trunk
changeset: 1023412:31dc1340bcfa
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Mon Sep 06 14:03:17 2021 +0000
description:
Instead of requiring drivers to be explicit about their device memory
mapping requirements, move this decision into the fdt layer. This
introduces a new MD function, fdtbus_bus_tag_create, which is responsible
for returning per-node bus_space handles.
diffstat:
sys/arch/arm/apple/apple_dart.c | 7 +--
sys/arch/arm/apple/apple_intc.c | 7 +--
sys/arch/arm/apple/apple_pcie.c | 15 ++++---
sys/arch/arm/apple/apple_wdog.c | 7 +--
sys/arch/arm/fdt/pcihost_fdt.c | 9 ++--
sys/arch/arm/fdt/pcihost_fdtvar.h | 3 +-
sys/arch/arm/rockchip/rk3399_pcie.c | 7 ++-
sys/arch/evbarm/conf/files.fdt | 3 +-
sys/arch/evbarm/fdt/fdt_bus_machdep.c | 68 +++++++++++++++++++++++++++++++++++
sys/arch/mips/cavium/mainbus.c | 10 ++++-
sys/dev/fdt/fdtbus.c | 37 +++++++++++++++++-
sys/dev/fdt/fdtvar.h | 5 ++-
12 files changed, 145 insertions(+), 33 deletions(-)
diffs (truncated from 431 to 300 lines):
diff -r 60af397532db -r 31dc1340bcfa sys/arch/arm/apple/apple_dart.c
--- a/sys/arch/arm/apple/apple_dart.c Mon Sep 06 13:11:34 2021 +0000
+++ b/sys/arch/arm/apple/apple_dart.c Mon Sep 06 14:03:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apple_dart.c,v 1.2 2021/09/04 12:35:31 jmcneill Exp $ */
+/* $NetBSD: apple_dart.c,v 1.3 2021/09/06 14:03:17 jmcneill Exp $ */
/*-
* Copyright (c) 2021 Mark Kettenis <kettenis%openbsd.org@localhost>
@@ -20,7 +20,7 @@
//#define APPLE_DART_DEBUG
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: apple_dart.c,v 1.2 2021/09/04 12:35:31 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apple_dart.c,v 1.3 2021/09/06 14:03:17 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -482,8 +482,7 @@
sc->sc_phandle = phandle;
sc->sc_dmat = faa->faa_dmat;
sc->sc_bst = faa->faa_bst;
- if (bus_space_map(sc->sc_bst, addr, size,
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED, &sc->sc_bsh) != 0) {
+ if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh) != 0) {
aprint_error(": couldn't map registers\n");
return;
}
diff -r 60af397532db -r 31dc1340bcfa sys/arch/arm/apple/apple_intc.c
--- a/sys/arch/arm/apple/apple_intc.c Mon Sep 06 13:11:34 2021 +0000
+++ b/sys/arch/arm/apple/apple_intc.c Mon Sep 06 14:03:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apple_intc.c,v 1.1 2021/08/30 23:26:26 jmcneill Exp $ */
+/* $NetBSD: apple_intc.c,v 1.2 2021/09/06 14:03:17 jmcneill Exp $ */
/*-
* Copyright (c) 2021 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -31,7 +31,7 @@
#define _INTR_PRIVATE
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: apple_intc.c,v 1.1 2021/08/30 23:26:26 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apple_intc.c,v 1.2 2021/09/06 14:03:17 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -465,8 +465,7 @@
sc->sc_dev = self;
sc->sc_bst = faa->faa_bst;
- if (bus_space_map(sc->sc_bst, addr, size,
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED, &sc->sc_bsh) != 0) {
+ if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh) != 0) {
aprint_error(": couldn't map registers\n");
return;
}
diff -r 60af397532db -r 31dc1340bcfa sys/arch/arm/apple/apple_pcie.c
--- a/sys/arch/arm/apple/apple_pcie.c Mon Sep 06 13:11:34 2021 +0000
+++ b/sys/arch/arm/apple/apple_pcie.c Mon Sep 06 14:03:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apple_pcie.c,v 1.2 2021/09/04 12:35:31 jmcneill Exp $ */
+/* $NetBSD: apple_pcie.c,v 1.3 2021/09/06 14:03:17 jmcneill Exp $ */
/*-
* Copyright (c) 2021 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: apple_pcie.c,v 1.2 2021/09/04 12:35:31 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apple_pcie.c,v 1.3 2021/09/06 14:03:17 jmcneill Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -106,9 +106,13 @@
sc->sc_dev = self;
sc->sc_dmat = faa->faa_dmat;
sc->sc_bst = faa->faa_bst;
+ /*
+ * Create a new bus tag for PCIe devices that does not inherit the
+ * nonposted MMIO flag from the host controller.
+ */
+ sc->sc_pci_bst = fdtbus_bus_tag_create(phandle, 0);
sc->sc_phandle = phandle;
- error = bus_space_map(sc->sc_bst, cs_addr, cs_size,
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED, &sc->sc_bsh);
+ error = bus_space_map(faa->faa_bst, cs_addr, cs_size, 0, &sc->sc_bsh);
if (error) {
aprint_error(": couldn't map registers: %d\n", error);
return;
@@ -146,8 +150,7 @@
aprint_error(": couldn't get %s regs\n", regname);
return;
}
- error = bus_space_map(bst, addr, size,
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED, &bsh);
+ error = bus_space_map(bst, addr, size, 0, &bsh);
if (error != 0) {
aprint_error(": couldn't map %s regs\n", regname);
return;
diff -r 60af397532db -r 31dc1340bcfa sys/arch/arm/apple/apple_wdog.c
--- a/sys/arch/arm/apple/apple_wdog.c Mon Sep 06 13:11:34 2021 +0000
+++ b/sys/arch/arm/apple/apple_wdog.c Mon Sep 06 14:03:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apple_wdog.c,v 1.1 2021/08/30 23:26:26 jmcneill Exp $ */
+/* $NetBSD: apple_wdog.c,v 1.2 2021/09/06 14:03:17 jmcneill Exp $ */
/*-
* Copyright (c) 2021 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: apple_wdog.c,v 1.1 2021/08/30 23:26:26 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apple_wdog.c,v 1.2 2021/09/06 14:03:17 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -99,8 +99,7 @@
sc->sc_dev = self;
sc->sc_bst = faa->faa_bst;
- if (bus_space_map(sc->sc_bst, addr, size,
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED, &sc->sc_bsh) != 0) {
+ if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh) != 0) {
aprint_error(": couldn't map registers\n");
return;
}
diff -r 60af397532db -r 31dc1340bcfa sys/arch/arm/fdt/pcihost_fdt.c
--- a/sys/arch/arm/fdt/pcihost_fdt.c Mon Sep 06 13:11:34 2021 +0000
+++ b/sys/arch/arm/fdt/pcihost_fdt.c Mon Sep 06 14:03:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcihost_fdt.c,v 1.26 2021/08/07 16:18:43 thorpej Exp $ */
+/* $NetBSD: pcihost_fdt.c,v 1.27 2021/09/06 14:03:17 jmcneill Exp $ */
/*-
* Copyright (c) 2018 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcihost_fdt.c,v 1.26 2021/08/07 16:18:43 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcihost_fdt.c,v 1.27 2021/09/06 14:03:17 jmcneill Exp $");
#include <sys/param.h>
@@ -126,6 +126,7 @@
sc->sc_dev = self;
sc->sc_dmat = faa->faa_dmat;
sc->sc_bst = faa->faa_bst;
+ sc->sc_pci_bst = faa->faa_bst;
sc->sc_phandle = faa->faa_phandle;
error = bus_space_map(sc->sc_bst, cs_addr, cs_size,
_ARM_BUS_SPACE_MAP_STRONGLY_ORDERED, &sc->sc_bsh);
@@ -230,14 +231,14 @@
bool swap;
struct pcih_bus_space * const pibs = &sc->sc_io;
- pibs->bst = *sc->sc_bst;
+ pibs->bst = *sc->sc_pci_bst;
pibs->bst.bs_cookie = pibs;
pibs->map = pibs->bst.bs_map;
pibs->flags = PCI_FLAGS_IO_OKAY;
pibs->bst.bs_map = pcihost_bus_space_map;
struct pcih_bus_space * const pmbs = &sc->sc_mem;
- pmbs->bst = *sc->sc_bst;
+ pmbs->bst = *sc->sc_pci_bst;
pmbs->bst.bs_cookie = pmbs;
pmbs->map = pmbs->bst.bs_map;
pmbs->flags = PCI_FLAGS_MEM_OKAY;
diff -r 60af397532db -r 31dc1340bcfa sys/arch/arm/fdt/pcihost_fdtvar.h
--- a/sys/arch/arm/fdt/pcihost_fdtvar.h Mon Sep 06 13:11:34 2021 +0000
+++ b/sys/arch/arm/fdt/pcihost_fdtvar.h Mon Sep 06 14:03:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcihost_fdtvar.h,v 1.3 2019/12/28 17:19:43 jmcneill Exp $ */
+/* $NetBSD: pcihost_fdtvar.h,v 1.4 2021/09/06 14:03:17 jmcneill Exp $ */
/*-
* Copyright (c) 2018 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -67,6 +67,7 @@
bus_dma_tag_t sc_dmat;
bus_space_tag_t sc_bst;
bus_space_handle_t sc_bsh;
+ bus_space_tag_t sc_pci_bst;
int sc_phandle;
enum pcihost_type sc_type;
diff -r 60af397532db -r 31dc1340bcfa sys/arch/arm/rockchip/rk3399_pcie.c
--- a/sys/arch/arm/rockchip/rk3399_pcie.c Mon Sep 06 13:11:34 2021 +0000
+++ b/sys/arch/arm/rockchip/rk3399_pcie.c Mon Sep 06 14:03:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rk3399_pcie.c,v 1.16 2021/09/03 01:21:48 mrg Exp $ */
+/* $NetBSD: rk3399_pcie.c,v 1.17 2021/09/06 14:03:17 jmcneill Exp $ */
/*
* Copyright (c) 2018 Mark Kettenis <kettenis%openbsd.org@localhost>
*
@@ -17,7 +17,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: rk3399_pcie.c,v 1.16 2021/09/03 01:21:48 mrg Exp $");
+__KERNEL_RCSID(1, "$NetBSD: rk3399_pcie.c,v 1.17 2021/09/06 14:03:17 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -215,11 +215,12 @@
phsc->sc_dev = self;
phsc->sc_bst = faa->faa_bst;
+ phsc->sc_pci_bst = faa->faa_bst;
phsc->sc_dmat = faa->faa_dmat;
sc->sc_iot = phsc->sc_bst;
phsc->sc_phandle = faa->faa_phandle;
const int phandle = phsc->sc_phandle;
-
+
if (fdtbus_get_reg_byname(faa->faa_phandle, "axi-base", &sc->sc_axi_addr, &sc->sc_axi_size) != 0) {
aprint_error(": couldn't get axi registers\n");
return;
diff -r 60af397532db -r 31dc1340bcfa sys/arch/evbarm/conf/files.fdt
--- a/sys/arch/evbarm/conf/files.fdt Mon Sep 06 13:11:34 2021 +0000
+++ b/sys/arch/evbarm/conf/files.fdt Mon Sep 06 14:03:17 2021 +0000
@@ -1,8 +1,9 @@
-# $NetBSD: files.fdt,v 1.8 2021/05/12 23:22:32 thorpej Exp $
+# $NetBSD: files.fdt,v 1.9 2021/09/06 14:03:17 jmcneill Exp $
#
# FDT-based kernel configuration info
#
+file arch/evbarm/fdt/fdt_bus_machdep.c fdt
file arch/evbarm/fdt/fdt_dma_machdep.c fdt
file arch/evbarm/fdt/fdt_machdep.c fdt
file dev/ofw/ofw_pci_subr.c fdt & pci
diff -r 60af397532db -r 31dc1340bcfa sys/arch/evbarm/fdt/fdt_bus_machdep.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/evbarm/fdt/fdt_bus_machdep.c Mon Sep 06 14:03:17 2021 +0000
@@ -0,0 +1,68 @@
+/* $NetBSD: fdt_bus_machdep.c,v 1.1 2021/09/06 14:03:18 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2021 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * 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 AUTHOR ``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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: fdt_bus_machdep.c,v 1.1 2021/09/06 14:03:18 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/kmem.h>
+
+#include <dev/fdt/fdtvar.h>
+#include <arm/fdt/arm_fdtvar.h>
+
+extern struct bus_space arm_generic_bs_tag;
+
+static int
+nonposted_mmio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flag,
+ bus_space_handle_t *bshp)
+{
+ if (flag == 0) {
+ flag |= _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED;
+ }
+
+ return bus_space_map(&arm_generic_bs_tag, bpa, size, flag, bshp);
+}
+
+bus_space_tag_t
+fdtbus_bus_tag_create(int phandle, uint32_t flags)
+{
+ const struct arm_platform *plat = arm_fdt_platform();
+ struct bus_space *tagp;
+ struct fdt_attach_args faa;
+
+ plat->ap_init_attach_args(&faa);
+
+ tagp = kmem_alloc(sizeof(*tagp), KM_SLEEP);
+ *tagp = *faa.faa_bst;
Home |
Main Index |
Thread Index |
Old Index