linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH libdrm v2 06/25] tegra: Add PRIME support helpers
@ 2022-02-17 19:19 Thierry Reding
  2022-02-17 19:19 ` [PATCH libdrm v2 07/25] tegra: Make API more consistent Thierry Reding
                   ` (18 more replies)
  0 siblings, 19 replies; 24+ messages in thread
From: Thierry Reding @ 2022-02-17 19:19 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Michał Mirosław, Dmitry Osipenko, dri-devel,
	linux-tegra

From: Thierry Reding <treding@nvidia.com>

These helpers facilitate exporting and importing buffer objects to and
from PRIME file descriptors.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
Changes in v3:
- add drm_public annotations
---
 tegra/tegra-symbols.txt |  2 ++
 tegra/tegra.c           | 61 +++++++++++++++++++++++++++++++++++++++++
 tegra/tegra.h           |  4 +++
 3 files changed, 67 insertions(+)

diff --git a/tegra/tegra-symbols.txt b/tegra/tegra-symbols.txt
index 630e075fa5d7..f8811bcd26f4 100644
--- a/tegra/tegra-symbols.txt
+++ b/tegra/tegra-symbols.txt
@@ -1,5 +1,7 @@
+drm_tegra_bo_export
 drm_tegra_bo_get_handle
 drm_tegra_bo_get_name
+drm_tegra_bo_import
 drm_tegra_bo_map
 drm_tegra_bo_new
 drm_tegra_bo_open
diff --git a/tegra/tegra.c b/tegra/tegra.c
index 3d645d87dd3d..cf091c1d758f 100644
--- a/tegra/tegra.c
+++ b/tegra/tegra.c
@@ -290,3 +290,64 @@ free:
     free(bo);
     return err;
 }
+
+drm_public int drm_tegra_bo_export(struct drm_tegra_bo *bo, uint32_t flags)
+{
+    int fd, err;
+
+    flags |= DRM_CLOEXEC;
+
+    err = drmPrimeHandleToFD(bo->drm->fd, bo->handle, flags, &fd);
+    if (err < 0)
+        return err;
+
+    return fd;
+}
+
+static ssize_t fd_get_size(int fd)
+{
+    ssize_t size, offset;
+    int err;
+
+    offset = lseek(fd, 0, SEEK_CUR);
+    if (offset < 0)
+        return -errno;
+
+    size = lseek(fd, 0, SEEK_END);
+    if (size < 0)
+        return -errno;
+
+    err = lseek(fd, offset, SEEK_SET);
+    if (err < 0)
+        return -errno;
+
+    return size;
+}
+
+drm_public int
+drm_tegra_bo_import(struct drm_tegra *drm, int fd, struct drm_tegra_bo **bop)
+{
+    struct drm_tegra_bo *bo;
+    ssize_t size;
+    int err;
+
+    size = fd_get_size(fd);
+    if (size < 0)
+        return size;
+
+    bo = drm_tegra_bo_alloc(drm, 0, 0, size);
+    if (!bo)
+        return -ENOMEM;
+
+    err = drmPrimeFDToHandle(drm->fd, fd, &bo->handle);
+    if (err < 0)
+        goto free;
+
+    *bop = bo;
+
+    return 0;
+
+free:
+    free(bo);
+    return err;
+}
diff --git a/tegra/tegra.h b/tegra/tegra.h
index 333690f23118..aaaf455fbc8e 100644
--- a/tegra/tegra.h
+++ b/tegra/tegra.h
@@ -48,4 +48,8 @@ int drm_tegra_bo_get_name(struct drm_tegra_bo *bo, uint32_t *name);
 int drm_tegra_bo_open(struct drm_tegra *drm, uint32_t name, uint32_t flags,
                       struct drm_tegra_bo **bop);
 
+int drm_tegra_bo_export(struct drm_tegra_bo *bo, uint32_t flags);
+int drm_tegra_bo_import(struct drm_tegra *drm, int fd,
+                        struct drm_tegra_bo **bop);
+
 #endif /* __DRM_TEGRA_H__ */
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2022-02-24 17:07 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-17 19:19 [PATCH libdrm v2 06/25] tegra: Add PRIME support helpers Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 07/25] tegra: Make API more consistent Thierry Reding
2022-02-24 17:07   ` Dmitry Osipenko
2022-02-17 19:19 ` [PATCH libdrm v2 08/25] tegra: Install tegra-openclose test Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 09/25] tegra: Update for new UABI Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 10/25] tegra: Include private.h in list of source files Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 11/25] tegra: Add channel APIs Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 12/25] tegra: Add job and push buffer APIs Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 13/25] tegra: Add syncpoint APIs Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 14/25] tests: tegra: Add helper library for tests Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 15/25] tests: tegra: Add gr2d-fill test Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 16/25] tests: tegra: Add syncpt-wait test Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 17/25] tests: tegra: Add syncpoint timeout test Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 18/25] tests: tegra: Add VIC support Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 19/25] tests: tegra: Add VIC 3.0 support Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 20/25] tests: tegra: Add VIC 4.0 support Thierry Reding
2022-02-18  9:29   ` Mikko Perttunen
2022-02-23 14:46     ` Thierry Reding
2022-02-23 14:58       ` Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 21/25] tests: tegra: Add VIC 4.1 support Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 22/25] tests: tegra: Add VIC 4.2 support Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 23/25] tests: tegra: Add VIC clear test Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 24/25] tests: tegra: Add VIC blit test Thierry Reding
2022-02-17 19:19 ` [PATCH libdrm v2 25/25] tests: tegra: Add VIC flip test Thierry Reding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).