sde_vm.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #ifndef __SDE_VM_H__
  7. #define __SDE_VM_H__
  8. #include "msm_drv.h"
  9. #define TRUSTED_VM_MAX_ENCODER_PER_CRTC 1
  10. struct sde_kms;
  11. /* sde_vm_msg_type - msg_type for dispaly custom messages */
  12. enum sde_vm_msg_type {
  13. SDE_VM_MSG_MAX,
  14. };
  15. /**
  16. * sde_vm_msg_work - sde msgq work definition
  17. * @work - base kthread work object
  18. * @msg_buf - payload buffer
  19. * @msg_size - payload buffer size
  20. * @sde_vm - handle to vm structure
  21. */
  22. struct sde_vm_msg_work {
  23. struct kthread_work work;
  24. void *msg_buf;
  25. size_t msg_size;
  26. struct sde_vm *sde_vm;
  27. };
  28. /**
  29. * sde_vm_msg_header - header definition for custom messages. Must
  30. * be placed at the beginning of each custom
  31. * message definition.
  32. * @msg_type - type of the message
  33. */
  34. struct sde_vm_msg_header {
  35. enum sde_vm_msg_type msg_type;
  36. };
  37. /**
  38. * sde_vm_irq_entry - VM irq specification
  39. * @label - VM_IRQ_LABEL assigned by Hyp RM
  40. * @irq - linux mapped irq number
  41. */
  42. struct sde_vm_irq_entry {
  43. u32 label;
  44. u32 irq;
  45. };
  46. /**
  47. * sde_vm_irq_desc - list of IRQ's to be handled
  48. * @n_irq - irq count
  49. * @irq_entries - list of sde_vm_irq_entry
  50. */
  51. struct sde_vm_irq_desc {
  52. u32 n_irq;
  53. struct sde_vm_irq_entry *irq_entries;
  54. };
  55. enum sde_crtc_vm_req;
  56. /**
  57. * sde_vm_ops - VM specific function hooks
  58. */
  59. struct sde_vm_ops {
  60. /**
  61. * vm_acquire - hook to handle HW accept
  62. * @kms - handle to sde_kms
  63. * @return - return 0 on success
  64. */
  65. int (*vm_acquire)(struct sde_kms *kms);
  66. /**
  67. * vm_release - hook to handle HW release
  68. * @kms - handle to sde_kms
  69. * @return - return 0 on success
  70. */
  71. int (*vm_release)(struct sde_kms *kms);
  72. /**
  73. * vm_owns_hw - hook to query the HW status of the VM
  74. * @kms - handle to sde_kms
  75. * @return - return true when vm owns the hw
  76. */
  77. bool (*vm_owns_hw)(struct sde_kms *kms);
  78. /**
  79. * vm_prepare_commit - hook to handle operations before the first
  80. commit after acquiring the HW
  81. * @sde_kms - handle to sde_kms
  82. * @state - global atomic state to be parsed
  83. * @return - return 0 on success
  84. */
  85. int (*vm_prepare_commit)(struct sde_kms *sde_kms,
  86. struct drm_atomic_state *state);
  87. /**
  88. * vm_post_commit - hook to handle operations after
  89. last commit before release
  90. * @sde_kms - handle to sde_kms
  91. * @state - global atomic state to be parsed
  92. * @return - return 0 on success
  93. */
  94. int (*vm_post_commit)(struct sde_kms *sde_kms,
  95. struct drm_atomic_state *state);
  96. /**
  97. * vm_deinit - deinitialize VM layer
  98. * @kms - pointer to sde_kms
  99. * @ops - primary VM specific ops functions
  100. */
  101. void (*vm_deinit)(struct sde_kms *kms, struct sde_vm_ops *ops);
  102. /**
  103. * vm_check - hook to check with vm_clients for its readiness to release
  104. the HW reasources
  105. */
  106. int (*vm_check)(void);
  107. /**
  108. * vm_client_pre_release - hook to invoke vm_client list for pre_release
  109. handling
  110. * @kms - handle to sde_kms
  111. */
  112. int (*vm_client_pre_release)(struct sde_kms *kms);
  113. /**
  114. * vm_client_post_acquire - hook to invoke vm_client list for
  115. * post_acquire resource handling
  116. * @kms - handle to sde_kms
  117. */
  118. int (*vm_client_post_acquire)(struct sde_kms *kms);
  119. /**
  120. * vm_request_valid - hook to validate the RM_REQ state change
  121. * @sde_kms - handle to sde_kms
  122. * @old_state - current vm_req state
  123. * @new_state - new vm_req state
  124. */
  125. int (*vm_request_valid)(struct sde_kms *sde_kms,
  126. enum sde_crtc_vm_req old_state,
  127. enum sde_crtc_vm_req new_state);
  128. /**
  129. * vm_acquire_fail_handler - hook to the handler when resource
  130. * accept/reclaim fails.
  131. * @sde_kms - handle to sde_kms
  132. */
  133. int (*vm_acquire_fail_handler)(struct sde_kms *sde_kms);
  134. /** vm_msg_recv_cb - sde kms callback hook for msgq data
  135. * @sde_vm - handle to sde_vm struct
  136. * @data - paylod data
  137. * @size - size of payload data
  138. */
  139. void (*vm_msg_recv_cb)(struct sde_vm *sde_vm, void *data, size_t size);
  140. /** vm_msg_send - hook to send custom data to VM
  141. * @sde_vm - handle to sde_vm struct
  142. * @msg - payload data
  143. * @msg_size - payload data size
  144. * @return - 0 on success, errorcode otherwise
  145. */
  146. int (*vm_msg_send)(struct sde_vm *sde_vm, void *msg, size_t msg_size);
  147. /**
  148. * vm_resource_init - hook to the handler when resource
  149. * accept/reclaim fails.
  150. * @sde_kms - handle to sde_kms
  151. * @state: current update atomic commit state
  152. */
  153. int (*vm_resource_init)(struct sde_kms *sde_kms,
  154. struct drm_atomic_state *state);
  155. };
  156. /**
  157. * sde_vm - VM layer descriptor. Abstract for all the VM's
  158. * @vm_res_lock - mutex to protect resource updates
  159. * @mem_notificaiton_cookie - Hyp RM notification identifier
  160. * @n_irq_lent - irq count
  161. * @io_mem_handle - RM identifier for the IO range
  162. * @sde_kms - handle to sde_kms
  163. * @vm_ops - VM operation hooks for respective VM type
  164. * @msgq_listener_thread - handle to msgq receiver thread
  165. * @vm_work - kthread work obj for msgq
  166. * @msgq_handle - handle to display msgq
  167. * @lastclose_in_progress - boolean entry to check if
  168. * lastclose is in progress
  169. */
  170. struct sde_vm {
  171. struct mutex vm_res_lock;
  172. void *mem_notification_cookie;
  173. atomic_t n_irq_lent;
  174. int io_mem_handle;
  175. struct sde_kms *sde_kms;
  176. struct sde_vm_ops vm_ops;
  177. struct task_struct *msgq_listener_thread;
  178. struct sde_vm_msg_work vm_work;
  179. void *msgq_handle;
  180. bool lastclose_in_progress;
  181. };
  182. /**
  183. * sde_vm_primary - VM layer descriptor for Primary VM
  184. * @base - parent struct object
  185. * @irq_desc - cache copy of irq list for validating reclaim
  186. */
  187. struct sde_vm_primary {
  188. struct sde_vm base;
  189. struct sde_vm_irq_desc *irq_desc;
  190. };
  191. /**
  192. * sde_vm_trusted - VM layer descriptor for Trusted VM
  193. * @base - parent struct object
  194. * @sgl_desc - hyp RM sgl list descriptor for IO ranges
  195. * @irq_desc - irq list
  196. */
  197. struct sde_vm_trusted {
  198. struct sde_vm base;
  199. struct sde_vm_irq_desc *irq_desc;
  200. struct gh_sgl_desc *sgl_desc;
  201. };
  202. #if IS_ENABLED(CONFIG_DRM_SDE_VM)
  203. /**
  204. * sde_vm_primary_init - Initialize primary VM layer
  205. * @kms - pointer to sde_kms
  206. * @return - 0 on success
  207. */
  208. int sde_vm_primary_init(struct sde_kms *kms);
  209. /**
  210. * sde_vm_trusted_init - Initialize Trusted VM layer
  211. * @kms - pointer to sde_kms
  212. * @ops - primary VM specific ops functions
  213. * @return - 0 on success
  214. */
  215. int sde_vm_trusted_init(struct sde_kms *kms);
  216. /**
  217. * sde_vm_is_enabled - check whether TUI feature is enabled
  218. * @sde_kms - pointer to sde_kms
  219. * @return - true if enabled, false otherwise
  220. */
  221. static inline bool sde_vm_is_enabled(struct sde_kms *sde_kms)
  222. {
  223. return !!sde_kms->vm;
  224. }
  225. /**
  226. * sde_vm_lock - lock vm variables
  227. * @sde_kms - pointer to sde_kms
  228. */
  229. static inline void sde_vm_lock(struct sde_kms *sde_kms)
  230. {
  231. if (!sde_kms->vm)
  232. return;
  233. mutex_lock(&sde_kms->vm->vm_res_lock);
  234. }
  235. /**
  236. * sde_vm_unlock - unlock vm variables
  237. * @sde_kms - pointer to sde_kms
  238. */
  239. static inline void sde_vm_unlock(struct sde_kms *sde_kms)
  240. {
  241. if (!sde_kms->vm)
  242. return;
  243. mutex_unlock(&sde_kms->vm->vm_res_lock);
  244. }
  245. /**
  246. * sde_vm_get_ops - helper API to retrieve sde_vm_ops
  247. * @sde_kms - pointer to sde_kms
  248. * @return - pointer to sde_vm_ops
  249. */
  250. static inline struct sde_vm_ops *sde_vm_get_ops(struct sde_kms *sde_kms)
  251. {
  252. if (!sde_kms->vm)
  253. return NULL;
  254. return &sde_kms->vm->vm_ops;
  255. }
  256. /**
  257. * sde_vm_owns_hw - checks if the executing VM currently has HW ownership (caller must be holding
  258. * the sde_vm_lock)
  259. * @sde_kms - pointer to sde_kms
  260. * @return - true if this VM currently owns the HW
  261. */
  262. static inline bool sde_vm_owns_hw(struct sde_kms *sde_kms)
  263. {
  264. struct sde_vm_ops *vm_ops = sde_kms ? sde_vm_get_ops(sde_kms) : NULL;
  265. if (vm_ops && vm_ops->vm_owns_hw)
  266. return vm_ops->vm_owns_hw(sde_kms);
  267. return true;
  268. }
  269. #else
  270. static inline int sde_vm_primary_init(struct sde_kms *kms)
  271. {
  272. return 0;
  273. }
  274. static inline int sde_vm_trusted_init(struct sde_kms *kms)
  275. {
  276. return 0;
  277. }
  278. static inline bool sde_vm_is_enabled(struct sde_kms *sde_kms)
  279. {
  280. return false;
  281. }
  282. static inline void sde_vm_lock(struct sde_kms *sde_kms)
  283. {
  284. }
  285. static inline void sde_vm_unlock(struct sde_kms *sde_kms)
  286. {
  287. }
  288. static inline struct sde_vm_ops *sde_vm_get_ops(struct sde_kms *sde_kms)
  289. {
  290. return NULL;
  291. }
  292. static inline bool sde_vm_owns_hw(struct sde_kms *sde_kms)
  293. {
  294. return true;
  295. }
  296. #endif /* IS_ENABLED(CONFIG_DRM_SDE_VM) */
  297. #endif /* __SDE_VM_H__ */