1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2019 Pengutronix, Michael Tretter <kernel@pengutronix.de> 4 * 5 * Allegro VCU firmware mailbox mail definitions 6 */ 7 8 #ifndef ALLEGRO_MAIL_H 9 #define ALLEGRO_MAIL_H 10 11 #include <linux/kernel.h> 12 13 enum mcu_msg_type { 14 MCU_MSG_TYPE_INIT = 0x0000, 15 MCU_MSG_TYPE_CREATE_CHANNEL = 0x0005, 16 MCU_MSG_TYPE_DESTROY_CHANNEL = 0x0006, 17 MCU_MSG_TYPE_ENCODE_FRAME = 0x0007, 18 MCU_MSG_TYPE_PUT_STREAM_BUFFER = 0x0012, 19 MCU_MSG_TYPE_PUSH_BUFFER_INTERMEDIATE = 0x000e, 20 MCU_MSG_TYPE_PUSH_BUFFER_REFERENCE = 0x000f, 21 }; 22 23 enum mcu_msg_version { 24 MCU_MSG_VERSION_2018_2, 25 MCU_MSG_VERSION_2019_2, 26 }; 27 28 const char *msg_type_name(enum mcu_msg_type type); 29 30 struct mcu_msg_header { 31 enum mcu_msg_type type; 32 enum mcu_msg_version version; 33 }; 34 35 struct mcu_msg_init_request { 36 struct mcu_msg_header header; 37 u32 reserved0; /* maybe a unused channel id */ 38 u32 suballoc_dma; 39 u32 suballoc_size; 40 s32 l2_cache[3]; 41 }; 42 43 struct mcu_msg_init_response { 44 struct mcu_msg_header header; 45 u32 reserved0; 46 }; 47 48 struct create_channel_param { 49 enum mcu_msg_version version; 50 u32 layer_id; 51 u16 width; 52 u16 height; 53 u32 videomode; 54 u32 format; 55 u32 colorspace; 56 u32 src_mode; 57 u32 src_bit_depth; 58 u8 profile; 59 u16 constraint_set_flags; 60 u32 codec; 61 u16 level; 62 u16 tier; 63 u32 log2_max_poc; 64 u32 log2_max_frame_num; 65 u32 temporal_mvp_enable; 66 u32 enable_reordering; 67 u32 dbf_ovr_en; 68 u32 num_ref_idx_l0; 69 u32 num_ref_idx_l1; 70 u32 custom_lda; 71 u32 rdo_cost_mode; 72 u32 lf; 73 u32 lf_x_tile; 74 u32 lf_x_slice; 75 s8 beta_offset; 76 s8 tc_offset; 77 u16 reserved10; 78 u32 unknown11; 79 u32 unknown12; 80 u16 num_slices; 81 u16 prefetch_auto; 82 u32 prefetch_mem_offset; 83 u32 prefetch_mem_size; 84 u16 clip_hrz_range; 85 u16 clip_vrt_range; 86 u16 me_range[4]; 87 u8 max_cu_size; 88 u8 min_cu_size; 89 u8 max_tu_size; 90 u8 min_tu_size; 91 u8 max_transfo_depth_inter; 92 u8 max_transfo_depth_intra; 93 u16 reserved20; 94 u32 entropy_mode; 95 u32 wp_mode; 96 97 /* rate control param */ 98 u32 rate_control_mode; 99 u32 initial_rem_delay; 100 u32 cpb_size; 101 u16 framerate; 102 u16 clk_ratio; 103 u32 target_bitrate; 104 u32 max_bitrate; 105 u16 initial_qp; 106 u16 min_qp; 107 u16 max_qp; 108 s16 ip_delta; 109 s16 pb_delta; 110 u16 golden_ref; 111 u16 golden_delta; 112 u16 golden_ref_frequency; 113 u32 rate_control_option; 114 u32 num_pixel; 115 u16 max_psnr; 116 u16 max_pixel_value; 117 u32 maxpicturesize[3]; 118 119 /* gop param */ 120 u32 gop_ctrl_mode; 121 u32 freq_idr; 122 u32 freq_lt; 123 u32 gdr_mode; 124 u16 gop_length; 125 u8 num_b; 126 u8 freq_golden_ref; 127 u32 enable_lt; 128 u32 tmpdqp; 129 130 u32 subframe_latency; 131 u32 lda_control_mode; 132 u32 unknown41; 133 134 u32 lda_factors[6]; 135 136 u32 max_num_merge_cand; 137 }; 138 139 struct mcu_msg_create_channel { 140 struct mcu_msg_header header; 141 u32 user_id; 142 u32 *blob; 143 size_t blob_size; 144 u32 blob_mcu_addr; 145 u32 ep1_addr; 146 }; 147 148 struct mcu_msg_create_channel_response { 149 struct mcu_msg_header header; 150 u32 channel_id; 151 u32 user_id; 152 u32 options; 153 u32 num_core; 154 u32 num_ref_idx_l0; 155 u32 num_ref_idx_l1; 156 u32 int_buffers_count; 157 u32 int_buffers_size; 158 u32 rec_buffers_count; 159 u32 rec_buffers_size; 160 u32 reserved; 161 u32 error_code; 162 }; 163 164 struct mcu_msg_destroy_channel { 165 struct mcu_msg_header header; 166 u32 channel_id; 167 }; 168 169 struct mcu_msg_destroy_channel_response { 170 struct mcu_msg_header header; 171 u32 channel_id; 172 }; 173 174 struct mcu_msg_push_buffers_internal_buffer { 175 u32 dma_addr; 176 u32 mcu_addr; 177 u32 size; 178 }; 179 180 struct mcu_msg_push_buffers_internal { 181 struct mcu_msg_header header; 182 u32 channel_id; 183 size_t num_buffers; 184 struct mcu_msg_push_buffers_internal_buffer buffer[]; 185 }; 186 187 struct mcu_msg_put_stream_buffer { 188 struct mcu_msg_header header; 189 u32 channel_id; 190 u32 dma_addr; 191 u32 mcu_addr; 192 u32 size; 193 u32 offset; 194 u64 dst_handle; 195 }; 196 197 struct mcu_msg_encode_frame { 198 struct mcu_msg_header header; 199 u32 channel_id; 200 u32 reserved; 201 202 u32 encoding_options; 203 #define AL_OPT_USE_QP_TABLE BIT(0) 204 #define AL_OPT_FORCE_LOAD BIT(1) 205 #define AL_OPT_USE_L2 BIT(2) 206 #define AL_OPT_DISABLE_INTRA BIT(3) 207 #define AL_OPT_DEPENDENT_SLICES BIT(4) 208 209 s16 pps_qp; 210 u16 padding; 211 u64 user_param; 212 u64 src_handle; 213 214 u32 request_options; 215 #define AL_OPT_SCENE_CHANGE BIT(0) 216 #define AL_OPT_RESTART_GOP BIT(1) 217 #define AL_OPT_USE_LONG_TERM BIT(2) 218 #define AL_OPT_UPDATE_PARAMS BIT(3) 219 220 /* u32 scene_change_delay (optional) */ 221 /* rate control param (optional) */ 222 /* gop param (optional) */ 223 /* dynamic resolution params (optional) */ 224 u32 src_y; 225 u32 src_uv; 226 u32 is_10_bit; 227 u32 stride; 228 u32 format; 229 u32 ep2; 230 u64 ep2_v; 231 }; 232 233 struct mcu_msg_encode_frame_response { 234 struct mcu_msg_header header; 235 u32 channel_id; 236 u64 dst_handle; /* see mcu_msg_put_stream_buffer */ 237 u64 user_param; /* see mcu_msg_encode_frame */ 238 u64 src_handle; /* see mcu_msg_encode_frame */ 239 u16 skip; 240 u16 is_ref; 241 u32 initial_removal_delay; 242 u32 dpb_output_delay; 243 u32 size; 244 u32 frame_tag_size; 245 s32 stuffing; 246 s32 filler; 247 u16 num_column; 248 u16 num_row; 249 u16 qp; 250 u8 num_ref_idx_l0; 251 u8 num_ref_idx_l1; 252 u32 partition_table_offset; 253 s32 partition_table_size; 254 u32 sum_complex; 255 s32 tile_width[4]; 256 s32 tile_height[22]; 257 u32 error_code; 258 259 u32 slice_type; 260 #define AL_ENC_SLICE_TYPE_B 0 261 #define AL_ENC_SLICE_TYPE_P 1 262 #define AL_ENC_SLICE_TYPE_I 2 263 264 u32 pic_struct; 265 u8 is_idr; 266 u8 is_first_slice; 267 u8 is_last_slice; 268 u8 reserved; 269 u16 pps_qp; 270 u16 reserved1; 271 u32 reserved2; 272 u32 reserved3; 273 u32 reserved4; 274 u32 reserved5; 275 u32 reserved6; 276 }; 277 278 union mcu_msg_response { 279 struct mcu_msg_header header; 280 struct mcu_msg_init_response init; 281 struct mcu_msg_create_channel_response create_channel; 282 struct mcu_msg_destroy_channel_response destroy_channel; 283 struct mcu_msg_encode_frame_response encode_frame; 284 }; 285 286 ssize_t allegro_encode_config_blob(u32 *dst, struct create_channel_param *param); 287 ssize_t allegro_decode_config_blob(struct create_channel_param *param, 288 struct mcu_msg_create_channel_response *msg, 289 u32 *src); 290 291 int allegro_decode_mail(void *msg, u32 *src); 292 ssize_t allegro_encode_mail(u32 *dst, void *msg); 293 294 #endif 295