virtio_card.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_kctl - VirtIO control element.
  30. * @kctl: ALSA control element.
  31. * @items: Items for the ENUMERATED element type.
  32. */
  33. struct virtio_kctl {
  34. struct snd_kcontrol *kctl;
  35. struct virtio_snd_ctl_enum_item *items;
  36. };
  37. /**
  38. * struct virtio_snd - VirtIO sound card device.
  39. * @vdev: Underlying virtio device.
  40. * @queues: Virtqueue wrappers.
  41. * @card: ALSA sound card.
  42. * @ctl_msgs: Pending control request list.
  43. * @event_msgs: Device events.
  44. * @pcm_list: VirtIO PCM device list.
  45. * @jacks: VirtIO jacks.
  46. * @njacks: Number of jacks.
  47. * @substreams: VirtIO PCM substreams.
  48. * @nsubstreams: Number of PCM substreams.
  49. * @chmaps: VirtIO channel maps.
  50. * @nchmaps: Number of channel maps.
  51. * @kctl_infos: VirtIO control element information.
  52. * @kctls: VirtIO control elements.
  53. * @nkctls: Number of control elements.
  54. */
  55. struct virtio_snd {
  56. struct virtio_device *vdev;
  57. struct virtio_snd_queue queues[VIRTIO_SND_VQ_MAX];
  58. struct snd_card *card;
  59. struct list_head ctl_msgs;
  60. struct virtio_snd_event *event_msgs;
  61. struct list_head pcm_list;
  62. struct virtio_jack *jacks;
  63. u32 njacks;
  64. struct virtio_pcm_substream *substreams;
  65. u32 nsubstreams;
  66. struct virtio_snd_chmap_info *chmaps;
  67. u32 nchmaps;
  68. struct virtio_snd_ctl_info *kctl_infos;
  69. struct virtio_kctl *kctls;
  70. u32 nkctls;
  71. };
  72. /* Message completion timeout in milliseconds (module parameter). */
  73. extern u32 virtsnd_msg_timeout_ms;
  74. static inline struct virtio_snd_queue *
  75. virtsnd_control_queue(struct virtio_snd *snd)
  76. {
  77. return &snd->queues[VIRTIO_SND_VQ_CONTROL];
  78. }
  79. static inline struct virtio_snd_queue *
  80. virtsnd_event_queue(struct virtio_snd *snd)
  81. {
  82. return &snd->queues[VIRTIO_SND_VQ_EVENT];
  83. }
  84. static inline struct virtio_snd_queue *
  85. virtsnd_tx_queue(struct virtio_snd *snd)
  86. {
  87. return &snd->queues[VIRTIO_SND_VQ_TX];
  88. }
  89. static inline struct virtio_snd_queue *
  90. virtsnd_rx_queue(struct virtio_snd *snd)
  91. {
  92. return &snd->queues[VIRTIO_SND_VQ_RX];
  93. }
  94. static inline struct virtio_snd_queue *
  95. virtsnd_pcm_queue(struct virtio_pcm_substream *vss)
  96. {
  97. if (vss->direction == SNDRV_PCM_STREAM_PLAYBACK)
  98. return virtsnd_tx_queue(vss->snd);
  99. else
  100. return virtsnd_rx_queue(vss->snd);
  101. }
  102. int virtsnd_jack_parse_cfg(struct virtio_snd *snd);
  103. int virtsnd_jack_build_devs(struct virtio_snd *snd);
  104. void virtsnd_jack_event(struct virtio_snd *snd,
  105. struct virtio_snd_event *event);
  106. int virtsnd_chmap_parse_cfg(struct virtio_snd *snd);
  107. int virtsnd_chmap_build_devs(struct virtio_snd *snd);
  108. int virtsnd_kctl_parse_cfg(struct virtio_snd *snd);
  109. int virtsnd_kctl_build_devs(struct virtio_snd *snd);
  110. void virtsnd_kctl_event(struct virtio_snd *snd, struct virtio_snd_event *event);
  111. #endif /* VIRTIO_SND_CARD_H */