drivers/media/platform/chips-media/coda/coda-bit.c
Source file repositories/reference/linux-study-clean/drivers/media/platform/chips-media/coda/coda-bit.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/platform/chips-media/coda/coda-bit.c- Extension
.c- Size
- 77349 bytes
- Lines
- 2667
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/irqreturn.hlinux/kernel.hlinux/log2.hlinux/platform_device.hlinux/ratelimit.hlinux/reset.hlinux/slab.hlinux/videodev2.hmedia/v4l2-common.hmedia/v4l2-ctrls.hmedia/v4l2-fh.hmedia/v4l2-mem2mem.hmedia/videobuf2-v4l2.hmedia/videobuf2-dma-contig.hmedia/videobuf2-vmalloc.hcoda.himx-vdoa.htrace.h
Detected Declarations
function coda_is_initializedfunction coda_isbusyfunction coda_wait_timeoutfunction coda_command_asyncfunction coda_command_syncfunction coda_hw_resetfunction coda_kfifo_sync_from_devicefunction coda_kfifo_sync_to_device_fullfunction coda_kfifo_sync_to_device_writefunction coda_h264_bitstream_padfunction coda_bitstream_flushfunction coda_bitstream_queuefunction coda_buffer_parse_headersfunction coda_bitstream_try_queuefunction coda_fill_bitstreamfunction coda_bit_stream_end_flagfunction coda_isbusyfunction coda_parabuf_writefunction coda_alloc_context_buffunction coda_free_framebuffersfunction coda_alloc_framebuffersfunction coda_free_context_buffersfunction coda_alloc_context_buffersfunction coda_encode_headerfunction coda_slice_modefunction coda_enc_param_changefunction coda_iram_allocfunction coda_setup_iramfunction coda_firmware_supportedfunction coda_check_firmwarefunction coda9_set_frame_cachefunction coda_encoder_reqbufsfunction coda_start_encodingfunction RBSPfunction coda_prepare_encodefunction coda_frame_type_charfunction coda_finish_encodefunction coda_seq_end_workfunction coda_bit_releasefunction coda_alloc_bitstream_bufferfunction coda_free_bitstream_bufferfunction coda_decoder_reqbufsfunction coda_reorder_enablefunction coda_decoder_drop_used_metasfunction __coda_decoder_seq_initfunction coda_dec_seq_init_workfunction __coda_start_decodingfunction coda_start_decoding
Annotated Snippet
while (coda_read(dev, CODA9_GDI_BUS_STATUS) != 0x77) {
if (time_after(jiffies, timeout))
return -ETIME;
cpu_relax();
}
}
ret = reset_control_reset(dev->rstc);
if (ret < 0)
return ret;
if (dev->devtype->product == CODA_960)
coda_write(dev, 0x00, CODA9_GDI_BUS_CTRL);
coda_write(dev, CODA_REG_BIT_BUSY_FLAG, CODA_REG_BIT_BUSY);
coda_write(dev, CODA_REG_RUN_ENABLE, CODA_REG_BIT_CODE_RUN);
ret = coda_wait_timeout(dev);
coda_write(dev, idx, CODA_REG_BIT_RUN_INDEX);
return ret;
}
static void coda_kfifo_sync_from_device(struct coda_ctx *ctx)
{
struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo;
struct coda_dev *dev = ctx->dev;
u32 rd_ptr;
rd_ptr = coda_read(dev, CODA_REG_BIT_RD_PTR(ctx->reg_idx));
kfifo->out = (kfifo->in & ~kfifo->mask) |
(rd_ptr - ctx->bitstream.paddr);
if (kfifo->out > kfifo->in)
kfifo->out -= kfifo->mask + 1;
}
static void coda_kfifo_sync_to_device_full(struct coda_ctx *ctx)
{
struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo;
struct coda_dev *dev = ctx->dev;
u32 rd_ptr, wr_ptr;
rd_ptr = ctx->bitstream.paddr + (kfifo->out & kfifo->mask);
coda_write(dev, rd_ptr, CODA_REG_BIT_RD_PTR(ctx->reg_idx));
wr_ptr = ctx->bitstream.paddr + (kfifo->in & kfifo->mask);
coda_write(dev, wr_ptr, CODA_REG_BIT_WR_PTR(ctx->reg_idx));
}
static void coda_kfifo_sync_to_device_write(struct coda_ctx *ctx)
{
struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo;
struct coda_dev *dev = ctx->dev;
u32 wr_ptr;
wr_ptr = ctx->bitstream.paddr + (kfifo->in & kfifo->mask);
coda_write(dev, wr_ptr, CODA_REG_BIT_WR_PTR(ctx->reg_idx));
}
static int coda_h264_bitstream_pad(struct coda_ctx *ctx, u32 size)
{
unsigned char *buf;
u32 n;
if (size < 6)
size = 6;
buf = kmalloc(size, GFP_KERNEL);
if (!buf)
return -ENOMEM;
coda_h264_filler_nal(size, buf);
n = kfifo_in(&ctx->bitstream_fifo, buf, size);
kfree(buf);
return (n < size) ? -ENOSPC : 0;
}
int coda_bitstream_flush(struct coda_ctx *ctx)
{
int ret;
if (ctx->inst_type != CODA_INST_DECODER || !ctx->use_bit)
return 0;
ret = coda_command_sync(ctx, CODA_COMMAND_DEC_BUF_FLUSH);
if (ret < 0) {
v4l2_err(&ctx->dev->v4l2_dev, "failed to flush bitstream\n");
return ret;
}
kfifo_init(&ctx->bitstream_fifo, ctx->bitstream.vaddr,
ctx->bitstream.size);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/irqreturn.h`, `linux/kernel.h`, `linux/log2.h`, `linux/platform_device.h`, `linux/ratelimit.h`, `linux/reset.h`, `linux/slab.h`.
- Detected declarations: `function coda_is_initialized`, `function coda_isbusy`, `function coda_wait_timeout`, `function coda_command_async`, `function coda_command_sync`, `function coda_hw_reset`, `function coda_kfifo_sync_from_device`, `function coda_kfifo_sync_to_device_full`, `function coda_kfifo_sync_to_device_write`, `function coda_h264_bitstream_pad`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.