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 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_composer { 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 * @composer: data required for composing computation 35 */ 36 struct vkms_plane_state { 37 struct drm_plane_state base; 38 struct vkms_composer *composer; 39 }; 40 41 /** 42 * vkms_crtc_state - Driver specific CRTC state 43 * @base: base CRTC state 44 * @composer_work: work struct to compose 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 composer_work; 51 52 int num_active_planes; 53 /* stack of active planes for crc computation, should be in z order */ 54 struct vkms_plane_state **active_planes; 55 56 /* below three are protected by vkms_output.composer_lock */ 57 bool crc_pending; 58 u64 frame_start; 59 u64 frame_end; 60 }; 61 62 struct vkms_output { 63 struct drm_crtc crtc; 64 struct drm_encoder encoder; 65 struct drm_connector connector; 66 struct hrtimer vblank_hrtimer; 67 ktime_t period_ns; 68 struct drm_pending_vblank_event *event; 69 /* ordered wq for composer_work */ 70 struct workqueue_struct *composer_workq; 71 /* protects concurrent access to composer */ 72 spinlock_t lock; 73 74 /* protected by @lock */ 75 bool composer_enabled; 76 struct vkms_crtc_state *composer_state; 77 78 spinlock_t composer_lock; 79 }; 80 81 struct vkms_device { 82 struct drm_device drm; 83 struct platform_device *platform; 84 struct vkms_output output; 85 }; 86 87 struct vkms_gem_object { 88 struct drm_gem_object gem; 89 struct mutex pages_lock; /* Page lock used in page fault handler */ 90 struct page **pages; 91 unsigned int vmap_count; 92 void *vaddr; 93 }; 94 95 #define drm_crtc_to_vkms_output(target) \ 96 container_of(target, struct vkms_output, crtc) 97 98 #define drm_device_to_vkms_device(target) \ 99 container_of(target, struct vkms_device, drm) 100 101 #define drm_gem_to_vkms_gem(target)\ 102 container_of(target, struct vkms_gem_object, gem) 103 104 #define to_vkms_crtc_state(target)\ 105 container_of(target, struct vkms_crtc_state, base) 106 107 #define to_vkms_plane_state(target)\ 108 container_of(target, struct vkms_plane_state, base) 109 110 /* CRTC */ 111 int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, 112 struct drm_plane *primary, struct drm_plane *cursor); 113 114 int vkms_output_init(struct vkms_device *vkmsdev, int index); 115 116 struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev, 117 enum drm_plane_type type, int index); 118 119 /* Gem stuff */ 120 vm_fault_t vkms_gem_fault(struct vm_fault *vmf); 121 122 int vkms_dumb_create(struct drm_file *file, struct drm_device *dev, 123 struct drm_mode_create_dumb *args); 124 125 void vkms_gem_free_object(struct drm_gem_object *obj); 126 127 int vkms_gem_vmap(struct drm_gem_object *obj); 128 129 void vkms_gem_vunmap(struct drm_gem_object *obj); 130 131 /* Prime */ 132 struct drm_gem_object * 133 vkms_prime_import_sg_table(struct drm_device *dev, 134 struct dma_buf_attachment *attach, 135 struct sg_table *sg); 136 137 /* CRC Support */ 138 const char *const *vkms_get_crc_sources(struct drm_crtc *crtc, 139 size_t *count); 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 144 /* Composer Support */ 145 void vkms_composer_worker(struct work_struct *work); 146 147 #endif /* _VKMS_DRV_H_ */ 148