hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c
....@@ -1,15 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Copyright (c) 2016 MediaTek Inc.
34 * Author: PC Chen <pc.chen@mediatek.com>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
135 */
146
157 #include <linux/module.h>
....@@ -37,6 +29,9 @@
3729 #define H264_MAX_FB_NUM 17
3830 #define HDR_PARSING_BUF_SZ 1024
3931
32
+#define DEC_ERR_RET(ret) ((ret) >> 16)
33
+#define H264_ERR_NOT_VALID 3
34
+
4035 /**
4136 * struct h264_fb - h264 decode frame buffer information
4237 * @vdec_fb_va : virtual address of struct vdec_fb
....@@ -55,7 +50,7 @@
5550
5651 /**
5752 * struct h264_ring_fb_list - ring frame buffer list
58
- * @fb_list : frame buffer arrary
53
+ * @fb_list : frame buffer array
5954 * @read_idx : read index
6055 * @write_idx : write index
6156 * @count : buffer count in list
....@@ -72,7 +67,7 @@
7267 /**
7368 * struct vdec_h264_dec_info - decode information
7469 * @dpb_sz : decoding picture buffer size
75
- * @resolution_changed : resoltion change happen
70
+ * @resolution_changed : resolution change happen
7671 * @realloc_mv_buf : flag to notify driver to re-allocate mv buffer
7772 * @reserved : for 8 bytes alignment
7873 * @bs_dma : Input bit-stream buffer dma address
....@@ -253,8 +248,8 @@
253248 *pic = inst->vsi->pic;
254249 mtk_vcodec_debug(inst, "pic(%d, %d), buf(%d, %d)",
255250 pic->pic_w, pic->pic_h, pic->buf_w, pic->buf_h);
256
- mtk_vcodec_debug(inst, "Y(%d, %d), C(%d, %d)", pic->y_bs_sz,
257
- pic->y_len_sz, pic->c_bs_sz, pic->c_len_sz);
251
+ mtk_vcodec_debug(inst, "fb size: Y(%d), C(%d)",
252
+ pic->fb_sz[0], pic->fb_sz[1]);
258253 }
259254
260255 static void get_crop_info(struct vdec_h264_inst *inst, struct v4l2_rect *cr)
....@@ -274,7 +269,7 @@
274269 mtk_vcodec_debug(inst, "sz=%d", *dpb_sz);
275270 }
276271
277
-static int vdec_h264_init(struct mtk_vcodec_ctx *ctx, unsigned long *h_vdec)
272
+static int vdec_h264_init(struct mtk_vcodec_ctx *ctx)
278273 {
279274 struct vdec_h264_inst *inst = NULL;
280275 int err;
....@@ -286,9 +281,7 @@
286281 inst->ctx = ctx;
287282
288283 inst->vpu.id = IPI_VDEC_H264;
289
- inst->vpu.dev = ctx->dev->vpu_plat_dev;
290284 inst->vpu.ctx = ctx;
291
- inst->vpu.handler = vpu_dec_ipi_handler;
292285
293286 err = vpu_dec_init(&inst->vpu);
294287 if (err) {
....@@ -303,7 +296,7 @@
303296
304297 mtk_vcodec_debug(inst, "H264 Instance >> %p", inst);
305298
306
- *h_vdec = (unsigned long)inst;
299
+ ctx->drv_handle = inst;
307300 return 0;
308301
309302 error_deinit:
....@@ -314,7 +307,7 @@
314307 return err;
315308 }
316309
317
-static void vdec_h264_deinit(unsigned long h_vdec)
310
+static void vdec_h264_deinit(void *h_vdec)
318311 {
319312 struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec;
320313
....@@ -339,7 +332,7 @@
339332 return -1;
340333 }
341334
342
-static int vdec_h264_decode(unsigned long h_vdec, struct mtk_vcodec_mem *bs,
335
+static int vdec_h264_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
343336 struct vdec_fb *fb, bool *res_chg)
344337 {
345338 struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec;
....@@ -365,8 +358,11 @@
365358 buf = (unsigned char *)bs->va;
366359 buf_sz = bs->size;
367360 nal_start_idx = find_start_code(buf, buf_sz);
368
- if (nal_start_idx < 0)
361
+ if (nal_start_idx < 0) {
362
+ mtk_vcodec_err(inst, "invalid nal start code");
363
+ err = -EIO;
369364 goto err_free_fb_out;
365
+ }
370366
371367 nal_start = buf[nal_start_idx];
372368 nal_type = NAL_TYPE(buf[nal_start_idx]);
....@@ -390,8 +386,14 @@
390386 data[0] = buf_sz;
391387 data[1] = nal_start;
392388 err = vpu_dec_start(vpu, data, 2);
393
- if (err)
389
+ if (err) {
390
+ if (err > 0 && (DEC_ERR_RET(err) == H264_ERR_NOT_VALID)) {
391
+ mtk_vcodec_err(inst, "- error bitstream - err = %d -",
392
+ err);
393
+ err = -EIO;
394
+ }
394395 goto err_free_fb_out;
396
+ }
395397
396398 *res_chg = inst->vsi->dec.resolution_changed;
397399 if (*res_chg) {
....@@ -459,8 +461,8 @@
459461 list->count--;
460462 }
461463
462
-static int vdec_h264_get_param(unsigned long h_vdec,
463
- enum vdec_get_param_type type, void *out)
464
+static int vdec_h264_get_param(void *h_vdec, enum vdec_get_param_type type,
465
+ void *out)
464466 {
465467 struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec;
466468
....@@ -493,16 +495,9 @@
493495 return 0;
494496 }
495497
496
-static struct vdec_common_if vdec_h264_if = {
498
+const struct vdec_common_if vdec_h264_if = {
497499 .init = vdec_h264_init,
498500 .decode = vdec_h264_decode,
499501 .get_param = vdec_h264_get_param,
500502 .deinit = vdec_h264_deinit,
501503 };
502
-
503
-struct vdec_common_if *get_h264_dec_comm_if(void);
504
-
505
-struct vdec_common_if *get_h264_dec_comm_if(void)
506
-{
507
- return &vdec_h264_if;
508
-}