1 /*
2  * Copyright (c) 2016 MediaTek Inc.
3  * Author: Jungchang Tsao <jungchang.tsao@mediatek.com>
4  *	   Daniel Hsiao <daniel.hsiao@mediatek.com>
5  *	   Tiffany Lin <tiffany.lin@mediatek.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  */
17 
18 #ifndef _VENC_IPI_MSG_H_
19 #define _VENC_IPI_MSG_H_
20 
21 #define AP_IPIMSG_VENC_BASE 0xC000
22 #define VPU_IPIMSG_VENC_BASE 0xD000
23 
24 /**
25  * enum venc_ipi_msg_id - message id between AP and VPU
26  * (ipi stands for inter-processor interrupt)
27  * @AP_IPIMSG_ENC_XXX:		AP to VPU cmd message id
28  * @VPU_IPIMSG_ENC_XXX_DONE:	VPU ack AP cmd message id
29  */
30 enum venc_ipi_msg_id {
31 	AP_IPIMSG_ENC_INIT = AP_IPIMSG_VENC_BASE,
32 	AP_IPIMSG_ENC_SET_PARAM,
33 	AP_IPIMSG_ENC_ENCODE,
34 	AP_IPIMSG_ENC_DEINIT,
35 
36 	VPU_IPIMSG_ENC_INIT_DONE = VPU_IPIMSG_VENC_BASE,
37 	VPU_IPIMSG_ENC_SET_PARAM_DONE,
38 	VPU_IPIMSG_ENC_ENCODE_DONE,
39 	VPU_IPIMSG_ENC_DEINIT_DONE,
40 };
41 
42 /**
43  * struct venc_ap_ipi_msg_init - AP to VPU init cmd structure
44  * @msg_id:	message id (AP_IPIMSG_XXX_ENC_INIT)
45  * @reserved:	reserved for future use. vpu is running in 32bit. Without
46  *		this reserved field, if kernel run in 64bit. this struct size
47  *		will be different between kernel and vpu
48  * @venc_inst:	AP encoder instance
49  *		(struct venc_vp8_inst/venc_h264_inst *)
50  */
51 struct venc_ap_ipi_msg_init {
52 	uint32_t msg_id;
53 	uint32_t reserved;
54 	uint64_t venc_inst;
55 };
56 
57 /**
58  * struct venc_ap_ipi_msg_set_param - AP to VPU set_param cmd structure
59  * @msg_id:	message id (AP_IPIMSG_XXX_ENC_SET_PARAM)
60  * @vpu_inst_addr:	VPU encoder instance addr
61  *			(struct venc_vp8_vsi/venc_h264_vsi *)
62  * @param_id:	parameter id (venc_set_param_type)
63  * @data_item:	number of items in the data array
64  * @data[8]:	data array to store the set parameters
65  */
66 struct venc_ap_ipi_msg_set_param {
67 	uint32_t msg_id;
68 	uint32_t vpu_inst_addr;
69 	uint32_t param_id;
70 	uint32_t data_item;
71 	uint32_t data[8];
72 };
73 
74 /**
75  * struct venc_ap_ipi_msg_enc - AP to VPU enc cmd structure
76  * @msg_id:	message id (AP_IPIMSG_XXX_ENC_ENCODE)
77  * @vpu_inst_addr:	VPU encoder instance addr
78  *			(struct venc_vp8_vsi/venc_h264_vsi *)
79  * @bs_mode:	bitstream mode for h264
80  *		(H264_BS_MODE_SPS/H264_BS_MODE_PPS/H264_BS_MODE_FRAME)
81  * @input_addr:	pointer to input image buffer plane
82  * @bs_addr:	pointer to output bit stream buffer
83  * @bs_size:	bit stream buffer size
84  */
85 struct venc_ap_ipi_msg_enc {
86 	uint32_t msg_id;
87 	uint32_t vpu_inst_addr;
88 	uint32_t bs_mode;
89 	uint32_t input_addr[3];
90 	uint32_t bs_addr;
91 	uint32_t bs_size;
92 };
93 
94 /**
95  * struct venc_ap_ipi_msg_deinit - AP to VPU deinit cmd structure
96  * @msg_id:	message id (AP_IPIMSG_XXX_ENC_DEINIT)
97  * @vpu_inst_addr:	VPU encoder instance addr
98  *			(struct venc_vp8_vsi/venc_h264_vsi *)
99  */
100 struct venc_ap_ipi_msg_deinit {
101 	uint32_t msg_id;
102 	uint32_t vpu_inst_addr;
103 };
104 
105 /**
106  * enum venc_ipi_msg_status - VPU ack AP cmd status
107  */
108 enum venc_ipi_msg_status {
109 	VENC_IPI_MSG_STATUS_OK,
110 	VENC_IPI_MSG_STATUS_FAIL,
111 };
112 
113 /**
114  * struct venc_vpu_ipi_msg_common - VPU ack AP cmd common structure
115  * @msg_id:	message id (VPU_IPIMSG_XXX_DONE)
116  * @status:	cmd status (venc_ipi_msg_status)
117  * @venc_inst:	AP encoder instance (struct venc_vp8_inst/venc_h264_inst *)
118  */
119 struct venc_vpu_ipi_msg_common {
120 	uint32_t msg_id;
121 	uint32_t status;
122 	uint64_t venc_inst;
123 };
124 
125 /**
126  * struct venc_vpu_ipi_msg_init - VPU ack AP init cmd structure
127  * @msg_id:	message id (VPU_IPIMSG_XXX_ENC_SET_PARAM_DONE)
128  * @status:	cmd status (venc_ipi_msg_status)
129  * @venc_inst:	AP encoder instance (struct venc_vp8_inst/venc_h264_inst *)
130  * @vpu_inst_addr:	VPU encoder instance addr
131  *			(struct venc_vp8_vsi/venc_h264_vsi *)
132  * @reserved:	reserved for future use. vpu is running in 32bit. Without
133  *		this reserved field, if kernel run in 64bit. this struct size
134  *		will be different between kernel and vpu
135  */
136 struct venc_vpu_ipi_msg_init {
137 	uint32_t msg_id;
138 	uint32_t status;
139 	uint64_t venc_inst;
140 	uint32_t vpu_inst_addr;
141 	uint32_t reserved;
142 };
143 
144 /**
145  * struct venc_vpu_ipi_msg_set_param - VPU ack AP set_param cmd structure
146  * @msg_id:	message id (VPU_IPIMSG_XXX_ENC_SET_PARAM_DONE)
147  * @status:	cmd status (venc_ipi_msg_status)
148  * @venc_inst:	AP encoder instance (struct venc_vp8_inst/venc_h264_inst *)
149  * @param_id:	parameter id (venc_set_param_type)
150  * @data_item:	number of items in the data array
151  * @data[6]:	data array to store the return result
152  */
153 struct venc_vpu_ipi_msg_set_param {
154 	uint32_t msg_id;
155 	uint32_t status;
156 	uint64_t venc_inst;
157 	uint32_t param_id;
158 	uint32_t data_item;
159 	uint32_t data[6];
160 };
161 
162 /**
163  * enum venc_ipi_msg_enc_state - Type of encode state
164  * VEN_IPI_MSG_ENC_STATE_FRAME:	one frame being encoded
165  * VEN_IPI_MSG_ENC_STATE_PART:	bit stream buffer full
166  * VEN_IPI_MSG_ENC_STATE_SKIP:	encoded skip frame
167  * VEN_IPI_MSG_ENC_STATE_ERROR:	encounter error
168  */
169 enum venc_ipi_msg_enc_state {
170 	VEN_IPI_MSG_ENC_STATE_FRAME,
171 	VEN_IPI_MSG_ENC_STATE_PART,
172 	VEN_IPI_MSG_ENC_STATE_SKIP,
173 	VEN_IPI_MSG_ENC_STATE_ERROR,
174 };
175 
176 /**
177  * struct venc_vpu_ipi_msg_enc - VPU ack AP enc cmd structure
178  * @msg_id:	message id (VPU_IPIMSG_XXX_ENC_ENCODE_DONE)
179  * @status:	cmd status (venc_ipi_msg_status)
180  * @venc_inst:	AP encoder instance (struct venc_vp8_inst/venc_h264_inst *)
181  * @state:	encode state (venc_ipi_msg_enc_state)
182  * @is_key_frm:	whether the encoded frame is key frame
183  * @bs_size:	encoded bitstream size
184  * @reserved:	reserved for future use. vpu is running in 32bit. Without
185  *		this reserved field, if kernel run in 64bit. this struct size
186  *		will be different between kernel and vpu
187  */
188 struct venc_vpu_ipi_msg_enc {
189 	uint32_t msg_id;
190 	uint32_t status;
191 	uint64_t venc_inst;
192 	uint32_t state;
193 	uint32_t is_key_frm;
194 	uint32_t bs_size;
195 	uint32_t reserved;
196 };
197 
198 /**
199  * struct venc_vpu_ipi_msg_deinit - VPU ack AP deinit cmd structure
200  * @msg_id:   message id (VPU_IPIMSG_XXX_ENC_DEINIT_DONE)
201  * @status:   cmd status (venc_ipi_msg_status)
202  * @venc_inst:	AP encoder instance (struct venc_vp8_inst/venc_h264_inst *)
203  */
204 struct venc_vpu_ipi_msg_deinit {
205 	uint32_t msg_id;
206 	uint32_t status;
207 	uint64_t venc_inst;
208 };
209 
210 #endif /* _VENC_IPI_MSG_H_ */
211