summaryrefslogtreecommitdiff
path: root/kms++
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2017-01-02 17:16:43 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2017-04-15 22:53:54 +0300
commitcdbee74e8da7555f77d19d3c5064dab83db607ff (patch)
tree0e4ba2814f309e0ab8af56a271da6cf8a591ae2a /kms++
parent28cab7063328f02abc5f31c0ef79017c3127ee57 (diff)
Add SW sync support
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'kms++')
-rw-r--r--kms++/inc/kms++/kms++.h1
-rw-r--r--kms++/inc/kms++/swsync.h39
-rw-r--r--kms++/src/swsync.cpp68
3 files changed, 108 insertions, 0 deletions
diff --git a/kms++/inc/kms++/kms++.h b/kms++/inc/kms++/kms++.h
index 6fc6977..f15c916 100644
--- a/kms++/inc/kms++/kms++.h
+++ b/kms++/inc/kms++/kms++.h
@@ -14,3 +14,4 @@
#include "blob.h"
#include "pipeline.h"
#include "pagefliphandler.h"
+#include "swsync.h"
diff --git a/kms++/inc/kms++/swsync.h b/kms++/inc/kms++/swsync.h
new file mode 100644
index 0000000..04b1596
--- /dev/null
+++ b/kms++/inc/kms++/swsync.h
@@ -0,0 +1,39 @@
+#pragma once
+
+#include <cstdint>
+
+namespace kms
+{
+
+class SWSync;
+
+class SWSyncTimeline
+{
+public:
+ SWSyncTimeline();
+ ~SWSyncTimeline();
+
+ SWSync *createFence(uint32_t value);
+ void signal(uint32_t value);
+ uint32_t value() const { return m_value; };
+
+private:
+ int m_fd;
+ uint32_t m_value;
+};
+
+class SWSync
+{
+public:
+ ~SWSync();
+
+ int fd() { return m_fd; };
+
+private:
+ friend SWSyncTimeline;
+ SWSync(int fd);
+
+ int m_fd;
+};
+
+}
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);
+}
+
+}