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

Commit 9079f0fb authored by Narendra Muppalla's avatar Narendra Muppalla
Browse files

drm/msm: handle dma_buf attach/map for secure buffers



During addfb2 ioctl, buffer is always attached to non-secure context bank.
At commit time when the plane property tells the buffer is secure
it needs to be attached and map to the secure context bank.
This change detects the context bank type and maps the buffer accordingly.

Change-Id: Icf3697b31d5ae5d217846fbee16467af55529c86
Signed-off-by: default avatarNarendra Muppalla <NarendraM@codeaurora.org>
parent c745d32a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -668,6 +668,8 @@ int msm_gem_map_vma(struct msm_gem_address_space *aspace,
		struct msm_gem_vma *vma, struct sg_table *sgt, int npages,
		unsigned int flags);

struct device *msm_gem_get_aspace_device(struct msm_gem_address_space *aspace);

void msm_gem_address_space_put(struct msm_gem_address_space *aspace);

struct msm_gem_address_space *
+37 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include "msm_gem.h"
#include "msm_gpu.h"
#include "msm_mmu.h"
#include "sde_dbg.h"

static void msm_gem_vunmap_locked(struct drm_gem_object *obj);

@@ -416,9 +417,44 @@ int msm_gem_get_iova(struct drm_gem_object *obj,

	if (!vma) {
		struct page **pages;
		struct device *dev;
		struct dma_buf *dmabuf;
		bool reattach = false;

		/*
		 * both secure/non-secure domains are attached with the default
		 * devive (non-sec) with dma_buf_attach during
		 * msm_gem_prime_import. detach and attach the correct device
		 * to the dma_buf based on the aspace domain.
		 */
		dev = msm_gem_get_aspace_device(aspace);
		if (dev && obj->import_attach &&
				(dev != obj->import_attach->dev)) {
			dmabuf = obj->import_attach->dmabuf;

			DRM_DEBUG("detach nsec-dev:%pK attach sec-dev:%pK\n",
					 obj->import_attach->dev, dev);
			SDE_EVT32(obj->import_attach->dev, dev, msm_obj->sgt);


			if (msm_obj->sgt)
				dma_buf_unmap_attachment(obj->import_attach,
							msm_obj->sgt,
							DMA_BIDIRECTIONAL);
			dma_buf_detach(dmabuf, obj->import_attach);

			obj->import_attach = dma_buf_attach(dmabuf, dev);
			if (IS_ERR(obj->import_attach)) {
				DRM_ERROR("dma_buf_attach failure, err=%ld\n",
						PTR_ERR(obj->import_attach));
				goto unlock;
			}
			reattach = true;
		}

		/* perform delayed import for buffers without existing sgt */
		if ((msm_obj->flags & MSM_BO_EXTBUF) && !(msm_obj->sgt)) {
		if (((msm_obj->flags & MSM_BO_EXTBUF) && !(msm_obj->sgt))
				|| reattach) {
			ret = msm_gem_delayed_import(obj);
			if (ret) {
				DRM_ERROR("delayed dma-buf import failed %d\n",
+10 −0
Original line number Diff line number Diff line
@@ -318,6 +318,16 @@ msm_gem_map_vma(struct msm_gem_address_space *aspace,
	return -EINVAL;
}

struct device *msm_gem_get_aspace_device(struct msm_gem_address_space *aspace)
{
	struct device *client_dev = NULL;

	if (aspace && aspace->mmu && aspace->mmu->funcs->get_dev)
		client_dev = aspace->mmu->funcs->get_dev(aspace->mmu);

	return client_dev;
}

void msm_gem_add_obj_to_aspace_active_list(
		struct msm_gem_address_space *aspace,
		struct drm_gem_object *obj)
+1 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ struct msm_mmu_funcs {
			uint32_t dest_address, uint32_t size, int prot);
	int (*one_to_one_unmap)(struct msm_mmu *mmu, uint32_t dest_address,
					uint32_t size);
	struct device *(*get_dev)(struct msm_mmu *mmu);
};

struct msm_mmu {
+8 −0
Original line number Diff line number Diff line
@@ -211,6 +211,13 @@ static void msm_smmu_destroy(struct msm_mmu *mmu)
	kfree(smmu);
}

struct device *msm_smmu_get_dev(struct msm_mmu *mmu)
{
	struct msm_smmu *smmu = to_msm_smmu(mmu);

	return smmu->client_dev;
}

static int msm_smmu_map_dma_buf(struct msm_mmu *mmu, struct sg_table *sgt,
		int dir, u32 flags)
{
@@ -292,6 +299,7 @@ static const struct msm_mmu_funcs funcs = {
	.set_attribute = msm_smmu_set_attribute,
	.one_to_one_map = msm_smmu_one_to_one_map,
	.one_to_one_unmap = msm_smmu_one_to_one_unmap,
	.get_dev = msm_smmu_get_dev,
};

static struct msm_smmu_domain msm_smmu_domains[MSM_SMMU_DOMAIN_MAX] = {