From 39482d59fe7160740ea5dd61f3ed965a88d848ce Mon Sep 17 00:00:00 2001 From: Harvey Yang Date: Thu, 21 Nov 2024 05:51:31 +0000 Subject: DmaBufAllocator: Add Dma Buffer synchronization function & helper class To synchronize CPU access with mmap and hardware access on DMA buffers, using `DMA_BUF_IOCTL_SYNC` is required. This patch adds a function and a helper class to allow users to sync buffers more easily. Signed-off-by: Han-Lin Chen Co-developed-by: Harvey Yang Signed-off-by: Harvey Yang Reviewed-by: Milan Zamazal Reviewed-by: Kieran Bingham Signed-off-by: Kieran Bingham --- include/libcamera/internal/dma_buf_allocator.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include') diff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h index 9211d483..fc5de2c1 100644 --- a/include/libcamera/internal/dma_buf_allocator.h +++ b/include/libcamera/internal/dma_buf_allocator.h @@ -12,6 +12,7 @@ #include #include +#include #include namespace libcamera { @@ -48,6 +49,26 @@ private: DmaBufAllocatorFlag type_; }; +class DmaSyncer final +{ +public: + enum class SyncType { + Read = 0, + Write, + ReadWrite, + }; + + explicit DmaSyncer(SharedFD fd, SyncType type = SyncType::ReadWrite); + + ~DmaSyncer(); + +private: + void sync(uint64_t step); + + SharedFD fd_; + uint64_t flags_ = 0; +}; + LIBCAMERA_FLAGS_ENABLE_OPERATORS(DmaBufAllocator::DmaBufAllocatorFlag) } /* namespace libcamera */ -- cgit v1.2.1