arm-smccc.h 4.5 KB

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