drm_client.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
  96. const char *name, const struct drm_client_funcs *funcs);
  97. void drm_client_release(struct drm_client_dev *client);
  98. void drm_client_register(struct drm_client_dev *client);
  99. void drm_client_dev_unregister(struct drm_device *dev);
  100. void drm_client_dev_hotplug(struct drm_device *dev);
  101. void drm_client_dev_restore(struct drm_device *dev);
  102. /**
  103. * struct drm_client_buffer - DRM client buffer
  104. */
  105. struct drm_client_buffer {
  106. /**
  107. * @client: DRM client
  108. */
  109. struct drm_client_dev *client;
  110. /**
  111. * @handle: Buffer handle
  112. */
  113. u32 handle;
  114. /**
  115. * @pitch: Buffer pitch
  116. */
  117. u32 pitch;
  118. /**
  119. * @gem: GEM object backing this buffer
  120. */
  121. struct drm_gem_object *gem;
  122. /**
  123. * @map: Virtual address for the buffer
  124. */
  125. struct iosys_map map;
  126. /**
  127. * @fb: DRM framebuffer
  128. */
  129. struct drm_framebuffer *fb;
  130. };
  131. struct drm_client_buffer *
  132. drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
  133. void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
  134. int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect);
  135. int drm_client_buffer_vmap(struct drm_client_buffer *buffer,
  136. struct iosys_map *map);
  137. void drm_client_buffer_vunmap(struct drm_client_buffer *buffer);
  138. int drm_client_modeset_create(struct drm_client_dev *client);
  139. void drm_client_modeset_free(struct drm_client_dev *client);
  140. int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height);
  141. bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation);
  142. int drm_client_modeset_check(struct drm_client_dev *client);
  143. int drm_client_modeset_commit_locked(struct drm_client_dev *client);
  144. int drm_client_modeset_commit(struct drm_client_dev *client);
  145. int drm_client_modeset_dpms(struct drm_client_dev *client, int mode);
  146. /**
  147. * drm_client_for_each_modeset() - Iterate over client modesets
  148. * @modeset: &drm_mode_set loop cursor
  149. * @client: DRM client
  150. */
  151. #define drm_client_for_each_modeset(modeset, client) \
  152. for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \
  153. modeset = (client)->modesets; modeset->crtc; modeset++)
  154. /**
  155. * drm_client_for_each_connector_iter - connector_list iterator macro
  156. * @connector: &struct drm_connector pointer used as cursor
  157. * @iter: &struct drm_connector_list_iter
  158. *
  159. * This iterates the connectors that are useable for internal clients (excludes
  160. * writeback connectors).
  161. *
  162. * For more info see drm_for_each_connector_iter().
  163. */
  164. #define drm_client_for_each_connector_iter(connector, iter) \
  165. drm_for_each_connector_iter(connector, iter) \
  166. if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
  167. void drm_client_debugfs_init(struct drm_minor *minor);
  168. #endif