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 sof_ipc4_multi_pipeline_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 */ 201 struct sof_ipc4_available_audio_format { 202 struct sof_ipc4_pin_format *output_pin_fmts; 203 struct sof_ipc4_pin_format *input_pin_fmts; 204 u32 num_input_formats; 205 u32 num_output_formats; 206 }; 207 208 /** 209 * struct sof_copier_gateway_cfg - IPC gateway configuration 210 * @node_id: ID of Gateway Node 211 * @dma_buffer_size: Preferred Gateway DMA buffer size (in bytes) 212 * @config_length: Length of gateway node configuration blob specified in #config_data 213 * config_data: Gateway node configuration blob 214 */ 215 struct sof_copier_gateway_cfg { 216 uint32_t node_id; 217 uint32_t dma_buffer_size; 218 uint32_t config_length; 219 uint32_t config_data[]; 220 }; 221 222 /** 223 * struct sof_ipc4_copier_data - IPC data for copier 224 * @base_config: Base configuration including input audio format 225 * @out_format: Output audio format 226 * @copier_feature_mask: Copier feature mask 227 * @gtw_cfg: Gateway configuration 228 */ 229 struct sof_ipc4_copier_data { 230 struct sof_ipc4_base_module_cfg base_config; 231 struct sof_ipc4_audio_format out_format; 232 uint32_t copier_feature_mask; 233 struct sof_copier_gateway_cfg gtw_cfg; 234 }; 235 236 /** 237 * struct sof_ipc4_gtw_attributes: Gateway attributes 238 * @lp_buffer_alloc: Gateway data requested in low power memory 239 * @alloc_from_reg_file: Gateway data requested in register file memory 240 * @rsvd: reserved for future use 241 */ 242 struct sof_ipc4_gtw_attributes { 243 uint32_t lp_buffer_alloc : 1; 244 uint32_t alloc_from_reg_file : 1; 245 uint32_t rsvd : 30; 246 }; 247 248 /** 249 * struct sof_ipc4_dma_device_stream_ch_map: abstract representation of 250 * channel mapping to DMAs 251 * @device: representation of hardware device address or FIFO 252 * @channel_mask: channels handled by @device. Channels are expected to be 253 * contiguous 254 */ 255 struct sof_ipc4_dma_device_stream_ch_map { 256 uint32_t device; 257 uint32_t channel_mask; 258 }; 259 260 /** 261 * struct sof_ipc4_dma_stream_ch_map: DMA configuration data 262 * @device_count: Number valid items in mapping array 263 * @mapping: device address and channel mask 264 */ 265 struct sof_ipc4_dma_stream_ch_map { 266 uint32_t device_count; 267 struct sof_ipc4_dma_device_stream_ch_map mapping[SOF_IPC4_DMA_DEVICE_MAX_COUNT]; 268 } __packed; 269 270 #define SOF_IPC4_DMA_METHOD_HDA 1 271 #define SOF_IPC4_DMA_METHOD_GPDMA 2 /* defined for consistency but not used */ 272 273 #define SOF_IPC4_CHAIN_DMA_BUF_SIZE_MS 2 274 275 /** 276 * struct sof_ipc4_dma_config: DMA configuration 277 * @dma_method: HDAudio or GPDMA 278 * @pre_allocated_by_host: 1 if host driver allocates DMA channels, 0 otherwise 279 * @dma_channel_id: for HDaudio defined as @stream_id - 1 280 * @stream_id: HDaudio stream tag 281 * @dma_stream_channel_map: array of device/channel mappings 282 * @dma_priv_config_size: currently not used 283 * @dma_priv_config: currently not used 284 */ 285 struct sof_ipc4_dma_config { 286 uint8_t dma_method; 287 uint8_t pre_allocated_by_host; 288 uint16_t rsvd; 289 uint32_t dma_channel_id; 290 uint32_t stream_id; 291 struct sof_ipc4_dma_stream_ch_map dma_stream_channel_map; 292 uint32_t dma_priv_config_size; 293 uint8_t dma_priv_config[]; 294 } __packed; 295 296 #define SOF_IPC4_GTW_DMA_CONFIG_ID 0x1000 297 298 /** 299 * struct sof_ipc4_dma_config: DMA configuration 300 * @type: set to SOF_IPC4_GTW_DMA_CONFIG_ID 301 * @length: sizeof(struct sof_ipc4_dma_config) + dma_config.dma_priv_config_size 302 * @dma_config: actual DMA configuration 303 */ 304 struct sof_ipc4_dma_config_tlv { 305 uint32_t type; 306 uint32_t length; 307 struct sof_ipc4_dma_config dma_config; 308 } __packed; 309 310 /** struct sof_ipc4_alh_configuration_blob: ALH blob 311 * @gw_attr: Gateway attributes 312 * @alh_cfg: ALH configuration data 313 */ 314 struct sof_ipc4_alh_configuration_blob { 315 struct sof_ipc4_gtw_attributes gw_attr; 316 struct sof_ipc4_dma_stream_ch_map alh_cfg; 317 }; 318 319 /** 320 * struct sof_ipc4_copier - copier config data 321 * @data: IPC copier data 322 * @copier_config: Copier + blob 323 * @ipc_config_size: Size of copier_config 324 * @available_fmt: Available audio format 325 * @frame_fmt: frame format 326 * @msg: message structure for copier 327 * @gtw_attr: Gateway attributes for copier blob 328 * @dai_type: DAI type 329 * @dai_index: DAI index 330 * @dma_config_tlv: DMA configuration 331 */ 332 struct sof_ipc4_copier { 333 struct sof_ipc4_copier_data data; 334 u32 *copier_config; 335 uint32_t ipc_config_size; 336 void *ipc_config_data; 337 struct sof_ipc4_available_audio_format available_fmt; 338 u32 frame_fmt; 339 struct sof_ipc4_msg msg; 340 struct sof_ipc4_gtw_attributes *gtw_attr; 341 u32 dai_type; 342 int dai_index; 343 struct sof_ipc4_dma_config_tlv dma_config_tlv[SOF_IPC4_DMA_DEVICE_MAX_COUNT]; 344 }; 345 346 /** 347 * struct sof_ipc4_ctrl_value_chan: generic channel mapped value data 348 * @channel: Channel ID 349 * @value: Value associated with @channel 350 */ 351 struct sof_ipc4_ctrl_value_chan { 352 u32 channel; 353 u32 value; 354 }; 355 356 /** 357 * struct sof_ipc4_control_data - IPC data for kcontrol IO 358 * @msg: message structure for kcontrol IO 359 * @index: pipeline ID 360 * @chanv: channel ID and value array used by volume type controls 361 * @data: data for binary kcontrols 362 */ 363 struct sof_ipc4_control_data { 364 struct sof_ipc4_msg msg; 365 int index; 366 367 union { 368 DECLARE_FLEX_ARRAY(struct sof_ipc4_ctrl_value_chan, chanv); 369 DECLARE_FLEX_ARRAY(struct sof_abi_hdr, data); 370 }; 371 }; 372 373 #define SOF_IPC4_SWITCH_CONTROL_PARAM_ID 200 374 #define SOF_IPC4_ENUM_CONTROL_PARAM_ID 201 375 #define SOF_IPC4_BYTES_CONTROL_PARAM_ID 202 376 377 /** 378 * struct sof_ipc4_control_msg_payload - IPC payload for kcontrol parameters 379 * @id: unique id of the control 380 * @num_elems: Number of elements in the chanv array or number of bytes in data 381 * @reserved: reserved for future use, must be set to 0 382 * @chanv: channel ID and value array 383 * @data: binary payload 384 */ 385 struct sof_ipc4_control_msg_payload { 386 uint16_t id; 387 uint16_t num_elems; 388 uint32_t reserved[4]; 389 union { 390 DECLARE_FLEX_ARRAY(struct sof_ipc4_ctrl_value_chan, chanv); 391 DECLARE_FLEX_ARRAY(uint8_t, data); 392 }; 393 } __packed; 394 395 /** 396 * struct sof_ipc4_gain_params - IPC gain parameters 397 * @channels: Channels 398 * @init_val: Initial value 399 * @curve_type: Curve type 400 * @reserved: reserved for future use 401 * @curve_duration_l: Curve duration low part 402 * @curve_duration_h: Curve duration high part 403 */ 404 struct sof_ipc4_gain_params { 405 uint32_t channels; 406 uint32_t init_val; 407 uint32_t curve_type; 408 uint32_t reserved; 409 uint32_t curve_duration_l; 410 uint32_t curve_duration_h; 411 } __packed __aligned(4); 412 413 /** 414 * struct sof_ipc4_gain_data - IPC gain init blob 415 * @base_config: IPC base config data 416 * @params: Initial parameters for the gain module 417 */ 418 struct sof_ipc4_gain_data { 419 struct sof_ipc4_base_module_cfg base_config; 420 struct sof_ipc4_gain_params params; 421 } __packed __aligned(4); 422 423 /** 424 * struct sof_ipc4_gain - gain config data 425 * @data: IPC gain blob 426 * @available_fmt: Available audio format 427 * @msg: message structure for gain 428 */ 429 struct sof_ipc4_gain { 430 struct sof_ipc4_gain_data data; 431 struct sof_ipc4_available_audio_format available_fmt; 432 struct sof_ipc4_msg msg; 433 }; 434 435 /** 436 * struct sof_ipc4_mixer - mixer config data 437 * @base_config: IPC base config data 438 * @available_fmt: Available audio format 439 * @msg: IPC4 message struct containing header and data info 440 */ 441 struct sof_ipc4_mixer { 442 struct sof_ipc4_base_module_cfg base_config; 443 struct sof_ipc4_available_audio_format available_fmt; 444 struct sof_ipc4_msg msg; 445 }; 446 447 /* 448 * struct sof_ipc4_src_data - IPC data for SRC 449 * @base_config: IPC base config data 450 * @sink_rate: Output rate for sink module 451 */ 452 struct sof_ipc4_src_data { 453 struct sof_ipc4_base_module_cfg base_config; 454 uint32_t sink_rate; 455 } __packed __aligned(4); 456 457 /** 458 * struct sof_ipc4_src - SRC config data 459 * @data: IPC base config data 460 * @available_fmt: Available audio format 461 * @msg: IPC4 message struct containing header and data info 462 */ 463 struct sof_ipc4_src { 464 struct sof_ipc4_src_data data; 465 struct sof_ipc4_available_audio_format available_fmt; 466 struct sof_ipc4_msg msg; 467 }; 468 469 /* 470 * struct sof_ipc4_asrc_data - IPC data for ASRC 471 * @base_config: IPC base config data 472 * @out_freq: Output rate for sink module, passed as such from topology to FW. 473 * @asrc_mode: Control for ASRC features with bit-fields, passed as such from topolgy to FW. 474 */ 475 struct sof_ipc4_asrc_data { 476 struct sof_ipc4_base_module_cfg base_config; 477 uint32_t out_freq; 478 uint32_t asrc_mode; 479 } __packed __aligned(4); 480 481 /** 482 * struct sof_ipc4_asrc - ASRC config data 483 * @data: IPC base config data 484 * @available_fmt: Available audio format 485 * @msg: IPC4 message struct containing header and data info 486 */ 487 struct sof_ipc4_asrc { 488 struct sof_ipc4_asrc_data data; 489 struct sof_ipc4_available_audio_format available_fmt; 490 struct sof_ipc4_msg msg; 491 }; 492 493 /** 494 * struct sof_ipc4_base_module_cfg_ext - base module config extension containing the pin format 495 * information for the module. Both @num_input_pin_fmts and @num_output_pin_fmts cannot be 0 for a 496 * module. 497 * @num_input_pin_fmts: number of input pin formats in the @pin_formats array 498 * @num_output_pin_fmts: number of output pin formats in the @pin_formats array 499 * @reserved: reserved for future use 500 * @pin_formats: flexible array consisting of @num_input_pin_fmts input pin format items followed 501 * by @num_output_pin_fmts output pin format items 502 */ 503 struct sof_ipc4_base_module_cfg_ext { 504 u16 num_input_pin_fmts; 505 u16 num_output_pin_fmts; 506 u8 reserved[12]; 507 DECLARE_FLEX_ARRAY(struct sof_ipc4_pin_format, pin_formats); 508 } __packed; 509 510 /** 511 * struct sof_ipc4_process - process config data 512 * @base_config: IPC base config data 513 * @base_config_ext: Base config extension data for module init 514 * @output_format: Output audio format 515 * @available_fmt: Available audio format 516 * @ipc_config_data: Process module config data 517 * @ipc_config_size: Size of process module config data 518 * @msg: IPC4 message struct containing header and data info 519 * @base_config_ext_size: Size of the base config extension data in bytes 520 * @init_config: Module init config type (SOF_IPC4_MODULE_INIT_CONFIG_TYPE_*) 521 */ 522 struct sof_ipc4_process { 523 struct sof_ipc4_base_module_cfg base_config; 524 struct sof_ipc4_base_module_cfg_ext *base_config_ext; 525 struct sof_ipc4_audio_format output_format; 526 struct sof_ipc4_available_audio_format available_fmt; 527 void *ipc_config_data; 528 uint32_t ipc_config_size; 529 struct sof_ipc4_msg msg; 530 u32 base_config_ext_size; 531 u32 init_config; 532 }; 533 534 bool sof_ipc4_copier_is_single_bitdepth(struct snd_sof_dev *sdev, 535 struct sof_ipc4_pin_format *pin_fmts, 536 u32 pin_fmts_size); 537 #endif 538