drm_writeback.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * (C) COPYRIGHT 2016 ARM Limited. All rights reserved.
  4. * Author: Brian Starkey <[email protected]>
  5. *
  6. * This program is free software and is provided to you under the terms of the
  7. * GNU General Public License version 2 as published by the Free Software
  8. * Foundation, and any use by you of this program is subject to the terms
  9. * of such GNU licence.
  10. */
  11. #ifndef __DRM_WRITEBACK_H__
  12. #define __DRM_WRITEBACK_H__
  13. #include <drm/drm_connector.h>
  14. #include <drm/drm_encoder.h>
  15. #include <linux/workqueue.h>
  16. /**
  17. * struct drm_writeback_connector - DRM writeback connector
  18. */
  19. struct drm_writeback_connector {
  20. /**
  21. * @base: base drm_connector object
  22. */
  23. struct drm_connector base;
  24. /**
  25. * @encoder: Internal encoder used by the connector to fulfill
  26. * the DRM framework requirements. The users of the
  27. * @drm_writeback_connector control the behaviour of the @encoder
  28. * by passing the @enc_funcs parameter to drm_writeback_connector_init()
  29. * function.
  30. * For users of drm_writeback_connector_init_with_encoder(), this field
  31. * is not valid as the encoder is managed within their drivers.
  32. */
  33. struct drm_encoder encoder;
  34. /**
  35. * @pixel_formats_blob_ptr:
  36. *
  37. * DRM blob property data for the pixel formats list on writeback
  38. * connectors
  39. * See also drm_writeback_connector_init()
  40. */
  41. struct drm_property_blob *pixel_formats_blob_ptr;
  42. /** @job_lock: Protects job_queue */
  43. spinlock_t job_lock;
  44. /**
  45. * @job_queue:
  46. *
  47. * Holds a list of a connector's writeback jobs; the last item is the
  48. * most recent. The first item may be either waiting for the hardware
  49. * to begin writing, or currently being written.
  50. *
  51. * See also: drm_writeback_queue_job() and
  52. * drm_writeback_signal_completion()
  53. */
  54. struct list_head job_queue;
  55. /**
  56. * @fence_context:
  57. *
  58. * timeline context used for fence operations.
  59. */
  60. unsigned int fence_context;
  61. /**
  62. * @fence_lock:
  63. *
  64. * spinlock to protect the fences in the fence_context.
  65. */
  66. spinlock_t fence_lock;
  67. /**
  68. * @fence_seqno:
  69. *
  70. * Seqno variable used as monotonic counter for the fences
  71. * created on the connector's timeline.
  72. */
  73. unsigned long fence_seqno;
  74. /**
  75. * @timeline_name:
  76. *
  77. * The name of the connector's fence timeline.
  78. */
  79. char timeline_name[32];
  80. };
  81. /**
  82. * struct drm_writeback_job - DRM writeback job
  83. */
  84. struct drm_writeback_job {
  85. /**
  86. * @connector:
  87. *
  88. * Back-pointer to the writeback connector associated with the job
  89. */
  90. struct drm_writeback_connector *connector;
  91. /**
  92. * @prepared:
  93. *
  94. * Set when the job has been prepared with drm_writeback_prepare_job()
  95. */
  96. bool prepared;
  97. /**
  98. * @cleanup_work:
  99. *
  100. * Used to allow drm_writeback_signal_completion to defer dropping the
  101. * framebuffer reference to a workqueue
  102. */
  103. struct work_struct cleanup_work;
  104. /**
  105. * @list_entry:
  106. *
  107. * List item for the writeback connector's @job_queue
  108. */
  109. struct list_head list_entry;
  110. /**
  111. * @fb:
  112. *
  113. * Framebuffer to be written to by the writeback connector. Do not set
  114. * directly, use drm_writeback_set_fb()
  115. */
  116. struct drm_framebuffer *fb;
  117. /**
  118. * @out_fence:
  119. *
  120. * Fence which will signal once the writeback has completed
  121. */
  122. struct dma_fence *out_fence;
  123. /**
  124. * @priv:
  125. *
  126. * Driver-private data
  127. */
  128. void *priv;
  129. };
  130. static inline struct drm_writeback_connector *
  131. drm_connector_to_writeback(struct drm_connector *connector)
  132. {
  133. return container_of(connector, struct drm_writeback_connector, base);
  134. }
  135. int drm_writeback_connector_init(struct drm_device *dev,
  136. struct drm_writeback_connector *wb_connector,
  137. const struct drm_connector_funcs *con_funcs,
  138. const struct drm_encoder_helper_funcs *enc_helper_funcs,
  139. const u32 *formats, int n_formats,
  140. u32 possible_crtcs);
  141. int drm_writeback_connector_init_with_encoder(struct drm_device *dev,
  142. struct drm_writeback_connector *wb_connector,
  143. struct drm_encoder *enc,
  144. const struct drm_connector_funcs *con_funcs, const u32 *formats,
  145. int n_formats);
  146. int drm_writeback_set_fb(struct drm_connector_state *conn_state,
  147. struct drm_framebuffer *fb);
  148. int drm_writeback_prepare_job(struct drm_writeback_job *job);
  149. void drm_writeback_queue_job(struct drm_writeback_connector *wb_connector,
  150. struct drm_connector_state *conn_state);
  151. void drm_writeback_cleanup_job(struct drm_writeback_job *job);
  152. void
  153. drm_writeback_signal_completion(struct drm_writeback_connector *wb_connector,
  154. int status);
  155. struct dma_fence *
  156. drm_writeback_get_out_fence(struct drm_writeback_connector *wb_connector);
  157. #endif