arm-smccc.h 4.1 KB

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