Module: Mesa Branch: main Commit: 240e9dc5dc502bab84870ce30d8af1ac99d71921 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=240e9dc5dc502bab84870ce30d8af1ac99d71921
Author: Asahi Lina <[email protected]> Date: Wed Mar 1 18:04:12 2023 +0900 asahi: Add APIs for DMA-BUF sync file import/export These are generic ioctls, so it is safe to add them now. Signed-off-by: Asahi Lina <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21662> --- src/asahi/lib/agx_device.c | 36 ++++++++++++++++++++++++++++++++++++ src/asahi/lib/agx_device.h | 3 +++ 2 files changed, 39 insertions(+) diff --git a/src/asahi/lib/agx_device.c b/src/asahi/lib/agx_device.c index bffdcb432e5..13cec9bef74 100644 --- a/src/asahi/lib/agx_device.c +++ b/src/asahi/lib/agx_device.c @@ -338,3 +338,39 @@ agx_submit_single(struct agx_device *dev, enum drm_asahi_cmd_type cmd_type, { unreachable("Linux UAPI not yet upstream"); } + +int +agx_import_sync_file(struct agx_device *dev, struct agx_bo *bo, int fd) +{ + struct dma_buf_import_sync_file import_sync_file_ioctl = { + .flags = DMA_BUF_SYNC_WRITE, + .fd = fd, + }; + + assert(fd >= 0); + assert(bo->prime_fd != -1); + + int ret = drmIoctl(bo->prime_fd, DMA_BUF_IOCTL_IMPORT_SYNC_FILE, + &import_sync_file_ioctl); + assert(ret >= 0); + + return ret; +} + +int +agx_export_sync_file(struct agx_device *dev, struct agx_bo *bo) +{ + struct dma_buf_export_sync_file export_sync_file_ioctl = { + .flags = DMA_BUF_SYNC_RW, + .fd = -1, + }; + + assert(bo->prime_fd != -1); + + int ret = drmIoctl(bo->prime_fd, DMA_BUF_IOCTL_EXPORT_SYNC_FILE, + &export_sync_file_ioctl); + assert(ret >= 0); + assert(export_sync_file_ioctl.fd >= 0); + + return ret >= 0 ? export_sync_file_ioctl.fd : ret; +} diff --git a/src/asahi/lib/agx_device.h b/src/asahi/lib/agx_device.h index 1722a077ead..0ed041f1bd7 100644 --- a/src/asahi/lib/agx_device.h +++ b/src/asahi/lib/agx_device.h @@ -140,4 +140,7 @@ int agx_submit_single(struct agx_device *dev, enum drm_asahi_cmd_type cmd_type, uint32_t result_handle, uint32_t result_off, uint32_t result_size); +int agx_import_sync_file(struct agx_device *dev, struct agx_bo *bo, int fd); +int agx_export_sync_file(struct agx_device *dev, struct agx_bo *bo); + #endif
