vkms_drv.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. #ifndef _VKMS_DRV_H_
  3. #define _VKMS_DRV_H_
  4. #include <linux/hrtimer.h>
  5. #include <drm/drm.h>
  6. #include <drm/drm_framebuffer.h>
  7. #include <drm/drm_gem.h>
  8. #include <drm/drm_gem_atomic_helper.h>
  9. #include <drm/drm_encoder.h>
  10. #include <drm/drm_writeback.h>
  11. #define XRES_MIN 10
  12. #define YRES_MIN 10
  13. #define XRES_DEF 1024
  14. #define YRES_DEF 768
  15. #define XRES_MAX 8192
  16. #define YRES_MAX 8192
  17. #define NUM_OVERLAY_PLANES 8
  18. #define VKMS_LUT_SIZE 256
  19. struct vkms_frame_info {
  20. struct drm_framebuffer *fb;
  21. struct drm_rect src, dst;
  22. struct drm_rect rotated;
  23. struct iosys_map map[DRM_FORMAT_MAX_PLANES];
  24. unsigned int rotation;
  25. unsigned int offset;
  26. unsigned int pitch;
  27. unsigned int cpp;
  28. };
  29. struct pixel_argb_u16 {
  30. u16 a, r, g, b;
  31. };
  32. struct line_buffer {
  33. size_t n_pixels;
  34. struct pixel_argb_u16 *pixels;
  35. };
  36. struct vkms_writeback_job {
  37. struct iosys_map data[DRM_FORMAT_MAX_PLANES];
  38. struct vkms_frame_info wb_frame_info;
  39. void (*pixel_write)(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel);
  40. };
  41. /**
  42. * vkms_plane_state - Driver specific plane state
  43. * @base: base plane state
  44. * @frame_info: data required for composing computation
  45. */
  46. struct vkms_plane_state {
  47. struct drm_shadow_plane_state base;
  48. struct vkms_frame_info *frame_info;
  49. void (*pixel_read)(u8 *src_buffer, struct pixel_argb_u16 *out_pixel);
  50. };
  51. struct vkms_plane {
  52. struct drm_plane base;
  53. };
  54. struct vkms_color_lut {
  55. struct drm_color_lut *base;
  56. size_t lut_length;
  57. s64 channel_value2index_ratio;
  58. };
  59. /**
  60. * vkms_crtc_state - Driver specific CRTC state
  61. * @base: base CRTC state
  62. * @composer_work: work struct to compose and add CRC entries
  63. * @n_frame_start: start frame number for computed CRC
  64. * @n_frame_end: end frame number for computed CRC
  65. */
  66. struct vkms_crtc_state {
  67. struct drm_crtc_state base;
  68. struct work_struct composer_work;
  69. int num_active_planes;
  70. /* stack of active planes for crc computation, should be in z order */
  71. struct vkms_plane_state **active_planes;
  72. struct vkms_writeback_job *active_writeback;
  73. struct vkms_color_lut gamma_lut;
  74. /* below four are protected by vkms_output.composer_lock */
  75. bool crc_pending;
  76. bool wb_pending;
  77. u64 frame_start;
  78. u64 frame_end;
  79. };
  80. struct vkms_output {
  81. struct drm_crtc crtc;
  82. struct drm_encoder encoder;
  83. struct drm_connector connector;
  84. struct drm_writeback_connector wb_connector;
  85. struct hrtimer vblank_hrtimer;
  86. ktime_t period_ns;
  87. /* ordered wq for composer_work */
  88. struct workqueue_struct *composer_workq;
  89. /* protects concurrent access to composer */
  90. spinlock_t lock;
  91. /* protected by @lock */
  92. bool composer_enabled;
  93. struct vkms_crtc_state *composer_state;
  94. spinlock_t composer_lock;
  95. };
  96. struct vkms_device;
  97. struct vkms_config {
  98. bool writeback;
  99. bool cursor;
  100. bool overlay;
  101. /* only set when instantiated */
  102. struct vkms_device *dev;
  103. };
  104. struct vkms_device {
  105. struct drm_device drm;
  106. struct platform_device *platform;
  107. struct vkms_output output;
  108. const struct vkms_config *config;
  109. };
  110. #define drm_crtc_to_vkms_output(target) \
  111. container_of(target, struct vkms_output, crtc)
  112. #define drm_device_to_vkms_device(target) \
  113. container_of(target, struct vkms_device, drm)
  114. #define to_vkms_crtc_state(target)\
  115. container_of(target, struct vkms_crtc_state, base)
  116. #define to_vkms_plane_state(target)\
  117. container_of(target, struct vkms_plane_state, base.base)
  118. /* CRTC */
  119. int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
  120. struct drm_plane *primary, struct drm_plane *cursor);
  121. int vkms_output_init(struct vkms_device *vkmsdev, int index);
  122. struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
  123. enum drm_plane_type type, int index);
  124. /* CRC Support */
  125. const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
  126. size_t *count);
  127. int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name);
  128. int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
  129. size_t *values_cnt);
  130. /* Composer Support */
  131. void vkms_composer_worker(struct work_struct *work);
  132. void vkms_set_composer(struct vkms_output *out, bool enabled);
  133. void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state *plane, int y);
  134. void vkms_writeback_row(struct vkms_writeback_job *wb, const struct line_buffer *src_buffer, int y);
  135. /* Writeback */
  136. int vkms_enable_writeback_connector(struct vkms_device *vkmsdev);
  137. #endif /* _VKMS_DRV_H_ */