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 #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 void s390_arch_random_generate(u8 *buf, unsigned int nbytes) 24 { 25 cpacf_trng(NULL, 0, buf, nbytes); 26 atomic64_add(nbytes, &s390_arch_random_counter); 27 } 28 29 static inline bool arch_has_random(void) 30 { 31 return false; 32 } 33 34 static inline bool arch_has_random_seed(void) 35 { 36 if (static_branch_likely(&s390_arch_random_available)) 37 return true; 38 return false; 39 } 40 41 static inline bool arch_get_random_long(unsigned long *v) 42 { 43 return false; 44 } 45 46 static inline bool arch_get_random_int(unsigned int *v) 47 { 48 return false; 49 } 50 51 static inline bool arch_get_random_seed_long(unsigned long *v) 52 { 53 if (static_branch_likely(&s390_arch_random_available)) { 54 s390_arch_random_generate((u8 *)v, sizeof(*v)); 55 return true; 56 } 57 return false; 58 } 59 60 static inline bool arch_get_random_seed_int(unsigned int *v) 61 { 62 if (static_branch_likely(&s390_arch_random_available)) { 63 s390_arch_random_generate((u8 *)v, sizeof(*v)); 64 return true; 65 } 66 return false; 67 } 68 69 #endif /* CONFIG_ARCH_RANDOM */ 70 #endif /* _ASM_S390_ARCHRANDOM_H */ 71