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()
95 spin_unlock_irqrestore(&queue->lock, flags); in virtsnd_event_notify_cb()
99 * virtsnd_find_vqs() - Enumerate and initialize all virtqueues.
100 * @snd: VirtIO sound device.
105 * Return: 0 on success, -errno on failure.
109 struct virtio_device *vdev = snd->vdev; in virtsnd_find_vqs()
117 [VIRTIO_SND_VQ_CONTROL] = "virtsnd-ctl", in virtsnd_find_vqs()
118 [VIRTIO_SND_VQ_EVENT] = "virtsnd-event", in virtsnd_find_vqs()
119 [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()
236 if (snd->njacks) { in virtsnd_build_devs()
242 if (snd->nsubstreams) { in virtsnd_build_devs()
248 if (snd->nchmaps) { in virtsnd_build_devs()
254 return snd_card_register(snd->card); in virtsnd_build_devs()
258 * virtsnd_validate() - Validate if the device can be started.
259 * @vdev: VirtIO parent device.
262 * Return: 0 on success, -EINVAL on failure.
266 if (!vdev->config->get) { in virtsnd_validate()
267 dev_err(&vdev->dev, "configuration access disabled\n"); in virtsnd_validate()
268 return -EINVAL; in virtsnd_validate()
272 dev_err(&vdev->dev, in virtsnd_validate()
273 "device does not comply with spec version 1.x\n"); in virtsnd_validate()
274 return -EINVAL; in virtsnd_validate()
278 dev_err(&vdev->dev, "msg_timeout_ms value cannot be zero\n"); in virtsnd_validate()
279 return -EINVAL; in virtsnd_validate()
283 return -EINVAL; in virtsnd_validate()
289 * virtsnd_probe() - Create and initialize the device.
290 * @vdev: VirtIO parent device.
293 * Return: 0 on success, -errno on failure.
301 snd = devm_kzalloc(&vdev->dev, sizeof(*snd), GFP_KERNEL); in virtsnd_probe()
303 return -ENOMEM; in virtsnd_probe()
305 snd->vdev = vdev; in virtsnd_probe()
306 INIT_LIST_HEAD(&snd->ctl_msgs); in virtsnd_probe()
307 INIT_LIST_HEAD(&snd->pcm_list); in virtsnd_probe()
309 vdev->priv = snd; in virtsnd_probe()
312 spin_lock_init(&snd->queues[i].lock); in virtsnd_probe()
334 * virtsnd_remove() - Remove VirtIO and ALSA devices.
335 * @vdev: VirtIO parent device.
341 struct virtio_snd *snd = vdev->priv; in virtsnd_remove()
347 if (snd->card) in virtsnd_remove()
348 snd_card_free(snd->card); in virtsnd_remove()
350 vdev->config->del_vqs(vdev); in virtsnd_remove()
353 for (i = 0; snd->substreams && i < snd->nsubstreams; ++i) { in virtsnd_remove()
354 struct virtio_pcm_substream *vss = &snd->substreams[i]; in virtsnd_remove()
356 cancel_work_sync(&vss->elapsed_period); in virtsnd_remove()
360 kfree(snd->event_msgs); in virtsnd_remove()
365 * virtsnd_freeze() - Suspend device.
366 * @vdev: VirtIO parent device.
369 * Return: 0 on success, -errno on failure.
373 struct virtio_snd *snd = vdev->priv; in virtsnd_freeze()
379 vdev->config->del_vqs(vdev); in virtsnd_freeze()
382 for (i = 0; i < snd->nsubstreams; ++i) in virtsnd_freeze()
383 cancel_work_sync(&snd->substreams[i].elapsed_period); in virtsnd_freeze()
385 kfree(snd->event_msgs); in virtsnd_freeze()
386 snd->event_msgs = NULL; in virtsnd_freeze()
392 * virtsnd_restore() - Resume device.
393 * @vdev: VirtIO parent device.
396 * Return: 0 on success, -errno on failure.
400 struct virtio_snd *snd = vdev->priv; in virtsnd_restore()
435 MODULE_DEVICE_TABLE(virtio, id_table);
436 MODULE_DESCRIPTION("Virtio sound card driver");