1 From e458f351c7af35775528575611cb9b8f12ef6775 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Mon, 21 Feb 2022 10:59:02 +0100
4 Subject: [PATCH] drm/object: Add
5 drm_object_property_get_default_value() function
7 Upstream commit adf47b75297ebc71c53b6dc2d3c55f42b8fb79fd.
9 Some functions to create properties (drm_plane_create_zpos_property or
10 drm_plane_create_color_properties for example) will ask for a range of
11 acceptable value and an initial one.
13 This initial value is then stored in the values array for that property.
15 Let's provide an helper to access this property.
17 Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
18 Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
19 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
20 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
21 Link: https://patchwork.freedesktop.org/patch/msgid/20220221095918.18763-7-maxime@cerno.tech
23 drivers/gpu/drm/drm_mode_object.c | 53 +++++++++++++++++++++++++------
24 include/drm/drm_mode_object.h | 7 ++++
25 2 files changed, 50 insertions(+), 10 deletions(-)
27 --- a/drivers/gpu/drm/drm_mode_object.c
28 +++ b/drivers/gpu/drm/drm_mode_object.c
29 @@ -297,11 +297,26 @@ int drm_object_property_set_value(struct
31 EXPORT_SYMBOL(drm_object_property_set_value);
33 +static int __drm_object_property_get_prop_value(struct drm_mode_object *obj,
34 + struct drm_property *property,
39 + for (i = 0; i < obj->properties->count; i++) {
40 + if (obj->properties->properties[i] == property) {
41 + *val = obj->properties->values[i];
49 static int __drm_object_property_get_value(struct drm_mode_object *obj,
50 struct drm_property *property,
55 /* read-only properties bypass atomic mechanism and still store
56 * their value in obj->properties->values[].. mostly to avoid
57 @@ -311,15 +326,7 @@ static int __drm_object_property_get_val
58 !(property->flags & DRM_MODE_PROP_IMMUTABLE))
59 return drm_atomic_get_property(obj, property, val);
61 - for (i = 0; i < obj->properties->count; i++) {
62 - if (obj->properties->properties[i] == property) {
63 - *val = obj->properties->values[i];
70 + return __drm_object_property_get_prop_value(obj, property, val);
74 @@ -348,6 +355,32 @@ int drm_object_property_get_value(struct
76 EXPORT_SYMBOL(drm_object_property_get_value);
79 + * drm_object_property_get_default_value - retrieve the default value of a
80 + * property when in atomic mode.
81 + * @obj: drm mode object to get property value from
82 + * @property: property to retrieve
83 + * @val: storage for the property value
85 + * This function retrieves the default state of the given property as passed in
86 + * to drm_object_attach_property
88 + * Only atomic drivers should call this function directly, as for non-atomic
89 + * drivers it will return the current value.
92 + * Zero on success, error code on failure.
94 +int drm_object_property_get_default_value(struct drm_mode_object *obj,
95 + struct drm_property *property,
98 + WARN_ON(!drm_drv_uses_atomic_modeset(property->dev));
100 + return __drm_object_property_get_prop_value(obj, property, val);
102 +EXPORT_SYMBOL(drm_object_property_get_default_value);
104 /* helper for getconnector and getproperties ioctls */
105 int drm_mode_object_get_properties(struct drm_mode_object *obj, bool atomic,
106 uint32_t __user *prop_ptr,
107 --- a/include/drm/drm_mode_object.h
108 +++ b/include/drm/drm_mode_object.h
109 @@ -98,6 +98,10 @@ struct drm_object_properties {
110 * Hence atomic drivers should not use drm_object_property_set_value()
111 * and drm_object_property_get_value() on mutable objects, i.e. those
112 * without the DRM_MODE_PROP_IMMUTABLE flag set.
114 + * For atomic drivers the default value of properties is stored in this
115 + * array, so drm_object_property_get_default_value can be used to
118 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
120 @@ -126,6 +130,9 @@ int drm_object_property_set_value(struct
121 int drm_object_property_get_value(struct drm_mode_object *obj,
122 struct drm_property *property,
124 +int drm_object_property_get_default_value(struct drm_mode_object *obj,
125 + struct drm_property *property,
128 void drm_object_attach_property(struct drm_mode_object *obj,
129 struct drm_property *property,