Skip to contentSkip to conversation

Wave515 decoder IP support

PATCH Superseded Ivan Bornyakov 2 participants 12 messages Apr 5, 2024 – Apr 15, 2024

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Wave515 decoder IP support

Initial support for Wave515 multi-decoder IP among other refinements. This was tested on FPGA prototype, so wave5_dt_ids[] was not expanded.

fluster score for JCT-VC-HEVC_V1 testsuite with
GStreamer-H.265-V4L2-Gst1.0 decoder is 132/147

The issue with Main10 tests is that fluster expects decoded file to be in yuv420p10le format while this driver decodes HEVC Main10 into 8-bit yuv420p. Though result is looks alright to the naked eye, proper decoding into yuv420p10le is to be added.

The rest failed fluster tests are common with Wave521.

ChangeLog:
v1:
https://lore.kernel.org/linux-media/[email protected]/
v2:
https://lore.kernel.org/linux-media/[email protected]/
* drop patch "dt-bindings: media: cnm,wave521c: drop resets restriction" The only user of Wave5 in mainline is TI K3 boards, thus there is no real need to alter dt-bindings
* in patch "media: chips-media: wave5: support decoding HEVC Main10 profile" add check for flag "support_hevc10bit_dec"
* in patch "media: chips-media: wave5: support reset lines" move reset_control_deassert() out of else branch, add reset_control_assert() to probe error path.
* rework patch "media: chips-media: wave5: drop "sram-size" DT prop"
- don't move alloc/free form device open/close
- intead of exact configuration of reserved SRAM memory in DT and allocating all of it, allocate all available SRAM memory up to WAVE5_MAX_SRAM_SIZE from whatever pool provided.
* adjust patch "media: chips-media: wave5: support Wave515 decoder" according to changes in patches
"media: chips-media: wave5: support decoding HEVC Main10 profile" and "media: chips-media: wave5: drop "sram-size" DT prop"
v3:
* reword patch "media: chips-media: wave5: separate irq setup routine" a bit.
* in patch "media: chips-media: wave5: drop "sram-size" DT prop"
- move MAX_SRAM_SIZE define into match_data->sram_size
- add placeholders for validation that allocated SRAM memory is enough to encode/decode bitstream of given resolution before setting W5_USE_SEC_AXI and W5_CMD_ENC_PIC_USE_SEC_AXI registers
- reword accordingly
* in patch "media: chips-media: wave5: support Wave515 decoder"
- add comments around SRAM memory allocation/freeing about Wave515 specifics
- add comments about BSOPTION_RD_PTR_VALID_FLAG bit in W5_BS_OPTION register
- add W[AVE]521_ prefix to defines, for wich there are W[AVE]515_ alternatieves
- add semi-magic Wave515 specific formulas to estimate SRAM usage

Ivan Bornyakov (5):
media: chips-media: wave5: support decoding HEVC Main10 profile
media: chips-media: wave5: support reset lines
media: chips-media: wave5: separate irq setup routine
media: chips-media: wave5: drop "sram-size" DT prop
media: chips-media: wave5: support Wave515 decoder

 .../platform/chips-media/wave5/wave5-helper.c |   8 +-
 .../platform/chips-media/wave5/wave5-hw.c     | 395 +++++++++++++-----
 .../chips-media/wave5/wave5-regdefine.h       |   5 +
 .../platform/chips-media/wave5/wave5-vdi.c    |  27 +-
 .../chips-media/wave5/wave5-vpu-dec.c         |  51 ++-
 .../chips-media/wave5/wave5-vpu-enc.c         |   2 +-
 .../platform/chips-media/wave5/wave5-vpu.c    |  35 +-
 .../platform/chips-media/wave5/wave5-vpuapi.h |   3 +
 .../chips-media/wave5/wave5-vpuconfig.h       |  16 +-
 .../media/platform/chips-media/wave5/wave5.h  |   6 +
 10 files changed, 407 insertions(+), 141 deletions(-)
Signature · 1 line
2.44.0
#1 lore raw

PATCH v3 1/5 media: chips-media: wave5: support decoding HEVC Main10 profile

Add support for decoding HEVC Main10 profile by scaling FBC buffer stride and size by the factor of (bitdepth / 8).

---
 .../chips-media/wave5/wave5-vpu-dec.c         | 30 +++++++++++--------
 .../platform/chips-media/wave5/wave5-vpuapi.h |  1 +
 2 files changed, 18 insertions(+), 13 deletions(-)
drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c +17 -13
index ef227af72348..5a71a711f2e8 100644
@@ -1055,6 +1055,22 @@ static int wave5_prepare_fb(struct vpu_instance *inst)
 	int ret, i;
 	struct v4l2_m2m_buffer *buf, *n;
 	struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx;
+	u32 bitdepth = inst->codec_info->dec_info.initial_info.luma_bitdepth;
+
+	switch (bitdepth) {
+	case 8:
+		break;
+	case 10:
+		if (inst->std == W_HEVC_DEC &&
+		    inst->dev->attr.support_hevc10bit_dec)
+			break;
+
+		fallthrough;
+	default:
+		dev_err(inst->dev->dev, "no support for %d bit depth\n", bitdepth);
+
+		return -EINVAL;
+	}
 
 	linear_num = v4l2_m2m_num_dst_bufs_ready(m2m_ctx);
 	non_linear_num = inst->fbc_buf_count;
@@ -1063,7 +1079,7 @@ static int wave5_prepare_fb(struct vpu_instance *inst)
 		struct frame_buffer *frame = &inst->frame_buf[i];
 		struct vpu_buf *vframe = &inst->frame_vbuf[i];
 
-		fb_stride = inst->dst_fmt.width;
+		fb_stride = ALIGN(inst->dst_fmt.width * bitdepth / 8, 32);
 		fb_height = ALIGN(inst->dst_fmt.height, 32);
 		luma_size = fb_stride * fb_height;
 
@@ -1408,22 +1424,10 @@ static int wave5_vpu_dec_start_streaming(struct vb2_queue *q, unsigned int count
 		if (ret)
 			goto free_bitstream_vbuf;
 	} else if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
-		struct dec_initial_info *initial_info =
-			&inst->codec_info->dec_info.initial_info;
-
 		if (inst->state == VPU_INST_STATE_STOP)
 			ret = switch_state(inst, VPU_INST_STATE_INIT_SEQ);
 		if (ret)
 			goto return_buffers;
-
-		if (inst->state == VPU_INST_STATE_INIT_SEQ) {
-			if (initial_info->luma_bitdepth != 8) {
-				dev_info(inst->dev->dev, "%s: no support for %d bit depth",
-					 __func__, initial_info->luma_bitdepth);
-				ret = -EINVAL;
-				goto return_buffers;
-			}
-		}
 	}
 
 	return ret;
drivers/media/platform/chips-media/wave5/wave5-vpuapi.h +1 -0
index 352f6e904e50..465ff9dfe8b1 100644
@@ -327,6 +327,7 @@ struct vpu_attr {
 	u32 support_backbone: 1;
 	u32 support_avc10bit_enc: 1;
 	u32 support_hevc10bit_enc: 1;
+	u32 support_hevc10bit_dec: 1;
 	u32 support_vcore_backbone: 1;
 	u32 support_vcpu_backbone: 1;
 };
Signature · 1 line
2.44.0
#2 lore raw

PATCH v3 2/5 media: chips-media: wave5: support reset lines

In reply to Ivan Bornyakov

Add initial support for optional reset lines. For now, simply deassert resets on driver probe and assert them back on driver remove.

---
 .../media/platform/chips-media/wave5/wave5-vpu.c | 16 +++++++++++++++-
 .../platform/chips-media/wave5/wave5-vpuapi.h    |  1 +
 2 files changed, 16 insertions(+), 1 deletion(-)
drivers/media/platform/chips-media/wave5/wave5-vpu.c +15 -1
index 1b3df5b04249..1e631da58e15 100644
@@ -10,6 +10,7 @@
 #include <linux/clk.h>
 #include <linux/firmware.h>
 #include <linux/interrupt.h>
+#include <linux/reset.h>
 #include "wave5-vpu.h"
 #include "wave5-regdefine.h"
 #include "wave5-vpuconfig.h"
@@ -151,6 +152,16 @@ static int wave5_vpu_probe(struct platform_device *pdev)
 	dev_set_drvdata(&pdev->dev, dev);
 	dev->dev = &pdev->dev;
 
+	dev->resets = devm_reset_control_array_get_optional_exclusive(&pdev->dev);
+	if (IS_ERR(dev->resets)) {
+		return dev_err_probe(&pdev->dev, PTR_ERR(dev->resets),
+				     "Failed to get reset control\n");
+	}
+
+	ret = reset_control_deassert(dev->resets);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "Failed to deassert resets\n");
+
 	ret = devm_clk_bulk_get_all(&pdev->dev, &dev->clks);
 
 	/* continue without clock, assume externally managed */
@@ -163,7 +174,7 @@ static int wave5_vpu_probe(struct platform_device *pdev)
 	ret = clk_bulk_prepare_enable(dev->num_clks, dev->clks);
 	if (ret) {
 		dev_err(&pdev->dev, "Enabling clocks, fail: %d\n", ret);
-		return ret;
+		goto err_reset_assert;
 	}
 
 	ret = of_property_read_u32(pdev->dev.of_node, "sram-size",
@@ -246,6 +257,8 @@ static int wave5_vpu_probe(struct platform_device *pdev)
 	wave5_vdi_release(&pdev->dev);
 err_clk_dis:
 	clk_bulk_disable_unprepare(dev->num_clks, dev->clks);
+err_reset_assert:
+	reset_control_assert(dev->resets);
 
 	return ret;
 }
@@ -256,6 +269,7 @@ static void wave5_vpu_remove(struct platform_device *pdev)
 
 	mutex_destroy(&dev->dev_lock);
 	mutex_destroy(&dev->hw_lock);
+	reset_control_assert(dev->resets);
 	clk_bulk_disable_unprepare(dev->num_clks, dev->clks);
 	wave5_vpu_enc_unregister_device(dev);
 	wave5_vpu_dec_unregister_device(dev);
drivers/media/platform/chips-media/wave5/wave5-vpuapi.h +1 -0
index 465ff9dfe8b1..da530fd98964 100644
@@ -758,6 +758,7 @@ struct vpu_device {
 	struct ida inst_ida;
 	struct clk_bulk_data *clks;
 	int num_clks;
+	struct reset_control *resets;
 };
 
 struct vpu_instance;
Signature · 1 line
2.44.0
#3 lore raw

PATCH v3 3/5 media: chips-media: wave5: separate irq setup routine

In reply to Ivan Bornyakov

Implement a separate setup routine for interrupts to reduce code duplication. Also enable interrupts based on vpu_attr->support_encoders and vpu_attr->support_decoders fields to facilitate support for other Wave5xx IPs, because not all of them are both encoders and decoders.

---
 .../platform/chips-media/wave5/wave5-hw.c     | 53 +++++++++----------
 1 file changed, 24 insertions(+), 29 deletions(-)
drivers/media/platform/chips-media/wave5/wave5-hw.c +24 -29
index 2d82791f575e..cdd0a0948a94 100644
@@ -299,6 +299,27 @@ static int wave5_send_query(struct vpu_device *vpu_dev, struct vpu_instance *ins
 	return wave5_vpu_firmware_command_queue_error_check(vpu_dev, NULL);
 }
 
