smccc-call.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015, Linaro Limited
  4. */
  5. #include <linux/linkage.h>
  6. #include <linux/arm-smccc.h>
  7. #include <asm/asm-offsets.h>
  8. #include <asm/assembler.h>
  9. #include <asm/thread_info.h>
  10. /*
  11. * If we have SMCCC v1.3 and (as is likely) no SVE state in
  12. * the registers then set the SMCCC hint bit to say there's no
  13. * need to preserve it. Do this by directly adjusting the SMCCC
  14. * function value which is already stored in x0 ready to be called.
  15. */
  16. SYM_FUNC_START(__arm_smccc_sve_check)
  17. ldr_l x16, smccc_has_sve_hint
  18. cbz x16, 2f
  19. get_current_task x16
  20. ldr x16, [x16, #TSK_TI_FLAGS]
  21. tbnz x16, #TIF_FOREIGN_FPSTATE, 1f // Any live FP state?
  22. tbnz x16, #TIF_SVE, 2f // Does that state include SVE?
  23. 1: orr x0, x0, ARM_SMCCC_1_3_SVE_HINT
  24. 2: ret
  25. SYM_FUNC_END(__arm_smccc_sve_check)
  26. EXPORT_SYMBOL(__arm_smccc_sve_check)
  27. .macro SMCCC instr
  28. stp x29, x30, [sp, #-16]!
  29. mov x29, sp
  30. alternative_if ARM64_SVE
  31. bl __arm_smccc_sve_check
  32. alternative_else_nop_endif
  33. \instr #0
  34. ldr x4, [sp, #16]
  35. stp x0, x1, [x4, #ARM_SMCCC_RES_X0_OFFS]
  36. stp x2, x3, [x4, #ARM_SMCCC_RES_X2_OFFS]
  37. ldr x4, [sp, #24]
  38. cbz x4, 1f /* no quirk structure */
  39. ldr x9, [x4, #ARM_SMCCC_QUIRK_ID_OFFS]
  40. cmp x9, #ARM_SMCCC_QUIRK_QCOM_A6
  41. b.ne 1f
  42. str x6, [x4, ARM_SMCCC_QUIRK_STATE_OFFS]
  43. 1: ldp x29, x30, [sp], #16
  44. ret
  45. .endm
  46. /*
  47. * void arm_smccc_smc(unsigned long a0, unsigned long a1, unsigned long a2,
  48. * unsigned long a3, unsigned long a4, unsigned long a5,
  49. * unsigned long a6, unsigned long a7, struct arm_smccc_res *res,
  50. * struct arm_smccc_quirk *quirk)
  51. */
  52. SYM_FUNC_START(__arm_smccc_smc)
  53. SMCCC smc
  54. SYM_FUNC_END(__arm_smccc_smc)
  55. EXPORT_SYMBOL(__arm_smccc_smc)
  56. /*
  57. * void arm_smccc_hvc(unsigned long a0, unsigned long a1, unsigned long a2,
  58. * unsigned long a3, unsigned long a4, unsigned long a5,
  59. * unsigned long a6, unsigned long a7, struct arm_smccc_res *res,
  60. * struct arm_smccc_quirk *quirk)
  61. */
  62. SYM_FUNC_START(__arm_smccc_hvc)
  63. SMCCC hvc
  64. SYM_FUNC_END(__arm_smccc_hvc)
  65. EXPORT_SYMBOL(__arm_smccc_hvc)
  66. .macro SMCCC_1_2 instr
  67. /* Save `res` and free a GPR that won't be clobbered */
  68. stp x1, x19, [sp, #-16]!
  69. /* Ensure `args` won't be clobbered while loading regs in next step */
  70. mov x19, x0
  71. /* Load the registers x0 - x17 from the struct arm_smccc_1_2_regs */
  72. ldp x0, x1, [x19, #ARM_SMCCC_1_2_REGS_X0_OFFS]
  73. ldp x2, x3, [x19, #ARM_SMCCC_1_2_REGS_X2_OFFS]
  74. ldp x4, x5, [x19, #ARM_SMCCC_1_2_REGS_X4_OFFS]
  75. ldp x6, x7, [x19, #ARM_SMCCC_1_2_REGS_X6_OFFS]
  76. ldp x8, x9, [x19, #ARM_SMCCC_1_2_REGS_X8_OFFS]
  77. ldp x10, x11, [x19, #ARM_SMCCC_1_2_REGS_X10_OFFS]
  78. ldp x12, x13, [x19, #ARM_SMCCC_1_2_REGS_X12_OFFS]
  79. ldp x14, x15, [x19, #ARM_SMCCC_1_2_REGS_X14_OFFS]
  80. ldp x16, x17, [x19, #ARM_SMCCC_1_2_REGS_X16_OFFS]
  81. \instr #0
  82. /* Load the `res` from the stack */
  83. ldr x19, [sp]
  84. /* Store the registers x0 - x17 into the result structure */
  85. stp x0, x1, [x19, #ARM_SMCCC_1_2_REGS_X0_OFFS]
  86. stp x2, x3, [x19, #ARM_SMCCC_1_2_REGS_X2_OFFS]
  87. stp x4, x5, [x19, #ARM_SMCCC_1_2_REGS_X4_OFFS]
  88. stp x6, x7, [x19, #ARM_SMCCC_1_2_REGS_X6_OFFS]
  89. stp x8, x9, [x19, #ARM_SMCCC_1_2_REGS_X8_OFFS]
  90. stp x10, x11, [x19, #ARM_SMCCC_1_2_REGS_X10_OFFS]
  91. stp x12, x13, [x19, #ARM_SMCCC_1_2_REGS_X12_OFFS]
  92. stp x14, x15, [x19, #ARM_SMCCC_1_2_REGS_X14_OFFS]
  93. stp x16, x17, [x19, #ARM_SMCCC_1_2_REGS_X16_OFFS]
  94. /* Restore original x19 */
  95. ldp xzr, x19, [sp], #16
  96. ret
  97. .endm
  98. /*
  99. * void arm_smccc_1_2_hvc(const struct arm_smccc_1_2_regs *args,
  100. * struct arm_smccc_1_2_regs *res);
  101. */
  102. SYM_FUNC_START(arm_smccc_1_2_hvc)
  103. SMCCC_1_2 hvc
  104. SYM_FUNC_END(arm_smccc_1_2_hvc)
  105. EXPORT_SYMBOL(arm_smccc_1_2_hvc)
  106. /*
  107. * void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args,
  108. * struct arm_smccc_1_2_regs *res);
  109. */
  110. SYM_FUNC_START(arm_smccc_1_2_smc)
  111. SMCCC_1_2 smc
  112. SYM_FUNC_END(arm_smccc_1_2_smc)
  113. EXPORT_SYMBOL(arm_smccc_1_2_smc)