media: rkvdec: Add support for VDPU381 and VDPU383
Subsystems (4)
Detlev Casanova
maintainerv6 cover media: rkvdec: Add support for VDPU381 and VDPU383
These variants are found respectively in the RK3588 and RK3576 SoCs. This patch only adds support for H264 and H265 in both variants.
As there is a considerable part of the code that can be shared with the already supported rkvdec decoder driver, the support for these variants is added here rather than writing a new driver.
This patch set uses the newly introduced hevc_ext_sps_[ls]t_rps v4l2 controls for HEVC.
Therefore, a patched version of userpace tools is needed for HEVC support (added for GStreamer[1] and in an early stage for FFmpeg[2]).
The DTS changes can be found in another patch set: [3]
[1]: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9355
[2]: https://gitlab.collabora.com/detlev/ffmpeg
[3]: https://lore.kernel.org/all/[email protected]/
Changes since v5:
- Extract multicore management in separate commit
- Move variant specific functions to an ops struct
- Fix a typo and "h264" -> "hevc" copy/paste mistakes
- Move RKVDEC_*_PIXELS to rkvdec.h
- Drop VDPU383_*_PIXELS, use the the RKVDEC ones instead
- Change RKVDEC_1080P_PIXELS value to 1920 * 1088
- Long and short term ref sets extend controls:
- Add them in visl traces
- Reword documentation to specify SPS extension and use
- Mention Vulkan Video API similarity
- Specify behavior for empty array values
- Reorder struct fields to ensure fixed compiled size
- Remove the mention of V4L2_CTRL_FLAG_DYNAMIC_ARRAY flag
Changes since v4:
- Add basic ext_sps_[ls]t_rps validation (flags only)
- Add missing copyright in new common files
- Rename num_coded_fmts, rcb_num, clk_count
- Avoid allocating RCB config when not needed
- Merge rkvdec_config into rkvdec_variant
- Keep rkvdec_hevc_get_image_fmt per variant
Changes since v3:
- Rebased on latest next (ea299a216426) + HEVC support for rk3399
Changes since v2:
- Rebased on Kwiboo's HEVC support for rk3399
- Include hevc_ext_sps_[ls]t_rps v4l2 controls commits
- Remove empty lines at end of files
- Rename RKVDEC2_ALLOC_* to RKVDEC_ALLOC_*
- Set min_with and min_height to 64
- Remove vdpu38x_fill_pixfmt_mp() function
- Handle userspace not supporting hevc_ext_sps_[ls]t_rps
- Make all config structs static const
Changes since v1:
- Add parsing of the short and long term ref frame sets from the new v4l2 controls
- Add RPS cache to avoid parsing the same data again
- Fix HEVC pixel formats selection
- Fix multiple indentation errors
Detlev Casanova (17):
media: uapi: HEVC: Add v4l2_ctrl_hevc_ext_sps_[ls]t_rps controls
media: v4l2-ctrls: Add hevc_ext_sps_[ls]t_rps controls
media: visl: Add HEVC short and long term RPS sets
media: rkvdec: Switch to using structs instead of writel
media: rkvdec: Move cabac tables to their own source file
media: rkvdec: Use structs to represent the HW RPS
media: rkvdec: Move h264 functions to common file
media: rkvdec: Move hevc functions to common file
media: rkvdec: Add variant specific coded formats list
media: rkvdec: Add RCB and SRAM support
media: rkvdec: Support per-variant interrupt handler
media: rkvdec: Enable all clocks without naming them
media: rkvdec: Disable multicore support
media: rkvdec: Add H264 support for the VDPU381 variant
media: rkvdec: Add H264 support for the VDPU383 variant
media: rkvdec: Add HEVC support for the VDPU381 variant
media: rkvdec: Add HEVC support for the VDPU383 variant
.../media/v4l/ext-ctrls-codec-stateless.rst | 120 +++
.../media/v4l/videodev2.h.rst.exceptions | 2 +
.../media/v4l/vidioc-queryctrl.rst | 12 +
.../media/platform/rockchip/rkvdec/Kconfig | 1 +
.../media/platform/rockchip/rkvdec/Makefile | 14 +-
.../{rkvdec-hevc-data.c => rkvdec-cabac.c} | 506 +++++++++-
.../rockchip/rkvdec/rkvdec-h264-common.c | 258 +++++
.../rockchip/rkvdec/rkvdec-h264-common.h | 89 ++
.../platform/rockchip/rkvdec/rkvdec-h264.c | 891 ++----------------
.../rockchip/rkvdec/rkvdec-hevc-common.c | 488 ++++++++++
.../rockchip/rkvdec/rkvdec-hevc-common.h | 108 +++
.../platform/rockchip/rkvdec/rkvdec-hevc.c | 257 +----
.../platform/rockchip/rkvdec/rkvdec-rcb.c | 178 ++++
.../platform/rockchip/rkvdec/rkvdec-rcb.h | 29 +
.../platform/rockchip/rkvdec/rkvdec-regs.h | 571 +++++++----
.../rockchip/rkvdec/rkvdec-vdpu381-h264.c | 469 +++++++++
.../rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 641 +++++++++++++
.../rockchip/rkvdec/rkvdec-vdpu381-regs.h | 424 +++++++++
.../rockchip/rkvdec/rkvdec-vdpu383-h264.c | 582 ++++++++++++
.../rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 736 +++++++++++++++
.../rockchip/rkvdec/rkvdec-vdpu383-regs.h | 281 ++++++
.../platform/rockchip/rkvdec/rkvdec-vp9.c | 231 ++---
.../media/platform/rockchip/rkvdec/rkvdec.c | 542 ++++++++++-
.../media/platform/rockchip/rkvdec/rkvdec.h | 43 +
drivers/media/test-drivers/visl/visl-dec.c | 7 +
drivers/media/test-drivers/visl/visl-dec.h | 3 +
.../media/test-drivers/visl/visl-trace-hevc.h | 59 ++
drivers/media/v4l2-core/v4l2-ctrls-core.c | 28 +
drivers/media/v4l2-core/v4l2-ctrls-defs.c | 10 +
include/uapi/linux/v4l2-controls.h | 61 ++
include/uapi/linux/videodev2.h | 2 +
31 files changed, 6230 insertions(+), 1413 deletions(-)
rename drivers/media/platform/rockchip/rkvdec/{rkvdec-hevc-data.c => rkvdec-cabac.c} (86%)
create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.c
create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.h
create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h
create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.h
create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c
create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h
create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c
create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-regs.hSignature · 1 line
2.52.0
Detlev Casanova
maintainerPATCH v6 1/17 media: uapi: HEVC: Add v4l2_ctrl_hevc_ext_sps_[ls]t_rps controls
Some hardware (e.g.: Rockchip's rk3588 hevc decoder) need to fully parse the slice header, which cannot be passed with the current controls. There is also no skip method similar as to what can be found in verisilicon HW.
The SPS is therefore extended through these 2 new controls, providing the long and short term reference information from the slice header for HEVC decoding.
These now controls are similar as what is passed in the Vulkan Video API with the StdVideoH265ShortTermRefPicSet and StdVideoH265LongTermRefPicsSps structures embedded in the SPS struct.
--- .../media/v4l/ext-ctrls-codec-stateless.rst | 120 ++++++++++++++++++ .../media/v4l/videodev2.h.rst.exceptions | 2 + .../media/v4l/vidioc-queryctrl.rst | 12 ++ 3 files changed, 134 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-codec-stateless.rst +120 -0
@@ -2959,6 +2959,126 @@ This structure contains all loop filter related parameters. See sections - 0x00000004 - +``V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS (struct)`` + Subset of the :c:type:`v4l2_ctrl_hevc_sps` control. + It extends it with the list of Long-term reference sets parameters. + These parameters are defined according to :ref:`hevc`. + They are described in section 7.4.3.2.1 "General sequence parameter set + RBSP semantics" of the specification. + This control is a dynamically sized 1-dimensional array. + The values in the array should be ignored when either + num_long_term_ref_pics_sps is 0 or the + V4L2_HEVC_SPS_FLAG_LONG_TERM_REF_PICS_PRESENT flag is not set in + :c:type:`v4l2_ctrl_hevc_sps`. + +.. c:type:: v4l2_ctrl_hevc_ext_sps_lt_rps + +.. cssclass:: longtable + +.. flat-table:: struct v4l2_ctrl_hevc_ext_sps_lt_rps + :header-rows: 0 + :stub-columns: 0 + :widths: 1 1 2 + + * - __u16 + - ``lt_ref_pic_poc_lsb_sps`` + - Long term reference picture order count as described in section 7.4.3.2.1 + "General sequence parameter set RBSP semantics" of the specification. + * - __u16 + - ``flags`` + - See :ref:`Extended Long-Term RPS Flags <hevc_ext_sps_lt_rps_flags>` + +.. _hevc_ext_sps_lt_rps_flags: + +``Extended SPS Long-Term RPS Flags`` + +.. cssclass:: longtable + +.. flat-table:: + :header-rows: 0 + :stub-columns: 0 + :widths: 1 1 2 + + * - ``V4L2_HEVC_EXT_SPS_LT_RPS_FLAG_USED_LT`` + - 0x00000001 + - Specifies if the long-term reference picture is used 7.4.3.2.1 "General sequence parameter + set RBSP semantics" of the specification. + +``V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS (struct)`` + Subset of the :c:type:`v4l2_ctrl_hevc_sps` control. + It extends it with the list of Short-term reference sets parameters. + These parameters are defined according to :ref:`hevc`. + They are described in section 7.4.8 "Short-term reference picture set + semantics" of the specification. + This control is a dynamically sized 1-dimensional array. + The values in the array should be ignored when + num_short_term_ref_pic_sets is 0. + +.. c:type:: v4l2_ctrl_hevc_ext_sps_st_rps + +.. cssclass:: longtable + +.. flat-table:: struct v4l2_ctrl_hevc_ext_sps_st_rps + :header-rows: 0 + :stub-columns: 0 + :widths: 1 1 2 + + * - __u8 + - ``delta_idx_minus1`` + - Specifies the delta compare to the index. See details in section 7.4.8 "Short-term + reference picture set semantics" of the specification. + * - __u8 + - ``delta_rps_sign`` + - Sign of the delta as specified in section 7.4.8 "Short-term reference picture set + semantics" of the specification. + * - __u8 + - ``num_negative_pics`` + - Number of short-term RPS entries that have picture order count values less than the + picture order count value of the current picture. + * - __u8 + - ``num_positive_pics`` + - Number of short-term RPS entries that have picture order count values greater than the + picture order count value of the current picture. + * - __u32 + - ``used_by_curr_pic`` + - Bit i specifies if short-term RPS i is used by the current picture. + * - __u32 + - ``use_delta_flag`` + - Bit i specifies if short-term RPS i is included in the short-term RPS entries. + * - __u16 + - ``abs_delta_rps_minus1`` + - Absolute delta RPS as specified in section 7.4.8 "Short-term reference picture set + semantics" of the specification. + * - __u16 + - ``delta_poc_s0_minus1[16]`` + - Specifies the negative picture order count delta for the i-th entry in the short-term RPS. + See details in section 7.4.8 "Short-term reference picture set semantics" of the + specification. + * - __u16 + - ``delta_poc_s1_minus1[16]`` + - Specifies the positive picture order count delta for the i-th entry in the short-term RPS. + See details in section 7.4.8 "Short-term reference picture set semantics" of the + specification. + * - __u16 + - ``flags`` + - See :ref:`Extended Short-Term RPS Flags <hevc_ext_sps_st_rps_flags>` + +.. _hevc_ext_sps_st_rps_flags: + +``Extended SPS Short-Term RPS Flags`` + +.. cssclass:: longtable + +.. flat-table:: + :header-rows: 0 + :stub-columns: 0 + :widths: 1 1 2 + + * - ``V4L2_HEVC_EXT_SPS_ST_RPS_FLAG_INTER_REF_PIC_SET_PRED`` + - 0x00000001 + - Specifies if the short-term RPS is predicted from another short term RPS. See details in + section 7.4.8 "Short-term reference picture set semantics" of the specification. + .. _v4l2-codec-stateless-av1: ``V4L2_CID_STATELESS_AV1_SEQUENCE (struct)``
Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions +2 -0
@@ -150,6 +150,8 @@ replace symbol V4L2_CTRL_TYPE_H264_SCALING_MATRIX :c:type:`V4L.v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_H264_PRED_WEIGHTS :c:type:`V4L.v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_H264_SLICE_PARAMS :c:type:`V4L.v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_H264_DECODE_PARAMS :c:type:`V4L.v4l2_ctrl_type` +replace symbol V4L2_CTRL_TYPE_HEVC_EXT_SPS_ST_RPS :c:type:`V4L.v4l2_ctrl_type` +replace symbol V4L2_CTRL_TYPE_HEVC_EXT_SPS_LT_RPS :c:type:`V4L.v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_HEVC_SPS :c:type:`V4L.v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_HEVC_PPS :c:type:`V4L.v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :c:type:`V4L.v4l2_ctrl_type`
Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst +12 -0
@@ -531,6 +531,18 @@ See also the examples in :ref:`control`. - n/a - A struct :c:type:`v4l2_ctrl_hevc_decode_params`, containing HEVC decoding parameters for stateless video decoders. + * - ``V4L2_CTRL_TYPE_HEVC_EXT_SPS_LT_RPS`` + - n/a + - n/a + - n/a + - A struct :c:type:`v4l2_ctrl_hevc_ext_sps_lt_rps`, containing HEVC + extended Long-Term RPS for stateless video decoders. + * - ``V4L2_CTRL_TYPE_HEVC_EXT_SPS_ST_RPS`` + - n/a + - n/a + - n/a + - A struct :c:type:`v4l2_ctrl_hevc_ext_sps_st_rps`, containing HEVC + extended Short-Term RPS for stateless video decoders. * - ``V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR`` - n/a - n/a
Signature · 1 line
2.52.0
Detlev Casanova
maintainerPATCH v6 2/17 media: v4l2-ctrls: Add hevc_ext_sps_[ls]t_rps controls
In reply to Detlev CasanovaThe vdpu381 decoder found on newer Rockchip SoC need the information from the long term and short term ref pic sets from the SPS.
So far, it wasn't included in the v4l2 API, so add it with new dynamic sized controls.
Each element of the hevc_ext_sps_lt_rps array contains the long term ref pic set at that index.
Each element of the hevc_ext_sps_st_rps contains the short term ref pic set at that index, as the raw data.
It is the role of the drivers to calculate the reference sets values.
--- drivers/media/v4l2-core/v4l2-ctrls-core.c | 28 +++++++++++ drivers/media/v4l2-core/v4l2-ctrls-defs.c | 10 ++++ include/uapi/linux/v4l2-controls.h | 61 +++++++++++++++++++++++ include/uapi/linux/videodev2.h | 2 + 4 files changed, 101 insertions(+)
drivers/media/v4l2-core/v4l2-ctrls-core.c +28 -0
@@ -424,6 +424,12 @@ void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctrl)case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :pr_cont ("HEVC_SLICE_PARAMS" );break ; +case V4L2_CTRL_TYPE_HEVC_EXT_SPS_ST_RPS : +pr_cont ("HEVC_EXT_SPS_ST_RPS" ); +break ; +case V4L2_CTRL_TYPE_HEVC_EXT_SPS_LT_RPS : +pr_cont ("HEVC_EXT_SPS_LT_RPS" ); +break ;case V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX :pr_cont ("HEVC_SCALING_MATRIX" );break ;
@@ -961,6 +967,8 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;struct v4l2_ctrl_h264_decode_params *p_h264_dec_params; +struct v4l2_ctrl_hevc_ext_sps_lt_rps *p_hevc_lt_rps; +struct v4l2_ctrl_hevc_ext_sps_st_rps *p_hevc_st_rps;struct v4l2_ctrl_hevc_sps *p_hevc_sps;struct v4l2_ctrl_hevc_pps *p_hevc_pps;struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
@@ -1254,6 +1262,20 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :break ; +case V4L2_CTRL_TYPE_HEVC_EXT_SPS_ST_RPS : + p_hevc_st_rps = p; + +if (p_hevc_st_rps->flags & ~V4L2_HEVC_EXT_SPS_ST_RPS_FLAG_INTER_REF_PIC_SET_PRED ) +return -EINVAL ; +break ; + +case V4L2_CTRL_TYPE_HEVC_EXT_SPS_LT_RPS : + p_hevc_lt_rps = p; + +if (p_hevc_lt_rps->flags & ~V4L2_HEVC_EXT_SPS_LT_RPS_FLAG_USED_LT ) +return -EINVAL ; +break ; +case V4L2_CTRL_TYPE_HDR10_CLL_INFO :break ;
@@ -2006,6 +2028,12 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS : elem_size =sizeof (struct v4l2_ctrl_hevc_slice_params );break ; +case V4L2_CTRL_TYPE_HEVC_EXT_SPS_ST_RPS : + elem_size =sizeof (struct v4l2_ctrl_hevc_ext_sps_st_rps ); +break ; +case V4L2_CTRL_TYPE_HEVC_EXT_SPS_LT_RPS : + elem_size =sizeof (struct v4l2_ctrl_hevc_ext_sps_lt_rps ); +break ;case V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX : elem_size =sizeof (struct v4l2_ctrl_hevc_scaling_matrix );break ;
drivers/media/v4l2-core/v4l2-ctrls-defs.c +10 -0
@@ -1233,6 +1233,8 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_STATELESS_HEVC_DECODE_MODE :return "HEVC Decode Mode" ;case V4L2_CID_STATELESS_HEVC_START_CODE :return "HEVC Start Code" ;case V4L2_CID_STATELESS_HEVC_ENTRY_POINT_OFFSETS :return "HEVC Entry Point Offsets" ; +case V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS :return "HEVC Short Term Ref Sets" ; +case V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS :return "HEVC Long Term Ref Sets" ;case V4L2_CID_STATELESS_AV1_SEQUENCE :return "AV1 Sequence Parameters" ;case V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY :return "AV1 Tile Group Entry" ;case V4L2_CID_STATELESS_AV1_FRAME :return "AV1 Frame Parameters" ;
@@ -1578,6 +1580,14 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, *type =V4L2_CTRL_TYPE_U32 ; *flags |=V4L2_CTRL_FLAG_DYNAMIC_ARRAY ;break ; +case V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS : + *type =V4L2_CTRL_TYPE_HEVC_EXT_SPS_ST_RPS ; + *flags |=V4L2_CTRL_FLAG_DYNAMIC_ARRAY ; +break ; +case V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS : + *type =V4L2_CTRL_TYPE_HEVC_EXT_SPS_LT_RPS ; + *flags |=V4L2_CTRL_FLAG_DYNAMIC_ARRAY ; +break ;case V4L2_CID_STATELESS_VP9_COMPRESSED_HDR : *type =V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR ;break ;
include/uapi/linux/v4l2-controls.h +61 -0
73 lines not on this page · raw message
include/uapi/linux/videodev2.h +2 -0
@@ -1985,6 +1985,8 @@ enum v4l2_ctrl_type {V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS =0x0272 ,V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX =0x0273 ,V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS =0x0274 , +V4L2_CTRL_TYPE_HEVC_EXT_SPS_ST_RPS =0x0275 , +V4L2_CTRL_TYPE_HEVC_EXT_SPS_LT_RPS =0x0276 ,V4L2_CTRL_TYPE_AV1_SEQUENCE =0x280 , V4L2_CTRL_TYPE_AV1_TILE_GROUP_ENTRY = 0x281,
Signature · 1 line
2.52.0
Detlev Casanova
maintainerPATCH v6 3/17 media: visl: Add HEVC short and long term RPS sets
In reply to Detlev CasanovaLog the recently added v4l2 controls to set HEVC short and long term RPS sets with 2 new ftrace entries.
--- drivers/media/test-drivers/visl/visl-dec.c | 7 +++ drivers/media/test-drivers/visl/visl-dec.h | 3 + .../media/test-drivers/visl/visl-trace-hevc.h | 59 +++++++++++++++++++ 3 files changed, 69 insertions(+)
drivers/media/test-drivers/visl/visl-dec.c +7 -0
@@ -547,6 +547,9 @@ static void visl_trace_ctrls(struct visl_ctx *ctx, struct visl_run *run)trace_v4l2_hevc_dpb_entry (&run->hevc.dpram->dpb[i]);trace_v4l2_hevc_pred_weight_table (&run->hevc.spram->pred_weight_table); +trace_v4l2_ctrl_hevc_ext_sps_lt_rps (run->hevc.rps_lt); +trace_v4l2_ctrl_hevc_ext_sps_st_rps (run->hevc.rps_st); +break ;case VISL_CODEC_AV1 :trace_v4l2_ctrl_av1_sequence (run->av1.seq);
@@ -611,6 +614,10 @@ void visl_device_run(void *priv) run.hevc.spram =visl_find_control_data (ctx,V4L2_CID_STATELESS_HEVC_SLICE_PARAMS ); run.hevc.sm =visl_find_control_data (ctx,V4L2_CID_STATELESS_HEVC_SCALING_MATRIX ); run.hevc.dpram =visl_find_control_data (ctx,V4L2_CID_STATELESS_HEVC_DECODE_PARAMS ); + run.hevc.rps_lt =visl_find_control_data (ctx, +V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS ); + run.hevc.rps_st =visl_find_control_data (ctx, +V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS );break ;case VISL_CODEC_AV1 : run.av1.seq =visl_find_control_data (ctx,V4L2_CID_STATELESS_AV1_SEQUENCE );
drivers/media/test-drivers/visl/visl-dec.h +3 -0
@@ -7,6 +7,7 @@#ifndef _VISL_DEC_H_#define _VISL_DEC_H_ +#include "linux/v4l2-controls.h" #include "visl.h" struct visl_fwht_run {
@@ -43,6 +44,8 @@ struct visl_hevc_run {const struct v4l2_ctrl_hevc_slice_params *spram;const struct v4l2_ctrl_hevc_scaling_matrix *sm;const struct v4l2_ctrl_hevc_decode_params *dpram; +const struct v4l2_ctrl_hevc_ext_sps_lt_rps *rps_lt; +const struct v4l2_ctrl_hevc_ext_sps_st_rps *rps_st; };struct visl_av1_run {
drivers/media/test-drivers/visl/visl-trace-hevc.h +59 -0
75 lines not on this page · raw message
Signature · 1 line
2.52.0
Detlev Casanova
maintainerPATCH v6 4/17 media: rkvdec: Switch to using structs instead of writel
In reply to Detlev CasanovaIn an effort to merge the rkvdec2 driver [1] with this one, switch from writel() calls to using structs to represent the register mappings.
This is done in order to have all supported decoders use the same format in the future and ease reading of the code.
Using structs also improves stability as the hardware is tested and validated downstream using a similar method.
It was noticed, on decoders, that:
- Some registers require to be writen in increasing order [2]
- Some registers, even if unrelated, need to be written to their reset values (it was the case here for axi_ddr_[rw]data).
Using structs can also help improving performance later when, e.g. multicore support is added on RK3588.
Performance seems to be slightly improved, but at least, not made worse. Running fluster's JVT-AVC_V1 test suite with GStreamer on the Radxa ROCK PI 4 SE gives the following times:
Before this patch:
- --jobs 1: Ran 129/135 tests successfully in 77.167 secs
- --jobs 6: Ran 129/135 tests successfully in 23.046 secs
With this patch:
- --jobs 1: Ran 129/135 tests successfully in 70.698 secs
- --jobs 6: Ran 129/135 tests successfully in 22.917 secs
This also shows that the fluster score hasn't changed.
[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/
--- .../platform/rockchip/rkvdec/rkvdec-h264.c | 165 +++-- .../platform/rockchip/rkvdec/rkvdec-hevc.c | 63 +- .../platform/rockchip/rkvdec/rkvdec-regs.h | 571 ++++++++++++------ .../platform/rockchip/rkvdec/rkvdec-vp9.c | 231 +++---- .../media/platform/rockchip/rkvdec/rkvdec.c | 10 +- .../media/platform/rockchip/rkvdec/rkvdec.h | 1 + 6 files changed, 587 insertions(+), 454 deletions(-)
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +70 -95
@@ -115,6 +115,7 @@ struct rkvdec_h264_run {struct rkvdec_h264_ctx {struct rkvdec_aux_buf priv_tbl;struct rkvdec_h264_reflists reflists; +struct rkvdec_regs regs; }; #define CABAC_ENTRY(ctxidx, idc0_m, idc0_n, idc1_m, idc1_n, \
@@ -841,45 +842,41 @@ static void assemble_hw_scaling_list(struct rkvdec_ctx *ctx, }/* -* dpb poc related registers table +* Set the ref POC in the correct register. +* +* The 32 registers are spread across 3 regions, each alternating top and bottom ref POCs: +* - 1: ref 0 to 14 contain top 0 to 7 and bottoms 0 to 6 +* - 2: ref 15 to 29 contain top 8 to 14 and bottoms 7 to 14 +* - 3: ref 30 and 31 which correspond to top 15 and bottom 15 respectively. */ -static const u32 poc_reg_tbl_top_field[16 ] = { -RKVDEC_REG_H264_POC_REFER0 (0 ), -RKVDEC_REG_H264_POC_REFER0 (2 ), -RKVDEC_REG_H264_POC_REFER0 (4 ), -RKVDEC_REG_H264_POC_REFER0 (6 ), -RKVDEC_REG_H264_POC_REFER0 (8 ), -RKVDEC_REG_H264_POC_REFER0 (10 ), -RKVDEC_REG_H264_POC_REFER0 (12 ), -RKVDEC_REG_H264_POC_REFER0 (14 ), -RKVDEC_REG_H264_POC_REFER1 (1 ), -RKVDEC_REG_H264_POC_REFER1 (3 ), -RKVDEC_REG_H264_POC_REFER1 (5 ), -RKVDEC_REG_H264_POC_REFER1 (7 ), -RKVDEC_REG_H264_POC_REFER1 (9 ), -RKVDEC_REG_H264_POC_REFER1 (11 ), -RKVDEC_REG_H264_POC_REFER1 (13 ), -RKVDEC_REG_H264_POC_REFER2 (0 ) -}; - -static const u32 poc_reg_tbl_bottom_field[16 ] = { -RKVDEC_REG_H264_POC_REFER0 (1 ), -RKVDEC_REG_H264_POC_REFER0 (3 ), -RKVDEC_REG_H264_POC_REFER0 (5 ), -RKVDEC_REG_H264_POC_REFER0 (7 ), -RKVDEC_REG_H264_POC_REFER0 (9 ), -RKVDEC_REG_H264_POC_REFER0 (11 ), -RKVDEC_REG_H264_POC_REFER0 (13 ), -RKVDEC_REG_H264_POC_REFER1 (0 ), -RKVDEC_REG_H264_POC_REFER1 (2 ), -RKVDEC_REG_H264_POC_REFER1 (4 ), -RKVDEC_REG_H264_POC_REFER1 (6 ), -RKVDEC_REG_H264_POC_REFER1 (8 ), -RKVDEC_REG_H264_POC_REFER1 (10 ), -RKVDEC_REG_H264_POC_REFER1 (12 ), -RKVDEC_REG_H264_POC_REFER1 (14 ), -RKVDEC_REG_H264_POC_REFER2 (1 ) -}; +static void set_poc_reg (struct rkvdec_regs *regs,uint32_t poc,int id,bool bottom) +{ +if (!bottom) { +switch (id) { + case 0 ... 7: + regs->h26x.ref0_14_poc[id *2 ] = poc; +break ; + case 8 ... 14: + regs->h26x.ref15_29_poc[(id -8 ) *2 +1 ] = poc; +break ; +case 15 : + regs->h26x.ref30_poc = poc; +break ; + } + }else { +switch (id) { + case 0 ... 6: + regs->h26x.ref0_14_poc[id *2 +1 ] = poc; +break ; + case 7 ... 14: + regs->h26x.ref15_29_poc[(id -7 ) *2 ] = poc; +break ; +case 15 : + regs->h26x.ref31_poc = poc; +break ; + } + } +}static void config_registers (struct rkvdec_ctx *ctx,struct rkvdec_h264_run *run)
@@ -894,6 +891,7 @@ static void config_registers(struct rkvdec_ctx *ctx,struct vb2_v4l2_buffer *src_buf = run->base.bufs.src;struct vb2_v4l2_buffer *dst_buf = run->base.bufs.dst;const struct v4l2_format *f; +struct rkvdec_regs *regs = &h264_ctx->regs;dma_addr_t rlc_addr;dma_addr_t refer_addr;u32 rlc_len;
@@ -903,10 +901,11 @@ static void config_registers(struct rkvdec_ctx *ctx,u32 yuv_virstride =0 ;u32 offset;dma_addr_t dst_addr; -u32 reg, i; +u32 i; - reg =RKVDEC_MODE (RKVDEC_MODE_H264 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_SYSCTRL ); +memset (regs,0 ,sizeof (*regs)); + + regs->common.reg02.dec_mode =RKVDEC_MODE_H264 ; f = &ctx->decoded_fmt; dst_fmt = &f->fmt.pix_mp;
@@ -921,39 +920,35 @@ static void config_registers(struct rkvdec_ctx *ctx,else if (sps->chroma_format_idc ==2 ) yuv_virstride =2 * y_virstride; - reg =RKVDEC_Y_HOR_VIRSTRIDE (hor_virstride /16 ) | -RKVDEC_UV_HOR_VIRSTRIDE (hor_virstride /16 ) | -RKVDEC_SLICE_NUM_HIGHBIT | -RKVDEC_SLICE_NUM_LOWBITS (0x7ff ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_PICPAR ); + regs->common.reg03.uv_hor_virstride = hor_virstride /16 ; + regs->common.reg03.y_hor_virstride = hor_virstride /16 ; + regs->common.reg03.slice_num_highbit =1 ; + regs->common.reg03.slice_num_lowbits =0x7ff ;/* config rlc base address */ rlc_addr =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,0 ); -writel_relaxed (rlc_addr, rkvdec->regs +RKVDEC_REG_STRM_RLC_BASE ); -writel_relaxed (rlc_addr, rkvdec->regs +RKVDEC_REG_RLCWRITE_BASE ); + regs->common.strm_rlc_base = rlc_addr; + regs->h26x.rlcwrite_base = rlc_addr; rlc_len =vb2_get_plane_payload (&src_buf->vb2_buf,0 ); - reg =RKVDEC_STRM_LEN (rlc_len); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_STRM_LEN ); + regs->common.stream_len = rlc_len;/* config cabac table */ offset = offsetof(struct rkvdec_h264_priv_tbl , cabac_table); -writel_relaxed (priv_start_addr + offset, - rkvdec->regs +RKVDEC_REG_CABACTBL_PROB_BASE ); + regs->common.cabactbl_base = priv_start_addr + offset;/* config output base address */ dst_addr =vb2_dma_contig_plane_dma_addr (&dst_buf->vb2_buf,0 ); -writel_relaxed (dst_addr, rkvdec->regs +RKVDEC_REG_DECOUT_BASE ); + regs->common.decout_base = dst_addr; - reg =RKVDEC_Y_VIRSTRIDE (y_virstride /16 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_Y_VIRSTRIDE ); + regs->common.reg08.y_virstride = y_virstride /16 ; - reg =RKVDEC_YUV_VIRSTRIDE (yuv_virstride /16 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_YUV_VIRSTRIDE ); + regs->common.reg09.yuv_virstride = yuv_virstride /16 ;/* config ref pic address & poc */ for (i =0 ; i <ARRAY_SIZE (dec_params->dpb); i++) {struct vb2_buffer *vb_buf = run->ref_buf[i]; +struct ref_base *base;/* * If a DPB entry is unused or invalid, address of current destination
@@ -963,54 +958,36 @@ static void config_registers(struct rkvdec_ctx *ctx, vb_buf = &dst_buf->vb2_buf; refer_addr =vb2_dma_contig_plane_dma_addr (vb_buf,0 ); -if (dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE ) - refer_addr |=RKVDEC_COLMV_USED_FLAG_REF ; -if (dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_FIELD ) - refer_addr |=RKVDEC_FIELD_REF ; - -if (dpb[i].fields &V4L2_H264_TOP_FIELD_REF ) - refer_addr |=RKVDEC_TOPFIELD_USED_REF ; -if (dpb[i].fields &V4L2_H264_BOTTOM_FIELD_REF ) - refer_addr |=RKVDEC_BOTFIELD_USED_REF ; - -writel_relaxed (dpb[i].top_field_order_cnt, - rkvdec->regs + poc_reg_tbl_top_field[i]); -writel_relaxed (dpb[i].bottom_field_order_cnt, - rkvdec->regs + poc_reg_tbl_bottom_field[i]); -if (i <V4L2_H264_NUM_DPB_ENTRIES -1 ) -writel_relaxed (refer_addr, - rkvdec->regs +RKVDEC_REG_H264_BASE_REFER (i)); + base = ®s->h26x.ref0_14_base[i];else -writel_relaxed (refer_addr, - rkvdec->regs +RKVDEC_REG_H264_BASE_REFER15 ); - } + base = ®s->h26x.ref15_base; - reg =RKVDEC_CUR_POC (dec_params->top_field_order_cnt); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_CUR_POC0 ); + base->field_ref = !!(dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_FIELD ); + base->colmv_used_flag_ref = !!(dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE ); + base->topfield_used_ref = !!(dpb[i].fields &V4L2_H264_TOP_FIELD_REF ); + base->botfield_used_ref = !!(dpb[i].fields &V4L2_H264_BOTTOM_FIELD_REF ); + base->base_addr = refer_addr >>4 ; - reg =RKVDEC_CUR_POC (dec_params->bottom_field_order_cnt); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_CUR_POC1 ); +set_poc_reg (regs, dpb[i].top_field_order_cnt, i, false); +set_poc_reg (regs, dpb[i].bottom_field_order_cnt, i, true); + } + + regs->h26x.cur_poc = dec_params->top_field_order_cnt; + regs->h26x.cur_poc1 = dec_params->bottom_field_order_cnt;/* config hw pps address */ offset = offsetof(struct rkvdec_h264_priv_tbl , param_set); -writel_relaxed (priv_start_addr + offset, - rkvdec->regs +RKVDEC_REG_PPS_BASE ); + regs->h26x.pps_base = priv_start_addr + offset;/* config hw rps address */ offset = offsetof(struct rkvdec_h264_priv_tbl , rps); -writel_relaxed (priv_start_addr + offset, - rkvdec->regs +RKVDEC_REG_RPS_BASE ); - - reg =RKVDEC_AXI_DDR_RDATA (0 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_AXI_DDR_RDATA ); - - reg =RKVDEC_AXI_DDR_WDATA (0 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_AXI_DDR_WDATA ); + regs->h26x.rps_base = priv_start_addr + offset; offset = offsetof(struct rkvdec_h264_priv_tbl , err_info); -writel_relaxed (priv_start_addr + offset, - rkvdec->regs +RKVDEC_REG_H264_ERRINFO_BASE ); + regs->h26x.errorinfo_base = priv_start_addr + offset; + +rkvdec_memcpy_toio (rkvdec->regs, regs,MIN (sizeof (*regs),4 * rkvdec->variant->num_regs)); }#define RKVDEC_H264_MAX_DEPTH_IN_BYTES 2
@@ -1181,8 +1158,6 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx)schedule_delayed_work (&rkvdec->watchdog_work,msecs_to_jiffies (2000 )); -writel (0 , rkvdec->regs +RKVDEC_REG_STRMD_ERR_EN ); -writel (0 , rkvdec->regs +RKVDEC_REG_H264_ERR_E );writel (1 , rkvdec->regs +RKVDEC_REG_PREF_LUMA_CACHE_COMMAND );writel (1 , rkvdec->regs +RKVDEC_REG_PREF_CHR_CACHE_COMMAND );
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c +27 -36
121 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +381 -190
586 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c +99 -132
358 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec.c +9 -1
@@ -914,6 +914,15 @@ void rkvdec_quirks_disable_qos(struct rkvdec_ctx *ctx)writel (reg, rkvdec->regs +RKVDEC_REG_QOS_CTRL ); } +void rkvdec_memcpy_toio (void __iomem *dst,void *src,size_t len) +{ +#ifdef CONFIG_ARM64 +__iowrite32_copy (dst, src, len /4 ); +#else +memcpy_toio (dst, src, len); +#endif +} +static void rkvdec_device_run (void *priv) {struct rkvdec_ctx *ctx = priv;
@@ -1227,7 +1236,6 @@ static void rkvdec_watchdog_func(struct work_struct *work)if (ctx) {dev_err (rkvdec->dev,"Frame processing timed out!\n" );writel (RKVDEC_IRQ_DIS , rkvdec->regs +RKVDEC_REG_INTERRUPT ); -writel (0 , rkvdec->regs +RKVDEC_REG_SYSCTRL );rkvdec_job_finish (ctx,VB2_BUF_STATE_ERROR ); } }
drivers/media/platform/rockchip/rkvdec/rkvdec.h +1 -0
@@ -151,6 +151,7 @@ struct rkvdec_aux_buf {void rkvdec_run_preamble (struct rkvdec_ctx *ctx,struct rkvdec_run *run);void rkvdec_run_postamble (struct rkvdec_ctx *ctx,struct rkvdec_run *run); +void rkvdec_memcpy_toio (void __iomem *dst,void *src,size_t len);void rkvdec_quirks_disable_qos (struct rkvdec_ctx *ctx);
Signature · 1 line
2.52.0
Re: [PATCH v6 04/17] media: rkvdec: Switch to using structs instead of writel
Hi Detlev,
Quoted 239 lines · Detlev Casanova
In an effort to merge the rkvdec2 driver [1] with this one, switch from
writel()calls to using structs to represent the register mappings.This is done in order to have all supported decoders use the same format in the future and ease reading of the code.
Using structs also improves stability as the hardware is tested and validated downstream using a similar method.
It was noticed, on decoders, that:
- Some registers require to be writen in increasing order [2]
- Some registers, even if unrelated, need to be written to their reset values (it was the case here for axi_ddr_[rw]data).Using structs can also help improving performance later when, e.g. multicore support is added on RK3588.
Performance seems to be slightly improved, but at least, not made worse. Running fluster's JVT-AVC_V1 test suite with GStreamer on the Radxa ROCK PI 4 SE gives the following times:
Before this patch:
- --jobs 1: Ran 129/135 tests successfully in 77.167 secs
- --jobs 6: Ran 129/135 tests successfully in 23.046 secsWith this patch:
- --jobs 1: Ran 129/135 tests successfully in 70.698 secs
- --jobs 6: Ran 129/135 tests successfully in 22.917 secsThis also shows that the fluster score hasn't changed.
[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/Reviewed-by Nicolas Dufresne <[email protected]>Signed-off-by Detlev Casanova <[email protected]>--- .../platform/rockchip/rkvdec/rkvdec-h264.c | 165 +++-- .../platform/rockchip/rkvdec/rkvdec-hevc.c | 63 +- .../platform/rockchip/rkvdec/rkvdec-regs.h | 571 ++++++++++++------ .../platform/rockchip/rkvdec/rkvdec-vp9.c | 231 +++---- .../media/platform/rockchip/rkvdec/rkvdec.c | 10 +- .../media/platform/rockchip/rkvdec/rkvdec.h | 1 + 6 files changed, 587 insertions(+), 454 deletions(-)drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +53
-76@@ -115,6 +115,7 @@ struct rkvdec_h264_run {struct rkvdec_h264_ctx {struct rkvdec_aux_buf priv_tbl;struct rkvdec_h264_reflists reflists; +struct rkvdec_regs regs; }; #define CABAC_ENTRY(ctxidx, idc0_m, idc0_n, idc1_m, idc1_n, \@@ -841,45 +842,41 @@ static void assemble_hw_scaling_list(struct rkvdec_ctx *ctx, }/* -* dpb poc related registers table +* Set the ref POC in the correct register. +* +* The 32 registers are spread across 3 regions, each alternating top and bottom ref POCs: +* - 1: ref 0 to 14 contain top 0 to 7 and bottoms 0 to 6 +* - 2: ref 15 to 29 contain top 8 to 14 and bottoms 7 to 14 +* - 3: ref 30 and 31 which correspond to top 15 and bottom 15 respectively. */ -static const u32 poc_reg_tbl_top_field[16 ] = { -RKVDEC_REG_H264_POC_REFER0 (0 ), -RKVDEC_REG_H264_POC_REFER0 (2 ), -RKVDEC_REG_H264_POC_REFER0 (4 ), -RKVDEC_REG_H264_POC_REFER0 (6 ), -RKVDEC_REG_H264_POC_REFER0 (8 ), -RKVDEC_REG_H264_POC_REFER0 (10 ), -RKVDEC_REG_H264_POC_REFER0 (12 ), -RKVDEC_REG_H264_POC_REFER0 (14 ), -RKVDEC_REG_H264_POC_REFER1 (1 ), -RKVDEC_REG_H264_POC_REFER1 (3 ), -RKVDEC_REG_H264_POC_REFER1 (5 ), -RKVDEC_REG_H264_POC_REFER1 (7 ), -RKVDEC_REG_H264_POC_REFER1 (9 ), -RKVDEC_REG_H264_POC_REFER1 (11 ), -RKVDEC_REG_H264_POC_REFER1 (13 ), -RKVDEC_REG_H264_POC_REFER2 (0 ) -}; - -static const u32 poc_reg_tbl_bottom_field[16 ] = { -RKVDEC_REG_H264_POC_REFER0 (1 ), -RKVDEC_REG_H264_POC_REFER0 (3 ), -RKVDEC_REG_H264_POC_REFER0 (5 ), -RKVDEC_REG_H264_POC_REFER0 (7 ), -RKVDEC_REG_H264_POC_REFER0 (9 ), -RKVDEC_REG_H264_POC_REFER0 (11 ), -RKVDEC_REG_H264_POC_REFER0 (13 ), -RKVDEC_REG_H264_POC_REFER1 (0 ), -RKVDEC_REG_H264_POC_REFER1 (2 ), -RKVDEC_REG_H264_POC_REFER1 (4 ), -RKVDEC_REG_H264_POC_REFER1 (6 ), -RKVDEC_REG_H264_POC_REFER1 (8 ), -RKVDEC_REG_H264_POC_REFER1 (10 ), -RKVDEC_REG_H264_POC_REFER1 (12 ), -RKVDEC_REG_H264_POC_REFER1 (14 ), -RKVDEC_REG_H264_POC_REFER2 (1 ) -}; +static void set_poc_reg (struct rkvdec_regs *regs,uint32_t poc,int id,bool bottom) +{ +if (!bottom) { +switch (id) { + case 0 ... 7: + regs->h26x.ref0_14_poc[id *2 ] = poc; +break ; + case 8 ... 14: + regs->h26x.ref15_29_poc[(id -8 ) *2 +1 ] = poc; +break ; +case 15 : + regs->h26x.ref30_poc = poc; +break ; + } + }else { +switch (id) { + case 0 ... 6: + regs->h26x.ref0_14_poc[id *2 +1 ] = poc; +break ; + case 7 ... 14: + regs->h26x.ref15_29_poc[(id -7 ) *2 ] = poc; +break ; +case 15 : + regs->h26x.ref31_poc = poc; +break ; + } + } +}static void config_registers (struct rkvdec_ctx *ctx,struct rkvdec_h264_run *run)@@ -894,6 +891,7 @@ static void config_registers(struct rkvdec_ctx *ctx,struct vb2_v4l2_buffer *src_buf = run->base.bufs.src;struct vb2_v4l2_buffer *dst_buf = run->base.bufs.dst;const struct v4l2_format *f; +struct rkvdec_regs *regs = &h264_ctx->regs;dma_addr_t rlc_addr;dma_addr_t refer_addr;u32 rlc_len;@@ -903,10 +901,11 @@ static void config_registers(struct rkvdec_ctx *ctx,u32 yuv_virstride =0 ;u32 offset;dma_addr_t dst_addr; -u32 reg, i; +u32 i; - reg =RKVDEC_MODE (RKVDEC_MODE_H264 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_SYSCTRL ); +memset (regs,0 ,sizeof (*regs)); + + regs->common.reg02.dec_mode =RKVDEC_MODE_H264 ; f = &ctx->decoded_fmt; dst_fmt = &f->fmt.pix_mp;@@ -921,39 +920,35 @@ static void config_registers(struct rkvdec_ctx *ctx,else if (sps->chroma_format_idc ==2 ) yuv_virstride =2 * y_virstride; - reg =RKVDEC_Y_HOR_VIRSTRIDE (hor_virstride /16 ) | -RKVDEC_UV_HOR_VIRSTRIDE (hor_virstride /16 ) | -RKVDEC_SLICE_NUM_HIGHBIT | -RKVDEC_SLICE_NUM_LOWBITS (0x7ff ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_PICPAR ); + regs->common.reg03.uv_hor_virstride = hor_virstride /16 ; + regs->common.reg03.y_hor_virstride = hor_virstride /16 ; + regs->common.reg03.slice_num_highbit =1 ; + regs->common.reg03.slice_num_lowbits =0x7ff ;/* config rlc base address */ rlc_addr =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,0 ); -writel_relaxed (rlc_addr, rkvdec->regs +RKVDEC_REG_STRM_RLC_BASE ); -writel_relaxed (rlc_addr, rkvdec->regs +RKVDEC_REG_RLCWRITE_BASE ); + regs->common.strm_rlc_base = rlc_addr; + regs->h26x.rlcwrite_base = rlc_addr; rlc_len =vb2_get_plane_payload (&src_buf->vb2_buf,0 ); - reg =RKVDEC_STRM_LEN (rlc_len); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_STRM_LEN ); + regs->common.stream_len = rlc_len;/* config cabac table */ offset = offsetof(struct rkvdec_h264_priv_tbl , cabac_table); -writel_relaxed (priv_start_addr + offset, - rkvdec->regs +RKVDEC_REG_CABACTBL_PROB_BASE ); + regs->common.cabactbl_base = priv_start_addr + offset;/* config output base address */ dst_addr =vb2_dma_contig_plane_dma_addr (&dst_buf->vb2_buf,0 ); -writel_relaxed (dst_addr, rkvdec->regs +RKVDEC_REG_DECOUT_BASE ); + regs->common.decout_base = dst_addr; - reg =RKVDEC_Y_VIRSTRIDE (y_virstride /16 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_Y_VIRSTRIDE ); + regs->common.reg08.y_virstride = y_virstride /16 ; - reg =RKVDEC_YUV_VIRSTRIDE (yuv_virstride /16 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_YUV_VIRSTRIDE ); + regs->common.reg09.yuv_virstride = yuv_virstride /16 ;/* config ref pic address & poc */ for (i =0 ; i <ARRAY_SIZE (dec_params->dpb); i++) {struct vb2_buffer *vb_buf = run->ref_buf[i]; +struct ref_base *base;/* * If a DPB entry is unused or invalid, address of current destination @@ -963,54 +958,36 @@ static void config_registers(struct rkvdec_ctx *ctx, vb_buf = &dst_buf->vb2_buf; refer_addr =vb2_dma_contig_plane_dma_addr (vb_buf,0 ); -if (dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE ) - refer_addr |=RKVDEC_COLMV_USED_FLAG_REF ; -if (dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_FIELD ) - refer_addr |=RKVDEC_FIELD_REF ; - -if (dpb[i].fields &V4L2_H264_TOP_FIELD_REF ) - refer_addr |=RKVDEC_TOPFIELD_USED_REF ; -if (dpb[i].fields &V4L2_H264_BOTTOM_FIELD_REF ) - refer_addr |=RKVDEC_BOTFIELD_USED_REF ; - -writel_relaxed (dpb[i].top_field_order_cnt, - rkvdec->regs + poc_reg_tbl_top_field[i]); -writel_relaxed (dpb[i].bottom_field_order_cnt, - rkvdec->regs + poc_reg_tbl_bottom_field[i]); -if (i <V4L2_H264_NUM_DPB_ENTRIES -1 ) -writel_relaxed (refer_addr, - rkvdec->regs +RKVDEC_REG_H264_BASE_REFER (i)); + base = ®s->h26x.ref0_14_base[i];else -writel_relaxed (refer_addr, - rkvdec->regs +RKVDEC_REG_H264_BASE_REFER15 );
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c static void config_registers(struct rkvdec_ctx *ctx, · line 970
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +6
-3- } + base = ®s->h26x.ref15_base; - reg =RKVDEC_CUR_POC (dec_params->top_field_order_cnt); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_CUR_POC0 ); + base->field_ref = !!(dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_FIELD ); + base->colmv_used_flag_ref = !!(dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE ); + base->topfield_used_ref = !!(dpb[i].fields &V4L2_H264_TOP_FIELD_REF ); + base->botfield_used_ref = !!(dpb[i].fields &V4L2_H264_BOTTOM_FIELD_REF ); + base->base_addr = refer_addr >>4 ;
Please set before ref fields to be consistent with hevc.
Quoted 24 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +7
-10- reg =RKVDEC_CUR_POC (dec_params->bottom_field_order_cnt); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_CUR_POC1 ); +set_poc_reg (regs, dpb[i].top_field_order_cnt, i, false); +set_poc_reg (regs, dpb[i].bottom_field_order_cnt, i, true); + } + + regs->h26x.cur_poc = dec_params->top_field_order_cnt; + regs->h26x.cur_poc1 = dec_params->bottom_field_order_cnt;/* config hw pps address */ offset = offsetof(struct rkvdec_h264_priv_tbl , param_set); -writel_relaxed (priv_start_addr + offset, - rkvdec->regs +RKVDEC_REG_PPS_BASE ); + regs->h26x.pps_base = priv_start_addr + offset;/* config hw rps address */ offset = offsetof(struct rkvdec_h264_priv_tbl , rps); -writel_relaxed (priv_start_addr + offset, - rkvdec->regs +RKVDEC_REG_RPS_BASE ); - - reg =RKVDEC_AXI_DDR_RDATA (0 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_AXI_DDR_RDATA ); -
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c static void config_registers(struct rkvdec_ctx *ctx, · line 990
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +4
-4- reg =RKVDEC_AXI_DDR_WDATA (0 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_AXI_DDR_WDATA ); + regs->h26x.rps_base = priv_start_addr + offset; offset = offsetof(struct rkvdec_h264_priv_tbl , err_info); -writel_relaxed (priv_start_addr + offset, - rkvdec->regs +RKVDEC_REG_H264_ERRINFO_BASE ); + regs->h26x.errorinfo_base = priv_start_addr + offset; + +rkvdec_memcpy_toio (rkvdec->regs, regs,MIN (sizeof (*regs),4 * rkvdec->variant->num_regs));
Should this use sizeof(u32) instead of 4 ?
Quoted 121 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +0
-2}#define RKVDEC_H264_MAX_DEPTH_IN_BYTES 2@@ -1181,8 +1158,6 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx)schedule_delayed_work (&rkvdec->watchdog_work,msecs_to_jiffies (2000 )); -writel (0 , rkvdec->regs +RKVDEC_REG_STRMD_ERR_EN ); -writel (0 , rkvdec->regs +RKVDEC_REG_H264_ERR_E );writel (1 , rkvdec->regs +RKVDEC_REG_PREF_LUMA_CACHE_COMMAND );writel (1 , rkvdec->regs +RKVDEC_REG_PREF_CHR_CACHE_COMMAND );drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c +25
-27@@ -129,6 +129,7 @@ struct rkvdec_hevc_run {struct rkvdec_hevc_ctx {struct rkvdec_aux_buf priv_tbl;struct v4l2_ctrl_hevc_scaling_matrix scaling_matrix_cache; +struct rkvdec_regs regs; };struct scaling_factor {@@ -548,6 +549,7 @@ static void config_registers(struct rkvdec_ctx *ctx,const struct v4l2_ctrl_hevc_slice_params *sl_params = &run->slices_params[0 ];const struct v4l2_hevc_dpb_entry *dpb = decode_params->dpb;struct rkvdec_hevc_ctx *hevc_ctx = ctx->priv; +struct rkvdec_regs *regs = &hevc_ctx->regs;dma_addr_t priv_start_addr = hevc_ctx->priv_tbl.dma;const struct v4l2_pix_format_mplane *dst_fmt;struct vb2_v4l2_buffer *src_buf = run->base.bufs.src;@@ -564,8 +566,9 @@ static void config_registers(struct rkvdec_ctx *ctx,dma_addr_t dst_addr;u32 reg, i; - reg =RKVDEC_MODE (RKVDEC_MODE_HEVC ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_SYSCTRL ); +memset (regs,0 ,sizeof (*regs)); + + regs->common.reg02.dec_mode =RKVDEC_MODE_HEVC ; f = &ctx->decoded_fmt; dst_fmt = &f->fmt.pix_mp;@@ -580,33 +583,27 @@ static void config_registers(struct rkvdec_ctx *ctx,else if (sps->chroma_format_idc ==2 ) yuv_virstride =2 * y_virstride; - reg =RKVDEC_Y_HOR_VIRSTRIDE (hor_virstride /16 ) | -RKVDEC_UV_HOR_VIRSTRIDE (hor_virstride /16 ) | -RKVDEC_SLICE_NUM_LOWBITS (run->num_slices); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_PICPAR ); + regs->common.reg03.slice_num_lowbits = run->num_slices; + regs->common.reg03.uv_hor_virstride = hor_virstride /16 ; + regs->common.reg03.y_hor_virstride = hor_virstride /16 ;/* config rlc base address */ rlc_addr =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,0 ); -writel_relaxed (rlc_addr, rkvdec->regs +RKVDEC_REG_STRM_RLC_BASE ); + regs->common.strm_rlc_base = rlc_addr; rlc_len =vb2_get_plane_payload (&src_buf->vb2_buf,0 ); - reg =RKVDEC_STRM_LEN (round_up (rlc_len,16 ) +64 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_STRM_LEN ); + regs->common.stream_len =round_up (rlc_len,16 ) +64 ;/* config cabac table */ offset = offsetof(struct rkvdec_hevc_priv_tbl , cabac_table); -writel_relaxed (priv_start_addr + offset, - rkvdec->regs +RKVDEC_REG_CABACTBL_PROB_BASE ); + regs->common.cabactbl_base = priv_start_addr + offset;/* config output base address */ dst_addr =vb2_dma_contig_plane_dma_addr (&dst_buf->vb2_buf,0 ); -writel_relaxed (dst_addr, rkvdec->regs +RKVDEC_REG_DECOUT_BASE ); - - reg =RKVDEC_Y_VIRSTRIDE (y_virstride /16 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_Y_VIRSTRIDE ); + regs->common.decout_base = dst_addr; - reg =RKVDEC_YUV_VIRSTRIDE (yuv_virstride /16 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_YUV_VIRSTRIDE ); + regs->common.reg08.y_virstride = y_virstride /16 ; + regs->common.reg09.yuv_virstride = yuv_virstride /16 ;/* config ref pic address */ for (i =0 ; i <15 ; i++) {@@ -620,33 +617,29 @@ static void config_registers(struct rkvdec_ctx *ctx, } refer_addr =vb2_dma_contig_plane_dma_addr (vb_buf,0 ); -writel_relaxed (refer_addr | reg, - rkvdec->regs +RKVDEC_REG_H264_BASE_REFER (i)); - reg =RKVDEC_POC_REFER (i < decode_params->num_active_dpb_entries ? - dpb[i].pic_order_cnt_val :0 ); -writel_relaxed (reg, - rkvdec->regs +RKVDEC_REG_H264_POC_REFER0 (i)); + regs->h26x.ref0_14_base[i].base_addr = refer_addr >>4 ; + regs->h26x.ref0_14_base[i].field_ref = !!(reg &1 ); + regs->h26x.ref0_14_base[i].topfield_used_ref = !!(reg &2 ); + regs->h26x.ref0_14_base[i].botfield_used_ref = !!(reg &4 ); + regs->h26x.ref0_14_base[i].colmv_used_flag_ref = !!(reg &8 ); + + regs->h26x.ref0_14_poc[i] = i < decode_params->num_active_dpb_entries + ? dpb[i].pic_order_cnt_val + :0 ; } - reg =RKVDEC_CUR_POC (sl_params->slice_pic_order_cnt); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_CUR_POC0 ); + regs->h26x.cur_poc = sl_params->slice_pic_order_cnt;/* config hw pps address */ offset = offsetof(struct rkvdec_hevc_priv_tbl , param_set); -writel_relaxed (priv_start_addr + offset, - rkvdec->regs +RKVDEC_REG_PPS_BASE ); + regs->h26x.pps_base = priv_start_addr + offset;/* config hw rps address */ offset = offsetof(struct rkvdec_hevc_priv_tbl , rps);
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c static void config_registers(struct rkvdec_ctx *ctx, · line 642
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c +2
-7-writel_relaxed (priv_start_addr + offset, - rkvdec->regs +RKVDEC_REG_RPS_BASE ); - - reg =RKVDEC_AXI_DDR_RDATA (0 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_AXI_DDR_RDATA ); + regs->h26x.rps_base = priv_start_addr + offset; - reg =RKVDEC_AXI_DDR_WDATA (0 ); -writel_relaxed (reg, rkvdec->regs +RKVDEC_REG_AXI_DDR_WDATA ); +rkvdec_memcpy_toio (rkvdec->regs, regs,MIN (sizeof (*regs),4 * rkvdec->variant->num_regs));
Same here regarding sizeof(u32)
Quoted 245 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c +0
-2}#define RKVDEC_HEVC_MAX_DEPTH_IN_BYTES 2@@ -784,8 +777,6 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx)schedule_delayed_work (&rkvdec->watchdog_work,msecs_to_jiffies (2000 )); -writel (0 , rkvdec->regs +RKVDEC_REG_STRMD_ERR_EN ); -writel (0 , rkvdec->regs +RKVDEC_REG_H264_ERR_E );writel (1 , rkvdec->regs +RKVDEC_REG_PREF_LUMA_CACHE_COMMAND );writel (1 , rkvdec->regs +RKVDEC_REG_PREF_CHR_CACHE_COMMAND );drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +23
-190@@ -3,7 +3,12 @@#ifndef RKVDEC_REGS_H_ #define RKVDEC_REGS_H_ -/* rkvcodec registers */ +#include <linux/types.h> + +/* +* REG_INTERRUPT is accessed via writel to enable the decoder after +* configuring it and clear interrupt strmd_error_status +*/ #define RKVDEC_REG_INTERRUPT 0x004#define RKVDEC_INTERRUPT_DEC_E BIT(0)#define RKVDEC_CONFIG_DEC_CLK_GATE_E BIT(1)@@ -30,198 +35,384 @@#define RKVDEC_SOFTRESET_RDY BIT(22)#define RKVDEC_WR_DDR_ALIGN_EN BIT(23) -#define RKVDEC_REG_SYSCTRL 0x008 -#define RKVDEC_IN_ENDIAN BIT(0) -#define RKVDEC_IN_SWAP32_E BIT(1) -#define RKVDEC_IN_SWAP64_E BIT(2) -#define RKVDEC_STR_ENDIAN BIT(3) -#define RKVDEC_STR_SWAP32_E BIT(4) -#define RKVDEC_STR_SWAP64_E BIT(5) -#define RKVDEC_OUT_ENDIAN BIT(6) -#define RKVDEC_OUT_SWAP32_E BIT(7) -#define RKVDEC_OUT_CBCR_SWAP BIT(8) -#define RKVDEC_RLC_MODE_DIRECT_WRITE BIT(10) -#define RKVDEC_RLC_MODE BIT(11) -#define RKVDEC_STRM_START_BIT (x) (((x) & 0x7f) << 12) -#define RKVDEC_MODE (x) (((x) & 0x03) << 20) -#define RKVDEC_MODE_HEVC 0 -#define RKVDEC_MODE_H264 1 -#define RKVDEC_MODE_VP9 2 -#define RKVDEC_RPS_MODE BIT(24) -#define RKVDEC_STRM_MODE BIT(25) -#define RKVDEC_H264_STRM_LASTPKT BIT(26) -#define RKVDEC_H264_FIRSTSLICE_FLAG BIT(27) -#define RKVDEC_H264_FRAME_ORSLICE BIT(28) -#define RKVDEC_BUSPR_SLOT_DIS BIT(29) - -#define RKVDEC_REG_PICPAR 0x00C -#define RKVDEC_Y_HOR_VIRSTRIDE (x) ((x) & 0x1ff) -#define RKVDEC_SLICE_NUM_HIGHBIT BIT(11) -#define RKVDEC_UV_HOR_VIRSTRIDE (x) (((x) & 0x1ff) << 12) -#define RKVDEC_SLICE_NUM_LOWBITS (x) (((x) & 0x7ff) << 21) - -#define RKVDEC_REG_STRM_RLC_BASE 0x010 - -#define RKVDEC_REG_STRM_LEN 0x014 -#define RKVDEC_STRM_LEN (x) ((x) & 0x7ffffff) - -#define RKVDEC_REG_CABACTBL_PROB_BASE 0x018 -#define RKVDEC_REG_DECOUT_BASE 0x01C - -#define RKVDEC_REG_Y_VIRSTRIDE 0x020 -#define RKVDEC_Y_VIRSTRIDE (x) ((x) & 0xfffff) - -#define RKVDEC_REG_YUV_VIRSTRIDE 0x024 -#define RKVDEC_YUV_VIRSTRIDE (x) ((x) & 0x1fffff) -#define RKVDEC_REG_H264_BASE_REFER (i) (((i) * 0x04) + 0x028) - -#define RKVDEC_REG_H264_BASE_REFER15 0x0C0 -#define RKVDEC_FIELD_REF BIT(0) -#define RKVDEC_TOPFIELD_USED_REF BIT(1) -#define RKVDEC_BOTFIELD_USED_REF BIT(2) -#define RKVDEC_COLMV_USED_FLAG_REF BIT(3) - -#define RKVDEC_REG_VP9_LAST_FRAME_BASE 0x02c -#define RKVDEC_REG_VP9_GOLDEN_FRAME_BASE 0x030 -#define RKVDEC_REG_VP9_ALTREF_FRAME_BASE 0x034 - -#define RKVDEC_REG_VP9_CPRHEADER_OFFSET 0x028 -#define RKVDEC_VP9_CPRHEADER_OFFSET (x) ((x) & 0xffff) - -#define RKVDEC_REG_VP9_REFERLAST_BASE 0x02C -#define RKVDEC_REG_VP9_REFERGOLDEN_BASE 0x030 -#define RKVDEC_REG_VP9_REFERALFTER_BASE 0x034 - -#define RKVDEC_REG_VP9COUNT_BASE 0x038 -#define RKVDEC_VP9COUNT_UPDATE_EN BIT(0) - -#define RKVDEC_REG_VP9_SEGIDLAST_BASE 0x03C -#define RKVDEC_REG_VP9_SEGIDCUR_BASE 0x040 -#define RKVDEC_REG_VP9_FRAME_SIZE (i) ((i) * 0x04 + 0x044) -#define RKVDEC_VP9_FRAMEWIDTH (x) (((x) & 0xffff) << 0) -#define RKVDEC_VP9_FRAMEHEIGHT (x) (((x) & 0xffff) << 16) - -#define RKVDEC_VP9_SEGID_GRP (i) ((i) * 0x04 + 0x050) -#define RKVDEC_SEGID_ABS_DELTA (x) ((x) & 0x1) -#define RKVDEC_SEGID_FRAME_QP_DELTA_EN (x) (((x) & 0x1) << 1) -#define RKVDEC_SEGID_FRAME_QP_DELTA (x) (((x) & 0x1ff) << 2) -#define RKVDEC_SEGID_FRAME_LOOPFILTER_VALUE_EN (x) (((x) & 0x1) << 11) -#define RKVDEC_SEGID_FRAME_LOOPFILTER_VALUE (x) (((x) & 0x7f) << 12) -#define RKVDEC_SEGID_REFERINFO_EN (x) (((x) & 0x1) << 19) -#define RKVDEC_SEGID_REFERINFO (x) (((x) & 0x03) << 20) -#define RKVDEC_SEGID_FRAME_SKIP_EN (x) (((x) & 0x1) << 22) - -#define RKVDEC_VP9_CPRHEADER_CONFIG 0x070 -#define RKVDEC_VP9_TX_MODE (x) ((x) & 0x07) -#define RKVDEC_VP9_FRAME_REF_MODE (x) (((x) & 0x03) << 3) - -#define RKVDEC_VP9_REF_SCALE (i) ((i) * 0x04 + 0x074) -#define RKVDEC_VP9_REF_HOR_SCALE (x) ((x) & 0xffff) -#define RKVDEC_VP9_REF_VER_SCALE (x) (((x) & 0xffff) << 16) - -#define RKVDEC_VP9_REF_DELTAS_LASTFRAME 0x080 -#define RKVDEC_REF_DELTAS_LASTFRAME (pos, val) (((val) & 0x7f) << ((pos) * 7)) - -#define RKVDEC_VP9_INFO_LASTFRAME 0x084 -#define RKVDEC_MODE_DELTAS_LASTFRAME (pos, val) (((val) & 0x7f) << ((pos) * 7)) -#define RKVDEC_SEG_EN_LASTFRAME BIT(16) -#define RKVDEC_LAST_SHOW_FRAME BIT(17) -#define RKVDEC_LAST_INTRA_ONLY BIT(18) -#define RKVDEC_LAST_WIDHHEIGHT_EQCUR BIT(19) -#define RKVDEC_COLOR_SPACE_LASTKEYFRAME (x) (((x) & 0x07) << 20) - -#define RKVDEC_VP9_INTERCMD_BASE 0x088 - -#define RKVDEC_VP9_INTERCMD_NUM 0x08C -#define RKVDEC_INTERCMD_NUM (x) ((x) & 0xffffff) - -#define RKVDEC_VP9_LASTTILE_SIZE 0x090 -#define RKVDEC_LASTTILE_SIZE (x) ((x) & 0xffffff) - -#define RKVDEC_VP9_HOR_VIRSTRIDE (i) ((i) * 0x04 + 0x094) -#define RKVDEC_HOR_Y_VIRSTRIDE (x) ((x) & 0x1ff) -#define RKVDEC_HOR_UV_VIRSTRIDE (x) (((x) & 0x1ff) << 16) - -#define RKVDEC_REG_H264_POC_REFER0 (i) (((i) * 0x04) + 0x064) -#define RKVDEC_REG_H264_POC_REFER1 (i) (((i) * 0x04) + 0x0C4) -#define RKVDEC_REG_H264_POC_REFER2 (i) (((i) * 0x04) + 0x120) -#define RKVDEC_POC_REFER (x) ((x) & 0xffffffff) - -#define RKVDEC_REG_CUR_POC0 0x0A0 -#define RKVDEC_REG_CUR_POC1 0x128 -#define RKVDEC_CUR_POC (x) ((x) & 0xffffffff) - -#define RKVDEC_REG_RLCWRITE_BASE 0x0A4 -#define RKVDEC_REG_PPS_BASE 0x0A8 -#define RKVDEC_REG_RPS_BASE 0x0AC - -#define RKVDEC_REG_STRMD_ERR_EN 0x0B0 -#define RKVDEC_STRMD_ERR_EN (x) ((x) & 0xffffffff) - -#define RKVDEC_REG_STRMD_ERR_STA 0x0B4 -#define RKVDEC_STRMD_ERR_STA (x) ((x) & 0xfffffff) -#define RKVDEC_COLMV_ERR_REF_PICIDX (x) (((x) & 0x0f) << 28) - -#define RKVDEC_REG_STRMD_ERR_CTU 0x0B8 -#define RKVDEC_STRMD_ERR_CTU (x) ((x) & 0xff) -#define RKVDEC_STRMD_ERR_CTU_YOFFSET (x) (((x) & 0xff) << 8) -#define RKVDEC_STRMFIFO_SPACE2FULL (x) (((x) & 0x7f) << 16) -#define RKVDEC_VP9_ERR_EN_CTU0 BIT(24) - -#define RKVDEC_REG_SAO_CTU_POS 0x0BC -#define RKVDEC_SAOWR_XOFFSET (x) ((x) & 0x1ff) -#define RKVDEC_SAOWR_YOFFSET (x) (((x) & 0x3ff) << 16) - -#define RKVDEC_VP9_LAST_FRAME_YSTRIDE 0x0C0 -#define RKVDEC_VP9_GOLDEN_FRAME_YSTRIDE 0x0C4 -#define RKVDEC_VP9_ALTREF_FRAME_YSTRIDE 0x0C8 -#define RKVDEC_VP9_REF_YSTRIDE (x) (((x) & 0xfffff) << 0) - -#define RKVDEC_VP9_LAST_FRAME_YUVSTRIDE 0x0CC -#define RKVDEC_VP9_REF_YUVSTRIDE (x) (((x) & 0x1fffff) << 0) - -#define RKVDEC_VP9_REF_COLMV_BASE 0x0D0 - -#define RKVDEC_REG_PERFORMANCE_CYCLE 0x100 -#define RKVDEC_PERFORMANCE_CYCLE (x) ((x) & 0xffffffff) - -#define RKVDEC_REG_AXI_DDR_RDATA 0x104 -#define RKVDEC_AXI_DDR_RDATA (x) ((x) & 0xffffffff) - -#define RKVDEC_REG_AXI_DDR_WDATA 0x108 -#define RKVDEC_AXI_DDR_WDATA (x) ((x) & 0xffffffff) - -#define RKVDEC_REG_FPGADEBUG_RESET 0x10C -#define RKVDEC_BUSIFD_RESETN BIT(0) -#define RKVDEC_CABAC_RESETN BIT(1) -#define RKVDEC_DEC_CTRL_RESETN BIT(2) -#define RKVDEC_TRANSD_RESETN BIT(3) -#define RKVDEC_INTRA_RESETN BIT(4) -#define RKVDEC_INTER_RESETN BIT(5) -#define RKVDEC_RECON_RESETN BIT(6) -#define RKVDEC_FILER_RESETN BIT(7) - -#define RKVDEC_REG_PERFORMANCE_SEL 0x110 -#define RKVDEC_PERF_SEL_CNT0 (x) ((x) & 0x3f) -#define RKVDEC_PERF_SEL_CNT1 (x) (((x) & 0x3f) << 8) -#define RKVDEC_PERF_SEL_CNT2 (x) (((x) & 0x3f) << 16) - -#define RKVDEC_REG_PERFORMANCE_CNT (i) ((i) * 0x04 + 0x114) -#define RKVDEC_PERF_CNT (x) ((x) & 0xffffffff) - -#define RKVDEC_REG_H264_ERRINFO_BASE 0x12C - -#define RKVDEC_REG_H264_ERRINFO_NUM 0x130 -#define RKVDEC_SLICEDEC_NUM (x) ((x) & 0x3fff) -#define RKVDEC_STRMD_DECT_ERR_FLAG BIT(15) -#define RKVDEC_ERR_PKT_NUM (x) (((x) & 0x3fff) << 16) - -#define RKVDEC_REG_H264_ERR_E 0x134 -#define RKVDEC_H264_ERR_EN_HIGHBITS (x) ((x) & 0x3fffffff) -#define RKVDEC_REG_QOS_CTRL 0x18C +/* +* Cache configuration is not covered in the range of the register struct +*/ #define RKVDEC_REG_PREF_LUMA_CACHE_COMMAND 0x410#define RKVDEC_REG_PREF_CHR_CACHE_COMMAND 0x450 +/* +* Define the mode values +*/ +#define RKVDEC_MODE_HEVC 0 +#define RKVDEC_MODE_H264 1 +#define RKVDEC_MODE_VP9 2 + +/* rkvcodec registers */ +struct rkvdec_common_regs { +struct rkvdec_id { +u32 minor_ver :8 ; +u32 level :1 ; +u32 dec_support :3 ; +u32 profile :1 ;
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h line 69
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +10
-0+ u32 reserved0 : 1; + u32 codec_flag : 1; + u32 reserved1 : 1; + u32 prod_num : 16; + } reg00; + +struct rkvdec_int { +u32 dec_e :1 ; +u32 dec_clkgate_e :1 ; +u32 reserved0 :1 ;
This is dec_e_strmd_clkgate_dis on rk3328.
Quoted 9 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +9
-0+ u32 timeout_mode : 1; + u32 dec_irq_dis : 1; + u32 dec_timeout_e : 1; + u32 buf_empty_en : 1; + u32 stmerror_waitdecfifo_empty : 1; + u32 dec_irq : 1; + u32 dec_irq_raw : 1; + u32 reserved2 : 2; + u32 dec_rdy_sta : 1;
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h line 88
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +10
-0+ u32 dec_bus_sta : 1; + u32 dec_error_sta : 1; + u32 dec_timeout_sta : 1; + u32 dec_empty_sta : 1; + u32 colmv_ref_error_sta : 1; + u32 cabu_end_sta : 1; + u32 h264orvp9_error_mode : 1; + u32 softrst_en_p : 1; + u32 force_softreset_valid : 1; + u32 softreset_rdy : 1;
This is missing following from e.g. rk3328:
u32 wr_ddr_align_en : 1; u32 scl_down_en : 1; u32 allow_not_wr_unref_bframe : 1;
Quoted 17 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +17
-0+ u32 reserved1 : 9; + } reg01; + +struct rkvdec_sysctrl { +u32 in_endian :1 ; +u32 in_swap32_e :1 ; +u32 in_swap64_e :1 ; +u32 str_endian :1 ; +u32 str_swap32_e :1 ; +u32 str_swap64_e :1 ; +u32 out_endian :1 ; +u32 out_swap32_e :1 ; +u32 out_cbcr_swap :1 ; +u32 reserved0 :1 ; +u32 rlc_mode_direct_write :1 ; +u32 rlc_mode :1 ; +u32 strm_start_bit :7 ;
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h line 115
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +10
-0+ u32 reserved1 : 1; + u32 dec_mode : 2; + u32 reserved2 : 2; + u32 rps_mode : 1; + u32 stream_mode : 1; + u32 stream_lastpacket : 1; + u32 firstslice_flag : 1; + u32 frame_orslice : 1; + u32 buspr_slot_disable : 1; + u32 reserved3 : 2;
This is colmv_mode and ycacherd_prior on rk3328.
Quoted 21 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +21
-0+ } reg02; + +struct rkvdec_picpar { +u32 y_hor_virstride :9 ; +u32 reserved :2 ; +u32 slice_num_highbit :1 ; +u32 uv_hor_virstride :9 ; +u32 slice_num_lowbits :11 ; + } reg03; + +u32 strm_rlc_base; +u32 stream_len; +u32 cabactbl_base; +u32 decout_base; + +struct rkvdec_y_virstride { +u32 y_virstride :20 ; +u32 reserved0 :12 ; + } reg08; + +struct rkvdec_yuv_virstride {
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h line 146
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +10
-0+ u32 yuv_virstride : 21; + u32 reserved0 : 11; + } reg09; +} __packed; + +struct ref_base { +u32 field_ref :1 ; +u32 topfield_used_ref :1 ; +u32 botfield_used_ref :1 ; +u32 colmv_used_flag_ref :1 ;
This is called colmv_use_flag in TRM.
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h line 147
Quoted 1 line
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +1
-0+ u32 base_addr : 28;
Maybe this could be a union to not have to >> 4 the base addr?
Quoted 71 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +71
-0+}; + +struct rkvdec_h26x_regs { +struct ref_base ref0_14_base[15 ]; +u32 ref0_14_poc[15 ]; + +u32 cur_poc; +u32 rlcwrite_base; +u32 pps_base; +u32 rps_base; + +u32 strmd_error_e; + +struct { +u32 strmd_error_status :28 ; +u32 colmv_error_ref_picidx :4 ; + } reg45; + +struct { +u32 strmd_error_ctu_xoffset :8 ; +u32 strmd_error_ctu_yoffset :8 ; +u32 streamfifo_space2full :7 ; +u32 reserved0 :1 ; +u32 vp9_error_ctu0_en :1 ; +u32 reserved1 :7 ; + } reg46; + +struct { +u32 saowr_xoffet :9 ; +u32 reserved0 :7 ; +u32 saowr_yoffset :10 ; +u32 reserved1 :6 ; + } reg47; + +struct ref_base ref15_base; + +u32 ref15_29_poc[15 ]; + +u32 performance_cycle; +u32 axi_ddr_rdata; +u32 axi_ddr_wdata; + +struct { +u32 busifd_resetn :1 ; +u32 cabac_resetn :1 ; +u32 dec_ctrl_resetn :1 ; +u32 transd_resetn :1 ; +u32 intra_resetn :1 ; +u32 inter_resetn :1 ; +u32 recon_resetn :1 ; +u32 filer_resetn :1 ; +u32 reserved0 :24 ; + } reg67; + +struct { +u32 perf_cnt0_sel :6 ; +u32 reserved0 :2 ; +u32 perf_cnt1_sel :6 ; +u32 reserved1 :2 ; +u32 perf_cnt2_sel :6 ; +u32 reserved2 :10 ; + } reg68; + +u32 perf_cnt0; +u32 perf_cnt1; +u32 perf_cnt2; +u32 ref30_poc; +u32 ref31_poc; +u32 cur_poc1; +u32 errorinfo_base; +
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h line 228
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +10
-0+struct { +u32 slicedec_num :14 ; +u32 reserved0 :1 ; +u32 strmd_detect_error_flag :1 ; +u32 error_packet_num :14 ; +u32 reserved1 :2 ; + } reg76; + +struct { +u32 error_en_highbits :30 ;
rk3328 has 29:28 as strmd_error_en:
- strmd_error_en[0]: HEVC, H264 slice end error enable
- strmd_error_en[1]: HEVC, H264, VP9 frame end error enable
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h line 230
Quoted 2 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +2
-0+ u32 reserved : 2; + } reg77;
rk3328 also has following for h264, hevc and vp9:
- reg78_colmv_cur_base
- reg79_colmv_ref0_base
...
- reg94_colmv_ref15_base
reg95_scanlist_addr (h264 and hevc)
- 31:4: scanlist_addr
- 0: scanlist_addr_valid_en
- reg96_sd_decout_base
- reg97_sd_y_virstride
- reg98_sd_hor_stride
- reg99_qos_ctrl
- reg100_PERF_*
...
- reg107_PERF_*
- reg108_qos1
Not sure we need to define all these here.
Quoted 540 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-regs.h +187
-0+} __packed; + +struct rkvdec_vp9_regs { +struct cprheader_offset { +u32 cprheader_offset :16 ; +u32 reserved :16 ; + } reg10; + +u32 refer_bases[3 ]; +u32 count_base; +u32 segidlast_base; +u32 segidcur_base; + +struct frame_sizes { +u32 framewidth :16 ; +u32 frameheight :16 ; + } reg17_19[3 ]; + +struct segid_grp { +u32 segid_abs_delta :1 ; +u32 segid_frame_qp_delta_en :1 ; +u32 segid_frame_qp_delta :9 ; +u32 segid_frame_loopfilter_value_en :1 ; +u32 segid_frame_loopfilter_value :7 ; +u32 segid_referinfo_en :1 ; +u32 segid_referinfo :2 ; +u32 segid_frame_skip_en :1 ; +u32 reserved :9 ; + } reg20_27[8 ]; + +struct cprheader_config { +u32 tx_mode :3 ; +u32 frame_reference_mode :2 ; +u32 reserved :27 ; + } reg28; + +struct ref_scale { +u32 ref_hor_scale :16 ; +u32 ref_ver_scale :16 ; + } reg29_31[3 ]; + +struct ref_deltas_lastframe { +u32 ref_deltas_lastframe0 :7 ; +u32 ref_deltas_lastframe1 :7 ; +u32 ref_deltas_lastframe2 :7 ; +u32 ref_deltas_lastframe3 :7 ; +u32 reserved :4 ; + } reg32; + +struct info_lastframe { +u32 mode_deltas_lastframe0 :7 ; +u32 mode_deltas_lastframe1 :7 ; +u32 reserved0 :2 ; +u32 segmentation_enable_lstframe :1 ; +u32 last_show_frame :1 ; +u32 last_intra_only :1 ; +u32 last_widthheight_eqcur :1 ; +u32 color_space_lastkeyframe :3 ; +u32 reserved1 :9 ; + } reg33; + +u32 intercmd_base; + +struct intercmd_num { +u32 intercmd_num :24 ; +u32 reserved :8 ; + } reg35; + +struct lasttile_size { +u32 lasttile_size :24 ; +u32 reserved :8 ; + } reg36; + +struct hor_virstride { +u32 y_hor_virstride :9 ; +u32 reserved0 :7 ; +u32 uv_hor_virstride :9 ; +u32 reserved1 :7 ; + } reg37_39[3 ]; + +u32 cur_poc; + +struct rlcwrite_base { +u32 reserved :3 ; +u32 rlcwrite_base :29 ; + } reg41; + +struct pps_base { +u32 reserved :4 ; +u32 pps_base :28 ; + } reg42; + +struct rps_base { +u32 reserved :4 ; +u32 rps_base :28 ; + } reg43; + +struct strmd_error_en { +u32 strmd_error_e :28 ; +u32 reserved :4 ; + } reg44; + +u32 vp9_error_info0; + +struct strmd_error_ctu { +u32 strmd_error_ctu_xoffset :8 ; +u32 strmd_error_ctu_yoffset :8 ; +u32 streamfifo_space2full :7 ; +u32 reserved0 :1 ; +u32 error_ctu0_en :1 ; +u32 reserved1 :7 ; + } reg46; + +struct sao_ctu_position { +u32 saowr_xoffet :9 ; +u32 reserved0 :7 ; +u32 saowr_yoffset :10 ; +u32 reserved1 :6 ; + } reg47; + +struct ystride { +u32 virstride :20 ; +u32 reserved :12 ; + } reg48_50[3 ]; + +struct lastref_yuvstride { +u32 lastref_yuv_virstride :21 ; +u32 reserved :11 ; + } reg51; + +u32 refcolmv_base; + +u32 reserved0[11 ]; + +u32 performance_cycle; +u32 axi_ddr_rdata; +u32 axi_ddr_wdata; + +struct fpgadebug_reset { +u32 busifd_resetn :1 ; +u32 cabac_resetn :1 ; +u32 dec_ctrl_resetn :1 ; +u32 transd_resetn :1 ; +u32 intra_resetn :1 ; +u32 inter_resetn :1 ; +u32 recon_resetn :1 ; +u32 filer_resetn :1 ; +u32 reserved :24 ; + } reg67; + +struct performance_sel { +u32 perf_cnt0_sel :6 ; +u32 reserved0 :2 ; +u32 perf_cnt1_sel :6 ; +u32 reserved1 :2 ; +u32 perf_cnt2_sel :6 ; +u32 reserved :10 ; + } reg68; + +u32 perf_cnt0; +u32 perf_cnt1; +u32 perf_cnt2; + +u32 reserved1[3 ]; + +u32 vp9_error_info1; + +struct error_ctu1 { +u32 vp9_error_ctu1_x :6 ; +u32 reserved0 :2 ; +u32 vp9_error_ctu1_y :6 ; +u32 reserved1 :1 ; +u32 vp9_error_ctu1_en :1 ; +u32 reserved2 :16 ; + } reg76; + +u32 reserved2; +} __packed; + +struct rkvdec_regs { +struct rkvdec_common_regs common; +union { +struct rkvdec_h26x_regs h26x; +struct rkvdec_vp9_regs vp9; + }; +} __packed; +#endif /* RKVDEC_REGS_H_ */ drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c +93
-127@@ -163,6 +163,7 @@ struct rkvdec_vp9_ctx {struct v4l2_vp9_frame_context frame_context[4 ];struct rkvdec_vp9_frame_info cur;struct rkvdec_vp9_frame_info last; +struct rkvdec_regs regs; };static void write_coeff_plane (const u8 coef[6 ][6 ][3 ],u8 *coeff_plane)@@ -347,38 +348,6 @@ static void init_probs(struct rkvdec_ctx *ctx,init_inter_probs (ctx, run); } -struct rkvdec_vp9_ref_reg { -u32 reg_frm_size; -u32 reg_hor_stride; -u32 reg_y_stride; -u32 reg_yuv_stride; -u32 reg_ref_base; -}; - -static struct rkvdec_vp9_ref_reg ref_regs[] = { - { - .reg_frm_size =RKVDEC_REG_VP9_FRAME_SIZE (0 ), - .reg_hor_stride =RKVDEC_VP9_HOR_VIRSTRIDE (0 ), - .reg_y_stride =RKVDEC_VP9_LAST_FRAME_YSTRIDE , - .reg_yuv_stride =RKVDEC_VP9_LAST_FRAME_YUVSTRIDE , - .reg_ref_base =RKVDEC_REG_VP9_LAST_FRAME_BASE , - }, - { - .reg_frm_size =RKVDEC_REG_VP9_FRAME_SIZE (1 ), - .reg_hor_stride =RKVDEC_VP9_HOR_VIRSTRIDE (1 ), - .reg_y_stride =RKVDEC_VP9_GOLDEN_FRAME_YSTRIDE , - .reg_yuv_stride =0 , - .reg_ref_base =RKVDEC_REG_VP9_GOLDEN_FRAME_BASE , - }, - { - .reg_frm_size =RKVDEC_REG_VP9_FRAME_SIZE (2 ), - .reg_hor_stride =RKVDEC_VP9_HOR_VIRSTRIDE (2 ), - .reg_y_stride =RKVDEC_VP9_ALTREF_FRAME_YSTRIDE , - .reg_yuv_stride =0 , - .reg_ref_base =RKVDEC_REG_VP9_ALTREF_FRAME_BASE , - } -}; -static struct rkvdec_decoded_buffer *get_ref_buf (struct rkvdec_ctx *ctx,struct vb2_v4l2_buffer *dst,u64 timestamp) {@@ -412,18 +381,17 @@ static dma_addr_t get_mv_base_addr(struct rkvdec_decoded_buffer *buf)static void config_ref_registers (struct rkvdec_ctx *ctx,const struct rkvdec_vp9_run *run,struct rkvdec_decoded_buffer *ref_buf, -struct rkvdec_vp9_ref_reg *ref_reg) +int i) {unsigned int aligned_pitch, aligned_height, y_len, yuv_len; -struct rkvdec_dev *rkvdec = ctx->dev; +struct rkvdec_vp9_ctx *vp9_ctx = ctx->priv; +struct rkvdec_regs *regs = &vp9_ctx->regs; aligned_height =round_up (ref_buf->vp9.height,64 ); -writel_relaxed (RKVDEC_VP9_FRAMEWIDTH (ref_buf->vp9.width) | -RKVDEC_VP9_FRAMEHEIGHT (ref_buf->vp9.height), - rkvdec->regs + ref_reg->reg_frm_size); + regs->vp9.reg17_19[i].frameheight = ref_buf->vp9.height; + regs->vp9.reg17_19[i].framewidth = ref_buf->vp9.width; -writel_relaxed (vb2_dma_contig_plane_dma_addr (&ref_buf->base.vb.vb2_buf,0 ), - rkvdec->regs + ref_reg->reg_ref_base); + regs->vp9.refer_bases[i] =vb2_dma_contig_plane_dma_addr (&ref_buf->base.vb.vb2_buf,0 );if (&ref_buf->base.vb == run->base.bufs.dst)return ;@@ -432,59 +400,50 @@ static void config_ref_registers(struct rkvdec_ctx *ctx, y_len = aligned_height * aligned_pitch; yuv_len = (y_len *3 ) /2 ; -writel_relaxed (RKVDEC_HOR_Y_VIRSTRIDE (aligned_pitch /16 ) | -RKVDEC_HOR_UV_VIRSTRIDE (aligned_pitch /16 ), - rkvdec->regs + ref_reg->reg_hor_stride); -writel_relaxed (RKVDEC_VP9_REF_YSTRIDE (y_len /16 ), - rkvdec->regs + ref_reg->reg_y_stride); - -if (!ref_reg->reg_yuv_stride) -return ; + regs->vp9.reg37_39[i].y_hor_virstride = aligned_pitch /16 ; + regs->vp9.reg37_39[i].uv_hor_virstride = aligned_pitch /16 ; + regs->vp9.reg48_50[i].virstride = y_len /16 ; -writel_relaxed (RKVDEC_VP9_REF_YUVSTRIDE (yuv_len /16 ), - rkvdec->regs + ref_reg->reg_yuv_stride); +if (!i) + regs->vp9.reg51.lastref_yuv_virstride = yuv_len /16 ; }static void config_seg_registers (struct rkvdec_ctx *ctx,unsigned int segid) {struct rkvdec_vp9_ctx *vp9_ctx = ctx->priv; +struct rkvdec_regs *regs = &vp9_ctx->regs;const struct v4l2_vp9_segmentation *seg; -struct rkvdec_dev *rkvdec = ctx->dev;s16 feature_val;int feature_id; -u32 val =0 ; seg = vp9_ctx->last.valid ? &vp9_ctx->last.seg : &vp9_ctx->cur.seg; feature_id =V4L2_VP9_SEG_LVL_ALT_Q ;if (v4l2_vp9_seg_feat_enabled (seg->feature_enabled, feature_id, segid)) { feature_val = seg->feature_data[segid][feature_id]; - val |=RKVDEC_SEGID_FRAME_QP_DELTA_EN (1 ) | -RKVDEC_SEGID_FRAME_QP_DELTA (feature_val); + regs->vp9.reg20_27[segid].segid_frame_qp_delta_en =1 ; + regs->vp9.reg20_27[segid].segid_frame_qp_delta = feature_val; } feature_id =V4L2_VP9_SEG_LVL_ALT_L ;if (v4l2_vp9_seg_feat_enabled (seg->feature_enabled, feature_id, segid)) { feature_val = seg->feature_data[segid][feature_id]; - val |=RKVDEC_SEGID_FRAME_LOOPFILTER_VALUE_EN (1 ) | -RKVDEC_SEGID_FRAME_LOOPFILTER_VALUE (feature_val); + regs->vp9.reg20_27[segid].segid_frame_loopfilter_value_en =1 ; + regs->vp9.reg20_27[segid].segid_frame_loopfilter_value = feature_val; } feature_id =V4L2_VP9_SEG_LVL_REF_FRAME ;if (v4l2_vp9_seg_feat_enabled (seg->feature_enabled, feature_id, segid)) { feature_val = seg->feature_data[segid][feature_id]; - val |=RKVDEC_SEGID_REFERINFO_EN (1 ) | -RKVDEC_SEGID_REFERINFO (feature_val); + regs->vp9.reg20_27[segid].segid_referinfo_en =1 ; + regs->vp9.reg20_27[segid].segid_referinfo = feature_val; } feature_id =V4L2_VP9_SEG_LVL_SKIP ; -if (v4l2_vp9_seg_feat_enabled (seg->feature_enabled, feature_id, segid)) - val |=RKVDEC_SEGID_FRAME_SKIP_EN (1 ); - -if (!segid && - (seg->flags &V4L2_VP9_SEGMENTATION_FLAG_ABS_OR_DELTA_UPDATE )) - val |=RKVDEC_SEGID_ABS_DELTA (1 ); + regs->vp9.reg20_27[segid].segid_frame_skip_en = +v4l2_vp9_seg_feat_enabled (seg->feature_enabled, feature_id, segid); -writel_relaxed (val, rkvdec->regs +RKVDEC_VP9_SEGID_GRP (segid)); + regs->vp9.reg20_27[segid].segid_abs_delta = !segid && + (seg->flags &V4L2_VP9_SEGMENTATION_FLAG_ABS_OR_DELTA_UPDATE ); } static void update_dec_buf_info(struct rkvdec_decoded_buffer *buf,@@ -521,7 +480,8 @@ static void config_registers(struct rkvdec_ctx *ctx,struct rkvdec_decoded_buffer *ref_bufs[3 ];struct rkvdec_decoded_buffer *dst, *last, *mv_ref;struct rkvdec_vp9_ctx *vp9_ctx = ctx->priv; -u32 val, last_frame_info =0 ; +struct rkvdec_regs *regs = &vp9_ctx->regs; +u32 val;const struct v4l2_vp9_segmentation *seg;struct rkvdec_dev *rkvdec = ctx->dev;dma_addr_t addr;@@ -547,8 +507,7 @@ static void config_registers(struct rkvdec_ctx *ctx, (V4L2_VP9_FRAME_FLAG_KEY_FRAME | V4L2_VP9_FRAME_FLAG_INTRA_ONLY)); -writel_relaxed (RKVDEC_MODE (RKVDEC_MODE_VP9 ), - rkvdec->regs +RKVDEC_REG_SYSCTRL ); + regs->common.reg02.dec_mode =RKVDEC_MODE_VP9 ; bit_depth = dec_params->bit_depth; aligned_height =round_up (ctx->decoded_fmt.fmt.pix_mp.height,64 );@@ -560,17 +519,14 @@ static void config_registers(struct rkvdec_ctx *ctx, uv_len = y_len /2 ; yuv_len = y_len + uv_len; -writel_relaxed (RKVDEC_Y_HOR_VIRSTRIDE (aligned_pitch /16 ) | -RKVDEC_UV_HOR_VIRSTRIDE (aligned_pitch /16 ), - rkvdec->regs +RKVDEC_REG_PICPAR ); -writel_relaxed (RKVDEC_Y_VIRSTRIDE (y_len /16 ), - rkvdec->regs +RKVDEC_REG_Y_VIRSTRIDE ); -writel_relaxed (RKVDEC_YUV_VIRSTRIDE (yuv_len /16 ), - rkvdec->regs +RKVDEC_REG_YUV_VIRSTRIDE ); + regs->common.reg03.y_hor_virstride = aligned_pitch /16 ; + regs->common.reg03.uv_hor_virstride = aligned_pitch /16 ; + regs->common.reg08.y_virstride = y_len /16 ; + regs->common.reg09.yuv_virstride = yuv_len /16 ; stream_len =vb2_get_plane_payload (&run->base.bufs.src->vb2_buf,0 ); -writel_relaxed (RKVDEC_STRM_LEN (stream_len), - rkvdec->regs +RKVDEC_REG_STRM_LEN ); + + regs->common.stream_len = stream_len;/* * Reset count buffer, because decoder only output intra related syntax @@ -588,14 +544,13 @@ static void config_registers(struct rkvdec_ctx *ctx, vp9_ctx->cur.segmapid++;for (i =0 ; i <ARRAY_SIZE (ref_bufs); i++) -config_ref_registers (ctx, run, ref_bufs[i], &ref_regs[i]); +config_ref_registers (ctx, run, ref_bufs[i], i);for (i =0 ; i <8 ; i++)config_seg_registers (ctx, i); -writel_relaxed (RKVDEC_VP9_TX_MODE (vp9_ctx->cur.tx_mode) | -RKVDEC_VP9_FRAME_REF_MODE (dec_params->reference_mode), - rkvdec->regs +RKVDEC_VP9_CPRHEADER_CONFIG ); + regs->vp9.reg28.tx_mode = vp9_ctx->cur.tx_mode; + regs->vp9.reg28.frame_reference_mode = dec_params->reference_mode;if (!intra_only) {const struct v4l2_vp9_loop_filter *lf;@@ -609,43 +564,56 @@ static void config_registers(struct rkvdec_ctx *ctx, val =0 ;for (i =0 ; i <ARRAY_SIZE (lf->ref_deltas); i++) { delta = lf->ref_deltas[i]; - val |=RKVDEC_REF_DELTAS_LASTFRAME (i, delta); +switch (i) { +case 0 : + regs->vp9.reg32.ref_deltas_lastframe0 = delta; +break ; +case 1 : + regs->vp9.reg32.ref_deltas_lastframe1 = delta; +break ; +case 2 : + regs->vp9.reg32.ref_deltas_lastframe2 = delta; +break ; +case 3 : + regs->vp9.reg32.ref_deltas_lastframe3 = delta; +break ; + } } -writel_relaxed (val, - rkvdec->regs +RKVDEC_VP9_REF_DELTAS_LASTFRAME ); -for (i =0 ; i <ARRAY_SIZE (lf->mode_deltas); i++) { delta = lf->mode_deltas[i]; - last_frame_info |=RKVDEC_MODE_DELTAS_LASTFRAME (i, - delta); +switch (i) { +case 0 : + regs->vp9.reg33.mode_deltas_lastframe0 = delta; +break ; +case 1 : + regs->vp9.reg33.mode_deltas_lastframe1 = delta; +break ; + } } } -if (vp9_ctx->last.valid && !intra_only && - vp9_ctx->last.seg.flags &V4L2_VP9_SEGMENTATION_FLAG_ENABLED ) - last_frame_info |=RKVDEC_SEG_EN_LASTFRAME ; + regs->vp9.reg33.segmentation_enable_lstframe = + vp9_ctx->last.valid && !intra_only && + vp9_ctx->last.seg.flags &V4L2_VP9_SEGMENTATION_FLAG_ENABLED ; -if (vp9_ctx->last.valid && - vp9_ctx->last.flags &V4L2_VP9_FRAME_FLAG_SHOW_FRAME ) - last_frame_info |=RKVDEC_LAST_SHOW_FRAME ; + regs->vp9.reg33.last_show_frame = + vp9_ctx->last.valid && + vp9_ctx->last.flags &V4L2_VP9_FRAME_FLAG_SHOW_FRAME ; -if (vp9_ctx->last.valid && - vp9_ctx->last.flags & - (V4L2_VP9_FRAME_FLAG_KEY_FRAME |V4L2_VP9_FRAME_FLAG_INTRA_ONLY )) - last_frame_info |=RKVDEC_LAST_INTRA_ONLY ; + regs->vp9.reg33.last_intra_only = + vp9_ctx->last.valid && + vp9_ctx->last.flags & + (V4L2_VP9_FRAME_FLAG_KEY_FRAME |V4L2_VP9_FRAME_FLAG_INTRA_ONLY ); -if (vp9_ctx->last.valid && - last->vp9.width == dst->vp9.width && - last->vp9.height == dst->vp9.height) - last_frame_info |=RKVDEC_LAST_WIDHHEIGHT_EQCUR ; + regs->vp9.reg33.last_widthheight_eqcur = + vp9_ctx->last.valid && + last->vp9.width == dst->vp9.width && + last->vp9.height == dst->vp9.height; -writel_relaxed (last_frame_info, - rkvdec->regs +RKVDEC_VP9_INFO_LASTFRAME ); - -writel_relaxed (stream_len - dec_params->compressed_header_size - - dec_params->uncompressed_header_size, - rkvdec->regs +RKVDEC_VP9_LASTTILE_SIZE ); + regs->vp9.reg36.lasttile_size = + stream_len - dec_params->compressed_header_size - + dec_params->uncompressed_header_size;for (i =0 ; !intra_only && i <ARRAY_SIZE (ref_bufs); i++) {unsigned int refw = ref_bufs[i]->vp9.width;@@ -654,29 +622,28 @@ static void config_registers(struct rkvdec_ctx *ctx, hscale = (refw <<14 ) / dst->vp9.width; vscale = (refh <<14 ) / dst->vp9.height; -writel_relaxed (RKVDEC_VP9_REF_HOR_SCALE (hscale) | -RKVDEC_VP9_REF_VER_SCALE (vscale), - rkvdec->regs +RKVDEC_VP9_REF_SCALE (i)); + + regs->vp9.reg29_31[i].ref_hor_scale = hscale; + regs->vp9.reg29_31[i].ref_ver_scale = vscale; } addr =vb2_dma_contig_plane_dma_addr (&dst->base.vb.vb2_buf,0 ); -writel_relaxed (addr, rkvdec->regs +RKVDEC_REG_DECOUT_BASE ); + regs->common.decout_base = addr; addr =vb2_dma_contig_plane_dma_addr (&run->base.bufs.src->vb2_buf,0 ); -writel_relaxed (addr, rkvdec->regs +RKVDEC_REG_STRM_RLC_BASE ); -writel_relaxed (vp9_ctx->priv_tbl.dma + - offsetof(struct rkvdec_vp9_priv_tbl , probs), - rkvdec->regs +RKVDEC_REG_CABACTBL_PROB_BASE ); -writel_relaxed (vp9_ctx->count_tbl.dma, - rkvdec->regs +RKVDEC_REG_VP9COUNT_BASE ); - -writel_relaxed (vp9_ctx->priv_tbl.dma + - offsetof(struct rkvdec_vp9_priv_tbl , segmap) + - (RKVDEC_VP9_MAX_SEGMAP_SIZE * vp9_ctx->cur.segmapid), - rkvdec->regs +RKVDEC_REG_VP9_SEGIDCUR_BASE ); -writel_relaxed (vp9_ctx->priv_tbl.dma + - offsetof(struct rkvdec_vp9_priv_tbl , segmap) + - (RKVDEC_VP9_MAX_SEGMAP_SIZE * (!vp9_ctx->cur.segmapid)), - rkvdec->regs +RKVDEC_REG_VP9_SEGIDLAST_BASE ); + regs->common.strm_rlc_base = addr; + + regs->common.cabactbl_base = vp9_ctx->priv_tbl.dma + + offsetof(struct rkvdec_vp9_priv_tbl , probs); + + regs->vp9.count_base = vp9_ctx->count_tbl.dma; + + regs->vp9.segidlast_base = vp9_ctx->priv_tbl.dma + + offsetof(struct rkvdec_vp9_priv_tbl , segmap) + + (RKVDEC_VP9_MAX_SEGMAP_SIZE * (!vp9_ctx->cur.segmapid)); + + regs->vp9.segidcur_base = vp9_ctx->priv_tbl.dma + + offsetof(struct rkvdec_vp9_priv_tbl , segmap) + + (RKVDEC_VP9_MAX_SEGMAP_SIZE * vp9_ctx->cur.segmapid); if (!intra_only && !(dec_params->flags & V4L2_VP9_FRAME_FLAG_ERROR_RESILIENT) &&@@ -685,12 +652,14 @@ static void config_registers(struct rkvdec_ctx *ctx,else mv_ref = dst; -writel_relaxed (get_mv_base_addr (mv_ref), - rkvdec->regs +RKVDEC_VP9_REF_COLMV_BASE ); + regs->vp9.refcolmv_base =get_mv_base_addr (mv_ref);
drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c static void config_registers(struct rkvdec_ctx *ctx, · line 662
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c +6
-3-writel_relaxed (ctx->decoded_fmt.fmt.pix_mp.width | - (ctx->decoded_fmt.fmt.pix_mp.height <<16 ), - rkvdec->regs +RKVDEC_REG_PERFORMANCE_CYCLE ); + regs->vp9.performance_cycle = ctx->decoded_fmt.fmt.pix_mp.width | + (ctx->decoded_fmt.fmt.pix_mp.height <<16 ); + + regs->vp9.reg44.strmd_error_e =0xe ; + +rkvdec_memcpy_toio (rkvdec->regs, regs,MIN (sizeof (*regs), rkvdec->variant->num_regs));
This is missing the 4 * on num_regs.
Btw, please add me to cc for next version :-)
Regards,
Jonas
Quoted 52 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vp9.c +0
-2} static int validate_dec_params(struct rkvdec_ctx *ctx,@@ -823,8 +792,6 @@ static int rkvdec_vp9_run(struct rkvdec_ctx *ctx)writel (1 , rkvdec->regs +RKVDEC_REG_PREF_LUMA_CACHE_COMMAND );writel (1 , rkvdec->regs +RKVDEC_REG_PREF_CHR_CACHE_COMMAND ); -writel (0xe , rkvdec->regs +RKVDEC_REG_STRMD_ERR_EN ); -if (rkvdec->variant->quirks &RKVDEC_QUIRK_DISABLE_QOS )rkvdec_quirks_disable_qos (ctx);drivers/media/platform/rockchip/rkvdec/rkvdec.c +9
-1@@ -914,6 +914,15 @@ void rkvdec_quirks_disable_qos(struct rkvdec_ctx *ctx)writel (reg, rkvdec->regs +RKVDEC_REG_QOS_CTRL ); } +void rkvdec_memcpy_toio (void __iomem *dst,void *src,size_t len) +{ +#ifdef CONFIG_ARM64 +__iowrite32_copy (dst, src, len /4 ); +#else +memcpy_toio (dst, src, len); +#endif +} +static void rkvdec_device_run (void *priv) {struct rkvdec_ctx *ctx = priv;@@ -1227,7 +1236,6 @@ static void rkvdec_watchdog_func(struct work_struct *work)if (ctx) {dev_err (rkvdec->dev,"Frame processing timed out!\n" );writel (RKVDEC_IRQ_DIS , rkvdec->regs +RKVDEC_REG_INTERRUPT ); -writel (0 , rkvdec->regs +RKVDEC_REG_SYSCTRL );rkvdec_job_finish (ctx,VB2_BUF_STATE_ERROR ); } }drivers/media/platform/rockchip/rkvdec/rkvdec.h +1
-0@@ -151,6 +151,7 @@ struct rkvdec_aux_buf {void rkvdec_run_preamble (struct rkvdec_ctx *ctx,struct rkvdec_run *run);void rkvdec_run_postamble (struct rkvdec_ctx *ctx,struct rkvdec_run *run); +void rkvdec_memcpy_toio (void __iomem *dst,void *src,size_t len);void rkvdec_quirks_disable_qos (struct rkvdec_ctx *ctx);
Detlev Casanova
maintainerPATCH v6 5/17 media: rkvdec: Move cabac tables to their own source file
In reply to Detlev CasanovaThis is in preparation to add support for new variants that will use the same tables.
---
.../media/platform/rockchip/rkvdec/Makefile | 7 +-
.../{rkvdec-hevc-data.c => rkvdec-cabac.c} | 506 +++++++++++++++++-
.../platform/rockchip/rkvdec/rkvdec-h264.c | 501 +----------------
.../platform/rockchip/rkvdec/rkvdec-hevc.c | 6 +-
4 files changed, 514 insertions(+), 506 deletions(-)
rename drivers/media/platform/rockchip/rkvdec/{rkvdec-hevc-data.c => rkvdec-cabac.c} (86%)drivers/media/platform/rockchip/rkvdec/Makefile +6 -1
@@ -1,3 +1,8 @@ obj-$(CONFIG_VIDEO_ROCKCHIP_VDEC) += rockchip-vdec.o -rockchip-vdec-y += rkvdec.o rkvdec-h264.o rkvdec-hevc.o rkvdec-vp9.o +rockchip-vdec-y += \ + rkvdec.o \ + rkvdec-cabac.o \ + rkvdec-h264.o \ + rkvdec-hevc.o \ + rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-cabac.c renamed from drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-data.c +502 -4
521 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +2 -499
513 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c +4 -2
@@ -16,7 +16,6 @@#include "rkvdec.h" #include "rkvdec-regs.h" -#include "rkvdec-hevc-data.c" /* Size in u8/u32 units. */ #define RKV_SCALING_LIST_SIZE 1360
@@ -25,6 +24,9 @@#define RKV_RPS_SIZE (32 / 4)#define RKV_RPS_LEN 600 +#define RKV_HEVC_CABAC_TABLE_SIZE 27456 +extern const u8 rkvdec_hevc_cabac_table[RKV_HEVC_CABAC_TABLE_SIZE ]; +struct rkvdec_sps_pps_packet {u32 info[RKV_PPS_SIZE ]; };
@@ -110,7 +112,7 @@ struct rkvdec_ps_field {/* Data structure describing auxiliary buffer format. */ struct rkvdec_hevc_priv_tbl { -u8 cabac_table[RKV_CABAC_TABLE_SIZE ]; +u8 cabac_table[RKV_HEVC_CABAC_TABLE_SIZE ];u8 scaling_list[RKV_SCALING_LIST_SIZE ];struct rkvdec_sps_pps_packet param_set[RKV_PPS_LEN ];struct rkvdec_rps_packet rps[RKV_RPS_LEN ];
Signature · 1 line
2.52.0
Detlev Casanova
maintainerPATCH v6 6/17 media: rkvdec: Use structs to represent the HW RPS
In reply to Detlev CasanovaThis is in preparation to add support for other variants of the decoder.
Moving to struct representation is mainly to prepare for multicore support that is present in e.g. rk3588.
--- .../platform/rockchip/rkvdec/rkvdec-h264.c | 93 +++++++++++++++++-- 1 file changed, 84 insertions(+), 9 deletions(-)
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +84 -9
@@ -19,7 +19,6 @@ extern const s8 rkvdec_h264_cabac_table[4][464][2];/* Size with u32 units. */ #define RKV_CABAC_INIT_BUFFER_SIZE (3680 + 128) -#define RKV_RPS_SIZE ((128 + 128) / 4)#define RKV_ERROR_INFO_SIZE (256 * 144 * 4)#define RKVDEC_NUM_REFLIST 3
@@ -34,6 +33,40 @@ struct rkvdec_sps_pps_packet {u32 info[8 ]; }; +struct rkvdec_rps_entry { +u32 dpb_info0:5 ; +u32 bottom_flag0:1 ; +u32 view_index_off0:1 ; +u32 dpb_info1:5 ; +u32 bottom_flag1:1 ; +u32 view_index_off1:1 ; +u32 dpb_info2:5 ; +u32 bottom_flag2:1 ; +u32 view_index_off2:1 ; +u32 dpb_info3:5 ; +u32 bottom_flag3:1 ; +u32 view_index_off3:1 ; +u32 dpb_info4:5 ; +u32 bottom_flag4:1 ; +u32 view_index_off4:1 ; +u32 dpb_info5:5 ; +u32 bottom_flag5:1 ; +u32 view_index_off5:1 ; +u32 dpb_info6:5 ; +u32 bottom_flag6:1 ; +u32 view_index_off6:1 ; +u32 dpb_info7:5 ; +u32 bottom_flag7:1 ; +u32 view_index_off7:1 ; +} __packed; + +struct rkvdec_rps { +u16 frame_num[16 ]; +u32 reserved0; +struct rkvdec_rps_entry entries[12 ]; +u32 reserved1[66 ]; +} __packed; +struct rkvdec_ps_field {u16 offset;u8 len;
@@ -94,7 +127,7 @@ struct rkvdec_ps_field {struct rkvdec_h264_priv_tbl {s8 cabac_table[4 ][464 ][2 ];struct rkvdec_h264_scaling_list scaling_list; -u32 rps[RKV_RPS_SIZE ]; +struct rkvdec_rps rps;struct rkvdec_sps_pps_packet param_set[256 ];u8 err_info[RKV_ERROR_INFO_SIZE ]; };
@@ -260,6 +293,51 @@ static void lookup_ref_buf_idx(struct rkvdec_ctx *ctx, } } +static void set_dpb_info (struct rkvdec_rps_entry *entries, +u8 reflist, +u8 refnum, +u8 info, +bool bottom) +{ +struct rkvdec_rps_entry *entry = &entries[(reflist *4 ) + refnum /8 ]; +u8 idx = refnum %8 ; + +switch (idx) { +case 0 : + entry->dpb_info0 = info; + entry->bottom_flag0 = bottom; +break ; +case 1 : + entry->dpb_info1 = info; + entry->bottom_flag1 = bottom; +break ; +case 2 : + entry->dpb_info2 = info; + entry->bottom_flag2 = bottom; +break ; +case 3 : + entry->dpb_info3 = info; + entry->bottom_flag3 = bottom; +break ; +case 4 : + entry->dpb_info4 = info; + entry->bottom_flag4 = bottom; +break ; +case 5 : + entry->dpb_info5 = info; + entry->bottom_flag5 = bottom; +break ; +case 6 : + entry->dpb_info6 = info; + entry->bottom_flag6 = bottom; +break ; +case 7 : + entry->dpb_info7 = info; + entry->bottom_flag7 = bottom; +break ; + } +} +static void assemble_hw_rps (struct rkvdec_ctx *ctx,struct v4l2_h264_reflist_builder *builder,struct rkvdec_h264_run *run)
@@ -269,11 +347,10 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx,struct rkvdec_h264_ctx *h264_ctx = ctx->priv;struct rkvdec_h264_priv_tbl *priv_tbl = h264_ctx->priv_tbl.cpu; -u32 *hw_rps = priv_tbl->rps; +struct rkvdec_rps *hw_rps = &priv_tbl->rps;u32 i, j; -u16 *p = (u16 *)hw_rps; -memset (hw_rps,0 ,sizeof (priv_tbl->rps)); +memset (hw_rps,0 ,sizeof (*hw_rps));/* * Assign an invalid pic_num if DPB entry at that position is inactive.
@@ -285,7 +362,7 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx,if (!(dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE ))continue ; - p[i] = builder->refs[i].frame_num; + hw_rps->frame_num[i] = builder->refs[i].frame_num; }for (j =0 ; j <RKVDEC_NUM_REFLIST ; j++) {
@@ -312,9 +389,7 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx, dpb_valid = run->ref_buf[ref->index] !=NULL ; bottom = ref->fields ==V4L2_H264_BOTTOM_FIELD_REF ; -set_ps_field (hw_rps,DPB_INFO (i, j), - ref->index | dpb_valid <<4 ); -set_ps_field (hw_rps,BOTTOM_FLAG (i, j), bottom); +set_dpb_info (hw_rps->entries, j, i, ref->index | (dpb_valid <<4 ), bottom); } } }
Signature · 1 line
2.52.0
Detlev Casanova
maintainerPATCH v6 7/17 media: rkvdec: Move h264 functions to common file
In reply to Detlev CasanovaThis is a preparation commit to add support for new variants of the decoder.
The functions will later be shared with vdpu381 (rk3588) and vdpu383 (rk3576).
--- .../media/platform/rockchip/rkvdec/Makefile | 1 + .../rockchip/rkvdec/rkvdec-h264-common.c | 258 +++++++++++++++ .../rockchip/rkvdec/rkvdec-h264-common.h | 87 +++++ .../platform/rockchip/rkvdec/rkvdec-h264.c | 310 +----------------- 4 files changed, 350 insertions(+), 306 deletions(-) create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.c create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.h
drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
@@ -4,5 +4,6 @@ rockchip-vdec-y += \ rkvdec.o \ rkvdec-cabac.o \ rkvdec-h264.o \ + rkvdec-h264-common.o \ rkvdec-hevc.o \ rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.c new file +258 -0
258 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.h new file +87 -0
87 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-h264.c +4 -306
369 lines not on this page · raw message
Signature · 1 line
2.52.0
Detlev Casanova
maintainerPATCH v6 8/17 media: rkvdec: Move hevc functions to common file
In reply to Detlev CasanovaThis is a preparation commit to add support for new variants of the decoder.
The functions will later be shared with vdpu381 (rk3588) and vdpu383 (rk3576).
--- .../media/platform/rockchip/rkvdec/Makefile | 1 + .../rockchip/rkvdec/rkvdec-hevc-common.c | 182 ++++++++++++++++ .../rockchip/rkvdec/rkvdec-hevc-common.h | 48 +++++ .../platform/rockchip/rkvdec/rkvdec-hevc.c | 194 +----------------- 4 files changed, 238 insertions(+), 187 deletions(-) create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h
drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
@@ -6,4 +6,5 @@ rockchip-vdec-y += \ rkvdec-h264.o \ rkvdec-h264-common.o \ rkvdec-hevc.o \ + rkvdec-hevc-common.o \ rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c new file +182 -0
182 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h new file +48 -0
48 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c +7 -187
254 lines not on this page · raw message
Signature · 1 line
2.52.0
Detlev Casanova
maintainerPATCH v6 9/17 media: rkvdec: Add variant specific coded formats list
In reply to Detlev CasanovaPrepare for adding new variants of the decoder and support specific formats and format ops per variant.
--- .../media/platform/rockchip/rkvdec/rkvdec.c | 35 ++++++++++++------- .../media/platform/rockchip/rkvdec/rkvdec.h | 2 ++ 2 files changed, 24 insertions(+), 13 deletions(-)
drivers/media/platform/rockchip/rkvdec/rkvdec.c +22 -13
@@ -373,15 +373,16 @@ static bool rkvdec_is_capable(struct rkvdec_ctx *ctx, unsigned int capability)static const struct rkvdec_coded_fmt_desc *rkvdec_enum_coded_fmt_desc (struct rkvdec_ctx *ctx,int index) { +const struct rkvdec_variant *variant = ctx->dev->variant;int fmt_idx =-1 ;unsigned int i; -for (i =0 ; i <ARRAY_SIZE (rkvdec_coded_fmts); i++) { -if (!rkvdec_is_capable (ctx, rkvdec_coded_fmts[i].capability)) +for (i =0 ; i < variant->num_coded_fmts; i++) { +if (!rkvdec_is_capable (ctx, variant->coded_fmts[i].capability))continue ; fmt_idx++;if (index == fmt_idx) -return &rkvdec_coded_fmts[i]; +return &variant->coded_fmts[i]; }return NULL ;
@@ -390,12 +391,13 @@ rkvdec_enum_coded_fmt_desc(struct rkvdec_ctx *ctx, int index)static const struct rkvdec_coded_fmt_desc *rkvdec_find_coded_fmt_desc (struct rkvdec_ctx *ctx,u32 fourcc) { +const struct rkvdec_variant *variant = ctx->dev->variant;unsigned int i; -for (i =0 ; i <ARRAY_SIZE (rkvdec_coded_fmts); i++) { -if (rkvdec_is_capable (ctx, rkvdec_coded_fmts[i].capability) && - rkvdec_coded_fmts[i].fourcc == fourcc) -return &rkvdec_coded_fmts[i]; +for (i =0 ; i < variant->num_coded_fmts; i++) { +if (rkvdec_is_capable (ctx, variant->coded_fmts[i].capability) && + variant->coded_fmts[i].fourcc == fourcc) +return &variant->coded_fmts[i]; }return NULL ;
@@ -1014,18 +1016,19 @@ static int rkvdec_add_ctrls(struct rkvdec_ctx *ctx,static int rkvdec_init_ctrls (struct rkvdec_ctx *ctx) { +const struct rkvdec_variant *variant = ctx->dev->variant;unsigned int i, nctrls =0 ;int ret; -for (i =0 ; i <ARRAY_SIZE (rkvdec_coded_fmts); i++) -if (rkvdec_is_capable (ctx, rkvdec_coded_fmts[i].capability)) - nctrls += rkvdec_coded_fmts[i].ctrls->num_ctrls; +for (i =0 ; i < variant->num_coded_fmts; i++) +if (rkvdec_is_capable (ctx, variant->coded_fmts[i].capability)) + nctrls += variant->coded_fmts[i].ctrls->num_ctrls;v4l2_ctrl_handler_init (&ctx->ctrl_hdl, nctrls); -for (i =0 ; i <ARRAY_SIZE (rkvdec_coded_fmts); i++) { -if (rkvdec_is_capable (ctx, rkvdec_coded_fmts[i].capability)) { - ret =rkvdec_add_ctrls (ctx, rkvdec_coded_fmts[i].ctrls); +for (i =0 ; i < variant->num_coded_fmts; i++) { +if (rkvdec_is_capable (ctx, variant->coded_fmts[i].capability)) { + ret =rkvdec_add_ctrls (ctx, variant->coded_fmts[i].ctrls);if (ret) goto err_free_handler; }
@@ -1242,11 +1245,15 @@ static void rkvdec_watchdog_func(struct work_struct *work)static const struct rkvdec_variant rk3288_rkvdec_variant = { .num_regs =68 , + .coded_fmts = rkvdec_coded_fmts, + .num_coded_fmts =ARRAY_SIZE (rkvdec_coded_fmts), .capabilities =RKVDEC_CAPABILITY_HEVC , };static const struct rkvdec_variant rk3328_rkvdec_variant = { .num_regs =109 , + .coded_fmts = rkvdec_coded_fmts, + .num_coded_fmts =ARRAY_SIZE (rkvdec_coded_fmts), .capabilities =RKVDEC_CAPABILITY_HEVC |RKVDEC_CAPABILITY_H264 |RKVDEC_CAPABILITY_VP9 ,
@@ -1255,6 +1262,8 @@ static const struct rkvdec_variant rk3328_rkvdec_variant = {static const struct rkvdec_variant rk3399_rkvdec_variant = { .num_regs =78 , + .coded_fmts = rkvdec_coded_fmts, + .num_coded_fmts =ARRAY_SIZE (rkvdec_coded_fmts), .capabilities =RKVDEC_CAPABILITY_HEVC |RKVDEC_CAPABILITY_H264 |RKVDEC_CAPABILITY_VP9 ,
drivers/media/platform/rockchip/rkvdec/rkvdec.h +2 -0
@@ -71,6 +71,8 @@ vb2_to_rkvdec_decoded_buf(struct vb2_buffer *buf)struct rkvdec_variant {unsigned int num_regs; +const struct rkvdec_coded_fmt_desc *coded_fmts; +size_t num_coded_fmts;unsigned int capabilities;unsigned int quirks; };
Signature · 1 line
2.52.0
Re: [PATCH v6 09/17] media: rkvdec: Add variant specific coded formats list
Hi Detlev,
Quoted 79 lines · Detlev Casanova
Prepare for adding new variants of the decoder and support specific formats and format ops per variant.
Signed-off-by Detlev Casanova <[email protected]>--- .../media/platform/rockchip/rkvdec/rkvdec.c | 35 ++++++++++++------- .../media/platform/rockchip/rkvdec/rkvdec.h | 2 ++ 2 files changed, 24 insertions(+), 13 deletions(-)drivers/media/platform/rockchip/rkvdec/rkvdec.c +16
-13@@ -373,15 +373,16 @@ static bool rkvdec_is_capable(struct rkvdec_ctx *ctx, unsigned int capability)static const struct rkvdec_coded_fmt_desc *rkvdec_enum_coded_fmt_desc (struct rkvdec_ctx *ctx,int index) { +const struct rkvdec_variant *variant = ctx->dev->variant;int fmt_idx =-1 ;unsigned int i; -for (i =0 ; i <ARRAY_SIZE (rkvdec_coded_fmts); i++) { -if (!rkvdec_is_capable (ctx, rkvdec_coded_fmts[i].capability)) +for (i =0 ; i < variant->num_coded_fmts; i++) { +if (!rkvdec_is_capable (ctx, variant->coded_fmts[i].capability))continue ; fmt_idx++;if (index == fmt_idx) -return &rkvdec_coded_fmts[i]; +return &variant->coded_fmts[i]; }return NULL ;@@ -390,12 +391,13 @@ rkvdec_enum_coded_fmt_desc(struct rkvdec_ctx *ctx, int index)static const struct rkvdec_coded_fmt_desc *rkvdec_find_coded_fmt_desc (struct rkvdec_ctx *ctx,u32 fourcc) { +const struct rkvdec_variant *variant = ctx->dev->variant;unsigned int i; -for (i =0 ; i <ARRAY_SIZE (rkvdec_coded_fmts); i++) { -if (rkvdec_is_capable (ctx, rkvdec_coded_fmts[i].capability) && - rkvdec_coded_fmts[i].fourcc == fourcc) -return &rkvdec_coded_fmts[i]; +for (i =0 ; i < variant->num_coded_fmts; i++) { +if (rkvdec_is_capable (ctx, variant->coded_fmts[i].capability) && + variant->coded_fmts[i].fourcc == fourcc) +return &variant->coded_fmts[i]; }return NULL ;@@ -1014,18 +1016,19 @@ static int rkvdec_add_ctrls(struct rkvdec_ctx *ctx,static int rkvdec_init_ctrls (struct rkvdec_ctx *ctx) { +const struct rkvdec_variant *variant = ctx->dev->variant;unsigned int i, nctrls =0 ;int ret; -for (i =0 ; i <ARRAY_SIZE (rkvdec_coded_fmts); i++) -if (rkvdec_is_capable (ctx, rkvdec_coded_fmts[i].capability)) - nctrls += rkvdec_coded_fmts[i].ctrls->num_ctrls; +for (i =0 ; i < variant->num_coded_fmts; i++) +if (rkvdec_is_capable (ctx, variant->coded_fmts[i].capability)) + nctrls += variant->coded_fmts[i].ctrls->num_ctrls;v4l2_ctrl_handler_init (&ctx->ctrl_hdl, nctrls); -for (i =0 ; i <ARRAY_SIZE (rkvdec_coded_fmts); i++) { -if (rkvdec_is_capable (ctx, rkvdec_coded_fmts[i].capability)) { - ret =rkvdec_add_ctrls (ctx, rkvdec_coded_fmts[i].ctrls); +for (i =0 ; i < variant->num_coded_fmts; i++) { +if (rkvdec_is_capable (ctx, variant->coded_fmts[i].capability)) { + ret =rkvdec_add_ctrls (ctx, variant->coded_fmts[i].ctrls);if (ret) goto err_free_handler; }
drivers/media/platform/rockchip/rkvdec/rkvdec.c static void rkvdec_watchdog_func(struct work_struct *work) · line 1250
Quoted 6 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +2
-0@@ -1242,11 +1245,15 @@ static void rkvdec_watchdog_func(struct work_struct *work)static const struct rkvdec_variant rk3288_rkvdec_variant = { .num_regs =68 , + .coded_fmts = rkvdec_coded_fmts, + .num_coded_fmts =ARRAY_SIZE (rkvdec_coded_fmts), .capabilities =RKVDEC_CAPABILITY_HEVC ,
Looks like we could drop the capabilities flags handling now that we use a per variant coded_fmts ?
Maybe a rk3288_coded_fmts should be added and used here, or in a cleanup patch that drops the capabilities flag handling.
Regards,
Jonas
Quoted 31 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +4
-0};static const struct rkvdec_variant rk3328_rkvdec_variant = { .num_regs =109 , + .coded_fmts = rkvdec_coded_fmts, + .num_coded_fmts =ARRAY_SIZE (rkvdec_coded_fmts), .capabilities =RKVDEC_CAPABILITY_HEVC |RKVDEC_CAPABILITY_H264 |RKVDEC_CAPABILITY_VP9 ,@@ -1255,6 +1262,8 @@ static const struct rkvdec_variant rk3328_rkvdec_variant = {static const struct rkvdec_variant rk3399_rkvdec_variant = { .num_regs =78 , + .coded_fmts = rkvdec_coded_fmts, + .num_coded_fmts =ARRAY_SIZE (rkvdec_coded_fmts), .capabilities =RKVDEC_CAPABILITY_HEVC |RKVDEC_CAPABILITY_H264 |RKVDEC_CAPABILITY_VP9 ,drivers/media/platform/rockchip/rkvdec/rkvdec.h +2
-0@@ -71,6 +71,8 @@ vb2_to_rkvdec_decoded_buf(struct vb2_buffer *buf)struct rkvdec_variant {unsigned int num_regs; +const struct rkvdec_coded_fmt_desc *coded_fmts; +size_t num_coded_fmts;unsigned int capabilities;unsigned int quirks; };
Detlev Casanova
maintainerPATCH v6 10/17 media: rkvdec: Add RCB and SRAM support
In reply to Detlev CasanovaThe RCB (Rows and Cols Buffers) are a set of buffers used by other variations of the decoder to store temporary data.
Those variation come with a dedicated SRAM area used to store those buffers for better performances.
The buffer sizes are either the width or height of the frame being decoded multiplied by a documented factor and can be stored either in SRAM or RAM.
A fallback to RAM is provided if the SRAM is full (e.g.: multiple streams are being decoded at the same time).
To manage the different kind of allocation, an enum is added to the rkvdec_aux_buf struct to specify how the buffer was allocated, and so, how to free it.
This commit is in preparation of other variants support.
--- .../media/platform/rockchip/rkvdec/Makefile | 1 + .../platform/rockchip/rkvdec/rkvdec-rcb.c | 178 ++++++++++++++++++ .../platform/rockchip/rkvdec/rkvdec-rcb.h | 29 +++ .../media/platform/rockchip/rkvdec/rkvdec.c | 27 ++- .../media/platform/rockchip/rkvdec/rkvdec.h | 13 ++ 5 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.h
drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
@@ -7,4 +7,5 @@ rockchip-vdec-y += \ rkvdec-h264-common.o \ rkvdec-hevc.o \ rkvdec-hevc-common.o \ + rkvdec-rcb.o \ rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c new file +178 -0
178 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Rockchip video decoder Rows and Cols Buffers manager +* +* Copyright (C) 2025 Collabora, Ltd. +* Detlev Casanova <[email protected]> +*/ + +#include <linux/types.h> + +struct rkvdec_ctx ; + +enum rcb_axis { +PIC_WIDTH =0 , +PIC_HEIGHT =1 +}; + +struct rcb_size_info { +u8 multiplier; +enum rcb_axis axis; +}; + +int rkvdec_allocate_rcb (struct rkvdec_ctx *ctx, +const struct rcb_size_info *size_info, +size_t rcb_count); +dma_addr_t rkvdec_rcb_buf_dma_addr (struct rkvdec_ctx *ctx,int id); +size_t rkvdec_rcb_buf_size (struct rkvdec_ctx *ctx,int id); +int rkvdec_rcb_buf_count (struct rkvdec_ctx *ctx); +void rkvdec_free_rcb (struct rkvdec_ctx *ctx);
drivers/media/platform/rockchip/rkvdec/rkvdec.c +25 -2
@@ -10,6 +10,7 @@*/ #include <linux/clk.h> +#include <linux/genalloc.h> #include <linux/interrupt.h> #include <linux/iommu.h> #include <linux/module.h>
@@ -28,6 +29,7 @@#include "rkvdec.h" #include "rkvdec-regs.h" +#include "rkvdec-rcb.h" static bool rkvdec_image_fmt_match (enum rkvdec_image_fmt fmt1,enum rkvdec_image_fmt fmt2)
@@ -771,6 +773,7 @@ static int rkvdec_start_streaming(struct vb2_queue *q, unsigned int count) {struct rkvdec_ctx *ctx =vb2_get_drv_priv (q);const struct rkvdec_coded_fmt_desc *desc; +const struct rkvdec_variant *variant = ctx->dev->variant;int ret;if (V4L2_TYPE_IS_CAPTURE (q->type))
@@ -780,13 +783,22 @@ static int rkvdec_start_streaming(struct vb2_queue *q, unsigned int count)if (WARN_ON (!desc))return -EINVAL ; + ret =rkvdec_allocate_rcb (ctx, variant->rcb_sizes, variant->num_rcb_sizes); +if (ret) +return ret; +if (desc->ops->start) { ret = desc->ops->start (ctx);if (ret) -return ret; + goto err_ops_start; }return 0 ; + +err_ops_start: +rkvdec_free_rcb (ctx); + +return ret; }static void rkvdec_queue_cleanup (struct vb2_queue *vq,u32 state)
@@ -822,6 +834,8 @@ static void rkvdec_stop_streaming(struct vb2_queue *q)if (desc->ops->stop) desc->ops->stop (ctx); + +rkvdec_free_rcb (ctx); }rkvdec_queue_cleanup (q,VB2_BUF_STATE_ERROR );
@@ -1348,6 +1362,10 @@ static int rkvdec_probe(struct platform_device *pdev)return ret; } + rkvdec->sram_pool =of_gen_pool_get (pdev->dev.of_node,"sram" ,0 ); +if (!rkvdec->sram_pool && rkvdec->variant->num_rcb_sizes >0 ) +dev_info (&pdev->dev,"No sram node, RCB will be stored in RAM\n" ); +pm_runtime_set_autosuspend_delay (&pdev->dev,100 );pm_runtime_use_autosuspend (&pdev->dev);pm_runtime_enable (&pdev->dev);
@@ -1356,7 +1374,8 @@ static int rkvdec_probe(struct platform_device *pdev)if (ret) goto err_disable_runtime_pm; -if (iommu_get_domain_for_dev (&pdev->dev)) { + rkvdec->iommu_domain =iommu_get_domain_for_dev (&pdev->dev); +if (rkvdec->iommu_domain) { rkvdec->empty_domain =iommu_paging_domain_alloc (rkvdec->dev);if (IS_ERR (rkvdec->empty_domain)) {
@@ -1370,6 +1389,10 @@ static int rkvdec_probe(struct platform_device *pdev) err_disable_runtime_pm:pm_runtime_dont_use_autosuspend (&pdev->dev);pm_runtime_disable (&pdev->dev); + +if (rkvdec->sram_pool) +gen_pool_destroy (rkvdec->sram_pool); +return ret; }
drivers/media/platform/rockchip/rkvdec/rkvdec.h +13 -0
@@ -19,6 +19,7 @@#include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> +#include <media/v4l2-mem2mem.h> #include <media/videobuf2-core.h> #include <media/videobuf2-dma-contig.h>
@@ -29,6 +30,7 @@#define RKVDEC_QUIRK_DISABLE_QOS BIT(0)struct rkvdec_ctx ; +struct rkvdec_rcb_config ;struct rkvdec_ctrl_desc {struct v4l2_ctrl_config cfg;
@@ -73,6 +75,8 @@ struct rkvdec_variant {unsigned int num_regs;const struct rkvdec_coded_fmt_desc *coded_fmts;size_t num_coded_fmts; +const struct rcb_size_info *rcb_sizes; +size_t num_rcb_sizes;unsigned int capabilities;unsigned int quirks; };
@@ -125,6 +129,8 @@ struct rkvdec_dev {void __iomem *regs;struct mutex vdev_lock;/* serializes ioctls */ struct delayed_work watchdog_work; +struct gen_pool *sram_pool; +struct iommu_domain *iommu_domain;struct iommu_domain *empty_domain;const struct rkvdec_variant *variant; };
@@ -137,6 +143,7 @@ struct rkvdec_ctx {struct v4l2_ctrl_handler ctrl_hdl;struct rkvdec_dev *dev;enum rkvdec_image_fmt image_fmt; +struct rkvdec_rcb_config *rcb_config;void *priv; };
@@ -145,10 +152,16 @@ static inline struct rkvdec_ctx *file_to_rkvdec_ctx(struct file *filp) return container_of(file_to_v4l2_fh(filp), struct rkvdec_ctx, fh); } +enum rkvdec_alloc_type { +RKVDEC_ALLOC_DMA =0 , +RKVDEC_ALLOC_SRAM =1 , +}; +struct rkvdec_aux_buf {void *cpu;dma_addr_t dma;size_t size; +enum rkvdec_alloc_type type; };void rkvdec_run_preamble (struct rkvdec_ctx *ctx,struct rkvdec_run *run);
Signature · 1 line
2.52.0
Re: [PATCH v6 10/17] media: rkvdec: Add RCB and SRAM support
Hi Detlev,
Quoted 155 lines · Detlev Casanova
The RCB (Rows and Cols Buffers) are a set of buffers used by other variations of the decoder to store temporary data.
Those variation come with a dedicated SRAM area used to store those buffers for better performances.
The buffer sizes are either the width or height of the frame being decoded multiplied by a documented factor and can be stored either in SRAM or RAM.
A fallback to RAM is provided if the SRAM is full (e.g.: multiple streams are being decoded at the same time).To manage the different kind of allocation, an enum is added to the
rkvdec_aux_bufstruct to specify how the buffer was allocated, and so, how to free it.This commit is in preparation of other variants support.
Signed-off-by Detlev Casanova <[email protected]>--- .../media/platform/rockchip/rkvdec/Makefile | 1 + .../platform/rockchip/rkvdec/rkvdec-rcb.c | 178 ++++++++++++++++++ .../platform/rockchip/rkvdec/rkvdec-rcb.h | 29 +++ .../media/platform/rockchip/rkvdec/rkvdec.c | 27 ++- .../media/platform/rockchip/rkvdec/rkvdec.h | 13 ++ 5 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.hdrivers/media/platform/rockchip/rkvdec/Makefile +1
-0@@ -7,4 +7,5 @@ rockchip-vdec-y += \ rkvdec-h264-common.o \ rkvdec-hevc.o \ rkvdec-hevc-common.o \ + rkvdec-rcb.o \ rkvdec-vp9.odrivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c new file +109
-0@@ -0,0 +1,178 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Rockchip video decoder Rows and Cols Buffers manager +* +* Copyright (C) 2025 Collabora, Ltd. +* Detlev Casanova <[email protected]> +*/ + +#include "rkvdec.h" +#include "rkvdec-rcb.h" + +#include <linux/types.h> +#include <linux/iommu.h> +#include <linux/genalloc.h> + +struct rkvdec_rcb_config { +struct rkvdec_aux_buf *rcb_bufs; +size_t rcb_count; +}; + +static size_t rkvdec_rcb_size (const struct rcb_size_info *size_info, +unsigned int width,unsigned int height) +{ +return size_info->multiplier * (size_info->axis ==PIC_HEIGHT ? height : width); +} + +dma_addr_t rkvdec_rcb_buf_dma_addr (struct rkvdec_ctx *ctx,int id) +{ +return ctx->rcb_config->rcb_bufs[id].dma; +} + +size_t rkvdec_rcb_buf_size (struct rkvdec_ctx *ctx,int id) +{ +return ctx->rcb_config->rcb_bufs[id].size; +} + +int rkvdec_rcb_buf_count (struct rkvdec_ctx *ctx) +{ +return ctx->rcb_config->rcb_count; +} + +void rkvdec_free_rcb (struct rkvdec_ctx *ctx) +{ +struct rkvdec_dev *dev = ctx->dev; +struct rkvdec_rcb_config *cfg = ctx->rcb_config; +unsigned long virt_addr; +int i; + +if (!cfg) +return ; + +for (i =0 ; i < cfg->rcb_count; i++) { +size_t rcb_size = cfg->rcb_bufs[i].size; + +if (!cfg->rcb_bufs[i].cpu) +continue ; + +switch (cfg->rcb_bufs[i].type) { +case RKVDEC_ALLOC_SRAM : + virt_addr = (unsigned long )cfg->rcb_bufs[i].cpu; + +if (dev->iommu_domain) +iommu_unmap (dev->iommu_domain, virt_addr, rcb_size); +gen_pool_free (dev->sram_pool, virt_addr, rcb_size); +break ; +case RKVDEC_ALLOC_DMA : +dma_free_coherent (dev->dev, + rcb_size, + cfg->rcb_bufs[i].cpu, + cfg->rcb_bufs[i].dma); +break ; + } + } + +if (cfg->rcb_bufs) +devm_kfree (dev->dev, cfg->rcb_bufs); + +devm_kfree (dev->dev, cfg); +} + +int rkvdec_allocate_rcb (struct rkvdec_ctx *ctx, +const struct rcb_size_info *size_info, +size_t rcb_count) +{ +int ret, i; +u32 width, height; +struct rkvdec_dev *rkvdec = ctx->dev; +struct rkvdec_rcb_config *cfg; + +if (!size_info || !rcb_count) { + ctx->rcb_config =NULL ; +return 0 ; + } + + ctx->rcb_config =devm_kzalloc (rkvdec->dev,sizeof (*ctx->rcb_config),GFP_KERNEL ); +if (!ctx->rcb_config) +return -ENOMEM ; + + cfg = ctx->rcb_config; + + cfg->rcb_bufs =devm_kzalloc (rkvdec->dev,sizeof (*cfg->rcb_bufs) * rcb_count,GFP_KERNEL ); +if (!cfg->rcb_bufs) { + ret = -ENOMEM ; + goto err_alloc; + } + + width = ctx->decoded_fmt.fmt.pix_mp.width; + height = ctx->decoded_fmt.fmt.pix_mp.height; +
drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c line 119
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c new file +10
-0+for (i =0 ; i < rcb_count; i++) { +void *cpu =NULL ; +dma_addr_t dma; +size_t rcb_size =rkvdec_rcb_size (&size_info[i], width, height); +enum rkvdec_alloc_type alloc_type =RKVDEC_ALLOC_SRAM ; + +/* Try allocating an SRAM buffer */ +if (ctx->dev->sram_pool) { +if (rkvdec->iommu_domain) + rcb_size =ALIGN (rcb_size,0x1000 );
Maybe SZ_4K instead of 0x1000 ?
drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c line 124
Quoted 5 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c new file +5
-0+ + cpu =gen_pool_dma_zalloc_align (ctx->dev->sram_pool, + rcb_size, + &dma, +0x1000 );
Same here ?
Regards,
Jonas
Quoted 245 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c new file +54
-0+ } + +/* If an IOMMU is used, map the SRAM address through it */ +if (cpu && rkvdec->iommu_domain) { +unsigned long virt_addr = (unsigned long )cpu; +phys_addr_t phys_addr = dma; + + ret =iommu_map (rkvdec->iommu_domain, virt_addr, phys_addr, + rcb_size,IOMMU_READ |IOMMU_WRITE ,0 ); +if (ret) { +gen_pool_free (ctx->dev->sram_pool, + (unsigned long )cpu, + rcb_size); + cpu =NULL ; + goto ram_fallback; + } + +/* +* The registers will be configured with the virtual +* address so that it goes through the IOMMU +*/ + dma = virt_addr; + } + +ram_fallback: +/* Fallback to RAM */ +if (!cpu) { + cpu =dma_alloc_coherent (ctx->dev->dev, + rcb_size, + &dma, +GFP_KERNEL ); + alloc_type =RKVDEC_ALLOC_DMA ; + } + +if (!cpu) { + ret = -ENOMEM ; + goto err_alloc; + } + + cfg->rcb_bufs[i].cpu = cpu; + cfg->rcb_bufs[i].dma = dma; + cfg->rcb_bufs[i].size = rcb_size; + cfg->rcb_bufs[i].type = alloc_type; + + cfg->rcb_count +=1 ; + } + +return 0 ; + +err_alloc: +rkvdec_free_rcb (ctx); + +return ret; +}drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.h new file +29
-0@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Rockchip video decoder Rows and Cols Buffers manager +* +* Copyright (C) 2025 Collabora, Ltd. +* Detlev Casanova <[email protected]> +*/ + +#include <linux/types.h> + +struct rkvdec_ctx ; + +enum rcb_axis { +PIC_WIDTH =0 , +PIC_HEIGHT =1 +}; + +struct rcb_size_info { +u8 multiplier; +enum rcb_axis axis; +}; + +int rkvdec_allocate_rcb (struct rkvdec_ctx *ctx, +const struct rcb_size_info *size_info, +size_t rcb_count); +dma_addr_t rkvdec_rcb_buf_dma_addr (struct rkvdec_ctx *ctx,int id); +size_t rkvdec_rcb_buf_size (struct rkvdec_ctx *ctx,int id); +int rkvdec_rcb_buf_count (struct rkvdec_ctx *ctx); +void rkvdec_free_rcb (struct rkvdec_ctx *ctx);drivers/media/platform/rockchip/rkvdec/rkvdec.c +25
-2@@ -10,6 +10,7 @@*/ #include <linux/clk.h> +#include <linux/genalloc.h> #include <linux/interrupt.h> #include <linux/iommu.h> #include <linux/module.h> @@ -28,6 +29,7 @@#include "rkvdec.h" #include "rkvdec-regs.h" +#include "rkvdec-rcb.h" static bool rkvdec_image_fmt_match (enum rkvdec_image_fmt fmt1,enum rkvdec_image_fmt fmt2)@@ -771,6 +773,7 @@ static int rkvdec_start_streaming(struct vb2_queue *q, unsigned int count) {struct rkvdec_ctx *ctx =vb2_get_drv_priv (q);const struct rkvdec_coded_fmt_desc *desc; +const struct rkvdec_variant *variant = ctx->dev->variant;int ret;if (V4L2_TYPE_IS_CAPTURE (q->type))@@ -780,13 +783,22 @@ static int rkvdec_start_streaming(struct vb2_queue *q, unsigned int count)if (WARN_ON (!desc))return -EINVAL ; + ret =rkvdec_allocate_rcb (ctx, variant->rcb_sizes, variant->num_rcb_sizes); +if (ret) +return ret; +if (desc->ops->start) { ret = desc->ops->start (ctx);if (ret) -return ret; + goto err_ops_start; }return 0 ; + +err_ops_start: +rkvdec_free_rcb (ctx); + +return ret; }static void rkvdec_queue_cleanup (struct vb2_queue *vq,u32 state)@@ -822,6 +834,8 @@ static void rkvdec_stop_streaming(struct vb2_queue *q)if (desc->ops->stop) desc->ops->stop (ctx); + +rkvdec_free_rcb (ctx); }rkvdec_queue_cleanup (q,VB2_BUF_STATE_ERROR );@@ -1348,6 +1362,10 @@ static int rkvdec_probe(struct platform_device *pdev)return ret; } + rkvdec->sram_pool =of_gen_pool_get (pdev->dev.of_node,"sram" ,0 ); +if (!rkvdec->sram_pool && rkvdec->variant->num_rcb_sizes >0 ) +dev_info (&pdev->dev,"No sram node, RCB will be stored in RAM\n" ); +pm_runtime_set_autosuspend_delay (&pdev->dev,100 );pm_runtime_use_autosuspend (&pdev->dev);pm_runtime_enable (&pdev->dev);@@ -1356,7 +1374,8 @@ static int rkvdec_probe(struct platform_device *pdev)if (ret) goto err_disable_runtime_pm; -if (iommu_get_domain_for_dev (&pdev->dev)) { + rkvdec->iommu_domain =iommu_get_domain_for_dev (&pdev->dev); +if (rkvdec->iommu_domain) { rkvdec->empty_domain =iommu_paging_domain_alloc (rkvdec->dev);if (IS_ERR (rkvdec->empty_domain)) {@@ -1370,6 +1389,10 @@ static int rkvdec_probe(struct platform_device *pdev) err_disable_runtime_pm:pm_runtime_dont_use_autosuspend (&pdev->dev);pm_runtime_disable (&pdev->dev); + +if (rkvdec->sram_pool) +gen_pool_destroy (rkvdec->sram_pool); +return ret; }drivers/media/platform/rockchip/rkvdec/rkvdec.h +13
-0@@ -19,6 +19,7 @@#include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> +#include <media/v4l2-mem2mem.h> #include <media/videobuf2-core.h> #include <media/videobuf2-dma-contig.h> @@ -29,6 +30,7 @@#define RKVDEC_QUIRK_DISABLE_QOS BIT(0)struct rkvdec_ctx ; +struct rkvdec_rcb_config ;struct rkvdec_ctrl_desc {struct v4l2_ctrl_config cfg;@@ -73,6 +75,8 @@ struct rkvdec_variant {unsigned int num_regs;const struct rkvdec_coded_fmt_desc *coded_fmts;size_t num_coded_fmts; +const struct rcb_size_info *rcb_sizes; +size_t num_rcb_sizes;unsigned int capabilities;unsigned int quirks; };@@ -125,6 +129,8 @@ struct rkvdec_dev {void __iomem *regs;struct mutex vdev_lock;/* serializes ioctls */ struct delayed_work watchdog_work; +struct gen_pool *sram_pool; +struct iommu_domain *iommu_domain;struct iommu_domain *empty_domain;const struct rkvdec_variant *variant; };@@ -137,6 +143,7 @@ struct rkvdec_ctx {struct v4l2_ctrl_handler ctrl_hdl;struct rkvdec_dev *dev;enum rkvdec_image_fmt image_fmt; +struct rkvdec_rcb_config *rcb_config;void *priv; };@@ -145,10 +152,16 @@ static inline struct rkvdec_ctx *file_to_rkvdec_ctx(struct file *filp) return container_of(file_to_v4l2_fh(filp), struct rkvdec_ctx, fh); } +enum rkvdec_alloc_type { +RKVDEC_ALLOC_DMA =0 , +RKVDEC_ALLOC_SRAM =1 , +}; +struct rkvdec_aux_buf {void *cpu;dma_addr_t dma;size_t size; +enum rkvdec_alloc_type type; };void rkvdec_run_preamble (struct rkvdec_ctx *ctx,struct rkvdec_run *run);
Detlev Casanova
maintainerPATCH v6 11/17 media: rkvdec: Support per-variant interrupt handler
In reply to Detlev CasanovaPrepare for supporting different variants with different interrupt managers.
To support other variants specific function type later, introduce the rkvdec_variant_ops struct.
--- .../media/platform/rockchip/rkvdec/rkvdec.c | 21 ++++++++++++++++--- .../media/platform/rockchip/rkvdec/rkvdec.h | 5 +++++ 2 files changed, 23 insertions(+), 3 deletions(-)
drivers/media/platform/rockchip/rkvdec/rkvdec.c +18 -3
@@ -1218,10 +1218,9 @@ static void rkvdec_iommu_restore(struct rkvdec_dev *rkvdec) } } -static irqreturn_t rkvdec_irq_handler (int irq,void *priv) +static irqreturn_t rk3399_irq_handler (struct rkvdec_ctx *ctx) { -struct rkvdec_dev *rkvdec = priv; -struct rkvdec_ctx *ctx =v4l2_m2m_get_curr_priv (rkvdec->m2m_dev); +struct rkvdec_dev *rkvdec = ctx->dev;enum vb2_buffer_state state;u32 status;
@@ -1242,6 +1241,15 @@ static irqreturn_t rkvdec_irq_handler(int irq, void *priv)return IRQ_HANDLED ; } +static irqreturn_t rkvdec_irq_handler (int irq,void *priv) +{ +struct rkvdec_dev *rkvdec = priv; +struct rkvdec_ctx *ctx =v4l2_m2m_get_curr_priv (rkvdec->m2m_dev); +const struct rkvdec_variant *variant = rkvdec->variant; + +return variant->ops->irq_handler (ctx); +} +static void rkvdec_watchdog_func (struct work_struct *work) {struct rkvdec_dev *rkvdec;
@@ -1257,10 +1265,15 @@ static void rkvdec_watchdog_func(struct work_struct *work) } } +static const struct rkvdec_variant_ops rk3399_variant_ops = { + .irq_handler = rk3399_irq_handler, +}; +static const struct rkvdec_variant rk3288_rkvdec_variant = { .num_regs =68 , .coded_fmts = rkvdec_coded_fmts, .num_coded_fmts =ARRAY_SIZE (rkvdec_coded_fmts), + .ops = &rk3399_variant_ops, .capabilities =RKVDEC_CAPABILITY_HEVC , };
@@ -1268,6 +1281,7 @@ static const struct rkvdec_variant rk3328_rkvdec_variant = { .num_regs = 109, .coded_fmts = rkvdec_coded_fmts, .num_coded_fmts = ARRAY_SIZE(rkvdec_coded_fmts), + .ops = &rk3399_variant_ops, .capabilities =RKVDEC_CAPABILITY_HEVC |RKVDEC_CAPABILITY_H264 | RKVDEC_CAPABILITY_VP9,
@@ -1278,6 +1292,7 @@ static const struct rkvdec_variant rk3399_rkvdec_variant = { .num_regs = 78, .coded_fmts = rkvdec_coded_fmts, .num_coded_fmts = ARRAY_SIZE(rkvdec_coded_fmts), + .ops = &rk3399_variant_ops, .capabilities =RKVDEC_CAPABILITY_HEVC |RKVDEC_CAPABILITY_H264 | RKVDEC_CAPABILITY_VP9,
drivers/media/platform/rockchip/rkvdec/rkvdec.h +5 -0
@@ -71,12 +71,17 @@ vb2_to_rkvdec_decoded_buf(struct vb2_buffer *buf) base.vb.vb2_buf); } +struct rkvdec_variant_ops { +irqreturn_t (*irq_handler)(struct rkvdec_ctx *ctx); +}; +struct rkvdec_variant {unsigned int num_regs;const struct rkvdec_coded_fmt_desc *coded_fmts;size_t num_coded_fmts;const struct rcb_size_info *rcb_sizes;size_t num_rcb_sizes; +const struct rkvdec_variant_ops *ops;unsigned int capabilities;unsigned int quirks; };
Signature · 1 line
2.52.0
Detlev Casanova
maintainerPATCH v6 12/17 media: rkvdec: Enable all clocks without naming them
In reply to Detlev CasanovaFor other variants, the clock names and number will differ.
There is no need to keep track of the clock names in the driver so drop them to avoid having a list for each variant.
--- .../media/platform/rockchip/rkvdec/rkvdec.c | 26 +++++-------------- .../media/platform/rockchip/rkvdec/rkvdec.h | 1 + 2 files changed, 7 insertions(+), 20 deletions(-)
drivers/media/platform/rockchip/rkvdec/rkvdec.c +6 -20
@@ -1315,15 +1315,10 @@ static const struct of_device_id of_rkvdec_match[] = { };MODULE_DEVICE_TABLE (of, of_rkvdec_match); -static const char *const rkvdec_clk_names[] = { -"axi" ,"ahb" ,"cabac" ,"core" -}; -static int rkvdec_probe (struct platform_device *pdev) {const struct rkvdec_variant *variant;struct rkvdec_dev *rkvdec; -unsigned int i;int ret, irq; variant =of_device_get_match_data (&pdev->dev);
@@ -1340,19 +1335,12 @@ static int rkvdec_probe(struct platform_device *pdev)mutex_init (&rkvdec->vdev_lock);INIT_DELAYED_WORK (&rkvdec->watchdog_work, rkvdec_watchdog_func); - rkvdec->clocks =devm_kcalloc (&pdev->dev,ARRAY_SIZE (rkvdec_clk_names), -sizeof (*rkvdec->clocks),GFP_KERNEL ); -if (!rkvdec->clocks) -return -ENOMEM ; - -for (i =0 ; i <ARRAY_SIZE (rkvdec_clk_names); i++) - rkvdec->clocks[i].id = rkvdec_clk_names[i]; - - ret =devm_clk_bulk_get (&pdev->dev,ARRAY_SIZE (rkvdec_clk_names), - rkvdec->clocks); -if (ret) + ret =devm_clk_bulk_get_all_enabled (&pdev->dev, &rkvdec->clocks); +if (ret <0 )return ret; + rkvdec->num_clocks = ret; + rkvdec->regs =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (rkvdec->regs))return PTR_ERR (rkvdec->regs);
@@ -1430,16 +1418,14 @@ static int rkvdec_runtime_resume(struct device *dev) {struct rkvdec_dev *rkvdec =dev_get_drvdata (dev); -return clk_bulk_prepare_enable (ARRAY_SIZE (rkvdec_clk_names), - rkvdec->clocks); +return clk_bulk_prepare_enable (rkvdec->num_clocks, rkvdec->clocks); }static int rkvdec_runtime_suspend (struct device *dev) {struct rkvdec_dev *rkvdec =dev_get_drvdata (dev); -clk_bulk_disable_unprepare (ARRAY_SIZE (rkvdec_clk_names), - rkvdec->clocks); +clk_bulk_disable_unprepare (rkvdec->num_clocks, rkvdec->clocks);return 0 ; }#endif
drivers/media/platform/rockchip/rkvdec/rkvdec.h +1 -0
@@ -131,6 +131,7 @@ struct rkvdec_dev {struct v4l2_m2m_dev *m2m_dev;struct device *dev;struct clk_bulk_data *clocks; +unsigned int num_clocks;void __iomem *regs;struct mutex vdev_lock;/* serializes ioctls */ struct delayed_work watchdog_work;
Signature · 1 line
2.52.0
Detlev Casanova
maintainerPATCH v6 13/17 media: rkvdec: Disable multicore support
In reply to Detlev CasanovaSimilarly to what is done in Hantro, avoid exposing equal video codecs to userspace. Equal video codecs allow scheduling work between the cores. For that kernel support is required, which does not yet exist. Until that is implemented, avoid exposing each core separately to userspace so that multicore can be added in the future without breaking userspace ABI.
This currently applies only to RK3588 which has 2 equal VDPU381 decoders, but will be applied for all SoC supported by rkvdec that has multiple DTS nodes with the same compatible.
--- .../media/platform/rockchip/rkvdec/rkvdec.c | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/media/platform/rockchip/rkvdec/rkvdec.c +47 -0
@@ -1265,6 +1265,49 @@ static void rkvdec_watchdog_func(struct work_struct *work) } } +/* +* Some SoCs, like RK3588 have multiple identical VDPU cores, but the +* kernel is currently missing support for multi-core handling. Exposing +* separate devices for each core to userspace is bad, since that does +* not allow scheduling tasks properly (and creates ABI). With this workaround +* the driver will only probe for the first core and early exit for the other +* cores. Once the driver gains multi-core support, the same technique +* for detecting the first core can be used to cluster all cores together. +*/ +static int rkvdec_disable_multicore (struct rkvdec_dev *rkvdec) +{ +struct device_node *node =NULL ; +const char *compatible; +bool is_first_core; +int ret; + +/* Intentionally ignores the fallback strings */ + ret =of_property_read_string (rkvdec->dev->of_node,"compatible" , &compatible); +if (ret) +return ret; + +/* The first compatible and available node found is considered the main core */ +do { + node =of_find_compatible_node (node,NULL , compatible); +if (of_device_is_available (node)) +break ; + }while (node); + +if (!node) +return -EINVAL ; + + is_first_core = (rkvdec->dev->of_node == node); + +of_node_put (node); + +if (!is_first_core) { +dev_info (rkvdec->dev,"missing multi-core support, ignoring this instance\n" ); +return -ENODEV ; + } + +return 0 ; +} +static const struct rkvdec_variant_ops rk3399_variant_ops = { .irq_handler = rk3399_irq_handler, };
@@ -1335,6 +1378,10 @@ static int rkvdec_probe(struct platform_device *pdev)mutex_init (&rkvdec->vdev_lock);INIT_DELAYED_WORK (&rkvdec->watchdog_work, rkvdec_watchdog_func); + ret =rkvdec_disable_multicore (rkvdec); +if (ret) +return ret; + ret =devm_clk_bulk_get_all_enabled (&pdev->dev, &rkvdec->clocks);if (ret <0 )return ret;
Signature · 1 line
2.52.0
Detlev Casanova
maintainerPATCH v6 14/17 media: rkvdec: Add H264 support for the VDPU381 variant
In reply to Detlev CasanovaThis decoder variant is found in Rockchip RK3588 SoC family.
Like for rkvdec on rk3399, it supports the NV12, NV15, NV16 and NV20 output formats and level up to 5.1.
The maximum width and height have been significantly increased supporting up to 65520 pixels for both.
Also make sure to only expose the first core and ignore the other until mutli-core is supported.
Fluster score for JVT-AVC_V1 is 129/135.
--- .../media/platform/rockchip/rkvdec/Makefile | 1 + .../rockchip/rkvdec/rkvdec-h264-common.h | 2 + .../rockchip/rkvdec/rkvdec-vdpu381-h264.c | 469 ++++++++++++++++++ .../rockchip/rkvdec/rkvdec-vdpu381-regs.h | 424 ++++++++++++++++ .../media/platform/rockchip/rkvdec/rkvdec.c | 84 ++++ .../media/platform/rockchip/rkvdec/rkvdec.h | 8 + 6 files changed, 988 insertions(+) create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h
drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
@@ -8,4 +8,5 @@ rockchip-vdec-y += \ rkvdec-hevc.o \ rkvdec-hevc-common.o \ rkvdec-rcb.o \ + rkvdec-vdpu381-h264.o \ rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-h264-common.h +2 -0
@@ -74,6 +74,8 @@ struct rkvdec_rps {u32 reserved1[66 ]; } __packed; +extern const s8 rkvdec_h264_cabac_table[4 ][464 ][2 ]; +void lookup_ref_buf_idx (struct rkvdec_ctx *ctx,struct rkvdec_h264_run *run); void assemble_hw_rps(struct v4l2_h264_reflist_builder *builder, struct rkvdec_h264_run *run,
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c new file +469 -0
469 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h new file +424 -0
424 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec.c +84 -0
132 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec.h +8 -0
@@ -29,6 +29,10 @@#define RKVDEC_QUIRK_DISABLE_QOS BIT(0) +#define RKVDEC_1080P_PIXELS (1920 * 1088) +#define RKVDEC_4K_PIXELS (4096 * 2304) +#define RKVDEC_8K_PIXELS (7680 * 4320) +struct rkvdec_ctx ;struct rkvdec_rcb_config ;
@@ -132,6 +136,7 @@ struct rkvdec_dev {struct device *dev;struct clk_bulk_data *clocks;unsigned int num_clocks; +struct clk *axi_clk;void __iomem *regs;struct mutex vdev_lock;/* serializes ioctls */ struct delayed_work watchdog_work;
@@ -150,6 +155,7 @@ struct rkvdec_ctx {struct rkvdec_dev *dev;enum rkvdec_image_fmt image_fmt;struct rkvdec_rcb_config *rcb_config; +u32 colmv_offset;void *priv; };
@@ -180,4 +186,6 @@ extern const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops;extern const struct rkvdec_coded_fmt_ops rkvdec_hevc_fmt_ops;extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops; +extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops; +#endif /* RKVDEC_H_ */
Signature · 1 line
2.52.0
Re: [PATCH v6 14/17] media: rkvdec: Add H264 support for the VDPU381 variant
Hi Detlev,
Quoted 26 lines · Detlev Casanova
This decoder variant is found in Rockchip RK3588 SoC family.
Like for rkvdec on rk3399, it supports the NV12, NV15, NV16 and NV20 output formats and level up to 5.1.
The maximum width and height have been significantly increased supporting up to 65520 pixels for both.
Also make sure to only expose the first core and ignore the other until mutli-core is supported.
Fluster score for JVT-AVC_V1 is 129/135.
Signed-off-by Detlev Casanova <[email protected]>--- .../media/platform/rockchip/rkvdec/Makefile | 1 + .../rockchip/rkvdec/rkvdec-h264-common.h | 2 + .../rockchip/rkvdec/rkvdec-vdpu381-h264.c | 469 ++++++++++++++++++ .../rockchip/rkvdec/rkvdec-vdpu381-regs.h | 424 ++++++++++++++++ .../media/platform/rockchip/rkvdec/rkvdec.c | 84 ++++ .../media/platform/rockchip/rkvdec/rkvdec.h | 8 + 6 files changed, 988 insertions(+) create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-regs.h
[snip]
Quoted 91 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +55
-0@@ -29,6 +29,7 @@#include "rkvdec.h" #include "rkvdec-regs.h" +#include "rkvdec-vdpu381-regs.h" #include "rkvdec-rcb.h" static bool rkvdec_image_fmt_match(enum rkvdec_image_fmt fmt1,@@ -90,6 +91,9 @@ static void rkvdec_fill_decoded_pixfmt(struct rkvdec_ctx *ctx, {v4l2_fill_pixfmt_mp (pix_mp, pix_mp->pixelformat, pix_mp->width, pix_mp->height); + + ctx->colmv_offset = pix_mp->plane_fmt[0 ].sizeimage; + pix_mp->plane_fmt[0 ].sizeimage +=128 *DIV_ROUND_UP (pix_mp->width,16 ) *DIV_ROUND_UP (pix_mp->height,16 );@@ -367,6 +371,26 @@ static const struct rkvdec_coded_fmt_desc rkvdec_coded_fmts[] = { } }; +static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = { + { + .fourcc =V4L2_PIX_FMT_H264_SLICE , + .frmsize = { + .min_width =64 , + .max_width =65520 , + .step_width =64 , + .min_height =64 , + .max_height =65520 , + .step_height =16 , + }, + .ctrls = &rkvdec_h264_ctrls, + .ops = &rkvdec_vdpu381_h264_fmt_ops, + .num_decoded_fmts =ARRAY_SIZE (rkvdec_h264_decoded_fmts), + .decoded_fmts = rkvdec_h264_decoded_fmts, + .subsystem_flags =VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF , + .capability =RKVDEC_CAPABILITY_H264 , + }, +}; +static bool rkvdec_is_capable (struct rkvdec_ctx *ctx,unsigned int capability) {return (ctx->dev->variant->capabilities & capability) == capability;@@ -1241,6 +1265,35 @@ static irqreturn_t rk3399_irq_handler(struct rkvdec_ctx *ctx)return IRQ_HANDLED ; } +static irqreturn_t vdpu381_irq_handler (struct rkvdec_ctx *ctx) +{ +struct rkvdec_dev *rkvdec = ctx->dev; +enum vb2_buffer_state state; +bool need_reset =0 ; +u32 status; + + status =readl (rkvdec->regs +VDPU381_REG_STA_INT ); +writel (0 , rkvdec->regs +VDPU381_REG_STA_INT ); + +if (status &VDPU381_STA_INT_DEC_RDY_STA ) { + state =VB2_BUF_STATE_DONE ; + }else { + state =VB2_BUF_STATE_ERROR ; +if (status & (VDPU381_STA_INT_SOFTRESET_RDY | +VDPU381_STA_INT_TIMEOUT | +VDPU381_STA_INT_ERROR )) +rkvdec_iommu_restore (rkvdec); + } + +if (need_reset) +rkvdec_iommu_restore (rkvdec); + +if (cancel_delayed_work (&rkvdec->watchdog_work)) +rkvdec_job_finish (ctx, state); + +return IRQ_HANDLED ; +} +static irqreturn_t rkvdec_irq_handler (int irq,void *priv) {struct rkvdec_dev *rkvdec = priv;@@ -1308,6 +1361,19 @@ static int rkvdec_disable_multicore(struct rkvdec_dev *rkvdec)return 0 ; } +static const struct rcb_size_info vdpu381_rcb_sizes[] = { + {6 ,PIC_WIDTH },// intrar
drivers/media/platform/rockchip/rkvdec/rkvdec.c static int rkvdec_disable_multicore(struct rkvdec_dev *rkvdec) · line 1375
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10
-0+ {1, PIC_WIDTH}, // transdr (Is actually 0.4*pic_width) + {1, PIC_HEIGHT}, // transdc (Is actually 0.1*pic_height) + {3, PIC_WIDTH}, // streamdr + {6, PIC_WIDTH}, // interr + {3, PIC_HEIGHT}, // interc + {22, PIC_WIDTH}, // dblkr + {6, PIC_WIDTH}, // saor + {11, PIC_WIDTH}, // fbcr + {67, PIC_HEIGHT}, // filtc col +};
This feel a little bit out of place, should it be moved just above vdpu381_variant_ops and after rk3399_rkvdec_variant ?
drivers/media/platform/rockchip/rkvdec/rkvdec.c static const struct rkvdec_variant rk3399_rkvdec_variant = { · line 1414
Quoted 13 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +6
-0+static const struct rkvdec_variant_ops rk3399_variant_ops = { .irq_handler = rk3399_irq_handler, };@@ -1341,6 +1407,19 @@ static const struct rkvdec_variant rk3399_rkvdec_variant = { RKVDEC_CAPABILITY_VP9, }; +static const struct rkvdec_variant_ops vdpu381_variant_ops = { + .irq_handler = vdpu381_irq_handler, +}; + +static const struct rkvdec_variant rk3588_vdpu381_variant = {
Are we expecting other soc use vdpu381 ? Or are there some reason why some of the structs are just named vdpu381 and this one both rk3588 and vdpu381 ?
Regards,
Jonas
Quoted 68 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +13
-0+ .coded_fmts = vdpu381_coded_fmts, + .num_coded_fmts = ARRAY_SIZE(vdpu381_coded_fmts), + .rcb_sizes = vdpu381_rcb_sizes, + .num_rcb_sizes = ARRAY_SIZE(vdpu381_rcb_sizes), + .ops = &vdpu381_variant_ops, + .capabilities = RKVDEC_CAPABILITY_H264, +}; +static const struct of_device_id of_rkvdec_match[] = { { .compatible ="rockchip,rk3288-vdec" ,@@ -1354,6 +1433,10 @@ static const struct of_device_id of_rkvdec_match[] = { .compatible = "rockchip,rk3399-vdec", .data = &rk3399_rkvdec_variant, }, + { + .compatible = "rockchip,rk3588-vdec", + .data = &rk3588_vdpu381_variant, + }, {/* sentinel */ } };MODULE_DEVICE_TABLE (of, of_rkvdec_match);@@ -1387,6 +1470,7 @@ static int rkvdec_probe(struct platform_device *pdev)return ret; rkvdec->num_clocks = ret; + rkvdec->axi_clk =devm_clk_get (&pdev->dev,"axi" ); rkvdec->regs =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (rkvdec->regs))drivers/media/platform/rockchip/rkvdec/rkvdec.h +8
-0@@ -29,6 +29,10 @@#define RKVDEC_QUIRK_DISABLE_QOS BIT(0) +#define RKVDEC_1080P_PIXELS (1920 * 1088) +#define RKVDEC_4K_PIXELS (4096 * 2304) +#define RKVDEC_8K_PIXELS (7680 * 4320) +struct rkvdec_ctx ;struct rkvdec_rcb_config ;@@ -132,6 +136,7 @@ struct rkvdec_dev {struct device *dev;struct clk_bulk_data *clocks;unsigned int num_clocks; +struct clk *axi_clk;void __iomem *regs;struct mutex vdev_lock;/* serializes ioctls */ struct delayed_work watchdog_work;@@ -150,6 +155,7 @@ struct rkvdec_ctx {struct rkvdec_dev *dev;enum rkvdec_image_fmt image_fmt;struct rkvdec_rcb_config *rcb_config; +u32 colmv_offset;void *priv; };@@ -180,4 +186,6 @@ extern const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops;extern const struct rkvdec_coded_fmt_ops rkvdec_hevc_fmt_ops;extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops; +extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops; +#endif /* RKVDEC_H_ */
Detlev Casanova
maintainerPATCH v6 15/17 media: rkvdec: Add H264 support for the VDPU383 variant
In reply to Detlev CasanovaThis variant is used on the RK3576 SoC.
The moving vectors size requirements are slightly different so support for a colmv_size function per variant is added.
Also, the link registers are used to start the decoder and read IRQ status. Per variant support for named register sections is added.
The fluster score is 128/135 for JVT-AVC_V1, with MPS_MW_A failing in addition to the usual ones.
The other test suites are not supported yet.
--- .../media/platform/rockchip/rkvdec/Makefile | 1 + .../rockchip/rkvdec/rkvdec-vdpu383-h264.c | 582 ++++++++++++++++++ .../rockchip/rkvdec/rkvdec-vdpu383-regs.h | 281 +++++++++ .../media/platform/rockchip/rkvdec/rkvdec.c | 118 +++- .../media/platform/rockchip/rkvdec/rkvdec.h | 8 + 5 files changed, 984 insertions(+), 6 deletions(-) create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-regs.h
drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
@@ -9,4 +9,5 @@ rockchip-vdec-y += \ rkvdec-hevc-common.o \ rkvdec-rcb.o \ rkvdec-vdpu381-h264.o \ + rkvdec-vdpu383-h264.o \ rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +582 -0
582 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-regs.h new file +281 -0
281 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec.c +112 -6
188 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec.h +8 -0
@@ -77,6 +77,7 @@ vb2_to_rkvdec_decoded_buf(struct vb2_buffer *buf)struct rkvdec_variant_ops {irqreturn_t (*irq_handler)(struct rkvdec_ctx *ctx); +u32 (*colmv_size)(u16 width,u16 height); };struct rkvdec_variant {
@@ -86,6 +87,7 @@ struct rkvdec_variant {const struct rcb_size_info *rcb_sizes;size_t num_rcb_sizes;const struct rkvdec_variant_ops *ops; +bool named_regs;unsigned int capabilities;unsigned int quirks; };
@@ -138,6 +140,7 @@ struct rkvdec_dev {unsigned int num_clocks;struct clk *axi_clk;void __iomem *regs; +void __iomem *link;struct mutex vdev_lock;/* serializes ioctls */ struct delayed_work watchdog_work;struct gen_pool *sram_pool;
@@ -182,10 +185,15 @@ void rkvdec_memcpy_toio(void __iomem *dst, void *src, size_t len);void rkvdec_quirks_disable_qos (struct rkvdec_ctx *ctx); +/* RKVDEC ops */ extern const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops;extern const struct rkvdec_coded_fmt_ops rkvdec_hevc_fmt_ops;extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops; +/* VDPU381 ops */ extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops; +/* VDPU383 ops */ +extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops; +#endif /* RKVDEC_H_ */
Signature · 1 line
2.52.0
Re: [PATCH v6 15/17] media: rkvdec: Add H264 support for the VDPU383 variant
Hi Detlev,
Quoted 39 lines · Detlev Casanova
This variant is used on the RK3576 SoC.
The moving vectors size requirements are slightly different so support for a
colmv_sizefunction per variant is added.Also, the link registers are used to start the decoder and read IRQ status. Per variant support for named register sections is added.
The fluster score is 128/135 for JVT-AVC_V1, with
MPS_MW_Afailing in addition to the usual ones.
The other test suites are not supported yet.Reviewed-by Nicolas Dufresne <[email protected]>Signed-off-by Detlev Casanova <[email protected]>--- .../media/platform/rockchip/rkvdec/Makefile | 1 + .../rockchip/rkvdec/rkvdec-vdpu383-h264.c | 582 ++++++++++++++++++ .../rockchip/rkvdec/rkvdec-vdpu383-regs.h | 281 +++++++++ .../media/platform/rockchip/rkvdec/rkvdec.c | 118 +++- .../media/platform/rockchip/rkvdec/rkvdec.h | 8 + 5 files changed, 984 insertions(+), 6 deletions(-) create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-regs.hdrivers/media/platform/rockchip/rkvdec/Makefile +1
-0@@ -9,4 +9,5 @@ rockchip-vdec-y += \ rkvdec-hevc-common.o \ rkvdec-rcb.o \ rkvdec-vdpu381-h264.o \ + rkvdec-vdpu383-h264.o \ rkvdec-vp9.odrivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +0
-0
[snip]
Quoted 6 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +6
-0+static int rkvdec_h264_start (struct rkvdec_ctx *ctx) +{ +struct rkvdec_dev *rkvdec = ctx->dev; +struct rkvdec_h264_priv_tbl *priv_tbl; +struct rkvdec_h264_ctx *h264_ctx; +struct v4l2_ctrl *ctrl;
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c line 482
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +10
-0+int ret; + + ctrl =v4l2_ctrl_find (&ctx->ctrl_hdl, +V4L2_CID_STATELESS_H264_SPS ); +if (!ctrl) +return -EINVAL ; + + ret =rkvdec_h264_validate_sps (ctx, ctrl->p_new.p_h264_sps); +if (ret) +return ret;
I recall some older mail thread that we should not have to validate sps in start ops. It is validated in try_ctrl and is expected to always be in a valid state.
This can most likely be dropped, it was removed from the HEVC start ops.
Quoted 100 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c new file +100
-0+ + h264_ctx =kzalloc (sizeof (*h264_ctx),GFP_KERNEL ); +if (!h264_ctx) +return -ENOMEM ; + + priv_tbl =dma_alloc_coherent (rkvdec->dev,sizeof (*priv_tbl), + &h264_ctx->priv_tbl.dma,GFP_KERNEL ); +if (!priv_tbl) { + ret = -ENOMEM ; + goto err_free_ctx; + } + + h264_ctx->priv_tbl.size =sizeof (*priv_tbl); + h264_ctx->priv_tbl.cpu = priv_tbl; +memcpy (priv_tbl->cabac_table, rkvdec_h264_cabac_table, +sizeof (rkvdec_h264_cabac_table)); + + ctx->priv = h264_ctx; + +return 0 ; + +err_free_ctx: +kfree (h264_ctx); +return ret; +} + +static void rkvdec_h264_stop (struct rkvdec_ctx *ctx) +{ +struct rkvdec_h264_ctx *h264_ctx = ctx->priv; +struct rkvdec_dev *rkvdec = ctx->dev; + +dma_free_coherent (rkvdec->dev, h264_ctx->priv_tbl.size, + h264_ctx->priv_tbl.cpu, h264_ctx->priv_tbl.dma); +kfree (h264_ctx); +} + +static int rkvdec_h264_run (struct rkvdec_ctx *ctx) +{ +struct v4l2_h264_reflist_builder reflist_builder; +struct rkvdec_dev *rkvdec = ctx->dev; +struct rkvdec_h264_ctx *h264_ctx = ctx->priv; +struct rkvdec_h264_run run; +struct rkvdec_h264_priv_tbl *tbl = h264_ctx->priv_tbl.cpu; +u32 watchdog_time; +u64 timeout_threshold; +unsigned long axi_rate; + +rkvdec_h264_run_preamble (ctx, &run); + +/* Build the P/B{0,1} ref lists. */ +v4l2_h264_init_reflist_builder (&reflist_builder, run.decode_params, + run.sps, run.decode_params->dpb); +v4l2_h264_build_p_ref_list (&reflist_builder, h264_ctx->reflists.p); +v4l2_h264_build_b_ref_lists (&reflist_builder, h264_ctx->reflists.b0, + h264_ctx->reflists.b1); + +assemble_hw_scaling_list (&run, &tbl->scaling_list); +assemble_hw_pps (ctx, &run); +lookup_ref_buf_idx (ctx, &run); +assemble_hw_rps (&reflist_builder, &run, &h264_ctx->reflists, &tbl->rps); + +config_registers (ctx, &run); + +rkvdec_run_postamble (ctx, &run.base); + +/* Set watchdog at 2 times the hardware timeout threshold */ + timeout_threshold = h264_ctx->regs.common.reg013_core_timeout_threshold; + axi_rate =clk_get_rate (rkvdec->axi_clk); + +if (axi_rate) + watchdog_time =2 * (1000 * timeout_threshold) / axi_rate; +else + watchdog_time =2000 ; +schedule_delayed_work (&rkvdec->watchdog_work, +msecs_to_jiffies (watchdog_time)); + +/* Start decoding! */ +writel (timeout_threshold, rkvdec->link +VDPU383_LINK_TIMEOUT_THRESHOLD ); +writel (0 , rkvdec->link +VDPU383_LINK_IP_ENABLE ); +writel (VDPU383_DEC_E_BIT , rkvdec->link +VDPU383_LINK_DEC_ENABLE ); + +return 0 ; +} + +static int rkvdec_h264_try_ctrl (struct rkvdec_ctx *ctx,struct v4l2_ctrl *ctrl) +{ +if (ctrl->id ==V4L2_CID_STATELESS_H264_SPS ) +return rkvdec_h264_validate_sps (ctx, ctrl->p_new.p_h264_sps); + +return 0 ; +} + +const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops = { + .adjust_fmt = rkvdec_h264_adjust_fmt, + .get_image_fmt = rkvdec_h264_get_image_fmt, + .start = rkvdec_h264_start, + .stop = rkvdec_h264_stop, + .run = rkvdec_h264_run, + .try_ctrl = rkvdec_h264_try_ctrl, +};
[snip]
Quoted 38 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +13
-0@@ -9,6 +9,7 @@* Copyright (C) 2011 Samsung Electronics Co., Ltd. */ +#include <linux/hw_bitfield.h> #include <linux/clk.h> #include <linux/genalloc.h> #include <linux/interrupt.h> @@ -30,6 +31,7 @@#include "rkvdec.h" #include "rkvdec-regs.h" #include "rkvdec-vdpu381-regs.h" +#include "rkvdec-vdpu383-regs.h" #include "rkvdec-rcb.h" static bool rkvdec_image_fmt_match(enum rkvdec_image_fmt fmt1,@@ -86,17 +88,27 @@ static bool rkvdec_is_valid_fmt(struct rkvdec_ctx *ctx, u32 fourcc,return false; } +static u32 rkvdec_colmv_size (u16 width,u16 height) +{ +return 128 *DIV_ROUND_UP (width,16 ) *DIV_ROUND_UP (height,16 ); +} + +static u32 vdpu383_colmv_size (u16 width,u16 height) +{ +return ALIGN (width,64 ) *ALIGN (height,16 ); +} +static void rkvdec_fill_decoded_pixfmt (struct rkvdec_ctx *ctx,struct v4l2_pix_format_mplane *pix_mp) { +const struct rkvdec_variant *variant = ctx->dev->variant;
drivers/media/platform/rockchip/rkvdec/rkvdec.c static bool rkvdec_is_valid_fmt(struct rkvdec_ctx *ctx, u32 fourcc, · line 111
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +2
-3+v4l2_fill_pixfmt_mp (pix_mp, pix_mp->pixelformat, pix_mp->width, pix_mp->height); ctx->colmv_offset = pix_mp->plane_fmt[0 ].sizeimage; - pix_mp->plane_fmt[0 ].sizeimage +=128 * -DIV_ROUND_UP (pix_mp->width,16 ) * -DIV_ROUND_UP (pix_mp->height,16 ); + pix_mp->plane_fmt[0 ].sizeimage += variant->ops->colmv_size (pix_mp->width, pix_mp->height);
nit: The rest of this function use line breake to keep line lengt below or around 80 chars, this long line feel out of place.
Maybe:
pix_mp->plane_fmt[0].sizeimage += variant->ops->colmv_size(pix_mp->width, pix_mp->height);
Quoted 98 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +64
-0} static void rkvdec_reset_fmt(struct rkvdec_ctx *ctx, struct v4l2_format *f,@@ -391,6 +403,26 @@ static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = { }, }; +static const struct rkvdec_coded_fmt_desc vdpu383_coded_fmts[] = { + { + .fourcc =V4L2_PIX_FMT_H264_SLICE , + .frmsize = { + .min_width =64 , + .max_width =65520 , + .step_width =64 , + .min_height =64 , + .max_height =65520 , + .step_height =16 , + }, + .ctrls = &rkvdec_h264_ctrls, + .ops = &rkvdec_vdpu383_h264_fmt_ops, + .num_decoded_fmts =ARRAY_SIZE (rkvdec_h264_decoded_fmts), + .decoded_fmts = rkvdec_h264_decoded_fmts, + .subsystem_flags =VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF , + .capability =RKVDEC_CAPABILITY_H264 , + }, +}; +static bool rkvdec_is_capable (struct rkvdec_ctx *ctx,unsigned int capability) {return (ctx->dev->variant->capabilities & capability) == capability;@@ -1294,6 +1326,35 @@ static irqreturn_t vdpu381_irq_handler(struct rkvdec_ctx *ctx)return IRQ_HANDLED ; } +static irqreturn_t vdpu383_irq_handler (struct rkvdec_ctx *ctx) +{ +struct rkvdec_dev *rkvdec = ctx->dev; +enum vb2_buffer_state state; +bool need_reset =0 ; +u32 status; + + status =readl (rkvdec->link +VDPU383_LINK_STA_INT ); +writel (FIELD_PREP_WM16 (VDPU383_STA_INT_ALL ,0 ), rkvdec->link +VDPU383_LINK_STA_INT ); +/* On vdpu383, the interrupts must be disabled */ +writel (FIELD_PREP_WM16 (VDPU383_INT_EN_IRQ |VDPU383_INT_EN_LINE_IRQ ,0 ), + rkvdec->link +VDPU383_LINK_INT_EN ); + +if (status &VDPU383_STA_INT_DEC_RDY_STA ) { + state =VB2_BUF_STATE_DONE ; + }else { + state =VB2_BUF_STATE_ERROR ; +rkvdec_iommu_restore (rkvdec); + } + +if (need_reset) +rkvdec_iommu_restore (rkvdec); + +if (cancel_delayed_work (&rkvdec->watchdog_work)) +rkvdec_job_finish (ctx, state); + +return IRQ_HANDLED ; +} +static irqreturn_t rkvdec_irq_handler (int irq,void *priv) {struct rkvdec_dev *rkvdec = priv;@@ -1374,8 +1435,22 @@ static const struct rcb_size_info vdpu381_rcb_sizes[] = { {67, PIC_HEIGHT}, // filtc col }; +static const struct rcb_size_info vdpu383_rcb_sizes[] = { + {6 ,PIC_WIDTH },// streamd + {6 ,PIC_WIDTH },// streamd_tile + {12 ,PIC_WIDTH },// inter + {12 ,PIC_WIDTH },// inter_tile + {16 ,PIC_WIDTH },// intra + {10 ,PIC_WIDTH },// intra_tile + {120 ,PIC_WIDTH },// filterd + {120 ,PIC_WIDTH },// filterd_protect + {120 ,PIC_WIDTH },// filterd_tile_row + {180 ,PIC_HEIGHT },// filterd_tile_col +}; +static const struct rkvdec_variant_ops rk3399_variant_ops = { .irq_handler = rk3399_irq_handler, + .colmv_size = rkvdec_colmv_size, }; static const struct rkvdec_variant rk3288_rkvdec_variant = {@@ -1409,6 +1484,7 @@ static const struct rkvdec_variant rk3399_rkvdec_variant = {static const struct rkvdec_variant_ops vdpu381_variant_ops = { .irq_handler = vdpu381_irq_handler, + .colmv_size = rkvdec_colmv_size, };static const struct rkvdec_variant rk3588_vdpu381_variant = {
drivers/media/platform/rockchip/rkvdec/rkvdec.c static const struct rkvdec_variant rk3588_vdpu381_variant = { · line 1496
Quoted 4 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +1
-0@@ -1417,6 +1493,22 @@ static const struct rkvdec_variant rk3588_vdpu381_variant = { .rcb_sizes = vdpu381_rcb_sizes, .num_rcb_sizes = ARRAY_SIZE(vdpu381_rcb_sizes), .ops = &vdpu381_variant_ops, + .named_regs = true,
Why is this added here in this patch ? Should probably be added in prior patch with the lookup for link regs added in this patch ?
Quoted 65 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +32
-3+ .capabilities = RKVDEC_CAPABILITY_H264, +}; + +static const struct rkvdec_variant_ops vdpu383_variant_ops = { + .irq_handler = vdpu383_irq_handler, + .colmv_size = vdpu383_colmv_size, +}; + +static const struct rkvdec_variant rk3576_vdpu383_variant = { + .coded_fmts = vdpu383_coded_fmts, + .num_coded_fmts =ARRAY_SIZE (vdpu383_coded_fmts), + .rcb_sizes = vdpu383_rcb_sizes, + .num_rcb_sizes =ARRAY_SIZE (vdpu383_rcb_sizes), + .ops = &vdpu383_variant_ops, + .named_regs = true, .capabilities =RKVDEC_CAPABILITY_H264 , };@@ -1437,6 +1529,10 @@ static const struct of_device_id of_rkvdec_match[] = { .compatible = "rockchip,rk3588-vdec", .data = &rk3588_vdpu381_variant, }, + { + .compatible = "rockchip,rk3576-vdec", + .data = &rk3576_vdpu383_variant, + }, {/* sentinel */ } };MODULE_DEVICE_TABLE (of, of_rkvdec_match);@@ -1472,9 +1568,19 @@ static int rkvdec_probe(struct platform_device *pdev) rkvdec->num_clocks = ret; rkvdec->axi_clk =devm_clk_get (&pdev->dev,"axi" ); - rkvdec->regs =devm_platform_ioremap_resource (pdev,0 ); -if (IS_ERR (rkvdec->regs)) -return PTR_ERR (rkvdec->regs); +if (rkvdec->variant->named_regs) { + rkvdec->regs =devm_platform_ioremap_resource_byname (pdev,"function" ); +if (IS_ERR (rkvdec->regs)) +return PTR_ERR (rkvdec->regs); + + rkvdec->link =devm_platform_ioremap_resource_byname (pdev,"link" ); +if (IS_ERR (rkvdec->link)) +return PTR_ERR (rkvdec->link); + }else { + rkvdec->regs =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (rkvdec->regs)) +return PTR_ERR (rkvdec->regs); + } ret =dma_set_coherent_mask (&pdev->dev,DMA_BIT_MASK (32 ));if (ret) {drivers/media/platform/rockchip/rkvdec/rkvdec.h +1
-0@@ -77,6 +77,7 @@ vb2_to_rkvdec_decoded_buf(struct vb2_buffer *buf)struct rkvdec_variant_ops {irqreturn_t (*irq_handler)(struct rkvdec_ctx *ctx); +u32 (*colmv_size)(u16 width,u16 height); };struct rkvdec_variant {
drivers/media/platform/rockchip/rkvdec/rkvdec.h struct rkvdec_variant { · line 90
Quoted 4 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.h +1
-0@@ -86,6 +87,7 @@ struct rkvdec_variant {const struct rcb_size_info *rcb_sizes;size_t num_rcb_sizes;const struct rkvdec_variant_ops *ops; +bool named_regs;
nit: Maybe use_named_regs or similar ?
Maybe this should be inverted as I suspect all new variants are expected to use named regs ?
Quoted 12 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.h +1
-0unsigned int capabilities;unsigned int quirks; };@@ -138,6 +140,7 @@ struct rkvdec_dev {unsigned int num_clocks;struct clk *axi_clk;void __iomem *regs; +void __iomem *link;struct mutex vdev_lock;/* serializes ioctls */ struct delayed_work watchdog_work;struct gen_pool *sram_pool;
drivers/media/platform/rockchip/rkvdec/rkvdec.h void rkvdec_memcpy_toio(void __iomem *dst, void *src, size_t len); · line 193
Quoted 9 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.h +2
-0@@ -182,10 +185,15 @@ void rkvdec_memcpy_toio(void __iomem *dst, void *src, size_t len);void rkvdec_quirks_disable_qos (struct rkvdec_ctx *ctx); +/* RKVDEC ops */ extern const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops;extern const struct rkvdec_coded_fmt_ops rkvdec_hevc_fmt_ops;extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops; +/* VDPU381 ops */
nit: This comment and the one above should be added in prior patch.
Regards,
Jonas
Quoted 6 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.h +3
-0extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops; +/* VDPU383 ops */ +extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops; +#endif /* RKVDEC_H_ */
Detlev Casanova
maintainerPATCH v6 16/17 media: rkvdec: Add HEVC support for the VDPU381 variant
In reply to Detlev CasanovaThe VDPU381 supports HEVC decoding up to 7680x4320@30fps. It could double that when using both decoder cores.
It support YUV420 (8 and 10 bits) as well as AFBC (not implemented here)
The fluster score is 146/147 for JCT-VC-HEVC_V1, tested on ROCK 5B. None of the other test suites works.
--- .../media/platform/rockchip/rkvdec/Kconfig | 1 + .../media/platform/rockchip/rkvdec/Makefile | 1 + .../rockchip/rkvdec/rkvdec-hevc-common.c | 349 +++++++++- .../rockchip/rkvdec/rkvdec-hevc-common.h | 73 +- .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 642 ++++++++++++++++++ .../media/platform/rockchip/rkvdec/rkvdec.c | 86 ++- .../media/platform/rockchip/rkvdec/rkvdec.h | 3 + 7 files changed, 1140 insertions(+), 15 deletions(-) create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
drivers/media/platform/rockchip/rkvdec/Kconfig +1 -0
@@ -8,6 +8,7 @@ config VIDEO_ROCKCHIP_VDEC select VIDEOBUF2_VMALLOC select V4L2_MEM2MEM_DEV select V4L2_H264 + select V4L2_HEVC select V4L2_VP9 help Support for the Rockchip Video Decoder IP present on Rockchip SoCs,
drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
@@ -9,5 +9,6 @@ rockchip-vdec-y += \ rkvdec-hevc-common.o \ rkvdec-rcb.o \ rkvdec-vdpu381-h264.o \ + rkvdec-vdpu381-hevc.o \ rkvdec-vdpu383-h264.o \ rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +342 -7
383 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h +66 -7
91 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c new file +642 -0
642 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec.c +85 -1
110 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec.h +3 -0
@@ -160,6 +160,8 @@ struct rkvdec_ctx {struct rkvdec_rcb_config *rcb_config;u32 colmv_offset;void *priv; + u8 has_sps_st_rps: 1; + u8 has_sps_lt_rps: 1; };static inline struct rkvdec_ctx *file_to_rkvdec_ctx (struct file *filp)
@@ -192,6 +194,7 @@ extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops;/* VDPU381 ops */ extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops; +extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_hevc_fmt_ops;/* VDPU383 ops */ extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops;
Signature · 1 line
2.52.0
Re: [PATCH v6 16/17] media: rkvdec: Add HEVC support for the VDPU381 variant
Hi Detlev,
Quoted 28 lines · Detlev Casanova
The VDPU381 supports HEVC decoding up to 7680x4320@30fps. It could double that when using both decoder cores.
It support YUV420 (8 and 10 bits) as well as AFBC (not implemented here)
The fluster score is 146/147 for JCT-VC-HEVC_V1, tested on ROCK 5B. None of the other test suites works.
Reviewed-by Nicolas Dufresne <[email protected]>Signed-off-by Detlev Casanova <[email protected]>--- .../media/platform/rockchip/rkvdec/Kconfig | 1 + .../media/platform/rockchip/rkvdec/Makefile | 1 + .../rockchip/rkvdec/rkvdec-hevc-common.c | 349 +++++++++- .../rockchip/rkvdec/rkvdec-hevc-common.h | 73 +- .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 642 ++++++++++++++++++ .../media/platform/rockchip/rkvdec/rkvdec.c | 86 ++- .../media/platform/rockchip/rkvdec/rkvdec.h | 3 + 7 files changed, 1140 insertions(+), 15 deletions(-) create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.cdrivers/media/platform/rockchip/rkvdec/Kconfig +0
-0
drivers/media/platform/rockchip/rkvdec/Kconfig config VIDEO_ROCKCHIP_VDEC · line 11
Quoted 4 lines
drivers/media/platform/rockchip/rkvdec/Kconfig +1
-0@@ -8,6 +8,7 @@ config VIDEO_ROCKCHIP_VDEC select VIDEOBUF2_VMALLOC select V4L2_MEM2MEM_DEV select V4L2_H264 + select V4L2_HEVC
Should this be a separate fix or is this something needed after this patch ?
Quoted 66 lines
drivers/media/platform/rockchip/rkvdec/Kconfig +0
-0select V4L2_VP9 help Support for the Rockchip Video Decoder IP present on Rockchip SoCs,drivers/media/platform/rockchip/rkvdec/Makefile +1
-0@@ -9,5 +9,6 @@ rockchip-vdec-y += \ rkvdec-hevc-common.o \ rkvdec-rcb.o \ rkvdec-vdpu381-h264.o \ + rkvdec-vdpu381-hevc.o \ rkvdec-vdpu383-h264.o \ rkvdec-vp9.odrivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +44
-0@@ -21,6 +21,127 @@#include "rkvdec.h" #include "rkvdec-hevc-common.h" +#define RKVDEC_HEVC_MAX_DEPTH_IN_BYTES 2 + +/* Store the Short term ref pic set calculated values */ +struct calculated_rps_st_set { +u8 num_delta_pocs; +u8 num_negative_pics; +u8 num_positive_pics; +u8 used_by_curr_pic_s0[16 ]; +u8 used_by_curr_pic_s1[16 ]; +s32 delta_poc_s0[16 ]; +s32 delta_poc_s1[16 ]; +}; + +void compute_tiles_uniform (struct rkvdec_hevc_run *run,u16 log2_min_cb_size, +u16 width,u16 height,s32 pic_in_cts_width, +s32 pic_in_cts_height,u16 *column_width,u16 *row_height) +{ +const struct v4l2_ctrl_hevc_pps *pps = run->pps; +int i; + +for (i =0 ; i < pps->num_tile_columns_minus1 +1 ; i++) + column_width[i] = ((i +1 ) * pic_in_cts_width) / + (pps->num_tile_columns_minus1 +1 ) - + (i * pic_in_cts_width) / + (pps->num_tile_columns_minus1 +1 ); + +for (i =0 ; i < pps->num_tile_rows_minus1 +1 ; i++) + row_height[i] = ((i +1 ) * pic_in_cts_height) / + (pps->num_tile_rows_minus1 +1 ) - + (i * pic_in_cts_height) / + (pps->num_tile_rows_minus1 +1 ); +} + +void compute_tiles_non_uniform (struct rkvdec_hevc_run *run,u16 log2_min_cb_size, +u16 width,u16 height,s32 pic_in_cts_width, +s32 pic_in_cts_height,u16 *column_width,u16 *row_height) +{ +const struct v4l2_ctrl_hevc_pps *pps = run->pps; +s32 sum =0 ; +int i; + +for (i =0 ; i < pps->num_tile_columns_minus1; i++) { + column_width[i] = pps->column_width_minus1[i] +1 ; + sum += column_width[i];
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c line 77
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +10
-0+ } + column_width[i] = pic_in_cts_width - sum; + + sum =0 ; +for (i =0 ; i < pps->num_tile_rows_minus1; i++) { + row_height[i] = pps->row_height_minus1[i] +1 ; + sum += row_height[i]; + } + row_height[i] = pic_in_cts_height - sum; +}
Would probably be good if the existing rkvdec hevc also is changed to used these two tiles helpers.
Quoted 80 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +68
-1+ +static void set_ref_poc (struct rkvdec_rps_short_term_ref_set *set,int poc,int value,int flag) +{ +switch (poc) { +case 0 : + set->delta_poc0 = value; + set->used_flag0 = flag; +break ; +case 1 : + set->delta_poc1 = value; + set->used_flag1 = flag; +break ; +case 2 : + set->delta_poc2 = value; + set->used_flag2 = flag; +break ; +case 3 : + set->delta_poc3 = value; + set->used_flag3 = flag; +break ; +case 4 : + set->delta_poc4 = value; + set->used_flag4 = flag; +break ; +case 5 : + set->delta_poc5 = value; + set->used_flag5 = flag; +break ; +case 6 : + set->delta_poc6 = value; + set->used_flag6 = flag; +break ; +case 7 : + set->delta_poc7 = value; + set->used_flag7 = flag; +break ; +case 8 : + set->delta_poc8 = value; + set->used_flag8 = flag; +break ; +case 9 : + set->delta_poc9 = value; + set->used_flag9 = flag; +break ; +case 10 : + set->delta_poc10 = value; + set->used_flag10 = flag; +break ; +case 11 : + set->delta_poc11 = value; + set->used_flag11 = flag; +break ; +case 12 : + set->delta_poc12 = value; + set->used_flag12 = flag; +break ; +case 13 : + set->delta_poc13 = value; + set->used_flag13 = flag; +break ; +case 14 : + set->delta_poc14 = value; + set->used_flag14 = flag; +break ; + } +} +/* * Flip one or more matrices along their main diagonal and flatten them * before writing it to the memory. @@ -105,7 +226,7 @@ static void translate_scaling_list(struct scaling_factor *output, }void rkvdec_hevc_assemble_hw_scaling_list (struct rkvdec_hevc_run *run, -struct scaling_factor *scaling_factor, +struct scaling_factor *scaling_list,struct v4l2_ctrl_hevc_scaling_matrix *cache) {const struct v4l2_ctrl_hevc_scaling_matrix *scaling = run->scaling_matrix;
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_hevc_run *run, · line 238
Quoted 5 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +1
-1@@ -114,15 +235,220 @@ void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_hevc_run *run, sizeof(struct v4l2_ctrl_hevc_scaling_matrix))) return; -translate_scaling_list (scaling_factor, scaling); +translate_scaling_list (scaling_list, scaling);
nit: Any reason for this rename ? Maybe move code style cleanup to a prerequisite patch ?
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_hevc_run *run, · line 125
Quoted 8 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +0
-3memcpy (cache, scaling,sizeof (struct v4l2_ctrl_hevc_scaling_matrix )); } -struct vb2_buffer * -get_ref_buf (struct rkvdec_ctx *ctx,struct rkvdec_hevc_run *run, -unsigned int dpb_idx)
nit: It does not seem to be a change introduced here, please move code style cleanup to a separate patch.
Quoted 198 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +198
-0+static void rkvdec_hevc_assemble_hw_lt_rps (struct rkvdec_hevc_run *run,struct rkvdec_rps *rps) +{ +const struct v4l2_ctrl_hevc_sps *sps = run->sps; + +if (!run->ext_sps_lt_rps) +return ; + +for (int i =0 ; i < sps->num_long_term_ref_pics_sps; i++) { + rps->refs[i].lt_ref_pic_poc_lsb = + run->ext_sps_lt_rps[i].lt_ref_pic_poc_lsb_sps; + rps->refs[i].used_by_curr_pic_lt_flag = + !!(run->ext_sps_lt_rps[i].flags &V4L2_HEVC_EXT_SPS_LT_RPS_FLAG_USED_LT ); + } +} + +static void rkvdec_hevc_assemble_hw_st_rps (struct rkvdec_hevc_run *run,struct rkvdec_rps *rps, +struct calculated_rps_st_set *calculated_rps_st_sets) +{ +const struct v4l2_ctrl_hevc_sps *sps = run->sps; + +for (int i =0 ; i < sps->num_short_term_ref_pic_sets; i++) { +int poc =0 ; +int j =0 ; +const struct calculated_rps_st_set *set = &calculated_rps_st_sets[i]; + + rps->short_term_ref_sets[i].num_negative = set->num_negative_pics; + rps->short_term_ref_sets[i].num_positive = set->num_positive_pics; + +for (; j < set->num_negative_pics; j++) { +set_ref_poc (&rps->short_term_ref_sets[i], j, + set->delta_poc_s0[j], set->used_by_curr_pic_s0[j]); + } + poc = j; + +for (j =0 ; j < set->num_positive_pics; j++) { +set_ref_poc (&rps->short_term_ref_sets[i], poc + j, + set->delta_poc_s1[j], set->used_by_curr_pic_s1[j]); + } + } +} + +/* +* Compute the short term ref pic set parameters based on its reference short term ref pic +*/ +static void st_ref_pic_set_prediction (struct rkvdec_hevc_run *run,int idx, +struct calculated_rps_st_set *calculated_rps_st_sets) +{ +const struct v4l2_ctrl_hevc_ext_sps_st_rps *rps_data = &run->ext_sps_st_rps[idx]; +struct calculated_rps_st_set *st_rps = &calculated_rps_st_sets[idx]; +struct calculated_rps_st_set *ref_rps; +u8 st_rps_idx = idx; +u8 ref_rps_idx =0 ; +s16 delta_rps =0 ; +u8 use_delta_flag[16 ] = {0 }; +u8 used_by_curr_pic_flag[16 ] = {0 }; +int i, j; +int dPoc; + + ref_rps_idx = st_rps_idx - (rps_data->delta_idx_minus1 +1 );/* 7-59 */ + delta_rps = (1 -2 * rps_data->delta_rps_sign) * + (rps_data->abs_delta_rps_minus1 +1 );/* 7-60 */ + + ref_rps = &calculated_rps_st_sets[ref_rps_idx]; + +for (j =0 ; j <= ref_rps->num_delta_pocs; j++) { + used_by_curr_pic_flag[j] = !!(rps_data->used_by_curr_pic & (1 << j)); + use_delta_flag[j] = !!(rps_data->use_delta_flag & (1 << j)); + } + +/* 7-61: calculate num_negative_pics, delta_poc_s0 and used_by_curr_pic_s0 */ + i =0 ; +for (j = (ref_rps->num_positive_pics -1 ); j >=0 ; j--) { + dPoc = ref_rps->delta_poc_s1[j] + delta_rps; +if (dPoc <0 && use_delta_flag[ref_rps->num_negative_pics + j]) { + st_rps->delta_poc_s0[i] = dPoc; + st_rps->used_by_curr_pic_s0[i++] = + used_by_curr_pic_flag[ref_rps->num_negative_pics + j]; + } + } +if (delta_rps <0 && use_delta_flag[ref_rps->num_delta_pocs]) { + st_rps->delta_poc_s0[i] = delta_rps; + st_rps->used_by_curr_pic_s0[i++] = used_by_curr_pic_flag[ref_rps->num_delta_pocs]; + } +for (j =0 ; j < ref_rps->num_negative_pics; j++) { + dPoc = ref_rps->delta_poc_s0[j] + delta_rps; +if (dPoc <0 && use_delta_flag[j]) { + st_rps->delta_poc_s0[i] = dPoc; + st_rps->used_by_curr_pic_s0[i++] = used_by_curr_pic_flag[j]; + } + } + st_rps->num_negative_pics = i; + +/* 7-62: calculate num_positive_pics, delta_poc_s1 and used_by_curr_pic_s1 */ + i =0 ; +for (j = (ref_rps->num_negative_pics -1 ); j >=0 ; j--) { + dPoc = ref_rps->delta_poc_s0[j] + delta_rps; +if (dPoc >0 && use_delta_flag[j]) { + st_rps->delta_poc_s1[i] = dPoc; + st_rps->used_by_curr_pic_s1[i++] = used_by_curr_pic_flag[j]; + } + } +if (delta_rps >0 && use_delta_flag[ref_rps->num_delta_pocs]) { + st_rps->delta_poc_s1[i] = delta_rps; + st_rps->used_by_curr_pic_s1[i++] = used_by_curr_pic_flag[ref_rps->num_delta_pocs]; + } +for (j =0 ; j < ref_rps->num_positive_pics; j++) { + dPoc = ref_rps->delta_poc_s1[j] + delta_rps; +if (dPoc >0 && use_delta_flag[ref_rps->num_negative_pics + j]) { + st_rps->delta_poc_s1[i] = dPoc; + st_rps->used_by_curr_pic_s1[i++] = + used_by_curr_pic_flag[ref_rps->num_negative_pics + j]; + } + } + st_rps->num_positive_pics = i; + + st_rps->num_delta_pocs = st_rps->num_positive_pics + st_rps->num_negative_pics; +} + +/* +* Compute the short term ref pic set parameters based on the control's data. +*/ +static void st_ref_pic_set_calculate (struct rkvdec_hevc_run *run,int idx, +struct calculated_rps_st_set *calculated_rps_st_sets) +{ +const struct v4l2_ctrl_hevc_ext_sps_st_rps *rps_data = &run->ext_sps_st_rps[idx]; +struct calculated_rps_st_set *st_rps = &calculated_rps_st_sets[idx]; +int j, i =0 ; + +/* 7-63 */ + st_rps->num_negative_pics = rps_data->num_negative_pics; +/* 7-64 */ + st_rps->num_positive_pics = rps_data->num_positive_pics; + +for (i =0 ; i < st_rps->num_negative_pics; i++) { +/* 7-65 */ + st_rps->used_by_curr_pic_s0[i] = !!(rps_data->used_by_curr_pic & (1 << i)); + +if (i ==0 ) { +/* 7-67 */ + st_rps->delta_poc_s0[i] = -(rps_data->delta_poc_s0_minus1[i] +1 ); + }else { +/* 7-69 */ + st_rps->delta_poc_s0[i] = + st_rps->delta_poc_s0[i -1 ] - + (rps_data->delta_poc_s0_minus1[i] +1 ); + } + } + +for (j =0 ; j < st_rps->num_positive_pics; j++) { +/* 7-66 */ + st_rps->used_by_curr_pic_s1[j] = !!(rps_data->used_by_curr_pic & (1 << (i + j))); + +if (j ==0 ) { +/* 7-68 */ + st_rps->delta_poc_s1[j] = rps_data->delta_poc_s1_minus1[j] +1 ; + }else { +/* 7-70 */ + st_rps->delta_poc_s1[j] = + st_rps->delta_poc_s1[j -1 ] + + (rps_data->delta_poc_s1_minus1[j] +1 ); + } + } + +/* 7-71 */ + st_rps->num_delta_pocs = st_rps->num_positive_pics + st_rps->num_negative_pics; +} + +static void rkvdec_hevc_prepare_hw_st_rps (struct rkvdec_hevc_run *run,struct rkvdec_rps *rps, +struct v4l2_ctrl_hevc_ext_sps_st_rps *cache) +{ +int idx; + +if (!run->ext_sps_st_rps) +return ; + +if (!memcmp (cache, run->ext_sps_st_rps,sizeof (struct v4l2_ctrl_hevc_ext_sps_st_rps ))) +return ; + +struct calculated_rps_st_set *calculated_rps_st_sets = +kzalloc (sizeof (struct calculated_rps_st_set ) * + run->sps->num_short_term_ref_pic_sets,GFP_KERNEL ); + +for (idx =0 ; idx < run->sps->num_short_term_ref_pic_sets; idx++) { +const struct v4l2_ctrl_hevc_ext_sps_st_rps *rps_data = &run->ext_sps_st_rps[idx]; + +if (rps_data->flags &V4L2_HEVC_EXT_SPS_ST_RPS_FLAG_INTER_REF_PIC_SET_PRED ) +st_ref_pic_set_prediction (run, idx, calculated_rps_st_sets); +else +st_ref_pic_set_calculate (run, idx, calculated_rps_st_sets); + } + +rkvdec_hevc_assemble_hw_st_rps (run, rps, calculated_rps_st_sets); + +kfree (calculated_rps_st_sets); + +memcpy (cache, run->ext_sps_st_rps,sizeof (struct v4l2_ctrl_hevc_ext_sps_st_rps )); +} +
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_hevc_run *run, · line 451
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +10
-0+void rkvdec_hevc_assemble_hw_rps (struct rkvdec_hevc_run *run,struct rkvdec_rps *rps, +struct v4l2_ctrl_hevc_ext_sps_st_rps *st_cache) +{ +rkvdec_hevc_prepare_hw_st_rps (run, rps, st_cache); +rkvdec_hevc_assemble_hw_lt_rps (run, rps); +} + +struct vb2_buffer *get_ref_buf (struct rkvdec_ctx *ctx, +struct rkvdec_hevc_run *run, +unsigned int dpb_idx)
nit: Any reason why formating of this function declaration is changed ?
Quoted 98 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +11
-2{struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx;const struct v4l2_ctrl_hevc_decode_params *decode_params = run->decode_params;@@ -143,8 +469,6 @@ get_ref_buf(struct rkvdec_ctx *ctx, struct rkvdec_hevc_run *run,return buf; } -#define RKVDEC_HEVC_MAX_DEPTH_IN_BYTES 2 -int rkvdec_hevc_adjust_fmt (struct rkvdec_ctx *ctx,struct v4l2_format *f) {struct v4l2_pix_format_mplane *fmt = &f->fmt.pix_mp;@@ -178,5 +502,16 @@ void rkvdec_hevc_run_preamble(struct rkvdec_ctx *ctx, V4L2_CID_STATELESS_HEVC_SCALING_MATRIX); run->scaling_matrix = ctrl ? ctrl->p_cur.p :NULL ; +if (ctx->has_sps_st_rps) { + ctrl =v4l2_ctrl_find (&ctx->ctrl_hdl, +V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS ); + run->ext_sps_st_rps = ctrl ? ctrl->p_cur.p :NULL ; + } +if (ctx->has_sps_lt_rps) { + ctrl =v4l2_ctrl_find (&ctx->ctrl_hdl, +V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS ); + run->ext_sps_lt_rps = ctrl ? ctrl->p_cur.p :NULL ; + } +rkvdec_run_preamble (ctx, &run->base); }drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h +49
-6@@ -16,19 +16,70 @@*/ #include <media/v4l2-mem2mem.h> +#include <linux/types.h> #include "rkvdec.h" #define RKV_HEVC_CABAC_TABLE_SIZE 27456extern const u8 rkvdec_hevc_cabac_table[RKV_HEVC_CABAC_TABLE_SIZE ]; +struct rkvdec_rps_refs { +u16 lt_ref_pic_poc_lsb; +u16 used_by_curr_pic_lt_flag :1 ; +u16 reserved :15 ; +} __packed; + +struct rkvdec_rps_short_term_ref_set { +u32 num_negative :4 ; +u32 num_positive :4 ; +u32 delta_poc0 :16 ; +u32 used_flag0 :1 ; +u32 delta_poc1 :16 ; +u32 used_flag1 :1 ; +u32 delta_poc2 :16 ; +u32 used_flag2 :1 ; +u32 delta_poc3 :16 ; +u32 used_flag3 :1 ; +u32 delta_poc4 :16 ; +u32 used_flag4 :1 ; +u32 delta_poc5 :16 ; +u32 used_flag5 :1 ; +u32 delta_poc6 :16 ; +u32 used_flag6 :1 ; +u32 delta_poc7 :16 ; +u32 used_flag7 :1 ; +u32 delta_poc8 :16 ; +u32 used_flag8 :1 ; +u32 delta_poc9 :16 ; +u32 used_flag9 :1 ; +u32 delta_poc10 :16 ; +u32 used_flag10 :1 ; +u32 delta_poc11 :16 ; +u32 used_flag11 :1 ; +u32 delta_poc12 :16 ; +u32 used_flag12 :1 ; +u32 delta_poc13 :16 ; +u32 used_flag13 :1 ; +u32 delta_poc14 :16 ; +u32 used_flag14 :1 ; +u32 reserved_bits :25 ; +u32 reserved[3 ]; +} __packed; + +struct rkvdec_rps { +struct rkvdec_rps_refs refs[32 ]; +struct rkvdec_rps_short_term_ref_set short_term_ref_sets[64 ]; +} __packed; +struct rkvdec_hevc_run { -struct rkvdec_run base; -const struct v4l2_ctrl_hevc_slice_params *slices_params; -const struct v4l2_ctrl_hevc_decode_params *decode_params; -const struct v4l2_ctrl_hevc_sps *sps; -const struct v4l2_ctrl_hevc_pps *pps; -const struct v4l2_ctrl_hevc_scaling_matrix *scaling_matrix;
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h line 82
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h +9
-1-int num_slices; +struct rkvdec_run base; +const struct v4l2_ctrl_hevc_decode_params *decode_params; +const struct v4l2_ctrl_hevc_slice_params *slices_params; +const struct v4l2_ctrl_hevc_sps *sps; +const struct v4l2_ctrl_hevc_pps *pps; +const struct v4l2_ctrl_hevc_scaling_matrix *scaling_matrix; +const struct v4l2_ctrl_hevc_ext_sps_st_rps *ext_sps_st_rps; +const struct v4l2_ctrl_hevc_ext_sps_lt_rps *ext_sps_lt_rps; +int num_slices;
nit: Any reason for this format change in code ? Does not match other structs.
Quoted 530 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h +8
-0};struct scaling_factor {@@ -38,6 +89,14 @@ struct scaling_factor {u8 reserved[4 ];/*16Bytes align*/ }; +void compute_tiles_uniform (struct rkvdec_hevc_run *run,u16 log2_min_cb_size, +u16 width,u16 height,s32 pic_in_cts_width, +s32 pic_in_cts_height,u16 *column_width,u16 *row_height); +void compute_tiles_non_uniform (struct rkvdec_hevc_run *run,u16 log2_min_cb_size, +u16 width,u16 height,s32 pic_in_cts_width, +s32 pic_in_cts_height,u16 *column_width,u16 *row_height); +void rkvdec_hevc_assemble_hw_rps (struct rkvdec_hevc_run *run,struct rkvdec_rps *rps, +struct v4l2_ctrl_hevc_ext_sps_st_rps *st_cache);void rkvdec_hevc_assemble_hw_scaling_list (struct rkvdec_hevc_run *run,struct scaling_factor *scaling_factor,struct v4l2_ctrl_hevc_scaling_matrix *cache);drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c new file +506
-0@@ -0,0 +1,642 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Rockchip VDPU381 HEVC backend +* +* Copyright (C) 2025 Collabora, Ltd. +* Detlev Casanova <[email protected]> +*/ + +#include <media/v4l2-mem2mem.h> + +#include "rkvdec.h" +#include "rkvdec-rcb.h" +#include "rkvdec-hevc-common.h" +#include "rkvdec-vdpu381-regs.h" + +// SPS +struct rkvdec_hevc_sps { +u16 video_parameters_set_id :4 ; +u16 seq_parameters_set_id_sps :4 ; +u16 chroma_format_idc :2 ; +u16 width :16 ; +u16 height :16 ; +u16 bit_depth_luma :4 ; +u16 bit_depth_chroma :4 ; +u16 max_pic_order_count_lsb :5 ; +u16 diff_max_min_luma_coding_block_size :2 ; +u16 min_luma_coding_block_size :3 ; +u16 min_transform_block_size :3 ; +u16 diff_max_min_transform_block_size :2 ; +u16 max_transform_hierarchy_depth_inter :3 ; +u16 max_transform_hierarchy_depth_intra :3 ; +u16 scaling_list_enabled_flag :1 ; +u16 amp_enabled_flag :1 ; +u16 sample_adaptive_offset_enabled_flag :1 ; +u16 pcm_enabled_flag :1 ; +u16 pcm_sample_bit_depth_luma :4 ; +u16 pcm_sample_bit_depth_chroma :4 ; +u16 pcm_loop_filter_disabled_flag :1 ; +u16 diff_max_min_pcm_luma_coding_block_size :3 ; +u16 min_pcm_luma_coding_block_size :3 ; +u16 num_short_term_ref_pic_sets :7 ; +u16 long_term_ref_pics_present_flag :1 ; +u16 num_long_term_ref_pics_sps :6 ; +u16 sps_temporal_mvp_enabled_flag :1 ; +u16 strong_intra_smoothing_enabled_flag :1 ; +u16 reserved_0 :7 ; +u16 sps_max_dec_pic_buffering_minus1 :4 ; +u16 reserved_0_2 :3 ; +u16 reserved_f :8 ; +} __packed; + +//PPS +struct rkvdec_hevc_pps { +u16 picture_parameters_set_id :6 ; +u16 seq_parameters_set_id_pps :4 ; +u16 dependent_slice_segments_enabled_flag :1 ; +u16 output_flag_present_flag :1 ; +u16 num_extra_slice_header_bits :13 ; +u16 sign_data_hiding_enabled_flag :1 ; +u16 cabac_init_present_flag :1 ; +u16 num_ref_idx_l0_default_active :4 ; +u16 num_ref_idx_l1_default_active :4 ; +u16 init_qp_minus26 :7 ; +u16 constrained_intra_pred_flag :1 ; +u16 transform_skip_enabled_flag :1 ; +u16 cu_qp_delta_enabled_flag :1 ; +u16 log2_min_cb_size :3 ; +u16 pps_cb_qp_offset :5 ; +u16 pps_cr_qp_offset :5 ; +u16 pps_slice_chroma_qp_offsets_present_flag :1 ; +u16 weighted_pred_flag :1 ; +u16 weighted_bipred_flag :1 ; +u16 transquant_bypass_enabled_flag :1 ; +u16 tiles_enabled_flag :1 ; +u16 entropy_coding_sync_enabled_flag :1 ; +u16 pps_loop_filter_across_slices_enabled_flag :1 ; +u16 loop_filter_across_tiles_enabled_flag :1 ; +u16 deblocking_filter_override_enabled_flag :1 ; +u16 pps_deblocking_filter_disabled_flag :1 ; +u16 pps_beta_offset_div2 :4 ; +u16 pps_tc_offset_div2 :4 ; +u16 lists_modification_present_flag :1 ; +u16 log2_parallel_merge_level :3 ; +u16 slice_segment_header_extension_present_flag :1 ; +u16 zeroes :3 ; +u16 num_tile_columns :5 ; +u16 num_tile_rows :5 ; +u16 sps_pps_mode :4 ; +u16 reserved_bits :14 ; +u16 reserved; +} __packed; + +struct rkvdec_hevc_tile { +u16 value0 :12 ; +u16 value1 :12 ; +} __packed; + +struct rkvdec_sps_pps_packet { +struct rkvdec_hevc_sps sps; +struct rkvdec_hevc_pps pps; +struct rkvdec_hevc_tile column_width[10 ]; +struct rkvdec_hevc_tile row_height[11 ]; +u32 zeroes[3 ]; +u32 zeroes_bits :6 ; +u32 padding_bits :2 ; +u32 padding; +} __packed; + +struct rkvdec_hevc_priv_tbl { +struct rkvdec_sps_pps_packet param_set[64 ]; +struct rkvdec_rps rps; +struct scaling_factor scaling_list; +u8 cabac_table[27456 ]; +}; + +struct rkvdec_hevc_ctx { +struct rkvdec_aux_buf priv_tbl; +struct v4l2_ctrl_hevc_scaling_matrix scaling_matrix_cache; +struct v4l2_ctrl_hevc_ext_sps_st_rps st_cache; +struct rkvdec_vdpu381_regs_hevc regs; +}; + +static void assemble_hw_pps (struct rkvdec_ctx *ctx, +struct rkvdec_hevc_run *run) +{ +struct rkvdec_hevc_ctx *hevc_ctx = ctx->priv; +const struct v4l2_ctrl_hevc_sps *sps = run->sps; +const struct v4l2_ctrl_hevc_pps *pps = run->pps; +struct rkvdec_hevc_priv_tbl *priv_tbl = hevc_ctx->priv_tbl.cpu; +struct rkvdec_sps_pps_packet *hw_ps; +bool tiles_enabled; +s32 max_cu_width; +s32 pic_in_cts_width; +s32 pic_in_cts_height; +u16 log2_min_cb_size, width, height; +u16 column_width[20 ]; +u16 row_height[22 ]; +u8 pcm_enabled; +u32 i; + +/* +* HW read the SPS/PPS information from PPS packet index by PPS id. +* offset from the base can be calculated by PPS_id * 32 (size per PPS +* packet unit). so the driver copy SPS/PPS information to the exact PPS +* packet unit for HW accessing. +*/ + hw_ps = &priv_tbl->param_set[pps->pic_parameter_set_id]; +memset (hw_ps,0 ,sizeof (*hw_ps)); + +/* write sps */ + hw_ps->sps.video_parameters_set_id = sps->video_parameter_set_id; + hw_ps->sps.seq_parameters_set_id_sps = sps->seq_parameter_set_id; + hw_ps->sps.chroma_format_idc = sps->chroma_format_idc; + + log2_min_cb_size = sps->log2_min_luma_coding_block_size_minus3 +3 ; + width = sps->pic_width_in_luma_samples; + height = sps->pic_height_in_luma_samples; + hw_ps->sps.width = width; + hw_ps->sps.height = height; + hw_ps->sps.bit_depth_luma = sps->bit_depth_luma_minus8 +8 ; + hw_ps->sps.bit_depth_chroma = sps->bit_depth_chroma_minus8 +8 ; + hw_ps->sps.max_pic_order_count_lsb = sps->log2_max_pic_order_cnt_lsb_minus4 +4 ; + hw_ps->sps.diff_max_min_luma_coding_block_size = + sps->log2_diff_max_min_luma_coding_block_size; + hw_ps->sps.min_luma_coding_block_size = sps->log2_min_luma_coding_block_size_minus3 +3 ; + hw_ps->sps.min_transform_block_size = sps->log2_min_luma_transform_block_size_minus2 +2 ; + hw_ps->sps.diff_max_min_transform_block_size = + sps->log2_diff_max_min_luma_transform_block_size; + hw_ps->sps.max_transform_hierarchy_depth_inter = sps->max_transform_hierarchy_depth_inter; + hw_ps->sps.max_transform_hierarchy_depth_intra = sps->max_transform_hierarchy_depth_intra; + hw_ps->sps.scaling_list_enabled_flag = + !!(sps->flags &V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED ); + hw_ps->sps.amp_enabled_flag = !!(sps->flags &V4L2_HEVC_SPS_FLAG_AMP_ENABLED ); + hw_ps->sps.sample_adaptive_offset_enabled_flag = + !!(sps->flags &V4L2_HEVC_SPS_FLAG_SAMPLE_ADAPTIVE_OFFSET ); + + pcm_enabled = !!(sps->flags &V4L2_HEVC_SPS_FLAG_PCM_ENABLED ); + hw_ps->sps.pcm_enabled_flag = pcm_enabled; + hw_ps->sps.pcm_sample_bit_depth_luma = + pcm_enabled ? sps->pcm_sample_bit_depth_luma_minus1 +1 :0 ; + hw_ps->sps.pcm_sample_bit_depth_chroma = + pcm_enabled ? sps->pcm_sample_bit_depth_chroma_minus1 +1 :0 ; + hw_ps->sps.pcm_loop_filter_disabled_flag = + !!(sps->flags &V4L2_HEVC_SPS_FLAG_PCM_LOOP_FILTER_DISABLED ); + hw_ps->sps.diff_max_min_pcm_luma_coding_block_size = + sps->log2_diff_max_min_pcm_luma_coding_block_size; + hw_ps->sps.min_pcm_luma_coding_block_size = + pcm_enabled ? sps->log2_min_pcm_luma_coding_block_size_minus3 +3 :0 ; + hw_ps->sps.num_short_term_ref_pic_sets = sps->num_short_term_ref_pic_sets; + hw_ps->sps.long_term_ref_pics_present_flag = + !!(sps->flags &V4L2_HEVC_SPS_FLAG_LONG_TERM_REF_PICS_PRESENT ); + hw_ps->sps.num_long_term_ref_pics_sps = sps->num_long_term_ref_pics_sps; + hw_ps->sps.sps_temporal_mvp_enabled_flag = + !!(sps->flags &V4L2_HEVC_SPS_FLAG_SPS_TEMPORAL_MVP_ENABLED ); + hw_ps->sps.strong_intra_smoothing_enabled_flag = + !!(sps->flags &V4L2_HEVC_SPS_FLAG_STRONG_INTRA_SMOOTHING_ENABLED ); + hw_ps->sps.sps_max_dec_pic_buffering_minus1 = sps->sps_max_dec_pic_buffering_minus1; + hw_ps->sps.reserved_f =0xff ; + +/* write pps */ + hw_ps->pps.picture_parameters_set_id = pps->pic_parameter_set_id; + hw_ps->pps.seq_parameters_set_id_pps = sps->seq_parameter_set_id; + hw_ps->pps.dependent_slice_segments_enabled_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_DEPENDENT_SLICE_SEGMENT_ENABLED ); + hw_ps->pps.output_flag_present_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_OUTPUT_FLAG_PRESENT ); + hw_ps->pps.num_extra_slice_header_bits = pps->num_extra_slice_header_bits; + hw_ps->pps.sign_data_hiding_enabled_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_SIGN_DATA_HIDING_ENABLED ); + hw_ps->pps.cabac_init_present_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_CABAC_INIT_PRESENT ); + hw_ps->pps.num_ref_idx_l0_default_active = pps->num_ref_idx_l0_default_active_minus1 +1 ; + hw_ps->pps.num_ref_idx_l1_default_active = pps->num_ref_idx_l1_default_active_minus1 +1 ; + hw_ps->pps.init_qp_minus26 = pps->init_qp_minus26; + hw_ps->pps.constrained_intra_pred_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_CONSTRAINED_INTRA_PRED ); + hw_ps->pps.transform_skip_enabled_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_TRANSFORM_SKIP_ENABLED ); + hw_ps->pps.cu_qp_delta_enabled_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_CU_QP_DELTA_ENABLED ); + hw_ps->pps.log2_min_cb_size = log2_min_cb_size + + sps->log2_diff_max_min_luma_coding_block_size - + pps->diff_cu_qp_delta_depth; + hw_ps->pps.pps_cb_qp_offset = pps->pps_cb_qp_offset; + hw_ps->pps.pps_cr_qp_offset = pps->pps_cr_qp_offset; + hw_ps->pps.pps_slice_chroma_qp_offsets_present_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_PPS_SLICE_CHROMA_QP_OFFSETS_PRESENT ); + hw_ps->pps.weighted_pred_flag = !!(pps->flags &V4L2_HEVC_PPS_FLAG_WEIGHTED_PRED ); + hw_ps->pps.weighted_bipred_flag = !!(pps->flags &V4L2_HEVC_PPS_FLAG_WEIGHTED_BIPRED ); + hw_ps->pps.transquant_bypass_enabled_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_TRANSQUANT_BYPASS_ENABLED ); + + tiles_enabled = !!(pps->flags &V4L2_HEVC_PPS_FLAG_TILES_ENABLED ); + hw_ps->pps.tiles_enabled_flag = tiles_enabled; + hw_ps->pps.entropy_coding_sync_enabled_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_ENTROPY_CODING_SYNC_ENABLED ); + hw_ps->pps.pps_loop_filter_across_slices_enabled_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_PPS_LOOP_FILTER_ACROSS_SLICES_ENABLED ); + hw_ps->pps.loop_filter_across_tiles_enabled_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_LOOP_FILTER_ACROSS_TILES_ENABLED ); + hw_ps->pps.deblocking_filter_override_enabled_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_OVERRIDE_ENABLED ); + hw_ps->pps.pps_deblocking_filter_disabled_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER ); + hw_ps->pps.pps_beta_offset_div2 = pps->pps_beta_offset_div2; + hw_ps->pps.pps_tc_offset_div2 = pps->pps_tc_offset_div2; + hw_ps->pps.lists_modification_present_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT ); + hw_ps->pps.log2_parallel_merge_level = pps->log2_parallel_merge_level_minus2 +2 ; + hw_ps->pps.slice_segment_header_extension_present_flag = + !!(pps->flags &V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT ); + hw_ps->pps.num_tile_columns = tiles_enabled ? pps->num_tile_columns_minus1 +1 :0 ; + hw_ps->pps.num_tile_rows = tiles_enabled ? pps->num_tile_rows_minus1 +1 :0 ; + hw_ps->pps.sps_pps_mode =0 ; + hw_ps->pps.reserved_bits =0x3fff ; + hw_ps->pps.reserved =0xffff ; + +// Setup tiles information +memset (column_width,0 ,sizeof (column_width)); +memset (row_height,0 ,sizeof (row_height)); + + max_cu_width =1 << (sps->log2_diff_max_min_luma_coding_block_size + log2_min_cb_size); + pic_in_cts_width = (width + max_cu_width -1 ) / max_cu_width; + pic_in_cts_height = (height + max_cu_width -1 ) / max_cu_width; + +if (pps->flags &V4L2_HEVC_PPS_FLAG_TILES_ENABLED ) { +if (pps->flags &V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING ) { +compute_tiles_uniform (run, log2_min_cb_size, width, height, + pic_in_cts_width, pic_in_cts_height, + column_width, row_height); + }else { +compute_tiles_non_uniform (run, log2_min_cb_size, width, height, + pic_in_cts_width, pic_in_cts_height, + column_width, row_height); + } + }else { + column_width[0 ] = (width + max_cu_width -1 ) / max_cu_width; + row_height[0 ] = (height + max_cu_width -1 ) / max_cu_width; + } + +for (i =0 ; i <20 ; i++) { +if (column_width[i] >0 ) + column_width[i]--; + +if (i &1 ) + hw_ps->column_width[i /2 ].value1 = column_width[i]; +else + hw_ps->column_width[i /2 ].value0 = column_width[i]; + } + +for (i =0 ; i <22 ; i++) { +if (row_height[i] >0 ) + row_height[i]--; + +if (i &1 ) + hw_ps->row_height[i /2 ].value1 = row_height[i]; +else + hw_ps->row_height[i /2 ].value0 = row_height[i]; + } + + hw_ps->padding =0xffffffff ; + hw_ps->padding_bits =0x3 ; +} + +static void set_ref_valid (struct rkvdec_vdpu381_regs_hevc *regs,int id,u32 valid) +{ +switch (id) { +case 0 : + regs->hevc_param.reg099.hevc_ref_valid_0 = valid; +break ; +case 1 : + regs->hevc_param.reg099.hevc_ref_valid_1 = valid; +break ; +case 2 : + regs->hevc_param.reg099.hevc_ref_valid_2 = valid; +break ; +case 3 : + regs->hevc_param.reg099.hevc_ref_valid_3 = valid; +break ; +case 4 : + regs->hevc_param.reg099.hevc_ref_valid_4 = valid; +break ; +case 5 : + regs->hevc_param.reg099.hevc_ref_valid_5 = valid; +break ; +case 6 : + regs->hevc_param.reg099.hevc_ref_valid_6 = valid; +break ; +case 7 : + regs->hevc_param.reg099.hevc_ref_valid_7 = valid; +break ; +case 8 : + regs->hevc_param.reg099.hevc_ref_valid_8 = valid; +break ; +case 9 : + regs->hevc_param.reg099.hevc_ref_valid_9 = valid; +break ; +case 10 : + regs->hevc_param.reg099.hevc_ref_valid_10 = valid; +break ; +case 11 : + regs->hevc_param.reg099.hevc_ref_valid_11 = valid; +break ; +case 12 : + regs->hevc_param.reg099.hevc_ref_valid_12 = valid; +break ; +case 13 : + regs->hevc_param.reg099.hevc_ref_valid_13 = valid; +break ; +case 14 : + regs->hevc_param.reg099.hevc_ref_valid_14 = valid; +break ; + } +} + +static void rkvdec_write_regs (struct rkvdec_ctx *ctx) +{ +struct rkvdec_dev *rkvdec = ctx->dev; +struct rkvdec_hevc_ctx *hevc_ctx = ctx->priv; + +rkvdec_memcpy_toio (rkvdec->regs +OFFSET_COMMON_REGS , + &hevc_ctx->regs.common, +sizeof (hevc_ctx->regs.common)); +rkvdec_memcpy_toio (rkvdec->regs +OFFSET_CODEC_PARAMS_REGS , + &hevc_ctx->regs.hevc_param, +sizeof (hevc_ctx->regs.hevc_param)); +rkvdec_memcpy_toio (rkvdec->regs +OFFSET_COMMON_ADDR_REGS , + &hevc_ctx->regs.common_addr, +sizeof (hevc_ctx->regs.common_addr)); +rkvdec_memcpy_toio (rkvdec->regs +OFFSET_CODEC_ADDR_REGS , + &hevc_ctx->regs.hevc_addr, +sizeof (hevc_ctx->regs.hevc_addr)); +rkvdec_memcpy_toio (rkvdec->regs +OFFSET_POC_HIGHBIT_REGS , + &hevc_ctx->regs.hevc_highpoc, +sizeof (hevc_ctx->regs.hevc_highpoc)); +} + +static void config_registers (struct rkvdec_ctx *ctx, +struct rkvdec_hevc_run *run) +{ +const struct v4l2_ctrl_hevc_decode_params *dec_params = run->decode_params; +const struct v4l2_hevc_dpb_entry *dpb = dec_params->dpb; +struct rkvdec_hevc_ctx *hevc_ctx = ctx->priv; +struct rkvdec_vdpu381_regs_hevc *regs = &hevc_ctx->regs; +dma_addr_t priv_start_addr = hevc_ctx->priv_tbl.dma; +const struct v4l2_pix_format_mplane *dst_fmt; +struct vb2_v4l2_buffer *src_buf = run->base.bufs.src; +struct vb2_v4l2_buffer *dst_buf = run->base.bufs.dst; +const struct v4l2_format *f; +dma_addr_t rlc_addr; +u32 hor_virstride =0 ; +u32 ver_virstride =0 ; +u32 y_virstride =0 ; +u32 offset; +u32 pixels; +dma_addr_t dst_addr; +u32 i; + +memset (regs,0 ,sizeof (*regs)); + +/* Set HEVC mode */ + regs->common.reg009.dec_mode =VDPU381_MODE_HEVC ; + +/* Set config */ + regs->common.reg011.buf_empty_en =1 ; + regs->common.reg011.dec_clkgate_e =1 ; + regs->common.reg011.dec_timeout_e =1 ; + regs->common.reg011.pix_range_detection_e =1 ; + +/* Set IDR flag */ + regs->common.reg013.cur_pic_is_idr = + !!(dec_params->flags &V4L2_HEVC_DECODE_PARAM_FLAG_IDR_PIC ); + +/* Set input stream length */ + regs->common.stream_len =vb2_get_plane_payload (&src_buf->vb2_buf,0 ); + +/* Set max slice number */ + regs->common.reg017.slice_num =1 ; + +/* Set strides */ + f = &ctx->decoded_fmt; + dst_fmt = &f->fmt.pix_mp; + hor_virstride = dst_fmt->plane_fmt[0 ].bytesperline; + ver_virstride = dst_fmt->height; + y_virstride = hor_virstride * ver_virstride; + pixels = dst_fmt->height * dst_fmt->width; + + regs->common.reg018.y_hor_virstride = hor_virstride /16 ; + regs->common.reg019.uv_hor_virstride = hor_virstride /16 ; + regs->common.reg020.y_virstride = y_virstride /16 ; + +/* Activate block gating */ + regs->common.reg026.swreg_block_gating_e =0xfffef ; + regs->common.reg026.reg_cfg_gating_en =1 ; + +/* Set timeout threshold */ +if (pixels <RKVDEC_1080P_PIXELS ) + regs->common.timeout_threshold = RKVDEC_TIMEOUT_1080p; +else if (pixels <RKVDEC_4K_PIXELS ) + regs->common.timeout_threshold =RKVDEC_TIMEOUT_4K ; +else if (pixels <RKVDEC_8K_PIXELS ) + regs->common.timeout_threshold =RKVDEC_TIMEOUT_8K ; + +/* Set POC val */ + regs->hevc_param.cur_top_poc = dec_params->pic_order_cnt_val; + +/* Set ref pic address & poc */ +for (i =0 ; i <ARRAY_SIZE (dec_params->dpb); i++) { +struct vb2_buffer *vb_buf =get_ref_buf (ctx, run, i); +dma_addr_t buf_dma =vb2_dma_contig_plane_dma_addr (vb_buf,0 ); +u32 valid = !!(dec_params->num_active_dpb_entries > i); + +/* Set reference addresses */ + regs->hevc_addr.ref_base[i] = buf_dma; + +/* Set COLMV addresses */ + regs->hevc_addr.colmv_base[i] = buf_dma + ctx->colmv_offset; + + regs->hevc_param.reg067_082_ref_poc[i] = + dpb[i].pic_order_cnt_val; + +set_ref_valid (regs, i, valid); + regs->hevc_param.reg103.ref_pic_layer_same_with_cur |=1 << i; + } + +/* Set rlc base address (input stream) */ + rlc_addr =vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,0 ); + regs->common_addr.rlc_base = rlc_addr; + regs->common_addr.rlcwrite_base = rlc_addr; + +/* Set output base address */ + dst_addr =vb2_dma_contig_plane_dma_addr (&dst_buf->vb2_buf,0 ); + regs->common_addr.decout_base = dst_addr; + regs->common_addr.error_ref_base = dst_addr; + +/* Set colmv address */ + regs->common_addr.colmv_cur_base = dst_addr + ctx->colmv_offset; + +/* Set RCB addresses */ +for (i =0 ; i <rkvdec_rcb_buf_count (ctx); i++) + regs->common_addr.rcb_base[i] =rkvdec_rcb_buf_dma_addr (ctx, i); + +/* Set hw pps address */ + offset = offsetof(struct rkvdec_hevc_priv_tbl , param_set); + regs->hevc_addr.pps_base = priv_start_addr + offset; + +/* Set hw rps address */ + offset = offsetof(struct rkvdec_hevc_priv_tbl , rps); + regs->hevc_addr.rps_base = priv_start_addr + offset; + +/* Set cabac table */ + offset = offsetof(struct rkvdec_hevc_priv_tbl , cabac_table); + regs->hevc_addr.cabactbl_base = priv_start_addr + offset; + +/* Set scaling matrix */ + offset = offsetof(struct rkvdec_hevc_priv_tbl , scaling_list); + regs->hevc_addr.scanlist_addr = priv_start_addr + offset; + +rkvdec_write_regs (ctx); +} + +static enum rkvdec_image_fmt rkvdec_hevc_get_image_fmt (struct rkvdec_ctx *ctx, +struct v4l2_ctrl *ctrl) +{ +const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps; +
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c line 516
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c new file +10
-0+if (ctrl->id !=V4L2_CID_STATELESS_HEVC_SPS ) +return RKVDEC_IMG_FMT_ANY ; + +if (sps->bit_depth_luma_minus8 ==0 ) +return RKVDEC_IMG_FMT_420_8BIT ; +else if (sps->bit_depth_luma_minus8 ==2 ) +return RKVDEC_IMG_FMT_420_10BIT ; + +return RKVDEC_IMG_FMT_ANY ; +}
There should not be a need for a dedicated version of this function.
You should probably move the existing rkvdec_hevc_get_image_fmt to common and use that version instead ?
Quoted 29 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c new file +29
-0+ +static int rkvdec_hevc_validate_sps (struct rkvdec_ctx *ctx, +const struct v4l2_ctrl_hevc_sps *sps) +{ +if (sps->chroma_format_idc !=1 ) +/* Only 4:2:0 is supported */ +return -EINVAL ; + +if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8) +/* Luma and chroma bit depth mismatch */ +return -EINVAL ; + +if (sps->bit_depth_luma_minus8 !=0 && sps->bit_depth_luma_minus8 !=2 ) +/* Only 8-bit and 10-bit are supported */ +return -EINVAL ; + +if (sps->pic_width_in_luma_samples > ctx->coded_fmt.fmt.pix_mp.width || + sps->pic_height_in_luma_samples > ctx->coded_fmt.fmt.pix_mp.height) +return -EINVAL ; + +return 0 ; +} + +static int rkvdec_hevc_start (struct rkvdec_ctx *ctx) +{ +struct rkvdec_dev *rkvdec = ctx->dev; +struct rkvdec_hevc_priv_tbl *priv_tbl; +struct rkvdec_hevc_ctx *hevc_ctx; +struct v4l2_ctrl *ctrl;
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c line 555
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c new file +10
-0+int ret; + + ctrl =v4l2_ctrl_find (&ctx->ctrl_hdl, +V4L2_CID_STATELESS_HEVC_SPS ); +if (!ctrl) +return -EINVAL ; + + ret =rkvdec_hevc_validate_sps (ctx, ctrl->p_new.p_hevc_sps); +if (ret) +return ret;
Same note as for h264, this validate sps should not be needed here.
Quoted 157 lines
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c new file +87
-0+ + hevc_ctx =kzalloc (sizeof (*hevc_ctx),GFP_KERNEL ); +if (!hevc_ctx) +return -ENOMEM ; + + priv_tbl =dma_alloc_coherent (rkvdec->dev,sizeof (*priv_tbl), + &hevc_ctx->priv_tbl.dma,GFP_KERNEL ); +if (!priv_tbl) { + ret = -ENOMEM ; + goto err_free_ctx; + } + + hevc_ctx->priv_tbl.size =sizeof (*priv_tbl); + hevc_ctx->priv_tbl.cpu = priv_tbl; +memcpy (priv_tbl->cabac_table, rkvdec_hevc_cabac_table, +sizeof (rkvdec_hevc_cabac_table)); + + ctx->priv = hevc_ctx; +return 0 ; + +err_free_ctx: +kfree (hevc_ctx); +return ret; +} + +static void rkvdec_hevc_stop (struct rkvdec_ctx *ctx) +{ +struct rkvdec_hevc_ctx *hevc_ctx = ctx->priv; +struct rkvdec_dev *rkvdec = ctx->dev; + +dma_free_coherent (rkvdec->dev, hevc_ctx->priv_tbl.size, + hevc_ctx->priv_tbl.cpu, hevc_ctx->priv_tbl.dma); +kfree (hevc_ctx); +} + +static int rkvdec_hevc_run (struct rkvdec_ctx *ctx) +{ +struct rkvdec_dev *rkvdec = ctx->dev; +struct rkvdec_hevc_run run; +struct rkvdec_hevc_ctx *hevc_ctx = ctx->priv; +struct rkvdec_hevc_priv_tbl *tbl = hevc_ctx->priv_tbl.cpu; + +rkvdec_hevc_run_preamble (ctx, &run); + +/* +* On vdpu381, not setting the long and short term ref sets will just output wrong frames. +* Let's just warn about it and let the decoder run anyway. +*/ +if ((!ctx->has_sps_lt_rps && run.sps->num_long_term_ref_pics_sps) || + (!ctx->has_sps_st_rps && run.sps->num_short_term_ref_pic_sets)) { +dev_warn_ratelimited (rkvdec->dev,"Long and short term RPS not set\n" ); + } + +rkvdec_hevc_assemble_hw_scaling_list (&run, + &tbl->scaling_list, + &hevc_ctx->scaling_matrix_cache); +assemble_hw_pps (ctx, &run); +rkvdec_hevc_assemble_hw_rps (&run, &tbl->rps, &hevc_ctx->st_cache); + +config_registers (ctx, &run); + +rkvdec_run_postamble (ctx, &run.base); + +schedule_delayed_work (&rkvdec->watchdog_work,msecs_to_jiffies (2000 )); + +/* Start decoding! */ +writel (VDPU381_DEC_E_BIT , rkvdec->regs +VDPU381_REG_DEC_E ); + +return 0 ; +} + +static int rkvdec_hevc_try_ctrl (struct rkvdec_ctx *ctx,struct v4l2_ctrl *ctrl) +{ +if (ctrl->id ==V4L2_CID_STATELESS_HEVC_SPS ) +return rkvdec_hevc_validate_sps (ctx, ctrl->p_new.p_hevc_sps); + +return 0 ; +} + +const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_hevc_fmt_ops = { + .adjust_fmt = rkvdec_hevc_adjust_fmt, + .start = rkvdec_hevc_start, + .stop = rkvdec_hevc_stop, + .run = rkvdec_hevc_run, + .try_ctrl = rkvdec_hevc_try_ctrl, + .get_image_fmt = rkvdec_hevc_get_image_fmt, +};drivers/media/platform/rockchip/rkvdec/rkvdec.c +55
-0@@ -154,6 +154,16 @@ static int rkvdec_s_ctrl(struct v4l2_ctrl *ctrl)enum rkvdec_image_fmt image_fmt;struct vb2_queue *vq; +if (ctrl->id ==V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS ) { + ctx->has_sps_st_rps |= !!(ctrl->has_changed); +return 0 ; + } + +if (ctrl->id ==V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS ) { + ctx->has_sps_lt_rps |= !!(ctrl->has_changed); +return 0 ; + } +/* Check if this change requires a capture format reset */ if (!desc->ops->get_image_fmt)return 0 ;@@ -285,6 +295,62 @@ static const struct rkvdec_ctrls rkvdec_h264_ctrls = { .num_ctrls = ARRAY_SIZE(rkvdec_h264_ctrl_descs), }; +static const struct rkvdec_ctrl_desc vdpu38x_hevc_ctrl_descs[] = { + { + .cfg.id =V4L2_CID_STATELESS_HEVC_DECODE_PARAMS , + }, + { + .cfg.id =V4L2_CID_STATELESS_HEVC_SPS , + .cfg.ops = &rkvdec_ctrl_ops, + }, + { + .cfg.id =V4L2_CID_STATELESS_HEVC_PPS , + }, + { + .cfg.id =V4L2_CID_STATELESS_HEVC_SCALING_MATRIX , + }, + { + .cfg.id =V4L2_CID_STATELESS_HEVC_DECODE_MODE , + .cfg.min =V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED , + .cfg.max =V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED , + .cfg.def =V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED , + }, + { + .cfg.id =V4L2_CID_STATELESS_HEVC_START_CODE , + .cfg.min =V4L2_STATELESS_HEVC_START_CODE_ANNEX_B , + .cfg.def =V4L2_STATELESS_HEVC_START_CODE_ANNEX_B , + .cfg.max =V4L2_STATELESS_HEVC_START_CODE_ANNEX_B , + }, + { + .cfg.id =V4L2_CID_MPEG_VIDEO_HEVC_PROFILE , + .cfg.min =V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN , + .cfg.max =V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10 , + .cfg.menu_skip_mask = +BIT (V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE ), + .cfg.def =V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN , + }, + { + .cfg.id =V4L2_CID_MPEG_VIDEO_HEVC_LEVEL , + .cfg.min =V4L2_MPEG_VIDEO_HEVC_LEVEL_1 , + .cfg.max =V4L2_MPEG_VIDEO_HEVC_LEVEL_6_1 , + }, + { + .cfg.id =V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS , + .cfg.ops = &rkvdec_ctrl_ops, + .cfg.dims = {65 }, + }, + {
drivers/media/platform/rockchip/rkvdec/rkvdec.c static const struct rkvdec_ctrls rkvdec_h264_ctrls = { · line 352
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10
-0+ .cfg.id = V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS, + .cfg.ops = &rkvdec_ctrl_ops, + .cfg.dims = { 65 }, + }, +}; + +static const struct rkvdec_ctrls vdpu38x_hevc_ctrls = { + .ctrls = vdpu38x_hevc_ctrl_descs, + .num_ctrls =ARRAY_SIZE (vdpu38x_hevc_ctrl_descs), +};
These new hevc struct seem out of place, maybe move closer to existing hevc structs ?
Quoted 15 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +8
-0+static const struct rkvdec_decoded_fmt_desc rkvdec_h264_decoded_fmts[] = { { .fourcc =V4L2_PIX_FMT_NV12 ,@@ -401,6 +467,23 @@ static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = { .subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF, .capability = RKVDEC_CAPABILITY_H264, }, + { + .fourcc = V4L2_PIX_FMT_HEVC_SLICE, + .frmsize = { + .min_width = 64, + .max_width = 65472, + .step_width = 64, + .min_height = 64,
drivers/media/platform/rockchip/rkvdec/rkvdec.c static const struct rkvdec_coded_fmt_desc vdpu381_coded_fmts[] = { · line 486
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10
-0+ .max_height = 65472, + .step_height = 16, + }, + .ctrls = &vdpu38x_hevc_ctrls, + .ops = &rkvdec_vdpu381_hevc_fmt_ops, + .num_decoded_fmts = ARRAY_SIZE(rkvdec_hevc_decoded_fmts), + .decoded_fmts = rkvdec_hevc_decoded_fmts, + .subsystem_flags = VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF, + .capability = RKVDEC_CAPABILITY_HEVC, + },
Please move HEVC before H264 to be consistent with dec_mode reg and existing order in coded_fmts for other variants.
drivers/media/platform/rockchip/rkvdec/rkvdec.c static const struct rkvdec_variant rk3588_vdpu381_variant = { · line 1581
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +2
-1};static const struct rkvdec_coded_fmt_desc vdpu383_coded_fmts[] = {@@ -1494,7 +1577,8 @@ static const struct rkvdec_variant rk3588_vdpu381_variant = { .num_rcb_sizes = ARRAY_SIZE(vdpu381_rcb_sizes), .ops = &vdpu381_variant_ops, .named_regs = true, - .capabilities = RKVDEC_CAPABILITY_H264, + .capabilities =RKVDEC_CAPABILITY_H264 | + RKVDEC_CAPABILITY_HEVC,
We should be albe to drop the capabilities flags now, else please order in consistent order as exising variants.
Quoted 24 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +0
-0};static const struct rkvdec_variant_ops vdpu383_variant_ops = {drivers/media/platform/rockchip/rkvdec/rkvdec.h +3
-0@@ -160,6 +160,8 @@ struct rkvdec_ctx {struct rkvdec_rcb_config *rcb_config;u32 colmv_offset;void *priv; + u8 has_sps_st_rps: 1; + u8 has_sps_lt_rps: 1; };static inline struct rkvdec_ctx *file_to_rkvdec_ctx (struct file *filp)@@ -192,6 +194,7 @@ extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops;/* VDPU381 ops */ extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_h264_fmt_ops; +extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_hevc_fmt_ops;/* VDPU383 ops */ extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops;
Detlev Casanova
maintainerPATCH v6 17/17 media: rkvdec: Add HEVC support for the VDPU383 variant
In reply to Detlev CasanovaThe VDPU383 decoder is used on the RK3576 SoC and has support for HEVC.
This patch also moves some functions to a common rkvdec-hevc-common.c file and adds a specific scaling matrix flatten function.
The fluster score for JCT-VC-HEVC_V1 is 146/147.
--- .../media/platform/rockchip/rkvdec/Makefile | 1 + .../rockchip/rkvdec/rkvdec-hevc-common.c | 59 +- .../rockchip/rkvdec/rkvdec-hevc-common.h | 3 +- .../platform/rockchip/rkvdec/rkvdec-hevc.c | 2 +- .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 3 +- .../rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 736 ++++++++++++++++++ .../media/platform/rockchip/rkvdec/rkvdec.c | 94 ++- .../media/platform/rockchip/rkvdec/rkvdec.h | 2 + 8 files changed, 851 insertions(+), 49 deletions(-) create mode 100644 drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c
drivers/media/platform/rockchip/rkvdec/Makefile +1 -0
@@ -11,4 +11,5 @@ rockchip-vdec-y += \ rkvdec-vdpu381-h264.o \ rkvdec-vdpu381-hevc.o \ rkvdec-vdpu383-h264.o \ + rkvdec-vdpu383-hevc.o \ rkvdec-vp9.o
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +15 -44
94 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h +2 -1
@@ -97,7 +97,8 @@ void compute_tiles_non_uniform(struct rkvdec_hevc_run *run, u16 log2_min_cb_size s32 pic_in_cts_height, u16 *column_width, u16 *row_height);void rkvdec_hevc_assemble_hw_rps (struct rkvdec_hevc_run *run,struct rkvdec_rps *rps,struct v4l2_ctrl_hevc_ext_sps_st_rps *st_cache); -void rkvdec_hevc_assemble_hw_scaling_list (struct rkvdec_hevc_run *run, +void rkvdec_hevc_assemble_hw_scaling_list (struct rkvdec_ctx *ctx, +struct rkvdec_hevc_run *run,struct scaling_factor *scaling_factor,struct v4l2_ctrl_hevc_scaling_matrix *cache); struct vb2_buffer *get_ref_buf(struct rkvdec_ctx *ctx,
drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c +1 -1
@@ -589,7 +589,7 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx)rkvdec_hevc_run_preamble (ctx, &run); -rkvdec_hevc_assemble_hw_scaling_list (&run, &tbl->scaling_list, +rkvdec_hevc_assemble_hw_scaling_list (ctx, &run, &tbl->scaling_list, &hevc_ctx->scaling_matrix_cache);assemble_hw_pps (ctx, &run);assemble_sw_rps (ctx, &run);
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c +1 -2
@@ -606,8 +606,7 @@ static int rkvdec_hevc_run(struct rkvdec_ctx *ctx)dev_warn_ratelimited (rkvdec->dev,"Long and short term RPS not set\n" ); } -rkvdec_hevc_assemble_hw_scaling_list (&run, - &tbl->scaling_list, +rkvdec_hevc_assemble_hw_scaling_list (ctx, &run, &tbl->scaling_list, &hevc_ctx->scaling_matrix_cache);assemble_hw_pps (ctx, &run);rkvdec_hevc_assemble_hw_rps (&run, &tbl->rps, &hevc_ctx->st_cache);
drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c new file +736 -0
736 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec.c +93 -1
130 lines not on this page · raw message
drivers/media/platform/rockchip/rkvdec/rkvdec.h +2 -0
@@ -78,6 +78,7 @@ vb2_to_rkvdec_decoded_buf(struct vb2_buffer *buf)struct rkvdec_variant_ops {irqreturn_t (*irq_handler)(struct rkvdec_ctx *ctx);u32 (*colmv_size)(u16 width,u16 height); +void (*flatten_matrices)(u8 *output,const u8 *input,int matrices,int row_length); };struct rkvdec_variant {
@@ -198,5 +199,6 @@ extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu381_hevc_fmt_ops;/* VDPU383 ops */ extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_h264_fmt_ops; +extern const struct rkvdec_coded_fmt_ops rkvdec_vdpu383_hevc_fmt_ops;#endif /* RKVDEC_H_ */
Signature · 1 line
2.52.0