1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */ 2 /* 3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * redistributing this file, you may do so under either license. 5 * 6 * Copyright(c) 2022 Intel Corporation 7 */ 8 9 #ifndef __INCLUDE_SOUND_SOF_IPC4_TOPOLOGY_H__ 10 #define __INCLUDE_SOUND_SOF_IPC4_TOPOLOGY_H__ 11 12 #include <sound/sof/ipc4/header.h> 13 14 #define SOF_IPC4_FW_PAGE_SIZE BIT(12) 15 #define SOF_IPC4_FW_PAGE(x) ((((x) + BIT(12) - 1) & ~(BIT(12) - 1)) >> 12) 16 #define SOF_IPC4_FW_ROUNDUP(x) (((x) + BIT(6) - 1) & (~(BIT(6) - 1))) 17 18 #define SOF_IPC4_MODULE_LOAD_TYPE GENMASK(3, 0) 19 #define SOF_IPC4_MODULE_AUTO_START BIT(4) 20 /* 21 * Two module schedule domains in fw : 22 * LL domain - Low latency domain 23 * DP domain - Data processing domain 24 * The LL setting should be equal to !DP setting 25 */ 26 #define SOF_IPC4_MODULE_LL BIT(5) 27 #define SOF_IPC4_MODULE_DP BIT(6) 28 #define SOF_IPC4_MODULE_LIB_CODE BIT(7) 29 #define SOF_IPC4_MODULE_INIT_CONFIG_MASK GENMASK(11, 8) 30 31 #define SOF_IPC4_MODULE_INIT_CONFIG_TYPE_BASE_CFG 0 32 #define SOF_IPC4_MODULE_INIT_CONFIG_TYPE_BASE_CFG_WITH_EXT 1 33 34 #define SOF_IPC4_MODULE_INSTANCE_LIST_ITEM_SIZE 12 35 #define SOF_IPC4_PIPELINE_OBJECT_SIZE 448 36 #define SOF_IPC4_DATA_QUEUE_OBJECT_SIZE 128 37 #define SOF_IPC4_LL_TASK_OBJECT_SIZE 72 38 #define SOF_IPC4_DP_TASK_OBJECT_SIZE 104 39 #define SOF_IPC4_DP_TASK_LIST_SIZE (12 + 8) 40 #define SOF_IPC4_LL_TASK_LIST_ITEM_SIZE 12 41 #define SOF_IPC4_FW_MAX_PAGE_COUNT 20 42 #define SOF_IPC4_FW_MAX_QUEUE_COUNT 8 43 44 /* IPC4 sample types */ 45 #define SOF_IPC4_TYPE_MSB_INTEGER 0 46 #define SOF_IPC4_TYPE_LSB_INTEGER 1 47 #define SOF_IPC4_TYPE_SIGNED_INTEGER 2 48 #define SOF_IPC4_TYPE_UNSIGNED_INTEGER 3 49 #define SOF_IPC4_TYPE_FLOAT 4 50 #define SOF_IPC4_TYPE_A_LAW 5 51 #define SOF_IPC4_TYPE_MU_LAW 6 52 53 /* Node index and mask applicable for host copier and ALH/HDA type DAI copiers */ 54 #define SOF_IPC4_NODE_INDEX_MASK 0xFF 55 #define SOF_IPC4_NODE_INDEX(x) ((x) & SOF_IPC4_NODE_INDEX_MASK) 56 #define SOF_IPC4_NODE_TYPE(x) ((x) << 8) 57 #define SOF_IPC4_GET_NODE_TYPE(node_id) ((node_id) >> 8) 58 59 /* Node ID for SSP type DAI copiers */ 60 #define SOF_IPC4_NODE_INDEX_INTEL_SSP(x) (((x) & 0xf) << 4) 61 62 /* Node ID for DMIC type DAI copiers */ 63 #define SOF_IPC4_NODE_INDEX_INTEL_DMIC(x) ((x) & 0x7) 64 65 #define SOF_IPC4_GAIN_ALL_CHANNELS_MASK 0xffffffff 66 #define SOF_IPC4_VOL_ZERO_DB 0x7fffffff 67 68 #define SOF_IPC4_DMA_DEVICE_MAX_COUNT 16 69 70 #define SOF_IPC4_CHAIN_DMA_NODE_ID 0x7fffffff 71 #define SOF_IPC4_INVALID_NODE_ID 0xffffffff 72 73 /* FW requires minimum 4ms DMA buffer size */ 74 #define SOF_IPC4_MIN_DMA_BUFFER_SIZE 4 75 76 /* ChainDMA in fw uses 5ms DMA buffer */ 77 #define SOF_IPC4_CHAIN_DMA_BUFFER_SIZE 5 78 79 /* 80 * The base of multi-gateways. Multi-gateways addressing starts from 81 * ALH_MULTI_GTW_BASE and there are ALH_MULTI_GTW_COUNT multi-sources 82 * and ALH_MULTI_GTW_COUNT multi-sinks available. 83 * Addressing is continuous from ALH_MULTI_GTW_BASE to 84 * ALH_MULTI_GTW_BASE + ALH_MULTI_GTW_COUNT - 1. 85 */ 86 #define ALH_MULTI_GTW_BASE 0x50 87 /* A magic number from FW */ 88 #define ALH_MULTI_GTW_COUNT 8 89 90 enum sof_ipc4_copier_module_config_params { 91 /* 92 * Use LARGE_CONFIG_SET to initialize timestamp event. Ipc mailbox must 93 * contain properly built CopierConfigTimestampInitData struct. 94 */ 95 SOF_IPC4_COPIER_MODULE_CFG_PARAM_TIMESTAMP_INIT = 1, 96 /* 97 * Use LARGE_CONFIG_SET to initialize copier sink. Ipc mailbox must contain 98 * properly built CopierConfigSetSinkFormat struct. 99 */ 100 SOF_IPC4_COPIER_MODULE_CFG_PARAM_SET_SINK_FORMAT, 101 /* 102 * Use LARGE_CONFIG_SET to initialize and enable on Copier data segment 103 * event. Ipc mailbox must contain properly built DataSegmentEnabled struct. 104 */ 105 SOF_IPC4_COPIER_MODULE_CFG_PARAM_DATA_SEGMENT_ENABLED, 106 /* 107 * Use LARGE_CONFIG_GET to retrieve Linear Link Position (LLP) value for non 108 * HD-A gateways. 109 */ 110 SOF_IPC4_COPIER_MODULE_CFG_PARAM_LLP_READING, 111 /* 112 * Use LARGE_CONFIG_GET to retrieve Linear Link Position (LLP) value for non 113 * HD-A gateways and corresponding total processed data 114 */ 115 SOF_IPC4_COPIER_MODULE_CFG_PARAM_LLP_READING_EXTENDED, 116 /* 117 * Use LARGE_CONFIG_SET to setup attenuation on output pins. Data is just uint32_t. 118 * note Config is only allowed when output pin is set up for 32bit and source 119 * is connected to Gateway 120 */ 121 SOF_IPC4_COPIER_MODULE_CFG_ATTENUATION, 122 }; 123 124 /* Scheduling domain, unset, Low Latency, or Data Processing */ 125 enum sof_comp_domain { 126 SOF_COMP_DOMAIN_UNSET = 0, /* Take domain value from manifest */ 127 SOF_COMP_DOMAIN_LL, /* Low Latency scheduling domain */ 128 SOF_COMP_DOMAIN_DP, /* Data Processing scheduling domain */ 129 }; 130 131 struct sof_ipc4_copier_config_set_sink_format { 132 /* Id of sink */ 133 u32 sink_id; 134 /* 135 * Input format used by the source 136 * attention must be the same as present if already initialized. 137 */ 138 struct sof_ipc4_audio_format source_fmt; 139 /* Output format used by the sink */ 140 struct sof_ipc4_audio_format sink_fmt; 141 } __packed __aligned(4); 142 143 /** 144 * struct sof_ipc4_pipeline - pipeline config data 145 * @priority: Priority of this pipeline 146 * @lp_mode: Low power mode 147 * @mem_usage: Memory usage 148 * @core_id: Target core for the pipeline 149 * @state: Pipeline state 150 * @use_chain_dma: flag to indicate if the firmware shall use chained DMA 151 * @msg: message structure for pipeline 152 * @skip_during_fe_trigger: skip triggering this pipeline during the FE DAI trigger 153 * @direction_valid: flag indicating if valid direction is set in topology 154 * @direction: pipeline direction set in topology if direction_valid is true 155 */ 156 struct sof_ipc4_pipeline { 157 uint32_t priority; 158 uint32_t lp_mode; 159 uint32_t mem_usage; 160 uint32_t core_id; 161 int state; 162 bool use_chain_dma; 163 struct sof_ipc4_msg msg; 164 bool skip_during_fe_trigger; 165 bool direction_valid; 166 u32 direction; 167 }; 168 169 /** 170 * struct ipc4_pipeline_set_state_data - multi pipeline trigger IPC data 171 * @count: Number of pipelines to be triggered 172 * @pipeline_instance_ids: Flexible array of IDs of the pipelines to be triggered 173 */ 174 struct ipc4_pipeline_set_state_data { 175 u32 count; 176 DECLARE_FLEX_ARRAY(u32, pipeline_instance_ids); 177 } __packed; 178 179 /** 180 * struct sof_ipc4_pin_format - Module pin format 181 * @pin_index: pin index 182 * @buffer_size: buffer size in bytes 183 * @audio_fmt: audio format for the pin 184 * 185 * This structure can be used for both output or input pins and the pin_index is relative to the 186 * pin type i.e output/input pin 187 */ 188 struct sof_ipc4_pin_format { 189 u32 pin_index; 190 u32 buffer_size; 191 struct sof_ipc4_audio_format audio_fmt; 192 }; 193 194 /** 195 * struct sof_ipc4_available_audio_format - Available audio formats 196 * @output_pin_fmts: Available output pin formats 197 * @input_pin_fmts: Available input pin formats 198 * @num_input_formats: Number of input pin formats 199 * @num_output_formats: Number of output pin formats 200 * @changed_params: Mask of changed params by the module instance between it's 201 * input and output formts (rate, channels, depth) 202 */ 203 struct sof_ipc4_available_audio_format { 204 struct sof_ipc4_pin_format *output_pin_fmts; 205 struct sof_ipc4_pin_format *input_pin_fmts; 206 u32 num_input_formats; 207 u32 num_output_formats; 208 u32 changed_params; 209 }; 210 211 /** 212 * struct sof_copier_gateway_cfg - IPC gateway configuration 213 * @node_id: ID of Gateway Node 214 * @dma_buffer_size: Preferred Gateway DMA buffer size (in bytes) 215 * @config_length: Length of gateway node configuration blob specified in #config_data 216 * @config_data: Gateway node configuration blob 217 */ 218 struct sof_copier_gateway_cfg { 219 uint32_t node_id; 220 uint32_t dma_buffer_size; 221 uint32_t config_length; 222 uint32_t config_data[]; 223 }; 224 225 /** 226 * struct sof_ipc4_copier_data - IPC data for copier 227 * @base_config: Base configuration including input audio format 228 * @out_format: Output audio format 229 * @copier_feature_mask: Copier feature mask 230 * @gtw_cfg: Gateway configuration 231 */ 232 struct sof_ipc4_copier_data { 233 struct sof_ipc4_base_module_cfg base_config; 234 struct sof_ipc4_audio_format out_format; 235 uint32_t copier_feature_mask; 236 struct sof_copier_gateway_cfg gtw_cfg; 237 }; 238 239 /** 240 * struct sof_ipc4_gtw_attributes: Gateway attributes 241 * @lp_buffer_alloc: Gateway data requested in low power memory 242 * @alloc_from_reg_file: Gateway data requested in register file memory 243 * @rsvd: reserved for future use 244 */ 245 struct sof_ipc4_gtw_attributes { 246 uint32_t lp_buffer_alloc : 1; 247 uint32_t alloc_from_reg_file : 1; 248 uint32_t rsvd : 30; 249 }; 250 251 /** 252 * struct sof_ipc4_dma_device_stream_ch_map: abstract representation of 253 * channel mapping to DMAs 254 * @device: representation of hardware device address or FIFO 255 * @channel_mask: channels handled by @device. Channels are expected to be 256 * contiguous 257 */ 258 struct sof_ipc4_dma_device_stream_ch_map { 259 uint32_t device; 260 uint32_t channel_mask; 261 }; 262 263 /** 264 * struct sof_ipc4_dma_stream_ch_map: DMA configuration data 265 * @device_count: Number valid items in mapping array 266 * @mapping: device address and channel mask 267 */ 268 struct sof_ipc4_dma_stream_ch_map { 269 uint32_t device_count; 270 struct sof_ipc4_dma_device_stream_ch_map mapping[SOF_IPC4_DMA_DEVICE_MAX_COUNT]; 271 } __packed; 272 273 #define SOF_IPC4_DMA_METHOD_HDA 1 274 #define SOF_IPC4_DMA_METHOD_GPDMA 2 /* defined for consistency but not used */ 275 276 #define SOF_IPC4_CHAIN_DMA_BUF_SIZE_MS 2 277 278 /** 279 * struct sof_ipc4_dma_config: DMA configuration 280 * @dma_method: HDAudio or GPDMA 281 * @pre_allocated_by_host: 1 if host driver allocates DMA channels, 0 otherwise 282 * @dma_channel_id: for HDaudio defined as @stream_id - 1 283 * @stream_id: HDaudio stream tag 284 * @dma_stream_channel_map: array of device/channel mappings 285 * @dma_priv_config_size: currently not used 286 * @dma_priv_config: currently not used 287 */ 288 struct sof_ipc4_dma_config { 289 uint8_t dma_method; 290 uint8_t pre_allocated_by_host; 291 /* private: */ 292 uint16_t rsvd; 293 /* public: */ 294 uint32_t dma_channel_id; 295 uint32_t stream_id; 296 struct sof_ipc4_dma_stream_ch_map dma_stream_channel_map; 297 uint32_t dma_priv_config_size; 298 uint8_t dma_priv_config[]; 299 } __packed; 300 301 #define SOF_IPC4_GTW_DMA_CONFIG_ID 0x1000 302 303 /** 304 * struct sof_ipc4_dma_config_tlv - DMA configuration 305 * @type: set to SOF_IPC4_GTW_DMA_CONFIG_ID 306 * @length: sizeof(struct sof_ipc4_dma_config) + dma_config.dma_priv_config_size 307 * @dma_config: actual DMA configuration 308 */ 309 struct sof_ipc4_dma_config_tlv { 310 uint32_t type; 311 uint32_t length; 312 struct sof_ipc4_dma_config dma_config; 313 } __packed; 314 315 /** struct sof_ipc4_alh_configuration_blob: ALH blob 316 * @gw_attr: Gateway attributes 317 * @alh_cfg: ALH configuration data 318 */ 319 struct sof_ipc4_alh_configuration_blob { 320 struct sof_ipc4_gtw_attributes gw_attr; 321 struct sof_ipc4_dma_stream_ch_map alh_cfg; 322 }; 323 324 /** 325 * struct sof_ipc4_copier - copier config data 326 * @data: IPC copier data 327 * @copier_config: Copier + blob 328 * @ipc_config_size: Size of copier_config 329 * @ipc_config_data: Copier module config data 330 * @available_fmt: Available audio format 331 * @frame_fmt: frame format 332 * @msg: message structure for copier 333 * @gtw_attr: Gateway attributes for copier blob 334 * @dai_type: DAI type 335 * @dai_index: DAI index 336 * @dma_config_tlv: DMA configuration 337 */ 338 struct sof_ipc4_copier { 339 struct sof_ipc4_copier_data data; 340 u32 *copier_config; 341 uint32_t ipc_config_size; 342 void *ipc_config_data; 343 struct sof_ipc4_available_audio_format available_fmt; 344 u32 frame_fmt; 345 struct sof_ipc4_msg msg; 346 struct sof_ipc4_gtw_attributes *gtw_attr; 347 u32 dai_type; 348 int dai_index; 349 struct sof_ipc4_dma_config_tlv dma_config_tlv[SOF_IPC4_DMA_DEVICE_MAX_COUNT]; 350 }; 351 352 /** 353 * struct sof_ipc4_ctrl_value_chan: generic channel mapped value data 354 * @channel: Channel ID 355 * @value: Value associated with @channel 356 */ 357 struct sof_ipc4_ctrl_value_chan { 358 u32 channel; 359 u32 value; 360 }; 361 362 /** 363 * struct sof_ipc4_control_data - IPC data for kcontrol IO 364 * @msg: message structure for kcontrol IO 365 * @index: pipeline ID 366 * @chanv: channel ID and value array used by volume type controls 367 * @data: data for binary kcontrols 368 */ 369 struct sof_ipc4_control_data { 370 struct sof_ipc4_msg msg; 371 int index; 372 373 union { 374 DECLARE_FLEX_ARRAY(struct sof_ipc4_ctrl_value_chan, chanv); 375 DECLARE_FLEX_ARRAY(struct sof_abi_hdr, data); 376 }; 377 }; 378 379 #define SOF_IPC4_SWITCH_CONTROL_PARAM_ID 200 380 #define SOF_IPC4_ENUM_CONTROL_PARAM_ID 201 381 #define SOF_IPC4_BYTES_CONTROL_PARAM_ID 202 382 383 /** 384 * struct sof_ipc4_control_msg_payload - IPC payload for kcontrol parameters 385 * @id: unique id of the control 386 * @num_elems: Number of elements in the chanv array or number of bytes in data 387 * @reserved: reserved for future use, must be set to 0 388 * @chanv: channel ID and value array 389 * @data: binary payload 390 */ 391 struct sof_ipc4_control_msg_payload { 392 uint16_t id; 393 uint16_t num_elems; 394 uint32_t reserved[4]; 395 union { 396 DECLARE_FLEX_ARRAY(struct sof_ipc4_ctrl_value_chan, chanv); 397 DECLARE_FLEX_ARRAY(uint8_t, data); 398 }; 399 } __packed; 400 401 /** 402 * struct sof_ipc4_gain_params - IPC gain parameters 403 * @channels: Channels 404 * @init_val: Initial value 405 * @curve_type: Curve type 406 * @reserved: reserved for future use 407 * @curve_duration_l: Curve duration low part 408 * @curve_duration_h: Curve duration high part 409 */ 410 struct sof_ipc4_gain_params { 411 uint32_t channels; 412 uint32_t init_val; 413 uint32_t curve_type; 414 uint32_t reserved; 415 uint32_t curve_duration_l; 416 uint32_t curve_duration_h; 417 } __packed __aligned(4); 418 419 /** 420 * struct sof_ipc4_gain_data - IPC gain init blob 421 * @base_config: IPC base config data 422 * @params: Initial parameters for the gain module 423 */ 424 struct sof_ipc4_gain_data { 425 struct sof_ipc4_base_module_cfg base_config; 426 struct sof_ipc4_gain_params params; 427 } __packed __aligned(4); 428 429 /** 430 * struct sof_ipc4_gain - gain config data 431 * @data: IPC gain blob 432 * @available_fmt: Available audio format 433 * @msg: message structure for gain 434 */ 435 struct sof_ipc4_gain { 436 struct sof_ipc4_gain_data data; 437 struct sof_ipc4_available_audio_format available_fmt; 438 struct sof_ipc4_msg msg; 439 }; 440 441 /** 442 * struct sof_ipc4_mixer - mixer config data 443 * @base_config: IPC base config data 444 * @available_fmt: Available audio format 445 * @msg: IPC4 message struct containing header and data info 446 */ 447 struct sof_ipc4_mixer { 448 struct sof_ipc4_base_module_cfg base_config; 449 struct sof_ipc4_available_audio_format available_fmt; 450 struct sof_ipc4_msg msg; 451 }; 452 453 /* 454 * struct sof_ipc4_src_data - IPC data for SRC 455 * @base_config: IPC base config data 456 * @sink_rate: Output rate for sink module 457 */ 458 struct sof_ipc4_src_data { 459 struct sof_ipc4_base_module_cfg base_config; 460 uint32_t sink_rate; 461 } __packed __aligned(4); 462 463 /** 464 * struct sof_ipc4_src - SRC config data 465 * @data: IPC base config data 466 * @available_fmt: Available audio format 467 * @msg: IPC4 message struct containing header and data info 468 */ 469 struct sof_ipc4_src { 470 struct sof_ipc4_src_data data; 471 struct sof_ipc4_available_audio_format available_fmt; 472 struct sof_ipc4_msg msg; 473 }; 474 475 /* 476 * struct sof_ipc4_asrc_data - IPC data for ASRC 477 * @base_config: IPC base config data 478 * @out_freq: Output rate for sink module, passed as such from topology to FW. 479 * @asrc_mode: Control for ASRC features with bit-fields, passed as such from topolgy to FW. 480 */ 481 struct sof_ipc4_asrc_data { 482 struct sof_ipc4_base_module_cfg base_config; 483 uint32_t out_freq; 484 uint32_t asrc_mode; 485 } __packed __aligned(4); 486 487 /** 488 * struct sof_ipc4_asrc - ASRC config data 489 * @data: IPC base config data 490 * @available_fmt: Available audio format 491 * @msg: IPC4 message struct containing header and data info 492 */ 493 struct sof_ipc4_asrc { 494 struct sof_ipc4_asrc_data data; 495 struct sof_ipc4_available_audio_format available_fmt; 496 struct sof_ipc4_msg msg; 497 }; 498 499 /** 500 * struct sof_ipc4_base_module_cfg_ext - base module config extension containing the pin format 501 * information for the module. Both @num_input_pin_fmts and @num_output_pin_fmts cannot be 0 for a 502 * module. 503 * @num_input_pin_fmts: number of input pin formats in the @pin_formats array 504 * @num_output_pin_fmts: number of output pin formats in the @pin_formats array 505 * @reserved: reserved for future use 506 * @pin_formats: flexible array consisting of @num_input_pin_fmts input pin format items followed 507 * by @num_output_pin_fmts output pin format items 508 */ 509 struct sof_ipc4_base_module_cfg_ext { 510 u16 num_input_pin_fmts; 511 u16 num_output_pin_fmts; 512 u8 reserved[12]; 513 DECLARE_FLEX_ARRAY(struct sof_ipc4_pin_format, pin_formats); 514 } __packed; 515 516 /** 517 * struct sof_ipc4_process - process config data 518 * @base_config: IPC base config data 519 * @base_config_ext: Base config extension data for module init 520 * @output_format: Output audio format 521 * @available_fmt: Available audio format 522 * @ipc_config_data: Process module config data 523 * @ipc_config_size: Size of process module config data 524 * @msg: IPC4 message struct containing header and data info 525 * @base_config_ext_size: Size of the base config extension data in bytes 526 * @init_config: Module init config type (SOF_IPC4_MODULE_INIT_CONFIG_TYPE_*) 527 */ 528 struct sof_ipc4_process { 529 struct sof_ipc4_base_module_cfg base_config; 530 struct sof_ipc4_base_module_cfg_ext *base_config_ext; 531 struct sof_ipc4_audio_format output_format; 532 struct sof_ipc4_available_audio_format available_fmt; 533 void *ipc_config_data; 534 uint32_t ipc_config_size; 535 struct sof_ipc4_msg msg; 536 u32 base_config_ext_size; 537 u32 init_config; 538 }; 539 540 bool sof_ipc4_copier_is_single_bitdepth(struct snd_sof_dev *sdev, 541 struct sof_ipc4_pin_format *pin_fmts, 542 u32 pin_fmts_size); 543 #endif 544