sde_vm.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. int (*vm_request_valid)(struct sde_kms *sde_kms,
  92. enum sde_crtc_vm_req old_state,
  93. enum sde_crtc_vm_req new_state);
  94. };
  95. /**
  96. * sde_vm - VM layer descriptor. Abstract for all the VM's
  97. * @vm_res_lock - mutex to protect resource updates
  98. * @mem_notificaiton_cookie - Hyp RM notification identifier
  99. * @n_irq_lent - irq count
  100. * @io_mem_handle - RM identifier for the IO range
  101. * @sde_kms - handle to sde_kms
  102. * @vm_ops - VM operation hooks for respective VM type
  103. */
  104. struct sde_vm {
  105. struct mutex vm_res_lock;
  106. void *mem_notification_cookie;
  107. atomic_t n_irq_lent;
  108. int io_mem_handle;
  109. struct sde_kms *sde_kms;
  110. struct sde_vm_ops vm_ops;
  111. };
  112. /**
  113. * sde_vm_primary - VM layer descriptor for Primary VM
  114. * @base - parent struct object
  115. * @irq_desc - cache copy of irq list for validating reclaim
  116. */
  117. struct sde_vm_primary {
  118. struct sde_vm base;
  119. struct sde_vm_irq_desc *irq_desc;
  120. };
  121. /**
  122. * sde_vm_trusted - VM layer descriptor for Trusted VM
  123. * @base - parent struct object
  124. * @sgl_desc - hyp RM sgl list descriptor for IO ranges
  125. * @irq_desc - irq list
  126. */
  127. struct sde_vm_trusted {
  128. struct sde_vm base;
  129. struct sde_vm_irq_desc *irq_desc;
  130. struct hh_sgl_desc *sgl_desc;
  131. };
  132. #if IS_ENABLED(CONFIG_DRM_SDE_VM)
  133. /**
  134. * sde_vm_primary_init - Initialize primary VM layer
  135. * @kms - pointer to sde_kms
  136. * @return - 0 on success
  137. */
  138. int sde_vm_primary_init(struct sde_kms *kms);
  139. /**
  140. * sde_vm_trusted_init - Initialize Trusted VM layer
  141. * @kms - pointer to sde_kms
  142. * @ops - primary VM specific ops functions
  143. * @return - 0 on success
  144. */
  145. int sde_vm_trusted_init(struct sde_kms *kms);
  146. /**
  147. * sde_vm_is_enabled - check whether TUI feature is enabled
  148. * @sde_kms - pointer to sde_kms
  149. * @return - true if enabled, false otherwise
  150. */
  151. static inline bool sde_vm_is_enabled(struct sde_kms *sde_kms)
  152. {
  153. return !!sde_kms->vm;
  154. }
  155. /**
  156. * sde_vm_lock - lock vm variables
  157. * @sde_kms - pointer to sde_kms
  158. */
  159. static inline void sde_vm_lock(struct sde_kms *sde_kms)
  160. {
  161. if (!sde_kms->vm)
  162. return;
  163. mutex_lock(&sde_kms->vm->vm_res_lock);
  164. }
  165. /**
  166. * sde_vm_unlock - unlock vm variables
  167. * @sde_kms - pointer to sde_kms
  168. */
  169. static inline void sde_vm_unlock(struct sde_kms *sde_kms)
  170. {
  171. if (!sde_kms->vm)
  172. return;
  173. mutex_unlock(&sde_kms->vm->vm_res_lock);
  174. }
  175. /**
  176. * sde_vm_get_ops - helper API to retrieve sde_vm_ops
  177. * @sde_kms - pointer to sde_kms
  178. * @return - pointer to sde_vm_ops
  179. */
  180. static inline struct sde_vm_ops *sde_vm_get_ops(struct sde_kms *sde_kms)
  181. {
  182. if (!sde_kms->vm)
  183. return NULL;
  184. return &sde_kms->vm->vm_ops;
  185. }
  186. #else
  187. static inline int sde_vm_primary_init(struct sde_kms *kms)
  188. {
  189. return 0;
  190. }
  191. static inline int sde_vm_trusted_init(struct sde_kms *kms)
  192. {
  193. return 0;
  194. }
  195. static inline bool sde_vm_is_enabled(struct sde_kms *sde_kms)
  196. {
  197. return false;
  198. }
  199. static inline void sde_vm_lock(struct sde_kms *sde_kms)
  200. {
  201. }
  202. static inline void sde_vm_unlock(struct sde_kms *sde_kms)
  203. {
  204. }
  205. static inline struct sde_vm_ops *sde_vm_get_ops(struct sde_kms *sde_kms)
  206. {
  207. return NULL;
  208. }
  209. #endif /* IS_ENABLED(CONFIG_DRM_SDE_VM) */
  210. #endif /* __SDE_VM_H__ */