1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright 2013, Michael Ellerman, IBM Corporation. 4 */ 5 6 #define pr_fmt(fmt) "pseries-rng: " fmt 7 8 #include <linux/kernel.h> 9 #include <linux/of.h> 10 #include <asm/archrandom.h> 11 #include <asm/machdep.h> 12 #include <asm/plpar_wrappers.h> 13 14 pseries_get_random_long(unsigned long * v)15static int pseries_get_random_long(unsigned long *v) 16 { 17 unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; 18 19 if (plpar_hcall(H_RANDOM, retbuf) == H_SUCCESS) { 20 *v = retbuf[0]; 21 return 1; 22 } 23 24 return 0; 25 } 26 rng_init(void)27static __init int rng_init(void) 28 { 29 struct device_node *dn; 30 31 dn = of_find_compatible_node(NULL, NULL, "ibm,random"); 32 if (!dn) 33 return -ENODEV; 34 35 pr_info("Registering arch random hook.\n"); 36 37 ppc_md.get_random_seed = pseries_get_random_long; 38 39 return 0; 40 } 41 machine_subsys_initcall(pseries, rng_init); 42