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