Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Kernel interface for the s390 arch_random_* functions
0004  *
0005  * Copyright IBM Corp. 2017, 2022
0006  *
0007  * Author: Harald Freudenberger <freude@de.ibm.com>
0008  *
0009  */
0010 
0011 #ifndef _ASM_S390_ARCHRANDOM_H
0012 #define _ASM_S390_ARCHRANDOM_H
0013 
0014 #include <linux/static_key.h>
0015 #include <linux/preempt.h>
0016 #include <linux/atomic.h>
0017 #include <asm/cpacf.h>
0018 
0019 DECLARE_STATIC_KEY_FALSE(s390_arch_random_available);
0020 extern atomic64_t s390_arch_random_counter;
0021 
0022 static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t max_longs)
0023 {
0024     return 0;
0025 }
0026 
0027 static inline size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs)
0028 {
0029     if (static_branch_likely(&s390_arch_random_available) &&
0030         in_task()) {
0031         cpacf_trng(NULL, 0, (u8 *)v, max_longs * sizeof(*v));
0032         atomic64_add(max_longs * sizeof(*v), &s390_arch_random_counter);
0033         return max_longs;
0034     }
0035     return 0;
0036 }
0037 
0038 #endif /* _ASM_S390_ARCHRANDOM_H */