Module Name:    src
Committed By:   jmcneill
Date:           Mon Dec 30 18:43:38 UTC 2019

Modified Files:
        src/sys/arch/arm/broadcom: bcm2835_mbox.c bcm2835_mbox.h files.bcm2835
Added Files:
        src/sys/arch/arm/broadcom: bcm2835_mbox_acpi.c bcm2835_mbox_fdt.c

Log Message:
Split bcm2835 mbox driver into separate fdt and acpi frontends.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/arm/broadcom/bcm2835_mbox.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/broadcom/bcm2835_mbox.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/broadcom/bcm2835_mbox_acpi.c \
    src/sys/arch/arm/broadcom/bcm2835_mbox_fdt.c
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/arm/broadcom/files.bcm2835

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/broadcom/bcm2835_mbox.c
diff -u src/sys/arch/arm/broadcom/bcm2835_mbox.c:1.13 src/sys/arch/arm/broadcom/bcm2835_mbox.c:1.14
--- src/sys/arch/arm/broadcom/bcm2835_mbox.c:1.13	Sun Aug 19 09:18:48 2018
+++ src/sys/arch/arm/broadcom/bcm2835_mbox.c	Mon Dec 30 18:43:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2835_mbox.c,v 1.13 2018/08/19 09:18:48 rin Exp $	*/
+/*	$NetBSD: bcm2835_mbox.c,v 1.14 2019/12/30 18:43:38 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox.c,v 1.13 2018/08/19 09:18:48 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox.c,v 1.14 2019/12/30 18:43:38 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -43,103 +43,10 @@ __KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox
 #include <arm/broadcom/bcm2835_mbox.h>
 #include <arm/broadcom/bcm2835_mboxreg.h>
 #include <arm/broadcom/bcm2835reg.h>
-
-#include <dev/fdt/fdtvar.h>
-
-struct bcm2835mbox_softc {
-	device_t sc_dev;
-	device_t sc_platdev;
-
-	bus_space_tag_t sc_iot;
-	bus_space_handle_t sc_ioh;
-	bus_dma_tag_t sc_dmat;
-	void *sc_intrh;
-
-	kmutex_t sc_lock;
-	kmutex_t sc_intr_lock;
-	kcondvar_t sc_chan[BCM2835_MBOX_NUMCHANNELS];
-	uint32_t sc_mbox[BCM2835_MBOX_NUMCHANNELS];
-};
+#include <arm/broadcom/bcm2835var.h>
 
 static struct bcm2835mbox_softc *bcm2835mbox_sc;
 
-static int bcmmbox_match(device_t, cfdata_t, void *);
-static void bcmmbox_attach(device_t, device_t, void *);
-static int bcmmbox_intr1(struct bcm2835mbox_softc *, int);
-static int bcmmbox_intr(void *);
-
-CFATTACH_DECL_NEW(bcmmbox, sizeof(struct bcm2835mbox_softc),
-    bcmmbox_match, bcmmbox_attach, NULL, NULL);
-
-/* ARGSUSED */
-static int
-bcmmbox_match(device_t parent, cfdata_t match, void *aux)
-{
-	const char * const compatible[] = { "brcm,bcm2835-mbox", NULL };
-	struct fdt_attach_args * const faa = aux;
-
-	return of_match_compatible(faa->faa_phandle, compatible);
-}
-
-static void
-bcmmbox_attach(device_t parent, device_t self, void *aux)
-{
-	struct bcm2835mbox_softc *sc = device_private(self);
-	struct fdt_attach_args * const faa = aux;
-	struct bcmmbox_attach_args baa;
-	const int phandle = faa->faa_phandle;
-	int i;
-
-	aprint_naive("\n");
-	aprint_normal(": VC mailbox\n");
-
-	sc->sc_dev = self;
-	sc->sc_iot = faa->faa_bst;
-	sc->sc_dmat = faa->faa_dmat;
-	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
-	mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_VM);
-	for (i = 0; i < BCM2835_MBOX_NUMCHANNELS; ++i)
-		cv_init(&sc->sc_chan[i], "bcmmbox");
-
-	bus_addr_t addr;
-	bus_size_t size;
-
-	if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
-		aprint_error(": couldn't get register address\n");
-		return;
-	}
-
-	if (bus_space_map(faa->faa_bst, addr, size, 0, &sc->sc_ioh) != 0) {
-		aprint_error_dev(sc->sc_dev, "unable to map device\n");
-		return;
-	}
-
-	char intrstr[128];
-	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
-		aprint_error(": failed to decode interrupt\n");
-		return;
-	}
-
-	sc->sc_intrh = fdtbus_intr_establish(phandle, 0, IPL_VM, 0,
-	    bcmmbox_intr, sc);
-	if (sc->sc_intrh == NULL) {
-		aprint_error_dev(self, "failed to establish interrupt %s\n",
-		    intrstr);
-		return;
-	}
-	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
-
-	/* enable mbox interrupt */
-	bus_space_write_4(sc->sc_iot, sc->sc_ioh, BCM2835_MBOX_CFG,
-	    BCM2835_MBOX_CFG_DATAIRQEN);
-
-	if (bcm2835mbox_sc == NULL)
-		bcm2835mbox_sc = sc;
-
-	baa.baa_dmat = sc->sc_dmat;
-	sc->sc_platdev = config_found_ia(self, "bcmmboxbus", &baa, NULL);
-}
-
 static int
 bcmmbox_intr1(struct bcm2835mbox_softc *sc, int cv)
 {
@@ -175,7 +82,29 @@ bcmmbox_intr1(struct bcm2835mbox_softc *
 	return ret;
 }
 
-static int
+void
+bcmmbox_attach(struct bcm2835mbox_softc *sc)
+{
+	struct bcmmbox_attach_args baa;
+	int i;
+
+	if (bcm2835mbox_sc == NULL)
+		bcm2835mbox_sc = sc;
+
+	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
+	mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_VM);
+	for (i = 0; i < BCM2835_MBOX_NUMCHANNELS; ++i)
+		cv_init(&sc->sc_chan[i], "bcmmbox");
+
+	/* enable mbox interrupt */
+	bus_space_write_4(sc->sc_iot, sc->sc_ioh, BCM2835_MBOX_CFG,
+	    BCM2835_MBOX_CFG_DATAIRQEN);
+
+	baa.baa_dmat = sc->sc_dmat;
+	sc->sc_platdev = config_found_ia(sc->sc_dev, "bcmmboxbus", &baa, NULL);
+}
+
+int
 bcmmbox_intr(void *cookie)
 {
 	struct bcm2835mbox_softc *sc = cookie;

Index: src/sys/arch/arm/broadcom/bcm2835_mbox.h
diff -u src/sys/arch/arm/broadcom/bcm2835_mbox.h:1.5 src/sys/arch/arm/broadcom/bcm2835_mbox.h:1.6
--- src/sys/arch/arm/broadcom/bcm2835_mbox.h:1.5	Tue Oct  7 08:30:05 2014
+++ src/sys/arch/arm/broadcom/bcm2835_mbox.h	Mon Dec 30 18:43:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2835_mbox.h,v 1.5 2014/10/07 08:30:05 skrll Exp $	*/
+/*	$NetBSD: bcm2835_mbox.h,v 1.6 2019/12/30 18:43:38 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -43,11 +43,28 @@
 #define	BCM2835_MBOX_MSG(chan, data) \
     (BCM2835_MBOX_CHAN(chan) | BCM2835_MBOX_DATA(data))
 
+struct bcm2835mbox_softc {
+	device_t sc_dev;
+	device_t sc_platdev;
+
+	bus_space_tag_t sc_iot;
+	bus_space_handle_t sc_ioh;
+	bus_dma_tag_t sc_dmat;
+	void *sc_intrh;
+
+	kmutex_t sc_lock;
+	kmutex_t sc_intr_lock;
+	kcondvar_t sc_chan[BCM2835_MBOX_NUMCHANNELS];
+	uint32_t sc_mbox[BCM2835_MBOX_NUMCHANNELS];
+};
+
 void bcm2835_mbox_read(bus_space_tag_t, bus_space_handle_t, uint8_t,
     uint32_t *);
 void bcm2835_mbox_write(bus_space_tag_t, bus_space_handle_t, uint8_t,
     uint32_t);
 
+void bcmmbox_attach(struct bcm2835mbox_softc *);
+int bcmmbox_intr(void *);
 void bcmmbox_read(uint8_t, uint32_t *);
 void bcmmbox_write(uint8_t, uint32_t);
 

Index: src/sys/arch/arm/broadcom/files.bcm2835
diff -u src/sys/arch/arm/broadcom/files.bcm2835:1.35 src/sys/arch/arm/broadcom/files.bcm2835:1.36
--- src/sys/arch/arm/broadcom/files.bcm2835:1.35	Wed Sep  4 05:10:38 2019
+++ src/sys/arch/arm/broadcom/files.bcm2835	Mon Dec 30 18:43:38 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: files.bcm2835,v 1.35 2019/09/04 05:10:38 mlelstv Exp $
+#	$NetBSD: files.bcm2835,v 1.36 2019/12/30 18:43:38 jmcneill Exp $
 #
 # Configuration info for Broadcom BCM2835 ARM Peripherals
 #
@@ -16,8 +16,11 @@ file	arch/arm/broadcom/bcm2835_intr.c	bc
 
 # VC Mailbox (BCM2835_ARMMBOX_BASE)
 device	bcmmbox: bcmmboxbus
-attach	bcmmbox at fdt with bcmmbox
 file	arch/arm/broadcom/bcm2835_mbox.c	bcmmbox
+attach	bcmmbox at fdt with bcmmbox_fdt
+file    arch/arm/broadcom/bcm2835_mbox_fdt.c	bcmmbox_fdt
+attach  bcmmbox at acpinodebus with bcmmbox_acpi
+file	arch/arm/broadcom/bcm2835_mbox_acpi.c	bcmmbox_acpi
 
 # System Timer (BCM2835_TIMER_BASE)
 device	bcmtmr

Added files:

Index: src/sys/arch/arm/broadcom/bcm2835_mbox_acpi.c
diff -u /dev/null src/sys/arch/arm/broadcom/bcm2835_mbox_acpi.c:1.1
--- /dev/null	Mon Dec 30 18:43:38 2019
+++ src/sys/arch/arm/broadcom/bcm2835_mbox_acpi.c	Mon Dec 30 18:43:38 2019
@@ -0,0 +1,114 @@
+/*	$NetBSD: bcm2835_mbox_acpi.c,v 1.1 2019/12/30 18:43:38 jmcneill Exp $	*/
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nick Hudson
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox_acpi.c,v 1.1 2019/12/30 18:43:38 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
+#include <sys/timetc.h>
+#include <sys/bus.h>
+#include <sys/mutex.h>
+
+#include <arm/broadcom/bcm2835_mbox.h>
+#include <arm/broadcom/bcm2835_mboxreg.h>
+#include <arm/broadcom/bcm2835reg.h>
+#include <arm/broadcom/bcm2835var.h>
+
+#include <dev/acpi/acpivar.h>
+#include <dev/acpi/acpi_intr.h>
+#include <arch/evbarm/rpi/vcprop.h>
+#include <arch/evbarm/rpi/vcio.h>
+#include <arch/evbarm/rpi/vcpm.h>
+
+static int bcmmbox_acpi_match(device_t, cfdata_t, void *);
+static void bcmmbox_acpi_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(bcmmbox_acpi, sizeof(struct bcm2835mbox_softc),
+    bcmmbox_acpi_match, bcmmbox_acpi_attach, NULL, NULL);
+
+static int
+bcmmbox_acpi_match(device_t parent, cfdata_t match, void *aux)
+{
+	const char * const acpi_compatible[] = {
+		"BCM2849",
+		NULL
+	};
+	struct acpi_attach_args * const aa = aux;
+
+	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
+		return 0;
+
+	return acpi_match_hid(aa->aa_node->ad_devinfo, acpi_compatible);
+}
+
+static void
+bcmmbox_acpi_attach(device_t parent, device_t self, void *aux)
+{
+	struct bcm2835mbox_softc *sc = device_private(self);
+	struct acpi_attach_args * const aa = aux;
+	struct acpi_resources res;
+	struct acpi_mem *mem;
+	struct acpi_irq *irq;
+	ACPI_STATUS rv;
+
+	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
+	    &res, &acpi_resource_parse_ops_default);
+	if (ACPI_FAILURE(rv))
+		return;
+
+	mem = acpi_res_mem(&res, 0);
+	irq = acpi_res_irq(&res, 0);
+	if (mem == NULL || irq == NULL) {
+		aprint_error_dev(self, "couldn't find resources\n");
+		return;
+	}
+
+	sc->sc_dev = self;
+	sc->sc_iot = aa->aa_memt;
+	sc->sc_dmat = aa->aa_dmat;
+
+	if (bus_space_map(sc->sc_iot, mem->ar_base, mem->ar_length, 0, &sc->sc_ioh) != 0) {
+		aprint_error_dev(sc->sc_dev, "unable to map device\n");
+		return;
+	}
+
+	sc->sc_intrh = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
+	    IPL_VM, false, bcmmbox_intr, sc, device_xname(self));
+	if (sc->sc_intrh == NULL) {
+		aprint_error_dev(self, "failed to establish interrupt\n");
+		return;
+	}
+
+	bcmmbox_attach(sc);
+}
Index: src/sys/arch/arm/broadcom/bcm2835_mbox_fdt.c
diff -u /dev/null src/sys/arch/arm/broadcom/bcm2835_mbox_fdt.c:1.1
--- /dev/null	Mon Dec 30 18:43:38 2019
+++ src/sys/arch/arm/broadcom/bcm2835_mbox_fdt.c	Mon Dec 30 18:43:38 2019
@@ -0,0 +1,108 @@
+/*	$NetBSD: bcm2835_mbox_fdt.c,v 1.1 2019/12/30 18:43:38 jmcneill Exp $	*/
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nick Hudson
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox_fdt.c,v 1.1 2019/12/30 18:43:38 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
+#include <sys/timetc.h>
+#include <sys/bus.h>
+#include <sys/mutex.h>
+
+#include <arm/broadcom/bcm2835_mbox.h>
+#include <arm/broadcom/bcm2835_mboxreg.h>
+#include <arm/broadcom/bcm2835reg.h>
+#include <arm/broadcom/bcm2835var.h>
+
+#include <dev/fdt/fdtvar.h>
+
+static int bcmmbox_fdt_match(device_t, cfdata_t, void *);
+static void bcmmbox_fdt_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(bcmmbox_fdt, sizeof(struct bcm2835mbox_softc),
+    bcmmbox_fdt_match, bcmmbox_fdt_attach, NULL, NULL);
+
+/* ARGSUSED */
+static int
+bcmmbox_fdt_match(device_t parent, cfdata_t match, void *aux)
+{
+	const char * const compatible[] = { "brcm,bcm2835-mbox", NULL };
+	struct fdt_attach_args * const faa = aux;
+
+	return of_match_compatible(faa->faa_phandle, compatible);
+}
+
+static void
+bcmmbox_fdt_attach(device_t parent, device_t self, void *aux)
+{
+	struct bcm2835mbox_softc *sc = device_private(self);
+	struct fdt_attach_args * const faa = aux;
+	const int phandle = faa->faa_phandle;
+	char intrstr[128];
+	bus_addr_t addr;
+	bus_size_t size;
+
+	sc->sc_dev = self;
+	sc->sc_iot = faa->faa_bst;
+	sc->sc_dmat = faa->faa_dmat;
+
+	if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
+		aprint_error(": couldn't get register address\n");
+		return;
+	}
+
+	if (bus_space_map(faa->faa_bst, addr, size, 0, &sc->sc_ioh) != 0) {
+		aprint_error_dev(sc->sc_dev, "unable to map device\n");
+		return;
+	}
+
+	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
+		aprint_error(": failed to decode interrupt\n");
+		return;
+	}
+
+	aprint_naive("\n");
+	aprint_normal(": VC mailbox\n");
+
+	sc->sc_intrh = fdtbus_intr_establish(phandle, 0, IPL_VM, 0,
+	    bcmmbox_intr, sc);
+	if (sc->sc_intrh == NULL) {
+		aprint_error_dev(self, "failed to establish interrupt %s\n",
+		    intrstr);
+		return;
+	}
+	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
+
+	bcmmbox_attach(sc);
+}

Reply via email to