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