2019-02-06 12:01:16 -02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2018-05-16 20:56:21 -03:00
|
|
|
|
2022-02-04 09:05:41 -08:00
|
|
|
#include <linux/iosys-map.h>
|
2020-11-03 10:30:11 +01:00
|
|
|
|
2018-07-24 19:30:22 +03:00
|
|
|
#include <drm/drm_atomic.h>
|
2018-05-16 20:56:21 -03:00
|
|
|
#include <drm/drm_atomic_helper.h>
|
2023-04-18 10:05:22 -03:00
|
|
|
#include <drm/drm_blend.h>
|
2019-06-30 08:19:01 +02:00
|
|
|
#include <drm/drm_fourcc.h>
|
2021-02-22 15:17:56 +01:00
|
|
|
#include <drm/drm_gem_atomic_helper.h>
|
2018-07-24 19:29:23 +03:00
|
|
|
#include <drm/drm_gem_framebuffer_helper.h>
|
2019-06-30 08:19:01 +02:00
|
|
|
|
|
|
|
#include "vkms_drv.h"
|
2022-09-05 16:08:08 -03:00
|
|
|
#include "vkms_formats.h"
|
2018-05-16 20:56:21 -03:00
|
|
|
|
2019-06-07 00:27:45 +02:00
|
|
|
static const u32 vkms_formats[] = {
|
|
|
|
DRM_FORMAT_ARGB8888,
|
2022-09-05 16:08:10 -03:00
|
|
|
DRM_FORMAT_XRGB8888,
|
2025-01-29 14:20:58 +00:00
|
|
|
DRM_FORMAT_ABGR8888,
|
2022-09-05 16:08:10 -03:00
|
|
|
DRM_FORMAT_XRGB16161616,
|
2022-09-05 16:08:11 -03:00
|
|
|
DRM_FORMAT_ARGB16161616,
|
2025-04-15 15:55:33 +02:00
|
|
|
DRM_FORMAT_RGB565,
|
|
|
|
DRM_FORMAT_NV12,
|
|
|
|
DRM_FORMAT_NV16,
|
|
|
|
DRM_FORMAT_NV24,
|
|
|
|
DRM_FORMAT_NV21,
|
|
|
|
DRM_FORMAT_NV61,
|
|
|
|
DRM_FORMAT_NV42,
|
|
|
|
DRM_FORMAT_YUV420,
|
|
|
|
DRM_FORMAT_YUV422,
|
|
|
|
DRM_FORMAT_YUV444,
|
|
|
|
DRM_FORMAT_YVU420,
|
|
|
|
DRM_FORMAT_YVU422,
|
|
|
|
DRM_FORMAT_YVU444,
|
2025-04-15 15:55:39 +02:00
|
|
|
DRM_FORMAT_R1,
|
|
|
|
DRM_FORMAT_R2,
|
|
|
|
DRM_FORMAT_R4,
|
|
|
|
DRM_FORMAT_R8,
|
2019-06-07 00:27:45 +02:00
|
|
|
};
|
|
|
|
|
2018-08-02 04:08:22 +03:00
|
|
|
static struct drm_plane_state *
|
|
|
|
vkms_plane_duplicate_state(struct drm_plane *plane)
|
|
|
|
{
|
|
|
|
struct vkms_plane_state *vkms_state;
|
2022-09-05 16:08:04 -03:00
|
|
|
struct vkms_frame_info *frame_info;
|
2018-08-02 04:08:22 +03:00
|
|
|
|
|
|
|
vkms_state = kzalloc(sizeof(*vkms_state), GFP_KERNEL);
|
|
|
|
if (!vkms_state)
|
|
|
|
return NULL;
|
|
|
|
|
2022-09-05 16:08:04 -03:00
|
|
|
frame_info = kzalloc(sizeof(*frame_info), GFP_KERNEL);
|
|
|
|
if (!frame_info) {
|
|
|
|
DRM_DEBUG_KMS("Couldn't allocate frame_info\n");
|
2018-11-28 11:10:33 +01:00
|
|
|
kfree(vkms_state);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-08-02 04:10:26 +03:00
|
|
|
|
2022-09-05 16:08:04 -03:00
|
|
|
vkms_state->frame_info = frame_info;
|
2018-08-02 04:10:26 +03:00
|
|
|
|
2021-07-05 09:46:31 +02:00
|
|
|
__drm_gem_duplicate_shadow_plane_state(plane, &vkms_state->base);
|
2018-08-02 04:08:22 +03:00
|
|
|
|
2021-07-05 09:46:31 +02:00
|
|
|
return &vkms_state->base.base;
|
2018-08-02 04:08:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vkms_plane_destroy_state(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *old_state)
|
|
|
|
{
|
|
|
|
struct vkms_plane_state *vkms_state = to_vkms_plane_state(old_state);
|
2021-07-05 09:46:31 +02:00
|
|
|
struct drm_crtc *crtc = vkms_state->base.base.crtc;
|
2018-08-02 04:10:26 +03:00
|
|
|
|
2022-09-05 16:08:06 -03:00
|
|
|
if (crtc && vkms_state->frame_info->fb) {
|
2018-08-02 04:10:26 +03:00
|
|
|
/* dropping the reference we acquired in
|
|
|
|
* vkms_primary_plane_update()
|
|
|
|
*/
|
2022-09-05 16:08:06 -03:00
|
|
|
if (drm_framebuffer_read_refcount(vkms_state->frame_info->fb))
|
|
|
|
drm_framebuffer_put(vkms_state->frame_info->fb);
|
2018-08-02 04:10:26 +03:00
|
|
|
}
|
|
|
|
|
2022-09-05 16:08:04 -03:00
|
|
|
kfree(vkms_state->frame_info);
|
|
|
|
vkms_state->frame_info = NULL;
|
2018-08-02 04:08:22 +03:00
|
|
|
|
2021-07-05 09:46:31 +02:00
|
|
|
__drm_gem_destroy_shadow_plane_state(&vkms_state->base);
|
2018-08-02 04:08:22 +03:00
|
|
|
kfree(vkms_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vkms_plane_reset(struct drm_plane *plane)
|
|
|
|
{
|
|
|
|
struct vkms_plane_state *vkms_state;
|
|
|
|
|
2021-07-05 09:46:31 +02:00
|
|
|
if (plane->state) {
|
2018-08-02 04:08:22 +03:00
|
|
|
vkms_plane_destroy_state(plane, plane->state);
|
2021-07-05 09:46:31 +02:00
|
|
|
plane->state = NULL; /* must be set to NULL here */
|
|
|
|
}
|
2018-08-02 04:08:22 +03:00
|
|
|
|
|
|
|
vkms_state = kzalloc(sizeof(*vkms_state), GFP_KERNEL);
|
|
|
|
if (!vkms_state) {
|
|
|
|
DRM_ERROR("Cannot allocate vkms_plane_state\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-05 09:46:31 +02:00
|
|
|
__drm_gem_reset_shadow_plane(plane, &vkms_state->base);
|
2018-08-02 04:08:22 +03:00
|
|
|
}
|
|
|
|
|
2018-05-16 20:56:21 -03:00
|
|
|
static const struct drm_plane_funcs vkms_plane_funcs = {
|
|
|
|
.update_plane = drm_atomic_helper_update_plane,
|
|
|
|
.disable_plane = drm_atomic_helper_disable_plane,
|
2018-08-02 04:08:22 +03:00
|
|
|
.reset = vkms_plane_reset,
|
|
|
|
.atomic_duplicate_state = vkms_plane_duplicate_state,
|
|
|
|
.atomic_destroy_state = vkms_plane_destroy_state,
|
2018-05-16 20:56:21 -03:00
|
|
|
};
|
|
|
|
|
2018-09-06 08:17:16 +03:00
|
|
|
static void vkms_plane_atomic_update(struct drm_plane *plane,
|
drm/atomic: Pass the full state to planes atomic disable and update
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert the remaining helpers to provide a consistent interface,
this time with the planes atomic_update and atomic_disable.
The conversion was done using the coccinelle script below, built tested on
all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_update)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
void (*atomic_disable)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier crtc_state;
identifier plane, plane_state, state;
expression e;
@@
f(struct drm_crtc_state *crtc_state)
{
...
struct drm_atomic_state *state = e;
<+...
(
- FUNCS->atomic_disable(plane, plane_state)
+ FUNCS->atomic_disable(plane, state)
|
- FUNCS->atomic_update(plane, plane_state)
+ FUNCS->atomic_update(plane, state)
)
...+>
}
@@
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *state)
+ struct drm_plane_state *old_plane_state)
{
<...
- state
+ old_plane_state
...>
}
@ ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on plane_atomic_func && !ignores_old_state @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *plane_state)
{
+ struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
struct drm_plane_state *plane_state = drm_atomic_get_old_plane_state(state, plane);
<+...
- plane_state->state
+ state
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-9-maxime@cerno.tech
2021-02-19 13:00:29 +01:00
|
|
|
struct drm_atomic_state *state)
|
2018-07-12 10:41:02 -03:00
|
|
|
{
|
drm: Use state helper instead of the plane state pointer
Many drivers reference the plane->state pointer in order to get the
current plane state in their atomic_update or atomic_disable hooks,
which would be the new plane state in the global atomic state since
_swap_state happened when those hooks are run.
Use the drm_atomic_get_new_plane_state helper to get that state to make it
more obvious.
This was made using the coccinelle script below:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
)
@ adds_new_state @
identifier plane_atomic_func.func;
identifier plane, state;
identifier new_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state)
{
...
- struct drm_plane_state *new_state = plane->state;
+ struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, plane);
...
}
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20210219120032.260676-1-maxime@cerno.tech
2021-02-19 13:00:30 +01:00
|
|
|
struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
|
|
|
|
plane);
|
2018-08-02 04:10:26 +03:00
|
|
|
struct vkms_plane_state *vkms_plane_state;
|
2021-07-05 09:46:33 +02:00
|
|
|
struct drm_shadow_plane_state *shadow_plane_state;
|
drm: Store new plane state in a variable for atomic_update and disable
In order to store the new plane state in a subsequent helper, let's move
the plane->state dereferences into a variable.
This was done using the following coccinelle script, plus some hand
changes for vmwgfx:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
)
@ has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
+ struct drm_plane_state *new_state = plane->state;
<+...
- plane->state
+ new_state
...+>
}
@ has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
+ struct drm_plane_state *new_plane_state = plane->state;
<+...
- plane->state
+ new_plane_state
...+>
}
@ has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
+ struct drm_plane_state *new_s = plane->state;
<+...
- plane->state
+ new_s
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20210219120032.260676-1-maxime@cerno.tech
2021-02-19 13:00:27 +01:00
|
|
|
struct drm_framebuffer *fb = new_state->fb;
|
2022-09-05 16:08:04 -03:00
|
|
|
struct vkms_frame_info *frame_info;
|
2022-09-08 03:56:23 -07:00
|
|
|
u32 fmt;
|
2018-08-02 04:10:26 +03:00
|
|
|
|
drm: Store new plane state in a variable for atomic_update and disable
In order to store the new plane state in a subsequent helper, let's move
the plane->state dereferences into a variable.
This was done using the following coccinelle script, plus some hand
changes for vmwgfx:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
)
@ has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
+ struct drm_plane_state *new_state = plane->state;
<+...
- plane->state
+ new_state
...+>
}
@ has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
+ struct drm_plane_state *new_plane_state = plane->state;
<+...
- plane->state
+ new_plane_state
...+>
}
@ has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
+ struct drm_plane_state *new_s = plane->state;
<+...
- plane->state
+ new_s
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20210219120032.260676-1-maxime@cerno.tech
2021-02-19 13:00:27 +01:00
|
|
|
if (!new_state->crtc || !fb)
|
2018-08-02 04:10:26 +03:00
|
|
|
return;
|
|
|
|
|
2022-09-08 03:56:23 -07:00
|
|
|
fmt = fb->format->format;
|
drm: Store new plane state in a variable for atomic_update and disable
In order to store the new plane state in a subsequent helper, let's move
the plane->state dereferences into a variable.
This was done using the following coccinelle script, plus some hand
changes for vmwgfx:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
(
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
|
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_update = func,
...,
};
)
@ has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_state @
identifier plane_atomic_func.func;
identifier plane;
symbol old_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_state)
{
+ struct drm_plane_state *new_state = plane->state;
<+...
- plane->state
+ new_state
...+>
}
@ has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_state @
identifier plane_atomic_func.func;
identifier plane;
symbol state;
@@
func(struct drm_plane *plane, struct drm_plane_state *state)
{
+ struct drm_plane_state *new_plane_state = plane->state;
<+...
- plane->state
+ new_plane_state
...+>
}
@ has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
identifier new_state;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
...
struct drm_plane_state *new_state = plane->state;
...
}
@ depends on !has_new_state_old_s @
identifier plane_atomic_func.func;
identifier plane;
symbol old_s;
@@
func(struct drm_plane *plane, struct drm_plane_state *old_s)
{
+ struct drm_plane_state *new_s = plane->state;
<+...
- plane->state
+ new_s
...+>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20210219120032.260676-1-maxime@cerno.tech
2021-02-19 13:00:27 +01:00
|
|
|
vkms_plane_state = to_vkms_plane_state(new_state);
|
2021-07-05 09:46:33 +02:00
|
|
|
shadow_plane_state = &vkms_plane_state->base;
|
2018-09-06 08:18:26 +03:00
|
|
|
|
2022-09-05 16:08:04 -03:00
|
|
|
frame_info = vkms_plane_state->frame_info;
|
|
|
|
memcpy(&frame_info->src, &new_state->src, sizeof(struct drm_rect));
|
|
|
|
memcpy(&frame_info->dst, &new_state->dst, sizeof(struct drm_rect));
|
2022-09-05 16:08:06 -03:00
|
|
|
frame_info->fb = fb;
|
2022-09-05 16:08:04 -03:00
|
|
|
memcpy(&frame_info->map, &shadow_plane_state->data, sizeof(frame_info->map));
|
2022-09-05 16:08:06 -03:00
|
|
|
drm_framebuffer_get(frame_info->fb);
|
2024-11-18 19:28:24 +01:00
|
|
|
frame_info->rotation = new_state->rotation;
|
2023-04-18 10:05:22 -03:00
|
|
|
|
2024-11-18 19:28:23 +01:00
|
|
|
vkms_plane_state->pixel_read_line = get_pixel_read_line_function(fmt);
|
2025-04-15 15:55:33 +02:00
|
|
|
get_conversion_matrix_to_argb_u16(fmt, new_state->color_encoding, new_state->color_range,
|
|
|
|
&vkms_plane_state->conversion_matrix);
|
2018-07-12 10:41:02 -03:00
|
|
|
}
|
|
|
|
|
2018-07-24 19:30:22 +03:00
|
|
|
static int vkms_plane_atomic_check(struct drm_plane *plane,
|
drm/atomic: Pass the full state to planes atomic_check
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert all the remaining helpers to provide a consistent
interface, starting with the planes atomic_check.
The conversion was done using the coccinelle script below plus some
manual changes for vmwgfx, built tested on all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
int (*atomic_check)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier dev;
identifier plane, plane_state, state;
@@
f(struct drm_device *dev, struct drm_atomic_state *state)
{
<+...
- FUNCS->atomic_check(plane, plane_state)
+ FUNCS->atomic_check(plane, state)
...+>
}
@ ignores_new_state @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *new_plane_state)
{
... when != new_plane_state
}
@ adds_new_state depends on plane_atomic_func && !ignores_new_state @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *new_plane_state)
{
+ struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *new_plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-4-maxime@cerno.tech
2021-02-19 13:00:24 +01:00
|
|
|
struct drm_atomic_state *state)
|
2018-07-24 19:30:22 +03:00
|
|
|
{
|
drm/atomic: Pass the full state to planes atomic_check
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's convert all the remaining helpers to provide a consistent
interface, starting with the planes atomic_check.
The conversion was done using the coccinelle script below plus some
manual changes for vmwgfx, built tested on all the drivers.
@@
identifier plane, plane_state;
symbol state;
@@
struct drm_plane_helper_funcs {
...
int (*atomic_check)(struct drm_plane *plane,
- struct drm_plane_state *plane_state);
+ struct drm_atomic_state *state);
...
}
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
static const struct drm_plane_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@@
struct drm_plane_helper_funcs *FUNCS;
identifier f;
identifier dev;
identifier plane, plane_state, state;
@@
f(struct drm_device *dev, struct drm_atomic_state *state)
{
<+...
- FUNCS->atomic_check(plane, plane_state)
+ FUNCS->atomic_check(plane, state)
...+>
}
@ ignores_new_state @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *new_plane_state)
{
... when != new_plane_state
}
@ adds_new_state depends on plane_atomic_func && !ignores_new_state @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane, struct drm_plane_state *new_plane_state)
{
+ struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
...
}
@ depends on plane_atomic_func @
identifier plane_atomic_func.func;
identifier plane, new_plane_state;
@@
func(struct drm_plane *plane,
- struct drm_plane_state *new_plane_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-4-maxime@cerno.tech
2021-02-19 13:00:24 +01:00
|
|
|
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
|
|
|
|
plane);
|
2018-07-24 19:30:22 +03:00
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
int ret;
|
|
|
|
|
2021-02-19 13:00:22 +01:00
|
|
|
if (!new_plane_state->fb || WARN_ON(!new_plane_state->crtc))
|
2018-07-24 19:30:22 +03:00
|
|
|
return 0;
|
|
|
|
|
drm: Use the state pointer directly in planes atomic_check
Now that atomic_check takes the global atomic state as a parameter, we
don't need to go through the pointer in the plane state.
This was done using the following coccinelle script:
@ plane_atomic_func @
identifier helpers;
identifier func;
@@
static struct drm_plane_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
- struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
<... when != plane_state
- plane_state->state
+ state
...>
}
@@
identifier plane_atomic_func.func;
identifier plane, state;
identifier plane_state;
@@
func(struct drm_plane *plane, struct drm_atomic_state *state) {
...
struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
<...
- plane_state->state
+ state
...>
}
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-5-maxime@cerno.tech
2021-02-19 13:00:25 +01:00
|
|
|
crtc_state = drm_atomic_get_crtc_state(state,
|
2021-02-19 13:00:22 +01:00
|
|
|
new_plane_state->crtc);
|
2018-07-24 19:30:22 +03:00
|
|
|
if (IS_ERR(crtc_state))
|
|
|
|
return PTR_ERR(crtc_state);
|
|
|
|
|
2021-02-19 13:00:22 +01:00
|
|
|
ret = drm_atomic_helper_check_plane_state(new_plane_state, crtc_state,
|
2022-07-20 10:30:54 +02:00
|
|
|
DRM_PLANE_NO_SCALING,
|
|
|
|
DRM_PLANE_NO_SCALING,
|
2023-03-24 13:42:26 -03:00
|
|
|
true, true);
|
2018-07-24 19:30:22 +03:00
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
drm/vkms: reintroduce prepare_fb and cleanup_fb functions
With commit 359c6649cd9a ("drm/gem: Implement shadow-plane {begin,
end}_fb_access with vmap"), the behavior of the shadow-plane helpers
changed and the vunmap is now performed at the end of
the current pageflip, instead of the end of the following pageflip.
By performing the vunmap at the end of the current pageflip, invalid
memory is accessed by the vkms during the plane composition, as the data
is being unmapped before being used, as reported by the following
warning:
[ 275.866047] BUG: unable to handle page fault for address: ffffb382814e8002
[ 275.866055] #PF: supervisor read access in kernel mode
[ 275.866058] #PF: error_code(0x0000) - not-present page
[ 275.866061] PGD 1000067 P4D 1000067 PUD 110a067 PMD 46e3067 PTE 0
[ 275.866066] Oops: 0000 [#1] PREEMPT SMP PTI
[ 275.866070] CPU: 2 PID: 49 Comm: kworker/u8:2 Not tainted 6.1.0-rc6-00018-gb357e7ac1b73-dirty #54
[ 275.866074] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.1-2.fc37 04/01/2014
[ 275.866076] Workqueue: vkms_composer vkms_composer_worker [vkms]
[ 275.866084] RIP: 0010:XRGB8888_to_argb_u16+0x5c/0xa0 [vkms]
[ 275.866092] Code: bf 56 0a 0f af 56 70 48 8b 76 28 01 ca 49 83 f8 02
41 b9 01 00 00 00 4d 0f 43 c8 48 01 f2 48 83 c2 02 31 f6 66 c7 04 f0 ff
ff <0f> b6 0c b2 89 cf c1 e7 08 09 cf 66 89 7c f0 02 0f b6 4c b2 ff 89
[ 275.866095] RSP: 0018:ffffb382801b7db0 EFLAGS: 00010246
[ 275.866098] RAX: ffff896336ace000 RBX: ffff896310e293c0 RCX: 0000000000000000
[ 275.866101] RDX: ffffb382814e8002 RSI: 0000000000000000 RDI: ffffb382801b7de8
[ 275.866103] RBP: 0000000000001400 R08: 0000000000000280 R09: 0000000000000280
[ 275.866105] R10: 0000000000000010 R11: ffffffffc011d990 R12: ffff896302a1ece0
[ 275.866107] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000080008001
[ 275.866109] FS: 0000000000000000(0000) GS:ffff89637dd00000(0000) knlGS:0000000000000000
[ 275.866112] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 275.866114] CR2: ffffb382814e8002 CR3: 0000000003bb4000 CR4: 00000000000006e0
[ 275.866120] Call Trace:
[ 275.866123] <TASK>
[ 275.866124] compose_active_planes+0x1c4/0x380 [vkms]
[ 275.866132] vkms_composer_worker+0x9f/0x130 [vkms]
[ 275.866139] process_one_work+0x1c0/0x370
[ 275.866160] worker_thread+0x221/0x410
[ 275.866164] ? worker_clr_flags+0x50/0x50
[ 275.866167] kthread+0xe1/0x100
[ 275.866172] ? kthread_blkcg+0x30/0x30
[ 275.866176] ret_from_fork+0x22/0x30
[ 275.866181] </TASK>
[ 275.866182] Modules linked in: vkms
[ 275.866186] CR2: ffffb382814e8002
[ 275.866191] ---[ end trace 0000000000000000 ]---
Therefore, introduce again prepare_fb and cleanup_fb functions to the
vkms, which were previously removed on commit b43e2ec03b0d ("drm/vkms:
Let shadow-plane helpers prepare the plane's FB").
Fixes: 359c6649cd9a ("drm/gem: Implement shadow-plane {begin, end}_fb_access with vmap")
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
Signed-off-by: Melissa Wen <melissa.srw@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230111131304.106039-1-mcanal@igalia.com
2023-01-11 10:13:05 -03:00
|
|
|
static int vkms_prepare_fb(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
struct drm_shadow_plane_state *shadow_plane_state;
|
|
|
|
struct drm_framebuffer *fb = state->fb;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!fb)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
shadow_plane_state = to_drm_shadow_plane_state(state);
|
|
|
|
|
|
|
|
ret = drm_gem_plane_helper_prepare_fb(plane, state);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return drm_gem_fb_vmap(fb, shadow_plane_state->map, shadow_plane_state->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vkms_cleanup_fb(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
struct drm_shadow_plane_state *shadow_plane_state;
|
|
|
|
struct drm_framebuffer *fb = state->fb;
|
|
|
|
|
|
|
|
if (!fb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
shadow_plane_state = to_drm_shadow_plane_state(state);
|
|
|
|
|
|
|
|
drm_gem_fb_vunmap(fb, shadow_plane_state->map);
|
|
|
|
}
|
|
|
|
|
2023-04-20 20:22:27 -03:00
|
|
|
static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = {
|
2018-09-06 08:17:16 +03:00
|
|
|
.atomic_update = vkms_plane_atomic_update,
|
2018-07-24 19:30:22 +03:00
|
|
|
.atomic_check = vkms_plane_atomic_check,
|
drm/vkms: reintroduce prepare_fb and cleanup_fb functions
With commit 359c6649cd9a ("drm/gem: Implement shadow-plane {begin,
end}_fb_access with vmap"), the behavior of the shadow-plane helpers
changed and the vunmap is now performed at the end of
the current pageflip, instead of the end of the following pageflip.
By performing the vunmap at the end of the current pageflip, invalid
memory is accessed by the vkms during the plane composition, as the data
is being unmapped before being used, as reported by the following
warning:
[ 275.866047] BUG: unable to handle page fault for address: ffffb382814e8002
[ 275.866055] #PF: supervisor read access in kernel mode
[ 275.866058] #PF: error_code(0x0000) - not-present page
[ 275.866061] PGD 1000067 P4D 1000067 PUD 110a067 PMD 46e3067 PTE 0
[ 275.866066] Oops: 0000 [#1] PREEMPT SMP PTI
[ 275.866070] CPU: 2 PID: 49 Comm: kworker/u8:2 Not tainted 6.1.0-rc6-00018-gb357e7ac1b73-dirty #54
[ 275.866074] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.1-2.fc37 04/01/2014
[ 275.866076] Workqueue: vkms_composer vkms_composer_worker [vkms]
[ 275.866084] RIP: 0010:XRGB8888_to_argb_u16+0x5c/0xa0 [vkms]
[ 275.866092] Code: bf 56 0a 0f af 56 70 48 8b 76 28 01 ca 49 83 f8 02
41 b9 01 00 00 00 4d 0f 43 c8 48 01 f2 48 83 c2 02 31 f6 66 c7 04 f0 ff
ff <0f> b6 0c b2 89 cf c1 e7 08 09 cf 66 89 7c f0 02 0f b6 4c b2 ff 89
[ 275.866095] RSP: 0018:ffffb382801b7db0 EFLAGS: 00010246
[ 275.866098] RAX: ffff896336ace000 RBX: ffff896310e293c0 RCX: 0000000000000000
[ 275.866101] RDX: ffffb382814e8002 RSI: 0000000000000000 RDI: ffffb382801b7de8
[ 275.866103] RBP: 0000000000001400 R08: 0000000000000280 R09: 0000000000000280
[ 275.866105] R10: 0000000000000010 R11: ffffffffc011d990 R12: ffff896302a1ece0
[ 275.866107] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000080008001
[ 275.866109] FS: 0000000000000000(0000) GS:ffff89637dd00000(0000) knlGS:0000000000000000
[ 275.866112] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 275.866114] CR2: ffffb382814e8002 CR3: 0000000003bb4000 CR4: 00000000000006e0
[ 275.866120] Call Trace:
[ 275.866123] <TASK>
[ 275.866124] compose_active_planes+0x1c4/0x380 [vkms]
[ 275.866132] vkms_composer_worker+0x9f/0x130 [vkms]
[ 275.866139] process_one_work+0x1c0/0x370
[ 275.866160] worker_thread+0x221/0x410
[ 275.866164] ? worker_clr_flags+0x50/0x50
[ 275.866167] kthread+0xe1/0x100
[ 275.866172] ? kthread_blkcg+0x30/0x30
[ 275.866176] ret_from_fork+0x22/0x30
[ 275.866181] </TASK>
[ 275.866182] Modules linked in: vkms
[ 275.866186] CR2: ffffb382814e8002
[ 275.866191] ---[ end trace 0000000000000000 ]---
Therefore, introduce again prepare_fb and cleanup_fb functions to the
vkms, which were previously removed on commit b43e2ec03b0d ("drm/vkms:
Let shadow-plane helpers prepare the plane's FB").
Fixes: 359c6649cd9a ("drm/gem: Implement shadow-plane {begin, end}_fb_access with vmap")
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
Signed-off-by: Melissa Wen <melissa.srw@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230111131304.106039-1-mcanal@igalia.com
2023-01-11 10:13:05 -03:00
|
|
|
.prepare_fb = vkms_prepare_fb,
|
|
|
|
.cleanup_fb = vkms_cleanup_fb,
|
2018-07-12 10:41:02 -03:00
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
|
|
|
struct drm_device *dev = &vkmsdev->drm;
|
2021-04-24 05:23:27 -03:00
|
|
|
struct vkms_plane *plane;
|
2018-05-16 20:56:21 -03:00
|
|
|
|
2024-11-19 14:34:04 +01:00
|
|
|
plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 0,
|
2021-04-24 05:23:27 -03:00
|
|
|
&vkms_plane_funcs,
|
2023-04-20 20:22:27 -03:00
|
|
|
vkms_formats, ARRAY_SIZE(vkms_formats),
|
2021-04-24 05:23:27 -03:00
|
|
|
NULL, type, NULL);
|
|
|
|
if (IS_ERR(plane))
|
|
|
|
return plane;
|
2018-05-16 20:56:21 -03:00
|
|
|
|
2023-04-20 20:22:27 -03:00
|
|
|
drm_plane_helper_add(&plane->base, &vkms_plane_helper_funcs);
|
2018-07-12 10:41:02 -03:00
|
|
|
|
2023-04-18 10:05:22 -03:00
|
|
|
drm_plane_create_rotation_property(&plane->base, DRM_MODE_ROTATE_0,
|
2023-04-18 10:05:25 -03:00
|
|
|
DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK);
|
2023-04-18 10:05:22 -03:00
|
|
|
|
2025-04-15 15:55:34 +02:00
|
|
|
drm_plane_create_color_properties(&plane->base,
|
|
|
|
BIT(DRM_COLOR_YCBCR_BT601) |
|
|
|
|
BIT(DRM_COLOR_YCBCR_BT709) |
|
|
|
|
BIT(DRM_COLOR_YCBCR_BT2020),
|
|
|
|
BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
|
|
|
|
BIT(DRM_COLOR_YCBCR_FULL_RANGE),
|
|
|
|
DRM_COLOR_YCBCR_BT601,
|
|
|
|
DRM_COLOR_YCBCR_FULL_RANGE);
|
|
|
|
|
2018-05-16 20:56:21 -03:00
|
|
|
return plane;
|
|
|
|
}
|