xref: /openbmc/linux/drivers/firmware/qcom_scm.h (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
197fb5e8dSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
25443cc5fSElliot Berman /* Copyright (c) 2010-2015,2019 The Linux Foundation. All rights reserved.
3b6a1dfbcSKumar Gala  */
4b6a1dfbcSKumar Gala #ifndef __QCOM_SCM_INT_H
5b6a1dfbcSKumar Gala #define __QCOM_SCM_INT_H
69a434ceeSElliot Berman 
79a434ceeSElliot Berman enum qcom_scm_convention {
89a434ceeSElliot Berman 	SMC_CONVENTION_UNKNOWN,
99a434ceeSElliot Berman 	SMC_CONVENTION_LEGACY,
109a434ceeSElliot Berman 	SMC_CONVENTION_ARM_32,
119a434ceeSElliot Berman 	SMC_CONVENTION_ARM_64,
129a434ceeSElliot Berman };
139a434ceeSElliot Berman 
149a434ceeSElliot Berman extern enum qcom_scm_convention qcom_scm_convention;
159a434ceeSElliot Berman 
1657d3b816SElliot Berman #define MAX_QCOM_SCM_ARGS 10
1757d3b816SElliot Berman #define MAX_QCOM_SCM_RETS 3
1857d3b816SElliot Berman 
1957d3b816SElliot Berman enum qcom_scm_arg_types {
2057d3b816SElliot Berman 	QCOM_SCM_VAL,
2157d3b816SElliot Berman 	QCOM_SCM_RO,
2257d3b816SElliot Berman 	QCOM_SCM_RW,
2357d3b816SElliot Berman 	QCOM_SCM_BUFVAL,
2457d3b816SElliot Berman };
2557d3b816SElliot Berman 
2657d3b816SElliot Berman #define QCOM_SCM_ARGS_IMPL(num, a, b, c, d, e, f, g, h, i, j, ...) (\
2757d3b816SElliot Berman 			   (((a) & 0x3) << 4) | \
2857d3b816SElliot Berman 			   (((b) & 0x3) << 6) | \
2957d3b816SElliot Berman 			   (((c) & 0x3) << 8) | \
3057d3b816SElliot Berman 			   (((d) & 0x3) << 10) | \
3157d3b816SElliot Berman 			   (((e) & 0x3) << 12) | \
3257d3b816SElliot Berman 			   (((f) & 0x3) << 14) | \
3357d3b816SElliot Berman 			   (((g) & 0x3) << 16) | \
3457d3b816SElliot Berman 			   (((h) & 0x3) << 18) | \
3557d3b816SElliot Berman 			   (((i) & 0x3) << 20) | \
3657d3b816SElliot Berman 			   (((j) & 0x3) << 22) | \
3757d3b816SElliot Berman 			   ((num) & 0xf))
3857d3b816SElliot Berman 
3957d3b816SElliot Berman #define QCOM_SCM_ARGS(...) QCOM_SCM_ARGS_IMPL(__VA_ARGS__, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
4057d3b816SElliot Berman 
4157d3b816SElliot Berman 
4257d3b816SElliot Berman /**
4357d3b816SElliot Berman  * struct qcom_scm_desc
4457d3b816SElliot Berman  * @arginfo:	Metadata describing the arguments in args[]
4557d3b816SElliot Berman  * @args:	The array of arguments for the secure syscall
4657d3b816SElliot Berman  */
4757d3b816SElliot Berman struct qcom_scm_desc {
4857d3b816SElliot Berman 	u32 svc;
4957d3b816SElliot Berman 	u32 cmd;
5057d3b816SElliot Berman 	u32 arginfo;
5157d3b816SElliot Berman 	u64 args[MAX_QCOM_SCM_ARGS];
5257d3b816SElliot Berman 	u32 owner;
5357d3b816SElliot Berman };
5457d3b816SElliot Berman 
5557d3b816SElliot Berman /**
5657d3b816SElliot Berman  * struct qcom_scm_res
5757d3b816SElliot Berman  * @result:	The values returned by the secure syscall
5857d3b816SElliot Berman  */
5957d3b816SElliot Berman struct qcom_scm_res {
6057d3b816SElliot Berman 	u64 result[MAX_QCOM_SCM_RETS];
6157d3b816SElliot Berman };
6257d3b816SElliot Berman 
63*6bf32599SGuru Das Srinagesh int qcom_scm_wait_for_wq_completion(u32 wq_ctx);
64*6bf32599SGuru Das Srinagesh int scm_get_wq_ctx(u32 *wq_ctx, u32 *flags, u32 *more_pending);
65*6bf32599SGuru Das Srinagesh 
669a434ceeSElliot Berman #define SCM_SMC_FNID(s, c)	((((s) & 0xFF) << 8) | ((c) & 0xFF))
67f6ea568fSStephen Boyd extern int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
68f6ea568fSStephen Boyd 			  enum qcom_scm_convention qcom_convention,
699a434ceeSElliot Berman 			  struct qcom_scm_res *res, bool atomic);
70f6ea568fSStephen Boyd #define scm_smc_call(dev, desc, res, atomic) \
71f6ea568fSStephen Boyd 	__scm_smc_call((dev), (desc), qcom_scm_convention, (res), (atomic))
729a434ceeSElliot Berman 
739a434ceeSElliot Berman #define SCM_LEGACY_FNID(s, c)	(((s) << 10) | ((c) & 0x3ff))
749a434ceeSElliot Berman extern int scm_legacy_call_atomic(struct device *dev,
7557d3b816SElliot Berman 				  const struct qcom_scm_desc *desc,
7657d3b816SElliot Berman 				  struct qcom_scm_res *res);
779a434ceeSElliot Berman extern int scm_legacy_call(struct device *dev, const struct qcom_scm_desc *desc,
789a434ceeSElliot Berman 			   struct qcom_scm_res *res);
79b6a1dfbcSKumar Gala 
8065f0c90bSElliot Berman #define QCOM_SCM_SVC_BOOT		0x01
8165f0c90bSElliot Berman #define QCOM_SCM_BOOT_SET_ADDR		0x01
8265f0c90bSElliot Berman #define QCOM_SCM_BOOT_TERMINATE_PC	0x02
835443cc5fSElliot Berman #define QCOM_SCM_BOOT_SET_DLOAD_MODE	0x10
84f60a317bSStephan Gerhold #define QCOM_SCM_BOOT_SET_ADDR_MC	0x11
8565f0c90bSElliot Berman #define QCOM_SCM_BOOT_SET_REMOTE_STATE	0x0a
8665f0c90bSElliot Berman #define QCOM_SCM_FLUSH_FLAG_MASK	0x3
877734c4b5SStephan Gerhold #define QCOM_SCM_BOOT_MAX_CPUS		4
88f60a317bSStephan Gerhold #define QCOM_SCM_BOOT_MC_FLAG_AARCH64	BIT(0)
89f60a317bSStephan Gerhold #define QCOM_SCM_BOOT_MC_FLAG_COLDBOOT	BIT(1)
90f60a317bSStephan Gerhold #define QCOM_SCM_BOOT_MC_FLAG_WARMBOOT	BIT(2)
91b6a1dfbcSKumar Gala 
9265f0c90bSElliot Berman #define QCOM_SCM_SVC_PIL		0x02
9365f0c90bSElliot Berman #define QCOM_SCM_PIL_PAS_INIT_IMAGE	0x01
9465f0c90bSElliot Berman #define QCOM_SCM_PIL_PAS_MEM_SETUP	0x02
9565f0c90bSElliot Berman #define QCOM_SCM_PIL_PAS_AUTH_AND_RESET	0x05
9665f0c90bSElliot Berman #define QCOM_SCM_PIL_PAS_SHUTDOWN	0x06
9765f0c90bSElliot Berman #define QCOM_SCM_PIL_PAS_IS_SUPPORTED	0x07
9865f0c90bSElliot Berman #define QCOM_SCM_PIL_PAS_MSS_RESET	0x0a
99f01e90feSBjorn Andersson 
10065f0c90bSElliot Berman #define QCOM_SCM_SVC_IO			0x05
10165f0c90bSElliot Berman #define QCOM_SCM_IO_READ		0x01
10265f0c90bSElliot Berman #define QCOM_SCM_IO_WRITE		0x02
10365f0c90bSElliot Berman 
10465f0c90bSElliot Berman #define QCOM_SCM_SVC_INFO		0x06
10565f0c90bSElliot Berman #define QCOM_SCM_INFO_IS_CALL_AVAIL	0x01
10665f0c90bSElliot Berman 
10765f0c90bSElliot Berman #define QCOM_SCM_SVC_MP				0x0c
10865f0c90bSElliot Berman #define QCOM_SCM_MP_RESTORE_SEC_CFG		0x02
10965f0c90bSElliot Berman #define QCOM_SCM_MP_IOMMU_SECURE_PTBL_SIZE	0x03
11065f0c90bSElliot Berman #define QCOM_SCM_MP_IOMMU_SECURE_PTBL_INIT	0x04
11194351509SAngeloGioacchino Del Regno #define QCOM_SCM_MP_IOMMU_SET_CP_POOL_SIZE	0x05
1126d885330SStanimir Varbanov #define QCOM_SCM_MP_VIDEO_VAR			0x08
11365f0c90bSElliot Berman #define QCOM_SCM_MP_ASSIGN			0x16
11465f0c90bSElliot Berman 
11565f0c90bSElliot Berman #define QCOM_SCM_SVC_OCMEM		0x0f
11665f0c90bSElliot Berman #define QCOM_SCM_OCMEM_LOCK_CMD		0x01
11765f0c90bSElliot Berman #define QCOM_SCM_OCMEM_UNLOCK_CMD	0x02
11865f0c90bSElliot Berman 
1190f206514SEric Biggers #define QCOM_SCM_SVC_ES			0x10	/* Enterprise Security */
1200f206514SEric Biggers #define QCOM_SCM_ES_INVALIDATE_ICE_KEY	0x03
1210f206514SEric Biggers #define QCOM_SCM_ES_CONFIG_SET_ICE_KEY	0x04
1220f206514SEric Biggers 
12365f0c90bSElliot Berman #define QCOM_SCM_SVC_HDCP		0x11
12465f0c90bSElliot Berman #define QCOM_SCM_HDCP_INVOKE		0x01
12565f0c90bSElliot Berman 
126de3438c4SThara Gopinath #define QCOM_SCM_SVC_LMH			0x13
127de3438c4SThara Gopinath #define QCOM_SCM_LMH_LIMIT_PROFILE_CHANGE	0x01
128de3438c4SThara Gopinath #define QCOM_SCM_LMH_LIMIT_DCVSH		0x10
129de3438c4SThara Gopinath 
13065f0c90bSElliot Berman #define QCOM_SCM_SVC_SMMU_PROGRAM		0x15
131071a1333SAngeloGioacchino Del Regno #define QCOM_SCM_SMMU_PT_FORMAT			0x01
13265f0c90bSElliot Berman #define QCOM_SCM_SMMU_CONFIG_ERRATA1		0x03
13365f0c90bSElliot Berman #define QCOM_SCM_SMMU_CONFIG_ERRATA1_CLIENT_ALL	0x02
13465f0c90bSElliot Berman 
135*6bf32599SGuru Das Srinagesh #define QCOM_SCM_SVC_WAITQ			0x24
136*6bf32599SGuru Das Srinagesh #define QCOM_SCM_WAITQ_RESUME			0x02
137*6bf32599SGuru Das Srinagesh #define QCOM_SCM_WAITQ_GET_WQ_CTX		0x03
138*6bf32599SGuru Das Srinagesh 
139b6a1dfbcSKumar Gala /* common error codes */
1406b1751a8SKumar Gala #define QCOM_SCM_V2_EBUSY	-12
141b6a1dfbcSKumar Gala #define QCOM_SCM_ENOMEM		-5
142b6a1dfbcSKumar Gala #define QCOM_SCM_EOPNOTSUPP	-4
143b6a1dfbcSKumar Gala #define QCOM_SCM_EINVAL_ADDR	-3
144b6a1dfbcSKumar Gala #define QCOM_SCM_EINVAL_ARG	-2
145b6a1dfbcSKumar Gala #define QCOM_SCM_ERROR		-1
146b6a1dfbcSKumar Gala #define QCOM_SCM_INTERRUPTED	1
147*6bf32599SGuru Das Srinagesh #define QCOM_SCM_WAITQ_SLEEP	2
148b6a1dfbcSKumar Gala 
qcom_scm_remap_error(int err)14911bdcee4SAndy Gross static inline int qcom_scm_remap_error(int err)
15011bdcee4SAndy Gross {
15111bdcee4SAndy Gross 	switch (err) {
15211bdcee4SAndy Gross 	case QCOM_SCM_ERROR:
15311bdcee4SAndy Gross 		return -EIO;
15411bdcee4SAndy Gross 	case QCOM_SCM_EINVAL_ADDR:
15511bdcee4SAndy Gross 	case QCOM_SCM_EINVAL_ARG:
15611bdcee4SAndy Gross 		return -EINVAL;
15711bdcee4SAndy Gross 	case QCOM_SCM_EOPNOTSUPP:
15811bdcee4SAndy Gross 		return -EOPNOTSUPP;
15911bdcee4SAndy Gross 	case QCOM_SCM_ENOMEM:
16011bdcee4SAndy Gross 		return -ENOMEM;
1616b1751a8SKumar Gala 	case QCOM_SCM_V2_EBUSY:
1626b1751a8SKumar Gala 		return -EBUSY;
16311bdcee4SAndy Gross 	}
16411bdcee4SAndy Gross 	return -EINVAL;
16511bdcee4SAndy Gross }
16611bdcee4SAndy Gross 
167b6a1dfbcSKumar Gala #endif
168