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) 2018 Intel Corporation. All rights reserved. 7 * 8 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> 9 */ 10 11 #ifndef __SOUND_SOC_SOF_PRIV_H 12 #define __SOUND_SOC_SOF_PRIV_H 13 14 #include <linux/device.h> 15 #include <sound/hdaudio.h> 16 #include <sound/sof.h> 17 #include <sound/sof/info.h> 18 #include <sound/sof/pm.h> 19 #include <sound/sof/trace.h> 20 #include <uapi/sound/sof/fw.h> 21 #include <sound/sof/ext_manifest.h> 22 23 struct snd_sof_pcm_stream; 24 25 /* Flag definitions used in sof_core_debug (sof_debug module parameter) */ 26 #define SOF_DBG_ENABLE_TRACE BIT(0) 27 #define SOF_DBG_RETAIN_CTX BIT(1) /* prevent DSP D3 on FW exception */ 28 #define SOF_DBG_VERIFY_TPLG BIT(2) /* verify topology during load */ 29 #define SOF_DBG_DYNAMIC_PIPELINES_OVERRIDE BIT(3) /* 0: use topology token 30 * 1: override topology 31 */ 32 #define SOF_DBG_DYNAMIC_PIPELINES_ENABLE BIT(4) /* 0: use static pipelines 33 * 1: use dynamic pipelines 34 */ 35 #define SOF_DBG_DISABLE_MULTICORE BIT(5) /* schedule all pipelines/widgets 36 * on primary core 37 */ 38 #define SOF_DBG_PRINT_ALL_DUMPS BIT(6) /* Print all ipc and dsp dumps */ 39 #define SOF_DBG_IGNORE_D3_PERSISTENT BIT(7) /* ignore the DSP D3 persistent capability 40 * and always download firmware upon D3 exit 41 */ 42 #define SOF_DBG_PRINT_DMA_POSITION_UPDATE_LOGS BIT(8) /* print DMA position updates 43 * in dmesg logs 44 */ 45 #define SOF_DBG_PRINT_IPC_SUCCESS_LOGS BIT(9) /* print IPC success 46 * in dmesg logs 47 */ 48 #define SOF_DBG_FORCE_NOCODEC BIT(10) /* ignore all codec-related 49 * configurations 50 */ 51 52 /* Flag definitions used for controlling the DSP dump behavior */ 53 #define SOF_DBG_DUMP_REGS BIT(0) 54 #define SOF_DBG_DUMP_MBOX BIT(1) 55 #define SOF_DBG_DUMP_TEXT BIT(2) 56 #define SOF_DBG_DUMP_PCI BIT(3) 57 /* Output this dump (at the DEBUG level) only when SOF_DBG_PRINT_ALL_DUMPS is set */ 58 #define SOF_DBG_DUMP_OPTIONAL BIT(4) 59 60 /* global debug state set by SOF_DBG_ flags */ 61 bool sof_debug_check_flag(int mask); 62 63 /* max BARs mmaped devices can use */ 64 #define SND_SOF_BARS 8 65 66 /* time in ms for runtime suspend delay */ 67 #define SND_SOF_SUSPEND_DELAY_MS 2000 68 69 /* DMA buffer size for trace */ 70 #define DMA_BUF_SIZE_FOR_TRACE (PAGE_SIZE * 16) 71 72 #define SOF_IPC_DSP_REPLY 0 73 #define SOF_IPC_HOST_REPLY 1 74 75 /* convenience constructor for DAI driver streams */ 76 #define SOF_DAI_STREAM(sname, scmin, scmax, srates, sfmt) \ 77 {.stream_name = sname, .channels_min = scmin, .channels_max = scmax, \ 78 .rates = srates, .formats = sfmt} 79 80 #define SOF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \ 81 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT) 82 83 /* So far the primary core on all DSPs has ID 0 */ 84 #define SOF_DSP_PRIMARY_CORE 0 85 86 /* max number of DSP cores */ 87 #define SOF_MAX_DSP_NUM_CORES 8 88 89 struct sof_dsp_power_state { 90 u32 state; 91 u32 substate; /* platform-specific */ 92 }; 93 94 /* System suspend target state */ 95 enum sof_system_suspend_state { 96 SOF_SUSPEND_NONE = 0, 97 SOF_SUSPEND_S0IX, 98 SOF_SUSPEND_S3, 99 SOF_SUSPEND_S4, 100 SOF_SUSPEND_S5, 101 }; 102 103 enum sof_dfsentry_type { 104 SOF_DFSENTRY_TYPE_IOMEM = 0, 105 SOF_DFSENTRY_TYPE_BUF, 106 }; 107 108 enum sof_debugfs_access_type { 109 SOF_DEBUGFS_ACCESS_ALWAYS = 0, 110 SOF_DEBUGFS_ACCESS_D0_ONLY, 111 }; 112 113 struct sof_compr_stream { 114 u64 copied_total; 115 u32 sampling_rate; 116 u16 channels; 117 u16 sample_container_bytes; 118 }; 119 120 struct snd_sof_dev; 121 struct snd_sof_ipc_msg; 122 struct snd_sof_ipc; 123 struct snd_sof_debugfs_map; 124 struct snd_soc_tplg_ops; 125 struct snd_soc_component; 126 struct snd_sof_pdata; 127 128 /** 129 * struct snd_sof_platform_stream_params - platform dependent stream parameters 130 * @stream_tag: Stream tag to use 131 * @use_phy_addr: Use the provided @phy_addr for configuration 132 * @phy_addr: Platform dependent address to be used, if @use_phy_addr 133 * is true 134 * @no_ipc_position: Disable position update IPC from firmware 135 */ 136 struct snd_sof_platform_stream_params { 137 u16 stream_tag; 138 bool use_phy_address; 139 u32 phy_addr; 140 bool no_ipc_position; 141 bool cont_update_posn; 142 }; 143 144 /** 145 * struct sof_firmware - Container struct for SOF firmware 146 * @fw: Pointer to the firmware 147 * @payload_offset: Offset of the data within the loaded firmware image to be 148 * loaded to the DSP (skipping for example ext_manifest section) 149 */ 150 struct sof_firmware { 151 const struct firmware *fw; 152 u32 payload_offset; 153 }; 154 155 /* 156 * SOF DSP HW abstraction operations. 157 * Used to abstract DSP HW architecture and any IO busses between host CPU 158 * and DSP device(s). 159 */ 160 struct snd_sof_dsp_ops { 161 162 /* probe/remove/shutdown */ 163 int (*probe)(struct snd_sof_dev *sof_dev); /* mandatory */ 164 int (*remove)(struct snd_sof_dev *sof_dev); /* optional */ 165 int (*shutdown)(struct snd_sof_dev *sof_dev); /* optional */ 166 167 /* DSP core boot / reset */ 168 int (*run)(struct snd_sof_dev *sof_dev); /* mandatory */ 169 int (*stall)(struct snd_sof_dev *sof_dev, unsigned int core_mask); /* optional */ 170 int (*reset)(struct snd_sof_dev *sof_dev); /* optional */ 171 int (*core_get)(struct snd_sof_dev *sof_dev, int core); /* optional */ 172 int (*core_put)(struct snd_sof_dev *sof_dev, int core); /* optional */ 173 174 /* 175 * Register IO: only used by respective drivers themselves, 176 * TODO: consider removing these operations and calling respective 177 * implementations directly 178 */ 179 void (*write8)(struct snd_sof_dev *sof_dev, void __iomem *addr, 180 u8 value); /* optional */ 181 u8 (*read8)(struct snd_sof_dev *sof_dev, 182 void __iomem *addr); /* optional */ 183 void (*write)(struct snd_sof_dev *sof_dev, void __iomem *addr, 184 u32 value); /* optional */ 185 u32 (*read)(struct snd_sof_dev *sof_dev, 186 void __iomem *addr); /* optional */ 187 void (*write64)(struct snd_sof_dev *sof_dev, void __iomem *addr, 188 u64 value); /* optional */ 189 u64 (*read64)(struct snd_sof_dev *sof_dev, 190 void __iomem *addr); /* optional */ 191 192 /* memcpy IO */ 193 int (*block_read)(struct snd_sof_dev *sof_dev, 194 enum snd_sof_fw_blk_type type, u32 offset, 195 void *dest, size_t size); /* mandatory */ 196 int (*block_write)(struct snd_sof_dev *sof_dev, 197 enum snd_sof_fw_blk_type type, u32 offset, 198 void *src, size_t size); /* mandatory */ 199 200 /* Mailbox IO */ 201 void (*mailbox_read)(struct snd_sof_dev *sof_dev, 202 u32 offset, void *dest, 203 size_t size); /* optional */ 204 void (*mailbox_write)(struct snd_sof_dev *sof_dev, 205 u32 offset, void *src, 206 size_t size); /* optional */ 207 208 /* doorbell */ 209 irqreturn_t (*irq_handler)(int irq, void *context); /* optional */ 210 irqreturn_t (*irq_thread)(int irq, void *context); /* optional */ 211 212 /* ipc */ 213 int (*send_msg)(struct snd_sof_dev *sof_dev, 214 struct snd_sof_ipc_msg *msg); /* mandatory */ 215 216 /* FW loading */ 217 int (*load_firmware)(struct snd_sof_dev *sof_dev); /* mandatory */ 218 int (*load_module)(struct snd_sof_dev *sof_dev, 219 struct snd_sof_mod_hdr *hdr); /* optional */ 220 221 /* connect pcm substream to a host stream */ 222 int (*pcm_open)(struct snd_sof_dev *sdev, 223 struct snd_pcm_substream *substream); /* optional */ 224 /* disconnect pcm substream to a host stream */ 225 int (*pcm_close)(struct snd_sof_dev *sdev, 226 struct snd_pcm_substream *substream); /* optional */ 227 228 /* host stream hw params */ 229 int (*pcm_hw_params)(struct snd_sof_dev *sdev, 230 struct snd_pcm_substream *substream, 231 struct snd_pcm_hw_params *params, 232 struct snd_sof_platform_stream_params *platform_params); /* optional */ 233 234 /* host stream hw_free */ 235 int (*pcm_hw_free)(struct snd_sof_dev *sdev, 236 struct snd_pcm_substream *substream); /* optional */ 237 238 /* host stream trigger */ 239 int (*pcm_trigger)(struct snd_sof_dev *sdev, 240 struct snd_pcm_substream *substream, 241 int cmd); /* optional */ 242 243 /* host stream pointer */ 244 snd_pcm_uframes_t (*pcm_pointer)(struct snd_sof_dev *sdev, 245 struct snd_pcm_substream *substream); /* optional */ 246 247 /* pcm ack */ 248 int (*pcm_ack)(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream); /* optional */ 249 250 /* host read DSP stream data */ 251 int (*ipc_msg_data)(struct snd_sof_dev *sdev, 252 struct snd_sof_pcm_stream *sps, 253 void *p, size_t sz); /* mandatory */ 254 255 /* host side configuration of the stream's data offset in stream mailbox area */ 256 int (*set_stream_data_offset)(struct snd_sof_dev *sdev, 257 struct snd_pcm_substream *substream, 258 size_t posn_offset); /* optional */ 259 260 /* pre/post firmware run */ 261 int (*pre_fw_run)(struct snd_sof_dev *sof_dev); /* optional */ 262 int (*post_fw_run)(struct snd_sof_dev *sof_dev); /* optional */ 263 264 /* parse platform specific extended manifest, optional */ 265 int (*parse_platform_ext_manifest)(struct snd_sof_dev *sof_dev, 266 const struct sof_ext_man_elem_header *hdr); 267 268 /* DSP PM */ 269 int (*suspend)(struct snd_sof_dev *sof_dev, 270 u32 target_state); /* optional */ 271 int (*resume)(struct snd_sof_dev *sof_dev); /* optional */ 272 int (*runtime_suspend)(struct snd_sof_dev *sof_dev); /* optional */ 273 int (*runtime_resume)(struct snd_sof_dev *sof_dev); /* optional */ 274 int (*runtime_idle)(struct snd_sof_dev *sof_dev); /* optional */ 275 int (*set_hw_params_upon_resume)(struct snd_sof_dev *sdev); /* optional */ 276 int (*set_power_state)(struct snd_sof_dev *sdev, 277 const struct sof_dsp_power_state *target_state); /* optional */ 278 279 /* DSP clocking */ 280 int (*set_clk)(struct snd_sof_dev *sof_dev, u32 freq); /* optional */ 281 282 /* debug */ 283 const struct snd_sof_debugfs_map *debug_map; /* optional */ 284 int debug_map_count; /* optional */ 285 void (*dbg_dump)(struct snd_sof_dev *sof_dev, 286 u32 flags); /* optional */ 287 void (*ipc_dump)(struct snd_sof_dev *sof_dev); /* optional */ 288 int (*debugfs_add_region_item)(struct snd_sof_dev *sdev, 289 enum snd_sof_fw_blk_type blk_type, u32 offset, 290 size_t size, const char *name, 291 enum sof_debugfs_access_type access_type); /* optional */ 292 293 /* host DMA trace (IPC3) */ 294 int (*trace_init)(struct snd_sof_dev *sdev, 295 struct snd_dma_buffer *dmatb, 296 struct sof_ipc_dma_trace_params_ext *dtrace_params); /* optional */ 297 int (*trace_release)(struct snd_sof_dev *sdev); /* optional */ 298 int (*trace_trigger)(struct snd_sof_dev *sdev, 299 int cmd); /* optional */ 300 301 /* misc */ 302 int (*get_bar_index)(struct snd_sof_dev *sdev, 303 u32 type); /* optional */ 304 int (*get_mailbox_offset)(struct snd_sof_dev *sdev);/* mandatory for common loader code */ 305 int (*get_window_offset)(struct snd_sof_dev *sdev, 306 u32 id);/* mandatory for common loader code */ 307 308 /* machine driver ops */ 309 int (*machine_register)(struct snd_sof_dev *sdev, 310 void *pdata); /* optional */ 311 void (*machine_unregister)(struct snd_sof_dev *sdev, 312 void *pdata); /* optional */ 313 struct snd_soc_acpi_mach * (*machine_select)(struct snd_sof_dev *sdev); /* optional */ 314 void (*set_mach_params)(struct snd_soc_acpi_mach *mach, 315 struct snd_sof_dev *sdev); /* optional */ 316 317 /* IPC client ops */ 318 int (*register_ipc_clients)(struct snd_sof_dev *sdev); /* optional */ 319 void (*unregister_ipc_clients)(struct snd_sof_dev *sdev); /* optional */ 320 321 /* DAI ops */ 322 struct snd_soc_dai_driver *drv; 323 int num_drv; 324 325 /* ALSA HW info flags, will be stored in snd_pcm_runtime.hw.info */ 326 u32 hw_info; 327 328 const struct dsp_arch_ops *dsp_arch_ops; 329 }; 330 331 /* DSP architecture specific callbacks for oops and stack dumps */ 332 struct dsp_arch_ops { 333 void (*dsp_oops)(struct snd_sof_dev *sdev, const char *level, void *oops); 334 void (*dsp_stack)(struct snd_sof_dev *sdev, const char *level, void *oops, 335 u32 *stack, u32 stack_words); 336 }; 337 338 #define sof_dsp_arch_ops(sdev) ((sdev)->pdata->desc->ops->dsp_arch_ops) 339 340 /* FS entry for debug files that can expose DSP memories, registers */ 341 struct snd_sof_dfsentry { 342 size_t size; 343 size_t buf_data_size; /* length of buffered data for file read operation */ 344 enum sof_dfsentry_type type; 345 /* 346 * access_type specifies if the 347 * memory -> DSP resource (memory, register etc) is always accessible 348 * or if it is accessible only when the DSP is in D0. 349 */ 350 enum sof_debugfs_access_type access_type; 351 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE) 352 char *cache_buf; /* buffer to cache the contents of debugfs memory */ 353 #endif 354 struct snd_sof_dev *sdev; 355 struct list_head list; /* list in sdev dfsentry list */ 356 union { 357 void __iomem *io_mem; 358 void *buf; 359 }; 360 }; 361 362 /* Debug mapping for any DSP memory or registers that can used for debug */ 363 struct snd_sof_debugfs_map { 364 const char *name; 365 u32 bar; 366 u32 offset; 367 u32 size; 368 /* 369 * access_type specifies if the memory is always accessible 370 * or if it is accessible only when the DSP is in D0. 371 */ 372 enum sof_debugfs_access_type access_type; 373 }; 374 375 /* mailbox descriptor, used for host <-> DSP IPC */ 376 struct snd_sof_mailbox { 377 u32 offset; 378 size_t size; 379 }; 380 381 /* IPC message descriptor for host <-> DSP IO */ 382 struct snd_sof_ipc_msg { 383 /* message data */ 384 void *msg_data; 385 void *reply_data; 386 size_t msg_size; 387 size_t reply_size; 388 int reply_error; 389 390 /* notification, firmware initiated messages */ 391 void *rx_data; 392 393 wait_queue_head_t waitq; 394 bool ipc_complete; 395 }; 396 397 /** 398 * struct sof_ipc_fw_tracing_ops - IPC-specific firmware tracing ops 399 * @init: Function pointer for initialization of the tracing 400 * @free: Optional function pointer for freeing of the tracing 401 * @fw_crashed: Optional function pointer to notify the tracing of a firmware crash 402 * @suspend: Function pointer for system/runtime suspend 403 * @resume: Function pointer for system/runtime resume 404 */ 405 struct sof_ipc_fw_tracing_ops { 406 int (*init)(struct snd_sof_dev *sdev); 407 void (*free)(struct snd_sof_dev *sdev); 408 void (*fw_crashed)(struct snd_sof_dev *sdev); 409 void (*suspend)(struct snd_sof_dev *sdev, pm_message_t pm_state); 410 int (*resume)(struct snd_sof_dev *sdev); 411 }; 412 413 /** 414 * struct sof_ipc_pm_ops - IPC-specific PM ops 415 * @ctx_save: Optional function pointer for context save 416 * @ctx_restore: Optional function pointer for context restore 417 * @set_core_state: Optional function pointer for turning on/off a DSP core 418 */ 419 struct sof_ipc_pm_ops { 420 int (*ctx_save)(struct snd_sof_dev *sdev); 421 int (*ctx_restore)(struct snd_sof_dev *sdev); 422 int (*set_core_state)(struct snd_sof_dev *sdev, int core_idx, bool on); 423 }; 424 425 /** 426 * struct sof_ipc_fw_loader_ops - IPC/FW-specific loader ops 427 * @validate: Function pointer for validating the firmware image 428 * @parse_ext_manifest: Function pointer for parsing the manifest of the firmware 429 * @load_fw_to_dsp: Optional function pointer for loading the firmware to the 430 * DSP. 431 * The function implements generic, hardware independent way 432 * of loading the initial firmware and its modules (if any). 433 */ 434 struct sof_ipc_fw_loader_ops { 435 int (*validate)(struct snd_sof_dev *sdev); 436 size_t (*parse_ext_manifest)(struct snd_sof_dev *sdev); 437 int (*load_fw_to_dsp)(struct snd_sof_dev *sdev); 438 }; 439 440 struct sof_ipc_tplg_ops; 441 struct sof_ipc_pcm_ops; 442 443 /** 444 * struct sof_ipc_ops - IPC-specific ops 445 * @tplg: Pointer to IPC-specific topology ops 446 * @pm: Pointer to PM ops 447 * @pcm: Pointer to PCM ops 448 * @fw_loader: Pointer to Firmware Loader ops 449 * @fw_tracing: Optional pointer to Firmware tracing ops 450 * 451 * @init: Optional pointer for IPC related initialization 452 * @exit: Optional pointer for IPC related cleanup 453 * @post_fw_boot: Optional pointer to execute IPC related tasks after firmware 454 * boot. 455 * 456 * @tx_msg: Function pointer for sending a 'short' IPC message 457 * @set_get_data: Function pointer for set/get data ('large' IPC message). This 458 * function may split up the 'large' message and use the @tx_msg 459 * path to transfer individual chunks, or use other means to transfer 460 * the message. 461 * @get_reply: Function pointer for fetching the reply to 462 * sdev->ipc->msg.reply_data 463 * @rx_msg: Function pointer for handling a received message 464 * 465 * Note: both @tx_msg and @set_get_data considered as TX functions and they are 466 * serialized for the duration of the instructed transfer. A large message sent 467 * via @set_get_data is a single transfer even if at the hardware level it is 468 * handled with multiple chunks. 469 */ 470 struct sof_ipc_ops { 471 const struct sof_ipc_tplg_ops *tplg; 472 const struct sof_ipc_pm_ops *pm; 473 const struct sof_ipc_pcm_ops *pcm; 474 const struct sof_ipc_fw_loader_ops *fw_loader; 475 const struct sof_ipc_fw_tracing_ops *fw_tracing; 476 477 int (*init)(struct snd_sof_dev *sdev); 478 void (*exit)(struct snd_sof_dev *sdev); 479 int (*post_fw_boot)(struct snd_sof_dev *sdev); 480 481 int (*tx_msg)(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes, 482 void *reply_data, size_t reply_bytes, bool no_pm); 483 int (*set_get_data)(struct snd_sof_dev *sdev, void *data, size_t data_bytes, 484 bool set); 485 int (*get_reply)(struct snd_sof_dev *sdev); 486 void (*rx_msg)(struct snd_sof_dev *sdev); 487 }; 488 489 /* SOF generic IPC data */ 490 struct snd_sof_ipc { 491 struct snd_sof_dev *sdev; 492 493 /* protects messages and the disable flag */ 494 struct mutex tx_mutex; 495 /* disables further sending of ipc's */ 496 bool disable_ipc_tx; 497 498 /* Maximum allowed size of a single IPC message/reply */ 499 size_t max_payload_size; 500 501 struct snd_sof_ipc_msg msg; 502 503 /* IPC ops based on version */ 504 const struct sof_ipc_ops *ops; 505 }; 506 507 /* Helper to retrieve the IPC ops */ 508 #define sof_ipc_get_ops(sdev, ops_name) \ 509 (((sdev)->ipc && (sdev)->ipc->ops) ? (sdev)->ipc->ops->ops_name : NULL) 510 511 /* 512 * SOF Device Level. 513 */ 514 struct snd_sof_dev { 515 struct device *dev; 516 spinlock_t ipc_lock; /* lock for IPC users */ 517 spinlock_t hw_lock; /* lock for HW IO access */ 518 519 /* Main, Base firmware image */ 520 struct sof_firmware basefw; 521 522 /* 523 * ASoC components. plat_drv fields are set dynamically so 524 * can't use const 525 */ 526 struct snd_soc_component_driver plat_drv; 527 528 /* current DSP power state */ 529 struct sof_dsp_power_state dsp_power_state; 530 /* mutex to protect the dsp_power_state access */ 531 struct mutex power_state_access; 532 533 /* Intended power target of system suspend */ 534 enum sof_system_suspend_state system_suspend_target; 535 536 /* DSP firmware boot */ 537 wait_queue_head_t boot_wait; 538 enum sof_fw_state fw_state; 539 bool first_boot; 540 541 /* work queue in case the probe is implemented in two steps */ 542 struct work_struct probe_work; 543 bool probe_completed; 544 545 /* DSP HW differentiation */ 546 struct snd_sof_pdata *pdata; 547 548 /* IPC */ 549 struct snd_sof_ipc *ipc; 550 struct snd_sof_mailbox dsp_box; /* DSP initiated IPC */ 551 struct snd_sof_mailbox host_box; /* Host initiated IPC */ 552 struct snd_sof_mailbox stream_box; /* Stream position update */ 553 struct snd_sof_mailbox debug_box; /* Debug info updates */ 554 struct snd_sof_ipc_msg *msg; 555 int ipc_irq; 556 u32 next_comp_id; /* monotonic - reset during S3 */ 557 558 /* memory bases for mmaped DSPs - set by dsp_init() */ 559 void __iomem *bar[SND_SOF_BARS]; /* DSP base address */ 560 int mmio_bar; 561 int mailbox_bar; 562 size_t dsp_oops_offset; 563 564 /* debug */ 565 struct dentry *debugfs_root; 566 struct list_head dfsentry_list; 567 bool dbg_dump_printed; 568 bool ipc_dump_printed; 569 570 /* firmware loader */ 571 struct sof_ipc_fw_ready fw_ready; 572 struct sof_ipc_fw_version fw_version; 573 struct sof_ipc_cc_version *cc_version; 574 575 /* topology */ 576 struct snd_soc_tplg_ops *tplg_ops; 577 struct list_head pcm_list; 578 struct list_head kcontrol_list; 579 struct list_head widget_list; 580 struct list_head dai_list; 581 struct list_head dai_link_list; 582 struct list_head route_list; 583 struct snd_soc_component *component; 584 u32 enabled_cores_mask; /* keep track of enabled cores */ 585 bool led_present; 586 587 /* FW configuration */ 588 struct sof_ipc_window *info_window; 589 590 /* IPC timeouts in ms */ 591 int ipc_timeout; 592 int boot_timeout; 593 594 /* firmwre tracing */ 595 bool fw_trace_is_supported; /* set with Kconfig or module parameter */ 596 void *fw_trace_data; /* private data used by firmware tracing implementation */ 597 598 bool msi_enabled; 599 600 /* DSP core context */ 601 u32 num_cores; 602 603 /* 604 * ref count per core that will be modified during system suspend/resume and during pcm 605 * hw_params/hw_free. This doesn't need to be protected with a mutex because pcm 606 * hw_params/hw_free are already protected by the PCM mutex in the ALSA framework in 607 * sound/core/ when streams are active and during system suspend/resume, streams are 608 * already suspended. 609 */ 610 int dsp_core_ref_count[SOF_MAX_DSP_NUM_CORES]; 611 612 /* 613 * Used to keep track of registered IPC client devices so that they can 614 * be removed when the parent SOF module is removed. 615 */ 616 struct list_head ipc_client_list; 617 618 /* mutex to protect client list */ 619 struct mutex ipc_client_mutex; 620 621 /* 622 * Used for tracking the IPC client's RX registration for DSP initiated 623 * message handling. 624 */ 625 struct list_head ipc_rx_handler_list; 626 627 /* 628 * Used for tracking the IPC client's registration for DSP state change 629 * notification 630 */ 631 struct list_head fw_state_handler_list; 632 633 /* to protect the ipc_rx_handler_list and dsp_state_handler_list list */ 634 struct mutex client_event_handler_mutex; 635 636 /* quirks to override topology values */ 637 bool mclk_id_override; 638 u16 mclk_id_quirk; /* same size as in IPC3 definitions */ 639 640 void *private; /* core does not touch this */ 641 }; 642 643 /* 644 * Device Level. 645 */ 646 647 int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data); 648 int snd_sof_device_remove(struct device *dev); 649 int snd_sof_device_shutdown(struct device *dev); 650 bool snd_sof_device_probe_completed(struct device *dev); 651 652 int snd_sof_runtime_suspend(struct device *dev); 653 int snd_sof_runtime_resume(struct device *dev); 654 int snd_sof_runtime_idle(struct device *dev); 655 int snd_sof_resume(struct device *dev); 656 int snd_sof_suspend(struct device *dev); 657 int snd_sof_dsp_power_down_notify(struct snd_sof_dev *sdev); 658 int snd_sof_prepare(struct device *dev); 659 void snd_sof_complete(struct device *dev); 660 661 void snd_sof_new_platform_drv(struct snd_sof_dev *sdev); 662 663 /* 664 * Compress support 665 */ 666 extern struct snd_compress_ops sof_compressed_ops; 667 668 /* 669 * Firmware loading. 670 */ 671 int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev); 672 int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev); 673 int snd_sof_run_firmware(struct snd_sof_dev *sdev); 674 void snd_sof_fw_unload(struct snd_sof_dev *sdev); 675 676 /* 677 * IPC low level APIs. 678 */ 679 struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev); 680 void snd_sof_ipc_free(struct snd_sof_dev *sdev); 681 void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev); 682 void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id); 683 static inline void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev) 684 { 685 sdev->ipc->ops->rx_msg(sdev); 686 } 687 int sof_ipc_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes, 688 void *reply_data, size_t reply_bytes); 689 int sof_ipc_set_get_data(struct snd_sof_ipc *ipc, void *msg_data, 690 size_t msg_bytes, bool set); 691 int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes, 692 void *reply_data, size_t reply_bytes); 693 int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes, 694 size_t reply_bytes); 695 696 static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_id) 697 { 698 snd_sof_ipc_get_reply(sdev); 699 snd_sof_ipc_reply(sdev, msg_id); 700 } 701 702 /* 703 * Trace/debug 704 */ 705 int snd_sof_dbg_init(struct snd_sof_dev *sdev); 706 void snd_sof_free_debug(struct snd_sof_dev *sdev); 707 int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev, 708 void *base, size_t size, 709 const char *name, mode_t mode); 710 void sof_print_oops_and_stack(struct snd_sof_dev *sdev, const char *level, 711 u32 panic_code, u32 tracep_code, void *oops, 712 struct sof_ipc_panic_info *panic_info, 713 void *stack, size_t stack_words); 714 void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev, const char *msg); 715 int snd_sof_dbg_memory_info_init(struct snd_sof_dev *sdev); 716 int snd_sof_debugfs_add_region_item_iomem(struct snd_sof_dev *sdev, 717 enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size, 718 const char *name, enum sof_debugfs_access_type access_type); 719 /* Firmware tracing */ 720 int sof_fw_trace_init(struct snd_sof_dev *sdev); 721 void sof_fw_trace_free(struct snd_sof_dev *sdev); 722 void sof_fw_trace_fw_crashed(struct snd_sof_dev *sdev); 723 void sof_fw_trace_suspend(struct snd_sof_dev *sdev, pm_message_t pm_state); 724 int sof_fw_trace_resume(struct snd_sof_dev *sdev); 725 726 /* 727 * DSP Architectures. 728 */ 729 static inline void sof_stack(struct snd_sof_dev *sdev, const char *level, 730 void *oops, u32 *stack, u32 stack_words) 731 { 732 sof_dsp_arch_ops(sdev)->dsp_stack(sdev, level, oops, stack, 733 stack_words); 734 } 735 736 static inline void sof_oops(struct snd_sof_dev *sdev, const char *level, void *oops) 737 { 738 if (sof_dsp_arch_ops(sdev)->dsp_oops) 739 sof_dsp_arch_ops(sdev)->dsp_oops(sdev, level, oops); 740 } 741 742 extern const struct dsp_arch_ops sof_xtensa_arch_ops; 743 744 /* 745 * Firmware state tracking 746 */ 747 void sof_set_fw_state(struct snd_sof_dev *sdev, enum sof_fw_state new_state); 748 749 /* 750 * Utilities 751 */ 752 void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value); 753 void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value); 754 u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr); 755 u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr); 756 void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset, 757 void *message, size_t bytes); 758 void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset, 759 void *message, size_t bytes); 760 int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type, 761 u32 offset, void *src, size_t size); 762 int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type, 763 u32 offset, void *dest, size_t size); 764 765 int sof_ipc_msg_data(struct snd_sof_dev *sdev, 766 struct snd_sof_pcm_stream *sps, 767 void *p, size_t sz); 768 int sof_set_stream_data_offset(struct snd_sof_dev *sdev, 769 struct snd_pcm_substream *substream, 770 size_t posn_offset); 771 772 int sof_stream_pcm_open(struct snd_sof_dev *sdev, 773 struct snd_pcm_substream *substream); 774 int sof_stream_pcm_close(struct snd_sof_dev *sdev, 775 struct snd_pcm_substream *substream); 776 777 int sof_machine_check(struct snd_sof_dev *sdev); 778 779 /* SOF client support */ 780 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CLIENT) 781 int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, u32 id, 782 const void *data, size_t size); 783 void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 id); 784 int sof_register_clients(struct snd_sof_dev *sdev); 785 void sof_unregister_clients(struct snd_sof_dev *sdev); 786 void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf); 787 void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev); 788 int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state); 789 int sof_resume_clients(struct snd_sof_dev *sdev); 790 #else /* CONFIG_SND_SOC_SOF_CLIENT */ 791 static inline int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, 792 u32 id, const void *data, size_t size) 793 { 794 return 0; 795 } 796 797 static inline void sof_client_dev_unregister(struct snd_sof_dev *sdev, 798 const char *name, u32 id) 799 { 800 } 801 802 static inline int sof_register_clients(struct snd_sof_dev *sdev) 803 { 804 return 0; 805 } 806 807 static inline void sof_unregister_clients(struct snd_sof_dev *sdev) 808 { 809 } 810 811 static inline void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf) 812 { 813 } 814 815 static inline void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev) 816 { 817 } 818 819 static inline int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state) 820 { 821 return 0; 822 } 823 824 static inline int sof_resume_clients(struct snd_sof_dev *sdev) 825 { 826 return 0; 827 } 828 #endif /* CONFIG_SND_SOC_SOF_CLIENT */ 829 830 /* Main ops for IPC implementations */ 831 extern const struct sof_ipc_ops ipc3_ops; 832 extern const struct sof_ipc_ops ipc4_ops; 833 834 #endif 835