drm: add drm_property_change_is_valid
Subsystems (3)
PATCH 1/8 drm: add drm_property_change_is_valid
From: Paulo Zanoni <[email protected]>
Move code from drm_mode_connector_property_set_ioctl to a new function, so we can reuse this code when we add crtc properties.
v2: use bool instead of int
--- drivers/gpu/drm/drm_crtc.c | 41 +++++++++++++++++++++-------------------- 1 files changed, 21 insertions(+), 20 deletions(-)
drivers/gpu/drm/drm_crtc.c +21 -20
@@ -3033,6 +3033,26 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector, }EXPORT_SYMBOL (drm_mode_connector_update_edid_property); +static bool drm_property_change_is_valid (struct drm_property *property, +__u64 value) +{ +if (property->flags &DRM_MODE_PROP_IMMUTABLE ) +return false; +if (property->flags &DRM_MODE_PROP_RANGE ) { +if (value < property->values[0 ]) +return false; +if (value > property->values[1 ]) +return false; +return true; + }else { +int i; +for (i =0 ; i < property->num_values; i++) +if (property->values[i] == value) +return true; +return false; + } +} +int drm_mode_connector_property_set_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv) {
@@ -3069,28 +3089,9 @@ int drm_mode_connector_property_set_ioctl(struct drm_device *dev, } property =obj_to_property (obj); -if (property->flags &DRM_MODE_PROP_IMMUTABLE ) +if (!drm_property_change_is_valid (property, out_resp->value)) goto out; -if (property->flags &DRM_MODE_PROP_RANGE ) { -if (out_resp->value < property->values[0 ]) - goto out; - -if (out_resp->value > property->values[1 ]) - goto out; - }else { -int found =0 ; -for (i =0 ; i < property->num_values; i++) { -if (property->values[i] == out_resp->value) { - found =1 ; -break ; - } - } -if (!found) { - goto out; - } - } -/* Do DPMS ourselves */ if (property == connector->dev->mode_config.dpms_property) {if (connector->funcs->dpms)
Signature · 1 line
1.7.9.1
PATCH 2/8 drm: WARN() when drm_connector_attach_property fails
From: Paulo Zanoni <[email protected]>
Also return void instead of int. We have more than 100 callers and no one checks for the return value.
If this function fails the property won't be exposed by the get/set ioctls, but we should probably survive. If this starts happening, the solution will be to increase DRM_CONNECTOR_MAX_PROPERTY and recompile the Kernel.
--- drivers/gpu/drm/drm_crtc.c | 8 +++----- include/drm/drm_crtc.h | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_crtc.c +3 -5
@@ -2778,7 +2778,7 @@ void drm_property_destroy(struct drm_device *dev, struct drm_property *property) }EXPORT_SYMBOL (drm_property_destroy); -int drm_connector_attach_property (struct drm_connector *connector, +void drm_connector_attach_property (struct drm_connector *connector,struct drm_property *property,uint64_t init_val) {int i;
@@ -2787,13 +2787,11 @@ int drm_connector_attach_property(struct drm_connector *connector,if (connector->property_ids[i] ==0 ) { connector->property_ids[i] = property->base.id; connector->property_values[i] = init_val; -break ; +return ; } } -if (i ==DRM_CONNECTOR_MAX_PROPERTY ) -return -EINVAL ; -return 0 ; +WARN (1 ,"Failed to attach connector property\n" ); }EXPORT_SYMBOL (drm_connector_attach_property);
include/drm/drm_crtc.h +2 -2
@@ -910,8 +910,8 @@ extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);extern void drm_crtc_probe_connector_modes (struct drm_device *dev,int maxX,int maxY);extern bool drm_crtc_in_use (struct drm_crtc *crtc); -extern int drm_connector_attach_property (struct drm_connector *connector, -struct drm_property *property,uint64_t init_val); +extern void drm_connector_attach_property (struct drm_connector *connector, +struct drm_property *property,uint64_t init_val);extern struct drm_property *drm_property_create (struct drm_device *dev,int flags,const char *name,int num_values); extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
Signature · 1 line
1.7.9.1
Re: [PATCH 2/8] drm: WARN() when drm_connector_attach_property fails
Quoted 9 lines · Paulo Zanoni
From: Paulo Zanoni <[email protected]>
Also return void instead of int. We have more than 100 callers and no one checks for the return value.
If this function fails the property won't be exposed by the get/set ioctls, but we should probably survive. If this starts happening, the solution will be to increase
DRM_CONNECTOR_MAX_PROPERTYand recompile the Kernel.
Please add that to the error message and use printk_once() since we only really want to annoy the user the first time.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
PATCH 3/8 drm: create struct drm_object_properties and use it
In reply to Paulo ZanoniFrom: Paulo Zanoni <[email protected]>
For now, only connectors have it. In the future, all objects that need properties should use it. Since the strucutre is referenced inside struct drm_mode_object, we will be able to deal with object properties without knowing the real type of the object.
--- drivers/gpu/drm/drm_crtc.c | 43 ++++++++++++++++++++++--------------------- include/drm/drm_crtc.h | 16 +++++++++++----- 2 files changed, 33 insertions(+), 26 deletions(-)
drivers/gpu/drm/drm_crtc.c +22 -21
@@ -481,6 +481,7 @@ int drm_connector_init(struct drm_device *dev,if (ret) goto out; + connector->base.properties = &connector->properties; connector->dev = dev; connector->funcs = funcs; connector->connector_type = connector_type;
@@ -1422,8 +1423,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, } connector =obj_to_connector (obj); -for (i =0 ; i <DRM_CONNECTOR_MAX_PROPERTY ; i++) { -if (connector->property_ids[i] !=0 ) { +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { +if (connector->properties.ids[i] !=0 ) { props_count++; } }
@@ -1479,15 +1480,15 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, copied =0 ; prop_ptr = (uint32_t __user *)(unsigned long )(out_resp->props_ptr); prop_values = (uint64_t __user *)(unsigned long )(out_resp->prop_values_ptr); -for (i =0 ; i <DRM_CONNECTOR_MAX_PROPERTY ; i++) { -if (connector->property_ids[i] !=0 ) { -if (put_user (connector->property_ids[i], +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { +if (connector->properties.ids[i] !=0 ) { +if (put_user (connector->properties.ids[i], prop_ptr + copied)) { ret = -EFAULT ; goto out; } -if (put_user (connector->property_values[i], +if (put_user (connector->properties.values[i], prop_values + copied)) { ret = -EFAULT ; goto out;
@@ -2783,10 +2784,10 @@ void drm_connector_attach_property(struct drm_connector *connector, {int i; -for (i =0 ; i <DRM_CONNECTOR_MAX_PROPERTY ; i++) { -if (connector->property_ids[i] ==0 ) { - connector->property_ids[i] = property->base.id; - connector->property_values[i] = init_val; +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { +if (connector->properties.ids[i] ==0 ) { + connector->properties.ids[i] = property->base.id; + connector->properties.values[i] = init_val;return ; } }
@@ -2800,14 +2801,14 @@ int drm_connector_property_set_value(struct drm_connector *connector, {int i; -for (i =0 ; i <DRM_CONNECTOR_MAX_PROPERTY ; i++) { -if (connector->property_ids[i] == property->base.id) { - connector->property_values[i] = value; +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { +if (connector->properties.ids[i] == property->base.id) { + connector->properties.values[i] = value;break ; } } -if (i ==DRM_CONNECTOR_MAX_PROPERTY ) +if (i ==DRM_OBJECT_MAX_PROPERTY )return -EINVAL ;return 0 ; }
@@ -2818,14 +2819,14 @@ int drm_connector_property_get_value(struct drm_connector *connector, {int i; -for (i =0 ; i <DRM_CONNECTOR_MAX_PROPERTY ; i++) { -if (connector->property_ids[i] == property->base.id) { - *val = connector->property_values[i]; +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { +if (connector->properties.ids[i] == property->base.id) { + *val = connector->properties.values[i];break ; } } -if (i ==DRM_CONNECTOR_MAX_PROPERTY ) +if (i ==DRM_OBJECT_MAX_PROPERTY )return -EINVAL ;return 0 ; }
@@ -3072,12 +3073,12 @@ int drm_mode_connector_property_set_ioctl(struct drm_device *dev, } connector =obj_to_connector (obj); -for (i =0 ; i <DRM_CONNECTOR_MAX_PROPERTY ; i++) { -if (connector->property_ids[i] == out_resp->prop_id) +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { +if (connector->properties.ids[i] == out_resp->prop_id)break ; } -if (i ==DRM_CONNECTOR_MAX_PROPERTY ) { +if (i ==DRM_OBJECT_MAX_PROPERTY ) { goto out; }
include/drm/drm_crtc.h +11 -5
@@ -36,6 +36,8 @@struct drm_device ;struct drm_mode_set ;struct drm_framebuffer ; +struct drm_property ; +struct drm_object_properties ;#define DRM_MODE_OBJECT_CRTC 0xcccccccc
@@ -50,6 +52,13 @@ struct drm_framebuffer;struct drm_mode_object {uint32_t id;uint32_t type; +struct drm_object_properties *properties; +}; + +#define DRM_OBJECT_MAX_PROPERTY 16 +struct drm_object_properties { +uint32_t ids[DRM_OBJECT_MAX_PROPERTY ]; +uint64_t values[DRM_OBJECT_MAX_PROPERTY ]; };/*
@@ -451,7 +460,6 @@ struct drm_encoder_funcs { };#define DRM_CONNECTOR_MAX_UMODES 16 -#define DRM_CONNECTOR_MAX_PROPERTY 16#define DRM_CONNECTOR_LEN 32#define DRM_CONNECTOR_MAX_ENCODER 3
@@ -520,8 +528,7 @@ enum drm_connector_force {* @funcs: connector control functions * @user_modes: user added mode list * @edid_blob_ptr: DRM property containing EDID if present -* @property_ids: property tracking for this connector -* @property_values: value pointers or data for properties +* @properties: property tracking for this connector * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling * @dpms: current dpms state * @helper_private: mid-layer private data
@@ -565,8 +572,7 @@ struct drm_connector {struct list_head user_modes;struct drm_property_blob *edid_blob_ptr; -u32 property_ids[DRM_CONNECTOR_MAX_PROPERTY ]; -uint64_t property_values[DRM_CONNECTOR_MAX_PROPERTY ]; +struct drm_object_properties properties;uint8_t polled;/* DRM_CONNECTOR_POLL_* */
Signature · 1 line
1.7.9.1
Re: [PATCH 3/8] drm: create struct drm_object_properties and use it
Quoted 5 lines · Paulo Zanoni
From: Paulo Zanoni <[email protected]>
For now, only connectors have it. In the future, all objects that need properties should use it. Since the strucutre is referenced inside
*structure
Quoted 6 lines
struct
drm_mode_object, we will be able to deal with object properties without knowing the real type of the object.Signed-off-by Paulo Zanoni <[email protected]>
Signature · 2 lines
Eugeni Dodonov <http://eugeni.dodonov.net/>
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 3/8] drm: create struct drm_object_properties and use it
In reply to Paulo Zanoniinclude/drm/drm_crtc.h line 39
Quoted 9 lines · Paulo Zanoni
include/drm/drm_crtc.h +1
-0@@ -36,6 +36,8 @@struct drm_device ;struct drm_mode_set ;struct drm_framebuffer ; +struct drm_property ;
Unrelated change?
Quoted 5 lines
include/drm/drm_crtc.h +1
-0+struct drm_object_properties ;#define DRM_MODE_OBJECT_CRTC 0xcccccccc@@ -50,6 +52,13 @@ struct drm_framebuffer;
Signature · 2 lines
Ville Syrjälä Intel OTC
PATCH 4/8 drm: add generic ioctls to get/set properties on any object
In reply to Paulo ZanoniFrom: Paulo Zanoni <[email protected]>
Useless for connector properties (since they already have their own ioctls), but useful when we add properties to CRTCs, planes and other objects.
--- drivers/gpu/drm/drm_crtc.c | 180 ++++++++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_drv.c | 4 +- include/drm/drm.h | 2 + include/drm/drm_crtc.h | 13 +++ include/drm/drm_mode.h | 15 ++++ 5 files changed, 213 insertions(+), 1 deletions(-)
drivers/gpu/drm/drm_crtc.c +180 -0
@@ -2832,6 +2832,56 @@ int drm_connector_property_get_value(struct drm_connector *connector, }EXPORT_SYMBOL (drm_connector_property_get_value); +void drm_object_attach_property (struct drm_mode_object *obj, +struct drm_property *property, +uint64_t init_val) +{ +int i; + +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { +if (obj->properties->ids[i] ==0 ) { + obj->properties->ids[i] = property->base.id; + obj->properties->values[i] = init_val; +return ; + } + } + +WARN (1 ,"Failed to attach object property\n" ); +} +EXPORT_SYMBOL (drm_object_attach_property); + +int drm_object_property_set_value (struct drm_mode_object *obj, +struct drm_property *property,uint64_t val) +{ +int i; + +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { +if (obj->properties->ids[i] == property->base.id) { + obj->properties->values[i] = val; +return 0 ; + } + } + +return -EINVAL ; +} +EXPORT_SYMBOL (drm_object_property_set_value); + +int drm_object_property_get_value (struct drm_mode_object *obj, +struct drm_property *property,uint64_t *val) +{ +int i; + +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { +if (obj->properties->ids[i] == property->base.id) { + *val = obj->properties->values[i]; +return 0 ; + } + } + +return -EINVAL ; +} +EXPORT_SYMBOL (drm_object_property_get_value); +int drm_mode_getproperty_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv) {
@@ -3107,6 +3157,136 @@ out:return ret; } +static int drm_mode_connector_set_obj_prop (struct drm_mode_object *obj, +struct drm_property *property, +uint64_t value) +{ +int ret = -EINVAL ; +struct drm_connector *connector =obj_to_connector (obj); + +/* Do DPMS ourselves */ +if (property == connector->dev->mode_config.dpms_property) { +if (connector->funcs->dpms) + (*connector->funcs->dpms)(connector, (int )value); + ret =0 ; + }else if (connector->funcs->set_property) + ret = connector->funcs->set_property (connector, property, value); + +/* store the property value if successful */ +if (!ret) +drm_connector_property_set_value (connector, property, value); +return ret; +} + +int drm_mode_obj_get_properties_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv) +{ +struct drm_mode_obj_get_properties *arg = data; +struct drm_mode_object *obj; +int ret =0 ; +int i; +int copied =0 ; +int props_count =0 ; +uint32_t __user *props_ptr; +uint64_t __user *prop_values_ptr; + +if (!drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; + +mutex_lock (&dev->mode_config.mutex); + + obj =drm_mode_object_find (dev, arg->obj_id, arg->obj_type); +if (!obj) { + ret = -EINVAL ; + goto out; + } +if (!obj->properties) { + ret = -EINVAL ; + goto out; + } + +/* Assume [ prop, 0, prop ] won't happen (if we ever delete properties, +* we need to remove the gap inside the array). */ +for (props_count =0 ; props_count <DRM_OBJECT_MAX_PROPERTY && + obj->properties->ids[props_count] !=0 ; props_count++) + ; + +/* This ioctl is called twice, once to determine how much space is +* needed, and the 2nd time to fill it. */ +if ((arg->count_props >= props_count) && props_count) { + copied =0 ; + props_ptr = (uint32_t __user *)(unsigned long )(arg->props_ptr); + prop_values_ptr = (uint64_t __user *)(unsigned long ) + (arg->prop_values_ptr); +for (i =0 ; i < props_count; i++) { +if (put_user (obj->properties->ids[i], + props_ptr + copied)) { + ret = -EFAULT ; + goto out; + } +if (put_user (obj->properties->values[i], + prop_values_ptr + copied)) { + ret = -EFAULT ; + goto out; + } + copied++; + } + } + arg->count_props = props_count; +out: +mutex_unlock (&dev->mode_config.mutex); +return ret; +} + +int drm_mode_obj_set_property_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv) +{ +struct drm_mode_obj_set_property *arg = data; +struct drm_mode_object *arg_obj; +struct drm_mode_object *prop_obj; +struct drm_property *property; +int ret = -EINVAL ; +int i; + +if (!drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; + +mutex_lock (&dev->mode_config.mutex); + + arg_obj =drm_mode_object_find (dev, arg->obj_id, arg->obj_type); +if (!arg_obj) + goto out; +if (!arg_obj->properties) + goto out; + +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) +if (arg_obj->properties->ids[i] == arg->prop_id) +break ; + +if (i ==DRM_OBJECT_MAX_PROPERTY ) + goto out; + + prop_obj =drm_mode_object_find (dev, arg->prop_id, +DRM_MODE_OBJECT_PROPERTY ); +if (!prop_obj) + goto out; + property =obj_to_property (prop_obj); + +if (!drm_property_change_is_valid (property, arg->value)) + goto out; + +switch (arg_obj->type) { +case DRM_MODE_OBJECT_CONNECTOR : + ret =drm_mode_connector_set_obj_prop (arg_obj, property, + arg->value); +break ; + } + +out: +mutex_unlock (&dev->mode_config.mutex); +return ret; +} +int drm_mode_connector_attach_encoder (struct drm_connector *connector,struct drm_encoder *encoder) {
drivers/gpu/drm/drm_drv.c +3 -1
@@ -159,7 +159,9 @@ static struct drm_ioctl_desc drm_ioctls[] = {DRM_IOCTL_DEF (DRM_IOCTL_MODE_DIRTYFB , drm_mode_dirtyfb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATE_DUMB , drm_mode_create_dumb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_MAP_DUMB , drm_mode_mmap_dumb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), - DRM_IOCTL_DEF(DRM_IOCTL_MODE_DESTROY_DUMB, drm_mode_destroy_dumb_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED) +DRM_IOCTL_DEF (DRM_IOCTL_MODE_DESTROY_DUMB , drm_mode_destroy_dumb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_OBJ_GETPROPERTIES , drm_mode_obj_get_properties_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), + DRM_IOCTL_DEF(DRM_IOCTL_MODE_OBJ_SETPROPERTY, drm_mode_obj_set_property_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED) };#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
include/drm/drm.h +2 -0
@@ -718,6 +718,8 @@ struct drm_get_cap {#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
include/drm/drm_crtc.h +13 -0
@@ -904,6 +904,12 @@ extern int drm_connector_property_set_value(struct drm_connector *connector,extern int drm_connector_property_get_value (struct drm_connector *connector,struct drm_property *property,uint64_t *value); +extern int drm_object_property_set_value (struct drm_mode_object *obj, +struct drm_property *property, +uint64_t val); +extern int drm_object_property_get_value (struct drm_mode_object *obj, +struct drm_property *property, +uint64_t *value);extern struct drm_display_mode *drm_crtc_mode_create (struct drm_device *dev);extern void drm_framebuffer_set_object (struct drm_device *dev,unsigned long handle);
@@ -918,6 +924,9 @@ extern bool drm_crtc_in_use(struct drm_crtc *crtc);extern void drm_connector_attach_property (struct drm_connector *connector,struct drm_property *property,uint64_t init_val); +extern void drm_object_attach_property (struct drm_mode_object *obj, +struct drm_property *property, +uint64_t init_val);extern struct drm_property *drm_property_create (struct drm_device *dev,int flags,const char *name,int num_values); extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
@@ -1029,6 +1038,10 @@ extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);extern int drm_mode_destroy_dumb_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv); +extern int drm_mode_obj_get_properties_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv); +extern int drm_mode_obj_set_property_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv);extern void drm_fb_get_bpp_depth (uint32_t format,unsigned int *depth,int *bpp);
include/drm/drm_mode.h +15 -0
@@ -252,6 +252,21 @@ struct drm_mode_connector_set_property {__u32 connector_id; }; +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;
Signature · 1 line
1.7.9.1
Re: [PATCH 4/8] drm: add generic ioctls to get/set properties on any object
drivers/gpu/drm/drm_crtc.c out: · line 3283
Quoted 7 lines · Paulo Zanoni
drivers/gpu/drm/drm_crtc.c +6
-0+switch (arg_obj->type) { +case DRM_MODE_OBJECT_CONNECTOR : + ret =drm_mode_connector_set_obj_prop (arg_obj, property, + arg->value); +break ; + }
<bikeshedding>
Perhaps we could add a debug message here for catch the unhandled types.. </bikeshedding>
But apart from that,
Signature · 2 lines
Eugeni Dodonov <http://eugeni.dodonov.net/>
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 4/8] drm: add generic ioctls to get/set properties on any object
In reply to Paulo ZanoniQuoted 123 lines · Paulo Zanoni
From: Paulo Zanoni <[email protected]>
Useless for connector properties (since they already have their own ioctls), but useful when we add properties to CRTCs, planes and other objects.
Signed-off-by Paulo Zanoni <[email protected]>--- drivers/gpu/drm/drm_crtc.c | 180 ++++++++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_drv.c | 4 +- include/drm/drm.h | 2 + include/drm/drm_crtc.h | 13 +++ include/drm/drm_mode.h | 15 ++++ 5 files changed, 213 insertions(+), 1 deletions(-)drivers/gpu/drm/drm_crtc.c +93
-0@@ -2832,6 +2832,56 @@ int drm_connector_property_get_value(struct drm_connector *connector, }EXPORT_SYMBOL (drm_connector_property_get_value); +void drm_object_attach_property (struct drm_mode_object *obj, +struct drm_property *property, +uint64_t init_val) +{ +int i; + +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { +if (obj->properties->ids[i] ==0 ) { + obj->properties->ids[i] = property->base.id; + obj->properties->values[i] = init_val; +return ; + } + } + +WARN (1 ,"Failed to attach object property\n" ); +} +EXPORT_SYMBOL (drm_object_attach_property); + +int drm_object_property_set_value (struct drm_mode_object *obj, +struct drm_property *property,uint64_t val) +{ +int i; + +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { +if (obj->properties->ids[i] == property->base.id) { + obj->properties->values[i] = val; +return 0 ; + } + } + +return -EINVAL ; +} +EXPORT_SYMBOL (drm_object_property_set_value); + +int drm_object_property_get_value (struct drm_mode_object *obj, +struct drm_property *property,uint64_t *val) +{ +int i; + +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { +if (obj->properties->ids[i] == property->base.id) { + *val = obj->properties->values[i]; +return 0 ; + } + } + +return -EINVAL ; +} +EXPORT_SYMBOL (drm_object_property_get_value); +int drm_mode_getproperty_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv) {@@ -3107,6 +3157,136 @@ out:return ret; } +static int drm_mode_connector_set_obj_prop (struct drm_mode_object *obj, +struct drm_property *property, +uint64_t value) +{ +int ret = -EINVAL ; +struct drm_connector *connector =obj_to_connector (obj); + +/* Do DPMS ourselves */ +if (property == connector->dev->mode_config.dpms_property) { +if (connector->funcs->dpms) + (*connector->funcs->dpms)(connector, (int )value); + ret =0 ; + }else if (connector->funcs->set_property) + ret = connector->funcs->set_property (connector, property, value); + +/* store the property value if successful */ +if (!ret) +drm_connector_property_set_value (connector, property, value); +return ret; +} + +int drm_mode_obj_get_properties_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv) +{ +struct drm_mode_obj_get_properties *arg = data; +struct drm_mode_object *obj; +int ret =0 ; +int i; +int copied =0 ; +int props_count =0 ; +uint32_t __user *props_ptr; +uint64_t __user *prop_values_ptr; + +if (!drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; + +mutex_lock (&dev->mode_config.mutex); + + obj =drm_mode_object_find (dev, arg->obj_id, arg->obj_type); +if (!obj) { + ret = -EINVAL ; + goto out; + }
drivers/gpu/drm/drm_crtc.c out: · line 3212
Quoted 10 lines
drivers/gpu/drm/drm_crtc.c +10
-0+if (!obj->properties) { + ret = -EINVAL ; + goto out; + } + +/* Assume [ prop, 0, prop ] won't happen (if we ever delete properties, +* we need to remove the gap inside the array). */ +for (props_count =0 ; props_count <DRM_OBJECT_MAX_PROPERTY && + obj->properties->ids[props_count] !=0 ; props_count++) + ;
How about adding obj->properties.count to avoid having to count every time?
Quoted 85 lines
drivers/gpu/drm/drm_crtc.c +77
-0+ +/* This ioctl is called twice, once to determine how much space is +* needed, and the 2nd time to fill it. */ +if ((arg->count_props >= props_count) && props_count) { + copied =0 ; + props_ptr = (uint32_t __user *)(unsigned long )(arg->props_ptr); + prop_values_ptr = (uint64_t __user *)(unsigned long ) + (arg->prop_values_ptr); +for (i =0 ; i < props_count; i++) { +if (put_user (obj->properties->ids[i], + props_ptr + copied)) { + ret = -EFAULT ; + goto out; + } +if (put_user (obj->properties->values[i], + prop_values_ptr + copied)) { + ret = -EFAULT ; + goto out; + } + copied++; + } + } + arg->count_props = props_count; +out: +mutex_unlock (&dev->mode_config.mutex); +return ret; +} + +int drm_mode_obj_set_property_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv) +{ +struct drm_mode_obj_set_property *arg = data; +struct drm_mode_object *arg_obj; +struct drm_mode_object *prop_obj; +struct drm_property *property; +int ret = -EINVAL ; +int i; + +if (!drm_core_check_feature (dev,DRIVER_MODESET )) +return -EINVAL ; + +mutex_lock (&dev->mode_config.mutex); + + arg_obj =drm_mode_object_find (dev, arg->obj_id, arg->obj_type); +if (!arg_obj) + goto out; +if (!arg_obj->properties) + goto out; + +for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) +if (arg_obj->properties->ids[i] == arg->prop_id) +break ; + +if (i ==DRM_OBJECT_MAX_PROPERTY ) + goto out; + + prop_obj =drm_mode_object_find (dev, arg->prop_id, +DRM_MODE_OBJECT_PROPERTY ); +if (!prop_obj) + goto out; + property =obj_to_property (prop_obj); + +if (!drm_property_change_is_valid (property, arg->value)) + goto out; + +switch (arg_obj->type) { +case DRM_MODE_OBJECT_CONNECTOR : + ret =drm_mode_connector_set_obj_prop (arg_obj, property, + arg->value); +break ; + } + +out: +mutex_unlock (&dev->mode_config.mutex); +return ret; +} +int drm_mode_connector_attach_encoder (struct drm_connector *connector,struct drm_encoder *encoder) {drivers/gpu/drm/drm_drv.c +0
-0
drivers/gpu/drm/drm_drv.c static struct drm_ioctl_desc drm_ioctls[] = { · line 164
Quoted 7 lines
drivers/gpu/drm/drm_drv.c +3
-1@@ -159,7 +159,9 @@ static struct drm_ioctl_desc drm_ioctls[] = {DRM_IOCTL_DEF (DRM_IOCTL_MODE_DIRTYFB , drm_mode_dirtyfb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATE_DUMB , drm_mode_create_dumb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_MAP_DUMB , drm_mode_mmap_dumb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), -DRM_IOCTL_DEF (DRM_IOCTL_MODE_DESTROY_DUMB , drm_mode_destroy_dumb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ) +DRM_IOCTL_DEF (DRM_IOCTL_MODE_DESTROY_DUMB , drm_mode_destroy_dumb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_OBJ_GETPROPERTIES , drm_mode_obj_get_properties_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_OBJ_SETPROPERTY , drm_mode_obj_set_property_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED )
Just add the trailing comma to the last line as well. Otherwise we keep on having ugly diffs when new ioctls are added.
Quoted 3 lines
drivers/gpu/drm/drm_drv.c +0
-0};#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
Signature · 2 lines
Ville Syrjälä Intel OTC
PATCH 5/8 drm: make the connector properties code use the object properties code
In reply to Paulo ZanoniFrom: Paulo Zanoni <[email protected]>
--- drivers/gpu/drm/drm_crtc.c | 96 +++++-------------------------------------- 1 files changed, 12 insertions(+), 84 deletions(-)
drivers/gpu/drm/drm_crtc.c +12 -84
@@ -2782,53 +2782,21 @@ EXPORT_SYMBOL(drm_property_destroy);void drm_connector_attach_property (struct drm_connector *connector,struct drm_property *property,uint64_t init_val) { -int i; - -for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { -if (connector->properties.ids[i] ==0 ) { - connector->properties.ids[i] = property->base.id; - connector->properties.values[i] = init_val; -return ; - } - } - -WARN (1 ,"Failed to attach connector property\n" ); +drm_object_attach_property (&connector->base, property, init_val); }EXPORT_SYMBOL (drm_connector_attach_property);int drm_connector_property_set_value (struct drm_connector *connector,struct drm_property *property,uint64_t value) { -int i; - -for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { -if (connector->properties.ids[i] == property->base.id) { - connector->properties.values[i] = value; -break ; - } - } - -if (i ==DRM_OBJECT_MAX_PROPERTY ) -return -EINVAL ; -return 0 ; +return drm_object_property_set_value (&connector->base, property, value); }EXPORT_SYMBOL (drm_connector_property_set_value);int drm_connector_property_get_value (struct drm_connector *connector,struct drm_property *property,uint64_t *val) { -int i; - -for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { -if (connector->properties.ids[i] == property->base.id) { - *val = connector->properties.values[i]; -break ; - } - } - -if (i ==DRM_OBJECT_MAX_PROPERTY ) -return -EINVAL ; -return 0 ; +return drm_object_property_get_value (&connector->base, property, val); }EXPORT_SYMBOL (drm_connector_property_get_value);
@@ -3105,56 +3073,16 @@ static bool drm_property_change_is_valid(struct drm_property *property,int drm_mode_connector_property_set_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv) { -struct drm_mode_connector_set_property *out_resp = data; -struct drm_mode_object *obj; -struct drm_property *property; -struct drm_connector *connector; -int ret = -EINVAL ; -int i; - -if (!drm_core_check_feature (dev,DRIVER_MODESET )) -return -EINVAL ; - -mutex_lock (&dev->mode_config.mutex); - - obj =drm_mode_object_find (dev, out_resp->connector_id,DRM_MODE_OBJECT_CONNECTOR ); -if (!obj) { - goto out; - } - connector =obj_to_connector (obj); - -for (i =0 ; i <DRM_OBJECT_MAX_PROPERTY ; i++) { -if (connector->properties.ids[i] == out_resp->prop_id) -break ; - } - -if (i ==DRM_OBJECT_MAX_PROPERTY ) { - goto out; - } - - obj =drm_mode_object_find (dev, out_resp->prop_id,DRM_MODE_OBJECT_PROPERTY ); -if (!obj) { - goto out; - } - property =obj_to_property (obj); +struct drm_mode_connector_set_property *conn_set_prop = data; +struct drm_mode_obj_set_property obj_set_prop = { + .value = conn_set_prop->value, + .prop_id = conn_set_prop->prop_id, + .obj_id = conn_set_prop->connector_id, + .obj_type =DRM_MODE_OBJECT_CONNECTOR + }; -if (!drm_property_change_is_valid (property, out_resp->value)) - goto out; - -/* Do DPMS ourselves */ -if (property == connector->dev->mode_config.dpms_property) { -if (connector->funcs->dpms) - (*connector->funcs->dpms)(connector, (int ) out_resp->value); - ret =0 ; - }else if (connector->funcs->set_property) - ret = connector->funcs->set_property (connector, property, out_resp->value); - -/* store the property value if successful */ -if (!ret) -drm_connector_property_set_value (connector, property, out_resp->value); -out: -mutex_unlock (&dev->mode_config.mutex); -return ret; +/* It does all the locking and checking we need */ +return drm_mode_obj_set_property_ioctl (dev, &obj_set_prop, file_priv); } static int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,
Signature · 1 line
1.7.9.1
Re: [PATCH 5/8] drm: make the connector properties code use the object properties code
Quoted 4 lines · Paulo Zanoni
From: Paulo Zanoni <[email protected]>
Signed-off-by Paulo Zanoni <[email protected]>
Signature · 2 lines
Eugeni Dodonov <http://eugeni.dodonov.net/>
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 6/8 drm: add CRTC properties
In reply to Paulo ZanoniFrom: Paulo Zanoni <[email protected]>
The i915 driver needs this for the rotation and overscan compensation properties. Other drivers might need this too.
--- drivers/gpu/drm/drm_crtc.c | 20 ++++++++++++++++++++ include/drm/drm_crtc.h | 9 ++++++++- 2 files changed, 28 insertions(+), 1 deletions(-)
drivers/gpu/drm/drm_crtc.c +20 -0
@@ -382,6 +382,8 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,if (ret) goto out; + crtc->base.properties = &crtc->properties; +list_add_tail (&crtc->head, &dev->mode_config.crtc_list); dev->mode_config.num_crtc++;
@@ -3106,6 +3108,21 @@ static int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,return ret; } +static int drm_mode_crtc_set_obj_prop (struct drm_mode_object *obj, +struct drm_property *property, +uint64_t value) +{ +int ret = -EINVAL ; +struct drm_crtc *crtc =obj_to_crtc (obj); + +if (crtc->funcs->set_property) + ret = crtc->funcs->set_property (crtc, property, value); +if (!ret) +drm_object_property_set_value (obj, property, value); + +return ret; +} +int drm_mode_obj_get_properties_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv) {
@@ -3208,6 +3225,9 @@ int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, ret =drm_mode_connector_set_obj_prop (arg_obj, property, arg->value);break ; +case DRM_MODE_OBJECT_CRTC : + ret =drm_mode_crtc_set_obj_prop (arg_obj, property, arg->value); +break ; } out:
include/drm/drm_crtc.h +8 -1
@@ -306,7 +306,8 @@ struct drm_plane;* @mode_fixup: fixup proposed mode * @mode_set: set the desired mode on the CRTC * @gamma_set: specify color ramp for CRTC -* @destroy: deinit and free object. +* @destroy: deinit and free object +* @set_property: called when a property is changed * * The drm_crtc_funcs structure is the central CRTC management structure * in the DRM. Each CRTC controls one or more connectors (note that the name
@@ -350,6 +351,9 @@ struct drm_crtc_funcs {int (*page_flip)(struct drm_crtc *crtc,struct drm_framebuffer *fb,struct drm_pending_vblank_event *event); + +int (*set_property)(struct drm_crtc *crtc, +struct drm_property *property,uint64_t val); };/**
@@ -369,6 +373,7 @@ struct drm_crtc_funcs {* @framedur_ns: precise line timing * @pixeldur_ns: precise pixel timing * @helper_private: mid-layer private data +* @properties: property tracking for this CRTC * * Each CRTC may have one or more connectors associated with it. This structure * allows the CRTC to be controlled.
@@ -404,6 +409,8 @@ struct drm_crtc {/* if you are using the helper */ void *helper_private; + +struct drm_object_properties properties; };
Signature · 1 line
1.7.9.1
RFC PATCH 7/8 drm/i915: add 'rotation' CRTC property
In reply to Paulo ZanoniFrom: Paulo Zanoni <[email protected]>
This property is needed so we can inform the KVMr feature about our current rotation: whenever we change the rotation, we should change that property so that the KVMr knows that the screen is rotated.
How to reproduce the problem:
- on an AMT machine, enable KVM
- boot the machine, use xrandr to rotate the display
- use VNC to connect to the KVM
- try to use the mouse
v2: only create the property once
v3: adapt to the new drm code for object properties
--- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_reg.h | 5 +++ drivers/gpu/drm/i915/intel_display.c | 66 ++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 0 deletions(-)
After talking to Rob we concluded that instead of having a value from 0-359 we should have a bitmask (just like X's RR_Rotate_X stuff). This will allow not only rotations, but also reflections. OTOH, rotations that are not 0, 90, 180 or 270 will not be allowed. If we ever need these arbitrary rotations, I think we should create a property that matches X's transformation matrix and keep this one existing (just like X).
Rob plans to implement "bit mask properties" support, so after his patch I'll update this one to use a bit mask property.
drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -779,6 +779,7 @@ typedef struct drm_i915_private {struct drm_property *broadcast_rgb_property;struct drm_property *force_audio_property; +struct drm_property *rotation_property; } drm_i915_private_t;enum hdmi_force_audio {
drivers/gpu/drm/i915/i915_reg.h +5 -0
@@ -2407,6 +2407,11 @@#define PIPECONF_INTERLACED_DBL_ILK (4 << 21)/* ilk/snb only */ #define PIPECONF_PFIT_PF_INTERLACED_DBL_ILK (5 << 21)/* ilk/snb only */ #define PIPECONF_CXSR_DOWNCLOCK (1<<16) +#define PIPECONF_ROTATION_MASK (3 << 14) +#define PIPECONF_ROTATION_0 (0 << 14) +#define PIPECONF_ROTATION_90 (1 << 14) +#define PIPECONF_ROTATION_180 (2 << 14) +#define PIPECONF_ROTATION_270 (3 << 14)#define PIPECONF_BPP_MASK (0x000000e0)#define PIPECONF_BPP_8 (0<<5)#define PIPECONF_BPP_10 (1<<5)
drivers/gpu/drm/i915/intel_display.c +66 -0
86 lines not on this page · raw message
Signature · 1 line
1.7.9.1
PATCH 8/8 drm/i915: add overscan compensation CRTC properties
In reply to Paulo ZanoniFrom: Paulo Zanoni <[email protected]>
They're named "underscan hborder" and "underscan vborder". The properties accept values from 0 to 100, where 0 is "don't compensate" and 100 is "shrink the screen as much as possible" (not necessarily 100 pixels).
V2: Rename to "underscan hborder" and "underscan vborder" to match the radeon properties. Note that we have a range of 0-100 (not pixels) and radeon has a range of 0-128 (pixels). Fix compilation on 32 bit systems.
--- drivers/gpu/drm/i915/i915_drv.h | 2 + drivers/gpu/drm/i915/intel_display.c | 117 +++++++++++++++++++++++++++++++++- 2 files changed, 118 insertions(+), 1 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -780,6 +780,8 @@ typedef struct drm_i915_private {struct drm_property *broadcast_rgb_property;struct drm_property *force_audio_property;struct drm_property *rotation_property; +struct drm_property *underscan_hborder_property; +struct drm_property *underscan_vborder_property; } drm_i915_private_t;enum hdmi_force_audio {
drivers/gpu/drm/i915/intel_display.c +116 -1
148 lines not on this page · raw message
Signature · 1 line
1.7.9.1
drivers/gpu/drm/drm_crtc.c int drm_mode_connector_update_edid_property(struct drm_connector *connector, · line 3045
Quoted 6 lines · Paulo Zanoni
drivers/gpu/drm/drm_crtc.c +5
-0+if (property->flags &DRM_MODE_PROP_RANGE ) { +if (value < property->values[0 ]) +return false; +if (value > property->values[1 ]) +return false;
Those two checks could probably be combined into one (< values || > values) for further simplification.
But other than this,
Signature · 2 lines
Eugeni Dodonov <http://eugeni.dodonov.net/>
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel