virtio_card.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * virtio-snd: Virtio sound device
  4. * Copyright (C) 2021 OpenSynergy GmbH
  5. */
  6. #ifndef VIRTIO_SND_CARD_H
  7. #define VIRTIO_SND_CARD_H
  8. #include <linux/slab.h>
  9. #include <linux/virtio.h>
  10. #include <sound/core.h>
  11. #include <uapi/linux/virtio_snd.h>
  12. #include "virtio_ctl_msg.h"
  13. #include "virtio_pcm.h"
  14. #define VIRTIO_SND_CARD_DRIVER "virtio-snd"
  15. #define VIRTIO_SND_CARD_NAME "VirtIO SoundCard"
  16. #define VIRTIO_SND_PCM_NAME "VirtIO PCM"
  17. struct virtio_jack;
  18. struct virtio_pcm_substream;
  19. /**
  20. * struct virtio_snd_queue - Virtqueue wrapper structure.
  21. * @lock: Used to synchronize access to a virtqueue.
  22. * @vqueue: Underlying virtqueue.
  23. */
  24. struct virtio_snd_queue {
  25. spinlock_t lock;
  26. struct virtqueue *vqueue;
  27. };
  28. /**
  29. * struct virtio_snd - VirtIO sound card device.
  30. * @vdev: Underlying virtio device.
  31. * @queues: Virtqueue wrappers.
  32. * @card: ALSA sound card.
  33. * @ctl_msgs: Pending control request list.
  34. * @event_msgs: Device events.
  35. * @pcm_list: VirtIO PCM device list.
  36. * @jacks: VirtIO jacks.
  37. * @njacks: Number of jacks.
  38. * @substreams: VirtIO PCM substreams.
  39. * @nsubstreams: Number of PCM substreams.
  40. * @chmaps: VirtIO channel maps.
  41. * @nchmaps: Number of channel maps.
  42. */
  43. struct virtio_snd {
  44. struct virtio_device *vdev;
  45. struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX];
  46. struct snd_card *card;
  47. struct list_head ctl_msgs;
  48. struct virtio_snd_event *event_msgs;
  49. struct list_head pcm_list;
  50. struct virtio_jack *jacks;
  51. u32 njacks;
  52. struct virtio_pcm_substream *substreams;
  53. u32 nsubstreams;
  54. struct virtio_snd_chmap_info *chmaps;
  55. u32 nchmaps;
  56. };
  57. /* Message completion timeout in milliseconds (module parameter). */
  58. extern u32 virtsnd_msg_timeout_ms;
  59. static inline struct virtio_snd_queue *
  60. virtsnd_control_queue(struct virtio_snd *snd)
  61. {
  62. return &snd->queues[VIRTIO_SND_VQ_CONTROL];
  63. }
  64. static inline struct virtio_snd_queue *
  65. virtsnd_event_queue(struct virtio_snd *snd)
  66. {
  67. return &snd->queues[VIRTIO_SND_VQ_EVENT];
  68. }
  69. static inline struct virtio_snd_queue *
  70. virtsnd_tx_queue(struct virtio_snd *snd)
  71. {
  72. return &snd->queues[VIRTIO_SND_VQ_TX];
  73. }
  74. static inline struct virtio_snd_queue *
  75. virtsnd_rx_queue(struct virtio_snd *snd)
  76. {
  77. return &snd->queues[VIRTIO_SND_VQ_RX];
  78. }
  79. static inline struct virtio_snd_queue *
  80. virtsnd_pcm_queue(struct virtio_pcm_substream *vss)
  81. {
  82. if (vss->direction == SNDRV_PCM_STREAM_PLAYBACK)
  83. return virtsnd_tx_queue(vss->snd);
  84. else
  85. return virtsnd_rx_queue(vss->snd);
  86. }
  87. int virtsnd_jack_parse_cfg(struct virtio_snd *snd);
  88. int virtsnd_jack_build_devs(struct virtio_snd *snd);
  89. void virtsnd_jack_event(struct virtio_snd *snd,
  90. struct virtio_snd_event *event);
  91. int virtsnd_chmap_parse_cfg(struct virtio_snd *snd);
  92. int virtsnd_chmap_build_devs(struct virtio_snd *snd);
  93. #endif /* VIRTIO_SND_CARD_H */