Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/amlogic add hardware rng support



details:   https://anonhg.NetBSD.org/src/rev/8dac0ad45b79
branches:  trunk
changeset: 806758:8dac0ad45b79
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Mar 07 21:34:25 2015 +0000

description:
add hardware rng support

diffstat:

 sys/arch/arm/amlogic/amlogic_io.c  |   15 +++-
 sys/arch/arm/amlogic/amlogic_rng.c |  111 +++++++++++++++++++++++++++++++++++++
 sys/arch/arm/amlogic/files.amlogic |   17 +++--
 3 files changed, 133 insertions(+), 10 deletions(-)

diffs (206 lines):

diff -r 0c190cd794dc -r 8dac0ad45b79 sys/arch/arm/amlogic/amlogic_io.c
--- a/sys/arch/arm/amlogic/amlogic_io.c Sat Mar 07 21:33:12 2015 +0000
+++ b/sys/arch/arm/amlogic/amlogic_io.c Sat Mar 07 21:34:25 2015 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 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 @@
   { "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
 };
 
diff -r 0c190cd794dc -r 8dac0ad45b79 sys/arch/arm/amlogic/amlogic_rng.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/amlogic/amlogic_rng.c        Sat Mar 07 21:34:25 2015 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
+ * 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);
+}
diff -r 0c190cd794dc -r 8dac0ad45b79 sys/arch/arm/amlogic/files.amlogic
--- a/sys/arch/arm/amlogic/files.amlogic        Sat Mar 07 21:33:12 2015 +0000
+++ b/sys/arch/arm/amlogic/files.amlogic        Sat Mar 07 21:34:25 2015 +0000
@@ -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 @@
 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 @@
 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



Home | Main Index | Thread Index | Old Index