xref: /linux/drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h (revision 8c13415c8a4383447c21ec832b20b3b283f0e01a)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 2025 Advanced Micro Devices, Inc.
4  */
5 
6 #ifndef _ISP4_FW_CMD_RESP_H_
7 #define _ISP4_FW_CMD_RESP_H_
8 
9 /*
10  *        Two types of command/response channel.
11  *          Type Global Command has one command/response channel.
12  *          Type Stream Command has one command/response channel.
13  *-----------                                        ------------
14  *|         |       ---------------------------      |          |
15  *|         |  ---->|  Global Command         |----> |          |
16  *|         |       ---------------------------      |          |
17  *|         |                                        |          |
18  *|         |                                        |          |
19  *|         |       ---------------------------      |          |
20  *|         |  ---->|   Stream Command        |----> |          |
21  *|         |       ---------------------------      |          |
22  *|         |                                        |          |
23  *|         |                                        |          |
24  *|         |                                        |          |
25  *|  HOST   |                                        | Firmware |
26  *|         |                                        |          |
27  *|         |                                        |          |
28  *|         |       --------------------------       |          |
29  *|         |  <----|  Global Response       |<----  |          |
30  *|         |       --------------------------       |          |
31  *|         |                                        |          |
32  *|         |                                        |          |
33  *|         |       --------------------------       |          |
34  *|         |  <----|  Stream Response       |<----  |          |
35  *|         |       --------------------------       |          |
36  *|         |                                        |          |
37  *|         |                                        |          |
38  *-----------                                        ------------
39  */
40 
41 /*
42  *        cmd_id is in the format of following type:
43  *        type: indicate command type, global/stream commands.
44  *        group: indicate the command group.
45  *        id: A unique command identification in one type and group.
46  *        |<-Bit31 ~ Bit24->|<-Bit23 ~ Bit16->|<-Bit15 ~ Bit0->|
47  *        |      type       |      group      |       id       |
48  */
49 
50 #define ISP4FW_CMD_TYPE_SHIFT            24
51 #define ISP4FW_CMD_GROUP_SHIFT           16
52 #define ISP4FW_CMD_TYPE_STREAM_CTRL      (0x2U << ISP4FW_CMD_TYPE_SHIFT)
53 
54 #define ISP4FW_CMD_GROUP_STREAM_CTRL     (0x1U << ISP4FW_CMD_GROUP_SHIFT)
55 #define ISP4FW_CMD_GROUP_STREAM_BUFFER   (0x4U << ISP4FW_CMD_GROUP_SHIFT)
56 
57 /* Stream  Command */
58 #define ISP4FW_CMD_ID_SET_STREAM_CONFIG  (ISP4FW_CMD_TYPE_STREAM_CTRL\
59 					 | ISP4FW_CMD_GROUP_STREAM_CTRL | 0x1)
60 #define ISP4FW_CMD_ID_SET_OUT_CHAN_PROP  (ISP4FW_CMD_TYPE_STREAM_CTRL\
61 					 | ISP4FW_CMD_GROUP_STREAM_CTRL | 0x3)
62 #define ISP4FW_CMD_ID_ENABLE_OUT_CHAN    (ISP4FW_CMD_TYPE_STREAM_CTRL\
63 					 | ISP4FW_CMD_GROUP_STREAM_CTRL | 0x5)
64 #define ISP4FW_CMD_ID_START_STREAM       (ISP4FW_CMD_TYPE_STREAM_CTRL\
65 					 | ISP4FW_CMD_GROUP_STREAM_CTRL | 0x7)
66 #define ISP4FW_CMD_ID_STOP_STREAM        (ISP4FW_CMD_TYPE_STREAM_CTRL\
67 					 | ISP4FW_CMD_GROUP_STREAM_CTRL | 0x8)
68 
69 /* Stream Buffer Command */
70 #define ISP4FW_CMD_ID_SEND_BUFFER        (ISP4FW_CMD_TYPE_STREAM_CTRL\
71 					 | ISP4FW_CMD_GROUP_STREAM_BUFFER | 0x1)
72 
73 /*
74  *        resp_id is in the format of following type:
75  *        type: indicate command type, global/stream commands.
76  *        group: indicate the command group.
77  *        id: A unique command identification in one type and group.
78  *        |<-Bit31 ~ Bit24->|<-Bit23 ~ Bit16->|<-Bit15 ~ Bit0->|
79  *        |      type       |      group      |       id       |
80  */
81 
82 #define ISP4FW_RESP_GROUP_SHIFT          16
83 
84 #define ISP4FW_RESP_GROUP_GENERAL        (0x1 << ISP4FW_RESP_GROUP_SHIFT)
85 #define ISP4FW_RESP_GROUP_NOTIFICATION   (0x3 << ISP4FW_RESP_GROUP_SHIFT)
86 
87 /* General Response */
88 #define ISP4FW_RESP_ID_CMD_DONE          (ISP4FW_RESP_GROUP_GENERAL | 0x1)
89 
90 /* Notification */
91 #define ISP4FW_RESP_ID_NOTI_FRAME_DONE   (ISP4FW_RESP_GROUP_NOTIFICATION | 0x1)
92 
93 #define ISP4FW_CMD_STATUS_SUCCESS        0
94 #define ISP4FW_CMD_STATUS_FAIL           1
95 #define ISP4FW_CMD_STATUS_SKIPPED        2
96 
97 #define ISP4FW_ADDR_SPACE_TYPE_GPU_VA    4
98 
99 #define ISP4FW_MEMORY_POOL_SIZE          (100 * 1024 * 1024)
100 
101 /*
102  * standard ISP pipeline: mipicsi=>isp
103  */
104 #define ISP4FW_MIPI0_ISP_PIPELINE_ID     0x5f91
105 
106 enum isp4fw_sensor_id {
107 	/* Sensor id for ISP input from MIPI port 0 */
108 	ISP4FW_SENSOR_ID_ON_MIPI0  = 0,
109 };
110 
111 enum isp4fw_stream_id {
112 	ISP4FW_STREAM_ID_INVALID = -1,
113 	ISP4FW_STREAM_ID_1 = 0,
114 	ISP4FW_STREAM_ID_2 = 1,
115 	ISP4FW_STREAM_ID_3 = 2,
116 	ISP4FW_STREAM_ID_MAXIMUM
117 };
118 
119 enum isp4fw_image_format {
120 	/* 4:2:0,semi-planar, 8-bit */
121 	ISP4FW_IMAGE_FORMAT_NV12 = 1,
122 	/* interleave, 4:2:2, 8-bit */
123 	ISP4FW_IMAGE_FORMAT_YUV422INTERLEAVED = 7,
124 };
125 
126 enum isp4fw_pipe_out_ch {
127 	ISP4FW_ISP_PIPE_OUT_CH_PREVIEW = 0,
128 };
129 
130 enum isp4fw_yuv_range {
131 	ISP4FW_ISP_YUV_RANGE_FULL = 0,     /* YUV value range in 0~255 */
132 	ISP4FW_ISP_YUV_RANGE_NARROW = 1,   /* YUV value range in 16~235 */
133 	ISP4FW_ISP_YUV_RANGE_MAX
134 };
135 
136 enum isp4fw_buffer_type {
137 	ISP4FW_BUFFER_TYPE_PREVIEW = 8,
138 	ISP4FW_BUFFER_TYPE_META_INFO = 10,
139 	ISP4FW_BUFFER_TYPE_MEM_POOL = 15,
140 };
141 
142 enum isp4fw_buffer_status {
143 	/* The buffer is INVALID */
144 	ISP4FW_BUFFER_STATUS_INVALID,
145 	/* The buffer is not filled with image data */
146 	ISP4FW_BUFFER_STATUS_SKIPPED,
147 	/* The buffer is available and awaiting to be filled */
148 	ISP4FW_BUFFER_STATUS_EXIST,
149 	/* The buffer is filled with image data */
150 	ISP4FW_BUFFER_STATUS_DONE,
151 	/* The buffer is unavailable */
152 	ISP4FW_BUFFER_STATUS_LACK,
153 	/* The buffer is dirty, probably caused by LMI leakage */
154 	ISP4FW_BUFFER_STATUS_DIRTY,
155 	ISP4FW_BUFFER_STATUS_MAX
156 };
157 
158 enum isp4fw_buffer_source {
159 	/* The buffer is from the stream buffer queue */
160 	ISP4FW_BUFFER_SOURCE_STREAM,
161 };
162 
163 struct isp4fw_error_code {
164 	u32 code1;
165 	u32 code2;
166 	u32 code3;
167 	u32 code4;
168 	u32 code5;
169 };
170 
171 /* Command Structure for FW */
172 
173 struct isp4fw_cmd {
174 	u32 cmd_seq_num;
175 	u32 cmd_id;
176 	u32 cmd_param[12];
177 	u16 cmd_stream_id;
178 	u8 cmd_silent_resp;
179 	u8 reserved;
180 	u32 cmd_check_sum;
181 };
182 
183 struct isp4fw_resp_cmd_done {
184 	/*
185 	 * The host2fw command seqNum.
186 	 * To indicate which command this response refers to.
187 	 */
188 	u32 cmd_seq_num;
189 	/* The host2fw command id for host double check. */
190 	u32 cmd_id;
191 	/*
192 	 * Indicate the command process status.
193 	 * 0 means success. 1 means fail. 2 means skipped
194 	 */
195 	u16 cmd_status;
196 	/*
197 	 * If cmd_status is 1, the command failed. The host can check
198 	 * isp4fw_error_code for details.
199 	 */
200 	u16 isp4fw_error_code;
201 	/* The response payload type varies by cmd. */
202 	u8 payload[36];
203 };
204 
205 struct isp4fw_resp_param_package {
206 	u32 package_addr_lo;	/* The low 32 bit of the pkg address. */
207 	u32 package_addr_hi;	/* The high 32 bit of the pkg address. */
208 	u32 package_size;	/* The total pkg size in bytes. */
209 	u32 package_check_sum;	/* The byte sum of the pkg. */
210 };
211 
212 struct isp4fw_resp {
213 	u32 resp_seq_num;
214 	u32 resp_id;
215 	union {
216 		struct isp4fw_resp_cmd_done cmd_done;
217 		struct isp4fw_resp_param_package frame_done;
218 		u32 resp_param[12];
219 	} param;
220 	u8  reserved[4];
221 	u32 resp_check_sum;
222 };
223 
224 struct isp4fw_mipi_pipe_path_cfg {
225 	u32 b_enable;
226 	enum isp4fw_sensor_id isp4fw_sensor_id;
227 };
228 
229 struct isp4fw_isp_pipe_path_cfg {
230 	u32  isp_pipe_id;	/* pipe ids for pipeline construction */
231 };
232 
233 struct isp4fw_isp_stream_cfg {
234 	/* Isp mipi path */
235 	struct isp4fw_mipi_pipe_path_cfg mipi_pipe_path_cfg;
236 	/* Isp pipe path */
237 	struct isp4fw_isp_pipe_path_cfg  isp_pipe_path_cfg;
238 	/* enable TNR */
239 	u32 b_enable_tnr;
240 	/*
241 	 * Number of frames for RTA processing.
242 	 * Set to 0 to use the firmware's default value.
243 	 */
244 	u32 rta_frames_per_proc;
245 };
246 
247 struct isp4fw_image_prop {
248 	enum isp4fw_image_format image_format;
249 	u32 width;
250 	u32 height;
251 	u32 luma_pitch;
252 	u32 chroma_pitch;
253 	enum isp4fw_yuv_range yuv_range;
254 };
255 
256 struct isp4fw_buffer {
257 	/*
258 	 * A check num for debug usage, host can set the buf_tags
259 	 * to different numbers
260 	 */
261 	u32 buf_tags;
262 	union {
263 		u32 value;
264 		struct {
265 			u32 space : 16;
266 			u32 vmid  : 16;
267 		} bit;
268 	} vmid_space;
269 	u32 buf_base_a_lo;		/* Low address of buffer A */
270 	u32 buf_base_a_hi;		/* High address of buffer A */
271 	u32 buf_size_a;			/* Buffer size of buffer A */
272 
273 	u32 buf_base_b_lo;		/* Low address of buffer B */
274 	u32 buf_base_b_hi;		/* High address of buffer B */
275 	u32 buf_size_b;			/* Buffer size of buffer B */
276 
277 	u32 buf_base_c_lo;		/* Low address of buffer C */
278 	u32 buf_base_c_hi;		/* High address of buffer C */
279 	u32 buf_size_c;			/* Buffer size of buffer C */
280 };
281 
282 struct isp4fw_buffer_meta_info {
283 	u32 enabled;					/* enabled flag */
284 	enum isp4fw_buffer_status status;		/* BufferStatus */
285 	struct isp4fw_error_code err;			/* err code */
286 	enum isp4fw_buffer_source source;		/* BufferSource */
287 	struct isp4fw_image_prop image_prop;		/* image_prop */
288 	struct isp4fw_buffer buffer;			/* buffer info */
289 };
290 
291 struct isp4fw_meta_info {
292 	u32 poc;				/* frame id */
293 	u32 fc_id;				/* frame ctl id */
294 	u32 time_stamp_lo;			/* timestamp low 32 bits */
295 	u32 time_stamp_hi;			/* timestamp_high 32 bits */
296 	struct isp4fw_buffer_meta_info preview;	/* preview BufferMetaInfo */
297 };
298 
299 struct isp4fw_cmd_send_buffer {
300 	enum isp4fw_buffer_type buffer_type;
301 	struct isp4fw_buffer buffer;		/* buffer info */
302 };
303 
304 struct isp4fw_cmd_set_out_ch_prop {
305 	enum isp4fw_pipe_out_ch ch;	/* ISP output channel */
306 	struct isp4fw_image_prop image_prop;	/* image property */
307 };
308 
309 struct isp4fw_cmd_enable_out_ch {
310 	enum isp4fw_pipe_out_ch ch;	/* ISP output channel */
311 	u32 is_enable;			/* If channel is enabled or not */
312 };
313 
314 struct isp4fw_cmd_set_stream_cfg {
315 	struct isp4fw_isp_stream_cfg stream_cfg; /* stream path config */
316 };
317 
318 #endif /* _ISP4_FW_CMD_RESP_H_ */
319