Skip to content

Commit 9875c0b

Browse files
committed
Merge tag 'media/v6.9-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media fixes from Mauro Carvalho Chehab: - some fixes for mediatec vcodec encoder/decoder oopses * tag 'media/v6.9-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: media: mediatek: vcodec: support 36 bits physical address media: mediatek: vcodec: adding lock to protect encoder context list media: mediatek: vcodec: adding lock to protect decoder context list media: mediatek: vcodec: Fix oops when HEVC init fails media: mediatek: vcodec: Handle VP9 superframe bitstream with 8 sub-frames
2 parents fe5b5ef + d353c3c commit 9875c0b

11 files changed

Lines changed: 32 additions & 13 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ static void mtk_vcodec_vpu_reset_dec_handler(void *priv)
5050

5151
dev_err(&dev->plat_dev->dev, "Watchdog timeout!!");
5252

53-
mutex_lock(&dev->dev_mutex);
53+
mutex_lock(&dev->dev_ctx_lock);
5454
list_for_each_entry(ctx, &dev->ctx_list, list) {
5555
ctx->state = MTK_STATE_ABORT;
5656
mtk_v4l2_vdec_dbg(0, ctx, "[%d] Change to state MTK_STATE_ABORT", ctx->id);
5757
}
58-
mutex_unlock(&dev->dev_mutex);
58+
mutex_unlock(&dev->dev_ctx_lock);
5959
}
6060

6161
static void mtk_vcodec_vpu_reset_enc_handler(void *priv)
@@ -65,12 +65,12 @@ static void mtk_vcodec_vpu_reset_enc_handler(void *priv)
6565

6666
dev_err(&dev->plat_dev->dev, "Watchdog timeout!!");
6767

68-
mutex_lock(&dev->dev_mutex);
68+
mutex_lock(&dev->dev_ctx_lock);
6969
list_for_each_entry(ctx, &dev->ctx_list, list) {
7070
ctx->state = MTK_STATE_ABORT;
7171
mtk_v4l2_vdec_dbg(0, ctx, "[%d] Change to state MTK_STATE_ABORT", ctx->id);
7272
}
73-
mutex_unlock(&dev->dev_mutex);
73+
mutex_unlock(&dev->dev_ctx_lock);
7474
}
7575

