xref: /openbmc/linux/drivers/gpu/drm/vkms/vkms_drv.h (revision 9134211f)
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_framebuffer.h>
10 #include <drm/drm_gem.h>
11 #include <drm/drm_gem_atomic_helper.h>
12 #include <drm/drm_encoder.h>
13 #include <drm/drm_writeback.h>
14 
15 #define XRES_MIN    10
16 #define YRES_MIN    10
17 
18 #define XRES_DEF  1024
19 #define YRES_DEF   768
20 
21 #define XRES_MAX  8192
22 #define YRES_MAX  8192
23 
24 #define NUM_OVERLAY_PLANES 8
25 
26 struct vkms_frame_info {
27 	struct drm_framebuffer *fb;
28 	struct drm_rect src, dst;
29 	struct drm_rect rotated;
30 	struct iosys_map map[DRM_FORMAT_MAX_PLANES];
31 	unsigned int rotation;
32 	unsigned int offset;
33 	unsigned int pitch;
34 	unsigned int cpp;
35 };
36 
37 struct pixel_argb_u16 {
38 	u16 a, r, g, b;
39 };
40 
41 struct line_buffer {
42 	size_t n_pixels;
43 	struct pixel_argb_u16 *pixels;
44 };
45 
46 struct vkms_writeback_job {
47 	struct iosys_map data[DRM_FORMAT_MAX_PLANES];
48 	struct vkms_frame_info wb_frame_info;
49 	void (*wb_write)(struct vkms_frame_info *frame_info,
50 			 const struct line_buffer *buffer, int y);
51 };
52 
53 /**
54  * vkms_plane_state - Driver specific plane state
55  * @base: base plane state
56  * @frame_info: data required for composing computation
57  */
58 struct vkms_plane_state {
59 	struct drm_shadow_plane_state base;
60 	struct vkms_frame_info *frame_info;
61 	void (*pixel_read)(u8 *src_buffer, struct pixel_argb_u16 *out_pixel);
62 };
63 
64 struct vkms_plane {
65 	struct drm_plane base;
66 };
67 
68 /**
69  * vkms_crtc_state - Driver specific CRTC state
70  * @base: base CRTC state
71  * @composer_work: work struct to compose and add CRC entries
72  * @n_frame_start: start frame number for computed CRC
73  * @n_frame_end: end frame number for computed CRC
74  */
75 struct vkms_crtc_state {
76 	struct drm_crtc_state base;
77 	struct work_struct composer_work;
78 
79 	int num_active_planes;
80 	/* stack of active planes for crc computation, should be in z order */
81 	struct vkms_plane_state **active_planes;
82 	struct vkms_writeback_job *active_writeback;
83 
84 	/* below four are protected by vkms_output.composer_lock */
85 	bool crc_pending;
86 	bool wb_pending;
87 	u64 frame_start;
88 	u64 frame_end;
89 };
90 
91 struct vkms_output {
92 	struct drm_crtc crtc;
93 	struct drm_encoder encoder;
94 	struct drm_connector connector;
95 	struct drm_writeback_connector wb_connector;
96 	struct hrtimer vblank_hrtimer;
97 	ktime_t period_ns;
98 	struct drm_pending_vblank_event *event;
99 	/* ordered wq for composer_work */
100 	struct workqueue_struct *composer_workq;
101 	/* protects concurrent access to composer */
102 	spinlock_t lock;
103 
104 	/* protected by @lock */
105 	bool composer_enabled;
106 	struct vkms_crtc_state *composer_state;
107 
108 	spinlock_t composer_lock;
109 };
110 
111 struct vkms_device;
112 
113 struct vkms_config {
114 	bool writeback;
115 	bool cursor;
116 	bool overlay;
117 	/* only set when instantiated */
118 	struct vkms_device *dev;
119 };
120 
121 struct vkms_device {
122 	struct drm_device drm;
123 	struct platform_device *platform;
124 	struct vkms_output output;
125 	const struct vkms_config *config;
126 };
127 
128 #define drm_crtc_to_vkms_output(target) \
129 	container_of(target, struct vkms_output, crtc)
130 
131 #define drm_device_to_vkms_device(target) \
132 	container_of(target, struct vkms_device, drm)
133 
134 #define to_vkms_crtc_state(target)\
135 	container_of(target, struct vkms_crtc_state, base)
136 
137 #define to_vkms_plane_state(target)\
138 	container_of(target, struct vkms_plane_state, base.base)
139 
140 /* CRTC */
141 int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
142 		   struct drm_plane *primary, struct drm_plane *cursor);
143 
144 int vkms_output_init(struct vkms_device *vkmsdev, int index);
145 
146 struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
147 				   enum drm_plane_type type, int index);
148 
149 /* CRC Support */
150 const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
151 					size_t *count);
152 int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name);
153 int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
154 			   size_t *values_cnt);
155 
156 /* Composer Support */
157 void vkms_composer_worker(struct work_struct *work);
158 void vkms_set_composer(struct vkms_output *out, bool enabled);
159 void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state *plane, int y);
160 
161 /* Writeback */
162 int vkms_enable_writeback_connector(struct vkms_device *vkmsdev);
163 
164 #endif /* _VKMS_DRV_H_ */
165