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