msm_prop.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _MSM_PROP_H_
  6. #define _MSM_PROP_H_
  7. #include <linux/list.h>
  8. #include "msm_drv.h"
  9. #define MSM_PROP_STATE_CACHE_SIZE 2
  10. /**
  11. * struct msm_property_data - opaque structure for tracking per
  12. * drm-object per property stuff
  13. * @default_value: Default property value for this drm object
  14. * @force_dirty: Always dirty property on incoming sets, rather than checking
  15. * for modified values
  16. */
  17. struct msm_property_data {
  18. uint64_t default_value;
  19. bool force_dirty;
  20. };
  21. /**
  22. * struct msm_property_value - opaque structure for tracking per
  23. * drm-object per property stuff
  24. * @value: Current property value for this drm object
  25. * @blob: Pointer to associated blob data, if available
  26. * @dirty_node: Linked list node to track if property is dirty or not
  27. */
  28. struct msm_property_value {
  29. uint64_t value;
  30. struct drm_property_blob *blob;
  31. struct list_head dirty_node;
  32. };
  33. /**
  34. * struct msm_property_info: Structure for property/state helper functions
  35. * @base: Pointer to base drm object (plane/crtc/etc.)
  36. * @dev: Pointer to drm device object
  37. * @property_array: Pointer to array for storing created property objects
  38. * @property_data: Pointer to array for storing private property data
  39. * @property_count: Total number of properties
  40. * @blob_count: Total number of blob properties, should be <= count
  41. * @install_request: Total number of property 'install' requests
  42. * @install_count: Total number of successful 'install' requests
  43. * @recent_idx: Index of property most recently accessed by set/get
  44. * @is_active: Whether or not drm component properties are 'active'
  45. * @state_cache: Cache of local states, to prevent alloc/free thrashing
  46. * @state_size: Size of local state structures
  47. * @state_cache_size: Number of state structures currently stored in state_cache
  48. * @property_lock: Mutex to protect local variables
  49. */
  50. struct msm_property_info {
  51. struct drm_mode_object *base;
  52. struct drm_device *dev;
  53. struct drm_property **property_array;
  54. struct msm_property_data *property_data;
  55. uint32_t property_count;
  56. uint32_t blob_count;
  57. uint32_t install_request;
  58. uint32_t install_count;
  59. int32_t recent_idx;
  60. bool is_active;
  61. void *state_cache[MSM_PROP_STATE_CACHE_SIZE];
  62. uint32_t state_size;
  63. int32_t state_cache_size;
  64. struct mutex property_lock;
  65. };
  66. /**
  67. * struct msm_property_state - Structure for local property state information
  68. * @property_count: Total number of properties
  69. * @values: Pointer to array of msm_property_value objects
  70. * @dirty_list: List of all properties that have been 'atomic_set' but not
  71. * yet cleared with 'msm_property_pop_dirty'
  72. */
  73. struct msm_property_state {
  74. uint32_t property_count;
  75. struct msm_property_value *values;
  76. struct list_head dirty_list;
  77. };
  78. /**
  79. * msm_property_index_to_drm_property - get drm property struct from prop index
  80. * @info: Pointer to property info container struct
  81. * @property_idx: Property index
  82. * Returns: drm_property pointer associated with property index
  83. */
  84. static inline
  85. struct drm_property *msm_property_index_to_drm_property(
  86. struct msm_property_info *info, uint32_t property_idx)
  87. {
  88. if (!info || property_idx >= info->property_count)
  89. return NULL;
  90. return info->property_array[property_idx];
  91. }
  92. /**
  93. * msm_property_get_default - query default value of a property
  94. * @info: Pointer to property info container struct
  95. * @property_idx: Property index
  96. * Returns: Default value for specified property
  97. */
  98. static inline
  99. uint64_t msm_property_get_default(struct msm_property_info *info,
  100. uint32_t property_idx)
  101. {
  102. uint64_t rc = 0;
  103. if (!info)
  104. return 0;
  105. mutex_lock(&info->property_lock);
  106. if (property_idx < info->property_count)
  107. rc = info->property_data[property_idx].default_value;
  108. mutex_unlock(&info->property_lock);
  109. return rc;
  110. }
  111. /**
  112. * msm_property_set_is_active - set overall 'active' status for all properties
  113. * @info: Pointer to property info container struct
  114. * @is_active: New 'is active' status
  115. */
  116. static inline
  117. void msm_property_set_is_active(struct msm_property_info *info, bool is_active)
  118. {
  119. if (info) {
  120. mutex_lock(&info->property_lock);
  121. info->is_active = is_active;
  122. mutex_unlock(&info->property_lock);
  123. }
  124. }
  125. /**
  126. * msm_property_get_is_active - query property 'is active' status
  127. * @info: Pointer to property info container struct
  128. * Returns: Current 'is active's status
  129. */
  130. static inline
  131. bool msm_property_get_is_active(struct msm_property_info *info)
  132. {
  133. bool rc = false;
  134. if (info) {
  135. mutex_lock(&info->property_lock);
  136. rc = info->is_active;
  137. mutex_unlock(&info->property_lock);
  138. }
  139. return rc;
  140. }
  141. /**
  142. * msm_property_pop_dirty - determine next dirty property and clear
  143. * its dirty flag
  144. * @info: Pointer to property info container struct
  145. * @property_state: Pointer to property state container struct
  146. * Returns: Valid msm property index on success,
  147. * -EAGAIN if no dirty properties are available
  148. * Property indicies returned from this function are similar
  149. * to those returned by the msm_property_index function.
  150. */
  151. int msm_property_pop_dirty(struct msm_property_info *info,
  152. struct msm_property_state *property_state);
  153. /**
  154. * msm_property_init - initialize property info structure
  155. * @info: Pointer to property info container struct
  156. * @base: Pointer to base drm object (plane/crtc/etc.)
  157. * @dev: Pointer to drm device object
  158. * @property_array: Pointer to array for storing created property objects
  159. * @property_data: Pointer to array for storing private property data
  160. * @property_count: Total number of properties
  161. * @blob_count: Total number of blob properties, should be <= count
  162. * @state_size: Size of local state object
  163. */
  164. void msm_property_init(struct msm_property_info *info,
  165. struct drm_mode_object *base,
  166. struct drm_device *dev,
  167. struct drm_property **property_array,
  168. struct msm_property_data *property_data,
  169. uint32_t property_count,
  170. uint32_t blob_count,
  171. uint32_t state_size);
  172. /**
  173. * msm_property_destroy - destroy helper info structure
  174. *
  175. * @info: Pointer to property info container struct
  176. */
  177. void msm_property_destroy(struct msm_property_info *info);
  178. /**
  179. * msm_property_install_range - install standard drm range property
  180. * @info: Pointer to property info container struct
  181. * @name: Property name
  182. * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
  183. * @min: Min property value
  184. * @max: Max property value
  185. * @init: Default Property value
  186. * @property_idx: Property index
  187. */
  188. void msm_property_install_range(struct msm_property_info *info,
  189. const char *name,
  190. int flags,
  191. uint64_t min,
  192. uint64_t max,
  193. uint64_t init,
  194. uint32_t property_idx);
  195. /**
  196. * msm_property_install_volatile_range - install drm range property
  197. * This function is similar to msm_property_install_range, but assumes
  198. * that the property is meant for holding user pointers or descriptors
  199. * that may reference volatile data without having an updated value.
  200. * @info: Pointer to property info container struct
  201. * @name: Property name
  202. * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
  203. * @min: Min property value
  204. * @max: Max property value
  205. * @init: Default Property value
  206. * @property_idx: Property index
  207. */
  208. void msm_property_install_volatile_range(struct msm_property_info *info,
  209. const char *name,
  210. int flags,
  211. uint64_t min,
  212. uint64_t max,
  213. uint64_t init,
  214. uint32_t property_idx);
  215. /**
  216. * msm_property_install_enum - install standard drm enum/bitmask property
  217. * @info: Pointer to property info container struct
  218. * @name: Property name
  219. * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
  220. * @is_bitmask: Set to non-zero to create a bitmask property, rather than an
  221. * enumeration one
  222. * @values: Array of allowable enumeration/bitmask values
  223. * @num_values: Size of values array
  224. * @property_idx: Property index
  225. */
  226. void msm_property_install_enum(struct msm_property_info *info,
  227. const char *name,
  228. int flags,
  229. int is_bitmask,
  230. const struct drm_prop_enum_list *values,
  231. int num_values,
  232. uint32_t property_idx);
  233. /**
  234. * msm_property_install_blob - install standard drm blob property
  235. * @info: Pointer to property info container struct
  236. * @name: Property name
  237. * @flags: Extra flags for property creation
  238. * @property_idx: Property index
  239. */
  240. void msm_property_install_blob(struct msm_property_info *info,
  241. const char *name,
  242. int flags,
  243. uint32_t property_idx);
  244. /**
  245. * msm_property_install_get_status - query overal status of property additions
  246. * @info: Pointer to property info container struct
  247. * Returns: Zero if previous property install calls were all successful
  248. */
  249. int msm_property_install_get_status(struct msm_property_info *info);
  250. /**
  251. * msm_property_index - determine property index from drm_property ptr
  252. * @info: Pointer to property info container struct
  253. * @property: Incoming property pointer
  254. * Returns: Valid property index, or -EINVAL on error
  255. */
  256. int msm_property_index(struct msm_property_info *info,
  257. struct drm_property *property);
  258. /**
  259. * msm_property_set_dirty - forcibly flag a property as dirty
  260. * @info: Pointer to property info container struct
  261. * @property_state: Pointer to property state container struct
  262. * @property_idx: Property index
  263. * Returns: Zero on success
  264. */
  265. int msm_property_set_dirty(struct msm_property_info *info,
  266. struct msm_property_state *property_state,
  267. int property_idx);
  268. /**
  269. * msm_property_is_dirty - check whether a property is dirty
  270. * Note: Intended for use during atomic_check before pop_dirty usage
  271. * @info: Pointer to property info container struct
  272. * @property_state: Pointer to property state container struct
  273. * @property_idx: Property index
  274. * Returns: true if dirty, false otherwise
  275. */
  276. bool msm_property_is_dirty(
  277. struct msm_property_info *info,
  278. struct msm_property_state *property_state,
  279. uint32_t property_idx);
  280. /**
  281. * msm_property_atomic_set - helper function for atomic property set callback
  282. * @info: Pointer to property info container struct
  283. * @property_state: Pointer to local state structure
  284. * @property: Incoming property pointer
  285. * @val: Incoming property value
  286. * Returns: Zero on success
  287. */
  288. int msm_property_atomic_set(struct msm_property_info *info,
  289. struct msm_property_state *property_state,
  290. struct drm_property *property,
  291. uint64_t val);
  292. /**
  293. * msm_property_atomic_get - helper function for atomic property get callback
  294. * @info: Pointer to property info container struct
  295. * @property_state: Pointer to local state structure
  296. * @property: Incoming property pointer
  297. * @val: Pointer to variable for receiving property value
  298. * Returns: Zero on success
  299. */
  300. int msm_property_atomic_get(struct msm_property_info *info,
  301. struct msm_property_state *property_state,
  302. struct drm_property *property,
  303. uint64_t *val);
  304. /**
  305. * msm_property_alloc_state - helper function for allocating local state objects
  306. * @info: Pointer to property info container struct
  307. */
  308. void *msm_property_alloc_state(struct msm_property_info *info);
  309. /**
  310. * msm_property_reset_state - helper function for state reset callback
  311. * @info: Pointer to property info container struct
  312. * @state: Pointer to local state structure
  313. * @property_state: Pointer to property state container struct
  314. * @property_values: Pointer to property values cache array
  315. */
  316. void msm_property_reset_state(struct msm_property_info *info, void *state,
  317. struct msm_property_state *property_state,
  318. struct msm_property_value *property_values);
  319. /**
  320. * msm_property_duplicate_state - helper function for duplicate state cb
  321. * @info: Pointer to property info container struct
  322. * @old_state: Pointer to original state structure
  323. * @state: Pointer to newly created state structure
  324. * @property_state: Pointer to destination property state container struct
  325. * @property_values: Pointer to property values cache array
  326. */
  327. void msm_property_duplicate_state(struct msm_property_info *info,
  328. void *old_state,
  329. void *state,
  330. struct msm_property_state *property_state,
  331. struct msm_property_value *property_values);
  332. /**
  333. * msm_property_destroy_state - helper function for destroy state cb
  334. * @info: Pointer to property info container struct
  335. * @state: Pointer to local state structure
  336. * @property_state: Pointer to property state container struct
  337. */
  338. void msm_property_destroy_state(struct msm_property_info *info,
  339. void *state,
  340. struct msm_property_state *property_state);
  341. /**
  342. * msm_property_get_blob - obtain cached data pointer for drm blob property
  343. * @info: Pointer to property info container struct
  344. * @property_state: Pointer to property state container struct
  345. * @byte_len: Optional pointer to variable for accepting blob size
  346. * @property_idx: Property index
  347. * Returns: Pointer to blob data
  348. */
  349. void *msm_property_get_blob(struct msm_property_info *info,
  350. struct msm_property_state *property_state,
  351. size_t *byte_len,
  352. uint32_t property_idx);
  353. /**
  354. * msm_property_set_blob - update blob property on a drm object
  355. * This function updates the blob property value of the given drm object. Its
  356. * intended use is to update blob properties that have been created with the
  357. * DRM_MODE_PROP_IMMUTABLE flag set.
  358. * @info: Pointer to property info container struct
  359. * @blob_reference: Reference to a pointer that holds the created data blob
  360. * @blob_data: Pointer to blob data
  361. * @byte_len: Length of blob data, in bytes
  362. * @property_idx: Property index
  363. * Returns: Zero on success
  364. */
  365. int msm_property_set_blob(struct msm_property_info *info,
  366. struct drm_property_blob **blob_reference,
  367. void *blob_data,
  368. size_t byte_len,
  369. uint32_t property_idx);
  370. /**
  371. * msm_property_set_property - update property on a drm object
  372. * This function updates the property value of the given drm object. Its
  373. * intended use is to update properties that have been created with the
  374. * DRM_MODE_PROP_IMMUTABLE flag set.
  375. * Note: This function cannot be called on a blob.
  376. * @info: Pointer to property info container struct
  377. * @property_state: Pointer to property state container struct
  378. * @property_idx: Property index
  379. * @val: value of the property to set
  380. * Returns: Zero on success
  381. */
  382. int msm_property_set_property(struct msm_property_info *info,
  383. struct msm_property_state *property_state,
  384. uint32_t property_idx,
  385. uint64_t val);
  386. #endif /* _MSM_PROP_H_ */