/include/drm/drm_client.h

https://github.com/kvaneesh/linux · C Header · 196 lines · 67 code · 29 blank · 100 comment · 3 complexity · af7b3fe3180dccce82e7be4416c3d2d7 MD5 · raw file

  1. /* SPDX-License-Identifier: GPL-2.0 or MIT */
  2. #ifndef _DRM_CLIENT_H_
  3. #define _DRM_CLIENT_H_
  4. #include <linux/dma-buf-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 dma_buf_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, struct dma_buf_map *map);
  136. void drm_client_buffer_vunmap(struct drm_client_buffer *buffer);
  137. int drm_client_modeset_create(struct drm_client_dev *client);
  138. void drm_client_modeset_free(struct drm_client_dev *client);
  139. int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height);
  140. bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation);
  141. int drm_client_modeset_check(struct drm_client_dev *client);
  142. int drm_client_modeset_commit_locked(struct drm_client_dev *client);
  143. int drm_client_modeset_commit(struct drm_client_dev *client);
  144. int drm_client_modeset_dpms(struct drm_client_dev *client, int mode);
  145. /**
  146. * drm_client_for_each_modeset() - Iterate over client modesets
  147. * @modeset: &drm_mode_set loop cursor
  148. * @client: DRM client
  149. */
  150. #define drm_client_for_each_modeset(modeset, client) \
  151. for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \
  152. modeset = (client)->modesets; modeset->crtc; modeset++)
  153. /**
  154. * drm_client_for_each_connector_iter - connector_list iterator macro
  155. * @connector: &struct drm_connector pointer used as cursor
  156. * @iter: &struct drm_connector_list_iter
  157. *
  158. * This iterates the connectors that are useable for internal clients (excludes
  159. * writeback connectors).
  160. *
  161. * For more info see drm_for_each_connector_iter().
  162. */
  163. #define drm_client_for_each_connector_iter(connector, iter) \
  164. drm_for_each_connector_iter(connector, iter) \
  165. if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
  166. void drm_client_debugfs_init(struct drm_minor *minor);
  167. #endif