Skip to content

Commit 56c0ac0

Browse files
yunfei-mtkHans Verkuil
authored andcommitted
media: mediatek: vcodec: using encoder device to alloc/free encoder memory
Need to use encoder device to allocate/free encoder memory when calling mtk_vcodec_mem_alloc/mtk_vcodec_mem_free, or leading to below crash log when test encoder with decoder device. pc : dma_alloc_attrs+0x44/0xf4 lr : mtk_vcodec_mem_alloc+0x50/0xa4 [mtk_vcodec_common] sp : ffffffc0209f3990 x29: ffffffc0209f39a0 x28: ffffff8024102a18 x27: 0000000000000000 x26: 0000000000000000 x25: ffffffc00c06e2d8 x24: 0000000000000001 x23: 0000000000000cc0 x22: 0000000000000010 x21: 0000000000000800 x20: ffffff8024102a18 x19: 0000000000000000 x18: 0000000000000000 x17: 0000000000000009 x16: ffffffe389736a98 x15: 0000000000000078 x14: ffffffe389704434 x13: 0000000000000007 x12: ffffffe38a2b2560 x11: 0000000000000800 x10: 0000000000000004 x9 : ffffffe331f07484 x8 : 5400e9aef2395000 x7 : 0000000000000000 x6 : 000000000000003f x5 : 0000000000000001 x4 : 0000000000000000 x3 : 0000000000000cc0 x2 : ffffff8024102a18 x1 : 0000000000000800 x0 : 0000000000000010 Call trace: dma_alloc_attrs+0x44/0xf4 mtk_vcodec_mem_alloc+0x50/0xa4 [mtk_vcodec_common 2819d3d601f3cd06c1f2213ac1b9995134441421] h264_enc_set_param+0x27c/0x378 [mtk_vcodec_enc 772cc3d26c254e8cf54079451ef8d930d2eb4404] venc_if_set_param+0x4c/0x7c [mtk_vcodec_enc 772cc3d26c254e8cf54079451ef8d930d2eb4404] vb2ops_venc_start_streaming+0x1bc/0x328 [mtk_vcodec_enc 772cc3d26c254e8cf54079451ef8d930d2eb4404] vb2_start_streaming+0x64/0x12c vb2_core_streamon+0x114/0x158 vb2_streamon+0x38/0x60 v4l2_m2m_streamon+0x48/0x88 v4l2_m2m_ioctl_streamon+0x20/0x2c v4l_streamon+0x2c/0x38 __video_do_ioctl+0x2c4/0x3dc video_usercopy+0x404/0x934 video_ioctl2+0x20/0x2c v4l2_ioctl+0x54/0x64 v4l2_compat_ioctl32+0x90/0xa34 __arm64_compat_sys_ioctl+0x128/0x13c invoke_syscall+0x4c/0x108 el0_svc_common+0x98/0x104 do_el0_svc_compat+0x28/0x34 el0_svc_compat+0x2c/0x74 el0t_32_sync_handler+0xa8/0xcc el0t_32_sync+0x194/0x198 Code: aa0003f6 aa0203f4 aa0103f5 f900 'Fixes: 01abf5f ("media: mediatek: vcodec: separate struct 'mtk_vcodec_ctx'")' Signed-off-by: Yunfei Dong <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent b833b17 commit 56c0ac0

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,42 +47,66 @@ EXPORT_SYMBOL(mtk_vcodec_write_vdecsys);
4747

