From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Heiko Stuebner <heiko@sntech.de>,
Philipp Zabel <p.zabel@pengutronix.de>
Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
"Paul Kocialkowski" <paulk@sys-base.io>,
"Sven Püschel" <s.pueschel@pengutronix.de>,
"Nicolas Dufresne" <nicolas.dufresne@collabora.com>,
"Detlev Casanova" <detlev.casanova@collabora.com>,
"Hans Verkuil" <hverkuil@kernel.org>,
"Jiaxing Hu" <gahing@gahingwoo.com>,
"Arun Iyengar" <aiyengar1990@gmail.com>
Subject: [PATCH RFC 07/12] media: rockchip: rkvenc: Encode pictures wider than 4096 pixels
Date: Tue, 10 Nov 2026 10:08:09 +0000 [thread overview]
Message-ID: <20261110-rkvenc-v1-7-ea8b47122d8c@gmail.com> (raw)
In-Reply-To: <20261110-rkvenc-v1-0-ea8b47122d8c@gmail.com>
From: Arun Iyengar <aiyengar1990@gmail.com>
The internal line buffers of the VEPU580 cover pictures up to 4096
pixels wide. Wider pictures need an external line buffer of 480 bytes per
64-pixel column, given to the encoder by its bottom address and its
(exclusive) top address in ADR_ELBB and ADR_ELBT. Both registers hold
address bits 31:8.
Allocate that buffer per context at stream start when the encoded width
is above 4096, program it for every picture, and raise the frame size
limits of both codecs to the 16384x8192 the encoder supports.
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
.../media/platform/rockchip/rkvenc/rkvenc-h264.c | 6 ++--
.../media/platform/rockchip/rkvenc/rkvenc-hevc.c | 6 ++--
.../media/platform/rockchip/rkvenc/rkvenc-regs.h | 2 ++
.../platform/rockchip/rkvenc/rkvenc-vepu580.c | 38 ++++++++++++++++++++--
drivers/media/platform/rockchip/rkvenc/rkvenc.c | 8 ++++-
drivers/media/platform/rockchip/rkvenc/rkvenc.h | 4 +++
6 files changed, 54 insertions(+), 10 deletions(-)
diff --git a/drivers/media/platform/rockchip/rkvenc/rkvenc-h264.c b/drivers/media/platform/rockchip/rkvenc/rkvenc-h264.c
index 665c54278029..11051aea43b4 100644
--- a/drivers/media/platform/rockchip/rkvenc/rkvenc-h264.c
+++ b/drivers/media/platform/rockchip/rkvenc/rkvenc-h264.c
@@ -501,11 +501,11 @@ const struct rkvenc_coded_fmt_desc rkvenc_h264_fmt_desc = {
.size_align = 16,
.frmsize = {
.min_width = 64,
- /* The external line buffer for wider pictures is not handled. */
- .max_width = 4096,
+ /* Wider than 4096 with the external line buffer. */
+ .max_width = 16384,
.step_width = 2,
.min_height = 64,
- .max_height = 4096,
+ .max_height = 8192,
.step_height = 2,
},
.ctrls = &rkvenc_h264_ctrls,
diff --git a/drivers/media/platform/rockchip/rkvenc/rkvenc-hevc.c b/drivers/media/platform/rockchip/rkvenc/rkvenc-hevc.c
index a3d35a7fdc3f..638b13d6642a 100644
--- a/drivers/media/platform/rockchip/rkvenc/rkvenc-hevc.c
+++ b/drivers/media/platform/rockchip/rkvenc/rkvenc-hevc.c
@@ -689,11 +689,11 @@ const struct rkvenc_coded_fmt_desc rkvenc_hevc_fmt_desc = {
.size_align = 8,
.frmsize = {
.min_width = 64,
- /* Wider pictures need tiles, which are not implemented. */
- .max_width = 4096,
+ /* Wider than 4096 with the external line buffer. */
+ .max_width = 16384,
.step_width = 2,
.min_height = 64,
- .max_height = 4096,
+ .max_height = 8192,
.step_height = 2,
},
.ctrls = &rkvenc_hevc_ctrls,
diff --git a/drivers/media/platform/rockchip/rkvenc/rkvenc-regs.h b/drivers/media/platform/rockchip/rkvenc/rkvenc-regs.h
index e8e7ce045f90..dd91004e31cf 100644
--- a/drivers/media/platform/rockchip/rkvenc/rkvenc-regs.h
+++ b/drivers/media/platform/rockchip/rkvenc/rkvenc-regs.h
@@ -82,6 +82,8 @@
#define VEPU580_LPFR_ADDR 0x02c4
#define VEPU580_EBUFT_ADDR 0x02d8
#define VEPU580_EBUFB_ADDR 0x02dc
+/* Widest picture the internal line buffers cover. */
+#define VEPU580_LINE_BUF_MAX_WIDTH 4096
/* Frame class: control */
#define VEPU580_ENC_PIC 0x0300
diff --git a/drivers/media/platform/rockchip/rkvenc/rkvenc-vepu580.c b/drivers/media/platform/rockchip/rkvenc/rkvenc-vepu580.c
index f14d5ae0b7f7..adb1372dff57 100644
--- a/drivers/media/platform/rockchip/rkvenc/rkvenc-vepu580.c
+++ b/drivers/media/platform/rockchip/rkvenc/rkvenc-vepu580.c
@@ -179,9 +179,41 @@ void vepu580_setup_common(struct rkvenc_ctx *ctx, struct rkvenc_core *core,
rkvenc_set(core, VEPU580_SLI_SPLT, 0);
rkvenc_set(core, VEPU580_SLI_CFG, VEPU580_SLI_CFG_SLI_CRS_EN);
- /* No external line buffer: widths above 4096 are rejected for now. */
- rkvenc_set(core, VEPU580_EBUFT_ADDR, 0);
- rkvenc_set(core, VEPU580_EBUFB_ADDR, 0);
+ /* The external line buffer: top is the exclusive end, 0 when unused. */
+ if (ctx->line_buf.cpu) {
+ rkvenc_set(core, VEPU580_EBUFT_ADDR,
+ ctx->line_buf.dma + ctx->line_buf.size);
+ rkvenc_set(core, VEPU580_EBUFB_ADDR, ctx->line_buf.dma);
+ } else {
+ rkvenc_set(core, VEPU580_EBUFT_ADDR, 0);
+ rkvenc_set(core, VEPU580_EBUFB_ADDR, 0);
+ }
+}
+
+/*
+ * The internal line buffers cover pictures up to 4096 pixels wide. Wider
+ * pictures need an external one of 480 bytes per 64-pixel column. Its
+ * address registers hold bits 31:8 only, hence the 256-byte rounding (the
+ * DMA allocation itself is page aligned). The content does not outlive a
+ * picture, and a context runs one picture at a time, so one buffer per
+ * context is enough.
+ */
+int vepu580_alloc_line_buf(struct rkvenc_ctx *ctx)
+{
+ unsigned int width = ALIGN(ctx->coded_fmt.fmt.pix_mp.width,
+ ctx->coded_fmt_desc->size_align);
+
+ if (width <= VEPU580_LINE_BUF_MAX_WIDTH)
+ return 0;
+
+ return rkvenc_alloc_aux(ctx->dev, &ctx->line_buf,
+ ALIGN(DIV_ROUND_UP(width, 64) * 480, 256),
+ false);
+}
+
+void vepu580_free_line_buf(struct rkvenc_ctx *ctx)
+{
+ rkvenc_free_aux(ctx->dev, &ctx->line_buf);
}
/*
diff --git a/drivers/media/platform/rockchip/rkvenc/rkvenc.c b/drivers/media/platform/rockchip/rkvenc/rkvenc.c
index 26bee08d4c2d..61c745994da9 100644
--- a/drivers/media/platform/rockchip/rkvenc/rkvenc.c
+++ b/drivers/media/platform/rockchip/rkvenc/rkvenc.c
@@ -505,7 +505,12 @@ static int rkvenc_start_streaming(struct vb2_queue *q, unsigned int count)
ctx->src_fmt.fmt.pix_mp.height != ctx->coded_fmt.fmt.pix_mp.height)
ret = -EINVAL;
else
- ret = desc->ops->start ? desc->ops->start(ctx) : 0;
+ ret = vepu580_alloc_line_buf(ctx);
+ if (!ret && desc->ops->start) {
+ ret = desc->ops->start(ctx);
+ if (ret)
+ vepu580_free_line_buf(ctx);
+ }
if (ret) {
rkvenc_queue_cleanup(q, VB2_BUF_STATE_QUEUED);
return ret;
@@ -524,6 +529,7 @@ static void rkvenc_stop_streaming(struct vb2_queue *q)
if (ctx->started) {
if (desc->ops->stop)
desc->ops->stop(ctx);
+ vepu580_free_line_buf(ctx);
ctx->started = false;
}
diff --git a/drivers/media/platform/rockchip/rkvenc/rkvenc.h b/drivers/media/platform/rockchip/rkvenc/rkvenc.h
index c2dd0bb91c51..ec6a955921b8 100644
--- a/drivers/media/platform/rockchip/rkvenc/rkvenc.h
+++ b/drivers/media/platform/rockchip/rkvenc/rkvenc.h
@@ -226,6 +226,8 @@ struct rkvenc_ctx {
struct v4l2_ctrl_handler ctrl_hdl;
struct rkvenc_core *core;
struct v4l2_ctrl *avg_qp_ctrl;
+ /* External line buffer, only for pictures wider than 4096 pixels. */
+ struct rkvenc_aux_buf line_buf;
void *priv;
bool started;
};
@@ -249,6 +251,8 @@ static inline void rkvenc_or(struct rkvenc_core *core, u32 reg, u32 val)
int rkvenc_alloc_aux(struct rkvenc_dev *rkvenc, struct rkvenc_aux_buf *buf,
size_t size, bool kernel_mapping);
void rkvenc_free_aux(struct rkvenc_dev *rkvenc, struct rkvenc_aux_buf *buf);
+int vepu580_alloc_line_buf(struct rkvenc_ctx *ctx);
+void vepu580_free_line_buf(struct rkvenc_ctx *ctx);
void vepu580_setup_common(struct rkvenc_ctx *ctx, struct rkvenc_core *core,
struct rkvenc_run *run);
void vepu580_setup_me(struct rkvenc_core *core, unsigned int width_mbs,
--
2.55.0
next prev parent reply other threads:[~2026-11-10 10:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 10:08 [PATCH RFC 00/12] media: rockchip: Add a VEPU580 stateless H.264/HEVC encoder driver for the RK3588 Arun Iyengar via B4 Relay
2026-11-10 10:08 ` [PATCH RFC 01/12] dt-bindings: media: Add the Rockchip VEPU580 video encoder Arun Iyengar via B4 Relay
2026-11-10 10:08 ` [PATCH RFC 02/12] media: rockchip: Add a VEPU580 stateless video encoder driver Arun Iyengar via B4 Relay
2026-11-10 10:08 ` [PATCH RFC 03/12] media: rockchip: rkvenc: Prepare the VEPU580 helpers for a second codec Arun Iyengar via B4 Relay
2026-11-10 10:08 ` [PATCH RFC 04/12] media: rockchip: rkvenc: Add HEVC encoding Arun Iyengar via B4 Relay
2026-11-10 10:08 ` [PATCH RFC 05/12] media: rockchip: rkvenc: Don't enable adaptive QP with the row rate control Arun Iyengar via B4 Relay
2026-11-10 10:08 ` [PATCH RFC 06/12] media: rockchip: rkvenc: Use MPP's moving-scene H.264 RDO tuning Arun Iyengar via B4 Relay
2026-11-10 10:08 ` Arun Iyengar via B4 Relay [this message]
2026-11-10 10:08 ` [PATCH RFC 08/12] media: rockchip: rkvenc: Encode HEVC wider than 4096 pixels in tile columns Arun Iyengar via B4 Relay
2026-11-10 10:08 ` [PATCH RFC 09/12] media: rockchip: rkvenc: Limit the QP of the HEVC I pictures to 15..51 Arun Iyengar via B4 Relay
2026-11-10 10:08 ` [PATCH RFC 10/12] media: rockchip: rkvenc: Re-encode oversized HEVC pictures Arun Iyengar via B4 Relay
2026-11-10 10:08 ` [PATCH RFC 11/12] media: rockchip: rkvenc: Offer VBR for H.264 encoding Arun Iyengar via B4 Relay
2026-11-10 10:08 ` [PATCH RFC 12/12] arm64: dts: rockchip: Add the VEPU580 encoder cores to the RK3588 Arun Iyengar via B4 Relay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261110-rkvenc-v1-7-ea8b47122d8c@gmail.com \
--to=devnull+aiyengar1990.gmail.com@kernel.org \
--cc=aiyengar1990@gmail.com \
--cc=conor+dt@kernel.org \
--cc=detlev.casanova@collabora.com \
--cc=devicetree@vger.kernel.org \
--cc=gahing@gahingwoo.com \
--cc=heiko@sntech.de \
--cc=hverkuil@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=p.zabel@pengutronix.de \
--cc=paulk@sys-base.io \
--cc=robh@kernel.org \
--cc=s.pueschel@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®