msm_kms.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
  4. * Copyright (C) 2013 Red Hat
  5. * Author: Rob Clark <robdclark@gmail.com>
  6. */
  7. #ifndef __MSM_KMS_H__
  8. #define __MSM_KMS_H__
  9. #include <linux/clk.h>
  10. #include <linux/regulator/consumer.h>
  11. #include "msm_drv.h"
  12. #define MAX_PLANE 4
  13. /* As there are different display controller blocks depending on the
  14. * snapdragon version, the kms support is split out and the appropriate
  15. * implementation is loaded at runtime. The kms module is responsible
  16. * for constructing the appropriate planes/crtcs/encoders/connectors.
  17. */
  18. struct msm_kms_funcs {
  19. /* hw initialization: */
  20. int (*hw_init)(struct msm_kms *kms);
  21. /* irq handling: */
  22. void (*irq_preinstall)(struct msm_kms *kms);
  23. int (*irq_postinstall)(struct msm_kms *kms);
  24. void (*irq_uninstall)(struct msm_kms *kms);
  25. irqreturn_t (*irq)(struct msm_kms *kms);
  26. int (*enable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
  27. void (*disable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
  28. /*
  29. * Atomic commit handling:
  30. *
  31. * Note that in the case of async commits, the funcs which take
  32. * a crtc_mask (ie. ->flush_commit(), and ->complete_commit())
  33. * might not be evenly balanced with ->prepare_commit(), however
  34. * each crtc that effected by a ->prepare_commit() (potentially
  35. * multiple times) will eventually (at end of vsync period) be
  36. * flushed and completed.
  37. *
  38. * This has some implications about tracking of cleanup state,
  39. * for example SMP blocks to release after commit completes. Ie.
  40. * cleanup state should be also duplicated in the various
  41. * duplicate_state() methods, as the current cleanup state at
  42. * ->complete_commit() time may have accumulated cleanup work
  43. * from multiple commits.
  44. */
  45. /**
  46. * Enable/disable power/clks needed for hw access done in other
  47. * commit related methods.
  48. *
  49. * If mdp4 is migrated to runpm, we could probably drop these
  50. * and use runpm directly.
  51. */
  52. void (*enable_commit)(struct msm_kms *kms);
  53. void (*disable_commit)(struct msm_kms *kms);
  54. /**
  55. * Prepare for atomic commit. This is called after any previous
  56. * (async or otherwise) commit has completed.
  57. */
  58. void (*prepare_commit)(struct msm_kms *kms, struct drm_atomic_state *state);
  59. /**
  60. * Flush an atomic commit. This is called after the hardware
  61. * updates have already been pushed down to effected planes/
  62. * crtcs/encoders/connectors.
  63. */
  64. void (*flush_commit)(struct msm_kms *kms, unsigned crtc_mask);
  65. /**
  66. * Wait for any in-progress flush to complete on the specified
  67. * crtcs. This should not block if there is no in-progress
  68. * commit (ie. don't just wait for a vblank), as it will also
  69. * be called before ->prepare_commit() to ensure any potential
  70. * "async" commit has completed.
  71. */
  72. void (*wait_flush)(struct msm_kms *kms, unsigned crtc_mask);
  73. /**
  74. * Clean up after commit is completed. This is called after
  75. * ->wait_flush(), to give the backend a chance to do any
  76. * post-commit cleanup.
  77. */
  78. void (*complete_commit)(struct msm_kms *kms, unsigned crtc_mask);
  79. /*
  80. * Format handling:
  81. */
  82. /* do format checking on format modified through fb_cmd2 modifiers */
  83. int (*check_modified_format)(const struct msm_kms *kms,
  84. const struct msm_format *msm_fmt,
  85. const struct drm_mode_fb_cmd2 *cmd,
  86. struct drm_gem_object **bos);
  87. /* misc: */
  88. long (*round_pixclk)(struct msm_kms *kms, unsigned long rate,
  89. struct drm_encoder *encoder);
  90. /* cleanup: */
  91. void (*destroy)(struct msm_kms *kms);
  92. /* snapshot: */
  93. void (*snapshot)(struct msm_disp_state *disp_state, struct msm_kms *kms);
  94. #ifdef CONFIG_DEBUG_FS
  95. /* debugfs: */
  96. int (*debugfs_init)(struct msm_kms *kms, struct drm_minor *minor);
  97. #endif
  98. };
  99. struct msm_kms;
  100. /*
  101. * A per-crtc timer for pending async atomic flushes. Scheduled to expire
  102. * shortly before vblank to flush pending async updates.
  103. */
  104. struct msm_pending_timer {
  105. struct msm_hrtimer_work work;
  106. struct kthread_worker *worker;
  107. struct msm_kms *kms;
  108. unsigned crtc_idx;
  109. };
  110. struct msm_kms {
  111. const struct msm_kms_funcs *funcs;
  112. struct drm_device *dev;
  113. /* irq number to be passed on to msm_irq_install */
  114. int irq;
  115. bool irq_requested;
  116. /* mapper-id used to request GEM buffer mapped for scanout: */
  117. struct msm_gem_address_space *aspace;
  118. /* disp snapshot support */
  119. struct kthread_worker *dump_worker;
  120. struct kthread_work dump_work;
  121. struct mutex dump_mutex;
  122. /*
  123. * For async commit, where ->flush_commit() and later happens
  124. * from the crtc's pending_timer close to end of the frame:
  125. */
  126. struct mutex commit_lock[MAX_CRTCS];
  127. unsigned pending_crtc_mask;
  128. struct msm_pending_timer pending_timers[MAX_CRTCS];
  129. };
  130. static inline int msm_kms_init(struct msm_kms *kms,
  131. const struct msm_kms_funcs *funcs)
  132. {
  133. unsigned i, ret;
  134. for (i = 0; i < ARRAY_SIZE(kms->commit_lock); i++)
  135. mutex_init(&kms->commit_lock[i]);
  136. kms->funcs = funcs;
  137. for (i = 0; i < ARRAY_SIZE(kms->pending_timers); i++) {
  138. ret = msm_atomic_init_pending_timer(&kms->pending_timers[i], kms, i);
  139. if (ret) {
  140. return ret;
  141. }
  142. }
  143. return 0;
  144. }
  145. static inline void msm_kms_destroy(struct msm_kms *kms)
  146. {
  147. unsigned i;
  148. for (i = 0; i < ARRAY_SIZE(kms->pending_timers); i++)
  149. msm_atomic_destroy_pending_timer(&kms->pending_timers[i]);
  150. }
  151. #define for_each_crtc_mask(dev, crtc, crtc_mask) \
  152. drm_for_each_crtc(crtc, dev) \
  153. for_each_if (drm_crtc_mask(crtc) & (crtc_mask))
  154. #define for_each_crtc_mask_reverse(dev, crtc, crtc_mask) \
  155. drm_for_each_crtc_reverse(crtc, dev) \
  156. for_each_if (drm_crtc_mask(crtc) & (crtc_mask))
  157. int msm_drm_kms_init(struct device *dev, const struct drm_driver *drv);
  158. void msm_drm_kms_uninit(struct device *dev);
  159. #endif /* __MSM_KMS_H__ */