+static void setup_wave5_interrupts(struct vpu_device *vpu_dev)
+{
+	u32 reg_val = 0;
+
+	if (vpu_dev->attr.support_encoders) {
+		/* Encoder interrupt */
+		reg_val |= BIT(INT_WAVE5_ENC_SET_PARAM);
+		reg_val |= BIT(INT_WAVE5_ENC_PIC);
+		reg_val |= BIT(INT_WAVE5_BSBUF_FULL);
+	}
+
+	if (vpu_dev->attr.support_decoders) {
+		/* Decoder interrupt */
+		reg_val |= BIT(INT_WAVE5_INIT_SEQ);
+		reg_val |= BIT(INT_WAVE5_DEC_PIC);
+		reg_val |= BIT(INT_WAVE5_BSBUF_EMPTY);
+	}
+
+	return vpu_write_reg(vpu_dev, W5_VPU_VINT_ENABLE, reg_val);
+}
+
 static int setup_wave5_properties(struct device *dev)
 {
 	struct vpu_device *vpu_dev = dev_get_drvdata(dev);
@@ -340,6 +361,8 @@ static int setup_wave5_properties(struct device *dev)
 	p_attr->support_vcpu_backbone = FIELD_GET(FEATURE_VCPU_BACKBONE, hw_config_def0);
 	p_attr->support_vcore_backbone = FIELD_GET(FEATURE_VCORE_BACKBONE, hw_config_def0);
 
+	setup_wave5_interrupts(vpu_dev);
+
 	return 0;
 }
 
@@ -417,16 +440,6 @@ int wave5_vpu_init(struct device *dev, u8 *fw, size_t size)
 	wave5_fio_writel(vpu_dev, W5_BACKBONE_AXI_PARAM, 0);
 	vpu_write_reg(vpu_dev, W5_SEC_AXI_PARAM, 0);
 
