[PATCH] drm: Add standardized boolean props

2015-01-22 Thread Thierry Reding
On Wed, Jan 21, 2015 at 08:47:38AM +0100, Daniel Vetter wrote:
[...]
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
[...]
> @@ -3738,6 +3738,24 @@ struct drm_property *drm_property_create_range(struct 
> drm_device *dev, int flags
>  }
>  EXPORT_SYMBOL(drm_property_create_range);
>  
> +/**
> + * drm_property_create_signed_range - create a new signed ranged property 
> type
> + * @dev: drm device
> + * @flags: flags specifying the property type
> + * @name: name of the property
> + * @min: minimum value of the property
> + * @max: maximum value of the property
> + *
> + * This creates a new generic drm property which can then be attached to a 
> drm

Nit: s/drm/DRM/ but that's the same for all others so can be done in a
follow-up. I'll volunteer because I realize that not everybody is that
pedantic.

>  /**
> + * drm_property_create_bool - create a new boolean property type
> + * @dev: drm device
> + * @flags: flags specifying the property type
> + * @name: name of the property
> + *
> + * This creates a new generic drm property which can then be attached to a 
> drm
> + * object with drm_object_attach_property. The returned property object must 
> be
> + * freed with drm_property_destroy.
> + *
> + * This is implemented as a ranged property with only {0, 1} as valid values.
> + *
> + * Returns:
> + * A pointer to the newly created property on success, NULL on failure.
> + */
> +struct drm_property *drm_property_create_bool(struct drm_device *dev, int 
> flags,

I find that int is a strange type for flags. unsigned long is a little
more idiomatic in my opinion. But again all other functions seem to do
the same, so no need to respin because of that.

Reviewed-by: Thierry Reding 
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: 



[PATCH] drm: Add standardized boolean props

2015-01-21 Thread Rob Clark
On Wed, Jan 21, 2015 at 2:47 AM, Daniel Vetter  
wrote:
> Not a new type exposed to userspace, just a standard way to create
> them since between range, bitmask and enum there's 3 different ways to
> pull out a boolean prop.
>
> Also add the kerneldoc for the recently added new prop types, which
> Rob forgot all about.
>
> v2: Fixup kerneldoc, spotted by Rob.
>
> Cc: Rob Clark 
> Signed-off-by: Daniel Vetter 

Reviewed-by: Rob Clark 

> ---
>  drivers/gpu/drm/drm_crtc.c | 66 
> +++---
>  include/drm/drm_crtc.h |  2 ++
>  2 files changed, 65 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 071d7465043a..56e3256d5249 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -3712,7 +3712,7 @@ static struct drm_property 
> *property_create_range(struct drm_device *dev,
>  }
>
>  /**
> - * drm_property_create_range - create a new ranged property type
> + * drm_property_create_range - create a new unsigned ranged property type
>   * @dev: drm device
>   * @flags: flags specifying the property type
>   * @name: name of the property
> @@ -3723,8 +3723,8 @@ static struct drm_property 
> *property_create_range(struct drm_device *dev,
>   * object with drm_object_attach_property. The returned property object must 
> be
>   * freed with drm_property_destroy.
>   *
> - * Userspace is allowed to set any integer value in the (min, max) range
> - * inclusive.
> + * Userspace is allowed to set any unsigned integer value in the (min, max)
> + * range inclusive.
>   *
>   * Returns:
>   * A pointer to the newly created property on success, NULL on failure.
> @@ -3738,6 +3738,24 @@ struct drm_property *drm_property_create_range(struct 
> drm_device *dev, int flags
>  }
>  EXPORT_SYMBOL(drm_property_create_range);
>
> +/**
> + * drm_property_create_signed_range - create a new signed ranged property 
> type
> + * @dev: drm device
> + * @flags: flags specifying the property type
> + * @name: name of the property
> + * @min: minimum value of the property
> + * @max: maximum value of the property
> + *
> + * This creates a new generic drm property which can then be attached to a 
> drm
> + * object with drm_object_attach_property. The returned property object must 
> be
> + * freed with drm_property_destroy.
> + *
> + * Userspace is allowed to set any signed integer value in the (min, max)
> + * range inclusive.
> + *
> + * Returns:
> + * A pointer to the newly created property on success, NULL on failure.
> + */
>  struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
>  int flags, const char *name,
>  int64_t min, int64_t max)
> @@ -3747,6 +3765,23 @@ struct drm_property 
> *drm_property_create_signed_range(struct drm_device *dev,
>  }
>  EXPORT_SYMBOL(drm_property_create_signed_range);
>
> +/**
> + * drm_property_create_object - create a new object property type
> + * @dev: drm device
> + * @flags: flags specifying the property type
> + * @name: name of the property
> + * @type: object type from DRM_MODE_OBJECT_* defines
> + *
> + * This creates a new generic drm property which can then be attached to a 
> drm
> + * object with drm_object_attach_property. The returned property object must 
> be
> + * freed with drm_property_destroy.
> + *
> + * Userspace is only allowed to set this to any property value of the given
> + * @type. Only useful for atomic properties, which is enforced.
> + *
> + * Returns:
> + * A pointer to the newly created property on success, NULL on failure.
> + */
>  struct drm_property *drm_property_create_object(struct drm_device *dev,
>  int flags, const char *name, 
> uint32_t type)
>  {
> @@ -3754,6 +3789,9 @@ struct drm_property *drm_property_create_object(struct 
> drm_device *dev,
>
> flags |= DRM_MODE_PROP_OBJECT;
>
> +   if (WARN_ON(!(flags & DRM_MODE_PROP_ATOMIC)))
> +   return NULL;
> +
> property = drm_property_create(dev, flags, name, 1);
> if (!property)
> return NULL;
> @@ -3765,6 +3803,28 @@ struct drm_property *drm_property_create_object(struct 
> drm_device *dev,
>  EXPORT_SYMBOL(drm_property_create_object);
>
>  /**
> + * drm_property_create_bool - create a new boolean property type
> + * @dev: drm device
> + * @flags: flags specifying the property type
> + * @name: name of the property
> + *
> + * This creates a new generic drm property which can then be attached to a 
> drm
> + * object with drm_object_attach_property. The returned property object must 
> be
> + * freed with drm_property_destroy.
> + *
> + * This is implemented as a ranged property with only {0, 1} as valid values.
> + *
> + * Returns:
> + * A pointer to the newly created property on success, NULL on failure.
> + */
> +struct drm_property *drm_property_create_bool(struct drm_device *dev, int 
> 

[PATCH] drm: Add standardized boolean props

2015-01-21 Thread Daniel Vetter
Not a new type exposed to userspace, just a standard way to create
them since between range, bitmask and enum there's 3 different ways to
pull out a boolean prop.

Also add the kerneldoc for the recently added new prop types, which
Rob forgot all about.

v2: Fixup kerneldoc, spotted by Rob.

Cc: Rob Clark 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_crtc.c | 66 +++---
 include/drm/drm_crtc.h |  2 ++
 2 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 071d7465043a..56e3256d5249 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -3712,7 +3712,7 @@ static struct drm_property *property_create_range(struct 
drm_device *dev,
 }

 /**
- * drm_property_create_range - create a new ranged property type
+ * drm_property_create_range - create a new unsigned ranged property type
  * @dev: drm device
  * @flags: flags specifying the property type
  * @name: name of the property
@@ -3723,8 +3723,8 @@ static struct drm_property *property_create_range(struct 
drm_device *dev,
  * object with drm_object_attach_property. The returned property object must be
  * freed with drm_property_destroy.
  *
- * Userspace is allowed to set any integer value in the (min, max) range
- * inclusive.
+ * Userspace is allowed to set any unsigned integer value in the (min, max)
+ * range inclusive.
  *
  * Returns:
  * A pointer to the newly created property on success, NULL on failure.
@@ -3738,6 +3738,24 @@ struct drm_property *drm_property_create_range(struct 
drm_device *dev, int flags
 }
 EXPORT_SYMBOL(drm_property_create_range);

+/**
+ * drm_property_create_signed_range - create a new signed ranged property type
+ * @dev: drm device
+ * @flags: flags specifying the property type
+ * @name: name of the property
+ * @min: minimum value of the property
+ * @max: maximum value of the property
+ *
+ * This creates a new generic drm property which can then be attached to a drm
+ * object with drm_object_attach_property. The returned property object must be
+ * freed with drm_property_destroy.
+ *
+ * Userspace is allowed to set any signed integer value in the (min, max)
+ * range inclusive.
+ *
+ * Returns:
+ * A pointer to the newly created property on success, NULL on failure.
+ */
 struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
 int flags, const char *name,
 int64_t min, int64_t max)
@@ -3747,6 +3765,23 @@ struct drm_property 
*drm_property_create_signed_range(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drm_property_create_signed_range);

+/**
+ * drm_property_create_object - create a new object property type
+ * @dev: drm device
+ * @flags: flags specifying the property type
+ * @name: name of the property
+ * @type: object type from DRM_MODE_OBJECT_* defines
+ *
+ * This creates a new generic drm property which can then be attached to a drm
+ * object with drm_object_attach_property. The returned property object must be
+ * freed with drm_property_destroy.
+ *
+ * Userspace is only allowed to set this to any property value of the given
+ * @type. Only useful for atomic properties, which is enforced.
+ *
+ * Returns:
+ * A pointer to the newly created property on success, NULL on failure.
+ */
 struct drm_property *drm_property_create_object(struct drm_device *dev,
 int flags, const char *name, uint32_t 
type)
 {
@@ -3754,6 +3789,9 @@ struct drm_property *drm_property_create_object(struct 
drm_device *dev,

flags |= DRM_MODE_PROP_OBJECT;

+   if (WARN_ON(!(flags & DRM_MODE_PROP_ATOMIC)))
+   return NULL;
+
property = drm_property_create(dev, flags, name, 1);
if (!property)
return NULL;
@@ -3765,6 +3803,28 @@ struct drm_property *drm_property_create_object(struct 
drm_device *dev,
 EXPORT_SYMBOL(drm_property_create_object);

 /**
+ * drm_property_create_bool - create a new boolean property type
+ * @dev: drm device
+ * @flags: flags specifying the property type
+ * @name: name of the property
+ *
+ * This creates a new generic drm property which can then be attached to a drm
+ * object with drm_object_attach_property. The returned property object must be
+ * freed with drm_property_destroy.
+ *
+ * This is implemented as a ranged property with only {0, 1} as valid values.
+ *
+ * Returns:
+ * A pointer to the newly created property on success, NULL on failure.
+ */
+struct drm_property *drm_property_create_bool(struct drm_device *dev, int 
flags,
+const char *name)
+{
+   return drm_property_create_range(dev, flags, name, 0, 1);
+}
+EXPORT_SYMBOL(drm_property_create_bool);
+
+/**
  * drm_property_add_enum - add a possible value to an enumeration property
  * @property: enumeration property to change
  * @index: index of the new enumeration