8e7844e057f89f3a5fb8a5e55bd9d49deefdbd29
[openwrt/staging/neocturne.git] /
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
6
7 Upstream commit adf47b75297ebc71c53b6dc2d3c55f42b8fb79fd.
8
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.
12
13 This initial value is then stored in the values array for that property.
14
15 Let's provide an helper to access this property.
16
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
22 ---
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(-)
26
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
30 }
31 EXPORT_SYMBOL(drm_object_property_set_value);
32
33 +static int __drm_object_property_get_prop_value(struct drm_mode_object *obj,
34 + struct drm_property *property,
35 + uint64_t *val)
36 +{
37 + int i;
38 +
39 + for (i = 0; i < obj->properties->count; i++) {
40 + if (obj->properties->properties[i] == property) {
41 + *val = obj->properties->values[i];
42 + return 0;
43 + }
44 + }
45 +
46 + return -EINVAL;
47 +}
48 +
49 static int __drm_object_property_get_value(struct drm_mode_object *obj,
50 struct drm_property *property,
51 uint64_t *val)
52 {
53 - int i;
54
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);
60
61 - for (i = 0; i < obj->properties->count; i++) {
62 - if (obj->properties->properties[i] == property) {
63 - *val = obj->properties->values[i];
64 - return 0;
65 - }
66 -
67 - }
68 -
69 - return -EINVAL;
70 + return __drm_object_property_get_prop_value(obj, property, val);
71 }
72
73 /**
74 @@ -348,6 +355,32 @@ int drm_object_property_get_value(struct
75 }
76 EXPORT_SYMBOL(drm_object_property_get_value);
77
78 +/**
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
84 + *
85 + * This function retrieves the default state of the given property as passed in
86 + * to drm_object_attach_property
87 + *
88 + * Only atomic drivers should call this function directly, as for non-atomic
89 + * drivers it will return the current value.
90 + *
91 + * Returns:
92 + * Zero on success, error code on failure.
93 + */
94 +int drm_object_property_get_default_value(struct drm_mode_object *obj,
95 + struct drm_property *property,
96 + uint64_t *val)
97 +{
98 + WARN_ON(!drm_drv_uses_atomic_modeset(property->dev));
99 +
100 + return __drm_object_property_get_prop_value(obj, property, val);
101 +}
102 +EXPORT_SYMBOL(drm_object_property_get_default_value);
103 +
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.
113 + *
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
116 + * retrieve it.
117 */
118 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
119 };
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,
123 uint64_t *value);
124 +int drm_object_property_get_default_value(struct drm_mode_object *obj,
125 + struct drm_property *property,
126 + uint64_t *val);
127
128 void drm_object_attach_property(struct drm_mode_object *obj,
129 struct drm_property *property,