cx18-queue.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * cx18 buffer queues
  3. *
  4. * Derived from ivtv-queue.h
  5. *
  6. * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
  7. * Copyright (C) 2008 Andy Walls <awalls@radix.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  22. * 02111-1307 USA
  23. */
  24. #define CX18_DMA_UNMAPPED ((u32) -1)
  25. /* cx18_buffer utility functions */
  26. static inline void cx18_buf_sync_for_cpu(struct cx18_stream *s,
  27. struct cx18_buffer *buf)
  28. {
  29. pci_dma_sync_single_for_cpu(s->cx->pci_dev, buf->dma_handle,
  30. s->buf_size, s->dma);
  31. }
  32. void _cx18_mdl_sync_for_cpu(struct cx18_stream *s, struct cx18_mdl *mdl);
  33. static inline void cx18_mdl_sync_for_cpu(struct cx18_stream *s,
  34. struct cx18_mdl *mdl)
  35. {
  36. if (list_is_singular(&mdl->buf_list))
  37. cx18_buf_sync_for_cpu(s, list_first_entry(&mdl->buf_list,
  38. struct cx18_buffer,
  39. list));
  40. else
  41. _cx18_mdl_sync_for_cpu(s, mdl);
  42. }
  43. static inline void cx18_buf_sync_for_device(struct cx18_stream *s,
  44. struct cx18_buffer *buf)
  45. {
  46. pci_dma_sync_single_for_device(s->cx->pci_dev, buf->dma_handle,
  47. s->buf_size, s->dma);
  48. }
  49. void _cx18_mdl_sync_for_device(struct cx18_stream *s, struct cx18_mdl *mdl);
  50. static inline void cx18_mdl_sync_for_device(struct cx18_stream *s,
  51. struct cx18_mdl *mdl)
  52. {
  53. if (list_is_singular(&mdl->buf_list))
  54. cx18_buf_sync_for_device(s, list_first_entry(&mdl->buf_list,
  55. struct cx18_buffer,
  56. list));
  57. else
  58. _cx18_mdl_sync_for_device(s, mdl);
  59. }
  60. void cx18_buf_swap(struct cx18_buffer *buf);
  61. void _cx18_mdl_swap(struct cx18_mdl *mdl);
  62. static inline void cx18_mdl_swap(struct cx18_mdl *mdl)
  63. {
  64. if (list_is_singular(&mdl->buf_list))
  65. cx18_buf_swap(list_first_entry(&mdl->buf_list,
  66. struct cx18_buffer, list));
  67. else
  68. _cx18_mdl_swap(mdl);
  69. }
  70. /* cx18_queue utility functions */
  71. struct cx18_queue *_cx18_enqueue(struct cx18_stream *s, struct cx18_mdl *mdl,
  72. struct cx18_queue *q, int to_front);
  73. static inline
  74. struct cx18_queue *cx18_enqueue(struct cx18_stream *s, struct cx18_mdl *mdl,
  75. struct cx18_queue *q)
  76. {
  77. return _cx18_enqueue(s, mdl, q, 0); /* FIFO */
  78. }
  79. static inline
  80. struct cx18_queue *cx18_push(struct cx18_stream *s, struct cx18_mdl *mdl,
  81. struct cx18_queue *q)
  82. {
  83. return _cx18_enqueue(s, mdl, q, 1); /* LIFO */
  84. }
  85. void cx18_queue_init(struct cx18_queue *q);
  86. struct cx18_mdl *cx18_dequeue(struct cx18_stream *s, struct cx18_queue *q);
  87. struct cx18_mdl *cx18_queue_get_mdl(struct cx18_stream *s, u32 id,
  88. u32 bytesused);
  89. void cx18_flush_queues(struct cx18_stream *s);
  90. /* queue MDL reconfiguration helpers */
  91. void cx18_unload_queues(struct cx18_stream *s);
  92. void cx18_load_queues(struct cx18_stream *s);
  93. /* cx18_stream utility functions */
  94. int cx18_stream_alloc(struct cx18_stream *s);
  95. void cx18_stream_free(struct cx18_stream *s);