xref: /openbmc/linux/arch/s390/include/asm/archrandom.h (revision b830f94f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Kernel interface for the s390 arch_random_* functions
4  *
5  * Copyright IBM Corp. 2017
6  *
7  * Author: Harald Freudenberger <freude@de.ibm.com>
8  *
9  */
10 
11 #ifndef _ASM_S390_ARCHRANDOM_H
12 #define _ASM_S390_ARCHRANDOM_H
13 
14 #ifdef CONFIG_ARCH_RANDOM
15 
16 #include <linux/static_key.h>
17 #include <linux/atomic.h>
18 
19 DECLARE_STATIC_KEY_FALSE(s390_arch_random_available);
20 extern atomic64_t s390_arch_random_counter;
21 
22 bool s390_arch_random_generate(u8 *buf, unsigned int nbytes);
23 
24 static inline bool arch_has_random(void)
25 {
26 	return false;
27 }
28 
29 static inline bool arch_has_random_seed(void)
30 {
31 	if (static_branch_likely(&s390_arch_random_available))
32 		return true;
33 	return false;
34 }
35 
36 static inline bool arch_get_random_long(unsigned long *v)
37 {
38 	return false;
39 }
40 
41 static inline bool arch_get_random_int(unsigned int *v)
42 {
43 	return false;
44 }
45 
46 static inline bool arch_get_random_seed_long(unsigned long *v)
47 {
48 	if (static_branch_likely(&s390_arch_random_available)) {
49 		return s390_arch_random_generate((u8 *)v, sizeof(*v));
50 	}
51 	return false;
52 }
53 
54 static inline bool arch_get_random_seed_int(unsigned int *v)
55 {
56 	if (static_branch_likely(&s390_arch_random_available)) {
57 		return s390_arch_random_generate((u8 *)v, sizeof(*v));
58 	}
59 	return false;
60 }
61 
62 #endif /* CONFIG_ARCH_RANDOM */
63 #endif /* _ASM_S390_ARCHRANDOM_H */
64