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