Linux Audio

Check our new training course

Loading...
v6.13.7
  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    10
 16#define YRES_MIN    10
 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#define VKMS_LUT_SIZE 256
 27
 28/**
 29 * struct vkms_frame_info - Structure to store the state of a frame
 30 *
 31 * @fb: backing drm framebuffer
 32 * @src: source rectangle of this frame in the source framebuffer, stored in 16.16 fixed-point form
 33 * @dst: destination rectangle in the crtc buffer, stored in whole pixel units
 34 * @map: see @drm_shadow_plane_state.data
 35 * @rotation: rotation applied to the source.
 36 *
 37 * @src and @dst should have the same size modulo the rotation.
 38 */
 39struct vkms_frame_info {
 40	struct drm_framebuffer *fb;
 41	struct drm_rect src, dst;
 42	struct drm_rect rotated;
 43	struct iosys_map map[DRM_FORMAT_MAX_PLANES];
 44	unsigned int rotation;
 45	unsigned int offset;
 46	unsigned int pitch;
 47	unsigned int cpp;
 48};
 49
 50struct pixel_argb_u16 {
 51	u16 a, r, g, b;
 52};
 53
 54struct line_buffer {
 55	size_t n_pixels;
 56	struct pixel_argb_u16 *pixels;
 57};
 58
 59struct vkms_writeback_job {
 60	struct iosys_map data[DRM_FORMAT_MAX_PLANES];
 61	struct vkms_frame_info wb_frame_info;
 62	void (*pixel_write)(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel);
 63};
 64
 65/**
 66 * struct vkms_plane_state - Driver specific plane state
 67 * @base: base plane state
 68 * @frame_info: data required for composing computation
 69 * @pixel_read: function to read a pixel in this plane. The creator of a struct vkms_plane_state
 70 *	        must ensure that this pointer is valid
 71 */
 72struct vkms_plane_state {
 73	struct drm_shadow_plane_state base;
 74	struct vkms_frame_info *frame_info;
 75	void (*pixel_read)(u8 *src_buffer, struct pixel_argb_u16 *out_pixel);
 76};
 77
 78struct vkms_plane {
 79	struct drm_plane base;
 80};
 81
 82struct vkms_color_lut {
 83	struct drm_color_lut *base;
 84	size_t lut_length;
 85	s64 channel_value2index_ratio;
 86};
 87
 88/**
 89 * struct vkms_crtc_state - Driver specific CRTC state
 90 *
 91 * @base: base CRTC state
 92 * @composer_work: work struct to compose and add CRC entries
 93 *
 94 * @num_active_planes: Number of active planes
 95 * @active_planes: List containing all the active planes (counted by
 96 *		   @num_active_planes). They should be stored in z-order.
 97 * @active_writeback: Current active writeback job
 98 * @gamma_lut: Look up table for gamma used in this CRTC
 99 * @crc_pending: Protected by @vkms_output.composer_lock, true when the frame CRC is not computed
100 *		 yet. Used by vblank to detect if the composer is too slow.
101 * @wb_pending: Protected by @vkms_output.composer_lock, true when a writeback frame is requested.
102 * @frame_start: Protected by @vkms_output.composer_lock, saves the frame number before the start
103 *		 of the composition process.
104 * @frame_end: Protected by @vkms_output.composer_lock, saves the last requested frame number.
105 *	       This is used to generate enough CRC entries when the composition worker is too slow.
106 */
107struct vkms_crtc_state {
108	struct drm_crtc_state base;
109	struct work_struct composer_work;
110
111	int num_active_planes;
 
112	struct vkms_plane_state **active_planes;
113	struct vkms_writeback_job *active_writeback;
114	struct vkms_color_lut gamma_lut;
115
 
116	bool crc_pending;
117	bool wb_pending;
118	u64 frame_start;
119	u64 frame_end;
120};
121
122/**
123 * struct vkms_output - Internal representation of all output components in VKMS
124 *
125 * @crtc: Base CRTC in DRM
126 * @encoder: DRM encoder used for this output
127 * @connector: DRM connector used for this output
128 * @wb_connecter: DRM writeback connector used for this output
129 * @vblank_hrtimer: Timer used to trigger the vblank
130 * @period_ns: vblank period, in nanoseconds, used to configure @vblank_hrtimer and to compute
131 *	       vblank timestamps
132 * @composer_workq: Ordered workqueue for @composer_state.composer_work.
133 * @lock: Lock used to protect concurrent access to the composer
134 * @composer_enabled: Protected by @lock, true when the VKMS composer is active (crc needed or
135 *		      writeback)
136 * @composer_state: Protected by @lock, current state of this VKMS output
137 * @composer_lock: Lock used internally to protect @composer_state members
138 */
139struct vkms_output {
140	struct drm_crtc crtc;
141	struct drm_encoder encoder;
142	struct drm_connector connector;
143	struct drm_writeback_connector wb_connector;
144	struct hrtimer vblank_hrtimer;
145	ktime_t period_ns;
 
 
146	struct workqueue_struct *composer_workq;
 
147	spinlock_t lock;
148
 
149	bool composer_enabled;
150	struct vkms_crtc_state *composer_state;
151
152	spinlock_t composer_lock;
153};
154
155/**
156 * struct vkms_config - General configuration for VKMS driver
157 *
158 * @writeback: If true, a writeback buffer can be attached to the CRTC
159 * @cursor: If true, a cursor plane is created in the VKMS device
160 * @overlay: If true, NUM_OVERLAY_PLANES will be created for the VKMS device
161 * @dev: Used to store the current VKMS device. Only set when the device is instantiated.
162 */
163struct vkms_config {
164	bool writeback;
165	bool cursor;
166	bool overlay;
167	struct vkms_device *dev;
168};
169
170/**
171 * struct vkms_device - Description of a VKMS device
172 *
173 * @drm - Base device in DRM
174 * @platform - Associated platform device
175 * @output - Configuration and sub-components of the VKMS device
176 * @config: Configuration used in this VKMS device
177 */
178struct vkms_device {
179	struct drm_device drm;
180	struct platform_device *platform;
181	struct vkms_output output;
182	const struct vkms_config *config;
183};
184
185/*
186 * The following helpers are used to convert a member of a struct into its parent.
187 */
 
 
 
 
188
189#define drm_crtc_to_vkms_output(target) \
190	container_of(target, struct vkms_output, crtc)
191
192#define drm_device_to_vkms_device(target) \
193	container_of(target, struct vkms_device, drm)
194
 
 
 
