1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2016 MediaTek Inc.
4  * Author: PC Chen <pc.chen@mediatek.com>
5  */
6 
7 #ifndef _VDEC_VPU_IF_H_
8 #define _VDEC_VPU_IF_H_
9 
10 #include "mtk_vcodec_fw.h"
11 
12 struct mtk_vcodec_ctx;
13 
14 /**
15  * struct vdec_vpu_inst - VPU instance for video codec
16  * @id          : ipi msg id for each decoder
17  * @core_id     : core id used to separate different hardware
18  * @vsi         : driver structure allocated by VPU side and shared to AP side
19  *                for control and info share
20  * @failure     : VPU execution result status, 0: success, others: fail
21  * @inst_addr	: VPU decoder instance address
22  * @fw_abi_version : ABI version of the firmware.
23  * @inst_id	: if fw_abi_version >= 2, contains the instance ID to be given
24  *                in place of inst_addr in messages.
25  * @signaled    : 1 - Host has received ack message from VPU, 0 - not received
26  * @ctx         : context for v4l2 layer integration
27  * @dev		: platform device of VPU
28  * @wq          : wait queue to wait VPU message ack
29  * @handler     : ipi handler for each decoder
30  * @codec_type     : use codec type to separate different codecs
31  * @capture_type:	used capture type to separate different capture format
32  * @fb_sz  : frame buffer size of each plane
33  */
34 struct vdec_vpu_inst {
35 	int id;
36 	int core_id;
37 	void *vsi;
38 	int32_t failure;
39 	uint32_t inst_addr;
40 	uint32_t fw_abi_version;
41 	uint32_t inst_id;
42 	unsigned int signaled;
43 	struct mtk_vcodec_ctx *ctx;
44 	wait_queue_head_t wq;
45 	mtk_vcodec_ipi_handler handler;
46 	unsigned int codec_type;
47 	unsigned int capture_type;
48 	unsigned int fb_sz[2];
49 };
50 
51 /**
52  * vpu_dec_init - init decoder instance and allocate required resource in VPU.
53  *
54  * @vpu: instance for vdec_vpu_inst
55  */
56 int vpu_dec_init(struct vdec_vpu_inst *vpu);
57 
58 /**
59  * vpu_dec_start - start decoding, basically the function will be invoked once
60  *                 every frame.
61  *
62  * @vpu : instance for vdec_vpu_inst
63  * @data: meta data to pass bitstream info to VPU decoder
64  * @len : meta data length
65  */
66 int vpu_dec_start(struct vdec_vpu_inst *vpu, uint32_t *data, unsigned int len);
67 
68 /**
69  * vpu_dec_end - end decoding, basically the function will be invoked once
70  *               when HW decoding done interrupt received successfully. The
71  *               decoder in VPU will continue to do reference frame management
72  *               and check if there is a new decoded frame available to display.
73  *
74  * @vpu : instance for vdec_vpu_inst
75  */
76 int vpu_dec_end(struct vdec_vpu_inst *vpu);
77 
78 /**
79  * vpu_dec_deinit - deinit decoder instance and resource freed in VPU.
80  *
81  * @vpu: instance for vdec_vpu_inst
82  */
83 int vpu_dec_deinit(struct vdec_vpu_inst *vpu);
84 
85 /**
86  * vpu_dec_reset - reset decoder, use for flush decoder when end of stream or
87  *                 seek. Remainig non displayed frame will be pushed to display.
88  *
89  * @vpu: instance for vdec_vpu_inst
90  */
91 int vpu_dec_reset(struct vdec_vpu_inst *vpu);
92 
93 /**
94  * vpu_dec_core - core start decoding, basically the function will be invoked once
95  *                 every frame.
96  *
97  * @vpu : instance for vdec_vpu_inst
98  */
99 int vpu_dec_core(struct vdec_vpu_inst *vpu);
100 
101 /**
102  * vpu_dec_core_end - core end decoding, basically the function will be invoked once
103  *               when core HW decoding done and receive interrupt successfully. The
104  *               decoder in VPU will updata hardware information and deinit hardware
105  *               and check if there is a new decoded frame available to display.
106  *
107  * @vpu : instance for vdec_vpu_inst
108  */
109 int vpu_dec_core_end(struct vdec_vpu_inst *vpu);
110 
111 /**
112  * vpu_dec_get_param - get param from scp
113  *
114  * @vpu : instance for vdec_vpu_inst
115  * @data: meta data to pass bitstream info to VPU decoder
116  * @len : meta data length
117  * @param_type : get param type
118  */
119 int vpu_dec_get_param(struct vdec_vpu_inst *vpu, uint32_t *data,
120 		      unsigned int len, unsigned int param_type);
121 
122 #endif
123