xref: /openbmc/linux/arch/s390/include/asm/archrandom.h (revision 2540d3c9)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Kernel interface for the s390 arch_random_* functions
4  *
5  * Copyright IBM Corp. 2017, 2020
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 #include <asm/cpacf.h>
19 
20 DECLARE_STATIC_KEY_FALSE(s390_arch_random_available);
21 extern atomic64_t s390_arch_random_counter;
22 
23 static inline bool __must_check arch_get_random_long(unsigned long *v)
24 {
25 	return false;
26 }
27 
28 static inline bool __must_check arch_get_random_int(unsigned int *v)
29 {
30 	return false;
31 }
32 
33 static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
34 {
35 	if (static_branch_likely(&s390_arch_random_available)) {
36 		cpacf_trng(NULL, 0, (u8 *)v, sizeof(*v));
37 		atomic64_add(sizeof(*v), &s390_arch_random_counter);
38 		return true;
39 	}
40 	return false;
41 }
42 
43 static inline bool __must_check arch_get_random_seed_int(unsigned int *v)
44 {
45 	if (static_branch_likely(&s390_arch_random_available)) {
46 		cpacf_trng(NULL, 0, (u8 *)v, sizeof(*v));
47 		atomic64_add(sizeof(*v), &s390_arch_random_counter);
48 		return true;
49 	}
50 	return false;
51 }
52 
53 #endif /* CONFIG_ARCH_RANDOM */
54 #endif /* _ASM_S390_ARCHRANDOM_H */
55