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 <veeras@codeaurora.org>
This commit is contained in:
Veera Sundaram Sankaran
2020-06-04 19:11:01 -07:00
committed by Gerrit - the friendly Code Review server
parent 1bd126d328
commit bd28c729e8
2 changed files with 32 additions and 41 deletions

View File

@@ -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 * - attach default drm device for all S2 only buffers or
* secure-cb might still not be attached back, while * when IOMMU is not available
* the prime_fd_to_handle call is made for the next * - avoid using lazying unmap feature as it doesn't add
* frame. Attach those buffers to default drm device * any value without nested translations
* and reattaching with the correct context-bank
* will be handled in msm_gem_delayed_import
*/ */
if (!attach_dev) if ((!iommu_present(&platform_bus_type))
attach_dev = dev->dev; || (flags & ION_FLAG_CP_SEC_DISPLAY)
} else if ((flags & ION_FLAG_CP_SEC_DISPLAY)
|| (flags & ION_FLAG_CP_CAMERA_PREVIEW)) { || (flags & ION_FLAG_CP_CAMERA_PREVIEW)) {
attach_dev = dev->dev; attach_dev = dev->dev;
lazy_unmap = false;
} else { } else {
DRM_ERROR("invalid ion secure flag: 0x%lx\n", flags); domain = (flags & ION_FLAG_CP_PIXEL) ?
} MSM_SMMU_DOMAIN_SECURE : MSM_SMMU_DOMAIN_UNSECURE;
} else { attach_dev = kms->funcs->get_address_space_device(kms, domain);
attach_dev = kms->funcs->get_address_space_device(kms,
MSM_SMMU_DOMAIN_UNSECURE);
} }
/*
* 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"); DRM_DEBUG("attaching dma buf with default drm device\n");
ret = -EINVAL; attach_dev = dev->dev;
goto fail_put;
} }
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) {
if (lazy_unmap)
attach->dma_map_attrs |= DMA_ATTR_DELAYED_UNMAP; attach->dma_map_attrs |= DMA_ATTR_DELAYED_UNMAP;
sgt = dma_buf_map_attachment( sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
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", "dma_buf_map_attachment failure, err=%d\n", ret);
ret);
goto fail_detach; goto fail_detach;
} }
} }

View File

@@ -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); aspace = _sde_kms_get_address_space(kms, domain);
dev = (aspace && aspace->domain_attached) ?
msm_gem_get_aspace_device(aspace) : NULL;
}
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)