Skip to content

Commit

Permalink
Merge branch 'Xilinx:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ManojTakasi authored Dec 12, 2023
2 parents c49ea29 + 4911da1 commit 35e37d4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/runtime_src/core/edge/drm/zocl/common/zocl_bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <linux/pagemap.h>
#include <linux/of_address.h>
#include <linux/dma-buf.h>
#include <linux/iommu.h>
#include <linux/version.h>
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0))
Expand Down Expand Up @@ -388,6 +389,38 @@ zocl_create_bo(struct drm_device *dev, uint64_t unaligned_size, u32 user_flags)
kfree(bo);
return ERR_PTR(err);
}
/*
* Allocate a sg_table for this GEM object.
* Note: Both the table's contents, and the sg_table itself must be freed by
* the caller.
* Returns a pointer to the newly allocated sg_table, or an ERR_PTR() error.
*/
struct sg_table *zocl_gem_prime_get_sg_table(struct drm_gem_object *obj)
{
struct drm_zocl_bo *zocl_obj = to_zocl_bo(obj);
if (zocl_obj && (zocl_obj->flags & ZOCL_BO_FLAGS_CMA)) {
return drm_gem_dma_get_sg_table(&zocl_obj->cma_base);
}
struct drm_device *drm = obj->dev;
struct sg_table *sgt;
int ret;
unsigned long dma_attrs = DMA_ATTR_WRITE_COMBINE;

sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
if (!sgt)
return ERR_PTR(-ENOMEM);

ret = dma_get_sgtable_attrs(drm->dev, sgt, zocl_obj->vmapping,
zocl_obj->mm_node->start, obj->size,
dma_attrs);
if (ret) {
DRM_ERROR("failed to allocate sgt, %d\n", ret);
kfree(sgt);
return ERR_PTR(ret);
}

return sgt;
}

static struct drm_zocl_bo *
zocl_create_svm_bo(struct drm_device *dev, void *data, struct drm_file *filp)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ const struct drm_gem_object_funcs zocl_gem_object_funcs = {
.free = zocl_free_bo,
.vm_ops = &zocl_bo_vm_ops,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
.get_sg_table = drm_gem_dma_object_get_sg_table,
.get_sg_table = zocl_gem_prime_get_sg_table,
.vmap = drm_gem_dma_object_vmap,
#else
.get_sg_table = drm_gem_cma_get_sg_table,
Expand Down
2 changes: 2 additions & 0 deletions src/runtime_src/core/edge/drm/zocl/include/zocl_bo.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,6 @@ static inline uint32_t zocl_convert_bo_uflags(uint32_t uflags)
struct drm_gem_object *
zocl_gem_import(struct drm_device *dev, struct dma_buf *dma_buf);

struct sg_table *zocl_gem_prime_get_sg_table(struct drm_gem_object *obj);

#endif /* _ZOCL_BO_H */

0 comments on commit 35e37d4

Please sign in to comment.