xref: /openbmc/linux/drivers/media/pci/ivtv/ivtv-queue.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2b285192aSMauro Carvalho Chehab /*
3b285192aSMauro Carvalho Chehab     buffer queues.
4b285192aSMauro Carvalho Chehab     Copyright (C) 2003-2004  Kevin Thayer <nufan_wfk at yahoo.com>
5b285192aSMauro Carvalho Chehab     Copyright (C) 2004  Chris Kennedy <c@groovy.org>
6b285192aSMauro Carvalho Chehab     Copyright (C) 2005-2007  Hans Verkuil <hverkuil@xs4all.nl>
7b285192aSMauro Carvalho Chehab 
8b285192aSMauro Carvalho Chehab  */
9b285192aSMauro Carvalho Chehab 
10b285192aSMauro Carvalho Chehab #ifndef IVTV_QUEUE_H
11b285192aSMauro Carvalho Chehab #define IVTV_QUEUE_H
12b285192aSMauro Carvalho Chehab 
13b285192aSMauro Carvalho Chehab #define IVTV_DMA_UNMAPPED	((u32) -1)
14b285192aSMauro Carvalho Chehab #define SLICED_VBI_PIO 0
15b285192aSMauro Carvalho Chehab 
16b285192aSMauro Carvalho Chehab /* ivtv_buffer utility functions */
17b285192aSMauro Carvalho Chehab 
ivtv_might_use_pio(struct ivtv_stream * s)18b285192aSMauro Carvalho Chehab static inline int ivtv_might_use_pio(struct ivtv_stream *s)
19b285192aSMauro Carvalho Chehab {
20*4e541b06SChristophe JAILLET 	return s->dma == DMA_NONE || (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI);
21b285192aSMauro Carvalho Chehab }
22b285192aSMauro Carvalho Chehab 
ivtv_use_pio(struct ivtv_stream * s)23b285192aSMauro Carvalho Chehab static inline int ivtv_use_pio(struct ivtv_stream *s)
24b285192aSMauro Carvalho Chehab {
25b285192aSMauro Carvalho Chehab 	struct ivtv *itv = s->itv;
26b285192aSMauro Carvalho Chehab 
27*4e541b06SChristophe JAILLET 	return s->dma == DMA_NONE ||
28b285192aSMauro Carvalho Chehab 	    (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set);
29b285192aSMauro Carvalho Chehab }
30b285192aSMauro Carvalho Chehab 
ivtv_might_use_dma(struct ivtv_stream * s)31b285192aSMauro Carvalho Chehab static inline int ivtv_might_use_dma(struct ivtv_stream *s)
32b285192aSMauro Carvalho Chehab {
33*4e541b06SChristophe JAILLET 	return s->dma != DMA_NONE;
34b285192aSMauro Carvalho Chehab }
35b285192aSMauro Carvalho Chehab 
ivtv_use_dma(struct ivtv_stream * s)36b285192aSMauro Carvalho Chehab static inline int ivtv_use_dma(struct ivtv_stream *s)
37b285192aSMauro Carvalho Chehab {
38b285192aSMauro Carvalho Chehab 	return !ivtv_use_pio(s);
39b285192aSMauro Carvalho Chehab }
40b285192aSMauro Carvalho Chehab 
ivtv_buf_sync_for_cpu(struct ivtv_stream * s,struct ivtv_buffer * buf)41b285192aSMauro Carvalho Chehab static inline void ivtv_buf_sync_for_cpu(struct ivtv_stream *s, struct ivtv_buffer *buf)
42b285192aSMauro Carvalho Chehab {
43b285192aSMauro Carvalho Chehab 	if (ivtv_use_dma(s))
44*4e541b06SChristophe JAILLET 		dma_sync_single_for_cpu(&s->itv->pdev->dev, buf->dma_handle,
45b285192aSMauro Carvalho Chehab 					s->buf_size + 256, s->dma);
46b285192aSMauro Carvalho Chehab }
47b285192aSMauro Carvalho Chehab 
ivtv_buf_sync_for_device(struct ivtv_stream * s,struct ivtv_buffer * buf)48b285192aSMauro Carvalho Chehab static inline void ivtv_buf_sync_for_device(struct ivtv_stream *s, struct ivtv_buffer *buf)
49b285192aSMauro Carvalho Chehab {
50b285192aSMauro Carvalho Chehab 	if (ivtv_use_dma(s))
51*4e541b06SChristophe JAILLET 		dma_sync_single_for_device(&s->itv->pdev->dev,
52*4e541b06SChristophe JAILLET 					   buf->dma_handle, s->buf_size + 256,
53*4e541b06SChristophe JAILLET 					   s->dma);
54b285192aSMauro Carvalho Chehab }
55b285192aSMauro Carvalho Chehab 
56b285192aSMauro Carvalho Chehab int ivtv_buf_copy_from_user(struct ivtv_stream *s, struct ivtv_buffer *buf, const char __user *src, int copybytes);
57b285192aSMauro Carvalho Chehab void ivtv_buf_swap(struct ivtv_buffer *buf);
58b285192aSMauro Carvalho Chehab 
59b285192aSMauro Carvalho Chehab /* ivtv_queue utility functions */
60b285192aSMauro Carvalho Chehab void ivtv_queue_init(struct ivtv_queue *q);
61b285192aSMauro Carvalho Chehab void ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_queue *q);
62b285192aSMauro Carvalho Chehab struct ivtv_buffer *ivtv_dequeue(struct ivtv_stream *s, struct ivtv_queue *q);
63b285192aSMauro Carvalho Chehab int ivtv_queue_move(struct ivtv_stream *s, struct ivtv_queue *from, struct ivtv_queue *steal,
64b285192aSMauro Carvalho Chehab 		    struct ivtv_queue *to, int needed_bytes);
65b285192aSMauro Carvalho Chehab void ivtv_flush_queues(struct ivtv_stream *s);
66b285192aSMauro Carvalho Chehab 
67b285192aSMauro Carvalho Chehab /* ivtv_stream utility functions */
68b285192aSMauro Carvalho Chehab int ivtv_stream_alloc(struct ivtv_stream *s);
69b285192aSMauro Carvalho Chehab void ivtv_stream_free(struct ivtv_stream *s);
70b285192aSMauro Carvalho Chehab 
ivtv_stream_sync_for_cpu(struct ivtv_stream * s)71b285192aSMauro Carvalho Chehab static inline void ivtv_stream_sync_for_cpu(struct ivtv_stream *s)
72b285192aSMauro Carvalho Chehab {
73b285192aSMauro Carvalho Chehab 	if (ivtv_use_dma(s))
74*4e541b06SChristophe JAILLET 		dma_sync_single_for_cpu(&s->itv->pdev->dev, s->sg_handle,
75*4e541b06SChristophe JAILLET 					sizeof(struct ivtv_sg_element),
76*4e541b06SChristophe JAILLET 					DMA_TO_DEVICE);
77b285192aSMauro Carvalho Chehab }
78b285192aSMauro Carvalho Chehab 
ivtv_stream_sync_for_device(struct ivtv_stream * s)79b285192aSMauro Carvalho Chehab static inline void ivtv_stream_sync_for_device(struct ivtv_stream *s)
80b285192aSMauro Carvalho Chehab {
81b285192aSMauro Carvalho Chehab 	if (ivtv_use_dma(s))
82*4e541b06SChristophe JAILLET 		dma_sync_single_for_device(&s->itv->pdev->dev, s->sg_handle,
83*4e541b06SChristophe JAILLET 					   sizeof(struct ivtv_sg_element),
84*4e541b06SChristophe JAILLET 					   DMA_TO_DEVICE);
85b285192aSMauro Carvalho Chehab }
86b285192aSMauro Carvalho Chehab 
87b285192aSMauro Carvalho Chehab #endif
88