summaryrefslogtreecommitdiff
path: root/src/drm.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/drm.cpp60
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;
}