psci.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017 Masahiro Yamada <yamada.masahiro@socionext.com>
  4. *
  5. * Based on drivers/firmware/psci.c from Linux:
  6. * Copyright (C) 2015 ARM Limited
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <dm/lists.h>
  11. #include <linux/libfdt.h>
  12. #include <linux/arm-smccc.h>
  13. #include <linux/errno.h>
  14. #include <linux/printk.h>
  15. #include <linux/psci.h>
  16. psci_fn *invoke_psci_fn;
  17. static unsigned long __invoke_psci_fn_hvc(unsigned long function_id,
  18. unsigned long arg0, unsigned long arg1,
  19. unsigned long arg2)
  20. {
  21. struct arm_smccc_res res;
  22. arm_smccc_hvc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
  23. return res.a0;
  24. }
  25. static unsigned long __invoke_psci_fn_smc(unsigned long function_id,
  26. unsigned long arg0, unsigned long arg1,
  27. unsigned long arg2)
  28. {
  29. struct arm_smccc_res res;
  30. arm_smccc_smc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
  31. return res.a0;
  32. }
  33. static int psci_bind(struct udevice *dev)
  34. {
  35. /* No SYSTEM_RESET support for PSCI 0.1 */
  36. if (device_is_compatible(dev, "arm,psci-0.2") ||
  37. device_is_compatible(dev, "arm,psci-1.0")) {
  38. int ret;
  39. /* bind psci-sysreset optionally */
  40. ret = device_bind_driver(dev, "psci-sysreset", "psci-sysreset",
  41. NULL);
  42. if (ret)
  43. pr_debug("PSCI System Reset was not bound.\n");
  44. }
  45. return 0;
  46. }
  47. static int psci_probe(struct udevice *dev)
  48. {
  49. DECLARE_GLOBAL_DATA_PTR;
  50. const char *method;
  51. method = fdt_stringlist_get(gd->fdt_blob, dev_of_offset(dev), "method",
  52. 0, NULL);
  53. if (!method) {
  54. pr_warn("missing \"method\" property\n");
  55. return -ENXIO;
  56. }
  57. if (!strcmp("hvc", method)) {
  58. invoke_psci_fn = __invoke_psci_fn_hvc;
  59. } else if (!strcmp("smc", method)) {
  60. invoke_psci_fn = __invoke_psci_fn_smc;
  61. } else {
  62. pr_warn("invalid \"method\" property: %s\n", method);
  63. return -EINVAL;
  64. }
  65. return 0;
  66. }
  67. static const struct udevice_id psci_of_match[] = {
  68. { .compatible = "arm,psci" },
  69. { .compatible = "arm,psci-0.2" },
  70. { .compatible = "arm,psci-1.0" },
  71. {},
  72. };
  73. U_BOOT_DRIVER(psci) = {
  74. .name = "psci",
  75. .id = UCLASS_FIRMWARE,
  76. .of_match = psci_of_match,
  77. .bind = psci_bind,
  78. .probe = psci_probe,
  79. };