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