ivtv-queue.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. buffer queues.
  3. Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
  4. Copyright (C) 2004 Chris Kennedy <c@groovy.org>
  5. Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef IVTV_QUEUE_H
  19. #define IVTV_QUEUE_H
  20. #define IVTV_DMA_UNMAPPED ((u32) -1)
  21. #define SLICED_VBI_PIO 0
  22. /* ivtv_buffer utility functions */
  23. static inline int ivtv_might_use_pio(struct ivtv_stream *s)
  24. {
  25. return s->dma == PCI_DMA_NONE || (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI);
  26. }
  27. static inline int ivtv_use_pio(struct ivtv_stream *s)
  28. {
  29. struct ivtv *itv = s->itv;
  30. return s->dma == PCI_DMA_NONE ||
  31. (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set);
  32. }
  33. static inline int ivtv_might_use_dma(struct ivtv_stream *s)
  34. {
  35. return s->dma != PCI_DMA_NONE;
  36. }
  37. static inline int ivtv_use_dma(struct ivtv_stream *s)
  38. {
  39. return !ivtv_use_pio(s);
  40. }
  41. static inline void ivtv_buf_sync_for_cpu(struct ivtv_stream *s, struct ivtv_buffer *buf)
  42. {
  43. if (ivtv_use_dma(s))
  44. pci_dma_sync_single_for_cpu(s->itv->pdev, buf->dma_handle,
  45. s->buf_size + 256, s->dma);
  46. }
  47. static inline void ivtv_buf_sync_for_device(struct ivtv_stream *s, struct ivtv_buffer *buf)
  48. {
  49. if (ivtv_use_dma(s))
  50. pci_dma_sync_single_for_device(s->itv->pdev, buf->dma_handle,
  51. s->buf_size + 256, s->dma);
  52. }
  53. int ivtv_buf_copy_from_user(struct ivtv_stream *s, struct ivtv_buffer *buf, const char __user *src, int copybytes);
  54. void ivtv_buf_swap(struct ivtv_buffer *buf);
  55. /* ivtv_queue utility functions */
  56. void ivtv_queue_init(struct ivtv_queue *q);
  57. void ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_queue *q);
  58. struct ivtv_buffer *ivtv_dequeue(struct ivtv_stream *s, struct ivtv_queue *q);
  59. int ivtv_queue_move(struct ivtv_stream *s, struct ivtv_queue *from, struct ivtv_queue *steal,
  60. struct ivtv_queue *to, int needed_bytes);
  61. void ivtv_flush_queues(struct ivtv_stream *s);
  62. /* ivtv_stream utility functions */
  63. int ivtv_stream_alloc(struct ivtv_stream *s);
  64. void ivtv_stream_free(struct ivtv_stream *s);
  65. static inline void ivtv_stream_sync_for_cpu(struct ivtv_stream *s)
  66. {
  67. if (ivtv_use_dma(s))
  68. pci_dma_sync_single_for_cpu(s->itv->pdev, s->sg_handle,
  69. sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
  70. }
  71. static inline void ivtv_stream_sync_for_device(struct ivtv_stream *s)
  72. {
  73. if (ivtv_use_dma(s))
  74. pci_dma_sync_single_for_device(s->itv->pdev, s->sg_handle,
  75. sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
  76. }
  77. #endif