fwcall.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 <efi_loader.h>
  10. #include <version.h>
  11. #include <asm/macro.h>
  12. #include <asm/psci.h>
  13. #include <asm/system.h>
  14. /*
  15. * Issue the hypervisor call
  16. *
  17. * x0~x7: input arguments
  18. * x0~x3: output arguments
  19. */
  20. static void __efi_runtime hvc_call(struct pt_regs *args)
  21. {
  22. asm volatile(
  23. "ldr x0, %0\n"
  24. "ldr x1, %1\n"
  25. "ldr x2, %2\n"
  26. "ldr x3, %3\n"
  27. "ldr x4, %4\n"
  28. "ldr x5, %5\n"
  29. "ldr x6, %6\n"
  30. "ldr x7, %7\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]), "m" (args->regs[7])
  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 __efi_runtime 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 __efi_runtime_data bool use_smc_for_psci = true;
  82. void __noreturn __efi_runtime 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 __efi_runtime psci_system_off(void)
  94. {
  95. struct pt_regs regs;
  96. regs.regs[0] = ARM_PSCI_0_2_FN_SYSTEM_OFF;
  97. if (use_smc_for_psci)
  98. smc_call(&regs);
  99. else
  100. hvc_call(&regs);
  101. while (1)
  102. ;
  103. }
  104. #ifdef CONFIG_CMD_POWEROFF
  105. int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  106. {
  107. puts("poweroff ...\n");
  108. udelay(50000); /* wait 50 ms */
  109. disable_interrupts();
  110. psci_system_off();
  111. /*NOTREACHED*/
  112. return 0;
  113. }
  114. #endif
  115. #ifdef CONFIG_PSCI_RESET
  116. void reset_misc(void)
  117. {
  118. psci_system_reset();
  119. }
  120. #ifdef CONFIG_EFI_LOADER
  121. void __efi_runtime EFIAPI efi_reset_system(
  122. enum efi_reset_type reset_type,
  123. efi_status_t reset_status,
  124. unsigned long data_size, void *reset_data)
  125. {
  126. if (reset_type == EFI_RESET_COLD ||
  127. reset_type == EFI_RESET_WARM ||
  128. reset_type == EFI_RESET_PLATFORM_SPECIFIC) {
  129. psci_system_reset();
  130. } else if (reset_type == EFI_RESET_SHUTDOWN) {
  131. psci_system_off();
  132. }
  133. while (1) { }
  134. }
  135. #endif /* CONFIG_EFI_LOADER */
  136. #endif /* CONFIG_PSCI_RESET */