archrandom.h 947 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Kernel interface for the s390 arch_random_* functions
  4. *
  5. * Copyright IBM Corp. 2017, 2022
  6. *
  7. * Author: Harald Freudenberger <[email protected]>
  8. *
  9. */
  10. #ifndef _ASM_S390_ARCHRANDOM_H
  11. #define _ASM_S390_ARCHRANDOM_H
  12. #include <linux/static_key.h>
  13. #include <linux/preempt.h>
  14. #include <linux/atomic.h>
  15. #include <asm/cpacf.h>
  16. DECLARE_STATIC_KEY_FALSE(s390_arch_random_available);
  17. extern atomic64_t s390_arch_random_counter;
  18. static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t max_longs)
  19. {
  20. return 0;
  21. }
  22. static inline size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs)
  23. {
  24. if (static_branch_likely(&s390_arch_random_available) &&
  25. in_task()) {
  26. cpacf_trng(NULL, 0, (u8 *)v, max_longs * sizeof(*v));
  27. atomic64_add(max_longs * sizeof(*v), &s390_arch_random_counter);
  28. return max_longs;
  29. }
  30. return 0;
  31. }
  32. #endif /* _ASM_S390_ARCHRANDOM_H */