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_gem.h> 10 #include <drm/drm_encoder.h> 11 #include <drm/drm_writeback.h> 12 13 #define XRES_MIN 20 14 #define YRES_MIN 20 15 16 #define XRES_DEF 1024 17 #define YRES_DEF 768 18 19 #define XRES_MAX 8192 20 #define YRES_MAX 8192 21 22 extern bool enable_cursor; 23 24 struct vkms_composer { 25 struct drm_framebuffer fb; 26 struct drm_rect src, dst; 27 unsigned int offset; 28 unsigned int pitch; 29 unsigned int cpp; 30 }; 31 32 /** 33 * vkms_plane_state - Driver specific plane state 34 * @base: base plane state 35 * @composer: data required for composing computation 36 */ 37 struct vkms_plane_state { 38 struct drm_plane_state base; 39 struct vkms_composer *composer; 40 }; 41 42 /** 43 * vkms_crtc_state - Driver specific CRTC state 44 * @base: base CRTC state 45 * @composer_work: work struct to compose and add CRC entries 46 * @n_frame_start: start frame number for computed CRC 47 * @n_frame_end: end frame number for computed CRC 48 */ 49 struct vkms_crtc_state { 50 struct drm_crtc_state base; 51 struct work_struct composer_work; 52 53 int num_active_planes; 54 /* stack of active planes for crc computation, should be in z order */ 55 struct vkms_plane_state **active_planes; 56 void *active_writeback; 57 58 /* below four are protected by vkms_output.composer_lock */ 59 bool crc_pending; 60 bool wb_pending; 61 u64 frame_start; 62 u64 frame_end; 63 }; 64 65 struct vkms_output { 66 struct drm_crtc crtc; 67 struct drm_encoder encoder; 68 struct drm_connector connector; 69 struct drm_writeback_connector wb_connector; 70 struct hrtimer vblank_hrtimer; 71 ktime_t period_ns; 72 struct drm_pending_vblank_event *event; 73 /* ordered wq for composer_work */ 74 struct workqueue_struct *composer_workq; 75 /* protects concurrent access to composer */ 76 spinlock_t lock; 77 78 /* protected by @lock */ 79 bool composer_enabled; 80 struct vkms_crtc_state *composer_state; 81 82 spinlock_t composer_lock; 83 }; 84 85 struct vkms_device { 86 struct drm_device drm; 87 struct platform_device *platform; 88 struct vkms_output output; 89 }; 90 91 struct vkms_gem_object { 92 struct drm_gem_object gem; 93 struct mutex pages_lock; /* Page lock used in page fault handler */ 94 struct page **pages; 95 unsigned int vmap_count; 96 void *vaddr; 97 }; 98 99 #define drm_crtc_to_vkms_output(target) \ 100 container_of(target, struct vkms_output, crtc) 101 102 #define drm_device_to_vkms_device(target) \ 103 container_of(target, struct vkms_device, drm) 104 105 #define drm_gem_to_vkms_gem(target)\ 106 container_of(target, struct vkms_gem_object, gem) 107 108 #define to_vkms_crtc_state(target)\ 109 container_of(target, struct vkms_crtc_state, base) 110 111 #define to_vkms_plane_state(target)\ 112 container_of(target, struct vkms_plane_state, base) 113 114 /* CRTC */ 115 int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, 116 struct drm_plane *primary, struct drm_plane *cursor); 117 118 int vkms_output_init(struct vkms_device *vkmsdev, int index); 119 120 struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev, 121 enum drm_plane_type type, int index); 122 123 /* Gem stuff */ 124 vm_fault_t vkms_gem_fault(struct vm_fault *vmf); 125 126 int vkms_dumb_create(struct drm_file *file, struct drm_device *dev, 127 struct drm_mode_create_dumb *args); 128 129 void vkms_gem_free_object(struct drm_gem_object *obj); 130 131 int vkms_gem_vmap(struct drm_gem_object *obj); 132 133 void vkms_gem_vunmap(struct drm_gem_object *obj); 134 135 /* Prime */ 136 struct drm_gem_object * 137 vkms_prime_import_sg_table(struct drm_device *dev, 138 struct dma_buf_attachment *attach, 139 struct sg_table *sg); 140 141 /* CRC Support */ 142 const char *const *vkms_get_crc_sources(struct drm_crtc *crtc, 143 size_t *count); 144 int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name); 145 int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name, 146 size_t *values_cnt); 147 148 /* Composer Support */ 149 void vkms_composer_worker(struct work_struct *work); 150 void vkms_set_composer(struct vkms_output *out, bool enabled); 151 152 /* Writeback */ 153 int vkms_enable_writeback_connector(struct vkms_device *vkmsdev); 154 155 #endif /* _VKMS_DRV_H_ */ 156