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