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 Add BCM2835 RNG support.
details: https://anonhg.NetBSD.org/src/rev/dd49556a5742
branches: trunk
changeset: 784315:dd49556a5742
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Fri Jan 25 00:04:06 2013 +0000
description:
Add BCM2835 RNG support.
diffstat:
sys/arch/arm/broadcom/bcm2835_obio.c | 11 ++-
sys/arch/arm/broadcom/bcm2835_rng.c | 140 +++++++++++++++++++++++++++++++++++
sys/arch/arm/broadcom/bcm2835reg.h | 4 +-
sys/arch/arm/broadcom/files.bcm2835 | 7 +-
4 files changed, 158 insertions(+), 4 deletions(-)
diffs (222 lines):
diff -r 3cc3eb32dcbd -r dd49556a5742 sys/arch/arm/broadcom/bcm2835_obio.c
--- a/sys/arch/arm/broadcom/bcm2835_obio.c Thu Jan 24 19:55:28 2013 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_obio.c Fri Jan 25 00:04:06 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835_obio.c,v 1.11 2013/01/09 22:23:44 skrll Exp $ */
+/* $NetBSD: bcm2835_obio.c,v 1.12 2013/01/25 00:04:06 jmcneill 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.11 2013/01/09 22:23:44 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_obio.c,v 1.12 2013/01/25 00:04:06 jmcneill Exp $");
#include "locators.h"
#include "obio.h"
@@ -98,6 +98,13 @@
.ad_intr = -1,
},
{
+ /* Random number generator */
+ .ad_name = "bcmrng",
+ .ad_addr = BCM2835_RNG_BASE,
+ .ad_size = BCM2835_RNG_SIZE,
+ .ad_intr = -1,
+ },
+ {
/* Uart 0 */
.ad_name = "plcom",
.ad_addr = BCM2835_UART0_BASE,
diff -r 3cc3eb32dcbd -r dd49556a5742 sys/arch/arm/broadcom/bcm2835_rng.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_rng.c Fri Jan 25 00:04:06 2013 +0000
@@ -0,0 +1,140 @@
+/* $NetBSD: bcm2835_rng.c,v 1.1 2013/01/25 00:04:06 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared D. McNeill
+ *
+ * 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_rng.c,v 1.1 2013/01/25 00:04:06 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+#include <sys/rnd.h>
+
+#include <arm/broadcom/bcm_amba.h>
+#include <arm/broadcom/bcm2835reg.h>
+#include <arm/broadcom/bcm2835_intr.h>
+
+#define RNG_CTRL 0x00
+#define RNG_CTRL_EN __BIT(0)
+#define RNG_STATUS 0x04
+#define RNG_STATUS_CNT_MASK __BITS(31,24)
+#define RNG_STATUS_CNT_SHIFT 24
+#define RNG_DATA 0x08
+
+#define RNG_DATA_MAX 256
+
+struct bcm2835rng_softc {
+ device_t sc_dev;
+
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_ioh;
+
+ krndsource_t sc_rnd;
+ callout_t sc_tick;
+
+ uint32_t sc_data[RNG_DATA_MAX];
+};
+
+static int bcmrng_match(device_t, cfdata_t, void *);
+static void bcmrng_attach(device_t, device_t, void *);
+
+static void bcmrng_tick(void *);
+
+CFATTACH_DECL_NEW(bcmrng_amba, sizeof(struct bcm2835rng_softc),
+ bcmrng_match, bcmrng_attach, NULL, NULL);
+
+/* ARGSUSED */
+static int
+bcmrng_match(device_t parent, cfdata_t match, void *aux)
+{
+ struct amba_attach_args *aaa = aux;
+
+ if (strcmp(aaa->aaa_name, "bcmrng") != 0)
+ return 0;
+
+ return 1;
+}
+
+static void
+bcmrng_attach(device_t parent, device_t self, void *aux)
+{
+ struct bcm2835rng_softc *sc = device_private(self);
+ struct amba_attach_args *aaa = aux;
+ uint32_t ctrl;
+
+ aprint_naive("\n");
+ aprint_normal(": RNG\n");
+
+ sc->sc_dev = self;
+ sc->sc_iot = aaa->aaa_iot;
+
+ if (bus_space_map(aaa->aaa_iot, aaa->aaa_addr, BCM2835_RNG_SIZE, 0,
+ &sc->sc_ioh)) {
+ aprint_error_dev(sc->sc_dev, "unable to map device\n");
+ return;
+ }
+
+ rnd_attach_source(&sc->sc_rnd, device_xname(self), RND_TYPE_RNG,
+ RND_FLAG_NO_ESTIMATE);
+
+ callout_init(&sc->sc_tick, CALLOUT_MPSAFE);
+ callout_setfunc(&sc->sc_tick, bcmrng_tick, sc);
+
+ /* enable rng */
+ ctrl = bus_space_read_4(sc->sc_iot, sc->sc_ioh, RNG_CTRL);
+ ctrl |= RNG_CTRL_EN;
+ bus_space_write_4(sc->sc_iot, sc->sc_ioh, RNG_CTRL, ctrl);
+
+ /* start timer */
+ bcmrng_tick(sc);
+}
+
+static void
+bcmrng_tick(void *priv)
+{
+ struct bcm2835rng_softc *sc = priv;
+ uint32_t status;
+ int cnt, i;
+
+ status = bus_space_read_4(sc->sc_iot, sc->sc_ioh, RNG_STATUS);
+ cnt = (status & RNG_STATUS_CNT_MASK) >> RNG_STATUS_CNT_SHIFT;
+ for (i = 0; i < cnt; i++) {
+ sc->sc_data[i] = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
+ RNG_DATA);
+ }
+ if (cnt > 0) {
+ rnd_add_data(&sc->sc_rnd, sc->sc_data,
+ cnt * 4, cnt * 4 * NBBY);
+ }
+
+ callout_schedule(&sc->sc_tick, 1);
+}
diff -r 3cc3eb32dcbd -r dd49556a5742 sys/arch/arm/broadcom/bcm2835reg.h
--- a/sys/arch/arm/broadcom/bcm2835reg.h Thu Jan 24 19:55:28 2013 +0000
+++ b/sys/arch/arm/broadcom/bcm2835reg.h Fri Jan 25 00:04:06 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835reg.h,v 1.7 2013/01/08 21:58:40 skrll Exp $ */
+/* $NetBSD: bcm2835reg.h,v 1.8 2013/01/25 00:04:06 jmcneill Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -45,6 +45,7 @@
#define BCM2835_DMA0_BASE (BCM2835_PERIPHERALS_BASE + 0x00007000)
#define BCM2835_ARM_BASE (BCM2835_PERIPHERALS_BASE + 0x0000B000)
#define BCM2835_PM_BASE (BCM2835_PERIPHERALS_BASE + 0x00100000)
+#define BCM2835_RNG_BASE (BCM2835_PERIPHERALS_BASE + 0x00104000)
#define BCM2835_GPIO_BASE (BCM2835_PERIPHERALS_BASE + 0x00200000)
#define BCM2835_UART0_BASE (BCM2835_PERIPHERALS_BASE + 0x00201000)
#define BCM2835_PCM_BASE (BCM2835_PERIPHERALS_BASE + 0x00203000)
@@ -62,6 +63,7 @@
#define BCM2835_DMA0_SIZE 0x1000
#define BCM2835_ARM_SIZE 0x1000
#define BCM2835_PM_SIZE 0x1000
+#define BCM2835_RNG_SIZE 0x1000
#define BCM2835_GPIO_SIZE 0x1000
#define BCM2835_UART0_SIZE 0x90
#define BCM2835_PCM_SIZE 0x1000
diff -r 3cc3eb32dcbd -r dd49556a5742 sys/arch/arm/broadcom/files.bcm2835
--- a/sys/arch/arm/broadcom/files.bcm2835 Thu Jan 24 19:55:28 2013 +0000
+++ b/sys/arch/arm/broadcom/files.bcm2835 Fri Jan 25 00:04:06 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.bcm2835,v 1.13 2013/01/10 02:23:26 jmcneill Exp $
+# $NetBSD: files.bcm2835,v 1.14 2013/01/25 00:04:06 jmcneill Exp $
#
# Configuration info for Broadcom BCM2835 ARM Peripherals
#
@@ -42,6 +42,11 @@
attach bcmpm at obio with bcmpm_amba
file arch/arm/broadcom/bcm2835_pm.c bcmpm
+# Random number generator (BCM2835_RNG_BASE)
+device bcmrng
+attach bcmrng at obio with bcmrng_amba
+file arch/arm/broadcom/bcm2835_rng.c bcmrng
+
# UART Interface (BCM2835_UART0_BASE)
attach plcom at obio with bcmplcom
file arch/arm/broadcom/bcm2835_plcom.c bcmplcom
Home |
Main Index |
Thread Index |
Old Index