Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | /* 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 | |
| 19 | DECLARE_STATIC_KEY_FALSE(s390_arch_random_available); |
| 20 | extern atomic64_t s390_arch_random_counter; |
| 21 | |
| 22 | bool s390_arch_random_generate(u8 *buf, unsigned int nbytes); |
| 23 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 24 | static inline bool __must_check arch_get_random_long(unsigned long *v) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 25 | { |
| 26 | return false; |
| 27 | } |
| 28 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 29 | static inline bool __must_check arch_get_random_int(unsigned int *v) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 30 | { |
| 31 | return false; |
| 32 | } |
| 33 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 34 | static inline bool __must_check arch_get_random_seed_long(unsigned long *v) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 35 | { |
| 36 | if (static_branch_likely(&s390_arch_random_available)) { |
| 37 | return s390_arch_random_generate((u8 *)v, sizeof(*v)); |
| 38 | } |
| 39 | return false; |
| 40 | } |
| 41 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 42 | static inline bool __must_check arch_get_random_seed_int(unsigned int *v) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 43 | { |
| 44 | if (static_branch_likely(&s390_arch_random_available)) { |
| 45 | return s390_arch_random_generate((u8 *)v, sizeof(*v)); |
| 46 | } |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | #endif /* CONFIG_ARCH_RANDOM */ |
| 51 | #endif /* _ASM_S390_ARCHRANDOM_H */ |