drm_client.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /* SPDX-License-Identifier: GPL-2.0 or MIT */
  2. #ifndef _DRM_CLIENT_H_
  3. #define _DRM_CLIENT_H_
  4. #include <linux/iosys-map.h>
  5. #include <linux/lockdep.h>
  6. #include <linux/mutex.h>
  7. #include <linux/types.h>
  8. #include <drm/drm_connector.h>
  9. #include <drm/drm_crtc.h>
  10. struct drm_client_dev;
  11. struct drm_device;
  12. struct drm_file;
  13. struct drm_framebuffer;
  14. struct drm_gem_object;
  15. struct drm_minor;
  16. struct module;
  17. /**
  18. * struct drm_client_funcs - DRM client callbacks
  19. */
  20. struct drm_client_funcs {
  21. /**
  22. * @owner: The module owner
  23. */
  24. struct module *owner;
  25. /**
  26. * @free:
  27. *
  28. * Called when the client gets unregistered. Implementations should
  29. * release all client-specific data and free the memory.
  30. *
  31. * This callback is optional.
  32. */
  33. void (*free)(struct drm_client_dev *client);
  34. /**
  35. * @unregister:
  36. *
  37. * Called when &drm_device is unregistered. The client should respond by
  38. * releasing its resources using drm_client_release().
  39. *
  40. * This callback is optional.
  41. */
  42. void (*unregister)(struct drm_client_dev *client);
  43. /**
  44. * @restore:
  45. *
  46. * Called on drm_lastclose(). The first client instance in the list that
  47. * returns zero gets the privilege to restore and no more clients are
  48. * called. This callback is not called after @unregister has been called.
  49. *
  50. * Note that the core does not guarantee exclusion against concurrent
  51. * drm_open(). Clients need to ensure this themselves, for example by
  52. * using drm_master_internal_acquire() and drm_master_internal_release().
  53. *
  54. * If the caller passes force, the client should ignore any present DRM
  55. * master and restore the display anyway.
  56. *
  57. * This callback is optional.
  58. */
  59. int (*restore)(struct drm_client_dev *client, bool force);
  60. /**
  61. * @hotplug:
  62. *
  63. * Called on drm_kms_helper_hotplug_event().
  64. * This callback is not called after @unregister has been called.
  65. *
  66. * This callback is optional.
  67. */
  68. int (*hotplug)(struct drm_client_dev *client);
  69. /**
  70. * @suspend:
  71. *
  72. * Called when suspending the device.
  73. *
  74. * This callback is optional.
  75. */
  76. int (*suspend)(struct drm_client_dev *client);
  77. /**
  78. * @resume:
  79. *
  80. * Called when resuming the device from suspend.
  81. *
  82. * This callback is optional.
  83. */
  84. int (*resume)(struct drm_client_dev *client);
  85. };
  86. /**
  87. * struct drm_client_dev - DRM client instance
  88. */
  89. struct drm_client_dev {
  90. /**
  91. * @dev: DRM device
  92. */
  93. struct drm_device *dev;
  94. /**
  95. * @name: Name of the client.
  96. */
  97. const char *name;
  98. /**
  99. * @list:
  100. *
  101. * List of all clients of a DRM device, linked into
  102. * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex.
  103. */
  104. struct list_head list;
  105. /**
  106. * @funcs: DRM client functions (optional)
  107. */
  108. const struct drm_client_funcs *funcs;
  109. /**
  110. * @file: DRM file
  111. */
  112. struct drm_file *file;
  113. /**
  114. * @modeset_mutex: Protects @modesets.
  115. */
  116. struct mutex modeset_mutex;
  117. /**
  118. * @modesets: CRTC configurations
  119. */
  120. struct drm_mode_set *modesets;
  121. /**
  122. * @suspended:
  123. *
  124. * The client has been suspended.
  125. */
  126. bool suspended;
  127. /**
  128. * @hotplug_pending:
  129. *
  130. * A hotplug event has been received while the client was suspended.
  131. * Try again on resume.
  132. */
  133. bool hotplug_pending;
  134. /**
  135. * @hotplug_failed:
  136. *
  137. * Set by client hotplug helpers if the hotplugging failed
  138. * before. It is usually not tried again.
  139. */
  140. bool hotplug_failed;
  141. };
  142. int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
  143. const char *name, const struct drm_client_funcs *funcs);
  144. void drm_client_release(struct drm_client_dev *client);
  145. void drm_client_register(struct drm_client_dev *client);
  146. /**
  147. * struct drm_client_buffer - DRM client buffer
  148. */
  149. struct drm_client_buffer {
  150. /**
  151. * @client: DRM client
  152. */
  153. struct drm_client_dev *client;
  154. /**
  155. * @gem: GEM object backing this buffer
  156. *
  157. * FIXME: The DRM framebuffer holds a reference on its GEM
  158. * buffer objects. Do not use this field in new code and
  159. * update existing users.
  160. */
  161. struct drm_gem_object *gem;
  162. /**
  163. * @map: Virtual address for the buffer
  164. */
  165. struct iosys_map map;
  166. /**
  167. * @fb: DRM framebuffer
  168. */
  169. struct drm_framebuffer *fb;
  170. };
  171. struct drm_client_buffer *
  172. drm_client_buffer_create_dumb(struct drm_client_dev *client, u32 width, u32 height, u32 format);
  173. void drm_client_buffer_delete(struct drm_client_buffer *buffer);
  174. int drm_client_buffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect);
  175. int drm_client_buffer_vmap_local(struct drm_client_buffer *buffer,
  176. struct iosys_map *map_copy);
  177. void drm_client_buffer_vunmap_local(struct drm_client_buffer *buffer);
  178. int drm_client_buffer_vmap(struct drm_client_buffer *buffer,
  179. struct iosys_map *map);
  180. void drm_client_buffer_vunmap(struct drm_client_buffer *buffer);
  181. int drm_client_modeset_create(struct drm_client_dev *client);
  182. void drm_client_modeset_free(struct drm_client_dev *client);
  183. int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height);
  184. bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation);
  185. int drm_client_modeset_check(struct drm_client_dev *client);
  186. int drm_client_modeset_commit_locked(struct drm_client_dev *client);
  187. int drm_client_modeset_commit(struct drm_client_dev *client);
  188. int drm_client_modeset_dpms(struct drm_client_dev *client, int mode);
  189. int drm_client_modeset_wait_for_vblank(struct drm_client_dev *client, unsigned int crtc_index);
  190. /**
  191. * drm_client_for_each_modeset() - Iterate over client modesets
  192. * @modeset: &drm_mode_set loop cursor
  193. * @client: DRM client
  194. */
  195. #define drm_client_for_each_modeset(modeset, client) \
  196. for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \
  197. modeset = (client)->modesets; modeset->crtc; modeset++)
  198. /**
  199. * drm_client_for_each_connector_iter - connector_list iterator macro
  200. * @connector: &struct drm_connector pointer used as cursor
  201. * @iter: &struct drm_connector_list_iter
  202. *
  203. * This iterates the connectors that are useable for internal clients (excludes
  204. * writeback connectors).
  205. *
  206. * For more info see drm_for_each_connector_iter().
  207. */
  208. #define drm_client_for_each_connector_iter(connector, iter) \
  209. drm_for_each_connector_iter(connector, iter) \
  210. if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
  211. #endif