18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/* Copyright (c) 2010-2015,2019 The Linux Foundation. All rights reserved.
38c2ecf20Sopenharmony_ci */
48c2ecf20Sopenharmony_ci#ifndef __QCOM_SCM_INT_H
58c2ecf20Sopenharmony_ci#define __QCOM_SCM_INT_H
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_cienum qcom_scm_convention {
88c2ecf20Sopenharmony_ci	SMC_CONVENTION_UNKNOWN,
98c2ecf20Sopenharmony_ci	SMC_CONVENTION_LEGACY,
108c2ecf20Sopenharmony_ci	SMC_CONVENTION_ARM_32,
118c2ecf20Sopenharmony_ci	SMC_CONVENTION_ARM_64,
128c2ecf20Sopenharmony_ci};
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciextern enum qcom_scm_convention qcom_scm_convention;
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define MAX_QCOM_SCM_ARGS 10
178c2ecf20Sopenharmony_ci#define MAX_QCOM_SCM_RETS 3
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cienum qcom_scm_arg_types {
208c2ecf20Sopenharmony_ci	QCOM_SCM_VAL,
218c2ecf20Sopenharmony_ci	QCOM_SCM_RO,
228c2ecf20Sopenharmony_ci	QCOM_SCM_RW,
238c2ecf20Sopenharmony_ci	QCOM_SCM_BUFVAL,
248c2ecf20Sopenharmony_ci};
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define QCOM_SCM_ARGS_IMPL(num, a, b, c, d, e, f, g, h, i, j, ...) (\
278c2ecf20Sopenharmony_ci			   (((a) & 0x3) << 4) | \
288c2ecf20Sopenharmony_ci			   (((b) & 0x3) << 6) | \
298c2ecf20Sopenharmony_ci			   (((c) & 0x3) << 8) | \
308c2ecf20Sopenharmony_ci			   (((d) & 0x3) << 10) | \
318c2ecf20Sopenharmony_ci			   (((e) & 0x3) << 12) | \
328c2ecf20Sopenharmony_ci			   (((f) & 0x3) << 14) | \
338c2ecf20Sopenharmony_ci			   (((g) & 0x3) << 16) | \
348c2ecf20Sopenharmony_ci			   (((h) & 0x3) << 18) | \
358c2ecf20Sopenharmony_ci			   (((i) & 0x3) << 20) | \
368c2ecf20Sopenharmony_ci			   (((j) & 0x3) << 22) | \
378c2ecf20Sopenharmony_ci			   ((num) & 0xf))
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define QCOM_SCM_ARGS(...) QCOM_SCM_ARGS_IMPL(__VA_ARGS__, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/**
438c2ecf20Sopenharmony_ci * struct qcom_scm_desc
448c2ecf20Sopenharmony_ci * @arginfo:	Metadata describing the arguments in args[]
458c2ecf20Sopenharmony_ci * @args:	The array of arguments for the secure syscall
468c2ecf20Sopenharmony_ci */
478c2ecf20Sopenharmony_cistruct qcom_scm_desc {
488c2ecf20Sopenharmony_ci	u32 svc;
498c2ecf20Sopenharmony_ci	u32 cmd;
508c2ecf20Sopenharmony_ci	u32 arginfo;
518c2ecf20Sopenharmony_ci	u64 args[MAX_QCOM_SCM_ARGS];
528c2ecf20Sopenharmony_ci	u32 owner;
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/**
568c2ecf20Sopenharmony_ci * struct qcom_scm_res
578c2ecf20Sopenharmony_ci * @result:	The values returned by the secure syscall
588c2ecf20Sopenharmony_ci */
598c2ecf20Sopenharmony_cistruct qcom_scm_res {
608c2ecf20Sopenharmony_ci	u64 result[MAX_QCOM_SCM_RETS];
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define SCM_SMC_FNID(s, c)	((((s) & 0xFF) << 8) | ((c) & 0xFF))
648c2ecf20Sopenharmony_ciextern int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
658c2ecf20Sopenharmony_ci			  enum qcom_scm_convention qcom_convention,
668c2ecf20Sopenharmony_ci			  struct qcom_scm_res *res, bool atomic);
678c2ecf20Sopenharmony_ci#define scm_smc_call(dev, desc, res, atomic) \
688c2ecf20Sopenharmony_ci	__scm_smc_call((dev), (desc), qcom_scm_convention, (res), (atomic))
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#define SCM_LEGACY_FNID(s, c)	(((s) << 10) | ((c) & 0x3ff))
718c2ecf20Sopenharmony_ciextern int scm_legacy_call_atomic(struct device *dev,
728c2ecf20Sopenharmony_ci				  const struct qcom_scm_desc *desc,
738c2ecf20Sopenharmony_ci				  struct qcom_scm_res *res);
748c2ecf20Sopenharmony_ciextern int scm_legacy_call(struct device *dev, const struct qcom_scm_desc *desc,
758c2ecf20Sopenharmony_ci			   struct qcom_scm_res *res);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#define QCOM_SCM_SVC_BOOT		0x01
788c2ecf20Sopenharmony_ci#define QCOM_SCM_BOOT_SET_ADDR		0x01
798c2ecf20Sopenharmony_ci#define QCOM_SCM_BOOT_TERMINATE_PC	0x02
808c2ecf20Sopenharmony_ci#define QCOM_SCM_BOOT_SET_DLOAD_MODE	0x10
818c2ecf20Sopenharmony_ci#define QCOM_SCM_BOOT_SET_REMOTE_STATE	0x0a
828c2ecf20Sopenharmony_ci#define QCOM_SCM_FLUSH_FLAG_MASK	0x3
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define QCOM_SCM_SVC_PIL		0x02
858c2ecf20Sopenharmony_ci#define QCOM_SCM_PIL_PAS_INIT_IMAGE	0x01
868c2ecf20Sopenharmony_ci#define QCOM_SCM_PIL_PAS_MEM_SETUP	0x02
878c2ecf20Sopenharmony_ci#define QCOM_SCM_PIL_PAS_AUTH_AND_RESET	0x05
888c2ecf20Sopenharmony_ci#define QCOM_SCM_PIL_PAS_SHUTDOWN	0x06
898c2ecf20Sopenharmony_ci#define QCOM_SCM_PIL_PAS_IS_SUPPORTED	0x07
908c2ecf20Sopenharmony_ci#define QCOM_SCM_PIL_PAS_MSS_RESET	0x0a
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define QCOM_SCM_SVC_IO			0x05
938c2ecf20Sopenharmony_ci#define QCOM_SCM_IO_READ		0x01
948c2ecf20Sopenharmony_ci#define QCOM_SCM_IO_WRITE		0x02
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#define QCOM_SCM_SVC_INFO		0x06
978c2ecf20Sopenharmony_ci#define QCOM_SCM_INFO_IS_CALL_AVAIL	0x01
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define QCOM_SCM_SVC_MP				0x0c
1008c2ecf20Sopenharmony_ci#define QCOM_SCM_MP_RESTORE_SEC_CFG		0x02
1018c2ecf20Sopenharmony_ci#define QCOM_SCM_MP_IOMMU_SECURE_PTBL_SIZE	0x03
1028c2ecf20Sopenharmony_ci#define QCOM_SCM_MP_IOMMU_SECURE_PTBL_INIT	0x04
1038c2ecf20Sopenharmony_ci#define QCOM_SCM_MP_VIDEO_VAR			0x08
1048c2ecf20Sopenharmony_ci#define QCOM_SCM_MP_ASSIGN			0x16
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define QCOM_SCM_SVC_OCMEM		0x0f
1078c2ecf20Sopenharmony_ci#define QCOM_SCM_OCMEM_LOCK_CMD		0x01
1088c2ecf20Sopenharmony_ci#define QCOM_SCM_OCMEM_UNLOCK_CMD	0x02
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#define QCOM_SCM_SVC_ES			0x10	/* Enterprise Security */
1118c2ecf20Sopenharmony_ci#define QCOM_SCM_ES_INVALIDATE_ICE_KEY	0x03
1128c2ecf20Sopenharmony_ci#define QCOM_SCM_ES_CONFIG_SET_ICE_KEY	0x04
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#define QCOM_SCM_SVC_HDCP		0x11
1158c2ecf20Sopenharmony_ci#define QCOM_SCM_HDCP_INVOKE		0x01
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#define QCOM_SCM_SVC_SMMU_PROGRAM		0x15
1188c2ecf20Sopenharmony_ci#define QCOM_SCM_SMMU_CONFIG_ERRATA1		0x03
1198c2ecf20Sopenharmony_ci#define QCOM_SCM_SMMU_CONFIG_ERRATA1_CLIENT_ALL	0x02
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ciextern void __qcom_scm_init(void);
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci/* common error codes */
1248c2ecf20Sopenharmony_ci#define QCOM_SCM_V2_EBUSY	-12
1258c2ecf20Sopenharmony_ci#define QCOM_SCM_ENOMEM		-5
1268c2ecf20Sopenharmony_ci#define QCOM_SCM_EOPNOTSUPP	-4
1278c2ecf20Sopenharmony_ci#define QCOM_SCM_EINVAL_ADDR	-3
1288c2ecf20Sopenharmony_ci#define QCOM_SCM_EINVAL_ARG	-2
1298c2ecf20Sopenharmony_ci#define QCOM_SCM_ERROR		-1
1308c2ecf20Sopenharmony_ci#define QCOM_SCM_INTERRUPTED	1
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic inline int qcom_scm_remap_error(int err)
1338c2ecf20Sopenharmony_ci{
1348c2ecf20Sopenharmony_ci	switch (err) {
1358c2ecf20Sopenharmony_ci	case QCOM_SCM_ERROR:
1368c2ecf20Sopenharmony_ci		return -EIO;
1378c2ecf20Sopenharmony_ci	case QCOM_SCM_EINVAL_ADDR:
1388c2ecf20Sopenharmony_ci	case QCOM_SCM_EINVAL_ARG:
1398c2ecf20Sopenharmony_ci		return -EINVAL;
1408c2ecf20Sopenharmony_ci	case QCOM_SCM_EOPNOTSUPP:
1418c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
1428c2ecf20Sopenharmony_ci	case QCOM_SCM_ENOMEM:
1438c2ecf20Sopenharmony_ci		return -ENOMEM;
1448c2ecf20Sopenharmony_ci	case QCOM_SCM_V2_EBUSY:
1458c2ecf20Sopenharmony_ci		return -EBUSY;
1468c2ecf20Sopenharmony_ci	}
1478c2ecf20Sopenharmony_ci	return -EINVAL;
1488c2ecf20Sopenharmony_ci}
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#endif
151