Răsfoiți Sursa

disp: msm: refactor dma buf attach device assignment

Assign default drm device for dma buf_attach when
IOMMMU is not present and for stage-2 only buffers.
Avoid setting lazy_unmap for stage-2 only buffers as
it doesn't have any impact without nested translations.
Assign default drm device when no device is found to
support transitions between secure usecases where
the nested context banks might not be attached back
at the prime_fd_to_handle time. These buffers would
be attached with the correct context bank device
during the delayed_import.

Change-Id: I9ccb38876d7843b4411762c7b8006ae8fca85391
Signed-off-by: Veera Sundaram Sankaran <[email protected]>
Veera Sundaram Sankaran 5 ani în urmă
părinte
comite
bd28c729e8
2 a modificat fișierele cu 32 adăugiri și 41 ștergeri
  1. 29 31
      msm/msm_gem_prime.c
  2. 3 10
      msm/sde/sde_kms.c

+ 29 - 31
msm/msm_gem_prime.c

@@ -95,6 +95,8 @@ struct drm_gem_object *msm_gem_prime_import(struct drm_device *dev,
 	struct msm_drm_private *priv;
 	struct msm_drm_private *priv;
 	struct msm_kms *kms;
 	struct msm_kms *kms;
 	int ret;
 	int ret;
+	bool lazy_unmap = true;
+	u32 domain;
 
 
 	if (!dma_buf || !dev->dev_private)
 	if (!dma_buf || !dev->dev_private)
 		return ERR_PTR(-EINVAL);
 		return ERR_PTR(-EINVAL);
@@ -132,36 +134,33 @@ struct drm_gem_object *msm_gem_prime_import(struct drm_device *dev,
 		goto fail_put;
 		goto fail_put;
 	}
 	}
 
 
-	if (flags & ION_FLAG_SECURE) {
-		if (flags & ION_FLAG_CP_PIXEL) {
-			attach_dev = kms->funcs->get_address_space_device(kms,
-						MSM_SMMU_DOMAIN_SECURE);
-			/*
-			 * While transitioning from secure use-cases, the
-			 * secure-cb might still not be attached back, while
-			 * the prime_fd_to_handle call is made for the next
-			 * frame. Attach those buffers to default drm device
-			 * and reattaching with the correct context-bank
-			 * will be handled in msm_gem_delayed_import
-			 */
-			if (!attach_dev)
-				attach_dev = dev->dev;
-
-		} else if ((flags & ION_FLAG_CP_SEC_DISPLAY)
-				|| (flags & ION_FLAG_CP_CAMERA_PREVIEW)) {
-			attach_dev = dev->dev;
-		} else {
-			DRM_ERROR("invalid ion secure flag: 0x%lx\n", flags);
-		}
+	/*
+	 * - attach default drm device for all S2 only buffers or
+	 *   when IOMMU is not available
+	 * - avoid using lazying unmap feature as it doesn't add
+	 * any value without nested translations
+	 */
+	if ((!iommu_present(&platform_bus_type))
+			|| (flags & ION_FLAG_CP_SEC_DISPLAY)
+			|| (flags & ION_FLAG_CP_CAMERA_PREVIEW)) {
+		attach_dev = dev->dev;
+		lazy_unmap = false;
 	} else {
 	} else {
-		attach_dev = kms->funcs->get_address_space_device(kms,
-						MSM_SMMU_DOMAIN_UNSECURE);
+		domain = (flags & ION_FLAG_CP_PIXEL) ?
+			    MSM_SMMU_DOMAIN_SECURE : MSM_SMMU_DOMAIN_UNSECURE;
+		attach_dev = kms->funcs->get_address_space_device(kms, domain);
 	}
 	}
 
 
+	/*
+	 * While transitioning from secure use-cases, the secure/non-secure
+	 * context bank might still not be attached back, while the
+	 * prime_fd_to_handle call is made for the next frame. Attach those
+	 * buffers to default drm device and reattaching with the correct
+	 * context-bank will be handled in msm_gem_delayed_import.
+	 */
 	if (!attach_dev) {
 	if (!attach_dev) {
-		DRM_ERROR("aspace device not found for domain\n");
-		ret = -EINVAL;
-		goto fail_put;
+		DRM_DEBUG("attaching dma buf with default drm device\n");
+		attach_dev = dev->dev;
 	}
 	}
 
 
 	attach = dma_buf_attach(dma_buf, attach_dev);
 	attach = dma_buf_attach(dma_buf, attach_dev);
@@ -178,14 +177,13 @@ struct drm_gem_object *msm_gem_prime_import(struct drm_device *dev,
 	 * otherwise do delayed mapping during the commit.
 	 * otherwise do delayed mapping during the commit.
 	 */
 	 */
 	if (flags & ION_FLAG_CACHED) {
 	if (flags & ION_FLAG_CACHED) {
-		attach->dma_map_attrs |= DMA_ATTR_DELAYED_UNMAP;
-		sgt = dma_buf_map_attachment(
-				attach, DMA_BIDIRECTIONAL);
+		if (lazy_unmap)
+			attach->dma_map_attrs |= DMA_ATTR_DELAYED_UNMAP;
+		sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
 		if (IS_ERR(sgt)) {
 		if (IS_ERR(sgt)) {
 			ret = PTR_ERR(sgt);
 			ret = PTR_ERR(sgt);
 			DRM_ERROR(
 			DRM_ERROR(
-			"dma_buf_map_attachment failure, err=%d\n",
-				ret);
+			"dma_buf_map_attachment failure, err=%d\n", ret);
 			goto fail_detach;
 			goto fail_detach;
 		}
 		}
 	}
 	}

+ 3 - 10
msm/sde/sde_kms.c

@@ -2182,7 +2182,6 @@ static struct device *_sde_kms_get_address_space_device(struct msm_kms *kms,
 		unsigned int domain)
 		unsigned int domain)
 {
 {
 	struct sde_kms *sde_kms;
 	struct sde_kms *sde_kms;
-	struct device *dev;
 	struct msm_gem_address_space *aspace;
 	struct msm_gem_address_space *aspace;
 
 
 	if (!kms) {
 	if (!kms) {
@@ -2196,16 +2195,10 @@ static struct device *_sde_kms_get_address_space_device(struct msm_kms *kms,
 		return NULL;
 		return NULL;
 	}
 	}
 
 
-	/* return default device, when IOMMU is not present */
-	if (!iommu_present(&platform_bus_type)) {
-		dev = sde_kms->dev->dev;
-	} else {
-		aspace = _sde_kms_get_address_space(kms, domain);
-		dev =  (aspace && aspace->domain_attached) ?
-				msm_gem_get_aspace_device(aspace) : NULL;
-	}
+	aspace = _sde_kms_get_address_space(kms, domain);
 
 
-	return dev;
+	return (aspace && aspace->domain_attached) ?
+				msm_gem_get_aspace_device(aspace) : NULL;
 }
 }
 
 
 static void _sde_kms_post_open(struct msm_kms *kms, struct drm_file *file)
 static void _sde_kms_post_open(struct msm_kms *kms, struct drm_file *file)