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.
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/pm_runtime.hlinux/scatterlist.hmedia/v4l2-common.hmedia/v4l2-device.hmedia/v4l2-ioctl.hmedia/v4l2-mem2mem.hmedia/videobuf2-dma-sg.hmedia/videobuf2-dma-contig.hmedia/videobuf2-v4l2.hrga.h
Detected Declarations
function Copyrightfunction for_each_sgtable_dma_pagefunction rga_queue_setupfunction rga_buf_initfunction get_plane_offsetfunction rga_buf_preparefunction rga_buf_queuefunction rga_buf_cleanupfunction rga_buf_return_buffersfunction rga_buf_prepare_streamingfunction vb2_is_streamingfunction rga_buf_start_streamingfunction rga_buf_stop_streaming
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
- Immediate include surface: `linux/pm_runtime.h`, `linux/scatterlist.h`, `media/v4l2-common.h`, `media/v4l2-device.h`, `media/v4l2-ioctl.h`, `media/v4l2-mem2mem.h`, `media/videobuf2-dma-sg.h`, `media/videobuf2-dma-contig.h`.
- Detected declarations: `function Copyright`, `function for_each_sgtable_dma_page`, `function rga_queue_setup`, `function rga_buf_init`, `function get_plane_offset`, `function rga_buf_prepare`, `function rga_buf_queue`, `function rga_buf_cleanup`, `function rga_buf_return_buffers`, `function rga_buf_prepare_streaming`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.