arch_random.c 912 B

123456789101112131415161718192021222324252627282930313233
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * s390 arch random implementation.
  4. *
  5. * Copyright IBM Corp. 2017
  6. * Author(s): Harald Freudenberger <freude@de.ibm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License (version 2 only)
  10. * as published by the Free Software Foundation.
  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. DEFINE_STATIC_KEY_FALSE(s390_arch_random_available);
  19. atomic64_t s390_arch_random_counter = ATOMIC64_INIT(0);
  20. EXPORT_SYMBOL(s390_arch_random_counter);
  21. static int __init s390_arch_random_init(void)
  22. {
  23. /* check if subfunction CPACF_PRNO_TRNG is available */
  24. if (cpacf_query_func(CPACF_PRNO, CPACF_PRNO_TRNG))
  25. static_branch_enable(&s390_arch_random_available);
  26. return 0;
  27. }
  28. arch_initcall(s390_arch_random_init);