xref: /linux/arch/powerpc/platforms/pseries/rng.c (revision b5bee6ced21ca98389000b7017dd41b0cc37fa50)
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 #include "pseries.h"
14 
15 
16 static int pseries_get_random_long(unsigned long *v)
17 {
18 	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
19 
20 	if (plpar_hcall(H_RANDOM, retbuf) == H_SUCCESS) {
21 		*v = retbuf[0];
22 		return 1;
23 	}
24 
25 	return 0;
26 }
27 
28 void __init pseries_rng_init(void)
29 {
30 	struct device_node *dn;
31 
32 	dn = of_find_compatible_node(NULL, NULL, "ibm,random");
33 	if (!dn)
34 		return;
35 	ppc_md.get_random_seed = pseries_get_random_long;
36 	of_node_put(dn);
37 }
38