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) 2021 Advanced Micro Devices, Inc. All rights reserved. 7 // 8 // Authors: Vishnuvardhanrao Ravuapati <vishnuvardhanrao.ravulapati@amd.com> 9 // V Sujith Kumar Reddy <Vsujithkumar.Reddy@amd.com> 10 11 /*This file support Host TRACE Logger driver callback for SOF FW */ 12 13 #include "acp.h" 14 15 #define ACP_LOGGER_STREAM 8 16 #define NUM_PAGES 16 17 18 int acp_sof_trace_release(struct snd_sof_dev *sdev) 19 { 20 struct acp_dsp_stream *stream; 21 struct acp_dev_data *adata; 22 int ret; 23 24 adata = sdev->pdata->hw_pdata; 25 stream = adata->dtrace_stream; 26 ret = acp_dsp_stream_put(sdev, stream); 27 if (ret < 0) { 28 dev_err(sdev->dev, "Failed to release trace stream\n"); 29 return ret; 30 } 31 32 adata->dtrace_stream = NULL; 33 return 0; 34 } 35 EXPORT_SYMBOL_NS(acp_sof_trace_release, SND_SOC_SOF_AMD_COMMON); 36 37 static int acp_sof_trace_prepare(struct snd_sof_dev *sdev, 38 struct sof_ipc_dma_trace_params_ext *params) 39 { 40 struct acp_dsp_stream *stream; 41 struct acp_dev_data *adata; 42 int ret; 43 44 adata = sdev->pdata->hw_pdata; 45 stream = adata->dtrace_stream; 46 stream->dmab = &sdev->dmatb; 47 stream->num_pages = NUM_PAGES; 48 49 ret = acp_dsp_stream_config(sdev, stream); 50 if (ret < 0) { 51 dev_err(sdev->dev, "Failed to configure trace stream\n"); 52 return ret; 53 } 54 55 params->buffer.phy_addr = stream->reg_offset; 56 params->stream_tag = stream->stream_tag; 57 58 return 0; 59 } 60 61 int acp_sof_trace_init(struct snd_sof_dev *sdev, u32 *stream_tag) 62 { 63 struct sof_ipc_dma_trace_params_ext *params; 64 struct acp_dsp_stream *stream; 65 struct acp_dev_data *adata; 66 int ret; 67 68 adata = sdev->pdata->hw_pdata; 69 stream = acp_dsp_stream_get(sdev, ACP_LOGGER_STREAM); 70 if (!stream) 71 return -ENODEV; 72 73 adata->dtrace_stream = stream; 74 params = container_of(stream_tag, struct sof_ipc_dma_trace_params_ext, stream_tag); 75 ret = acp_sof_trace_prepare(sdev, params); 76 if (ret < 0) { 77 acp_dsp_stream_put(sdev, stream); 78 return ret; 79 } 80 81 *stream_tag = stream->stream_tag; 82 return 0; 83 } 84 EXPORT_SYMBOL_NS(acp_sof_trace_init, SND_SOC_SOF_AMD_COMMON); 85