195#define to_vkms_crtc_state(target)\
196	container_of(target, struct vkms_crtc_state, base)
197
198#define to_vkms_plane_state(target)\
199	container_of(target, struct vkms_plane_state, base.base)
200
201/**
202 * vkms_crtc_init() - Initialize a CRTC for VKMS
203 * @dev: DRM device associated with the VKMS buffer
204 * @crtc: uninitialized CRTC device
205 * @primary: primary plane to attach to the CRTC
206 * @cursor: plane to attach to the CRTC
207 */
208int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
209		   struct drm_plane *primary, struct drm_plane *cursor);
210
211/**
212 * vkms_output_init() - Initialize all sub-components needed for a VKMS device.
213 *
214 * @vkmsdev: VKMS device to initialize
215 * @index: CRTC which can be attached to the planes. The caller must ensure that
216 *	   @index is positive and less or equals to 31.
217 */
218int vkms_output_init(struct vkms_device *vkmsdev, int index);
219
220/**
221 * vkms_plane_init() - Initialize a plane
222 *
223 * @vkmsdev: VKMS device containing the plane
224 * @type: type of plane to initialize
225 * @index: CRTC which can be attached to the plane. The caller must ensure that
226 *	   @index is positive and less or equals to 31.
227 */
228struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
229				   enum drm_plane_type type, int index);
 
 
 
 
 
 
 
 
 
