drm_framebuffer.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (c) 2016 Intel Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that copyright
  7. * notice and this permission notice appear in supporting documentation, and
  8. * that the name of the copyright holders not be used in advertising or
  9. * publicity pertaining to distribution of the software without specific,
  10. * written prior permission. The copyright holders make no representations
  11. * about the suitability of this software for any purpose. It is provided "as
  12. * is" without express or implied warranty.
  13. *
  14. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THIS SOFTWARE.
  21. */
  22. #ifndef __DRM_FRAMEBUFFER_H__
  23. #define __DRM_FRAMEBUFFER_H__
  24. #include <linux/list.h>
  25. #include <linux/ctype.h>
  26. #include <drm/drm_modeset.h>
  27. struct drm_framebuffer;
  28. struct drm_file;
  29. struct drm_device;
  30. /**
  31. * struct drm_framebuffer_funcs - framebuffer hooks
  32. */
  33. struct drm_framebuffer_funcs {
  34. /**
  35. * @destroy:
  36. *
  37. * Clean up framebuffer resources, specifically also unreference the
  38. * backing storage. The core guarantees to call this function for every
  39. * framebuffer successfully created by ->fb_create() in
  40. * &drm_mode_config_funcs. Drivers must also call
  41. * drm_framebuffer_cleanup() to release DRM core resources for this
  42. * framebuffer.
  43. */
  44. void (*destroy)(struct drm_framebuffer *framebuffer);
  45. /**
  46. * @create_handle:
  47. *
  48. * Create a buffer handle in the driver-specific buffer manager (either
  49. * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
  50. * the core to implement the GETFB IOCTL, which returns (for
  51. * sufficiently priviledged user) also a native buffer handle. This can
  52. * be used for seamless transitions between modesetting clients by
  53. * copying the current screen contents to a private buffer and blending
  54. * between that and the new contents.
  55. *
  56. * GEM based drivers should call drm_gem_handle_create() to create the
  57. * handle.
  58. *
  59. * RETURNS:
  60. *
  61. * 0 on success or a negative error code on failure.
  62. */
  63. int (*create_handle)(struct drm_framebuffer *fb,
  64. struct drm_file *file_priv,
  65. unsigned int *handle);
  66. /**
  67. * @dirty:
  68. *
  69. * Optional callback for the dirty fb IOCTL.
  70. *
  71. * Userspace can notify the driver via this callback that an area of the
  72. * framebuffer has changed and should be flushed to the display
  73. * hardware. This can also be used internally, e.g. by the fbdev
  74. * emulation, though that's not the case currently.
  75. *
  76. * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
  77. * for more information as all the semantics and arguments have a one to
  78. * one mapping on this function.
  79. *
  80. * RETURNS:
  81. *
  82. * 0 on success or a negative error code on failure.
  83. */
  84. int (*dirty)(struct drm_framebuffer *framebuffer,
  85. struct drm_file *file_priv, unsigned flags,
  86. unsigned color, struct drm_clip_rect *clips,
  87. unsigned num_clips);
  88. };
  89. struct drm_framebuffer {
  90. struct drm_device *dev;
  91. /*
  92. * Note that the fb is refcounted for the benefit of driver internals,
  93. * for example some hw, disabling a CRTC/plane is asynchronous, and
  94. * scanout does not actually complete until the next vblank. So some
  95. * cleanup (like releasing the reference(s) on the backing GEM bo(s))
  96. * should be deferred. In cases like this, the driver would like to
  97. * hold a ref to the fb even though it has already been removed from
  98. * userspace perspective.
  99. * The refcount is stored inside the mode object.
  100. */
  101. /*
  102. * Place on the dev->mode_config.fb_list, access protected by
  103. * dev->mode_config.fb_lock.
  104. */
  105. struct list_head head;
  106. struct drm_mode_object base;
  107. const struct drm_framebuffer_funcs *funcs;
  108. unsigned int pitches[4];
  109. unsigned int offsets[4];
  110. uint64_t modifier[4];
  111. unsigned int width;
  112. unsigned int height;
  113. /* depth can be 15 or 16 */
  114. unsigned int depth;
  115. int bits_per_pixel;
  116. int flags;
  117. uint32_t pixel_format; /* fourcc format */
  118. int hot_x;
  119. int hot_y;
  120. struct list_head filp_head;
  121. };
  122. int drm_framebuffer_init(struct drm_device *dev,
  123. struct drm_framebuffer *fb,
  124. const struct drm_framebuffer_funcs *funcs);
  125. struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
  126. uint32_t id);
  127. void drm_framebuffer_remove(struct drm_framebuffer *fb);
  128. void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
  129. void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
  130. /**
  131. * drm_framebuffer_reference - incr the fb refcnt
  132. * @fb: framebuffer
  133. *
  134. * This functions increments the fb's refcount.
  135. */
  136. static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
  137. {
  138. drm_mode_object_reference(&fb->base);
  139. }
  140. /**
  141. * drm_framebuffer_unreference - unref a framebuffer
  142. * @fb: framebuffer to unref
  143. *
  144. * This functions decrements the fb's refcount and frees it if it drops to zero.
  145. */
  146. static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
  147. {
  148. drm_mode_object_unreference(&fb->base);
  149. }
  150. /**
  151. * drm_framebuffer_read_refcount - read the framebuffer reference count.
  152. * @fb: framebuffer
  153. *
  154. * This functions returns the framebuffer's reference count.
  155. */
  156. static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
  157. {
  158. return atomic_read(&fb->base.refcount.refcount);
  159. }
  160. #endif