ivtv-queue.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. buffer queues.
  4. Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
  5. Copyright (C) 2004 Chris Kennedy <[email protected]>
  6. Copyright (C) 2005-2007 Hans Verkuil <[email protected]>
  7. */
  8. #ifndef IVTV_QUEUE_H
  9. #define IVTV_QUEUE_H
  10. #define IVTV_DMA_UNMAPPED ((u32) -1)
  11. #define SLICED_VBI_PIO 0
  12. /* ivtv_buffer utility functions */
  13. static inline int ivtv_might_use_pio(struct ivtv_stream *s)
  14. {
  15. return s->dma == DMA_NONE || (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI);
  16. }
  17. static inline int ivtv_use_pio(struct ivtv_stream *s)
  18. {
  19. struct ivtv *itv = s->itv;
  20. return s->dma == DMA_NONE ||
  21. (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set);
  22. }
  23. static inline int ivtv_might_use_dma(struct ivtv_stream *s)
  24. {
  25. return s->dma != DMA_NONE;
  26. }
  27. static inline int ivtv_use_dma(struct ivtv_stream *s)
  28. {
  29. return !ivtv_use_pio(s);
  30. }
  31. static inline void ivtv_buf_sync_for_cpu(struct ivtv_stream *s, struct ivtv_buffer *buf)
  32. {
  33. if (ivtv_use_dma(s))
  34. dma_sync_single_for_cpu(&s->itv->pdev->dev, buf->dma_handle,
  35. s->buf_size + 256, s->dma);
  36. }
  37. static inline void ivtv_buf_sync_for_device(struct ivtv_stream *s, struct ivtv_buffer *buf)
  38. {
  39. if (ivtv_use_dma(s))
  40. dma_sync_single_for_device(&s->itv->pdev->dev,
  41. buf->dma_handle, s->buf_size + 256,
  42. s->dma);
  43. }
  44. int ivtv_buf_copy_from_user(struct ivtv_stream *s, struct ivtv_buffer *buf, const char __user *src, int copybytes);
  45. void ivtv_buf_swap(struct ivtv_buffer *buf);
  46. /* ivtv_queue utility functions */
  47. void ivtv_queue_init(struct ivtv_queue *q);
  48. void ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_queue *q);
  49. struct ivtv_buffer *ivtv_dequeue(struct ivtv_stream *s, struct ivtv_queue *q);
  50. int ivtv_queue_move(struct ivtv_stream *s, struct ivtv_queue *from, struct ivtv_queue *steal,
  51. struct ivtv_queue *to, int needed_bytes);
  52. void ivtv_flush_queues(struct ivtv_stream *s);
  53. /* ivtv_stream utility functions */
  54. int ivtv_stream_alloc(struct ivtv_stream *s);
  55. void ivtv_stream_free(struct ivtv_stream *s);
  56. static inline void ivtv_stream_sync_for_cpu(struct ivtv_stream *s)
  57. {
  58. if (ivtv_use_dma(s))
  59. dma_sync_single_for_cpu(&s->itv->pdev->dev, s->sg_handle,
  60. sizeof(struct ivtv_sg_element),
  61. DMA_TO_DEVICE);
  62. }
  63. static inline void ivtv_stream_sync_for_device(struct ivtv_stream *s)
  64. {
  65. if (ivtv_use_dma(s))
  66. dma_sync_single_for_device(&s->itv->pdev->dev, s->sg_handle,
  67. sizeof(struct ivtv_sg_element),
  68. DMA_TO_DEVICE);
  69. }
  70. #endif