Pierre-Louis Bossart | e149ca2 | 2020-05-01 09:58:50 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */ |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 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> |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 15 | #include <sound/hdaudio.h> |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 16 | #include <sound/sof.h> |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 17 | #include <sound/sof/info.h> |
| 18 | #include <sound/sof/pm.h> |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 19 | #include <sound/sof/trace.h> |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 20 | #include <uapi/sound/sof/fw.h> |
| 21 | |
| 22 | /* debug flags */ |
Pierre-Louis Bossart | 2ab4c50 | 2019-09-27 15:05:28 -0500 | [diff] [blame] | 23 | #define SOF_DBG_ENABLE_TRACE BIT(0) |
| 24 | #define SOF_DBG_REGS BIT(1) |
| 25 | #define SOF_DBG_MBOX BIT(2) |
| 26 | #define SOF_DBG_TEXT BIT(3) |
| 27 | #define SOF_DBG_PCI BIT(4) |
Liam Girdwood | 9a06508 | 2019-09-27 15:05:29 -0500 | [diff] [blame] | 28 | #define SOF_DBG_RETAIN_CTX BIT(5) /* prevent DSP D3 on FW exception */ |
Pierre-Louis Bossart | 2ab4c50 | 2019-09-27 15:05:28 -0500 | [diff] [blame] | 29 | |
| 30 | /* global debug state set by SOF_DBG_ flags */ |
| 31 | extern int sof_core_debug; |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 32 | |
| 33 | /* max BARs mmaped devices can use */ |
| 34 | #define SND_SOF_BARS 8 |
| 35 | |
| 36 | /* time in ms for runtime suspend delay */ |
| 37 | #define SND_SOF_SUSPEND_DELAY_MS 2000 |
| 38 | |
| 39 | /* DMA buffer size for trace */ |
| 40 | #define DMA_BUF_SIZE_FOR_TRACE (PAGE_SIZE * 16) |
| 41 | |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 42 | #define SOF_IPC_DSP_REPLY 0 |
| 43 | #define SOF_IPC_HOST_REPLY 1 |
| 44 | |
| 45 | /* convenience constructor for DAI driver streams */ |
| 46 | #define SOF_DAI_STREAM(sname, scmin, scmax, srates, sfmt) \ |
| 47 | {.stream_name = sname, .channels_min = scmin, .channels_max = scmax, \ |
| 48 | .rates = srates, .formats = sfmt} |
| 49 | |
| 50 | #define SOF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \ |
| 51 | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT) |
| 52 | |
Ranjani Sridharan | 091c12e | 2019-06-03 11:18:20 -0500 | [diff] [blame] | 53 | #define ENABLE_DEBUGFS_CACHEBUF \ |
| 54 | (IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE) || \ |
| 55 | IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST)) |
| 56 | |
Ranjani Sridharan | 700d167 | 2020-01-29 16:07:21 -0600 | [diff] [blame] | 57 | /* DSP power state */ |
| 58 | enum sof_dsp_power_states { |
| 59 | SOF_DSP_PM_D0, |
| 60 | SOF_DSP_PM_D1, |
| 61 | SOF_DSP_PM_D2, |
| 62 | SOF_DSP_PM_D3_HOT, |
| 63 | SOF_DSP_PM_D3, |
| 64 | SOF_DSP_PM_D3_COLD, |
| 65 | }; |
| 66 | |
Ranjani Sridharan | 61e285c | 2020-01-29 16:07:22 -0600 | [diff] [blame] | 67 | struct sof_dsp_power_state { |
| 68 | u32 state; |
| 69 | u32 substate; /* platform-specific */ |
Keyon Jie | 4c19030 | 2019-10-25 17:40:57 -0500 | [diff] [blame] | 70 | }; |
| 71 | |
Ranjani Sridharan | 043ae13 | 2020-01-29 16:07:20 -0600 | [diff] [blame] | 72 | /* System suspend target state */ |
| 73 | enum sof_system_suspend_state { |
| 74 | SOF_SUSPEND_NONE = 0, |
| 75 | SOF_SUSPEND_S0IX, |
| 76 | SOF_SUSPEND_S3, |
| 77 | }; |
| 78 | |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 79 | struct snd_sof_dev; |
| 80 | struct snd_sof_ipc_msg; |
| 81 | struct snd_sof_ipc; |
| 82 | struct snd_sof_debugfs_map; |
| 83 | struct snd_soc_tplg_ops; |
| 84 | struct snd_soc_component; |
| 85 | struct snd_sof_pdata; |
| 86 | |
| 87 | /* |
| 88 | * SOF DSP HW abstraction operations. |
| 89 | * Used to abstract DSP HW architecture and any IO busses between host CPU |
| 90 | * and DSP device(s). |
| 91 | */ |
| 92 | struct snd_sof_dsp_ops { |
| 93 | |
| 94 | /* probe and remove */ |
| 95 | int (*probe)(struct snd_sof_dev *sof_dev); /* mandatory */ |
| 96 | int (*remove)(struct snd_sof_dev *sof_dev); /* optional */ |
| 97 | |
| 98 | /* DSP core boot / reset */ |
| 99 | int (*run)(struct snd_sof_dev *sof_dev); /* mandatory */ |
| 100 | int (*stall)(struct snd_sof_dev *sof_dev); /* optional */ |
| 101 | int (*reset)(struct snd_sof_dev *sof_dev); /* optional */ |
| 102 | int (*core_power_up)(struct snd_sof_dev *sof_dev, |
| 103 | unsigned int core_mask); /* optional */ |
| 104 | int (*core_power_down)(struct snd_sof_dev *sof_dev, |
| 105 | unsigned int core_mask); /* optional */ |
| 106 | |
| 107 | /* |
| 108 | * Register IO: only used by respective drivers themselves, |
| 109 | * TODO: consider removing these operations and calling respective |
| 110 | * implementations directly |
| 111 | */ |
| 112 | void (*write)(struct snd_sof_dev *sof_dev, void __iomem *addr, |
| 113 | u32 value); /* optional */ |
| 114 | u32 (*read)(struct snd_sof_dev *sof_dev, |
| 115 | void __iomem *addr); /* optional */ |
| 116 | void (*write64)(struct snd_sof_dev *sof_dev, void __iomem *addr, |
| 117 | u64 value); /* optional */ |
| 118 | u64 (*read64)(struct snd_sof_dev *sof_dev, |
| 119 | void __iomem *addr); /* optional */ |
| 120 | |
| 121 | /* memcpy IO */ |
| 122 | void (*block_read)(struct snd_sof_dev *sof_dev, u32 bar, |
| 123 | u32 offset, void *dest, |
| 124 | size_t size); /* mandatory */ |
| 125 | void (*block_write)(struct snd_sof_dev *sof_dev, u32 bar, |
| 126 | u32 offset, void *src, |
| 127 | size_t size); /* mandatory */ |
| 128 | |
| 129 | /* doorbell */ |
| 130 | irqreturn_t (*irq_handler)(int irq, void *context); /* optional */ |
| 131 | irqreturn_t (*irq_thread)(int irq, void *context); /* optional */ |
| 132 | |
| 133 | /* ipc */ |
| 134 | int (*send_msg)(struct snd_sof_dev *sof_dev, |
| 135 | struct snd_sof_ipc_msg *msg); /* mandatory */ |
| 136 | |
| 137 | /* FW loading */ |
| 138 | int (*load_firmware)(struct snd_sof_dev *sof_dev); /* mandatory */ |
| 139 | int (*load_module)(struct snd_sof_dev *sof_dev, |
| 140 | struct snd_sof_mod_hdr *hdr); /* optional */ |
| 141 | /* |
| 142 | * FW ready checks for ABI compatibility and creates |
| 143 | * memory windows at first boot |
| 144 | */ |
Ranjani Sridharan | 8692d49 | 2019-09-27 15:05:32 -0500 | [diff] [blame] | 145 | int (*fw_ready)(struct snd_sof_dev *sdev, u32 msg_id); /* mandatory */ |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 146 | |
| 147 | /* connect pcm substream to a host stream */ |
| 148 | int (*pcm_open)(struct snd_sof_dev *sdev, |
| 149 | struct snd_pcm_substream *substream); /* optional */ |
| 150 | /* disconnect pcm substream to a host stream */ |
| 151 | int (*pcm_close)(struct snd_sof_dev *sdev, |
| 152 | struct snd_pcm_substream *substream); /* optional */ |
| 153 | |
| 154 | /* host stream hw params */ |
| 155 | int (*pcm_hw_params)(struct snd_sof_dev *sdev, |
| 156 | struct snd_pcm_substream *substream, |
| 157 | struct snd_pcm_hw_params *params, |
| 158 | struct sof_ipc_stream_params *ipc_params); /* optional */ |
| 159 | |
Ranjani Sridharan | 93146bc | 2019-06-12 12:23:39 -0500 | [diff] [blame] | 160 | /* host stream hw_free */ |
| 161 | int (*pcm_hw_free)(struct snd_sof_dev *sdev, |
| 162 | struct snd_pcm_substream *substream); /* optional */ |
| 163 | |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 164 | /* host stream trigger */ |
| 165 | int (*pcm_trigger)(struct snd_sof_dev *sdev, |
| 166 | struct snd_pcm_substream *substream, |
| 167 | int cmd); /* optional */ |
| 168 | |
| 169 | /* host stream pointer */ |
| 170 | snd_pcm_uframes_t (*pcm_pointer)(struct snd_sof_dev *sdev, |
| 171 | struct snd_pcm_substream *substream); /* optional */ |
| 172 | |
Cezary Rojewski | e145e9a | 2020-02-18 15:39:20 +0100 | [diff] [blame] | 173 | #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES) |
| 174 | /* Except for probe_pointer, all probe ops are mandatory */ |
| 175 | int (*probe_assign)(struct snd_sof_dev *sdev, |
| 176 | struct snd_compr_stream *cstream, |
| 177 | struct snd_soc_dai *dai); /* mandatory */ |
| 178 | int (*probe_free)(struct snd_sof_dev *sdev, |
| 179 | struct snd_compr_stream *cstream, |
| 180 | struct snd_soc_dai *dai); /* mandatory */ |
| 181 | int (*probe_set_params)(struct snd_sof_dev *sdev, |
| 182 | struct snd_compr_stream *cstream, |
| 183 | struct snd_compr_params *params, |
| 184 | struct snd_soc_dai *dai); /* mandatory */ |
| 185 | int (*probe_trigger)(struct snd_sof_dev *sdev, |
| 186 | struct snd_compr_stream *cstream, int cmd, |
| 187 | struct snd_soc_dai *dai); /* mandatory */ |
| 188 | int (*probe_pointer)(struct snd_sof_dev *sdev, |
| 189 | struct snd_compr_stream *cstream, |
| 190 | struct snd_compr_tstamp *tstamp, |
| 191 | struct snd_soc_dai *dai); /* optional */ |
| 192 | #endif |
| 193 | |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 194 | /* host read DSP stream data */ |
| 195 | void (*ipc_msg_data)(struct snd_sof_dev *sdev, |
| 196 | struct snd_pcm_substream *substream, |
| 197 | void *p, size_t sz); /* mandatory */ |
| 198 | |
| 199 | /* host configure DSP HW parameters */ |
| 200 | int (*ipc_pcm_params)(struct snd_sof_dev *sdev, |
| 201 | struct snd_pcm_substream *substream, |
| 202 | const struct sof_ipc_pcm_params_reply *reply); /* mandatory */ |
| 203 | |
| 204 | /* pre/post firmware run */ |
| 205 | int (*pre_fw_run)(struct snd_sof_dev *sof_dev); /* optional */ |
| 206 | int (*post_fw_run)(struct snd_sof_dev *sof_dev); /* optional */ |
| 207 | |
| 208 | /* DSP PM */ |
Ranjani Sridharan | 61e285c | 2020-01-29 16:07:22 -0600 | [diff] [blame] | 209 | int (*suspend)(struct snd_sof_dev *sof_dev, |
| 210 | u32 target_state); /* optional */ |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 211 | int (*resume)(struct snd_sof_dev *sof_dev); /* optional */ |
Fred Oh | 1c38c92 | 2019-07-22 09:13:50 -0500 | [diff] [blame] | 212 | int (*runtime_suspend)(struct snd_sof_dev *sof_dev); /* optional */ |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 213 | int (*runtime_resume)(struct snd_sof_dev *sof_dev); /* optional */ |
Kai Vehmanen | 62fde97 | 2019-07-02 16:24:27 +0300 | [diff] [blame] | 214 | int (*runtime_idle)(struct snd_sof_dev *sof_dev); /* optional */ |
Ranjani Sridharan | 7077a07 | 2019-06-12 12:23:38 -0500 | [diff] [blame] | 215 | int (*set_hw_params_upon_resume)(struct snd_sof_dev *sdev); /* optional */ |
Keyon Jie | e8f112d | 2019-10-25 17:40:59 -0500 | [diff] [blame] | 216 | int (*set_power_state)(struct snd_sof_dev *sdev, |
Ranjani Sridharan | 61e285c | 2020-01-29 16:07:22 -0600 | [diff] [blame] | 217 | const struct sof_dsp_power_state *target_state); /* optional */ |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 218 | |
| 219 | /* DSP clocking */ |
| 220 | int (*set_clk)(struct snd_sof_dev *sof_dev, u32 freq); /* optional */ |
| 221 | |
| 222 | /* debug */ |
| 223 | const struct snd_sof_debugfs_map *debug_map; /* optional */ |
| 224 | int debug_map_count; /* optional */ |
| 225 | void (*dbg_dump)(struct snd_sof_dev *sof_dev, |
| 226 | u32 flags); /* optional */ |
Pan Xiuli | 5e4a27f | 2019-04-30 18:09:32 -0500 | [diff] [blame] | 227 | void (*ipc_dump)(struct snd_sof_dev *sof_dev); /* optional */ |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 228 | |
| 229 | /* host DMA trace initialization */ |
| 230 | int (*trace_init)(struct snd_sof_dev *sdev, |
| 231 | u32 *stream_tag); /* optional */ |
| 232 | int (*trace_release)(struct snd_sof_dev *sdev); /* optional */ |
| 233 | int (*trace_trigger)(struct snd_sof_dev *sdev, |
| 234 | int cmd); /* optional */ |
| 235 | |
Daniel Baluta | ce8234a | 2019-07-22 09:13:47 -0500 | [diff] [blame] | 236 | /* misc */ |
| 237 | int (*get_bar_index)(struct snd_sof_dev *sdev, |
| 238 | u32 type); /* optional */ |
Daniel Baluta | bb9c93f | 2019-08-07 10:01:59 -0500 | [diff] [blame] | 239 | int (*get_mailbox_offset)(struct snd_sof_dev *sdev);/* mandatory for common loader code */ |
Daniel Baluta | e17422c | 2019-08-07 10:02:00 -0500 | [diff] [blame] | 240 | int (*get_window_offset)(struct snd_sof_dev *sdev, |
| 241 | u32 id);/* mandatory for common loader code */ |
Daniel Baluta | bb9c93f | 2019-08-07 10:01:59 -0500 | [diff] [blame] | 242 | |
Daniel Baluta | 285880a | 2019-12-04 15:15:53 -0600 | [diff] [blame] | 243 | /* machine driver ops */ |
| 244 | int (*machine_register)(struct snd_sof_dev *sdev, |
| 245 | void *pdata); /* optional */ |
| 246 | void (*machine_unregister)(struct snd_sof_dev *sdev, |
| 247 | void *pdata); /* optional */ |
| 248 | void (*machine_select)(struct snd_sof_dev *sdev); /* optional */ |
| 249 | void (*set_mach_params)(const struct snd_soc_acpi_mach *mach, |
| 250 | struct device *dev); /* optional */ |
| 251 | |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 252 | /* DAI ops */ |
| 253 | struct snd_soc_dai_driver *drv; |
| 254 | int num_drv; |
Pierre-Louis Bossart | 27e322f | 2019-10-24 16:03:17 -0500 | [diff] [blame] | 255 | |
| 256 | /* ALSA HW info flags, will be stored in snd_pcm_runtime.hw.info */ |
| 257 | u32 hw_info; |
Pierre-Louis Bossart | 0f501c7 | 2019-12-17 14:22:30 -0600 | [diff] [blame] | 258 | |
| 259 | const struct sof_arch_ops *arch_ops; |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | /* DSP architecture specific callbacks for oops and stack dumps */ |
| 263 | struct sof_arch_ops { |
| 264 | void (*dsp_oops)(struct snd_sof_dev *sdev, void *oops); |
| 265 | void (*dsp_stack)(struct snd_sof_dev *sdev, void *oops, |
| 266 | u32 *stack, u32 stack_words); |
| 267 | }; |
| 268 | |
Pierre-Louis Bossart | 0f501c7 | 2019-12-17 14:22:30 -0600 | [diff] [blame] | 269 | #define sof_arch_ops(sdev) ((sdev)->pdata->desc->ops->arch_ops) |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 270 | |
| 271 | /* DSP device HW descriptor mapping between bus ID and ops */ |
| 272 | struct sof_ops_table { |
| 273 | const struct sof_dev_desc *desc; |
| 274 | const struct snd_sof_dsp_ops *ops; |
| 275 | }; |
| 276 | |
| 277 | enum sof_dfsentry_type { |
| 278 | SOF_DFSENTRY_TYPE_IOMEM = 0, |
| 279 | SOF_DFSENTRY_TYPE_BUF, |
| 280 | }; |
| 281 | |
| 282 | enum sof_debugfs_access_type { |
| 283 | SOF_DEBUGFS_ACCESS_ALWAYS = 0, |
| 284 | SOF_DEBUGFS_ACCESS_D0_ONLY, |
| 285 | }; |
| 286 | |
| 287 | /* FS entry for debug files that can expose DSP memories, registers */ |
| 288 | struct snd_sof_dfsentry { |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 289 | size_t size; |
| 290 | enum sof_dfsentry_type type; |
| 291 | /* |
| 292 | * access_type specifies if the |
| 293 | * memory -> DSP resource (memory, register etc) is always accessible |
| 294 | * or if it is accessible only when the DSP is in D0. |
| 295 | */ |
| 296 | enum sof_debugfs_access_type access_type; |
Ranjani Sridharan | 091c12e | 2019-06-03 11:18:20 -0500 | [diff] [blame] | 297 | #if ENABLE_DEBUGFS_CACHEBUF |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 298 | char *cache_buf; /* buffer to cache the contents of debugfs memory */ |
| 299 | #endif |
| 300 | struct snd_sof_dev *sdev; |
| 301 | struct list_head list; /* list in sdev dfsentry list */ |
| 302 | union { |
| 303 | void __iomem *io_mem; |
| 304 | void *buf; |
| 305 | }; |
| 306 | }; |
| 307 | |
| 308 | /* Debug mapping for any DSP memory or registers that can used for debug */ |
| 309 | struct snd_sof_debugfs_map { |
| 310 | const char *name; |
| 311 | u32 bar; |
| 312 | u32 offset; |
| 313 | u32 size; |
| 314 | /* |
| 315 | * access_type specifies if the memory is always accessible |
| 316 | * or if it is accessible only when the DSP is in D0. |
| 317 | */ |
| 318 | enum sof_debugfs_access_type access_type; |
| 319 | }; |
| 320 | |
| 321 | /* mailbox descriptor, used for host <-> DSP IPC */ |
| 322 | struct snd_sof_mailbox { |
| 323 | u32 offset; |
| 324 | size_t size; |
| 325 | }; |
| 326 | |
| 327 | /* IPC message descriptor for host <-> DSP IO */ |
| 328 | struct snd_sof_ipc_msg { |
| 329 | /* message data */ |
| 330 | u32 header; |
| 331 | void *msg_data; |
| 332 | void *reply_data; |
| 333 | size_t msg_size; |
| 334 | size_t reply_size; |
| 335 | int reply_error; |
| 336 | |
| 337 | wait_queue_head_t waitq; |
| 338 | bool ipc_complete; |
| 339 | }; |
| 340 | |
Ranjani Sridharan | 6ca5cec | 2019-12-17 18:26:09 -0600 | [diff] [blame] | 341 | enum snd_sof_fw_state { |
| 342 | SOF_FW_BOOT_NOT_STARTED = 0, |
| 343 | SOF_FW_BOOT_PREPARE, |
| 344 | SOF_FW_BOOT_IN_PROGRESS, |
| 345 | SOF_FW_BOOT_FAILED, |
| 346 | SOF_FW_BOOT_READY_FAILED, /* firmware booted but fw_ready op failed */ |
| 347 | SOF_FW_BOOT_COMPLETE, |
| 348 | }; |
| 349 | |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 350 | /* |
| 351 | * SOF Device Level. |
| 352 | */ |
| 353 | struct snd_sof_dev { |
| 354 | struct device *dev; |
| 355 | spinlock_t ipc_lock; /* lock for IPC users */ |
| 356 | spinlock_t hw_lock; /* lock for HW IO access */ |
| 357 | |
| 358 | /* |
| 359 | * ASoC components. plat_drv fields are set dynamically so |
| 360 | * can't use const |
| 361 | */ |
| 362 | struct snd_soc_component_driver plat_drv; |
| 363 | |
Ranjani Sridharan | 61e285c | 2020-01-29 16:07:22 -0600 | [diff] [blame] | 364 | /* current DSP power state */ |
| 365 | struct sof_dsp_power_state dsp_power_state; |
Ranjani Sridharan | 043ae13 | 2020-01-29 16:07:20 -0600 | [diff] [blame] | 366 | |
| 367 | /* Intended power target of system suspend */ |
| 368 | enum sof_system_suspend_state system_suspend_target; |
Keyon Jie | 4c19030 | 2019-10-25 17:40:57 -0500 | [diff] [blame] | 369 | |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 370 | /* DSP firmware boot */ |
| 371 | wait_queue_head_t boot_wait; |
Ranjani Sridharan | 6ca5cec | 2019-12-17 18:26:09 -0600 | [diff] [blame] | 372 | enum snd_sof_fw_state fw_state; |
Guennadi Liakhovetski | f738d81 | 2020-08-24 15:09:06 -0500 | [diff] [blame] | 373 | bool first_boot; |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 374 | |
| 375 | /* work queue in case the probe is implemented in two steps */ |
| 376 | struct work_struct probe_work; |
| 377 | |
| 378 | /* DSP HW differentiation */ |
| 379 | struct snd_sof_pdata *pdata; |
| 380 | |
| 381 | /* IPC */ |
| 382 | struct snd_sof_ipc *ipc; |
| 383 | struct snd_sof_mailbox dsp_box; /* DSP initiated IPC */ |
| 384 | struct snd_sof_mailbox host_box; /* Host initiated IPC */ |
| 385 | struct snd_sof_mailbox stream_box; /* Stream position update */ |
Iulian Olaru | e17b738 | 2020-08-25 16:58:54 -0700 | [diff] [blame^] | 386 | struct snd_sof_mailbox debug_box; /* Debug info updates */ |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 387 | struct snd_sof_ipc_msg *msg; |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 388 | int ipc_irq; |
| 389 | u32 next_comp_id; /* monotonic - reset during S3 */ |
| 390 | |
| 391 | /* memory bases for mmaped DSPs - set by dsp_init() */ |
| 392 | void __iomem *bar[SND_SOF_BARS]; /* DSP base address */ |
| 393 | int mmio_bar; |
| 394 | int mailbox_bar; |
| 395 | size_t dsp_oops_offset; |
| 396 | |
| 397 | /* debug */ |
| 398 | struct dentry *debugfs_root; |
| 399 | struct list_head dfsentry_list; |
| 400 | |
| 401 | /* firmware loader */ |
| 402 | struct snd_dma_buffer dmab; |
| 403 | struct snd_dma_buffer dmab_bdl; |
| 404 | struct sof_ipc_fw_ready fw_ready; |
| 405 | struct sof_ipc_fw_version fw_version; |
Karol Trzcinski | 5928395 | 2019-12-17 18:26:11 -0600 | [diff] [blame] | 406 | struct sof_ipc_cc_version *cc_version; |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 407 | |
| 408 | /* topology */ |
| 409 | struct snd_soc_tplg_ops *tplg_ops; |
| 410 | struct list_head pcm_list; |
| 411 | struct list_head kcontrol_list; |
| 412 | struct list_head widget_list; |
| 413 | struct list_head dai_list; |
| 414 | struct list_head route_list; |
| 415 | struct snd_soc_component *component; |
| 416 | u32 enabled_cores_mask; /* keep track of enabled cores */ |
| 417 | |
| 418 | /* FW configuration */ |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 419 | struct sof_ipc_window *info_window; |
| 420 | |
| 421 | /* IPC timeouts in ms */ |
| 422 | int ipc_timeout; |
| 423 | int boot_timeout; |
| 424 | |
Cezary Rojewski | e145e9a | 2020-02-18 15:39:20 +0100 | [diff] [blame] | 425 | #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES) |
| 426 | unsigned int extractor_stream_tag; |
| 427 | #endif |
| 428 | |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 429 | /* DMA for Trace */ |
| 430 | struct snd_dma_buffer dmatb; |
| 431 | struct snd_dma_buffer dmatp; |
| 432 | int dma_trace_pages; |
| 433 | wait_queue_head_t trace_sleep; |
| 434 | u32 host_offset; |
Guennadi Liakhovetski | f738d81 | 2020-08-24 15:09:06 -0500 | [diff] [blame] | 435 | bool dtrace_is_supported; /* set with Kconfig or module parameter */ |
| 436 | bool dtrace_is_enabled; |
| 437 | bool dtrace_error; |
| 438 | bool dtrace_draining; |
Kai Vehmanen | ec9025e | 2019-05-24 14:23:06 -0500 | [diff] [blame] | 439 | |
Guennadi Liakhovetski | 672ff5e | 2019-07-22 09:13:57 -0500 | [diff] [blame] | 440 | bool msi_enabled; |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 441 | |
| 442 | void *private; /* core does not touch this */ |
| 443 | }; |
| 444 | |
| 445 | /* |
| 446 | * Device Level. |
| 447 | */ |
| 448 | |
| 449 | int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data); |
| 450 | int snd_sof_device_remove(struct device *dev); |
| 451 | |
| 452 | int snd_sof_runtime_suspend(struct device *dev); |
| 453 | int snd_sof_runtime_resume(struct device *dev); |
Kai Vehmanen | 62fde97 | 2019-07-02 16:24:27 +0300 | [diff] [blame] | 454 | int snd_sof_runtime_idle(struct device *dev); |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 455 | int snd_sof_resume(struct device *dev); |
| 456 | int snd_sof_suspend(struct device *dev); |
Marcin Rajwa | 3541aef | 2020-05-15 16:59:52 +0300 | [diff] [blame] | 457 | int snd_sof_dsp_power_down_notify(struct snd_sof_dev *sdev); |
Keyon Jie | 0b50b3b | 2019-10-25 17:41:17 -0500 | [diff] [blame] | 458 | int snd_sof_prepare(struct device *dev); |
| 459 | void snd_sof_complete(struct device *dev); |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 460 | |
| 461 | void snd_sof_new_platform_drv(struct snd_sof_dev *sdev); |
| 462 | |
Ranjani Sridharan | 3e62579 | 2019-12-04 15:15:48 -0600 | [diff] [blame] | 463 | int snd_sof_create_page_table(struct device *dev, |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 464 | struct snd_dma_buffer *dmab, |
| 465 | unsigned char *page_table, size_t size); |
| 466 | |
| 467 | /* |
| 468 | * Firmware loading. |
| 469 | */ |
| 470 | int snd_sof_load_firmware(struct snd_sof_dev *sdev); |
| 471 | int snd_sof_load_firmware_raw(struct snd_sof_dev *sdev); |
| 472 | int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev); |
| 473 | int snd_sof_run_firmware(struct snd_sof_dev *sdev); |
| 474 | int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev, |
| 475 | struct snd_sof_mod_hdr *module); |
| 476 | void snd_sof_fw_unload(struct snd_sof_dev *sdev); |
| 477 | int snd_sof_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 bar, u32 offset); |
| 478 | |
| 479 | /* |
| 480 | * IPC low level APIs. |
| 481 | */ |
| 482 | struct snd_sof_ipc *snd_sof_ipc_init(struct snd_sof_dev *sdev); |
| 483 | void snd_sof_ipc_free(struct snd_sof_dev *sdev); |
Ranjani Sridharan | d7a1ed2 | 2020-05-26 15:36:37 -0500 | [diff] [blame] | 484 | void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id); |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 485 | void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev); |
| 486 | int snd_sof_ipc_stream_pcm_params(struct snd_sof_dev *sdev, |
| 487 | struct sof_ipc_pcm_params *params); |
| 488 | int snd_sof_dsp_mailbox_init(struct snd_sof_dev *sdev, u32 dspbox, |
| 489 | size_t dspbox_size, u32 hostbox, |
| 490 | size_t hostbox_size); |
| 491 | int snd_sof_ipc_valid(struct snd_sof_dev *sdev); |
| 492 | int sof_ipc_tx_message(struct snd_sof_ipc *ipc, u32 header, |
| 493 | void *msg_data, size_t msg_bytes, void *reply_data, |
| 494 | size_t reply_bytes); |
Ranjani Sridharan | 63e51fd3 | 2020-01-29 16:07:25 -0600 | [diff] [blame] | 495 | int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, u32 header, |
| 496 | void *msg_data, size_t msg_bytes, |
| 497 | void *reply_data, size_t reply_bytes); |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 498 | |
| 499 | /* |
| 500 | * Trace/debug |
| 501 | */ |
| 502 | int snd_sof_init_trace(struct snd_sof_dev *sdev); |
| 503 | void snd_sof_release_trace(struct snd_sof_dev *sdev); |
| 504 | void snd_sof_free_trace(struct snd_sof_dev *sdev); |
| 505 | int snd_sof_dbg_init(struct snd_sof_dev *sdev); |
| 506 | void snd_sof_free_debug(struct snd_sof_dev *sdev); |
| 507 | int snd_sof_debugfs_io_item(struct snd_sof_dev *sdev, |
| 508 | void __iomem *base, size_t size, |
| 509 | const char *name, |
| 510 | enum sof_debugfs_access_type access_type); |
| 511 | int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev, |
| 512 | void *base, size_t size, |
Ranjani Sridharan | 5c9714f | 2019-06-03 11:18:18 -0500 | [diff] [blame] | 513 | const char *name, mode_t mode); |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 514 | int snd_sof_trace_update_pos(struct snd_sof_dev *sdev, |
| 515 | struct sof_ipc_dma_trace_posn *posn); |
| 516 | void snd_sof_trace_notify_for_error(struct snd_sof_dev *sdev); |
| 517 | void snd_sof_get_status(struct snd_sof_dev *sdev, u32 panic_code, |
| 518 | u32 tracep_code, void *oops, |
| 519 | struct sof_ipc_panic_info *panic_info, |
| 520 | void *stack, size_t stack_words); |
| 521 | int snd_sof_init_trace_ipc(struct snd_sof_dev *sdev); |
Liam Girdwood | 9a06508 | 2019-09-27 15:05:29 -0500 | [diff] [blame] | 522 | void snd_sof_handle_fw_exception(struct snd_sof_dev *sdev); |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 523 | |
| 524 | /* |
| 525 | * Platform specific ops. |
| 526 | */ |
Kuninori Morimoto | 39118ce | 2020-04-20 16:09:48 +0900 | [diff] [blame] | 527 | extern struct snd_compress_ops sof_compressed_ops; |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 528 | |
| 529 | /* |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 530 | * DSP Architectures. |
| 531 | */ |
| 532 | static inline void sof_stack(struct snd_sof_dev *sdev, void *oops, u32 *stack, |
| 533 | u32 stack_words) |
| 534 | { |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 535 | sof_arch_ops(sdev)->dsp_stack(sdev, oops, stack, stack_words); |
| 536 | } |
| 537 | |
| 538 | static inline void sof_oops(struct snd_sof_dev *sdev, void *oops) |
| 539 | { |
| 540 | if (sof_arch_ops(sdev)->dsp_oops) |
| 541 | sof_arch_ops(sdev)->dsp_oops(sdev, oops); |
| 542 | } |
| 543 | |
| 544 | extern const struct sof_arch_ops sof_xtensa_arch_ops; |
| 545 | |
| 546 | /* |
| 547 | * Utilities |
| 548 | */ |
| 549 | void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value); |
| 550 | void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value); |
| 551 | u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr); |
| 552 | u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr); |
| 553 | void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset, |
| 554 | void *message, size_t bytes); |
| 555 | void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset, |
| 556 | void *message, size_t bytes); |
| 557 | void sof_block_write(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *src, |
| 558 | size_t size); |
| 559 | void sof_block_read(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *dest, |
| 560 | size_t size); |
| 561 | |
Daniel Baluta | 83ee7ab | 2019-08-07 10:02:01 -0500 | [diff] [blame] | 562 | int sof_fw_ready(struct snd_sof_dev *sdev, u32 msg_id); |
| 563 | |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 564 | void intel_ipc_msg_data(struct snd_sof_dev *sdev, |
| 565 | struct snd_pcm_substream *substream, |
| 566 | void *p, size_t sz); |
| 567 | int intel_ipc_pcm_params(struct snd_sof_dev *sdev, |
| 568 | struct snd_pcm_substream *substream, |
| 569 | const struct sof_ipc_pcm_params_reply *reply); |
| 570 | |
| 571 | int intel_pcm_open(struct snd_sof_dev *sdev, |
| 572 | struct snd_pcm_substream *substream); |
| 573 | int intel_pcm_close(struct snd_sof_dev *sdev, |
| 574 | struct snd_pcm_substream *substream); |
| 575 | |
Daniel Baluta | 285880a | 2019-12-04 15:15:53 -0600 | [diff] [blame] | 576 | int sof_machine_check(struct snd_sof_dev *sdev); |
| 577 | |
Liam Girdwood | c16211d | 2019-04-12 11:05:06 -0500 | [diff] [blame] | 578 | #endif |