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 #include <linux/static_key.h> 15 #include <linux/atomic.h> 16 #include <asm/cpacf.h> 17 18 DECLARE_STATIC_KEY_FALSE(s390_arch_random_available); 19 extern atomic64_t s390_arch_random_counter; 20 21 static inline bool __must_check arch_get_random_long(unsigned long *v) 22 { 23 return false; 24 } 25 26 static inline bool __must_check arch_get_random_int(unsigned int *v) 27 { 28 return false; 29 } 30 31 static inline bool __must_check arch_get_random_seed_long(unsigned long *v) 32 { 33 if (static_branch_likely(&s390_arch_random_available)) { 34 cpacf_trng(NULL, 0, (u8 *)v, sizeof(*v)); 35 atomic64_add(sizeof(*v), &s390_arch_random_counter); 36 return true; 37 } 38 return false; 39 } 40 41 static inline bool __must_check arch_get_random_seed_int(unsigned int *v) 42 { 43 if (static_branch_likely(&s390_arch_random_available)) { 44 cpacf_trng(NULL, 0, (u8 *)v, sizeof(*v)); 45 atomic64_add(sizeof(*v), &s390_arch_random_counter); 46 return true; 47 } 48 return false; 49 } 50 51 #endif /* _ASM_S390_ARCHRANDOM_H */ 52