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