blob: 7cfc0c9ab050ca781386068ea3c1f0fd1d671e25 [file] [log] [blame]
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001/*
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
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
Hans Verkuil612570f2007-08-23 05:42:59 -030022#ifndef IVTV_QUEUE_H
23#define IVTV_QUEUE_H
24
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030025#define IVTV_DMA_UNMAPPED ((u32) -1)
Hans Verkuildc02d502007-05-19 14:07:16 -030026#define SLICED_VBI_PIO 1
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030027
28/* ivtv_buffer utility functions */
Hans Verkuildc02d502007-05-19 14:07:16 -030029
30static inline int ivtv_might_use_pio(struct ivtv_stream *s)
31{
32 return s->dma == PCI_DMA_NONE || (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI);
33}
34
35static inline int ivtv_use_pio(struct ivtv_stream *s)
36{
37 struct ivtv *itv = s->itv;
38
39 return s->dma == PCI_DMA_NONE ||
40 (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set);
41}
42
43static inline int ivtv_might_use_dma(struct ivtv_stream *s)
44{
45 return s->dma != PCI_DMA_NONE;
46}
47
48static inline int ivtv_use_dma(struct ivtv_stream *s)
49{
50 return !ivtv_use_pio(s);
51}
52
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030053static inline void ivtv_buf_sync_for_cpu(struct ivtv_stream *s, struct ivtv_buffer *buf)
54{
Hans Verkuildc02d502007-05-19 14:07:16 -030055 if (ivtv_use_dma(s))
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030056 pci_dma_sync_single_for_cpu(s->itv->dev, buf->dma_handle,
57 s->buf_size + 256, s->dma);
58}
59
60static inline void ivtv_buf_sync_for_device(struct ivtv_stream *s, struct ivtv_buffer *buf)
61{
Hans Verkuildc02d502007-05-19 14:07:16 -030062 if (ivtv_use_dma(s))
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030063 pci_dma_sync_single_for_device(s->itv->dev, buf->dma_handle,
64 s->buf_size + 256, s->dma);
65}
66
67int ivtv_buf_copy_from_user(struct ivtv_stream *s, struct ivtv_buffer *buf, const char __user *src, int copybytes);
68void ivtv_buf_swap(struct ivtv_buffer *buf);
69
70/* ivtv_queue utility functions */
71void ivtv_queue_init(struct ivtv_queue *q);
72void ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_queue *q);
73struct ivtv_buffer *ivtv_dequeue(struct ivtv_stream *s, struct ivtv_queue *q);
74int ivtv_queue_move(struct ivtv_stream *s, struct ivtv_queue *from, struct ivtv_queue *steal,
75 struct ivtv_queue *to, int needed_bytes);
76void ivtv_flush_queues(struct ivtv_stream *s);
77
78/* ivtv_stream utility functions */
79int ivtv_stream_alloc(struct ivtv_stream *s);
80void ivtv_stream_free(struct ivtv_stream *s);
81
82static inline void ivtv_stream_sync_for_cpu(struct ivtv_stream *s)
83{
Hans Verkuildc02d502007-05-19 14:07:16 -030084 if (ivtv_use_dma(s))
Hans Verkuil37093b12007-07-28 19:45:50 -030085 pci_dma_sync_single_for_cpu(s->itv->dev, s->sg_handle,
86 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030087}
88
89static inline void ivtv_stream_sync_for_device(struct ivtv_stream *s)
90{
Hans Verkuildc02d502007-05-19 14:07:16 -030091 if (ivtv_use_dma(s))
Hans Verkuil37093b12007-07-28 19:45:50 -030092 pci_dma_sync_single_for_device(s->itv->dev, s->sg_handle,
93 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030094}
Hans Verkuil612570f2007-08-23 05:42:59 -030095
96#endif