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