Add support for generic object properties IOCTLs
authorPaulo Zanoni <paulo.r.zanoni@intel.com>
Tue, 15 May 2012 21:38:28 +0000 (18:38 -0300)
committerRob Clark <rob@ti.com>
Fri, 8 Jun 2012 14:27:20 +0000 (09:27 -0500)
New library calls:
- drmModeObjectGetProperties
- drmModeFreeObjectProperties
- drmModeObjectSetProperties

Reviewed-by: Eugeni Dodonov <eugeni.dodonov@intel.com>
Reviewed-by: Rob Clark <rob@ti.com>
Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
include/drm/drm.h
include/drm/drm_mode.h
xf86drmMode.c
xf86drmMode.h

index 753d2fc8558218cc1661a215d26eeb7ea62797e5..5e6cd2910c88af1ff069bec95b6f2b8372b70df5 100644 (file)
@@ -731,6 +731,8 @@ struct drm_prime_handle {
 #define DRM_IOCTL_MODE_GETPLANE        DRM_IOWR(0xB6, struct drm_mode_get_plane)
 #define DRM_IOCTL_MODE_SETPLANE        DRM_IOWR(0xB7, struct drm_mode_set_plane)
 #define DRM_IOCTL_MODE_ADDFB2          DRM_IOWR(0xB8, struct drm_mode_fb_cmd2)
+#define DRM_IOCTL_MODE_OBJ_GETPROPERTIES       DRM_IOWR(0xB9, struct drm_mode_obj_get_properties)
+#define DRM_IOCTL_MODE_OBJ_SETPROPERTY DRM_IOWR(0xBA, struct drm_mode_obj_set_property)
 
 /**
  * Device specific ioctls should only be in their respective headers
index f36c61a58ebe5199d1bf4590357fb5101ff0d2c1..f303d94c547992d0506e4c65792a956bdf57064e 100644 (file)
@@ -250,6 +250,30 @@ struct drm_mode_connector_set_property {
        __u32 connector_id;
 };
 
+#define DRM_MODE_OBJECT_CRTC 0xcccccccc
+#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
+#define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
+#define DRM_MODE_OBJECT_MODE 0xdededede
+#define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
+#define DRM_MODE_OBJECT_FB 0xfbfbfbfb
+#define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
+#define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
+
+struct drm_mode_obj_get_properties {
+       __u64 props_ptr;
+       __u64 prop_values_ptr;
+       __u32 count_props;
+       __u32 obj_id;
+       __u32 obj_type;
+};
+
+struct drm_mode_obj_set_property {
+       __u64 value;
+       __u32 prop_id;
+       __u32 obj_id;
+       __u32 obj_type;
+};
+
 struct drm_mode_get_blob {
        __u32 blob_id;
        __u32 length;
index c809c44acc2db318978fd2f92dd8062fa7153818..a60c7cb1702ec7c1ef6a8566d58c580f19367adf 100644 (file)
@@ -974,3 +974,86 @@ void drmModeFreePlaneResources(drmModePlaneResPtr ptr)
        drmFree(ptr->planes);
        drmFree(ptr);
 }
+
+drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
+                                                     uint32_t object_id,
+                                                     uint32_t object_type)
+{
+       struct drm_mode_obj_get_properties properties;
+       drmModeObjectPropertiesPtr ret = NULL;
+       uint32_t count;
+
+retry:
+       memset(&properties, 0, sizeof(struct drm_mode_obj_get_properties));
+       properties.obj_id = object_id;
+       properties.obj_type = object_type;
+
+       if (drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties))
+               return 0;
+
+       count = properties.count_props;
+
+       if (count) {
+               properties.props_ptr = VOID2U64(drmMalloc(count *
+                                                         sizeof(uint32_t)));
+               if (!properties.props_ptr)
+                       goto err_allocs;
+               properties.prop_values_ptr = VOID2U64(drmMalloc(count *
+                                                     sizeof(uint64_t)));
+               if (!properties.prop_values_ptr)
+                       goto err_allocs;
+       }
+
+       if (drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties))
+               goto err_allocs;
+
+       if (count < properties.count_props) {
+               drmFree(U642VOID(properties.props_ptr));
+               drmFree(U642VOID(properties.prop_values_ptr));
+               goto retry;
+       }
+       count = properties.count_props;
+
+       ret = drmMalloc(sizeof(*ret));
+       if (!ret)
+               goto err_allocs;
+
+       ret->count_props = count;
+       ret->props = drmAllocCpy(U642VOID(properties.props_ptr),
+                                count, sizeof(uint32_t));
+       ret->prop_values = drmAllocCpy(U642VOID(properties.prop_values_ptr),
+                                      count, sizeof(uint64_t));
+       if (ret->count_props && (!ret->props || !ret->prop_values)) {
+               drmFree(ret->props);
+               drmFree(ret->prop_values);
+               drmFree(ret);
+               ret = NULL;
+       }
+
+err_allocs:
+       drmFree(U642VOID(properties.props_ptr));
+       drmFree(U642VOID(properties.prop_values_ptr));
+       return ret;
+}
+
+void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr)
+{
+       if (!ptr)
+               return;
+       drmFree(ptr->props);
+       drmFree(ptr->prop_values);
+       drmFree(ptr);
+}
+
+int drmModeObjectSetProperty(int fd, uint32_t object_id, uint32_t object_type,
+                            uint32_t property_id, uint64_t value)
+{
+       struct drm_mode_obj_set_property prop;
+
+       prop.value = value;
+       prop.prop_id = property_id;
+       prop.obj_id = object_id;
+       prop.obj_type = object_type;
+
+       return DRM_IOCTL(fd, DRM_IOCTL_MODE_OBJ_SETPROPERTY, &prop);
+}
index 991e3f94cc363d2bd8a381730559d42a82e306a7..8e40034052792c2b7e8a5cce815214d7205b2a03 100644 (file)
@@ -281,6 +281,12 @@ typedef struct _drmModeConnector {
        uint32_t *encoders; /**< List of encoder ids */
 } drmModeConnector, *drmModeConnectorPtr;
 
+typedef struct _drmModeObjectProperties {
+       uint32_t count_props;
+       uint32_t *props;
+       uint64_t *prop_values;
+} drmModeObjectProperties, *drmModeObjectPropertiesPtr;
+
 typedef struct _drmModePlane {
        uint32_t count_formats;
        uint32_t *formats;
@@ -428,6 +434,14 @@ extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
                           uint32_t src_x, uint32_t src_y,
                           uint32_t src_w, uint32_t src_h);
 
+extern drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
+                                                       uint32_t object_id,
+                                                       uint32_t object_type);
+extern void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr);
+extern int drmModeObjectSetProperty(int fd, uint32_t object_id,
+                                   uint32_t object_type, uint32_t property_id,
+                                   uint64_t value);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif