Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified the if loops to check for mm_node #8449

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading