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