sde_vm.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __SDE_VM_H__
  6. #define __SDE_VM_H__
  7. #include "msm_drv.h"
  8. #define TRUSTED_VM_MAX_ENCODER_PER_CRTC 1
  9. struct sde_kms;
  10. /**
  11. * sde_vm_irq_entry - VM irq specification
  12. * @label - VM_IRQ_LABEL assigned by Hyp RM
  13. * @irq - linux mapped irq number
  14. */
  15. struct sde_vm_irq_entry {
  16. u32 label;
  17. u32 irq;
  18. };
  19. /**
  20. * sde_vm_irq_desc - list of IRQ's to be handled
  21. * @n_irq - irq count
  22. * @irq_entries - list of sde_vm_irq_entry
  23. */
  24. struct sde_vm_irq_desc {
  25. u32 n_irq;
  26. struct sde_vm_irq_entry *irq_entries;
  27. };
  28. enum sde_crtc_vm_req;
  29. /**
  30. * sde_vm_ops - VM specific function hooks
  31. */
  32. struct sde_vm_ops {
  33. /**
  34. * vm_acquire - hook to handle HW accept
  35. * @kms - handle to sde_kms
  36. * @return - return 0 on success
  37. */
  38. int (*vm_acquire)(struct sde_kms *kms);
  39. /**
  40. * vm_release - hook to handle HW release
  41. * @kms - handle to sde_kms
  42. * @return - return 0 on success
  43. */
  44. int (*vm_release)(struct sde_kms *kms);
  45. /**
  46. * vm_owns_hw - hook to query the HW status of the VM
  47. * @kms - handle to sde_kms
  48. * @return - return true when vm owns the hw
  49. */
  50. bool (*vm_owns_hw)(struct sde_kms *kms);
  51. /**
  52. * vm_prepare_commit - hook to handle operations before the first
  53. commit after acquiring the HW
  54. * @sde_kms - handle to sde_kms
  55. * @state - global atomic state to be parsed
  56. * @return - return 0 on success
  57. */
  58. int (*vm_prepare_commit)(struct sde_kms *sde_kms,
  59. struct drm_atomic_state *state);
  60. /**
  61. * vm_post_commit - hook to handle operations after
  62. last commit before release
  63. * @sde_kms - handle to sde_kms
  64. * @state - global atomic state to be parsed
  65. * @return - return 0 on success
  66. */
  67. int (*vm_post_commit)(struct sde_kms *sde_kms,
  68. struct drm_atomic_state *state);
  69. /**
  70. * vm_deinit - deinitialize VM layer
  71. * @kms - pointer to sde_kms
  72. * @ops - primary VM specific ops functions
  73. */
  74. void (*vm_deinit)(struct sde_kms *kms, struct sde_vm_ops *ops);
  75. /**
  76. * vm_check - hook to check with vm_clients for its readiness to release
  77. the HW reasources
  78. */
  79. int (*vm_check)(void);
  80. /**
  81. * vm_client_pre_release - hook to invoke vm_client list for pre_release
  82. handling
  83. * @kms - handle to sde_kms
  84. */
  85. int (*vm_client_pre_release)(struct sde_kms *kms);
  86. /**
  87. * vm_client_post_acquire - hook to invoke vm_client list for
  88. * post_acquire resource handling
  89. * @kms - handle to sde_kms
  90. */
  91. int (*vm_client_post_acquire)(struct sde_kms *kms);
  92. /**
  93. * vm_request_valid - hook to validate the RM_REQ state change
  94. * @sde_kms - handle to sde_kms
  95. * @old_state - current vm_req state
  96. * @new_state - new vm_req state
  97. */
  98. int (*vm_request_valid)(struct sde_kms *sde_kms,
  99. enum sde_crtc_vm_req old_state,
  100. enum sde_crtc_vm_req new_state);
  101. /**
  102. * vm_acquire_fail_handler - hook to the handler when resource
  103. * accept/reclaim fails.
  104. * @sde_kms - handle to sde_kms
  105. */
  106. int (*vm_acquire_fail_handler)(struct sde_kms *sde_kms);
  107. };
  108. /**
  109. * sde_vm - VM layer descriptor. Abstract for all the VM's
  110. * @vm_res_lock - mutex to protect resource updates
  111. * @mem_notificaiton_cookie - Hyp RM notification identifier
  112. * @n_irq_lent - irq count
  113. * @io_mem_handle - RM identifier for the IO range
  114. * @sde_kms - handle to sde_kms
  115. * @vm_ops - VM operation hooks for respective VM type
  116. */
  117. struct sde_vm {
  118. struct mutex vm_res_lock;
  119. void *mem_notification_cookie;
  120. atomic_t n_irq_lent;
  121. int io_mem_handle;
  122. struct sde_kms *sde_kms;
  123. struct sde_vm_ops vm_ops;
  124. };
  125. /**
  126. * sde_vm_primary - VM layer descriptor for Primary VM
  127. * @base - parent struct object
  128. * @irq_desc - cache copy of irq list for validating reclaim
  129. */
  130. struct sde_vm_primary {
  131. struct sde_vm base;
  132. struct sde_vm_irq_desc *irq_desc;
  133. };
  134. /**
  135. * sde_vm_trusted - VM layer descriptor for Trusted VM
  136. * @base - parent struct object
  137. * @sgl_desc - hyp RM sgl list descriptor for IO ranges
  138. * @irq_desc - irq list
  139. */
  140. struct sde_vm_trusted {
  141. struct sde_vm base;
  142. struct sde_vm_irq_desc *irq_desc;
  143. struct hh_sgl_desc *sgl_desc;
  144. };
  145. #if IS_ENABLED(CONFIG_DRM_SDE_VM)
  146. /**
  147. * sde_vm_primary_init - Initialize primary VM layer
  148. * @kms - pointer to sde_kms
  149. * @return - 0 on success
  150. */
  151. int sde_vm_primary_init(struct sde_kms *kms);
  152. /**
  153. * sde_vm_trusted_init - Initialize Trusted VM layer
  154. * @kms - pointer to sde_kms
  155. * @ops - primary VM specific ops functions
  156. * @return - 0 on success
  157. */
  158. int sde_vm_trusted_init(struct sde_kms *kms);
  159. /**
  160. * sde_vm_is_enabled - check whether TUI feature is enabled
  161. * @sde_kms - pointer to sde_kms
  162. * @return - true if enabled, false otherwise
  163. */
  164. static inline bool sde_vm_is_enabled(struct sde_kms *sde_kms)
  165. {
  166. return !!sde_kms->vm;
  167. }
  168. /**
  169. * sde_vm_lock - lock vm variables
  170. * @sde_kms - pointer to sde_kms
  171. */
  172. static inline void sde_vm_lock(struct sde_kms *sde_kms)
  173. {
  174. if (!sde_kms->vm)
  175. return;
  176. mutex_lock(&sde_kms->vm->vm_res_lock);
  177. }
  178. /**
  179. * sde_vm_unlock - unlock vm variables
  180. * @sde_kms - pointer to sde_kms
  181. */
  182. static inline void sde_vm_unlock(struct sde_kms *sde_kms)
  183. {
  184. if (!sde_kms->vm)
  185. return;
  186. mutex_unlock(&sde_kms->vm->vm_res_lock);
  187. }
  188. /**
  189. * sde_vm_get_ops - helper API to retrieve sde_vm_ops
  190. * @sde_kms - pointer to sde_kms
  191. * @return - pointer to sde_vm_ops
  192. */
  193. static inline struct sde_vm_ops *sde_vm_get_ops(struct sde_kms *sde_kms)
  194. {
  195. if (!sde_kms->vm)
  196. return NULL;
  197. return &sde_kms->vm->vm_ops;
  198. }
  199. #else
  200. static inline int sde_vm_primary_init(struct sde_kms *kms)
  201. {
  202. return 0;
  203. }
  204. static inline int sde_vm_trusted_init(struct sde_kms *kms)
  205. {
  206. return 0;
  207. }
  208. static inline bool sde_vm_is_enabled(struct sde_kms *sde_kms)
  209. {
  210. return false;
  211. }
  212. static inline void sde_vm_lock(struct sde_kms *sde_kms)
  213. {
  214. }
  215. static inline void sde_vm_unlock(struct sde_kms *sde_kms)
  216. {
  217. }
  218. static inline struct sde_vm_ops *sde_vm_get_ops(struct sde_kms *sde_kms)
  219. {
  220. return NULL;
  221. }
  222. #endif /* IS_ENABLED(CONFIG_DRM_SDE_VM) */
  223. #endif /* __SDE_VM_H__ */