From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ville =?iso-8859-1?Q?Syrj=E4l=E4?= Subject: Re: [PATCH 4/8] drm: add generic ioctls to get/set properties on any object Date: Fri, 30 Mar 2012 16:04:08 +0300 Message-ID: <20120330130408.GA4917@intel.com> References: <1333056446-3383-1-git-send-email-przanoni@gmail.com> <1333056446-3383-4-git-send-email-przanoni@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id A3D9BA0F3D for ; Fri, 30 Mar 2012 06:04:11 -0700 (PDT) Content-Disposition: inline In-Reply-To: <1333056446-3383-4-git-send-email-przanoni@gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org Errors-To: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org To: Paulo Zanoni Cc: Paulo Zanoni , dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org On Thu, Mar 29, 2012 at 06:27:22PM -0300, Paulo Zanoni wrote: > From: Paulo Zanoni > = > 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 > --- > 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(-) > = > diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c > index 8800830..12f93e4 100644 > --- a/drivers/gpu/drm/drm_crtc.c > +++ b/drivers/gpu/drm/drm_crtc.c > @@ -2832,6 +2832,56 @@ int drm_connector_property_get_value(struct drm_co= nnector *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 =3D 0; i < DRM_OBJECT_MAX_PROPERTY; i++) { > + if (obj->properties->ids[i] =3D=3D 0) { > + obj->properties->ids[i] =3D property->base.id; > + obj->properties->values[i] =3D 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 =3D 0; i < DRM_OBJECT_MAX_PROPERTY; i++) { > + if (obj->properties->ids[i] =3D=3D property->base.id) { > + obj->properties->values[i] =3D 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 =3D 0; i < DRM_OBJECT_MAX_PROPERTY; i++) { > + if (obj->properties->ids[i] =3D=3D property->base.id) { > + *val =3D 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 =3D -EINVAL; > + struct drm_connector *connector =3D obj_to_connector(obj); > + > + /* Do DPMS ourselves */ > + if (property =3D=3D connector->dev->mode_config.dpms_property) { > + if (connector->funcs->dpms) > + (*connector->funcs->dpms)(connector, (int)value); > + ret =3D 0; > + } else if (connector->funcs->set_property) > + ret =3D 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 =3D data; > + struct drm_mode_object *obj; > + int ret =3D 0; > + int i; > + int copied =3D 0; > + int props_count =3D 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 =3D drm_mode_object_find(dev, arg->obj_id, arg->obj_type); > + if (!obj) { > + ret =3D -EINVAL; > + goto out; > + } > + if (!obj->properties) { > + ret =3D -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 =3D 0; props_count < DRM_OBJECT_MAX_PROPERTY && > + obj->properties->ids[props_count] !=3D 0; props_count++) > + ; How about adding obj->properties.count to avoid having to count every time? > + > + /* This ioctl is called twice, once to determine how much space is > + * needed, and the 2nd time to fill it. */ > + if ((arg->count_props >=3D props_count) && props_count) { > + copied =3D 0; > + props_ptr =3D (uint32_t __user *)(unsigned long)(arg->props_ptr); > + prop_values_ptr =3D (uint64_t __user *)(unsigned long) > + (arg->prop_values_ptr); > + for (i =3D 0; i < props_count; i++) { > + if (put_user(obj->properties->ids[i], > + props_ptr + copied)) { > + ret =3D -EFAULT; > + goto out; > + } > + if (put_user(obj->properties->values[i], > + prop_values_ptr + copied)) { > + ret =3D -EFAULT; > + goto out; > + } > + copied++; > + } > + } > + arg->count_props =3D 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 =3D data; > + struct drm_mode_object *arg_obj; > + struct drm_mode_object *prop_obj; > + struct drm_property *property; > + int ret =3D -EINVAL; > + int i; > + > + if (!drm_core_check_feature(dev, DRIVER_MODESET)) > + return -EINVAL; > + > + mutex_lock(&dev->mode_config.mutex); > + > + arg_obj =3D drm_mode_object_find(dev, arg->obj_id, arg->obj_type); > + if (!arg_obj) > + goto out; > + if (!arg_obj->properties) > + goto out; > + > + for (i =3D 0; i < DRM_OBJECT_MAX_PROPERTY; i++) > + if (arg_obj->properties->ids[i] =3D=3D arg->prop_id) > + break; > + > + if (i =3D=3D DRM_OBJECT_MAX_PROPERTY) > + goto out; > + > + prop_obj =3D drm_mode_object_find(dev, arg->prop_id, > + DRM_MODE_OBJECT_PROPERTY); > + if (!prop_obj) > + goto out; > + property =3D 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 =3D 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) > { > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c > index 0b65fbc..18db86e 100644 > --- a/drivers/gpu/drm/drm_drv.c > +++ b/drivers/gpu/drm/drm_drv.c > @@ -159,7 +159,9 @@ static struct drm_ioctl_desc drm_ioctls[] =3D { > DRM_IOCTL_DEF(DRM_IOCTL_MODE_DIRTYFB, drm_mode_dirtyfb_ioctl, DRM_MASTE= R|DRM_CONTROL_ALLOW|DRM_UNLOCKED), > DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_DUMB, drm_mode_create_dumb_ioctl, D= RM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), > DRM_IOCTL_DEF(DRM_IOCTL_MODE_MAP_DUMB, drm_mode_mmap_dumb_ioctl, DRM_MA= STER|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_proper= ties_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. > }; > = > #define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls ) -- = Ville Syrj=E4l=E4 Intel OTC