blob: c67b82dfa558ee6b32a56fa069a7ac426a5a7a1f [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* 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
19DECLARE_STATIC_KEY_FALSE(s390_arch_random_available);
20extern atomic64_t s390_arch_random_counter;
21
22bool s390_arch_random_generate(u8 *buf, unsigned int nbytes);
23
24static inline bool arch_has_random(void)
25{
26 return false;
27}
28
29static inline bool arch_has_random_seed(void)
30{
31 if (static_branch_likely(&s390_arch_random_available))
32 return true;
33 return false;
34}
35
36static inline bool arch_get_random_long(unsigned long *v)
37{
38 return false;
39}
40
41static inline bool arch_get_random_int(unsigned int *v)
42{
43 return false;
44}
45
46static inline bool arch_get_random_seed_long(unsigned long *v)
47{
48 if (static_branch_likely(&s390_arch_random_available)) {
49 return s390_arch_random_generate((u8 *)v, sizeof(*v));
50 }
51 return false;
52}
53
54static inline bool arch_get_random_seed_int(unsigned int *v)
55{
56 if (static_branch_likely(&s390_arch_random_available)) {
57 return s390_arch_random_generate((u8 *)v, sizeof(*v));
58 }
59 return false;
60}
61
62#endif /* CONFIG_ARCH_RANDOM */
63#endif /* _ASM_S390_ARCHRANDOM_H */