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