2019-05-29 07:17:56 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2014-08-22 18:36:26 +08:00
|
|
|
/*
|
2024-12-14 15:13:33 +08:00
|
|
|
* Copyright (C) Rockchip Electronics Co., Ltd.
|
2014-08-22 18:36:26 +08:00
|
|
|
* Author:Mark Yao <mark.yao@rock-chips.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2019-07-16 08:42:19 +02:00
|
|
|
|
2014-08-22 18:36:26 +08:00
|
|
|
#include <drm/drm.h>
|
2015-11-30 18:22:42 +08:00
|
|
|
#include <drm/drm_atomic.h>
|
2019-06-11 12:08:20 -04:00
|
|
|
#include <drm/drm_damage_helper.h>
|
2019-07-16 08:42:19 +02:00
|
|
|
#include <drm/drm_fourcc.h>
|
2022-06-14 12:54:49 +03:00
|
|
|
#include <drm/drm_framebuffer.h>
|
2018-03-30 15:11:18 +01:00
|
|
|
#include <drm/drm_gem_framebuffer_helper.h>
|
2019-01-17 22:03:34 +01:00
|
|
|
#include <drm/drm_probe_helper.h>
|
2014-08-22 18:36:26 +08:00
|
|
|
|
|
|
|
#include "rockchip_drm_drv.h"
|
2016-05-10 17:03:55 +01:00
|
|
|
#include "rockchip_drm_fb.h"
|
2014-08-22 18:36:26 +08:00
|
|
|
#include "rockchip_drm_gem.h"
|
|
|
|
|
2015-12-15 12:21:12 +01:00
|
|
|
static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = {
|
2018-03-30 15:11:18 +01:00
|
|
|
.destroy = drm_gem_fb_destroy,
|
|
|
|
.create_handle = drm_gem_fb_create_handle,
|
2019-06-11 12:08:20 -04:00
|
|
|
.dirty = drm_atomic_helper_dirtyfb,
|
2014-08-22 18:36:26 +08:00
|
|
|
};
|
|
|
|
|
2017-01-02 11:16:13 +02:00
|
|
|
static const struct drm_mode_config_helper_funcs rockchip_mode_config_helpers = {
|
2019-06-11 12:08:25 -04:00
|
|
|
.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
|
2016-06-08 14:19:12 +02:00
|
|
|
};
|
2015-11-30 18:22:42 +08:00
|
|
|
|
2020-03-11 15:55:41 +01:00
|
|
|
static struct drm_framebuffer *
|
|
|
|
rockchip_fb_create(struct drm_device *dev, struct drm_file *file,
|
drm: Pass the format info to .fb_create()
Pass along the format information from the top to .fb_create()
so that we can avoid redundant (and somewhat expensive) lookups
in the drivers.
Done with cocci (with some manual fixups):
@@
identifier func =~ ".*create.*";
identifier dev, file, mode_cmd;
@@
struct drm_framebuffer *func(
struct drm_device *dev,
struct drm_file *file,
+ const struct drm_format_info *info,
const struct drm_mode_fb_cmd2 *mode_cmd)
{
...
(
- const struct drm_format_info *info = drm_get_format_info(...);
|
- const struct drm_format_info *info;
...
- info = drm_get_format_info(...);
)
<...
- if (!info)
- return ...;
...>
}
@@
identifier func =~ ".*create.*";
identifier dev, file, mode_cmd;
@@
struct drm_framebuffer *func(
struct drm_device *dev,
struct drm_file *file,
+ const struct drm_format_info *info,
const struct drm_mode_fb_cmd2 *mode_cmd)
{
...
}
@find@
identifier fb_create_func =~ ".*create.*";
identifier dev, file, mode_cmd;
@@
struct drm_framebuffer *fb_create_func(
struct drm_device *dev,
struct drm_file *file,
+ const struct drm_format_info *info,
const struct drm_mode_fb_cmd2 *mode_cmd);
@@
identifier find.fb_create_func;
expression dev, file, mode_cmd;
@@
fb_create_func(dev, file
+ ,info
,mode_cmd)
@@
expression dev, file, mode_cmd;
@@
drm_gem_fb_create(dev, file
+ ,info
,mode_cmd)
@@
expression dev, file, mode_cmd;
@@
drm_gem_fb_create_with_dirty(dev, file
+ ,info
,mode_cmd)
@@
expression dev, file_priv, mode_cmd;
identifier info, fb;
@@
info = drm_get_format_info(...);
...
fb = dev->mode_config.funcs->fb_create(dev, file_priv
+ ,info
,mode_cmd);
@@
identifier dev, file_priv, mode_cmd;
@@
struct drm_mode_config_funcs {
...
struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
struct drm_file *file_priv,
+ const struct drm_format_info *info,
const struct drm_mode_fb_cmd2 *mode_cmd);
...
};
v2: Fix kernel docs (Laurent)
Fix commit msg (Geert)
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Inki Dae <inki.dae@samsung.com>
Cc: Seung-Woo Kim <sw0312.kim@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Cc: Chun-Kuang Hu <chunkuang.hu@kernel.org>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Abhinav Kumar <quic_abhinavk@quicinc.com>
Cc: Dmitry Baryshkov <lumag@kernel.org>
Cc: Sean Paul <sean@poorly.run>
Cc: Marijn Suijten <marijn.suijten@somainline.org>
Cc: Marek Vasut <marex@denx.de>
Cc: Stefan Agner <stefan@agner.ch>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Cc: Biju Das <biju.das.jz@bp.renesas.com>
Cc: Sandy Huang <hjc@rock-chips.com>
Cc: "Heiko Stübner" <heiko@sntech.de>
Cc: Andy Yan <andy.yan@rock-chips.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Mikko Perttunen <mperttunen@nvidia.com>
Cc: Dave Stevenson <dave.stevenson@raspberrypi.com>
Cc: "Maíra Canal" <mcanal@igalia.com>
Cc: Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: Gurchetan Singh <gurchetansingh@chromium.org>
Cc: Chia-I Wu <olvaffe@gmail.com>
Cc: Zack Rusin <zack.rusin@broadcom.com>
Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
Cc: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Cc: amd-gfx@lists.freedesktop.org
Cc: linux-arm-msm@vger.kernel.org
Cc: freedreno@lists.freedesktop.org
Cc: nouveau@lists.freedesktop.org
Cc: virtualization@lists.linux.dev
Cc: spice-devel@lists.freedesktop.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-tegra@vger.kernel.org
Cc: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Acked-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Acked-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250701090722.13645-5-ville.syrjala@linux.intel.com
2025-07-01 12:07:07 +03:00
|
|
|
const struct drm_format_info *info,
|
2020-03-11 15:55:41 +01:00
|
|
|
const struct drm_mode_fb_cmd2 *mode_cmd)
|
|
|
|
{
|
|
|
|
struct drm_afbc_framebuffer *afbc_fb;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
afbc_fb = kzalloc(sizeof(*afbc_fb), GFP_KERNEL);
|
|
|
|
if (!afbc_fb)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2025-07-01 12:07:10 +03:00
|
|
|
ret = drm_gem_fb_init_with_funcs(dev, &afbc_fb->base,
|
|
|
|
file, info, mode_cmd,
|
2020-03-11 15:55:41 +01:00
|
|
|
&rockchip_drm_fb_funcs);
|
|
|
|
if (ret) {
|
|
|
|
kfree(afbc_fb);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drm_is_afbc(mode_cmd->modifier[0])) {
|
2025-07-01 12:07:11 +03:00
|
|
|
ret = drm_gem_fb_afbc_init(dev, info, mode_cmd, afbc_fb);
|
2020-03-11 15:55:41 +01:00
|
|
|
if (ret) {
|
2025-05-09 11:15:59 +08:00
|
|
|
drm_framebuffer_put(&afbc_fb->base);
|
2020-03-11 15:55:41 +01:00
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &afbc_fb->base;
|
|
|
|
}
|
|
|
|
|
2014-08-22 18:36:26 +08:00
|
|
|
static const struct drm_mode_config_funcs rockchip_drm_mode_config_funcs = {
|
2020-03-11 15:55:41 +01:00
|
|
|
.fb_create = rockchip_fb_create,
|
2015-11-30 18:22:42 +08:00
|
|
|
.atomic_check = drm_atomic_helper_check,
|
2016-06-08 14:19:12 +02:00
|
|
|
.atomic_commit = drm_atomic_helper_commit,
|
2014-08-22 18:36:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void rockchip_drm_mode_config_init(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
dev->mode_config.min_width = 0;
|
|
|
|
dev->mode_config.min_height = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set max width and height as default value(4096x4096).
|
|
|
|
* this value would be used to check framebuffer size limitation
|
|
|
|
* at drm_mode_addfb().
|
|
|
|
*/
|
|
|
|
dev->mode_config.max_width = 4096;
|
|
|
|
dev->mode_config.max_height = 4096;
|
|
|
|
|
|
|
|
dev->mode_config.funcs = &rockchip_drm_mode_config_funcs;
|
2016-06-08 14:19:12 +02:00
|
|
|
dev->mode_config.helper_private = &rockchip_mode_config_helpers;
|
2022-04-22 09:28:39 +02:00
|
|
|
|
|
|
|
dev->mode_config.normalize_zpos = true;
|
2014-08-22 18:36:26 +08:00
|
|
|
}
|