xref: /OK3568_Linux_fs/kernel/include/drm/drm_property.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2016 Intel Corporation
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission to use, copy, modify, distribute, and sell this software and its
5*4882a593Smuzhiyun  * documentation for any purpose is hereby granted without fee, provided that
6*4882a593Smuzhiyun  * the above copyright notice appear in all copies and that both that copyright
7*4882a593Smuzhiyun  * notice and this permission notice appear in supporting documentation, and
8*4882a593Smuzhiyun  * that the name of the copyright holders not be used in advertising or
9*4882a593Smuzhiyun  * publicity pertaining to distribution of the software without specific,
10*4882a593Smuzhiyun  * written prior permission.  The copyright holders make no representations
11*4882a593Smuzhiyun  * about the suitability of this software for any purpose.  It is provided "as
12*4882a593Smuzhiyun  * is" without express or implied warranty.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15*4882a593Smuzhiyun  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16*4882a593Smuzhiyun  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17*4882a593Smuzhiyun  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18*4882a593Smuzhiyun  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19*4882a593Smuzhiyun  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20*4882a593Smuzhiyun  * OF THIS SOFTWARE.
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #ifndef __DRM_PROPERTY_H__
24*4882a593Smuzhiyun #define __DRM_PROPERTY_H__
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #include <linux/list.h>
27*4882a593Smuzhiyun #include <linux/ctype.h>
28*4882a593Smuzhiyun #include <drm/drm_mode_object.h>
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #include <uapi/drm/drm_mode.h>
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun /**
33*4882a593Smuzhiyun  * struct drm_property_enum - symbolic values for enumerations
34*4882a593Smuzhiyun  * @value: numeric property value for this enum entry
35*4882a593Smuzhiyun  * @head: list of enum values, linked to &drm_property.enum_list
36*4882a593Smuzhiyun  * @name: symbolic name for the enum
37*4882a593Smuzhiyun  *
38*4882a593Smuzhiyun  * For enumeration and bitmask properties this structure stores the symbolic
39*4882a593Smuzhiyun  * decoding for each value. This is used for example for the rotation property.
40*4882a593Smuzhiyun  */
41*4882a593Smuzhiyun struct drm_property_enum {
42*4882a593Smuzhiyun 	uint64_t value;
43*4882a593Smuzhiyun 	struct list_head head;
44*4882a593Smuzhiyun 	char name[DRM_PROP_NAME_LEN];
45*4882a593Smuzhiyun };
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun /**
48*4882a593Smuzhiyun  * struct drm_property - modeset object property
49*4882a593Smuzhiyun  *
50*4882a593Smuzhiyun  * This structure represent a modeset object property. It combines both the name
51*4882a593Smuzhiyun  * of the property with the set of permissible values. This means that when a
52*4882a593Smuzhiyun  * driver wants to use a property with the same name on different objects, but
53*4882a593Smuzhiyun  * with different value ranges, then it must create property for each one. An
54*4882a593Smuzhiyun  * example would be rotation of &drm_plane, when e.g. the primary plane cannot
55*4882a593Smuzhiyun  * be rotated. But if both the name and the value range match, then the same
56*4882a593Smuzhiyun  * property structure can be instantiated multiple times for the same object.
57*4882a593Smuzhiyun  * Userspace must be able to cope with this and cannot assume that the same
58*4882a593Smuzhiyun  * symbolic property will have the same modeset object ID on all modeset
59*4882a593Smuzhiyun  * objects.
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  * Properties are created by one of the special functions, as explained in
62*4882a593Smuzhiyun  * detail in the @flags structure member.
63*4882a593Smuzhiyun  *
64*4882a593Smuzhiyun  * To actually expose a property it must be attached to each object using
65*4882a593Smuzhiyun  * drm_object_attach_property(). Currently properties can only be attached to
66*4882a593Smuzhiyun  * &drm_connector, &drm_crtc and &drm_plane.
67*4882a593Smuzhiyun  *
68*4882a593Smuzhiyun  * Properties are also used as the generic metadatatransport for the atomic
69*4882a593Smuzhiyun  * IOCTL. Everything that was set directly in structures in the legacy modeset
70*4882a593Smuzhiyun  * IOCTLs (like the plane source or destination windows, or e.g. the links to
71*4882a593Smuzhiyun  * the CRTC) is exposed as a property with the DRM_MODE_PROP_ATOMIC flag set.
72*4882a593Smuzhiyun  */
73*4882a593Smuzhiyun struct drm_property {
74*4882a593Smuzhiyun 	/**
75*4882a593Smuzhiyun 	 * @head: per-device list of properties, for cleanup.
76*4882a593Smuzhiyun 	 */
77*4882a593Smuzhiyun 	struct list_head head;
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	/**
80*4882a593Smuzhiyun 	 * @base: base KMS object
81*4882a593Smuzhiyun 	 */
82*4882a593Smuzhiyun 	struct drm_mode_object base;
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun 	/**
85*4882a593Smuzhiyun 	 * @flags:
86*4882a593Smuzhiyun 	 *
87*4882a593Smuzhiyun 	 * Property flags and type. A property needs to be one of the following
88*4882a593Smuzhiyun 	 * types:
89*4882a593Smuzhiyun 	 *
90*4882a593Smuzhiyun 	 * DRM_MODE_PROP_RANGE
91*4882a593Smuzhiyun 	 *     Range properties report their minimum and maximum admissible unsigned values.
92*4882a593Smuzhiyun 	 *     The KMS core verifies that values set by application fit in that
93*4882a593Smuzhiyun 	 *     range. The range is unsigned. Range properties are created using
94*4882a593Smuzhiyun 	 *     drm_property_create_range().
95*4882a593Smuzhiyun 	 *
96*4882a593Smuzhiyun 	 * DRM_MODE_PROP_SIGNED_RANGE
97*4882a593Smuzhiyun 	 *     Range properties report their minimum and maximum admissible unsigned values.
98*4882a593Smuzhiyun 	 *     The KMS core verifies that values set by application fit in that
99*4882a593Smuzhiyun 	 *     range. The range is signed. Range properties are created using
100*4882a593Smuzhiyun 	 *     drm_property_create_signed_range().
101*4882a593Smuzhiyun 	 *
102*4882a593Smuzhiyun 	 * DRM_MODE_PROP_ENUM
103*4882a593Smuzhiyun 	 *     Enumerated properties take a numerical value that ranges from 0 to
104*4882a593Smuzhiyun 	 *     the number of enumerated values defined by the property minus one,
105*4882a593Smuzhiyun 	 *     and associate a free-formed string name to each value. Applications
106*4882a593Smuzhiyun 	 *     can retrieve the list of defined value-name pairs and use the
107*4882a593Smuzhiyun 	 *     numerical value to get and set property instance values. Enum
108*4882a593Smuzhiyun 	 *     properties are created using drm_property_create_enum().
109*4882a593Smuzhiyun 	 *
110*4882a593Smuzhiyun 	 * DRM_MODE_PROP_BITMASK
111*4882a593Smuzhiyun 	 *     Bitmask properties are enumeration properties that additionally
112*4882a593Smuzhiyun 	 *     restrict all enumerated values to the 0..63 range. Bitmask property
113*4882a593Smuzhiyun 	 *     instance values combine one or more of the enumerated bits defined
114*4882a593Smuzhiyun 	 *     by the property. Bitmask properties are created using
115*4882a593Smuzhiyun 	 *     drm_property_create_bitmask().
116*4882a593Smuzhiyun 	 *
117*4882a593Smuzhiyun 	 * DRM_MODE_PROB_OBJECT
118*4882a593Smuzhiyun 	 *     Object properties are used to link modeset objects. This is used
119*4882a593Smuzhiyun 	 *     extensively in the atomic support to create the display pipeline,
120*4882a593Smuzhiyun 	 *     by linking &drm_framebuffer to &drm_plane, &drm_plane to
121*4882a593Smuzhiyun 	 *     &drm_crtc and &drm_connector to &drm_crtc. An object property can
122*4882a593Smuzhiyun 	 *     only link to a specific type of &drm_mode_object, this limit is
123*4882a593Smuzhiyun 	 *     enforced by the core. Object properties are created using
124*4882a593Smuzhiyun 	 *     drm_property_create_object().
125*4882a593Smuzhiyun 	 *
126*4882a593Smuzhiyun 	 *     Object properties work like blob properties, but in a more
127*4882a593Smuzhiyun 	 *     general fashion. They are limited to atomic drivers and must have
128*4882a593Smuzhiyun 	 *     the DRM_MODE_PROP_ATOMIC flag set.
129*4882a593Smuzhiyun 	 *
130*4882a593Smuzhiyun 	 * DRM_MODE_PROP_BLOB
131*4882a593Smuzhiyun 	 *     Blob properties store a binary blob without any format restriction.
132*4882a593Smuzhiyun 	 *     The binary blobs are created as KMS standalone objects, and blob
133*4882a593Smuzhiyun 	 *     property instance values store the ID of their associated blob
134*4882a593Smuzhiyun 	 *     object. Blob properties are created by calling
135*4882a593Smuzhiyun 	 *     drm_property_create() with DRM_MODE_PROP_BLOB as the type.
136*4882a593Smuzhiyun 	 *
137*4882a593Smuzhiyun 	 *     Actual blob objects to contain blob data are created using
138*4882a593Smuzhiyun 	 *     drm_property_create_blob(), or through the corresponding IOCTL.
139*4882a593Smuzhiyun 	 *
140*4882a593Smuzhiyun 	 *     Besides the built-in limit to only accept blob objects blob
141*4882a593Smuzhiyun 	 *     properties work exactly like object properties. The only reasons
142*4882a593Smuzhiyun 	 *     blob properties exist is backwards compatibility with existing
143*4882a593Smuzhiyun 	 *     userspace.
144*4882a593Smuzhiyun 	 *
145*4882a593Smuzhiyun 	 * In addition a property can have any combination of the below flags:
146*4882a593Smuzhiyun 	 *
147*4882a593Smuzhiyun 	 * DRM_MODE_PROP_ATOMIC
148*4882a593Smuzhiyun 	 *     Set for properties which encode atomic modeset state. Such
149*4882a593Smuzhiyun 	 *     properties are not exposed to legacy userspace.
150*4882a593Smuzhiyun 	 *
151*4882a593Smuzhiyun 	 * DRM_MODE_PROP_IMMUTABLE
152*4882a593Smuzhiyun 	 *     Set for properties whose values cannot be changed by
153*4882a593Smuzhiyun 	 *     userspace. The kernel is allowed to update the value of these
154*4882a593Smuzhiyun 	 *     properties. This is generally used to expose probe state to
155*4882a593Smuzhiyun 	 *     userspace, e.g. the EDID, or the connector path property on DP
156*4882a593Smuzhiyun 	 *     MST sinks. Kernel can update the value of an immutable property
157*4882a593Smuzhiyun 	 *     by calling drm_object_property_set_value().
158*4882a593Smuzhiyun 	 */
159*4882a593Smuzhiyun 	uint32_t flags;
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 	/**
162*4882a593Smuzhiyun 	 * @name: symbolic name of the properties
163*4882a593Smuzhiyun 	 */
164*4882a593Smuzhiyun 	char name[DRM_PROP_NAME_LEN];
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun 	/**
167*4882a593Smuzhiyun 	 * @num_values: size of the @values array.
168*4882a593Smuzhiyun 	 */
169*4882a593Smuzhiyun 	uint32_t num_values;
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	/**
172*4882a593Smuzhiyun 	 * @values:
173*4882a593Smuzhiyun 	 *
174*4882a593Smuzhiyun 	 * Array with limits and values for the property. The
175*4882a593Smuzhiyun 	 * interpretation of these limits is dependent upon the type per @flags.
176*4882a593Smuzhiyun 	 */
177*4882a593Smuzhiyun 	uint64_t *values;
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun 	/**
180*4882a593Smuzhiyun 	 * @dev: DRM device
181*4882a593Smuzhiyun 	 */
182*4882a593Smuzhiyun 	struct drm_device *dev;
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun 	/**
185*4882a593Smuzhiyun 	 * @enum_list:
186*4882a593Smuzhiyun 	 *
187*4882a593Smuzhiyun 	 * List of &drm_prop_enum_list structures with the symbolic names for
188*4882a593Smuzhiyun 	 * enum and bitmask values.
189*4882a593Smuzhiyun 	 */
190*4882a593Smuzhiyun 	struct list_head enum_list;
191*4882a593Smuzhiyun };
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun /**
194*4882a593Smuzhiyun  * struct drm_property_blob - Blob data for &drm_property
195*4882a593Smuzhiyun  * @base: base KMS object
196*4882a593Smuzhiyun  * @dev: DRM device
197*4882a593Smuzhiyun  * @head_global: entry on the global blob list in
198*4882a593Smuzhiyun  * 	&drm_mode_config.property_blob_list.
199*4882a593Smuzhiyun  * @head_file: entry on the per-file blob list in &drm_file.blobs list.
200*4882a593Smuzhiyun  * @length: size of the blob in bytes, invariant over the lifetime of the object
201*4882a593Smuzhiyun  * @data: actual data, embedded at the end of this structure
202*4882a593Smuzhiyun  *
203*4882a593Smuzhiyun  * Blobs are used to store bigger values than what fits directly into the 64
204*4882a593Smuzhiyun  * bits available for a &drm_property.
205*4882a593Smuzhiyun  *
206*4882a593Smuzhiyun  * Blobs are reference counted using drm_property_blob_get() and
207*4882a593Smuzhiyun  * drm_property_blob_put(). They are created using drm_property_create_blob().
208*4882a593Smuzhiyun  */
209*4882a593Smuzhiyun struct drm_property_blob {
210*4882a593Smuzhiyun 	struct drm_mode_object base;
211*4882a593Smuzhiyun 	struct drm_device *dev;
212*4882a593Smuzhiyun 	struct list_head head_global;
213*4882a593Smuzhiyun 	struct list_head head_file;
214*4882a593Smuzhiyun 	size_t length;
215*4882a593Smuzhiyun 	void *data;
216*4882a593Smuzhiyun };
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun struct drm_prop_enum_list {
219*4882a593Smuzhiyun 	int type;
220*4882a593Smuzhiyun 	const char *name;
221*4882a593Smuzhiyun };
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun #define obj_to_property(x) container_of(x, struct drm_property, base)
224*4882a593Smuzhiyun #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun /**
227*4882a593Smuzhiyun  * drm_property_type_is - check the type of a property
228*4882a593Smuzhiyun  * @property: property to check
229*4882a593Smuzhiyun  * @type: property type to compare with
230*4882a593Smuzhiyun  *
231*4882a593Smuzhiyun  * This is a helper function becauase the uapi encoding of property types is
232*4882a593Smuzhiyun  * a bit special for historical reasons.
233*4882a593Smuzhiyun  */
drm_property_type_is(struct drm_property * property,uint32_t type)234*4882a593Smuzhiyun static inline bool drm_property_type_is(struct drm_property *property,
235*4882a593Smuzhiyun 					uint32_t type)
236*4882a593Smuzhiyun {
237*4882a593Smuzhiyun 	/* instanceof for props.. handles extended type vs original types: */
238*4882a593Smuzhiyun 	if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
239*4882a593Smuzhiyun 		return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
240*4882a593Smuzhiyun 	return property->flags & type;
241*4882a593Smuzhiyun }
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun struct drm_property *drm_property_create(struct drm_device *dev,
244*4882a593Smuzhiyun 					 u32 flags, const char *name,
245*4882a593Smuzhiyun 					 int num_values);
246*4882a593Smuzhiyun struct drm_property *drm_property_create_enum(struct drm_device *dev,
247*4882a593Smuzhiyun 					      u32 flags, const char *name,
248*4882a593Smuzhiyun 					      const struct drm_prop_enum_list *props,
249*4882a593Smuzhiyun 					      int num_values);
250*4882a593Smuzhiyun struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
251*4882a593Smuzhiyun 						 u32 flags, const char *name,
252*4882a593Smuzhiyun 						 const struct drm_prop_enum_list *props,
253*4882a593Smuzhiyun 						 int num_props,
254*4882a593Smuzhiyun 						 uint64_t supported_bits);
255*4882a593Smuzhiyun struct drm_property *drm_property_create_range(struct drm_device *dev,
256*4882a593Smuzhiyun 					       u32 flags, const char *name,
257*4882a593Smuzhiyun 					       uint64_t min, uint64_t max);
258*4882a593Smuzhiyun struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
259*4882a593Smuzhiyun 						      u32 flags, const char *name,
260*4882a593Smuzhiyun 						      int64_t min, int64_t max);
261*4882a593Smuzhiyun struct drm_property *drm_property_create_object(struct drm_device *dev,
262*4882a593Smuzhiyun 						u32 flags, const char *name,
263*4882a593Smuzhiyun 						uint32_t type);
264*4882a593Smuzhiyun struct drm_property *drm_property_create_bool(struct drm_device *dev,
265*4882a593Smuzhiyun 					      u32 flags, const char *name);
266*4882a593Smuzhiyun int drm_property_add_enum(struct drm_property *property,
267*4882a593Smuzhiyun 			  uint64_t value, const char *name);
268*4882a593Smuzhiyun void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
269*4882a593Smuzhiyun 
270*4882a593Smuzhiyun struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
271*4882a593Smuzhiyun 						   size_t length,
272*4882a593Smuzhiyun 						   const void *data);
273*4882a593Smuzhiyun struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
274*4882a593Smuzhiyun 						   uint32_t id);
275*4882a593Smuzhiyun int drm_property_replace_global_blob(struct drm_device *dev,
276*4882a593Smuzhiyun 				     struct drm_property_blob **replace,
277*4882a593Smuzhiyun 				     size_t length,
278*4882a593Smuzhiyun 				     const void *data,
279*4882a593Smuzhiyun 				     struct drm_mode_object *obj_holds_id,
280*4882a593Smuzhiyun 				     struct drm_property *prop_holds_id);
281*4882a593Smuzhiyun bool drm_property_replace_blob(struct drm_property_blob **blob,
282*4882a593Smuzhiyun 			       struct drm_property_blob *new_blob);
283*4882a593Smuzhiyun struct drm_property_blob *drm_property_blob_get(struct drm_property_blob *blob);
284*4882a593Smuzhiyun void drm_property_blob_put(struct drm_property_blob *blob);
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun /**
287*4882a593Smuzhiyun  * drm_property_find - find property object
288*4882a593Smuzhiyun  * @dev: DRM device
289*4882a593Smuzhiyun  * @file_priv: drm file to check for lease against.
290*4882a593Smuzhiyun  * @id: property object id
291*4882a593Smuzhiyun  *
292*4882a593Smuzhiyun  * This function looks up the property object specified by id and returns it.
293*4882a593Smuzhiyun  */
drm_property_find(struct drm_device * dev,struct drm_file * file_priv,uint32_t id)294*4882a593Smuzhiyun static inline struct drm_property *drm_property_find(struct drm_device *dev,
295*4882a593Smuzhiyun 						     struct drm_file *file_priv,
296*4882a593Smuzhiyun 						     uint32_t id)
297*4882a593Smuzhiyun {
298*4882a593Smuzhiyun 	struct drm_mode_object *mo;
299*4882a593Smuzhiyun 	mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_PROPERTY);
300*4882a593Smuzhiyun 	return mo ? obj_to_property(mo) : NULL;
301*4882a593Smuzhiyun }
302*4882a593Smuzhiyun 
303*4882a593Smuzhiyun #endif
304