1 /* SPDX-License-Identifier: GPL-2.0-or-later */
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>
13 #define IVTV_DMA_UNMAPPED ((u32) -1)
14 #define SLICED_VBI_PIO 0
16 /* ivtv_buffer utility functions */
18 static inline int ivtv_might_use_pio(struct ivtv_stream
*s
)
20 return s
->dma
== DMA_NONE
|| (SLICED_VBI_PIO
&& s
->type
== IVTV_ENC_STREAM_TYPE_VBI
);
23 static inline int ivtv_use_pio(struct ivtv_stream
*s
)
25 struct ivtv
*itv
= s
->itv
;
27 return s
->dma
== DMA_NONE
||
28 (SLICED_VBI_PIO
&& s
->type
== IVTV_ENC_STREAM_TYPE_VBI
&& itv
->vbi
.sliced_in
->service_set
);
31 static inline int ivtv_might_use_dma(struct ivtv_stream
*s
)
33 return s
->dma
!= DMA_NONE
;
36 static inline int ivtv_use_dma(struct ivtv_stream
*s
)
38 return !ivtv_use_pio(s
);
41 static inline void ivtv_buf_sync_for_cpu(struct ivtv_stream
*s
, struct ivtv_buffer
*buf
)
44 dma_sync_single_for_cpu(&s
->itv
->pdev
->dev
, buf
->dma_handle
,
45 s
->buf_size
+ 256, s
->dma
);
48 static inline void ivtv_buf_sync_for_device(struct ivtv_stream
*s
, struct ivtv_buffer
*buf
)
51 dma_sync_single_for_device(&s
->itv
->pdev
->dev
,
52 buf
->dma_handle
, s
->buf_size
+ 256,
56 int ivtv_buf_copy_from_user(struct ivtv_stream
*s
, struct ivtv_buffer
*buf
, const char __user
*src
, int copybytes
);
57 void ivtv_buf_swap(struct ivtv_buffer
*buf
);
59 /* ivtv_queue utility functions */
60 void ivtv_queue_init(struct ivtv_queue
*q
);
61 void ivtv_enqueue(struct ivtv_stream
*s
, struct ivtv_buffer
*buf
, struct ivtv_queue
*q
);
62 struct ivtv_buffer
*ivtv_dequeue(struct ivtv_stream
*s
, struct ivtv_queue
*q
);
63 int ivtv_queue_move(struct ivtv_stream
*s
, struct ivtv_queue
*from
, struct ivtv_queue
*steal
,
64 struct ivtv_queue
*to
, int needed_bytes
);
65 void ivtv_flush_queues(struct ivtv_stream
*s
);
67 /* ivtv_stream utility functions */
68 int ivtv_stream_alloc(struct ivtv_stream
*s
);
69 void ivtv_stream_free(struct ivtv_stream
*s
);
71 static inline void ivtv_stream_sync_for_cpu(struct ivtv_stream
*s
)
74 dma_sync_single_for_cpu(&s
->itv
->pdev
->dev
, s
->sg_handle
,
75 sizeof(struct ivtv_sg_element
),
79 static inline void ivtv_stream_sync_for_device(struct ivtv_stream
*s
)
82 dma_sync_single_for_device(&s
->itv
->pdev
->dev
, s
->sg_handle
,
83 sizeof(struct ivtv_sg_element
),