Lines Matching +full:rng +full:-
56 #define RNG_CTRL 0x00 /* RNG Control Register */
67 #define RNG_RBGEN_BIT 0x00000001 /* Enable RNG bit */
69 #define BCM2835_RNG_STATUS 0x04 /* BCM2835 RNG status register */
70 #define BCM2838_RNG_STATUS 0x18 /* BCM2838 RNG status register */
77 #define BCM2835_RND_VAL_WARM_CNT 0x40000 /* RNG Warm Up count */
78 #define BCM2835_RND_WARM_CNT 0xfffff /* RNG Warm Up Count mask */
80 #define BCM2835_RNG_DATA 0x08 /* RNG Data Register */
153 {"broadcom,bcm2835-rng", (uintptr_t)&bcm2835_rng_conf},
154 {"brcm,bcm2835-rng", (uintptr_t)&bcm2835_rng_conf},
156 {"brcm,bcm2711-rng200", (uintptr_t)&bcm2838_rng_conf},
157 {"brcm,bcm2838-rng", (uintptr_t)&bcm2838_rng_conf},
158 {"brcm,bcm2838-rng200", (uintptr_t)&bcm2838_rng_conf},
159 {"brcm,bcm7211-rng", (uintptr_t)&bcm2838_rng_conf},
160 {"brcm,bcm7278-rng", (uintptr_t)&bcm2838_rng_conf},
161 {"brcm,iproc-rng200", (uintptr_t)&bcm2838_rng_conf},
169 atomic_add_long(&sc->sc_underrun, 1); in bcm2835_rng_stat_inc_underrun()
176 return bus_read_4(sc->sc_mem_res, off); in bcm2835_rng_read4()
184 bus_read_multi_4(sc->sc_mem_res, off, datap, count); in bcm2835_rng_read_multi4()
191 bus_write_4(sc->sc_mem_res, off, val); in bcm2835_rng_write4()
200 if (!sc->conf->can_diagnose) in bcm2835_rng_dump_registers()
204 /* Display RNG control register contents */ in bcm2835_rng_dump_registers()
205 val = bcm2835_rng_read4(sc, sc->conf->control_reg); in bcm2835_rng_dump_registers()
228 "Use RNG clock (APB clock)"); in bcm2835_rng_dump_registers()
235 sbuf_cat(sbp, " RNG_RBG2X: RNG 2X SPEED enabled\n"); in bcm2835_rng_dump_registers()
240 /* Display RNG status register contents */ in bcm2835_rng_dump_registers()
241 val = bcm2835_rng_read4(sc, sc->conf->status_reg); in bcm2835_rng_dump_registers()
244 (val >> sc->conf->count_value_shift) & sc->conf->count_value_mask); in bcm2835_rng_dump_registers()
245 sbuf_printf(sbp, " RND_WARM_CNT: %05x\n", val & sc->conf->warmup_count); in bcm2835_rng_dump_registers()
252 val = bcm2835_rng_read4(sc, sc->conf->intr_mask_reg); in bcm2835_rng_dump_registers()
254 ((val & sc->conf->intr_disable_bit) != 0) ? "disabled" : "enabled"); in bcm2835_rng_dump_registers()
263 mask = bcm2835_rng_read4(sc, sc->conf->intr_mask_reg); in bcm2835_rng_disable_intr()
264 mask |= sc->conf->intr_disable_bit; in bcm2835_rng_disable_intr()
265 bcm2835_rng_write4(sc, sc->conf->intr_mask_reg, mask); in bcm2835_rng_disable_intr()
274 if (sc->conf->intr_mask_reg) in bcm2835_rng_start()
278 if (sc->conf->warmup_count > 0) in bcm2835_rng_start()
279 bcm2835_rng_write4(sc, sc->conf->status_reg, in bcm2835_rng_start()
280 sc->conf->warmup_count); in bcm2835_rng_start()
282 /* Enable the RNG */ in bcm2835_rng_start()
283 ctrl = bcm2835_rng_read4(sc, sc->conf->control_reg); in bcm2835_rng_start()
285 if (sc->sc_rbg2x && sc->conf->allow_2x_mode) in bcm2835_rng_start()
287 bcm2835_rng_write4(sc, sc->conf->control_reg, ctrl); in bcm2835_rng_start()
295 /* Disable the RNG */ in bcm2835_rng_stop()
296 ctrl = bcm2835_rng_read4(sc, sc->conf->control_reg); in bcm2835_rng_stop()
298 bcm2835_rng_write4(sc, sc->conf->control_reg, ctrl); in bcm2835_rng_stop()
308 chunk_size = sizeof(((struct harvest_event *)0)->he_entropy); in bcm2835_rng_enqueue_harvest()
310 sc_buf_chunk = (void*)sc->sc_buf; in bcm2835_rng_enqueue_harvest()
320 cnt -= size; in bcm2835_rng_enqueue_harvest()
333 dest = sc->sc_buf; in bcm2835_rng_harvest()
337 for (cnt = sizeof(sc->sc_buf) / sizeof(uint32_t); cnt > 0; in bcm2835_rng_harvest()
338 cnt -= num_words) { in bcm2835_rng_harvest()
340 hwcount = bcm2835_rng_read4(sc, sc->conf->count_reg); in bcm2835_rng_harvest()
341 num_avail = (hwcount >> sc->conf->count_value_shift) & in bcm2835_rng_harvest()
342 sc->conf->count_value_mask; in bcm2835_rng_harvest()
347 if (++seen_underrun >= sc->sc_stall_count) { in bcm2835_rng_harvest()
349 device_printf(sc->sc_dev, in bcm2835_rng_harvest()
350 "RNG stalled, disabling device\n"); in bcm2835_rng_harvest()
354 device_printf(sc->sc_dev, in bcm2835_rng_harvest()
365 CTR2(KTR_DEV, "%s: %d words available in RNG FIFO", in bcm2835_rng_harvest()
366 device_get_nameunit(sc->sc_dev), num_avail); in bcm2835_rng_harvest()
370 bcm2835_rng_read_multi4(sc, sc->conf->data_reg, dest, in bcm2835_rng_harvest()
378 callout_reset(&sc->sc_rngto, RNG_CALLOUT_TICKS, bcm2835_rng_harvest, sc); in bcm2835_rng_harvest()
387 rbg2x = sc->sc_rbg2x; in sysctl_bcm2835_rng_2xspeed()
391 if (req->newptr == NULL) in sysctl_bcm2835_rng_2xspeed()
393 if (rbg2x == sc->sc_rbg2x) in sysctl_bcm2835_rng_2xspeed()
396 /* Reset the RNG */ in sysctl_bcm2835_rng_2xspeed()
398 sc->sc_rbg2x = rbg2x; in sysctl_bcm2835_rng_2xspeed()
430 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) in bcm2835_rng_probe()
433 device_set_desc(dev, "Broadcom BCM2835/BCM2838 RNG"); in bcm2835_rng_probe()
448 sc->sc_dev = dev; in bcm2835_rng_attach()
450 sc->conf = (void const*)ofw_bus_search_compatible(dev, compat_data)->ocd_data; in bcm2835_rng_attach()
451 KASSERT(sc->conf != NULL, ("bcm2835_rng_attach: sc->conf == NULL")); in bcm2835_rng_attach()
453 sc->sc_stall_count = RNG_STALL_COUNT_DEFAULT; in bcm2835_rng_attach()
456 callout_init(&sc->sc_rngto, CALLOUT_MPSAFE); in bcm2835_rng_attach()
458 TUNABLE_INT_FETCH("bcmrng.stall_count", &sc->sc_stall_count); in bcm2835_rng_attach()
459 if (sc->conf->allow_2x_mode) in bcm2835_rng_attach()
460 TUNABLE_INT_FETCH("bcmrng.2xspeed", &sc->sc_rbg2x); in bcm2835_rng_attach()
464 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in bcm2835_rng_attach()
466 if (sc->sc_mem_res == NULL) { in bcm2835_rng_attach()
471 /* Start the RNG */ in bcm2835_rng_attach()
491 "underrun", CTLFLAG_RD, &sc->sc_underrun, in bcm2835_rng_attach()
493 if (sc->conf->allow_2x_mode) in bcm2835_rng_attach()
498 "stall_count", CTLFLAG_RW, &sc->sc_stall_count, in bcm2835_rng_attach()
499 RNG_STALL_COUNT_DEFAULT, "Number of underruns to assume RNG stall"); in bcm2835_rng_attach()
503 sysctl_bcm2835_rng_dump, "S", "Dump RNG registers"); in bcm2835_rng_attach()
508 * hardware RNG plenty of time to generate the first random bytes. in bcm2835_rng_attach()
510 callout_reset(&sc->sc_rngto, hz, bcm2835_rng_harvest, sc); in bcm2835_rng_attach()
522 /* Stop the RNG */ in bcm2835_rng_detach()
526 callout_drain(&sc->sc_rngto); in bcm2835_rng_detach()
529 if (sc->sc_mem_res != NULL) in bcm2835_rng_detach()
530 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); in bcm2835_rng_detach()