Skip to content

Commit

Permalink
Modified the if loops to check for mm_node if buffers are created on …
Browse files Browse the repository at this point in the history
…DMA (#8449) (#8452)

Signed-off-by: Manoj Takasi <[email protected]>
Co-authored-by: Manoj Takasi <[email protected]>
(cherry picked from commit 72a2ed6)
  • Loading branch information
ManojTakasi authored Sep 25, 2024
1 parent f6205f4 commit 8f3beee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
51 changes: 24 additions & 27 deletions src/runtime_src/core/edge/drm/zocl/common/zocl_bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -213,46 +213,43 @@ 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) {
struct drm_zocl_bo *cma_bo =
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;
}
DRM_WARN("Memory allocated from CMA region"
" 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);
Expand Down
6 changes: 3 additions & 3 deletions src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 8f3beee

Please sign in to comment.