archrandom.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Kernel interface for the s390 arch_random_* functions
  4. *
  5. * Copyright IBM Corp. 2017
  6. *
  7. * Author: Harald Freudenberger <freude@de.ibm.com>
  8. *
  9. */
  10. #ifndef _ASM_S390_ARCHRANDOM_H
  11. #define _ASM_S390_ARCHRANDOM_H
  12. #ifdef CONFIG_ARCH_RANDOM
  13. #include <linux/static_key.h>
  14. #include <linux/atomic.h>
  15. DECLARE_STATIC_KEY_FALSE(s390_arch_random_available);
  16. extern atomic64_t s390_arch_random_counter;
  17. bool s390_arch_random_generate(u8 *buf, unsigned int nbytes);
  18. static inline bool arch_has_random(void)
  19. {
  20. return false;
  21. }
  22. static inline bool arch_has_random_seed(void)
  23. {
  24. if (static_branch_likely(&s390_arch_random_available))
  25. return true;
  26. return false;
  27. }
  28. static inline bool arch_get_random_long(unsigned long *v)
  29. {
  30. return false;
  31. }
  32. static inline bool arch_get_random_int(unsigned int *v)
  33. {
  34. return false;
  35. }
  36. static inline bool arch_get_random_seed_long(unsigned long *v)
  37. {
  38. if (static_branch_likely(&s390_arch_random_available)) {
  39. return s390_arch_random_generate((u8 *)v, sizeof(*v));
  40. }
  41. return false;
  42. }
  43. static inline bool arch_get_random_seed_int(unsigned int *v)
  44. {
  45. if (static_branch_likely(&s390_arch_random_available)) {
  46. return s390_arch_random_generate((u8 *)v, sizeof(*v));
  47. }
  48. return false;
  49. }
  50. #endif /* CONFIG_ARCH_RANDOM */
  51. #endif /* _ASM_S390_ARCHRANDOM_H */