[PATCH libdrm 1/2] Add drm mode lease ioctl wrappers [v3]

keithp at keithp.com keithp at keithp.com
Wed Aug 2 10:03:59 UTC 2017


From: Keith Packard <keithp at keithp.com>

drmModeCreateLease
drmModeListLessees
drmModeGetLease
drmModeRevokeLease

Changes for v2:

Remove lessee id from GetLease
Remove lessor_id from ListLeases
Add revoke
Renumber to track kernel rebase on drm-next

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 include/drm/drm.h      |  4 +++
 include/drm/drm_mode.h | 66 ++++++++++++++++++++++++++++++++++++
 xf86drmMode.c          | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++
 xf86drmMode.h          | 23 +++++++++++++
 4 files changed, 184 insertions(+)

diff --git a/include/drm/drm.h b/include/drm/drm.h
index bf3674ae..7c736765 100644
--- a/include/drm/drm.h
+++ b/include/drm/drm.h
@@ -829,6 +829,10 @@ extern "C" {
 #define DRM_IOCTL_MODE_ATOMIC		DRM_IOWR(0xBC, struct drm_mode_atomic)
 #define DRM_IOCTL_MODE_CREATEPROPBLOB	DRM_IOWR(0xBD, struct drm_mode_create_blob)
 #define DRM_IOCTL_MODE_DESTROYPROPBLOB	DRM_IOWR(0xBE, struct drm_mode_destroy_blob)
+#define DRM_IOCTL_MODE_CREATE_LEASE	DRM_IOWR(0xC3, struct drm_mode_create_lease)
+#define DRM_IOCTL_MODE_LIST_LESSEES	DRM_IOWR(0xC4, struct drm_mode_list_lessees)
+#define DRM_IOCTL_MODE_GET_LEASE	DRM_IOWR(0xC5, struct drm_mode_get_lease)
+#define DRM_IOCTL_MODE_REVOKE_LEASE	DRM_IOWR(0xC6, struct drm_mode_revoke_lease)
 
 #define DRM_IOCTL_SYNCOBJ_CREATE	DRM_IOWR(0xBF, struct drm_syncobj_create)
 #define DRM_IOCTL_SYNCOBJ_DESTROY	DRM_IOWR(0xC0, struct drm_syncobj_destroy)
diff --git a/include/drm/drm_mode.h b/include/drm/drm_mode.h
index 70571af6..a2b71614 100644
--- a/include/drm/drm_mode.h
+++ b/include/drm/drm_mode.h
@@ -677,6 +677,72 @@ struct drm_mode_destroy_blob {
 	__u32 blob_id;
 };
 
+/**
+ * Lease mode resources to another user.
+ */
+struct drm_mode_create_lease {
+	/** Pointer to array of object ids (__u32) */
+	__u64 object_ids;
+	/** Number of object ids */
+	__u32 object_count;
+	/** flags for new FD (O_CLOEXEC, etc) */
+	__u32 flags;
+
+	/** Return: unique identifier for lessee. */
+	__u32 lessee_id;
+	/** Return: file descriptor to new drm_master file */
+	__u32 fd;
+};
+
+/**
+ * List lesses from a drm_master
+ */
+struct drm_mode_list_lessees {
+	/** Number of lessees.
+	 * On input, provides length of the array.
+	 * On output, provides total number. No
+	 * more than the input number will be written
+	 * back, so two calls can be used to get
+	 * the size and then the data.
+	 */
+	__u32 count_lessees;
+	__u32 pad;
+
+	/** Pointer to lessees.
+	 * pointer to __u64 array of lessee ids
+	 */
+	__u64 lessees_ptr;
+};
+
+/**
+ * Get leased objects for a lessee
+ */
+struct drm_mode_get_lease {
+	/** Number of leased objects.
+	 * On input, provides length of the array.
+	 * On output, provides total number. No
+	 * more than the input number will be written
+	 * back, so two calls can be used to get
+	 * the size and then the data.
+	 */
+	__u32 count_objects;
+	__u32 pad;
+
+	/** Pointer to objects.
+	 * pointer to __u32 array of object ids
+	 */
+	__u64 objects_ptr;
+};
+
+/**
+ * Revoke lease
+ */
+struct drm_mode_revoke_lease {
+	/** Unique ID of lessee
+	 */
+	__u32 lessee_id;
+};
+
 #if defined(__cplusplus)
 }
 #endif
