qcom_scm.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (c) 2010-2015,2019,2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __QCOM_SCM_INT_H
  6. #define __QCOM_SCM_INT_H
  7. #include <linux/semaphore.h>
  8. enum qcom_scm_convention {
  9. SMC_CONVENTION_UNKNOWN,
  10. SMC_CONVENTION_LEGACY,
  11. SMC_CONVENTION_ARM_32,
  12. SMC_CONVENTION_ARM_64,
  13. };
  14. extern enum qcom_scm_convention qcom_scm_convention;
  15. extern struct semaphore qcom_scm_sem_lock;
  16. #define MAX_QCOM_SCM_ARGS 10
  17. #define MAX_QCOM_SCM_RETS 3
  18. enum qcom_scm_arg_types {
  19. QCOM_SCM_VAL,
  20. QCOM_SCM_RO,
  21. QCOM_SCM_RW,
  22. QCOM_SCM_BUFVAL,
  23. };
  24. #define QCOM_SCM_ARGS_IMPL(num, a, b, c, d, e, f, g, h, i, j, ...) (\
  25. (((a) & 0x3) << 4) | \
  26. (((b) & 0x3) << 6) | \
  27. (((c) & 0x3) << 8) | \
  28. (((d) & 0x3) << 10) | \
  29. (((e) & 0x3) << 12) | \
  30. (((f) & 0x3) << 14) | \
  31. (((g) & 0x3) << 16) | \
  32. (((h) & 0x3) << 18) | \
  33. (((i) & 0x3) << 20) | \
  34. (((j) & 0x3) << 22) | \
  35. ((num) & 0xf))
  36. #define QCOM_SCM_ARGS(...) QCOM_SCM_ARGS_IMPL(__VA_ARGS__, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
  37. /*SMMU Paravirt driver*/
  38. #define SMMU_PARAVIRT_OP_ATTACH 0
  39. #define SMMU_PARAVIRT_OP_DETACH 1
  40. #define SMMU_PARAVIRT_OP_INVAL_ASID 2
  41. #define SMMU_PARAVIRT_OP_INVAL_VA 3
  42. #define SMMU_PARAVIRT_OP_ALL_S1_BYPASS 4
  43. #define SMMU_PARAVIRT_OP_CFGI_CD_ALL 5
  44. #define SMMU_PARAVIRT_OP_TLBI_NH_ALL 6
  45. #define ARM_SMMU_PARAVIRT_CMD 0x6
  46. #define ARM_SMMU_PARAVIRT_DESCARG 0x22200a
  47. /**
  48. * struct qcom_scm_desc
  49. * @arginfo: Metadata describing the arguments in args[]
  50. * @args: The array of arguments for the secure syscall
  51. */
  52. struct qcom_scm_desc {
  53. u32 svc;
  54. u32 cmd;
  55. u32 arginfo;
  56. u64 args[MAX_QCOM_SCM_ARGS];
  57. u32 owner;
  58. bool multicall_allowed;
  59. };
  60. /**
  61. * struct qcom_scm_res
  62. * @result: The values returned by the secure syscall
  63. */
  64. struct qcom_scm_res {
  65. u64 result[MAX_QCOM_SCM_RETS];
  66. };
  67. enum qcom_scm_call_type {
  68. QCOM_SCM_CALL_NORMAL,
  69. QCOM_SCM_CALL_ATOMIC,
  70. QCOM_SCM_CALL_NORETRY,
  71. };
  72. enum qcom_scm_wq_feature {
  73. QCOM_SCM_SINGLE_SMC_ALLOW,
  74. QCOM_SCM_MULTI_SMC_WHITE_LIST_ALLOW, /* Release global lock for certain allowed SMC calls */
  75. };
  76. struct qcom_scm;
  77. extern struct completion *qcom_scm_lookup_wq(struct qcom_scm *scm, u32 wq_ctx);
  78. extern void scm_waitq_flag_handler(struct completion *wq, u32 flags);
  79. extern int scm_get_wq_ctx(u32 *wq_ctx, u32 *flags, u32 *more_pending);
  80. extern bool qcom_scm_multi_call_allow(struct device *dev, bool multicall_allowed);
  81. #define SCM_SMC_FNID(s, c) ((((s) & 0xFF) << 8) | ((c) & 0xFF))
  82. extern int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
  83. enum qcom_scm_convention qcom_convention,
  84. struct qcom_scm_res *res,
  85. enum qcom_scm_call_type call_type);
  86. #define scm_smc_call(dev, desc, res, atomic) \
  87. __scm_smc_call((dev), (desc), qcom_scm_convention, (res), (atomic))
  88. #define SCM_LEGACY_FNID(s, c) (((s) << 10) | ((c) & 0x3ff))
  89. extern int scm_legacy_call_atomic(struct device *dev,
  90. const struct qcom_scm_desc *desc,
  91. struct qcom_scm_res *res);
  92. extern int scm_legacy_call(struct device *dev, const struct qcom_scm_desc *desc,
  93. struct qcom_scm_res *res);
  94. #define QCOM_SCM_SVC_BOOT 0x01
  95. #define QCOM_SCM_BOOT_SET_ADDR 0x01
  96. #define QCOM_SCM_BOOT_TERMINATE_PC 0x02
  97. #define QCOM_SCM_BOOT_SET_DLOAD_MODE 0x10
  98. #define QCOM_SCM_BOOT_SEC_WDOG_DIS 0x07
  99. #define QCOM_SCM_BOOT_SEC_WDOG_TRIGGER 0x08
  100. #define QCOM_SCM_BOOT_WDOG_DEBUG_PART 0x09
  101. #define QCOM_SCM_BOOT_SET_REMOTE_STATE 0x0a
  102. #define QCOM_SCM_BOOT_SPIN_CPU 0x0d
  103. #define QCOM_SCM_BOOT_SWITCH_MODE 0x0f
  104. #define QCOM_SCM_BOOT_SET_DLOAD_MODE 0x10
  105. #define QCOM_SCM_BOOT_CONFIG_CPU_ERRATA 0x12
  106. #define QCOM_SCM_QUSB2PHY_LVL_SHIFTER_CMD_ID 0x1B
  107. #define QCOM_SCM_FLUSH_FLAG_MASK 0x3
  108. #define QCOM_SCM_SVC_PIL 0x02
  109. #define QCOM_SCM_PIL_PAS_INIT_IMAGE 0x01
  110. #define QCOM_SCM_PIL_PAS_MEM_SETUP 0x02
  111. #define QCOM_SCM_PIL_PAS_AUTH_AND_RESET 0x05
  112. #define QCOM_SCM_PIL_PAS_SHUTDOWN 0x06
  113. #define QCOM_SCM_PIL_PAS_IS_SUPPORTED 0x07
  114. #define QCOM_SCM_PIL_PAS_MSS_RESET 0x0a
  115. #define QCOM_SCM_SVC_UTIL 0x03
  116. #define QCOM_SCM_UTIL_GET_SEC_DUMP_STATE 0x10
  117. #define QCOM_SCM_UTIL_DUMP_TABLE_ASSIGN 0x13
  118. #define QCOM_SCM_SVC_TZ 0x04
  119. #define QOCM_SCM_TZ_BLSP_MODIFY_OWNER 0x03
  120. #define QCOM_SCM_SVC_IO 0x05
  121. #define QCOM_SCM_IO_READ 0x01
  122. #define QCOM_SCM_IO_WRITE 0x02
  123. #define QCOM_SCM_IO_RESET 0x03
  124. #define QCOM_SCM_SVC_INFO 0x06
  125. #define QCOM_SCM_INFO_IS_CALL_AVAIL 0x01
  126. #define QCOM_SCM_INFO_GET_FEAT_VERSION_CMD 0x03
  127. #define QCOM_SCM_SVC_PWR 0x09
  128. #define QCOM_SCM_PWR_IO_DISABLE_PMIC_ARBITER 0x01
  129. #define QCOM_SCM_PWR_IO_DEASSERT_PS_HOLD 0x02
  130. #define QCOM_SCM_PWR_MMU_SYNC 0x08
  131. #define QCOM_SCM_SVC_MP 0x0c
  132. #define QCOM_SCM_MP_RESTORE_SEC_CFG 0x02
  133. #define QCOM_SCM_MP_IOMMU_SECURE_PTBL_SIZE 0x03
  134. #define QCOM_SCM_MP_IOMMU_SECURE_PTBL_INIT 0x04
  135. #define QCOM_SCM_MP_VIDEO_VAR 0x08
  136. #define QCOM_SCM_MP_MEM_PROTECT_REGION_ID 0x10
  137. #define QCOM_SCM_MP_MEM_PROTECT_LOCK_ID2_FLAT 0x11
  138. #define QCOM_SCM_MP_IOMMU_SECURE_MAP2_FLAT 0x12
  139. #define QCOM_SCM_MP_IOMMU_SECURE_UNMAP2_FLAT 0x13
  140. #define QCOM_SCM_MP_ASSIGN 0x16
  141. #define QCOM_SCM_MP_CMD_SD_CTRL 0x18
  142. #define QCOM_SCM_MP_CP_SMMU_APERTURE_ID 0x1b
  143. #define QCOM_SCM_MEMP_SHM_BRIDGE_ENABLE 0x1c
  144. #define QCOM_SCM_MEMP_SHM_BRIDGE_DELETE 0x1d
  145. #define QCOM_SCM_MEMP_SHM_BRDIGE_CREATE 0x1e
  146. #define QCOM_SCM_MP_SMMU_PREPARE_ATOS_ID 0x21
  147. #define QCOM_SCM_MP_MPU_LOCK_NS_REGION 0x25
  148. #define QCOM_SCM_IOMMU_TLBINVAL_FLAG 0x00000001
  149. #define QCOM_SCM_CP_APERTURE_REG 0x0
  150. #define QCOM_SCM_CP_LPAC_APERTURE_REG 0x1
  151. #define QCOM_SCM_SVC_DCVS 0x0D
  152. #define QCOM_SCM_DCVS_RESET 0x07
  153. #define QCOM_SCM_DCVS_UPDATE 0x08
  154. #define QCOM_SCM_DCVS_INIT 0x09
  155. #define QCOM_SCM_DCVS_UPDATE_V2 0x0a
  156. #define QCOM_SCM_DCVS_INIT_V2 0x0b
  157. #define QCOM_SCM_DCVS_INIT_CA_V2 0x0c
  158. #define QCOM_SCM_DCVS_UPDATE_CA_V2 0x0d
  159. #define QCOM_SCM_SVC_OCMEM 0x0f
  160. #define QCOM_SCM_OCMEM_LOCK_CMD 0x01
  161. #define QCOM_SCM_OCMEM_UNLOCK_CMD 0x02
  162. #define QCOM_SCM_SVC_ES 0x10 /* Enterprise Security */
  163. #define QCOM_SCM_ES_INVALIDATE_ICE_KEY 0x03
  164. #define QCOM_SCM_ES_CONFIG_SET_ICE_KEY 0x04
  165. #define QCOM_SCM_ES_CONFIG_SET_ICE_KEY_V2 0x05
  166. #define QCOM_SCM_ES_CLEAR_ICE_KEY 0x06
  167. #define QCOM_SCM_ES_DERIVE_RAW_SECRET 0x07
  168. #define QCOM_SCM_SVC_HDCP 0x11
  169. #define QCOM_SCM_HDCP_INVOKE 0x01
  170. #define QCOM_SCM_SVC_LMH 0x13
  171. #define QCOM_SCM_LMH_LIMIT_PROFILE_CHANGE 0x01
  172. #define QCOM_SCM_LMH_DEBUG_SET 0x08
  173. #define QCOM_SCM_LMH_DEBUG_READ_BUF_SIZE 0x09
  174. #define QCOM_SCM_LMH_LIMIT_DCVSH 0x10
  175. #define QCOM_SCM_LMH_DEBUG_READ 0x0A
  176. #define QCOM_SCM_LMH_DEBUG_GET_TYPE 0x0B
  177. #define QCOM_SCM_LMH_DEBUG_FETCH_DATA 0x0D
  178. #define QCOM_SCM_SVC_SMMU_PROGRAM 0x15
  179. #define QCOM_SCM_SMMU_CHANGE_PGTBL_FORMAT 0x01
  180. #define QCOM_SCM_SMMU_SECURE_LUT 0x03
  181. #define QCOM_SCM_SMMU_CONFIG_ERRATA1 0x03
  182. #define QCOM_SCM_SMMU_CONFIG_ERRATA1_CLIENT_ALL 0x02
  183. #define QCOM_SCM_SVC_QDSS 0x16
  184. #define QCOM_SCM_QDSS_INVOKE 0x01
  185. #define QCOM_SCM_SVC_CAMERA 0x18
  186. #define QCOM_SCM_CAMERA_PROTECT_ALL 0x06
  187. #define QCOM_SCM_CAMERA_PROTECT_PHY_LANES 0x07
  188. #define QCOM_SCM_CAMERA_UPDATE_CAMNOC_QOS 0x0A
  189. #define QCOM_SCM_SVC_WAITQ 0x24
  190. #define QCOM_SCM_WAITQ_ACK 0x01
  191. #define QCOM_SCM_WAITQ_RESUME 0x02
  192. #define QCOM_SCM_WAITQ_GET_WQ_CTX 0x03
  193. #define QCOM_SCM_GET_WQ_QUEUE_INFO 0x04
  194. #define QCOM_SCM_SVC_TSENS 0x1E
  195. #define QCOM_SCM_TSENS_INIT_ID 0x5
  196. /* OEM Services and Function IDs */
  197. #define QCOM_SCM_SVC_OEM_POWER 0x09
  198. #define QCOM_SCM_OEM_POWER_REBOOT 0x22
  199. /* GPU Service IDs */
  200. #define QCOM_SCM_SVC_GPU 0x28
  201. #define QCOM_SCM_SVC_GPU_INIT_REGS 0x1
  202. /* TOS Services and Function IDs */
  203. #define QCOM_SCM_SVC_QSEELOG 0x01
  204. #define QCOM_SCM_QSEELOG_REGISTER 0x06
  205. #define QCOM_SCM_QUERY_ENCR_LOG_FEAT_ID 0x0b
  206. #define QCOM_SCM_REQUEST_ENCR_LOG_ID 0x0c
  207. #define QCOM_SCM_SVC_KEYSTORE 0x05
  208. #define QCOM_SCM_ICE_RESTORE_KEY_ID 0x06
  209. #define QCOM_SCM_SVC_SMCINVOKE 0x06
  210. #define QCOM_SCM_SMCINVOKE_INVOKE_LEGACY 0x00
  211. #define QCOM_SCM_SMCINVOKE_INVOKE 0x02
  212. #define QCOM_SCM_SMCINVOKE_CB_RSP 0x01
  213. /* Feature IDs for QCOM_SCM_INFO_GET_FEAT_VERSION */
  214. #define QCOM_SCM_TZ_DBG_ETM_FEAT_ID 0x08
  215. #define QCOM_SCM_FEAT_LOG_ID 0x0a
  216. #define QCOM_SCM_MP_CP_FEAT_ID 0x0c
  217. #define QCOM_SCM_SVC_CPUCFG 0x29
  218. #define QCOM_SCM_CPUCFG_PREFETCH_TGT_CMD 0x1
  219. extern void __qcom_scm_init(void);
  220. extern void __qcom_scm_qcpe_exit(void);
  221. /* common error codes */
  222. #define QCOM_SCM_V2_EBUSY -12
  223. #define QCOM_SCM_ENOMEM -5
  224. #define QCOM_SCM_EOPNOTSUPP -4
  225. #define QCOM_SCM_EINVAL_ADDR -3
  226. #define QCOM_SCM_EINVAL_ARG -2
  227. #define QCOM_SCM_ERROR -1
  228. #define QCOM_SCM_INTERRUPTED 1
  229. #define QCOM_SCM_WAITQ_SLEEP 2
  230. #define QCOM_SCM_WAITQ_WAKE 3
  231. static inline int qcom_scm_remap_error(int err)
  232. {
  233. switch (err) {
  234. case QCOM_SCM_ERROR:
  235. return -EIO;
  236. case QCOM_SCM_EINVAL_ADDR:
  237. case QCOM_SCM_EINVAL_ARG:
  238. return -EINVAL;
  239. case QCOM_SCM_EOPNOTSUPP:
  240. return -EOPNOTSUPP;
  241. case QCOM_SCM_ENOMEM:
  242. return -ENOMEM;
  243. case QCOM_SCM_V2_EBUSY:
  244. return -EBUSY;
  245. }
  246. return -EINVAL;
  247. }
  248. #endif