Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c92fd78
media: apple: avd: check that buffer size is positive
sofus13 Sep 1, 2026
14d4754
fixup! media: apple: avd: add av1 support
sofus13 Aug 31, 2026
0fcdc96
media: apple: avd: rename buffers
sofus13 Sep 2, 2026
1a134cb
fixup! media: apple: avd: define static values and bitmasks
sofus13 Sep 4, 2026
71f0cc9
media: apple: avd: add a dedicated "submit" step
sofus13 Sep 4, 2026
b27f8fd
fixup! media: apple: avd: support vp9
sofus13 Sep 8, 2026
f8d2e39
media: apple: avd: allow cacheable (non-coherent) MMAP buffers
aquarat Sep 13, 2026
d18d8b2
media: apple: avd: h264: reject slices that reference invalid DPB ent…
aquarat Sep 13, 2026
34292f7
media: apple: avd: allocate the job segment table with kvcalloc
aquarat Sep 13, 2026
b2d7e9d
media: apple: avd: h264: reset slice_num when a frame is done
aquarat Sep 13, 2026
e77342e
media: apple: avd: track job state so completions cannot race the run
chriskearney Sep 21, 2026
992f066
media: apple: avd: hevc: read controls after applying the request
chriskearney Sep 15, 2026
a7657a2
media: apple: avd: size the compressed chroma plane for 4:2:2
chriskearney Sep 15, 2026
f456f8a
media: apple: avd: h264: fill chroma with grey for 4:0:0 pictures
chriskearney Sep 15, 2026
012c81e
media: apple: avd: hevc: reject unequal bit depths and non-4:2:0 SPS
chriskearney Sep 15, 2026
14846c0
media: apple: avd: hevc: copy the slice and entry point arrays for th…
chriskearney Sep 15, 2026
dde0fc8
media: apple: avd: hevc: bound entry points and complete the request …
chriskearney Sep 15, 2026
79337a5
media: apple: avd: free job tables that were never submitted
chriskearney Sep 15, 2026
39f00a8
media: apple: avd: h264: keep slice data and the job table in bounds
chriskearney Sep 15, 2026
3791bf6
media: apple: avd: h264: use the 10-bit grey value for 10-bit 4:0:0
chriskearney Sep 15, 2026
6bc901c
media: apple: avd: accept HEVC 4:2:2 again, reject formats without a …
chriskearney Sep 15, 2026
cc2e2bc
media: apple: avd: drain the old watchdog before reusing its generation
chriskearney Sep 21, 2026
701175e
media: apple: avd: free AV1 above_info on stop
chriskearney Sep 21, 2026
a112078
media: apple: avd: clear failed allocations before retrying
chriskearney Sep 22, 2026
283bb51
media: apple: avd: complete requests when job allocation fails
chriskearney Sep 22, 2026
3e7e65e
media: apple: avd: fill monochrome chroma after capture synchronization
chriskearney Sep 22, 2026
9e8578f
media: apple: avd: release codec buffers when startup fails
chriskearney Sep 22, 2026
cf5b2c2
media: apple: avd: handle AV1 work buffer allocation failures
chriskearney Sep 22, 2026
0b4025f
media: apple: avd: return source buffers when streaming fails to start
chriskearney Sep 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
422 changes: 215 additions & 207 deletions drivers/media/platform/apple/avd/avd-av1.c

Large diffs are not rendered by default.

281 changes: 230 additions & 51 deletions drivers/media/platform/apple/avd/avd-drv.c

Large diffs are not rendered by default.

316 changes: 193 additions & 123 deletions drivers/media/platform/apple/avd/avd-h264.c

Large diffs are not rendered by default.

331 changes: 148 additions & 183 deletions drivers/media/platform/apple/avd/avd-hevc.c

Large diffs are not rendered by default.

47 changes: 30 additions & 17 deletions drivers/media/platform/apple/avd/avd-inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@

