drivers/media/platform/rockchip/rga/rga-buf.c

Source file repositories/reference/linux-study-clean/drivers/media/platform/rockchip/rga/rga-buf.c

File Facts

System
Linux kernel
Corpus path
drivers/media/platform/rockchip/rga/rga-buf.c
Extension
.c
Size
7011 bytes
Lines
281
Domain
Driver Families
Bucket
drivers/media
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (rga_has_internal_iommu(ctx->rga)) {
			/* Create local MMU table for RGA */
			n_desc = fill_descriptors(&rbuf->dma_desc[curr_desc],
						  rbuf->n_desc - curr_desc,
						  vb2_dma_sg_plane_desc(vb, i));
			if (n_desc < 0) {
				v4l2_err(&ctx->rga->v4l2_dev,
					 "Failed to map video buffer to RGA\n");
				return n_desc;
			}
			dma_addrs[i] = curr_desc << PAGE_SHIFT;
			curr_desc += n_desc;
		} else {
			dma_addrs[i] = vb2_dma_contig_plane_dma_addr(vb, i);
		}
	}

	/* Fill the remaining planes */
	info = v4l2_format_info(f->pix.pixelformat);
	for (i = info->mem_planes; i < info->comp_planes; i++)
		dma_addrs[i] = dma_addrs[0] + get_plane_offset(f, info, i);

	rbuf->dma_addrs.y_addr = dma_addrs[0];
	rbuf->dma_addrs.u_addr = dma_addrs[1];
	rbuf->dma_addrs.v_addr = dma_addrs[2];

	return 0;
}

static void rga_buf_queue(struct vb2_buffer *vb)
{
	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
	struct rga_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);

	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
}

static void rga_buf_cleanup(struct vb2_buffer *vb)
{
	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
	struct rga_vb_buffer *rbuf = vb_to_rga(vbuf);
	struct rga_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
	struct rockchip_rga *rga = ctx->rga;

	if (!rga_has_internal_iommu(rga))
		return;

	dma_free_coherent(rga->dev, rbuf->n_desc * sizeof(*rbuf->dma_desc),
			  rbuf->dma_desc, rbuf->dma_desc_pa);
}

static void rga_buf_return_buffers(struct vb2_queue *q,
				   enum vb2_buffer_state state)
{
	struct rga_ctx *ctx = vb2_get_drv_priv(q);
	struct vb2_v4l2_buffer *vbuf;

	for (;;) {
		if (V4L2_TYPE_IS_OUTPUT(q->type))
			vbuf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
		else
			vbuf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
		if (!vbuf)
			break;
		v4l2_m2m_buf_done(vbuf, state);
	}
}

static int rga_buf_prepare_streaming(struct vb2_queue *q)
{
	struct rga_ctx *ctx = vb2_get_drv_priv(q);
	const struct rga_hw *hw = ctx->rga->hw;
	int ret;

	/* It's safe to check the streaming state of the other queue,
	 * as the streamon ioctl's can't race due to the lock set in
	 * the queue_init function.
	 */
	if ((V4L2_TYPE_IS_OUTPUT(q->type) &&
	     vb2_is_streaming(v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx))) ||
	    (V4L2_TYPE_IS_CAPTURE(q->type) &&
	     vb2_is_streaming(v4l2_m2m_get_src_vq(ctx->fh.m2m_ctx)))) {
		/*
		 * As the other side is already streaming,
		 * check that the max scaling factor isn't exceeded.
		 */
		ret = rga_check_scaling(hw, &ctx->in.crop, &ctx->out.crop,
					ctx->rotate);
		if (ret < 0)
			return ret;

Annotation

Implementation Notes