Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arm/broadcom Split bcm2835 mbox driver into separat...
details: https://anonhg.NetBSD.org/src/rev/cc9662ee6693
branches: trunk
changeset: 967985:cc9662ee6693
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Mon Dec 30 18:43:38 2019 +0000
description:
Split bcm2835 mbox driver into separate fdt and acpi frontends.
diffstat:
sys/arch/arm/broadcom/bcm2835_mbox.c | 123 ++++++-----------------------
sys/arch/arm/broadcom/bcm2835_mbox.h | 19 ++++-
sys/arch/arm/broadcom/bcm2835_mbox_acpi.c | 114 +++++++++++++++++++++++++++
sys/arch/arm/broadcom/bcm2835_mbox_fdt.c | 108 ++++++++++++++++++++++++++
sys/arch/arm/broadcom/files.bcm2835 | 7 +-
5 files changed, 271 insertions(+), 100 deletions(-)
diffs (truncated from 444 to 300 lines):
diff -r 45893e113175 -r cc9662ee6693 sys/arch/arm/broadcom/bcm2835_mbox.c
--- a/sys/arch/arm/broadcom/bcm2835_mbox.c Mon Dec 30 18:28:06 2019 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_mbox.c Mon Dec 30 18:43:38 2019 +0000
@@ -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 @@
#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 @@
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;
diff -r 45893e113175 -r cc9662ee6693 sys/arch/arm/broadcom/bcm2835_mbox.h
--- a/sys/arch/arm/broadcom/bcm2835_mbox.h Mon Dec 30 18:28:06 2019 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_mbox.h Mon Dec 30 18:43:38 2019 +0000
@@ -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);
diff -r 45893e113175 -r cc9662ee6693 sys/arch/arm/broadcom/bcm2835_mbox_acpi.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_mbox_acpi.c Mon Dec 30 18:43:38 2019 +0000
@@ -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;
+ }
Home |
Main Index |
Thread Index |
Old Index