Module Name: src
Committed By: jmcneill
Date: Sat Mar 7 21:34:26 UTC 2015
Modified Files:
src/sys/arch/arm/amlogic: amlogic_io.c files.amlogic
Added Files:
src/sys/arch/arm/amlogic: amlogic_rng.c
Log Message:
add hardware rng support
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/amlogic/amlogic_io.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/amlogic/amlogic_rng.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/amlogic/files.amlogic
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/amlogic/amlogic_io.c
diff -u src/sys/arch/arm/amlogic/amlogic_io.c:1.4 src/sys/arch/arm/amlogic/amlogic_io.c:1.5
--- src/sys/arch/arm/amlogic/amlogic_io.c:1.4 Wed Mar 4 12:36:12 2015
+++ src/sys/arch/arm/amlogic/amlogic_io.c Sat Mar 7 21:34:25 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_io.c,v 1.4 2015/03/04 12:36:12 jmcneill Exp $ */
+/* $NetBSD: amlogic_io.c,v 1.5 2015/03/07 21:34:25 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -29,7 +29,7 @@
#include "opt_amlogic.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amlogic_io.c,v 1.4 2015/03/04 12:36:12 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amlogic_io.c,v 1.5 2015/03/07 21:34:25 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -56,12 +56,19 @@ static int amlogicio_find(device_t, cfda
static bool amlogicio_found = false;
#define NOPORT AMLOGICIOCF_PORT_DEFAULT
+#define NOINTR AMLOGICIO_INTR_DEFAULT
static const struct amlogic_locators amlogic_locators[] = {
{ "amlogiccom",
AMLOGIC_UART0AO_OFFSET, AMLOGIC_UART_SIZE, 0, AMLOGIC_INTR_UART0AO },
{ "amlogiccom",
AMLOGIC_UART2AO_OFFSET, AMLOGIC_UART_SIZE, 2, AMLOGIC_INTR_UART2AO },
+#if notyet
+ { "genfb",
+ AMLOGIC_DMC_OFFSET, AMLOGIC_DMC_SIZE, NOPORT, NOINTR },
+#endif
+ { "amlogicrng",
+ AMLOGIC_RAND_OFFSET, AMLOGIC_RAND_SIZE, NOPORT, NOINTR },
{ "dwctwo",
AMLOGIC_USB0_OFFSET, AMLOGIC_USB_SIZE, 0, AMLOGIC_INTR_USB0 },
{ "dwctwo",
@@ -69,8 +76,8 @@ static const struct amlogic_locators aml
{ "awge",
AMLOGIC_GMAC_OFFSET, AMLOGIC_GMAC_SIZE, NOPORT, AMLOGIC_INTR_GMAC },
#if notyet
- { "amlogicmmc",
- AMLOGIC_MMC_OFFSET, AMLOGIC_MMC_SIZE, 0, AMLOGIC_INTR_MMC },
+ { "amlogicsdhc",
+ AMLOGIC_SDHC_OFFSET, AMLOGIC_SDHC_SIZE, 0, AMLOGIC_INTR_SDHC },
#endif
};
Index: src/sys/arch/arm/amlogic/files.amlogic
diff -u src/sys/arch/arm/amlogic/files.amlogic:1.5 src/sys/arch/arm/amlogic/files.amlogic:1.6
--- src/sys/arch/arm/amlogic/files.amlogic:1.5 Thu Mar 5 23:43:53 2015
+++ src/sys/arch/arm/amlogic/files.amlogic Sat Mar 7 21:34:25 2015
@@ -1,4 +1,4 @@
-# $NetBSD: files.amlogic,v 1.5 2015/03/05 23:43:53 jmcneill Exp $
+# $NetBSD: files.amlogic,v 1.6 2015/03/07 21:34:25 jmcneill Exp $
#
# Configuration info for Amlogic ARM Peripherals
#
@@ -21,15 +21,15 @@ device amlogicio { [port=-1] } : bus_spa
attach amlogicio at mainbus with amlogic_io
file arch/arm/amlogic/amlogic_io.c amlogic_io
-# serial
+# UART
device amlogiccom
attach amlogiccom at amlogicio with amlogic_com
file arch/arm/amlogic/amlogic_com.c amlogic_com needs-flag
-# mmc/sd/sdio
-device amlogicmmc: sdmmcbus
-attach amlogicmmc at amlogicio with amlogic_mmc
-file arch/arm/amlogic/amlogic_mmc.c amlogic_mmc
+# SDHC
+device amlogicsdhc: sdmmcbus
+attach amlogicsdhc at amlogicio with amlogic_sdhc
+file arch/arm/amlogic/amlogic_sdhc.c amlogic_sdhc
# usb otg
attach dwctwo at amlogicio with amlogic_dwctwo
@@ -39,6 +39,11 @@ file arch/arm/amlogic/amlogic_dwctwo.c a
attach awge at amlogicio with amlogic_gmac
file arch/arm/amlogic/amlogic_gmac.c amlogic_gmac
+# Hardware random number generator
+device amlogicrng
+attach amlogicrng at amlogicio with amlogic_rng
+file arch/arm/amlogic/amlogic_rng.c amlogic_rng
+
# Console parameters
defparam opt_amlogic.h CONADDR
defparam opt_amlogic.h CONSPEED
Added files:
Index: src/sys/arch/arm/amlogic/amlogic_rng.c
diff -u /dev/null src/sys/arch/arm/amlogic/amlogic_rng.c:1.1
--- /dev/null Sat Mar 7 21:34:26 2015
+++ src/sys/arch/arm/amlogic/amlogic_rng.c Sat Mar 7 21:34:25 2015
@@ -0,0 +1,111 @@
+/* $NetBSD: amlogic_rng.c,v 1.1 2015/03/07 21:34:25 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2015 Jared D. McNeill <[email protected]>
+ * 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 "locators.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: amlogic_rng.c,v 1.1 2015/03/07 21:34:25 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/mutex.h>
+#include <sys/callout.h>
+#include <sys/rnd.h>
+
+#include <arm/amlogic/amlogic_reg.h>
+#include <arm/amlogic/amlogic_var.h>
+
+static int amlogic_rng_match(device_t, cfdata_t, void *);
+static void amlogic_rng_attach(device_t, device_t, void *);
+
+static void amlogic_rng_callout(void *);
+
+struct amlogic_rng_softc {
+ device_t sc_dev;
+ bus_space_tag_t sc_bst;
+ bus_space_handle_t sc_bsh;
+
+ void * sc_sih;
+
+ callout_t sc_tick;
+ krndsource_t sc_rndsource;
+ size_t sc_bytes_wanted;
+};
+
+CFATTACH_DECL_NEW(amlogic_rng, sizeof(struct amlogic_rng_softc),
+ amlogic_rng_match, amlogic_rng_attach, NULL, NULL);
+
+static int
+amlogic_rng_match(device_t parent, cfdata_t cf, void *aux)
+{
+ return 1;
+}
+
+static void
+amlogic_rng_attach(device_t parent, device_t self, void *aux)
+{
+ struct amlogic_rng_softc * const sc = device_private(self);
+ struct amlogicio_attach_args * const aio = aux;
+ const struct amlogic_locators * const loc = &aio->aio_loc;
+
+ sc->sc_dev = self;
+ sc->sc_bst = aio->aio_core_bst;
+ bus_space_subregion(aio->aio_core_bst, aio->aio_bsh,
+ loc->loc_offset, loc->loc_size, &sc->sc_bsh);
+
+ callout_init(&sc->sc_tick, CALLOUT_MPSAFE);
+ callout_setfunc(&sc->sc_tick, amlogic_rng_callout, sc);
+
+ amlogic_rng_init();
+
+ aprint_naive("\n");
+ aprint_normal("\n");
+
+ rnd_attach_source(&sc->sc_rndsource, device_xname(self), RND_TYPE_RNG,
+ RND_FLAG_COLLECT_VALUE);
+
+ amlogic_rng_callout(sc);
+}
+
+static void
+amlogic_rng_callout(void *priv)
+{
+ struct amlogic_rng_softc * const sc = priv;
+ uint32_t data[2];
+
+ bus_space_read_region_4(sc->sc_bst, sc->sc_bsh, 0, data, 2);
+ rnd_add_data(&sc->sc_rndsource, data, sizeof(data),
+ sizeof(data) * NBBY);
+
+ explicit_memset(data, 0, sizeof(data));
+
+ callout_schedule(&sc->sc_tick, 1);
+}