#define AVD_OP_HDR FIELD_PREP(GENMASK(31, 20), 0x2db)
#define AVD_OP_HDR_CONST FIELD_PREP(GENMASK(10, 0), 0x2e0)

/*
* only for 10 bit.
* output in packed p010 / nv15 kinda format
* 10 bits per component. With groups of tree packed into 4 bytes (little
* endian order)
* P 3 2 1
* [2:10:10:10]
*
* additionally, av1 and vp9 need an extra scratch buffer if this is set
*/
#define AVD_OP_HDR_FLAG_PACKED(v) FIELD_PREP(BIT(10), !!(v))
/* decompress pixel data */
#define AVD_OP_HDR_FLAG_DECOMP(v) FIELD_PREP(BIT(12), !!(v))
#define AVD_OP_HDR_FLAG_INTRA(v) FIELD_PREP(BIT(13), !!(v))
Expand Down Expand Up @@ -153,42 +165,43 @@ static inline bool boolify(u32 v)
return !!(v);
}

static inline void push(struct avd_dev *avd, struct avd_ctx *ctx, u32 inst)
static inline void push(struct avd_ctx *ctx, u32 inst)
{
writel(inst, avd->ctrl + avd->variant->vp_slot_offset + ctx->vp_slot * 4);
struct avd_job *job = &ctx->job;
struct avd_segment *seg = &job->segments[job->num];
seg->instructions[seg->num++] = inst;
}

static inline void push_address(struct avd_dev *avd, struct avd_ctx *ctx,
dma_addr_t addr)
static inline void push_address(struct avd_ctx *ctx, dma_addr_t addr)
{
if (avd->variant->quirks & AVD_QUIRK_LSR) {
push(avd, ctx, (addr >> 8));
if (ctx->dev->variant->quirks & AVD_QUIRK_LSR) {
push(ctx, (addr >> 8));
} else {
push(avd, ctx, (u32)(addr & 0xffffffff));
push(avd, ctx, (u32)(addr >> 32));
push(ctx, (u32)(addr & 0xffffffff));
push(ctx, (u32)(addr >> 32));
}
}
static inline void push_comp(struct avd_dev *avd, struct avd_ctx *ctx,
dma_addr_t addr, u32 offsets[4])
static inline void push_comp(struct avd_ctx *ctx, dma_addr_t addr,
u32 offsets[4])
{
if (avd->variant->quirks & AVD_QUIRK_LSR) {
if (ctx->dev->variant->quirks & AVD_QUIRK_LSR) {
for (int i = 0; i < 4; i++)
push(avd, ctx, (addr + offsets[i]) >> 7);
push(ctx, (addr + offsets[i]) >> 7);
} else {
for (int i = 0; i < 4; i++)
push_address(avd, ctx, (addr + offsets[i]));
push_address(ctx, (addr + offsets[i]));
}
}

#ifdef DEBUG_INST
#define push(inst, name) \
do { \
dev_info(ctx->dev->dev, "%8x | %s", (inst), name); \
push(avd, ctx, inst); \
push(ctx, inst); \
} while (0)

#else
#define push(inst, name) push(avd, ctx, inst)
#define push(inst, name) push(ctx, inst)
#endif

#ifdef DEBUG_INST_ADDR
Expand All @@ -198,11 +211,11 @@ static inline void push_comp(struct avd_dev *avd, struct avd_ctx *ctx,
name, i); \
dev_info(ctx->dev->dev, "%8llx | %s[%d] (high)", (inst) >> 32, \
name, i); \
push_address(avd, ctx, inst); \
push_address(ctx, inst); \
} while (0)

#else
#define pusha(inst, name, i) push_address(avd, ctx, inst)
#define pusha(inst, name, i) push_address(ctx, inst)
#endif

#endif /* AVD_INST_H_ */
66 changes: 62 additions & 4 deletions drivers/media/platform/apple/avd/avd-v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,13 +823,46 @@ static int avd_buf_prepare(struct vb2_buffer *vb)
* (for OUTPUT buffers, if userspace passes 0 bytesused, v4l2-core sets
* it to buffer length).
*/
if (V4L2_TYPE_IS_CAPTURE(vq->type))
if (V4L2_TYPE_IS_CAPTURE(vq->type)) {
vb2_to_avd_decoded_buf(vb)->grey_chroma_offset = 0;
vb2_set_plane_payload(vb, 0,
f->fmt.pix_mp.plane_fmt[0].sizeimage);
}

return 0;
}

static void avd_buf_finish(struct vb2_buffer *vb)
{
struct avd_decoded_buffer *buf;
size_t luma;
u8 *y;

if (!V4L2_TYPE_IS_CAPTURE(vb->vb2_queue->type))
return;

buf = vb2_to_avd_decoded_buf(vb);
luma = buf->grey_chroma_offset;
buf->grey_chroma_offset = 0;
if (!luma || vb->state != VB2_BUF_STATE_DONE)
return;

/* VB2 has synchronized the capture buffer for CPU access. */
y = vb2_plane_vaddr(vb, 0);
if (!y)
return;

if (buf->grey_chroma_10bit) {
/* P010: 16-bit little-endian samples, 512 << 6. */
for (size_t i = 0; i + 1 < luma / 2; i += 2) {
y[luma + i] = 0x00;
y[luma + i + 1] = 0x80;
}
} else {
memset(y + luma, 0x80, luma / 2);
}
}

static void avd_buf_queue(struct vb2_buffer *vb)
{
struct avd_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
Expand Down Expand Up @@ -857,22 +890,31 @@ static int avd_start_streaming(struct vb2_queue *q, unsigned int count)
{
struct avd_ctx *ctx = vb2_get_drv_priv(q);
const struct avd_coded_fmt_desc *desc;
struct vb2_v4l2_buffer *vbuf;
int ret;

if (V4L2_TYPE_IS_CAPTURE(q->type))
return 0;

desc = ctx->coded_fmt_desc;
if (WARN_ON(!desc))
return -EINVAL;
if (WARN_ON(!desc)) {
ret = -EINVAL;
goto err_return_buffers;
}

if (desc->ops->start) {
ret = desc->ops->start(ctx);
if (ret)
return ret;
goto err_return_buffers;
}

return 0;

err_return_buffers:
/* Keep requests queued for a later STREAMON retry. */
while ((vbuf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx)))
v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_QUEUED);
return ret;
}

static void avd_queue_cleanup(struct vb2_queue *vq, u32 state)
Expand Down Expand Up @@ -908,6 +950,10 @@ static void avd_stop_streaming(struct vb2_queue *q)

if (desc->ops->stop)
desc->ops->stop(ctx);

/* Drop a job table left over from a frame that never finished. */
kvfree(ctx->job.segments);
ctx->job.segments = NULL;
}

avd_queue_cleanup(q, VB2_BUF_STATE_ERROR);
Expand All @@ -916,6 +962,7 @@ static void avd_stop_streaming(struct vb2_queue *q)
const struct vb2_ops avd_queue_ops = {
.queue_setup = avd_queue_setup,
.buf_prepare = avd_buf_prepare,
.buf_finish = avd_buf_finish,
.buf_queue = avd_buf_queue,
.buf_out_validate = avd_buf_out_validate,
.buf_request_complete = avd_buf_request_complete,
Expand All @@ -925,6 +972,17 @@ const struct vb2_ops avd_queue_ops = {

void avd_job_finish_no_pm(struct avd_ctx *ctx, enum vb2_buffer_state result)
{
struct avd_dev *avd = ctx->dev;
unsigned long flags;

spin_lock_irqsave(&avd->job_lock, flags);
if (avd->job_ctx == ctx) {
avd->job_state = AVD_JOB_IDLE;
avd->job_ctx = NULL;
avd->job_pending = false;
}
spin_unlock_irqrestore(&avd->job_lock, flags);

if (ctx->coded_fmt_desc->ops->done) {
struct vb2_v4l2_buffer *src_buf, *dst_buf;

Expand Down
Loading