diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2017-01-02 17:16:43 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2017-04-15 22:53:54 +0300 |
commit | cdbee74e8da7555f77d19d3c5064dab83db607ff (patch) | |
tree | 0e4ba2814f309e0ab8af56a271da6cf8a591ae2a /kms++/src | |
parent | 28cab7063328f02abc5f31c0ef79017c3127ee57 (diff) |
Add SW sync support
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'kms++/src')
-rw-r--r-- | kms++/src/swsync.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/kms++/src/swsync.cpp b/kms++/src/swsync.cpp new file mode 100644 index 0000000..fde0efe --- /dev/null +++ b/kms++/src/swsync.cpp @@ -0,0 +1,68 @@ +#include <fcntl.h> +#include <unistd.h> +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <sys/types.h> + +#include <linux/ioctl.h> +#include <linux/types.h> + +#include <kms++/kms++.h> + +struct sw_sync_create_fence_data { + __u32 value; + char name[32]; + __s32 fence; /* fd of new fence */ +}; + +#define SW_SYNC_IOC_MAGIC 'W' +#define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0, struct sw_sync_create_fence_data) +#define SW_SYNC_IOC_INC _IOW (SW_SYNC_IOC_MAGIC, 1, __u32) + +using namespace std; + +namespace kms +{ + +SWSyncTimeline::SWSyncTimeline() + : m_value(0) +{ + m_fd = open("/sys/kernel/debug/sync/sw_sync", 0); + if (m_fd == -1) + throw std::runtime_error("Failed to open sw_sync file"); +} + +SWSyncTimeline::~SWSyncTimeline() +{ + close(m_fd); +} + +SWSync *SWSyncTimeline::createFence(uint32_t value) +{ + struct sw_sync_create_fence_data data = { value }; + int ret; + + ret = ioctl(m_fd, SW_SYNC_IOC_CREATE_FENCE, &data); + if (ret < 0) + return NULL; + + return new SWSync(data.fence); +} + +void SWSyncTimeline::signal(uint32_t value) +{ + ioctl(m_fd, SW_SYNC_IOC_INC, &value); + m_value += value; +} + +SWSync::SWSync(int fd) + : m_fd(fd) +{ +} + +SWSync::~SWSync() +{ + close(m_fd); +} + +} |