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