1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 3 #ifndef _VKMS_DRV_H_ 4 #define _VKMS_DRV_H_ 5 6 #include <drm/drmP.h> 7 #include <drm/drm.h> 8 #include <drm/drm_gem.h> 9 #include <drm/drm_encoder.h> 10 #include <linux/hrtimer.h> 11 12 #define XRES_MIN 20 13 #define YRES_MIN 20 14 15 #define XRES_DEF 1024 16 #define YRES_DEF 768 17 18 #define XRES_MAX 8192 19 #define YRES_MAX 8192 20 21 extern bool enable_cursor; 22 23 struct vkms_crc_data { 24 struct drm_framebuffer fb; 25 struct drm_rect src, dst; 26 unsigned int offset; 27 unsigned int pitch; 28 unsigned int cpp; 29 }; 30 31 /** 32 * vkms_plane_state - Driver specific plane state 33 * @base: base plane state 34 * @crc_data: data required for CRC computation 35 */ 36 struct vkms_plane_state { 37 struct drm_plane_state base; 38 struct vkms_crc_data *crc_data; 39 }; 40 41 /** 42 * vkms_crtc_state - Driver specific CRTC state 43 * @base: base CRTC state 44 * @crc_work: work struct to compute and add CRC entries 45 * @n_frame_start: start frame number for computed CRC 46 * @n_frame_end: end frame number for computed CRC 47 */ 48 struct vkms_crtc_state { 49 struct drm_crtc_state base; 50 struct work_struct crc_work; 51 u64 frame_start; 52 u64 frame_end; 53 }; 54 55 struct vkms_output { 56 struct drm_crtc crtc; 57 struct drm_encoder encoder; 58 struct drm_connector connector; 59 struct hrtimer vblank_hrtimer; 60 ktime_t period_ns; 61 struct drm_pending_vblank_event *event; 62 bool crc_enabled; 63 /* ordered wq for crc_work */ 64 struct workqueue_struct *crc_workq; 65 /* protects concurrent access to crc_data */ 66 spinlock_t lock; 67 /* protects concurrent access to crtc_state */ 68 spinlock_t state_lock; 69 }; 70 71 struct vkms_device { 72 struct drm_device drm; 73 struct platform_device *platform; 74 struct vkms_output output; 75 }; 76 77 struct vkms_gem_object { 78 struct drm_gem_object gem; 79 struct mutex pages_lock; /* Page lock used in page fault handler */ 80 struct page **pages; 81 unsigned int vmap_count; 82 void *vaddr; 83 }; 84 85 #define drm_crtc_to_vkms_output(target) \ 86 container_of(target, struct vkms_output, crtc) 87 88 #define drm_device_to_vkms_device(target) \ 89 container_of(target, struct vkms_device, drm) 90 91 #define drm_gem_to_vkms_gem(target)\ 92 container_of(target, struct vkms_gem_object, gem) 93 94 #define to_vkms_crtc_state(target)\ 95 container_of(target, struct vkms_crtc_state, base) 96 97 #define to_vkms_plane_state(target)\ 98 container_of(target, struct vkms_plane_state, base) 99 100 /* CRTC */ 101 int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, 102 struct drm_plane *primary, struct drm_plane *cursor); 103 104 bool vkms_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe, 105 int *max_error, ktime_t *vblank_time, 106 bool in_vblank_irq); 107 108 int vkms_output_init(struct vkms_device *vkmsdev); 109 110 struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev, 111 enum drm_plane_type type); 112 113 /* Gem stuff */ 114 struct drm_gem_object *vkms_gem_create(struct drm_device *dev, 115 struct drm_file *file, 116 u32 *handle, 117 u64 size); 118 119 vm_fault_t vkms_gem_fault(struct vm_fault *vmf); 120 121 int vkms_dumb_create(struct drm_file *file, struct drm_device *dev, 122 struct drm_mode_create_dumb *args); 123 124 void vkms_gem_free_object(struct drm_gem_object *obj); 125 126 int vkms_gem_vmap(struct drm_gem_object *obj); 127 128 void vkms_gem_vunmap(struct drm_gem_object *obj); 129 130 /* CRC Support */ 131 const char *const *vkms_get_crc_sources(struct drm_crtc *crtc, 132 size_t *count); 133 int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name); 134 int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name, 135 size_t *values_cnt); 136 void vkms_crc_work_handle(struct work_struct *work); 137 138 #endif /* _VKMS_DRV_H_ */ 139