Module Name:    src
Committed By:   skrll
Date:           Mon Aug 20 07:45:24 UTC 2012

Modified Files:
        src/sys/arch/arm/broadcom: bcm2835_obio.c bcm2835reg.h files.bcm2835
        src/sys/arch/evbarm/conf: RPI
Added Files:
        src/sys/arch/arm/broadcom: bcm2835_mbox.c bcm2835_mbox.h
            bcm2835_mboxreg.h

Log Message:
First pass at a VC mailbox driver.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/broadcom/bcm2835_mbox.c \
    src/sys/arch/arm/broadcom/bcm2835_mbox.h \
    src/sys/arch/arm/broadcom/bcm2835_mboxreg.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/broadcom/bcm2835_obio.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/broadcom/bcm2835reg.h \
    src/sys/arch/arm/broadcom/files.bcm2835
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/evbarm/conf/RPI

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_obio.c
diff -u src/sys/arch/arm/broadcom/bcm2835_obio.c:1.3 src/sys/arch/arm/broadcom/bcm2835_obio.c:1.4
--- src/sys/arch/arm/broadcom/bcm2835_obio.c:1.3	Fri Aug 17 09:44:30 2012
+++ src/sys/arch/arm/broadcom/bcm2835_obio.c	Mon Aug 20 07:45:24 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2835_obio.c,v 1.3 2012/08/17 09:44:30 skrll Exp $	*/
+/*	$NetBSD: bcm2835_obio.c,v 1.4 2012/08/20 07:45:24 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_obio.c,v 1.3 2012/08/17 09:44:30 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_obio.c,v 1.4 2012/08/20 07:45:24 skrll Exp $");
 
 #include "opt_broadcom.h"
 #include "locators.h"
@@ -78,6 +78,13 @@ static const struct ambadev_locators bcm
 		.ad_size = BCM2835_ARMICU_SIZE,
 		.ad_intr = -1,
 	},
+        {
+		/* Mailbox */
+		.ad_name = "bcmmbox",
+		.ad_addr = BCM2835_ARMMBOX_BASE,
+		.ad_size = BCM2835_ARMMBOX_SIZE,
+		.ad_intr = -1, /* BCM2835_INT_ARMMAILBOX */
+	},
 	{
 		/* System Timer */
 		.ad_name = "bcmtmr",

Index: src/sys/arch/arm/broadcom/bcm2835reg.h
diff -u src/sys/arch/arm/broadcom/bcm2835reg.h:1.1 src/sys/arch/arm/broadcom/bcm2835reg.h:1.2
--- src/sys/arch/arm/broadcom/bcm2835reg.h:1.1	Thu Jul 26 06:21:57 2012
+++ src/sys/arch/arm/broadcom/bcm2835reg.h	Mon Aug 20 07:45:24 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2835reg.h,v 1.1 2012/07/26 06:21:57 skrll Exp $	*/
+/*	$NetBSD: bcm2835reg.h,v 1.2 2012/08/20 07:45:24 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -65,6 +65,9 @@
 #define	BCM2835_ARMICU_BASE	(BCM2835_ARM_BASE + 0x0200)
 #define	BCM2835_ARMICU_SIZE	0x200
 
+#define	BCM2835_ARMMBOX_BASE	(BCM2835_ARM_BASE + 0x0880)
+#define	BCM2835_ARMMBOX_SIZE	0x40
+
 #define	BCM2835_ARMICU_VBASE	BCM2835_IOPHYSTOVIRT(BCM2835_ARMICU_BASE)
 
 #define	BCM2835_INTC_BASE	(0x0)	/* Relative to BCM2835_ARMICU_BASE */
Index: src/sys/arch/arm/broadcom/files.bcm2835
diff -u src/sys/arch/arm/broadcom/files.bcm2835:1.1 src/sys/arch/arm/broadcom/files.bcm2835:1.2
--- src/sys/arch/arm/broadcom/files.bcm2835:1.1	Thu Jul 26 06:21:57 2012
+++ src/sys/arch/arm/broadcom/files.bcm2835	Mon Aug 20 07:45:24 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: files.bcm2835,v 1.1 2012/07/26 06:21:57 skrll Exp $
+#	$NetBSD: files.bcm2835,v 1.2 2012/08/20 07:45:24 skrll Exp $
 #
 # Configuration info for Broadcom BCM2835 ARM Peripherals
 #
@@ -27,6 +27,11 @@ device	bcmicu: pic, pic_splfuncs
 attach	bcmicu at obio with bcmicu
 file	arch/arm/broadcom/bcm2835_intr.c	bcmicu
 
+# VC Mailbox (BCM2835_ARMMBOX_BASE)
+device	bcmmbox
+attach	bcmmbox at obio with bcmmbox
+file	arch/arm/broadcom/bcm2835_mbox.c	bcmmbox
+
 # System Timer (BCM2835_TIMER_BASE)
 device	bcmtmr
 attach	bcmtmr at obio with bcmtmr_amba

Index: src/sys/arch/evbarm/conf/RPI
diff -u src/sys/arch/evbarm/conf/RPI:1.3 src/sys/arch/evbarm/conf/RPI:1.4
--- src/sys/arch/evbarm/conf/RPI:1.3	Fri Aug 17 19:43:24 2012
+++ src/sys/arch/evbarm/conf/RPI	Mon Aug 20 07:45:24 2012
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: RPI,v 1.3 2012/08/17 19:43:24 abs Exp $
+#	$NetBSD: RPI,v 1.4 2012/08/20 07:45:24 skrll Exp $
 #
 #	RPi -- Raspberry Pi
 #
@@ -176,6 +176,9 @@ obio0		at mainbus?
 # Interrupt Controller
 bcmicu0		at obio?
 
+# VC Mailbox
+bcmmbox0	at obio?
+
 # PL011 uart
 plcom0		at obio?
 

Added files:

Index: src/sys/arch/arm/broadcom/bcm2835_mbox.c
diff -u /dev/null src/sys/arch/arm/broadcom/bcm2835_mbox.c:1.1
--- /dev/null	Mon Aug 20 07:45:24 2012
+++ src/sys/arch/arm/broadcom/bcm2835_mbox.c	Mon Aug 20 07:45:24 2012
@@ -0,0 +1,151 @@
+/*	$NetBSD: bcm2835_mbox.c,v 1.1 2012/08/20 07:45:24 skrll 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.c,v 1.1 2012/08/20 07:45:24 skrll 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 <arm/broadcom/bcm_amba.h>
+#include <arm/broadcom/bcm2835_mbox.h>
+#include <arm/broadcom/bcm2835_mboxreg.h>
+#include <arm/broadcom/bcm2835reg.h>
+
+struct bcm2835mbox_softc {
+	device_t sc_dev;
+
+	bus_space_tag_t sc_iot;
+	bus_space_handle_t sc_ioh;
+};
+
+static struct bcm2835mbox_softc *bcm2835mbox_sc;
+
+static int bcmmbox_match(device_t, cfdata_t, void *);
+static void bcmmbox_attach(device_t, device_t, 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)
+{
+	struct amba_attach_args *aaa = aux;
+
+	if (strcmp(aaa->aaa_name, "bcmmbox") != 0)
+		return 0;
+
+	return 1;
+}
+
+static void
+bcmmbox_attach(device_t parent, device_t self, void *aux)
+{
+        struct bcm2835mbox_softc *sc = device_private(self);
+ 	struct amba_attach_args *aaa = aux;
+
+	aprint_naive("\n");
+	aprint_normal(": VC mailbox\n");
+
+	if (bcm2835mbox_sc == NULL)
+		bcm2835mbox_sc = sc;
+	
+	sc->sc_dev = self;
+	sc->sc_iot = aaa->aaa_iot;
+
+	if (bus_space_map(aaa->aaa_iot, aaa->aaa_addr, BCM2835_MBOX_SIZE, 0,
+	    &sc->sc_ioh)) {
+		aprint_error_dev(sc->sc_dev, "unable to map device\n");
+		return;
+	}
+}
+
+void
+bcmmbox_read(uint8_t chan, uint32_t *data)
+{
+	struct bcm2835mbox_softc *sc = bcm2835mbox_sc;
+	uint32_t mbox;
+
+	KASSERT(sc != NULL);
+
+	for (;;) {
+		uint8_t rchan;
+		uint32_t rdata;
+
+		bus_space_barrier(sc->sc_iot, sc->sc_ioh, 0,
+		    BCM2835_MBOX_SIZE, BUS_SPACE_BARRIER_READ);
+
+		if ((bus_space_read_4(sc->sc_iot, sc->sc_ioh,
+		    BCM2835_MBOX0_STATUS) & BCM2835_MBOX_STATUS_EMPTY) != 0)
+			continue;
+
+		mbox = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
+		    BCM2835_MBOX0_READ);
+
+		rchan = BCM2835_MBOX_CHAN(mbox);
+		rdata = BCM2835_MBOX_DATA(mbox);
+
+		if (rchan == chan) {
+			*data = rdata;
+			return;
+		}
+	}
+}
+
+void
+bcmmbox_write(uint8_t chan, uint32_t data)
+{
+	struct bcm2835mbox_softc *sc = bcm2835mbox_sc;
+
+	KASSERT(sc != NULL);
+	uint32_t rdata;
+
+	for (;;) {
+
+		bus_space_barrier(sc->sc_iot, sc->sc_ioh, 0,
+		    BCM2835_MBOX_SIZE, BUS_SPACE_BARRIER_READ);
+
+		if ((rdata = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
+		    BCM2835_MBOX0_STATUS) & BCM2835_MBOX_STATUS_FULL) == 0)
+			break;
+	}
+
+	bus_space_write_4(sc->sc_iot, sc->sc_ioh,
+	    BCM2835_MBOX1_WRITE, BCM2835_MBOX_MSG(chan, data));
+
+	bus_space_barrier(sc->sc_iot, sc->sc_ioh, 0,
+	    BCM2835_MBOX_SIZE, BUS_SPACE_BARRIER_WRITE);
+}
Index: src/sys/arch/arm/broadcom/bcm2835_mbox.h
diff -u /dev/null src/sys/arch/arm/broadcom/bcm2835_mbox.h:1.1
--- /dev/null	Mon Aug 20 07:45:24 2012
+++ src/sys/arch/arm/broadcom/bcm2835_mbox.h	Mon Aug 20 07:45:24 2012
@@ -0,0 +1,43 @@
+/*	$NetBSD: bcm2835_mbox.h,v 1.1 2012/08/20 07:45:24 skrll 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.
+ */
+
+#ifndef _BCM2835_MBOX_H_
+#define	_BCM2835_MBOX_H_
+
+#define	BCM2835_MBOX_CHAN(mbox) ((mbox) & 0xf)
+#define	BCM2835_MBOX_DATA(mbox) ((mbox) & ~0xf)
+
+#define	BCM2835_MBOX_MSG(chan, data) (((chan) & 0xf) | ((data) << 4))
+
+void bcmmbox_read(uint8_t, uint32_t *);
+void bcmmbox_write(uint8_t, uint32_t);
+
+#endif /* _BCM2835_MBOX_H_ */
Index: src/sys/arch/arm/broadcom/bcm2835_mboxreg.h
diff -u /dev/null src/sys/arch/arm/broadcom/bcm2835_mboxreg.h:1.1
--- /dev/null	Mon Aug 20 07:45:24 2012
+++ src/sys/arch/arm/broadcom/bcm2835_mboxreg.h	Mon Aug 20 07:45:24 2012
@@ -0,0 +1,75 @@
+/*	$NetBSD: bcm2835_mboxreg.h,v 1.1 2012/08/20 07:45:24 skrll 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.
+ */
+
+#ifndef _BCM2835_MBOXREG_H_
+#define	_BCM2835_MBOXREG_H_
+
+/* mailbox 0 (from VC) and mailbox 1 (to VC) */
+#define	BCM2835_MBOX_SIZE	0x80
+
+#define	BCM2835_MBOX_READ	0x00
+#define	BCM2835_MBOX_WRITE	0x00
+#define	BCM2835_MBOX_POLL	0x10	/* read without popping the fifo */
+#define	BCM2835_MBOX_ID		0x14	/* sender ID (bottom two bits) */
+#define	BCM2835_MBOX_STATUS	0x18	/* status */
+#define	 BCM2835_MBOX_STATUS_FULL	0x80000000
+#define	 BCM2835_MBOX_STATUS_EMPTY	0x40000000
+#define	 BCM2835_MBOX_STATUS_LEVEL	0x400000FF
+#define	BCM2835_MBOX_CFG	0x1C	/* configuration */
+#define	 BCM2835_MBOX_CFG_DATAIRQEN		0x00000001
+#define	 BCM2835_MBOX_CFG_SPACEIRQEN		0x00000002
+#define	 BCM2835_MBOX_CFG_EMPTYOPIRQEN		0x00000004
+#define	 BCM2835_MBOX_CFG_MAILCLEAR		0x00000008
+#define	 BCM2835_MBOX_CFG_DATAPENDING		0x00000010
+#define	 BCM2835_MBOX_CFG_SPACEPENDING		0x00000020
+#define	 BCM2835_MBOX_CFG_EMPTYOPPENDING	0x00000040
+#define	 BCM2835_MBOX_CFG_ENOOWN		0x00000100
+#define	 BCM2835_MBOX_CFG_EOVERFLOW		0x00000200
+#define	 BCM2835_MBOX_CFG_EUNDERFLOW		0x00000400
+
+#define	BCM2835_MBOX0_BASE	0x00
+#define	BCM2835_MBOX1_BASE	0x20
+
+#define	BCM2835_MBOX0_READ	(BCM2835_MBOX0_BASE + BCM2835_MBOX_READ)
+#define	BCM2835_MBOX0_WRITE	(BCM2835_MBOX0_BASE + BCM2835_MBOX_WRITE)
+#define	BCM2835_MBOX0_POLL	(BCM2835_MBOX0_BASE + BCM2835_MBOX_POLL)
+#define	BCM2835_MBOX0_ID	(BCM2835_MBOX0_BASE + BCM2835_MBOX_ID)
+#define	BCM2835_MBOX0_STATUS	(BCM2835_MBOX0_BASE + BCM2835_MBOX_STATUS)
+#define	BCM2835_MBOX0_CFG	(BCM2835_MBOX0_BASE + BCM2835_MBOX_READ)
+
+#define	BCM2835_MBOX1_READ	(BCM2835_MBOX1_BASE + BCM2835_MBOX_READ)
+#define	BCM2835_MBOX1_WRITE	(BCM2835_MBOX1_BASE + BCM2835_MBOX_WRITE)
+#define	BCM2835_MBOX1_POLL	(BCM2835_MBOX1_BASE + BCM2835_MBOX_POLL)
+#define	BCM2835_MBOX1_ID	(BCM2835_MBOX1_BASE + BCM2835_MBOX_ID)
+#define	BCM2835_MBOX1_STATUS	(BCM2835_MBOX1_BASE + BCM2835_MBOX_STATUS)
+#define	BCM2835_MBOX1_CFG	(BCM2835_MBOX1_BASE + BCM2835_MBOX_READ)
+
+#endif /* _BCM2835_MBOXREG_H_ */

Reply via email to