fwcall.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /**
  3. * (C) Copyright 2014, Cavium Inc.
  4. * (C) Copyright 2017, Xilinx Inc.
  5. *
  6. **/
  7. #include <asm-offsets.h>
  8. #include <config.h>
  9. #include <version.h>
  10. #include <asm/cache.h>
  11. #include <asm/macro.h>
  12. #include <asm/psci.h>
  13. #include <asm/ptrace.h>
  14. #include <asm/system.h>
  15. /*
  16. * Issue the hypervisor call
  17. *
  18. * x0~x7: input arguments
  19. * x0~x3: output arguments
  20. */
  21. static void hvc_call(struct pt_regs *args)
  22. {
  23. asm volatile(
  24. "ldr x0, %0\n"
  25. "ldr x1, %1\n"
  26. "ldr x2, %2\n"
  27. "ldr x3, %3\n"
  28. "ldr x4, %4\n"
  29. "ldr x5, %5\n"
  30. "ldr x6, %6\n"
  31. "hvc #0\n"
  32. "str x0, %0\n"
  33. "str x1, %1\n"
  34. "str x2, %2\n"
  35. "str x3, %3\n"
  36. : "+m" (args->regs[0]), "+m" (args->regs[1]),
  37. "+m" (args->regs[2]), "+m" (args->regs[3])
  38. : "m" (args->regs[4]), "m" (args->regs[5]),
  39. "m" (args->regs[6])
  40. : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
  41. "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
  42. "x16", "x17");
  43. }
  44. /*
  45. * void smc_call(arg0, arg1...arg7)
  46. *
  47. * issue the secure monitor call
  48. *
  49. * x0~x7: input arguments
  50. * x0~x3: output arguments
  51. */
  52. void smc_call(struct pt_regs *args)
  53. {
  54. asm volatile(
  55. "ldr x0, %0\n"
  56. "ldr x1, %1\n"
  57. "ldr x2, %2\n"
  58. "ldr x3, %3\n"
  59. "ldr x4, %4\n"
  60. "ldr x5, %5\n"
  61. "ldr x6, %6\n"
  62. "smc #0\n"
  63. "str x0, %0\n"
  64. "str x1, %1\n"
  65. "str x2, %2\n"
  66. "str x3, %3\n"
  67. : "+m" (args->regs[0]), "+m" (args->regs[1]),
  68. "+m" (args->regs[2]), "+m" (args->regs[3])
  69. : "m" (args->regs[4]), "m" (args->regs[5]),
  70. "m" (args->regs[6])
  71. : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
  72. "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
  73. "x16", "x17");
  74. }
  75. /*
  76. * For now, all systems we support run at least in EL2 and thus
  77. * trigger PSCI calls to EL3 using SMC. If anyone ever wants to
  78. * use PSCI on U-Boot running below a hypervisor, please detect
  79. * this and set the flag accordingly.
  80. */
  81. static const bool use_smc_for_psci = true;
  82. void __noreturn psci_system_reset(void)
  83. {
  84. struct pt_regs regs;
  85. regs.regs[0] = ARM_PSCI_0_2_FN_SYSTEM_RESET;
  86. if (use_smc_for_psci)
  87. smc_call(&regs);
  88. else
  89. hvc_call(&regs);
  90. while (1)
  91. ;
  92. }
  93. void __noreturn psci_system_reset2(u32 reset_level, u32 cookie)
  94. {
  95. struct pt_regs regs;
  96. regs.regs[0] = ARM_PSCI_0_2_FN64_SYSTEM_RESET2;
  97. regs.regs[1] = PSCI_RESET2_TYPE_VENDOR | reset_level;
  98. regs.regs[2] = cookie;
  99. if (use_smc_for_psci)
  100. smc_call(&regs);
  101. else
  102. hvc_call(&regs);
  103. while (1)
  104. ;
  105. }
  106. void __noreturn psci_system_off(void)
  107. {
  108. struct pt_regs regs;
  109. regs.regs[0] = ARM_PSCI_0_2_FN_SYSTEM_OFF;
  110. if (use_smc_for_psci)
  111. smc_call(&regs);
  112. else
  113. hvc_call(&regs);
  114. while (1)
  115. ;
  116. }