xref: /openbmc/linux/arch/s390/crypto/arch_random.c (revision d236d361)
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/static_key.h>
16 #include <asm/cpacf.h>
17 
18 DEFINE_STATIC_KEY_FALSE(s390_arch_random_available);
19 
20 atomic64_t s390_arch_random_counter = ATOMIC64_INIT(0);
21 EXPORT_SYMBOL(s390_arch_random_counter);
22 
23 static int __init s390_arch_random_init(void)
24 {
25 	/* check if subfunction CPACF_PRNO_TRNG is available */
26 	if (cpacf_query_func(CPACF_PRNO, CPACF_PRNO_TRNG))
27 		static_branch_enable(&s390_arch_random_available);
28 
29 	return 0;
30 }
31 arch_initcall(s390_arch_random_init);
32