rng.c 994 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright 2013, Michael Ellerman, IBM Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #define pr_fmt(fmt) "pseries-rng: " fmt
  10. #include <linux/kernel.h>
  11. #include <linux/of.h>
  12. #include <asm/archrandom.h>
  13. #include <asm/machdep.h>
  14. #include <asm/plpar_wrappers.h>
  15. static int pseries_get_random_long(unsigned long *v)
  16. {
  17. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  18. if (plpar_hcall(H_RANDOM, retbuf) == H_SUCCESS) {
  19. *v = retbuf[0];
  20. return 1;
  21. }
  22. return 0;
  23. }
  24. static __init int rng_init(void)
  25. {
  26. struct device_node *dn;
  27. dn = of_find_compatible_node(NULL, NULL, "ibm,random");
  28. if (!dn)
  29. return -ENODEV;
  30. pr_info("Registering arch random hook.\n");
  31. ppc_md.get_random_seed = pseries_get_random_long;
  32. return 0;
  33. }
  34. machine_subsys_initcall(pseries, rng_init);