virtio_card.c (9d45e514da88ff74fc24ffb34e7d6eb92576440b) virtio_card.c (29b96bf50ba958eb5f097cdc3fbd4c1acf9547a2)
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * virtio-snd: Virtio sound device
4 * Copyright (C) 2021 OpenSynergy GmbH
5 */
6#include <linux/module.h>
7#include <linux/moduleparam.h>
8#include <linux/virtio_config.h>

--- 195 unchanged lines hidden (view full) ---

204 VIRTIO_SND_CARD_NAME " at %s/%s/%s",
205 dev->parent->bus->name, dev_name(dev->parent),
206 dev_name(dev));
207 else
208 snprintf(snd->card->longname, sizeof(snd->card->longname),
209 VIRTIO_SND_CARD_NAME " at %s/%s",
210 dev_name(dev->parent), dev_name(dev));
211
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * virtio-snd: Virtio sound device
4 * Copyright (C) 2021 OpenSynergy GmbH
5 */
6#include <linux/module.h>
7#include <linux/moduleparam.h>
8#include <linux/virtio_config.h>

--- 195 unchanged lines hidden (view full) ---

204 VIRTIO_SND_CARD_NAME " at %s/%s/%s",
205 dev->parent->bus->name, dev_name(dev->parent),
206 dev_name(dev));
207 else
208 snprintf(snd->card->longname, sizeof(snd->card->longname),
209 VIRTIO_SND_CARD_NAME " at %s/%s",
210 dev_name(dev->parent), dev_name(dev));
211
212 rc = virtsnd_pcm_parse_cfg(snd);
213 if (rc)
214 return rc;
215
216 if (snd->nsubstreams) {
217 rc = virtsnd_pcm_build_devs(snd);
218 if (rc)
219 return rc;
220 }
221
212 return snd_card_register(snd->card);
213}
214
215/**
216 * virtsnd_validate() - Validate if the device can be started.
217 * @vdev: VirtIO parent device.
218 *
219 * Context: Any context.

--- 12 unchanged lines hidden (view full) ---

232 return -EINVAL;
233 }
234
235 if (!virtsnd_msg_timeout_ms) {
236 dev_err(&vdev->dev, "msg_timeout_ms value cannot be zero\n");
237 return -EINVAL;
238 }
239
222 return snd_card_register(snd->card);
223}
224
225/**
226 * virtsnd_validate() - Validate if the device can be started.
227 * @vdev: VirtIO parent device.
228 *
229 * Context: Any context.

--- 12 unchanged lines hidden (view full) ---

242 return -EINVAL;
243 }
244
245 if (!virtsnd_msg_timeout_ms) {
246 dev_err(&vdev->dev, "msg_timeout_ms value cannot be zero\n");
247 return -EINVAL;
248 }
249
250 if (virtsnd_pcm_validate(vdev))
251 return -EINVAL;
252
240 return 0;
241}
242
243/**
244 * virtsnd_probe() - Create and initialize the device.
245 * @vdev: VirtIO parent device.
246 *
247 * Context: Any context that permits to sleep.

--- 6 unchanged lines hidden (view full) ---

254 int rc;
255
256 snd = devm_kzalloc(&vdev->dev, sizeof(*snd), GFP_KERNEL);
257 if (!snd)
258 return -ENOMEM;
259
260 snd->vdev = vdev;
261 INIT_LIST_HEAD(&snd->ctl_msgs);
253 return 0;
254}
255
256/**
257 * virtsnd_probe() - Create and initialize the device.
258 * @vdev: VirtIO parent device.
259 *
260 * Context: Any context that permits to sleep.

--- 6 unchanged lines hidden (view full) ---

267 int rc;
268
269 snd = devm_kzalloc(&vdev->dev, sizeof(*snd), GFP_KERNEL);
270 if (!snd)
271 return -ENOMEM;
272
273 snd->vdev = vdev;
274 INIT_LIST_HEAD(&snd->ctl_msgs);
275 INIT_LIST_HEAD(&snd->pcm_list);
262
263 vdev->priv = snd;
264
265 for (i = 0; i < VIRTIO_SND_VQ_MAX; ++i)
266 spin_lock_init(&snd->queues[i].lock);
267
268 rc = virtsnd_find_vqs(snd);
269 if (rc)

--- 18 unchanged lines hidden (view full) ---

288 * virtsnd_remove() - Remove VirtIO and ALSA devices.
289 * @vdev: VirtIO parent device.
290 *
291 * Context: Any context that permits to sleep.
292 */
293static void virtsnd_remove(struct virtio_device *vdev)
294{
295 struct virtio_snd *snd = vdev->priv;
276
277 vdev->priv = snd;
278
279 for (i = 0; i < VIRTIO_SND_VQ_MAX; ++i)
280 spin_lock_init(&snd->queues[i].lock);
281
282 rc = virtsnd_find_vqs(snd);
283 if (rc)

--- 18 unchanged lines hidden (view full) ---

302 * virtsnd_remove() - Remove VirtIO and ALSA devices.
303 * @vdev: VirtIO parent device.
304 *
305 * Context: Any context that permits to sleep.
306 */
307static void virtsnd_remove(struct virtio_device *vdev)
308{
309 struct virtio_snd *snd = vdev->priv;
310 unsigned int i;
296
297 virtsnd_disable_event_vq(snd);
298 virtsnd_ctl_msg_cancel_all(snd);
299
300 if (snd->card)
301 snd_card_free(snd->card);
302
303 vdev->config->del_vqs(vdev);
304 vdev->config->reset(vdev);
305
311
312 virtsnd_disable_event_vq(snd);
313 virtsnd_ctl_msg_cancel_all(snd);
314
315 if (snd->card)
316 snd_card_free(snd->card);
317
318 vdev->config->del_vqs(vdev);
319 vdev->config->reset(vdev);
320
321 for (i = 0; snd->substreams && i < snd->nsubstreams; ++i)
322 cancel_work_sync(&snd->substreams[i].elapsed_period);
323
306 kfree(snd->event_msgs);
307}
308
309static const struct virtio_device_id id_table[] = {
310 { VIRTIO_ID_SOUND, VIRTIO_DEV_ANY_ID },
311 { 0 },
312};
313

--- 24 unchanged lines hidden ---
324 kfree(snd->event_msgs);
325}
326
327static const struct virtio_device_id id_table[] = {
328 { VIRTIO_ID_SOUND, VIRTIO_DEV_ANY_ID },
329 { 0 },
330};
331

--- 24 unchanged lines hidden ---