230
231/* CRC Support */
232const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
233					size_t *count);
234int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name);
235int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
236			   size_t *values_cnt);
237
238/* Composer Support */
239void vkms_composer_worker(struct work_struct *work);
240void vkms_set_composer(struct vkms_output *out, bool enabled);
241void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state *plane, int y);
242void vkms_writeback_row(struct vkms_writeback_job *wb, const struct line_buffer *src_buffer, int y);
243
244/* Writeback */
245int vkms_enable_writeback_connector(struct vkms_device *vkmsdev);
246
247#endif /* _VKMS_DRV_H_ */
v5.4
  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
 12#define XRES_MIN    20
 13#define YRES_MIN    20
 14
 15#define XRES_DEF  1024
 16#define YRES_DEF   768
 17
 18#define XRES_MAX  8192
 19#define YRES_MAX  8192
 20
 21extern bool enable_cursor;
 22
 23struct vkms_composer {
 24	struct drm_framebuffer fb;
 
 
 
 
 
 
 
 
 
 
 
 
 
 25	struct drm_rect src, dst;
 
 
 
 26	unsigned int offset;
 27	unsigned int pitch;
 28	unsigned int cpp;
 29};
 30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 31/**
 32 * vkms_plane_state - Driver specific plane state
 33 * @base: base plane state
 34 * @composer: data required for composing computation
 
 
 35 */
 36struct vkms_plane_state {
 37	struct drm_plane_state base;
 38	struct vkms_composer *composer;
 
 
 
 
 
 
 
 
 
 
 
 39};
 40
 41/**
 42 * vkms_crtc_state - Driver specific CRTC state
 
 43 * @base: base CRTC state
 44 * @composer_work: work struct to compose and add CRC entries
 45 * @n_frame_start: start frame number for computed CRC
 46 * @n_frame_end: end frame number for computed CRC
 
 
 
 
 
 
 
 
 
 
 
 47 */
 48struct vkms_crtc_state {
 49	struct drm_crtc_state base;
 50	struct work_struct composer_work;
 51
 52	int num_active_planes;
 53	/* stack of active planes for crc computation, should be in z order */
 54	struct vkms_plane_state **active_planes;
 
 
 55
 56	/* below three are protected by vkms_output.composer_lock */
 57	bool crc_pending;
 
 58	u64 frame_start;
 59	u64 frame_end;
 60};
 61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 62struct vkms_output {
 63	struct drm_crtc crtc;
 64	struct drm_encoder encoder;
 65	struct drm_connector connector;
 
 66	struct hrtimer vblank_hrtimer;
 67	ktime_t period_ns;
 68	struct drm_pending_vblank_event *event;
 69	/* ordered wq for composer_work */
 70	struct workqueue_struct *composer_workq;
 71	/* protects concurrent access to composer */
 72	spinlock_t lock;
 73
 74	/* protected by @lock */
 75	bool composer_enabled;
 76	struct vkms_crtc_state *composer_state;
 77
 78	spinlock_t composer_lock;
 79};
 80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 81struct vkms_device {
 82	struct drm_device drm;
 83	struct platform_device *platform;
 84	struct vkms_output output;
 
 85};
 86
 87struct vkms_gem_object {
 88	struct drm_gem_object gem;
 89	struct mutex pages_lock; /* Page lock used in page fault handler */
 90	struct page **pages;
 91	unsigned int vmap_count;
 92	void *vaddr;
 93};
 94
 95#define drm_crtc_to_vkms_output(target) \
 96	container_of(target, struct vkms_output, crtc)
 97
 98#define drm_device_to_vkms_device(target) \
 99	container_of(target, struct vkms_device, drm)
100
101#define drm_gem_to_vkms_gem(target)\
102	container_of(target, struct vkms_gem_object, gem)
103
104#define to_vkms_crtc_state(target)\
105	container_of(target, struct vkms_crtc_state, base)
106
107#define to_vkms_plane_state(target)\
108	container_of(target, struct vkms_plane_state, base)
109
110/* CRTC */
 
 
 
 
 
 
111int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
112		   struct drm_plane *primary, struct drm_plane *cursor);
113
114bool vkms_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
115			       int *max_error, ktime_t *vblank_time,
116			       bool in_vblank_irq);
117
 
 
 
118int vkms_output_init(struct vkms_device *vkmsdev, int index);
119
120struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev,
121				  enum drm_plane_type type, int index);
122
123/* Gem stuff */
124struct drm_gem_object *vkms_gem_create(struct drm_device *dev,
125				       struct drm_file *file,
126				       u32 *handle,
127				       u64 size);
128
129vm_fault_t vkms_gem_fault(struct vm_fault *vmf);
130
131int vkms_dumb_create(struct drm_file *file, struct drm_device *dev,
132		     struct drm_mode_create_dumb *args);
133
134void vkms_gem_free_object(struct drm_gem_object *obj);
135
136int vkms_gem_vmap(struct drm_gem_object *obj);
137
138void vkms_gem_vunmap(struct drm_gem_object *obj);
139
140/* CRC Support */
141const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
142					size_t *count);
143int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name);
144int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
145			   size_t *values_cnt);
146
147/* Composer Support */
148void vkms_composer_worker(struct work_struct *work);
 
 
 
 
 
 
149
150#endif /* _VKMS_DRV_H_ */