2013-09-08 17:02:56 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Red Hat, Inc.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <drm/drm_atomic_helper.h>
|
2019-12-12 05:53:46 -07:00
|
|
|
#include <drm/drm_damage_helper.h>
|
2019-06-29 23:19:16 -07:00
|
|
|
#include <drm/drm_fourcc.h>
|
|
|
|
|
|
|
|
#include "virtgpu_drv.h"
|
2013-09-08 17:02:56 -07:00
|
|
|
|
|
|
|
static const uint32_t virtio_gpu_formats[] = {
|
2018-09-21 06:47:03 -07:00
|
|
|
DRM_FORMAT_HOST_XRGB8888,
|
2013-09-08 17:02:56 -07:00
|
|
|
};
|
|
|
|
|
2016-05-26 02:42:52 -07:00
|
|
|
static const uint32_t virtio_gpu_cursor_formats[] = {
|
2018-09-21 06:47:03 -07:00
|
|
|
DRM_FORMAT_HOST_ARGB8888,
|
2016-05-26 02:42:52 -07:00
|
|
|
};
|
|
|
|
|
2017-04-03 00:08:44 -07:00
|
|
|
uint32_t virtio_gpu_translate_format(uint32_t drm_fourcc)
|
|
|
|
{
|
|
|
|
uint32_t format;
|
|
|
|
|
|
|
|
switch (drm_fourcc) {
|
|
|
|
case DRM_FORMAT_XRGB8888:
|
|
|
|
format = VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM;
|
|
|
|
break;
|
|
|
|
case DRM_FORMAT_ARGB8888:
|
|
|
|
format = VIRTIO_GPU_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
break;
|
|
|
|
case DRM_FORMAT_BGRX8888:
|
|
|
|
format = VIRTIO_GPU_FORMAT_X8R8G8B8_UNORM;
|
|
|
|
break;
|
|
|
|
case DRM_FORMAT_BGRA8888:
|
|
|
|
format = VIRTIO_GPU_FORMAT_A8R8G8B8_UNORM;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* This should not happen, we handle everything listed
|
|
|
|
* in virtio_gpu_formats[].
|
|
|
|
*/
|
|
|
|
format = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
WARN_ON(format == 0);
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
2013-09-08 17:02:56 -07:00
|
|
|
static const struct drm_plane_funcs virtio_gpu_plane_funcs = {
|
|
|
|
.update_plane = drm_atomic_helper_update_plane,
|
|
|
|
.disable_plane = drm_atomic_helper_disable_plane,
|
|
|
|
.reset = drm_atomic_helper_plane_reset,
|
|
|
|
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int virtio_gpu_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 05:00:24 -07:00
|
|
|
struct drm_atomic_state *state)
|
2013-09-08 17:02:56 -07: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 05:00:24 -07:00
|
|
|
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
|
|
|
|
plane);
|
2023-11-23 15:13:01 -07:00
|
|
|
struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(state,
|
|
|
|
plane);
|
2019-08-22 02:46:57 -07:00
|
|
|
bool is_cursor = plane->type == DRM_PLANE_TYPE_CURSOR;
|
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
int ret;
|
|
|
|
|
2021-02-19 05:00:22 -07:00
|
|
|
if (!new_plane_state->fb || WARN_ON(!new_plane_state->crtc))
|
2019-08-22 02:46:57 -07:00
|
|
|
return 0;
|
|
|
|
|
2023-11-23 15:13:01 -07:00
|
|
|
/*
|
|
|
|
* Ignore damage clips if the framebuffer attached to the plane's state
|
|
|
|
* has changed since the last plane update (page-flip). In this case, a
|
|
|
|
* full plane update should happen because uploads are done per-buffer.
|
|
|
|
*/
|
|
|
|
if (old_plane_state->fb != new_plane_state->fb)
|
|
|
|
new_plane_state->ignore_damage_clips = true;
|
|
|
|
|
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 05:00:25 -07:00
|
|
|
crtc_state = drm_atomic_get_crtc_state(state,
|
2021-02-19 05:00:22 -07:00
|
|
|
new_plane_state->crtc);
|
2019-08-22 02:46:57 -07:00
|
|
|
if (IS_ERR(crtc_state))
|
|
|
|
return PTR_ERR(crtc_state);
|
|
|
|
|
2021-02-19 05:00:22 -07:00
|
|
|
ret = drm_atomic_helper_check_plane_state(new_plane_state, crtc_state,
|
2022-07-20 01:30:54 -07:00
|
|
|
DRM_PLANE_NO_SCALING,
|
|
|
|
DRM_PLANE_NO_SCALING,
|
2019-08-22 02:46:57 -07:00
|
|
|
is_cursor, true);
|
|
|
|
return ret;
|
2013-09-08 17:02:56 -07:00
|
|
|
}
|
|
|
|
|
2019-10-22 23:25:39 -07:00
|
|
|
static void virtio_gpu_update_dumb_bo(struct virtio_gpu_device *vgdev,
|
2019-12-12 05:53:46 -07:00
|
|
|
struct drm_plane_state *state,
|
|
|
|
struct drm_rect *rect)
|
2019-10-22 23:25:39 -07:00
|
|
|
{
|
2019-12-12 05:53:46 -07:00
|
|
|
struct virtio_gpu_object *bo =
|
|
|
|
gem_to_virtio_gpu_obj(state->fb->obj[0]);
|
2019-10-22 23:25:39 -07:00
|
|
|
struct virtio_gpu_object_array *objs;
|
2019-12-12 05:53:46 -07:00
|
|
|
uint32_t w = rect->x2 - rect->x1;
|
|
|
|
uint32_t h = rect->y2 - rect->y1;
|
|
|
|
uint32_t x = rect->x1;
|
|
|
|
uint32_t y = rect->y1;
|
|
|
|
uint32_t off = x * state->fb->format->cpp[0] +
|
|
|
|
y * state->fb->pitches[0];
|
2019-10-22 23:25:39 -07:00
|
|
|
|
|
|
|
objs = virtio_gpu_array_alloc(1);
|
|
|
|
if (!objs)
|
|
|
|
return;
|
|
|
|
virtio_gpu_array_add_obj(objs, &bo->base.base);
|
2019-12-12 05:53:46 -07:00
|
|
|
|
|
|
|
virtio_gpu_cmd_transfer_to_host_2d(vgdev, off, w, h, x, y,
|
|
|
|
objs, NULL);
|
2019-10-22 23:25:39 -07:00
|
|
|
}
|
|
|
|
|
2021-06-10 16:24:56 -07:00
|
|
|
static void virtio_gpu_resource_flush(struct drm_plane *plane,
|
|
|
|
uint32_t x, uint32_t y,
|
|
|
|
uint32_t width, uint32_t height)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = plane->dev;
|
|
|
|
struct virtio_gpu_device *vgdev = dev->dev_private;
|
|
|
|
struct virtio_gpu_framebuffer *vgfb;
|
|
|
|
struct virtio_gpu_object *bo;
|
|
|
|
|
|
|
|
vgfb = to_virtio_gpu_framebuffer(plane->state->fb);
|
|
|
|
bo = gem_to_virtio_gpu_obj(vgfb->base.obj[0]);
|
|
|
|
if (vgfb->fence) {
|
|
|
|
struct virtio_gpu_object_array *objs;
|
|
|
|
|
|
|
|
objs = virtio_gpu_array_alloc(1);
|
|
|
|
if (!objs)
|
|
|
|
return;
|
|
|
|
virtio_gpu_array_add_obj(objs, vgfb->base.obj[0]);
|
|
|
|
virtio_gpu_array_lock_resv(objs);
|
|
|
|
virtio_gpu_cmd_resource_flush(vgdev, bo->hw_res_handle, x, y,
|
|
|
|
width, height, objs, vgfb->fence);
|
|
|
|
virtio_gpu_notify(vgdev);
|
|
|
|
|
|
|
|
dma_fence_wait_timeout(&vgfb->fence->f, true,
|
|
|
|
msecs_to_jiffies(50));
|
|
|
|
dma_fence_put(&vgfb->fence->f);
|
|
|
|
vgfb->fence = NULL;
|
|
|
|
} else {
|
|
|
|
virtio_gpu_cmd_resource_flush(vgdev, bo->hw_res_handle, x, y,
|
|
|
|
width, height, NULL, NULL);
|
|
|
|
virtio_gpu_notify(vgdev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-26 02:42:52 -07:00
|
|
|
static void virtio_gpu_primary_plane_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 05:00:29 -07:00
|
|
|
struct drm_atomic_state *state)
|
2013-09-08 17:02:56 -07:00
|
|
|
{
|
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 05:00:29 -07:00
|
|
|
struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
|
|
|
|
plane);
|
2013-09-08 17:02:56 -07:00
|
|
|
struct drm_device *dev = plane->dev;
|
|
|
|
struct virtio_gpu_device *vgdev = dev->dev_private;
|
2016-05-27 05:20:24 -07:00
|
|
|
struct virtio_gpu_output *output = NULL;
|
2013-09-08 17:02:56 -07:00
|
|
|
struct virtio_gpu_object *bo;
|
2019-12-12 05:53:46 -07:00
|
|
|
struct drm_rect rect;
|
2013-09-08 17:02:56 -07:00
|
|
|
|
2016-05-27 05:20:24 -07:00
|
|
|
if (plane->state->crtc)
|
|
|
|
output = drm_crtc_to_virtio_gpu_output(plane->state->crtc);
|
|
|
|
if (old_state->crtc)
|
|
|
|
output = drm_crtc_to_virtio_gpu_output(old_state->crtc);
|
2016-08-21 14:06:06 -07:00
|
|
|
if (WARN_ON(!output))
|
|
|
|
return;
|
2016-05-27 05:20:24 -07:00
|
|
|
|
2020-08-18 00:25:11 -07:00
|
|
|
if (!plane->state->fb || !output->crtc.state->active) {
|
2019-10-22 23:25:38 -07:00
|
|
|
DRM_DEBUG("nofb\n");
|
|
|
|
virtio_gpu_cmd_set_scanout(vgdev, output->index, 0,
|
|
|
|
plane->state->src_w >> 16,
|
|
|
|
plane->state->src_h >> 16,
|
|
|
|
0, 0);
|
2020-02-14 05:55:32 -07:00
|
|
|
virtio_gpu_notify(vgdev);
|
2019-10-22 23:25:38 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-12 05:53:46 -07:00
|
|
|
if (!drm_atomic_helper_damage_merged(old_state, plane->state, &rect))
|
|
|
|
return;
|
|
|
|
|
|
|
|
bo = gem_to_virtio_gpu_obj(plane->state->fb->obj[0]);
|
2019-10-22 23:25:39 -07:00
|
|
|
if (bo->dumb)
|
2019-12-12 05:53:46 -07:00
|
|
|
virtio_gpu_update_dumb_bo(vgdev, plane->state, &rect);
|
2013-09-08 17:02:56 -07:00
|
|
|
|
2019-12-12 05:53:44 -07:00
|
|
|
if (plane->state->fb != old_state->fb ||
|
|
|
|
plane->state->src_w != old_state->src_w ||
|
|
|
|
plane->state->src_h != old_state->src_h ||
|
|
|
|
plane->state->src_x != old_state->src_x ||
|
2020-08-18 00:25:10 -07:00
|
|
|
plane->state->src_y != old_state->src_y ||
|
|
|
|
output->needs_modeset) {
|
|
|
|
output->needs_modeset = false;
|
2019-12-12 05:53:44 -07:00
|
|
|
DRM_DEBUG("handle 0x%x, crtc %dx%d+%d+%d, src %dx%d+%d+%d\n",
|
|
|
|
bo->hw_res_handle,
|
|
|
|
plane->state->crtc_w, plane->state->crtc_h,
|
|
|
|
plane->state->crtc_x, plane->state->crtc_y,
|
|
|
|
plane->state->src_w >> 16,
|
|
|
|
plane->state->src_h >> 16,
|
|
|
|
plane->state->src_x >> 16,
|
|
|
|
plane->state->src_y >> 16);
|
2020-09-23 17:32:09 -07:00
|
|
|
|
|
|
|
if (bo->host3d_blob || bo->guest_blob) {
|
|
|
|
virtio_gpu_cmd_set_scanout_blob
|
|
|
|
(vgdev, output->index, bo,
|
|
|
|
plane->state->fb,
|
|
|
|
plane->state->src_w >> 16,
|
|
|
|
plane->state->src_h >> 16,
|
|
|
|
plane->state->src_x >> 16,
|
|
|
|
plane->state->src_y >> 16);
|
|
|
|
} else {
|
|
|
|
virtio_gpu_cmd_set_scanout(vgdev, output->index,
|
|
|
|
bo->hw_res_handle,
|
|
|
|
plane->state->src_w >> 16,
|
|
|
|
plane->state->src_h >> 16,
|
|
|
|
plane->state->src_x >> 16,
|
|
|
|
plane->state->src_y >> 16);
|
|
|
|
}
|
2019-12-12 05:53:44 -07:00
|
|
|
}
|
|
|
|
|
2021-06-10 16:24:56 -07:00
|
|
|
virtio_gpu_resource_flush(plane,
|
|
|
|
rect.x1,
|
|
|
|
rect.y1,
|
|
|
|
rect.x2 - rect.x1,
|
|
|
|
rect.y2 - rect.y1);
|
2013-09-08 17:02:56 -07:00
|
|
|
}
|
|
|
|
|
2021-06-10 16:24:54 -07:00
|
|
|
static int virtio_gpu_plane_prepare_fb(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *new_state)
|
2018-11-12 09:51:54 -07:00
|
|
|
{
|
|
|
|
struct drm_device *dev = plane->dev;
|
|
|
|
struct virtio_gpu_device *vgdev = dev->dev_private;
|
|
|
|
struct virtio_gpu_framebuffer *vgfb;
|
|
|
|
struct virtio_gpu_object *bo;
|
|
|
|
|
|
|
|
if (!new_state->fb)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
vgfb = to_virtio_gpu_framebuffer(new_state->fb);
|
|
|
|
bo = gem_to_virtio_gpu_obj(vgfb->base.obj[0]);
|
2021-06-10 16:24:54 -07:00
|
|
|
if (!bo || (plane->type == DRM_PLANE_TYPE_PRIMARY && !bo->guest_blob))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (bo->dumb && (plane->state->fb != new_state->fb)) {
|
2021-09-21 16:20:19 -07:00
|
|
|
vgfb->fence = virtio_gpu_fence_alloc(vgdev, vgdev->fence_drv.context,
|
|
|
|
0);
|
2018-11-12 09:51:54 -07:00
|
|
|
if (!vgfb->fence)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-10 16:24:54 -07:00
|
|
|
static void virtio_gpu_plane_cleanup_fb(struct drm_plane *plane,
|
2022-06-30 13:07:22 -07:00
|
|
|
struct drm_plane_state *state)
|
2018-11-12 09:51:54 -07:00
|
|
|
{
|
|
|
|
struct virtio_gpu_framebuffer *vgfb;
|
|
|
|
|
2022-06-30 13:07:22 -07:00
|
|
|
if (!state->fb)
|
2018-11-12 09:51:54 -07:00
|
|
|
return;
|
|
|
|
|
2022-06-30 13:07:22 -07:00
|
|
|
vgfb = to_virtio_gpu_framebuffer(state->fb);
|
2018-12-19 05:27:01 -07:00
|
|
|
if (vgfb->fence) {
|
|
|
|
dma_fence_put(&vgfb->fence->f);
|
|
|
|
vgfb->fence = NULL;
|
|
|
|
}
|
2018-11-12 09:51:54 -07:00
|
|
|
}
|
|
|
|
|
2016-05-26 02:42:52 -07:00
|
|
|
static void virtio_gpu_cursor_plane_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 05:00:29 -07:00
|
|
|
struct drm_atomic_state *state)
|
2016-05-26 02:42:52 -07:00
|
|
|
{
|
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 05:00:29 -07:00
|
|
|
struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
|
|
|
|
plane);
|
2016-05-26 02:42:52 -07:00
|
|
|
struct drm_device *dev = plane->dev;
|
|
|
|
struct virtio_gpu_device *vgdev = dev->dev_private;
|
|
|
|
struct virtio_gpu_output *output = NULL;
|
|
|
|
struct virtio_gpu_framebuffer *vgfb;
|
|
|
|
struct virtio_gpu_object *bo = NULL;
|
|
|
|
uint32_t handle;
|
2013-09-08 17:02:56 -07:00
|
|
|
|
2016-05-26 02:42:52 -07:00
|
|
|
if (plane->state->crtc)
|
|
|
|
output = drm_crtc_to_virtio_gpu_output(plane->state->crtc);
|
|
|
|
if (old_state->crtc)
|
|
|
|
output = drm_crtc_to_virtio_gpu_output(old_state->crtc);
|
2016-08-21 14:06:06 -07:00
|
|
|
if (WARN_ON(!output))
|
|
|
|
return;
|
2016-05-26 02:42:52 -07:00
|
|
|
|
|
|
|
if (plane->state->fb) {
|
|
|
|
vgfb = to_virtio_gpu_framebuffer(plane->state->fb);
|
2018-03-30 07:11:17 -07:00
|
|
|
bo = gem_to_virtio_gpu_obj(vgfb->base.obj[0]);
|
2016-05-26 02:42:52 -07:00
|
|
|
handle = bo->hw_res_handle;
|
|
|
|
} else {
|
|
|
|
handle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bo && bo->dumb && (plane->state->fb != old_state->fb)) {
|
|
|
|
/* new cursor -- update & wait */
|
2019-08-29 03:32:54 -07:00
|
|
|
struct virtio_gpu_object_array *objs;
|
|
|
|
|
|
|
|
objs = virtio_gpu_array_alloc(1);
|
|
|
|
if (!objs)
|
|
|
|
return;
|
|
|
|
virtio_gpu_array_add_obj(objs, vgfb->base.obj[0]);
|
2020-02-11 06:50:47 -07:00
|
|
|
virtio_gpu_array_lock_resv(objs);
|
2016-05-26 02:42:52 -07:00
|
|
|
virtio_gpu_cmd_transfer_to_host_2d
|
2019-08-29 03:32:54 -07:00
|
|
|
(vgdev, 0,
|
2019-10-18 05:23:52 -07:00
|
|
|
plane->state->crtc_w,
|
|
|
|
plane->state->crtc_h,
|
2019-08-29 03:32:54 -07:00
|
|
|
0, 0, objs, vgfb->fence);
|
2020-02-14 05:55:32 -07:00
|
|
|
virtio_gpu_notify(vgdev);
|
2019-08-29 03:32:46 -07:00
|
|
|
dma_fence_wait(&vgfb->fence->f, true);
|
|
|
|
dma_fence_put(&vgfb->fence->f);
|
|
|
|
vgfb->fence = NULL;
|
2016-05-26 02:42:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (plane->state->fb != old_state->fb) {
|
2016-05-31 00:36:21 -07:00
|
|
|
DRM_DEBUG("update, handle %d, pos +%d+%d, hot %d,%d\n", handle,
|
2016-05-26 02:42:52 -07:00
|
|
|
plane->state->crtc_x,
|
2016-05-31 00:36:21 -07:00
|
|
|
plane->state->crtc_y,
|
2023-10-23 00:46:10 -07:00
|
|
|
plane->state->hotspot_x,
|
|
|
|
plane->state->hotspot_y);
|
2016-05-26 02:42:52 -07:00
|
|
|
output->cursor.hdr.type =
|
|
|
|
cpu_to_le32(VIRTIO_GPU_CMD_UPDATE_CURSOR);
|
|
|
|
output->cursor.resource_id = cpu_to_le32(handle);
|
2016-05-31 00:36:21 -07:00
|
|
|
if (plane->state->fb) {
|
|
|
|
output->cursor.hot_x =
|
2023-10-23 00:46:10 -07:00
|
|
|
cpu_to_le32(plane->state->hotspot_x);
|
2016-05-31 00:36:21 -07:00
|
|
|
output->cursor.hot_y =
|
2023-10-23 00:46:10 -07:00
|
|
|
cpu_to_le32(plane->state->hotspot_y);
|
2016-05-31 00:36:21 -07:00
|
|
|
} else {
|
|
|
|
output->cursor.hot_x = cpu_to_le32(0);
|
|
|
|
output->cursor.hot_y = cpu_to_le32(0);
|
|
|
|
}
|
2016-05-26 02:42:52 -07:00
|
|
|
} else {
|
|
|
|
DRM_DEBUG("move +%d+%d\n",
|
|
|
|
plane->state->crtc_x,
|
|
|
|
plane->state->crtc_y);
|
|
|
|
output->cursor.hdr.type =
|
|
|
|
cpu_to_le32(VIRTIO_GPU_CMD_MOVE_CURSOR);
|
|
|
|
}
|
|
|
|
output->cursor.pos.x = cpu_to_le32(plane->state->crtc_x);
|
|
|
|
output->cursor.pos.y = cpu_to_le32(plane->state->crtc_y);
|
|
|
|
virtio_gpu_cursor_ping(vgdev, output);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_plane_helper_funcs virtio_gpu_primary_helper_funcs = {
|
2021-06-10 16:24:54 -07:00
|
|
|
.prepare_fb = virtio_gpu_plane_prepare_fb,
|
|
|
|
.cleanup_fb = virtio_gpu_plane_cleanup_fb,
|
2013-09-08 17:02:56 -07:00
|
|
|
.atomic_check = virtio_gpu_plane_atomic_check,
|
2016-05-26 02:42:52 -07:00
|
|
|
.atomic_update = virtio_gpu_primary_plane_update,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct drm_plane_helper_funcs virtio_gpu_cursor_helper_funcs = {
|
2021-06-10 16:24:54 -07:00
|
|
|
.prepare_fb = virtio_gpu_plane_prepare_fb,
|
|
|
|
.cleanup_fb = virtio_gpu_plane_cleanup_fb,
|
2016-05-26 02:42:52 -07:00
|
|
|
.atomic_check = virtio_gpu_plane_atomic_check,
|
|
|
|
.atomic_update = virtio_gpu_cursor_plane_update,
|
2013-09-08 17:02:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,
|
2016-05-26 02:42:52 -07:00
|
|
|
enum drm_plane_type type,
|
2013-09-08 17:02:56 -07:00
|
|
|
int index)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = vgdev->ddev;
|
2016-05-26 02:42:52 -07:00
|
|
|
const struct drm_plane_helper_funcs *funcs;
|
2013-09-08 17:02:56 -07:00
|
|
|
struct drm_plane *plane;
|
2016-05-26 02:42:52 -07:00
|
|
|
const uint32_t *formats;
|
2022-07-14 06:00:27 -07:00
|
|
|
int nformats;
|
2013-09-08 17:02:56 -07:00
|
|
|
|
2016-05-26 02:42:52 -07:00
|
|
|
if (type == DRM_PLANE_TYPE_CURSOR) {
|
|
|
|
formats = virtio_gpu_cursor_formats;
|
|
|
|
nformats = ARRAY_SIZE(virtio_gpu_cursor_formats);
|
|
|
|
funcs = &virtio_gpu_cursor_helper_funcs;
|
|
|
|
} else {
|
|
|
|
formats = virtio_gpu_formats;
|
|
|
|
nformats = ARRAY_SIZE(virtio_gpu_formats);
|
|
|
|
funcs = &virtio_gpu_primary_helper_funcs;
|
|
|
|
}
|
2022-07-14 06:00:27 -07:00
|
|
|
|
|
|
|
plane = drmm_universal_plane_alloc(dev, struct drm_plane, dev,
|
|
|
|
1 << index, &virtio_gpu_plane_funcs,
|
|
|
|
formats, nformats, NULL, type, NULL);
|
|
|
|
if (IS_ERR(plane))
|
|
|
|
return plane;
|
2013-09-08 17:02:56 -07:00
|
|
|
|
2016-05-26 02:42:52 -07:00
|
|
|
drm_plane_helper_add(plane, funcs);
|
2023-03-10 05:59:42 -07:00
|
|
|
|
|
|
|
if (type == DRM_PLANE_TYPE_PRIMARY)
|
|
|
|
drm_plane_enable_fb_damage_clips(plane);
|
|
|
|
|
2013-09-08 17:02:56 -07:00
|
|
|
return plane;
|
|
|
|
}
|