Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 329a94d9 authored by Abhijit Kulkarni's avatar Abhijit Kulkarni
Browse files

drm/msm/sde: add support to attach/detach context banks



This change adds API to attach detach the context. This change is
required for secure display and secure camera preview use cases.
The APIs provide support to attach/detach all contexts or only
secure contexts.

CRs-Fixed: 2064272
Change-Id: Ie6784920df4e03f1dafce54e22e2996923c01054
Signed-off-by: default avatarAbhijit Kulkarni <kabhijit@codeaurora.org>
parent 4d9a308b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ struct msm_gem_address_space {
	const char *name;
	struct msm_mmu *mmu;
	const struct msm_gem_aspace_ops *ops;
	bool domain_attached;
};

struct msm_gem_vma {
+1 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ struct msm_mmu_funcs {
	void (*unmap_dma_buf)(struct msm_mmu *mmu, struct sg_table *sgt,
			struct dma_buf *dma_buf, int dir);
	void (*destroy)(struct msm_mmu *mmu);
	bool (*is_domain_secure)(struct msm_mmu *mmu);
};

struct msm_mmu {
+11 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ struct msm_smmu_client {
	struct device *dev;
	struct dma_iommu_mapping *mmu_mapping;
	bool domain_attached;
	bool secure;
};

struct msm_smmu {
@@ -275,6 +276,14 @@ static void msm_smmu_unmap_dma_buf(struct msm_mmu *mmu, struct sg_table *sgt,
	msm_dma_unmap_sg(client->dev, sgt->sgl, sgt->nents, dir, dma_buf);
}

static bool msm_smmu_is_domain_secure(struct msm_mmu *mmu)
{
	struct msm_smmu *smmu = to_msm_smmu(mmu);
	struct msm_smmu_client *client = msm_smmu_to_client(smmu);

	return client->secure;
}

static const struct msm_mmu_funcs funcs = {
	.attach = msm_smmu_attach,
	.detach = msm_smmu_detach,
@@ -285,6 +294,7 @@ static const struct msm_mmu_funcs funcs = {
	.map_dma_buf = msm_smmu_map_dma_buf,
	.unmap_dma_buf = msm_smmu_unmap_dma_buf,
	.destroy = msm_smmu_destroy,
	.is_domain_secure = msm_smmu_is_domain_secure,
};

static struct msm_smmu_domain msm_smmu_domains[MSM_SMMU_DOMAIN_MAX] = {
@@ -458,6 +468,7 @@ static int _msm_smmu_create_mapping(struct msm_smmu_client *client,
	if (domain->secure) {
		int secure_vmid = VMID_CP_PIXEL;

		client->secure = true;
		rc = iommu_domain_set_attr(client->mmu_mapping->domain,
				DOMAIN_ATTR_SECURE_VMID, &secure_vmid);
		if (rc) {
+61 −1
Original line number Diff line number Diff line
@@ -1344,6 +1344,66 @@ static void _sde_kms_hw_destroy(struct sde_kms *sde_kms,
	sde_reg_dma_deinit();
}

int sde_kms_mmu_detach(struct sde_kms *sde_kms, bool secure_only)
{
	int i;

	if (!sde_kms)
		return -EINVAL;

	for (i = 0; i < MSM_SMMU_DOMAIN_MAX; i++) {
		struct msm_mmu *mmu;
		struct msm_gem_address_space *aspace = sde_kms->aspace[i];

		if (!aspace)
			continue;

		mmu = sde_kms->aspace[i]->mmu;

		if (secure_only &&
			!aspace->mmu->funcs->is_domain_secure(mmu))
			continue;

		SDE_DEBUG("Detaching domain:%d\n", i);
		aspace->mmu->funcs->detach(mmu, (const char **)iommu_ports,
			ARRAY_SIZE(iommu_ports));

		aspace->domain_attached = false;
	}

	return 0;
}

int sde_kms_mmu_attach(struct sde_kms *sde_kms, bool secure_only)
{
	int i;

	if (!sde_kms)
		return -EINVAL;

	for (i = 0; i < MSM_SMMU_DOMAIN_MAX; i++) {
		struct msm_mmu *mmu;
		struct msm_gem_address_space *aspace = sde_kms->aspace[i];

		if (!aspace)
			continue;

		mmu = sde_kms->aspace[i]->mmu;

		if (secure_only &&
			!aspace->mmu->funcs->is_domain_secure(mmu))
			continue;

		SDE_DEBUG("Attaching domain:%d\n", i);
		aspace->mmu->funcs->attach(mmu, (const char **)iommu_ports,
			ARRAY_SIZE(iommu_ports));

		aspace->domain_attached = true;
	}

	return 0;
}

static void sde_kms_destroy(struct msm_kms *kms)
{
	struct sde_kms *sde_kms;
@@ -1483,7 +1543,7 @@ static int _sde_kms_mmu_init(struct sde_kms *sde_kms)
			msm_gem_address_space_destroy(aspace);
			goto fail;
		}

		aspace->domain_attached = true;
	}

	return 0;
+9 −0
Original line number Diff line number Diff line
@@ -500,4 +500,13 @@ int sde_kms_fbo_reference(struct sde_kms_fbo *fbo);
 */
void sde_kms_fbo_unreference(struct sde_kms_fbo *fbo);

/**
 * smmu attach/detach functions
 * @sde_kms: poiner to sde_kms structure
 * @secure_only: if true only secure contexts are attached/detached, else
 * all contexts are attached/detached/
 */
int sde_kms_mmu_attach(struct sde_kms *sde_kms, bool secure_only);
int sde_kms_mmu_detach(struct sde_kms *sde_kms, bool secure_only);

#endif /* __sde_kms_H__ */