media: mediatek: jpeg: add MT8196 JPEG support
Subsystems (4)
v19 cover media: mediatek: jpeg: add MT8196 JPEG support
From: Kyrie Wu (吴晗) <[email protected]>
This series have the follow changing:
Firstly fix some bugs, including resolution change handleing, stop streaming sw flow, fix buffer layout and clock setting to support multi-hw jpeg working and others.
Secondly add mt8196 jpegdec and jpegenc compatible to support MT8196 kernel driver.
Lastly, Add smmu setting to support smmu and iommu at the same time.
Historical testing reported for v18 (not rerun for this revision):
This series has been tested with MT8196 tast test. Encoding and decoding worked for this chip.
Patches 1 fix jpeg hw count setting to support different chips. Patches 2 fix jpeg buffer payload setting to handle buffer size bug while resolution changed.
Patches 3 fix jpeg dst buffer layout.
Patches 4 fix multi-core stop streaming flow
Patches 5 fix multi-core clk suspend/resume setting
Patches 6 fix buffer state update timing
Patches 7 fix decoding resolution change operation
Patches 8 fix remove buffer operation
Patch 9 adds the shared MT8196 JPEG SMMU configuration syscon binding. Patches 10-11 add complete decoder and encoder bindings for MT8196. Patch 12 adds the driver compatible strings for MT8196.
Patch 13 adds jpeg smmu sid setting.
---
Changes compared with v18:
--Rebased on mainline 23c62304dde29abe92013d85910d03a77dada35d. --Initialize hw_rdy before populating children to preserve probe counts. --Drain ready queues before waiting for in-flight buffers at STREAMOFF. --Reject component suspend with -EBUSY while hardware is active; restore
M2M scheduling on failure and use pm_ptr() for component PM operations.
--Publish decoder completion metadata before arming the timeout. --Keep queue-format updates under CAPTURE STREAMOFF locking and check
SOURCE_CHANGE state before comparing resolutions.
--Unlink prepared buffers before arming timeout or starting hardware. --Introduce the shared SMMU schema before complete MT8196 decoder and
encoder bindings, including their required smmu-config phandles.
--Clarify MT8196 SMMU stream IDs in encoder iommus descriptions and use
the soc binding prefix for the shared SMMU schema patch.
--Complete SMMU initialization before allocating a child index and
publishing child pointers, preserving parent state on probe failure.
--Update changed descriptions and remove the agreed Reviewed-by tags
on patches requiring renewed review.
Changes compared with v17:
--Keep suspend/resume callbacks and clock ownership on multi-hw component
devices. Leave single-hw callbacks on the master, and wait for the active job before disabling component clocks.
--Add a standalone DT binding patch for mediatek,smmu-config and the
dedicated MT8196 JPEG SMMU configuration syscon at 0x38d0000.
Changes compared with v16:
--Rebased on top of the latest media tree
Changes compared with v15:
--Set max_hw_count from the DT child count and update hw_rdy from child hardware probes in patch 1. --Fix patch 2 commit message wording per review.
--Rework patch 6 commit message per review.
--Remove redundant devm_clk_bulk_get() calls in patch 5 per review comments.
--Use %pe to print smmu_regmap error pointer in patch 12 to fix media-ci/static warnings.
Changes compared with v14:
--Rebased on top of the latest media tree
Changes compared with v13:
--Rebased on top of the latest media tree
Changes compared with v12:
--Rebased on top of the latest media tree
--fix kernel rebot build warnings in patch 5
Changes compared with v11:
--Rebased on top of the latest media tree --Some modifications for patch v11's review comments. --add reviewer to commit messages
Changes compared with v10:
--Rebased on top of the latest media tree
--add reviewer to commit messages
Changes compared with v9:
--Rebased on top of the latest media tree
Changes compared with v8:
--Rebased on top of the latest media tree
Changes compared with v7:
--Rebased on top of the latest media tree
Changes compared with v6:
--Rebased on top of the latest media tree
Changes compared with v5:
--reorder the patches set.
--fix commit message of patch 1-8.
Changes compared with v4:
--fix kernel robot build errors for patch 4.
--add reviewer for patch 1 and patch 2.
Changes compared with v3:
--change patch subject of jpeg encoder and decoder compatible.
Changes compared with v2:
--refactor smmu sid setting function interface --Some modifications for patch v2's review comments.
Changes compared with v1:
--refine jpeg dt-bindings for MT8196 --optimize software code to manage jpeg HW count --refactor smmu sid setting function interface --Some modifications for patch v1's review comments.
Kyrie Wu (13):
media: mediatek: jpeg: fix jpeg cores' amounts setting
media: mediatek: jpeg: fix jpeg buffer payload size setting
media: mediatek: jpeg: fix buffer structure size and layout
media: mediatek: jpeg: Fix buffer completion on multi-core streaming
stop
media: mediatek: jpeg: Fix multi-core clk suspend and resume setting
media: mediatek: jpeg: fix buffer state update timing
media: mediatek: jpeg: fix resolution change event handling in decoder
media: mediatek: jpeg: fix remove buffer removal timing for multi-core
dt-bindings: soc: mediatek: Add MT8196 JPEG SMMU
media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec
compatible
media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc
compatible
media: mediatek: jpeg: add jpeg compatible
media: mediatek: jpeg: add jpeg smmu sid setting
.../media/mediatek,mt8195-jpegdec.yaml | 24 ++- .../media/mediatek,mt8195-jpegenc.yaml | 39 ++++- .../mediatek/mediatek,mt8196-jpeg-smmu.yaml | 41 +++++ MAINTAINERS | 2 + .../platform/mediatek/jpeg/mtk_jpeg_core.c | 161 +++++++++++++----- .../platform/mediatek/jpeg/mtk_jpeg_core.h | 19 ++- .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 96 ++++++++++- .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 94 +++++++++- 8 files changed, 410 insertions(+), 66 deletions(-) create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-jpeg-smmu.yaml
base-commit: 23c62304dde29abe92013d85910d03a77dada35d
Signature · 1 line
2.51.0.windows.2
PATCH v19 1/13 media: mediatek: jpeg: fix jpeg cores' amounts setting
Different ICs have different amounts of cores,
use a variable to set the cores' amounts.
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 11 ++++++----- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h | 2 ++ .../media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 2 ++ .../media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 2 ++ 4 files changed, 12 insertions(+), 5 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +6 -5
@@ -1302,6 +1302,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 +1326,7 @@ 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); + jpeg->max_hw_count = num_child;atomic_set (&jpeg->hw_index,0 ); jpeg->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
@@ -1462,7 +1463,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 +1510,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 +1593,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 +1689,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 ;
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +2 -0
@@ -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; };/**
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +2 -0
@@ -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 ; }
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +2 -0
@@ -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 ; }
Signature · 1 line
2.51.0.windows.2
[email protected]
AI reviewRe: [PATCH v19 01/13] media: mediatek: jpeg: fix jpeg cores' amounts setting
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] media: mediatek: jpeg: NULL dereference when max_hw_count exceeds probed cores - [Medium] media…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] media: mediatek: jpeg: NULL dereference when max_hw_count exceeds probed cores
- [Medium] media: mediatek: jpeg: out-of-bounds access from unbounded max_hw_count
--
commit 888c2ebff2ebcf833297cbded692a442f2ea0e7e
Author: Kyrie Wu <[email protected]>
media: mediatek: jpeg: fix jpeg cores' amounts setting
This commit replaces the fixed MTK_JPEGENC_HW_MAX and MTK_JPEGDEC_HW_MAX loop bounds with a dynamic max_hw_count derived from the number of child device tree nodes, and increments hw_rdy as each child hardware device probes.
Quoted 13 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +1
-0@@ -1302,6 +1302,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);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c static int mtk_jpeg_probe(struct platform_device *pdev) · line 1332
Quoted 8 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +1
-1@@ -1325,7 +1326,7 @@ 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); + jpeg->max_hw_count = num_child;atomic_set (&jpeg->hw_index,0 ); jpeg->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
[Severity: Medium]
Can jpeg->max_hw_count overflow the fixed-size enc_hw_dev[], dec_hw_dev[] and worker comp_jpeg[] arrays?
struct mtk_jpeg_dev and the workers size those arrays to MTK_JPEGENC_HW_MAX
(2) and MTK_JPEGDEC_HW_MAX (3), whereas mtk_jpeg_probe() sets jpeg->max_hw_count directly to num_child without clamping or validating it against those limits. If a device tree node has more children than the array capacity, the loops in mtk_jpegenc_get_hw(), mtk_jpegdec_get_hw(), mtk_jpegenc_worker() and mtk_jpegdec_worker() will read past enc_hw_dev[] or dec_hw_dev[] and overflow the stack-allocated comp_jpeg[] array.
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c static int mtk_jpegenc_get_hw(struct mtk_jpeg_ctx *ctx) · line 1469
Quoted 9 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +1
-1@@ -1462,7 +1463,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;
[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?
mtk_jpeg_probe() counts all child nodes with for_each_child_of_node() and registers the video device immediately, while enc_hw_dev[i], dec_hw_dev[i] and hw_rdy are only populated as each child finishes mtk_jpegenc_hw_probe() or mtk_jpegdec_hw_probe(). If any child node is disabled in DT, defers or fails probe, or has not probed yet when userspace queues a job, mtk_jpegenc_worker() and mtk_jpegdec_worker() call mtk_jpegenc_get_hw() or mtk_jpegdec_get_hw() before waiting on hw_rdy > 0 and dereference comp_jpeg->hw_state on an unpopulated NULL slot.
In addition, both workers snapshot enc_hw_dev[] or dec_hw_dev[] into a local comp_jpeg[] array before the retry_select wait loop; if a child probes while the worker is waiting on hw_wq, the worker will later dereference a stale NULL comp_jpeg[hw_id] when calling pm_runtime_resume_and_get().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v19 2/13 media: mediatek: jpeg: fix jpeg buffer payload size setting
In reply to Kyrie WuFor 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.
--- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +14 -5
@@ -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 ;
Signature · 1 line
2.51.0.windows.2
PATCH v19 3/13 media: mediatek: jpeg: fix buffer structure size and layout
In reply to Kyrie WuUpdates 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).
--- 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(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +1 -1
@@ -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 ;
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +1 -1
@@ -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;
Signature · 1 line
2.51.0.windows.2
PATCH v19 4/13 media: mediatek: jpeg: Fix buffer completion on multi-core streaming stop
In reply to Kyrie WuEnhances 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.
--- .../media/platform/mediatek/jpeg/mtk_jpeg_core.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +11 -3
@@ -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 = {
Signature · 1 line
2.51.0.windows.2
PATCH v19 5/13 media: mediatek: jpeg: Fix multi-core clk suspend and resume setting
In reply to Kyrie WuMake multi-hw component devices own their clocks and suspend callbacks. Keep single-core clock callbacks on the master device.
Stop new jobs and wait for the active job with v4l2_m2m_suspend() before disabling component clocks. Runtime-PM references keep clocks enabled until job completion or timeout.
--- .../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(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +8 -19
@@ -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); }
@@ -1648,14 +1654,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);
@@ -1765,13 +1763,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);
@@ -1781,7 +1772,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,
@@ -1802,9 +1793,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);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +58 -6
108 lines not on this page · raw message
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +58 -4
94 lines not on this page · raw message
Signature · 1 line
2.51.0.windows.2
[email protected]
AI reviewRe: [PATCH v19 05/13] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] media: mediatek: jpeg: deadlock and missed hw wait in v4l2_m2m_suspend() - [Medium] media: mediatek…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] media: mediatek: jpeg: deadlock and missed hw wait in v4l2_m2m_suspend()
- [Medium] media: mediatek: jpeg: uncoordinated v4l2_m2m_resume() on shared m2m_dev
--
commit 3fc9b3db7f2ed0b9fd6715e9fd9cf8dac338e53f
Author: Kyrie Wu <[email protected]>
media: mediatek: jpeg: Fix multi-core clk suspend and resume setting
This commit moves multi-core clock management to the hardware component devices' runtime PM callbacks and adds system sleep callbacks to suspend and resume the M2M queue and component clocks.
Quoted 4 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +0
-0
[ ... ]
Quoted 22 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +18
-0@@ -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); +} +
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c static int mtk_jpegdec_hw_probe(struct platform_device *pdev) · line 699
Quoted 10 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +10
-0+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 ;
[Severity: High]
Can v4l2_m2m_suspend() deadlock during system suspend, and does it wait for active multi-core hardware jobs?
v4l2_m2m_suspend() waits until TRANS_RUNNING is cleared by v4l2_m2m_job_finish(). However, mtk_jpegdec_worker() and mtk_jpegenc_worker() call v4l2_m2m_job_finish() immediately after starting the hardware, while jpeg->hw_state is still MTK_JPEG_HW_BUSY:
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c:mtk_jpegdec_worker() {
...
mtk_jpeg_dec_start(comp_jpeg[hw_id]->reg_base);
v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
spin_unlock_irqrestore(&comp_jpeg[hw_id]->hw_lock, flags);
}As a result, v4l2_m2m_suspend() does not wait for an in-flight frame to finish on the hardware, and the subsequent jpeg->hw_state check immediately fails system suspend with -EBUSY whenever a frame is active.
Furthermore, mtk_jpeg_probe() allocates jpeg->workqueue with WQ_FREEZABLE, which is frozen during suspend_freeze_processes() before device suspend callbacks run, whereas v4l2_m2m_job_finish() schedules the next job via m2m_dev->job_work on the non-freezable system_percpu_wq:
kworker (jpeg->workqueue) PM task / system_percpu_wq
suspend_freeze_processes()
freeze_workqueues_begin()mtk_jpegdec_worker()
mtk_jpeg_dec_start()
v4l2_m2m_job_finish()
v4l2_m2m_try_run()
curr_ctx->job_flags |= TRANS_RUNNING
mtk_jpeg_multicore_dec_device_run()
queue_work(jpeg->workqueue, ...)
(queued on frozen workqueue)
mtk_jpegdec_suspend()
v4l2_m2m_suspend()
wait_event(..., !TRANS_RUNNING)
<-- hangs foreverThe same issue applies to mtk_jpegenc_suspend() in mtk_jpeg_enc_hw.c.
Quoted 11 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +11
-0+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);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c static int mtk_jpegdec_hw_probe(struct platform_device *pdev) · line 720
Quoted 10 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +10
-0+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 device unpause the M2M queue while sibling components are still force-suspended?
In multi-core mode, the parent device and all component devices share a single m2m_dev whose QUEUE_PAUSED flag is a single non-refcounted bit. During system resume, the parent device resumes before its children in mtk_jpeg_resume() and calls v4l2_m2m_resume(jpeg->m2m_dev), and the first child to resume calls v4l2_m2m_resume(jpeg->master_dev->m2m_dev) again while the remaining child devices are still force-suspended (and even if a sibling fails pm_runtime_force_resume()). Similarly, if one child device suspends and a second child fails mtk_jpegdec_suspend() with -EBUSY, the error path calls v4l2_m2m_resume() before dpm_resume() has force-resumed the first child.
If v4l2_m2m_resume() dispatches a queued job while any idle sibling is still force-suspended, mtk_jpegdec_worker() or mtk_jpegenc_worker() can select that sibling, fail pm_runtime_resume_and_get() with -EACCES, and complete the buffers with VB2_BUF_STATE_ERROR. The same issue exists in mtk_jpegenc_suspend() and mtk_jpegenc_resume() in mtk_jpeg_enc_hw.c.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v19 05/13] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting
In reply to Kyrie WuQuoted 11 lines · Kyrie Wu
Make multi-hw component devices own their clocks and suspend callbacks. Keep single-core clock callbacks on the master device.
Stop new jobs and wait for the active job with
v4l2_m2m_suspend()before disabling component clocks. 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 <[email protected]>
PATCH v19 6/13 media: mediatek: jpeg: fix buffer state update timing
In reply to Kyrie WuPublish 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.
Stop walking the done queue after completing the next expected frame; remaining buffers must wait for their own frame order.
--- 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(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +5 -7
@@ -1741,7 +1741,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)) {
@@ -1750,11 +1749,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 ) {
@@ -1775,11 +1769,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,
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +1 -0
@@ -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 ; } } }
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +1 -0
@@ -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 ; } } }
Signature · 1 line
2.51.0.windows.2
[email protected]
AI reviewRe: [PATCH v19 06/13] media: mediatek: jpeg: fix buffer state update timing
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] media: mediatek: jpeg: inaccurate done-queue commit log and missing Fixes tags --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] media: mediatek: jpeg: inaccurate done-queue commit log and missing Fixes tags
--
commit f59ad92b8e09a13f32b7826bdddbfafbfe79fb42
Author: Kyrie Wu <[email protected]>
Quoted 7 lines
media: mediatek: jpeg: fix buffer state update timing
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.
Quoted 7 lines
Stop walking the done queue after completing the next expected frame; remaining buffers must wait for their own frame order.
Fixes dedc21500334 ("media: mtk-jpegdec: add jpeg decode worker interface")Signed-off-by Kyrie Wu <[email protected]>Reviewed-by Nicolas Dufresne <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>
[Severity: Low]
Is the second paragraph of the commit message accurate about what the added break statement does in mtk_jpegdec_put_buf() and mtk_jpegenc_put_buf()?
In both functions, list_for_each_prev_safe() is nested inside an outer loop that checks pos != &ctx->dst_done_queue:
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c:mtk_jpegdec_put_buf() {
...
while (!list_empty(&ctx->dst_done_queue) &&
(pos != &ctx->dst_done_queue)) {
list_for_each_prev_safe(pos, temp_entry, &ctx->dst_done_queue) {
...
}Without the break, list_for_each_prev_safe() always ran until pos reached &ctx->dst_done_queue, ending the outer while loop after a single reverse pass even if frame N+1 was already queued behind frame N. Breaking out of the inner loop while pos != &ctx->dst_done_queue causes the outer while loop to restart the scan from the tail of dst_done_queue for the incremented last_done_frame_num, completing consecutive ready frames rather than stopping the walk.
Also, since the patch fixes the done-queue loops in mtk_jpegdec_put_buf() and mtk_jpegenc_put_buf() as well as the ctx->total_frame_num increment placement in mtk_jpegdec_worker(), should it include the following Fixes tags in addition to dedc21500334 ("media: mtk-jpegdec: add jpeg decode worker interface")?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v19 7/13 media: mediatek: jpeg: fix resolution change event handling in decoder
In reply to Kyrie WuAnnounce 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.
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +4 -1
@@ -1742,10 +1742,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; }
Signature · 1 line
2.51.0.windows.2
[email protected]
AI reviewRe: [PATCH v19 07/13] media: mediatek: jpeg: fix resolution change event handling in decoder
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] media: mtk-jpeg: infinite workqueue loop in mtk_jpegdec_worker() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] media: mtk-jpeg: infinite workqueue loop in mtk_jpegdec_worker()
--
commit ad29b1fb39c9c613b94dec7d4d11fb66bb5328c6
Author: Kyrie Wu <[email protected]>
media: mediatek: jpeg: fix resolution change event handling in decoder
This commit checks for MTK_JPEG_SOURCE_CHANGE in mtk_jpegdec_worker() and updates ctx->state before queueing the source change event.
Quoted 8 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +0
-0@@ -1742,10 +1742,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);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c static void mtk_jpegdec_worker(struct work_struct *work) · line 1753
Quoted 10 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +4
-1+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 when ctx->state is MTK_JPEG_SOURCE_CHANGE cause an infinite workqueue loop on a resolution or format change?
Jumping to getbuf_fail leaves src_buf and dst_buf on the M2M ready queues and calls v4l2_m2m_job_finish(). Unlike mtk_jpeg_dec_m2m_ops, mtk_jpeg_multicore_dec_m2m_ops has no .job_ready callback to check ctx->state, so v4l2_m2m_job_finish() -> v4l2_m2m_schedule_next_job() -> __v4l2_m2m_try_queue() immediately re-queues the context and schedules mtk_jpeg_multicore_dec_device_run() -> mtk_jpegdec_worker() again, spinning across the M2M and decoder workqueues until userspace calls VIDIOC_STREAMOFF.
Wiring .job_ready = mtk_jpeg_dec_job_ready in mtk_jpeg_multicore_dec_m2m_ops would prevent M2M from scheduling new jobs while ctx->state is MTK_JPEG_SOURCE_CHANGE.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
PATCH v19 8/13 media: mediatek: jpeg: fix remove buffer removal timing for multi-core
In reply to Kyrie WuRemove 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.
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +3 -3
@@ -1760,9 +1760,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,
@@ -1777,6 +1774,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 ));
Signature · 1 line
2.51.0.windows.2
PATCH v19 9/13 dt-bindings: soc: mediatek: Add MT8196 JPEG SMMU
In reply to Kyrie WuDocument the dedicated MT8196 JPEG SMMU configuration syscon and its GUSER_ID register block. JPEG decoder and encoder cores use this shared register block to configure their SMMU stream IDs.
--- .../mediatek/mediatek,mt8196-jpeg-smmu.yaml | 41 +++++++++++++++++++ MAINTAINERS | 2 + 2 files changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-jpeg-smmu.yaml
Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-jpeg-smmu.yaml new file +41 -0
@@ -0,0 +1,41 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/soc/mediatek/mediatek,mt8196-jpeg-smmu.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek MT8196 JPEG SMMU configuration registers + +maintainers: + - Kyrie Wu <[email protected]> + +description: + The MT8196 JPEG SMMU configuration register block contains the GUSER_ID + fields used by the JPEG decoder and encoder hardware. + +properties: + compatible: + items: + - const: mediatek,mt8196-jpeg-smmu + - const: syscon + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + jpeg_smmu: syscon@38d0000 { + compatible = "mediatek,mt8196-jpeg-smmu", "syscon"; + reg = <0 0x38d0000 0 0x1000>; + }; + };
MAINTAINERS +2 -0
@@ -3241,6 +3241,7 @@ L: [email protected] (moderated for non-subscribers) S: Maintained W: https://mtk.wiki.kernel.org/ C: irc://irc.libera.chat/linux-mediatek +F: Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-jpeg-smmu.yaml F: arch/arm/boot/dts/mediatek/ F: arch/arm/mach-mediatek/ F: arch/arm64/boot/dts/mediatek/
@@ -17070,6 +17071,7 @@ F: include/dt-bindings/memory/mt*-port.h MEDIATEK JPEG DRIVER M: Bin Liu <[email protected]> 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/
Signature · 1 line
2.51.0.windows.2
[email protected]
AI reviewRe: [PATCH v19 09/13] dt-bindings: soc: mediatek: Add MT8196 JPEG SMMU
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] dt-bindings: soc: mediatek: unused label jpeg_smmu in example --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] dt-bindings: soc: mediatek: unused label jpeg_smmu in example --
commit 518e0e8d206746ff03eb3b640f89c00e57b40210
Author: Kyrie Wu <[email protected]>
dt-bindings: soc: mediatek: Add MT8196 JPEG SMMU
This commit documents the DT binding for the MediaTek MT8196 JPEG SMMU configuration syscon and updates MAINTAINERS.
Quoted 6 lines
Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-jpeg-smmu.yaml new file +0
-0@@ -0,0 +1,41 @@
[ ... ]
Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-jpeg-smmu.yaml line 41
Quoted 11 lines
Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-jpeg-smmu.yaml new file +11
-0+examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + jpeg_smmu: syscon@38d0000 { + compatible = "mediatek,mt8196-jpeg-smmu", "syscon"; + reg = <0 0x38d0000 0 0x1000>; + }; + };
[Severity: Low]
Should the jpeg_smmu node label be dropped from the example? It is not referenced in the example, which causes scripts/dtc/dt-check-style in strict mode to warn about an unused label.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Rob Herring
maintainerRe: [PATCH v19 09/13] dt-bindings: soc: mediatek: Add MT8196 JPEG SMMU
In reply to Kyrie WuQuoted 27 lines · Kyrie Wu
Document the dedicated MT8196 JPEG SMMU configuration syscon and its
GUSER_IDregister block. JPEG decoder and encoder cores use this shared register block to configure their SMMU stream IDs.Signed-off-by Kyrie Wu <[email protected]>--- .../mediatek/mediatek,mt8196-jpeg-smmu.yaml | 41 +++++++++++++++++++ MAINTAINERS | 2 + 2 files changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-jpeg-smmu.yamlDocumentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-jpeg-smmu.yaml new file +10
-0@@ -0,0 +1,41 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/soc/mediatek/mediatek,mt8196-jpeg-smmu.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek MT8196 JPEG SMMU configuration registers + +maintainers: + - Kyrie Wu <[email protected]>
Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-jpeg-smmu.yaml line 20
Quoted 10 lines
Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-jpeg-smmu.yaml new file +10
-0+ +description: + The MT8196 JPEG SMMU configuration register block contains the GUSER_ID + fields used by the JPEG decoder and encoder hardware. + +properties: + compatible: + items: + - const: mediatek,mt8196-jpeg-smmu + - const: syscon
Trivial syscon's like this can go in syscon.yaml.
Rob
PATCH v19 10/13 media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible
In reply to Kyrie WuAdd the MT8196 JPEG decoder and decoder-core compatible strings. Describe the child mediatek,smmu-config phandle to the dedicated JPEG SMMU configuration syscon and require it for MT8196 decoder cores, so the compatible and its hardware requirements are introduced together.
--- .../media/mediatek,mt8195-jpegdec.yaml | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml +22 -2
@@ -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
@@ -69,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
Signature · 1 line
2.51.0.windows.2
Re: [PATCH v19 10/13] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible
Quoted 7 lines · Kyrie Wu
Add the MT8196 JPEG decoder and decoder-core compatible strings. Describe the child mediatek,smmu-config phandle to the dedicated JPEG SMMU configuration syscon and require it for MT8196 decoder cores, so the compatible and its hardware requirements are introduced together.
Signed-off-by Kyrie Wu <[email protected]>---
This was reviewed and your cover letter is vague about tag removal.
Adding new properties at v19 is more than unexpected. Honestly, this should not happen.
I drop the patchset from DT patchwork.
Best regards,
Krzysztof
Re: [PATCH v19 10/13] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible
Quoted 14 lines · Krzysztof Kozlowski
Quoted 10 lines · Kyrie Wu
Add the MT8196 JPEG decoder and decoder-core compatible strings. Describe the child mediatek,smmu-config phandle to the dedicated JPEG
SMMU configuration syscon and require it for MT8196 decoder cores, so
the compatible and its hardware requirements are introduced together.Signed-off-by Kyrie Wu <[email protected]>---
This was reviewed and your cover letter is vague about tag removal.
Quoted 8 lines
Adding new properties at v19 is more than unexpected. Honestly, this should not happen.
I drop the patchset from DT patchwork.
Best regards,
Krzysztof
Hi Krzysztof,
I apologize for changing the scope of the previously reviewed DT patches at v19 and for the vague explanation of the tag removal.
I folded the SMMU property changes into the reviewed decoder and encoder compatible patches and removed their Reviewed-by tags. I should have kept the reviewed changes separate and explicitly documented which tags wereremoved and why. This was my mistake.
For the next revision, I will:
Restore the compatible-only patches to their previously reviewed form, retaining the applicable Reviewed-by tags.
Submit the SMMU syscon and property changes separately for fresh DT review.
Clearly document the changes and any tag removal in the individual patch changelogs and cover letter.
I will resolve the DT binding review before reposting the combined series.
I am sorry for the unnecessary review work this caused.
Best regards,
Kyrie
PATCH v19 11/13 media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc compatible
In reply to Kyrie WuAdd the MT8196 JPEG encoder and encoder-core compatible strings. Describe the child mediatek,smmu-config phandle to the dedicated JPEG SMMU configuration syscon and require it for MT8196 encoder cores.
Document SMMU stream IDs for MT8196 while retaining the MediaTek IOMMU master-port description for MT8195.
--- .../media/mediatek,mt8195-jpegenc.yaml | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml +32 -7
@@ -14,7 +14,9 @@ description: properties: compatible: - const: mediatek,mt8195-jpgenc + enum: + - mediatek,mt8195-jpgenc + - mediatek,mt8196-jpgenc power-domains: maxItems: 1
@@ -22,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
@@ -44,7 +48,9 @@ patternProperties: properties: compatible: - const: mediatek,mt8195-jpgenc-hw + enum: + - mediatek,mt8195-jpgenc-hw + - mediatek,mt8196-jpgenc-hw reg: maxItems: 1
@@ -53,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
@@ -69,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
Signature · 1 line
2.51.0.windows.2
PATCH v19 12/13 media: mediatek: jpeg: add jpeg compatible
In reply to Kyrie WuAdd jpeg dec and enc compatible for mt8196
--- .../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(+)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +36 -0
@@ -1963,6 +1963,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 ,
@@ -1976,6 +1990,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" ,
@@ -2005,6 +2033,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, + }, {}, };
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +3 -0
@@ -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);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +3 -0
@@ -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);
Signature · 1 line
2.51.0.windows.2
[email protected]
AI reviewRe: [PATCH v19 12/13] media: mediatek: jpeg: add jpeg compatible
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] media: mediatek: jpeg: bad 34-bit stall address in mtk_jpeg_set_enc_dst() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] media: mediatek: jpeg: bad 34-bit stall address in mtk_jpeg_set_enc_dst()
--
commit 2178cb0abdb84f47ce9c6cd9ebe6e4f64b01196b
Author: Kyrie Wu <[email protected]>
media: mediatek: jpeg: add jpeg compatible
This commit adds MT8196 device tree compatible strings and driver variant data for the MediaTek multi-core JPEG encoder and decoder.
Quoted 11 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +3
-0@@ -1963,6 +1963,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 ,
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c static struct mtk_jpeg_variant mtk8195_jpegenc_drvdata = { · line 1978
Quoted 10 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +10
-0+ .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, +};
[Severity: High]
Does enabling support_34bit with mtk_jpegenc_worker() program a corrupted upper stall address into JPEG_ENC_STALL_ADDR0_EXT?
mtk_jpegenc_worker() calls mtk_jpeg_set_enc_dst(), which adds the buffer byte size directly to the 2-bit upper address extension instead of extracting the upper bits of dma_addr + size:
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c:mtk_jpeg_set_enc_dst() {
...
if (support_34bit) {
addr_ext = FIELD_PREP(MTK_JPEG_ADDR_MASK, upper_32_bits(dma_addr));
writel(addr_ext, base + JPEG_ENC_DEST_ADDR0_EXT);
writel(addr_ext + size, base + JPEG_ENC_STALL_ADDR0_EXT);
}
}Because size is page-aligned, any carry across a 4 GiB boundary in dma_addr + size is lost from bits [1:0] while upper bits of size are written into the register, corrupting the 34-bit destination end boundary used to stall DMA writes when the encoded bitstream overflows the buffer. Should JPEG_ENC_STALL_ADDR0_EXT be programmed with FIELD_PREP(MTK_JPEG_ADDR_MASK, upper_32_bits(dma_addr + size))?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
PATCH v19 13/13 media: mediatek: jpeg: add jpeg smmu sid setting
In reply to Kyrie WuConfigure 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.
--- .../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(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +29 -0
@@ -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>
@@ -1602,6 +1603,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 ];
@@ -1666,6 +1683,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);
@@ -1782,6 +1804,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,
@@ -1975,6 +2002,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 = {
@@ -2002,6 +2030,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[] = {
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +15 -0
@@ -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; };/**
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +25 -1
@@ -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);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +25 -1
@@ -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);
Signature · 1 line
2.51.0.windows.2
[email protected]
AI reviewRe: [PATCH v19 13/13] media: mediatek: jpeg: add jpeg smmu sid setting
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 --
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 2fd151988985bb81b93a21e0a51263106e01c671
Author: Kyrie Wu <[email protected]>
media: mediatek: jpeg: add jpeg smmu sid setting
This commit configures the JPEG decoder and encoder SMMU stream IDs via the mediatek,smmu-config syscon on MT8196 and initializes the SMMU regmap in the component hardware probe functions before registering each core with the parent device.
Quoted 84 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +25
-1@@ -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);drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +22
-0@@ -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);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c static int mtk_jpegenc_hw_probe(struct platform_device *pdev) · line 416
Quoted 10 lines
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +3
-1+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 returning early when mtk_jpegdec_smmu_init() or mtk_jpegenc_smmu_init() fails or defers cause a NULL pointer dereference in mtk_jpegdec_get_hw() and mtk_jpegenc_get_hw()?
In mtk_jpeg_probe(), jpeg->max_hw_count is set to the total number of child DT nodes and the video device is registered regardless of whether each child probe succeeded. When a child probe fails or defers before reserving hw_index, its slot in master_dev->dec_hw_dev[] or master_dev->enc_hw_dev[] remains NULL, and mtk_jpegdec_get_hw() and mtk_jpegenc_get_hw() iterate up to jpeg->max_hw_count without checking comp_jpeg for NULL:
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, mtk_jpeg_probe() calls devm_of_platform_populate() before initializing jpeg->max_hw_count and resetting jpeg->hw_index to 0:
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c:mtk_jpeg_probe() {
...
ret = devm_of_platform_populate(&pdev->dev);
if (ret) {
v4l2_err(&jpeg->v4l2_dev, "Master of platform populate failed.");
return -EINVAL;
}
if (!jpeg->variant->multi_core) {
...
} else {
init_waitqueue_head(&jpeg->hw_wq);
for_each_child_of_node(pdev->dev.of_node, child)
num_child++;
jpeg->max_hw_count = num_child;
atomic_set(&jpeg->hw_index, 0);
...
}If one child probes synchronously inside devm_of_platform_populate() and another defers in mtk_jpegdec_smmu_init() or mtk_jpegenc_smmu_init(), atomic_set(&jpeg->hw_index, 0) resets hw_index to 0, so the deferred child's later re-probe overwrites slot 0 and leaves slot 1 NULL.
Finally, when probe succeeds, master_dev->dec_hw_dev[i] and master_dev->enc_hw_dev[i] are published with dev->hw_state already set to MTK_JPEG_HW_IDLE without holding master_dev->hw_lock and before platform_set_drvdata() and pm_runtime_enable() run, allowing a concurrent worker to select hw_id = i and call pm_runtime_resume_and_get() before the child device is ready.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13