blob: 586b0bf63c261a0c90eef04adb6ac68e9daf1dc1 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03002/*
3 buffer queues.
4 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
5 Copyright (C) 2004 Chris Kennedy <c@groovy.org>
6 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
7
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03008 */
9
Hans Verkuil612570f2007-08-23 05:42:59 -030010#ifndef IVTV_QUEUE_H
11#define IVTV_QUEUE_H
12
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030013#define IVTV_DMA_UNMAPPED ((u32) -1)
Hans Verkuild526afe2008-09-03 16:47:14 -030014#define SLICED_VBI_PIO 0
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030015
16/* ivtv_buffer utility functions */
Hans Verkuildc02d502007-05-19 14:07:16 -030017
18static inline int ivtv_might_use_pio(struct ivtv_stream *s)
19{
20 return s->dma == PCI_DMA_NONE || (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI);
21}
22
23static inline int ivtv_use_pio(struct ivtv_stream *s)
24{
25 struct ivtv *itv = s->itv;
26
27 return s->dma == PCI_DMA_NONE ||
28 (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set);
29}
30
31static inline int ivtv_might_use_dma(struct ivtv_stream *s)
32{
33 return s->dma != PCI_DMA_NONE;
34}
35
36static inline int ivtv_use_dma(struct ivtv_stream *s)
37{
38 return !ivtv_use_pio(s);
39}
40
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030041static inline void ivtv_buf_sync_for_cpu(struct ivtv_stream *s, struct ivtv_buffer *buf)
42{
Hans Verkuildc02d502007-05-19 14:07:16 -030043 if (ivtv_use_dma(s))
Hans Verkuil8ac05ae2009-02-07 07:02:27 -030044 pci_dma_sync_single_for_cpu(s->itv->pdev, buf->dma_handle,
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030045 s->buf_size + 256, s->dma);
46}
47
48static inline void ivtv_buf_sync_for_device(struct ivtv_stream *s, struct ivtv_buffer *buf)
49{
Hans Verkuildc02d502007-05-19 14:07:16 -030050 if (ivtv_use_dma(s))
Hans Verkuil8ac05ae2009-02-07 07:02:27 -030051 pci_dma_sync_single_for_device(s->itv->pdev, buf->dma_handle,
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030052 s->buf_size + 256, s->dma);
53}
54
55int ivtv_buf_copy_from_user(struct ivtv_stream *s, struct ivtv_buffer *buf, const char __user *src, int copybytes);
56void ivtv_buf_swap(struct ivtv_buffer *buf);
57
58/* ivtv_queue utility functions */
59void ivtv_queue_init(struct ivtv_queue *q);
60void ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_queue *q);
61struct ivtv_buffer *ivtv_dequeue(struct ivtv_stream *s, struct ivtv_queue *q);
62int ivtv_queue_move(struct ivtv_stream *s, struct ivtv_queue *from, struct ivtv_queue *steal,
63 struct ivtv_queue *to, int needed_bytes);
64void ivtv_flush_queues(struct ivtv_stream *s);
65
66/* ivtv_stream utility functions */
67int ivtv_stream_alloc(struct ivtv_stream *s);
68void ivtv_stream_free(struct ivtv_stream *s);
69
70static inline void ivtv_stream_sync_for_cpu(struct ivtv_stream *s)
71{
Hans Verkuildc02d502007-05-19 14:07:16 -030072 if (ivtv_use_dma(s))
Hans Verkuil8ac05ae2009-02-07 07:02:27 -030073 pci_dma_sync_single_for_cpu(s->itv->pdev, s->sg_handle,
Hans Verkuil37093b12007-07-28 19:45:50 -030074 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030075}
76
77static inline void ivtv_stream_sync_for_device(struct ivtv_stream *s)
78{
Hans Verkuildc02d502007-05-19 14:07:16 -030079 if (ivtv_use_dma(s))
Hans Verkuil8ac05ae2009-02-07 07:02:27 -030080 pci_dma_sync_single_for_device(s->itv->pdev, s->sg_handle,
Hans Verkuil37093b12007-07-28 19:45:50 -030081 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030082}
Hans Verkuil612570f2007-08-23 05:42:59 -030083
84#endif