xref: /openbmc/linux/sound/soc/sof/ops.h (revision f71f59dd450813684d838e0c1d6602186b7d2d8f)
1e149ca29SPierre-Louis Bossart /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2d1d95fcbSLiam Girdwood /*
3d1d95fcbSLiam Girdwood  * This file is provided under a dual BSD/GPLv2 license.  When using or
4d1d95fcbSLiam Girdwood  * redistributing this file, you may do so under either license.
5d1d95fcbSLiam Girdwood  *
6d1d95fcbSLiam Girdwood  * Copyright(c) 2018 Intel Corporation. All rights reserved.
7d1d95fcbSLiam Girdwood  *
8d1d95fcbSLiam Girdwood  * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9d1d95fcbSLiam Girdwood  */
10d1d95fcbSLiam Girdwood 
11d1d95fcbSLiam Girdwood #ifndef __SOUND_SOC_SOF_IO_H
12d1d95fcbSLiam Girdwood #define __SOUND_SOC_SOF_IO_H
13d1d95fcbSLiam Girdwood 
14d1d95fcbSLiam Girdwood #include <linux/device.h>
15d1d95fcbSLiam Girdwood #include <linux/interrupt.h>
16d1d95fcbSLiam Girdwood #include <linux/kernel.h>
17d1d95fcbSLiam Girdwood #include <linux/types.h>
18d1d95fcbSLiam Girdwood #include <sound/pcm.h>
19d1d95fcbSLiam Girdwood #include "sof-priv.h"
20d1d95fcbSLiam Girdwood 
21d1d95fcbSLiam Girdwood #define sof_ops(sdev) \
22d1d95fcbSLiam Girdwood 	((sdev)->pdata->desc->ops)
23d1d95fcbSLiam Girdwood 
24d1d95fcbSLiam Girdwood /* Mandatory operations are verified during probing */
25d1d95fcbSLiam Girdwood 
26d1d95fcbSLiam Girdwood /* init */
27d1d95fcbSLiam Girdwood static inline int snd_sof_probe(struct snd_sof_dev *sdev)
28d1d95fcbSLiam Girdwood {
29d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->probe(sdev);
30d1d95fcbSLiam Girdwood }
31d1d95fcbSLiam Girdwood 
32d1d95fcbSLiam Girdwood static inline int snd_sof_remove(struct snd_sof_dev *sdev)
33d1d95fcbSLiam Girdwood {
34d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->remove)
35d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->remove(sdev);
36d1d95fcbSLiam Girdwood 
37d1d95fcbSLiam Girdwood 	return 0;
38d1d95fcbSLiam Girdwood }
39d1d95fcbSLiam Girdwood 
407edb3051SKeyon Jie static inline int snd_sof_shutdown(struct snd_sof_dev *sdev)
417edb3051SKeyon Jie {
427edb3051SKeyon Jie 	if (sof_ops(sdev)->shutdown)
437edb3051SKeyon Jie 		return sof_ops(sdev)->shutdown(sdev);
447edb3051SKeyon Jie 
457edb3051SKeyon Jie 	return 0;
467edb3051SKeyon Jie }
477edb3051SKeyon Jie 
48d1d95fcbSLiam Girdwood /* control */
49d1d95fcbSLiam Girdwood 
50d1d95fcbSLiam Girdwood /*
51d1d95fcbSLiam Girdwood  * snd_sof_dsp_run returns the core mask of the cores that are available
52d1d95fcbSLiam Girdwood  * after successful fw boot
53d1d95fcbSLiam Girdwood  */
54d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_run(struct snd_sof_dev *sdev)
55d1d95fcbSLiam Girdwood {
56d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->run(sdev);
57d1d95fcbSLiam Girdwood }
58d1d95fcbSLiam Girdwood 
59a70eb708SFred Oh static inline int snd_sof_dsp_stall(struct snd_sof_dev *sdev, unsigned int core_mask)
60d1d95fcbSLiam Girdwood {
61d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->stall)
62a70eb708SFred Oh 		return sof_ops(sdev)->stall(sdev, core_mask);
63d1d95fcbSLiam Girdwood 
64d1d95fcbSLiam Girdwood 	return 0;
65d1d95fcbSLiam Girdwood }
66d1d95fcbSLiam Girdwood 
67d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_reset(struct snd_sof_dev *sdev)
68d1d95fcbSLiam Girdwood {
69d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->reset)
70d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->reset(sdev);
71d1d95fcbSLiam Girdwood 
72d1d95fcbSLiam Girdwood 	return 0;
73d1d95fcbSLiam Girdwood }
74d1d95fcbSLiam Girdwood 
75d1d95fcbSLiam Girdwood /* dsp core power up/power down */
76d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_core_power_up(struct snd_sof_dev *sdev,
77d1d95fcbSLiam Girdwood 					    unsigned int core_mask)
78d1d95fcbSLiam Girdwood {
7942077f08SBard Liao 	int ret = 0;
80d1d95fcbSLiam Girdwood 
8130876e2aSBard Liao 	core_mask &= ~sdev->enabled_cores_mask;
8230876e2aSBard Liao 	if (sof_ops(sdev)->core_power_up && core_mask) {
8342077f08SBard Liao 		ret = sof_ops(sdev)->core_power_up(sdev, core_mask);
8442077f08SBard Liao 		if (!ret)
8542077f08SBard Liao 			sdev->enabled_cores_mask |= core_mask;
8642077f08SBard Liao 	}
8742077f08SBard Liao 
8842077f08SBard Liao 	return ret;
89d1d95fcbSLiam Girdwood }
90d1d95fcbSLiam Girdwood 
91d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_core_power_down(struct snd_sof_dev *sdev,
92d1d95fcbSLiam Girdwood 					      unsigned int core_mask)
93d1d95fcbSLiam Girdwood {
9442077f08SBard Liao 	int ret = 0;
95d1d95fcbSLiam Girdwood 
9630876e2aSBard Liao 	core_mask &= sdev->enabled_cores_mask;
9730876e2aSBard Liao 	if (sof_ops(sdev)->core_power_down && core_mask) {
9842077f08SBard Liao 		ret = sof_ops(sdev)->core_power_down(sdev, core_mask);
9942077f08SBard Liao 		if (!ret)
10042077f08SBard Liao 			sdev->enabled_cores_mask &= ~core_mask;
10142077f08SBard Liao 	}
10242077f08SBard Liao 
10342077f08SBard Liao 	return ret;
104d1d95fcbSLiam Girdwood }
105d1d95fcbSLiam Girdwood 
106d1d95fcbSLiam Girdwood /* pre/post fw load */
107d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_pre_fw_run(struct snd_sof_dev *sdev)
108d1d95fcbSLiam Girdwood {
109d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->pre_fw_run)
110d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pre_fw_run(sdev);
111d1d95fcbSLiam Girdwood 
112d1d95fcbSLiam Girdwood 	return 0;
113d1d95fcbSLiam Girdwood }
114d1d95fcbSLiam Girdwood 
115d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_post_fw_run(struct snd_sof_dev *sdev)
116d1d95fcbSLiam Girdwood {
117d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->post_fw_run)
118d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->post_fw_run(sdev);
119d1d95fcbSLiam Girdwood 
120d1d95fcbSLiam Girdwood 	return 0;
121d1d95fcbSLiam Girdwood }
122d1d95fcbSLiam Girdwood 
123e984f3efSFred Oh /* parse platform specific extended manifest */
124e984f3efSFred Oh static inline int snd_sof_dsp_parse_platform_ext_manifest(struct snd_sof_dev *sdev,
125e984f3efSFred Oh 							  const struct sof_ext_man_elem_header *hdr)
126e984f3efSFred Oh {
127e984f3efSFred Oh 	if (sof_ops(sdev)->parse_platform_ext_manifest)
128e984f3efSFred Oh 		return sof_ops(sdev)->parse_platform_ext_manifest(sdev, hdr);
129e984f3efSFred Oh 
130e984f3efSFred Oh 	return 0;
131e984f3efSFred Oh }
132e984f3efSFred Oh 
133ce8234a6SDaniel Baluta /* misc */
134ce8234a6SDaniel Baluta 
135ce8234a6SDaniel Baluta /**
136ce8234a6SDaniel Baluta  * snd_sof_dsp_get_bar_index - Maps a section type with a BAR index
137ce8234a6SDaniel Baluta  *
138ce8234a6SDaniel Baluta  * @sdev: sof device
139ce8234a6SDaniel Baluta  * @type: section type as described by snd_sof_fw_blk_type
140ce8234a6SDaniel Baluta  *
141ce8234a6SDaniel Baluta  * Returns the corresponding BAR index (a positive integer) or -EINVAL
142ce8234a6SDaniel Baluta  * in case there is no mapping
143ce8234a6SDaniel Baluta  */
144ce8234a6SDaniel Baluta static inline int snd_sof_dsp_get_bar_index(struct snd_sof_dev *sdev, u32 type)
145ce8234a6SDaniel Baluta {
146ce8234a6SDaniel Baluta 	if (sof_ops(sdev)->get_bar_index)
147ce8234a6SDaniel Baluta 		return sof_ops(sdev)->get_bar_index(sdev, type);
148ce8234a6SDaniel Baluta 
149ce8234a6SDaniel Baluta 	return sdev->mmio_bar;
150ce8234a6SDaniel Baluta }
151ce8234a6SDaniel Baluta 
152bb9c93f5SDaniel Baluta static inline int snd_sof_dsp_get_mailbox_offset(struct snd_sof_dev *sdev)
153bb9c93f5SDaniel Baluta {
154bb9c93f5SDaniel Baluta 	if (sof_ops(sdev)->get_mailbox_offset)
155bb9c93f5SDaniel Baluta 		return sof_ops(sdev)->get_mailbox_offset(sdev);
156bb9c93f5SDaniel Baluta 
157bb9c93f5SDaniel Baluta 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
158bb9c93f5SDaniel Baluta 	return -ENOTSUPP;
159bb9c93f5SDaniel Baluta }
160bb9c93f5SDaniel Baluta 
161e17422cdSDaniel Baluta static inline int snd_sof_dsp_get_window_offset(struct snd_sof_dev *sdev,
162e17422cdSDaniel Baluta 						u32 id)
163e17422cdSDaniel Baluta {
164e17422cdSDaniel Baluta 	if (sof_ops(sdev)->get_window_offset)
165e17422cdSDaniel Baluta 		return sof_ops(sdev)->get_window_offset(sdev, id);
166e17422cdSDaniel Baluta 
167e17422cdSDaniel Baluta 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
168e17422cdSDaniel Baluta 	return -ENOTSUPP;
169e17422cdSDaniel Baluta }
170d1d95fcbSLiam Girdwood /* power management */
171d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_resume(struct snd_sof_dev *sdev)
172d1d95fcbSLiam Girdwood {
173d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->resume)
174d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->resume(sdev);
175d1d95fcbSLiam Girdwood 
176d1d95fcbSLiam Girdwood 	return 0;
177d1d95fcbSLiam Girdwood }
178d1d95fcbSLiam Girdwood 
17961e285caSRanjani Sridharan static inline int snd_sof_dsp_suspend(struct snd_sof_dev *sdev,
18061e285caSRanjani Sridharan 				      u32 target_state)
181d1d95fcbSLiam Girdwood {
182d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->suspend)
18361e285caSRanjani Sridharan 		return sof_ops(sdev)->suspend(sdev, target_state);
184d1d95fcbSLiam Girdwood 
185d1d95fcbSLiam Girdwood 	return 0;
186d1d95fcbSLiam Girdwood }
187d1d95fcbSLiam Girdwood 
188d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_runtime_resume(struct snd_sof_dev *sdev)
189d1d95fcbSLiam Girdwood {
190d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->runtime_resume)
191d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->runtime_resume(sdev);
192d1d95fcbSLiam Girdwood 
193d1d95fcbSLiam Girdwood 	return 0;
194d1d95fcbSLiam Girdwood }
195d1d95fcbSLiam Girdwood 
1961c38c922SFred Oh static inline int snd_sof_dsp_runtime_suspend(struct snd_sof_dev *sdev)
197d1d95fcbSLiam Girdwood {
198d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->runtime_suspend)
1991c38c922SFred Oh 		return sof_ops(sdev)->runtime_suspend(sdev);
200d1d95fcbSLiam Girdwood 
201d1d95fcbSLiam Girdwood 	return 0;
202d1d95fcbSLiam Girdwood }
203d1d95fcbSLiam Girdwood 
20462fde977SKai Vehmanen static inline int snd_sof_dsp_runtime_idle(struct snd_sof_dev *sdev)
20562fde977SKai Vehmanen {
20662fde977SKai Vehmanen 	if (sof_ops(sdev)->runtime_idle)
20762fde977SKai Vehmanen 		return sof_ops(sdev)->runtime_idle(sdev);
20862fde977SKai Vehmanen 
20962fde977SKai Vehmanen 	return 0;
21062fde977SKai Vehmanen }
21162fde977SKai Vehmanen 
2127077a07aSRanjani Sridharan static inline int snd_sof_dsp_hw_params_upon_resume(struct snd_sof_dev *sdev)
213ed3baacdSRanjani Sridharan {
214ed3baacdSRanjani Sridharan 	if (sof_ops(sdev)->set_hw_params_upon_resume)
2157077a07aSRanjani Sridharan 		return sof_ops(sdev)->set_hw_params_upon_resume(sdev);
2167077a07aSRanjani Sridharan 	return 0;
217ed3baacdSRanjani Sridharan }
218ed3baacdSRanjani Sridharan 
219d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_set_clk(struct snd_sof_dev *sdev, u32 freq)
220d1d95fcbSLiam Girdwood {
221d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->set_clk)
222d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->set_clk(sdev, freq);
223d1d95fcbSLiam Girdwood 
224d1d95fcbSLiam Girdwood 	return 0;
225d1d95fcbSLiam Girdwood }
226d1d95fcbSLiam Girdwood 
22761e285caSRanjani Sridharan static inline int
22861e285caSRanjani Sridharan snd_sof_dsp_set_power_state(struct snd_sof_dev *sdev,
22961e285caSRanjani Sridharan 			    const struct sof_dsp_power_state *target_state)
230e8f112d8SKeyon Jie {
2318b66d7c5SKeyon Jie 	int ret = 0;
232e8f112d8SKeyon Jie 
2338b66d7c5SKeyon Jie 	mutex_lock(&sdev->power_state_access);
2348b66d7c5SKeyon Jie 
2358b66d7c5SKeyon Jie 	if (sof_ops(sdev)->set_power_state)
2368b66d7c5SKeyon Jie 		ret = sof_ops(sdev)->set_power_state(sdev, target_state);
2378b66d7c5SKeyon Jie 
2388b66d7c5SKeyon Jie 	mutex_unlock(&sdev->power_state_access);
2398b66d7c5SKeyon Jie 
2408b66d7c5SKeyon Jie 	return ret;
241e8f112d8SKeyon Jie }
242e8f112d8SKeyon Jie 
243d1d95fcbSLiam Girdwood /* debug */
244d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_dbg_dump(struct snd_sof_dev *sdev, u32 flags)
245d1d95fcbSLiam Girdwood {
246d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->dbg_dump)
2474f50f16eSPierre-Louis Bossart 		sof_ops(sdev)->dbg_dump(sdev, flags);
248d1d95fcbSLiam Girdwood }
249d1d95fcbSLiam Girdwood 
2505e4a27fdSPan Xiuli static inline void snd_sof_ipc_dump(struct snd_sof_dev *sdev)
2515e4a27fdSPan Xiuli {
2525e4a27fdSPan Xiuli 	if (sof_ops(sdev)->ipc_dump)
2534f50f16eSPierre-Louis Bossart 		sof_ops(sdev)->ipc_dump(sdev);
2545e4a27fdSPan Xiuli }
2555e4a27fdSPan Xiuli 
25607e833b4SPeter Ujfalusi static inline int snd_sof_debugfs_add_region_item(struct snd_sof_dev *sdev,
25707e833b4SPeter Ujfalusi 		enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size,
25807e833b4SPeter Ujfalusi 		const char *name, enum sof_debugfs_access_type access_type)
25907e833b4SPeter Ujfalusi {
26007e833b4SPeter Ujfalusi 	if (sof_ops(sdev) && sof_ops(sdev)->debugfs_add_region_item)
26107e833b4SPeter Ujfalusi 		return sof_ops(sdev)->debugfs_add_region_item(sdev, blk_type, offset,
26207e833b4SPeter Ujfalusi 							      size, name, access_type);
26307e833b4SPeter Ujfalusi 
26407e833b4SPeter Ujfalusi 	return 0;
26507e833b4SPeter Ujfalusi }
26607e833b4SPeter Ujfalusi 
267d1d95fcbSLiam Girdwood /* register IO */
268d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_write(struct snd_sof_dev *sdev, u32 bar,
269d1d95fcbSLiam Girdwood 				     u32 offset, u32 value)
270d1d95fcbSLiam Girdwood {
271d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->write) {
272d1d95fcbSLiam Girdwood 		sof_ops(sdev)->write(sdev, sdev->bar[bar] + offset, value);
273d1d95fcbSLiam Girdwood 		return;
274d1d95fcbSLiam Girdwood 	}
275d1d95fcbSLiam Girdwood 
276d1d95fcbSLiam Girdwood 	dev_err_ratelimited(sdev->dev, "error: %s not defined\n", __func__);
277d1d95fcbSLiam Girdwood }
278d1d95fcbSLiam Girdwood 
279d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_write64(struct snd_sof_dev *sdev, u32 bar,
280d1d95fcbSLiam Girdwood 				       u32 offset, u64 value)
281d1d95fcbSLiam Girdwood {
282d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->write64) {
283d1d95fcbSLiam Girdwood 		sof_ops(sdev)->write64(sdev, sdev->bar[bar] + offset, value);
284d1d95fcbSLiam Girdwood 		return;
285d1d95fcbSLiam Girdwood 	}
286d1d95fcbSLiam Girdwood 
287d1d95fcbSLiam Girdwood 	dev_err_ratelimited(sdev->dev, "error: %s not defined\n", __func__);
288d1d95fcbSLiam Girdwood }
289d1d95fcbSLiam Girdwood 
290d1d95fcbSLiam Girdwood static inline u32 snd_sof_dsp_read(struct snd_sof_dev *sdev, u32 bar,
291d1d95fcbSLiam Girdwood 				   u32 offset)
292d1d95fcbSLiam Girdwood {
293d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->read)
294d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->read(sdev, sdev->bar[bar] + offset);
295d1d95fcbSLiam Girdwood 
296d1d95fcbSLiam Girdwood 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
297d1d95fcbSLiam Girdwood 	return -ENOTSUPP;
298d1d95fcbSLiam Girdwood }
299d1d95fcbSLiam Girdwood 
300d1d95fcbSLiam Girdwood static inline u64 snd_sof_dsp_read64(struct snd_sof_dev *sdev, u32 bar,
301d1d95fcbSLiam Girdwood 				     u32 offset)
302d1d95fcbSLiam Girdwood {
303d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->read64)
304d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->read64(sdev, sdev->bar[bar] + offset);
305d1d95fcbSLiam Girdwood 
306d1d95fcbSLiam Girdwood 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
307d1d95fcbSLiam Girdwood 	return -ENOTSUPP;
308d1d95fcbSLiam Girdwood }
309d1d95fcbSLiam Girdwood 
310d1d95fcbSLiam Girdwood /* block IO */
3114624bb2fSPeter Ujfalusi static inline int snd_sof_dsp_block_read(struct snd_sof_dev *sdev,
3124624bb2fSPeter Ujfalusi 					 enum snd_sof_fw_blk_type blk_type,
313d1d95fcbSLiam Girdwood 					 u32 offset, void *dest, size_t bytes)
314d1d95fcbSLiam Girdwood {
3154624bb2fSPeter Ujfalusi 	return sof_ops(sdev)->block_read(sdev, blk_type, offset, dest, bytes);
316d1d95fcbSLiam Girdwood }
317d1d95fcbSLiam Girdwood 
3184624bb2fSPeter Ujfalusi static inline int snd_sof_dsp_block_write(struct snd_sof_dev *sdev,
3194624bb2fSPeter Ujfalusi 					  enum snd_sof_fw_blk_type blk_type,
320d1d95fcbSLiam Girdwood 					  u32 offset, void *src, size_t bytes)
321d1d95fcbSLiam Girdwood {
3224624bb2fSPeter Ujfalusi 	return sof_ops(sdev)->block_write(sdev, blk_type, offset, src, bytes);
323d1d95fcbSLiam Girdwood }
324d1d95fcbSLiam Girdwood 
325*f71f59ddSDaniel Baluta /* mailbox IO */
326*f71f59ddSDaniel Baluta static inline void snd_sof_dsp_mailbox_read(struct snd_sof_dev *sdev,
327*f71f59ddSDaniel Baluta 					    u32 offset, void *dest, size_t bytes)
328*f71f59ddSDaniel Baluta {
329*f71f59ddSDaniel Baluta 	if (sof_ops(sdev)->mailbox_read)
330*f71f59ddSDaniel Baluta 		sof_ops(sdev)->mailbox_read(sdev, offset, dest, bytes);
331*f71f59ddSDaniel Baluta }
332*f71f59ddSDaniel Baluta 
333*f71f59ddSDaniel Baluta static inline void snd_sof_dsp_mailbox_write(struct snd_sof_dev *sdev,
334*f71f59ddSDaniel Baluta 					     u32 offset, void *src, size_t bytes)
335*f71f59ddSDaniel Baluta {
336*f71f59ddSDaniel Baluta 	if (sof_ops(sdev)->mailbox_write)
337*f71f59ddSDaniel Baluta 		sof_ops(sdev)->mailbox_write(sdev, offset, src, bytes);
338*f71f59ddSDaniel Baluta }
339*f71f59ddSDaniel Baluta 
340d1d95fcbSLiam Girdwood /* ipc */
341d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_send_msg(struct snd_sof_dev *sdev,
342d1d95fcbSLiam Girdwood 				       struct snd_sof_ipc_msg *msg)
343d1d95fcbSLiam Girdwood {
344d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->send_msg(sdev, msg);
345d1d95fcbSLiam Girdwood }
346d1d95fcbSLiam Girdwood 
347d1d95fcbSLiam Girdwood /* host DMA trace */
348d1d95fcbSLiam Girdwood static inline int snd_sof_dma_trace_init(struct snd_sof_dev *sdev,
349d1d95fcbSLiam Girdwood 					 u32 *stream_tag)
350d1d95fcbSLiam Girdwood {
351d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->trace_init)
352d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->trace_init(sdev, stream_tag);
353d1d95fcbSLiam Girdwood 
354d1d95fcbSLiam Girdwood 	return 0;
355d1d95fcbSLiam Girdwood }
356d1d95fcbSLiam Girdwood 
357d1d95fcbSLiam Girdwood static inline int snd_sof_dma_trace_release(struct snd_sof_dev *sdev)
358d1d95fcbSLiam Girdwood {
359d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->trace_release)
360d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->trace_release(sdev);
361d1d95fcbSLiam Girdwood 
362d1d95fcbSLiam Girdwood 	return 0;
363d1d95fcbSLiam Girdwood }
364d1d95fcbSLiam Girdwood 
365d1d95fcbSLiam Girdwood static inline int snd_sof_dma_trace_trigger(struct snd_sof_dev *sdev, int cmd)
366d1d95fcbSLiam Girdwood {
367d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->trace_trigger)
368d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->trace_trigger(sdev, cmd);
369d1d95fcbSLiam Girdwood 
370d1d95fcbSLiam Girdwood 	return 0;
371d1d95fcbSLiam Girdwood }
372d1d95fcbSLiam Girdwood 
373d1d95fcbSLiam Girdwood /* host PCM ops */
374d1d95fcbSLiam Girdwood static inline int
375d1d95fcbSLiam Girdwood snd_sof_pcm_platform_open(struct snd_sof_dev *sdev,
376d1d95fcbSLiam Girdwood 			  struct snd_pcm_substream *substream)
377d1d95fcbSLiam Girdwood {
378d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_open)
379d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_open(sdev, substream);
380d1d95fcbSLiam Girdwood 
381d1d95fcbSLiam Girdwood 	return 0;
382d1d95fcbSLiam Girdwood }
383d1d95fcbSLiam Girdwood 
384d1d95fcbSLiam Girdwood /* disconnect pcm substream to a host stream */
385d1d95fcbSLiam Girdwood static inline int
386d1d95fcbSLiam Girdwood snd_sof_pcm_platform_close(struct snd_sof_dev *sdev,
387d1d95fcbSLiam Girdwood 			   struct snd_pcm_substream *substream)
388d1d95fcbSLiam Girdwood {
389d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_close)
390d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_close(sdev, substream);
391d1d95fcbSLiam Girdwood 
392d1d95fcbSLiam Girdwood 	return 0;
393d1d95fcbSLiam Girdwood }
394d1d95fcbSLiam Girdwood 
395d1d95fcbSLiam Girdwood /* host stream hw params */
396d1d95fcbSLiam Girdwood static inline int
397d1d95fcbSLiam Girdwood snd_sof_pcm_platform_hw_params(struct snd_sof_dev *sdev,
398d1d95fcbSLiam Girdwood 			       struct snd_pcm_substream *substream,
399d1d95fcbSLiam Girdwood 			       struct snd_pcm_hw_params *params,
400d1d95fcbSLiam Girdwood 			       struct sof_ipc_stream_params *ipc_params)
401d1d95fcbSLiam Girdwood {
402d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_hw_params)
403d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_hw_params(sdev, substream,
404d1d95fcbSLiam Girdwood 						    params, ipc_params);
405d1d95fcbSLiam Girdwood 
406d1d95fcbSLiam Girdwood 	return 0;
407d1d95fcbSLiam Girdwood }
408d1d95fcbSLiam Girdwood 
40993146bc2SRanjani Sridharan /* host stream hw free */
41093146bc2SRanjani Sridharan static inline int
41193146bc2SRanjani Sridharan snd_sof_pcm_platform_hw_free(struct snd_sof_dev *sdev,
41293146bc2SRanjani Sridharan 			     struct snd_pcm_substream *substream)
41393146bc2SRanjani Sridharan {
41493146bc2SRanjani Sridharan 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_hw_free)
41593146bc2SRanjani Sridharan 		return sof_ops(sdev)->pcm_hw_free(sdev, substream);
41693146bc2SRanjani Sridharan 
41793146bc2SRanjani Sridharan 	return 0;
41893146bc2SRanjani Sridharan }
41993146bc2SRanjani Sridharan 
420d1d95fcbSLiam Girdwood /* host stream trigger */
421d1d95fcbSLiam Girdwood static inline int
422d1d95fcbSLiam Girdwood snd_sof_pcm_platform_trigger(struct snd_sof_dev *sdev,
423d1d95fcbSLiam Girdwood 			     struct snd_pcm_substream *substream, int cmd)
424d1d95fcbSLiam Girdwood {
425d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_trigger)
426d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_trigger(sdev, substream, cmd);
427d1d95fcbSLiam Girdwood 
428d1d95fcbSLiam Girdwood 	return 0;
429d1d95fcbSLiam Girdwood }
430d1d95fcbSLiam Girdwood 
43196ec1741SPeter Ujfalusi /* Firmware loading */
43296ec1741SPeter Ujfalusi static inline int snd_sof_load_firmware(struct snd_sof_dev *sdev)
43396ec1741SPeter Ujfalusi {
43496ec1741SPeter Ujfalusi 	dev_dbg(sdev->dev, "loading firmware\n");
43596ec1741SPeter Ujfalusi 
43696ec1741SPeter Ujfalusi 	return sof_ops(sdev)->load_firmware(sdev);
43796ec1741SPeter Ujfalusi }
43896ec1741SPeter Ujfalusi 
439d1d95fcbSLiam Girdwood /* host DSP message data */
4406a0ba071SGuennadi Liakhovetski static inline int snd_sof_ipc_msg_data(struct snd_sof_dev *sdev,
441d1d95fcbSLiam Girdwood 				       struct snd_pcm_substream *substream,
442d1d95fcbSLiam Girdwood 				       void *p, size_t sz)
443d1d95fcbSLiam Girdwood {
4446a0ba071SGuennadi Liakhovetski 	return sof_ops(sdev)->ipc_msg_data(sdev, substream, p, sz);
445d1d95fcbSLiam Girdwood }
446d1d95fcbSLiam Girdwood 
447d1d95fcbSLiam Girdwood /* host configure DSP HW parameters */
448d1d95fcbSLiam Girdwood static inline int
449d1d95fcbSLiam Girdwood snd_sof_ipc_pcm_params(struct snd_sof_dev *sdev,
450d1d95fcbSLiam Girdwood 		       struct snd_pcm_substream *substream,
451d1d95fcbSLiam Girdwood 		       const struct sof_ipc_pcm_params_reply *reply)
452d1d95fcbSLiam Girdwood {
453d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->ipc_pcm_params(sdev, substream, reply);
454d1d95fcbSLiam Girdwood }
455d1d95fcbSLiam Girdwood 
456d1d95fcbSLiam Girdwood /* host stream pointer */
457d1d95fcbSLiam Girdwood static inline snd_pcm_uframes_t
458d1d95fcbSLiam Girdwood snd_sof_pcm_platform_pointer(struct snd_sof_dev *sdev,
459d1d95fcbSLiam Girdwood 			     struct snd_pcm_substream *substream)
460d1d95fcbSLiam Girdwood {
461d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_pointer)
462d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_pointer(sdev, substream);
463d1d95fcbSLiam Girdwood 
464d1d95fcbSLiam Girdwood 	return 0;
465d1d95fcbSLiam Girdwood }
466d1d95fcbSLiam Girdwood 
467e145e9afSCezary Rojewski #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
468e145e9afSCezary Rojewski static inline int
469e145e9afSCezary Rojewski snd_sof_probe_compr_assign(struct snd_sof_dev *sdev,
470e145e9afSCezary Rojewski 		struct snd_compr_stream *cstream, struct snd_soc_dai *dai)
471e145e9afSCezary Rojewski {
472e145e9afSCezary Rojewski 	return sof_ops(sdev)->probe_assign(sdev, cstream, dai);
473e145e9afSCezary Rojewski }
474e145e9afSCezary Rojewski 
475e145e9afSCezary Rojewski static inline int
476e145e9afSCezary Rojewski snd_sof_probe_compr_free(struct snd_sof_dev *sdev,
477e145e9afSCezary Rojewski 		struct snd_compr_stream *cstream, struct snd_soc_dai *dai)
478e145e9afSCezary Rojewski {
479e145e9afSCezary Rojewski 	return sof_ops(sdev)->probe_free(sdev, cstream, dai);
480e145e9afSCezary Rojewski }
481e145e9afSCezary Rojewski 
482e145e9afSCezary Rojewski static inline int
483e145e9afSCezary Rojewski snd_sof_probe_compr_set_params(struct snd_sof_dev *sdev,
484e145e9afSCezary Rojewski 		struct snd_compr_stream *cstream,
485e145e9afSCezary Rojewski 		struct snd_compr_params *params, struct snd_soc_dai *dai)
486e145e9afSCezary Rojewski {
487e145e9afSCezary Rojewski 	return sof_ops(sdev)->probe_set_params(sdev, cstream, params, dai);
488e145e9afSCezary Rojewski }
489e145e9afSCezary Rojewski 
490e145e9afSCezary Rojewski static inline int
491e145e9afSCezary Rojewski snd_sof_probe_compr_trigger(struct snd_sof_dev *sdev,
492e145e9afSCezary Rojewski 		struct snd_compr_stream *cstream, int cmd,
493e145e9afSCezary Rojewski 		struct snd_soc_dai *dai)
494e145e9afSCezary Rojewski {
495e145e9afSCezary Rojewski 	return sof_ops(sdev)->probe_trigger(sdev, cstream, cmd, dai);
496e145e9afSCezary Rojewski }
497e145e9afSCezary Rojewski 
498e145e9afSCezary Rojewski static inline int
499e145e9afSCezary Rojewski snd_sof_probe_compr_pointer(struct snd_sof_dev *sdev,
500e145e9afSCezary Rojewski 		struct snd_compr_stream *cstream,
501e145e9afSCezary Rojewski 		struct snd_compr_tstamp *tstamp, struct snd_soc_dai *dai)
502e145e9afSCezary Rojewski {
503e145e9afSCezary Rojewski 	if (sof_ops(sdev) && sof_ops(sdev)->probe_pointer)
504e145e9afSCezary Rojewski 		return sof_ops(sdev)->probe_pointer(sdev, cstream, tstamp, dai);
505e145e9afSCezary Rojewski 
506e145e9afSCezary Rojewski 	return 0;
507e145e9afSCezary Rojewski }
508e145e9afSCezary Rojewski #endif
509e145e9afSCezary Rojewski 
510285880a2SDaniel Baluta /* machine driver */
511285880a2SDaniel Baluta static inline int
512285880a2SDaniel Baluta snd_sof_machine_register(struct snd_sof_dev *sdev, void *pdata)
513285880a2SDaniel Baluta {
514285880a2SDaniel Baluta 	if (sof_ops(sdev) && sof_ops(sdev)->machine_register)
515285880a2SDaniel Baluta 		return sof_ops(sdev)->machine_register(sdev, pdata);
516285880a2SDaniel Baluta 
517285880a2SDaniel Baluta 	return 0;
518285880a2SDaniel Baluta }
519285880a2SDaniel Baluta 
520285880a2SDaniel Baluta static inline void
521285880a2SDaniel Baluta snd_sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata)
522285880a2SDaniel Baluta {
523285880a2SDaniel Baluta 	if (sof_ops(sdev) && sof_ops(sdev)->machine_unregister)
524285880a2SDaniel Baluta 		sof_ops(sdev)->machine_unregister(sdev, pdata);
525285880a2SDaniel Baluta }
526285880a2SDaniel Baluta 
527285880a2SDaniel Baluta static inline void
528285880a2SDaniel Baluta snd_sof_machine_select(struct snd_sof_dev *sdev)
529285880a2SDaniel Baluta {
530285880a2SDaniel Baluta 	if (sof_ops(sdev) && sof_ops(sdev)->machine_select)
531285880a2SDaniel Baluta 		sof_ops(sdev)->machine_select(sdev);
532285880a2SDaniel Baluta }
533285880a2SDaniel Baluta 
534285880a2SDaniel Baluta static inline void
535285880a2SDaniel Baluta snd_sof_set_mach_params(const struct snd_soc_acpi_mach *mach,
53617e9d6b0SPierre-Louis Bossart 			struct snd_sof_dev *sdev)
537285880a2SDaniel Baluta {
538285880a2SDaniel Baluta 	if (sof_ops(sdev) && sof_ops(sdev)->set_mach_params)
53917e9d6b0SPierre-Louis Bossart 		sof_ops(sdev)->set_mach_params(mach, sdev);
540285880a2SDaniel Baluta }
541285880a2SDaniel Baluta 
542d1d95fcbSLiam Girdwood /**
543d1d95fcbSLiam Girdwood  * snd_sof_dsp_register_poll_timeout - Periodically poll an address
544d1d95fcbSLiam Girdwood  * until a condition is met or a timeout occurs
545d1d95fcbSLiam Girdwood  * @op: accessor function (takes @addr as its only argument)
546d1d95fcbSLiam Girdwood  * @addr: Address to poll
547d1d95fcbSLiam Girdwood  * @val: Variable to read the value into
548d1d95fcbSLiam Girdwood  * @cond: Break condition (usually involving @val)
549d1d95fcbSLiam Girdwood  * @sleep_us: Maximum time to sleep between reads in us (0
550d1d95fcbSLiam Girdwood  *            tight-loops).  Should be less than ~20ms since usleep_range
551458f69efSMauro Carvalho Chehab  *            is used (see Documentation/timers/timers-howto.rst).
552d1d95fcbSLiam Girdwood  * @timeout_us: Timeout in us, 0 means never timeout
553d1d95fcbSLiam Girdwood  *
554d1d95fcbSLiam Girdwood  * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
555d1d95fcbSLiam Girdwood  * case, the last read value at @addr is stored in @val. Must not
556d1d95fcbSLiam Girdwood  * be called from atomic context if sleep_us or timeout_us are used.
557d1d95fcbSLiam Girdwood  *
558d1d95fcbSLiam Girdwood  * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
559d1d95fcbSLiam Girdwood  */
560d1d95fcbSLiam Girdwood #define snd_sof_dsp_read_poll_timeout(sdev, bar, offset, val, cond, sleep_us, timeout_us) \
561d1d95fcbSLiam Girdwood ({ \
562d1d95fcbSLiam Girdwood 	u64 __timeout_us = (timeout_us); \
563d1d95fcbSLiam Girdwood 	unsigned long __sleep_us = (sleep_us); \
564d1d95fcbSLiam Girdwood 	ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
565d1d95fcbSLiam Girdwood 	might_sleep_if((__sleep_us) != 0); \
566d1d95fcbSLiam Girdwood 	for (;;) {							\
567d1d95fcbSLiam Girdwood 		(val) = snd_sof_dsp_read(sdev, bar, offset);		\
568d1d95fcbSLiam Girdwood 		if (cond) { \
569d1d95fcbSLiam Girdwood 			dev_dbg(sdev->dev, \
5703b2e93edSKeyon Jie 				"FW Poll Status: reg[%#x]=%#x successful\n", \
5713b2e93edSKeyon Jie 				(offset), (val)); \
572d1d95fcbSLiam Girdwood 			break; \
573d1d95fcbSLiam Girdwood 		} \
574d1d95fcbSLiam Girdwood 		if (__timeout_us && \
575d1d95fcbSLiam Girdwood 		    ktime_compare(ktime_get(), __timeout) > 0) { \
576d1d95fcbSLiam Girdwood 			(val) = snd_sof_dsp_read(sdev, bar, offset); \
577d1d95fcbSLiam Girdwood 			dev_dbg(sdev->dev, \
5783b2e93edSKeyon Jie 				"FW Poll Status: reg[%#x]=%#x timedout\n", \
5793b2e93edSKeyon Jie 				(offset), (val)); \
580d1d95fcbSLiam Girdwood 			break; \
581d1d95fcbSLiam Girdwood 		} \
582d1d95fcbSLiam Girdwood 		if (__sleep_us) \
583d1d95fcbSLiam Girdwood 			usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
584d1d95fcbSLiam Girdwood 	} \
585d1d95fcbSLiam Girdwood 	(cond) ? 0 : -ETIMEDOUT; \
586d1d95fcbSLiam Girdwood })
587d1d95fcbSLiam Girdwood 
588d1d95fcbSLiam Girdwood /* This is for registers bits with attribute RWC */
589d1d95fcbSLiam Girdwood bool snd_sof_pci_update_bits(struct snd_sof_dev *sdev, u32 offset,
590d1d95fcbSLiam Girdwood 			     u32 mask, u32 value);
591d1d95fcbSLiam Girdwood 
592d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits_unlocked(struct snd_sof_dev *sdev, u32 bar,
593d1d95fcbSLiam Girdwood 				      u32 offset, u32 mask, u32 value);
594d1d95fcbSLiam Girdwood 
595d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits64_unlocked(struct snd_sof_dev *sdev, u32 bar,
596d1d95fcbSLiam Girdwood 					u32 offset, u64 mask, u64 value);
597d1d95fcbSLiam Girdwood 
598d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits(struct snd_sof_dev *sdev, u32 bar, u32 offset,
599d1d95fcbSLiam Girdwood 			     u32 mask, u32 value);
600d1d95fcbSLiam Girdwood 
601d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits64(struct snd_sof_dev *sdev, u32 bar,
602d1d95fcbSLiam Girdwood 			       u32 offset, u64 mask, u64 value);
603d1d95fcbSLiam Girdwood 
604d1d95fcbSLiam Girdwood void snd_sof_dsp_update_bits_forced(struct snd_sof_dev *sdev, u32 bar,
605d1d95fcbSLiam Girdwood 				    u32 offset, u32 mask, u32 value);
606d1d95fcbSLiam Girdwood 
607d1d95fcbSLiam Girdwood int snd_sof_dsp_register_poll(struct snd_sof_dev *sdev, u32 bar, u32 offset,
608d1d95fcbSLiam Girdwood 			      u32 mask, u32 target, u32 timeout_ms,
609d1d95fcbSLiam Girdwood 			      u32 interval_us);
610d1d95fcbSLiam Girdwood 
611d1d95fcbSLiam Girdwood void snd_sof_dsp_panic(struct snd_sof_dev *sdev, u32 offset);
612d1d95fcbSLiam Girdwood #endif
613