sde_vm.h 5.8 KB

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