Skip to contentSkip to conversation

media: rkvdec: Switch to using structs instead of writel

PATCH In review Detlev Casanova 4 participants 4 messages May 27, 2025 – May 28, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: rkvdec: Switch to using structs instead of writel

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 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]/

---
 drivers/staging/media/rkvdec/rkvdec-h264.c | 168 +++---
 drivers/staging/media/rkvdec/rkvdec-regs.h | 567 ++++++++++++++-------
 drivers/staging/media/rkvdec/rkvdec-vp9.c  | 239 ++++-----
 drivers/staging/media/rkvdec/rkvdec.c      |   1 -
 4 files changed, 559 insertions(+), 416 deletions(-)
drivers/staging/media/rkvdec/rkvdec-h264.c +72 -96
index 4fc167b42cf0c..85ca4a8967ceb 100644
@@ -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,		\
@@ -839,46 +840,43 @@ static void assemble_hw_scaling_list(struct rkvdec_ctx *ctx,
 	       sizeof(scaling->scaling_list_8x8));
 }
 
-/*
- * dpb poc related registers table
- */
-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 void set_poc_reg(struct rkvdec_regs *regs, uint32_t poc, int id, bool bottom)
+{
+	if (!bottom) {
+		switch (id) {
+		case 0 ... 7:
+			regs->h264.ref0_14_poc[id * 2] = poc;
+			break;
+		case 8 ... 14:
+			regs->h264.ref15_29_poc[(id - 8) * 2 + 1] = poc;
+			break;
+		case 15:
+			regs->h264.ref30_poc = poc;
+			break;
+		}
+	} else {
+		switch (id) {
+		case 0 ... 6:
+			regs->h264.ref0_14_poc[id * 2 + 1] = poc;
+			break;
+		case 7 ... 14:
+			regs->h264.ref15_29_poc[(id - 7) * 2] = poc;
+			break;
+		case 15:
+			regs->h264.ref31_poc = poc;
+			break;
+		}
+	}
+}
 
-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 rkvdec_write_regs(struct rkvdec_dev *dev, struct rkvdec_regs *regs)
+{
+#ifdef CONFIG_ARM64
+	__iowrite32_copy(dev->regs, regs, sizeof(*regs) / 4);
+#else
+	memcpy_toio(dev->regs, regs, sizeof(*regs));
+#endif
+}
 
 static void config_registers(struct rkvdec_ctx *ctx,
 			     struct rkvdec_h264_run *run)
@@ -893,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;
@@ -902,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;
+
+	memset(regs, 0, sizeof(*regs));
 
-	reg = RKVDEC_MODE(RKVDEC_MODE_H264);
-	writel_relaxed(reg, rkvdec->regs + RKVDEC_REG_SYSCTRL);
+	regs->common.reg02.dec_mode = RKVDEC_MODE_H264;
 
 	f = &ctx->decoded_fmt;
 	dst_fmt = &f->fmt.pix_mp;
@@ -920,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->h264.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
@@ -962,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 = &regs->h264.ref0_14_base[i];
 		else
-			writel_relaxed(refer_addr,
-				       rkvdec->regs + RKVDEC_REG_H264_BASE_REFER15);
-	}
+			base = &regs->h264.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->h264.cur_poc = dec_params->top_field_order_cnt;
+	regs->h264.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->h264.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->h264.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->h264.errorinfo_base = priv_start_addr + offset;
+
+	rkvdec_write_regs(rkvdec, regs);
 }
 
 #define RKVDEC_H264_MAX_DEPTH_IN_BYTES		2
@@ -1162,8 +1140,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/staging/media/rkvdec/rkvdec-regs.h +379 -188

581 lines not on this page · raw message

drivers/staging/media/rkvdec/rkvdec-vp9.c +108 -131

372 lines not on this page · raw message

drivers/staging/media/rkvdec/rkvdec.c +0 -1
index 2a44406d397f8..8d36411b663b8 100644
@@ -999,7 +999,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);
 	}
 }
Signature · 1 line
2.49.0
#1 lore raw

Hi Detlev,

Quoted 2 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.

Please wait with this until HEVC support has landed, now that H264 4:2:2/Hi10 finally have been merged I was hoping to be able to send a v2 of the old HEVC series [3]. I was waiting on v6.16-rc1 before sending the series but can send it sooner if needed, [4] has current state of v2.

H264 4:2:2/Hi10 and HEVC have been in the works for a few years now, would be nice to have it fully land before refactoring starts ;-)

[3] https://lore.kernel.org/linux-media/[email protected]
[4] https://github.com/Kwiboo/linux-rockchip/commits/linuxtv-rkvdec-hevc-v2b/

