1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
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.
6 // Copyright(c) 2019 Intel Corporation. All rights reserved.
8 // Authors: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
10 /* Generic SOF IPC code */
12 #include <linux/device.h>
13 #include <linux/export.h>
14 #include <linux/module.h>
15 #include <linux/types.h>
17 #include <sound/pcm.h>
18 #include <sound/sof/stream.h>
27 /* Mailbox-based Generic IPC implementation */
28 int sof_ipc_msg_data(struct snd_sof_dev *sdev,
29 struct snd_pcm_substream *substream,
32 if (!substream || !sdev->stream_box.size) {
33 snd_sof_dsp_mailbox_read(sdev, sdev->dsp_box.offset, p, sz);
35 struct sof_stream *stream = substream->runtime->private_data;
37 /* The stream might already be closed */
41 snd_sof_dsp_mailbox_read(sdev, stream->posn_offset, p, sz);
46 EXPORT_SYMBOL(sof_ipc_msg_data);
48 int sof_set_stream_data_offset(struct snd_sof_dev *sdev,
49 struct snd_pcm_substream *substream,
52 struct sof_stream *stream = substream->runtime->private_data;
54 /* check if offset is overflow or it is not aligned */
55 if (posn_offset > sdev->stream_box.size ||
56 posn_offset % sizeof(struct sof_ipc_stream_posn) != 0)
59 stream->posn_offset = sdev->stream_box.offset + posn_offset;
61 dev_dbg(sdev->dev, "pcm: stream dir %d, posn mailbox offset is %zu",
62 substream->stream, stream->posn_offset);
66 EXPORT_SYMBOL(sof_set_stream_data_offset);
68 int sof_stream_pcm_open(struct snd_sof_dev *sdev,
69 struct snd_pcm_substream *substream)
71 struct sof_stream *stream = kmalloc(sizeof(*stream), GFP_KERNEL);
76 /* binding pcm substream to hda stream */
77 substream->runtime->private_data = stream;
79 /* align to DMA minimum transfer size */
80 snd_pcm_hw_constraint_step(substream->runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 4);
82 /* avoid circular buffer wrap in middle of period */
83 snd_pcm_hw_constraint_integer(substream->runtime,
84 SNDRV_PCM_HW_PARAM_PERIODS);
88 EXPORT_SYMBOL(sof_stream_pcm_open);
90 int sof_stream_pcm_close(struct snd_sof_dev *sdev,
91 struct snd_pcm_substream *substream)
93 struct sof_stream *stream = substream->runtime->private_data;
95 substream->runtime->private_data = NULL;
100 EXPORT_SYMBOL(sof_stream_pcm_close);
102 MODULE_LICENSE("Dual BSD/GPL");