media: rockchip: Add a VEPU580 stateless H.264/HEVC encoder driver for the RK3588
Subsystems (3)
cover media: rockchip: Add a VEPU580 stateless H.264/HEVC encoder driver for the RK3588
Hi,
This RFC adds a V4L2 stateless encoder driver for the VEPU580 (RKVENC) of the Rockchip RK3588, the H.264/HEVC encoder block with two cores that the vendor kernel drives through its "mpp" framework. It is a non-Hantro user of Paul Kocialkowski's H.264 stateless encode uAPI, and the first user of the HEVC stateless encode uAPI I am proposing in a separate RFC.
It depends on unmerged work and is sent for review of the approach. It applies on media next 6628e7d4c6b2 (v7.4-rc1) with, in this order:
- patches 1-7 of "[PATCH 00/14] media: Add V4L2 H.264 stateless encode and VC8000E support" v1 (Paul Kocialkowski, 2026-05-22):
https://lore.kernel.org/all/[email protected]/
(https://patchwork.kernel.org/project/linux-media/list/?series=1099281)
- my "[PATCH RFC 00/11] media: h264: Stateless encode core follow-ups" (the SPS/PPS fix, the CBR rework on v4l2-enc-cbr and VBR);
- my "[PATCH RFC 00/10] media: Add a V4L2 HEVC stateless encode uAPI and helpers", for the HEVC patches;
- patches 6 and 7 of "[PATCH v2 00/17] media: rockchip: rga: Add multi-core support" (Sven Püschel, 2026-09-16), for v4l2_m2m_set_max_parallel_jobs():
https://lore.kernel.org/all/[email protected]/
Paul has announced a rework of the H.264 core helpers for v2; the driver will follow it.
Patches 1-4 add the binding, the driver with H.264, and HEVC. Both cores are independent DT nodes (nothing in the hardware ties them together) bound as components of one m2m device, sharing the first core's IOMMU domain; jobs of different contexts run on both cores in parallel. The one-stream-on-two-cores handshake of the vendor driver is not used. Patches 5-6 change the defaults the driver took from MPP (no texture adaptive QP, MPP's moving-scene H.264 tuning), with the measurements in the commit messages. Patches 7-8 encode pictures wider than 4096 pixels (HEVC in tile columns, as MPP does), patches 9-10 add MPP's I picture QP limits and re-encoding of oversized pictures for HEVC, patch 11 offers VBR for H.264. Patch 12 adds the device tree nodes and can go through the Rockchip tree once the binding is accepted.
H.264: Baseline/Main/High, CAVLC/CABAC, 8x8 transform, I and P pictures with one reference (the hardware has a single reference read port), single slice. HEVC: Main profile, I and P pictures, inline short-term RPS and long-term pictures as resolved by the core, TMVP. Both up to 16384x8192. For both, the core writes the parameter sets at the start of the CAPTURE buffer and the hardware writes the slice header and data from its syntax registers. Reconstructed/reference pictures are driver-internal FBC buffers. Fixed QP, constant quality and constant bitrate come from the cores, whose picture size target drives the hardware row rate control; the measured per-picture statistics are reported back (V4L2_CID_MPEG_VIDEO_AVERAGE_QP for H.264, the HEVC feedback control for HEVC).
There is no public documentation of this block. The register layout, meanings and default tuning values were derived from the Rockchip MPP userspace library (Apache-2.0), read as documentation and written as named fields and formulas; the power, watchdog and reset/IOMMU recovery sequences follow the vendor kernel driver. No code was copied.
Related: Jiaxing Hu's RFC for the VEPU510 of the RK3576 (a stateful H.264 driver) is a different generation of this block:
https://lore.kernel.org/all/[email protected]/
Tested on an Orange Pi 5 (RK3588S), on a v7.3-based kernel whose rkvenc files and binding are byte-identical to this series, with a request-API test client and GStreamer (local patches), decoding every stream with FFmpeg and measuring PSNR against the source:
- H.264, 1080p60, 300 pictures of two clips (Big Buck Bunny and a natural one): CBR at 4 Mbit/s with an IDR period of 120, 8 Mbit/s with 10 and 20 Mbit/s all-intra within 2.2% of the target, the largest one second window at most 1.37 times the bitrate (a scene change in a P picture); VBR with the peak at 1.5 times the bitrate in the same cases and at 8 Mbit/s with an IDR period of 120 within 3.2% of the target, every one second window
within the peak (at most 0.94 of it);
- HEVC, CBR with an IDR period of 120: 1080p60 at 2-16 Mbit/s and 2160p30 at 20 and 40 Mbit/s within 3.4% of the target, the largest one second window at most 1.35 times the bitrate; 4104x2160, 5120x2880 and 8192x4320 in tile columns, PSNR-Y 43-52 dB.
With earlier revisions of patches 2-4: both cores probe and bind, v4l2-compliance 1.32 44/49 with 0 warnings (the 5 failures are the tool not knowing stateless encoders); H.264 and HEVC at 1080p and 4K, fixed QP 22-37 with GOP 1/10/30, the three H.264 profiles with CAVLC and CABAC, HEVC TMVP on/off, SAO off, long-term references, CQ and odd sizes with a conformance window, decode with 0 errors at 38-59 dB PSNR, and the HEVC feedback control matched the expected NAL type, POC, QP and reference list on every picture; two parallel 4K streams run one on each core at about twice the single-stream rate with outputs identical to single-stream runs; both cores runtime-suspend after the last job; H.264 up to 16384x2048 and 8192x4320 through the external line buffer. The error, watchdog and IOMMU recovery paths have not been exercised on hardware.
This series was developed with Claude (Anthropic) as a coding assistant:
it wrote the code and the commit messages, and I reviewed and tested every change as described above.
---
Arun Iyengar (12):
dt-bindings: media: Add the Rockchip VEPU580 video encoder
media: rockchip: Add a VEPU580 stateless video encoder driver
media: rockchip: rkvenc: Prepare the VEPU580 helpers for a second codec
media: rockchip: rkvenc: Add HEVC encoding
media: rockchip: rkvenc: Don't enable adaptive QP with the row rate control
media: rockchip: rkvenc: Use MPP's moving-scene H.264 RDO tuning
media: rockchip: rkvenc: Encode pictures wider than 4096 pixels
media: rockchip: rkvenc: Encode HEVC wider than 4096 pixels in tile columns
media: rockchip: rkvenc: Limit the QP of the HEVC I pictures to 15..51
media: rockchip: rkvenc: Re-encode oversized HEVC pictures
media: rockchip: rkvenc: Offer VBR for H.264 encoding
arm64: dts: rockchip: Add the VEPU580 encoder cores to the RK3588
.../bindings/media/rockchip,rk3588-vepu580.yaml | 93 ++ MAINTAINERS | 8 + arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 56 + drivers/media/platform/rockchip/Kconfig | 1 + drivers/media/platform/rockchip/Makefile | 1 + drivers/media/platform/rockchip/rkvenc/Kconfig | 18 + drivers/media/platform/rockchip/rkvenc/Makefile | 8 + .../media/platform/rockchip/rkvenc/rkvenc-h264.c | 519 +++++++ .../media/platform/rockchip/rkvenc/rkvenc-hevc.c | 869 +++++++++++ .../media/platform/rockchip/rkvenc/rkvenc-regs.h | 539 +++++++ .../platform/rockchip/rkvenc/rkvenc-vepu580.c | 999 +++++++++++++ drivers/media/platform/rockchip/rkvenc/rkvenc.c | 1581 ++++++++++++++++++++ drivers/media/platform/rockchip/rkvenc/rkvenc.h | 329 ++++ 13 files changed, 5021 insertions(+)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261110-rkvenc-e0f1c61c00a2
prerequisite-patch-id: fd11f19266754d1bd40bf61dd5d1da74a0dc13c2
prerequisite-patch-id: 7c7edc7344998d520efaf7b430c90fd527c704c7
prerequisite-patch-id: 4689de770eb1bcdc153d6beda2e392d0ce6f344d
prerequisite-patch-id: 0afdcc24892eac773036d05d8f504e5ccb35eb62
prerequisite-patch-id: ecc849b3328d4396380f0cfc331536c16d2e0d28
prerequisite-patch-id: c62d0fd16706c4328624948805eb2f8d7b223ae0
prerequisite-patch-id: e955d15603fd070034960a1362e4867c2f124d69
prerequisite-patch-id: 76eb64d7920ddc1f268afa6f13df14cf9d1931c8
prerequisite-patch-id: 654c303a6e9e4a3108e9ae9b7c9aa78f95b82c0c
prerequisite-patch-id: 96f470c1f8b2ca83ffc496f41fd173e925180501
prerequisite-patch-id: fa3430fcef00637bb84f9401bb9045dd46194298
prerequisite-patch-id: da666def8ed2b5296da8dee1be387b2818ba3cc3
prerequisite-patch-id: 7e532c86fbd0f7bd6705ac4f1544b7d7d27cbc26
prerequisite-patch-id: 09e1836b24606834b9ac4aa3c851d39f564cfef6
prerequisite-patch-id: fd8fcc747458e52344df760a17b61748361bfbb1
prerequisite-patch-id: 883eefffa7ea70d39d357467780cb4f2b69c8d36
prerequisite-patch-id: aa018c975f9b1f0555164d46446dea01d6496823
prerequisite-patch-id: d8d6323a5177f6b1ce661a86ee5813d55b4a3570
prerequisite-patch-id: 25c5c1c067936d313b20c287e66da34fa6c52f02
prerequisite-patch-id: d7ab57d731445a0d6a06a305f015060e1ea2aa0d
prerequisite-patch-id: 68ed30e5ad9b17d0a8f4cbc8c4278cbb2a82ea23
prerequisite-patch-id: 5f042c1c0679a0f587bcd623e69d7f3aa205d4ce
prerequisite-patch-id: 4e3feb81141e90296253fe1809dd9d7b8cd86244
prerequisite-patch-id: 68222baa5172eef1abdbe693e0209056b98e9d54
prerequisite-patch-id: d66a7ce272d3911c662d008828570f439ce298c7
prerequisite-patch-id: dcb576eb303c4f0794c67ae9b2c1a41c208ab519
prerequisite-patch-id: 53bde0480b78711ed69704eb2f343b667fdbe087
prerequisite-patch-id: 6cf0960c01f1c7ce51101987c37633ffe214075f
prerequisite-patch-id: 6ad9550f96aeed8429737800e4afc6e35be2c3ed
prerequisite-patch-id: 42252ba52d9c65ea011f6971395e709cc4bff684
Best regards,
Signature · 1 line
Arun Iyengar <[email protected]>
RFC PATCH 1/12 dt-bindings: media: Add the Rockchip VEPU580 video encoder
The VEPU580 (RKVENC) is the H.264/HEVC video encoder of the RK3588. The SoC has two identical cores at 0xfdbd0000 and 0xfdbe0000, each with its own clocks, resets, power domain, interrupt and IOMMU.
Describe each core as an independent node. Unlike the vendor kernel, which groups the cores under software-only "mpp-service" and "ccu" nodes, nothing in the hardware ties the cores together, so how they are used (one job per core, or both cores on one stream) is left to the operating system.
--- .../bindings/media/rockchip,rk3588-vepu580.yaml | 93 ++++++++++++++++++++++ MAINTAINERS | 7 ++ 2 files changed, 100 insertions(+)
Documentation/devicetree/bindings/media/rockchip,rk3588-vepu580.yaml new file +93 -0
@@ -0,0 +1,93 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/rockchip,rk3588-vepu580.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Rockchip VEPU580 video encoder + +maintainers: + - Heiko Stuebner <[email protected]> + +description: + The VEPU580 (also called RKVENC) is the H.264 and HEVC video encoder of the + Rockchip RK3588. The SoC has two identical encoder cores, each with its own + clocks, resets, power domain, interrupt and IOMMU. Every core is described + by its own node; the operating system may use the cores independently or + together. + +properties: + compatible: + const: rockchip,rk3588-vepu580 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + items: + - description: AXI bus clock + - description: AHB bus clock + - description: Encoder core clock + + clock-names: + items: + - const: aclk + - const: hclk + - const: core + + resets: + items: + - description: AXI bus reset + - description: AHB bus reset + - description: Encoder core reset + + reset-names: + items: + - const: aclk + - const: hclk + - const: core + + power-domains: + maxItems: 1 + + iommus: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - clocks + - clock-names + - power-domains + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/rockchip,rk3588-cru.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/power/rk3588-power.h> + #include <dt-bindings/reset/rockchip,rk3588-cru.h> + + bus { + #address-cells = <2>; + #size-cells = <2>; + + video-codec@fdbd0000 { + compatible = "rockchip,rk3588-vepu580"; + reg = <0x0 0xfdbd0000 0x0 0x6000>; + interrupts = <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&cru ACLK_RKVENC0>, <&cru HCLK_RKVENC0>, + <&cru CLK_RKVENC0_CORE>; + clock-names = "aclk", "hclk", "core"; + resets = <&cru SRST_A_RKVENC0>, <&cru SRST_H_RKVENC0>, + <&cru SRST_RKVENC0_CORE>; + reset-names = "aclk", "hclk", "core"; + power-domains = <&power RK3588_PD_VENC0>; + iommus = <&vepu580_0_mmu>; + }; + };
MAINTAINERS +7 -0
@@ -24322,6 +24322,13 @@ S: Maintained F: Documentation/devicetree/bindings/sound/rockchip,rk3576-sai.yaml F: sound/soc/rockchip/rockchip_sai.* +ROCKCHIP VEPU580 VIDEO ENCODER DRIVER +M: Arun Iyengar <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/media/rockchip,rk3588-vepu580.yaml + ROCKCHIP XPCS DRIVER M: Coia Prant <[email protected]> L: [email protected]
Signature · 1 line
2.55.0
RFC PATCH 2/12 media: rockchip: Add a VEPU580 stateless video encoder driver
In reply to Arun IyengarAdd a V4L2 m2m driver for the VEPU580 (RKVENC) encoder of the RK3588, using the H.264 stateless encode uAPI and helpers (v4l2-h264-enc) proposed by Paul Kocialkowski. H.264 is supported:
- Baseline, Main and High profile, CAVLC and CABAC, 8x8 transform, a single slice per picture, I and P pictures with one reference picture (the hardware has a single reference read port);
- input in NV12, NV12M, NV21, YUV420, YUV420M, YUYV or UYVY, up to 4096x4096 (wider pictures need the external line buffer, not handled);
- the parameter sets come from the v4l2-h264-enc RBSP writer and are put at the start of the CAPTURE buffer; the hardware then writes the start code, NAL header and slice header from its syntax registers, followed by the slice data;
- reconstructed and reference pictures are driver-internal FBC buffers with their quarter-resolution thumbnails, managed by the v4l2-h264-enc reference code;
- direct QP and constant quality use a fixed frame QP. In CBR mode the frame size target of the common rate control is also given to the hardware macroblock row rate control with adaptive quantisation, which may move the QP of each row by up to row_rc_qp_range (module parameter, default 2, 0 for frame-level rate control only). The average QP measured by the hardware is exposed through V4L2_CID_MPEG_VIDEO_AVERAGE_QP. It is not fed back into the frame-level
statistics: with adaptive quantisation it sits below the frame QP and the estimate would spiral down.
Each of the two cores is a component of a virtual master device that owns the video device. The cores share the first core's IOMMU domain, and v4l2_m2m_set_max_parallel_jobs() lets jobs of different contexts run on both cores at the same time. The dual-core handshake (one stream on two cores) is not used.
The codec specific part sits behind a small ops structure so that HEVC can be added once a stateless HEVC encode uAPI exists.
Provenance: there is no public documentation of this block. The register layout and meanings, and the default tuning values (RDO lambda and weight tables, intra/ATR thresholds, motion search parameters, flat quantisation tables, row rate control thresholds) were derived from the Rockchip MPP user space library (Apache-2.0: vepu580_common.h, hal_h264e_vepu580.c, hal_h264e_vepu580_reg.h, hal_h264e_vepu580_tune.c, vepu5xx_common.c). They are written as named fields and formulas, not register dumps. The power, watchdog, per-frame force clear and reset/IOMMU recovery sequences follow the Rockchip BSP mpp_rkvenc2 driver (GPL-2.0) as found in an out-of-tree port, with the interrupt status bits corrected to the layout used by MPP (safe clear done is bit 2, watchdog bit 8).
--- MAINTAINERS | 1 + drivers/media/platform/rockchip/Kconfig | 1 + drivers/media/platform/rockchip/Makefile | 1 + drivers/media/platform/rockchip/rkvenc/Kconfig | 17 + drivers/media/platform/rockchip/rkvenc/Makefile | 7 + .../media/platform/rockchip/rkvenc/rkvenc-h264.c | 520 +++++++ .../media/platform/rockchip/rkvenc/rkvenc-regs.h | 379 +++++ .../platform/rockchip/rkvenc/rkvenc-vepu580.c | 585 ++++++++ drivers/media/platform/rockchip/rkvenc/rkvenc.c | 1502 ++++++++++++++++++++ drivers/media/platform/rockchip/rkvenc/rkvenc.h | 236 +++ 10 files changed, 3249 insertions(+)
MAINTAINERS +1 -0
@@ -24328,6 +24328,7 @@ L: [email protected] L: [email protected] S: Maintained F: Documentation/devicetree/bindings/media/rockchip,rk3588-vepu580.yaml +F: drivers/media/platform/rockchip/rkvenc/ ROCKCHIP XPCS DRIVER M: Coia Prant <[email protected]>
drivers/media/platform/rockchip/Kconfig +1 -0
@@ -6,3 +6,4 @@ source "drivers/media/platform/rockchip/rga/Kconfig" source "drivers/media/platform/rockchip/rkcif/Kconfig" source "drivers/media/platform/rockchip/rkisp1/Kconfig" source "drivers/media/platform/rockchip/rkvdec/Kconfig" +source "drivers/media/platform/rockchip/rkvenc/Kconfig"
drivers/media/platform/rockchip/Makefile +1 -0
@@ -3,3 +3,4 @@ obj-y += rga/ obj-y += rkcif/ obj-y += rkisp1/ obj-y += rkvdec/ +obj-y += rkvenc/
drivers/media/platform/rockchip/rkvenc/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 +config VIDEO_ROCKCHIP_VENC + tristate "Rockchip VEPU580 stateless video encoder driver" + depends on ARCH_ROCKCHIP || COMPILE_TEST + depends on VIDEO_DEV + select MEDIA_CONTROLLER + select VIDEOBUF2_DMA_CONTIG + select V4L2_MEM2MEM_DEV + select V4L2_H264 + select V4L2_H264_ENC + help + Support for the VEPU580 (RKVENC) video encoder of the Rockchip + RK3588, using the V4L2 stateless encoder interface. H.264 is + supported. + + To compile this driver as a module, choose M here: the module + will be called rockchip-venc.
drivers/media/platform/rockchip/rkvenc/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_VIDEO_ROCKCHIP_VENC) += rockchip-venc.o + +rockchip-venc-y += \ + rkvenc.o \ + rkvenc-h264.o \ + rkvenc-vepu580.o
drivers/media/platform/rockchip/rkvenc/rkvenc-h264.c new file +520 -0
520 lines not on this page · raw message
drivers/media/platform/rockchip/rkvenc/rkvenc-regs.h new file +379 -0
379 lines not on this page · raw message
drivers/media/platform/rockchip/rkvenc/rkvenc-vepu580.c new file +585 -0
585 lines not on this page · raw message
drivers/media/platform/rockchip/rkvenc/rkvenc.c new file +1502 -0
1,477 lines not on this page · raw message
drivers/media/platform/rockchip/rkvenc/rkvenc.h new file +236 -0
236 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.55.0
Part of the diff is not shown here. View the raw message.
RFC PATCH 3/12 media: rockchip: rkvenc: Prepare the VEPU580 helpers for a second codec
In reply to Arun IyengarMake the codec-independent VEPU580 programming usable by the coming HEVC backend, without changing the H.264 programming:
- The encoded picture size alignment (enc_rsl and src_fill) comes from the coded format: 16 for H.264, while HEVC uses 8.
- The hardware row rate control takes its codec-specific parameters (QP adjustment per deviation bucket, outer threshold multiple, AQ mode) from a table. The H.264 one holds the values used so far.
- The row_rc_qp_range module parameter moves to the shared code so that both codecs honour it. Its name and default are unchanged.
- Controls shared by several coded formats are registered once.
- The status read-back also collects the inter and intra block counts per block size and the lowest and highest QP of the 8x8 block QP histogram, for the per-frame statistics.
--- .../media/platform/rockchip/rkvenc/rkvenc-h264.c | 22 +++++------- .../media/platform/rockchip/rkvenc/rkvenc-regs.h | 7 ++++ .../platform/rockchip/rkvenc/rkvenc-vepu580.c | 41 +++++++++++++++------- drivers/media/platform/rockchip/rkvenc/rkvenc.c | 24 ++++++++++--- drivers/media/platform/rockchip/rkvenc/rkvenc.h | 41 +++++++++++++++++++++- 5 files changed, 103 insertions(+), 32 deletions(-)
drivers/media/platform/rockchip/rkvenc/rkvenc-h264.c +8 -14
@@ -12,20 +12,12 @@*/ #include <linux/bitfield.h> -#include <linux/moduleparam.h> #include <linux/sizes.h> #include <linux/slab.h> #include <media/v4l2-h264-enc.h> #include "rkvenc.h" -#define RKVENC_H264_ROW_QP_RANGE 2 - -static unsigned int row_rc_qp_range =RKVENC_H264_ROW_QP_RANGE ; -module_param (row_rc_qp_range, uint,0644 ); -MODULE_PARM_DESC (row_rc_qp_range, -"CBR: maximum per-row QP change by the hardware rate control (0 = frame-level rate control only)" ); -#define RKVENC_H264_PROFILE_BASELINE 66#define RKVENC_H264_PROFILE_MAIN 77#define RKVENC_H264_PROFILE_HIGH 100
@@ -390,15 +382,16 @@ static int rkvenc_h264_run(struct rkvenc_ctx *ctx, struct rkvenc_core *core,vepu580_setup_h264_tuning (ctx->dev, core, intra);/* -* In CBR mode the frame size target from the common rate control is -* handed to the hardware row rate control, which adapts the QP of -* each macroblock row by up to RKVENC_H264_ROW_QP_RANGE. +* In CBR mode the frame size target of the rate control is handed to +* the hardware row rate control, which adapts the QP of each +* macroblock row by up to the row_rc_qp_range parameter. */ h264->hw_rc = rc->mode && rc->mode->type ==V4L2_H264_ENC_RC_TYPE_CBR && -READ_ONCE (row_rc_qp_range); +READ_ONCE (rkvenc_row_rc_qp_range);if (h264->hw_rc) -vepu580_setup_row_rc (core, rc->qp, state->qp_min, state->qp_max, -min (READ_ONCE (row_rc_qp_range),15U ), +vepu580_setup_row_rc (core, &vepu580_h264_row_rc, rc->qp, + state->qp_min, state->qp_max, +min (READ_ONCE (rkvenc_row_rc_qp_range),15U ), (u64 )rc->size *8 , mbs, state->width_mbs);else
@@ -506,6 +499,7 @@ static const struct rkvenc_ctrls rkvenc_h264_ctrls = {const struct rkvenc_coded_fmt_desc rkvenc_h264_fmt_desc = { .fourcc =V4L2_PIX_FMT_H264_SLICE , + .size_align =16 , .frmsize = { .min_width =64 ,/* The external line buffer for wider pictures is not handled. */
drivers/media/platform/rockchip/rkvenc/rkvenc-regs.h +7 -0
@@ -360,6 +360,11 @@#define VEPU580_ST_BUS 0x4030#define VEPU580_ST_SNUM 0x4034#define VEPU580_ST_SLEN 0x4038 +#define VEPU580_ST_PNUM_P64 0x4100 +#define VEPU580_ST_PNUM_P32 0x4104 +#define VEPU580_ST_PNUM_P16 0x4108 +#define VEPU580_ST_PNUM_P8 0x410c +#define VEPU580_ST_PNUM_I32 0x4110#define VEPU580_ST_PNUM_I16 0x4114#define VEPU580_ST_PNUM_I8 0x4118#define VEPU580_ST_PNUM_I4 0x411c
@@ -367,6 +372,8 @@#define VEPU580_ST_BNUM_CME 0x4124#define VEPU580_ST_MADI 0x4128#define VEPU580_ST_BNUM_B16 0x412c +/* Histogram of the QP of the 8x8 blocks, one counter per QP 0..51 */ +#define VEPU580_ST_B8_QP (qp) (0x4200 + 4 * (qp))/* Debug class */ #define VEPU580_DBG_FRAME_CYC 0x5200
drivers/media/platform/rockchip/rkvenc/rkvenc-vepu580.c +28 -13
90 lines not on this page · raw message
drivers/media/platform/rockchip/rkvenc/rkvenc.c +20 -4
@@ -720,6 +720,7 @@ static void rkvenc_read_feedback(struct rkvenc_core *core, {void __iomem *r = core->regs;u32 sse_bsl =readl_relaxed (r +VEPU580_ST_SSE_BSL ); +unsigned int i; fb->bs_len =readl_relaxed (r +VEPU580_ST_BS_LGTH_L32 ) | (u64 )FIELD_GET (VEPU580_ST_BS_LGTH_H8 , sse_bsl) <<32 ;
@@ -728,9 +729,20 @@ static void rkvenc_read_feedback(struct rkvenc_core *core, fb->qp_sum =readl_relaxed (r +VEPU580_ST_QP_SUM ); fb->madi =readl_relaxed (r +VEPU580_ST_MADI ); fb->madp =readl_relaxed (r +VEPU580_ST_MADP ); - fb->intra_blocks =readl_relaxed (r +VEPU580_ST_PNUM_I16 ) + -readl_relaxed (r +VEPU580_ST_PNUM_I8 ) + -readl_relaxed (r +VEPU580_ST_PNUM_I4 ); +for (i =0 ; i <RKVENC_PNUM_COUNT ; i++) + fb->pnum[i] =readl_relaxed (r +VEPU580_ST_PNUM_P64 +4 * i); + fb->intra_blocks = fb->pnum[RKVENC_PNUM_I16 ] + fb->pnum[RKVENC_PNUM_I8 ] + + fb->pnum[RKVENC_PNUM_I4 ]; + + fb->qp_min =-1 ; + fb->qp_max =-1 ; +for (i =0 ; i <52 ; i++) { +if (!readl_relaxed (r +VEPU580_ST_B8_QP (i))) +continue ; +if (fb->qp_min <0 ) + fb->qp_min = i; + fb->qp_max = i; + } fb->cycles =readl_relaxed (r +VEPU580_DBG_FRAME_CYC ); }
@@ -941,8 +953,12 @@ static int rkvenc_init_ctrls(struct rkvenc_ctx *ctx)for (i =0 ; i <ARRAY_SIZE (rkvenc_coded_fmts); i++) {const struct rkvenc_ctrls *ctrls = rkvenc_coded_fmts[i]->ctrls; -for (j =0 ; j < ctrls->num_ctrls; j++) +for (j =0 ; j < ctrls->num_ctrls; j++) { +/* Controls shared by several codecs are added once. */ +if (v4l2_ctrl_find (hdl, ctrls->ctrls[j].id)) +continue ;v4l2_ctrl_new_custom (hdl, &ctrls->ctrls[j],NULL ); + } } ctx->avg_qp_ctrl =v4l2_ctrl_find (hdl,V4L2_CID_MPEG_VIDEO_AVERAGE_QP );
drivers/media/platform/rockchip/rkvenc/rkvenc.h +40 -1
70 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC PATCH 4/12 media: rockchip: rkvenc: Add HEVC encoding
In reply to Arun IyengarAdd an HEVC backend to the VEPU580 stateless encoder, on top of the V4L2 HEVC stateless encode core. The CAPTURE format is V4L2_PIX_FMT_HEVC_SLICE, one access unit per buffer, Annex B.
The core writes the VPS, SPS and PPS at the start of the CAPTURE buffer; the hardware writes the slice segment NAL unit and header from the HEVC syntax registers, and the core patches nuh_temporal_id_plus1 afterwards, which the hardware cannot write.
- Main profile, 8-bit 4:2:0, I and P pictures with one reference read port (max_l0_refs = 1), single slice and tile, up to 4096x4096.
- The SPS is forced to the fixed coding structure of the hardware:
64x64 CTBs, 8x8 minimum CBs, 4x4 to 32x32 TBs with max_transform_hierarchy_depth_inter/intra = 0 (MPP's TU depth 1 is HM's QuadtreeTUMaxDepth, coded minus 1; found on the board), no AMP, PCM, scaling lists, transform skip, transquant bypass, constrained intra prediction, tiles or WPP. cu_qp_delta is always enabled (as in MPP), so the row rate control and AQ can change the QP. The hardware has one chroma QP offset, so Cr follows Cb.
- Inline short-term RPS of up to four negative pictures and up to three long-term pictures, as the core resolves them; the reference picture is the first entry of list 0. TMVP with collocated motion vector buffers that are stored with each reference picture; motion vectors of an intra collocated picture are not loaded. TMVP is not used with long-term pictures.
- Recon/reference slots are FBC header + body, a 1/4 thumbnail and the collocated MVs, sized per CTU with one extra CTU row.
- Fixed QP, constant quality and constant bitrate come from the core. In the constant bitrate mode, the picture size target of the core drives the hardware CTU row rate control (MPP's HEVC deviation thresholds, row_rc_qp_range).
- Per-picture statistics (QP sum, count and range, luma SSE, intra and inter block counts in 8x8 units) are passed to the core, which reports them in V4L2_CID_STATELESS_HEVC_ENCODE_FEEDBACK. The request is completed after that, as before.
- HEVC tuning: RDO thresholds and weights per CU size, segment and smear thresholds, pre-intra and Sobel edge weights, intra cost thresholds, CIME/RIME/FME settings, AQ steps, the quantisation dead zone and the lambda tables (generated from their 2^(1/3) and 2^(1/6) progressions) use the values of MPP's default configuration. The scaling list block stays zero (scl_lst_sel = 0, flat).
The register layout and the default values were derived from the Rockchip MPP library (hal_h265e_vepu580.c, hal_h265e_vepu580_reg.h, hal_h265e_vepu580_tune.c, vepu5xx_common.c, h265e_ps.c, h265e_api.c, Apache-2.0), read as documentation; no code was copied.
--- drivers/media/platform/rockchip/rkvenc/Kconfig | 5 +- drivers/media/platform/rockchip/rkvenc/Makefile | 1 + .../media/platform/rockchip/rkvenc/rkvenc-hevc.c | 702 +++++++++++++++++++++ .../media/platform/rockchip/rkvenc/rkvenc-regs.h | 151 ++++- .../platform/rockchip/rkvenc/rkvenc-vepu580.c | 343 +++++++++- drivers/media/platform/rockchip/rkvenc/rkvenc.c | 5 + drivers/media/platform/rockchip/rkvenc/rkvenc.h | 16 + 7 files changed, 1218 insertions(+), 5 deletions(-)
drivers/media/platform/rockchip/rkvenc/Kconfig +3 -2
@@ -8,10 +8,11 @@ config VIDEO_ROCKCHIP_VENC select V4L2_MEM2MEM_DEV select V4L2_H264 select V4L2_H264_ENC + select V4L2_HEVC_ENC help Support for the VEPU580 (RKVENC) video encoder of the Rockchip - RK3588, using the V4L2 stateless encoder interface. H.264 is - supported. + RK3588, using the V4L2 stateless encoder interface. H.264 and + HEVC are supported. To compile this driver as a module, choose M here: the module will be called rockchip-venc.
drivers/media/platform/rockchip/rkvenc/Makefile +1 -0
@@ -4,4 +4,5 @@ obj-$(CONFIG_VIDEO_ROCKCHIP_VENC) += rockchip-venc.o rockchip-venc-y += \ rkvenc.o \ rkvenc-h264.o \ + rkvenc-hevc.o \ rkvenc-vepu580.o
drivers/media/platform/rockchip/rkvenc/rkvenc-hevc.c new file +702 -0
702 lines not on this page · raw message
drivers/media/platform/rockchip/rkvenc/rkvenc-regs.h +150 -1
175 lines not on this page · raw message
drivers/media/platform/rockchip/rkvenc/rkvenc-vepu580.c +341 -2
355 lines not on this page · raw message
drivers/media/platform/rockchip/rkvenc/rkvenc.c +5 -0
@@ -43,6 +43,7 @@ static const struct rkvenc_raw_fmt rkvenc_raw_fmts[] = {static const struct rkvenc_coded_fmt_desc *rkvenc_coded_fmts[] = { &rkvenc_h264_fmt_desc, + &rkvenc_hevc_fmt_desc, };static const struct rkvenc_coded_fmt_desc *rkvenc_find_coded_fmt (u32 fourcc)
@@ -655,6 +656,10 @@ static void rkvenc_hw_start(struct rkvenc_core *core)rkvenc_write_range (core,VEPU580_FRAME_START ,VEPU580_FRAME_END );rkvenc_write_range (core,VEPU580_KLUT_START ,VEPU580_KLUT_END );rkvenc_write_range (core,VEPU580_PARAM_START ,VEPU580_PARAM_END ); +if (FIELD_GET (VEPU580_ENC_PIC_ENC_STND , core->shadow[VEPU580_ENC_PIC /4 ]) == +VEPU580_ENC_STND_HEVC ) +rkvenc_write_range (core,VEPU580_HEVC_WGT_START , +VEPU580_HEVC_WGT_END );rkvenc_write_range (core,VEPU580_RDO_START ,VEPU580_RDO_END );rkvenc_write_range (core,VEPU580_SCL_START ,VEPU580_SCL_END );
drivers/media/platform/rockchip/rkvenc/rkvenc.h +16 -0
@@ -15,6 +15,7 @@#include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-h264-enc.h> +#include <media/v4l2-hevc-enc.h> #include <media/v4l2-ioctl.h> #include <media/v4l2-mem2mem.h> #include <media/videobuf2-core.h>
@@ -45,12 +46,15 @@ struct rkvenc_aux_buf {* @thumb: 1/4 x 1/4 down-scaled luma used by the coarse motion search * @colmv: collocated motion vectors (HEVC TMVP only) * @fbc_hdr_size: offset of the FBC body inside @pixel +* @colmv_valid: the hardware stored the motion vectors of the picture in +* @colmv (HEVC, inter pictures only) */ struct rkvenc_rec_buf {struct rkvenc_aux_buf pixel;struct rkvenc_aux_buf thumb;struct rkvenc_aux_buf colmv;size_t fbc_hdr_size; +bool colmv_valid; };enum rkvenc_pnum {
@@ -203,6 +207,14 @@ struct rkvenc_h264_ctx {bool hw_rc; }; +/** +* struct rkvenc_hevc_ctx - HEVC per-context state +*/ +struct rkvenc_hevc_ctx { +struct v4l2_hevc_enc enc; +bool hw_rc; +}; +struct rkvenc_ctx {struct v4l2_fh fh;struct rkvenc_dev *dev;
@@ -244,6 +256,9 @@ void vepu580_setup_me(struct rkvenc_core *core, unsigned int width_mbs, bool intra);void vepu580_setup_h264_tuning (struct rkvenc_dev *rkvenc,struct rkvenc_core *core,bool intra); +void vepu580_setup_hevc_me (struct rkvenc_core *core,unsigned int width, +unsigned int height,bool colmv_stor,bool colmv_load); +void vepu580_setup_hevc_tuning (struct rkvenc_core *core,bool intra);/** * struct vepu580_row_rc - codec-specific row rate control parameters
@@ -271,5 +286,6 @@ dma_addr_t rkvenc_dst_addr(struct rkvenc_run *run);size_t rkvenc_dst_size (struct rkvenc_run *run);extern const struct rkvenc_coded_fmt_desc rkvenc_h264_fmt_desc; +extern const struct rkvenc_coded_fmt_desc rkvenc_hevc_fmt_desc;#endif /* RKVENC_H_ */
Signature · 1 line
2.55.0
RFC PATCH 5/12 media: rockchip: rkvenc: Don't enable adaptive QP with the row rate control
In reply to Arun IyengarThe row rate control setup enables the texture adaptive QP (aq_en) with MPP's MADI threshold and QP step tables, as MPP does. On the board it costs PSNR at the same bitrate in every case measured: 0.7-1.3 dB for H.264 (where SSIM drops too) and 0.3-0.7 dB for HEVC (1080p60 clips, 2 to 16 Mb/s, CBR). Leave it off: only the row size deviation moves the QP within a picture, and the aq_mode field of the row rate control parameters goes away.
--- drivers/media/platform/rockchip/rkvenc/rkvenc-hevc.c | 3 +-- drivers/media/platform/rockchip/rkvenc/rkvenc-vepu580.c | 9 ++++++--- drivers/media/platform/rockchip/rkvenc/rkvenc.h | 2 -- 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/media/platform/rockchip/rkvenc/rkvenc-hevc.c +1 -2
@@ -40,12 +40,11 @@ static const struct v4l2_hevc_enc_rps_limits rkvenc_hevc_rps_limits = {/* * Row rate control: MPP's HEVC deviation thresholds are {2n, n, p, 2p} -* with the adjustments {-2, -1, 0, 1, 2} and AQ mode 1. +* with the adjustments {-2, -1, 0, 1, 2}. */ static const struct vepu580_row_rc rkvenc_hevc_row_rc = { .qp_adj = {-2 ,-1 ,0 ,1 ,2 ,0 ,0 ,0 ,0 }, .dthd_outer =2 , - .aq_mode = true, }; static int rkvenc_hevc_state_constrain(struct v4l2_hevc_enc *enc,
drivers/media/platform/rockchip/rkvenc/rkvenc-vepu580.c +6 -3
@@ -805,7 +805,6 @@ void vepu580_setup_hevc_tuning(struct rkvenc_core *core, bool intra)const struct vepu580_row_rc vepu580_h264_row_rc = { .qp_adj = {-2 ,-1 ,0 ,1 ,2 ,0 ,0 ,0 ,1 }, .dthd_outer =4 , - .aq_mode = false, }; void vepu580_setup_row_rc(struct rkvenc_core *core,
@@ -825,9 +824,13 @@ void vepu580_setup_row_rc(struct rkvenc_core *core, thd =5 * row_bits /16 ;rkvenc_or (core,VEPU580_ENC_PIC ,FIELD_PREP (VEPU580_ENC_PIC_PIC_QP , qp)); +/* +* MPP also enables the texture adaptive QP here (aq_en). With its +* tables that costs 0.3-1.3 dB of PSNR at the same bitrate (and SSIM +* for H.264), so the QP only follows the row size deviation. +*/ rkvenc_set (core,VEPU580_RC_CFG , -VEPU580_RC_CFG_RC_EN |VEPU580_RC_CFG_AQ_EN | - (cfg->aq_mode ?VEPU580_RC_CFG_AQ_MODE :0 ) | +VEPU580_RC_CFG_RC_EN |FIELD_PREP (VEPU580_RC_CFG_RC_CTU_NUM , blocks_per_row)); rkvenc_set(core, VEPU580_RC_QP, FIELD_PREP(VEPU580_RC_QP_RANGE, qp_range) |
drivers/media/platform/rockchip/rkvenc/rkvenc.h +0 -2
@@ -264,12 +264,10 @@ void vepu580_setup_hevc_tuning(struct rkvenc_core *core, bool intra);* struct vepu580_row_rc - codec-specific row rate control parameters * @qp_adj: QP adjustment for each of the nine deviation buckets * @dthd_outer: multiple of the base threshold for the outer buckets -* @aq_mode: value of rc_cfg.aq_mode */ struct vepu580_row_rc {s8 qp_adj[9 ];unsigned int dthd_outer; -bool aq_mode; };extern const struct vepu580_row_rc vepu580_h264_row_rc;
Signature · 1 line
2.55.0
RFC PATCH 6/12 media: rockchip: rkvenc: Use MPP's moving-scene H.264 RDO tuning
In reply to Arun IyengarThe H.264 mode decision and motion search registers had the values of MPP's still-scene tuning set. MPP keeps two sets and switches per picture from a motion detector (hal_h264e_vepu580_tune.c): the still-scene one biases the decision towards intra and skip blocks and toward the zero motion vector against flicker in surveillance video; the moving-scene one is neutral: ATF weights 16, ATR weights 20, CIME/RIME cost multipliers 4, no anti-flicker skip or intra, zero PMV off, no CIME SAD early exits, move lambda 8, P dead zone 341/1024, ATR QP threshold 51, intra cost thresholds 0 and the intra chroma weights.
Use the moving-scene set for every picture, and start the RDO lambda table one entry lower than MPP (index 5, lambda / 2^(1/3)). At a fixed QP (22-36, 1080p60 clips) this needs 7% (animation) to 11% (natural video) fewer bits for the same PSNR-Y than the still-scene set with MPP's lambda.
--- .../media/platform/rockchip/rkvenc/rkvenc-h264.c | 3 +- .../platform/rockchip/rkvenc/rkvenc-vepu580.c | 79 +++++++++++----------- 2 files changed, 41 insertions(+), 41 deletions(-)
drivers/media/platform/rockchip/rkvenc/rkvenc-h264.c +1 -2
@@ -333,8 +333,7 @@ static void rkvenc_h264_setup_syntax(struct rkvenc_core *core,rkvenc_set (core,VEPU580_H264_SYNT_REFM2 ,0 ); val =VEPU580_RDO_CFG_INTER_4X4 |VEPU580_RDO_CFG_CHRM_SPCL | -VEPU580_RDO_CFG_CCWA_E |VEPU580_RDO_CFG_ATR_E | -VEPU580_RDO_CFG_ATF_INTRA_E ; +VEPU580_RDO_CFG_CCWA_E |VEPU580_RDO_CFG_ATR_E ;if (sps->profile_idc ==RKVENC_H264_PROFILE_BASELINE && sps->level_idc <=30 ) val |=VEPU580_RDO_CFG_RECT_SIZE ;
drivers/media/platform/rockchip/rkvenc/rkvenc-vepu580.c +40 -39
143 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC PATCH 7/12 media: rockchip: rkvenc: Encode pictures wider than 4096 pixels
In reply to Arun IyengarThe 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.
--- .../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(-)
drivers/media/platform/rockchip/rkvenc/rkvenc-h264.c +3 -3
@@ -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,
drivers/media/platform/rockchip/rkvenc/rkvenc-hevc.c +3 -3
@@ -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,
drivers/media/platform/rockchip/rkvenc/rkvenc-regs.h +2 -0
@@ -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
drivers/media/platform/rockchip/rkvenc/rkvenc-vepu580.c +35 -3
@@ -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); }/*
drivers/media/platform/rockchip/rkvenc/rkvenc.c +7 -1
@@ -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; }
drivers/media/platform/rockchip/rkvenc/rkvenc.h +4 -0
@@ -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,
Signature · 1 line
2.55.0
RFC PATCH 8/12 media: rockchip: rkvenc: Encode HEVC wider than 4096 pixels in tile columns
In reply to Arun IyengarThe VEPU580 HEVC encoder does not keep the state of the CTU row above in the external line buffer: with it, HEVC pictures wider than 4096 pixels come out corrupted all over, with CABAC desynchronisation in the decoder, while H.264 pictures of the same sizes are fine. Rockchip's MPP never uses the line buffer for HEVC on this encoder either; it splits wider pictures into tile columns of at most 4096 pixels and encodes each with its own hardware pass.
Do the same: above 4096 pixels, signal ceil(width / 4096) uniformly spaced tile columns, with loop filtering across them, in the PPS, and encode the picture in one pass per tile column. Each pass gets the size and position of its tile, the motion search cache for the CTU columns its search window can reach, the CTUs per row of the row rate control, and the buffers that carry the loop filter data of the tile edges from one tile to the next. It continues the bitstream after the previous one as a slice of its own; the status of the passes is summed for the picture.
Keep the default L2 cache mapping for pictures wider than 4096, as MPP does (the 4x4096 mapping covers at most 4096 columns), and allocate the external line buffer for H.264 only.
--- .../media/platform/rockchip/rkvenc/rkvenc-h264.c | 1 + .../media/platform/rockchip/rkvenc/rkvenc-hevc.c | 141 ++++++++++++++++++++- .../media/platform/rockchip/rkvenc/rkvenc-regs.h | 2 + .../platform/rockchip/rkvenc/rkvenc-vepu580.c | 100 +++++++++------ drivers/media/platform/rockchip/rkvenc/rkvenc.c | 48 +++++++ drivers/media/platform/rockchip/rkvenc/rkvenc.h | 31 +++++ 6 files changed, 281 insertions(+), 42 deletions(-)
drivers/media/platform/rockchip/rkvenc/rkvenc-h264.c +1 -0
@@ -499,6 +499,7 @@ static const struct rkvenc_ctrls rkvenc_h264_ctrls = {const struct rkvenc_coded_fmt_desc rkvenc_h264_fmt_desc = { .fourcc =V4L2_PIX_FMT_H264_SLICE , .size_align =16 , + .ext_line_buf = true, .frmsize = { .min_width =64 ,/* Wider than 4096 with the external line buffer. */
drivers/media/platform/rockchip/rkvenc/rkvenc-hevc.c +137 -4
213 lines not on this page · raw message
drivers/media/platform/rockchip/rkvenc/rkvenc-regs.h +2 -0
@@ -354,6 +354,8 @@#define VEPU580_SLI_CFG 0x03f0#define VEPU580_SLI_CFG_SLI_CRS_EN BIT(31)#define VEPU580_TILE_POS 0x03f4 +#define VEPU580_TILE_POS_TILE_X GENMASK(7, 0) +#define VEPU580_TILE_POS_TILE_Y GENMASK(23, 16)#define VEPU580_FRAME_START 0x0280#define VEPU580_FRAME_END 0x03f8
drivers/media/platform/rockchip/rkvenc/rkvenc-vepu580.c +62 -38
134 lines not on this page · raw message
drivers/media/platform/rockchip/rkvenc/rkvenc.c +48 -0
66 lines not on this page · raw message
drivers/media/platform/rockchip/rkvenc/rkvenc.h +31 -0
@@ -98,6 +98,10 @@ struct rkvenc_run {struct vb2_v4l2_buffer *dst;/* Bytes written by software at the start of @dst (parameter sets). */ unsigned int hdr_bytes; +/* Hardware pass of the picture, counted from 0. */ +unsigned int pass; +/* Status read-back of the finished passes, summed. */ +struct rkvenc_feedback fb; };/**
@@ -107,6 +111,11 @@ struct rkvenc_run {* @stop: called on STREAMOFF, frees codec state * @run: prepare the job: produce software headers and fill @core's shadow * registers (codec syntax, rate control and references) +* @next_pass: optional, called after each hardware pass that finished without +* error, with the status of the passes so far summed in @run->fb. +* Returns 1 after updating @core's shadow registers for another +* pass of the same picture, 0 when the picture is complete, or a +* negative error code. * @done: called after the hardware finished; @fb holds the status read-back. * The backend sets the CAPTURE payload and may change @state. */
@@ -116,6 +125,8 @@ struct rkvenc_codec_ops {void (*stop)(struct rkvenc_ctx *ctx);int (*run)(struct rkvenc_ctx *ctx,struct rkvenc_core *core,struct rkvenc_run *run); +int (*next_pass)(struct rkvenc_ctx *ctx,struct rkvenc_core *core, +struct rkvenc_run *run);void (*done)(struct rkvenc_ctx *ctx,struct rkvenc_run *run,const struct rkvenc_feedback *fb,enum vb2_buffer_state *state);
@@ -130,10 +141,13 @@ struct rkvenc_ctrls {* struct rkvenc_coded_fmt_desc - coded (CAPTURE) format description * @size_align: alignment of the encoded picture size (enc_rsl), the * hardware pads the source up to it +* @ext_line_buf: pictures wider than 4096 pixels are encoded in one pass +* with the external line buffer */ struct rkvenc_coded_fmt_desc {u32 fourcc;unsigned int size_align; +bool ext_line_buf;struct v4l2_frmsize_stepwise frmsize;const struct rkvenc_ctrls *ctrls;const struct rkvenc_codec_ops *ops;
@@ -209,10 +223,19 @@ struct rkvenc_h264_ctx {/** * struct rkvenc_hevc_ctx - HEVC per-context state +* @enc: HEVC stateless encode core +* @hw_rc: the current picture uses the hardware row rate control +* @tile_buf: loop filter data at the tile column boundaries, one part of +* @tile_buf_size bytes per tile column (pictures wider than 4096) +* @tile_buf_size: size of one part of @tile_buf +* @tile: tile column the current hardware pass encodes */ struct rkvenc_hevc_ctx {struct v4l2_hevc_enc enc;bool hw_rc; +struct rkvenc_aux_buf tile_buf; +size_t tile_buf_size; +unsigned int tile; };struct rkvenc_ctx {
@@ -247,6 +270,12 @@ static inline void rkvenc_or(struct rkvenc_core *core, u32 reg, u32 val) core->shadow[reg /4 ] |= val; } +static inline void rkvenc_update (struct rkvenc_core *core,u32 reg,u32 mask, +u32 val) +{ + core->shadow[reg /4 ] = (core->shadow[reg /4 ] & ~mask) | (val & mask); +} +/* Shared VEPU580 programming helpers (rkvenc-vepu580.c). */ int rkvenc_alloc_aux (struct rkvenc_dev *rkvenc,struct rkvenc_aux_buf *buf,size_t size,bool kernel_mapping);
@@ -262,6 +291,8 @@ void vepu580_setup_h264_tuning(struct rkvenc_dev *rkvenc, struct rkvenc_core *core, bool intra);void vepu580_setup_hevc_me (struct rkvenc_core *core,unsigned int width,unsigned int height,bool colmv_stor,bool colmv_load); +void vepu580_setup_hevc_cime (struct rkvenc_core *core,unsigned int width, +unsigned int tile_x,unsigned int tile_w);void vepu580_setup_hevc_tuning (struct rkvenc_core *core,bool intra);/**
Signature · 1 line
2.55.0
RFC PATCH 9/12 media: rockchip: rkvenc: Limit the QP of the HEVC I pictures to 15..51
In reply to Arun IyengarAs the Rockchip MPP library does by default for HEVC, keep the I pictures of the frame rate control at QP 15 or above, while the P pictures may go down to 10: add the I picture QP limit controls, with the defaults 15 and
51. The hardware row rate control of an I picture gets the same limits.
Move the QP setup of the picture to a function of its own.
--- .../media/platform/rockchip/rkvenc/rkvenc-hevc.c | 61 +++++++++++++++------- 1 file changed, 41 insertions(+), 20 deletions(-)
drivers/media/platform/rockchip/rkvenc/rkvenc-hevc.c +41 -20
@@ -567,6 +567,43 @@ static void rkvenc_hevc_setup_tile(struct rkvenc_hevc_ctx *hevc, buf + (tile ? tile - 1 : 1) * hevc->tile_buf_size); } +/* +* QP of the picture. In CBR mode the size target of the frame rate control +* is handed to the hardware CTU row rate control, which adapts the QP of +* each CTU row by up to the row_rc_qp_range parameter, within the QP limits +* of the picture type. +*/ +static void rkvenc_hevc_setup_qp (struct rkvenc_hevc_ctx *hevc, +struct rkvenc_core *core) +{ +struct v4l2_hevc_enc *enc = &hevc->enc; +const struct v4l2_hevc_enc_state *state = &enc->state_active; +bool intra = state->encode.slice_type ==V4L2_HEVC_SLICE_TYPE_I ; +unsigned int qp_range; +int qp_min, qp_max; + +rkvenc_update (core,VEPU580_ENC_PIC ,VEPU580_ENC_PIC_PIC_QP ,0 ); +rkvenc_update (core,VEPU580_HEVC_SYNT_SLI1 ,VEPU580_HEVC_SLI1_SLI_QP , +FIELD_PREP (VEPU580_HEVC_SLI1_SLI_QP , enc->qp)); + + qp_range =min (READ_ONCE (rkvenc_row_rc_qp_range),15U ); + hevc->hw_rc = state->frame_rc_enable && + state->bitrate_mode ==V4L2_MPEG_VIDEO_BITRATE_MODE_CBR && + qp_range; +if (!hevc->hw_rc) { +vepu580_setup_fixed_qp (core, enc->qp); +return ; + } + + qp_min = intra ? state->qp_min_i : state->qp_min; + qp_max = intra ? state->qp_max_i : state->qp_max; +vepu580_setup_row_rc (core, &rkvenc_hevc_row_rc, enc->qp, +clamp (qp_min,0 ,51 ),clamp (qp_max,0 ,51 ), + qp_range, enc->cbr.target_bits, + state->width_ctbs * state->height_ctbs, + state->width_ctbs); +} +static int rkvenc_hevc_run (struct rkvenc_ctx *ctx,struct rkvenc_core *core,struct rkvenc_run *run) {
@@ -574,7 +611,6 @@ static int rkvenc_hevc_run(struct rkvenc_ctx *ctx, struct rkvenc_core *core,struct v4l2_hevc_enc *enc = &hevc->enc;const struct v4l2_hevc_enc_state *state = &enc->state_active;struct rkvenc_rec_buf *rec, *refr =NULL , *col =NULL ; -unsigned int ctus, qp_range;bool intra, tmvp, colmv_stor;int ret;
@@ -591,7 +627,6 @@ static int rkvenc_hevc_run(struct rkvenc_ctx *ctx, struct rkvenc_core *core,return -ENOSPC ; intra = state->encode.slice_type ==V4L2_HEVC_SLICE_TYPE_I ; - ctus = state->width_ctbs * state->height_ctbs; rec = enc->ref.buffer_current.private_data;if (!rec)
@@ -645,24 +680,7 @@ static int rkvenc_hevc_run(struct rkvenc_ctx *ctx, struct rkvenc_core *core, colmv_stor, col && col->colmv_valid);vepu580_setup_hevc_tuning (core, intra); -/* -* In CBR mode the size target of the frame rate control is handed to -* the hardware CTU row rate control, which adapts the QP of each CTU -* row by up to the row_rc_qp_range parameter. -*/ - qp_range =min (READ_ONCE (rkvenc_row_rc_qp_range),15U ); - hevc->hw_rc = state->frame_rc_enable && - state->bitrate_mode ==V4L2_MPEG_VIDEO_BITRATE_MODE_CBR && - qp_range; -if (hevc->hw_rc) -vepu580_setup_row_rc (core, &rkvenc_hevc_row_rc, enc->qp, -clamp (state->qp_min,0 ,51 ), -clamp (state->qp_max,0 ,51 ), qp_range, - enc->cbr.target_bits, ctus, - state->width_ctbs); -else -vepu580_setup_fixed_qp (core, enc->qp); - +rkvenc_hevc_setup_qp (hevc, core);rkvenc_hevc_setup_tile (hevc, core,0 );return 0 ;
@@ -807,6 +825,9 @@ static const struct v4l2_ctrl_config rkvenc_hevc_ctrl_cfgs[] = { }, { .id = V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP, .max = 51, .step = 1, .def = 10, }, { .id = V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP, .max = 51, .step = 1, .def = 51, }, + /* I pictures of the frame rate control: 15..51 as in MPP */ + { .id = V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MIN_QP, .max = 51, .step = 1, .def = 15, }, + { .id = V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MAX_QP, .max = 51, .step = 1, .def = 51, }, { .id = V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP, .max = 51, .step = 1, .def = 30, }, { .id = V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP, .max = 51, .step = 1, .def = 32, }, { .id = V4L2_CID_MPEG_VIDEO_AVERAGE_QP, .max = 51, .step = 1, },
Signature · 1 line
2.55.0
RFC PATCH 10/12 media: rockchip: rkvenc: Re-encode oversized HEVC pictures
In reply to Arun IyengarLet the constant bitrate mode of the HEVC encode core code a picture far above its size target a second time, as the Rockchip MPP library does:
once the last pass of the picture finished, ask v4l2_hevc_enc_reencode() and run the whole picture again with the new QP, writing the slice data over that of the first pass. The hardware writes the slice header, so the software headers stay as they are.
A codec backend now returns RKVENC_PASS_AGAIN from next_pass to encode the whole picture again, which restarts the summed status of the passes, and RKVENC_PASS_NEXT for the next pass of the same picture.
--- .../media/platform/rockchip/rkvenc/rkvenc-hevc.c | 24 +++++++++++++++++----- drivers/media/platform/rockchip/rkvenc/rkvenc.c | 6 +++++- drivers/media/platform/rockchip/rkvenc/rkvenc.h | 11 +++++++--- 3 files changed, 32 insertions(+), 9 deletions(-)
drivers/media/platform/rockchip/rkvenc/rkvenc-hevc.c +19 -5
@@ -688,19 +688,33 @@ static int rkvenc_hevc_run(struct rkvenc_ctx *ctx, struct rkvenc_core *core,/* * The next tile column continues the bitstream right after the previous -* one, as a slice of its own (the hardware writes its slice header). +* one, as a slice of its own (the hardware writes its slice header). Once +* the picture is complete, the rate control may have it encoded again with +* a higher QP, from the first tile column, over the slice data of the first +* encode. */ static int rkvenc_hevc_next_pass (struct rkvenc_ctx *ctx,struct rkvenc_core *core,struct rkvenc_run *run) {struct rkvenc_hevc_ctx *hevc = ctx->priv; -const struct v4l2_ctrl_hevc_pps *pps = &hevc->enc.state_active.pps; +struct v4l2_hevc_enc *enc = &hevc->enc; +const struct v4l2_ctrl_hevc_pps *pps = &enc->state_active.pps;u64 offset = run->hdr_bytes + run->fb.bs_len;if (!(pps->flags &V4L2_HEVC_PPS_FLAG_TILES_ENABLED ) || - hevc->tile >= pps->num_tile_columns_minus1) -return 0 ; + hevc->tile >= pps->num_tile_columns_minus1) { +if (!run->fb.bs_len || offset >rkvenc_dst_size (run) || + !v4l2_hevc_enc_reencode (enc, offset)) +return 0 ; + +rkvenc_set (core,VEPU580_ADR_BSBS , +rkvenc_dst_addr (run) + run->hdr_bytes); +rkvenc_hevc_setup_qp (hevc, core); +rkvenc_hevc_setup_tile (hevc, core,0 ); + +return RKVENC_PASS_AGAIN ; + }if (!run->fb.bs_len || offset +SZ_4K >rkvenc_dst_size (run))return -ENOSPC ;
@@ -708,7 +722,7 @@ static int rkvenc_hevc_next_pass(struct rkvenc_ctx *ctx,rkvenc_set (core,VEPU580_ADR_BSBS ,rkvenc_dst_addr (run) + offset);rkvenc_hevc_setup_tile (hevc, core, hevc->tile +1 ); -return 1 ; +return RKVENC_PASS_NEXT ; } static void rkvenc_hevc_done(struct rkvenc_ctx *ctx, struct rkvenc_run *run,
drivers/media/platform/rockchip/rkvenc/rkvenc.c +5 -1
@@ -965,7 +965,11 @@ static irqreturn_t rkvenc_irq_thread(int irq, void *priv)if (ops->next_pass) ret = ops->next_pass (core->curr_ctx, core, &core->run);if (ret >0 ) { - core->run.pass++; +/* A picture encoded again starts a new status sum. */ +if (ret ==RKVENC_PASS_AGAIN ) + core->run.pass =0 ; +else + core->run.pass++;rkvenc_hw_start (core);pm_runtime_put_noidle (core->dev);return IRQ_HANDLED ;
drivers/media/platform/rockchip/rkvenc/rkvenc.h +8 -3
@@ -113,12 +113,17 @@ struct rkvenc_run {* registers (codec syntax, rate control and references) * @next_pass: optional, called after each hardware pass that finished without * error, with the status of the passes so far summed in @run->fb. -* Returns 1 after updating @core's shadow registers for another -* pass of the same picture, 0 when the picture is complete, or a -* negative error code. +* Returns RKVENC_PASS_NEXT after updating @core's shadow registers +* for another pass of the same picture, RKVENC_PASS_AGAIN after +* setting them up to encode the whole picture again (the status +* of the passes so far is dropped), 0 when the picture is +* complete, or a negative error code. * @done: called after the hardware finished; @fb holds the status read-back. * The backend sets the CAPTURE payload and may change @state. */ +#define RKVENC_PASS_NEXT 1 +#define RKVENC_PASS_AGAIN 2 +struct rkvenc_codec_ops {int (*adjust_fmt)(struct rkvenc_ctx *ctx,struct v4l2_format *f);int (*start)(struct rkvenc_ctx *ctx);
Signature · 1 line
2.55.0
RFC PATCH 11/12 media: rockchip: rkvenc: Offer VBR for H.264 encoding
In reply to Arun IyengarThe H.264 encode core has a variable bitrate mode now. Offer it in V4L2_CID_MPEG_VIDEO_BITRATE_MODE and add V4L2_CID_MPEG_VIDEO_BITRATE_PEAK, which the core reads for it (default 20 Mbit/s, twice the default bitrate), and hand the size target of the variable bitrate pictures to the hardware row rate control as for constant bitrate.
--- drivers/media/platform/rockchip/rkvenc/rkvenc-h264.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/media/platform/rockchip/rkvenc/rkvenc-h264.c +9 -4
@@ -381,11 +381,13 @@ static int rkvenc_h264_run(struct rkvenc_ctx *ctx, struct rkvenc_core *core,vepu580_setup_h264_tuning (ctx->dev, core, intra);/* -* In CBR mode the frame size target of the rate control is handed to -* the hardware row rate control, which adapts the QP of each +* In CBR and VBR mode the frame size target of the rate control is +* handed to the hardware row rate control, which adapts the QP of each * macroblock row by up to the row_rc_qp_range parameter. */ - h264->hw_rc = rc->mode && rc->mode->type ==V4L2_H264_ENC_RC_TYPE_CBR && + h264->hw_rc = rc->mode && + (rc->mode->type ==V4L2_H264_ENC_RC_TYPE_CBR || + rc->mode->type ==V4L2_H264_ENC_RC_TYPE_VBR ) &&READ_ONCE (rkvenc_row_rc_qp_range);if (h264->hw_rc) vepu580_setup_row_rc(core, &vepu580_h264_row_rc, rc->qp,
@@ -466,12 +468,15 @@ static const struct v4l2_ctrl_config rkvenc_h264_ctrl_cfgs[] = { .min = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR, .max = V4L2_MPEG_VIDEO_BITRATE_MODE_CQ, .def = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, - .menu_skip_mask = BIT(V4L2_MPEG_VIDEO_BITRATE_MODE_VBR), }, { .id = V4L2_CID_MPEG_VIDEO_BITRATE, .min = 10000, .max = 200000000, .step = 1, .def = 10000000, }, + { + .id = V4L2_CID_MPEG_VIDEO_BITRATE_PEAK, + .min = 10000, .max = 200000000, .step = 1, .def = 20000000, + }, { .id = V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY, .min = 1, .max = 100, .step = 1, .def = 50,
Signature · 1 line
2.55.0
RFC PATCH 12/12 arm64: dts: rockchip: Add the VEPU580 encoder cores to the RK3588
In reply to Arun IyengarAdd the two VEPU580 (RKVENC) video encoder cores and their IOMMUs.
Interrupts, clocks, resets, power domains and the clock rates (500 MHz AXI, 800 MHz core) are taken from the Rockchip BSP rk3588s.dtsi. Each IOMMU has two register banks and two interrupts, and keeps the BSP's rockchip,disable-mmu-reset.
--- arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +56 -0
@@ -1397,6 +1397,62 @@ vepu121_3_mmu: iommu@fdbac800 { #iommu-cells = <0>; }; + vepu580_0: video-codec@fdbd0000 { + compatible = "rockchip,rk3588-vepu580"; + reg = <0x0 0xfdbd0000 0x0 0x6000>; + interrupts = <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&cru ACLK_RKVENC0>, <&cru HCLK_RKVENC0>, + <&cru CLK_RKVENC0_CORE>; + clock-names = "aclk", "hclk", "core"; + assigned-clocks = <&cru ACLK_RKVENC0>, <&cru CLK_RKVENC0_CORE>; + assigned-clock-rates = <500000000>, <800000000>; + resets = <&cru SRST_A_RKVENC0>, <&cru SRST_H_RKVENC0>, + <&cru SRST_RKVENC0_CORE>; + reset-names = "aclk", "hclk", "core"; + iommus = <&vepu580_0_mmu>; + power-domains = <&power RK3588_PD_VENC0>; + }; + + vepu580_0_mmu: iommu@fdbdf000 { + compatible = "rockchip,rk3588-iommu", "rockchip,rk3568-iommu"; + reg = <0x0 0xfdbdf000 0x0 0x40>, <0x0 0xfdbdf040 0x0 0x40>; + interrupts = <GIC_SPI 99 IRQ_TYPE_LEVEL_HIGH 0>, + <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&cru ACLK_RKVENC0>, <&cru HCLK_RKVENC0>; + clock-names = "aclk", "iface"; + power-domains = <&power RK3588_PD_VENC0>; + rockchip,disable-mmu-reset; + #iommu-cells = <0>; + }; + + vepu580_1: video-codec@fdbe0000 { + compatible = "rockchip,rk3588-vepu580"; + reg = <0x0 0xfdbe0000 0x0 0x6000>; + interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&cru ACLK_RKVENC1>, <&cru HCLK_RKVENC1>, + <&cru CLK_RKVENC1_CORE>; + clock-names = "aclk", "hclk", "core"; + assigned-clocks = <&cru ACLK_RKVENC1>, <&cru CLK_RKVENC1_CORE>; + assigned-clock-rates = <500000000>, <800000000>; + resets = <&cru SRST_A_RKVENC1>, <&cru SRST_H_RKVENC1>, + <&cru SRST_RKVENC1_CORE>; + reset-names = "aclk", "hclk", "core"; + iommus = <&vepu580_1_mmu>; + power-domains = <&power RK3588_PD_VENC1>; + }; + + vepu580_1_mmu: iommu@fdbef000 { + compatible = "rockchip,rk3588-iommu", "rockchip,rk3568-iommu"; + reg = <0x0 0xfdbef000 0x0 0x40>, <0x0 0xfdbef040 0x0 0x40>; + interrupts = <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH 0>, + <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&cru ACLK_RKVENC1>, <&cru HCLK_RKVENC1>; + clock-names = "aclk", "iface"; + power-domains = <&power RK3588_PD_VENC1>; + rockchip,disable-mmu-reset; + #iommu-cells = <0>; + }; + vdec0: video-codec@fdc38000 { compatible = "rockchip,rk3588-vdec"; reg = <0x0 0xfdc38000 0x0 0x100>,
Signature · 1 line
2.55.0
I'm withdrawing this RFC; please don't review it. It depends on my H.264 follow-ups RFC, which I have dropped. The cover also should have said that Detlev is already writing a driver for this block, as Nicolas explained in the VEPU510 thread it links; I don't want to push a second uAPI for the same hardware.
Detlev, three things from the bring-up on an Orange Pi 5, in case they save you time:
- HEVC wider than 4096 came out corrupted with the external line buffer (H.264 is fine with it, tested to 16384x2048). Tile columns of at most 4096, one hardware pass each, as MPP does, work (tested to 16384x2048 and 8192x4320).
- MPP's "TU depth 1" is max_transform_hierarchy_depth_inter/intra = 0 in the SPS. With 1, decoders misparse the residual.
- Two streams, one per core, with both cores in one IOMMU domain and no dual-core handshake, ran at about twice the single-stream rate with the same output as single-stream runs.
Arun