Lines Matching +full:virtio +full:- +full:device

1 // SPDX-License-Identifier: GPL-2.0+
3 * virtio-snd: Virtio sound device
21 * virtsnd_event_send() - Add an event to the event queue.
24 * @notify: Indicates whether or not to send a notification to the device.
49 * virtsnd_event_dispatch() - Dispatch an event from the device side.
50 * @snd: VirtIO sound device.
51 * @event: VirtIO sound event.
58 switch (le32_to_cpu(event->hdr.code)) { in virtsnd_event_dispatch()
71 * virtsnd_event_notify_cb() - Dispatch all reported events from the event queue.
75 * device.
81 struct virtio_snd *snd = vqueue->vdev->priv; in virtsnd_event_notify_cb()
87 spin_lock_irqsave(&queue->lock, flags); in virtsnd_event_notify_cb()
97 spin_unlock_irqrestore(&queue->lock, flags); in virtsnd_event_notify_cb()
101 * virtsnd_find_vqs() - Enumerate and initialize all virtqueues.
102 * @snd: VirtIO sound device.
107 * Return: 0 on success, -errno on failure.
111 struct virtio_device *vdev = snd->vdev; in virtsnd_find_vqs()
119 [VIRTIO_SND_VQ_CONTROL] = "virtsnd-ctl", in virtsnd_find_vqs()
120 [VIRTIO_SND_VQ_EVENT] = "virtsnd-event", in virtsnd_find_vqs()
121 [VIRTIO_SND_VQ_TX] = "virtsnd-tx", in virtsnd_find_vqs()
122 [VIRTIO_SND_VQ_RX] = "virtsnd-rx" in virtsnd_find_vqs()
132 dev_err(&vdev->dev, "failed to initialize virtqueues\n"); in virtsnd_find_vqs()
137 snd->queues[i].vqueue = vqs[i]; in virtsnd_find_vqs()
144 snd->event_msgs = kmalloc_array(n, sizeof(*snd->event_msgs), in virtsnd_find_vqs()
146 if (!snd->event_msgs) in virtsnd_find_vqs()
147 return -ENOMEM; in virtsnd_find_vqs()
151 &snd->event_msgs[i], false, GFP_KERNEL); in virtsnd_find_vqs()
157 * virtsnd_enable_event_vq() - Enable the event virtqueue.
158 * @snd: VirtIO sound device.
166 if (!virtqueue_enable_cb(queue->vqueue)) in virtsnd_enable_event_vq()
167 virtsnd_event_notify_cb(queue->vqueue); in virtsnd_enable_event_vq()
171 * virtsnd_disable_event_vq() - Disable the event virtqueue.
172 * @snd: VirtIO sound device.
183 if (queue->vqueue) { in virtsnd_disable_event_vq()
184 spin_lock_irqsave(&queue->lock, flags); in virtsnd_disable_event_vq()
185 virtqueue_disable_cb(queue->vqueue); in virtsnd_disable_event_vq()
186 while ((event = virtqueue_get_buf(queue->vqueue, &length))) in virtsnd_disable_event_vq()
188 spin_unlock_irqrestore(&queue->lock, flags); in virtsnd_disable_event_vq()
193 * virtsnd_build_devs() - Read configuration and build ALSA devices.
194 * @snd: VirtIO sound device.
197 * Return: 0 on success, -errno on failure.
201 struct virtio_device *vdev = snd->vdev; in virtsnd_build_devs()
202 struct device *dev = &vdev->dev; in virtsnd_build_devs()
206 THIS_MODULE, 0, &snd->card); in virtsnd_build_devs()
210 snd->card->private_data = snd; in virtsnd_build_devs()
212 strscpy(snd->card->driver, VIRTIO_SND_CARD_DRIVER, in virtsnd_build_devs()
213 sizeof(snd->card->driver)); in virtsnd_build_devs()
214 strscpy(snd->card->shortname, VIRTIO_SND_CARD_NAME, in virtsnd_build_devs()
215 sizeof(snd->card->shortname)); in virtsnd_build_devs()
216 if (dev->parent->bus) in virtsnd_build_devs()
217 snprintf(snd->card->longname, sizeof(snd->card->longname), in virtsnd_build_devs()
219 dev->parent->bus->name, dev_name(dev->parent), in virtsnd_build_devs()
222 snprintf(snd->card->longname, sizeof(snd->card->longname), in virtsnd_build_devs()
224 dev_name(dev->parent), dev_name(dev)); in virtsnd_build_devs()
238 if (snd->njacks) { in virtsnd_build_devs()
244 if (snd->nsubstreams) { in virtsnd_build_devs()
250 if (snd->nchmaps) { in virtsnd_build_devs()
256 return snd_card_register(snd->card); in virtsnd_build_devs()
260 * virtsnd_validate() - Validate if the device can be started.
261 * @vdev: VirtIO parent device.
264 * Return: 0 on success, -EINVAL on failure.
268 if (!vdev->config->get) { in virtsnd_validate()
269 dev_err(&vdev->dev, "configuration access disabled\n"); in virtsnd_validate()
270 return -EINVAL; in virtsnd_validate()
274 dev_err(&vdev->dev, in virtsnd_validate()
275 "device does not comply with spec version 1.x\n"); in virtsnd_validate()
276 return -EINVAL; in virtsnd_validate()
280 dev_err(&vdev->dev, "msg_timeout_ms value cannot be zero\n"); in virtsnd_validate()
281 return -EINVAL; in virtsnd_validate()
285 return -EINVAL; in virtsnd_validate()
291 * virtsnd_probe() - Create and initialize the device.
292 * @vdev: VirtIO parent device.
295 * Return: 0 on success, -errno on failure.
303 snd = devm_kzalloc(&vdev->dev, sizeof(*snd), GFP_KERNEL); in virtsnd_probe()
305 return -ENOMEM; in virtsnd_probe()
307 snd->vdev = vdev; in virtsnd_probe()
308 INIT_LIST_HEAD(&snd->ctl_msgs); in virtsnd_probe()
309 INIT_LIST_HEAD(&snd->pcm_list); in virtsnd_probe()
311 vdev->priv = snd; in virtsnd_probe()
314 spin_lock_init(&snd->queues[i].lock); in virtsnd_probe()
336 * virtsnd_remove() - Remove VirtIO and ALSA devices.
337 * @vdev: VirtIO parent device.
343 struct virtio_snd *snd = vdev->priv; in virtsnd_remove()
349 if (snd->card) in virtsnd_remove()
350 snd_card_free(snd->card); in virtsnd_remove()
352 vdev->config->del_vqs(vdev); in virtsnd_remove()
355 for (i = 0; snd->substreams && i < snd->nsubstreams; ++i) { in virtsnd_remove()
356 struct virtio_pcm_substream *vss = &snd->substreams[i]; in virtsnd_remove()
358 cancel_work_sync(&vss->elapsed_period); in virtsnd_remove()
362 kfree(snd->event_msgs); in virtsnd_remove()
367 * virtsnd_freeze() - Suspend device.
368 * @vdev: VirtIO parent device.
371 * Return: 0 on success, -errno on failure.
375 struct virtio_snd *snd = vdev->priv; in virtsnd_freeze()
381 vdev->config->del_vqs(vdev); in virtsnd_freeze()
384 for (i = 0; i < snd->nsubstreams; ++i) in virtsnd_freeze()
385 cancel_work_sync(&snd->substreams[i].elapsed_period); in virtsnd_freeze()
387 kfree(snd->event_msgs); in virtsnd_freeze()
388 snd->event_msgs = NULL; in virtsnd_freeze()
394 * virtsnd_restore() - Resume device.
395 * @vdev: VirtIO parent device.
398 * Return: 0 on success, -errno on failure.
402 struct virtio_snd *snd = vdev->priv; in virtsnd_restore()
437 MODULE_DEVICE_TABLE(virtio, id_table);
438 MODULE_DESCRIPTION("Virtio sound card driver");