]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
accel/qaic: Add support to export dmabuf fd
authorPranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
Tue, 7 Oct 2025 05:38:53 +0000 (07:38 +0200)
committerJeff Hugo <jeff.hugo@oss.qualcomm.com>
Mon, 13 Oct 2025 17:26:31 +0000 (11:26 -0600)
Add support to export BO as DMABUF to enable userspace to reuse buffers
and reduce number of copy.

Signed-off-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
Signed-off-by: Youssef Samir <youssef.abdulrahman@oss.qualcomm.com>
Reviewed-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com>
Signed-off-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20251007053853.193608-1-youssef.abdulrahman@oss.qualcomm.com
drivers/accel/qaic/qaic_data.c

index adabc4028bb26d28f133e27e6f0175a1db26f4fd..85c155c74fca11a48b7058d20b7e50932db81a48 100644 (file)
@@ -644,8 +644,36 @@ static void qaic_free_object(struct drm_gem_object *obj)
        kfree(bo);
 }
 
+static struct sg_table *qaic_get_sg_table(struct drm_gem_object *obj)
+{
+       struct qaic_bo *bo = to_qaic_bo(obj);
+       struct scatterlist *sg, *sg_in;
+       struct sg_table *sgt, *sgt_in;
+       int i;
+
+       sgt_in = bo->sgt;
+
+       sgt = kmalloc(sizeof(*sgt), GFP_KERNEL);
+       if (!sgt)
+               return ERR_PTR(-ENOMEM);
+
+       if (sg_alloc_table(sgt, sgt_in->orig_nents, GFP_KERNEL)) {
+               kfree(sgt);
+               return ERR_PTR(-ENOMEM);
+       }
+
+       sg = sgt->sgl;
+       for_each_sgtable_sg(sgt_in, sg_in, i) {
+               memcpy(sg, sg_in, sizeof(*sg));
+               sg = sg_next(sg);
+       }
+
+       return sgt;
+}
+
 static const struct drm_gem_object_funcs qaic_gem_funcs = {
        .free = qaic_free_object,
+       .get_sg_table = qaic_get_sg_table,
        .print_info = qaic_gem_print_info,
        .mmap = qaic_gem_object_mmap,
        .vm_ops = &drm_vm_ops,