drm_client.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. * @unregister:
  27. *
  28. * Called when &drm_device is unregistered. The client should respond by
  29. * releasing its resources using drm_client_release().
  30. *
  31. * This callback is optional.
  32. */
  33. void (*unregister)(struct drm_client_dev *client);
  34. /**
  35. * @restore:
  36. *
  37. * Called on drm_lastclose(). The first client instance in the list that
  38. * returns zero gets the privilege to restore and no more clients are
  39. * called. This callback is not called after @unregister has been called.
  40. *
  41. * Note that the core does not guarantee exclusion against concurrent
  42. * drm_open(). Clients need to ensure this themselves, for example by
  43. * using drm_master_internal_acquire() and
  44. * drm_master_internal_release().
  45. *
  46. * This callback is optional.
  47. */
  48. int (*restore)(struct drm_client_dev *client);
  49. /**
  50. * @hotplug:
  51. *
  52. * Called on drm_kms_helper_hotplug_event().
  53. * This callback is not called after @unregister has been called.
  54. *
  55. * This callback is optional.
  56. */
  57. int (*hotplug)(struct drm_client_dev *client);
  58. };
  59. /**
  60. * struct drm_client_dev - DRM client instance
  61. */
  62. struct drm_client_dev {
  63. /**
  64. * @dev: DRM device
  65. */
  66. struct drm_device *dev;
  67. /**
  68. * @name: Name of the client.
  69. */
  70. const char *name;
  71. /**
  72. * @list:
  73. *
  74. * List of all clients of a DRM device, linked into
  75. * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex.
  76. */
  77. struct list_head list;
  78. /**
  79. * @funcs: DRM client functions (optional)
  80. */
  81. const struct drm_client_funcs *funcs;
  82. /**
  83. * @file: DRM file
  84. */
  85. struct drm_file *file;
  86. /**
  87. * @modeset_mutex: Protects @modesets.
  88. */
  89. struct mutex modeset_mutex;
  90. /**
  91. * @modesets: CRTC configurations
  92. */
  93. struct drm_mode_set *modesets;
  94. /**
  95. * @hotplug_failed:
  96. *
  97. * Set by client hotplug helpers if the hotplugging failed
  98. * before. It is usually not tried again.
  99. */
  100. bool hotplug_failed;
  101. };
  102. int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
  103. const char *name, const struct drm_client_funcs *funcs);
  104. void drm_client_release(struct drm_client_dev *client);
  105. void drm_client_register(struct drm_client_dev *client);
  106. void drm_client_dev_unregister(struct drm_device *dev);
  107. void drm_client_dev_hotplug(struct drm_device *dev);
  108. void drm_client_dev_restore(struct drm_device *dev);
  109. /**
  110. * struct drm_client_buffer - DRM client buffer
  111. */
  112. struct drm_client_buffer {
  113. /**
  114. * @client: DRM client
  115. */
  116. struct drm_client_dev *client;
  117. /**
  118. * @pitch: Buffer pitch
  119. */
  120. u32 pitch;
  121. /**
  122. * @gem: GEM object backing this buffer
  123. *
  124. * FIXME: The dependency on GEM here isn't required, we could
  125. * convert the driver handle to a dma-buf instead and use the
  126. * backend-agnostic dma-buf vmap support instead. This would
  127. * require that the handle2fd prime ioctl is reworked to pull the
  128. * fd_install step out of the driver backend hooks, to make that
  129. * final step optional for internal users.
  130. */
  131. struct drm_gem_object *gem;
  132. /**
  133. * @map: Virtual address for the buffer
  134. */
  135. struct iosys_map map;
  136. /**
  137. * @fb: DRM framebuffer
  138. */
  139. struct drm_framebuffer *fb;
  140. };
  141. struct drm_client_buffer *
  142. drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
  143. void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
  144. int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect);
  145. int drm_client_buffer_vmap_local(struct drm_client_buffer *buffer,
  146. struct iosys_map *map_copy);
  147. void drm_client_buffer_vunmap_local(struct drm_client_buffer *buffer);
  148. int drm_client_buffer_vmap(struct drm_client_buffer *buffer,
  149. struct iosys_map *map);
  150. void drm_client_buffer_vunmap(struct drm_client_buffer *buffer);
  151. int drm_client_modeset_create(struct drm_client_dev *client);
  152. void drm_client_modeset_free(struct drm_client_dev *client);
  153. int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height);
  154. bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation);
  155. int drm_client_modeset_check(struct drm_client_dev *client);
  156. int drm_client_modeset_commit_locked(struct drm_client_dev *client);
  157. int drm_client_modeset_commit(struct drm_client_dev *client);
  158. int drm_client_modeset_dpms(struct drm_client_dev *client, int mode);
  159. /**
  160. * drm_client_for_each_modeset() - Iterate over client modesets
  161. * @modeset: &drm_mode_set loop cursor
  162. * @client: DRM client
  163. */
  164. #define drm_client_for_each_modeset(modeset, client) \
  165. for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \
  166. modeset = (client)->modesets; modeset->crtc; modeset++)
  167. /**
  168. * drm_client_for_each_connector_iter - connector_list iterator macro
  169. * @connector: &struct drm_connector pointer used as cursor
  170. * @iter: &struct drm_connector_list_iter
  171. *
  172. * This iterates the connectors that are useable for internal clients (excludes
  173. * writeback connectors).
  174. *
  175. * For more info see drm_for_each_connector_iter().
  176. */
  177. #define drm_client_for_each_connector_iter(connector, iter) \
  178. drm_for_each_connector_iter(connector, iter) \
  179. if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
  180. void drm_client_debugfs_init(struct drm_device *dev);
  181. #endif