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