162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/* Copyright (c) 2010-2015,2019 The Linux Foundation. All rights reserved.
362306a36Sopenharmony_ci */
462306a36Sopenharmony_ci#ifndef __QCOM_SCM_INT_H
562306a36Sopenharmony_ci#define __QCOM_SCM_INT_H
662306a36Sopenharmony_ci
762306a36Sopenharmony_cienum qcom_scm_convention {
862306a36Sopenharmony_ci	SMC_CONVENTION_UNKNOWN,
962306a36Sopenharmony_ci	SMC_CONVENTION_LEGACY,
1062306a36Sopenharmony_ci	SMC_CONVENTION_ARM_32,
1162306a36Sopenharmony_ci	SMC_CONVENTION_ARM_64,
1262306a36Sopenharmony_ci};
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciextern enum qcom_scm_convention qcom_scm_convention;
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define MAX_QCOM_SCM_ARGS 10
1762306a36Sopenharmony_ci#define MAX_QCOM_SCM_RETS 3
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cienum qcom_scm_arg_types {
2062306a36Sopenharmony_ci	QCOM_SCM_VAL,
2162306a36Sopenharmony_ci	QCOM_SCM_RO,
2262306a36Sopenharmony_ci	QCOM_SCM_RW,
2362306a36Sopenharmony_ci	QCOM_SCM_BUFVAL,
2462306a36Sopenharmony_ci};
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define QCOM_SCM_ARGS_IMPL(num, a, b, c, d, e, f, g, h, i, j, ...) (\
2762306a36Sopenharmony_ci			   (((a) & 0x3) << 4) | \
2862306a36Sopenharmony_ci			   (((b) & 0x3) << 6) | \
2962306a36Sopenharmony_ci			   (((c) & 0x3) << 8) | \
3062306a36Sopenharmony_ci			   (((d) & 0x3) << 10) | \
3162306a36Sopenharmony_ci			   (((e) & 0x3) << 12) | \
3262306a36Sopenharmony_ci			   (((f) & 0x3) << 14) | \
3362306a36Sopenharmony_ci			   (((g) & 0x3) << 16) | \
3462306a36Sopenharmony_ci			   (((h) & 0x3) << 18) | \
3562306a36Sopenharmony_ci			   (((i) & 0x3) << 20) | \
3662306a36Sopenharmony_ci			   (((j) & 0x3) << 22) | \
3762306a36Sopenharmony_ci			   ((num) & 0xf))
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#define QCOM_SCM_ARGS(...) QCOM_SCM_ARGS_IMPL(__VA_ARGS__, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/**
4362306a36Sopenharmony_ci * struct qcom_scm_desc
4462306a36Sopenharmony_ci * @arginfo:	Metadata describing the arguments in args[]
4562306a36Sopenharmony_ci * @args:	The array of arguments for the secure syscall
4662306a36Sopenharmony_ci */
4762306a36Sopenharmony_cistruct qcom_scm_desc {
4862306a36Sopenharmony_ci	u32 svc;
4962306a36Sopenharmony_ci	u32 cmd;
5062306a36Sopenharmony_ci	u32 arginfo;
5162306a36Sopenharmony_ci	u64 args[MAX_QCOM_SCM_ARGS];
5262306a36Sopenharmony_ci	u32 owner;
5362306a36Sopenharmony_ci};
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/**
5662306a36Sopenharmony_ci * struct qcom_scm_res
5762306a36Sopenharmony_ci * @result:	The values returned by the secure syscall
5862306a36Sopenharmony_ci */
5962306a36Sopenharmony_cistruct qcom_scm_res {
6062306a36Sopenharmony_ci	u64 result[MAX_QCOM_SCM_RETS];
6162306a36Sopenharmony_ci};
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ciint qcom_scm_wait_for_wq_completion(u32 wq_ctx);
6462306a36Sopenharmony_ciint scm_get_wq_ctx(u32 *wq_ctx, u32 *flags, u32 *more_pending);
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define SCM_SMC_FNID(s, c)	((((s) & 0xFF) << 8) | ((c) & 0xFF))
6762306a36Sopenharmony_ciextern int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
6862306a36Sopenharmony_ci			  enum qcom_scm_convention qcom_convention,
6962306a36Sopenharmony_ci			  struct qcom_scm_res *res, bool atomic);
7062306a36Sopenharmony_ci#define scm_smc_call(dev, desc, res, atomic) \
7162306a36Sopenharmony_ci	__scm_smc_call((dev), (desc), qcom_scm_convention, (res), (atomic))
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci#define SCM_LEGACY_FNID(s, c)	(((s) << 10) | ((c) & 0x3ff))
7462306a36Sopenharmony_ciextern int scm_legacy_call_atomic(struct device *dev,
7562306a36Sopenharmony_ci				  const struct qcom_scm_desc *desc,
7662306a36Sopenharmony_ci				  struct qcom_scm_res *res);
7762306a36Sopenharmony_ciextern int scm_legacy_call(struct device *dev, const struct qcom_scm_desc *desc,
7862306a36Sopenharmony_ci			   struct qcom_scm_res *res);
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#define QCOM_SCM_SVC_BOOT		0x01
8162306a36Sopenharmony_ci#define QCOM_SCM_BOOT_SET_ADDR		0x01
8262306a36Sopenharmony_ci#define QCOM_SCM_BOOT_TERMINATE_PC	0x02
8362306a36Sopenharmony_ci#define QCOM_SCM_BOOT_SET_DLOAD_MODE	0x10
8462306a36Sopenharmony_ci#define QCOM_SCM_BOOT_SET_ADDR_MC	0x11
8562306a36Sopenharmony_ci#define QCOM_SCM_BOOT_SET_REMOTE_STATE	0x0a
8662306a36Sopenharmony_ci#define QCOM_SCM_FLUSH_FLAG_MASK	0x3
8762306a36Sopenharmony_ci#define QCOM_SCM_BOOT_MAX_CPUS		4
8862306a36Sopenharmony_ci#define QCOM_SCM_BOOT_MC_FLAG_AARCH64	BIT(0)
8962306a36Sopenharmony_ci#define QCOM_SCM_BOOT_MC_FLAG_COLDBOOT	BIT(1)
9062306a36Sopenharmony_ci#define QCOM_SCM_BOOT_MC_FLAG_WARMBOOT	BIT(2)
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci#define QCOM_SCM_SVC_PIL		0x02
9362306a36Sopenharmony_ci#define QCOM_SCM_PIL_PAS_INIT_IMAGE	0x01
9462306a36Sopenharmony_ci#define QCOM_SCM_PIL_PAS_MEM_SETUP	0x02
9562306a36Sopenharmony_ci#define QCOM_SCM_PIL_PAS_AUTH_AND_RESET	0x05
9662306a36Sopenharmony_ci#define QCOM_SCM_PIL_PAS_SHUTDOWN	0x06
9762306a36Sopenharmony_ci#define QCOM_SCM_PIL_PAS_IS_SUPPORTED	0x07
9862306a36Sopenharmony_ci#define QCOM_SCM_PIL_PAS_MSS_RESET	0x0a
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci#define QCOM_SCM_SVC_IO			0x05
10162306a36Sopenharmony_ci#define QCOM_SCM_IO_READ		0x01
10262306a36Sopenharmony_ci#define QCOM_SCM_IO_WRITE		0x02
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#define QCOM_SCM_SVC_INFO		0x06
10562306a36Sopenharmony_ci#define QCOM_SCM_INFO_IS_CALL_AVAIL	0x01
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci#define QCOM_SCM_SVC_MP				0x0c
10862306a36Sopenharmony_ci#define QCOM_SCM_MP_RESTORE_SEC_CFG		0x02
10962306a36Sopenharmony_ci#define QCOM_SCM_MP_IOMMU_SECURE_PTBL_SIZE	0x03
11062306a36Sopenharmony_ci#define QCOM_SCM_MP_IOMMU_SECURE_PTBL_INIT	0x04
11162306a36Sopenharmony_ci#define QCOM_SCM_MP_IOMMU_SET_CP_POOL_SIZE	0x05
11262306a36Sopenharmony_ci#define QCOM_SCM_MP_VIDEO_VAR			0x08
11362306a36Sopenharmony_ci#define QCOM_SCM_MP_ASSIGN			0x16
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci#define QCOM_SCM_SVC_OCMEM		0x0f
11662306a36Sopenharmony_ci#define QCOM_SCM_OCMEM_LOCK_CMD		0x01
11762306a36Sopenharmony_ci#define QCOM_SCM_OCMEM_UNLOCK_CMD	0x02
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci#define QCOM_SCM_SVC_ES			0x10	/* Enterprise Security */
12062306a36Sopenharmony_ci#define QCOM_SCM_ES_INVALIDATE_ICE_KEY	0x03
12162306a36Sopenharmony_ci#define QCOM_SCM_ES_CONFIG_SET_ICE_KEY	0x04
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci#define QCOM_SCM_SVC_HDCP		0x11
12462306a36Sopenharmony_ci#define QCOM_SCM_HDCP_INVOKE		0x01
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci#define QCOM_SCM_SVC_LMH			0x13
12762306a36Sopenharmony_ci#define QCOM_SCM_LMH_LIMIT_PROFILE_CHANGE	0x01
12862306a36Sopenharmony_ci#define QCOM_SCM_LMH_LIMIT_DCVSH		0x10
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci#define QCOM_SCM_SVC_SMMU_PROGRAM		0x15
13162306a36Sopenharmony_ci#define QCOM_SCM_SMMU_PT_FORMAT			0x01
13262306a36Sopenharmony_ci#define QCOM_SCM_SMMU_CONFIG_ERRATA1		0x03
13362306a36Sopenharmony_ci#define QCOM_SCM_SMMU_CONFIG_ERRATA1_CLIENT_ALL	0x02
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci#define QCOM_SCM_SVC_WAITQ			0x24
13662306a36Sopenharmony_ci#define QCOM_SCM_WAITQ_RESUME			0x02
13762306a36Sopenharmony_ci#define QCOM_SCM_WAITQ_GET_WQ_CTX		0x03
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci/* common error codes */
14062306a36Sopenharmony_ci#define QCOM_SCM_V2_EBUSY	-12
14162306a36Sopenharmony_ci#define QCOM_SCM_ENOMEM		-5
14262306a36Sopenharmony_ci#define QCOM_SCM_EOPNOTSUPP	-4
14362306a36Sopenharmony_ci#define QCOM_SCM_EINVAL_ADDR	-3
14462306a36Sopenharmony_ci#define QCOM_SCM_EINVAL_ARG	-2
14562306a36Sopenharmony_ci#define QCOM_SCM_ERROR		-1
14662306a36Sopenharmony_ci#define QCOM_SCM_INTERRUPTED	1
14762306a36Sopenharmony_ci#define QCOM_SCM_WAITQ_SLEEP	2
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_cistatic inline int qcom_scm_remap_error(int err)
15062306a36Sopenharmony_ci{
15162306a36Sopenharmony_ci	switch (err) {
15262306a36Sopenharmony_ci	case QCOM_SCM_ERROR:
15362306a36Sopenharmony_ci		return -EIO;
15462306a36Sopenharmony_ci	case QCOM_SCM_EINVAL_ADDR:
15562306a36Sopenharmony_ci	case QCOM_SCM_EINVAL_ARG:
15662306a36Sopenharmony_ci		return -EINVAL;
15762306a36Sopenharmony_ci	case QCOM_SCM_EOPNOTSUPP:
15862306a36Sopenharmony_ci		return -EOPNOTSUPP;
15962306a36Sopenharmony_ci	case QCOM_SCM_ENOMEM:
16062306a36Sopenharmony_ci		return -ENOMEM;
16162306a36Sopenharmony_ci	case QCOM_SCM_V2_EBUSY:
16262306a36Sopenharmony_ci		return -EBUSY;
16362306a36Sopenharmony_ci	}
16462306a36Sopenharmony_ci	return -EINVAL;
16562306a36Sopenharmony_ci}
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci#endif
168