disp: msm: attach cp_pixel/tvm vmids to correct devices

Attach the dmabuf with cp-pixel vmid to secure-cb device and the
tvm vmid in HLOS to DRM device to support CSF 2.5. Some cases like
DEMURA has dmabuf set with both cp-pixel & tvm VMIDs as its used
in HLOS and shared with Trusted-vm. Attach to secure-cb device in
these cases.

Change-Id: I97f59cc01bb5ea18061541e68454b848f1a78a09
Signed-off-by: Veera Sundaram Sankaran <quic_veeras@quicinc.com>
Цей коміт міститься в:
Veera Sundaram Sankaran
2023-03-15 21:28:17 -07:00
джерело 280c38cc54
коміт 4cc48c385e

Переглянути файл

@@ -117,13 +117,10 @@ struct drm_gem_object *msm_gem_prime_import(struct drm_device *dev,
struct device *attach_dev = NULL;
struct msm_drm_private *priv;
struct msm_kms *kms;
int ret;
u32 domain;
bool lazy_unmap = true, is_nested_sec_vmid = false;
#if (KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE)
bool lazy_unmap = true, is_vmid_tvm = false, is_vmid_cp_pixel = false;
int *vmid_list, *perms_list;
int nelems = 0, i;
#endif
int nelems = 0, i, ret;
unsigned long dma_map_attrs = 0;
if (!dma_buf || !dev->dev_private)
return ERR_PTR(-EINVAL);
@@ -156,38 +153,44 @@ struct drm_gem_object *msm_gem_prime_import(struct drm_device *dev,
goto fail_put;
}
#if (KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE)
/* avoid VMID checks in trusted-vm */
if (!kms->funcs->in_trusted_vm || !kms->funcs->in_trusted_vm(kms)) {
ret = mem_buf_dma_buf_copy_vmperm(dma_buf, &vmid_list, &perms_list, &nelems);
if (ret) {
DRM_ERROR("get vmid list failure, ret:%d", ret);
goto fail_put;
}
for (i = 0; i < nelems; i++)
if (vmid_list[i] == VMID_TVM)
is_nested_sec_vmid = true;
/* mem_buf_dma_buf_copy_vmperm uses kmemdup, do kfree to free up the memory */
kfree(vmid_list);
kfree(perms_list);
ret = mem_buf_dma_buf_copy_vmperm(dma_buf, &vmid_list, &perms_list, &nelems);
if (ret) {
DRM_ERROR("get vmid list failure, ret:%d", ret);
goto fail_put;
}
for (i = 0; i < nelems; i++) {
#if (KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE)
/* avoid VMID checks in trusted-vm, set flag in HLOS when only VMID_TVM is set */
if ((vmid_list[i] == VMID_TVM) &&
(!kms->funcs->in_trusted_vm || !kms->funcs->in_trusted_vm(kms))) {
is_vmid_tvm = true;
dma_map_attrs = DMA_ATTR_QTI_SMMU_PROXY_MAP;
}
#endif
if (vmid_list[i] == VMID_CP_PIXEL) {
is_vmid_cp_pixel = true;
is_vmid_tvm = false;
dma_map_attrs = 0;
break;
}
}
/* mem_buf_dma_buf_copy_vmperm uses kmemdup, do kfree to free up the memory */
kfree(vmid_list);
kfree(perms_list);
/*
* - 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
* - use the same drm device for nested secure-camera buffer
* - attach default drm device for VMID_TVM-only or when IOMMU is not available
* - avoid using lazy unmap feature as it doesn't add value without nested translations
*/
if (!iommu_present(&platform_bus_type) || is_nested_sec_vmid) {
if (is_vmid_cp_pixel) {
attach_dev = kms->funcs->get_address_space_device(kms, MSM_SMMU_DOMAIN_SECURE);
} else if (!iommu_present(&platform_bus_type) || is_vmid_tvm) {
attach_dev = dev->dev;
lazy_unmap = false;
} else {
domain = MSM_SMMU_DOMAIN_UNSECURE;
attach_dev = kms->funcs->get_address_space_device(kms, domain);
attach_dev = kms->funcs->get_address_space_device(kms, MSM_SMMU_DOMAIN_UNSECURE);
}
/*
@@ -216,10 +219,7 @@ struct drm_gem_object *msm_gem_prime_import(struct drm_device *dev,
if (lazy_unmap)
attach->dma_map_attrs |= DMA_ATTR_DELAYED_UNMAP;
#if (KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE)
if (is_nested_sec_vmid)
attach->dma_map_attrs |= DMA_ATTR_QTI_SMMU_PROXY_MAP;
#endif
attach->dma_map_attrs |= dma_map_attrs;
sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
if (IS_ERR(sgt)) {