1 /* $OpenBSD: ccp.c,v 1.11 2024/09/04 07:45:08 jsg 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/device.h>
22 #include <sys/timeout.h>
23
24 #include <machine/bus.h>
25
26 #include <dev/ic/ccpvar.h>
27
28 #define CCP_REG_TRNG 0xc
29
30 static void ccp_rng(void *);
31
32 struct cfdriver ccp_cd = {
33 NULL,
34 "ccp",
35 DV_DULL
36 };
37
38 void
ccp_attach(struct ccp_softc * sc)39 ccp_attach(struct ccp_softc *sc)
40 {
41 timeout_set(&sc->sc_tick, ccp_rng, sc);
42 ccp_rng(sc);
43
44 printf("\n");
45 }
46
47 static void
ccp_rng(void * arg)48 ccp_rng(void *arg)
49 {
50 struct ccp_softc *sc = arg;
51 uint32_t trng;
52
53 trng = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CCP_REG_TRNG);
54 if (trng != 0)
55 enqueue_randomness(trng);
56
57 timeout_add_msec(&sc->sc_tick, 100);
58 }
59