Enable Hantro G1 post-processor
Subsystems (3)
v2 cover Enable Hantro G1 post-processor
Hi all,
The Hantro G1 VPU post-processor block can be pipelined with the decoder hardware, allowing to perform operations such as color conversion, scaling, rotation, cropping, among others.
When the post-processor is enabled, the decoder hardware gets its own set of NV12 buffers (the native decoder format), and the post-processor is the owner of the CAPTURE buffers.
This allows the application get processed
(scaled, converted, etc) buffers, completely transparently.
This feature is implemented by exposing the post-processed pixel formats on ENUM_FMT. When the application sets a pixel format other than NV12, and if the post-processor is MC-linked, the driver will make use of it, transparently.
On this v2, the media controller API is now required
to "enable" (aka link, in topology jargon) the post-processor. Therefore, applications now have to explicitly request this feature.
For instance, the post-processor is enabled using the media-ctl tool:
media-ctl -l "'decoder':1 -> 'rockchip,rk3288-vpu-dec':0[0]" media-ctl -l "'postproc':1 -> 'rockchip,rk3288-vpu-dec':0[1]"
v4l2-ctl -d 1 --list-formats
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture Multiplanar [0]: 'NV12' (Y/CbCr 4:2:0) [1]: 'YUYV' (YUYV 4:2:2)
Patches 1 and 2 are simply cleanups needed to easier integrate the post-processor. Patch 2 is a bit invasive, but it's a step forward towards merging the implementation for RK3399 and RK3288.
Patch 3 re-works the media-topology, making the decoder a v4l2_subdevice, instead of a bare entity. This allows to introduce a more accurate of the decoder+post-processor complex.
Patch 4 introduces the post-processing support.
This is tested on RK3288 platforms with MPEG-2, VP8 and H264 streams, decoding to YUY2 surfaces. For now, this series is only adding support for NV12-to-YUY2 conversion.
The design and implementation is quite different from v1:
* The decoder->post-processor topology is now exposed explicitly and applications need to configure the pipeline. By default, the decoder is enabled and the post-processor is disabled.
* RGB post-processing output has been dropped. We might add this in the future, but for now, it seems it would make the code more complex without a use-case in mind. RGB is much more memory-consuming so less attractive than YUV, and modern GPUs and display controllers support YUV.
* The post-processor implementation still supports RK3288 only. However, a generic register infrastructure is introduced to make addition of other variants such as RK3399 really easy.
Ezequiel Garcia (4):
media: hantro: Cleanup format negotiation helpers
media: hantro: mpeg2_dec: Re-use common register macros
media: hantro: Rework media topology
media: hantro: Support color conversion via post-processing
drivers/staging/media/hantro/Makefile | 1 + drivers/staging/media/hantro/hantro.h | 105 +++++- drivers/staging/media/hantro/hantro_drv.c | 336 ++++++++++++++---- .../staging/media/hantro/hantro_g1_h264_dec.c | 2 +- .../media/hantro/hantro_g1_mpeg2_dec.c | 188 ++++------ drivers/staging/media/hantro/hantro_g1_regs.h | 109 ++++-- .../staging/media/hantro/hantro_g1_vp8_dec.c | 2 +- drivers/staging/media/hantro/hantro_h264.c | 6 +- drivers/staging/media/hantro/hantro_hw.h | 13 + .../staging/media/hantro/hantro_postproc.c | 141 ++++++++ drivers/staging/media/hantro/hantro_v4l2.c | 116 ++++-- drivers/staging/media/hantro/rk3288_vpu_hw.c | 10 + 12 files changed, 754 insertions(+), 275 deletions(-) create mode 100644 drivers/staging/media/hantro/hantro_postproc.c
Signature · 1 line
2.22.0
PATCH v2 1/4 media: hantro: Cleanup format negotiation helpers
Format negotation helpers, hantro_find_format() and hantro_get_default_fmt() can be simplified, making the code a little bit clearer.
More importantly, this change is preparation work for the post-processor usage.
--- drivers/staging/media/hantro/hantro_v4l2.c | 53 ++++++++-------------- 1 file changed, 20 insertions(+), 33 deletions(-)
drivers/staging/media/hantro/hantro_v4l2.c +20 -33
@@ -47,23 +47,26 @@ hantro_get_formats(const struct hantro_ctx *ctx, unsigned int *num_fmts) }static const struct hantro_fmt * -hantro_find_format (const struct hantro_fmt *formats,unsigned int num_fmts, -u32 fourcc) +hantro_find_format (const struct hantro_ctx *ctx,u32 fourcc) { -unsigned int i; +const struct hantro_fmt *formats; +unsigned int i, num_fmts; + formats =hantro_get_formats (ctx, &num_fmts);for (i =0 ; i < num_fmts; i++)if (formats[i].fourcc == fourcc)return &formats[i]; +return NULL ; }static const struct hantro_fmt * -hantro_get_default_fmt (const struct hantro_fmt *formats,unsigned int num_fmts, -bool bitstream) +hantro_get_default_fmt (const struct hantro_ctx *ctx,bool bitstream) { -unsigned int i; +const struct hantro_fmt *formats; +unsigned int i, num_fmts; + formats =hantro_get_formats (ctx, &num_fmts);for (i =0 ; i < num_fmts; i++) {if (bitstream == (formats[i].codec_mode !=HANTRO_MODE_NONE ))
@@ -89,8 +92,7 @@ static int vidioc_enum_framesizes(struct file *file, void *priv, struct v4l2_frmsizeenum *fsize) {struct hantro_ctx *ctx =fh_to_ctx (priv); -const struct hantro_fmt *formats, *fmt; -unsigned int num_fmts; +const struct hantro_fmt *fmt;if (fsize->index !=0 ) { vpu_debug(0, "invalid frame size index (expected 0, got %d)\n",
@@ -98,8 +100,7 @@ static int vidioc_enum_framesizes(struct file *file, void *priv,return -EINVAL ; } - formats =hantro_get_formats (ctx, &num_fmts); - fmt =hantro_find_format (formats, num_fmts, fsize->pixel_format); + fmt =hantro_find_format (ctx, fsize->pixel_format);if (!fmt) {vpu_debug (0 ,"unsupported bitstream format (%08x)\n" , fsize->pixel_format);
@@ -196,8 +197,7 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f, {struct hantro_ctx *ctx =fh_to_ctx (priv);struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; -const struct hantro_fmt *formats, *fmt, *vpu_fmt; -unsigned int num_fmts; +const struct hantro_fmt *fmt, *vpu_fmt;bool coded; coded = capture ==hantro_is_encoder_ctx (ctx);
@@ -208,10 +208,9 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f, (pix_mp->pixelformat >>16 ) &0x7f , (pix_mp->pixelformat >> 24) & 0x7f); - formats =hantro_get_formats (ctx, &num_fmts); - fmt =hantro_find_format (formats, num_fmts, pix_mp->pixelformat); + fmt =hantro_find_format (ctx, pix_mp->pixelformat);if (!fmt) { - fmt =hantro_get_default_fmt (formats, num_fmts, coded); + fmt =hantro_get_default_fmt (ctx, coded); f->fmt.pix_mp.pixelformat = fmt->fourcc; }
@@ -290,12 +289,10 @@ hantro_reset_fmt(struct v4l2_pix_format_mplane *fmt,static void hantro_reset_encoded_fmt (struct hantro_ctx *ctx) { -const struct hantro_fmt *vpu_fmt, *formats; +const struct hantro_fmt *vpu_fmt;struct v4l2_pix_format_mplane *fmt; -unsigned int num_fmts; - formats =hantro_get_formats (ctx, &num_fmts); - vpu_fmt =hantro_get_default_fmt (formats, num_fmts, true); + vpu_fmt =hantro_get_default_fmt (ctx, true);if (hantro_is_encoder_ctx (ctx)) { ctx->vpu_dst_fmt = vpu_fmt;
@@ -316,12 +313,10 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx)static void hantro_reset_raw_fmt (struct hantro_ctx *ctx) { -const struct hantro_fmt *raw_vpu_fmt, *formats; +const struct hantro_fmt *raw_vpu_fmt;struct v4l2_pix_format_mplane *raw_fmt, *encoded_fmt; -unsigned int num_fmts; - formats =hantro_get_formats (ctx, &num_fmts); - raw_vpu_fmt =hantro_get_default_fmt (formats, num_fmts, false); + raw_vpu_fmt =hantro_get_default_fmt (ctx, false);if (hantro_is_encoder_ctx (ctx)) { ctx->vpu_src_fmt = raw_vpu_fmt;
@@ -367,8 +362,6 @@ vidioc_s_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f) {struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;struct hantro_ctx *ctx =fh_to_ctx (priv); -const struct hantro_fmt *formats; -unsigned int num_fmts;struct vb2_queue *vq;int ret;
@@ -395,9 +388,7 @@ vidioc_s_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)if (ret)return ret; - formats =hantro_get_formats (ctx, &num_fmts); - ctx->vpu_src_fmt =hantro_find_format (formats, num_fmts, - pix_mp->pixelformat); + ctx->vpu_src_fmt =hantro_find_format (ctx, pix_mp->pixelformat); ctx->src_fmt = *pix_mp;/*
@@ -431,9 +422,7 @@ static int vidioc_s_fmt_cap_mplane(struct file *file, void *priv, {struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;struct hantro_ctx *ctx =fh_to_ctx (priv); -const struct hantro_fmt *formats;struct vb2_queue *vq; -unsigned int num_fmts;int ret;/* Change not allowed if queue is busy. */
@@ -462,9 +451,7 @@ static int vidioc_s_fmt_cap_mplane(struct file *file, void *priv,if (ret)return ret; - formats =hantro_get_formats (ctx, &num_fmts); - ctx->vpu_dst_fmt =hantro_find_format (formats, num_fmts, - pix_mp->pixelformat); + ctx->vpu_dst_fmt =hantro_find_format (ctx, pix_mp->pixelformat); ctx->dst_fmt = *pix_mp;/*
Signature · 1 line
2.22.0
PATCH v2 2/4 media: hantro: mpeg2_dec: Re-use common register macros
In reply to Ezequiel GarciaThe MPEG-2 decoder register macros can be re-used from hantro_g1_regs.h, and the re-definitions removed.
--- .../media/hantro/hantro_g1_mpeg2_dec.c | 186 ++++++------------ drivers/staging/media/hantro/hantro_g1_regs.h | 58 +++--- 2 files changed, 96 insertions(+), 148 deletions(-)
drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c +64 -122
@@ -10,60 +10,9 @@#include <media/v4l2-mem2mem.h> #include "hantro.h" #include "hantro_hw.h" +#include "hantro_g1_regs.h" -#define G1_SWREG (nr) ((nr) * 4) - -#define G1_REG_RLC_VLC_BASE G1_SWREG(12) -#define G1_REG_DEC_OUT_BASE G1_SWREG(13) -#define G1_REG_REFER0_BASE G1_SWREG(14) -#define G1_REG_REFER1_BASE G1_SWREG(15) -#define G1_REG_REFER2_BASE G1_SWREG(16) -#define G1_REG_REFER3_BASE G1_SWREG(17) -#define G1_REG_QTABLE_BASE G1_SWREG(40) -#define G1_REG_DEC_E (v) ((v) ? BIT(0) : 0) - -#define G1_REG_DEC_AXI_RD_ID (v) (((v) << 24) & GENMASK(31, 24)) -#define G1_REG_DEC_TIMEOUT_E (v) ((v) ? BIT(23) : 0) -#define G1_REG_DEC_STRSWAP32_E (v) ((v) ? BIT(22) : 0) -#define G1_REG_DEC_STRENDIAN_E (v) ((v) ? BIT(21) : 0) -#define G1_REG_DEC_INSWAP32_E (v) ((v) ? BIT(20) : 0) -#define G1_REG_DEC_OUTSWAP32_E (v) ((v) ? BIT(19) : 0) -#define G1_REG_DEC_DATA_DISC_E (v) ((v) ? BIT(18) : 0) -#define G1_REG_DEC_LATENCY (v) (((v) << 11) & GENMASK(16, 11)) -#define G1_REG_DEC_CLK_GATE_E (v) ((v) ? BIT(10) : 0) -#define G1_REG_DEC_IN_ENDIAN (v) ((v) ? BIT(9) : 0) -#define G1_REG_DEC_OUT_ENDIAN (v) ((v) ? BIT(8) : 0) -#define G1_REG_DEC_ADV_PRE_DIS (v) ((v) ? BIT(6) : 0) -#define G1_REG_DEC_SCMD_DIS (v) ((v) ? BIT(5) : 0) -#define G1_REG_DEC_MAX_BURST (v) (((v) << 0) & GENMASK(4, 0)) - -#define G1_REG_DEC_MODE (v) (((v) << 28) & GENMASK(31, 28)) -#define G1_REG_RLC_MODE_E (v) ((v) ? BIT(27) : 0) -#define G1_REG_PIC_INTERLACE_E (v) ((v) ? BIT(23) : 0) -#define G1_REG_PIC_FIELDMODE_E (v) ((v) ? BIT(22) : 0) -#define G1_REG_PIC_B_E (v) ((v) ? BIT(21) : 0) -#define G1_REG_PIC_INTER_E (v) ((v) ? BIT(20) : 0) -#define G1_REG_PIC_TOPFIELD_E (v) ((v) ? BIT(19) : 0) -#define G1_REG_FWD_INTERLACE_E (v) ((v) ? BIT(18) : 0) -#define G1_REG_FILTERING_DIS (v) ((v) ? BIT(14) : 0) -#define G1_REG_WRITE_MVS_E (v) ((v) ? BIT(12) : 0) -#define G1_REG_DEC_AXI_WR_ID (v) (((v) << 0) & GENMASK(7, 0)) - -#define G1_REG_PIC_MB_WIDTH (v) (((v) << 23) & GENMASK(31, 23)) -#define G1_REG_PIC_MB_HEIGHT_P (v) (((v) << 11) & GENMASK(18, 11)) -#define G1_REG_ALT_SCAN_E (v) ((v) ? BIT(6) : 0) -#define G1_REG_TOPFIELDFIRST_E (v) ((v) ? BIT(5) : 0) - -#define G1_REG_STRM_START_BIT (v) (((v) << 26) & GENMASK(31, 26)) -#define G1_REG_QSCALE_TYPE (v) ((v) ? BIT(24) : 0) -#define G1_REG_CON_MV_E (v) ((v) ? BIT(4) : 0) -#define G1_REG_INTRA_DC_PREC (v) (((v) << 2) & GENMASK(3, 2)) -#define G1_REG_INTRA_VLC_TAB (v) ((v) ? BIT(1) : 0) -#define G1_REG_FRAME_PRED_DCT (v) ((v) ? BIT(0) : 0) - -#define G1_REG_INIT_QP (v) (((v) << 25) & GENMASK(30, 25)) -#define G1_REG_STREAM_LEN (v) (((v) << 0) & GENMASK(23, 0)) - +/* These bits seem undocumented. */ #define G1_REG_ALT_SCAN_FLAG_E (v) ((v) ? BIT(19) : 0)#define G1_REG_FCODE_FWD_HOR (v) (((v) << 15) & GENMASK(18, 15))#define G1_REG_FCODE_FWD_VER (v) (((v) << 11) & GENMASK(14, 11))
@@ -72,11 +21,6 @@#define G1_REG_MV_ACCURACY_FWD (v) ((v) ? BIT(2) : 0)#define G1_REG_MV_ACCURACY_BWD (v) ((v) ? BIT(1) : 0) -#define G1_REG_STARTMB_X (v) (((v) << 23) & GENMASK(31, 23)) -#define G1_REG_STARTMB_Y (v) (((v) << 15) & GENMASK(22, 15)) - -#define G1_REG_APF_THRESHOLD (v) (((v) << 0) & GENMASK(13, 0)) -#define PICT_TOP_FIELD 1#define PICT_BOTTOM_FIELD 2#define PICT_FRAME 3
@@ -92,7 +36,7 @@ hantro_g1_mpeg2_dec_set_quantization(struct hantro_dev *vpu,hantro_mpeg2_dec_copy_qtable (ctx->mpeg2_dec.qtable.cpu, quantization);vdpu_write_relaxed (vpu, ctx->mpeg2_dec.qtable.dma, -G1_REG_QTABLE_BASE ); +G1_REG_ADDR_QTABLE ); } static void
@@ -118,7 +62,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, struct hantro_ctx *ctx,/* Source bitstream buffer */ addr =vb2_dma_contig_plane_dma_addr (src_buf,0 ); -vdpu_write_relaxed (vpu, addr,G1_REG_RLC_VLC_BASE ); +vdpu_write_relaxed (vpu, addr,G1_REG_ADDR_STR );/* Destination frame buffer */ addr =vb2_dma_contig_plane_dma_addr (dst_buf,0 );
@@ -126,7 +70,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, struct hantro_ctx *ctx,if (picture->picture_structure ==PICT_BOTTOM_FIELD ) addr +=ALIGN (ctx->dst_fmt.width,16 ); -vdpu_write_relaxed (vpu, addr,G1_REG_DEC_OUT_BASE ); +vdpu_write_relaxed (vpu, addr,G1_REG_ADDR_DST );if (!forward_addr) forward_addr = current_addr;
@@ -140,19 +84,19 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, struct hantro_ctx *ctx, picture->top_field_first) || (picture->picture_structure == PICT_BOTTOM_FIELD && !picture->top_field_first)) { -vdpu_write_relaxed (vpu, forward_addr,G1_REG_REFER0_BASE ); -vdpu_write_relaxed (vpu, forward_addr,G1_REG_REFER1_BASE ); +vdpu_write_relaxed (vpu, forward_addr,G1_REG_ADDR_REF (0 )); +vdpu_write_relaxed (vpu, forward_addr,G1_REG_ADDR_REF (1 )); } else if (picture->picture_structure == PICT_TOP_FIELD) { -vdpu_write_relaxed (vpu, forward_addr,G1_REG_REFER0_BASE ); -vdpu_write_relaxed (vpu, current_addr,G1_REG_REFER1_BASE ); +vdpu_write_relaxed (vpu, forward_addr,G1_REG_ADDR_REF (0 )); +vdpu_write_relaxed (vpu, current_addr,G1_REG_ADDR_REF (1 )); } else if (picture->picture_structure == PICT_BOTTOM_FIELD) { -vdpu_write_relaxed (vpu, current_addr,G1_REG_REFER0_BASE ); -vdpu_write_relaxed (vpu, forward_addr,G1_REG_REFER1_BASE ); +vdpu_write_relaxed (vpu, current_addr,G1_REG_ADDR_REF (0 )); +vdpu_write_relaxed (vpu, forward_addr,G1_REG_ADDR_REF (1 )); }/* Set backward ref frame (top/bottom field) */ -vdpu_write_relaxed (vpu, backward_addr,G1_REG_REFER2_BASE ); -vdpu_write_relaxed (vpu, backward_addr,G1_REG_REFER3_BASE ); +vdpu_write_relaxed (vpu, backward_addr,G1_REG_ADDR_REF (2 )); +vdpu_write_relaxed (vpu, backward_addr,G1_REG_ADDR_REF (3 )); }void hantro_g1_mpeg2_dec_run (struct hantro_ctx *ctx)
@@ -175,52 +119,51 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx) sequence = &slice_params->sequence; picture = &slice_params->picture; - reg =G1_REG_DEC_AXI_RD_ID (0 ) | -G1_REG_DEC_TIMEOUT_E (1 ) | -G1_REG_DEC_STRSWAP32_E (1 ) | -G1_REG_DEC_STRENDIAN_E (1 ) | -G1_REG_DEC_INSWAP32_E (1 ) | -G1_REG_DEC_OUTSWAP32_E (1 ) | -G1_REG_DEC_DATA_DISC_E (0 ) | -G1_REG_DEC_LATENCY (0 ) | -G1_REG_DEC_CLK_GATE_E (1 ) | -G1_REG_DEC_IN_ENDIAN (1 ) | -G1_REG_DEC_OUT_ENDIAN (1 ) | -G1_REG_DEC_ADV_PRE_DIS (0 ) | -G1_REG_DEC_SCMD_DIS (0 ) | -G1_REG_DEC_MAX_BURST (16 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (2 )); - - reg =G1_REG_DEC_MODE (5 ) | -G1_REG_RLC_MODE_E (0 ) | -G1_REG_PIC_INTERLACE_E (!sequence->progressive_sequence) | -G1_REG_PIC_FIELDMODE_E (picture->picture_structure !=PICT_FRAME ) | -G1_REG_PIC_B_E (picture->picture_coding_type ==V4L2_MPEG2_PICTURE_CODING_TYPE_B ) | -G1_REG_PIC_INTER_E (picture->picture_coding_type !=V4L2_MPEG2_PICTURE_CODING_TYPE_I ) | -G1_REG_PIC_TOPFIELD_E (picture->picture_structure ==PICT_TOP_FIELD ) | -G1_REG_FWD_INTERLACE_E (0 ) | -G1_REG_FILTERING_DIS (1 ) | -G1_REG_WRITE_MVS_E (0 ) | -G1_REG_DEC_AXI_WR_ID (0 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (3 )); - - reg =G1_REG_PIC_MB_WIDTH (MB_WIDTH (ctx->dst_fmt.width)) | -G1_REG_PIC_MB_HEIGHT_P (MB_HEIGHT (ctx->dst_fmt.height)) | -G1_REG_ALT_SCAN_E (picture->alternate_scan) | -G1_REG_TOPFIELDFIRST_E (picture->top_field_first); -vdpu_write_relaxed (vpu, reg,G1_SWREG (4 )); - - reg =G1_REG_STRM_START_BIT (slice_params->data_bit_offset) | -G1_REG_QSCALE_TYPE (picture->q_scale_type) | -G1_REG_CON_MV_E (picture->concealment_motion_vectors) | -G1_REG_INTRA_DC_PREC (picture->intra_dc_precision) | -G1_REG_INTRA_VLC_TAB (picture->intra_vlc_format) | -G1_REG_FRAME_PRED_DCT (picture->frame_pred_frame_dct); -vdpu_write_relaxed (vpu, reg,G1_SWREG (5 )); - - reg =G1_REG_INIT_QP (1 ) | -G1_REG_STREAM_LEN (slice_params->bit_size >>3 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (6 )); + reg =G1_REG_CONFIG_DEC_AXI_RD_ID (0 ) | +G1_REG_CONFIG_DEC_TIMEOUT_E | +G1_REG_CONFIG_DEC_STRSWAP32_E | +G1_REG_CONFIG_DEC_STRENDIAN_E | +G1_REG_CONFIG_DEC_INSWAP32_E | +G1_REG_CONFIG_DEC_OUTSWAP32_E | +G1_REG_CONFIG_DEC_LATENCY (0 ) | +G1_REG_CONFIG_DEC_CLK_GATE_E | +G1_REG_CONFIG_DEC_IN_ENDIAN | +G1_REG_CONFIG_DEC_OUT_ENDIAN | +G1_REG_CONFIG_DEC_MAX_BURST (16 ); +vdpu_write_relaxed (vpu, reg,G1_REG_CONFIG ); + + reg =G1_REG_DEC_CTRL0_DEC_MODE (5 ) | +G1_REG_DEC_CTRL0_FILTERING_DIS | +G1_REG_DEC_CTRL0_DEC_AXI_WR_ID (0 ); +G1_SWREG_SET_IF (reg, !sequence->progressive_sequence, +G1_REG_DEC_CTRL0_PIC_INTERLACE_E ); +G1_SWREG_SET_IF (reg, picture->picture_coding_type ==V4L2_MPEG2_PICTURE_CODING_TYPE_B , +G1_REG_DEC_CTRL0_PIC_B_E ); +G1_SWREG_SET_IF (reg, picture->picture_coding_type !=V4L2_MPEG2_PICTURE_CODING_TYPE_I , +G1_REG_DEC_CTRL0_PIC_INTER_E ); +G1_SWREG_SET_IF (reg, picture->picture_structure ==PICT_TOP_FIELD , +G1_REG_DEC_CTRL0_PIC_TOPFIELD_E ); +G1_SWREG_SET_IF (reg, picture->picture_structure !=PICT_FRAME , +G1_REG_DEC_CTRL0_PIC_FIELDMODE_E ); +vdpu_write_relaxed (vpu, reg,G1_REG_DEC_CTRL0 ); + + reg =G1_REG_DEC_CTRL1_PIC_MB_WIDTH (MB_WIDTH (ctx->dst_fmt.width)) | +G1_REG_DEC_CTRL1_PIC_MB_HEIGHT_P (MB_HEIGHT (ctx->dst_fmt.height)); +G1_SWREG_SET_IF (reg, picture->alternate_scan,G1_REG_DEC_CTRL1_ALT_SCAN_E ); +G1_SWREG_SET_IF (reg, picture->top_field_first,G1_REG_DEC_CTRL1_TOPFIELDFIRST_E ); +vdpu_write_relaxed (vpu, reg,G1_REG_DEC_CTRL1 ); + + reg =G1_REG_DEC_CTRL2_STRM_START_BIT (slice_params->data_bit_offset) | +G1_REG_DEC_CTRL2_INTRA_DC_PREC (picture->intra_dc_precision); +G1_SWREG_SET_IF (reg, picture->q_scale_type,G1_REG_DEC_CTRL2_QSCALE_TYPE ); +G1_SWREG_SET_IF (reg, picture->concealment_motion_vectors,G1_REG_DEC_CTRL2_CON_MV_E ); +G1_SWREG_SET_IF (reg, picture->intra_vlc_format,G1_REG_DEC_CTRL2_INTRA_VLC_TAB ); +G1_SWREG_SET_IF (reg, picture->frame_pred_frame_dct,G1_REG_DEC_CTRL2_FRAME_PRED_DCT ); +vdpu_write_relaxed (vpu, reg,G1_REG_DEC_CTRL2 ); + + reg =G1_REG_DEC_CTRL3_INIT_QP (1 ) | +G1_REG_DEC_CTRL3_STREAM_LEN (slice_params->bit_size >>3 ); +vdpu_write_relaxed (vpu, reg,G1_REG_DEC_CTRL3 ); reg =G1_REG_ALT_SCAN_FLAG_E (picture->alternate_scan) | G1_REG_FCODE_FWD_HOR(picture->f_code[0][0]) |
@@ -231,12 +174,12 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)G1_REG_MV_ACCURACY_BWD (1 );vdpu_write_relaxed (vpu, reg,G1_SWREG (18 )); - reg =G1_REG_STARTMB_X (0 ) | -G1_REG_STARTMB_Y (0 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (48 )); + reg =G1_REG_ERR_CONC_STARTMB_X (0 ) | +G1_REG_ERR_CONC_STARTMB_Y (0 ); +vdpu_write_relaxed (vpu, reg,G1_REG_ERR_CONC ); - reg =G1_REG_APF_THRESHOLD (8 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (55 )); + reg =G1_REG_REF_BUF_CTRL2_APF_THRESHOLD (8 ); +vdpu_write_relaxed (vpu, reg,G1_REG_REF_BUF_CTRL2 );hantro_g1_mpeg2_dec_set_quantization (vpu, ctx);
@@ -246,6 +189,5 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)hantro_finish_run (ctx); - reg =G1_REG_DEC_E (1 ); -vdpu_write (vpu, reg,G1_SWREG (1 )); +vdpu_write (vpu,G1_REG_INTERRUPT_DEC_E ,G1_REG_INTERRUPT ); }
drivers/staging/media/hantro/hantro_g1_regs.h +32 -26
164 lines not on this page · raw message
Signature · 1 line
2.22.0
Re: [PATCH v2 2/4] media: hantro: mpeg2_dec: Re-use common register macros
Quoted 2 lines · Ezequiel Garcia
The MPEG-2 decoder register macros can be re-used from
hantro_g1_regs.h, and the re-definitions removed.
I am not a very big fan of this change as it makes it a little bit harder to spot differences and to keep the RK3399 version of the code in sync.
The original MPEG-2 code for G1 (RK3288) and RK3399 was generated based on [1], [2] and [3] with the main purpose to make it easy to keep the code for the different vpu variants in sync.
[1] https://github.com/Kwiboo/rockchip-vpu-regtool/blob/master/vpu1hwtable.h
[2] https://github.com/Kwiboo/rockchip-vpu-regtool/blob/master/vpu2hwtable.h
[3] https://github.com/Kwiboo/rockchip-vpu-regtool/blob/master/mpeg2.txt
Regards,
Jonas
Quoted 447 lines
Signed-off-by Ezequiel Garcia <[email protected]>--- .../media/hantro/hantro_g1_mpeg2_dec.c | 186 ++++++------------ drivers/staging/media/hantro/hantro_g1_regs.h | 58 +++--- 2 files changed, 96 insertions(+), 148 deletions(-)drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c +64
-122@@ -10,60 +10,9 @@#include <media/v4l2-mem2mem.h> #include "hantro.h" #include "hantro_hw.h" +#include "hantro_g1_regs.h" -#define G1_SWREG (nr) ((nr) * 4) - -#define G1_REG_RLC_VLC_BASE G1_SWREG(12) -#define G1_REG_DEC_OUT_BASE G1_SWREG(13) -#define G1_REG_REFER0_BASE G1_SWREG(14) -#define G1_REG_REFER1_BASE G1_SWREG(15) -#define G1_REG_REFER2_BASE G1_SWREG(16) -#define G1_REG_REFER3_BASE G1_SWREG(17) -#define G1_REG_QTABLE_BASE G1_SWREG(40) -#define G1_REG_DEC_E (v) ((v) ? BIT(0) : 0) - -#define G1_REG_DEC_AXI_RD_ID (v) (((v) << 24) & GENMASK(31, 24)) -#define G1_REG_DEC_TIMEOUT_E (v) ((v) ? BIT(23) : 0) -#define G1_REG_DEC_STRSWAP32_E (v) ((v) ? BIT(22) : 0) -#define G1_REG_DEC_STRENDIAN_E (v) ((v) ? BIT(21) : 0) -#define G1_REG_DEC_INSWAP32_E (v) ((v) ? BIT(20) : 0) -#define G1_REG_DEC_OUTSWAP32_E (v) ((v) ? BIT(19) : 0) -#define G1_REG_DEC_DATA_DISC_E (v) ((v) ? BIT(18) : 0) -#define G1_REG_DEC_LATENCY (v) (((v) << 11) & GENMASK(16, 11)) -#define G1_REG_DEC_CLK_GATE_E (v) ((v) ? BIT(10) : 0) -#define G1_REG_DEC_IN_ENDIAN (v) ((v) ? BIT(9) : 0) -#define G1_REG_DEC_OUT_ENDIAN (v) ((v) ? BIT(8) : 0) -#define G1_REG_DEC_ADV_PRE_DIS (v) ((v) ? BIT(6) : 0) -#define G1_REG_DEC_SCMD_DIS (v) ((v) ? BIT(5) : 0) -#define G1_REG_DEC_MAX_BURST (v) (((v) << 0) & GENMASK(4, 0)) - -#define G1_REG_DEC_MODE (v) (((v) << 28) & GENMASK(31, 28)) -#define G1_REG_RLC_MODE_E (v) ((v) ? BIT(27) : 0) -#define G1_REG_PIC_INTERLACE_E (v) ((v) ? BIT(23) : 0) -#define G1_REG_PIC_FIELDMODE_E (v) ((v) ? BIT(22) : 0) -#define G1_REG_PIC_B_E (v) ((v) ? BIT(21) : 0) -#define G1_REG_PIC_INTER_E (v) ((v) ? BIT(20) : 0) -#define G1_REG_PIC_TOPFIELD_E (v) ((v) ? BIT(19) : 0) -#define G1_REG_FWD_INTERLACE_E (v) ((v) ? BIT(18) : 0) -#define G1_REG_FILTERING_DIS (v) ((v) ? BIT(14) : 0) -#define G1_REG_WRITE_MVS_E (v) ((v) ? BIT(12) : 0) -#define G1_REG_DEC_AXI_WR_ID (v) (((v) << 0) & GENMASK(7, 0)) - -#define G1_REG_PIC_MB_WIDTH (v) (((v) << 23) & GENMASK(31, 23)) -#define G1_REG_PIC_MB_HEIGHT_P (v) (((v) << 11) & GENMASK(18, 11)) -#define G1_REG_ALT_SCAN_E (v) ((v) ? BIT(6) : 0) -#define G1_REG_TOPFIELDFIRST_E (v) ((v) ? BIT(5) : 0) - -#define G1_REG_STRM_START_BIT (v) (((v) << 26) & GENMASK(31, 26)) -#define G1_REG_QSCALE_TYPE (v) ((v) ? BIT(24) : 0) -#define G1_REG_CON_MV_E (v) ((v) ? BIT(4) : 0) -#define G1_REG_INTRA_DC_PREC (v) (((v) << 2) & GENMASK(3, 2)) -#define G1_REG_INTRA_VLC_TAB (v) ((v) ? BIT(1) : 0) -#define G1_REG_FRAME_PRED_DCT (v) ((v) ? BIT(0) : 0) - -#define G1_REG_INIT_QP (v) (((v) << 25) & GENMASK(30, 25)) -#define G1_REG_STREAM_LEN (v) (((v) << 0) & GENMASK(23, 0)) - +/* These bits seem undocumented. */ #define G1_REG_ALT_SCAN_FLAG_E (v) ((v) ? BIT(19) : 0)#define G1_REG_FCODE_FWD_HOR (v) (((v) << 15) & GENMASK(18, 15))#define G1_REG_FCODE_FWD_VER (v) (((v) << 11) & GENMASK(14, 11))@@ -72,11 +21,6 @@#define G1_REG_MV_ACCURACY_FWD (v) ((v) ? BIT(2) : 0)#define G1_REG_MV_ACCURACY_BWD (v) ((v) ? BIT(1) : 0) -#define G1_REG_STARTMB_X (v) (((v) << 23) & GENMASK(31, 23)) -#define G1_REG_STARTMB_Y (v) (((v) << 15) & GENMASK(22, 15)) - -#define G1_REG_APF_THRESHOLD (v) (((v) << 0) & GENMASK(13, 0)) -#define PICT_TOP_FIELD 1#define PICT_BOTTOM_FIELD 2#define PICT_FRAME 3@@ -92,7 +36,7 @@ hantro_g1_mpeg2_dec_set_quantization(struct hantro_dev *vpu,hantro_mpeg2_dec_copy_qtable (ctx->mpeg2_dec.qtable.cpu, quantization);vdpu_write_relaxed (vpu, ctx->mpeg2_dec.qtable.dma, -G1_REG_QTABLE_BASE ); +G1_REG_ADDR_QTABLE ); } static void@@ -118,7 +62,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, struct hantro_ctx *ctx,/* Source bitstream buffer */ addr =vb2_dma_contig_plane_dma_addr (src_buf,0 ); -vdpu_write_relaxed (vpu, addr,G1_REG_RLC_VLC_BASE ); +vdpu_write_relaxed (vpu, addr,G1_REG_ADDR_STR );/* Destination frame buffer */ addr =vb2_dma_contig_plane_dma_addr (dst_buf,0 );@@ -126,7 +70,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, struct hantro_ctx *ctx,if (picture->picture_structure ==PICT_BOTTOM_FIELD ) addr +=ALIGN (ctx->dst_fmt.width,16 ); -vdpu_write_relaxed (vpu, addr,G1_REG_DEC_OUT_BASE ); +vdpu_write_relaxed (vpu, addr,G1_REG_ADDR_DST );if (!forward_addr) forward_addr = current_addr;@@ -140,19 +84,19 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, struct hantro_ctx *ctx, picture->top_field_first) || (picture->picture_structure == PICT_BOTTOM_FIELD && !picture->top_field_first)) { -vdpu_write_relaxed (vpu, forward_addr,G1_REG_REFER0_BASE ); -vdpu_write_relaxed (vpu, forward_addr,G1_REG_REFER1_BASE ); +vdpu_write_relaxed (vpu, forward_addr,G1_REG_ADDR_REF (0 )); +vdpu_write_relaxed (vpu, forward_addr,G1_REG_ADDR_REF (1 )); } else if (picture->picture_structure == PICT_TOP_FIELD) { -vdpu_write_relaxed (vpu, forward_addr,G1_REG_REFER0_BASE ); -vdpu_write_relaxed (vpu, current_addr,G1_REG_REFER1_BASE ); +vdpu_write_relaxed (vpu, forward_addr,G1_REG_ADDR_REF (0 )); +vdpu_write_relaxed (vpu, current_addr,G1_REG_ADDR_REF (1 )); } else if (picture->picture_structure == PICT_BOTTOM_FIELD) { -vdpu_write_relaxed (vpu, current_addr,G1_REG_REFER0_BASE ); -vdpu_write_relaxed (vpu, forward_addr,G1_REG_REFER1_BASE ); +vdpu_write_relaxed (vpu, current_addr,G1_REG_ADDR_REF (0 )); +vdpu_write_relaxed (vpu, forward_addr,G1_REG_ADDR_REF (1 )); }/* Set backward ref frame (top/bottom field) */ -vdpu_write_relaxed (vpu, backward_addr,G1_REG_REFER2_BASE ); -vdpu_write_relaxed (vpu, backward_addr,G1_REG_REFER3_BASE ); +vdpu_write_relaxed (vpu, backward_addr,G1_REG_ADDR_REF (2 )); +vdpu_write_relaxed (vpu, backward_addr,G1_REG_ADDR_REF (3 )); }void hantro_g1_mpeg2_dec_run (struct hantro_ctx *ctx)@@ -175,52 +119,51 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx) sequence = &slice_params->sequence; picture = &slice_params->picture; - reg =G1_REG_DEC_AXI_RD_ID (0 ) | -G1_REG_DEC_TIMEOUT_E (1 ) | -G1_REG_DEC_STRSWAP32_E (1 ) | -G1_REG_DEC_STRENDIAN_E (1 ) | -G1_REG_DEC_INSWAP32_E (1 ) | -G1_REG_DEC_OUTSWAP32_E (1 ) | -G1_REG_DEC_DATA_DISC_E (0 ) | -G1_REG_DEC_LATENCY (0 ) | -G1_REG_DEC_CLK_GATE_E (1 ) | -G1_REG_DEC_IN_ENDIAN (1 ) | -G1_REG_DEC_OUT_ENDIAN (1 ) | -G1_REG_DEC_ADV_PRE_DIS (0 ) | -G1_REG_DEC_SCMD_DIS (0 ) | -G1_REG_DEC_MAX_BURST (16 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (2 )); - - reg =G1_REG_DEC_MODE (5 ) | -G1_REG_RLC_MODE_E (0 ) | -G1_REG_PIC_INTERLACE_E (!sequence->progressive_sequence) | -G1_REG_PIC_FIELDMODE_E (picture->picture_structure !=PICT_FRAME ) | -G1_REG_PIC_B_E (picture->picture_coding_type ==V4L2_MPEG2_PICTURE_CODING_TYPE_B ) | -G1_REG_PIC_INTER_E (picture->picture_coding_type !=V4L2_MPEG2_PICTURE_CODING_TYPE_I ) | -G1_REG_PIC_TOPFIELD_E (picture->picture_structure ==PICT_TOP_FIELD ) | -G1_REG_FWD_INTERLACE_E (0 ) | -G1_REG_FILTERING_DIS (1 ) | -G1_REG_WRITE_MVS_E (0 ) | -G1_REG_DEC_AXI_WR_ID (0 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (3 )); - - reg =G1_REG_PIC_MB_WIDTH (MB_WIDTH (ctx->dst_fmt.width)) | -G1_REG_PIC_MB_HEIGHT_P (MB_HEIGHT (ctx->dst_fmt.height)) | -G1_REG_ALT_SCAN_E (picture->alternate_scan) | -G1_REG_TOPFIELDFIRST_E (picture->top_field_first); -vdpu_write_relaxed (vpu, reg,G1_SWREG (4 )); - - reg =G1_REG_STRM_START_BIT (slice_params->data_bit_offset) | -G1_REG_QSCALE_TYPE (picture->q_scale_type) | -G1_REG_CON_MV_E (picture->concealment_motion_vectors) | -G1_REG_INTRA_DC_PREC (picture->intra_dc_precision) | -G1_REG_INTRA_VLC_TAB (picture->intra_vlc_format) | -G1_REG_FRAME_PRED_DCT (picture->frame_pred_frame_dct); -vdpu_write_relaxed (vpu, reg,G1_SWREG (5 )); - - reg =G1_REG_INIT_QP (1 ) | -G1_REG_STREAM_LEN (slice_params->bit_size >>3 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (6 )); + reg =G1_REG_CONFIG_DEC_AXI_RD_ID (0 ) | +G1_REG_CONFIG_DEC_TIMEOUT_E | +G1_REG_CONFIG_DEC_STRSWAP32_E | +G1_REG_CONFIG_DEC_STRENDIAN_E | +G1_REG_CONFIG_DEC_INSWAP32_E | +G1_REG_CONFIG_DEC_OUTSWAP32_E | +G1_REG_CONFIG_DEC_LATENCY (0 ) | +G1_REG_CONFIG_DEC_CLK_GATE_E | +G1_REG_CONFIG_DEC_IN_ENDIAN | +G1_REG_CONFIG_DEC_OUT_ENDIAN | +G1_REG_CONFIG_DEC_MAX_BURST (16 ); +vdpu_write_relaxed (vpu, reg,G1_REG_CONFIG ); + + reg =G1_REG_DEC_CTRL0_DEC_MODE (5 ) | +G1_REG_DEC_CTRL0_FILTERING_DIS | +G1_REG_DEC_CTRL0_DEC_AXI_WR_ID (0 ); +G1_SWREG_SET_IF (reg, !sequence->progressive_sequence, +G1_REG_DEC_CTRL0_PIC_INTERLACE_E ); +G1_SWREG_SET_IF (reg, picture->picture_coding_type ==V4L2_MPEG2_PICTURE_CODING_TYPE_B , +G1_REG_DEC_CTRL0_PIC_B_E ); +G1_SWREG_SET_IF (reg, picture->picture_coding_type !=V4L2_MPEG2_PICTURE_CODING_TYPE_I , +G1_REG_DEC_CTRL0_PIC_INTER_E ); +G1_SWREG_SET_IF (reg, picture->picture_structure ==PICT_TOP_FIELD , +G1_REG_DEC_CTRL0_PIC_TOPFIELD_E ); +G1_SWREG_SET_IF (reg, picture->picture_structure !=PICT_FRAME , +G1_REG_DEC_CTRL0_PIC_FIELDMODE_E ); +vdpu_write_relaxed (vpu, reg,G1_REG_DEC_CTRL0 ); + + reg =G1_REG_DEC_CTRL1_PIC_MB_WIDTH (MB_WIDTH (ctx->dst_fmt.width)) | +G1_REG_DEC_CTRL1_PIC_MB_HEIGHT_P (MB_HEIGHT (ctx->dst_fmt.height)); +G1_SWREG_SET_IF (reg, picture->alternate_scan,G1_REG_DEC_CTRL1_ALT_SCAN_E ); +G1_SWREG_SET_IF (reg, picture->top_field_first,G1_REG_DEC_CTRL1_TOPFIELDFIRST_E ); +vdpu_write_relaxed (vpu, reg,G1_REG_DEC_CTRL1 ); + + reg =G1_REG_DEC_CTRL2_STRM_START_BIT (slice_params->data_bit_offset) | +G1_REG_DEC_CTRL2_INTRA_DC_PREC (picture->intra_dc_precision); +G1_SWREG_SET_IF (reg, picture->q_scale_type,G1_REG_DEC_CTRL2_QSCALE_TYPE ); +G1_SWREG_SET_IF (reg, picture->concealment_motion_vectors,G1_REG_DEC_CTRL2_CON_MV_E ); +G1_SWREG_SET_IF (reg, picture->intra_vlc_format,G1_REG_DEC_CTRL2_INTRA_VLC_TAB ); +G1_SWREG_SET_IF (reg, picture->frame_pred_frame_dct,G1_REG_DEC_CTRL2_FRAME_PRED_DCT ); +vdpu_write_relaxed (vpu, reg,G1_REG_DEC_CTRL2 ); + + reg =G1_REG_DEC_CTRL3_INIT_QP (1 ) | +G1_REG_DEC_CTRL3_STREAM_LEN (slice_params->bit_size >>3 ); +vdpu_write_relaxed (vpu, reg,G1_REG_DEC_CTRL3 ); reg =G1_REG_ALT_SCAN_FLAG_E (picture->alternate_scan) | G1_REG_FCODE_FWD_HOR(picture->f_code[0][0]) |@@ -231,12 +174,12 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)G1_REG_MV_ACCURACY_BWD (1 );vdpu_write_relaxed (vpu, reg,G1_SWREG (18 )); - reg =G1_REG_STARTMB_X (0 ) | -G1_REG_STARTMB_Y (0 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (48 )); + reg =G1_REG_ERR_CONC_STARTMB_X (0 ) | +G1_REG_ERR_CONC_STARTMB_Y (0 ); +vdpu_write_relaxed (vpu, reg,G1_REG_ERR_CONC ); - reg =G1_REG_APF_THRESHOLD (8 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (55 )); + reg =G1_REG_REF_BUF_CTRL2_APF_THRESHOLD (8 ); +vdpu_write_relaxed (vpu, reg,G1_REG_REF_BUF_CTRL2 );hantro_g1_mpeg2_dec_set_quantization (vpu, ctx);@@ -246,6 +189,5 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)hantro_finish_run (ctx); - reg =G1_REG_DEC_E (1 ); -vdpu_write (vpu, reg,G1_SWREG (1 )); +vdpu_write (vpu,G1_REG_INTERRUPT_DEC_E ,G1_REG_INTERRUPT ); }drivers/staging/media/hantro/hantro_g1_regs.h +32
-26@@ -9,8 +9,14 @@#ifndef HANTRO_G1_REGS_H_ #define HANTRO_G1_REGS_H_ +#define G1_SWREG (nr) ((nr) * 4) +#define G1_SWREG_SET_IF (reg, cond, val) \ + do \ + reg |= (cond) ? (val) : 0x0; \ + while (0) +/* Decoder registers. */ -#define G1_REG_INTERRUPT 0x004 +#define G1_REG_INTERRUPT G1_SWREG(1)#define G1_REG_INTERRUPT_DEC_PIC_INF BIT(24)#define G1_REG_INTERRUPT_DEC_TIMEOUT BIT(18)#define G1_REG_INTERRUPT_DEC_SLICE_INT BIT(17)@@ -22,7 +28,7 @@#define G1_REG_INTERRUPT_DEC_IRQ BIT(8)#define G1_REG_INTERRUPT_DEC_IRQ_DIS BIT(4)#define G1_REG_INTERRUPT_DEC_E BIT(0) -#define G1_REG_CONFIG 0x008 +#define G1_REG_CONFIG G1_SWREG(2)#define G1_REG_CONFIG_DEC_AXI_RD_ID (x) (((x) & 0xff) << 24)#define G1_REG_CONFIG_DEC_TIMEOUT_E BIT(23)#define G1_REG_CONFIG_DEC_STRSWAP32_E BIT(22)@@ -41,7 +47,7 @@#define G1_REG_CONFIG_DEC_ADV_PRE_DIS BIT(6)#define G1_REG_CONFIG_DEC_SCMD_DIS BIT(5)#define G1_REG_CONFIG_DEC_MAX_BURST (x) (((x) & 0x1f) << 0) -#define G1_REG_DEC_CTRL0 0x00c +#define G1_REG_DEC_CTRL0 G1_SWREG(3)#define G1_REG_DEC_CTRL0_DEC_MODE (x) (((x) & 0xf) << 28)#define G1_REG_DEC_CTRL0_RLC_MODE_E BIT(27)#define G1_REG_DEC_CTRL0_SKIP_MODE BIT(26)@@ -66,7 +72,7 @@#define G1_REG_DEC_CTRL0_PICORD_COUNT_E BIT(9)#define G1_REG_DEC_CTRL0_DEC_AHB_HLOCK_E BIT(8)#define G1_REG_DEC_CTRL0_DEC_AXI_WR_ID (x) (((x) & 0xff) << 0) -#define G1_REG_DEC_CTRL1 0x010 +#define G1_REG_DEC_CTRL1 G1_SWREG(4)#define G1_REG_DEC_CTRL1_PIC_MB_WIDTH (x) (((x) & 0x1ff) << 23)#define G1_REG_DEC_CTRL1_MB_WIDTH_OFF (x) (((x) & 0xf) << 19)#define G1_REG_DEC_CTRL1_PIC_MB_HEIGHT_P (x) (((x) & 0xff) << 11)@@ -77,7 +83,7 @@#define G1_REG_DEC_CTRL1_PIC_MB_W_EXT (x) (((x) & 0x7) << 3)#define G1_REG_DEC_CTRL1_PIC_MB_H_EXT (x) (((x) & 0x7) << 0)#define G1_REG_DEC_CTRL1_PIC_REFER_FLAG BIT(0) -#define G1_REG_DEC_CTRL2 0x014 +#define G1_REG_DEC_CTRL2 G1_SWREG(5)#define G1_REG_DEC_CTRL2_STRM_START_BIT (x) (((x) & 0x3f) << 26)#define G1_REG_DEC_CTRL2_SYNC_MARKER_E BIT(25)#define G1_REG_DEC_CTRL2_TYPE1_QUANT_E BIT(24)@@ -120,13 +126,13 @@#define G1_REG_DEC_CTRL2_BOOLEAN_RANGE (x) (((x) & 0xff) << 0)#define G1_REG_DEC_CTRL2_ALPHA_OFFSET (x) (((x) & 0x1f) << 5)#define G1_REG_DEC_CTRL2_BETA_OFFSET (x) (((x) & 0x1f) << 0) -#define G1_REG_DEC_CTRL3 0x018 +#define G1_REG_DEC_CTRL3 G1_SWREG(6)#define G1_REG_DEC_CTRL3_START_CODE_E BIT(31)#define G1_REG_DEC_CTRL3_INIT_QP (x) (((x) & 0x3f) << 25)#define G1_REG_DEC_CTRL3_CH_8PIX_ILEAV_E BIT(24)#define G1_REG_DEC_CTRL3_STREAM_LEN_EXT (x) (((x) & 0xff) << 24)#define G1_REG_DEC_CTRL3_STREAM_LEN (x) (((x) & 0xffffff) << 0) -#define G1_REG_DEC_CTRL4 0x01c +#define G1_REG_DEC_CTRL4 G1_SWREG(7)#define G1_REG_DEC_CTRL4_CABAC_E BIT(31)#define G1_REG_DEC_CTRL4_BLACKWHITE_E BIT(30)#define G1_REG_DEC_CTRL4_DIR_8X8_INFER_E BIT(29)@@ -163,7 +169,7 @@#define G1_REG_DEC_CTRL4_INIT_DC_MATCH0 (x) (((x) & 0x7) << 9)#define G1_REG_DEC_CTRL4_INIT_DC_MATCH1 (x) (((x) & 0x7) << 6)#define G1_REG_DEC_CTRL4_VP7_VERSION BIT(5) -#define G1_REG_DEC_CTRL5 0x020 +#define G1_REG_DEC_CTRL5 G1_SWREG(8)#define G1_REG_DEC_CTRL5_CONST_INTRA_E BIT(31)#define G1_REG_DEC_CTRL5_FILT_CTRL_PRES BIT(30)#define G1_REG_DEC_CTRL5_RDPIC_CNT_PRES BIT(29)@@ -187,7 +193,7 @@#define G1_REG_DEC_CTRL5_RV_BWD_SCALE (x) (((x) & 0x3fff) << 0)#define G1_REG_DEC_CTRL5_INIT_DC_COMP0 (x) (((x) & 0xffff) << 16)#define G1_REG_DEC_CTRL5_INIT_DC_COMP1 (x) (((x) & 0xffff) << 0) -#define G1_REG_DEC_CTRL6 0x024 +#define G1_REG_DEC_CTRL6 G1_SWREG(9)#define G1_REG_DEC_CTRL6_PPS_ID (x) (((x) & 0xff) << 24)#define G1_REG_DEC_CTRL6_REFIDX1_ACTIVE (x) (((x) & 0x1f) << 19)#define G1_REG_DEC_CTRL6_REFIDX0_ACTIVE (x) (((x) & 0x1f) << 14)@@ -198,7 +204,7 @@#define G1_REG_DEC_CTRL6_STREAM1_LEN (x) (((x) & 0xffffff) << 0)#define G1_REG_DEC_CTRL6_PIC_SLICE_AM (x) (((x) & 0x1fff) << 0)#define G1_REG_DEC_CTRL6_COEFFS_PART_AM (x) (((x) & 0xf) << 24) -#define G1_REG_FWD_PIC (i) (0x028 + ((i) * 0x4)) +#define G1_REG_FWD_PIC (i) (G1_SWREG(10) + ((i) * 0x4))#define G1_REG_FWD_PIC_PINIT_RLIST_F5 (x) (((x) & 0x1f) << 25)#define G1_REG_FWD_PIC_PINIT_RLIST_F4 (x) (((x) & 0x1f) << 20)#define G1_REG_FWD_PIC_PINIT_RLIST_F3 (x) (((x) & 0x1f) << 15)@@ -211,7 +217,7 @@#define G1_REG_FWD_PIC1_SEGMENT_BASE (x) ((x) << 0)#define G1_REG_FWD_PIC1_SEGMENT_UPD_E BIT(1)#define G1_REG_FWD_PIC1_SEGMENT_E BIT(0) -#define G1_REG_DEC_CTRL7 0x02c +#define G1_REG_DEC_CTRL7 G1_SWREG(11)#define G1_REG_DEC_CTRL7_PINIT_RLIST_F15 (x) (((x) & 0x1f) << 25)#define G1_REG_DEC_CTRL7_PINIT_RLIST_F14 (x) (((x) & 0x1f) << 20)#define G1_REG_DEC_CTRL7_PINIT_RLIST_F13 (x) (((x) & 0x1f) << 15)@@ -226,12 +232,12 @@#define G1_REG_DEC_CTRL7_DCT5_START_BIT (x) (((x) & 0x3f) << 12)#define G1_REG_DEC_CTRL7_DCT6_START_BIT (x) (((x) & 0x3f) << 6)#define G1_REG_DEC_CTRL7_DCT7_START_BIT (x) (((x) & 0x3f) << 0) -#define G1_REG_ADDR_STR 0x030 -#define G1_REG_ADDR_DST 0x034 -#define G1_REG_ADDR_REF (i) (0x038 + ((i) * 0x4)) +#define G1_REG_ADDR_STR G1_SWREG(12) +#define G1_REG_ADDR_DST G1_SWREG(13) +#define G1_REG_ADDR_REF (i) (G1_SWREG(14) + ((i) * 0x4))#define G1_REG_ADDR_REF_FIELD_E BIT(1)#define G1_REG_ADDR_REF_TOPC_E BIT(0) -#define G1_REG_REF_PIC (i) (0x078 + ((i) * 0x4)) +#define G1_REG_REF_PIC (i) (G1_SWREG(30) + ((i) * 0x4))#define G1_REG_REF_PIC_FILT_TYPE_E BIT(31)#define G1_REG_REF_PIC_FILT_SHARPNESS (x) (((x) & 0x7) << 28)#define G1_REG_REF_PIC_MB_ADJ_0 (x) (((x) & 0x7f) << 21)@@ -248,11 +254,11 @@#define G1_REG_REF_PIC_QUANT_DELTA_1 (x) (((x) & 0x1f) << 22)#define G1_REG_REF_PIC_QUANT_0 (x) (((x) & 0x7ff) << 11)#define G1_REG_REF_PIC_QUANT_1 (x) (((x) & 0x7ff) << 0) -#define G1_REG_LT_REF 0x098 -#define G1_REG_VALID_REF 0x09c -#define G1_REG_ADDR_QTABLE 0x0a0 -#define G1_REG_ADDR_DIR_MV 0x0a4 -#define G1_REG_BD_REF_PIC (i) (0x0a8 + ((i) * 0x4)) +#define G1_REG_LT_REF G1_SWREG(38) +#define G1_REG_VALID_REF G1_SWREG(39) +#define G1_REG_ADDR_QTABLE G1_SWREG(40) +#define G1_REG_ADDR_DIR_MV G1_SWREG(41) +#define G1_REG_BD_REF_PIC (i) (G1_SWREG(42) + ((i) * 0x4))#define G1_REG_BD_REF_PIC_BINIT_RLIST_B2 (x) (((x) & 0x1f) << 25)#define G1_REG_BD_REF_PIC_BINIT_RLIST_F2 (x) (((x) & 0x1f) << 20)#define G1_REG_BD_REF_PIC_BINIT_RLIST_B1 (x) (((x) & 0x1f) << 15)@@ -269,7 +275,7 @@#define G1_REG_BD_REF_PIC_QUANT_DELTA_3 (x) (((x) & 0x1f) << 22)#define G1_REG_BD_REF_PIC_QUANT_2 (x) (((x) & 0x7ff) << 11)#define G1_REG_BD_REF_PIC_QUANT_3 (x) (((x) & 0x7ff) << 0) -#define G1_REG_BD_P_REF_PIC 0x0bc +#define G1_REG_BD_P_REF_PIC G1_SWREG(47)#define G1_REG_BD_P_REF_PIC_QUANT_DELTA_4 (x) (((x) & 0x1f) << 27)#define G1_REG_BD_P_REF_PIC_PINIT_RLIST_F3 (x) (((x) & 0x1f) << 25)#define G1_REG_BD_P_REF_PIC_PINIT_RLIST_F2 (x) (((x) & 0x1f) << 20)@@ -277,25 +283,25 @@#define G1_REG_BD_P_REF_PIC_PINIT_RLIST_F0 (x) (((x) & 0x1f) << 10)#define G1_REG_BD_P_REF_PIC_BINIT_RLIST_B15 (x) (((x) & 0x1f) << 5)#define G1_REG_BD_P_REF_PIC_BINIT_RLIST_F15 (x) (((x) & 0x1f) << 0) -#define G1_REG_ERR_CONC 0x0c0 +#define G1_REG_ERR_CONC G1_SWREG(48)#define G1_REG_ERR_CONC_STARTMB_X (x) (((x) & 0x1ff) << 23)#define G1_REG_ERR_CONC_STARTMB_Y (x) (((x) & 0xff) << 15) -#define G1_REG_PRED_FLT 0x0c4 +#define G1_REG_PRED_FLT G1_SWREG(49)#define G1_REG_PRED_FLT_PRED_BC_TAP_0_0 (x) (((x) & 0x3ff) << 22)#define G1_REG_PRED_FLT_PRED_BC_TAP_0_1 (x) (((x) & 0x3ff) << 12)#define G1_REG_PRED_FLT_PRED_BC_TAP_0_2 (x) (((x) & 0x3ff) << 2) -#define G1_REG_REF_BUF_CTRL 0x0cc +#define G1_REG_REF_BUF_CTRL G1_SWREG(51)#define G1_REG_REF_BUF_CTRL_REFBU_E BIT(31)#define G1_REG_REF_BUF_CTRL_REFBU_THR (x) (((x) & 0xfff) << 19)#define G1_REG_REF_BUF_CTRL_REFBU_PICID (x) (((x) & 0x1f) << 14)#define G1_REG_REF_BUF_CTRL_REFBU_EVAL_E BIT(13)#define G1_REG_REF_BUF_CTRL_REFBU_FPARMOD_E BIT(12)#define G1_REG_REF_BUF_CTRL_REFBU_Y_OFFSET (x) (((x) & 0x1ff) << 0) -#define G1_REG_REF_BUF_CTRL2 0x0dc +#define G1_REG_REF_BUF_CTRL2 G1_SWREG(55)#define G1_REG_REF_BUF_CTRL2_REFBU2_BUF_E BIT(31)#define G1_REG_REF_BUF_CTRL2_REFBU2_THR (x) (((x) & 0xfff) << 19)#define G1_REG_REF_BUF_CTRL2_REFBU2_PICID (x) (((x) & 0x1f) << 14)#define G1_REG_REF_BUF_CTRL2_APF_THRESHOLD (x) (((x) & 0x3fff) << 0) -#define G1_REG_SOFT_RESET 0x194 +#define G1_REG_SOFT_RESET G1_SWREG(101)#endif /* HANTRO_G1_REGS_H_ */
Re: [PATCH v2 2/4] media: hantro: mpeg2_dec: Re-use common register macros
Quoted 7 lines · Jonas Karlman
Quoted 2 lines · Ezequiel Garcia
The MPEG-2 decoder register macros can be re-used from
hantro_g1_regs.h, and the re-definitions removed.I am not a very big fan of this change as it makes it a little bit harder to spot differences and to keep the RK3399 version of the code in sync.
Quoted 7 lines
The original MPEG-2 code for G1 (RK3288) and RK3399 was generated based on [1], [2] and [3] with the main purpose to make it easy to keep the code for the different vpu variants in sync.
[1] https://github.com/Kwiboo/rockchip-vpu-regtool/blob/master/vpu1hwtable.h
[2] https://github.com/Kwiboo/rockchip-vpu-regtool/blob/master/vpu2hwtable.h
[3] https://github.com/Kwiboo/rockchip-vpu-regtool/blob/master/mpeg2.txt
Yeah, that maybe true. A more useful improvement, would be to get rid of the rk3399 implementation and have a single one using, following the example in hantro_postproc.c, introduced in patch 4.
I guess we can drop this patch, and instead work towards a unification goal.
OTOH, it's a bit annoying to have hantro_g1_regs.h and then not use it and roll our own, which is what motivated this.
Thanks for reviewing!
Ezequiel
Quoted 449 lines
Regards,
JonasQuoted 446 lines
Signed-off-by Ezequiel Garcia <[email protected]>--- .../media/hantro/hantro_g1_mpeg2_dec.c | 186 ++++++------------ drivers/staging/media/hantro/hantro_g1_regs.h | 58 +++--- 2 files changed, 96 insertions(+), 148 deletions(-)drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c +64
-122@@ -10,60 +10,9 @@#include <media/v4l2-mem2mem.h> #include "hantro.h" #include "hantro_hw.h" +#include "hantro_g1_regs.h" -#define G1_SWREG (nr) ((nr) * 4) - -#define G1_REG_RLC_VLC_BASE G1_SWREG(12) -#define G1_REG_DEC_OUT_BASE G1_SWREG(13) -#define G1_REG_REFER0_BASE G1_SWREG(14) -#define G1_REG_REFER1_BASE G1_SWREG(15) -#define G1_REG_REFER2_BASE G1_SWREG(16) -#define G1_REG_REFER3_BASE G1_SWREG(17) -#define G1_REG_QTABLE_BASE G1_SWREG(40) -#define G1_REG_DEC_E (v) ((v) ? BIT(0) : 0) - -#define G1_REG_DEC_AXI_RD_ID (v) (((v) << 24) & GENMASK(31, 24)) -#define G1_REG_DEC_TIMEOUT_E (v) ((v) ? BIT(23) : 0) -#define G1_REG_DEC_STRSWAP32_E (v) ((v) ? BIT(22) : 0) -#define G1_REG_DEC_STRENDIAN_E (v) ((v) ? BIT(21) : 0) -#define G1_REG_DEC_INSWAP32_E (v) ((v) ? BIT(20) : 0) -#define G1_REG_DEC_OUTSWAP32_E (v) ((v) ? BIT(19) : 0) -#define G1_REG_DEC_DATA_DISC_E (v) ((v) ? BIT(18) : 0) -#define G1_REG_DEC_LATENCY (v) (((v) << 11) & GENMASK(16, 11)) -#define G1_REG_DEC_CLK_GATE_E (v) ((v) ? BIT(10) : 0) -#define G1_REG_DEC_IN_ENDIAN (v) ((v) ? BIT(9) : 0) -#define G1_REG_DEC_OUT_ENDIAN (v) ((v) ? BIT(8) : 0) -#define G1_REG_DEC_ADV_PRE_DIS (v) ((v) ? BIT(6) : 0) -#define G1_REG_DEC_SCMD_DIS (v) ((v) ? BIT(5) : 0) -#define G1_REG_DEC_MAX_BURST (v) (((v) << 0) & GENMASK(4, 0)) - -#define G1_REG_DEC_MODE (v) (((v) << 28) & GENMASK(31, 28)) -#define G1_REG_RLC_MODE_E (v) ((v) ? BIT(27) : 0) -#define G1_REG_PIC_INTERLACE_E (v) ((v) ? BIT(23) : 0) -#define G1_REG_PIC_FIELDMODE_E (v) ((v) ? BIT(22) : 0) -#define G1_REG_PIC_B_E (v) ((v) ? BIT(21) : 0) -#define G1_REG_PIC_INTER_E (v) ((v) ? BIT(20) : 0) -#define G1_REG_PIC_TOPFIELD_E (v) ((v) ? BIT(19) : 0) -#define G1_REG_FWD_INTERLACE_E (v) ((v) ? BIT(18) : 0) -#define G1_REG_FILTERING_DIS (v) ((v) ? BIT(14) : 0) -#define G1_REG_WRITE_MVS_E (v) ((v) ? BIT(12) : 0) -#define G1_REG_DEC_AXI_WR_ID (v) (((v) << 0) & GENMASK(7, 0)) - -#define G1_REG_PIC_MB_WIDTH (v) (((v) << 23) & GENMASK(31, 23)) -#define G1_REG_PIC_MB_HEIGHT_P (v) (((v) << 11) & GENMASK(18, 11)) -#define G1_REG_ALT_SCAN_E (v) ((v) ? BIT(6) : 0) -#define G1_REG_TOPFIELDFIRST_E (v) ((v) ? BIT(5) : 0) - -#define G1_REG_STRM_START_BIT (v) (((v) << 26) & GENMASK(31, 26)) -#define G1_REG_QSCALE_TYPE (v) ((v) ? BIT(24) : 0) -#define G1_REG_CON_MV_E (v) ((v) ? BIT(4) : 0) -#define G1_REG_INTRA_DC_PREC (v) (((v) << 2) & GENMASK(3, 2)) -#define G1_REG_INTRA_VLC_TAB (v) ((v) ? BIT(1) : 0) -#define G1_REG_FRAME_PRED_DCT (v) ((v) ? BIT(0) : 0) - -#define G1_REG_INIT_QP (v) (((v) << 25) & GENMASK(30, 25)) -#define G1_REG_STREAM_LEN (v) (((v) << 0) & GENMASK(23, 0)) - +/* These bits seem undocumented. */ #define G1_REG_ALT_SCAN_FLAG_E (v) ((v) ? BIT(19) : 0)#define G1_REG_FCODE_FWD_HOR (v) (((v) << 15) & GENMASK(18, 15))#define G1_REG_FCODE_FWD_VER (v) (((v) << 11) & GENMASK(14, 11))@@ -72,11 +21,6 @@#define G1_REG_MV_ACCURACY_FWD (v) ((v) ? BIT(2) : 0)#define G1_REG_MV_ACCURACY_BWD (v) ((v) ? BIT(1) : 0) -#define G1_REG_STARTMB_X (v) (((v) << 23) & GENMASK(31, 23)) -#define G1_REG_STARTMB_Y (v) (((v) << 15) & GENMASK(22, 15)) - -#define G1_REG_APF_THRESHOLD (v) (((v) << 0) & GENMASK(13, 0)) -#define PICT_TOP_FIELD 1#define PICT_BOTTOM_FIELD 2#define PICT_FRAME 3@@ -92,7 +36,7 @@ hantro_g1_mpeg2_dec_set_quantization(struct hantro_dev *vpu,hantro_mpeg2_dec_copy_qtable (ctx->mpeg2_dec.qtable.cpu, quantization);vdpu_write_relaxed (vpu, ctx->mpeg2_dec.qtable.dma, -G1_REG_QTABLE_BASE ); +G1_REG_ADDR_QTABLE ); } static void@@ -118,7 +62,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, struct hantro_ctx *ctx,/* Source bitstream buffer */ addr =vb2_dma_contig_plane_dma_addr (src_buf,0 ); -vdpu_write_relaxed (vpu, addr,G1_REG_RLC_VLC_BASE ); +vdpu_write_relaxed (vpu, addr,G1_REG_ADDR_STR );/* Destination frame buffer */ addr =vb2_dma_contig_plane_dma_addr (dst_buf,0 );@@ -126,7 +70,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, struct hantro_ctx *ctx,if (picture->picture_structure ==PICT_BOTTOM_FIELD ) addr +=ALIGN (ctx->dst_fmt.width,16 ); -vdpu_write_relaxed (vpu, addr,G1_REG_DEC_OUT_BASE ); +vdpu_write_relaxed (vpu, addr,G1_REG_ADDR_DST );if (!forward_addr) forward_addr = current_addr;@@ -140,19 +84,19 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, struct hantro_ctx *ctx, picture->top_field_first) || (picture->picture_structure == PICT_BOTTOM_FIELD && !picture->top_field_first)) { -vdpu_write_relaxed (vpu, forward_addr,G1_REG_REFER0_BASE ); -vdpu_write_relaxed (vpu, forward_addr,G1_REG_REFER1_BASE ); +vdpu_write_relaxed (vpu, forward_addr,G1_REG_ADDR_REF (0 )); +vdpu_write_relaxed (vpu, forward_addr,G1_REG_ADDR_REF (1 )); } else if (picture->picture_structure == PICT_TOP_FIELD) { -vdpu_write_relaxed (vpu, forward_addr,G1_REG_REFER0_BASE ); -vdpu_write_relaxed (vpu, current_addr,G1_REG_REFER1_BASE ); +vdpu_write_relaxed (vpu, forward_addr,G1_REG_ADDR_REF (0 )); +vdpu_write_relaxed (vpu, current_addr,G1_REG_ADDR_REF (1 )); } else if (picture->picture_structure == PICT_BOTTOM_FIELD) { -vdpu_write_relaxed (vpu, current_addr,G1_REG_REFER0_BASE ); -vdpu_write_relaxed (vpu, forward_addr,G1_REG_REFER1_BASE ); +vdpu_write_relaxed (vpu, current_addr,G1_REG_ADDR_REF (0 )); +vdpu_write_relaxed (vpu, forward_addr,G1_REG_ADDR_REF (1 )); }/* Set backward ref frame (top/bottom field) */ -vdpu_write_relaxed (vpu, backward_addr,G1_REG_REFER2_BASE ); -vdpu_write_relaxed (vpu, backward_addr,G1_REG_REFER3_BASE ); +vdpu_write_relaxed (vpu, backward_addr,G1_REG_ADDR_REF (2 )); +vdpu_write_relaxed (vpu, backward_addr,G1_REG_ADDR_REF (3 )); }void hantro_g1_mpeg2_dec_run (struct hantro_ctx *ctx)@@ -175,52 +119,51 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx) sequence = &slice_params->sequence; picture = &slice_params->picture; - reg =G1_REG_DEC_AXI_RD_ID (0 ) | -G1_REG_DEC_TIMEOUT_E (1 ) | -G1_REG_DEC_STRSWAP32_E (1 ) | -G1_REG_DEC_STRENDIAN_E (1 ) | -G1_REG_DEC_INSWAP32_E (1 ) | -G1_REG_DEC_OUTSWAP32_E (1 ) | -G1_REG_DEC_DATA_DISC_E (0 ) | -G1_REG_DEC_LATENCY (0 ) | -G1_REG_DEC_CLK_GATE_E (1 ) | -G1_REG_DEC_IN_ENDIAN (1 ) | -G1_REG_DEC_OUT_ENDIAN (1 ) | -G1_REG_DEC_ADV_PRE_DIS (0 ) | -G1_REG_DEC_SCMD_DIS (0 ) | -G1_REG_DEC_MAX_BURST (16 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (2 )); - - reg =G1_REG_DEC_MODE (5 ) | -G1_REG_RLC_MODE_E (0 ) | -G1_REG_PIC_INTERLACE_E (!sequence->progressive_sequence) | -G1_REG_PIC_FIELDMODE_E (picture->picture_structure !=PICT_FRAME ) | -G1_REG_PIC_B_E (picture->picture_coding_type ==V4L2_MPEG2_PICTURE_CODING_TYPE_B ) | -G1_REG_PIC_INTER_E (picture->picture_coding_type !=V4L2_MPEG2_PICTURE_CODING_TYPE_I ) | -G1_REG_PIC_TOPFIELD_E (picture->picture_structure ==PICT_TOP_FIELD ) | -G1_REG_FWD_INTERLACE_E (0 ) | -G1_REG_FILTERING_DIS (1 ) | -G1_REG_WRITE_MVS_E (0 ) | -G1_REG_DEC_AXI_WR_ID (0 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (3 )); - - reg =G1_REG_PIC_MB_WIDTH (MB_WIDTH (ctx->dst_fmt.width)) | -G1_REG_PIC_MB_HEIGHT_P (MB_HEIGHT (ctx->dst_fmt.height)) | -G1_REG_ALT_SCAN_E (picture->alternate_scan) | -G1_REG_TOPFIELDFIRST_E (picture->top_field_first); -vdpu_write_relaxed (vpu, reg,G1_SWREG (4 )); - - reg =G1_REG_STRM_START_BIT (slice_params->data_bit_offset) | -G1_REG_QSCALE_TYPE (picture->q_scale_type) | -G1_REG_CON_MV_E (picture->concealment_motion_vectors) | -G1_REG_INTRA_DC_PREC (picture->intra_dc_precision) | -G1_REG_INTRA_VLC_TAB (picture->intra_vlc_format) | -G1_REG_FRAME_PRED_DCT (picture->frame_pred_frame_dct); -vdpu_write_relaxed (vpu, reg,G1_SWREG (5 )); - - reg =G1_REG_INIT_QP (1 ) | -G1_REG_STREAM_LEN (slice_params->bit_size >>3 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (6 )); + reg =G1_REG_CONFIG_DEC_AXI_RD_ID (0 ) | +G1_REG_CONFIG_DEC_TIMEOUT_E | +G1_REG_CONFIG_DEC_STRSWAP32_E | +G1_REG_CONFIG_DEC_STRENDIAN_E | +G1_REG_CONFIG_DEC_INSWAP32_E | +G1_REG_CONFIG_DEC_OUTSWAP32_E | +G1_REG_CONFIG_DEC_LATENCY (0 ) | +G1_REG_CONFIG_DEC_CLK_GATE_E | +G1_REG_CONFIG_DEC_IN_ENDIAN | +G1_REG_CONFIG_DEC_OUT_ENDIAN | +G1_REG_CONFIG_DEC_MAX_BURST (16 ); +vdpu_write_relaxed (vpu, reg,G1_REG_CONFIG ); + + reg =G1_REG_DEC_CTRL0_DEC_MODE (5 ) | +G1_REG_DEC_CTRL0_FILTERING_DIS | +G1_REG_DEC_CTRL0_DEC_AXI_WR_ID (0 ); +G1_SWREG_SET_IF (reg, !sequence->progressive_sequence, +G1_REG_DEC_CTRL0_PIC_INTERLACE_E ); +G1_SWREG_SET_IF (reg, picture->picture_coding_type ==V4L2_MPEG2_PICTURE_CODING_TYPE_B , +G1_REG_DEC_CTRL0_PIC_B_E ); +G1_SWREG_SET_IF (reg, picture->picture_coding_type !=V4L2_MPEG2_PICTURE_CODING_TYPE_I , +G1_REG_DEC_CTRL0_PIC_INTER_E ); +G1_SWREG_SET_IF (reg, picture->picture_structure ==PICT_TOP_FIELD , +G1_REG_DEC_CTRL0_PIC_TOPFIELD_E ); +G1_SWREG_SET_IF (reg, picture->picture_structure !=PICT_FRAME , +G1_REG_DEC_CTRL0_PIC_FIELDMODE_E ); +vdpu_write_relaxed (vpu, reg,G1_REG_DEC_CTRL0 ); + + reg =G1_REG_DEC_CTRL1_PIC_MB_WIDTH (MB_WIDTH (ctx->dst_fmt.width)) | +G1_REG_DEC_CTRL1_PIC_MB_HEIGHT_P (MB_HEIGHT (ctx->dst_fmt.height)); +G1_SWREG_SET_IF (reg, picture->alternate_scan,G1_REG_DEC_CTRL1_ALT_SCAN_E ); +G1_SWREG_SET_IF (reg, picture->top_field_first,G1_REG_DEC_CTRL1_TOPFIELDFIRST_E ); +vdpu_write_relaxed (vpu, reg,G1_REG_DEC_CTRL1 ); + + reg =G1_REG_DEC_CTRL2_STRM_START_BIT (slice_params->data_bit_offset) | +G1_REG_DEC_CTRL2_INTRA_DC_PREC (picture->intra_dc_precision); +G1_SWREG_SET_IF (reg, picture->q_scale_type,G1_REG_DEC_CTRL2_QSCALE_TYPE ); +G1_SWREG_SET_IF (reg, picture->concealment_motion_vectors,G1_REG_DEC_CTRL2_CON_MV_E ); +G1_SWREG_SET_IF (reg, picture->intra_vlc_format,G1_REG_DEC_CTRL2_INTRA_VLC_TAB ); +G1_SWREG_SET_IF (reg, picture->frame_pred_frame_dct,G1_REG_DEC_CTRL2_FRAME_PRED_DCT ); +vdpu_write_relaxed (vpu, reg,G1_REG_DEC_CTRL2 ); + + reg =G1_REG_DEC_CTRL3_INIT_QP (1 ) | +G1_REG_DEC_CTRL3_STREAM_LEN (slice_params->bit_size >>3 ); +vdpu_write_relaxed (vpu, reg,G1_REG_DEC_CTRL3 ); reg =G1_REG_ALT_SCAN_FLAG_E (picture->alternate_scan) | G1_REG_FCODE_FWD_HOR(picture->f_code[0][0]) |@@ -231,12 +174,12 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)G1_REG_MV_ACCURACY_BWD (1 );vdpu_write_relaxed (vpu, reg,G1_SWREG (18 )); - reg =G1_REG_STARTMB_X (0 ) | -G1_REG_STARTMB_Y (0 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (48 )); + reg =G1_REG_ERR_CONC_STARTMB_X (0 ) | +G1_REG_ERR_CONC_STARTMB_Y (0 ); +vdpu_write_relaxed (vpu, reg,G1_REG_ERR_CONC ); - reg =G1_REG_APF_THRESHOLD (8 ); -vdpu_write_relaxed (vpu, reg,G1_SWREG (55 )); + reg =G1_REG_REF_BUF_CTRL2_APF_THRESHOLD (8 ); +vdpu_write_relaxed (vpu, reg,G1_REG_REF_BUF_CTRL2 );hantro_g1_mpeg2_dec_set_quantization (vpu, ctx);@@ -246,6 +189,5 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)hantro_finish_run (ctx); - reg =G1_REG_DEC_E (1 ); -vdpu_write (vpu, reg,G1_SWREG (1 )); +vdpu_write (vpu,G1_REG_INTERRUPT_DEC_E ,G1_REG_INTERRUPT ); }drivers/staging/media/hantro/hantro_g1_regs.h +32
-26@@ -9,8 +9,14 @@#ifndef HANTRO_G1_REGS_H_ #define HANTRO_G1_REGS_H_ +#define G1_SWREG (nr) ((nr) * 4) +#define G1_SWREG_SET_IF (reg, cond, val) \ + do \ + reg |= (cond) ? (val) : 0x0; \ + while (0) +/* Decoder registers. */ -#define G1_REG_INTERRUPT 0x004 +#define G1_REG_INTERRUPT G1_SWREG(1)#define G1_REG_INTERRUPT_DEC_PIC_INF BIT(24)#define G1_REG_INTERRUPT_DEC_TIMEOUT BIT(18)#define G1_REG_INTERRUPT_DEC_SLICE_INT BIT(17)@@ -22,7 +28,7 @@#define G1_REG_INTERRUPT_DEC_IRQ BIT(8)#define G1_REG_INTERRUPT_DEC_IRQ_DIS BIT(4)#define G1_REG_INTERRUPT_DEC_E BIT(0) -#define G1_REG_CONFIG 0x008 +#define G1_REG_CONFIG G1_SWREG(2)#define G1_REG_CONFIG_DEC_AXI_RD_ID (x) (((x) & 0xff) << 24)#define G1_REG_CONFIG_DEC_TIMEOUT_E BIT(23)#define G1_REG_CONFIG_DEC_STRSWAP32_E BIT(22)@@ -41,7 +47,7 @@#define G1_REG_CONFIG_DEC_ADV_PRE_DIS BIT(6)#define G1_REG_CONFIG_DEC_SCMD_DIS BIT(5)#define G1_REG_CONFIG_DEC_MAX_BURST (x) (((x) & 0x1f) << 0) -#define G1_REG_DEC_CTRL0 0x00c +#define G1_REG_DEC_CTRL0 G1_SWREG(3)#define G1_REG_DEC_CTRL0_DEC_MODE (x) (((x) & 0xf) << 28)#define G1_REG_DEC_CTRL0_RLC_MODE_E BIT(27)#define G1_REG_DEC_CTRL0_SKIP_MODE BIT(26)@@ -66,7 +72,7 @@#define G1_REG_DEC_CTRL0_PICORD_COUNT_E BIT(9)#define G1_REG_DEC_CTRL0_DEC_AHB_HLOCK_E BIT(8)#define G1_REG_DEC_CTRL0_DEC_AXI_WR_ID (x) (((x) & 0xff) << 0) -#define G1_REG_DEC_CTRL1 0x010 +#define G1_REG_DEC_CTRL1 G1_SWREG(4)#define G1_REG_DEC_CTRL1_PIC_MB_WIDTH (x) (((x) & 0x1ff) << 23)#define G1_REG_DEC_CTRL1_MB_WIDTH_OFF (x) (((x) & 0xf) << 19)#define G1_REG_DEC_CTRL1_PIC_MB_HEIGHT_P (x) (((x) & 0xff) << 11)@@ -77,7 +83,7 @@#define G1_REG_DEC_CTRL1_PIC_MB_W_EXT (x) (((x) & 0x7) << 3)#define G1_REG_DEC_CTRL1_PIC_MB_H_EXT (x) (((x) & 0x7) << 0)#define G1_REG_DEC_CTRL1_PIC_REFER_FLAG BIT(0) -#define G1_REG_DEC_CTRL2 0x014 +#define G1_REG_DEC_CTRL2 G1_SWREG(5)#define G1_REG_DEC_CTRL2_STRM_START_BIT (x) (((x) & 0x3f) << 26)#define G1_REG_DEC_CTRL2_SYNC_MARKER_E BIT(25)#define G1_REG_DEC_CTRL2_TYPE1_QUANT_E BIT(24)@@ -120,13 +126,13 @@#define G1_REG_DEC_CTRL2_BOOLEAN_RANGE (x) (((x) & 0xff) << 0)#define G1_REG_DEC_CTRL2_ALPHA_OFFSET (x) (((x) & 0x1f) << 5)#define G1_REG_DEC_CTRL2_BETA_OFFSET (x) (((x) & 0x1f) << 0) -#define G1_REG_DEC_CTRL3 0x018 +#define G1_REG_DEC_CTRL3 G1_SWREG(6)#define G1_REG_DEC_CTRL3_START_CODE_E BIT(31)#define G1_REG_DEC_CTRL3_INIT_QP (x) (((x) & 0x3f) << 25)#define G1_REG_DEC_CTRL3_CH_8PIX_ILEAV_E BIT(24)#define G1_REG_DEC_CTRL3_STREAM_LEN_EXT (x) (((x) & 0xff) << 24)#define G1_REG_DEC_CTRL3_STREAM_LEN (x) (((x) & 0xffffff) << 0) -#define G1_REG_DEC_CTRL4 0x01c +#define G1_REG_DEC_CTRL4 G1_SWREG(7)#define G1_REG_DEC_CTRL4_CABAC_E BIT(31)#define G1_REG_DEC_CTRL4_BLACKWHITE_E BIT(30)#define G1_REG_DEC_CTRL4_DIR_8X8_INFER_E BIT(29)@@ -163,7 +169,7 @@#define G1_REG_DEC_CTRL4_INIT_DC_MATCH0 (x) (((x) & 0x7) << 9)#define G1_REG_DEC_CTRL4_INIT_DC_MATCH1 (x) (((x) & 0x7) << 6)#define G1_REG_DEC_CTRL4_VP7_VERSION BIT(5) -#define G1_REG_DEC_CTRL5 0x020 +#define G1_REG_DEC_CTRL5 G1_SWREG(8)#define G1_REG_DEC_CTRL5_CONST_INTRA_E BIT(31)#define G1_REG_DEC_CTRL5_FILT_CTRL_PRES BIT(30)#define G1_REG_DEC_CTRL5_RDPIC_CNT_PRES BIT(29)@@ -187,7 +193,7 @@#define G1_REG_DEC_CTRL5_RV_BWD_SCALE (x) (((x) & 0x3fff) << 0)#define G1_REG_DEC_CTRL5_INIT_DC_COMP0 (x) (((x) & 0xffff) << 16)#define G1_REG_DEC_CTRL5_INIT_DC_COMP1 (x) (((x) & 0xffff) << 0) -#define G1_REG_DEC_CTRL6 0x024 +#define G1_REG_DEC_CTRL6 G1_SWREG(9)#define G1_REG_DEC_CTRL6_PPS_ID (x) (((x) & 0xff) << 24)#define G1_REG_DEC_CTRL6_REFIDX1_ACTIVE (x) (((x) & 0x1f) << 19)#define G1_REG_DEC_CTRL6_REFIDX0_ACTIVE (x) (((x) & 0x1f) << 14)@@ -198,7 +204,7 @@#define G1_REG_DEC_CTRL6_STREAM1_LEN (x) (((x) & 0xffffff) << 0)#define G1_REG_DEC_CTRL6_PIC_SLICE_AM (x) (((x) & 0x1fff) << 0)#define G1_REG_DEC_CTRL6_COEFFS_PART_AM (x) (((x) & 0xf) << 24) -#define G1_REG_FWD_PIC (i) (0x028 + ((i) * 0x4)) +#define G1_REG_FWD_PIC (i) (G1_SWREG(10) + ((i) * 0x4))#define G1_REG_FWD_PIC_PINIT_RLIST_F5 (x) (((x) & 0x1f) << 25)#define G1_REG_FWD_PIC_PINIT_RLIST_F4 (x) (((x) & 0x1f) << 20)#define G1_REG_FWD_PIC_PINIT_RLIST_F3 (x) (((x) & 0x1f) << 15)@@ -211,7 +217,7 @@#define G1_REG_FWD_PIC1_SEGMENT_BASE (x) ((x) << 0)#define G1_REG_FWD_PIC1_SEGMENT_UPD_E BIT(1)#define G1_REG_FWD_PIC1_SEGMENT_E BIT(0) -#define G1_REG_DEC_CTRL7 0x02c +#define G1_REG_DEC_CTRL7 G1_SWREG(11)#define G1_REG_DEC_CTRL7_PINIT_RLIST_F15 (x) (((x) & 0x1f) << 25)#define G1_REG_DEC_CTRL7_PINIT_RLIST_F14 (x) (((x) & 0x1f) << 20)#define G1_REG_DEC_CTRL7_PINIT_RLIST_F13 (x) (((x) & 0x1f) << 15)@@ -226,12 +232,12 @@#define G1_REG_DEC_CTRL7_DCT5_START_BIT (x) (((x) & 0x3f) << 12)#define G1_REG_DEC_CTRL7_DCT6_START_BIT (x) (((x) & 0x3f) << 6)#define G1_REG_DEC_CTRL7_DCT7_START_BIT (x) (((x) & 0x3f) << 0) -#define G1_REG_ADDR_STR 0x030 -#define G1_REG_ADDR_DST 0x034 -#define G1_REG_ADDR_REF (i) (0x038 + ((i) * 0x4)) +#define G1_REG_ADDR_STR G1_SWREG(12) +#define G1_REG_ADDR_DST G1_SWREG(13) +#define G1_REG_ADDR_REF (i) (G1_SWREG(14) + ((i) * 0x4))#define G1_REG_ADDR_REF_FIELD_E BIT(1)#define G1_REG_ADDR_REF_TOPC_E BIT(0) -#define G1_REG_REF_PIC (i) (0x078 + ((i) * 0x4)) +#define G1_REG_REF_PIC (i) (G1_SWREG(30) + ((i) * 0x4))#define G1_REG_REF_PIC_FILT_TYPE_E BIT(31)#define G1_REG_REF_PIC_FILT_SHARPNESS (x) (((x) & 0x7) << 28)#define G1_REG_REF_PIC_MB_ADJ_0 (x) (((x) & 0x7f) << 21)@@ -248,11 +254,11 @@#define G1_REG_REF_PIC_QUANT_DELTA_1 (x) (((x) & 0x1f) << 22)#define G1_REG_REF_PIC_QUANT_0 (x) (((x) & 0x7ff) << 11)#define G1_REG_REF_PIC_QUANT_1 (x) (((x) & 0x7ff) << 0) -#define G1_REG_LT_REF 0x098 -#define G1_REG_VALID_REF 0x09c -#define G1_REG_ADDR_QTABLE 0x0a0 -#define G1_REG_ADDR_DIR_MV 0x0a4 -#define G1_REG_BD_REF_PIC (i) (0x0a8 + ((i) * 0x4)) +#define G1_REG_LT_REF G1_SWREG(38) +#define G1_REG_VALID_REF G1_SWREG(39) +#define G1_REG_ADDR_QTABLE G1_SWREG(40) +#define G1_REG_ADDR_DIR_MV G1_SWREG(41) +#define G1_REG_BD_REF_PIC (i) (G1_SWREG(42) + ((i) * 0x4))#define G1_REG_BD_REF_PIC_BINIT_RLIST_B2 (x) (((x) & 0x1f) << 25)#define G1_REG_BD_REF_PIC_BINIT_RLIST_F2 (x) (((x) & 0x1f) << 20)#define G1_REG_BD_REF_PIC_BINIT_RLIST_B1 (x) (((x) & 0x1f) << 15)@@ -269,7 +275,7 @@#define G1_REG_BD_REF_PIC_QUANT_DELTA_3 (x) (((x) & 0x1f) << 22)#define G1_REG_BD_REF_PIC_QUANT_2 (x) (((x) & 0x7ff) << 11)#define G1_REG_BD_REF_PIC_QUANT_3 (x) (((x) & 0x7ff) << 0) -#define G1_REG_BD_P_REF_PIC 0x0bc +#define G1_REG_BD_P_REF_PIC G1_SWREG(47)#define G1_REG_BD_P_REF_PIC_QUANT_DELTA_4 (x) (((x) & 0x1f) << 27)#define G1_REG_BD_P_REF_PIC_PINIT_RLIST_F3 (x) (((x) & 0x1f) << 25)#define G1_REG_BD_P_REF_PIC_PINIT_RLIST_F2 (x) (((x) & 0x1f) << 20)@@ -277,25 +283,25 @@#define G1_REG_BD_P_REF_PIC_PINIT_RLIST_F0 (x) (((x) & 0x1f) << 10)#define G1_REG_BD_P_REF_PIC_BINIT_RLIST_B15 (x) (((x) & 0x1f) << 5)#define G1_REG_BD_P_REF_PIC_BINIT_RLIST_F15 (x) (((x) & 0x1f) << 0) -#define G1_REG_ERR_CONC 0x0c0 +#define G1_REG_ERR_CONC G1_SWREG(48)#define G1_REG_ERR_CONC_STARTMB_X (x) (((x) & 0x1ff) << 23)#define G1_REG_ERR_CONC_STARTMB_Y (x) (((x) & 0xff) << 15) -#define G1_REG_PRED_FLT 0x0c4 +#define G1_REG_PRED_FLT G1_SWREG(49)#define G1_REG_PRED_FLT_PRED_BC_TAP_0_0 (x) (((x) & 0x3ff) << 22)#define G1_REG_PRED_FLT_PRED_BC_TAP_0_1 (x) (((x) & 0x3ff) << 12)#define G1_REG_PRED_FLT_PRED_BC_TAP_0_2 (x) (((x) & 0x3ff) << 2) -#define G1_REG_REF_BUF_CTRL 0x0cc +#define G1_REG_REF_BUF_CTRL G1_SWREG(51)#define G1_REG_REF_BUF_CTRL_REFBU_E BIT(31)#define G1_REG_REF_BUF_CTRL_REFBU_THR (x) (((x) & 0xfff) << 19)#define G1_REG_REF_BUF_CTRL_REFBU_PICID (x) (((x) & 0x1f) << 14)#define G1_REG_REF_BUF_CTRL_REFBU_EVAL_E BIT(13)#define G1_REG_REF_BUF_CTRL_REFBU_FPARMOD_E BIT(12)#define G1_REG_REF_BUF_CTRL_REFBU_Y_OFFSET (x) (((x) & 0x1ff) << 0) -#define G1_REG_REF_BUF_CTRL2 0x0dc +#define G1_REG_REF_BUF_CTRL2 G1_SWREG(55)#define G1_REG_REF_BUF_CTRL2_REFBU2_BUF_E BIT(31)#define G1_REG_REF_BUF_CTRL2_REFBU2_THR (x) (((x) & 0xfff) << 19)#define G1_REG_REF_BUF_CTRL2_REFBU2_PICID (x) (((x) & 0x1f) << 14)#define G1_REG_REF_BUF_CTRL2_APF_THRESHOLD (x) (((x) & 0x3fff) << 0) -#define G1_REG_SOFT_RESET 0x194 +#define G1_REG_SOFT_RESET G1_SWREG(101)#endif /* HANTRO_G1_REGS_H_ */
PATCH v2 3/4 media: hantro: Rework media topology
In reply to Ezequiel GarciaAs suggested by Helen Koike, the decoder processing entity can be modeled as a V4L2 subdevice.
This change will allow to describe more complex topology and/or behavior to userspace, starting with the post-processing feature, which will be soon introduced.
For now, introduce a simple subdevice, maintaining an immutable topology, and now exposing the subdevices to userspace.
--- drivers/staging/media/hantro/hantro.h | 21 +- drivers/staging/media/hantro/hantro_drv.c | 250 +++++++++++++++------ drivers/staging/media/hantro/hantro_v4l2.c | 18 +- 3 files changed, 205 insertions(+), 84 deletions(-)
drivers/staging/media/hantro/hantro.h +8 -13
@@ -124,25 +124,19 @@ struct hantro_ctrl {* %MEDIA_ENT_F_PROC_VIDEO_DECODER) * @vdev: &struct video_device that exposes the encoder or * decoder functionality -* @source_pad: &struct media_pad with the source pad. -* @sink: &struct media_entity pointer with the sink entity -* @sink_pad: &struct media_pad with the sink pad. -* @proc: &struct media_entity pointer with the M2M device itself. -* @proc_pads: &struct media_pad with the @proc pads. -* @intf_devnode: &struct media_intf devnode pointer with the interface -* with controls the M2M device. +* @vdev_pads: &struct media_pad with the @vdev pads. +* @sd_proc: &struct v4l2_subdev exposing the encoder or decoder sub-device +* @sd_proc_pads: &struct media_pad with the @sd_proc pads. * * Contains everything needed to attach the video device to the media device. */ struct hantro_func {unsigned int id;struct video_device vdev; -struct media_pad source_pad; -struct media_entity sink; -struct media_pad sink_pad; -struct media_entity proc; -struct media_pad proc_pads[2 ]; -struct media_intf_devnode *intf_devnode; +struct media_pad vdev_pads[2 ]; + +struct v4l2_subdev sd_proc; +struct media_pad sd_proc_pads[2 ]; }; static inline struct hantro_func *
@@ -220,6 +214,7 @@ struct hantro_dev {struct hantro_ctx {struct hantro_dev *dev;struct v4l2_fh fh; +struct media_pipeline pipe;u32 sequence_cap;u32 sequence_out;
drivers/staging/media/hantro/hantro_drv.c +180 -70
309 lines not on this page · raw message
drivers/staging/media/hantro/hantro_v4l2.c +17 -1
@@ -594,6 +594,7 @@ static bool hantro_vq_is_coded(struct vb2_queue *q)static int hantro_start_streaming (struct vb2_queue *q,unsigned int count) {struct hantro_ctx *ctx =vb2_get_drv_priv (q); +struct media_entity *entity = &ctx->fh.vdev->entity;int ret =0 ;if (V4L2_TYPE_IS_OUTPUT (q->type))
@@ -601,6 +602,11 @@ static int hantro_start_streaming(struct vb2_queue *q, unsigned int count)else ctx->sequence_cap =0 ; +/* Start the media pipeline */ + ret =media_pipeline_start (entity, &ctx->pipe); +if (ret) +return ret; +if (hantro_vq_is_coded (q)) {enum hantro_codec_mode codec_mode;
@@ -611,11 +617,18 @@ static int hantro_start_streaming(struct vb2_queue *q, unsigned int count)vpu_debug (4 ,"Codec mode = %d\n" , codec_mode); ctx->codec_ops = &ctx->dev->variant->codec_ops[codec_mode]; -if (ctx->codec_ops->init) +if (ctx->codec_ops->init) { ret = ctx->codec_ops->init (ctx); +if (ret) + goto err_pipe_stop; + } }return ret; + +err_pipe_stop: +media_pipeline_stop (entity); +return ret; } static void
@@ -639,12 +652,15 @@ hantro_return_bufs(struct vb2_queue *q,static void hantro_stop_streaming (struct vb2_queue *q) {struct hantro_ctx *ctx =vb2_get_drv_priv (q); +struct media_entity *entity = &ctx->fh.vdev->entity;if (hantro_vq_is_coded (q)) {if (ctx->codec_ops && ctx->codec_ops->exit) ctx->codec_ops->exit (ctx); } +media_pipeline_stop (entity); +/* * The mem2mem framework calls v4l2_m2m_cancel_job before * .stop_streaming, so there isn't any job running and
Signature · 1 line
2.22.0
PATCH v2 4/4 media: hantro: Support color conversion via post-processing
In reply to Ezequiel GarciaThe Hantro G1 decoder is able to enable a post-processor on the decoding pipeline, which can be used to perform scaling and color conversion.
The post-processor is integrated to the decoder, and it's possible to use it in a way that is completely transparent to the user.
This commit enables color conversion via post-processing, which means the driver now exposes YUV packed, in addition to NV12.
--- drivers/staging/media/hantro/Makefile | 1 + drivers/staging/media/hantro/hantro.h | 84 ++++++++++- drivers/staging/media/hantro/hantro_drv.c | 90 ++++++++++- .../staging/media/hantro/hantro_g1_h264_dec.c | 2 +- .../media/hantro/hantro_g1_mpeg2_dec.c | 2 +- drivers/staging/media/hantro/hantro_g1_regs.h | 51 +++++++ .../staging/media/hantro/hantro_g1_vp8_dec.c | 2 +- drivers/staging/media/hantro/hantro_h264.c | 6 +- drivers/staging/media/hantro/hantro_hw.h | 13 ++ .../staging/media/hantro/hantro_postproc.c | 141 ++++++++++++++++++ drivers/staging/media/hantro/hantro_v4l2.c | 47 +++++- drivers/staging/media/hantro/rk3288_vpu_hw.c | 10 ++ 12 files changed, 436 insertions(+), 13 deletions(-) create mode 100644 drivers/staging/media/hantro/hantro_postproc.c
drivers/staging/media/hantro/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_VIDEO_HANTRO) += hantro-vpu.o hantro-vpu-y += \ hantro_drv.o \ hantro_v4l2.o \ + hantro_postproc.o \ hantro_h1_jpeg_enc.o \ hantro_g1_h264_dec.o \ hantro_g1_mpeg2_dec.o \
drivers/staging/media/hantro/hantro.h +81 -3
166 lines not on this page · raw message
drivers/staging/media/hantro/hantro_drv.c +87 -3
145 lines not on this page · raw message
drivers/staging/media/hantro/hantro_g1_h264_dec.c +1 -1
@@ -241,7 +241,7 @@ static void set_buffers(struct hantro_ctx *ctx)vdpu_write_relaxed (vpu, src_dma,G1_REG_ADDR_STR );/* Destination (decoded frame) buffer. */ - dst_dma =vb2_dma_contig_plane_dma_addr (&dst_buf->vb2_buf,0 ); + dst_dma =hantro_get_dec_buf_addr (ctx, &dst_buf->vb2_buf);vdpu_write_relaxed (vpu, dst_dma,G1_REG_ADDR_DST );/* Higher profiles require DMV buffer appended to reference frames. */
drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c +1 -1
@@ -65,7 +65,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, struct hantro_ctx *ctx,vdpu_write_relaxed (vpu, addr,G1_REG_ADDR_STR );/* Destination frame buffer */ - addr =vb2_dma_contig_plane_dma_addr (dst_buf,0 ); + addr =hantro_get_dec_buf_addr (ctx, dst_buf); current_addr = addr;if (picture->picture_structure ==PICT_BOTTOM_FIELD )
drivers/staging/media/hantro/hantro_g1_regs.h +51 -0
55 lines not on this page · raw message
drivers/staging/media/hantro/hantro_g1_vp8_dec.c +1 -1
@@ -422,7 +422,7 @@ static void cfg_buffers(struct hantro_ctx *ctx, }vdpu_write_relaxed (vpu, reg,G1_REG_FWD_PIC (0 )); - dst_dma =vb2_dma_contig_plane_dma_addr (&vb2_dst->vb2_buf,0 ); + dst_dma =hantro_get_dec_buf_addr (ctx, &vb2_dst->vb2_buf);vdpu_write_relaxed (vpu, dst_dma,G1_REG_ADDR_DST ); }
drivers/staging/media/hantro/hantro_h264.c +5 -1
@@ -656,7 +656,11 @@ int hantro_h264_dec_init(struct hantro_ctx *ctx) tbl = priv->cpu;memcpy (tbl->cabac_table, h264_cabac_table,sizeof (tbl->cabac_table)); -v4l2_fill_pixfmt_mp (&pix_mp, ctx->dst_fmt.pixelformat, +/* +* For the decoder picture size, we want the decoder +* native pixel format. +*/ +v4l2_fill_pixfmt_mp (&pix_mp,V4L2_PIX_FMT_NV12 , ctx->dst_fmt.width, ctx->dst_fmt.height); h264_dec->pic_size = pix_mp.plane_fmt[0 ].sizeimage;
drivers/staging/media/hantro/hantro_hw.h +13 -0
@@ -28,11 +28,13 @@ struct hantro_variant;* @cpu: CPU pointer to the buffer. * @dma: DMA address of the buffer. * @size: Size of the buffer. +* @attrs: Attributes of the DMA mapping. */ struct hantro_aux_buf {void *cpu;dma_addr_t dma;size_t size; +unsigned long attrs; };/**
@@ -109,6 +111,15 @@ struct hantro_vp8_dec_hw_ctx {struct hantro_aux_buf prob_tbl; }; +/** +* struct hantro_postproc_ctx +* +* @dec_q: References buffers, in decoder format. +*/ +struct hantro_postproc_ctx { +struct hantro_aux_buf dec_q[VB2_MAX_FRAME ]; +}; +/** * struct hantro_codec_ops - codec mode specific operations *
@@ -144,6 +155,8 @@ extern const struct hantro_variant rk3399_vpu_variant;extern const struct hantro_variant rk3328_vpu_variant;extern const struct hantro_variant rk3288_vpu_variant; +extern const struct hantro_postproc_regs hantro_g1_postproc_regs; +extern const u32 hantro_vp8_dec_mc_filter[8 ][6 ];void hantro_watchdog (struct work_struct *work);
drivers/staging/media/hantro/hantro_postproc.c new file +141 -0
141 lines not on this page · raw message
drivers/staging/media/hantro/hantro_v4l2.c +44 -3
87 lines not on this page · raw message
drivers/staging/media/hantro/rk3288_vpu_hw.c +10 -0
@@ -56,6 +56,13 @@ static const struct hantro_fmt rk3288_vpu_enc_fmts[] = { }, }; +static const struct hantro_fmt rk3288_vpu_postproc_fmts[] = { + { + .fourcc =V4L2_PIX_FMT_YUYV , + .codec_mode =HANTRO_MODE_NONE , + }, +}; +static const struct hantro_fmt rk3288_vpu_dec_fmts[] = { { .fourcc =V4L2_PIX_FMT_NV12 ,
@@ -215,6 +222,9 @@ const struct hantro_variant rk3288_vpu_variant = { .dec_offset = 0x400, .dec_fmts = rk3288_vpu_dec_fmts, .num_dec_fmts = ARRAY_SIZE(rk3288_vpu_dec_fmts), + .postproc_fmts = rk3288_vpu_postproc_fmts, + .num_postproc_fmts = ARRAY_SIZE(rk3288_vpu_postproc_fmts), + .postproc_regs = &hantro_g1_postproc_regs, .codec =HANTRO_JPEG_ENCODER |HANTRO_MPEG2_DECODER | HANTRO_VP8_DECODER | HANTRO_H264_DECODER, .codec_ops = rk3288_vpu_codec_ops,
Signature · 1 line
2.22.0
Hi Ezequiel,
Quoted 50 lines · Ezequiel Garcia
Hi all,
The Hantro G1 VPU post-processor block can be pipelined with the decoder hardware, allowing to perform operations such as color conversion, scaling, rotation, cropping, among others.
When the post-processor is enabled, the decoder hardware gets its own set of NV12 buffers (the native decoder format), and the post-processor is the owner of the CAPTURE buffers.
This allows the application get processed
(scaled, converted, etc) buffers, completely transparently.This feature is implemented by exposing the post-processed pixel formats on
ENUM_FMT. When the application sets a pixel format other than NV12, and if the post-processor is MC-linked, the driver will make use of it, transparently.On this v2, the media controller API is now required
to "enable" (aka link, in topology jargon) the post-processor. Therefore, applications now have to explicitly request this feature.For instance, the post-processor is enabled using the media-ctl tool:
media-ctl -l "'decoder':1 -> 'rockchip,rk3288-vpu-dec':0[0]" media-ctl -l "'postproc':1 -> 'rockchip,rk3288-vpu-dec':0[1]"
v4l2-ctl -d 1 --list-formats
ioctl:VIDIOC_ENUM_FMTType: Video Capture Multiplanar [0]: 'NV12' (Y/CbCr 4:2:0) [1]: 'YUYV' (YUYV 4:2:2)Patches 1 and 2 are simply cleanups needed to easier integrate the post-processor. Patch 2 is a bit invasive, but it's a step forward towards merging the implementation for RK3399 and RK3288.
Patch 3 re-works the media-topology, making the decoder a
v4l2_subdevice, instead of a bare entity. This allows to introduce a more accurate of the decoder+post-processor complex.Patch 4 introduces the post-processing support.
This is tested on RK3288 platforms with MPEG-2, VP8 and H264 streams, decoding to YUY2 surfaces. For now, this series is only adding support for NV12-to-YUY2 conversion.
Quoted 7 lines
The design and implementation is quite different from v1:
* The decoder->post-processor topology is now exposed explicitly and applications need to configure the pipeline. By default, the decoder is enabled and the post-processor is disabled.
First of all, thanks for working on this. While from Chromium point of view there isn't any practical use case for this feature, it could possibly be valuable for some other platforms.
I still see a problem with the current design. Mem-to-mem decoders are commonly used in a multi-instance fashion, but media topology is global. That means that when having two applications on the system decoding their own videos, one might be stepping on the other by changing the topology.
I believe that if we want this to be really usable, we would need to make the media topology per instance, but that's a significant change to the media subsystem. Maybe we could pursue the other options I suggested in the previous revision instead, like ordering the formats returned by enum_fmt by native first and adding format flags that would tell the userspace that the format can have some performance and/or power penalty?
Best regards,
Tomasz
Quoted 71 lines · Tomasz Figa
Hi Ezequiel,
Quoted 50 lines · Ezequiel Garcia
Hi all,
The Hantro G1 VPU post-processor block can be pipelined with the decoder hardware, allowing to perform operations such as color conversion, scaling, rotation, cropping, among others.
When the post-processor is enabled, the decoder hardware gets its own set of NV12 buffers (the native decoder format), and the post-processor is the owner of the CAPTURE buffers.
This allows the application get processed
(scaled, converted, etc) buffers, completely transparently.This feature is implemented by exposing the post-processed pixel formats on
ENUM_FMT. When the application sets a pixel format other than NV12, and if the post-processor is MC-linked, the driver will make use of it, transparently.On this v2, the media controller API is now required
to "enable" (aka link, in topology jargon) the post-processor. Therefore, applications now have to explicitly request this feature.For instance, the post-processor is enabled using the media-ctl tool:
media-ctl -l "'decoder':1 -> 'rockchip,rk3288-vpu-dec':0[0]" media-ctl -l "'postproc':1 -> 'rockchip,rk3288-vpu-dec':0[1]"
v4l2-ctl -d 1 --list-formats
ioctl:VIDIOC_ENUM_FMTType: Video Capture Multiplanar [0]: 'NV12' (Y/CbCr 4:2:0) [1]: 'YUYV' (YUYV 4:2:2)Patches 1 and 2 are simply cleanups needed to easier integrate the post-processor. Patch 2 is a bit invasive, but it's a step forward towards merging the implementation for RK3399 and RK3288.
Patch 3 re-works the media-topology, making the decoder a
v4l2_subdevice, instead of a bare entity. This allows to introduce a more accurate of the decoder+post-processor complex.Patch 4 introduces the post-processing support.
This is tested on RK3288 platforms with MPEG-2, VP8 and H264 streams, decoding to YUY2 surfaces. For now, this series is only adding support for NV12-to-YUY2 conversion.
Quoted 7 lines
The design and implementation is quite different from v1:
* The decoder->post-processor topology is now exposed explicitly and applications need to configure the pipeline. By default, the decoder is enabled and the post-processor is disabled.
First of all, thanks for working on this. While from Chromium point of view there isn't any practical use case for this feature, it could possibly be valuable for some other platforms.
I still see a problem with the current design. Mem-to-mem decoders are commonly used in a multi-instance fashion, but media topology is global. That means that when having two applications on the system decoding their own videos, one might be stepping on the other by changing the topology.
Quoted 7 lines
I believe that if we want this to be really usable, we would need to make the media topology per instance, but that's a significant change to the media subsystem. Maybe we could pursue the other options I suggested in the previous revision instead, like ordering the formats returned by
enum_fmtby native first and adding format flags that would tell the userspace that the format can have some performance and/or power penalty?
I discussed this with Ezequiel in Lyon, and my preference is also to not rely on the media controller, but instead order the formats with the native formats first, followed by the formats that need this additional processing step. A format flag can be added, but I feel that it is better to wait with that until it is clear that there is a real need for it.
It would be good to document in the ENUM_FMT ioctl that formats that require additional processing are at the end of the format list.
Ezequiel, I'm marking this series as "Changes Requested" in patchwork.
Regards,
Hans
Quoted 4 lines
Best regards,
Tomasz
Quoted 85 lines · Hans Verkuil
Quoted 70 lines · Tomasz Figa
Hi Ezequiel,
Quoted 49 lines · Ezequiel Garcia
Hi all,
The Hantro G1 VPU post-processor block can be pipelined with the decoder hardware, allowing to perform operations such as color conversion, scaling, rotation, cropping, among others.
When the post-processor is enabled, the decoder hardware gets its own set of NV12 buffers (the native decoder format), and the post-processor is the owner of the CAPTURE buffers.
This allows the application get processed
(scaled, converted, etc) buffers, completely transparently.This feature is implemented by exposing the post-processed pixel formats on
ENUM_FMT. When the application sets a pixel format other than NV12, and if the post-processor is MC-linked, the driver will make use of it, transparently.On this v2, the media controller API is now required
to "enable" (aka link, in topology jargon) the post-processor. Therefore, applications now have to explicitly request this feature.For instance, the post-processor is enabled using the media-ctl tool:
media-ctl -l "'decoder':1 -> 'rockchip,rk3288-vpu-dec':0[0]" media-ctl -l "'postproc':1 -> 'rockchip,rk3288-vpu-dec':0[1]"
v4l2-ctl -d 1 --list-formats
ioctl:VIDIOC_ENUM_FMTType: Video Capture Multiplanar [0]: 'NV12' (Y/CbCr 4:2:0) [1]: 'YUYV' (YUYV 4:2:2)Patches 1 and 2 are simply cleanups needed to easier integrate the post-processor. Patch 2 is a bit invasive, but it's a step forward towards merging the implementation for RK3399 and RK3288.
Patch 3 re-works the media-topology, making the decoder a
v4l2_subdevice, instead of a bare entity. This allows to introduce a more accurate of the decoder+post-processor complex.Patch 4 introduces the post-processing support.
This is tested on RK3288 platforms with MPEG-2, VP8 and H264 streams, decoding to YUY2 surfaces. For now, this series is only adding support for NV12-to-YUY2 conversion.
Quoted 7 lines
The design and implementation is quite different from v1:
* The decoder->post-processor topology is now exposed explicitly and applications need to configure the pipeline. By default, the decoder is enabled and the post-processor is disabled.
First of all, thanks for working on this. While from Chromium point of view there isn't any practical use case for this feature, it could possibly be valuable for some other platforms.
I still see a problem with the current design. Mem-to-mem decoders are commonly used in a multi-instance fashion, but media topology is global. That means that when having two applications on the system decoding their own videos, one might be stepping on the other by changing the topology.
Quoted 7 lines
I believe that if we want this to be really usable, we would need to make the media topology per instance, but that's a significant change to the media subsystem. Maybe we could pursue the other options I suggested in the previous revision instead, like ordering the formats returned by
enum_fmtby native first and adding format flags that would tell the userspace that the format can have some performance and/or power penalty?I discussed this with Ezequiel in Lyon, and my preference is also to not rely on the media controller, but instead order the formats with the native formats first, followed by the formats that need this additional processing step. A format flag can be added, but I feel that it is better to wait with that until it is clear that there is a real need for it.
Quoted 5 lines
It would be good to document in the
ENUM_FMTioctl that formats that require additional processing are at the end of the format list.Ezequiel, I'm marking this series as "Changes Requested" in patchwork.
Thanks! I should revisit this and post a new series soon.
Ezequiel