diff options
-rw-r--r-- | kms++/inc/kms++/kms++.h | 1 | ||||
-rw-r--r-- | kms++/inc/kms++/swsync.h | 39 | ||||
-rw-r--r-- | kms++/src/swsync.cpp | 68 | ||||
-rw-r--r-- | py/pykms/pykmsbase.cpp | 12 |
4 files changed, 120 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); +} + +} diff --git a/py/pykms/pykmsbase.cpp b/py/pykms/pykmsbase.cpp index 4d4559d..970e533 100644 --- a/py/pykms/pykmsbase.cpp +++ b/py/pykms/pykmsbase.cpp @@ -189,4 +189,16 @@ void init_pykmsbase(py::module &m) }, py::arg("data"), py::arg("allow_modeset") = false) .def("commit_sync", &AtomicReq::commit_sync, py::arg("allow_modeset") = false) ; + + py::class_<SWSync>(m, "SWSync") + .def_property_readonly("fd", &SWSync::fd) + ; + + py::class_<SWSyncTimeline>(m, "SWSyncTimeline") + .def(py::init<>()) + .def("create_fence", &SWSyncTimeline::createFence) + .def("signal", &SWSyncTimeline::signal) + .def_property_readonly("value", &SWSyncTimeline::value) + ; + } |