Quoted 2 lines

This is done in order to have all supported decoders use the same format in the future and ease reading of the code.

Do you have any work-in-progress patches for this?

Quoted 9 lines

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.

Are your referring to the linked-list feature (also present in e.g. RK3328) or just for multi-core purpose?

Regards,
Jonas

Quoted 25 lines

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]/

---
 drivers/staging/media/rkvdec/rkvdec-h264.c | 168 +++---
 drivers/staging/media/rkvdec/rkvdec-regs.h | 567 ++++++++++++++-------
 drivers/staging/media/rkvdec/rkvdec-vp9.c  | 239 ++++-----
 drivers/staging/media/rkvdec/rkvdec.c      |   1 -
 4 files changed, 559 insertions(+), 416 deletions(-)

[snip]

#2 lore raw

Hi Jonas,

Le mardi 27 mai 2025 à 19:51 +0200, Jonas Karlman a écrit :

Quoted 8 lines

Hi Detlev,

Quoted 2 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.

Please wait with this until HEVC support has landed, now that H264 4:2:2/Hi10 finally have been merged I was hoping to be able to send a v2

Detlev communicated to me that this was meant to have the RFC tag. The intent being to check with others if the usage of bitfield in structure for registers is acceptable. I personally like it, and don't see any issue with it considering the performance is not affected at all. The idea is not new, you can find similar proposal from 2019.

https://lore.kernel.org/all/[email protected]/

Quoted 2 lines

of the old HEVC series [3]. I was waiting on v6.16-rc1 before sending the series but can send it sooner if needed, [4] has current state of v2.

Please don't wait for that, just send as soon as your are happy with it. Just based it on current media-committers/next branch, I will deal with the rest.

Quoted 3 lines

H264 4:2:2/Hi10 and HEVC have been in the works for a few years now, would be nice to have it fully land before refactoring starts ;-)

My roadmap was that HEVC was not truly an unstaging dependency. I was a lot more worried about concurrent decode, but I have a patch in queue now. So unstaging is what I will prioritize once a patch is made. Meanwhile, better send you patches soon.

Quoted 16 lines

[3] https://lore.kernel.org/linux-media/[email protected]
[4] https://github.com/Kwiboo/linux-rockchip/commits/linuxtv-rkvdec-hevc-v2b/

Quoted 2 lines

This is done in order to have all supported decoders use the same format in the future and ease reading of the code.

Do you have any work-in-progress patches for this?

Quoted 7 lines

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).

Quoted 5 lines
Quoted 2 lines

Using structs can also help improving performance later when, e.g. multicore support is added on RK3588.

Are your referring to the linked-list feature (also present in e.g. RK3328) or just for multi-core purpose?

RK3588 multi-core design, but this is also needed if you want to use HW queues. Multi-core is more pressing at the moment, the benefit of using HW queues will have to be proven. It does not make a big difference for a single media.

Nicolas

Quoted 31 lines

Regards,
Jonas

Quoted 25 lines

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]/

---
 drivers/staging/media/rkvdec/rkvdec-h264.c | 168 +++--- drivers/staging/media/rkvdec/rkvdec-regs.h | 567 ++++++++++++++------- drivers/staging/media/rkvdec/rkvdec-vp9.c  | 239 ++++----- drivers/staging/media/rkvdec/rkvdec.c      |   1 -

 4 files changed, 559 insertions(+), 416 deletions(-)

[snip]

#3 lore raw
In reply to Detlev Casanova
kernel test robot noticed the following build warnings:

Hi Detlev,

kernel test robot noticed the following build warnings:

