~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/sof/sof-client-probes-ipc3.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 //
  3 // Copyright(c) 2019-2022 Intel Corporation
  4 //
  5 // Author: Cezary Rojewski <cezary.rojewski@intel.com>
  6 //
  7 // Code moved to this file by:
  8 //  Jyri Sarha <jyri.sarha@intel.com>
  9 //
 10 
 11 #include <linux/stddef.h>
 12 #include <sound/soc.h>
 13 #include <sound/sof/header.h>
 14 #include "sof-client.h"
 15 #include "sof-client-probes.h"
 16 
 17 struct sof_probe_dma {
 18         unsigned int stream_tag;
 19         unsigned int dma_buffer_size;
 20 } __packed;
 21 
 22 struct sof_ipc_probe_dma_add_params {
 23         struct sof_ipc_cmd_hdr hdr;
 24         unsigned int num_elems;
 25         struct sof_probe_dma dma[];
 26 } __packed;
 27 
 28 struct sof_ipc_probe_info_params {
 29         struct sof_ipc_reply rhdr;
 30         unsigned int num_elems;
 31         union {
 32                 DECLARE_FLEX_ARRAY(struct sof_probe_dma, dma);
 33                 DECLARE_FLEX_ARRAY(struct sof_probe_point_desc, desc);
 34         };
 35 } __packed;
 36 
 37 struct sof_ipc_probe_point_add_params {
 38         struct sof_ipc_cmd_hdr hdr;
 39         unsigned int num_elems;
 40         struct sof_probe_point_desc desc[];
 41 } __packed;
 42 
 43 struct sof_ipc_probe_point_remove_params {
 44         struct sof_ipc_cmd_hdr hdr;
 45         unsigned int num_elems;
 46         unsigned int buffer_id[];
 47 } __packed;
 48 
 49 /**
 50  * ipc3_probes_init - initialize data probing
 51  * @cdev:               SOF client device
 52  * @stream_tag:         Extractor stream tag
 53  * @buffer_size:        DMA buffer size to set for extractor
 54  *
 55  * Host chooses whether extraction is supported or not by providing
 56  * valid stream tag to DSP. Once specified, stream described by that
 57  * tag will be tied to DSP for extraction for the entire lifetime of
 58  * probe.
 59  *
 60  * Probing is initialized only once and each INIT request must be
 61  * matched by DEINIT call.
 62  */
 63 static int ipc3_probes_init(struct sof_client_dev *cdev, u32 stream_tag,
 64                             size_t buffer_size)
 65 {
 66         struct sof_ipc_probe_dma_add_params *msg;
 67         size_t size = struct_size(msg, dma, 1);
 68         int ret;
 69 
 70         msg = kmalloc(size, GFP_KERNEL);
 71         if (!msg)
 72                 return -ENOMEM;
 73         msg->hdr.size = size;
 74         msg->hdr.cmd = SOF_IPC_GLB_PROBE | SOF_IPC_PROBE_INIT;
 75         msg->num_elems = 1;
 76         msg->dma[0].stream_tag = stream_tag;
 77         msg->dma[0].dma_buffer_size = buffer_size;
 78 
 79         ret = sof_client_ipc_tx_message_no_reply(cdev, msg);
 80         kfree(msg);
 81         return ret;
 82 }
 83 
 84 /**
 85  * ipc3_probes_deinit - cleanup after data probing
 86  * @cdev:               SOF client device
 87  *
 88  * Host sends DEINIT request to free previously initialized probe
 89  * on DSP side once it is no longer needed. DEINIT only when there
 90  * are no probes connected and with all injectors detached.
 91  */
 92 static int ipc3_probes_deinit(struct sof_client_dev *cdev)
 93 {
 94         struct sof_ipc_cmd_hdr msg;
 95 
 96         msg.size = sizeof(msg);
 97         msg.cmd = SOF_IPC_GLB_PROBE | SOF_IPC_PROBE_DEINIT;
 98 
 99         return sof_client_ipc_tx_message_no_reply(cdev, &msg);
100 }
101 
102 static int ipc3_probes_info(struct sof_client_dev *cdev, unsigned int cmd,
103                             void **params, size_t *num_params)
104 {
105         size_t max_msg_size = sof_client_get_ipc_max_payload_size(cdev);
106         struct sof_ipc_probe_info_params msg = {{{0}}};
107         struct sof_ipc_probe_info_params *reply;
108         size_t bytes;
109         int ret;
110 
111         *params = NULL;
112         *num_params = 0;
113 
114         reply = kzalloc(max_msg_size, GFP_KERNEL);
115         if (!reply)
116                 return -ENOMEM;
117         msg.rhdr.hdr.size = sizeof(msg);
118         msg.rhdr.hdr.cmd = SOF_IPC_GLB_PROBE | cmd;
119 
120         ret = sof_client_ipc_tx_message(cdev, &msg, reply, max_msg_size);
121         if (ret < 0 || reply->rhdr.error < 0)
122                 goto exit;
123 
124         if (!reply->num_elems)
125                 goto exit;
126 
127         if (cmd == SOF_IPC_PROBE_DMA_INFO)
128                 bytes = sizeof(reply->dma[0]);
129         else
130                 bytes = sizeof(reply->desc[0]);
131         bytes *= reply->num_elems;
132         *params = kmemdup(&reply->dma[0], bytes, GFP_KERNEL);
133         if (!*params) {
134                 ret = -ENOMEM;
135                 goto exit;
136         }
137         *num_params = reply->num_elems;
138 
139 exit:
140         kfree(reply);
141         return ret;
142 }
143 
144 /**
145  * ipc3_probes_points_info - retrieve list of active probe points
146  * @cdev:               SOF client device
147  * @desc:       Returned list of active probes
148  * @num_desc:   Returned count of active probes
149  *
150  * Host sends PROBE_POINT_INFO request to obtain list of active probe
151  * points, valid for disconnection when given probe is no longer
152  * required.
153  */
154 static int ipc3_probes_points_info(struct sof_client_dev *cdev,
155                                    struct sof_probe_point_desc **desc,
156                                    size_t *num_desc)
157 {
158         return ipc3_probes_info(cdev, SOF_IPC_PROBE_POINT_INFO,
159                                (void **)desc, num_desc);
160 }
161 
162 /**
163  * ipc3_probes_points_add - connect specified probes
164  * @cdev:               SOF client device
165  * @desc:       List of probe points to connect
166  * @num_desc:   Number of elements in @desc
167  *
168  * Dynamically connects to provided set of endpoints. Immediately
169  * after connection is established, host must be prepared to
170  * transfer data from or to target stream given the probing purpose.
171  *
172  * Each probe point should be removed using PROBE_POINT_REMOVE
173  * request when no longer needed.
174  */
175 static int ipc3_probes_points_add(struct sof_client_dev *cdev,
176                                   struct sof_probe_point_desc *desc,
177                                   size_t num_desc)
178 {
179         struct sof_ipc_probe_point_add_params *msg;
180         size_t size = struct_size(msg, desc, num_desc);
181         int ret;
182 
183         msg = kmalloc(size, GFP_KERNEL);
184         if (!msg)
185                 return -ENOMEM;
186         msg->hdr.size = size;
187         msg->num_elems = num_desc;
188         msg->hdr.cmd = SOF_IPC_GLB_PROBE | SOF_IPC_PROBE_POINT_ADD;
189         memcpy(&msg->desc[0], desc, size - sizeof(*msg));
190 
191         ret = sof_client_ipc_tx_message_no_reply(cdev, msg);
192         kfree(msg);
193         return ret;
194 }
195 
196 /**
197  * ipc3_probes_points_remove - disconnect specified probes
198  * @cdev:               SOF client device
199  * @buffer_id:          List of probe points to disconnect
200  * @num_buffer_id:      Number of elements in @desc
201  *
202  * Removes previously connected probes from list of active probe
203  * points and frees all resources on DSP side.
204  */
205 static int ipc3_probes_points_remove(struct sof_client_dev *cdev,
206                                      unsigned int *buffer_id,
207                                      size_t num_buffer_id)
208 {
209         struct sof_ipc_probe_point_remove_params *msg;
210         size_t size = struct_size(msg, buffer_id, num_buffer_id);
211         int ret;
212 
213         msg = kmalloc(size, GFP_KERNEL);
214         if (!msg)
215                 return -ENOMEM;
216         msg->hdr.size = size;
217         msg->num_elems = num_buffer_id;
218         msg->hdr.cmd = SOF_IPC_GLB_PROBE | SOF_IPC_PROBE_POINT_REMOVE;
219         memcpy(&msg->buffer_id[0], buffer_id, size - sizeof(*msg));
220 
221         ret = sof_client_ipc_tx_message_no_reply(cdev, msg);
222         kfree(msg);
223         return ret;
224 }
225 
226 const struct sof_probes_ipc_ops ipc3_probe_ops =  {
227         .init = ipc3_probes_init,
228         .deinit = ipc3_probes_deinit,
229         .points_info = ipc3_probes_points_info,
230         .points_add = ipc3_probes_points_add,
231         .points_remove = ipc3_probes_points_remove,
232 };
233 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php