msm_prop.h 15 KB

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