drm_client.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* SPDX-License-Identifier: GPL-2.0 or MIT */
  2. #ifndef _DRM_CLIENT_H_
  3. #define _DRM_CLIENT_H_
  4. #include <linux/lockdep.h>
  5. #include <linux/mutex.h>
  6. #include <linux/types.h>
  7. #include <drm/drm_connector.h>
  8. #include <drm/drm_crtc.h>
  9. struct drm_client_dev;
  10. struct drm_device;
  11. struct drm_file;
  12. struct drm_framebuffer;
  13. struct drm_gem_object;
  14. struct drm_minor;
  15. struct module;
  16. /**
  17. * struct drm_client_funcs - DRM client callbacks
  18. */
  19. struct drm_client_funcs {
  20. /**
  21. * @owner: The module owner
  22. */
  23. struct module *owner;
  24. /**
  25. * @unregister:
  26. *
  27. * Called when &drm_device is unregistered. The client should respond by
  28. * releasing its resources using drm_client_release().
  29. *
  30. * This callback is optional.
  31. */
  32. void (*unregister)(struct drm_client_dev *client);
  33. /**
  34. * @restore:
  35. *
  36. * Called on drm_lastclose(). The first client instance in the list that
  37. * returns zero gets the privilege to restore and no more clients are
  38. * called. This callback is not called after @unregister has been called.
  39. *
  40. * Note that the core does not guarantee exclusion against concurrent
  41. * drm_open(). Clients need to ensure this themselves, for example by
  42. * using drm_master_internal_acquire() and
  43. * drm_master_internal_release().
  44. *
  45. * This callback is optional.
  46. */
  47. int (*restore)(struct drm_client_dev *client);
  48. /**
  49. * @hotplug:
  50. *
  51. * Called on drm_kms_helper_hotplug_event().
  52. * This callback is not called after @unregister has been called.
  53. *
  54. * This callback is optional.
  55. */
  56. int (*hotplug)(struct drm_client_dev *client);
  57. };
  58. /**
  59. * struct drm_client_dev - DRM client instance
  60. */
  61. struct drm_client_dev {
  62. /**
  63. * @dev: DRM device
  64. */
  65. struct drm_device *dev;
  66. /**
  67. * @name: Name of the client.
  68. */
  69. const char *name;
  70. /**
  71. * @list:
  72. *
  73. * List of all clients of a DRM device, linked into
  74. * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex.
  75. */
  76. struct list_head list;
  77. /**
  78. * @funcs: DRM client functions (optional)
  79. */
  80. const struct drm_client_funcs *funcs;
  81. /**
  82. * @file: DRM file
  83. */
  84. struct drm_file *file;
  85. /**
  86. * @modeset_mutex: Protects @modesets.
  87. */
  88. struct mutex modeset_mutex;
  89. /**
  90. * @modesets: CRTC configurations
  91. */
  92. struct drm_mode_set *modesets;
  93. };
  94. int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
  95. const char *name, const struct drm_client_funcs *funcs);
  96. void drm_client_release(struct drm_client_dev *client);
  97. void drm_client_register(struct drm_client_dev *client);
  98. void drm_client_dev_unregister(struct drm_device *dev);
  99. void drm_client_dev_hotplug(struct drm_device *dev);
  100. void drm_client_dev_restore(struct drm_device *dev);
  101. /**
  102. * struct drm_client_buffer - DRM client buffer
  103. */
  104. struct drm_client_buffer {
  105. /**
  106. * @client: DRM client
  107. */
  108. struct drm_client_dev *client;
  109. /**
  110. * @handle: Buffer handle
  111. */
  112. u32 handle;
  113. /**
  114. * @pitch: Buffer pitch
  115. */
  116. u32 pitch;
  117. /**
  118. * @gem: GEM object backing this buffer
  119. */
  120. struct drm_gem_object *gem;
  121. /**
  122. * @vaddr: Virtual address for the buffer
  123. */
  124. void *vaddr;
  125. /**
  126. * @fb: DRM framebuffer
  127. */
  128. struct drm_framebuffer *fb;
  129. };
  130. struct drm_client_buffer *
  131. drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
  132. void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
  133. int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect);
  134. void *drm_client_buffer_vmap(struct drm_client_buffer *buffer);
  135. void drm_client_buffer_vunmap(struct drm_client_buffer *buffer);
  136. int drm_client_modeset_create(struct drm_client_dev *client);
  137. void drm_client_modeset_free(struct drm_client_dev *client);
  138. int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height);
  139. bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation);
  140. int drm_client_modeset_check(struct drm_client_dev *client);
  141. int drm_client_modeset_commit_locked(struct drm_client_dev *client);
  142. int drm_client_modeset_commit(struct drm_client_dev *client);
  143. int drm_client_modeset_dpms(struct drm_client_dev *client, int mode);
  144. /**
  145. * drm_client_for_each_modeset() - Iterate over client modesets
  146. * @modeset: &drm_mode_set loop cursor
  147. * @client: DRM client
  148. */
  149. #define drm_client_for_each_modeset(modeset, client) \
  150. for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \
  151. modeset = (client)->modesets; modeset->crtc; modeset++)
  152. /**
  153. * drm_client_for_each_connector_iter - connector_list iterator macro
  154. * @connector: &struct drm_connector pointer used as cursor
  155. * @iter: &struct drm_connector_list_iter
  156. *
  157. * This iterates the connectors that are useable for internal clients (excludes
  158. * writeback connectors).
  159. *
  160. * For more info see drm_for_each_connector_iter().
  161. */
  162. #define drm_client_for_each_connector_iter(connector, iter) \
  163. drm_for_each_connector_iter(connector, iter) \
  164. if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
  165. void drm_client_debugfs_init(struct drm_minor *minor);
  166. #endif