virtio_ctl_msg.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_MSG_H
  7. #define VIRTIO_SND_MSG_H
  8. #include <linux/atomic.h>
  9. #include <linux/virtio.h>
  10. struct virtio_snd;
  11. struct virtio_snd_msg;
  12. void virtsnd_ctl_msg_ref(struct virtio_snd_msg *msg);
  13. void virtsnd_ctl_msg_unref(struct virtio_snd_msg *msg);
  14. void *virtsnd_ctl_msg_request(struct virtio_snd_msg *msg);
  15. void *virtsnd_ctl_msg_response(struct virtio_snd_msg *msg);
  16. struct virtio_snd_msg *virtsnd_ctl_msg_alloc(size_t request_size,
  17. size_t response_size, gfp_t gfp);
  18. int virtsnd_ctl_msg_send(struct virtio_snd *snd, struct virtio_snd_msg *msg,
  19. struct scatterlist *out_sgs,
  20. struct scatterlist *in_sgs, bool nowait);
  21. /**
  22. * virtsnd_ctl_msg_send_sync() - Simplified sending of synchronous message.
  23. * @snd: VirtIO sound device.
  24. * @msg: Control message.
  25. *
  26. * After returning from this function, the message will be deleted. If message
  27. * content is still needed, the caller must additionally to
  28. * virtsnd_ctl_msg_ref/unref() it.
  29. *
  30. * The msg_timeout_ms module parameter defines the message completion timeout.
  31. * If the message is not completed within this time, the function will return an
  32. * error.
  33. *
  34. * Context: Any context that permits to sleep.
  35. * Return: 0 on success, -errno on failure.
  36. *
  37. * The return value is a message status code (VIRTIO_SND_S_XXX) converted to an
  38. * appropriate -errno value.
  39. */
  40. static inline int virtsnd_ctl_msg_send_sync(struct virtio_snd *snd,
  41. struct virtio_snd_msg *msg)
  42. {
  43. return virtsnd_ctl_msg_send(snd, msg, NULL, NULL, false);
  44. }
  45. /**
  46. * virtsnd_ctl_msg_send_async() - Simplified sending of asynchronous message.
  47. * @snd: VirtIO sound device.
  48. * @msg: Control message.
  49. *
  50. * Context: Any context.
  51. * Return: 0 on success, -errno on failure.
  52. */
  53. static inline int virtsnd_ctl_msg_send_async(struct virtio_snd *snd,
  54. struct virtio_snd_msg *msg)
  55. {
  56. return virtsnd_ctl_msg_send(snd, msg, NULL, NULL, true);
  57. }
  58. void virtsnd_ctl_msg_cancel_all(struct virtio_snd *snd);
  59. void virtsnd_ctl_msg_complete(struct virtio_snd_msg *msg);
  60. int virtsnd_ctl_query_info(struct virtio_snd *snd, int command, int start_id,
  61. int count, size_t size, void *info);
  62. void virtsnd_ctl_notify_cb(struct virtqueue *vqueue);
  63. #endif /* VIRTIO_SND_MSG_H */