diff options
| author | PancakeTAS <pancake@mgnet.work> | 2026-06-25 12:33:32 +0200 |
|---|---|---|
| committer | PancakeTAS <pancake@mgnet.work> | 2026-06-25 12:33:32 +0200 |
| commit | cf7e9496e92e496840c5cd235f4cd52a6789a11d (patch) | |
| tree | 6749f44341ba6445d0ec63a57bb3c5799841cb1a /src/drm.cpp | |
| parent | Project hierarchy overhaul (diff) | |
Generalize device class
Diffstat (limited to '')
| -rw-r--r-- | src/drm.cpp | 60 |
1 files changed, 50 insertions, 10 deletions
diff --git a/src/drm.cpp b/src/drm.cpp index 3046412..66fe147 100644 --- a/src/drm.cpp +++ b/src/drm.cpp @@ -7,6 +7,7 @@ #include <stdexcept> #include <drm.h> +#include <string> #include <unistd.h> using namespace drm; @@ -15,14 +16,27 @@ Device::Device(int fd) : m_fd(fd) { if (this->m_fd < 0) { throw std::invalid_argument("invalid file descriptor"); } +} - drm_auth args{ - +void Device::setClientName(const std::string& name) const { + drm_set_client_name name_args{ + .name_len = name.size(), + .name = reinterpret_cast<u64>(name.data()) }; - ioctl::perform(this->m_fd, DRM_IOCTL_GET_MAGIC, args); - this->m_magic = args.magic; + ioctl::perform(this->m_fd, DRM_IOCTL_SET_CLIENT_NAME, name_args); } +void Device::destruct() noexcept { + if (this->m_fd < 0) { + return; + } + + ::close(this->m_fd); + this->m_fd = -1; +} + +/* Authentication */ + void Device::acquireMaster() const { ioctl::perform(this->m_fd, DRM_IOCTL_SET_MASTER); } @@ -31,6 +45,14 @@ void Device::releaseMaster() const { ioctl::perform(this->m_fd, DRM_IOCTL_DROP_MASTER); } +u32 Device::magic() const { + drm_auth auth_args{ + .magic = 0 + }; + ioctl::perform(this->m_fd, DRM_IOCTL_GET_MAGIC, auth_args); + return auth_args.magic; +} + void Device::authenticate(u32 magic) const { drm_auth args{ .magic = magic @@ -38,11 +60,29 @@ void Device::authenticate(u32 magic) const { ioctl::perform(this->m_fd, DRM_IOCTL_AUTH_MAGIC, args); } -void Device::destruct() noexcept { - if (this->m_fd < 0) { - return; - } +/* Device information */ - ::close(this->m_fd); - this->m_fd = -1; +std::string Device::unique() const { + drm_set_version version_args{ + .drm_di_major = 1, + .drm_di_minor = 4, // See kernel drm_ioctl.c for why this is here + .drm_dd_major = -1, + .drm_dd_minor = -1 + }; + ioctl::perform(this->m_fd, DRM_IOCTL_SET_VERSION, version_args); + + drm_unique unique_args{ + .unique_len = 0, + }; + ioctl::perform(this->m_fd, DRM_IOCTL_GET_UNIQUE, unique_args); + + std::string unique(unique_args.unique_len, '\0'); + + unique_args = { + .unique_len = unique.size(), + .unique = unique.data() + }; + ioctl::perform(this->m_fd, DRM_IOCTL_GET_UNIQUE, unique_args); + + return unique; } |