4848
int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem)
4949
{
50+
enum mtk_instance_type inst_type = *((unsigned int *)priv);
51+
struct platform_device *plat_dev;
5052
unsigned long size = mem->size;
51-
struct mtk_vcodec_dec_ctx *ctx = priv;
52-
struct device *dev = &ctx->dev->plat_dev->dev;
53+
int id;
5354

54-
mem->va = dma_alloc_coherent(dev, size, &mem->dma_addr, GFP_KERNEL);
55+
if (inst_type == MTK_INST_ENCODER) {
56+
struct mtk_vcodec_enc_ctx *enc_ctx = priv;
57+
58+
plat_dev = enc_ctx->dev->plat_dev;
59+
id = enc_ctx->id;
60+
} else {
61+
struct mtk_vcodec_dec_ctx *dec_ctx = priv;
62+
63+
plat_dev = dec_ctx->dev->plat_dev;
64+
id = dec_ctx->id;
65+
}
66+
67+
mem->va = dma_alloc_coherent(&plat_dev->dev, size, &mem->dma_addr, GFP_KERNEL);
5568
if (!mem->va) {
56-
mtk_v4l2_vdec_err(ctx, "%s dma_alloc size=%ld failed!", dev_name(dev), size);
69+
mtk_v4l2_err(plat_dev, "%s dma_alloc size=%ld failed!",
70+
dev_name(&plat_dev->dev), size);
5771
return -ENOMEM;
5872
}
5973

60-
mtk_v4l2_vdec_dbg(3, ctx, "[%d] - va = %p", ctx->id, mem->va);
61-
mtk_v4l2_vdec_dbg(3, ctx, "[%d] - dma = 0x%lx", ctx->id,
62-
(unsigned long)mem->dma_addr);
63-
mtk_v4l2_vdec_dbg(3, ctx, "[%d] size = 0x%lx", ctx->id, size);
74+
mtk_v4l2_debug(plat_dev, 3, "[%d] - va = %p dma = 0x%lx size = 0x%lx", id, mem->va,
75+
(unsigned long)mem->dma_addr, size);
6476

6577
return 0;
6678
}
6779
EXPORT_SYMBOL(mtk_vcodec_mem_alloc);
6880

6981
void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem)
7082
{
83+
enum mtk_instance_type inst_type = *((unsigned int *)priv);
84+
struct platform_device *plat_dev;
7185
unsigned long size = mem->size;
72-
struct mtk_vcodec_dec_ctx *ctx = priv;
73-
struct device *dev = &ctx->dev->plat_dev->dev;
86+
int id;
87+
88+
if (inst_type == MTK_INST_ENCODER) {
89+
struct mtk_vcodec_enc_ctx *enc_ctx = priv;
90+
91+
plat_dev = enc_ctx->dev->plat_dev;
92+
id = enc_ctx->id;
93+
} else {
94+
struct mtk_vcodec_dec_ctx *dec_ctx = priv;
95+
96+
plat_dev = dec_ctx->dev->plat_dev;
97+
id = dec_ctx->id;
98+
}
7499

75100
if (!mem->va) {
76-
mtk_v4l2_vdec_err(ctx, "%s dma_free size=%ld failed!", dev_name(dev), size);
101+
mtk_v4l2_err(plat_dev, "%s dma_free size=%ld failed!",
102+
dev_name(&plat_dev->dev), size);
77103
return;
78104
}
79105

80-
mtk_v4l2_vdec_dbg(3, ctx, "[%d] - va = %p", ctx->id, mem->va);
81-
mtk_v4l2_vdec_dbg(3, ctx, "[%d] - dma = 0x%lx", ctx->id,
82-
(unsigned long)mem->dma_addr);
83-
mtk_v4l2_vdec_dbg(3, ctx, "[%d] size = 0x%lx", ctx->id, size);
106+
mtk_v4l2_debug(plat_dev, 3, "[%d] - va = %p dma = 0x%lx size = 0x%lx", id, mem->va,
107+
(unsigned long)mem->dma_addr, size);
84108

85-
dma_free_coherent(dev, size, mem->va, mem->dma_addr);
109+
dma_free_coherent(&plat_dev->dev, size, mem->va, mem->dma_addr);
86110
mem->va = NULL;
87111
mem->dma_addr = 0;
88112
mem->size = 0;

0 commit comments

Comments
 (0)