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