-	/* Encoder interrupt */
-	reg_val = BIT(INT_WAVE5_ENC_SET_PARAM);
-	reg_val |= BIT(INT_WAVE5_ENC_PIC);
-	reg_val |= BIT(INT_WAVE5_BSBUF_FULL);
-	/* Decoder interrupt */
-	reg_val |= BIT(INT_WAVE5_INIT_SEQ);
-	reg_val |= BIT(INT_WAVE5_DEC_PIC);
-	reg_val |= BIT(INT_WAVE5_BSBUF_EMPTY);
-	vpu_write_reg(vpu_dev, W5_VPU_VINT_ENABLE, reg_val);
-
 	reg_val = vpu_read_reg(vpu_dev, W5_VPU_RET_VPU_CONFIG0);
 	if (FIELD_GET(FEATURE_BACKBONE, reg_val)) {
 		reg_val = ((WAVE5_PROC_AXI_ID << 28) |
@@ -1034,16 +1047,6 @@ int wave5_vpu_re_init(struct device *dev, u8 *fw, size_t size)
 		wave5_fio_writel(vpu_dev, W5_BACKBONE_AXI_PARAM, 0);
 		vpu_write_reg(vpu_dev, W5_SEC_AXI_PARAM, 0);
 
-		/* Encoder interrupt */
-		reg_val = BIT(INT_WAVE5_ENC_SET_PARAM);
-		reg_val |= BIT(INT_WAVE5_ENC_PIC);
-		reg_val |= BIT(INT_WAVE5_BSBUF_FULL);
-		/* Decoder interrupt */
-		reg_val |= BIT(INT_WAVE5_INIT_SEQ);
-		reg_val |= BIT(INT_WAVE5_DEC_PIC);
-		reg_val |= BIT(INT_WAVE5_BSBUF_EMPTY);
-		vpu_write_reg(vpu_dev, W5_VPU_VINT_ENABLE, reg_val);
-
 		reg_val = vpu_read_reg(vpu_dev, W5_VPU_RET_VPU_CONFIG0);
 		if (FIELD_GET(FEATURE_BACKBONE, reg_val)) {
 			reg_val = ((WAVE5_PROC_AXI_ID << 28) |
@@ -1134,15 +1137,7 @@ static int wave5_vpu_sleep_wake(struct device *dev, bool i_sleep_wake, const uin
 		wave5_fio_writel(vpu_dev, W5_BACKBONE_AXI_PARAM, 0);
 		vpu_write_reg(vpu_dev, W5_SEC_AXI_PARAM, 0);
 
-		/* Encoder interrupt */
-		reg_val = BIT(INT_WAVE5_ENC_SET_PARAM);
-		reg_val |= BIT(INT_WAVE5_ENC_PIC);
-		reg_val |= BIT(INT_WAVE5_BSBUF_FULL);
-		/* Decoder interrupt */
-		reg_val |= BIT(INT_WAVE5_INIT_SEQ);
-		reg_val |= BIT(INT_WAVE5_DEC_PIC);
-		reg_val |= BIT(INT_WAVE5_BSBUF_EMPTY);
-		vpu_write_reg(vpu_dev, W5_VPU_VINT_ENABLE, reg_val);
+		setup_wave5_interrupts(vpu_dev);
 
 		reg_val = vpu_read_reg(vpu_dev, W5_VPU_RET_VPU_CONFIG0);
 		if (FIELD_GET(FEATURE_BACKBONE, reg_val)) {
Signature · 1 line
2.44.0
#4 lore raw

PATCH v3 4/5 media: chips-media: wave5: drop "sram-size" DT prop

In reply to Ivan Bornyakov

Move excessive "sram-size" device-tree property to device match data. Also change SRAM memory allocation strategy: instead of allocation exact sram_size bytes, allocate all available SRAM memory up to sram_size. Add placeholders wave5_vpu_dec_validate_sec_axi() and wave5_vpu_enc_validate_sec_axi() for validation that allocated SRAM memory is enough to decode/encode bitstream of given resolution.

---
 .../platform/chips-media/wave5/wave5-hw.c     | 62 +++++++++++++++++--
 .../platform/chips-media/wave5/wave5-vdi.c    | 21 ++++---
 .../platform/chips-media/wave5/wave5-vpu.c    | 11 ++--
 3 files changed, 72 insertions(+), 22 deletions(-)
drivers/media/platform/chips-media/wave5/wave5-hw.c +57 -5
index cdd0a0948a94..36f2fc818013 100644
@@ -843,6 +843,36 @@ int wave5_vpu_dec_register_framebuffer(struct vpu_instance *inst, struct frame_b
 	return ret;
 }
 
+static u32 wave5_vpu_dec_validate_sec_axi(struct vpu_instance *inst)
+{
+	struct dec_info *p_dec_info = &inst->codec_info->dec_info;
+	u32 bit_size = 0, ip_size = 0, lf_size = 0, ret = 0;
+	u32 sram_size = inst->dev->sram_size;
+
+	if (!sram_size)
+		return 0;
+
+	/*
+	 * TODO: calculate bit_size, ip_size, lf_size from inst->src_fmt.width
+	 * and inst->codec_info->dec_info.initial_info.luma_bitdepth
+	 */
+
+	if (p_dec_info->sec_axi_info.use_bit_enable && sram_size >= bit_size) {
+		ret |= BIT(0);
+		sram_size -= bit_size;
+	}
+
+	if (p_dec_info->sec_axi_info.use_ip_enable && sram_size >= ip_size) {
+		ret |= BIT(9);
+		sram_size -= ip_size;
+	}
+
+	if (p_dec_info->sec_axi_info.use_lf_row_enable && sram_size >= lf_size)
+		ret |= BIT(15);
+
+	return ret;
+}
+
 int wave5_vpu_decode(struct vpu_instance *inst, u32 *fail_res)
 {
 	u32 reg_val;
@@ -855,9 +885,7 @@ int wave5_vpu_decode(struct vpu_instance *inst, u32 *fail_res)
 	vpu_write_reg(inst->dev, W5_BS_OPTION, get_bitstream_options(p_dec_info));
 
 	/* secondary AXI */
-	reg_val = p_dec_info->sec_axi_info.use_bit_enable |
-		(p_dec_info->sec_axi_info.use_ip_enable << 9) |
-		(p_dec_info->sec_axi_info.use_lf_row_enable << 15);
+	reg_val = wave5_vpu_dec_validate_sec_axi(inst);
 	vpu_write_reg(inst->dev, W5_USE_SEC_AXI, reg_val);
 
 	/* set attributes of user buffer */
@@ -1938,6 +1966,31 @@ int wave5_vpu_enc_register_framebuffer(struct device *dev, struct vpu_instance *
 	return ret;
 }
 
+static u32 wave5_vpu_enc_validate_sec_axi(struct vpu_instance *inst)
+{
+	struct enc_info *p_enc_info = &inst->codec_info->enc_info;
+	u32 rdo_size = 0, lf_size = 0, ret = 0;
+	u32 sram_size = inst->dev->sram_size;
+
+	if (!sram_size)
+		return 0;
+
+	/*
+	 * TODO: calculate rdo_size and lf_size from inst->src_fmt.width and
+	 * inst->codec_info->enc_info.open_param.wave_param.internal_bit_depth
+	 */
+
+	if (p_enc_info->sec_axi_info.use_enc_rdo_enable && sram_size >= rdo_size) {
+		ret |= BIT(11);
+		sram_size -= rdo_size;
+	}
+
+	if (p_enc_info->sec_axi_info.use_enc_lf_enable && sram_size >= lf_size)
+		ret |= BIT(15);
+
+	return ret;
+}
+
 int wave5_vpu_encode(struct vpu_instance *inst, struct enc_param *option, u32 *fail_res)
 {
 	u32 src_frame_format;
@@ -1959,8 +2012,7 @@ int wave5_vpu_encode(struct vpu_instance *inst, struct enc_param *option, u32 *f
 
 	vpu_write_reg(inst->dev, W5_CMD_ENC_PIC_SRC_AXI_SEL, DEFAULT_SRC_AXI);
 	/* secondary AXI */
-	reg_val = (p_enc_info->sec_axi_info.use_enc_rdo_enable << 11) |
-		(p_enc_info->sec_axi_info.use_enc_lf_enable << 15);
+	reg_val = wave5_vpu_enc_validate_sec_axi(inst);
 	vpu_write_reg(inst->dev, W5_CMD_ENC_PIC_USE_SEC_AXI, reg_val);
 
 	vpu_write_reg(inst->dev, W5_CMD_ENC_PIC_REPORT_PARAM, 0);
drivers/media/platform/chips-media/wave5/wave5-vdi.c +11 -10
index 3809f70bc0b4..556de2f043fe 100644
@@ -174,16 +174,19 @@ int wave5_vdi_allocate_array(struct vpu_device *vpu_dev, struct vpu_buf *array,
 void wave5_vdi_allocate_sram(struct vpu_device *vpu_dev)
 {
 	struct vpu_buf *vb = &vpu_dev->sram_buf;
+	dma_addr_t daddr;
+	void *vaddr;
+	size_t size;
 
-	if (!vpu_dev->sram_pool || !vpu_dev->sram_size)
+	if (!vpu_dev->sram_pool || vb->vaddr)
 		return;
 
-	if (!vb->vaddr) {
-		vb->size = vpu_dev->sram_size;
-		vb->vaddr = gen_pool_dma_alloc(vpu_dev->sram_pool, vb->size,
-					       &vb->daddr);
-		if (!vb->vaddr)
-			vb->size = 0;
+	size = min_t(size_t, vpu_dev->sram_size, gen_pool_avail(vpu_dev->sram_pool));
+	vaddr = gen_pool_dma_alloc(vpu_dev->sram_pool, size, &daddr);
+	if (vaddr) {
+		vb->vaddr = vaddr;
+		vb->daddr = daddr;
+		vb->size = size;
 	}
 
 	dev_dbg(vpu_dev->dev, "%s: sram daddr: %pad, size: %zu, vaddr: 0x%p\n",
@@ -197,9 +200,7 @@ void wave5_vdi_free_sram(struct vpu_device *vpu_dev)
 	if (!vb->size || !vb->vaddr)
 		return;
 
-	if (vb->vaddr)
-		gen_pool_free(vpu_dev->sram_pool, (unsigned long)vb->vaddr,
-			      vb->size);
+	gen_pool_free(vpu_dev->sram_pool, (unsigned long)vb->vaddr, vb->size);
 
 	memset(vb, 0, sizeof(*vb));
 }
drivers/media/platform/chips-media/wave5/wave5-vpu.c +4 -7
index 1e631da58e15..9e93969ab6db 100644
@@ -25,6 +25,7 @@
 struct wave5_match_data {
 	int flags;
 	const char *fw_name;
+	u32 sram_size;
 };
 
 int wave5_vpu_wait_interrupt(struct vpu_instance *inst, unsigned int timeout)
@@ -177,17 +178,12 @@ static int wave5_vpu_probe(struct platform_device *pdev)
 		goto err_reset_assert;
 	}
 
-	ret = of_property_read_u32(pdev->dev.of_node, "sram-size",
-				   &dev->sram_size);
-	if (ret) {
-		dev_warn(&pdev->dev, "sram-size not found\n");
-		dev->sram_size = 0;
-	}
-
 	dev->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0);
 	if (!dev->sram_pool)
 		dev_warn(&pdev->dev, "sram node not found\n");
 
+	dev->sram_size = match_data->sram_size;
+
 	dev->product_code = wave5_vdi_read_register(dev, VPU_PRODUCT_CODE_REGISTER);
 	ret = wave5_vdi_init(&pdev->dev);
 	if (ret < 0) {
@@ -281,6 +277,7 @@ static void wave5_vpu_remove(struct platform_device *pdev)
 static const struct wave5_match_data ti_wave521c_data = {
 	.flags = WAVE5_IS_ENC | WAVE5_IS_DEC,
 	.fw_name = "cnm/wave521c_k3_codec_fw.bin",
+	.sram_size = (64 * 1024),
 };
 
 static const struct of_device_id wave5_dt_ids[] = {
Signature · 1 line
2.44.0
maintainer
#5 lore raw

RE: [PATCH v3 4/5] media: chips-media: wave5: drop "sram-size" DT prop

Hey Ivan

Quoted 33 lines

-----Original Message-----
From: Ivan Bornyakov <[email protected]>
Sent: Saturday, April 6, 2024 1:41 AM
To: Nas Chung <[email protected]>; jackson.lee <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Philipp Zabel <[email protected]>; Sebastian Fricke <[email protected]>
Cc: Ivan Bornyakov <[email protected]>; [email protected]; [email protected]
Subject: [PATCH v3 4/5] media: chips-media: wave5: drop "sram-size" DT prop

Move excessive "sram-size" device-tree property to device match data. Also change SRAM memory allocation strategy: instead of allocation exact sram_size bytes, allocate all available SRAM memory up to sram_size. Add placeholders wave5_vpu_dec_validate_sec_axi() and wave5_vpu_enc_validate_sec_axi() for validation that allocated SRAM memory is enough to decode/encode bitstream of given resolution.

---
 .../platform/chips-media/wave5/wave5-hw.c     | 62 +++++++++++++++++--
 .../platform/chips-media/wave5/wave5-vdi.c    | 21 ++++---
 .../platform/chips-media/wave5/wave5-vpu.c    | 11 ++--
 3 files changed, 72 insertions(+), 22 deletions(-)
drivers/media/platform/chips-media/wave5/wave5-hw.c +0 -0
index cdd0a0948a94..36f2fc818013 100644
@@ -843,6 +843,36 @@ int wave5_vpu_dec_register_framebuffer(struct

vpu_instance *inst, struct frame_b

drivers/media/platform/chips-media/wave5/wave5-hw.c int wave5_vpu_dec_register_framebuffer(struct vpu_instance *inst, struct frame_b · line 849

Quoted 6 lines
drivers/media/platform/chips-media/wave5/wave5-hw.c +3 -0
 	return ret;
 }
 
+static u32 wave5_vpu_dec_validate_sec_axi(struct vpu_instance *inst) {
+	struct dec_info *p_dec_info = &inst->codec_info->dec_info;
+	u32 bit_size = 0, ip_size = 0, lf_size = 0, ret = 0;

The bit_size, ip_size and 1f_size is always 0? If so, why are you using them ?

Quoted 47 lines
drivers/media/platform/chips-media/wave5/wave5-hw.c +7 -0
+	u32 sram_size = inst->dev->sram_size;
+
+	if (!sram_size)
+		return 0;
+
+	/*
+	 * TODO: calculate bit_size, ip_size, lf_size from inst-
Quoted 1 line

src_fmt.width

drivers/media/platform/chips-media/wave5/wave5-hw.c +4 -0
+	 * and inst->codec_info->dec_info.initial_info.luma_bitdepth
+	 */
+
+	if (p_dec_info->sec_axi_info.use_bit_enable && sram_size >=

bit_size) {

drivers/media/platform/chips-media/wave5/wave5-hw.c +5 -0
+		ret |= BIT(0);
+		sram_size -= bit_size;
+	}
+
+	if (p_dec_info->sec_axi_info.use_ip_enable && sram_size >= ip_size)

{

drivers/media/platform/chips-media/wave5/wave5-hw.c +5 -0
+		ret |= BIT(9);
+		sram_size -= ip_size;
+	}
+
+	if (p_dec_info->sec_axi_info.use_lf_row_enable && sram_size >=

lf_size)

drivers/media/platform/chips-media/wave5/wave5-hw.c +6 -3
+		ret |= BIT(15);
+
+	return ret;
+}
+
 int wave5_vpu_decode(struct vpu_instance *inst, u32 *fail_res)  {
 	u32 reg_val;
@@ -855,9 +885,7 @@ int wave5_vpu_decode(struct vpu_instance *inst, u32
 *fail_res)
 	vpu_write_reg(inst->dev, W5_BS_OPTION,
 get_bitstream_options(p_dec_info));
 
 	/* secondary AXI */
-	reg_val = p_dec_info->sec_axi_info.use_bit_enable |
-		(p_dec_info->sec_axi_info.use_ip_enable << 9) |
-		(p_dec_info->sec_axi_info.use_lf_row_enable << 15);
+	reg_val = wave5_vpu_dec_validate_sec_axi(inst);
 	vpu_write_reg(inst->dev, W5_USE_SEC_AXI, reg_val);
drivers/media/platform/chips-media/wave5/wave5-hw.c +0 -0
 	/* set attributes of user buffer */
@@ -1938,6 +1966,31 @@ int wave5_vpu_enc_register_framebuffer(struct

device *dev, struct vpu_instance *

drivers/media/platform/chips-media/wave5/wave5-hw.c int wave5_vpu_enc_register_framebuffer(struct device *dev, struct vpu_instance * · line 1972

Quoted 6 lines
drivers/media/platform/chips-media/wave5/wave5-hw.c +3 -0
 	return ret;
 }
 
+static u32 wave5_vpu_enc_validate_sec_axi(struct vpu_instance *inst) {
+	struct enc_info *p_enc_info = &inst->codec_info->enc_info;
+	u32 rdo_size = 0, lf_size = 0, ret = 0;

The rdo_size and 1f_size is always 0? If so, why are you using them ?

drivers/media/platform/chips-media/wave5/wave5-vdi.c

Quoted 45 lines
drivers/media/platform/chips-media/wave5/wave5-hw.c +7 -0
+	u32 sram_size = inst->dev->sram_size;
+
+	if (!sram_size)
+		return 0;
+
+	/*
+	 * TODO: calculate rdo_size and lf_size from inst->src_fmt.width

and

drivers/media/platform/chips-media/wave5/wave5-hw.c +1 -0
+	 * inst->codec_info-
Quoted 1 line

enc_info.open_param.wave_param.internal_bit_depth

drivers/media/platform/chips-media/wave5/wave5-hw.c +3 -0
+	 */
+
+	if (p_enc_info->sec_axi_info.use_enc_rdo_enable && sram_size >=

rdo_size) {

drivers/media/platform/chips-media/wave5/wave5-hw.c +5 -0
+		ret |= BIT(11);
+		sram_size -= rdo_size;
+	}
+
+	if (p_enc_info->sec_axi_info.use_enc_lf_enable && sram_size >=

lf_size)

drivers/media/platform/chips-media/wave5/wave5-hw.c +5 -0
+		ret |= BIT(15);
+
+	return ret;
+}
+
 int wave5_vpu_encode(struct vpu_instance *inst, struct enc_param *option,

u32 *fail_res) {

drivers/media/platform/chips-media/wave5/wave5-hw.c +0 -0
 	u32 src_frame_format;
@@ -1959,8 +2012,7 @@ int wave5_vpu_encode(struct vpu_instance *inst,

struct enc_param *option, u32 *f

vpu_write_reg(inst->dev, W5_CMD_ENC_PIC_SRC_AXI_SEL,
DEFAULT_SRC_AXI);

drivers/media/platform/chips-media/wave5/wave5-hw.c +1 -2
 	/* secondary AXI */
-	reg_val = (p_enc_info->sec_axi_info.use_enc_rdo_enable << 11) |
-		(p_enc_info->sec_axi_info.use_enc_lf_enable << 15);
+	reg_val = wave5_vpu_enc_validate_sec_axi(inst);
 	vpu_write_reg(inst->dev, W5_CMD_ENC_PIC_USE_SEC_AXI, reg_val);
 
 	vpu_write_reg(inst->dev, W5_CMD_ENC_PIC_REPORT_PARAM, 0); diff --

git a/drivers/media/platform/chips-media/wave5/wave5-vdi.c b/drivers/media/platform/chips-media/wave5/wave5-vdi.c index 3809f70bc0b4..556de2f043fe 100644

drivers/media/platform/chips-media/wave5/wave5-vdi.c +0 -0

The below code is not based on the current upstream code. Where did you get the original code ?

Quoted 86 lines
drivers/media/platform/chips-media/wave5/wave5-vdi.c +10 -7
@@ -174,16 +174,19 @@ int wave5_vdi_allocate_array(struct vpu_device
 *vpu_dev, struct vpu_buf *array,  void wave5_vdi_allocate_sram(struct
 vpu_device *vpu_dev)  {
 	struct vpu_buf *vb = &vpu_dev->sram_buf;
+	dma_addr_t daddr;
+	void *vaddr;
+	size_t size;
 
-	if (!vpu_dev->sram_pool || !vpu_dev->sram_size)
+	if (!vpu_dev->sram_pool || vb->vaddr)
 		return;
 
-	if (!vb->vaddr) {
-		vb->size = vpu_dev->sram_size;
-		vb->vaddr = gen_pool_dma_alloc(vpu_dev->sram_pool, vb->size,
-					       &vb->daddr);
-		if (!vb->vaddr)
-			vb->size = 0;
+	size = min_t(size_t, vpu_dev->sram_size, gen_pool_avail(vpu_dev-
 >sram_pool));
+	vaddr = gen_pool_dma_alloc(vpu_dev->sram_pool, size, &daddr);
+	if (vaddr) {
+		vb->vaddr = vaddr;
+		vb->daddr = daddr;
+		vb->size = size;
 	}
 

dev_dbg(vpu_dev->dev, "%s: sram daddr: %pad, size: %zu, vaddr:
0x%p\n", @@ -197,9 +200,7 @@ void wave5_vdi_free_sram(struct vpu_device *vpu_dev)

drivers/media/platform/chips-media/wave5/wave5-vdi.c +1 -3
 	if (!vb->size || !vb->vaddr)
 		return;
 
-	if (vb->vaddr)
-		gen_pool_free(vpu_dev->sram_pool, (unsigned long)vb->vaddr,
-			      vb->size);
+	gen_pool_free(vpu_dev->sram_pool, (unsigned long)vb->vaddr, vb-
Quoted 1 line

size);

drivers/media/platform/chips-media/wave5/wave5-vdi.c +0 -0
 	memset(vb, 0, sizeof(*vb));
 }
drivers/media/platform/chips-media/wave5/wave5-vpu.c +1 -0
index 1e631da58e15..9e93969ab6db 100644
@@ -25,6 +25,7 @@
 struct wave5_match_data {
 	int flags;
 	const char *fw_name;
+	u32 sram_size;
 };
 
 int wave5_vpu_wait_interrupt(struct vpu_instance *inst, unsigned int

timeout) @@ -177,17 +178,12 @@ static int wave5_vpu_probe(struct platform_device *pdev)

drivers/media/platform/chips-media/wave5/wave5-vpu.c +2 -7
 		goto err_reset_assert;
 	}
 
-	ret = of_property_read_u32(pdev->dev.of_node, "sram-size",
-				   &dev->sram_size);
-	if (ret) {
-		dev_warn(&pdev->dev, "sram-size not found\n");
-		dev->sram_size = 0;
-	}
-
 	dev->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0);
 	if (!dev->sram_pool)
 		dev_warn(&pdev->dev, "sram node not found\n");
 
+	dev->sram_size = match_data->sram_size;
+
 	dev->product_code = wave5_vdi_read_register(dev,

VPU_PRODUCT_CODE_REGISTER);

drivers/media/platform/chips-media/wave5/wave5-vpu.c +1 -1
 	ret = wave5_vdi_init(&pdev->dev);
 	if (ret < 0) {
@@ -281,6 +277,7 @@ static void wave5_vpu_remove(struct platform_device
 *pdev)  static const struct wave5_match_data ti_wave521c_data = {
 	.flags = WAVE5_IS_ENC | WAVE5_IS_DEC,
 	.fw_name = "cnm/wave521c_k3_codec_fw.bin",
+	.sram_size = (64 * 1024),
 };
 
 static const struct of_device_id wave5_dt_ids[] = {
--

2.44.0

#6 lore raw

Re: RE: [PATCH v3 4/5] media: chips-media: wave5: drop "sram-size" DT prop

Hi, Jackson

Quoted 38 lines · jackson.lee

Hey Ivan

Quoted 36 lines

-----Original Message-----
From: Ivan Bornyakov <[email protected]>
Sent: Saturday, April 6, 2024 1:41 AM
To: Nas Chung <[email protected]>; jackson.lee <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Philipp Zabel <[email protected]>; Sebastian Fricke <[email protected]>
Cc: Ivan Bornyakov <[email protected]>; [email protected]; [email protected]
Subject: [PATCH v3 4/5] media: chips-media: wave5: drop "sram-size" DT prop

Move excessive "sram-size" device-tree property to device match data. Also change SRAM memory allocation strategy: instead of allocation exact sram_size bytes, allocate all available SRAM memory up to sram_size. Add placeholders wave5_vpu_dec_validate_sec_axi() and wave5_vpu_enc_validate_sec_axi() for validation that allocated SRAM memory is enough to decode/encode bitstream of given resolution.

---
 .../platform/chips-media/wave5/wave5-hw.c     | 62 +++++++++++++++++--
 .../platform/chips-media/wave5/wave5-vdi.c    | 21 ++++---
 .../platform/chips-media/wave5/wave5-vpu.c    | 11 ++--
 3 files changed, 72 insertions(+), 22 deletions(-)
drivers/media/platform/chips-media/wave5/wave5-hw.c +0 -0
index cdd0a0948a94..36f2fc818013 100644
@@ -843,6 +843,36 @@ int wave5_vpu_dec_register_framebuffer(struct

vpu_instance *inst, struct frame_b
return ret;
}

Quoted 6 lines

drivers/media/platform/chips-media/wave5/wave5-hw.c int wave5_vpu_dec_register_framebuffer(struct vpu_instance *inst, struct frame_b · line 849

Quoted 3 lines
drivers/media/platform/chips-media/wave5/wave5-hw.c +3 -0
+static u32 wave5_vpu_dec_validate_sec_axi(struct vpu_instance *inst) {
+	struct dec_info *p_dec_info = &inst->codec_info->dec_info;
+	u32 bit_size = 0, ip_size = 0, lf_size = 0, ret = 0;

The bit_size, ip_size and 1f_size is always 0? If so, why are you using them ?

Since I don't have documentation on Wave521, this is a placeholder for someone who have documentation to write proper SRAM size validation, hence TODO comment.

In the next patch "media: chips-media: wave5: support Wave515 decoder" I added validation of SRAM usage for Wave515, for which I do have documentation.

Quoted 51 lines
Quoted 51 lines
drivers/media/platform/chips-media/wave5/wave5-hw.c +7 -0
+	u32 sram_size = inst->dev->sram_size;
+
+	if (!sram_size)
+		return 0;
+
+	/*
+	 * TODO: calculate bit_size, ip_size, lf_size from inst-
Quoted 1 line

src_fmt.width

drivers/media/platform/chips-media/wave5/wave5-hw.c +4 -0
+	 * and inst->codec_info->dec_info.initial_info.luma_bitdepth
+	 */
+
+	if (p_dec_info->sec_axi_info.use_bit_enable && sram_size >=

bit_size) {

drivers/media/platform/chips-media/wave5/wave5-hw.c +5 -0
+		ret |= BIT(0);
+		sram_size -= bit_size;
+	}
+
+	if (p_dec_info->sec_axi_info.use_ip_enable && sram_size >= ip_size)

{

drivers/media/platform/chips-media/wave5/wave5-hw.c +5 -0
+		ret |= BIT(9);
+		sram_size -= ip_size;
+	}
+
+	if (p_dec_info->sec_axi_info.use_lf_row_enable && sram_size >=

lf_size)

drivers/media/platform/chips-media/wave5/wave5-hw.c +6 -3
+		ret |= BIT(15);
+
+	return ret;
+}
+
 int wave5_vpu_decode(struct vpu_instance *inst, u32 *fail_res)  {
 	u32 reg_val;
@@ -855,9 +885,7 @@ int wave5_vpu_decode(struct vpu_instance *inst, u32
 *fail_res)
 	vpu_write_reg(inst->dev, W5_BS_OPTION,
 get_bitstream_options(p_dec_info));
 
 	/* secondary AXI */
-	reg_val = p_dec_info->sec_axi_info.use_bit_enable |
-		(p_dec_info->sec_axi_info.use_ip_enable << 9) |
-		(p_dec_info->sec_axi_info.use_lf_row_enable << 15);
+	reg_val = wave5_vpu_dec_validate_sec_axi(inst);
 	vpu_write_reg(inst->dev, W5_USE_SEC_AXI, reg_val);
drivers/media/platform/chips-media/wave5/wave5-hw.c +0 -0
 	/* set attributes of user buffer */
@@ -1938,6 +1966,31 @@ int wave5_vpu_enc_register_framebuffer(struct

device *dev, struct vpu_instance *
return ret;
}

Quoted 6 lines

drivers/media/platform/chips-media/wave5/wave5-hw.c int wave5_vpu_enc_register_framebuffer(struct device *dev, struct vpu_instance * · line 1972

Quoted 3 lines
drivers/media/platform/chips-media/wave5/wave5-hw.c +3 -0
+static u32 wave5_vpu_enc_validate_sec_axi(struct vpu_instance *inst) {
+	struct enc_info *p_enc_info = &inst->codec_info->enc_info;
+	u32 rdo_size = 0, lf_size = 0, ret = 0;

The rdo_size and 1f_size is always 0? If so, why are you using them ?

Same as above. It is a placeholder for someone else to implement these.

Quoted 39 lines
Quoted 39 lines
drivers/media/platform/chips-media/wave5/wave5-hw.c +7 -0
+	u32 sram_size = inst->dev->sram_size;
+
+	if (!sram_size)
+		return 0;
+
+	/*
+	 * TODO: calculate rdo_size and lf_size from inst->src_fmt.width

and

drivers/media/platform/chips-media/wave5/wave5-hw.c +1 -0
+	 * inst->codec_info-
Quoted 1 line

enc_info.open_param.wave_param.internal_bit_depth

drivers/media/platform/chips-media/wave5/wave5-hw.c +3 -0
+	 */
+
+	if (p_enc_info->sec_axi_info.use_enc_rdo_enable && sram_size >=

rdo_size) {

drivers/media/platform/chips-media/wave5/wave5-hw.c +5 -0
+		ret |= BIT(11);
+		sram_size -= rdo_size;
+	}
+
+	if (p_enc_info->sec_axi_info.use_enc_lf_enable && sram_size >=

lf_size)

drivers/media/platform/chips-media/wave5/wave5-hw.c +5 -0
+		ret |= BIT(15);
+
+	return ret;
+}
+
 int wave5_vpu_encode(struct vpu_instance *inst, struct enc_param *option,

u32 *fail_res) {

drivers/media/platform/chips-media/wave5/wave5-hw.c +0 -0
 	u32 src_frame_format;
@@ -1959,8 +2012,7 @@ int wave5_vpu_encode(struct vpu_instance *inst,

struct enc_param *option, u32 *f

vpu_write_reg(inst->dev, W5_CMD_ENC_PIC_SRC_AXI_SEL,
DEFAULT_SRC_AXI);

drivers/media/platform/chips-media/wave5/wave5-hw.c +1 -2
 	/* secondary AXI */
-	reg_val = (p_enc_info->sec_axi_info.use_enc_rdo_enable << 11) |
-		(p_enc_info->sec_axi_info.use_enc_lf_enable << 15);
+	reg_val = wave5_vpu_enc_validate_sec_axi(inst);
 	vpu_write_reg(inst->dev, W5_CMD_ENC_PIC_USE_SEC_AXI, reg_val);
Quoted 10 lines

drivers/media/platform/chips-media/wave5/wave5-vdi.c

Quoted 6 lines

vpu_write_reg(inst->dev, W5_CMD_ENC_PIC_REPORT_PARAM, 0); diff --
git a/drivers/media/platform/chips-media/wave5/wave5-vdi.c b/drivers/media/platform/chips-media/wave5/wave5-vdi.c
index 3809f70bc0b4..556de2f043fe 100644

drivers/media/platform/chips-media/wave5/wave5-vdi.c +0 -0

The below code is not based on the current upstream code. Where did you get the original code ?

What do you mean? This patch series is based on the latest linux-next.

Quoted 87 lines
Quoted 86 lines
drivers/media/platform/chips-media/wave5/wave5-vdi.c +10 -7
@@ -174,16 +174,19 @@ int wave5_vdi_allocate_array(struct vpu_device
 *vpu_dev, struct vpu_buf *array,  void wave5_vdi_allocate_sram(struct
 vpu_device *vpu_dev)  {
 	struct vpu_buf *vb = &vpu_dev->sram_buf;
+	dma_addr_t daddr;
+	void *vaddr;
+	size_t size;
 
-	if (!vpu_dev->sram_pool || !vpu_dev->sram_size)
+	if (!vpu_dev->sram_pool || vb->vaddr)
 		return;
 
-	if (!vb->vaddr) {
-		vb->size = vpu_dev->sram_size;
-		vb->vaddr = gen_pool_dma_alloc(vpu_dev->sram_pool, vb->size,
-					       &vb->daddr);
-		if (!vb->vaddr)
-			vb->size = 0;
+	size = min_t(size_t, vpu_dev->sram_size, gen_pool_avail(vpu_dev-
 >sram_pool));
+	vaddr = gen_pool_dma_alloc(vpu_dev->sram_pool, size, &daddr);
+	if (vaddr) {
+		vb->vaddr = vaddr;
+		vb->daddr = daddr;
+		vb->size = size;
 	}
 

dev_dbg(vpu_dev->dev, "%s: sram daddr: %pad, size: %zu, vaddr:
0x%p\n", @@ -197,9 +200,7 @@ void wave5_vdi_free_sram(struct vpu_device *vpu_dev)

drivers/media/platform/chips-media/wave5/wave5-vdi.c +1 -3
 	if (!vb->size || !vb->vaddr)
 		return;
 
-	if (vb->vaddr)
-		gen_pool_free(vpu_dev->sram_pool, (unsigned long)vb->vaddr,
-			      vb->size);
+	gen_pool_free(vpu_dev->sram_pool, (unsigned long)vb->vaddr, vb-
Quoted 1 line

size);

drivers/media/platform/chips-media/wave5/wave5-vdi.c +0 -0
 	memset(vb, 0, sizeof(*vb));
 }
drivers/media/platform/chips-media/wave5/wave5-vpu.c +1 -0
index 1e631da58e15..9e93969ab6db 100644
@@ -25,6 +25,7 @@
 struct wave5_match_data {
 	int flags;
 	const char *fw_name;
+	u32 sram_size;
 };
 
 int wave5_vpu_wait_interrupt(struct vpu_instance *inst, unsigned int

timeout) @@ -177,17 +178,12 @@ static int wave5_vpu_probe(struct platform_device *pdev)

drivers/media/platform/chips-media/wave5/wave5-vpu.c +2 -7
 		goto err_reset_assert;
 	}
 
-	ret = of_property_read_u32(pdev->dev.of_node, "sram-size",
-				   &dev->sram_size);
-	if (ret) {
-		dev_warn(&pdev->dev, "sram-size not found\n");
-		dev->sram_size = 0;
-	}
-
 	dev->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0);
 	if (!dev->sram_pool)
 		dev_warn(&pdev->dev, "sram node not found\n");
 
+	dev->sram_size = match_data->sram_size;
+
 	dev->product_code = wave5_vdi_read_register(dev,

VPU_PRODUCT_CODE_REGISTER);

drivers/media/platform/chips-media/wave5/wave5-vpu.c +1 -1
 	ret = wave5_vdi_init(&pdev->dev);
 	if (ret < 0) {
@@ -281,6 +277,7 @@ static void wave5_vpu_remove(struct platform_device
 *pdev)  static const struct wave5_match_data ti_wave521c_data = {
 	.flags = WAVE5_IS_ENC | WAVE5_IS_DEC,
 	.fw_name = "cnm/wave521c_k3_codec_fw.bin",
+	.sram_size = (64 * 1024),
 };
 
 static const struct of_device_id wave5_dt_ids[] = {
--

2.44.0

maintainer
#7 lore raw

RE: RE: [PATCH v3 4/5] media: chips-media: wave5: drop "sram-size" DT prop

Hi Ivan

Quoted 182 lines

-----Original Message-----
From: Ivan Bornyakov <[email protected]>
Sent: Tuesday, April 9, 2024 5:12 PM
To: jackson.lee <[email protected]>
Cc: Nas Chung <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Philipp Zabel <[email protected]>; Sebastian Fricke <[email protected]>; [email protected]; [email protected]
Subject: Re: RE: [PATCH v3 4/5] media: chips-media: wave5: drop "sram- size" DT prop

Hi, Jackson

Quoted 17 lines · jackson.lee

Hey Ivan

Quoted 15 lines

-----Original Message-----
From: Ivan Bornyakov <[email protected]>
Sent: Saturday, April 6, 2024 1:41 AM
To: Nas Chung <[email protected]>; jackson.lee <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Philipp Zabel <[email protected]>; Sebastian Fricke <[email protected]>
Cc: Ivan Bornyakov <[email protected]>; [email protected]; [email protected]
Subject: [PATCH v3 4/5] media: chips-media: wave5: drop "sram-size" DT prop

Move excessive "sram-size" device-tree property to device match data. Also change SRAM memory allocation strategy: instead of allocation exact sram_size bytes, allocate all available SRAM memory up to

sram_size.

Quoted 21 lines
Quoted 21 lines

Add placeholders wave5_vpu_dec_validate_sec_axi() and wave5_vpu_enc_validate_sec_axi() for validation that allocated SRAM memory is enough to decode/encode bitstream of given resolution.

---
 .../platform/chips-media/wave5/wave5-hw.c     | 62 +++++++++++++++++--
 .../platform/chips-media/wave5/wave5-vdi.c    | 21 ++++---
 .../platform/chips-media/wave5/wave5-vpu.c    | 11 ++--
 3 files changed, 72 insertions(+), 22 deletions(-)
drivers/media/platform/chips-media/wave5/wave5-hw.c +0 -0
index cdd0a0948a94..36f2fc818013 100644
@@ -843,6 +843,36 @@ int wave5_vpu_dec_register_framebuffer(struct

vpu_instance *inst, struct frame_b
return ret;
}

Quoted 1 line
Quoted 1 line

+static u32 wave5_vpu_dec_validate_sec_axi(struct vpu_instance *inst)

{

Quoted 4 lines

drivers/media/platform/chips-media/wave5/wave5-hw.c int wave5_vpu_dec_register_framebuffer(struct vpu_instance *inst, struct frame_b · line 849

Quoted 2 lines
drivers/media/platform/chips-media/wave5/wave5-hw.c +2 -0
+	struct dec_info *p_dec_info = &inst->codec_info->dec_info;
+	u32 bit_size = 0, ip_size = 0, lf_size = 0, ret = 0;

The bit_size, ip_size and 1f_size is always 0? If so, why are you using

them ?

Quoted 1 line

Since I don't have documentation on Wave521, this is a placeholder for someone who have documentation to write proper SRAM size validation, hence TODO comment.

In the next patch "media: chips-media: wave5: support Wave515 decoder" I added validation of SRAM usage for Wave515, for which I do have documentation.

Quoted 47 lines
Quoted 47 lines
drivers/media/platform/chips-media/wave5/wave5-hw.c +7 -0
+	u32 sram_size = inst->dev->sram_size;
+
+	if (!sram_size)
+		return 0;
+
+	/*
+	 * TODO: calculate bit_size, ip_size, lf_size from inst-
Quoted 1 line

src_fmt.width

drivers/media/platform/chips-media/wave5/wave5-hw.c +4 -0
+	 * and inst->codec_info->dec_info.initial_info.luma_bitdepth
+	 */
+
+	if (p_dec_info->sec_axi_info.use_bit_enable && sram_size >=

bit_size) {

drivers/media/platform/chips-media/wave5/wave5-hw.c +6 -0
+		ret |= BIT(0);
+		sram_size -= bit_size;
+	}
+
+	if (p_dec_info->sec_axi_info.use_ip_enable && sram_size >=
+ip_size)

{

drivers/media/platform/chips-media/wave5/wave5-hw.c +5 -0
+		ret |= BIT(9);
+		sram_size -= ip_size;
+	}
+
+	if (p_dec_info->sec_axi_info.use_lf_row_enable && sram_size >=

lf_size)

drivers/media/platform/chips-media/wave5/wave5-hw.c +5 -0
+		ret |= BIT(15);
+
+	return ret;
+}
+
 int wave5_vpu_decode(struct vpu_instance *inst, u32 *fail_res)  {
 	u32 reg_val;
@@ -855,9 +885,7 @@ int wave5_vpu_decode(struct vpu_instance *inst,

u32
*fail_res)
vpu_write_reg(inst->dev, W5_BS_OPTION,
get_bitstream_options(p_dec_info));

drivers/media/platform/chips-media/wave5/wave5-hw.c +1 -3
 	/* secondary AXI */
-	reg_val = p_dec_info->sec_axi_info.use_bit_enable |
-		(p_dec_info->sec_axi_info.use_ip_enable << 9) |
-		(p_dec_info->sec_axi_info.use_lf_row_enable << 15);
+	reg_val = wave5_vpu_dec_validate_sec_axi(inst);
 	vpu_write_reg(inst->dev, W5_USE_SEC_AXI, reg_val);
Quoted 7 lines

drivers/media/platform/chips-media/wave5/wave5-hw.c int wave5_vpu_enc_register_framebuffer(struct device *dev, struct vpu_instance * · line 1969

Quoted 7 lines

/* set attributes of user buffer */ @@ -1938,6 +1966,31 @@ int
wave5_vpu_enc_register_framebuffer(struct
device *dev, struct vpu_instance *

drivers/media/platform/chips-media/wave5/wave5-hw.c +1 -0
 	return ret;
 }
 
+static u32 wave5_vpu_enc_validate_sec_axi(struct vpu_instance *inst)

{

Quoted 5 lines

drivers/media/platform/chips-media/wave5/wave5-hw.c int wave5_vpu_enc_register_framebuffer(struct device *dev, struct vpu_instance * · line 1972

Quoted 2 lines
drivers/media/platform/chips-media/wave5/wave5-hw.c +2 -0
+	struct enc_info *p_enc_info = &inst->codec_info->enc_info;
+	u32 rdo_size = 0, lf_size = 0, ret = 0;

The rdo_size and 1f_size is always 0? If so, why are you using them ?

Same as above. It is a placeholder for someone else to implement these.

Quoted 40 lines
Quoted 40 lines
drivers/media/platform/chips-media/wave5/wave5-hw.c +7 -0
+	u32 sram_size = inst->dev->sram_size;
+
+	if (!sram_size)
+		return 0;
+
+	/*
+	 * TODO: calculate rdo_size and lf_size from inst->src_fmt.width

and

drivers/media/platform/chips-media/wave5/wave5-hw.c +1 -0
+	 * inst->codec_info-
Quoted 1 line

enc_info.open_param.wave_param.internal_bit_depth

drivers/media/platform/chips-media/wave5/wave5-hw.c +3 -0
+	 */
+
+	if (p_enc_info->sec_axi_info.use_enc_rdo_enable && sram_size >=

rdo_size) {

drivers/media/platform/chips-media/wave5/wave5-hw.c +5 -0
+		ret |= BIT(11);
+		sram_size -= rdo_size;
+	}
+
+	if (p_enc_info->sec_axi_info.use_enc_lf_enable && sram_size >=

lf_size)

drivers/media/platform/chips-media/wave5/wave5-hw.c +5 -0
+		ret |= BIT(15);
+
+	return ret;
+}
+
 int wave5_vpu_encode(struct vpu_instance *inst, struct enc_param

*option,
u32 *fail_res) {

drivers/media/platform/chips-media/wave5/wave5-hw.c +1 -2
 	u32 src_frame_format;
@@ -1959,8 +2012,7 @@ int wave5_vpu_encode(struct vpu_instance
 *inst, struct enc_param *option, u32 *f
 
 	vpu_write_reg(inst->dev, W5_CMD_ENC_PIC_SRC_AXI_SEL,
 DEFAULT_SRC_AXI);
 	/* secondary AXI */
-	reg_val = (p_enc_info->sec_axi_info.use_enc_rdo_enable << 11) |
-		(p_enc_info->sec_axi_info.use_enc_lf_enable << 15);
+	reg_val = wave5_vpu_enc_validate_sec_axi(inst);
 	vpu_write_reg(inst->dev, W5_CMD_ENC_PIC_USE_SEC_AXI, reg_val);
Quoted 9 lines

drivers/media/platform/chips-media/wave5/wave5-vdi.c

Quoted 6 lines

vpu_write_reg(inst->dev, W5_CMD_ENC_PIC_REPORT_PARAM, 0); diff --
git a/drivers/media/platform/chips-media/wave5/wave5-vdi.c b/drivers/media/platform/chips-media/wave5/wave5-vdi.c
index 3809f70bc0b4..556de2f043fe 100644

drivers/media/platform/chips-media/wave5/wave5-vdi.c +0 -0

The below code is not based on the current upstream code. Where did you

Quoted 4 lines

get the original code ?

Quoted 1 line

What do you mean? This patch series is based on the latest linux-next.

I was confused, please ignore the above comment.

Quoted 91 lines
Quoted 91 lines
Quoted 90 lines
drivers/media/platform/chips-media/wave5/wave5-vdi.c +10 -7
@@ -174,16 +174,19 @@ int wave5_vdi_allocate_array(struct vpu_device
 *vpu_dev, struct vpu_buf *array,  void
 wave5_vdi_allocate_sram(struct vpu_device *vpu_dev)  {
 	struct vpu_buf *vb = &vpu_dev->sram_buf;
+	dma_addr_t daddr;
+	void *vaddr;
+	size_t size;
 
-	if (!vpu_dev->sram_pool || !vpu_dev->sram_size)
+	if (!vpu_dev->sram_pool || vb->vaddr)
 		return;
 
-	if (!vb->vaddr) {
-		vb->size = vpu_dev->sram_size;
-		vb->vaddr = gen_pool_dma_alloc(vpu_dev->sram_pool, vb->size,
-					       &vb->daddr);
-		if (!vb->vaddr)
-			vb->size = 0;
+	size = min_t(size_t, vpu_dev->sram_size, gen_pool_avail(vpu_dev-
 >sram_pool));
+	vaddr = gen_pool_dma_alloc(vpu_dev->sram_pool, size, &daddr);
+	if (vaddr) {
+		vb->vaddr = vaddr;
+		vb->daddr = daddr;
+		vb->size = size;
 	}
 

dev_dbg(vpu_dev->dev, "%s: sram daddr: %pad, size: %zu, vaddr:
0x%p\n", @@ -197,9 +200,7 @@ void wave5_vdi_free_sram(struct vpu_device
*vpu_dev)

drivers/media/platform/chips-media/wave5/wave5-vdi.c +1 -3
 	if (!vb->size || !vb->vaddr)
 		return;
 
-	if (vb->vaddr)
-		gen_pool_free(vpu_dev->sram_pool, (unsigned long)vb->vaddr,
-			      vb->size);
+	gen_pool_free(vpu_dev->sram_pool, (unsigned long)vb->vaddr, vb-
Quoted 1 line

size);

drivers/media/platform/chips-media/wave5/wave5-vdi.c +0 -0
 	memset(vb, 0, sizeof(*vb));
 }
drivers/media/platform/chips-media/wave5/wave5-vpu.c +1 -0
index 1e631da58e15..9e93969ab6db 100644
@@ -25,6 +25,7 @@
 struct wave5_match_data {
 	int flags;
 	const char *fw_name;
+	u32 sram_size;
 };
 
 int wave5_vpu_wait_interrupt(struct vpu_instance *inst, unsigned

int
timeout) @@ -177,17 +178,12 @@ static int wave5_vpu_probe(struct platform_device *pdev)

drivers/media/platform/chips-media/wave5/wave5-vpu.c +2 -7
 		goto err_reset_assert;
 	}
 
-	ret = of_property_read_u32(pdev->dev.of_node, "sram-size",
-				   &dev->sram_size);
-	if (ret) {
-		dev_warn(&pdev->dev, "sram-size not found\n");
-		dev->sram_size = 0;
-	}
-
 	dev->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0);
 	if (!dev->sram_pool)
 		dev_warn(&pdev->dev, "sram node not found\n");
 
+	dev->sram_size = match_data->sram_size;
+
 	dev->product_code = wave5_vdi_read_register(dev,

VPU_PRODUCT_CODE_REGISTER);

drivers/media/platform/chips-media/wave5/wave5-vpu.c +0 -0
 	ret = wave5_vdi_init(&pdev->dev);
 	if (ret < 0) {
@@ -281,6 +277,7 @@ static void wave5_vpu_remove(struct

platform_device
*pdev) static const struct wave5_match_data ti_wave521c_data = {

drivers/media/platform/chips-media/wave5/wave5-vpu.c +1 -1
 	.flags = WAVE5_IS_ENC | WAVE5_IS_DEC,
 	.fw_name = "cnm/wave521c_k3_codec_fw.bin",
+	.sram_size = (64 * 1024),
 };
 
 static const struct of_device_id wave5_dt_ids[] = {
--

2.44.0

#8 lore raw

PATCH v3 5/5 media: chips-media: wave5: support Wave515 decoder

In reply to Ivan Bornyakov

Add initial support for Wave515 multi-decoder IP. For now it is only able to decode HEVC Main/Main10 profile videos into YUV420.

This was tested on FPGA prototype, so wave5_dt_ids[] was not expanded. Users of the real hardware with Wave515 IP will have to
* provide firmware specific to their SoC
* add struct wave5_match_data like this:

	static const struct wave5_match_data platform_name_wave515_data = {
		.flags = WAVE5_IS_DEC,
		.fw_name = "cnm/wave515_platform_name_fw.bin",
		.sram_size = (71 * 1024),
	};

* add item to wave5_dt_ids[] like this:

	{
		.compatible = "vendor,soc-wave515",
		.data = &platform_name_wave515_data,
	},

* describe new compatible in Documentation/devicetree/bindings/media/cnm,wave521c.yaml

---
 .../platform/chips-media/wave5/wave5-helper.c |   8 +-
 .../platform/chips-media/wave5/wave5-hw.c     | 286 +++++++++++++-----
 .../chips-media/wave5/wave5-regdefine.h       |   5 +
 .../platform/chips-media/wave5/wave5-vdi.c    |   6 +-
 .../chips-media/wave5/wave5-vpu-dec.c         |  21 +-
 .../chips-media/wave5/wave5-vpu-enc.c         |   2 +-
 .../platform/chips-media/wave5/wave5-vpu.c    |   8 +-
 .../platform/chips-media/wave5/wave5-vpuapi.h |   1 +
 .../chips-media/wave5/wave5-vpuconfig.h       |  16 +-
 .../media/platform/chips-media/wave5/wave5.h  |   6 +
 10 files changed, 280 insertions(+), 79 deletions(-)
drivers/media/platform/chips-media/wave5/wave5-helper.c +7 -1
index 8433ecab230c..bb89b279ca8f 100644
@@ -29,7 +29,13 @@ void wave5_cleanup_instance(struct vpu_instance *inst)
 {
 	int i;
 
-	if (list_is_singular(&inst->list))
+	/*
+	 * For Wave515 SRAM memory is allocated at
+	 * wave5_vpu_dec_register_device() and freed at
+	 * wave5_vpu_dec_unregister_device().
+	 */
+	if (list_is_singular(&inst->list) &&
+	    inst->dev->product_code != WAVE515_CODE)
 		wave5_vdi_free_sram(inst->dev);
 
 	for (i = 0; i < inst->fbc_buf_count; i++)
drivers/media/platform/chips-media/wave5/wave5-hw.c +217 -69

470 lines not on this page · raw message

drivers/media/platform/chips-media/wave5/wave5-regdefine.h +5 -0
index a15c6b2c3d8b..557344754c4c 100644
@@ -205,6 +205,9 @@ enum query_opt {
 #define W5_ADDR_TEMP_BASE                       (W5_REG_BASE + 0x011C)
 #define W5_TEMP_SIZE                            (W5_REG_BASE + 0x0120)
 #define W5_HW_OPTION                            (W5_REG_BASE + 0x012C)
+#define W5_CMD_INIT_NUM_TASK_BUF		(W5_REG_BASE + 0x0134)
+#define W5_CMD_INIT_ADDR_TASK_BUF0		(W5_REG_BASE + 0x0138)
+#define W5_CMD_INIT_TASK_BUF_SIZE		(W5_REG_BASE + 0x0178)
 #define W5_SEC_AXI_PARAM                        (W5_REG_BASE + 0x0180)
 
 /************************************************************************/
@@ -216,7 +219,9 @@ enum query_opt {
 #define W5_CMD_DEC_BS_SIZE                      (W5_REG_BASE + 0x0120)
 #define W5_CMD_BS_PARAM                         (W5_REG_BASE + 0x0124)
 #define W5_CMD_ADDR_SEC_AXI                     (W5_REG_BASE + 0x0130)
+#define W515_CMD_ADDR_SEC_AXI			(W5_REG_BASE + 0x0124)
 #define W5_CMD_SEC_AXI_SIZE                     (W5_REG_BASE + 0x0134)
+#define W515_CMD_SEC_AXI_SIZE			(W5_REG_BASE + 0x0128)
 #define W5_CMD_EXT_ADDR                         (W5_REG_BASE + 0x0138)
 #define W5_CMD_NUM_CQ_DEPTH_M1                  (W5_REG_BASE + 0x013C)
 #define W5_CMD_ERR_CONCEAL                      (W5_REG_BASE + 0x0140)
drivers/media/platform/chips-media/wave5/wave5-vdi.c +5 -1
index 556de2f043fe..bb13267ced38 100644
@@ -18,7 +18,11 @@ static int wave5_vdi_allocate_common_memory(struct device *dev)
 	if (!vpu_dev->common_mem.vaddr) {
 		int ret;
 
-		vpu_dev->common_mem.size = SIZE_COMMON;
+		if (vpu_dev->product_code == WAVE515_CODE)
+			vpu_dev->common_mem.size = WAVE515_SIZE_COMMON;
+		else
+			vpu_dev->common_mem.size = WAVE521_SIZE_COMMON;
+
 		ret = wave5_vdi_allocate_dma_memory(vpu_dev, &vpu_dev->common_mem);
 		if (ret) {
 			dev_err(dev, "unable to allocate common buffer\n");
drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c +20 -1
index 5a71a711f2e8..6697534e9a12 100644
@@ -1869,7 +1869,12 @@ static int wave5_vpu_open_dec(struct file *filp)
 		goto cleanup_inst;
 	}
 
-	wave5_vdi_allocate_sram(inst->dev);
+	/*
+	 * For Wave515 SRAM memory was already allocated
+	 * at wave5_vpu_dec_register_device()
+	 */
+	if (inst->dev->product_code != WAVE515_CODE)
+		wave5_vdi_allocate_sram(inst->dev);
 
 	return 0;
 
@@ -1897,6 +1902,13 @@ int wave5_vpu_dec_register_device(struct vpu_device *dev)
 	struct video_device *vdev_dec;
 	int ret;
 
+	/*
+	 * Secondary AXI setup for Wave515 is done by INIT_VPU command,
+	 * i.e. wave5_vpu_init(), that's why we allocate SRAM memory early.
+	 */
+	if (dev->product_code == WAVE515_CODE)
+		wave5_vdi_allocate_sram(dev);
+
 	vdev_dec = devm_kzalloc(dev->v4l2_dev.dev, sizeof(*vdev_dec), GFP_KERNEL);
 	if (!vdev_dec)
 		return -ENOMEM;
@@ -1930,6 +1942,13 @@ int wave5_vpu_dec_register_device(struct vpu_device *dev)
 
 void wave5_vpu_dec_unregister_device(struct vpu_device *dev)
 {
+	/*
+	 * Here is a freeing pair for Wave515 SRAM memory allocation
+	 * happened at wave5_vpu_dec_register_device().
+	 */
+	if (dev->product_code == WAVE515_CODE)
+		wave5_vdi_free_sram(dev);
+
 	video_unregister_device(dev->video_dev_dec);
 	if (dev->v4l2_m2m_dec_dev)
 		v4l2_m2m_release(dev->v4l2_m2m_dec_dev);
drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c +1 -1
index 8bbf9d10b467..9d2a490d2516 100644
@@ -1247,7 +1247,7 @@ static int initialize_sequence(struct vpu_instance *inst)
 		__func__, initial_info.min_frame_buffer_count,
 		initial_info.min_src_frame_count);
 	inst->min_src_buf_count = initial_info.min_src_frame_count +
-				  COMMAND_QUEUE_DEPTH;
+				  WAVE521_COMMAND_QUEUE_DEPTH;
 
 	ctrl = v4l2_ctrl_find(&inst->v4l2_ctrl_hdl,
 			      V4L2_CID_MIN_BUFFERS_FOR_OUTPUT);
drivers/media/platform/chips-media/wave5/wave5-vpu.c +7 -1
index 9e93969ab6db..da254b422cff 100644
@@ -61,7 +61,13 @@ static irqreturn_t wave5_vpu_irq_thread(int irq, void *dev_id)
 
 			if (irq_reason & BIT(INT_WAVE5_INIT_SEQ) ||
 			    irq_reason & BIT(INT_WAVE5_ENC_SET_PARAM)) {
-				if (seq_done & BIT(inst->id)) {
+				if ((dev->product_code == WAVE515_CODE) &&
+				    (cmd_done & BIT(inst->id))) {
+					cmd_done &= ~BIT(inst->id);
+					wave5_vdi_write_register(dev, W5_RET_QUEUE_CMD_DONE_INST,
+								 cmd_done);
+					complete(&inst->irq_done);
+				} else if (seq_done & BIT(inst->id)) {
 					seq_done &= ~BIT(inst->id);
 					wave5_vdi_write_register(dev, W5_RET_SEQ_DONE_INSTANCE_INFO,
 								 seq_done);
drivers/media/platform/chips-media/wave5/wave5-vpuapi.h +1 -0
index da530fd98964..71c6d3e6bb20 100644
@@ -18,6 +18,7 @@
 #include "wave5-vdi.h"
 
 enum product_id {
+	PRODUCT_ID_515,
 	PRODUCT_ID_521,
 	PRODUCT_ID_511,
 	PRODUCT_ID_517,
drivers/media/platform/chips-media/wave5/wave5-vpuconfig.h +11 -5
index d9751eedb0f9..e4bc2e467cb5 100644
@@ -8,6 +8,7 @@
 #ifndef _VPU_CONFIG_H_
 #define _VPU_CONFIG_H_
 
+#define WAVE515_CODE			0x5150
 #define WAVE517_CODE                    0x5170
 #define WAVE537_CODE                    0x5370
 #define WAVE511_CODE                    0x5110
@@ -21,12 +22,13 @@
 		((c) == WAVE517_CODE ||	(c) == WAVE537_CODE ||		\
 		 (c) == WAVE511_CODE || (c) == WAVE521_CODE ||		\
 		 (c) == WAVE521E1_CODE || (c) == WAVE521C_CODE ||	\
-		 (c) == WAVE521C_DUAL_CODE);				\
+		 (c) == WAVE521C_DUAL_CODE) || (c) == WAVE515_CODE;	\
 })
 
 #define WAVE517_WORKBUF_SIZE            (2 * 1024 * 1024)
 #define WAVE521ENC_WORKBUF_SIZE         (128 * 1024)      //HEVC 128K, AVC 40K
 #define WAVE521DEC_WORKBUF_SIZE         (1784 * 1024)
+#define WAVE515DEC_WORKBUF_SIZE		(2 * 1024 * 1024)
 
 #define MAX_NUM_INSTANCE                32
 
@@ -49,17 +51,21 @@
 /************************************************************************/
 #define VLC_BUF_NUM                     (2)
 
-#define COMMAND_QUEUE_DEPTH             (2)
+#define WAVE521_COMMAND_QUEUE_DEPTH	(2)
+#define WAVE515_COMMAND_QUEUE_DEPTH	(4)
 
 #define W5_REMAP_INDEX0                 0
 #define W5_REMAP_INDEX1                 1
 #define W5_REMAP_MAX_SIZE               (1024 * 1024)
 
-#define WAVE5_MAX_CODE_BUF_SIZE         (2 * 1024 * 1024)
-#define WAVE5_TEMPBUF_OFFSET            WAVE5_MAX_CODE_BUF_SIZE
+#define WAVE521_MAX_CODE_BUF_SIZE	(2 * 1024 * 1024)
+#define WAVE515_MAX_CODE_BUF_SIZE	(1024 * 1024)
 #define WAVE5_TEMPBUF_SIZE              (1024 * 1024)
 
-#define SIZE_COMMON                 (WAVE5_MAX_CODE_BUF_SIZE + WAVE5_TEMPBUF_SIZE)
+#define WAVE521_SIZE_COMMON		(WAVE521_MAX_CODE_BUF_SIZE + WAVE5_TEMPBUF_SIZE)
+#define WAVE515_ONE_TASKBUF_SIZE	(8 * 1024 * 1024)
+#define WAVE515_SIZE_COMMON		(WAVE515_MAX_CODE_BUF_SIZE + WAVE5_TEMPBUF_SIZE + \
+					 WAVE515_COMMAND_QUEUE_DEPTH * WAVE515_ONE_TASKBUF_SIZE)
 
 //=====4. VPU REPORT MEMORY  ======================//
 
drivers/media/platform/chips-media/wave5/wave5.h +6 -0
index 063028eccd3b..2a29b9164f97 100644
@@ -22,6 +22,12 @@
  */
 #define BSOPTION_ENABLE_EXPLICIT_END		BIT(0)
 #define BSOPTION_HIGHLIGHT_STREAM_END		BIT(1)
+/*
+ * When RD_PTR_VALID_FLAG is 0 Wave515 ignores RD_PTR value and starts to
+ * decode from the access unit end position of the last decoded picture in
+ * bitstream buffer.
+ */
+#define BSOPTION_RD_PTR_VALID_FLAG		BIT(31)
 
 /*
  * Currently the driver only supports hardware with little endian but for source
Signature · 1 line
2.44.0
maintainer
#9 lore raw
In reply to Ivan Bornyakov

Hi Ivan

Can you provide a score for testing a fluster tool so that we can verify the change on your HW?

Thanks
Jackson

Quoted 89 lines

-----Original Message-----
From: Ivan Bornyakov <[email protected]>
Sent: Saturday, April 6, 2024 1:41 AM
To: Nas Chung <[email protected]>; jackson.lee <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Philipp Zabel <[email protected]>; Sebastian Fricke <[email protected]>
Cc: Ivan Bornyakov <[email protected]>; [email protected]; [email protected]
Subject: [PATCH v3 0/5] Wave515 decoder IP support

Initial support for Wave515 multi-decoder IP among other refinements. This was tested on FPGA prototype, so wave5_dt_ids[] was not expanded.

fluster score for JCT-VC-HEVC_V1 testsuite with
GStreamer-H.265-V4L2-Gst1.0 decoder is 132/147

The issue with Main10 tests is that fluster expects decoded file to be in yuv420p10le format while this driver decodes HEVC Main10 into 8-bit yuv420p. Though result is looks alright to the naked eye, proper decoding into yuv420p10le is to be added.

The rest failed fluster tests are common with Wave521.

ChangeLog:
v1:
https://lore.kernel.org/linux-media/20240318144225.30835-1-
[email protected]/
v2:
https://lore.kernel.org/linux-media/20240325064102.9278-1-
[email protected]/
* drop patch "dt-bindings: media: cnm,wave521c: drop resets
restriction"
The only user of Wave5 in mainline is TI K3 boards, thus there is no real need to alter dt-bindings
* in patch "media: chips-media: wave5: support decoding HEVC Main10
profile"
add check for flag "support_hevc10bit_dec"
* in patch "media: chips-media: wave5: support reset lines" move reset_control_deassert() out of else branch, add reset_control_assert() to probe error path.
* rework patch "media: chips-media: wave5: drop "sram-size" DT prop"
- don't move alloc/free form device open/close
- intead of exact configuration of reserved SRAM memory in DT and allocating all of it, allocate all available SRAM memory up to WAVE5_MAX_SRAM_SIZE from whatever pool provided.
* adjust patch "media: chips-media: wave5: support Wave515 decoder" according to changes in patches
"media: chips-media: wave5: support decoding HEVC Main10 profile" and "media: chips-media: wave5: drop "sram-size" DT prop"
v3:
* reword patch "media: chips-media: wave5: separate irq setup routine" a bit.
* in patch "media: chips-media: wave5: drop "sram-size" DT prop"
- move MAX_SRAM_SIZE define into match_data->sram_size
- add placeholders for validation that allocated SRAM memory is enough to encode/decode bitstream of given resolution before setting W5_USE_SEC_AXI and W5_CMD_ENC_PIC_USE_SEC_AXI registers
- reword accordingly
* in patch "media: chips-media: wave5: support Wave515 decoder"
- add comments around SRAM memory allocation/freeing about Wave515 specifics
- add comments about BSOPTION_RD_PTR_VALID_FLAG bit in W5_BS_OPTION register
- add W[AVE]521_ prefix to defines, for wich there are W[AVE]515_ alternatieves
- add semi-magic Wave515 specific formulas to estimate SRAM usage

Ivan Bornyakov (5):
media: chips-media: wave5: support decoding HEVC Main10 profile
media: chips-media: wave5: support reset lines
media: chips-media: wave5: separate irq setup routine
media: chips-media: wave5: drop "sram-size" DT prop
media: chips-media: wave5: support Wave515 decoder

 .../platform/chips-media/wave5/wave5-helper.c |   8 +-
 .../platform/chips-media/wave5/wave5-hw.c     | 395 +++++++++++++-----
 .../chips-media/wave5/wave5-regdefine.h       |   5 +
 .../platform/chips-media/wave5/wave5-vdi.c    |  27 +-
 .../chips-media/wave5/wave5-vpu-dec.c         |  51 ++-
 .../chips-media/wave5/wave5-vpu-enc.c         |   2 +-
 .../platform/chips-media/wave5/wave5-vpu.c    |  35 +-
 .../platform/chips-media/wave5/wave5-vpuapi.h |   3 +
 .../chips-media/wave5/wave5-vpuconfig.h       |  16 +-
 .../media/platform/chips-media/wave5/wave5.h  |   6 +
 10 files changed, 407 insertions(+), 141 deletions(-)

--
2.44.0

#10 lore raw

Hi

Quoted 4 lines · jackson.lee

Hi Ivan

Can you provide a score for testing a fluster tool so that we can verify the change on your HW?

I did that, didn't I?

Quoted 20 lines

Thanks
Jackson

Quoted 17 lines

-----Original Message-----
From: Ivan Bornyakov <[email protected]>
Sent: Saturday, April 6, 2024 1:41 AM
To: Nas Chung <[email protected]>; jackson.lee <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Philipp Zabel <[email protected]>; Sebastian Fricke <[email protected]>
Cc: Ivan Bornyakov <[email protected]>; [email protected]; [email protected]
Subject: [PATCH v3 0/5] Wave515 decoder IP support

Initial support for Wave515 multi-decoder IP among other refinements. This was tested on FPGA prototype, so wave5_dt_ids[] was not expanded.

fluster score for JCT-VC-HEVC_V1 testsuite with
GStreamer-H.265-V4L2-Gst1.0 decoder is 132/147

Here it is. Above is the score, below is notes about failed tests.

Quoted 73 lines
Quoted 72 lines

The issue with Main10 tests is that fluster expects decoded file to be in yuv420p10le format while this driver decodes HEVC Main10 into 8-bit yuv420p. Though result is looks alright to the naked eye, proper decoding into yuv420p10le is to be added.

The rest failed fluster tests are common with Wave521.

ChangeLog:
v1:
https://lore.kernel.org/linux-media/20240318144225.30835-1-
[email protected]/
v2:
https://lore.kernel.org/linux-media/20240325064102.9278-1-
[email protected]/
* drop patch "dt-bindings: media: cnm,wave521c: drop resets
restriction"
The only user of Wave5 in mainline is TI K3 boards, thus there is no real need to alter dt-bindings
* in patch "media: chips-media: wave5: support decoding HEVC Main10
profile"
add check for flag "support_hevc10bit_dec"
* in patch "media: chips-media: wave5: support reset lines" move reset_control_deassert() out of else branch, add reset_control_assert() to probe error path.
* rework patch "media: chips-media: wave5: drop "sram-size" DT prop"
- don't move alloc/free form device open/close
- intead of exact configuration of reserved SRAM memory in DT and allocating all of it, allocate all available SRAM memory up to WAVE5_MAX_SRAM_SIZE from whatever pool provided.
* adjust patch "media: chips-media: wave5: support Wave515 decoder" according to changes in patches
"media: chips-media: wave5: support decoding HEVC Main10 profile" and "media: chips-media: wave5: drop "sram-size" DT prop"
v3:
* reword patch "media: chips-media: wave5: separate irq setup routine" a bit.
* in patch "media: chips-media: wave5: drop "sram-size" DT prop"
- move MAX_SRAM_SIZE define into match_data->sram_size
- add placeholders for validation that allocated SRAM memory is enough to encode/decode bitstream of given resolution before setting W5_USE_SEC_AXI and W5_CMD_ENC_PIC_USE_SEC_AXI registers
- reword accordingly
* in patch "media: chips-media: wave5: support Wave515 decoder"
- add comments around SRAM memory allocation/freeing about Wave515 specifics
- add comments about BSOPTION_RD_PTR_VALID_FLAG bit in W5_BS_OPTION register
- add W[AVE]521_ prefix to defines, for wich there are W[AVE]515_ alternatieves
- add semi-magic Wave515 specific formulas to estimate SRAM usage

Ivan Bornyakov (5):
media: chips-media: wave5: support decoding HEVC Main10 profile
media: chips-media: wave5: support reset lines
media: chips-media: wave5: separate irq setup routine
media: chips-media: wave5: drop "sram-size" DT prop
media: chips-media: wave5: support Wave515 decoder

 .../platform/chips-media/wave5/wave5-helper.c |   8 +-
 .../platform/chips-media/wave5/wave5-hw.c     | 395 +++++++++++++-----
 .../chips-media/wave5/wave5-regdefine.h       |   5 +
 .../platform/chips-media/wave5/wave5-vdi.c    |  27 +-
 .../chips-media/wave5/wave5-vpu-dec.c         |  51 ++-
 .../chips-media/wave5/wave5-vpu-enc.c         |   2 +-
 .../platform/chips-media/wave5/wave5-vpu.c    |  35 +-
 .../platform/chips-media/wave5/wave5-vpuapi.h |   3 +
 .../chips-media/wave5/wave5-vpuconfig.h       |  16 +-
 .../media/platform/chips-media/wave5/wave5.h  |   6 +
 10 files changed, 407 insertions(+), 141 deletions(-)

--
2.44.0

maintainer
#11 lore raw

Hi Ivan

Quoted 35 lines

-----Original Message-----
From: Ivan Bornyakov <[email protected]>
Sent: Thursday, April 11, 2024 6:37 PM
To: jackson.lee <[email protected]>
Cc: Nas Chung <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Philipp Zabel <[email protected]>; Sebastian Fricke <[email protected]>; [email protected]; linux- [email protected]
Subject: Re: RE: [PATCH v3 0/5] Wave515 decoder IP support

Hi

Quoted 3 lines · jackson.lee

Hi Ivan

Can you provide a score for testing a fluster tool so that we can verify

the change on your HW?

Quoted 1 line

I did that, didn't I?

Quoted 14 lines

Thanks
Jackson

Quoted 11 lines

-----Original Message-----
From: Ivan Bornyakov <[email protected]>
Sent: Saturday, April 6, 2024 1:41 AM
To: Nas Chung <[email protected]>; jackson.lee <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Philipp Zabel <[email protected]>; Sebastian Fricke <[email protected]>
Cc: Ivan Bornyakov <[email protected]>; [email protected]; [email protected]
Subject: [PATCH v3 0/5] Wave515 decoder IP support

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

Initial support for Wave515 multi-decoder IP among other refinements. This was tested on FPGA prototype, so wave5_dt_ids[] was not expanded.

fluster score for JCT-VC-HEVC_V1 testsuite with
GStreamer-H.265-V4L2-Gst1.0 decoder is 132/147

Here it is. Above is the score, below is notes about failed tests.

I didn't see that, It is enough for HEVC

Quoted 75 lines
Quoted 24 lines
Quoted 24 lines

The issue with Main10 tests is that fluster expects decoded file to be in yuv420p10le format while this driver decodes HEVC Main10 into 8-bit yuv420p. Though result is looks alright to the naked eye, proper decoding into yuv420p10le is to be added.

The rest failed fluster tests are common with Wave521.

ChangeLog:
v1:
https://lore.kernel.org/linux-media/20240318144225.30835-1-
[email protected]/
v2:
https://lore.kernel.org/linux-media/20240325064102.9278-1-
[email protected]/
* drop patch "dt-bindings: media: cnm,wave521c: drop resets
restriction"
The only user of Wave5 in mainline is TI K3 boards, thus there is no real need to alter dt-bindings
* in patch "media: chips-media: wave5: support decoding HEVC
Main10 profile"
add check for flag "support_hevc10bit_dec"
* in patch "media: chips-media: wave5: support reset lines" move reset_control_deassert() out of else branch, add reset_control_assert() to probe error path.

Quoted 8 lines
Quoted 8 lines

* rework patch "media: chips-media: wave5: drop "sram-size" DT prop"
- don't move alloc/free form device open/close
- intead of exact configuration of reserved SRAM memory in DT and allocating all of it, allocate all available SRAM memory up to WAVE5_MAX_SRAM_SIZE from whatever pool provided.
* adjust patch "media: chips-media: wave5: support Wave515 decoder" according to changes in patches
"media: chips-media: wave5: support decoding HEVC Main10 profile"

and

Quoted 42 lines
Quoted 41 lines

"media: chips-media: wave5: drop "sram-size" DT prop"
v3:
* reword patch "media: chips-media: wave5: separate irq setup routine" a bit.
* in patch "media: chips-media: wave5: drop "sram-size" DT prop"
- move MAX_SRAM_SIZE define into match_data->sram_size
- add placeholders for validation that allocated SRAM memory is enough to encode/decode bitstream of given resolution before setting W5_USE_SEC_AXI and W5_CMD_ENC_PIC_USE_SEC_AXI registers
- reword accordingly
* in patch "media: chips-media: wave5: support Wave515 decoder"
- add comments around SRAM memory allocation/freeing about Wave515 specifics
- add comments about BSOPTION_RD_PTR_VALID_FLAG bit in W5_BS_OPTION register
- add W[AVE]521_ prefix to defines, for wich there are W[AVE]515_ alternatieves
- add semi-magic Wave515 specific formulas to estimate SRAM
usage

Ivan Bornyakov (5):
media: chips-media: wave5: support decoding HEVC Main10 profile
media: chips-media: wave5: support reset lines
media: chips-media: wave5: separate irq setup routine
media: chips-media: wave5: drop "sram-size" DT prop
media: chips-media: wave5: support Wave515 decoder

 .../platform/chips-media/wave5/wave5-helper.c |   8 +-
 .../platform/chips-media/wave5/wave5-hw.c     | 395 +++++++++++++-----
 .../chips-media/wave5/wave5-regdefine.h       |   5 +
 .../platform/chips-media/wave5/wave5-vdi.c    |  27 +-
 .../chips-media/wave5/wave5-vpu-dec.c         |  51 ++-
 .../chips-media/wave5/wave5-vpu-enc.c         |   2 +-
 .../platform/chips-media/wave5/wave5-vpu.c    |  35 +-
 .../platform/chips-media/wave5/wave5-vpuapi.h |   3 +
 .../chips-media/wave5/wave5-vpuconfig.h       |  16 +-
 .../media/platform/chips-media/wave5/wave5.h  |   6 +
 10 files changed, 407 insertions(+), 141 deletions(-)

--
2.44.0