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