xref: /openbmc/linux/arch/s390/crypto/arch_random.c (revision 8cb5d748)
1 /*
2  * s390 arch random implementation.
3  *
4  * Copyright IBM Corp. 2017
5  * Author(s): Harald Freudenberger <freude@de.ibm.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License (version 2 only)
9  * as published by the Free Software Foundation.
10  *
11  */
12 
13 #include <linux/kernel.h>
14 #include <linux/atomic.h>
15 #include <linux/random.h>
16 #include <linux/static_key.h>
17 #include <asm/cpacf.h>
18 
19 DEFINE_STATIC_KEY_FALSE(s390_arch_random_available);
20 
21 atomic64_t s390_arch_random_counter = ATOMIC64_INIT(0);
22 EXPORT_SYMBOL(s390_arch_random_counter);
23 
24 static int __init s390_arch_random_init(void)
25 {
26 	/* check if subfunction CPACF_PRNO_TRNG is available */
27 	if (cpacf_query_func(CPACF_PRNO, CPACF_PRNO_TRNG))
28 		static_branch_enable(&s390_arch_random_available);
29 
30 	return 0;
31 }
32 arch_initcall(s390_arch_random_init);
33