arm-smccc.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2015, Linaro Limited
  4. */
  5. #ifndef __LINUX_ARM_SMCCC_H
  6. #define __LINUX_ARM_SMCCC_H
  7. /*
  8. * This file provides common defines for ARM SMC Calling Convention as
  9. * specified in
  10. * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
  11. */
  12. #define ARM_SMCCC_STD_CALL 0
  13. #define ARM_SMCCC_FAST_CALL 1
  14. #define ARM_SMCCC_TYPE_SHIFT 31
  15. #define ARM_SMCCC_SMC_32 0
  16. #define ARM_SMCCC_SMC_64 1
  17. #define ARM_SMCCC_CALL_CONV_SHIFT 30
  18. #define ARM_SMCCC_OWNER_MASK 0x3F
  19. #define ARM_SMCCC_OWNER_SHIFT 24
  20. #define ARM_SMCCC_FUNC_MASK 0xFFFF
  21. #define ARM_SMCCC_IS_FAST_CALL(smc_val) \
  22. ((smc_val) & (ARM_SMCCC_FAST_CALL << ARM_SMCCC_TYPE_SHIFT))
  23. #define ARM_SMCCC_IS_64(smc_val) \
  24. ((smc_val) & (ARM_SMCCC_SMC_64 << ARM_SMCCC_CALL_CONV_SHIFT))
  25. #define ARM_SMCCC_FUNC_NUM(smc_val) ((smc_val) & ARM_SMCCC_FUNC_MASK)
  26. #define ARM_SMCCC_OWNER_NUM(smc_val) \
  27. (((smc_val) >> ARM_SMCCC_OWNER_SHIFT) & ARM_SMCCC_OWNER_MASK)
  28. #define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \
  29. (((type) << ARM_SMCCC_TYPE_SHIFT) | \
  30. ((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) | \
  31. (((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) | \
  32. ((func_num) & ARM_SMCCC_FUNC_MASK))
  33. #define ARM_SMCCC_OWNER_ARCH 0
  34. #define ARM_SMCCC_OWNER_CPU 1
  35. #define ARM_SMCCC_OWNER_SIP 2
  36. #define ARM_SMCCC_OWNER_OEM 3
  37. #define ARM_SMCCC_OWNER_STANDARD 4
  38. #define ARM_SMCCC_OWNER_TRUSTED_APP 48
  39. #define ARM_SMCCC_OWNER_TRUSTED_APP_END 49
  40. #define ARM_SMCCC_OWNER_TRUSTED_OS 50
  41. #define ARM_SMCCC_OWNER_TRUSTED_OS_END 63
  42. #define ARM_SMCCC_QUIRK_NONE 0
  43. #define ARM_SMCCC_QUIRK_QCOM_A6 1 /* Save/restore register a6 */
  44. #ifndef __ASSEMBLY__
  45. #include <linux/linkage.h>
  46. #include <linux/types.h>
  47. /**
  48. * struct arm_smccc_res - Result from SMC/HVC call
  49. * @a0-a3 result values from registers 0 to 3
  50. */
  51. struct arm_smccc_res {
  52. unsigned long a0;
  53. unsigned long a1;
  54. unsigned long a2;
  55. unsigned long a3;
  56. };
  57. /**
  58. * struct arm_smccc_quirk - Contains quirk information
  59. * @id: quirk identification
  60. * @state: quirk specific information
  61. * @a6: Qualcomm quirk entry for returning post-smc call contents of a6
  62. */
  63. struct arm_smccc_quirk {
  64. int id;
  65. union {
  66. unsigned long a6;
  67. } state;
  68. };
  69. /**
  70. * __arm_smccc_smc() - make SMC calls
  71. * @a0-a7: arguments passed in registers 0 to 7
  72. * @res: result values from registers 0 to 3
  73. * @quirk: points to an arm_smccc_quirk, or NULL when no quirks are required.
  74. *
  75. * This function is used to make SMC calls following SMC Calling Convention.
  76. * The content of the supplied param are copied to registers 0 to 7 prior
  77. * to the SMC instruction. The return values are updated with the content
  78. * from register 0 to 3 on return from the SMC instruction. An optional
  79. * quirk structure provides vendor specific behavior.
  80. */
  81. asmlinkage void __arm_smccc_smc(unsigned long a0, unsigned long a1,
  82. unsigned long a2, unsigned long a3, unsigned long a4,
  83. unsigned long a5, unsigned long a6, unsigned long a7,
  84. struct arm_smccc_res *res, struct arm_smccc_quirk *quirk);
  85. /**
  86. * __arm_smccc_hvc() - make HVC calls
  87. * @a0-a7: arguments passed in registers 0 to 7
  88. * @res: result values from registers 0 to 3
  89. * @quirk: points to an arm_smccc_quirk, or NULL when no quirks are required.
  90. *
  91. * This function is used to make HVC calls following SMC Calling
  92. * Convention. The content of the supplied param are copied to registers 0
  93. * to 7 prior to the HVC instruction. The return values are updated with
  94. * the content from register 0 to 3 on return from the HVC instruction. An
  95. * optional quirk structure provides vendor specific behavior.
  96. */
  97. asmlinkage void __arm_smccc_hvc(unsigned long a0, unsigned long a1,
  98. unsigned long a2, unsigned long a3, unsigned long a4,
  99. unsigned long a5, unsigned long a6, unsigned long a7,
  100. struct arm_smccc_res *res, struct arm_smccc_quirk *quirk);
  101. #define arm_smccc_smc(...) __arm_smccc_smc(__VA_ARGS__, NULL)
  102. #define arm_smccc_smc_quirk(...) __arm_smccc_smc(__VA_ARGS__)
  103. #define arm_smccc_hvc(...) __arm_smccc_hvc(__VA_ARGS__, NULL)
  104. #define arm_smccc_hvc_quirk(...) __arm_smccc_hvc(__VA_ARGS__)
  105. #endif /*__ASSEMBLY__*/
  106. #endif /*__LINUX_ARM_SMCCC_H*/