drm_writeback.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * (C) COPYRIGHT 2016 ARM Limited. All rights reserved.
  4. * Author: Brian Starkey <brian.starkey@arm.com>
  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. */
  31. struct drm_encoder encoder;
  32. /**
  33. * @pixel_formats_blob_ptr:
  34. *
  35. * DRM blob property data for the pixel formats list on writeback
  36. * connectors
  37. * See also drm_writeback_connector_init()
  38. */
  39. struct drm_property_blob *pixel_formats_blob_ptr;
  40. /** @job_lock: Protects job_queue */
  41. spinlock_t job_lock;
  42. /**
  43. * @job_queue:
  44. *
  45. * Holds a list of a connector's writeback jobs; the last item is the
  46. * most recent. The first item may be either waiting for the hardware
  47. * to begin writing, or currently being written.
  48. *
  49. * See also: drm_writeback_queue_job() and
  50. * drm_writeback_signal_completion()
  51. */
  52. struct list_head job_queue;
  53. /**
  54. * @fence_context:
  55. *
  56. * timeline context used for fence operations.
  57. */
  58. unsigned int fence_context;
  59. /**
  60. * @fence_lock:
  61. *
  62. * spinlock to protect the fences in the fence_context.
  63. */
  64. spinlock_t fence_lock;
  65. /**
  66. * @fence_seqno:
  67. *
  68. * Seqno variable used as monotonic counter for the fences
  69. * created on the connector's timeline.
  70. */
  71. unsigned long fence_seqno;
  72. /**
  73. * @timeline_name:
  74. *
  75. * The name of the connector's fence timeline.
  76. */
  77. char timeline_name[32];
  78. };
  79. /**
  80. * struct drm_writeback_job - DRM writeback job
  81. */
  82. struct drm_writeback_job {
  83. /**
  84. * @connector:
  85. *
  86. * Back-pointer to the writeback connector associated with the job
  87. */
  88. struct drm_writeback_connector *connector;
  89. /**
  90. * @prepared:
  91. *
  92. * Set when the job has been prepared with drm_writeback_prepare_job()
  93. */
  94. bool prepared;
  95. /**
  96. * @cleanup_work:
  97. *
  98. * Used to allow drm_writeback_signal_completion to defer dropping the
  99. * framebuffer reference to a workqueue
  100. */
  101. struct work_struct cleanup_work;
  102. /**
  103. * @list_entry:
  104. *
  105. * List item for the writeback connector's @job_queue
  106. */
  107. struct list_head list_entry;
  108. /**
  109. * @fb:
  110. *
  111. * Framebuffer to be written to by the writeback connector. Do not set
  112. * directly, use drm_writeback_set_fb()
  113. */
  114. struct drm_framebuffer *fb;
  115. /**
  116. * @out_fence:
  117. *
  118. * Fence which will signal once the writeback has completed
  119. */
  120. struct dma_fence *out_fence;
  121. /**
  122. * @priv:
  123. *
  124. * Driver-private data
  125. */
  126. void *priv;
  127. };
  128. static inline struct drm_writeback_connector *
  129. drm_connector_to_writeback(struct drm_connector *connector)
  130. {
  131. return container_of(connector, struct drm_writeback_connector, base);
  132. }
  133. int drm_writeback_connector_init(struct drm_device *dev,
  134. struct drm_writeback_connector *wb_connector,
  135. const struct drm_connector_funcs *con_funcs,
  136. const struct drm_encoder_helper_funcs *enc_helper_funcs,
  137. const u32 *formats, int n_formats);
  138. int drm_writeback_set_fb(struct drm_connector_state *conn_state,
  139. struct drm_framebuffer *fb);
  140. int drm_writeback_prepare_job(struct drm_writeback_job *job);
  141. void drm_writeback_queue_job(struct drm_writeback_connector *wb_connector,
  142. struct drm_connector_state *conn_state);
  143. void drm_writeback_cleanup_job(struct drm_writeback_job *job);
  144. void
  145. drm_writeback_signal_completion(struct drm_writeback_connector *wb_connector,
  146. int status);
  147. struct dma_fence *
  148. drm_writeback_get_out_fence(struct drm_writeback_connector *wb_connector);
  149. #endif