[auto build test WARNING on staging/staging-testing]
[also build test WARNING on staging/staging-next staging/staging-linus linuxtv-media-pending/master linus/master v6.15 next-20250527] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Detlev-Casanova/media-rkvdec-Switch-to-using-structs-instead-of-writel/20250527-230234
base:   staging/staging-testing
patch link:    https://lore.kernel.org/r/20250527150043.174415-1-detlev.casanova%40collabora.com
patch subject: [PATCH] media: rkvdec: Switch to using structs instead of writel
config: arm64-randconfig-002-20250528 (https://download.01.org/0day-ci/archive/20250528/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250528/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/staging/media/rkvdec/rkvdec-vp9.c: In function 'config_registers':

>> drivers/staging/media/rkvdec/rkvdec-vp9.c:493:6: warning: variable 'val' set but not used [-Wunused-but-set-variable]
     u32 val;
         ^~~

vim +/val +493 drivers/staging/media/rkvdec/rkvdec-vp9.c

483
484 static void config_registers(struct rkvdec_ctx *ctx,
485 const struct rkvdec_vp9_run *run)
486 {
487 unsigned int y_len, uv_len, yuv_len, bit_depth, aligned_height, aligned_pitch, stream_len;
488 const struct v4l2_ctrl_vp9_frame *dec_params;
489 struct rkvdec_decoded_buffer *ref_bufs[3];
490 struct rkvdec_decoded_buffer *dst, *last, *mv_ref;
491 struct rkvdec_vp9_ctx *vp9_ctx = ctx->priv;
492 struct rkvdec_regs *regs = &vp9_ctx->regs;

 > 493		u32 val;

494 const struct v4l2_vp9_segmentation *seg;
495 struct rkvdec_dev *rkvdec = ctx->dev;
496 dma_addr_t addr;
497 bool intra_only;
498 unsigned int i;
499
500 dec_params = run->decode_params;
501 dst = vb2_to_rkvdec_decoded_buf(&run->base.bufs.dst->vb2_buf);
502 ref_bufs[0] = get_ref_buf(ctx, &dst->base.vb, dec_params->last_frame_ts);
503 ref_bufs[1] = get_ref_buf(ctx, &dst->base.vb, dec_params->golden_frame_ts);
504 ref_bufs[2] = get_ref_buf(ctx, &dst->base.vb, dec_params->alt_frame_ts);
505
506 if (vp9_ctx->last.valid)
507 last = get_ref_buf(ctx, &dst->base.vb, vp9_ctx->last.timestamp);
508 else
509 last = dst;
510
511 update_dec_buf_info(dst, dec_params);
512 update_ctx_cur_info(vp9_ctx, dst, dec_params);
513 seg = &dec_params->seg;
514
515 intra_only = !!(dec_params->flags &
516 (V4L2_VP9_FRAME_FLAG_KEY_FRAME |
517 V4L2_VP9_FRAME_FLAG_INTRA_ONLY));
518
519 regs->common.reg02.dec_mode = RKVDEC_MODE_VP9;
520
521 bit_depth = dec_params->bit_depth;
522 aligned_height = round_up(ctx->decoded_fmt.fmt.pix_mp.height, 64);
523
524 aligned_pitch = round_up(ctx->decoded_fmt.fmt.pix_mp.width *
525 bit_depth,
526 512) / 8;
527 y_len = aligned_height * aligned_pitch;
528 uv_len = y_len / 2;
529 yuv_len = y_len + uv_len;
530
531 regs->common.reg03.y_hor_virstride = aligned_pitch / 16;
532 regs->common.reg03.uv_hor_virstride = aligned_pitch / 16;
533 regs->common.reg08.y_virstride = y_len / 16;
534 regs->common.reg09.yuv_virstride = yuv_len / 16;
535
536 stream_len = vb2_get_plane_payload(&run->base.bufs.src->vb2_buf, 0);
537
538 regs->common.stream_len = stream_len;
539
540 /*
541 * Reset count buffer, because decoder only output intra related syntax
542 * counts when decoding intra frame, but update entropy need to update
543 * all the probabilities.
544 */
545 if (intra_only)
546 memset(vp9_ctx->count_tbl.cpu, 0, vp9_ctx->count_tbl.size);
547
548 vp9_ctx->cur.segmapid = vp9_ctx->last.segmapid;
549 if (!intra_only &&
550 !(dec_params->flags & V4L2_VP9_FRAME_FLAG_ERROR_RESILIENT) &&
551 (!(seg->flags & V4L2_VP9_SEGMENTATION_FLAG_ENABLED) ||
552 (seg->flags & V4L2_VP9_SEGMENTATION_FLAG_UPDATE_MAP)))
553 vp9_ctx->cur.segmapid++;
554
555 for (i = 0; i < ARRAY_SIZE(ref_bufs); i++)
556 config_ref_registers(ctx, run, ref_bufs[i], i);
557
558 for (i = 0; i < 8; i++)
559 config_seg_registers(ctx, i);
560
561 regs->vp9.reg28.tx_mode = vp9_ctx->cur.tx_mode;
562 regs->vp9.reg28.frame_reference_mode = dec_params->reference_mode;
563
564 if (!intra_only) {
565 const struct v4l2_vp9_loop_filter *lf;
566 s8 delta;
567
568 if (vp9_ctx->last.valid)
569 lf = &vp9_ctx->last.lf;
570 else
571 lf = &vp9_ctx->cur.lf;
572
573 val = 0;
574 for (i = 0; i < ARRAY_SIZE(lf->ref_deltas); i++) {
575 delta = lf->ref_deltas[i];
576 switch (i) {
577 case 0:
578 regs->vp9.reg32.ref_deltas_lastframe0 = delta;
579 break;
580 case 1:
581 regs->vp9.reg32.ref_deltas_lastframe1 = delta;
582 break;
583 case 2:
584 regs->vp9.reg32.ref_deltas_lastframe2 = delta;
585 break;
586 case 3:
587 regs->vp9.reg32.ref_deltas_lastframe3 = delta;
588 break;
589 }
590 }
591
592 for (i = 0; i < ARRAY_SIZE(lf->mode_deltas); i++) {
593 delta = lf->mode_deltas[i];
594 switch (i) {
595 case 0:
596 regs->vp9.reg33.mode_deltas_lastframe0 = delta;
597 break;
598 case 1:
599 regs->vp9.reg33.mode_deltas_lastframe1 = delta;
600 break;
601 }
602 }
603 }
604
605 regs->vp9.reg33.segmentation_enable_lstframe =
606 vp9_ctx->last.valid && !intra_only &&
607 vp9_ctx->last.seg.flags & V4L2_VP9_SEGMENTATION_FLAG_ENABLED;
608
609 regs->vp9.reg33.last_show_frame =
610 vp9_ctx->last.valid &&
611 vp9_ctx->last.flags & V4L2_VP9_FRAME_FLAG_SHOW_FRAME;
612
613 regs->vp9.reg33.last_intra_only =
614 vp9_ctx->last.valid &&
615 vp9_ctx->last.flags &
616 (V4L2_VP9_FRAME_FLAG_KEY_FRAME | V4L2_VP9_FRAME_FLAG_INTRA_ONLY);
617
618 regs->vp9.reg33.last_widthheight_eqcur =
619 vp9_ctx->last.valid &&
620 last->vp9.width == dst->vp9.width &&
621 last->vp9.height == dst->vp9.height;
622
623 regs->vp9.reg36.lasttile_size =
624 stream_len - dec_params->compressed_header_size -
625 dec_params->uncompressed_header_size;
626
627 for (i = 0; !intra_only && i < ARRAY_SIZE(ref_bufs); i++) {
628 unsigned int refw = ref_bufs[i]->vp9.width;
629 unsigned int refh = ref_bufs[i]->vp9.height;
630 u32 hscale, vscale;
631
632 hscale = (refw << 14) / dst->vp9.width;
633 vscale = (refh << 14) / dst->vp9.height;
634
635 regs->vp9.reg29_31[i].ref_hor_scale = hscale;
636 regs->vp9.reg29_31[i].ref_ver_scale = vscale;
637 }
638
639 addr = vb2_dma_contig_plane_dma_addr(&dst->base.vb.vb2_buf, 0);
640 regs->common.decout_base = addr;
641 addr = vb2_dma_contig_plane_dma_addr(&run->base.bufs.src->vb2_buf, 0);
642 regs->common.strm_rlc_base = addr;
643
644 regs->common.cabactbl_base = vp9_ctx->priv_tbl.dma +
645 offsetof(struct rkvdec_vp9_priv_tbl, probs);
646
647 regs->vp9.count_base = vp9_ctx->count_tbl.dma;
648
649 regs->vp9.segidlast_base = vp9_ctx->priv_tbl.dma +
650 offsetof(struct rkvdec_vp9_priv_tbl, segmap) +
651 (RKVDEC_VP9_MAX_SEGMAP_SIZE * (!vp9_ctx->cur.segmapid));
652
653 regs->vp9.segidcur_base = vp9_ctx->priv_tbl.dma +
654 offsetof(struct rkvdec_vp9_priv_tbl, segmap) +
655 (RKVDEC_VP9_MAX_SEGMAP_SIZE * vp9_ctx->cur.segmapid);
656
657 if (!intra_only &&
658 !(dec_params->flags & V4L2_VP9_FRAME_FLAG_ERROR_RESILIENT) &&
659 vp9_ctx->last.valid)
660 mv_ref = last;
661 else
662 mv_ref = dst;
663
664 regs->vp9.refcolmv_base = get_mv_base_addr(mv_ref);
665
666 regs->vp9.performance_cycle = ctx->decoded_fmt.fmt.pix_mp.width |
667 (ctx->decoded_fmt.fmt.pix_mp.height << 16);
668
669 regs->vp9.reg44.strmd_error_e = 0xe;
670
671 rkvdec_write_regs(rkvdec, regs);
672 }
673

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki