* [PATCH v20 01/15] media: mediatek: jpeg: fix jpeg cores' amounts setting
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:29 ` sashiko-bot
2026-11-25 6:16 ` [PATCH v20 02/15] media: mediatek: jpeg: fix jpeg buffer payload size setting Kyrie Wu
` (13 subsequent siblings)
14 siblings, 1 reply; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
Different ICs have different amounts of cores,
use a variable to set the cores' amounts.
Fixes: 934e8bccac95 ("mtk-jpegenc: support jpegenc multi-hardware")
Fixes: 0fa49df4222f ("media: mtk-jpegdec: support jpegdec multi-hardware")
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
.../platform/mediatek/jpeg/mtk_jpeg_core.c | 19 ++++++++++++++-----
.../platform/mediatek/jpeg/mtk_jpeg_core.h | 2 ++
.../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 2 ++
.../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 2 ++
4 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index e01dd4d80..3caee184f 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1294,6 +1294,7 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
struct mtk_jpeg_dev *jpeg;
struct device_node *child;
int num_child = 0;
+ int hw_max;
int ret;
jpeg = devm_kzalloc_obj(&pdev->dev, *jpeg);
@@ -1302,6 +1303,7 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
mutex_init(&jpeg->lock);
spin_lock_init(&jpeg->hw_lock);
+ atomic_set(&jpeg->hw_rdy, 0);
jpeg->dev = &pdev->dev;
jpeg->variant = of_device_get_match_data(jpeg->dev);
@@ -1325,7 +1327,14 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
for_each_child_of_node(pdev->dev.of_node, child)
num_child++;
- atomic_set(&jpeg->hw_rdy, num_child);
+ hw_max = jpeg->variant->cap_q_default_fourcc == V4L2_PIX_FMT_JPEG ?
+ MTK_JPEGENC_HW_MAX : MTK_JPEGDEC_HW_MAX;
+ if (num_child > hw_max)
+ return dev_err_probe(jpeg->dev, -EINVAL,
+ "Too many JPEG cores: %d (max %d)\n",
+ num_child, hw_max);
+
+ jpeg->max_hw_count = num_child;
atomic_set(&jpeg->hw_index, 0);
jpeg->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
@@ -1462,7 +1471,7 @@ static int mtk_jpegenc_get_hw(struct mtk_jpeg_ctx *ctx)
int i;
spin_lock_irqsave(&jpeg->hw_lock, flags);
- for (i = 0; i < MTK_JPEGENC_HW_MAX; i++) {
+ for (i = 0; i < jpeg->max_hw_count; i++) {
comp_jpeg = jpeg->enc_hw_dev[i];
if (comp_jpeg->hw_state == MTK_JPEG_HW_IDLE) {
hw_id = i;
@@ -1509,7 +1518,7 @@ static int mtk_jpegdec_get_hw(struct mtk_jpeg_ctx *ctx)
int i;
spin_lock_irqsave(&jpeg->hw_lock, flags);
- for (i = 0; i < MTK_JPEGDEC_HW_MAX; i++) {
+ for (i = 0; i < jpeg->max_hw_count; i++) {
comp_jpeg = jpeg->dec_hw_dev[i];
if (comp_jpeg->hw_state == MTK_JPEG_HW_IDLE) {
hw_id = i;
@@ -1592,7 +1601,7 @@ static void mtk_jpegenc_worker(struct work_struct *work)
jpeg_work);
struct mtk_jpeg_dev *jpeg = ctx->jpeg;
- for (i = 0; i < MTK_JPEGENC_HW_MAX; i++)
+ for (i = 0; i < jpeg->max_hw_count; i++)
comp_jpeg[i] = jpeg->enc_hw_dev[i];
i = 0;
@@ -1688,7 +1697,7 @@ static void mtk_jpegdec_worker(struct work_struct *work)
struct mtk_jpeg_fb fb;
unsigned long flags;
- for (i = 0; i < MTK_JPEGDEC_HW_MAX; i++)
+ for (i = 0; i < jpeg->max_hw_count; i++)
comp_jpeg[i] = jpeg->dec_hw_dev[i];
i = 0;
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
index 02ed0ed5b..6be5cf30d 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
@@ -212,6 +212,7 @@ struct mtk_jpegdec_comp_dev {
* @reg_decbase: jpg decode register base addr
* @dec_hw_dev: jpg decode hardware device
* @hw_index: jpg hw index
+ * @max_hw_count: jpeg hw-core count
*/
struct mtk_jpeg_dev {
struct mutex lock;
@@ -234,6 +235,7 @@ struct mtk_jpeg_dev {
void __iomem *reg_decbase[MTK_JPEGDEC_HW_MAX];
struct mtk_jpegdec_comp_dev *dec_hw_dev[MTK_JPEGDEC_HW_MAX];
atomic_t hw_index;
+ u32 max_hw_count;
};
/**
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
index 74df7fbad..3c22417f4 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
@@ -668,6 +668,8 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, dev);
pm_runtime_enable(&pdev->dev);
+ atomic_inc(&master_dev->hw_rdy);
+
return 0;
}
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
index cbea791e6..708f3fbc6 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
@@ -389,6 +389,8 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, dev);
pm_runtime_enable(&pdev->dev);
+ atomic_inc(&master_dev->hw_rdy);
+
return 0;
}
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH v20 01/15] media: mediatek: jpeg: fix jpeg cores' amounts setting
2026-11-25 6:16 ` [PATCH v20 01/15] media: mediatek: jpeg: fix jpeg cores' amounts setting Kyrie Wu
@ 2026-11-25 6:29 ` sashiko-bot
0 siblings, 0 replies; 23+ messages in thread
From: sashiko-bot @ 2026-11-25 6:29 UTC (permalink / raw)
To: Kyrie Wu, devicetree; +Cc: robh, conor+dt, media-ci
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] media: mediatek: jpeg: child probe in mtk_jpeg_probe() before
bounds check
- [High] media: mediatek: jpeg: NULL deref in get_hw() when max_hw_count
> probed
--
commit cfc2baea3485ec02d134ce90cc368bfa48a69866
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: jpeg: fix jpeg cores' amounts setting
This commit tracks the number of JPEG hardware core child nodes in
jpeg->max_hw_count instead of iterating over the fixed MTK_JPEGENC_HW_MAX
and MTK_JPEGDEC_HW_MAX limits, and increments jpeg->hw_rdy as each child
core probes.
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> index e01dd4d80722c..3caee184ff5ed 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> @@ -1294,6 +1294,7 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
> struct mtk_jpeg_dev *jpeg;
> struct device_node *child;
> int num_child = 0;
> + int hw_max;
> int ret;
>
> jpeg = devm_kzalloc_obj(&pdev->dev, *jpeg);
> @@ -1302,6 +1303,7 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
>
> mutex_init(&jpeg->lock);
> spin_lock_init(&jpeg->hw_lock);
> + atomic_set(&jpeg->hw_rdy, 0);
> jpeg->dev = &pdev->dev;
> jpeg->variant = of_device_get_match_data(jpeg->dev);
>
> @@ -1325,7 +1327,14 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
> for_each_child_of_node(pdev->dev.of_node, child)
> num_child++;
>
> - atomic_set(&jpeg->hw_rdy, num_child);
> + hw_max = jpeg->variant->cap_q_default_fourcc == V4L2_PIX_FMT_JPEG ?
> + MTK_JPEGENC_HW_MAX : MTK_JPEGDEC_HW_MAX;
> + if (num_child > hw_max)
> + return dev_err_probe(jpeg->dev, -EINVAL,
> + "Too many JPEG cores: %d (max %d)\n",
> + num_child, hw_max);
> +
> + jpeg->max_hw_count = num_child;
> atomic_set(&jpeg->hw_index, 0);
>
> jpeg->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
[Severity: High]
Does the num_child > hw_max check and atomic_set(&jpeg->hw_index, 0) run
too late when devm_of_platform_populate() is called earlier in
mtk_jpeg_probe()?
When the child driver is already registered (such as when built as a
module, since mtk_jpeg.ko depends on mtk-jpeg-enc-hw.ko and
mtk-jpeg-dec-hw.ko), devm_of_platform_populate() synchronously runs
mtk_jpegenc_hw_probe() or mtk_jpegdec_hw_probe() before reaching the
multi_core block:
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c:mtk_jpegdec_hw_probe() {
...
i = atomic_add_return(1, &master_dev->hw_index) - 1;
master_dev->dec_hw_dev[i] = dev;
master_dev->reg_decbase[i] = dev->reg_base;
...
}
If num_child > hw_max, the child probes write out of bounds into
dec_hw_dev[] or enc_hw_dev[] before the bounds check in mtk_jpeg_probe()
is reached. In addition, resetting jpeg->hw_index to 0 after
devm_of_platform_populate() means that if one child probes synchronously
(taking slot 0) and a second child defers probe, the deferred child will
also receive index 0 when it later probes, overwriting slot 0 and leaving
slot 1 NULL.
> @@ -1462,7 +1471,7 @@ static int mtk_jpegenc_get_hw(struct mtk_jpeg_ctx *ctx)
> int i;
>
> spin_lock_irqsave(&jpeg->hw_lock, flags);
> - for (i = 0; i < MTK_JPEGENC_HW_MAX; i++) {
> + for (i = 0; i < jpeg->max_hw_count; i++) {
> comp_jpeg = jpeg->enc_hw_dev[i];
> if (comp_jpeg->hw_state == MTK_JPEG_HW_IDLE) {
> hw_id = i;
> @@ -1509,7 +1518,7 @@ static int mtk_jpegdec_get_hw(struct mtk_jpeg_ctx *ctx)
> int i;
>
> spin_lock_irqsave(&jpeg->hw_lock, flags);
> - for (i = 0; i < MTK_JPEGDEC_HW_MAX; i++) {
> + for (i = 0; i < jpeg->max_hw_count; i++) {
> comp_jpeg = jpeg->dec_hw_dev[i];
> if (comp_jpeg->hw_state == MTK_JPEG_HW_IDLE) {
> hw_id = i;
> @@ -1592,7 +1601,7 @@ static void mtk_jpegenc_worker(struct work_struct *work)
> jpeg_work);
> struct mtk_jpeg_dev *jpeg = ctx->jpeg;
>
> - for (i = 0; i < MTK_JPEGENC_HW_MAX; i++)
> + for (i = 0; i < jpeg->max_hw_count; i++)
> comp_jpeg[i] = jpeg->enc_hw_dev[i];
> i = 0;
>
> @@ -1688,7 +1697,7 @@ static void mtk_jpegdec_worker(struct work_struct *work)
> struct mtk_jpeg_fb fb;
> unsigned long flags;
>
> - for (i = 0; i < MTK_JPEGDEC_HW_MAX; i++)
> + for (i = 0; i < jpeg->max_hw_count; i++)
> comp_jpeg[i] = jpeg->dec_hw_dev[i];
> i = 0;
>
[Severity: High]
Can mtk_jpegenc_get_hw() and mtk_jpegdec_get_hw() dereference a NULL
comp_jpeg pointer when jpeg->max_hw_count exceeds the number of probed
child cores?
jpeg->max_hw_count is set from for_each_child_of_node(), which counts all
DT child nodes including disabled ones, whereas enc_hw_dev[i] and
dec_hw_dev[i] are only populated as each child finishes probing. If a
child node is disabled, fails or defers probe, or has not bound yet when a
V4L2 job runs, mtk_jpegenc_worker() and mtk_jpegdec_worker() call
mtk_jpegenc_get_hw() / mtk_jpegdec_get_hw() before waiting on
jpeg->hw_rdy, and iterating up to jpeg->max_hw_count hits a NULL
enc_hw_dev[i] or dec_hw_dev[i] and dereferences comp_jpeg->hw_state.
Even if a child finishes probing while the worker is waiting on
jpeg->hw_wq, comp_jpeg[] in the worker is snapshotted before the
retry_select loop, so comp_jpeg[hw_id] remains NULL and crashes at
pm_runtime_resume_and_get(comp_jpeg[hw_id]->dev).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125061618.2544386-1-kyrie.wu@mediatek.com?part=1
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH v20 02/15] media: mediatek: jpeg: fix jpeg buffer payload size setting
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
2026-11-25 6:16 ` [PATCH v20 01/15] media: mediatek: jpeg: fix jpeg cores' amounts setting Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:16 ` [PATCH v20 03/15] media: mediatek: jpeg: fix buffer structure size and layout Kyrie Wu
` (12 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
For multi-core jpegdec, if one core gets resolution change event,
the payload size, representing the size of Y/C data, needs to change.
But others are decoding at the same time and it can not be changed
immediately, which results in the payload size not matching the real
buffer length.
The payload size must be less than the real buffer length to avoid
warning logs.
Fixes: 0fa49df4222f ("media: mtk-jpegdec: support jpegdec multi-hardware")
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
.../platform/mediatek/jpeg/mtk_jpeg_core.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 3caee184f..75d6fac0e 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -702,6 +702,7 @@ static int mtk_jpeg_buf_prepare(struct vb2_buffer *vb)
struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct mtk_jpeg_q_data *q_data = NULL;
struct v4l2_plane_pix_format plane_fmt = {};
+ size_t max_size;
int i;
q_data = mtk_jpeg_get_q_data(ctx, vb->vb2_queue->type);
@@ -710,12 +711,20 @@ static int mtk_jpeg_buf_prepare(struct vb2_buffer *vb)
for (i = 0; i < q_data->fmt->colplanes; i++) {
plane_fmt = q_data->pix_mp.plane_fmt[i];
+ max_size = plane_fmt.sizeimage;
+
if (ctx->enable_exif &&
- q_data->fmt->fourcc == V4L2_PIX_FMT_JPEG)
- vb2_set_plane_payload(vb, i, plane_fmt.sizeimage +
- MTK_JPEG_MAX_EXIF_SIZE);
- else
- vb2_set_plane_payload(vb, i, plane_fmt.sizeimage);
+ q_data->fmt->fourcc == V4L2_PIX_FMT_JPEG) {
+ max_size += MTK_JPEG_MAX_EXIF_SIZE;
+
+ vb2_set_plane_payload(vb, i,
+ MIN(vb->planes[i].length,
+ max_size));
+ } else {
+ vb2_set_plane_payload(vb, i,
+ MIN(plane_fmt.sizeimage,
+ vb->planes[i].length));
+ }
}
return 0;
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH v20 03/15] media: mediatek: jpeg: fix buffer structure size and layout
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
2026-11-25 6:16 ` [PATCH v20 01/15] media: mediatek: jpeg: fix jpeg cores' amounts setting Kyrie Wu
2026-11-25 6:16 ` [PATCH v20 02/15] media: mediatek: jpeg: fix jpeg buffer payload size setting Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:16 ` [PATCH v20 04/15] media: mediatek: jpeg: Fix buffer completion on multi-core streaming stop Kyrie Wu
` (11 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
Updates the `buf_struct_size` in the JPEG driver to use the correct
structure `mtk_jpeg_src_buf` instead of `v4l2_m2m_buffer`, ensuring
proper handling of source buffers. The previous buffer size led to
mismatches and potential issues during video buffer handling.
Moves `frame_num` in the `mtk_jpeg_src_buf` structure to align with
other members appropriately. The first field of the driver-specific
buffer structure must be the subsystem-specificstruct
(vb2_v4l2_buffer in the case of V4L2).
Fixes: 5fb1c2361e56 ("mtk-jpegenc: add jpeg encode worker interface")
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 2 +-
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 75d6fac0e..16798b2c7 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1092,7 +1092,7 @@ static int mtk_jpeg_queue_init(void *priv, struct vb2_queue *src_vq,
dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
dst_vq->io_modes = VB2_DMABUF | VB2_MMAP;
dst_vq->drv_priv = ctx;
- dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
+ dst_vq->buf_struct_size = sizeof(struct mtk_jpeg_src_buf);
dst_vq->ops = jpeg->variant->qops;
dst_vq->mem_ops = &vb2_dma_contig_memops;
dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
index 6be5cf30d..148fd4175 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
@@ -85,10 +85,10 @@ struct mtk_jpeg_variant {
};
struct mtk_jpeg_src_buf {
- u32 frame_num;
struct vb2_v4l2_buffer b;
struct list_head list;
u32 bs_size;
+ u32 frame_num;
struct mtk_jpeg_dec_param dec_param;
struct mtk_jpeg_ctx *curr_ctx;
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH v20 04/15] media: mediatek: jpeg: Fix buffer completion on multi-core streaming stop
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
` (2 preceding siblings ...)
2026-11-25 6:16 ` [PATCH v20 03/15] media: mediatek: jpeg: fix buffer structure size and layout Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:16 ` [PATCH v20 05/15] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting Kyrie Wu
` (10 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
Enhances the Mediatek JPEG driver's stability and reliability by ensuring
that all queued buffers are processed before stopping the streaming in
multi-core environments. It introduces a call to
`vb2_wait_for_all_buffers()` in the `mtk_jpeg_enc_stop_streaming()` and
`mtk_jpeg_dec_stop_streaming()` functions when the `multi_core` variant
is enabled. This change ensures that no buffers are left unprocessed,
preventing potential data loss or corruption during multi-core flow.
Fixes: 0fa49df4222f ("media: mtk-jpegdec: support jpegdec multi-hardware")
Fixes: dedc21500334 ("media: mtk-jpegdec: add jpeg decode worker interface")
Fixes: 934e8bccac95 ("mtk-jpegenc: support jpegenc multi-hardware")
Fixes: 5fb1c2361e56 ("mtk-jpegenc: add jpeg encode worker interface")
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
.../media/platform/mediatek/jpeg/mtk_jpeg_core.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 16798b2c7..6386f9004 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -850,22 +850,33 @@ static struct vb2_v4l2_buffer *mtk_jpeg_buf_remove(struct mtk_jpeg_ctx *ctx,
static void mtk_jpeg_enc_stop_streaming(struct vb2_queue *q)
{
struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(q);
+ struct mtk_jpeg_dev *jpeg = ctx->jpeg;
struct vb2_v4l2_buffer *vb;
while ((vb = mtk_jpeg_buf_remove(ctx, q->type)))
v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
+
+ if (jpeg->variant->multi_core)
+ vb2_wait_for_all_buffers(q);
}
static void mtk_jpeg_dec_stop_streaming(struct vb2_queue *q)
{
struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(q);
+ struct mtk_jpeg_dev *jpeg = ctx->jpeg;
struct vb2_v4l2_buffer *vb;
+ while ((vb = mtk_jpeg_buf_remove(ctx, q->type)))
+ v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
+
/*
* STREAMOFF is an acknowledgment for source change event.
* Before STREAMOFF, we still have to return the old resolution and
* subsampling. Update capture queue when the stream is off.
*/
+ if (jpeg->variant->multi_core)
+ vb2_wait_for_all_buffers(q);
+
if (ctx->state == MTK_JPEG_SOURCE_CHANGE &&
V4L2_TYPE_IS_CAPTURE(q->type)) {
struct mtk_jpeg_src_buf *src_buf;
@@ -877,9 +888,6 @@ static void mtk_jpeg_dec_stop_streaming(struct vb2_queue *q)
} else if (V4L2_TYPE_IS_OUTPUT(q->type)) {
ctx->state = MTK_JPEG_INIT;
}
-
- while ((vb = mtk_jpeg_buf_remove(ctx, q->type)))
- v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
}
static const struct vb2_ops mtk_jpeg_dec_qops = {
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH v20 05/15] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
` (3 preceding siblings ...)
2026-11-25 6:16 ` [PATCH v20 04/15] media: mediatek: jpeg: Fix buffer completion on multi-core streaming stop Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:38 ` sashiko-bot
2026-11-25 6:16 ` [PATCH v20 06/15] media: mediatek: jpeg: fix buffer state update timing Kyrie Wu
` (9 subsequent siblings)
14 siblings, 1 reply; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
Make multi-hw component devices own their clocks and suspend callbacks.
Keep single-core clock callbacks on the master device.
Pause M2M job dispatch with v4l2_m2m_suspend(). Multi-core workers
finish M2M dispatch before hardware completion, so reject system
suspend with -EBUSY if a component is busy. Only force runtime suspend
for idle components. Runtime-PM references keep clocks enabled until
job completion or timeout.
Fixes: 934e8bccac95 ("mtk-jpegenc: support jpegenc multi-hardware")
Fixes: 0fa49df4222f ("media: mtk-jpegdec: support jpegdec multi-hardware")
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
.../platform/mediatek/jpeg/mtk_jpeg_core.c | 27 +++-----
.../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 64 +++++++++++++++++--
.../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 62 ++++++++++++++++--
3 files changed, 124 insertions(+), 29 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 6386f9004..649b9d952 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1115,6 +1115,9 @@ static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg)
{
int ret;
+ if (jpeg->variant->multi_core)
+ return;
+
ret = clk_bulk_prepare_enable(jpeg->variant->num_clks,
jpeg->variant->clks);
if (ret)
@@ -1123,6 +1126,9 @@ static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg)
static void mtk_jpeg_clk_off(struct mtk_jpeg_dev *jpeg)
{
+ if (jpeg->variant->multi_core)
+ return;
+
clk_bulk_disable_unprepare(jpeg->variant->num_clks,
jpeg->variant->clks);
}
@@ -1656,14 +1662,6 @@ retry_select:
goto enc_end;
}
- ret = clk_prepare_enable(comp_jpeg[hw_id]->venc_clk.clks->clk);
- if (ret) {
- dev_err(jpeg->dev, "%s : %d, jpegenc clk_prepare_enable fail\n",
- __func__, __LINE__);
- pm_runtime_put(comp_jpeg[hw_id]->dev);
- goto enc_end;
- }
-
v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
@@ -1773,13 +1771,6 @@ retry_select:
goto dec_end;
}
- ret = clk_prepare_enable(comp_jpeg[hw_id]->jdec_clk.clks->clk);
- if (ret) {
- dev_err(jpeg->dev, "%s : %d, jpegdec clk_prepare_enable fail\n",
- __func__, __LINE__);
- goto clk_end;
- }
-
v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
@@ -1789,7 +1780,7 @@ retry_select:
&dst_buf->vb2_buf, &fb)) {
dev_err(jpeg->dev, "%s : %d, mtk_jpeg_set_dec_dst fail\n",
__func__, __LINE__);
- goto setdst_end;
+ goto set_dst_fail;
}
schedule_delayed_work(&comp_jpeg[hw_id]->job_timeout_work,
@@ -1810,9 +1801,7 @@ retry_select:
return;
-setdst_end:
- clk_disable_unprepare(comp_jpeg[hw_id]->jdec_clk.clks->clk);
-clk_end:
+set_dst_fail:
pm_runtime_put(comp_jpeg[hw_id]->dev);
dec_end:
v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
index 3c22417f4..b9ba37a88 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
@@ -533,13 +533,12 @@ static void mtk_jpegdec_timeout_work(struct work_struct *work)
v4l2_m2m_buf_copy_metadata(src_buf, dst_buf);
mtk_jpeg_dec_reset(cjpeg->reg_base);
- clk_disable_unprepare(cjpeg->jdec_clk.clks->clk);
- pm_runtime_put(cjpeg->dev);
cjpeg->hw_state = MTK_JPEG_HW_IDLE;
atomic_inc(&master_jpeg->hw_rdy);
wake_up(&master_jpeg->hw_wq);
v4l2_m2m_buf_done(src_buf, buf_state);
mtk_jpegdec_put_buf(cjpeg);
+ pm_runtime_put(cjpeg->dev);
}
static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv)
@@ -547,7 +546,6 @@ static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv)
struct vb2_v4l2_buffer *src_buf, *dst_buf;
struct mtk_jpeg_src_buf *jpeg_src_buf;
enum vb2_buffer_state buf_state;
- struct mtk_jpeg_ctx *ctx;
u32 dec_irq_ret;
u32 irq_status;
int i;
@@ -557,7 +555,6 @@ static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv)
cancel_delayed_work(&jpeg->job_timeout_work);
- ctx = jpeg->hw_param.curr_ctx;
src_buf = jpeg->hw_param.src_buffer;
dst_buf = jpeg->hw_param.dst_buffer;
v4l2_m2m_buf_copy_metadata(src_buf, dst_buf);
@@ -580,12 +577,11 @@ static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv)
buf_state = VB2_BUF_STATE_DONE;
v4l2_m2m_buf_done(src_buf, buf_state);
mtk_jpegdec_put_buf(jpeg);
- pm_runtime_put(ctx->jpeg->dev);
- clk_disable_unprepare(jpeg->jdec_clk.clks->clk);
jpeg->hw_state = MTK_JPEG_HW_IDLE;
wake_up(&master_jpeg->hw_wq);
atomic_inc(&master_jpeg->hw_rdy);
+ pm_runtime_put(jpeg->dev);
return IRQ_HANDLED;
}
@@ -673,11 +669,67 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev)
return 0;
}
+static int mtk_jpegdec_pm_suspend(struct device *dev)
+{
+ struct mtk_jpegdec_comp_dev *jpeg = dev_get_drvdata(dev);
+
+ clk_bulk_disable_unprepare(jpeg->jdec_clk.clk_num,
+ jpeg->jdec_clk.clks);
+
+ return 0;
+}
+
+static int mtk_jpegdec_pm_resume(struct device *dev)
+{
+ struct mtk_jpegdec_comp_dev *jpeg = dev_get_drvdata(dev);
+
+ return clk_bulk_prepare_enable(jpeg->jdec_clk.clk_num,
+ jpeg->jdec_clk.clks);
+}
+
+static int mtk_jpegdec_suspend(struct device *dev)
+{
+ struct mtk_jpegdec_comp_dev *jpeg = dev_get_drvdata(dev);
+ int ret;
+
+ /* Stop new submissions before checking hardware activity. */
+ v4l2_m2m_suspend(jpeg->master_dev->m2m_dev);
+
+ if (READ_ONCE(jpeg->hw_state) != MTK_JPEG_HW_IDLE)
+ ret = -EBUSY;
+ else
+ ret = pm_runtime_force_suspend(dev);
+ if (ret)
+ v4l2_m2m_resume(jpeg->master_dev->m2m_dev);
+
+ return ret;
+}
+
+static int mtk_jpegdec_resume(struct device *dev)
+{
+ struct mtk_jpegdec_comp_dev *jpeg = dev_get_drvdata(dev);
+ int ret;
+
+ ret = pm_runtime_force_resume(dev);
+ if (ret < 0)
+ return ret;
+
+ v4l2_m2m_resume(jpeg->master_dev->m2m_dev);
+
+ return 0;
+}
+
+static const struct dev_pm_ops mtk_jpegdec_pm_ops = {
+ SYSTEM_SLEEP_PM_OPS(mtk_jpegdec_suspend, mtk_jpegdec_resume)
+ RUNTIME_PM_OPS(mtk_jpegdec_pm_suspend, mtk_jpegdec_pm_resume, NULL)
+};
+
static struct platform_driver mtk_jpegdec_hw_driver = {
.probe = mtk_jpegdec_hw_probe,
.driver = {
.name = "mtk-jpegdec-hw",
.of_match_table = mtk_jpegdec_hw_ids,
+ .pm = pm_ptr(&mtk_jpegdec_pm_ops),
},
};
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
index 708f3fbc6..25e1aafc4 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
@@ -263,13 +263,12 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work)
v4l2_m2m_buf_copy_metadata(src_buf, dst_buf);
mtk_jpeg_enc_reset(cjpeg->reg_base);
- clk_disable_unprepare(cjpeg->venc_clk.clks->clk);
- pm_runtime_put(cjpeg->dev);
cjpeg->hw_state = MTK_JPEG_HW_IDLE;
atomic_inc(&master_jpeg->hw_rdy);
wake_up(&master_jpeg->hw_wq);
v4l2_m2m_buf_done(src_buf, buf_state);
mtk_jpegenc_put_buf(cjpeg);
+ pm_runtime_put(cjpeg->dev);
}
static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv)
@@ -303,12 +302,11 @@ static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv)
buf_state = VB2_BUF_STATE_DONE;
v4l2_m2m_buf_done(src_buf, buf_state);
mtk_jpegenc_put_buf(jpeg);
- pm_runtime_put(ctx->jpeg->dev);
- clk_disable_unprepare(jpeg->venc_clk.clks->clk);
jpeg->hw_state = MTK_JPEG_HW_IDLE;
wake_up(&master_jpeg->hw_wq);
atomic_inc(&master_jpeg->hw_rdy);
+ pm_runtime_put(jpeg->dev);
return IRQ_HANDLED;
}
@@ -394,11 +392,67 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev)
return 0;
}
+static int mtk_jpegenc_pm_suspend(struct device *dev)
+{
+ struct mtk_jpegenc_comp_dev *jpeg = dev_get_drvdata(dev);
+
+ clk_bulk_disable_unprepare(jpeg->venc_clk.clk_num,
+ jpeg->venc_clk.clks);
+
+ return 0;
+}
+
+static int mtk_jpegenc_pm_resume(struct device *dev)
+{
+ struct mtk_jpegenc_comp_dev *jpeg = dev_get_drvdata(dev);
+
+ return clk_bulk_prepare_enable(jpeg->venc_clk.clk_num,
+ jpeg->venc_clk.clks);
+}
+
+static int mtk_jpegenc_suspend(struct device *dev)
+{
+ struct mtk_jpegenc_comp_dev *jpeg = dev_get_drvdata(dev);
+ int ret;
+
+ /* Stop new submissions before checking hardware activity. */
+ v4l2_m2m_suspend(jpeg->master_dev->m2m_dev);
+
+ if (READ_ONCE(jpeg->hw_state) != MTK_JPEG_HW_IDLE)
+ ret = -EBUSY;
+ else
+ ret = pm_runtime_force_suspend(dev);
+ if (ret)
+ v4l2_m2m_resume(jpeg->master_dev->m2m_dev);
+
+ return ret;
+}
+
+static int mtk_jpegenc_resume(struct device *dev)
+{
+ struct mtk_jpegenc_comp_dev *jpeg = dev_get_drvdata(dev);
+ int ret;
+
+ ret = pm_runtime_force_resume(dev);
+ if (ret < 0)
+ return ret;
+
+ v4l2_m2m_resume(jpeg->master_dev->m2m_dev);
+
+ return 0;
+}
+
+static const struct dev_pm_ops mtk_jpegenc_pm_ops = {
+ SYSTEM_SLEEP_PM_OPS(mtk_jpegenc_suspend, mtk_jpegenc_resume)
+ RUNTIME_PM_OPS(mtk_jpegenc_pm_suspend, mtk_jpegenc_pm_resume, NULL)
+};
+
static struct platform_driver mtk_jpegenc_hw_driver = {
.probe = mtk_jpegenc_hw_probe,
.driver = {
.name = "mtk-jpegenc-hw",
.of_match_table = mtk_jpegenc_drv_ids,
+ .pm = pm_ptr(&mtk_jpegenc_pm_ops),
},
};
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH v20 05/15] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting
2026-11-25 6:16 ` [PATCH v20 05/15] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting Kyrie Wu
@ 2026-11-25 6:38 ` sashiko-bot
0 siblings, 0 replies; 23+ messages in thread
From: sashiko-bot @ 2026-11-25 6:38 UTC (permalink / raw)
To: Kyrie Wu, devicetree; +Cc: robh, conor+dt, media-ci
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] media: mediatek: jpeg: system suspend deadlock in
v4l2_m2m_suspend()
- [Medium] media: mediatek: jpeg: uncoordinated v4l2_m2m_resume() on
shared m2m_dev
- [Medium] media: mediatek: jpeg: race between hw_state idle and
pm_runtime_put()
--
commit ef54e8a58e87570a3e896564d7ed5ef3de2fbbc3
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: jpeg: Fix multi-core clk suspend and resume setting
This commit moves multi-core JPEG clock management into runtime PM
callbacks on the hardware component devices and adds system sleep
callbacks for the encoder and decoder component drivers.
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> index 3c22417f4e7c4..b9ba37a880b2d 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> @@ -533,13 +533,12 @@ static void mtk_jpegdec_timeout_work(struct work_struct *work)
> v4l2_m2m_buf_copy_metadata(src_buf, dst_buf);
>
> mtk_jpeg_dec_reset(cjpeg->reg_base);
> - clk_disable_unprepare(cjpeg->jdec_clk.clks->clk);
> - pm_runtime_put(cjpeg->dev);
> cjpeg->hw_state = MTK_JPEG_HW_IDLE;
> atomic_inc(&master_jpeg->hw_rdy);
> wake_up(&master_jpeg->hw_wq);
> v4l2_m2m_buf_done(src_buf, buf_state);
> mtk_jpegdec_put_buf(cjpeg);
> + pm_runtime_put(cjpeg->dev);
> }
>
> static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv)
> @@ -547,7 +546,6 @@ static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv)
> struct vb2_v4l2_buffer *src_buf, *dst_buf;
> struct mtk_jpeg_src_buf *jpeg_src_buf;
> enum vb2_buffer_state buf_state;
> - struct mtk_jpeg_ctx *ctx;
> u32 dec_irq_ret;
> u32 irq_status;
> int i;
> @@ -557,7 +555,6 @@ static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv)
>
> cancel_delayed_work(&jpeg->job_timeout_work);
>
> - ctx = jpeg->hw_param.curr_ctx;
> src_buf = jpeg->hw_param.src_buffer;
> dst_buf = jpeg->hw_param.dst_buffer;
> v4l2_m2m_buf_copy_metadata(src_buf, dst_buf);
> @@ -580,12 +577,11 @@ static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv)
> buf_state = VB2_BUF_STATE_DONE;
> v4l2_m2m_buf_done(src_buf, buf_state);
> mtk_jpegdec_put_buf(jpeg);
> - pm_runtime_put(ctx->jpeg->dev);
> - clk_disable_unprepare(jpeg->jdec_clk.clks->clk);
>
> jpeg->hw_state = MTK_JPEG_HW_IDLE;
> wake_up(&master_jpeg->hw_wq);
> atomic_inc(&master_jpeg->hw_rdy);
> + pm_runtime_put(jpeg->dev);
>
> return IRQ_HANDLED;
> }
[Severity: Medium]
Can setting hw_state = MTK_JPEG_HW_IDLE before calling pm_runtime_put()
race with mtk_jpegdec_suspend()?
CPU0 (IRQ / timeout) CPU1 (system suspend)
mtk_jpegdec_hw_irq_handler()
jpeg->hw_state = MTK_JPEG_HW_IDLE;
mtk_jpegdec_suspend()
READ_ONCE(jpeg->hw_state) == IDLE
pm_runtime_force_suspend(dev)
usage_count == 2 (> 1)
dev->power.needs_force_resume = 1
pm_runtime_put(jpeg->dev)
If mtk_jpegdec_suspend() runs between the hw_state store and
pm_runtime_put(), dev->power.usage_count is still 2 (1 from
device_prepare() plus 1 from the finishing job).
pm_runtime_force_suspend() then sees usage_count > 1, skips
pm_runtime_set_suspended(), and sets needs_force_resume, causing
pm_runtime_force_resume() to unconditionally re-enable the component
clocks on resume and leave the idle device active. The same ordering
exists in mtk_jpegenc_timeout_work() and mtk_jpegenc_hw_irq_handler().
> @@ -673,11 +669,67 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev)
> return 0;
> }
>
> +static int mtk_jpegdec_pm_suspend(struct device *dev)
> +{
> + struct mtk_jpegdec_comp_dev *jpeg = dev_get_drvdata(dev);
> +
> + clk_bulk_disable_unprepare(jpeg->jdec_clk.clk_num,
> + jpeg->jdec_clk.clks);
> +
> + return 0;
> +}
> +
> +static int mtk_jpegdec_pm_resume(struct device *dev)
> +{
> + struct mtk_jpegdec_comp_dev *jpeg = dev_get_drvdata(dev);
> +
> + return clk_bulk_prepare_enable(jpeg->jdec_clk.clk_num,
> + jpeg->jdec_clk.clks);
> +}
> +
> +static int mtk_jpegdec_suspend(struct device *dev)
> +{
> + struct mtk_jpegdec_comp_dev *jpeg = dev_get_drvdata(dev);
> + int ret;
> +
> + /* Stop new submissions before checking hardware activity. */
> + v4l2_m2m_suspend(jpeg->master_dev->m2m_dev);
[Severity: High]
Can v4l2_m2m_suspend() deadlock during system suspend when a multi-core
job is queued on jpeg->workqueue?
In multi-core mode, mtk_jpeg_probe() allocates jpeg->workqueue with
WQ_FREEZABLE, and mtk_jpeg_multicore_dec_device_run() only queues
ctx->jpeg_work onto jpeg->workqueue while TRANS_RUNNING remains set on
curr_ctx until mtk_jpegdec_worker() runs and calls v4l2_m2m_job_finish().
kworker PM suspend
mtk_jpegdec_worker() (job 1) freeze_kernel_threads()
freeze_workqueues_begin()
v4l2_m2m_job_finish()
schedule_work(&m2m_dev->job_work)
v4l2_m2m_device_run_work()
v4l2_m2m_try_run() (job 2)
curr_ctx->job_flags |= TRANS_RUNNING
queue_work(jpeg->workqueue, &ctx->jpeg_work)
(queued on frozen wq; cannot run)
dpm_suspend()
mtk_jpegdec_suspend()
v4l2_m2m_suspend()
wait_event(..., !TRANS_RUNNING)
<-- hangs forever
Because v4l2_m2m_device_run_work() runs on the non-freezable
system_percpu_wq, a worker finishing while workqueues are freezing can
schedule the next M2M job onto the already-frozen jpeg->workqueue before
v4l2_m2m_suspend() sets QUEUE_PAUSED. v4l2_m2m_suspend() then waits
uninterruptibly for TRANS_RUNNING to clear on a work item that will not
run until thaw_workqueues(). mtk_jpegenc_suspend() has the same issue.
> +
> + if (READ_ONCE(jpeg->hw_state) != MTK_JPEG_HW_IDLE)
> + ret = -EBUSY;
> + else
> + ret = pm_runtime_force_suspend(dev);
> + if (ret)
> + v4l2_m2m_resume(jpeg->master_dev->m2m_dev);
> +
> + return ret;
> +}
> +
> +static int mtk_jpegdec_resume(struct device *dev)
> +{
> + struct mtk_jpegdec_comp_dev *jpeg = dev_get_drvdata(dev);
> + int ret;
> +
> + ret = pm_runtime_force_resume(dev);
> + if (ret < 0)
> + return ret;
> +
> + v4l2_m2m_resume(jpeg->master_dev->m2m_dev);
> +
> + return 0;
> +}
[Severity: Medium]
Does calling v4l2_m2m_resume() on the shared master_dev->m2m_dev from each
component and from the parent device unpause the M2M queue while component
devices are still force-suspended?
All component devices and the parent master device share a single
master_dev->m2m_dev, where QUEUE_PAUSED is a single non-reference-counted
bit and v4l2_m2m_resume() immediately calls v4l2_m2m_try_run().
During dpm_resume(), the parent device runs mtk_jpeg_resume() before its
child component devices and calls v4l2_m2m_resume(jpeg->m2m_dev) while all
children still have runtime PM disabled by pm_runtime_force_suspend(), and
the first child component to resume does the same before its remaining
siblings have resumed. Similarly, if one child component is idle and
enters pm_runtime_force_suspend() during dpm_suspend(), and a later
sibling is busy and returns -EBUSY, its error path calls
v4l2_m2m_resume(jpeg->master_dev->m2m_dev) while the first sibling is
still force-suspended. Any job dispatched in that window selects an idle
force-suspended component, fails pm_runtime_resume_and_get() with -EACCES,
and completes user buffers with VB2_BUF_STATE_ERROR. mtk_jpegenc_suspend()
and mtk_jpegenc_resume() have the same issue.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125061618.2544386-1-kyrie.wu@mediatek.com?part=5
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH v20 06/15] media: mediatek: jpeg: fix buffer state update timing
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
` (4 preceding siblings ...)
2026-11-25 6:16 ` [PATCH v20 05/15] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:16 ` [PATCH v20 07/15] media: mediatek: jpeg: fix resolution change event handling in decoder Kyrie Wu
` (8 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
Publish destination context and frame tracking metadata only after the
decoder has selected a hardware core, resumed runtime PM, and prepared
the destination. Publish it before arming the timeout or starting hardware
so completion observes initialized state.
Restart the reverse scan of the done queue after completing each
expected frame, releasing consecutive completed frames in order.
Fixes: dedc21500334 ("media: mtk-jpegdec: add jpeg decode worker interface")
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 12 +++++-------
.../media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 1 +
.../media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 1 +
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 649b9d952..bcf8745ca 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1749,7 +1749,6 @@ retry_select:
v4l2_m2m_buf_copy_metadata(src_buf, dst_buf);
jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf);
- jpeg_dst_buf = mtk_jpeg_vb2_to_srcbuf(&dst_buf->vb2_buf);
if (mtk_jpeg_check_resolution_change(ctx,
&jpeg_src_buf->dec_param)) {
@@ -1758,11 +1757,6 @@ retry_select:
goto getbuf_fail;
}
- jpeg_src_buf->curr_ctx = ctx;
- jpeg_src_buf->frame_num = ctx->total_frame_num;
- jpeg_dst_buf->curr_ctx = ctx;
- jpeg_dst_buf->frame_num = ctx->total_frame_num;
-
mtk_jpegdec_set_hw_param(ctx, hw_id, src_buf, dst_buf);
ret = pm_runtime_resume_and_get(comp_jpeg[hw_id]->dev);
if (ret < 0) {
@@ -1783,11 +1777,15 @@ retry_select:
goto set_dst_fail;
}
+ jpeg_dst_buf = mtk_jpeg_vb2_to_srcbuf(&dst_buf->vb2_buf);
+ jpeg_dst_buf->curr_ctx = ctx;
+ jpeg_dst_buf->frame_num = ctx->total_frame_num;
+ ctx->total_frame_num++;
+
schedule_delayed_work(&comp_jpeg[hw_id]->job_timeout_work,
msecs_to_jiffies(MTK_JPEG_HW_TIMEOUT_MSEC));
spin_lock_irqsave(&comp_jpeg[hw_id]->hw_lock, flags);
- ctx->total_frame_num++;
mtk_jpeg_dec_reset(comp_jpeg[hw_id]->reg_base);
mtk_jpeg_dec_set_config(comp_jpeg[hw_id]->reg_base,
jpeg->variant->support_34bit,
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
index b9ba37a88..0ce798d35 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
@@ -513,6 +513,7 @@ static void mtk_jpegdec_put_buf(struct mtk_jpegdec_comp_dev *jpeg)
v4l2_m2m_buf_done(&tmp_dst_done_buf->b,
VB2_BUF_STATE_DONE);
ctx->last_done_frame_num++;
+ break;
}
}
}
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
index 25e1aafc4..d6ecaeec2 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
@@ -241,6 +241,7 @@ static void mtk_jpegenc_put_buf(struct mtk_jpegenc_comp_dev *jpeg)
v4l2_m2m_buf_done(&tmp_dst_done_buf->b,
VB2_BUF_STATE_DONE);
ctx->last_done_frame_num++;
+ break;
}
}
}
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH v20 07/15] media: mediatek: jpeg: fix resolution change event handling in decoder
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
` (5 preceding siblings ...)
2026-11-25 6:16 ` [PATCH v20 06/15] media: mediatek: jpeg: fix buffer state update timing Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:32 ` sashiko-bot
2026-11-25 6:16 ` [PATCH v20 08/15] media: mediatek: jpeg: fix remove buffer removal timing for multi-core Kyrie Wu
` (7 subsequent siblings)
14 siblings, 1 reply; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
Announce a source change from the decoder worker and stop processing
while the context is in MTK_JPEG_SOURCE_CHANGE. Check that state before
comparing resolutions to avoid duplicate source-change notifications.
Keep queue-format updates in CAPTURE STREAMOFF under its existing
locking instead of changing queue data asynchronously in the worker.
Fixes: dedc21500334 ("media: mtk-jpegdec: add jpeg decode worker interface")
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
---
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index bcf8745ca..199d15828 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1750,10 +1750,13 @@ retry_select:
v4l2_m2m_buf_copy_metadata(src_buf, dst_buf);
jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf);
+ if (ctx->state == MTK_JPEG_SOURCE_CHANGE)
+ goto getbuf_fail;
+
if (mtk_jpeg_check_resolution_change(ctx,
&jpeg_src_buf->dec_param)) {
- mtk_jpeg_queue_src_chg_event(ctx);
ctx->state = MTK_JPEG_SOURCE_CHANGE;
+ mtk_jpeg_queue_src_chg_event(ctx);
goto getbuf_fail;
}
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH v20 07/15] media: mediatek: jpeg: fix resolution change event handling in decoder
2026-11-25 6:16 ` [PATCH v20 07/15] media: mediatek: jpeg: fix resolution change event handling in decoder Kyrie Wu
@ 2026-11-25 6:32 ` sashiko-bot
0 siblings, 0 replies; 23+ messages in thread
From: sashiko-bot @ 2026-11-25 6:32 UTC (permalink / raw)
To: Kyrie Wu, devicetree; +Cc: robh, conor+dt, media-ci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] media: mediatek: jpeg: infinite workqueue loop in
mtk_jpegdec_worker()
--
commit c3b81e9e96516f012823565e25f860a3928a4e5b
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: jpeg: fix resolution change event handling in decoder
This commit checks whether the decoder context is already in
MTK_JPEG_SOURCE_CHANGE before checking for resolution changes in
mtk_jpegdec_worker() and reorders the state transition before queueing the
source-change event.
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> index bcf8745ca1d81..199d158285d4e 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> @@ -1750,10 +1750,13 @@ static void mtk_jpegdec_worker(struct work_struct *work)
> v4l2_m2m_buf_copy_metadata(src_buf, dst_buf);
> jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf);
>
> + if (ctx->state == MTK_JPEG_SOURCE_CHANGE)
> + goto getbuf_fail;
> +
> if (mtk_jpeg_check_resolution_change(ctx,
> &jpeg_src_buf->dec_param)) {
> - mtk_jpeg_queue_src_chg_event(ctx);
> ctx->state = MTK_JPEG_SOURCE_CHANGE;
> + mtk_jpeg_queue_src_chg_event(ctx);
> goto getbuf_fail;
> }
[Severity: High]
Does jumping to getbuf_fail while ctx->state is MTK_JPEG_SOURCE_CHANGE put
mtk_jpegdec_worker() into an unthrottled workqueue loop?
src_buf and dst_buf are only peeked here and remain on the M2M ready
queues when getbuf_fail calls v4l2_m2m_job_finish(). Unlike single-core
mtk_jpeg_dec_m2m_ops, mtk_jpeg_multicore_dec_m2m_ops does not set
.job_ready = mtk_jpeg_dec_job_ready to stop scheduling jobs when
ctx->state != MTK_JPEG_RUNNING:
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c:
static const struct v4l2_m2m_ops mtk_jpeg_multicore_dec_m2m_ops = {
.device_run = mtk_jpeg_multicore_dec_device_run,
};
static const struct v4l2_m2m_ops mtk_jpeg_dec_m2m_ops = {
.device_run = mtk_jpeg_dec_device_run,
.job_ready = mtk_jpeg_dec_job_ready,
};
v4l2_m2m_job_finish() therefore immediately re-queues the context and
re-schedules mtk_jpegdec_worker(). Because the MTK_JPEG_SOURCE_CHANGE
check runs after mtk_jpegdec_get_hw(), every iteration also claims and
releases a hardware decoder core, starving other contexts and spinning at
100% CPU until userspace issues VIDIOC_STREAMOFF.
Should mtk_jpeg_multicore_dec_m2m_ops wire up .job_ready =
mtk_jpeg_dec_job_ready?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125061618.2544386-1-kyrie.wu@mediatek.com?part=7
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH v20 08/15] media: mediatek: jpeg: fix remove buffer removal timing for multi-core
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
` (6 preceding siblings ...)
2026-11-25 6:16 ` [PATCH v20 07/15] media: mediatek: jpeg: fix resolution change event handling in decoder Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:16 ` [PATCH v20 09/15] dt-bindings: mfd: syscon: Add MT8196 JPEG SMMU compatible Kyrie Wu
` (6 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
Remove prepared source and destination buffers from the M2M ready
queues in the multi-core decoder after destination preparation succeeds
and before arming the timeout or starting hardware, matching the encoder
flow. Completion can then return buffers without leaving them linked
in a ready queue. Preparation failures keep the existing cleanup path.
Fixes: 86379bd9d399 ("media: mtk-jpeg: Fixes jpeg enc&dec worker sw flow")
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
---
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 199d15828..7e4fd36dd 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1768,9 +1768,6 @@ retry_select:
goto dec_end;
}
- v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
- v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
-
mtk_jpeg_set_dec_src(ctx, &src_buf->vb2_buf, &bs);
if (mtk_jpeg_set_dec_dst(ctx,
&jpeg_src_buf->dec_param,
@@ -1785,6 +1782,9 @@ retry_select:
jpeg_dst_buf->frame_num = ctx->total_frame_num;
ctx->total_frame_num++;
+ v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+ v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
+
schedule_delayed_work(&comp_jpeg[hw_id]->job_timeout_work,
msecs_to_jiffies(MTK_JPEG_HW_TIMEOUT_MSEC));
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH v20 09/15] dt-bindings: mfd: syscon: Add MT8196 JPEG SMMU compatible
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
` (7 preceding siblings ...)
2026-11-25 6:16 ` [PATCH v20 08/15] media: mediatek: jpeg: fix remove buffer removal timing for multi-core Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:21 ` sashiko-bot
2026-11-25 6:16 ` [PATCH v20 10/15] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible Kyrie Wu
` (5 subsequent siblings)
14 siblings, 1 reply; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
Add the MT8196 JPEG SMMU configuration compatible to the common syscon
binding. JPEG decoder and encoder cores use this shared register block
to configure their SMMU stream IDs through its GUSER_ID fields.
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
---
Documentation/devicetree/bindings/mfd/syscon.yaml | 1 +
MAINTAINERS | 1 +
2 files changed, 2 insertions(+)
diff --git a/Documentation/devicetree/bindings/mfd/syscon.yaml b/Documentation/devicetree/bindings/mfd/syscon.yaml
index 80ff0e1ca..cd22af4d4 100644
--- a/Documentation/devicetree/bindings/mfd/syscon.yaml
+++ b/Documentation/devicetree/bindings/mfd/syscon.yaml
@@ -91,6 +91,7 @@ properties:
- mediatek,mt8135-pctl-a-syscfg
- mediatek,mt8135-pctl-b-syscfg
- mediatek,mt8173-pctl-a-syscfg
+ - mediatek,mt8196-jpeg-smmu
- mediatek,mt8365-infracfg-nao
- mediatek,mt8365-syscfg
- microchip,lan966x-cpu-syscon
diff --git a/MAINTAINERS b/MAINTAINERS
index 742c4e6b2..6690f1efa 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17063,6 +17063,7 @@ F: include/dt-bindings/memory/mt*-port.h
MEDIATEK JPEG DRIVER
M: Bin Liu <bin.liu@mediatek.com>
S: Supported
+F: Documentation/devicetree/bindings/media/mediatek,mt8195-jpeg*.yaml
F: Documentation/devicetree/bindings/media/mediatek-jpeg-*.yaml
F: drivers/media/platform/mediatek/jpeg/
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH v20 09/15] dt-bindings: mfd: syscon: Add MT8196 JPEG SMMU compatible
2026-11-25 6:16 ` [PATCH v20 09/15] dt-bindings: mfd: syscon: Add MT8196 JPEG SMMU compatible Kyrie Wu
@ 2026-11-25 6:21 ` sashiko-bot
0 siblings, 0 replies; 23+ messages in thread
From: sashiko-bot @ 2026-11-25 6:21 UTC (permalink / raw)
To: Kyrie Wu, devicetree; +Cc: robh, conor+dt, media-ci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dt-bindings: mfd: syscon: unrelated and undocumented MAINTAINERS
change
--
commit c96a483b72d1a409e80e78b68c423c55f8ca87cf
Author: Kyrie Wu <kyrie.wu@mediatek.com>
dt-bindings: mfd: syscon: Add MT8196 JPEG SMMU compatible
This commit adds the mediatek,mt8196-jpeg-smmu compatible string to the
common MFD syscon devicetree binding and adds a media JPEG binding pattern
to MAINTAINERS.
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 742c4e6b291ff..6690f1efa9458 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -17063,6 +17063,7 @@ F: include/dt-bindings/memory/mt*-port.h
> MEDIATEK JPEG DRIVER
> M: Bin Liu <bin.liu@mediatek.com>
> S: Supported
> +F: Documentation/devicetree/bindings/media/mediatek,mt8195-jpeg*.yaml
> F: Documentation/devicetree/bindings/media/mediatek-jpeg-*.yaml
> F: drivers/media/platform/mediatek/jpeg/
>
[Severity: Low]
Was this MAINTAINERS entry for the media JPEG bindings meant to be in a
separate patch? The commit subject and message only describe adding
mediatek,mt8196-jpeg-smmu to Documentation/devicetree/bindings/mfd/syscon.yaml.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125061618.2544386-1-kyrie.wu@mediatek.com?part=9
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH v20 10/15] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
` (8 preceding siblings ...)
2026-11-25 6:16 ` [PATCH v20 09/15] dt-bindings: mfd: syscon: Add MT8196 JPEG SMMU compatible Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:16 ` [PATCH v20 11/15] dt-bindings: media: mediatek,jpeg: Add MT8196 decoder SMMU configuration Kyrie Wu
` (4 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu, Krzysztof Kozlowski
Compared to the previous generation IC, the MT8196 uses SMMU
instead of IOMMU and supports features such as dynamic voltage
and frequency scaling. Therefore, add "mediatek,mt8196-jpgdec"
compatible to the binding document.
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
.../bindings/media/mediatek,mt8195-jpegdec.yaml | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
index e5448c60e..28a9a9bfd 100644
--- a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
+++ b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
@@ -14,7 +14,9 @@ description:
properties:
compatible:
- const: mediatek,mt8195-jpgdec
+ enum:
+ - mediatek,mt8195-jpgdec
+ - mediatek,mt8196-jpgdec
power-domains:
maxItems: 1
@@ -44,7 +46,9 @@ patternProperties:
properties:
compatible:
- const: mediatek,mt8195-jpgdec-hw
+ enum:
+ - mediatek,mt8195-jpgdec-hw
+ - mediatek,mt8196-jpgdec-hw
reg:
maxItems: 1
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH v20 11/15] dt-bindings: media: mediatek,jpeg: Add MT8196 decoder SMMU configuration
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
` (9 preceding siblings ...)
2026-11-25 6:16 ` [PATCH v20 10/15] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:25 ` sashiko-bot
2026-11-25 6:16 ` [PATCH v20 12/15] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc compatible Kyrie Wu
` (3 subsequent siblings)
14 siblings, 1 reply; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
Describe the mediatek,smmu-config phandle to the MT8196 JPEG SMMU
configuration syscon used to program a decoder core's GUSER_ID fields.
Require the property for MT8196 decoder cores.
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
---
.../bindings/media/mediatek,mt8195-jpegdec.yaml | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
index 28a9a9bfd..b1dccc3c8 100644
--- a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
+++ b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
@@ -73,6 +73,22 @@ patternProperties:
power-domains:
maxItems: 1
+ mediatek,smmu-config:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ Phandle to the MT8196 JPEG SMMU configuration syscon used to
+ program this decoder's GUSER_ID fields.
+
+ allOf:
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: mediatek,mt8196-jpgdec-hw
+ then:
+ required:
+ - mediatek,smmu-config
+
required:
- compatible
- reg
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH v20 11/15] dt-bindings: media: mediatek,jpeg: Add MT8196 decoder SMMU configuration
2026-11-25 6:16 ` [PATCH v20 11/15] dt-bindings: media: mediatek,jpeg: Add MT8196 decoder SMMU configuration Kyrie Wu
@ 2026-11-25 6:25 ` sashiko-bot
0 siblings, 0 replies; 23+ messages in thread
From: sashiko-bot @ 2026-11-25 6:25 UTC (permalink / raw)
To: Kyrie Wu, devicetree; +Cc: robh, conor+dt, media-ci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dt-bindings: media: split MT8196 decoder binding adds required
property late
--
commit 8fc700b55092f5f90e77cee812b3c4702a9eab2b
Author: Kyrie Wu <kyrie.wu@mediatek.com>
dt-bindings: media: mediatek,jpeg: Add MT8196 decoder SMMU configuration
This commit documents the mediatek,smmu-config phandle property and
requires it for mediatek,mt8196-jpgdec-hw decoder child nodes.
> diff --git a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
> index 28a9a9bfdbf88..b1dccc3c899c5 100644
> --- a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
> +++ b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
> @@ -73,6 +73,22 @@ patternProperties:
> power-domains:
> maxItems: 1
>
> + mediatek,smmu-config:
> + $ref: /schemas/types.yaml#/definitions/phandle
> + description:
> + Phandle to the MT8196 JPEG SMMU configuration syscon used to
> + program this decoder's GUSER_ID fields.
> +
> + allOf:
> + - if:
> + properties:
> + compatible:
> + contains:
> + const: mediatek,mt8196-jpgdec-hw
> + then:
> + required:
> + - mediatek,smmu-config
[Severity: Low]
As reported by Krzysztof Kozlowski on v18 [1], should mediatek,smmu-config
and its required constraint be folded into the earlier commit "media:
dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible" rather
than introducing an incomplete mediatek,mt8196-jpgdec-hw binding and
immediately adding a required property to it in a follow-up patch?
[1] https://lore.kernel.org/r/20261012-determined-magenta-camel-ff2ca8@quoll
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125061618.2544386-1-kyrie.wu@mediatek.com?part=11
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH v20 12/15] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc compatible
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
` (10 preceding siblings ...)
2026-11-25 6:16 ` [PATCH v20 11/15] dt-bindings: media: mediatek,jpeg: Add MT8196 decoder SMMU configuration Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:16 ` [PATCH v20 13/15] dt-bindings: media: mediatek,jpeg: Add MT8196 encoder SMMU configuration Kyrie Wu
` (2 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu, Krzysztof Kozlowski
Compared to the previous generation IC, the MT8196 uses SMMU
instead of IOMMU and supports features such as dynamic voltage
and frequency scaling. Therefore, add "mediatek,mt8196-jpgenc"
compatible to the binding document.
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
.../bindings/media/mediatek,mt8195-jpegenc.yaml | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml
index 596186497..e2d772ea0 100644
--- a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml
+++ b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml
@@ -14,7 +14,9 @@ description:
properties:
compatible:
- const: mediatek,mt8195-jpgenc
+ enum:
+ - mediatek,mt8195-jpgenc
+ - mediatek,mt8196-jpgenc
power-domains:
maxItems: 1
@@ -44,7 +46,9 @@ patternProperties:
properties:
compatible:
- const: mediatek,mt8195-jpgenc-hw
+ enum:
+ - mediatek,mt8195-jpgenc-hw
+ - mediatek,mt8196-jpgenc-hw
reg:
maxItems: 1
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH v20 13/15] dt-bindings: media: mediatek,jpeg: Add MT8196 encoder SMMU configuration
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
` (11 preceding siblings ...)
2026-11-25 6:16 ` [PATCH v20 12/15] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc compatible Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:16 ` [PATCH v20 14/15] media: mediatek: jpeg: add jpeg compatible Kyrie Wu
2026-11-25 6:16 ` [PATCH v20 15/15] media: mediatek: jpeg: add jpeg smmu sid setting Kyrie Wu
14 siblings, 0 replies; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
Describe the mediatek,smmu-config phandle to the MT8196 JPEG SMMU
configuration syscon used to program an encoder core's GUSER_ID fields.
Require the property for MT8196 encoder cores.
Document SMMU stream IDs for MT8196 in the parent and child iommus
descriptions while retaining the MT8195 hardware master-port description.
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
---
.../media/mediatek,mt8195-jpegenc.yaml | 31 ++++++++++++++++---
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml
index e2d772ea0..46597003e 100644
--- a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml
+++ b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml
@@ -24,9 +24,11 @@ properties:
iommus:
maxItems: 4
description:
- Points to the respective IOMMU block with master port as argument, see
- Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml for details.
- Ports are according to the HW.
+ Phandles to the respective IOMMU blocks. For MT8195, the argument is
+ a hardware master port; see
+ Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml.
+ For MT8196, the argument is an SMMU stream ID; see
+ Documentation/devicetree/bindings/iommu/arm,smmu-v3.yaml.
"#address-cells":
const: 2
@@ -57,8 +59,11 @@ patternProperties:
minItems: 1
maxItems: 32
description:
- List of the hardware port in respective IOMMU block for current Socs.
- Refer to bindings/iommu/mediatek,iommu.yaml.
+ Phandles to the respective IOMMU blocks. For MT8195, the argument is
+ a hardware master port; see
+ Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml.
+ For MT8196, the argument is an SMMU stream ID; see
+ Documentation/devicetree/bindings/iommu/arm,smmu-v3.yaml.
interrupts:
maxItems: 1
@@ -73,6 +78,22 @@ patternProperties:
power-domains:
maxItems: 1
+ mediatek,smmu-config:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ Phandle to the MT8196 JPEG SMMU configuration syscon used to
+ program this encoder's GUSER_ID fields.
+
+ allOf:
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: mediatek,mt8196-jpgenc-hw
+ then:
+ required:
+ - mediatek,smmu-config
+
required:
- compatible
- reg
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH v20 14/15] media: mediatek: jpeg: add jpeg compatible
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
` (12 preceding siblings ...)
2026-11-25 6:16 ` [PATCH v20 13/15] dt-bindings: media: mediatek,jpeg: Add MT8196 encoder SMMU configuration Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:44 ` sashiko-bot
2026-11-25 6:16 ` [PATCH v20 15/15] media: mediatek: jpeg: add jpeg smmu sid setting Kyrie Wu
14 siblings, 1 reply; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
Add jpeg dec and enc compatible for mt8196
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
.../platform/mediatek/jpeg/mtk_jpeg_core.c | 36 +++++++++++++++++++
.../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 3 ++
.../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 3 ++
3 files changed, 42 insertions(+)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 7e4fd36dd..31a0fbc07 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1971,6 +1971,20 @@ static struct mtk_jpeg_variant mtk8195_jpegenc_drvdata = {
.jpeg_worker = mtk_jpegenc_worker,
};
+static struct mtk_jpeg_variant mtk8196_jpegenc_drvdata = {
+ .formats = mtk_jpeg_enc_formats,
+ .num_formats = MTK_JPEG_ENC_NUM_FORMATS,
+ .qops = &mtk_jpeg_enc_qops,
+ .m2m_ops = &mtk_jpeg_multicore_enc_m2m_ops,
+ .dev_name = "mtk-jpeg-enc",
+ .ioctl_ops = &mtk_jpeg_enc_ioctl_ops,
+ .out_q_default_fourcc = V4L2_PIX_FMT_YUYV,
+ .cap_q_default_fourcc = V4L2_PIX_FMT_JPEG,
+ .multi_core = true,
+ .jpeg_worker = mtk_jpegenc_worker,
+ .support_34bit = true,
+};
+
static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = {
.formats = mtk_jpeg_dec_formats,
.num_formats = MTK_JPEG_DEC_NUM_FORMATS,
@@ -1984,6 +1998,20 @@ static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = {
.jpeg_worker = mtk_jpegdec_worker,
};
+static const struct mtk_jpeg_variant mtk8196_jpegdec_drvdata = {
+ .formats = mtk_jpeg_dec_formats,
+ .num_formats = MTK_JPEG_DEC_NUM_FORMATS,
+ .qops = &mtk_jpeg_dec_qops,
+ .m2m_ops = &mtk_jpeg_multicore_dec_m2m_ops,
+ .dev_name = "mtk-jpeg-dec",
+ .ioctl_ops = &mtk_jpeg_dec_ioctl_ops,
+ .out_q_default_fourcc = V4L2_PIX_FMT_JPEG,
+ .cap_q_default_fourcc = V4L2_PIX_FMT_YUV420M,
+ .multi_core = true,
+ .jpeg_worker = mtk_jpegdec_worker,
+ .support_34bit = true,
+};
+
static const struct of_device_id mtk_jpeg_match[] = {
{
.compatible = "mediatek,mt8173-jpgdec",
@@ -2013,6 +2041,14 @@ static const struct of_device_id mtk_jpeg_match[] = {
.compatible = "mediatek,mt8195-jpgdec",
.data = &mtk8195_jpegdec_drvdata,
},
+ {
+ .compatible = "mediatek,mt8196-jpgenc",
+ .data = &mtk8196_jpegenc_drvdata,
+ },
+ {
+ .compatible = "mediatek,mt8196-jpgdec",
+ .data = &mtk8196_jpegdec_drvdata,
+ },
{},
};
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
index 0ce798d35..6b636ec63 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
@@ -45,6 +45,9 @@ static const struct of_device_id mtk_jpegdec_hw_ids[] = {
{
.compatible = "mediatek,mt8195-jpgdec-hw",
},
+ {
+ .compatible = "mediatek,mt8196-jpgdec-hw",
+ },
{},
};
MODULE_DEVICE_TABLE(of, mtk_jpegdec_hw_ids);
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
index d6ecaeec2..c2de272d7 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
@@ -51,6 +51,9 @@ static const struct of_device_id mtk_jpegenc_drv_ids[] = {
{
.compatible = "mediatek,mt8195-jpgenc-hw",
},
+ {
+ .compatible = "mediatek,mt8196-jpgenc-hw",
+ },
{},
};
MODULE_DEVICE_TABLE(of, mtk_jpegenc_drv_ids);
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH v20 14/15] media: mediatek: jpeg: add jpeg compatible
2026-11-25 6:16 ` [PATCH v20 14/15] media: mediatek: jpeg: add jpeg compatible Kyrie Wu
@ 2026-11-25 6:44 ` sashiko-bot
0 siblings, 0 replies; 23+ messages in thread
From: sashiko-bot @ 2026-11-25 6:44 UTC (permalink / raw)
To: Kyrie Wu, devicetree; +Cc: robh, conor+dt, media-ci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] media: mediatek: jpeg: Kconfig requires MTK_IOMMU and MTK_SMI on
MT8196
--
commit 98d3cc1b26efcb2a1ab3f4c6f3c40747fa7aac4f
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: jpeg: add jpeg compatible
This commit adds MT8196 compatible strings and variant driver data for the
MediaTek JPEG encoder and decoder.
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> index 7e4fd36dde01d..31a0fbc0769b4 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
[ ... ]
> @@ -2013,6 +2041,14 @@ static const struct of_device_id mtk_jpeg_match[] = {
> .compatible = "mediatek,mt8195-jpgdec",
> .data = &mtk8195_jpegdec_drvdata,
> },
> + {
> + .compatible = "mediatek,mt8196-jpgenc",
> + .data = &mtk8196_jpegenc_drvdata,
> + },
> + {
> + .compatible = "mediatek,mt8196-jpgdec",
> + .data = &mtk8196_jpegdec_drvdata,
> + },
> {},
> };
[Severity: Low]
Can VIDEO_MEDIATEK_JPEG be enabled on an MT8196 kernel configuration that
uses ARM_SMMU_V3 without enabling MTK_IOMMU or COMPILE_TEST?
drivers/media/platform/mediatek/jpeg/Kconfig:
depends on MTK_IOMMU_V1 || MTK_IOMMU || COMPILE_TEST
...
depends on MTK_SMI || (COMPILE_TEST && MTK_SMI=n)
MT8196 uses ARM SMMUv3 rather than MTK_IOMMU, and MTK_SMI has no prompt
when COMPILE_TEST=n and is only selected by MTK_IOMMU and MTK_IOMMU_V1, so
the driver cannot be selected on an MT8196-only build unless those
dependencies are updated.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125061618.2544386-1-kyrie.wu@mediatek.com?part=14
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH v20 15/15] media: mediatek: jpeg: add jpeg smmu sid setting
2026-11-25 6:16 [PATCH v20 00/15] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
` (13 preceding siblings ...)
2026-11-25 6:16 ` [PATCH v20 14/15] media: mediatek: jpeg: add jpeg compatible Kyrie Wu
@ 2026-11-25 6:16 ` Kyrie Wu
2026-11-25 6:38 ` sashiko-bot
14 siblings, 1 reply; 23+ messages in thread
From: Kyrie Wu @ 2026-11-25 6:16 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Bin Liu, kyrie wu, Hans Verkuil, irui wang, Nicolas Dufresne,
linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: Kyrie Wu
Configure the JPEG decoder and encoder SMMU stream IDs through the
dedicated MT8196 JPEG SMMU configuration syscon.
Complete failure-prone SMMU initialization before reserving hw_index
and publishing child pointers and register bases. Failed or deferred
probes then leave parent bookkeeping unchanged.
Signed-off-by: Kyrie Wu <kyrie.wu@mediatek.com>
---
.../platform/mediatek/jpeg/mtk_jpeg_core.c | 29 +++++++++++++++++++
.../platform/mediatek/jpeg/mtk_jpeg_core.h | 15 ++++++++++
.../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 26 ++++++++++++++++-
.../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 26 ++++++++++++++++-
4 files changed, 94 insertions(+), 2 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 31a0fbc07..5d3242a1c 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -15,6 +15,7 @@
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <media/v4l2-event.h>
@@ -1610,6 +1611,22 @@ static irqreturn_t mtk_jpeg_enc_done(struct mtk_jpeg_dev *jpeg)
return IRQ_HANDLED;
}
+static void mtk_jpeg_set_smmu_sid(struct regmap *smmu_regmap, unsigned int sid)
+{
+ if (sid == JPG_REG_GUSER_ID_DEC_SID)
+ regmap_update_bits(smmu_regmap, JPEG_DEC_SMMU_SID,
+ JPG_REG_GUSER_ID_MASK <<
+ JPG_REG_DEC_GUSER_ID_SHIFT,
+ JPG_REG_GUSER_ID_DEC_SID <<
+ JPG_REG_DEC_GUSER_ID_SHIFT);
+ else
+ regmap_update_bits(smmu_regmap, JPEG_ENC_SMMU_SID,
+ JPG_REG_GUSER_ID_MASK <<
+ JPG_REG_ENC_GUSER_ID_SHIFT,
+ JPG_REG_GUSER_ID_ENC_SID <<
+ JPG_REG_ENC_GUSER_ID_SHIFT);
+}
+
static void mtk_jpegenc_worker(struct work_struct *work)
{
struct mtk_jpegenc_comp_dev *comp_jpeg[MTK_JPEGENC_HW_MAX];
@@ -1674,6 +1691,11 @@ retry_select:
jpeg_dst_buf->frame_num = ctx->total_frame_num;
ctx->total_frame_num++;
mtk_jpeg_enc_reset(comp_jpeg[hw_id]->reg_base);
+
+ if (jpeg->variant->support_smmu && comp_jpeg[hw_id]->smmu_regmap)
+ mtk_jpeg_set_smmu_sid(comp_jpeg[hw_id]->smmu_regmap,
+ JPG_REG_GUSER_ID_ENC_SID);
+
mtk_jpeg_set_enc_dst(ctx,
comp_jpeg[hw_id]->reg_base,
&dst_buf->vb2_buf);
@@ -1790,6 +1812,11 @@ retry_select:
spin_lock_irqsave(&comp_jpeg[hw_id]->hw_lock, flags);
mtk_jpeg_dec_reset(comp_jpeg[hw_id]->reg_base);
+
+ if (jpeg->variant->support_smmu && comp_jpeg[hw_id]->smmu_regmap)
+ mtk_jpeg_set_smmu_sid(comp_jpeg[hw_id]->smmu_regmap,
+ JPG_REG_GUSER_ID_DEC_SID);
+
mtk_jpeg_dec_set_config(comp_jpeg[hw_id]->reg_base,
jpeg->variant->support_34bit,
&jpeg_src_buf->dec_param,
@@ -1983,6 +2010,7 @@ static struct mtk_jpeg_variant mtk8196_jpegenc_drvdata = {
.multi_core = true,
.jpeg_worker = mtk_jpegenc_worker,
.support_34bit = true,
+ .support_smmu = true,
};
static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = {
@@ -2010,6 +2038,7 @@ static const struct mtk_jpeg_variant mtk8196_jpegdec_drvdata = {
.multi_core = true,
.jpeg_worker = mtk_jpegdec_worker,
.support_34bit = true,
+ .support_smmu = true,
};
static const struct of_device_id mtk_jpeg_match[] = {
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
index 148fd4175..186cd1862 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
@@ -11,6 +11,7 @@
#include <linux/clk.h>
#include <linux/interrupt.h>
+#include <linux/mfd/syscon.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/v4l2-fh.h>
@@ -34,6 +35,14 @@
#define MTK_JPEG_MAX_EXIF_SIZE (64 * 1024)
+#define JPEG_DEC_SMMU_SID 0
+#define JPEG_ENC_SMMU_SID 0
+#define JPG_REG_GUSER_ID_MASK 0x7
+#define JPG_REG_GUSER_ID_DEC_SID 0x4
+#define JPG_REG_GUSER_ID_ENC_SID 0x5
+#define JPG_REG_DEC_GUSER_ID_SHIFT 8
+#define JPG_REG_ENC_GUSER_ID_SHIFT 4
+
#define MTK_JPEG_ADDR_MASK GENMASK(1, 0)
/**
@@ -65,6 +74,7 @@ enum mtk_jpeg_ctx_state {
* @multi_core: mark jpeg hw is multi_core or not
* @jpeg_worker: jpeg dec or enc worker
* @support_34bit: flag to check support for 34-bit DMA address
+ * @support_smmu: flag to check if support smmu
*/
struct mtk_jpeg_variant {
struct clk_bulk_data *clks;
@@ -82,6 +92,7 @@ struct mtk_jpeg_variant {
bool multi_core;
void (*jpeg_worker)(struct work_struct *work);
bool support_34bit;
+ bool support_smmu;
};
struct mtk_jpeg_src_buf {
@@ -150,6 +161,7 @@ struct mtk_jpegdec_clk {
* @hw_param: jpeg encode hw parameters
* @hw_state: record hw state
* @hw_lock: spinlock protecting the hw device resource
+ * @smmu_regmap: SMMU registers mapping
*/
struct mtk_jpegenc_comp_dev {
struct device *dev;
@@ -163,6 +175,7 @@ struct mtk_jpegenc_comp_dev {
enum mtk_jpeg_hw_state hw_state;
/* spinlock protecting the hw device resource */
spinlock_t hw_lock;
+ struct regmap *smmu_regmap;
};
/**
@@ -177,6 +190,7 @@ struct mtk_jpegenc_comp_dev {
* @hw_param: jpeg decode hw parameters
* @hw_state: record hw state
* @hw_lock: spinlock protecting hw
+ * @smmu_regmap: SMMU registers mapping
*/
struct mtk_jpegdec_comp_dev {
struct device *dev;
@@ -190,6 +204,7 @@ struct mtk_jpegdec_comp_dev {
enum mtk_jpeg_hw_state hw_state;
/* spinlock protecting the hw device resource */
spinlock_t hw_lock;
+ struct regmap *smmu_regmap;
};
/**
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
index 6b636ec63..508ed4ff5 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
@@ -613,6 +613,25 @@ static int mtk_jpegdec_hw_init_irq(struct mtk_jpegdec_comp_dev *dev)
return 0;
}
+static int mtk_jpegdec_smmu_init(struct mtk_jpegdec_comp_dev *dev)
+{
+ struct mtk_jpeg_dev *master_dev = dev->master_dev;
+
+ if (!master_dev->variant->support_smmu)
+ return 0;
+
+ dev->smmu_regmap =
+ syscon_regmap_lookup_by_phandle(dev->plat_dev->dev.of_node,
+ "mediatek,smmu-config");
+ if (IS_ERR(dev->smmu_regmap)) {
+ return dev_err_probe(dev->dev, PTR_ERR(dev->smmu_regmap),
+ "mmap smmu_base failed(%pe)\n",
+ dev->smmu_regmap);
+ }
+
+ return 0;
+}
+
static int mtk_jpegdec_hw_probe(struct platform_device *pdev)
{
struct mtk_jpegdec_clk *jpegdec_clk;
@@ -660,10 +679,15 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, ret,
"Failed to register JPEGDEC irq handler.\n");
+ dev->master_dev = master_dev;
+
+ ret = mtk_jpegdec_smmu_init(dev);
+ if (ret)
+ return ret;
+
i = atomic_add_return(1, &master_dev->hw_index) - 1;
master_dev->dec_hw_dev[i] = dev;
master_dev->reg_decbase[i] = dev->reg_base;
- dev->master_dev = master_dev;
platform_set_drvdata(pdev, dev);
pm_runtime_enable(&pdev->dev);
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
index c2de272d7..8830480a4 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
@@ -338,6 +338,25 @@ static int mtk_jpegenc_hw_init_irq(struct mtk_jpegenc_comp_dev *dev)
return 0;
}
+static int mtk_jpegenc_smmu_init(struct mtk_jpegenc_comp_dev *dev)
+{
+ struct mtk_jpeg_dev *master_dev = dev->master_dev;
+
+ if (!master_dev->variant->support_smmu)
+ return 0;
+
+ dev->smmu_regmap =
+ syscon_regmap_lookup_by_phandle(dev->plat_dev->dev.of_node,
+ "mediatek,smmu-config");
+ if (IS_ERR(dev->smmu_regmap)) {
+ return dev_err_probe(dev->dev, PTR_ERR(dev->smmu_regmap),
+ "mmap smmu_base failed(%pe)\n",
+ dev->smmu_regmap);
+ }
+
+ return 0;
+}
+
static int mtk_jpegenc_hw_probe(struct platform_device *pdev)
{
struct mtk_jpegenc_clk *jpegenc_clk;
@@ -383,10 +402,15 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev)
if (ret)
return ret;
+ dev->master_dev = master_dev;
+
+ ret = mtk_jpegenc_smmu_init(dev);
+ if (ret)
+ return ret;
+
i = atomic_add_return(1, &master_dev->hw_index) - 1;
master_dev->enc_hw_dev[i] = dev;
master_dev->reg_encbase[i] = dev->reg_base;
- dev->master_dev = master_dev;
platform_set_drvdata(pdev, dev);
pm_runtime_enable(&pdev->dev);
--
2.51.0.windows.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* Re: [PATCH v20 15/15] media: mediatek: jpeg: add jpeg smmu sid setting
2026-11-25 6:16 ` [PATCH v20 15/15] media: mediatek: jpeg: add jpeg smmu sid setting Kyrie Wu
@ 2026-11-25 6:38 ` sashiko-bot
0 siblings, 0 replies; 23+ messages in thread
From: sashiko-bot @ 2026-11-25 6:38 UTC (permalink / raw)
To: Kyrie Wu, devicetree; +Cc: robh, conor+dt, media-ci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] media: mediatek: jpeg: broken parent bookkeeping on child probe
failure
--
commit 176ed455ed4a414badd5df2dbced78dc780e59ed
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: jpeg: add jpeg smmu sid setting
This commit configures the MT8196 JPEG decoder and encoder SMMU stream IDs
via a syscon regmap and moves SMMU initialization ahead of reserving
hw_index in the child hardware probe paths.
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> index 6b636ec63434a..508ed4ff53695 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> @@ -613,6 +613,25 @@ static int mtk_jpegdec_hw_init_irq(struct mtk_jpegdec_comp_dev *dev)
> return 0;
> }
>
> +static int mtk_jpegdec_smmu_init(struct mtk_jpegdec_comp_dev *dev)
> +{
> + struct mtk_jpeg_dev *master_dev = dev->master_dev;
> +
> + if (!master_dev->variant->support_smmu)
> + return 0;
> +
> + dev->smmu_regmap =
> + syscon_regmap_lookup_by_phandle(dev->plat_dev->dev.of_node,
> + "mediatek,smmu-config");
> + if (IS_ERR(dev->smmu_regmap)) {
> + return dev_err_probe(dev->dev, PTR_ERR(dev->smmu_regmap),
> + "mmap smmu_base failed(%pe)\n",
> + dev->smmu_regmap);
> + }
> +
> + return 0;
> +}
> +
> static int mtk_jpegdec_hw_probe(struct platform_device *pdev)
> {
> struct mtk_jpegdec_clk *jpegdec_clk;
> @@ -660,10 +679,15 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev)
> return dev_err_probe(&pdev->dev, ret,
> "Failed to register JPEGDEC irq handler.\n");
>
> + dev->master_dev = master_dev;
> +
> + ret = mtk_jpegdec_smmu_init(dev);
> + if (ret)
> + return ret;
> +
> i = atomic_add_return(1, &master_dev->hw_index) - 1;
> master_dev->dec_hw_dev[i] = dev;
> master_dev->reg_decbase[i] = dev->reg_base;
> - dev->master_dev = master_dev;
>
> platform_set_drvdata(pdev, dev);
> pm_runtime_enable(&pdev->dev);
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
> index c2de272d71a34..8830480a4391e 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
[ ... ]
> @@ -383,10 +402,15 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev)
> if (ret)
> return ret;
>
> + dev->master_dev = master_dev;
> +
> + ret = mtk_jpegenc_smmu_init(dev);
> + if (ret)
> + return ret;
> +
> i = atomic_add_return(1, &master_dev->hw_index) - 1;
> master_dev->enc_hw_dev[i] = dev;
> master_dev->reg_encbase[i] = dev->reg_base;
> - dev->master_dev = master_dev;
>
> platform_set_drvdata(pdev, dev);
> pm_runtime_enable(&pdev->dev);
[Severity: High]
Can a failed or deferred child probe in mtk_jpegdec_smmu_init() or
mtk_jpegenc_smmu_init() leave master_dev->dec_hw_dev[] or
master_dev->enc_hw_dev[] with NULL entries and cause a NULL pointer
dereference when jobs are queued?
In mtk_jpeg_probe(), the parent sets jpeg->max_hw_count to the total number
of DT child nodes and registers the V4L2 video device regardless of whether
every child core finished probing:
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c:mtk_jpeg_probe() {
...
ret = devm_of_platform_populate(&pdev->dev);
...
for_each_child_of_node(pdev->dev.of_node, child)
num_child++;
...
jpeg->max_hw_count = num_child;
atomic_set(&jpeg->hw_index, 0);
...
}
When a child probe fails or returns -EPROBE_DEFER before incrementing
master_dev->hw_index, its slot in dec_hw_dev[] or enc_hw_dev[] remains NULL.
mtk_jpegdec_worker() and mtk_jpegenc_worker() call mtk_jpegdec_get_hw() and
mtk_jpegenc_get_hw() before waiting on jpeg->hw_rdy, and both functions loop
up to jpeg->max_hw_count and dereference comp_jpeg->hw_state without a NULL
check:
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c:mtk_jpegdec_get_hw() {
...
for (i = 0; i < jpeg->max_hw_count; i++) {
comp_jpeg = jpeg->dec_hw_dev[i];
if (comp_jpeg->hw_state == MTK_JPEG_HW_IDLE) {
...
}
In addition, because mtk_jpeg_probe() calls devm_of_platform_populate()
before atomic_set(&jpeg->hw_index, 0), if one child probes synchronously
during devm_of_platform_populate() (recording slot 0) and a second child
defers in mtk_jpegdec_smmu_init() or mtk_jpegenc_smmu_init(),
mtk_jpeg_probe() resets hw_index back to 0; when the deferred child later
probes, it claims slot 0 again, overwriting dec_hw_dev[0] or enc_hw_dev[0]
and leaving slot 1 permanently NULL.
The workers also snapshot dec_hw_dev[] and enc_hw_dev[] into a local
comp_jpeg[] array before the retry_select wait loop, and the child probes
publish dec_hw_dev[i] and enc_hw_dev[i] before calling
platform_set_drvdata() and pm_runtime_enable(), so a worker racing with a
late-probing child can dereference a stale NULL comp_jpeg[hw_id] snapshot or
call pm_runtime_resume_and_get() before the child's drvdata is set.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125061618.2544386-1-kyrie.wu@mediatek.com?part=15
^ permalink raw reply [flat|nested] 23+ messages in thread