drm_encoder.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * Copyright (c) 2016 Intel Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that copyright
  7. * notice and this permission notice appear in supporting documentation, and
  8. * that the name of the copyright holders not be used in advertising or
  9. * publicity pertaining to distribution of the software without specific,
  10. * written prior permission. The copyright holders make no representations
  11. * about the suitability of this software for any purpose. It is provided "as
  12. * is" without express or implied warranty.
  13. *
  14. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THIS SOFTWARE.
  21. */
  22. #ifndef __DRM_ENCODER_H__
  23. #define __DRM_ENCODER_H__
  24. #include <linux/list.h>
  25. #include <linux/ctype.h>
  26. #include <drm/drm_mode_object.h>
  27. /**
  28. * struct drm_encoder_funcs - encoder controls
  29. *
  30. * Encoders sit between CRTCs and connectors.
  31. */
  32. struct drm_encoder_funcs {
  33. /**
  34. * @reset:
  35. *
  36. * Reset encoder hardware and software state to off. This function isn't
  37. * called by the core directly, only through drm_mode_config_reset().
  38. * It's not a helper hook only for historical reasons.
  39. */
  40. void (*reset)(struct drm_encoder *encoder);
  41. /**
  42. * @destroy:
  43. *
  44. * Clean up encoder resources. This is only called at driver unload time
  45. * through drm_mode_config_cleanup() since an encoder cannot be
  46. * hotplugged in DRM.
  47. */
  48. void (*destroy)(struct drm_encoder *encoder);
  49. /**
  50. * @late_register:
  51. *
  52. * This optional hook can be used to register additional userspace
  53. * interfaces attached to the encoder like debugfs interfaces.
  54. * It is called late in the driver load sequence from drm_dev_register().
  55. * Everything added from this callback should be unregistered in
  56. * the early_unregister callback.
  57. *
  58. * Returns:
  59. *
  60. * 0 on success, or a negative error code on failure.
  61. */
  62. int (*late_register)(struct drm_encoder *encoder);
  63. /**
  64. * @early_unregister:
  65. *
  66. * This optional hook should be used to unregister the additional
  67. * userspace interfaces attached to the encoder from
  68. * late_unregister(). It is called from drm_dev_unregister(),
  69. * early in the driver unload sequence to disable userspace access
  70. * before data structures are torndown.
  71. */
  72. void (*early_unregister)(struct drm_encoder *encoder);
  73. };
  74. /**
  75. * struct drm_encoder - central DRM encoder structure
  76. * @dev: parent DRM device
  77. * @head: list management
  78. * @base: base KMS object
  79. * @name: human readable name, can be overwritten by the driver
  80. * @crtc: currently bound CRTC
  81. * @bridge: bridge associated to the encoder
  82. * @funcs: control functions
  83. * @helper_private: mid-layer private data
  84. *
  85. * CRTCs drive pixels to encoders, which convert them into signals
  86. * appropriate for a given connector or set of connectors.
  87. */
  88. struct drm_encoder {
  89. struct drm_device *dev;
  90. struct list_head head;
  91. struct drm_mode_object base;
  92. char *name;
  93. /**
  94. * @encoder_type:
  95. *
  96. * One of the DRM_MODE_ENCODER_<foo> types in drm_mode.h. The following
  97. * encoder types are defined thus far:
  98. *
  99. * - DRM_MODE_ENCODER_DAC for VGA and analog on DVI-I/DVI-A.
  100. *
  101. * - DRM_MODE_ENCODER_TMDS for DVI, HDMI and (embedded) DisplayPort.
  102. *
  103. * - DRM_MODE_ENCODER_LVDS for display panels, or in general any panel
  104. * with a proprietary parallel connector.
  105. *
  106. * - DRM_MODE_ENCODER_TVDAC for TV output (Composite, S-Video,
  107. * Component, SCART).
  108. *
  109. * - DRM_MODE_ENCODER_VIRTUAL for virtual machine displays
  110. *
  111. * - DRM_MODE_ENCODER_DSI for panels connected using the DSI serial bus.
  112. *
  113. * - DRM_MODE_ENCODER_DPI for panels connected using the DPI parallel
  114. * bus.
  115. *
  116. * - DRM_MODE_ENCODER_DPMST for special fake encoders used to allow
  117. * mutliple DP MST streams to share one physical encoder.
  118. */
  119. int encoder_type;
  120. /**
  121. * @index: Position inside the mode_config.list, can be used as an array
  122. * index. It is invariant over the lifetime of the encoder.
  123. */
  124. unsigned index;
  125. /**
  126. * @possible_crtcs: Bitmask of potential CRTC bindings, using
  127. * drm_crtc_index() as the index into the bitfield. The driver must set
  128. * the bits for all &drm_crtc objects this encoder can be connected to
  129. * before calling drm_encoder_init().
  130. *
  131. * In reality almost every driver gets this wrong.
  132. *
  133. * Note that since CRTC objects can't be hotplugged the assigned indices
  134. * are stable and hence known before registering all objects.
  135. */
  136. uint32_t possible_crtcs;
  137. /**
  138. * @possible_clones: Bitmask of potential sibling encoders for cloning,
  139. * using drm_encoder_index() as the index into the bitfield. The driver
  140. * must set the bits for all &drm_encoder objects which can clone a
  141. * &drm_crtc together with this encoder before calling
  142. * drm_encoder_init(). Drivers should set the bit representing the
  143. * encoder itself, too. Cloning bits should be set such that when two
  144. * encoders can be used in a cloned configuration, they both should have
  145. * each another bits set.
  146. *
  147. * In reality almost every driver gets this wrong.
  148. *
  149. * Note that since encoder objects can't be hotplugged the assigned indices
  150. * are stable and hence known before registering all objects.
  151. */
  152. uint32_t possible_clones;
  153. struct drm_crtc *crtc;
  154. struct drm_bridge *bridge;
  155. const struct drm_encoder_funcs *funcs;
  156. const struct drm_encoder_helper_funcs *helper_private;
  157. };
  158. #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
  159. __printf(5, 6)
  160. int drm_encoder_init(struct drm_device *dev,
  161. struct drm_encoder *encoder,
  162. const struct drm_encoder_funcs *funcs,
  163. int encoder_type, const char *name, ...);
  164. /**
  165. * drm_encoder_index - find the index of a registered encoder
  166. * @encoder: encoder to find index for
  167. *
  168. * Given a registered encoder, return the index of that encoder within a DRM
  169. * device's list of encoders.
  170. */
  171. static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
  172. {
  173. return encoder->index;
  174. }
  175. /* FIXME: We have an include file mess still, drm_crtc.h needs untangling. */
  176. static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc);
  177. /**
  178. * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
  179. * @encoder: encoder to test
  180. * @crtc: crtc to test
  181. *
  182. * Returns false if @encoder can't be driven by @crtc, true otherwise.
  183. */
  184. static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
  185. struct drm_crtc *crtc)
  186. {
  187. return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
  188. }
  189. /**
  190. * drm_encoder_find - find a &drm_encoder
  191. * @dev: DRM device
  192. * @id: encoder id
  193. *
  194. * Returns the encoder with @id, NULL if it doesn't exist. Simple wrapper around
  195. * drm_mode_object_find().
  196. */
  197. static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
  198. uint32_t id)
  199. {
  200. struct drm_mode_object *mo;
  201. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
  202. return mo ? obj_to_encoder(mo) : NULL;
  203. }
  204. void drm_encoder_cleanup(struct drm_encoder *encoder);
  205. /**
  206. * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
  207. * @encoder: the loop cursor
  208. * @dev: the DRM device
  209. * @encoder_mask: bitmask of encoder indices
  210. *
  211. * Iterate over all encoders specified by bitmask.
  212. */
  213. #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
  214. list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
  215. for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
  216. /**
  217. * drm_for_each_encoder - iterate over all encoders
  218. * @encoder: the loop cursor
  219. * @dev: the DRM device
  220. *
  221. * Iterate over all encoders of @dev.
  222. */
  223. #define drm_for_each_encoder(encoder, dev) \
  224. list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
  225. #endif