2019-02-06 12:01:16 -02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
|
|
|
2018-05-14 17:33:46 +03:00
|
|
|
#ifndef _VKMS_DRV_H_
|
|
|
|
#define _VKMS_DRV_H_
|
|
|
|
|
2019-06-30 08:19:01 +02:00
|
|
|
#include <linux/hrtimer.h>
|
|
|
|
|
2018-05-16 20:56:21 -03:00
|
|
|
#include <drm/drm.h>
|
2022-06-14 12:54:49 +03:00
|
|
|
#include <drm/drm_framebuffer.h>
|
2018-07-11 23:01:47 -03:00
|
|
|
#include <drm/drm_gem.h>
|
2021-07-05 09:46:31 +02:00
|
|
|
#include <drm/drm_gem_atomic_helper.h>
|
2018-05-16 20:56:21 -03:00
|
|
|
#include <drm/drm_encoder.h>
|
2020-08-30 10:20:00 -04:00
|
|
|
#include <drm/drm_writeback.h>
|
2018-05-16 20:56:21 -03:00
|
|
|
|
2025-02-18 11:12:06 +01:00
|
|
|
#define DEFAULT_DEVICE_NAME "vkms"
|
|
|
|
|
2022-11-09 13:39:45 +02:00
|
|
|
#define XRES_MIN 10
|
|
|
|
#define YRES_MIN 10
|
2018-07-11 23:02:14 -03:00
|
|
|
|
|
|
|
#define XRES_DEF 1024
|
|
|
|
#define YRES_DEF 768
|
|
|
|
|
|
|
|
#define XRES_MAX 8192
|
|
|
|
#define YRES_MAX 8192
|
|
|
|
|
2022-01-07 19:28:08 +01:00
|
|
|
#define NUM_OVERLAY_PLANES 8
|
|
|
|
|
2023-07-08 22:38:35 -03:00
|
|
|
#define VKMS_LUT_SIZE 256
|
|
|
|
|
2024-09-05 15:27:06 +02:00
|
|
|
/**
|
|
|
|
* struct vkms_frame_info - Structure to store the state of a frame
|
|
|
|
*
|
|
|
|
* @fb: backing drm framebuffer
|
|
|
|
* @src: source rectangle of this frame in the source framebuffer, stored in 16.16 fixed-point form
|
|
|
|
* @dst: destination rectangle in the crtc buffer, stored in whole pixel units
|
|
|
|
* @map: see @drm_shadow_plane_state.data
|
|
|
|
* @rotation: rotation applied to the source.
|
|
|
|
*
|
|
|
|
* @src and @dst should have the same size modulo the rotation.
|
|
|
|
*/
|
2022-09-05 16:08:04 -03:00
|
|
|
struct vkms_frame_info {
|
2022-09-05 16:08:06 -03:00
|
|
|
struct drm_framebuffer *fb;
|
2018-09-06 08:18:26 +03:00
|
|
|
struct drm_rect src, dst;
|
2022-09-05 16:08:03 -03:00
|
|
|
struct iosys_map map[DRM_FORMAT_MAX_PLANES];
|
2023-04-18 10:05:22 -03:00
|
|
|
unsigned int rotation;
|
2018-08-02 04:10:26 +03:00
|
|
|
};
|
|
|
|
|
2025-04-15 15:55:32 +02:00
|
|
|
/**
|
|
|
|
* struct pixel_argb_u16 - Internal representation of a pixel color.
|
|
|
|
* @a: Alpha component value, stored in 16 bits, without padding, using
|
|
|
|
* machine endianness
|
|
|
|
* @r: Red component value, stored in 16 bits, without padding, using
|
|
|
|
* machine endianness
|
|
|
|
* @g: Green component value, stored in 16 bits, without padding, using
|
|
|
|
* machine endianness
|
|
|
|
* @b: Blue component value, stored in 16 bits, without padding, using
|
|
|
|
* machine endianness
|
|
|
|
*
|
|
|
|
* The goal of this structure is to keep enough precision to ensure
|
|
|
|
* correct composition results in VKMS and simplifying color
|
|
|
|
* manipulation by splitting each component into its own field.
|
|
|
|
* Caution: the byte ordering of this structure is machine-dependent,
|
|
|
|
* you can't cast it directly to AR48 or xR48.
|
|
|
|
*/
|
2022-09-05 16:08:07 -03:00
|
|
|
struct pixel_argb_u16 {
|
|
|
|
u16 a, r, g, b;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct line_buffer {
|
|
|
|
size_t n_pixels;
|
|
|
|
struct pixel_argb_u16 *pixels;
|
|
|
|
};
|
|
|
|
|
2024-11-18 19:28:18 +01:00
|
|
|
/**
|
|
|
|
* typedef pixel_write_t - These functions are used to read a pixel from a
|
|
|
|
* &struct pixel_argb_u16, convert it in a specific format and write it in the @out_pixel
|
|
|
|
* buffer.
|
|
|
|
*
|
|
|
|
* @out_pixel: destination address to write the pixel
|
|
|
|
* @in_pixel: pixel to write
|
|
|
|
*/
|
2024-11-18 19:28:19 +01:00
|
|
|
typedef void (*pixel_write_t)(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel);
|
2024-11-18 19:28:18 +01:00
|
|
|
|
2022-09-05 16:08:07 -03:00
|
|
|
struct vkms_writeback_job {
|
|
|
|
struct iosys_map data[DRM_FORMAT_MAX_PLANES];
|
|
|
|
struct vkms_frame_info wb_frame_info;
|
2024-11-18 19:28:18 +01:00
|
|
|
pixel_write_t pixel_write;
|
2022-09-05 16:08:07 -03:00
|
|
|
};
|
|
|
|
|
2024-11-18 19:28:22 +01:00
|
|
|
/**
|
|
|
|
* enum pixel_read_direction - Enum used internally by VKMS to represent a reading direction in a
|
|
|
|
* plane.
|
|
|
|
*/
|
|
|
|
enum pixel_read_direction {
|
|
|
|
READ_BOTTOM_TO_TOP,
|
|
|
|
READ_TOP_TO_BOTTOM,
|
|
|
|
READ_RIGHT_TO_LEFT,
|
|
|
|
READ_LEFT_TO_RIGHT
|
|
|
|
};
|
|
|
|
|
2024-11-18 19:28:23 +01:00
|
|
|
struct vkms_plane_state;
|
|
|
|
|
2024-11-18 19:28:18 +01:00
|
|
|
/**
|
2024-11-18 19:28:23 +01:00
|
|
|
* typedef pixel_read_line_t - These functions are used to read a pixel line in the source frame,
|
2024-11-18 19:28:18 +01:00
|
|
|
* convert it to `struct pixel_argb_u16` and write it to @out_pixel.
|
|
|
|
*
|
2024-11-18 19:28:23 +01:00
|
|
|
* @plane: plane used as source for the pixel value
|
|
|
|
* @x_start: X (width) coordinate of the first pixel to copy. The caller must ensure that x_start
|
|
|
|
* is non-negative and smaller than @plane->frame_info->fb->width.
|
|
|
|
* @y_start: Y (height) coordinate of the first pixel to copy. The caller must ensure that y_start
|
|
|
|
* is non-negative and smaller than @plane->frame_info->fb->height.
|
|
|
|
* @direction: direction to use for the copy, starting at @x_start/@y_start
|
|
|
|
* @count: number of pixels to copy
|
|
|
|
* @out_pixel: pointer where to write the pixel values. They will be written from @out_pixel[0]
|
|
|
|
* (included) to @out_pixel[@count] (excluded). The caller must ensure that out_pixel have a
|
|
|
|
* length of at least @count.
|
2024-11-18 19:28:18 +01:00
|
|
|
*/
|
2024-11-18 19:28:23 +01:00
|
|
|
typedef void (*pixel_read_line_t)(const struct vkms_plane_state *plane, int x_start,
|
|
|
|
int y_start, enum pixel_read_direction direction, int count,
|
|
|
|
struct pixel_argb_u16 out_pixel[]);
|
2024-11-18 19:28:18 +01:00
|
|
|
|
2025-04-15 15:55:33 +02:00
|
|
|
/**
|
|
|
|
* struct conversion_matrix - Matrix to use for a specific encoding and range
|
|
|
|
*
|
|
|
|
* @matrix: Conversion matrix from yuv to rgb. The matrix is stored in a row-major manner and is
|
|
|
|
* used to compute rgb values from yuv values:
|
|
|
|
* [[r],[g],[b]] = @matrix * [[y],[u],[v]]
|
|
|
|
* OR for yvu formats:
|
|
|
|
* [[r],[g],[b]] = @matrix * [[y],[v],[u]]
|
|
|
|
* The values of the matrix are signed fixed-point values with 32 bits fractional part.
|
|
|
|
* @y_offset: Offset to apply on the y value.
|
|
|
|
*/
|
|
|
|
struct conversion_matrix {
|
|
|
|
s64 matrix[3][3];
|
|
|
|
int y_offset;
|
|
|
|
};
|
|
|
|
|
2018-08-02 04:08:22 +03:00
|
|
|
/**
|
2024-09-05 15:27:06 +02:00
|
|
|
* struct vkms_plane_state - Driver specific plane state
|
2018-08-02 04:08:22 +03:00
|
|
|
* @base: base plane state
|
2022-09-05 16:08:04 -03:00
|
|
|
* @frame_info: data required for composing computation
|
2024-11-18 19:28:23 +01:00
|
|
|
* @pixel_read_line: function to read a pixel line in this plane. The creator of a
|
|
|
|
* struct vkms_plane_state must ensure that this pointer is valid
|
2025-04-15 15:55:33 +02:00
|
|
|
* @conversion_matrix: matrix used for yuv formats to convert to rgb
|
2018-08-02 04:08:22 +03:00
|
|
|
*/
|
|
|
|
struct vkms_plane_state {
|
2021-07-05 09:46:31 +02:00
|
|
|
struct drm_shadow_plane_state base;
|
2022-09-05 16:08:04 -03:00
|
|
|
struct vkms_frame_info *frame_info;
|
2024-11-18 19:28:23 +01:00
|
|
|
pixel_read_line_t pixel_read_line;
|
2025-04-15 15:55:33 +02:00
|
|
|
struct conversion_matrix conversion_matrix;
|
2018-08-02 04:08:22 +03:00
|
|
|
};
|
|
|
|
|
2021-04-24 05:23:27 -03:00
|
|
|
struct vkms_plane {
|
|
|
|
struct drm_plane base;
|
|
|
|
};
|
|
|
|
|
2023-07-08 22:38:35 -03:00
|
|
|
struct vkms_color_lut {
|
|
|
|
struct drm_color_lut *base;
|
|
|
|
size_t lut_length;
|
|
|
|
s64 channel_value2index_ratio;
|
|
|
|
};
|
|
|
|
|
2018-07-24 19:31:05 +03:00
|
|
|
/**
|
2024-09-05 15:27:06 +02:00
|
|
|
* struct vkms_crtc_state - Driver specific CRTC state
|
|
|
|
*
|
2018-07-24 19:31:05 +03:00
|
|
|
* @base: base CRTC state
|
2019-06-25 22:37:05 -03:00
|
|
|
* @composer_work: work struct to compose and add CRC entries
|
2024-09-05 15:27:06 +02:00
|
|
|
*
|
|
|
|
* @num_active_planes: Number of active planes
|
|
|
|
* @active_planes: List containing all the active planes (counted by
|
|
|
|
* @num_active_planes). They should be stored in z-order.
|
|
|
|
* @active_writeback: Current active writeback job
|
|
|
|
* @gamma_lut: Look up table for gamma used in this CRTC
|
|
|
|
* @crc_pending: Protected by @vkms_output.composer_lock, true when the frame CRC is not computed
|
|
|
|
* yet. Used by vblank to detect if the composer is too slow.
|
|
|
|
* @wb_pending: Protected by @vkms_output.composer_lock, true when a writeback frame is requested.
|
|
|
|
* @frame_start: Protected by @vkms_output.composer_lock, saves the frame number before the start
|
|
|
|
* of the composition process.
|
|
|
|
* @frame_end: Protected by @vkms_output.composer_lock, saves the last requested frame number.
|
|
|
|
* This is used to generate enough CRC entries when the composition worker is too slow.
|
2018-07-24 19:31:05 +03:00
|
|
|
*/
|
|
|
|
struct vkms_crtc_state {
|
|
|
|
struct drm_crtc_state base;
|
2019-06-25 22:37:05 -03:00
|
|
|
struct work_struct composer_work;
|
drm/vkms: Fix crc worker races
The issue we have is that the crc worker might fall behind. We've
tried to handle this by tracking both the earliest frame for which it
still needs to compute a crc, and the last one. Plus when the
crtc_state changes, we have a new work item, which are all run in
order due to the ordered workqueue we allocate for each vkms crtc.
Trouble is there's been a few small issues in the current code:
- we need to capture frame_end in the vblank hrtimer, not in the
worker. The worker might run much later, and then we generate a lot
of crc for which there's already a different worker queued up.
- frame number might be 0, so create a new crc_pending boolean to
track this without confusion.
- we need to atomically grab frame_start/end and clear it, so do that
all in one go. This is not going to create a new race, because if we
race with the hrtimer then our work will be re-run.
- only race that can happen is the following:
1. worker starts
2. hrtimer runs and updates frame_end
3. worker grabs frame_start/end, already reading the new frame_end,
and clears crc_pending
4. hrtimer calls queue_work()
5. worker completes
6. worker gets re-run, crc_pending is false
Explain this case a bit better by rewording the comment.
v2: Demote warning level output to debug when we fail to requeue, this
is expected under high load when the crc worker can't quite keep up.
Cc: Shayenne Moura <shayenneluzmoura@gmail.com>
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Tested-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190606222751.32567-2-daniel.vetter@ffwll.ch
2019-06-07 00:27:42 +02:00
|
|
|
|
drm/vkms: totally reworked crc data tracking
The crc computation worker needs to be able to get at some data
structures and framebuffer mappings, while potentially more atomic
updates are going on. The solution thus far is to copy relevant bits
around, but that's very tedious.
Here's a new approach, which tries to be more clever, but relies on a
few not-so-obvious things:
- crtc_state is always updated when a plane_state changes. Therefore
we can just stuff plane_state pointers into a crtc_state. That
solves the problem of easily getting at the needed plane_states.
- with the flushing changes from previous patches the above also holds
without races due to the next atomic update being a bit eager with
cleaning up pending work - we always wait for all crc work items to
complete before unmapping framebuffers.
- we also need to make sure that the hrtimer fires off the right
worker. Keep a new distinct crc_state pointer, under the
vkms_output->lock protection for this. Note that crtc->state is
updated very early in the atomic commit, way before we arm the
vblank event - the vblank event should always match the buffers we
use to compute the crc. This also solves an issue in the hrtimer,
where we've accessed drm_crtc->state without holding the right locks
(we held none - oops).
- in the worker itself we can then just access the plane states we
need, again solving a bunch of ordering and locking issues.
Accessing plane->state requires locks, accessing the private
vkms_crtc_state->active_planes pointer only requires that the memory
doesn't get freed too early.
The idea behind vkms_crtc_state->active_planes is that this would
contain all visible planes, in z-order, as a first step towards a more
generic blending implementation.
Note that this patch also fixes races between prepare_fb/cleanup_fb
and the crc worker accessing ->vaddr.
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Tested-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190606222751.32567-10-daniel.vetter@ffwll.ch
2019-06-07 00:27:50 +02:00
|
|
|
int num_active_planes;
|
|
|
|
struct vkms_plane_state **active_planes;
|
2021-07-30 20:35:11 +02:00
|
|
|
struct vkms_writeback_job *active_writeback;
|
2023-07-08 22:38:35 -03:00
|
|
|
struct vkms_color_lut gamma_lut;
|
drm/vkms: totally reworked crc data tracking
The crc computation worker needs to be able to get at some data
structures and framebuffer mappings, while potentially more atomic
updates are going on. The solution thus far is to copy relevant bits
around, but that's very tedious.
Here's a new approach, which tries to be more clever, but relies on a
few not-so-obvious things:
- crtc_state is always updated when a plane_state changes. Therefore
we can just stuff plane_state pointers into a crtc_state. That
solves the problem of easily getting at the needed plane_states.
- with the flushing changes from previous patches the above also holds
without races due to the next atomic update being a bit eager with
cleaning up pending work - we always wait for all crc work items to
complete before unmapping framebuffers.
- we also need to make sure that the hrtimer fires off the right
worker. Keep a new distinct crc_state pointer, under the
vkms_output->lock protection for this. Note that crtc->state is
updated very early in the atomic commit, way before we arm the
vblank event - the vblank event should always match the buffers we
use to compute the crc. This also solves an issue in the hrtimer,
where we've accessed drm_crtc->state without holding the right locks
(we held none - oops).
- in the worker itself we can then just access the plane states we
need, again solving a bunch of ordering and locking issues.
Accessing plane->state requires locks, accessing the private
vkms_crtc_state->active_planes pointer only requires that the memory
doesn't get freed too early.
The idea behind vkms_crtc_state->active_planes is that this would
contain all visible planes, in z-order, as a first step towards a more
generic blending implementation.
Note that this patch also fixes races between prepare_fb/cleanup_fb
and the crc worker accessing ->vaddr.
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Tested-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190606222751.32567-10-daniel.vetter@ffwll.ch
2019-06-07 00:27:50 +02:00
|
|
|
|
drm/vkms: Fix crc worker races
The issue we have is that the crc worker might fall behind. We've
tried to handle this by tracking both the earliest frame for which it
still needs to compute a crc, and the last one. Plus when the
crtc_state changes, we have a new work item, which are all run in
order due to the ordered workqueue we allocate for each vkms crtc.
Trouble is there's been a few small issues in the current code:
- we need to capture frame_end in the vblank hrtimer, not in the
worker. The worker might run much later, and then we generate a lot
of crc for which there's already a different worker queued up.
- frame number might be 0, so create a new crc_pending boolean to
track this without confusion.
- we need to atomically grab frame_start/end and clear it, so do that
all in one go. This is not going to create a new race, because if we
race with the hrtimer then our work will be re-run.
- only race that can happen is the following:
1. worker starts
2. hrtimer runs and updates frame_end
3. worker grabs frame_start/end, already reading the new frame_end,
and clears crc_pending
4. hrtimer calls queue_work()
5. worker completes
6. worker gets re-run, crc_pending is false
Explain this case a bit better by rewording the comment.
v2: Demote warning level output to debug when we fail to requeue, this
is expected under high load when the crc worker can't quite keep up.
Cc: Shayenne Moura <shayenneluzmoura@gmail.com>
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Tested-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190606222751.32567-2-daniel.vetter@ffwll.ch
2019-06-07 00:27:42 +02:00
|
|
|
bool crc_pending;
|
2020-08-30 10:20:00 -04:00
|
|
|
bool wb_pending;
|
2018-09-04 00:18:17 +03:00
|
|
|
u64 frame_start;
|
|
|
|
u64 frame_end;
|
2018-07-24 19:31:05 +03:00
|
|
|
};
|
|
|
|
|
2024-09-05 15:27:06 +02:00
|
|
|
/**
|
|
|
|
* struct vkms_output - Internal representation of all output components in VKMS
|
|
|
|
*
|
|
|
|
* @crtc: Base CRTC in DRM
|
|
|
|
* @encoder: DRM encoder used for this output
|
|
|
|
* @connector: DRM connector used for this output
|
|
|
|
* @wb_connecter: DRM writeback connector used for this output
|
|
|
|
* @vblank_hrtimer: Timer used to trigger the vblank
|
|
|
|
* @period_ns: vblank period, in nanoseconds, used to configure @vblank_hrtimer and to compute
|
|
|
|
* vblank timestamps
|
|
|
|
* @composer_workq: Ordered workqueue for @composer_state.composer_work.
|
|
|
|
* @lock: Lock used to protect concurrent access to the composer
|
|
|
|
* @composer_enabled: Protected by @lock, true when the VKMS composer is active (crc needed or
|
|
|
|
* writeback)
|
|
|
|
* @composer_state: Protected by @lock, current state of this VKMS output
|
|
|
|
* @composer_lock: Lock used internally to protect @composer_state members
|
|
|
|
*/
|
2018-05-16 20:56:21 -03:00
|
|
|
struct vkms_output {
|
|
|
|
struct drm_crtc crtc;
|
2020-08-30 10:20:00 -04:00
|
|
|
struct drm_writeback_connector wb_connector;
|
2025-01-16 18:47:20 +01:00
|
|
|
struct drm_encoder wb_encoder;
|
2018-07-11 23:02:26 -03:00
|
|
|
struct hrtimer vblank_hrtimer;
|
|
|
|
ktime_t period_ns;
|
2019-06-25 22:37:05 -03:00
|
|
|
struct workqueue_struct *composer_workq;
|
2018-08-02 04:10:26 +03:00
|
|
|
spinlock_t lock;
|
2019-06-07 00:27:44 +02:00
|
|
|
|
2019-06-25 22:37:05 -03:00
|
|
|
bool composer_enabled;
|
|
|
|
struct vkms_crtc_state *composer_state;
|
drm/vkms: totally reworked crc data tracking
The crc computation worker needs to be able to get at some data
structures and framebuffer mappings, while potentially more atomic
updates are going on. The solution thus far is to copy relevant bits
around, but that's very tedious.
Here's a new approach, which tries to be more clever, but relies on a
few not-so-obvious things:
- crtc_state is always updated when a plane_state changes. Therefore
we can just stuff plane_state pointers into a crtc_state. That
solves the problem of easily getting at the needed plane_states.
- with the flushing changes from previous patches the above also holds
without races due to the next atomic update being a bit eager with
cleaning up pending work - we always wait for all crc work items to
complete before unmapping framebuffers.
- we also need to make sure that the hrtimer fires off the right
worker. Keep a new distinct crc_state pointer, under the
vkms_output->lock protection for this. Note that crtc->state is
updated very early in the atomic commit, way before we arm the
vblank event - the vblank event should always match the buffers we
use to compute the crc. This also solves an issue in the hrtimer,
where we've accessed drm_crtc->state without holding the right locks
(we held none - oops).
- in the worker itself we can then just access the plane states we
need, again solving a bunch of ordering and locking issues.
Accessing plane->state requires locks, accessing the private
vkms_crtc_state->active_planes pointer only requires that the memory
doesn't get freed too early.
The idea behind vkms_crtc_state->active_planes is that this would
contain all visible planes, in z-order, as a first step towards a more
generic blending implementation.
Note that this patch also fixes races between prepare_fb/cleanup_fb
and the crc worker accessing ->vaddr.
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Tested-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190606222751.32567-10-daniel.vetter@ffwll.ch
2019-06-07 00:27:50 +02:00
|
|
|
|
2019-06-25 22:37:05 -03:00
|
|
|
spinlock_t composer_lock;
|
2018-05-16 20:56:21 -03:00
|
|
|
};
|
2018-05-14 17:33:46 +03:00
|
|
|
|
2025-02-18 11:12:04 +01:00
|
|
|
struct vkms_config;
|
2021-01-12 00:36:34 +05:30
|
|
|
|
2024-09-05 15:27:06 +02:00
|
|
|
/**
|
|
|
|
* struct vkms_device - Description of a VKMS device
|
|
|
|
*
|
|
|
|
* @drm - Base device in DRM
|
2025-07-01 12:49:48 +02:00
|
|
|
* @faux_dev - Associated faux device
|
2024-09-05 15:27:06 +02:00
|
|
|
* @output - Configuration and sub-components of the VKMS device
|
|
|
|
* @config: Configuration used in this VKMS device
|
|
|
|
*/
|
2018-05-14 17:33:46 +03:00
|
|
|
struct vkms_device {
|
|
|
|
struct drm_device drm;
|
2025-07-01 12:49:48 +02:00
|
|
|
struct faux_device *faux_dev;
|
2021-01-12 00:36:34 +05:30
|
|
|
const struct vkms_config *config;
|
2018-05-14 17:33:46 +03:00
|
|
|
};
|
|
|
|
|
2024-09-05 15:27:06 +02:00
|
|
|
/*
|
|
|
|
* The following helpers are used to convert a member of a struct into its parent.
|
|
|
|
*/
|
|
|
|
|
2018-07-11 23:02:26 -03:00
|
|
|
#define drm_crtc_to_vkms_output(target) \
|
|
|
|
container_of(target, struct vkms_output, crtc)
|
|
|
|
|
|
|
|
#define drm_device_to_vkms_device(target) \
|
|
|
|
container_of(target, struct vkms_device, drm)
|
|
|
|
|
2018-07-24 19:31:05 +03:00
|
|
|
#define to_vkms_crtc_state(target)\
|
|
|
|
container_of(target, struct vkms_crtc_state, base)
|
|
|
|
|
2018-08-02 04:08:22 +03:00
|
|
|
#define to_vkms_plane_state(target)\
|
2021-07-05 09:46:31 +02:00
|
|
|
container_of(target, struct vkms_plane_state, base.base)
|
2018-08-02 04:08:22 +03:00
|
|
|
|
2024-09-05 15:27:06 +02:00
|
|
|
/**
|
|
|
|
* vkms_crtc_init() - Initialize a CRTC for VKMS
|
|
|
|
* @dev: DRM device associated with the VKMS buffer
|
|
|
|
* @crtc: uninitialized CRTC device
|
|
|
|
* @primary: primary plane to attach to the CRTC
|
|
|
|
* @cursor: plane to attach to the CRTC
|
|
|
|
*/
|
2025-01-17 10:04:29 +01:00
|
|
|
struct vkms_output *vkms_crtc_init(struct drm_device *dev,
|
|
|
|
struct drm_plane *primary,
|
|
|
|
struct drm_plane *cursor);
|
2018-05-16 20:56:21 -03:00
|
|
|
|
2024-09-05 15:27:06 +02:00
|
|
|
/**
|
|
|
|
* vkms_output_init() - Initialize all sub-components needed for a VKMS device.
|
|
|
|
*
|
|
|
|
* @vkmsdev: VKMS device to initialize
|
|
|
|
*/
|
2024-11-19 14:34:04 +01:00
|
|
|
int vkms_output_init(struct vkms_device *vkmsdev);
|
2018-05-16 20:56:21 -03:00
|
|
|
|
2024-09-05 15:27:06 +02:00
|
|
|
/**
|
|
|
|
* vkms_plane_init() - Initialize a plane
|
|
|
|
*
|
|
|
|
* @vkmsdev: VKMS device containing the plane
|
|
|
|
* @type: type of plane to initialize
|
|
|
|
*/
|
2021-04-24 05:23:27 -03:00
|
|
|
struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
|
2024-11-19 14:34:04 +01:00
|
|
|
enum drm_plane_type type);
|
2018-05-16 20:56:21 -03:00
|
|
|
|
2018-08-02 04:10:26 +03:00
|
|
|
/* CRC Support */
|
2019-06-13 15:18:02 +03:00
|
|
|
const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
|
|
|
|
size_t *count);
|
2018-08-21 14:08:56 +05:30
|
|
|
int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name);
|
2018-08-21 14:08:55 +05:30
|
|
|
int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
|
|
|
|
size_t *values_cnt);
|
2019-06-25 22:37:05 -03:00
|
|
|
|
|
|
|
/* Composer Support */
|
|
|
|
void vkms_composer_worker(struct work_struct *work);
|
2020-08-30 10:20:00 -04:00
|
|
|
void vkms_set_composer(struct vkms_output *out, bool enabled);
|
2023-05-09 17:28:53 -03:00
|
|
|
void vkms_writeback_row(struct vkms_writeback_job *wb, const struct line_buffer *src_buffer, int y);
|
2020-08-30 10:20:00 -04:00
|
|
|
|
|
|
|
/* Writeback */
|
2025-01-17 10:04:29 +01:00
|
|
|
int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, struct vkms_output *vkms_out);
|
2018-08-02 04:10:26 +03:00
|
|
|
|
2018-05-14 17:33:46 +03:00
|
|
|
#endif /* _VKMS_DRV_H_ */
|