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