rng.c 714 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright 2013, Michael Ellerman, IBM Corporation.
  4. */
  5. #define pr_fmt(fmt) "pseries-rng: " fmt
  6. #include <linux/kernel.h>
  7. #include <linux/of.h>
  8. #include <asm/archrandom.h>
  9. #include <asm/machdep.h>
  10. #include <asm/plpar_wrappers.h>
  11. #include "pseries.h"
  12. static int pseries_get_random_long(unsigned long *v)
  13. {
  14. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  15. if (plpar_hcall(H_RANDOM, retbuf) == H_SUCCESS) {
  16. *v = retbuf[0];
  17. return 1;
  18. }
  19. return 0;
  20. }
  21. void __init pseries_rng_init(void)
  22. {
  23. struct device_node *dn;
  24. dn = of_find_compatible_node(NULL, NULL, "ibm,random");
  25. if (!dn)
  26. return;
  27. ppc_md.get_random_seed = pseries_get_random_long;
  28. of_node_put(dn);
  29. }