compress_driver.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * compress_driver.h - compress offload driver definations
  4. *
  5. * Copyright (C) 2011 Intel Corporation
  6. * Authors: Vinod Koul <vinod.koul@linux.intel.com>
  7. * Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
  8. */
  9. #ifndef __COMPRESS_DRIVER_H
  10. #define __COMPRESS_DRIVER_H
  11. #include <linux/types.h>
  12. #include <linux/sched.h>
  13. #include <sound/core.h>
  14. #include <sound/compress_offload.h>
  15. #include <sound/asound.h>
  16. #include <sound/pcm.h>
  17. struct snd_compr_ops;
  18. /**
  19. * struct snd_compr_runtime: runtime stream description
  20. * @state: stream state
  21. * @ops: pointer to DSP callbacks
  22. * @buffer: pointer to kernel buffer, valid only when not in mmap mode or
  23. * DSP doesn't implement copy
  24. * @buffer_size: size of the above buffer
  25. * @fragment_size: size of buffer fragment in bytes
  26. * @fragments: number of such fragments
  27. * @total_bytes_available: cumulative number of bytes made available in
  28. * the ring buffer
  29. * @total_bytes_transferred: cumulative bytes transferred by offload DSP
  30. * @sleep: poll sleep
  31. * @private_data: driver private data pointer
  32. */
  33. struct snd_compr_runtime {
  34. snd_pcm_state_t state;
  35. struct snd_compr_ops *ops;
  36. void *buffer;
  37. u64 buffer_size;
  38. u32 fragment_size;
  39. u32 fragments;
  40. u64 total_bytes_available;
  41. u64 total_bytes_transferred;
  42. wait_queue_head_t sleep;
  43. void *private_data;
  44. };
  45. /**
  46. * struct snd_compr_stream: compressed stream
  47. * @name: device name
  48. * @ops: pointer to DSP callbacks
  49. * @runtime: pointer to runtime structure
  50. * @device: device pointer
  51. * @error_work: delayed work used when closing the stream due to an error
  52. * @direction: stream direction, playback/recording
  53. * @metadata_set: metadata set flag, true when set
  54. * @next_track: has userspace signal next track transition, true when set
  55. * @private_data: pointer to DSP private data
  56. */
  57. struct snd_compr_stream {
  58. const char *name;
  59. struct snd_compr_ops *ops;
  60. struct snd_compr_runtime *runtime;
  61. struct snd_compr *device;
  62. struct delayed_work error_work;
  63. enum snd_compr_direction direction;
  64. bool metadata_set;
  65. bool next_track;
  66. void *private_data;
  67. };
  68. /**
  69. * struct snd_compr_ops: compressed path DSP operations
  70. * @open: Open the compressed stream
  71. * This callback is mandatory and shall keep dsp ready to receive the stream
  72. * parameter
  73. * @free: Close the compressed stream, mandatory
  74. * @set_params: Sets the compressed stream parameters, mandatory
  75. * This can be called in during stream creation only to set codec params
  76. * and the stream properties
  77. * @get_params: retrieve the codec parameters, mandatory
  78. * @set_metadata: Set the metadata values for a stream
  79. * @get_metadata: retrieves the requested metadata values from stream
  80. * @trigger: Trigger operations like start, pause, resume, drain, stop.
  81. * This callback is mandatory
  82. * @pointer: Retrieve current h/w pointer information. Mandatory
  83. * @copy: Copy the compressed data to/from userspace, Optional
  84. * Can't be implemented if DSP supports mmap
  85. * @mmap: DSP mmap method to mmap DSP memory
  86. * @ack: Ack for DSP when data is written to audio buffer, Optional
  87. * Not valid if copy is implemented
  88. * @get_caps: Retrieve DSP capabilities, mandatory
  89. * @get_codec_caps: Retrieve capabilities for a specific codec, mandatory
  90. */
  91. struct snd_compr_ops {
  92. int (*open)(struct snd_compr_stream *stream);
  93. int (*free)(struct snd_compr_stream *stream);
  94. int (*set_params)(struct snd_compr_stream *stream,
  95. struct snd_compr_params *params);
  96. int (*get_params)(struct snd_compr_stream *stream,
  97. struct snd_codec *params);
  98. int (*set_metadata)(struct snd_compr_stream *stream,
  99. struct snd_compr_metadata *metadata);
  100. int (*get_metadata)(struct snd_compr_stream *stream,
  101. struct snd_compr_metadata *metadata);
  102. int (*trigger)(struct snd_compr_stream *stream, int cmd);
  103. int (*pointer)(struct snd_compr_stream *stream,
  104. struct snd_compr_tstamp *tstamp);
  105. int (*copy)(struct snd_compr_stream *stream, char __user *buf,
  106. size_t count);
  107. int (*mmap)(struct snd_compr_stream *stream,
  108. struct vm_area_struct *vma);
  109. int (*ack)(struct snd_compr_stream *stream, size_t bytes);
  110. int (*get_caps) (struct snd_compr_stream *stream,
  111. struct snd_compr_caps *caps);
  112. int (*get_codec_caps) (struct snd_compr_stream *stream,
  113. struct snd_compr_codec_caps *codec);
  114. };
  115. /**
  116. * struct snd_compr: Compressed device
  117. * @name: DSP device name
  118. * @dev: associated device instance
  119. * @ops: pointer to DSP callbacks
  120. * @private_data: pointer to DSP pvt data
  121. * @card: sound card pointer
  122. * @direction: Playback or capture direction
  123. * @lock: device lock
  124. * @device: device id
  125. */
  126. struct snd_compr {
  127. const char *name;
  128. struct device dev;
  129. struct snd_compr_ops *ops;
  130. void *private_data;
  131. struct snd_card *card;
  132. unsigned int direction;
  133. struct mutex lock;
  134. int device;
  135. #ifdef CONFIG_SND_VERBOSE_PROCFS
  136. /* private: */
  137. char id[64];
  138. struct snd_info_entry *proc_root;
  139. struct snd_info_entry *proc_info_entry;
  140. #endif
  141. };
  142. /* compress device register APIs */
  143. int snd_compress_register(struct snd_compr *device);
  144. int snd_compress_deregister(struct snd_compr *device);
  145. int snd_compress_new(struct snd_card *card, int device,
  146. int type, const char *id, struct snd_compr *compr);
  147. /* dsp driver callback apis
  148. * For playback: driver should call snd_compress_fragment_elapsed() to let the
  149. * framework know that a fragment has been consumed from the ring buffer
  150. *
  151. * For recording: we want to know when a frame is available or when
  152. * at least one frame is available so snd_compress_frame_elapsed()
  153. * callback should be called when a encodeded frame is available
  154. */
  155. static inline void snd_compr_fragment_elapsed(struct snd_compr_stream *stream)
  156. {
  157. wake_up(&stream->runtime->sleep);
  158. }
  159. static inline void snd_compr_drain_notify(struct snd_compr_stream *stream)
  160. {
  161. if (snd_BUG_ON(!stream))
  162. return;
  163. stream->runtime->state = SNDRV_PCM_STATE_SETUP;
  164. wake_up(&stream->runtime->sleep);
  165. }
  166. int snd_compr_stop_error(struct snd_compr_stream *stream,
  167. snd_pcm_state_t state);
  168. #endif