Merge tag 'pm-fixes-4.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[linux/fpc-iii.git] / arch / s390 / include / asm / archrandom.h
blob09aed1095336259411eee0d9fdbb0fd37fc35179
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Kernel interface for the s390 arch_random_* functions
5 * Copyright IBM Corp. 2017
7 * Author: Harald Freudenberger <freude@de.ibm.com>
9 */
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)
31 return false;
34 static inline bool arch_has_random_seed(void)
36 if (static_branch_likely(&s390_arch_random_available))
37 return true;
38 return false;
41 static inline bool arch_get_random_long(unsigned long *v)
43 return false;
46 static inline bool arch_get_random_int(unsigned int *v)
48 return false;
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));
55 return true;
57 return false;
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));
64 return true;
66 return false;
69 #endif /* CONFIG_ARCH_RANDOM */
70 #endif /* _ASM_S390_ARCHRANDOM_H */