diff --git a/xf86drmMode.c b/xf86drmMode.c
index d3bc20ea..affd3fb7 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -1485,3 +1485,94 @@ drmModeDestroyPropertyBlob(int fd, uint32_t id)
 	destroy.blob_id = id;
 	return DRM_IOCTL(fd, DRM_IOCTL_MODE_DESTROYPROPBLOB, &destroy);
 }
+
+int
+drmModeCreateLease(int fd, const uint32_t *objects, int num_objects, int flags, uint32_t *lessee_id)
+{
+        struct drm_mode_create_lease create;
+        int ret;
+
+        memclear(create);
+        create.object_ids = (uintptr_t) objects;
+        create.object_count = num_objects;
+        create.flags = flags;
+
+        ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_CREATE_LEASE, &create);
+        if (ret == 0) {
+                *lessee_id = create.lessee_id;
+                return create.fd;
+        }
+        return -errno;
+}
+
+drmModeLesseeListPtr
+drmModeListLessees(int fd)
+{
+        struct drm_mode_list_lessees list;
+        uint32_t count;
+        drmModeLesseeListPtr ret;
+
+        memclear(list);
+
+        if (DRM_IOCTL(fd, DRM_IOCTL_MODE_LIST_LESSEES, &list))
+                return NULL;
+
+        count = list.count_lessees;
+        ret = drmMalloc(sizeof (drmModeLesseeListRes) + count * sizeof (ret->lessees[0]));
+        if (!ret)
+                return NULL;
+
+        list.lessees_ptr = VOID2U64(&ret->lessees[0]);
+        if (DRM_IOCTL(fd, DRM_IOCTL_MODE_LIST_LESSEES, &list)) {
+                drmFree(ret);
+                return NULL;
+        }
+
+        ret->count = count;
+        return ret;
+}
+
+drmModeObjectListPtr
+drmModeGetLease(int fd)
+{
+        struct drm_mode_get_lease get;
+        uint32_t count;
+        drmModeObjectListPtr ret;
+
+        memclear(get);
+
+        if (DRM_IOCTL(fd, DRM_IOCTL_MODE_GET_LEASE, &get))
+                return NULL;
+
+        count = get.count_objects;
+        ret = drmMalloc(sizeof (drmModeObjectListRes) + count * sizeof (ret->objects[0]));
+        if (!ret)
+                return NULL;
+
+        get.objects_ptr = VOID2U64(&ret->objects[0]);
+        if (DRM_IOCTL(fd, DRM_IOCTL_MODE_GET_LEASE, &get)) {
+                drmFree(ret);
+                return NULL;
+        }
+
+        ret->count = count;
+        return ret;
+}
+
+int
+drmModeRevokeLease(int fd, uint32_t lessee_id)
+{
+        struct drm_mode_revoke_lease revoke;
+        int ret;
+
+        memclear(revoke);
+
+        revoke.lessee_id = lessee_id;
+
+        ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_REVOKE_LEASE, &revoke);
+        if (ret == 0)
+                return 0;
+        return -errno;
+}
+
+
diff --git a/xf86drmMode.h b/xf86drmMode.h
index 5b390d9f..b5e22720 100644
--- a/xf86drmMode.h
+++ b/xf86drmMode.h
@@ -521,6 +521,29 @@ extern int drmModeCreatePropertyBlob(int fd, const void *data, size_t size,
 extern int drmModeDestroyPropertyBlob(int fd, uint32_t id);
 
 
+/*
+ * DRM mode lease APIs. These create and manage new drm_masters with
+ * access to a subset of the available DRM resources
+ */
+
+extern int drmModeCreateLease(int fd, const uint32_t *objects, int num_objects, int flags, uint32_t *lessee_id);
+
+typedef struct drmModeLesseeList {
+        uint32_t count;
+        uint32_t lessees[0];
+} drmModeLesseeListRes, *drmModeLesseeListPtr;
+
+extern drmModeLesseeListPtr drmModeListLessees(int fd);
+
+typedef struct drmModeObjectList {
+        uint32_t count;
+        uint32_t objects[0];
+} drmModeObjectListRes, *drmModeObjectListPtr;
+
+extern drmModeObjectListPtr drmModeGetLease(int fd);
+
+extern int drmModeRevokeLease(int fd, uint32_t lessee_id);
+
 #if defined(__cplusplus)
 }
 #endif
-- 
2.11.0



More information about the dri-devel mailing list