1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Derived from arch/powerpc/platforms/powernv/rng.c, which is:
4 * Copyright 2013, Michael Ellerman, IBM Corporation.
7 #define pr_fmt(fmt) "microwatt-rng: " fmt
9 #include <linux/kernel.h>
10 #include <linux/smp.h>
11 #include <asm/archrandom.h>
12 #include <asm/cputable.h>
13 #include <asm/machdep.h>
15 #define DARN_ERR 0xFFFFFFFFFFFFFFFFul
17 static int microwatt_get_random_darn(unsigned long *v)
21 /* Using DARN with L=1 - 64-bit conditioned random number */
22 asm volatile(PPC_DARN(%0, 1) : "=r"(val));
32 static __init int rng_init(void)
37 for (i = 0; i < 10; i++) {
38 if (microwatt_get_random_darn(&val)) {
39 ppc_md.get_random_seed = microwatt_get_random_darn;
44 pr_warn("Unable to use DARN for get_random_seed()\n");
48 machine_subsys_initcall(, rng_init);