Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58b7677d authored by Philipp Zabel's avatar Philipp Zabel Committed by Mauro Carvalho Chehab
Browse files

[media] coda: move per-instance buffer allocation and cleanup



This patch moves the context buffer allocation into the context start_streaming
callbacks. The context buffer and internal framebuffer cleanup is moved into
the context release callback.

Signed-off-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: default avatarKamil Debski <k.debski@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent 347bb7f0
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -1861,6 +1861,11 @@ static int __coda_start_decoding(struct coda_ctx *ctx)
	bitstream_size = ctx->bitstream.size;
	src_fourcc = q_data_src->fourcc;

	/* Allocate per-instance buffers */
	ret = coda_alloc_context_buffers(ctx, q_data_src);
	if (ret < 0)
		return ret;

	coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR);

	/* Update coda bitstream read and write pointers from kfifo */
@@ -2137,11 +2142,6 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
		return -EINVAL;
	}

	/* Allocate per-instance buffers */
	ret = coda_alloc_context_buffers(ctx, q_data_src);
	if (ret < 0)
		return ret;

	ret = ctx->ops->start_streaming(ctx);
	if (ctx->inst_type == CODA_INST_DECODER) {
		if (ret == -EAGAIN)
@@ -2168,6 +2168,11 @@ static int coda_start_encoding(struct coda_ctx *ctx)
	q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
	dst_fourcc = q_data_dst->fourcc;

	/* Allocate per-instance buffers */
	ret = coda_alloc_context_buffers(ctx, q_data_src);
	if (ret < 0)
		return ret;

	buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
	bitstream_buf = vb2_dma_contig_plane_dma_addr(buf, 0);
	bitstream_size = q_data_dst->sizeimage;
@@ -2838,7 +2843,6 @@ static int coda_open(struct file *file, enum coda_inst_type inst_type,
	return 0;

err_dma_writecombine:
	coda_free_context_buffers(ctx);
	if (ctx->dev->devtype->product == CODA_DX6)
		coda_free_aux_buf(dev, &ctx->workbuf);
	coda_free_aux_buf(dev, &ctx->parabuf);
@@ -2861,12 +2865,19 @@ static int coda_open(struct file *file, enum coda_inst_type inst_type,
	return ret;
}

static void coda_bit_release(struct coda_ctx *ctx)
{
	coda_free_framebuffers(ctx);
	coda_free_context_buffers(ctx);
}

struct coda_context_ops coda_encode_ops = {
	.queue_init = coda_encoder_queue_init,
	.start_streaming = coda_start_encoding,
	.prepare_run = coda_prepare_encode,
	.finish_run = coda_finish_encode,
	.seq_end_work = coda_seq_end_work,
	.release = coda_bit_release,
};

struct coda_context_ops coda_decode_ops = {
@@ -2874,7 +2885,8 @@ struct coda_context_ops coda_decode_ops = {
	.start_streaming = coda_start_decoding,
	.prepare_run = coda_prepare_decode,
	.finish_run = coda_finish_decode,
	.seq_end_work = coda_seq_end_work
	.seq_end_work = coda_seq_end_work,
	.release = coda_bit_release,
};

static int coda_encoder_open(struct file *file)
@@ -2906,15 +2918,12 @@ static int coda_release(struct file *file)
		flush_work(&ctx->seq_end_work);
	}

	coda_free_framebuffers(ctx);

	coda_lock(ctx);
	list_del(&ctx->list);
	coda_unlock(ctx);

	dma_free_writecombine(&dev->plat_dev->dev, ctx->bitstream.size,
		ctx->bitstream.vaddr, ctx->bitstream.paddr);
	coda_free_context_buffers(ctx);
	if (ctx->dev->devtype->product == CODA_DX6)
		coda_free_aux_buf(dev, &ctx->workbuf);

@@ -2926,6 +2935,8 @@ static int coda_release(struct file *file)
	v4l2_fh_del(&ctx->fh);
	v4l2_fh_exit(&ctx->fh);
	clear_bit(ctx->idx, &dev->instance_mask);
	if (ctx->ops->release)
		ctx->ops->release(ctx);
	kfree(ctx);

	return 0;