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 start convert all the remaining helpers to provide a consistent interface, starting with the planes atomic_async_check and atomic_async_update. 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 { ... int (*atomic_async_check)(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_async_update)(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_async_check = func, ..., }; | static const struct drm_plane_helper_funcs helpers = { ..., .atomic_async_update = 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_async_check(plane, plane_state) + FUNCS->atomic_async_check(plane, state) ...+> } @@ 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_async_update(plane, plane_state) + FUNCS->atomic_async_update(plane, state) ...+> } @@ identifier mtk_plane_atomic_async_update; identifier plane; symbol new_state, state; expression e; @@ void mtk_plane_atomic_async_update(struct drm_plane *plane, struct drm_plane_state *new_state) { ... - struct mtk_plane_state *state = e; + struct mtk_plane_state *new_plane_state = e; <+... - state + new_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 *new_plane_state) { <... - state + new_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, plane_state; @@ func(struct drm_plane *plane, - struct drm_plane_state *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/...> @@ 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 ...+> } Acked-by: Thomas Zimmermann <tzimmermann@suse.de> Signed-off-by: Maxime Ripard <maxime@cerno.tech> Link: https://patchwork.freedesktop.org/patch/msgid/20210219120032.260676-1-maxime@cerno.tech
257 lines
6.9 KiB
C
257 lines
6.9 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (c) 2015 MediaTek Inc.
|
|
* Author: CK Hu <ck.hu@mediatek.com>
|
|
*/
|
|
|
|
#include <drm/drm_atomic.h>
|
|
#include <drm/drm_atomic_helper.h>
|
|
#include <drm/drm_atomic_uapi.h>
|
|
#include <drm/drm_fourcc.h>
|
|
#include <drm/drm_gem_atomic_helper.h>
|
|
#include <drm/drm_plane_helper.h>
|
|
|
|
#include "mtk_drm_crtc.h"
|
|
#include "mtk_drm_ddp_comp.h"
|
|
#include "mtk_drm_drv.h"
|
|
#include "mtk_drm_gem.h"
|
|
#include "mtk_drm_plane.h"
|
|
|
|
static const u32 formats[] = {
|
|
DRM_FORMAT_XRGB8888,
|
|
DRM_FORMAT_ARGB8888,
|
|
DRM_FORMAT_BGRX8888,
|
|
DRM_FORMAT_BGRA8888,
|
|
DRM_FORMAT_ABGR8888,
|
|
DRM_FORMAT_XBGR8888,
|
|
DRM_FORMAT_RGB888,
|
|
DRM_FORMAT_BGR888,
|
|
DRM_FORMAT_RGB565,
|
|
DRM_FORMAT_UYVY,
|
|
DRM_FORMAT_YUYV,
|
|
};
|
|
|
|
static void mtk_plane_reset(struct drm_plane *plane)
|
|
{
|
|
struct mtk_plane_state *state;
|
|
|
|
if (plane->state) {
|
|
__drm_atomic_helper_plane_destroy_state(plane->state);
|
|
|
|
state = to_mtk_plane_state(plane->state);
|
|
memset(state, 0, sizeof(*state));
|
|
} else {
|
|
state = kzalloc(sizeof(*state), GFP_KERNEL);
|
|
if (!state)
|
|
return;
|
|
plane->state = &state->base;
|
|
}
|
|
|
|
state->base.plane = plane;
|
|
state->pending.format = DRM_FORMAT_RGB565;
|
|
}
|
|
|
|
static struct drm_plane_state *mtk_plane_duplicate_state(struct drm_plane *plane)
|
|
{
|
|
struct mtk_plane_state *old_state = to_mtk_plane_state(plane->state);
|
|
struct mtk_plane_state *state;
|
|
|
|
state = kzalloc(sizeof(*state), GFP_KERNEL);
|
|
if (!state)
|
|
return NULL;
|
|
|
|
__drm_atomic_helper_plane_duplicate_state(plane, &state->base);
|
|
|
|
WARN_ON(state->base.plane != plane);
|
|
|
|
state->pending = old_state->pending;
|
|
|
|
return &state->base;
|
|
}
|
|
|
|
static void mtk_drm_plane_destroy_state(struct drm_plane *plane,
|
|
struct drm_plane_state *state)
|
|
{
|
|
__drm_atomic_helper_plane_destroy_state(state);
|
|
kfree(to_mtk_plane_state(state));
|
|
}
|
|
|
|
static int mtk_plane_atomic_async_check(struct drm_plane *plane,
|
|
struct drm_atomic_state *state)
|
|
{
|
|
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
|
|
plane);
|
|
struct drm_crtc_state *crtc_state;
|
|
int ret;
|
|
|
|
if (plane != new_plane_state->crtc->cursor)
|
|
return -EINVAL;
|
|
|
|
if (!plane->state)
|
|
return -EINVAL;
|
|
|
|
if (!plane->state->fb)
|
|
return -EINVAL;
|
|
|
|
ret = mtk_drm_crtc_plane_check(new_plane_state->crtc, plane,
|
|
to_mtk_plane_state(new_plane_state));
|
|
if (ret)
|
|
return ret;
|
|
|
|
if (state)
|
|
crtc_state = drm_atomic_get_existing_crtc_state(state,
|
|
new_plane_state->crtc);
|
|
else /* Special case for asynchronous cursor updates. */
|
|
crtc_state = new_plane_state->crtc->state;
|
|
|
|
return drm_atomic_helper_check_plane_state(plane->state, crtc_state,
|
|
DRM_PLANE_HELPER_NO_SCALING,
|
|
DRM_PLANE_HELPER_NO_SCALING,
|
|
true, true);
|
|
}
|
|
|
|
static void mtk_plane_atomic_async_update(struct drm_plane *plane,
|
|
struct drm_atomic_state *state)
|
|
{
|
|
struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
|
|
plane);
|
|
struct mtk_plane_state *new_plane_state = to_mtk_plane_state(plane->state);
|
|
|
|
plane->state->crtc_x = new_state->crtc_x;
|
|
plane->state->crtc_y = new_state->crtc_y;
|
|
plane->state->crtc_h = new_state->crtc_h;
|
|
plane->state->crtc_w = new_state->crtc_w;
|
|
plane->state->src_x = new_state->src_x;
|
|
plane->state->src_y = new_state->src_y;
|
|
plane->state->src_h = new_state->src_h;
|
|
plane->state->src_w = new_state->src_w;
|
|
swap(plane->state->fb, new_state->fb);
|
|
new_plane_state->pending.async_dirty = true;
|
|
|
|
mtk_drm_crtc_async_update(new_state->crtc, plane, new_state);
|
|
}
|
|
|
|
static const struct drm_plane_funcs mtk_plane_funcs = {
|
|
.update_plane = drm_atomic_helper_update_plane,
|
|
.disable_plane = drm_atomic_helper_disable_plane,
|
|
.destroy = drm_plane_cleanup,
|
|
.reset = mtk_plane_reset,
|
|
.atomic_duplicate_state = mtk_plane_duplicate_state,
|
|
.atomic_destroy_state = mtk_drm_plane_destroy_state,
|
|
};
|
|
|
|
static int mtk_plane_atomic_check(struct drm_plane *plane,
|
|
struct drm_plane_state *state)
|
|
{
|
|
struct drm_framebuffer *fb = state->fb;
|
|
struct drm_crtc_state *crtc_state;
|
|
int ret;
|
|
|
|
if (!fb)
|
|
return 0;
|
|
|
|
if (WARN_ON(!state->crtc))
|
|
return 0;
|
|
|
|
ret = mtk_drm_crtc_plane_check(state->crtc, plane,
|
|
to_mtk_plane_state(state));
|
|
if (ret)
|
|
return ret;
|
|
|
|
crtc_state = drm_atomic_get_crtc_state(state->state, state->crtc);
|
|
if (IS_ERR(crtc_state))
|
|
return PTR_ERR(crtc_state);
|
|
|
|
return drm_atomic_helper_check_plane_state(state, crtc_state,
|
|
DRM_PLANE_HELPER_NO_SCALING,
|
|
DRM_PLANE_HELPER_NO_SCALING,
|
|
true, true);
|
|
}
|
|
|
|
static void mtk_plane_atomic_disable(struct drm_plane *plane,
|
|
struct drm_plane_state *old_state)
|
|
{
|
|
struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
|
|
|
|
state->pending.enable = false;
|
|
wmb(); /* Make sure the above parameter is set before update */
|
|
state->pending.dirty = true;
|
|
}
|
|
|
|
static void mtk_plane_atomic_update(struct drm_plane *plane,
|
|
struct drm_plane_state *old_state)
|
|
{
|
|
struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
|
|
struct drm_crtc *crtc = plane->state->crtc;
|
|
struct drm_framebuffer *fb = plane->state->fb;
|
|
struct drm_gem_object *gem;
|
|
struct mtk_drm_gem_obj *mtk_gem;
|
|
unsigned int pitch, format;
|
|
dma_addr_t addr;
|
|
|
|
if (!crtc || WARN_ON(!fb))
|
|
return;
|
|
|
|
if (!plane->state->visible) {
|
|
mtk_plane_atomic_disable(plane, old_state);
|
|
return;
|
|
}
|
|
|
|
gem = fb->obj[0];
|
|
mtk_gem = to_mtk_gem_obj(gem);
|
|
addr = mtk_gem->dma_addr;
|
|
pitch = fb->pitches[0];
|
|
format = fb->format->format;
|
|
|
|
addr += (plane->state->src.x1 >> 16) * fb->format->cpp[0];
|
|
addr += (plane->state->src.y1 >> 16) * pitch;
|
|
|
|
state->pending.enable = true;
|
|
state->pending.pitch = pitch;
|
|
state->pending.format = format;
|
|
state->pending.addr = addr;
|
|
state->pending.x = plane->state->dst.x1;
|
|
state->pending.y = plane->state->dst.y1;
|
|
state->pending.width = drm_rect_width(&plane->state->dst);
|
|
state->pending.height = drm_rect_height(&plane->state->dst);
|
|
state->pending.rotation = plane->state->rotation;
|
|
wmb(); /* Make sure the above parameters are set before update */
|
|
state->pending.dirty = true;
|
|
}
|
|
|
|
static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = {
|
|
.prepare_fb = drm_gem_plane_helper_prepare_fb,
|
|
.atomic_check = mtk_plane_atomic_check,
|
|
.atomic_update = mtk_plane_atomic_update,
|
|
.atomic_disable = mtk_plane_atomic_disable,
|
|
.atomic_async_update = mtk_plane_atomic_async_update,
|
|
.atomic_async_check = mtk_plane_atomic_async_check,
|
|
};
|
|
|
|
int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,
|
|
unsigned long possible_crtcs, enum drm_plane_type type,
|
|
unsigned int supported_rotations)
|
|
{
|
|
int err;
|
|
|
|
err = drm_universal_plane_init(dev, plane, possible_crtcs,
|
|
&mtk_plane_funcs, formats,
|
|
ARRAY_SIZE(formats), NULL, type, NULL);
|
|
if (err) {
|
|
DRM_ERROR("failed to initialize plane\n");
|
|
return err;
|
|
}
|
|
|
|
if (supported_rotations & ~DRM_MODE_ROTATE_0) {
|
|
err = drm_plane_create_rotation_property(plane,
|
|
DRM_MODE_ROTATE_0,
|
|
supported_rotations);
|
|
if (err)
|
|
DRM_INFO("Create rotation property failed\n");
|
|
}
|
|
|
|
drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
|
|
|
|
return 0;
|
|
}
|