1671e0b90SPeter Ujfalusi // SPDX-License-Identifier: GPL-2.0-only
2671e0b90SPeter Ujfalusi //
3671e0b90SPeter Ujfalusi // Copyright(c) 2022 Intel Corporation. All rights reserved.
4671e0b90SPeter Ujfalusi //
5671e0b90SPeter Ujfalusi // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
6671e0b90SPeter Ujfalusi
7671e0b90SPeter Ujfalusi #include <linux/debugfs.h>
8671e0b90SPeter Ujfalusi #include <linux/sched/signal.h>
9671e0b90SPeter Ujfalusi #include "sof-priv.h"
10671e0b90SPeter Ujfalusi #include "sof-audio.h"
11671e0b90SPeter Ujfalusi #include "ops.h"
12671e0b90SPeter Ujfalusi #include "sof-utils.h"
13671e0b90SPeter Ujfalusi #include "ipc3-priv.h"
14671e0b90SPeter Ujfalusi
15671e0b90SPeter Ujfalusi #define TRACE_FILTER_ELEMENTS_PER_ENTRY 4
16671e0b90SPeter Ujfalusi #define TRACE_FILTER_MAX_CONFIG_STRING_LENGTH 1024
17671e0b90SPeter Ujfalusi
1806835329SPeter Ujfalusi enum sof_dtrace_state {
1906835329SPeter Ujfalusi SOF_DTRACE_DISABLED,
2006835329SPeter Ujfalusi SOF_DTRACE_STOPPED,
21135786c3SPeter Ujfalusi SOF_DTRACE_INITIALIZING,
2206835329SPeter Ujfalusi SOF_DTRACE_ENABLED,
2306835329SPeter Ujfalusi };
2406835329SPeter Ujfalusi
2506835329SPeter Ujfalusi struct sof_dtrace_priv {
2606835329SPeter Ujfalusi struct snd_dma_buffer dmatb;
2706835329SPeter Ujfalusi struct snd_dma_buffer dmatp;
2806835329SPeter Ujfalusi int dma_trace_pages;
2906835329SPeter Ujfalusi wait_queue_head_t trace_sleep;
3006835329SPeter Ujfalusi u32 host_offset;
3106835329SPeter Ujfalusi bool dtrace_error;
3206835329SPeter Ujfalusi bool dtrace_draining;
3306835329SPeter Ujfalusi enum sof_dtrace_state dtrace_state;
3406835329SPeter Ujfalusi };
3506835329SPeter Ujfalusi
trace_pos_update_expected(struct sof_dtrace_priv * priv)36135786c3SPeter Ujfalusi static bool trace_pos_update_expected(struct sof_dtrace_priv *priv)
37135786c3SPeter Ujfalusi {
38135786c3SPeter Ujfalusi if (priv->dtrace_state == SOF_DTRACE_ENABLED ||
39135786c3SPeter Ujfalusi priv->dtrace_state == SOF_DTRACE_INITIALIZING)
40135786c3SPeter Ujfalusi return true;
41135786c3SPeter Ujfalusi
42135786c3SPeter Ujfalusi return false;
43135786c3SPeter Ujfalusi }
44135786c3SPeter Ujfalusi
trace_filter_append_elem(struct snd_sof_dev * sdev,u32 key,u32 value,struct sof_ipc_trace_filter_elem * elem_list,int capacity,int * counter)45671e0b90SPeter Ujfalusi static int trace_filter_append_elem(struct snd_sof_dev *sdev, u32 key, u32 value,
46671e0b90SPeter Ujfalusi struct sof_ipc_trace_filter_elem *elem_list,
47671e0b90SPeter Ujfalusi int capacity, int *counter)
48671e0b90SPeter Ujfalusi {
49671e0b90SPeter Ujfalusi if (*counter >= capacity)
50671e0b90SPeter Ujfalusi return -ENOMEM;
51671e0b90SPeter Ujfalusi
52671e0b90SPeter Ujfalusi elem_list[*counter].key = key;
53671e0b90SPeter Ujfalusi elem_list[*counter].value = value;
54671e0b90SPeter Ujfalusi ++*counter;
55671e0b90SPeter Ujfalusi
56671e0b90SPeter Ujfalusi return 0;
57671e0b90SPeter Ujfalusi }
58671e0b90SPeter Ujfalusi
trace_filter_parse_entry(struct snd_sof_dev * sdev,const char * line,struct sof_ipc_trace_filter_elem * elem,int capacity,int * counter)59671e0b90SPeter Ujfalusi static int trace_filter_parse_entry(struct snd_sof_dev *sdev, const char *line,
60671e0b90SPeter Ujfalusi struct sof_ipc_trace_filter_elem *elem,
61671e0b90SPeter Ujfalusi int capacity, int *counter)
62671e0b90SPeter Ujfalusi {
63671e0b90SPeter Ujfalusi int log_level, pipe_id, comp_id, read, ret;
64671e0b90SPeter Ujfalusi int len = strlen(line);
65671e0b90SPeter Ujfalusi int cnt = *counter;
66671e0b90SPeter Ujfalusi u32 uuid_id;
67671e0b90SPeter Ujfalusi
68671e0b90SPeter Ujfalusi /* ignore empty content */
69671e0b90SPeter Ujfalusi ret = sscanf(line, " %n", &read);
70671e0b90SPeter Ujfalusi if (!ret && read == len)
71671e0b90SPeter Ujfalusi return len;
72671e0b90SPeter Ujfalusi
73671e0b90SPeter Ujfalusi ret = sscanf(line, " %d %x %d %d %n", &log_level, &uuid_id, &pipe_id, &comp_id, &read);
74671e0b90SPeter Ujfalusi if (ret != TRACE_FILTER_ELEMENTS_PER_ENTRY || read != len) {
75671e0b90SPeter Ujfalusi dev_err(sdev->dev, "Invalid trace filter entry '%s'\n", line);
76671e0b90SPeter Ujfalusi return -EINVAL;
77671e0b90SPeter Ujfalusi }
78671e0b90SPeter Ujfalusi
79671e0b90SPeter Ujfalusi if (uuid_id > 0) {
80671e0b90SPeter Ujfalusi ret = trace_filter_append_elem(sdev, SOF_IPC_TRACE_FILTER_ELEM_BY_UUID,
81671e0b90SPeter Ujfalusi uuid_id, elem, capacity, &cnt);
82671e0b90SPeter Ujfalusi if (ret)
83671e0b90SPeter Ujfalusi return ret;
84671e0b90SPeter Ujfalusi }
85671e0b90SPeter Ujfalusi if (pipe_id >= 0) {
86671e0b90SPeter Ujfalusi ret = trace_filter_append_elem(sdev, SOF_IPC_TRACE_FILTER_ELEM_BY_PIPE,
87671e0b90SPeter Ujfalusi pipe_id, elem, capacity, &cnt);
88671e0b90SPeter Ujfalusi if (ret)
89671e0b90SPeter Ujfalusi return ret;
90671e0b90SPeter Ujfalusi }
91671e0b90SPeter Ujfalusi if (comp_id >= 0) {
92671e0b90SPeter Ujfalusi ret = trace_filter_append_elem(sdev, SOF_IPC_TRACE_FILTER_ELEM_BY_COMP,
93671e0b90SPeter Ujfalusi comp_id, elem, capacity, &cnt);
94671e0b90SPeter Ujfalusi if (ret)
95671e0b90SPeter Ujfalusi return ret;
96671e0b90SPeter Ujfalusi }
97671e0b90SPeter Ujfalusi
98671e0b90SPeter Ujfalusi ret = trace_filter_append_elem(sdev, SOF_IPC_TRACE_FILTER_ELEM_SET_LEVEL |
99671e0b90SPeter Ujfalusi SOF_IPC_TRACE_FILTER_ELEM_FIN,
100671e0b90SPeter Ujfalusi log_level, elem, capacity, &cnt);
101671e0b90SPeter Ujfalusi if (ret)
102671e0b90SPeter Ujfalusi return ret;
103671e0b90SPeter Ujfalusi
104671e0b90SPeter Ujfalusi /* update counter only when parsing whole entry passed */
105671e0b90SPeter Ujfalusi *counter = cnt;
106671e0b90SPeter Ujfalusi
107671e0b90SPeter Ujfalusi return len;
108671e0b90SPeter Ujfalusi }
109671e0b90SPeter Ujfalusi
trace_filter_parse(struct snd_sof_dev * sdev,char * string,int * out_elem_cnt,struct sof_ipc_trace_filter_elem ** out)110671e0b90SPeter Ujfalusi static int trace_filter_parse(struct snd_sof_dev *sdev, char *string,
111671e0b90SPeter Ujfalusi int *out_elem_cnt,
112671e0b90SPeter Ujfalusi struct sof_ipc_trace_filter_elem **out)
113671e0b90SPeter Ujfalusi {
114671e0b90SPeter Ujfalusi static const char entry_delimiter[] = ";";
115671e0b90SPeter Ujfalusi char *entry = string;
116671e0b90SPeter Ujfalusi int capacity = 0;
117671e0b90SPeter Ujfalusi int entry_len;
118671e0b90SPeter Ujfalusi int cnt = 0;
119671e0b90SPeter Ujfalusi
120671e0b90SPeter Ujfalusi /*
121671e0b90SPeter Ujfalusi * Each entry contains at least 1, up to TRACE_FILTER_ELEMENTS_PER_ENTRY
122671e0b90SPeter Ujfalusi * IPC elements, depending on content. Calculate IPC elements capacity
123671e0b90SPeter Ujfalusi * for the input string where each element is set.
124671e0b90SPeter Ujfalusi */
125671e0b90SPeter Ujfalusi while (entry) {
126671e0b90SPeter Ujfalusi capacity += TRACE_FILTER_ELEMENTS_PER_ENTRY;
127671e0b90SPeter Ujfalusi entry = strchr(entry + 1, entry_delimiter[0]);
128671e0b90SPeter Ujfalusi }
129671e0b90SPeter Ujfalusi *out = kmalloc(capacity * sizeof(**out), GFP_KERNEL);
130671e0b90SPeter Ujfalusi if (!*out)
131671e0b90SPeter Ujfalusi return -ENOMEM;
132671e0b90SPeter Ujfalusi
133671e0b90SPeter Ujfalusi /* split input string by ';', and parse each entry separately in trace_filter_parse_entry */
134671e0b90SPeter Ujfalusi while ((entry = strsep(&string, entry_delimiter))) {
135671e0b90SPeter Ujfalusi entry_len = trace_filter_parse_entry(sdev, entry, *out, capacity, &cnt);
136671e0b90SPeter Ujfalusi if (entry_len < 0) {
137671e0b90SPeter Ujfalusi dev_err(sdev->dev,
138671e0b90SPeter Ujfalusi "Parsing filter entry '%s' failed with %d\n",
139671e0b90SPeter Ujfalusi entry, entry_len);
140671e0b90SPeter Ujfalusi return -EINVAL;
141671e0b90SPeter Ujfalusi }
142671e0b90SPeter Ujfalusi }
143671e0b90SPeter Ujfalusi
144671e0b90SPeter Ujfalusi *out_elem_cnt = cnt;
145671e0b90SPeter Ujfalusi
146671e0b90SPeter Ujfalusi return 0;
147671e0b90SPeter Ujfalusi }
148671e0b90SPeter Ujfalusi
ipc3_trace_update_filter(struct snd_sof_dev * sdev,int num_elems,struct sof_ipc_trace_filter_elem * elems)149671e0b90SPeter Ujfalusi static int ipc3_trace_update_filter(struct snd_sof_dev *sdev, int num_elems,
150671e0b90SPeter Ujfalusi struct sof_ipc_trace_filter_elem *elems)
151671e0b90SPeter Ujfalusi {
152671e0b90SPeter Ujfalusi struct sof_ipc_trace_filter *msg;
153671e0b90SPeter Ujfalusi size_t size;
154671e0b90SPeter Ujfalusi int ret;
155671e0b90SPeter Ujfalusi
156671e0b90SPeter Ujfalusi size = struct_size(msg, elems, num_elems);
157671e0b90SPeter Ujfalusi if (size > SOF_IPC_MSG_MAX_SIZE)
158671e0b90SPeter Ujfalusi return -EINVAL;
159671e0b90SPeter Ujfalusi
160671e0b90SPeter Ujfalusi msg = kmalloc(size, GFP_KERNEL);
161671e0b90SPeter Ujfalusi if (!msg)
162671e0b90SPeter Ujfalusi return -ENOMEM;
163671e0b90SPeter Ujfalusi
164671e0b90SPeter Ujfalusi msg->hdr.size = size;
165671e0b90SPeter Ujfalusi msg->hdr.cmd = SOF_IPC_GLB_TRACE_MSG | SOF_IPC_TRACE_FILTER_UPDATE;
166671e0b90SPeter Ujfalusi msg->elem_cnt = num_elems;
167671e0b90SPeter Ujfalusi memcpy(&msg->elems[0], elems, num_elems * sizeof(*elems));
168671e0b90SPeter Ujfalusi
169c7b6c95cSPierre-Louis Bossart ret = pm_runtime_resume_and_get(sdev->dev);
170671e0b90SPeter Ujfalusi if (ret < 0 && ret != -EACCES) {
171671e0b90SPeter Ujfalusi dev_err(sdev->dev, "enabling device failed: %d\n", ret);
172671e0b90SPeter Ujfalusi goto error;
173671e0b90SPeter Ujfalusi }
174367fd6ffSCurtis Malainey ret = sof_ipc_tx_message_no_reply(sdev->ipc, msg, msg->hdr.size);
175671e0b90SPeter Ujfalusi pm_runtime_mark_last_busy(sdev->dev);
176671e0b90SPeter Ujfalusi pm_runtime_put_autosuspend(sdev->dev);
177671e0b90SPeter Ujfalusi
178671e0b90SPeter Ujfalusi error:
179671e0b90SPeter Ujfalusi kfree(msg);
180367fd6ffSCurtis Malainey return ret;
181671e0b90SPeter Ujfalusi }
182671e0b90SPeter Ujfalusi
dfsentry_trace_filter_write(struct file * file,const char __user * from,size_t count,loff_t * ppos)183671e0b90SPeter Ujfalusi static ssize_t dfsentry_trace_filter_write(struct file *file, const char __user *from,
184671e0b90SPeter Ujfalusi size_t count, loff_t *ppos)
185671e0b90SPeter Ujfalusi {
186671e0b90SPeter Ujfalusi struct snd_sof_dfsentry *dfse = file->private_data;
187671e0b90SPeter Ujfalusi struct sof_ipc_trace_filter_elem *elems = NULL;
188671e0b90SPeter Ujfalusi struct snd_sof_dev *sdev = dfse->sdev;
189671e0b90SPeter Ujfalusi int num_elems;
190671e0b90SPeter Ujfalusi char *string;
191671e0b90SPeter Ujfalusi int ret;
192671e0b90SPeter Ujfalusi
193671e0b90SPeter Ujfalusi if (count > TRACE_FILTER_MAX_CONFIG_STRING_LENGTH) {
194671e0b90SPeter Ujfalusi dev_err(sdev->dev, "%s too long input, %zu > %d\n", __func__, count,
195671e0b90SPeter Ujfalusi TRACE_FILTER_MAX_CONFIG_STRING_LENGTH);
196671e0b90SPeter Ujfalusi return -EINVAL;
197671e0b90SPeter Ujfalusi }
198671e0b90SPeter Ujfalusi
199*93fd2be6SYang Yingliang string = memdup_user_nul(from, count);
200*93fd2be6SYang Yingliang if (IS_ERR(string))
201*93fd2be6SYang Yingliang return PTR_ERR(string);
202671e0b90SPeter Ujfalusi
203671e0b90SPeter Ujfalusi ret = trace_filter_parse(sdev, string, &num_elems, &elems);
204671e0b90SPeter Ujfalusi if (ret < 0)
205671e0b90SPeter Ujfalusi goto error;
206671e0b90SPeter Ujfalusi
207671e0b90SPeter Ujfalusi if (num_elems) {
208671e0b90SPeter Ujfalusi ret = ipc3_trace_update_filter(sdev, num_elems, elems);
209671e0b90SPeter Ujfalusi if (ret < 0) {
210671e0b90SPeter Ujfalusi dev_err(sdev->dev, "Filter update failed: %d\n", ret);
211671e0b90SPeter Ujfalusi goto error;
212671e0b90SPeter Ujfalusi }
213671e0b90SPeter Ujfalusi }
214671e0b90SPeter Ujfalusi ret = count;
215671e0b90SPeter Ujfalusi error:
216671e0b90SPeter Ujfalusi kfree(string);
217671e0b90SPeter Ujfalusi kfree(elems);
218671e0b90SPeter Ujfalusi return ret;
219671e0b90SPeter Ujfalusi }
220671e0b90SPeter Ujfalusi
221671e0b90SPeter Ujfalusi static const struct file_operations sof_dfs_trace_filter_fops = {
222671e0b90SPeter Ujfalusi .open = simple_open,
223671e0b90SPeter Ujfalusi .write = dfsentry_trace_filter_write,
224671e0b90SPeter Ujfalusi .llseek = default_llseek,
225671e0b90SPeter Ujfalusi };
226671e0b90SPeter Ujfalusi
debugfs_create_trace_filter(struct snd_sof_dev * sdev)227671e0b90SPeter Ujfalusi static int debugfs_create_trace_filter(struct snd_sof_dev *sdev)
228671e0b90SPeter Ujfalusi {
229671e0b90SPeter Ujfalusi struct snd_sof_dfsentry *dfse;
230671e0b90SPeter Ujfalusi
231671e0b90SPeter Ujfalusi dfse = devm_kzalloc(sdev->dev, sizeof(*dfse), GFP_KERNEL);
232671e0b90SPeter Ujfalusi if (!dfse)
233671e0b90SPeter Ujfalusi return -ENOMEM;
234671e0b90SPeter Ujfalusi
235671e0b90SPeter Ujfalusi dfse->sdev = sdev;
236671e0b90SPeter Ujfalusi dfse->type = SOF_DFSENTRY_TYPE_BUF;
237671e0b90SPeter Ujfalusi
238671e0b90SPeter Ujfalusi debugfs_create_file("filter", 0200, sdev->debugfs_root, dfse,
239671e0b90SPeter Ujfalusi &sof_dfs_trace_filter_fops);
240671e0b90SPeter Ujfalusi /* add to dfsentry list */
241671e0b90SPeter Ujfalusi list_add(&dfse->list, &sdev->dfsentry_list);
242671e0b90SPeter Ujfalusi
243671e0b90SPeter Ujfalusi return 0;
244671e0b90SPeter Ujfalusi }
245671e0b90SPeter Ujfalusi
sof_dtrace_set_host_offset(struct sof_dtrace_priv * priv,u32 new_offset)246b66f9e70SPeter Ujfalusi static bool sof_dtrace_set_host_offset(struct sof_dtrace_priv *priv, u32 new_offset)
247b66f9e70SPeter Ujfalusi {
248b66f9e70SPeter Ujfalusi u32 host_offset = READ_ONCE(priv->host_offset);
249b66f9e70SPeter Ujfalusi
250b66f9e70SPeter Ujfalusi if (host_offset != new_offset) {
251b66f9e70SPeter Ujfalusi /* This is a bit paranoid and unlikely that it is needed */
252b66f9e70SPeter Ujfalusi u32 ret = cmpxchg(&priv->host_offset, host_offset, new_offset);
253b66f9e70SPeter Ujfalusi
254b66f9e70SPeter Ujfalusi if (ret == host_offset)
255b66f9e70SPeter Ujfalusi return true;
256b66f9e70SPeter Ujfalusi }
257b66f9e70SPeter Ujfalusi
258b66f9e70SPeter Ujfalusi return false;
259b66f9e70SPeter Ujfalusi }
260b66f9e70SPeter Ujfalusi
sof_dtrace_avail(struct snd_sof_dev * sdev,loff_t pos,size_t buffer_size)261671e0b90SPeter Ujfalusi static size_t sof_dtrace_avail(struct snd_sof_dev *sdev,
262671e0b90SPeter Ujfalusi loff_t pos, size_t buffer_size)
263671e0b90SPeter Ujfalusi {
26406835329SPeter Ujfalusi struct sof_dtrace_priv *priv = sdev->fw_trace_data;
26506835329SPeter Ujfalusi loff_t host_offset = READ_ONCE(priv->host_offset);
266671e0b90SPeter Ujfalusi
267671e0b90SPeter Ujfalusi /*
268671e0b90SPeter Ujfalusi * If host offset is less than local pos, it means write pointer of
269671e0b90SPeter Ujfalusi * host DMA buffer has been wrapped. We should output the trace data
270671e0b90SPeter Ujfalusi * at the end of host DMA buffer at first.
271671e0b90SPeter Ujfalusi */
272671e0b90SPeter Ujfalusi if (host_offset < pos)
273671e0b90SPeter Ujfalusi return buffer_size - pos;
274671e0b90SPeter Ujfalusi
275671e0b90SPeter Ujfalusi /* If there is available trace data now, it is unnecessary to wait. */
276671e0b90SPeter Ujfalusi if (host_offset > pos)
277671e0b90SPeter Ujfalusi return host_offset - pos;
278671e0b90SPeter Ujfalusi
279671e0b90SPeter Ujfalusi return 0;
280671e0b90SPeter Ujfalusi }
281671e0b90SPeter Ujfalusi
sof_wait_dtrace_avail(struct snd_sof_dev * sdev,loff_t pos,size_t buffer_size)282671e0b90SPeter Ujfalusi static size_t sof_wait_dtrace_avail(struct snd_sof_dev *sdev, loff_t pos,
283671e0b90SPeter Ujfalusi size_t buffer_size)
284671e0b90SPeter Ujfalusi {
285671e0b90SPeter Ujfalusi size_t ret = sof_dtrace_avail(sdev, pos, buffer_size);
28606835329SPeter Ujfalusi struct sof_dtrace_priv *priv = sdev->fw_trace_data;
28706835329SPeter Ujfalusi wait_queue_entry_t wait;
288671e0b90SPeter Ujfalusi
289671e0b90SPeter Ujfalusi /* data immediately available */
290671e0b90SPeter Ujfalusi if (ret)
291671e0b90SPeter Ujfalusi return ret;
292671e0b90SPeter Ujfalusi
293135786c3SPeter Ujfalusi if (priv->dtrace_draining && !trace_pos_update_expected(priv)) {
294671e0b90SPeter Ujfalusi /*
295671e0b90SPeter Ujfalusi * tracing has ended and all traces have been
296671e0b90SPeter Ujfalusi * read by client, return EOF
297671e0b90SPeter Ujfalusi */
29806835329SPeter Ujfalusi priv->dtrace_draining = false;
299671e0b90SPeter Ujfalusi return 0;
300671e0b90SPeter Ujfalusi }
301671e0b90SPeter Ujfalusi
302671e0b90SPeter Ujfalusi /* wait for available trace data from FW */
303671e0b90SPeter Ujfalusi init_waitqueue_entry(&wait, current);
304671e0b90SPeter Ujfalusi set_current_state(TASK_INTERRUPTIBLE);
30506835329SPeter Ujfalusi add_wait_queue(&priv->trace_sleep, &wait);
306671e0b90SPeter Ujfalusi
307671e0b90SPeter Ujfalusi if (!signal_pending(current)) {
308671e0b90SPeter Ujfalusi /* set timeout to max value, no error code */
309671e0b90SPeter Ujfalusi schedule_timeout(MAX_SCHEDULE_TIMEOUT);
310671e0b90SPeter Ujfalusi }
31106835329SPeter Ujfalusi remove_wait_queue(&priv->trace_sleep, &wait);
312671e0b90SPeter Ujfalusi
313671e0b90SPeter Ujfalusi return sof_dtrace_avail(sdev, pos, buffer_size);
314671e0b90SPeter Ujfalusi }
315671e0b90SPeter Ujfalusi
dfsentry_dtrace_read(struct file * file,char __user * buffer,size_t count,loff_t * ppos)316671e0b90SPeter Ujfalusi static ssize_t dfsentry_dtrace_read(struct file *file, char __user *buffer,
317671e0b90SPeter Ujfalusi size_t count, loff_t *ppos)
318671e0b90SPeter Ujfalusi {
319671e0b90SPeter Ujfalusi struct snd_sof_dfsentry *dfse = file->private_data;
320671e0b90SPeter Ujfalusi struct snd_sof_dev *sdev = dfse->sdev;
32106835329SPeter Ujfalusi struct sof_dtrace_priv *priv = sdev->fw_trace_data;
322671e0b90SPeter Ujfalusi unsigned long rem;
323671e0b90SPeter Ujfalusi loff_t lpos = *ppos;
324671e0b90SPeter Ujfalusi size_t avail, buffer_size = dfse->size;
325671e0b90SPeter Ujfalusi u64 lpos_64;
326671e0b90SPeter Ujfalusi
327671e0b90SPeter Ujfalusi /* make sure we know about any failures on the DSP side */
32806835329SPeter Ujfalusi priv->dtrace_error = false;
329671e0b90SPeter Ujfalusi
330671e0b90SPeter Ujfalusi /* check pos and count */
331671e0b90SPeter Ujfalusi if (lpos < 0)
332671e0b90SPeter Ujfalusi return -EINVAL;
333671e0b90SPeter Ujfalusi if (!count)
334671e0b90SPeter Ujfalusi return 0;
335671e0b90SPeter Ujfalusi
336671e0b90SPeter Ujfalusi /* check for buffer wrap and count overflow */
337671e0b90SPeter Ujfalusi lpos_64 = lpos;
338671e0b90SPeter Ujfalusi lpos = do_div(lpos_64, buffer_size);
339671e0b90SPeter Ujfalusi
340671e0b90SPeter Ujfalusi /* get available count based on current host offset */
341671e0b90SPeter Ujfalusi avail = sof_wait_dtrace_avail(sdev, lpos, buffer_size);
34206835329SPeter Ujfalusi if (priv->dtrace_error) {
343671e0b90SPeter Ujfalusi dev_err(sdev->dev, "trace IO error\n");
344671e0b90SPeter Ujfalusi return -EIO;
345671e0b90SPeter Ujfalusi }
346671e0b90SPeter Ujfalusi
3471e90de2cSPeter Ujfalusi /* no new trace data */
3481e90de2cSPeter Ujfalusi if (!avail)
3491e90de2cSPeter Ujfalusi return 0;
3501e90de2cSPeter Ujfalusi
351671e0b90SPeter Ujfalusi /* make sure count is <= avail */
352671e0b90SPeter Ujfalusi if (count > avail)
353671e0b90SPeter Ujfalusi count = avail;
354671e0b90SPeter Ujfalusi
355671e0b90SPeter Ujfalusi /*
356671e0b90SPeter Ujfalusi * make sure that all trace data is available for the CPU as the trace
357671e0b90SPeter Ujfalusi * data buffer might be allocated from non consistent memory.
358671e0b90SPeter Ujfalusi * Note: snd_dma_buffer_sync() is called for normal audio playback and
359671e0b90SPeter Ujfalusi * capture streams also.
360671e0b90SPeter Ujfalusi */
36106835329SPeter Ujfalusi snd_dma_buffer_sync(&priv->dmatb, SNDRV_DMA_SYNC_CPU);
362671e0b90SPeter Ujfalusi /* copy available trace data to debugfs */
363671e0b90SPeter Ujfalusi rem = copy_to_user(buffer, ((u8 *)(dfse->buf) + lpos), count);
364671e0b90SPeter Ujfalusi if (rem)
365671e0b90SPeter Ujfalusi return -EFAULT;
366671e0b90SPeter Ujfalusi
367671e0b90SPeter Ujfalusi *ppos += count;
368671e0b90SPeter Ujfalusi
369671e0b90SPeter Ujfalusi /* move debugfs reading position */
370671e0b90SPeter Ujfalusi return count;
371671e0b90SPeter Ujfalusi }
372671e0b90SPeter Ujfalusi
dfsentry_dtrace_release(struct inode * inode,struct file * file)373671e0b90SPeter Ujfalusi static int dfsentry_dtrace_release(struct inode *inode, struct file *file)
374671e0b90SPeter Ujfalusi {
375671e0b90SPeter Ujfalusi struct snd_sof_dfsentry *dfse = inode->i_private;
376671e0b90SPeter Ujfalusi struct snd_sof_dev *sdev = dfse->sdev;
37706835329SPeter Ujfalusi struct sof_dtrace_priv *priv = sdev->fw_trace_data;
378671e0b90SPeter Ujfalusi
379671e0b90SPeter Ujfalusi /* avoid duplicate traces at next open */
38006835329SPeter Ujfalusi if (priv->dtrace_state != SOF_DTRACE_ENABLED)
381b66f9e70SPeter Ujfalusi sof_dtrace_set_host_offset(priv, 0);
382671e0b90SPeter Ujfalusi
383671e0b90SPeter Ujfalusi return 0;
384671e0b90SPeter Ujfalusi }
385671e0b90SPeter Ujfalusi
386671e0b90SPeter Ujfalusi static const struct file_operations sof_dfs_dtrace_fops = {
387671e0b90SPeter Ujfalusi .open = simple_open,
388671e0b90SPeter Ujfalusi .read = dfsentry_dtrace_read,
389671e0b90SPeter Ujfalusi .llseek = default_llseek,
390671e0b90SPeter Ujfalusi .release = dfsentry_dtrace_release,
391671e0b90SPeter Ujfalusi };
392671e0b90SPeter Ujfalusi
debugfs_create_dtrace(struct snd_sof_dev * sdev)393671e0b90SPeter Ujfalusi static int debugfs_create_dtrace(struct snd_sof_dev *sdev)
394671e0b90SPeter Ujfalusi {
39506835329SPeter Ujfalusi struct sof_dtrace_priv *priv;
396671e0b90SPeter Ujfalusi struct snd_sof_dfsentry *dfse;
397671e0b90SPeter Ujfalusi int ret;
398671e0b90SPeter Ujfalusi
399671e0b90SPeter Ujfalusi if (!sdev)
400671e0b90SPeter Ujfalusi return -EINVAL;
401671e0b90SPeter Ujfalusi
40206835329SPeter Ujfalusi priv = sdev->fw_trace_data;
40306835329SPeter Ujfalusi
404671e0b90SPeter Ujfalusi ret = debugfs_create_trace_filter(sdev);
405671e0b90SPeter Ujfalusi if (ret < 0)
406671e0b90SPeter Ujfalusi dev_warn(sdev->dev, "failed to create filter debugfs file: %d", ret);
407671e0b90SPeter Ujfalusi
408671e0b90SPeter Ujfalusi dfse = devm_kzalloc(sdev->dev, sizeof(*dfse), GFP_KERNEL);
409671e0b90SPeter Ujfalusi if (!dfse)
410671e0b90SPeter Ujfalusi return -ENOMEM;
411671e0b90SPeter Ujfalusi
412671e0b90SPeter Ujfalusi dfse->type = SOF_DFSENTRY_TYPE_BUF;
41306835329SPeter Ujfalusi dfse->buf = priv->dmatb.area;
41406835329SPeter Ujfalusi dfse->size = priv->dmatb.bytes;
415671e0b90SPeter Ujfalusi dfse->sdev = sdev;
416671e0b90SPeter Ujfalusi
417671e0b90SPeter Ujfalusi debugfs_create_file("trace", 0444, sdev->debugfs_root, dfse,
418671e0b90SPeter Ujfalusi &sof_dfs_dtrace_fops);
419671e0b90SPeter Ujfalusi
420671e0b90SPeter Ujfalusi return 0;
421671e0b90SPeter Ujfalusi }
422671e0b90SPeter Ujfalusi
ipc3_dtrace_enable(struct snd_sof_dev * sdev)423671e0b90SPeter Ujfalusi static int ipc3_dtrace_enable(struct snd_sof_dev *sdev)
424671e0b90SPeter Ujfalusi {
42506835329SPeter Ujfalusi struct sof_dtrace_priv *priv = sdev->fw_trace_data;
426671e0b90SPeter Ujfalusi struct sof_ipc_fw_ready *ready = &sdev->fw_ready;
427671e0b90SPeter Ujfalusi struct sof_ipc_fw_version *v = &ready->version;
428671e0b90SPeter Ujfalusi struct sof_ipc_dma_trace_params_ext params;
429671e0b90SPeter Ujfalusi int ret;
430671e0b90SPeter Ujfalusi
431671e0b90SPeter Ujfalusi if (!sdev->fw_trace_is_supported)
432671e0b90SPeter Ujfalusi return 0;
433671e0b90SPeter Ujfalusi
43406835329SPeter Ujfalusi if (priv->dtrace_state == SOF_DTRACE_ENABLED || !priv->dma_trace_pages)
435671e0b90SPeter Ujfalusi return -EINVAL;
436671e0b90SPeter Ujfalusi
43706835329SPeter Ujfalusi if (priv->dtrace_state == SOF_DTRACE_STOPPED)
438671e0b90SPeter Ujfalusi goto start;
439671e0b90SPeter Ujfalusi
440671e0b90SPeter Ujfalusi /* set IPC parameters */
441671e0b90SPeter Ujfalusi params.hdr.cmd = SOF_IPC_GLB_TRACE_MSG;
442671e0b90SPeter Ujfalusi /* PARAMS_EXT is only supported from ABI 3.7.0 onwards */
443671e0b90SPeter Ujfalusi if (v->abi_version >= SOF_ABI_VER(3, 7, 0)) {
444671e0b90SPeter Ujfalusi params.hdr.size = sizeof(struct sof_ipc_dma_trace_params_ext);
445671e0b90SPeter Ujfalusi params.hdr.cmd |= SOF_IPC_TRACE_DMA_PARAMS_EXT;
446671e0b90SPeter Ujfalusi params.timestamp_ns = ktime_get(); /* in nanosecond */
447671e0b90SPeter Ujfalusi } else {
448671e0b90SPeter Ujfalusi params.hdr.size = sizeof(struct sof_ipc_dma_trace_params);
449671e0b90SPeter Ujfalusi params.hdr.cmd |= SOF_IPC_TRACE_DMA_PARAMS;
450671e0b90SPeter Ujfalusi }
45106835329SPeter Ujfalusi params.buffer.phy_addr = priv->dmatp.addr;
45206835329SPeter Ujfalusi params.buffer.size = priv->dmatb.bytes;
45306835329SPeter Ujfalusi params.buffer.pages = priv->dma_trace_pages;
454671e0b90SPeter Ujfalusi params.stream_tag = 0;
455671e0b90SPeter Ujfalusi
456b66f9e70SPeter Ujfalusi sof_dtrace_set_host_offset(priv, 0);
45706835329SPeter Ujfalusi priv->dtrace_draining = false;
458671e0b90SPeter Ujfalusi
45906835329SPeter Ujfalusi ret = sof_dtrace_host_init(sdev, &priv->dmatb, ¶ms);
460671e0b90SPeter Ujfalusi if (ret < 0) {
461671e0b90SPeter Ujfalusi dev_err(sdev->dev, "Host dtrace init failed: %d\n", ret);
462671e0b90SPeter Ujfalusi return ret;
463671e0b90SPeter Ujfalusi }
4649fd8fcd0SPierre-Louis Bossart dev_dbg(sdev->dev, "stream_tag: %d\n", params.stream_tag);
465671e0b90SPeter Ujfalusi
466671e0b90SPeter Ujfalusi /* send IPC to the DSP */
467135786c3SPeter Ujfalusi priv->dtrace_state = SOF_DTRACE_INITIALIZING;
468367fd6ffSCurtis Malainey ret = sof_ipc_tx_message_no_reply(sdev->ipc, ¶ms, sizeof(params));
469671e0b90SPeter Ujfalusi if (ret < 0) {
470671e0b90SPeter Ujfalusi dev_err(sdev->dev, "can't set params for DMA for trace %d\n", ret);
471671e0b90SPeter Ujfalusi goto trace_release;
472671e0b90SPeter Ujfalusi }
473671e0b90SPeter Ujfalusi
474671e0b90SPeter Ujfalusi start:
475135786c3SPeter Ujfalusi priv->dtrace_state = SOF_DTRACE_ENABLED;
476135786c3SPeter Ujfalusi
477b69979a1SPeter Ujfalusi ret = sof_dtrace_host_trigger(sdev, SNDRV_PCM_TRIGGER_START);
478671e0b90SPeter Ujfalusi if (ret < 0) {
479671e0b90SPeter Ujfalusi dev_err(sdev->dev, "Host dtrace trigger start failed: %d\n", ret);
480671e0b90SPeter Ujfalusi goto trace_release;
481671e0b90SPeter Ujfalusi }
482671e0b90SPeter Ujfalusi
483671e0b90SPeter Ujfalusi return 0;
484671e0b90SPeter Ujfalusi
485671e0b90SPeter Ujfalusi trace_release:
486135786c3SPeter Ujfalusi priv->dtrace_state = SOF_DTRACE_DISABLED;
487b69979a1SPeter Ujfalusi sof_dtrace_host_release(sdev);
488671e0b90SPeter Ujfalusi return ret;
489671e0b90SPeter Ujfalusi }
490671e0b90SPeter Ujfalusi
ipc3_dtrace_init(struct snd_sof_dev * sdev)491671e0b90SPeter Ujfalusi static int ipc3_dtrace_init(struct snd_sof_dev *sdev)
492671e0b90SPeter Ujfalusi {
49306835329SPeter Ujfalusi struct sof_dtrace_priv *priv;
494671e0b90SPeter Ujfalusi int ret;
495671e0b90SPeter Ujfalusi
496671e0b90SPeter Ujfalusi /* dtrace is only supported with SOF_IPC */
497671e0b90SPeter Ujfalusi if (sdev->pdata->ipc_type != SOF_IPC)
498671e0b90SPeter Ujfalusi return -EOPNOTSUPP;
499671e0b90SPeter Ujfalusi
50006835329SPeter Ujfalusi if (sdev->fw_trace_data) {
50106835329SPeter Ujfalusi dev_err(sdev->dev, "fw_trace_data has been already allocated\n");
50206835329SPeter Ujfalusi return -EBUSY;
50306835329SPeter Ujfalusi }
50406835329SPeter Ujfalusi
50506835329SPeter Ujfalusi priv = devm_kzalloc(sdev->dev, sizeof(*priv), GFP_KERNEL);
50606835329SPeter Ujfalusi if (!priv)
50706835329SPeter Ujfalusi return -ENOMEM;
50806835329SPeter Ujfalusi
50906835329SPeter Ujfalusi sdev->fw_trace_data = priv;
51006835329SPeter Ujfalusi
511671e0b90SPeter Ujfalusi /* set false before start initialization */
51206835329SPeter Ujfalusi priv->dtrace_state = SOF_DTRACE_DISABLED;
513671e0b90SPeter Ujfalusi
514671e0b90SPeter Ujfalusi /* allocate trace page table buffer */
515671e0b90SPeter Ujfalusi ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, sdev->dev,
51606835329SPeter Ujfalusi PAGE_SIZE, &priv->dmatp);
517671e0b90SPeter Ujfalusi if (ret < 0) {
518671e0b90SPeter Ujfalusi dev_err(sdev->dev, "can't alloc page table for trace %d\n", ret);
519671e0b90SPeter Ujfalusi return ret;
520671e0b90SPeter Ujfalusi }
521671e0b90SPeter Ujfalusi
522671e0b90SPeter Ujfalusi /* allocate trace data buffer */
523671e0b90SPeter Ujfalusi ret = snd_dma_alloc_dir_pages(SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
524671e0b90SPeter Ujfalusi DMA_FROM_DEVICE, DMA_BUF_SIZE_FOR_TRACE,
52506835329SPeter Ujfalusi &priv->dmatb);
526671e0b90SPeter Ujfalusi if (ret < 0) {
527671e0b90SPeter Ujfalusi dev_err(sdev->dev, "can't alloc buffer for trace %d\n", ret);
528671e0b90SPeter Ujfalusi goto page_err;
529671e0b90SPeter Ujfalusi }
530671e0b90SPeter Ujfalusi
531671e0b90SPeter Ujfalusi /* create compressed page table for audio firmware */
53206835329SPeter Ujfalusi ret = snd_sof_create_page_table(sdev->dev, &priv->dmatb,
53306835329SPeter Ujfalusi priv->dmatp.area, priv->dmatb.bytes);
534671e0b90SPeter Ujfalusi if (ret < 0)
535671e0b90SPeter Ujfalusi goto table_err;
536671e0b90SPeter Ujfalusi
53706835329SPeter Ujfalusi priv->dma_trace_pages = ret;
5389fd8fcd0SPierre-Louis Bossart dev_dbg(sdev->dev, "dma_trace_pages: %d\n", priv->dma_trace_pages);
539671e0b90SPeter Ujfalusi
540671e0b90SPeter Ujfalusi if (sdev->first_boot) {
541671e0b90SPeter Ujfalusi ret = debugfs_create_dtrace(sdev);
542671e0b90SPeter Ujfalusi if (ret < 0)
543671e0b90SPeter Ujfalusi goto table_err;
544671e0b90SPeter Ujfalusi }
545671e0b90SPeter Ujfalusi
54606835329SPeter Ujfalusi init_waitqueue_head(&priv->trace_sleep);
547671e0b90SPeter Ujfalusi
548671e0b90SPeter Ujfalusi ret = ipc3_dtrace_enable(sdev);
549671e0b90SPeter Ujfalusi if (ret < 0)
550671e0b90SPeter Ujfalusi goto table_err;
551671e0b90SPeter Ujfalusi
552671e0b90SPeter Ujfalusi return 0;
553671e0b90SPeter Ujfalusi table_err:
55406835329SPeter Ujfalusi priv->dma_trace_pages = 0;
55506835329SPeter Ujfalusi snd_dma_free_pages(&priv->dmatb);
556671e0b90SPeter Ujfalusi page_err:
55706835329SPeter Ujfalusi snd_dma_free_pages(&priv->dmatp);
558671e0b90SPeter Ujfalusi return ret;
559671e0b90SPeter Ujfalusi }
560671e0b90SPeter Ujfalusi
ipc3_dtrace_posn_update(struct snd_sof_dev * sdev,struct sof_ipc_dma_trace_posn * posn)561671e0b90SPeter Ujfalusi int ipc3_dtrace_posn_update(struct snd_sof_dev *sdev,
562671e0b90SPeter Ujfalusi struct sof_ipc_dma_trace_posn *posn)
563671e0b90SPeter Ujfalusi {
56406835329SPeter Ujfalusi struct sof_dtrace_priv *priv = sdev->fw_trace_data;
56506835329SPeter Ujfalusi
566671e0b90SPeter Ujfalusi if (!sdev->fw_trace_is_supported)
567671e0b90SPeter Ujfalusi return 0;
568671e0b90SPeter Ujfalusi
569135786c3SPeter Ujfalusi if (trace_pos_update_expected(priv) &&
570b66f9e70SPeter Ujfalusi sof_dtrace_set_host_offset(priv, posn->host_offset))
57106835329SPeter Ujfalusi wake_up(&priv->trace_sleep);
572671e0b90SPeter Ujfalusi
573671e0b90SPeter Ujfalusi if (posn->overflow != 0)
574671e0b90SPeter Ujfalusi dev_err(sdev->dev,
575671e0b90SPeter Ujfalusi "DSP trace buffer overflow %u bytes. Total messages %d\n",
576671e0b90SPeter Ujfalusi posn->overflow, posn->messages);
577671e0b90SPeter Ujfalusi
578671e0b90SPeter Ujfalusi return 0;
579671e0b90SPeter Ujfalusi }
580671e0b90SPeter Ujfalusi
581671e0b90SPeter Ujfalusi /* an error has occurred within the DSP that prevents further trace */
ipc3_dtrace_fw_crashed(struct snd_sof_dev * sdev)582671e0b90SPeter Ujfalusi static void ipc3_dtrace_fw_crashed(struct snd_sof_dev *sdev)
583671e0b90SPeter Ujfalusi {
58406835329SPeter Ujfalusi struct sof_dtrace_priv *priv = sdev->fw_trace_data;
58506835329SPeter Ujfalusi
58606835329SPeter Ujfalusi if (priv->dtrace_state == SOF_DTRACE_ENABLED) {
58706835329SPeter Ujfalusi priv->dtrace_error = true;
58806835329SPeter Ujfalusi wake_up(&priv->trace_sleep);
589671e0b90SPeter Ujfalusi }
590671e0b90SPeter Ujfalusi }
591671e0b90SPeter Ujfalusi
ipc3_dtrace_release(struct snd_sof_dev * sdev,bool only_stop)592671e0b90SPeter Ujfalusi static void ipc3_dtrace_release(struct snd_sof_dev *sdev, bool only_stop)
593671e0b90SPeter Ujfalusi {
59406835329SPeter Ujfalusi struct sof_dtrace_priv *priv = sdev->fw_trace_data;
595671e0b90SPeter Ujfalusi struct sof_ipc_fw_ready *ready = &sdev->fw_ready;
596671e0b90SPeter Ujfalusi struct sof_ipc_fw_version *v = &ready->version;
597671e0b90SPeter Ujfalusi struct sof_ipc_cmd_hdr hdr;
598671e0b90SPeter Ujfalusi int ret;
599671e0b90SPeter Ujfalusi
60006835329SPeter Ujfalusi if (!sdev->fw_trace_is_supported || priv->dtrace_state == SOF_DTRACE_DISABLED)
601671e0b90SPeter Ujfalusi return;
602671e0b90SPeter Ujfalusi
603b69979a1SPeter Ujfalusi ret = sof_dtrace_host_trigger(sdev, SNDRV_PCM_TRIGGER_STOP);
604671e0b90SPeter Ujfalusi if (ret < 0)
605671e0b90SPeter Ujfalusi dev_err(sdev->dev, "Host dtrace trigger stop failed: %d\n", ret);
60606835329SPeter Ujfalusi priv->dtrace_state = SOF_DTRACE_STOPPED;
607671e0b90SPeter Ujfalusi
608671e0b90SPeter Ujfalusi /*
609671e0b90SPeter Ujfalusi * stop and free trace DMA in the DSP. TRACE_DMA_FREE is only supported from
610671e0b90SPeter Ujfalusi * ABI 3.20.0 onwards
611671e0b90SPeter Ujfalusi */
612671e0b90SPeter Ujfalusi if (v->abi_version >= SOF_ABI_VER(3, 20, 0)) {
613671e0b90SPeter Ujfalusi hdr.size = sizeof(hdr);
614671e0b90SPeter Ujfalusi hdr.cmd = SOF_IPC_GLB_TRACE_MSG | SOF_IPC_TRACE_DMA_FREE;
615671e0b90SPeter Ujfalusi
616367fd6ffSCurtis Malainey ret = sof_ipc_tx_message_no_reply(sdev->ipc, &hdr, hdr.size);
617671e0b90SPeter Ujfalusi if (ret < 0)
618671e0b90SPeter Ujfalusi dev_err(sdev->dev, "DMA_TRACE_FREE failed with error: %d\n", ret);
619671e0b90SPeter Ujfalusi }
620671e0b90SPeter Ujfalusi
621671e0b90SPeter Ujfalusi if (only_stop)
622671e0b90SPeter Ujfalusi goto out;
623671e0b90SPeter Ujfalusi
624b69979a1SPeter Ujfalusi ret = sof_dtrace_host_release(sdev);
625671e0b90SPeter Ujfalusi if (ret < 0)
626671e0b90SPeter Ujfalusi dev_err(sdev->dev, "Host dtrace release failed %d\n", ret);
627671e0b90SPeter Ujfalusi
62806835329SPeter Ujfalusi priv->dtrace_state = SOF_DTRACE_DISABLED;
629671e0b90SPeter Ujfalusi
630671e0b90SPeter Ujfalusi out:
63106835329SPeter Ujfalusi priv->dtrace_draining = true;
63206835329SPeter Ujfalusi wake_up(&priv->trace_sleep);
633671e0b90SPeter Ujfalusi }
634671e0b90SPeter Ujfalusi
ipc3_dtrace_suspend(struct snd_sof_dev * sdev,pm_message_t pm_state)635671e0b90SPeter Ujfalusi static void ipc3_dtrace_suspend(struct snd_sof_dev *sdev, pm_message_t pm_state)
636671e0b90SPeter Ujfalusi {
637671e0b90SPeter Ujfalusi ipc3_dtrace_release(sdev, pm_state.event == SOF_DSP_PM_D0);
638671e0b90SPeter Ujfalusi }
639671e0b90SPeter Ujfalusi
ipc3_dtrace_resume(struct snd_sof_dev * sdev)640671e0b90SPeter Ujfalusi static int ipc3_dtrace_resume(struct snd_sof_dev *sdev)
641671e0b90SPeter Ujfalusi {
642671e0b90SPeter Ujfalusi return ipc3_dtrace_enable(sdev);
643671e0b90SPeter Ujfalusi }
644671e0b90SPeter Ujfalusi
ipc3_dtrace_free(struct snd_sof_dev * sdev)645671e0b90SPeter Ujfalusi static void ipc3_dtrace_free(struct snd_sof_dev *sdev)
646671e0b90SPeter Ujfalusi {
64706835329SPeter Ujfalusi struct sof_dtrace_priv *priv = sdev->fw_trace_data;
64806835329SPeter Ujfalusi
649671e0b90SPeter Ujfalusi /* release trace */
650671e0b90SPeter Ujfalusi ipc3_dtrace_release(sdev, false);
651671e0b90SPeter Ujfalusi
65206835329SPeter Ujfalusi if (priv->dma_trace_pages) {
65306835329SPeter Ujfalusi snd_dma_free_pages(&priv->dmatb);
65406835329SPeter Ujfalusi snd_dma_free_pages(&priv->dmatp);
65506835329SPeter Ujfalusi priv->dma_trace_pages = 0;
656671e0b90SPeter Ujfalusi }
657671e0b90SPeter Ujfalusi }
658671e0b90SPeter Ujfalusi
659671e0b90SPeter Ujfalusi const struct sof_ipc_fw_tracing_ops ipc3_dtrace_ops = {
660671e0b90SPeter Ujfalusi .init = ipc3_dtrace_init,
661671e0b90SPeter Ujfalusi .free = ipc3_dtrace_free,
662671e0b90SPeter Ujfalusi .fw_crashed = ipc3_dtrace_fw_crashed,
663671e0b90SPeter Ujfalusi .suspend = ipc3_dtrace_suspend,
664671e0b90SPeter Ujfalusi .resume = ipc3_dtrace_resume,
665671e0b90SPeter Ujfalusi };
666