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