Greg Kroah-Hartman | 20a884f | 2017-11-24 15:00:34 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Harald Freudenberger | 4c637cd | 2017-03-17 10:46:31 +0100 | [diff] [blame] | 2 | /* |
| 3 | * s390 arch random implementation. |
| 4 | * |
| 5 | * Copyright IBM Corp. 2017 |
| 6 | * Author(s): Harald Freudenberger <freude@de.ibm.com> |
Harald Freudenberger | 4c637cd | 2017-03-17 10:46:31 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/atomic.h> |
Heiko Carstens | 92acfb7 | 2017-05-09 11:01:26 +0200 | [diff] [blame] | 11 | #include <linux/random.h> |
Harald Freudenberger | 4c637cd | 2017-03-17 10:46:31 +0100 | [diff] [blame] | 12 | #include <linux/static_key.h> |
| 13 | #include <asm/cpacf.h> |
| 14 | |
| 15 | DEFINE_STATIC_KEY_FALSE(s390_arch_random_available); |
| 16 | |
| 17 | atomic64_t s390_arch_random_counter = ATOMIC64_INIT(0); |
| 18 | EXPORT_SYMBOL(s390_arch_random_counter); |
| 19 | |
| 20 | static int __init s390_arch_random_init(void) |
| 21 | { |
| 22 | /* check if subfunction CPACF_PRNO_TRNG is available */ |
| 23 | if (cpacf_query_func(CPACF_PRNO, CPACF_PRNO_TRNG)) |
| 24 | static_branch_enable(&s390_arch_random_available); |
| 25 | |
| 26 | return 0; |
| 27 | } |
| 28 | arch_initcall(s390_arch_random_init); |