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[8]:	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 /**
66  * struct venc_ap_ipi_msg_enc - AP to VPU enc cmd structure
67  * @msg_id:	message id (AP_IPIMSG_XXX_ENC_ENCODE)
68  * @vpu_inst_addr:	VPU encoder instance addr
69  *			(struct venc_vp8_vsi/venc_h264_vsi *)
70  * @bs_mode:	bitstream mode for h264
71  *		(H264_BS_MODE_SPS/H264_BS_MODE_PPS/H264_BS_MODE_FRAME)
72  * @input_addr:	pointer to input image buffer plane
73  * @bs_addr:	pointer to output bit stream buffer
74  * @bs_size:	bit stream buffer size
75  */
76 struct venc_ap_ipi_msg_enc {
77 	uint32_t msg_id;
78 	uint32_t vpu_inst_addr;
79 	uint32_t bs_mode;
80 	uint32_t input_addr[3];
81 	uint32_t bs_addr;
82 	uint32_t bs_size;
83 };
84 
85 /**
86  * struct venc_ap_ipi_msg_deinit - AP to VPU deinit cmd structure
87  * @msg_id:	message id (AP_IPIMSG_XXX_ENC_DEINIT)
88  * @vpu_inst_addr:	VPU encoder instance addr
89  *			(struct venc_vp8_vsi/venc_h264_vsi *)
90  */
91 struct venc_ap_ipi_msg_deinit {
92 	uint32_t msg_id;
93 	uint32_t vpu_inst_addr;
94 };
95 
96 /**
97  * enum venc_ipi_msg_status - VPU ack AP cmd status
98  */
99 enum venc_ipi_msg_status {
100 	VENC_IPI_MSG_STATUS_OK,
101 	VENC_IPI_MSG_STATUS_FAIL,
102 };
103 
104 /**
105  * struct venc_vpu_ipi_msg_common - VPU ack AP cmd common structure
106  * @msg_id:	message id (VPU_IPIMSG_XXX_DONE)
107  * @status:	cmd status (venc_ipi_msg_status)
108  * @venc_inst:	AP encoder instance (struct venc_vp8_inst/venc_h264_inst *)
109  */
110 struct venc_vpu_ipi_msg_common {
111 	uint32_t msg_id;
112 	uint32_t status;
113 	uint64_t venc_inst;
114 };
115 
116 /**
117  * struct venc_vpu_ipi_msg_init - VPU ack AP init cmd structure
118  * @msg_id:	message id (VPU_IPIMSG_XXX_ENC_SET_PARAM_DONE)
119  * @status:	cmd status (venc_ipi_msg_status)
120  * @venc_inst:	AP encoder instance (struct venc_vp8_inst/venc_h264_inst *)
121  * @vpu_inst_addr:	VPU encoder instance addr
122  *			(struct venc_vp8_vsi/venc_h264_vsi *)
123  * @reserved:	reserved for future use. vpu is running in 32bit. Without
124  *		this reserved field, if kernel run in 64bit. this struct size
125  *		will be different between kernel and vpu
126  */
127 struct venc_vpu_ipi_msg_init {
128 	uint32_t msg_id;
129 	uint32_t status;
130 	uint64_t venc_inst;
131 	uint32_t vpu_inst_addr;
132 	uint32_t reserved;
133 };
134 
135 /**
136  * struct venc_vpu_ipi_msg_set_param - VPU ack AP set_param cmd structure
137  * @msg_id:	message id (VPU_IPIMSG_XXX_ENC_SET_PARAM_DONE)
138  * @status:	cmd status (venc_ipi_msg_status)
139  * @venc_inst:	AP encoder instance (struct venc_vp8_inst/venc_h264_inst *)
140  * @param_id:	parameter id (venc_set_param_type)
141  * @data_item:	number of items in the data array
142  * @data[6]:	data array to store the return result
143  */
144 struct venc_vpu_ipi_msg_set_param {
145 	uint32_t msg_id;
146 	uint32_t status;
147 	uint64_t venc_inst;
148 	uint32_t param_id;
149 	uint32_t data_item;
150 	uint32_t data[6];
151 };
152 
153 /**
154  * enum venc_ipi_msg_enc_state - Type of encode state
155  * VEN_IPI_MSG_ENC_STATE_FRAME:	one frame being encoded
156  * VEN_IPI_MSG_ENC_STATE_PART:	bit stream buffer full
157  * VEN_IPI_MSG_ENC_STATE_SKIP:	encoded skip frame
158  * VEN_IPI_MSG_ENC_STATE_ERROR:	encounter error
159  */
160 enum venc_ipi_msg_enc_state {
161 	VEN_IPI_MSG_ENC_STATE_FRAME,
162 	VEN_IPI_MSG_ENC_STATE_PART,
163 	VEN_IPI_MSG_ENC_STATE_SKIP,
164 	VEN_IPI_MSG_ENC_STATE_ERROR,
165 };
166 
167 /**
168  * struct venc_vpu_ipi_msg_enc - VPU ack AP enc cmd structure
169  * @msg_id:	message id (VPU_IPIMSG_XXX_ENC_ENCODE_DONE)
170  * @status:	cmd status (venc_ipi_msg_status)
171  * @venc_inst:	AP encoder instance (struct venc_vp8_inst/venc_h264_inst *)
172  * @state:	encode state (venc_ipi_msg_enc_state)
173  * @is_key_frm:	whether the encoded frame is key frame
174  * @bs_size:	encoded bitstream size
175  * @reserved:	reserved for future use. vpu is running in 32bit. Without
176  *		this reserved field, if kernel run in 64bit. this struct size
177  *		will be different between kernel and vpu
178  */
179 struct venc_vpu_ipi_msg_enc {
180 	uint32_t msg_id;
181 	uint32_t status;
182 	uint64_t venc_inst;
183 	uint32_t state;
184 	uint32_t is_key_frm;
185 	uint32_t bs_size;
186 	uint32_t reserved;
187 };
188 
189 /**
190  * struct venc_vpu_ipi_msg_deinit - VPU ack AP deinit cmd structure
191  * @msg_id:   message id (VPU_IPIMSG_XXX_ENC_DEINIT_DONE)
192  * @status:   cmd status (venc_ipi_msg_status)
193  * @venc_inst:	AP encoder instance (struct venc_vp8_inst/venc_h264_inst *)
194  */
195 struct venc_vpu_ipi_msg_deinit {
196 	uint32_t msg_id;
197 	uint32_t status;
198 	uint64_t venc_inst;
199 };
200 
201 #endif /* _VENC_IPI_MSG_H_ */
202