7676
static const struct mtk_vcodec_fw_ops mtk_vcodec_vpu_msg = {

drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ static int fops_vcodec_open(struct file *file)
268268

269269
ctx->dev->vdec_pdata->init_vdec_params(ctx);
270270

271+
mutex_lock(&dev->dev_ctx_lock);
271272
list_add(&ctx->list, &dev->ctx_list);
273+
mutex_unlock(&dev->dev_ctx_lock);
272274
mtk_vcodec_dbgfs_create(ctx);
273275

274276
mutex_unlock(&dev->dev_mutex);
@@ -311,7 +313,9 @@ static int fops_vcodec_release(struct file *file)
311313
v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
312314

313315
mtk_vcodec_dbgfs_remove(dev, ctx->id);
316+
mutex_lock(&dev->dev_ctx_lock);
314317
list_del_init(&ctx->list);
318+
mutex_unlock(&dev->dev_ctx_lock);
315319
kfree(ctx);
316320
mutex_unlock(&dev->dev_mutex);
317321
return 0;
@@ -404,6 +408,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
404408
for (i = 0; i < MTK_VDEC_HW_MAX; i++)
405409
mutex_init(&dev->dec_mutex[i]);
406410
mutex_init(&dev->dev_mutex);
411+
mutex_init(&dev->dev_ctx_lock);
407412
spin_lock_init(&dev->irqlock);
408413

409414
snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s",

drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ struct mtk_vcodec_dec_ctx {
241241
*
242242
* @dec_mutex: decoder hardware lock
243243
* @dev_mutex: video_device lock
244+
* @dev_ctx_lock: the lock of context list
244245
* @decode_workqueue: decode work queue
245246
*
246247
* @irqlock: protect data access by irq handler and work thread
@@ -282,6 +283,7 @@ struct mtk_vcodec_dec_dev {
282283
/* decoder hardware mutex lock */
283284
struct mutex dec_mutex[MTK_VDEC_HW_MAX];
284285
struct mutex dev_mutex;
286+
struct mutex dev_ctx_lock;
285287
struct workqueue_struct *decode_workqueue;
286288

287289
spinlock_t irqlock;

drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,6 @@ static int vdec_hevc_slice_init(struct mtk_vcodec_dec_ctx *ctx)
869869
inst->vpu.codec_type = ctx->current_codec;
870870
inst->vpu.capture_type = ctx->capture_fourcc;
871871

872-
ctx->drv_handle = inst;
873872
err = vpu_dec_init(&inst->vpu);
874873
if (err) {
875874
mtk_vdec_err(ctx, "vdec_hevc init err=%d", err);
@@ -898,6 +897,7 @@ static int vdec_hevc_slice_init(struct mtk_vcodec_dec_ctx *ctx)
898897
mtk_vdec_debug(ctx, "lat hevc instance >> %p, codec_type = 0x%x",
899898
inst, inst->vpu.codec_type);
900899

900+
ctx->drv_handle = inst;
901901
return 0;
902902
error_free_inst:
903903
kfree(inst);

drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp8_if.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ static int vdec_vp8_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
449449
inst->frm_cnt, y_fb_dma, c_fb_dma, fb);
450450

451451
inst->cur_fb = fb;
452-
dec->bs_dma = (unsigned long)bs->dma_addr;
452+
dec->bs_dma = (uint64_t)bs->dma_addr;
453453
dec->bs_sz = bs->size;
454454
dec->cur_y_fb_dma = y_fb_dma;
455455
dec->cur_c_fb_dma = c_fb_dma;

drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_if.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "../vdec_drv_base.h"
1717
#include "../vdec_vpu_if.h"
1818

19+
#define VP9_MAX_SUPER_FRAMES_NUM 8
1920
#define VP9_SUPER_FRAME_BS_SZ 64
2021
#define MAX_VP9_DPB_SIZE 9
2122

@@ -133,11 +134,11 @@ struct vp9_sf_ref_fb {
133134
*/
134135
struct vdec_vp9_vsi {
135136
unsigned char sf_bs_buf[VP9_SUPER_FRAME_BS_SZ];
136-
struct vp9_sf_ref_fb sf_ref_fb[VP9_MAX_FRM_BUF_NUM-1];
137+
struct vp9_sf_ref_fb sf_ref_fb[VP9_MAX_SUPER_FRAMES_NUM];
137138
int sf_next_ref_fb_idx;
138139
unsigned int sf_frm_cnt;
139-
unsigned int sf_frm_offset[VP9_MAX_FRM_BUF_NUM-1];
140-
unsigned int sf_frm_sz[VP9_MAX_FRM_BUF_NUM-1];
140+
unsigned int sf_frm_offset[VP9_MAX_SUPER_FRAMES_NUM];
141+
unsigned int sf_frm_sz[VP9_MAX_SUPER_FRAMES_NUM];
141142
unsigned int sf_frm_idx;
142143
unsigned int sf_init;
143144
struct vdec_fb fb;
@@ -526,7 +527,7 @@ static void vp9_swap_frm_bufs(struct vdec_vp9_inst *inst)
526527
/* if this super frame and it is not last sub-frame, get next fb for
527528
* sub-frame decode
528529
*/
529-
if (vsi->sf_frm_cnt > 0 && vsi->sf_frm_idx != vsi->sf_frm_cnt - 1)
530+
if (vsi->sf_frm_cnt > 0 && vsi->sf_frm_idx != vsi->sf_frm_cnt)
530531
vsi->sf_next_ref_fb_idx = vp9_get_sf_ref_fb(inst);
531532
}
532533

@@ -735,7 +736,7 @@ static void get_free_fb(struct vdec_vp9_inst *inst, struct vdec_fb **out_fb)
735736

736737
static int validate_vsi_array_indexes(struct vdec_vp9_inst *inst,
737738
struct vdec_vp9_vsi *vsi) {
738-
if (vsi->sf_frm_idx >= VP9_MAX_FRM_BUF_NUM - 1) {
739+
if (vsi->sf_frm_idx > VP9_MAX_SUPER_FRAMES_NUM) {
739740
mtk_vdec_err(inst->ctx, "Invalid vsi->sf_frm_idx=%u.", vsi->sf_frm_idx);
740741
return -EIO;
741742
}

drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ static int vdec_vp9_slice_setup_tile_buffer(struct vdec_vp9_slice_instance *inst
10741074
unsigned int mi_row;
10751075
unsigned int mi_col;
10761076
unsigned int offset;
1077-
unsigned int pa;
1077+
dma_addr_t pa;
10781078
unsigned int size;
10791079
struct vdec_vp9_slice_tiles *tiles;
10801080
unsigned char *pos;
@@ -1109,7 +1109,7 @@ static int vdec_vp9_slice_setup_tile_buffer(struct vdec_vp9_slice_instance *inst
11091109
pos = va + offset;
11101110
end = va + bs->size;
11111111
/* truncated */
1112-
pa = (unsigned int)bs->dma_addr + offset;
1112+
pa = bs->dma_addr + offset;
11131113
tb = instance->tile.va;
11141114
for (i = 0; i < rows; i++) {
11151115
for (j = 0; j < cols; j++) {

drivers/media/platform/mediatek/vcodec/decoder/vdec_vpu_if.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ static bool vpu_dec_check_ap_inst(struct mtk_vcodec_dec_dev *dec_dev, struct vde
7777
struct mtk_vcodec_dec_ctx *ctx;
7878
int ret = false;
7979

80+
mutex_lock(&dec_dev->dev_ctx_lock);
8081
list_for_each_entry(ctx, &dec_dev->ctx_list, list) {
8182
if (!IS_ERR_OR_NULL(ctx) && ctx->vpu_inst == vpu) {
8283
ret = true;
8384
break;
8485
}
8586
}
87+
mutex_unlock(&dec_dev->dev_ctx_lock);
8688

8789
return ret;
8890
}

drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ static int fops_vcodec_open(struct file *file)
177177
mtk_v4l2_venc_dbg(2, ctx, "Create instance [%d]@%p m2m_ctx=%p ",
178178
ctx->id, ctx, ctx->m2m_ctx);
179179

180+
mutex_lock(&dev->dev_ctx_lock);
180181
list_add(&ctx->list, &dev->ctx_list);
182+
mutex_unlock(&dev->dev_ctx_lock);
181183

182184
mutex_unlock(&dev->dev_mutex);
183185
mtk_v4l2_venc_dbg(0, ctx, "%s encoder [%d]", dev_name(&dev->plat_dev->dev),
@@ -212,7 +214,9 @@ static int fops_vcodec_release(struct file *file)
212214
v4l2_fh_exit(&ctx->fh);
213215
v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
214216

217+
mutex_lock(&dev->dev_ctx_lock);
215218
list_del_init(&ctx->list);
219+
mutex_unlock(&dev->dev_ctx_lock);
216220
kfree(ctx);
217221
mutex_unlock(&dev->dev_mutex);
218222
return 0;
@@ -294,6 +298,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
294298

295299
mutex_init(&dev->enc_mutex);
296300
mutex_init(&dev->dev_mutex);
301+
mutex_init(&dev->dev_ctx_lock);
297302
spin_lock_init(&dev->irqlock);
298303

299304
snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s",

drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ struct mtk_vcodec_enc_ctx {
178178
*
179179
* @enc_mutex: encoder hardware lock.
180180
* @dev_mutex: video_device lock
181+
* @dev_ctx_lock: the lock of context list
181182
* @encode_workqueue: encode work queue
182183
*
183184
* @enc_irq: h264 encoder irq resource
@@ -205,6 +206,7 @@ struct mtk_vcodec_enc_dev {
205206
/* encoder hardware mutex lock */
206207
struct mutex enc_mutex;
207208
struct mutex dev_mutex;
209+
struct mutex dev_ctx_lock;
208210
struct workqueue_struct *encode_workqueue;
209211

210212
int enc_irq;

0 commit comments

Comments
 (0)