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