drm_property.h 11 KB

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