1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Kernel interface for the s390 arch_random_* functions
5 * Copyright IBM Corp. 2017
7 * Author: Harald Freudenberger <freude@de.ibm.com>
11 #ifndef _ASM_S390_ARCHRANDOM_H
12 #define _ASM_S390_ARCHRANDOM_H
14 #ifdef CONFIG_ARCH_RANDOM
16 #include <linux/static_key.h>
17 #include <linux/atomic.h>
18 #include <asm/cpacf.h>
20 DECLARE_STATIC_KEY_FALSE(s390_arch_random_available
);
21 extern atomic64_t s390_arch_random_counter
;
23 static void s390_arch_random_generate(u8
*buf
, unsigned int nbytes
)
25 cpacf_trng(NULL
, 0, buf
, nbytes
);
26 atomic64_add(nbytes
, &s390_arch_random_counter
);
29 static inline bool arch_has_random(void)
34 static inline bool arch_has_random_seed(void)
36 if (static_branch_likely(&s390_arch_random_available
))
41 static inline bool arch_get_random_long(unsigned long *v
)
46 static inline bool arch_get_random_int(unsigned int *v
)
51 static inline bool arch_get_random_seed_long(unsigned long *v
)
53 if (static_branch_likely(&s390_arch_random_available
)) {
54 s390_arch_random_generate((u8
*)v
, sizeof(*v
));
60 static inline bool arch_get_random_seed_int(unsigned int *v
)
62 if (static_branch_likely(&s390_arch_random_available
)) {
63 s390_arch_random_generate((u8
*)v
, sizeof(*v
));
69 #endif /* CONFIG_ARCH_RANDOM */
70 #endif /* _ASM_S390_ARCHRANDOM_H */