1 /* $OpenBSD: ccp.c,v 1.3 2020/05/29 04:42:25 deraadt Exp $ */ 2 3 /* 4 * Copyright (c) 2018 David Gwynne <dlg@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <sys/param.h> 20 #include <sys/systm.h> 21 #include <sys/buf.h> 22 #include <sys/device.h> 23 #include <sys/malloc.h> 24 #include <sys/kernel.h> 25 #include <sys/timeout.h> 26 27 #include <machine/bus.h> 28 29 #include <dev/ic/ccpvar.h> 30 31 #define CCP_REG_TRNG 0xc 32 33 static void ccp_rng(void *); 34 35 struct cfdriver ccp_cd = { 36 NULL, 37 "ccp", 38 DV_DULL 39 }; 40 41 void 42 ccp_attach(struct ccp_softc *sc) 43 { 44 timeout_set(&sc->sc_tick, ccp_rng, sc); 45 ccp_rng(sc); 46 47 printf("\n"); 48 } 49 50 static void 51 ccp_rng(void *arg) 52 { 53 struct ccp_softc *sc = arg; 54 uint32_t trng; 55 56 trng = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CCP_REG_TRNG); 57 if (trng != 0) 58 enqueue_randomness(trng); 59 60 timeout_add_msec(&sc->sc_tick, 100); 61 } 62