xref: /linux/sound/soc/sof/ipc4-priv.h (revision fed620a78a656e25cfffc503171f86a74ef0de50)
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2 /*
3  * This file is provided under a dual BSD/GPLv2 license.  When using or
4  * redistributing this file, you may do so under either license.
5  *
6  * Copyright(c) 2022 Intel Corporation
7  */
8 
9 #ifndef __SOUND_SOC_SOF_IPC4_PRIV_H
10 #define __SOUND_SOC_SOF_IPC4_PRIV_H
11 
12 #include <linux/idr.h>
13 #include <sound/sof/ext_manifest4.h>
14 #include <sound/sof/ipc4/header.h>
15 #include "sof-priv.h"
16 
17 /* The DSP window indices are fixed */
18 #define SOF_IPC4_INBOX_WINDOW_IDX	0
19 #define SOF_IPC4_OUTBOX_WINDOW_IDX	1
20 #define SOF_IPC4_DEBUG_WINDOW_IDX	2
21 
22 enum sof_ipc4_mtrace_type {
23 	SOF_IPC4_MTRACE_NOT_AVAILABLE = 0,
24 	SOF_IPC4_MTRACE_INTEL_CAVS_1_5,
25 	SOF_IPC4_MTRACE_INTEL_CAVS_1_8,
26 	SOF_IPC4_MTRACE_INTEL_CAVS_2,
27 };
28 
29 /**
30  * struct sof_ipc4_fw_module - IPC4 module info
31  * @sof_man4_module: Module info
32  * @fw_mod_cfg: Pointer to the module config start of the module
33  * @m_ida: Module instance identifier
34  * @private: Module private data
35  */
36 struct sof_ipc4_fw_module {
37 	struct sof_man4_module man4_module_entry;
38 	const struct sof_man4_module_config *fw_mod_cfg;
39 	struct ida m_ida;
40 	void *private;
41 };
42 
43 /**
44  * struct sof_ipc4_fw_library - IPC4 library information
45  * @sof_fw: SOF Firmware of the library
46  * @id: Library ID. 0 is reserved for basefw, external libraries must have unique
47  *	ID number between 1 and (sof_ipc4_fw_data.max_libs_count - 1)
48  *	Note: sof_ipc4_fw_data.max_libs_count == 1 implies that external libraries
49  *	are not supported
50  * @num_modules : Number of FW modules in the library
51  * @modules: Array of FW modules
52  */
53 struct sof_ipc4_fw_library {
54 	struct sof_firmware sof_fw;
55 	const char *name;
56 	u32 id;
57 	int num_modules;
58 	struct sof_ipc4_fw_module *modules;
59 };
60 
61 struct snd_ipc4_nhlt {
62 	struct list_head list;
63 	void *nhlt;
64 	bool from_acpi;
65 };
66 
67 /**
68  * struct sof_ipc4_fw_data - IPC4-specific data
69  * @manifest_fw_hdr_offset: FW header offset in the manifest
70  * @fw_lib_xa: XArray for firmware libraries, including basefw (ID = 0)
71  *	       Used to store the FW libraries and to manage the unique IDs of the
72  *	       libraries.
73  * @mtrace_type: mtrace type supported on the booted platform
74  * @mtrace_log_bytes: log bytes as reported by the firmware via fw_config reply
75  * @num_playback_streams: max number of playback DMAs, needed for CHAIN_DMA offset
76  * @num_capture_streams: max number of capture DMAs
77  * @max_num_pipelines: max number of pipelines
78  * @max_libs_count: Maximum number of libraries support by the FW including the
79  *		    base firmware
80  * @fw_context_save: Firmware supports full context save and restore
81  * @libraries_restored: The libraries have been retained during firmware boot
82  * @nhlt_list: The NHLT tables from the BIOS and the topology manifest
83  *
84  * @codec_info: Information about the available codecs in booted firmware. The
85  *		data is to be used by the code for compressed support.
86  * @load_library: Callback function for platform dependent library loading
87  * @pipeline_state_mutex: Mutex to protect pipeline triggers, ref counts, states and deletion
88  */
89 struct sof_ipc4_fw_data {
90 	u32 manifest_fw_hdr_offset;
91 	struct xarray fw_lib_xa;
92 	enum sof_ipc4_mtrace_type mtrace_type;
93 	u32 mtrace_log_bytes;
94 	int num_playback_streams;
95 	int num_capture_streams;
96 	int max_num_pipelines;
97 	u32 max_libs_count;
98 	bool fw_context_save;
99 	bool libraries_restored;
100 	struct list_head nhlt_list;
101 
102 	void *codec_info;
103 
104 	int (*load_library)(struct snd_sof_dev *sdev,
105 			    struct sof_ipc4_fw_library *fw_lib, bool reload);
106 	void (*intel_configure_mic_privacy)(struct snd_sof_dev *sdev,
107 					    struct sof_ipc4_intel_mic_privacy_cap *caps);
108 	struct mutex pipeline_state_mutex; /* protect pipeline triggers, ref counts and states */
109 };
110 
111 /**
112  * struct sof_ipc4_timestamp_info - IPC4 timestamp info
113  * @host_copier: the host copier of the pcm stream
114  * @dai_copier: the dai copier of the pcm stream
115  * @stream_start_offset: reported by fw in memory window (converted to
116  *                       frames at host_copier sampling rate)
117  * @stream_end_offset: reported by fw in memory window (converted to
118  *                     frames at host_copier sampling rate)
119  * @llp_offset: llp offset in memory window
120  * @delay: Calculated and stored in pointer callback. The stored value is
121  *         returned in the delay callback. Expressed in frames at host copier
122  *         sampling rate.
123  */
124 struct sof_ipc4_timestamp_info {
125 	struct sof_ipc4_copier *host_copier;
126 	struct sof_ipc4_copier *dai_copier;
127 	u64 stream_start_offset;
128 	u64 stream_end_offset;
129 	u32 llp_offset;
130 
131 	snd_pcm_sframes_t delay;
132 };
133 
134 extern const struct sof_ipc_fw_loader_ops ipc4_loader_ops;
135 extern const struct sof_ipc_tplg_ops ipc4_tplg_ops;
136 extern const struct sof_ipc_tplg_control_ops tplg_ipc4_control_ops;
137 extern const struct sof_ipc_pcm_ops ipc4_pcm_ops;
138 extern const struct sof_ipc_fw_tracing_ops ipc4_mtrace_ops;
139 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
140 extern const struct snd_compress_ops sof_ipc4_compressed_ops;
141 #endif
142 
143 int sof_ipc4_set_pipeline_state(struct snd_sof_dev *sdev, u32 instance_id, u32 state);
144 int sof_ipc4_mtrace_update_pos(struct snd_sof_dev *sdev, int core);
145 
146 int sof_ipc4_complete_split_release(struct snd_sof_dev *sdev);
147 int sof_ipc4_query_fw_configuration(struct snd_sof_dev *sdev);
148 int sof_ipc4_reload_fw_libraries(struct snd_sof_dev *sdev);
149 struct sof_ipc4_fw_module *sof_ipc4_find_module_by_uuid(struct snd_sof_dev *sdev,
150 							const guid_t *uuid);
151 
152 struct snd_sof_widget *sof_ipc4_find_swidget_by_ids(struct snd_sof_dev *sdev,
153 						    u32 module_id, int instance_id);
154 
155 struct sof_ipc4_base_module_cfg;
156 void sof_ipc4_update_cpc_from_manifest(struct snd_sof_dev *sdev,
157 				       struct sof_ipc4_fw_module *fw_module,
158 				       struct sof_ipc4_base_module_cfg *basecfg);
159 
160 size_t sof_ipc4_find_debug_slot_offset_by_type(struct snd_sof_dev *sdev,
161 					       u32 slot_type);
162 
163 void sof_ipc4_mic_privacy_state_change(struct snd_sof_dev *sdev, bool state);
164 
165 enum sof_ipc4_pipeline_state;
166 const char *sof_ipc4_pipeline_state_str(enum sof_ipc4_pipeline_state state);
167 
168 struct sof_ipc4_timestamp_info *sof_ipc4_sps_to_time_info(struct snd_sof_pcm_stream *sps);
169 void sof_ipc4_build_time_info(struct snd_sof_dev *sdev, struct snd_sof_pcm_stream *sps);
170 int sof_ipc4_get_stream_start_offset(struct snd_sof_dev *sdev,
171 				     struct snd_pcm_substream *substream,
172 				     struct snd_sof_pcm_stream *sps,
173 				     struct sof_ipc4_timestamp_info *time_info);
174 u64 sof_ipc4_frames_dai_to_host(struct sof_ipc4_timestamp_info *time_info, u64 value);
175 
176 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
177 void sof_ipc4_compr_drain_done(struct snd_sof_dev *sdev, void *ipc_message);
178 #else
179 static inline void sof_ipc4_compr_drain_done(struct snd_sof_dev *sdev,
180 					     void *ipc_message) { }
181 #endif
182 
183 #endif
184