msm_prop.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2020, 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. Caller needs to acquire property
  144. * lock before calling this function and release
  145. * the lock when finished.
  146. * @info: Pointer to property info container struct
  147. * @property_state: Pointer to property state container struct
  148. * Returns: Valid msm property index on success,
  149. * -EAGAIN if no dirty properties are available
  150. * Property indicies returned from this function are similar
  151. * to those returned by the msm_property_index function.
  152. */
  153. int msm_property_pop_dirty(struct msm_property_info *info,
  154. struct msm_property_state *property_state);
  155. /**
  156. * msm_property_init - initialize property info structure
  157. * @info: Pointer to property info container struct
  158. * @base: Pointer to base drm object (plane/crtc/etc.)
  159. * @dev: Pointer to drm device object
  160. * @property_array: Pointer to array for storing created property objects
  161. * @property_data: Pointer to array for storing private property data
  162. * @property_count: Total number of properties
  163. * @blob_count: Total number of blob properties, should be <= count
  164. * @state_size: Size of local state object
  165. */
  166. void msm_property_init(struct msm_property_info *info,
  167. struct drm_mode_object *base,
  168. struct drm_device *dev,
  169. struct drm_property **property_array,
  170. struct msm_property_data *property_data,
  171. uint32_t property_count,
  172. uint32_t blob_count,
  173. uint32_t state_size);
  174. /**
  175. * msm_property_destroy - destroy helper info structure
  176. *
  177. * @info: Pointer to property info container struct
  178. */
  179. void msm_property_destroy(struct msm_property_info *info);
  180. /**
  181. * msm_property_install_range - install standard drm range property
  182. * @info: Pointer to property info container struct
  183. * @name: Property name
  184. * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
  185. * @min: Min property value
  186. * @max: Max property value
  187. * @init: Default Property value
  188. * @property_idx: Property index
  189. */
  190. void msm_property_install_range(struct msm_property_info *info,
  191. const char *name,
  192. int flags,
  193. uint64_t min,
  194. uint64_t max,
  195. uint64_t init,
  196. uint32_t property_idx);
  197. /**
  198. * msm_property_install_volatile_range - install drm range property
  199. * This function is similar to msm_property_install_range, but assumes
  200. * that the property is meant for holding user pointers or descriptors
  201. * that may reference volatile data without having an updated value.
  202. * @info: Pointer to property info container struct
  203. * @name: Property name
  204. * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
  205. * @min: Min property value
  206. * @max: Max property value
  207. * @init: Default Property value
  208. * @property_idx: Property index
  209. */
  210. void msm_property_install_volatile_range(struct msm_property_info *info,
  211. const char *name,
  212. int flags,
  213. uint64_t min,
  214. uint64_t max,
  215. uint64_t init,
  216. uint32_t property_idx);
  217. /**
  218. * msm_property_install_enum - install standard drm enum/bitmask property
  219. * @info: Pointer to property info container struct
  220. * @name: Property name
  221. * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
  222. * @is_bitmask: Set to non-zero to create a bitmask property, rather than an
  223. * enumeration one
  224. * @values: Array of allowable enumeration/bitmask values
  225. * @num_values: Size of values array
  226. * @init_idx: index of the values array entry to initialize the property
  227. * @property_idx: Property index
  228. */
  229. void msm_property_install_enum(struct msm_property_info *info,
  230. const char *name,
  231. int flags,
  232. int is_bitmask,
  233. const struct drm_prop_enum_list *values,
  234. int num_values,
  235. u32 init_idx,
  236. uint32_t property_idx);
  237. /**
  238. * msm_property_install_blob - install standard drm blob property
  239. * @info: Pointer to property info container struct
  240. * @name: Property name
  241. * @flags: Extra flags for property creation
  242. * @property_idx: Property index
  243. */
  244. void msm_property_install_blob(struct msm_property_info *info,
  245. const char *name,
  246. int flags,
  247. uint32_t property_idx);
  248. /**
  249. * msm_property_install_get_status - query overal status of property additions
  250. * @info: Pointer to property info container struct
  251. * Returns: Zero if previous property install calls were all successful
  252. */
  253. int msm_property_install_get_status(struct msm_property_info *info);
  254. /**
  255. * msm_property_index - determine property index from drm_property ptr
  256. * @info: Pointer to property info container struct
  257. * @property: Incoming property pointer
  258. * Returns: Valid property index, or -EINVAL on error
  259. */
  260. int msm_property_index(struct msm_property_info *info,
  261. struct drm_property *property);
  262. /**
  263. * msm_property_set_dirty - forcibly flag a property as dirty
  264. * @info: Pointer to property info container struct
  265. * @property_state: Pointer to property state container struct
  266. * @property_idx: Property index
  267. * Returns: Zero on success
  268. */
  269. int msm_property_set_dirty(struct msm_property_info *info,
  270. struct msm_property_state *property_state,
  271. int property_idx);
  272. /**
  273. * msm_property_is_dirty - check whether a property is dirty
  274. * Note: Intended for use during atomic_check before pop_dirty usage
  275. * @info: Pointer to property info container struct
  276. * @property_state: Pointer to property state container struct
  277. * @property_idx: Property index
  278. * Returns: true if dirty, false otherwise
  279. */
  280. bool msm_property_is_dirty(
  281. struct msm_property_info *info,
  282. struct msm_property_state *property_state,
  283. uint32_t property_idx);
  284. /**
  285. * msm_property_atomic_set - helper function for atomic property set callback
  286. * @info: Pointer to property info container struct
  287. * @property_state: Pointer to local state structure
  288. * @property: Incoming property pointer
  289. * @val: Incoming property value
  290. * Returns: Zero on success
  291. */
  292. int msm_property_atomic_set(struct msm_property_info *info,
  293. struct msm_property_state *property_state,
  294. struct drm_property *property,
  295. uint64_t val);
  296. /**
  297. * msm_property_atomic_get - helper function for atomic property get callback
  298. * @info: Pointer to property info container struct
  299. * @property_state: Pointer to local state structure
  300. * @property: Incoming property pointer
  301. * @val: Pointer to variable for receiving property value
  302. * Returns: Zero on success
  303. */
  304. int msm_property_atomic_get(struct msm_property_info *info,
  305. struct msm_property_state *property_state,
  306. struct drm_property *property,
  307. uint64_t *val);
  308. /**
  309. * msm_property_alloc_state - helper function for allocating local state objects
  310. * @info: Pointer to property info container struct
  311. */
  312. void *msm_property_alloc_state(struct msm_property_info *info);
  313. /**
  314. * msm_property_reset_state - helper function for state reset callback
  315. * @info: Pointer to property info container struct
  316. * @state: Pointer to local state structure
  317. * @property_state: Pointer to property state container struct
  318. * @property_values: Pointer to property values cache array
  319. */
  320. void msm_property_reset_state(struct msm_property_info *info, void *state,
  321. struct msm_property_state *property_state,
  322. struct msm_property_value *property_values);
  323. /**
  324. * msm_property_duplicate_state - helper function for duplicate state cb
  325. * @info: Pointer to property info container struct
  326. * @old_state: Pointer to original state structure
  327. * @state: Pointer to newly created state structure
  328. * @property_state: Pointer to destination property state container struct
  329. * @property_values: Pointer to property values cache array
  330. */
  331. void msm_property_duplicate_state(struct msm_property_info *info,
  332. void *old_state,
  333. void *state,
  334. struct msm_property_state *property_state,
  335. struct msm_property_value *property_values);
  336. /**
  337. * msm_property_destroy_state - helper function for destroy state cb
  338. * @info: Pointer to property info container struct
  339. * @state: Pointer to local state structure
  340. * @property_state: Pointer to property state container struct
  341. */
  342. void msm_property_destroy_state(struct msm_property_info *info,
  343. void *state,
  344. struct msm_property_state *property_state);
  345. /**
  346. * msm_property_get_blob - obtain cached data pointer for drm blob property
  347. * @info: Pointer to property info container struct
  348. * @property_state: Pointer to property state container struct
  349. * @byte_len: Optional pointer to variable for accepting blob size
  350. * @property_idx: Property index
  351. * Returns: Pointer to blob data
  352. */
  353. void *msm_property_get_blob(struct msm_property_info *info,
  354. struct msm_property_state *property_state,
  355. size_t *byte_len,
  356. uint32_t property_idx);
  357. /**
  358. * msm_property_set_blob - update blob property on a drm object
  359. * This function updates the blob property value of the given drm object. Its
  360. * intended use is to update blob properties that have been created with the
  361. * DRM_MODE_PROP_IMMUTABLE flag set.
  362. * @info: Pointer to property info container struct
  363. * @blob_reference: Reference to a pointer that holds the created data blob
  364. * @blob_data: Pointer to blob data
  365. * @byte_len: Length of blob data, in bytes
  366. * @property_idx: Property index
  367. * Returns: Zero on success
  368. */
  369. int msm_property_set_blob(struct msm_property_info *info,
  370. struct drm_property_blob **blob_reference,
  371. void *blob_data,
  372. size_t byte_len,
  373. uint32_t property_idx);
  374. /**
  375. * msm_property_set_property - update property on a drm object
  376. * This function updates the property value of the given drm object. Its
  377. * intended use is to update properties that have been created with the
  378. * DRM_MODE_PROP_IMMUTABLE flag set.
  379. * Note: This function cannot be called on a blob.
  380. * @info: Pointer to property info container struct
  381. * @property_state: Pointer to property state container struct
  382. * @property_idx: Property index
  383. * @val: value of the property to set
  384. * Returns: Zero on success
  385. */
  386. int msm_property_set_property(struct msm_property_info *info,
  387. struct msm_property_state *property_state,
  388. uint32_t property_idx,
  389. uint64_t val);
  390. #endif /* _MSM_PROP_H_ */