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