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()
74 * virtsnd_event_notify_cb() - Dispatch all reported events from the event queue.
78 * device.
84 struct virtio_snd *snd = vqueue->vdev->priv; in virtsnd_event_notify_cb()
90 spin_lock_irqsave(&queue->lock, flags); in virtsnd_event_notify_cb()
98 spin_unlock_irqrestore(&queue->lock, flags); in virtsnd_event_notify_cb()
102 * virtsnd_find_vqs() - Enumerate and initialize all virtqueues.
103 * @snd: VirtIO sound device.
108 * Return: 0 on success, -errno on failure.
112 struct virtio_device *vdev = snd->vdev; in virtsnd_find_vqs()
114 [VIRTIO_SND_VQ_CONTROL] = { "virtsnd-ctl", in virtsnd_find_vqs()
116 [VIRTIO_SND_VQ_EVENT] = { "virtsnd-event", in virtsnd_find_vqs()
118 [VIRTIO_SND_VQ_TX] = { "virtsnd-tx", in virtsnd_find_vqs()
120 [VIRTIO_SND_VQ_RX] = { "virtsnd-rx", in virtsnd_find_vqs()
130 dev_err(&vdev->dev, "failed to initialize virtqueues\n"); in virtsnd_find_vqs()
135 snd->queues[i].vqueue = vqs[i]; in virtsnd_find_vqs()
142 snd->event_msgs = kmalloc_array(n, sizeof(*snd->event_msgs), in virtsnd_find_vqs()
144 if (!snd->event_msgs) in virtsnd_find_vqs()
145 return -ENOMEM; in virtsnd_find_vqs()
149 &snd->event_msgs[i], false, GFP_KERNEL); in virtsnd_find_vqs()
155 * virtsnd_enable_event_vq() - Enable the event virtqueue.
156 * @snd: VirtIO sound device.
164 if (!virtqueue_enable_cb(queue->vqueue)) in virtsnd_enable_event_vq()
165 virtsnd_event_notify_cb(queue->vqueue); in virtsnd_enable_event_vq()
169 * virtsnd_disable_event_vq() - Disable the event virtqueue.
170 * @snd: VirtIO sound device.
181 if (queue->vqueue) { in virtsnd_disable_event_vq()
182 spin_lock_irqsave(&queue->lock, flags); in virtsnd_disable_event_vq()
183 virtqueue_disable_cb(queue->vqueue); in virtsnd_disable_event_vq()
184 while ((event = virtqueue_get_buf(queue->vqueue, &length))) in virtsnd_disable_event_vq()
186 spin_unlock_irqrestore(&queue->lock, flags); in virtsnd_disable_event_vq()
191 * virtsnd_build_devs() - Read configuration and build ALSA devices.
192 * @snd: VirtIO sound device.
195 * Return: 0 on success, -errno on failure.
199 struct virtio_device *vdev = snd->vdev; in virtsnd_build_devs()
200 struct device *dev = &vdev->dev; in virtsnd_build_devs()
204 THIS_MODULE, 0, &snd->card); in virtsnd_build_devs()
208 snd->card->private_data = snd; in virtsnd_build_devs()
210 strscpy(snd->card->driver, VIRTIO_SND_CARD_DRIVER, in virtsnd_build_devs()
211 sizeof(snd->card->driver)); in virtsnd_build_devs()
212 strscpy(snd->card->shortname, VIRTIO_SND_CARD_NAME, in virtsnd_build_devs()
213 sizeof(snd->card->shortname)); in virtsnd_build_devs()
214 if (dev->parent->bus) in virtsnd_build_devs()
215 snprintf(snd->card->longname, sizeof(snd->card->longname), in virtsnd_build_devs()
217 dev->parent->bus->name, dev_name(dev->parent), in virtsnd_build_devs()
220 snprintf(snd->card->longname, sizeof(snd->card->longname), in virtsnd_build_devs()
222 dev_name(dev->parent), dev_name(dev)); in virtsnd_build_devs()
242 if (snd->njacks) { in virtsnd_build_devs()
248 if (snd->nsubstreams) { in virtsnd_build_devs()
254 if (snd->nchmaps) { in virtsnd_build_devs()
260 if (snd->nkctls) { in virtsnd_build_devs()
266 return snd_card_register(snd->card); in virtsnd_build_devs()
270 * virtsnd_validate() - Validate if the device can be started.
271 * @vdev: VirtIO parent device.
274 * Return: 0 on success, -EINVAL on failure.
278 if (!vdev->config->get) { in virtsnd_validate()
279 dev_err(&vdev->dev, "configuration access disabled\n"); in virtsnd_validate()
280 return -EINVAL; in virtsnd_validate()
284 dev_err(&vdev->dev, in virtsnd_validate()
285 "device does not comply with spec version 1.x\n"); in virtsnd_validate()
286 return -EINVAL; in virtsnd_validate()
290 dev_err(&vdev->dev, "msg_timeout_ms value cannot be zero\n"); in virtsnd_validate()
291 return -EINVAL; in virtsnd_validate()
295 return -EINVAL; in virtsnd_validate()
301 * virtsnd_probe() - Create and initialize the device.
302 * @vdev: VirtIO parent device.
305 * Return: 0 on success, -errno on failure.
313 snd = devm_kzalloc(&vdev->dev, sizeof(*snd), GFP_KERNEL); in virtsnd_probe()
315 return -ENOMEM; in virtsnd_probe()
317 snd->vdev = vdev; in virtsnd_probe()
318 INIT_LIST_HEAD(&snd->ctl_msgs); in virtsnd_probe()
319 INIT_LIST_HEAD(&snd->pcm_list); in virtsnd_probe()
321 vdev->priv = snd; in virtsnd_probe()
324 spin_lock_init(&snd->queues[i].lock); in virtsnd_probe()
346 * virtsnd_remove() - Remove VirtIO and ALSA devices.
347 * @vdev: VirtIO parent device.
353 struct virtio_snd *snd = vdev->priv; in virtsnd_remove()
359 if (snd->card) in virtsnd_remove()
360 snd_card_free(snd->card); in virtsnd_remove()
362 vdev->config->del_vqs(vdev); in virtsnd_remove()
365 for (i = 0; snd->substreams && i < snd->nsubstreams; ++i) { in virtsnd_remove()
366 struct virtio_pcm_substream *vss = &snd->substreams[i]; in virtsnd_remove()
368 cancel_work_sync(&vss->elapsed_period); in virtsnd_remove()
372 kfree(snd->event_msgs); in virtsnd_remove()
377 * virtsnd_freeze() - Suspend device.
378 * @vdev: VirtIO parent device.
381 * Return: 0 on success, -errno on failure.
385 struct virtio_snd *snd = vdev->priv; in virtsnd_freeze()
391 vdev->config->del_vqs(vdev); in virtsnd_freeze()
394 for (i = 0; i < snd->nsubstreams; ++i) in virtsnd_freeze()
395 cancel_work_sync(&snd->substreams[i].elapsed_period); in virtsnd_freeze()
397 kfree(snd->event_msgs); in virtsnd_freeze()
398 snd->event_msgs = NULL; in virtsnd_freeze()
404 * virtsnd_restore() - Resume device.
405 * @vdev: VirtIO parent device.
408 * Return: 0 on success, -errno on failure.
412 struct virtio_snd *snd = vdev->priv; in virtsnd_restore()
452 MODULE_DEVICE_TABLE(virtio, id_table);
453 MODULE_DESCRIPTION("Virtio sound card driver");