rng.c 863 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Derived from arch/powerpc/platforms/powernv/rng.c, which is:
  4. * Copyright 2013, Michael Ellerman, IBM Corporation.
  5. */
  6. #define pr_fmt(fmt) "microwatt-rng: " fmt
  7. #include <linux/kernel.h>
  8. #include <linux/smp.h>
  9. #include <asm/archrandom.h>
  10. #include <asm/cputable.h>
  11. #include <asm/machdep.h>
  12. #include "microwatt.h"
  13. #define DARN_ERR 0xFFFFFFFFFFFFFFFFul
  14. static int microwatt_get_random_darn(unsigned long *v)
  15. {
  16. unsigned long val;
  17. /* Using DARN with L=1 - 64-bit conditioned random number */
  18. asm volatile(PPC_DARN(%0, 1) : "=r"(val));
  19. if (val == DARN_ERR)
  20. return 0;
  21. *v = val;
  22. return 1;
  23. }
  24. void __init microwatt_rng_init(void)
  25. {
  26. unsigned long val;
  27. int i;
  28. for (i = 0; i < 10; i++) {
  29. if (microwatt_get_random_darn(&val)) {
  30. ppc_md.get_random_seed = microwatt_get_random_darn;
  31. return;
  32. }
  33. }
  34. }