Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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#ifdef CONFIG_ARCH_RANDOM
15
16#include <linux/static_key.h>
17#include <linux/atomic.h>
18
19DECLARE_STATIC_KEY_FALSE(s390_arch_random_available);
20extern atomic64_t s390_arch_random_counter;
21
22bool s390_arch_get_random_long(unsigned long *v);
23bool s390_arch_random_generate(u8 *buf, unsigned int nbytes);
24
25static inline bool __must_check arch_get_random_long(unsigned long *v)
26{
27 if (static_branch_likely(&s390_arch_random_available))
28 return s390_arch_get_random_long(v);
29 return false;
30}
31
32static inline bool __must_check arch_get_random_int(unsigned int *v)
33{
34 return false;
35}
36
37static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
38{
39 if (static_branch_likely(&s390_arch_random_available)) {
40 return s390_arch_random_generate((u8 *)v, sizeof(*v));
41 }
42 return false;
43}
44
45static inline bool __must_check arch_get_random_seed_int(unsigned int *v)
46{
47 if (static_branch_likely(&s390_arch_random_available)) {
48 return s390_arch_random_generate((u8 *)v, sizeof(*v));
49 }
50 return false;
51}
52
53#endif /* CONFIG_ARCH_RANDOM */
54#endif /* _ASM_S390_ARCHRANDOM_H */