From 72a2ed6a5fe7ac6a609f21753c34233465bcc6a7 Mon Sep 17 00:00:00 2001 From: Manoj Takasi <133196374+ManojTakasi@users.noreply.github.com> Date: Wed, 25 Sep 2024 09:22:00 +0530 Subject: [PATCH] Modified the if loops to check for mm_node if buffers are created on DMA (#8449) Signed-off-by: Manoj Takasi Co-authored-by: Manoj Takasi --- .../core/edge/drm/zocl/common/zocl_bo.c | 51 +++++++++---------- .../core/edge/drm/zocl/common/zocl_drv.c | 6 +-- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/runtime_src/core/edge/drm/zocl/common/zocl_bo.c b/src/runtime_src/core/edge/drm/zocl/common/zocl_bo.c index 90d45f2430b..62e2452c335 100644 --- a/src/runtime_src/core/edge/drm/zocl/common/zocl_bo.c +++ b/src/runtime_src/core/edge/drm/zocl/common/zocl_bo.c @@ -57,7 +57,7 @@ void zocl_describe(const struct drm_zocl_bo *obj) static inline void zocl_bo_describe(const struct drm_zocl_bo *bo, uint64_t *size, uint64_t *paddr) { - if (bo->flags & (ZOCL_BO_FLAGS_CMA | ZOCL_BO_FLAGS_USERPTR)) { + if (!bo->mm_node) { *size = (uint64_t)bo->cma_base.base.size; #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) *paddr = (uint64_t)bo->cma_base.dma_addr; @@ -213,27 +213,6 @@ zocl_create_range_mem(struct drm_device *dev, size_t size, struct zocl_mem *mem) struct zocl_mem *head_mem = mem; int err = -ENOMEM; - bo = kzalloc(sizeof(struct drm_zocl_bo), GFP_KERNEL); - if (IS_ERR(bo)) - return ERR_PTR(-ENOMEM); - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0) - bo->gem_base.funcs = &zocl_gem_object_funcs; -#endif - err = drm_gem_object_init(dev, &bo->gem_base, size); - if (err) { - kfree(bo); - return ERR_PTR(err); - } - - bo->mm_node = kzalloc(sizeof(struct drm_mm_node), - GFP_KERNEL); - if (IS_ERR(bo->mm_node)) { - drm_gem_object_release(&bo->gem_base); - kfree(bo); - return ERR_PTR(-ENOMEM); - } - mutex_lock(&zdev->mm_lock); do { if (mem->zm_type == ZOCL_MEM_TYPE_CMA) { @@ -241,10 +220,6 @@ zocl_create_range_mem(struct drm_device *dev, size_t size, struct zocl_mem *mem) zocl_create_cma_mem(dev, size); if (!IS_ERR(cma_bo)) { /* Get the memory from CMA memory region */ - mutex_unlock(&zdev->mm_lock); - kfree(bo->mm_node); - drm_gem_object_release(&bo->gem_base); - kfree(bo); cma_bo->flags |= ZOCL_BO_FLAGS_CMA; return cma_bo; } @@ -252,7 +227,29 @@ zocl_create_range_mem(struct drm_device *dev, size_t size, struct zocl_mem *mem) " whereas requested for reserved memory region\n"); } else { - err = drm_mm_insert_node_in_range(zdev->zm_drm_mm, + bo = kzalloc(sizeof(struct drm_zocl_bo), GFP_KERNEL); + if (IS_ERR(bo)) + return ERR_PTR(-ENOMEM); + + #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0) + bo->gem_base.funcs = &zocl_gem_object_funcs; + #endif + + err = drm_gem_object_init(dev, &bo->gem_base, size); + if (err) { + kfree(bo); + return ERR_PTR(err); + } + + bo->mm_node = kzalloc(sizeof(struct drm_mm_node),GFP_KERNEL); + + if (IS_ERR(bo->mm_node)) { + drm_gem_object_release(&bo->gem_base); + kfree(bo); + return ERR_PTR(-ENOMEM); + } + + err = drm_mm_insert_node_in_range(zdev->zm_drm_mm, bo->mm_node, size, PAGE_SIZE, 0, mem->zm_base_addr, mem->zm_base_addr + mem->zm_size, 0); diff --git a/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c b/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c index 0c8fe3c726a..dbe08502925 100644 --- a/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c +++ b/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c @@ -708,7 +708,7 @@ zocl_gem_mmap(struct file *filp, struct vm_area_struct *vma) */ vma->vm_page_prot = prot; - if (bo->flags & ZOCL_BO_FLAGS_CMA) { + if (!bo->mm_node) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) dma_obj = to_drm_gem_dma_obj(gem_obj); paddr = dma_obj->dma_addr; @@ -719,8 +719,8 @@ zocl_gem_mmap(struct file *filp, struct vm_area_struct *vma) } else paddr = bo->mm_node->start; - if ((!(bo->flags & ZOCL_BO_FLAGS_CMA)) || - (bo->flags & ZOCL_BO_FLAGS_CMA && + if (bo->mm_node || + (!bo->mm_node && bo->flags & ZOCL_BO_FLAGS_CACHEABLE)) { /* Map PL-DDR and cacheable CMA */ rc = remap_pfn_range(vma, vma->vm_start,