ivtv-queue.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #define IVTV_DMA_UNMAPPED ((u32) -1)
  19. #define SLICED_VBI_PIO 1
  20. /* ivtv_buffer utility functions */
  21. static inline int ivtv_might_use_pio(struct ivtv_stream *s)
  22. {
  23. return s->dma == PCI_DMA_NONE || (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI);
  24. }
  25. static inline int ivtv_use_pio(struct ivtv_stream *s)
  26. {
  27. struct ivtv *itv = s->itv;
  28. return s->dma == PCI_DMA_NONE ||
  29. (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set);
  30. }
  31. static inline int ivtv_might_use_dma(struct ivtv_stream *s)
  32. {
  33. return s->dma != PCI_DMA_NONE;
  34. }
  35. static inline int ivtv_use_dma(struct ivtv_stream *s)
  36. {
  37. return !ivtv_use_pio(s);
  38. }
  39. static inline void ivtv_buf_sync_for_cpu(struct ivtv_stream *s, struct ivtv_buffer *buf)
  40. {
  41. if (ivtv_use_dma(s))
  42. pci_dma_sync_single_for_cpu(s->itv->dev, buf->dma_handle,
  43. s->buf_size + 256, s->dma);
  44. }
  45. static inline void ivtv_buf_sync_for_device(struct ivtv_stream *s, struct ivtv_buffer *buf)
  46. {
  47. if (ivtv_use_dma(s))
  48. pci_dma_sync_single_for_device(s->itv->dev, buf->dma_handle,
  49. s->buf_size + 256, s->dma);
  50. }
  51. int ivtv_buf_copy_from_user(struct ivtv_stream *s, struct ivtv_buffer *buf, const char __user *src, int copybytes);
  52. void ivtv_buf_swap(struct ivtv_buffer *buf);
  53. /* ivtv_queue utility functions */
  54. void ivtv_queue_init(struct ivtv_queue *q);
  55. void ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_queue *q);
  56. struct ivtv_buffer *ivtv_dequeue(struct ivtv_stream *s, struct ivtv_queue *q);
  57. int ivtv_queue_move(struct ivtv_stream *s, struct ivtv_queue *from, struct ivtv_queue *steal,
  58. struct ivtv_queue *to, int needed_bytes);
  59. void ivtv_flush_queues(struct ivtv_stream *s);
  60. /* ivtv_stream utility functions */
  61. int ivtv_stream_alloc(struct ivtv_stream *s);
  62. void ivtv_stream_free(struct ivtv_stream *s);
  63. static inline void ivtv_stream_sync_for_cpu(struct ivtv_stream *s)
  64. {
  65. if (ivtv_use_dma(s))
  66. pci_dma_sync_single_for_cpu(s->itv->dev, s->sg_handle,
  67. sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
  68. }
  69. static inline void ivtv_stream_sync_for_device(struct ivtv_stream *s)
  70. {
  71. if (ivtv_use_dma(s))
  72. pci_dma_sync_single_for_device(s->itv->dev, s->sg_handle,
  73. sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
  74. }