1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * cx18 buffer queues
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Derived from ivtv-queue.h
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
8*4882a593Smuzhiyun * Copyright (C) 2008 Andy Walls <awalls@md.metrocast.net>
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #define CX18_DMA_UNMAPPED ((u32) -1)
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun /* cx18_buffer utility functions */
14*4882a593Smuzhiyun
cx18_buf_sync_for_cpu(struct cx18_stream * s,struct cx18_buffer * buf)15*4882a593Smuzhiyun static inline void cx18_buf_sync_for_cpu(struct cx18_stream *s,
16*4882a593Smuzhiyun struct cx18_buffer *buf)
17*4882a593Smuzhiyun {
18*4882a593Smuzhiyun pci_dma_sync_single_for_cpu(s->cx->pci_dev, buf->dma_handle,
19*4882a593Smuzhiyun s->buf_size, s->dma);
20*4882a593Smuzhiyun }
21*4882a593Smuzhiyun
cx18_buf_sync_for_device(struct cx18_stream * s,struct cx18_buffer * buf)22*4882a593Smuzhiyun static inline void cx18_buf_sync_for_device(struct cx18_stream *s,
23*4882a593Smuzhiyun struct cx18_buffer *buf)
24*4882a593Smuzhiyun {
25*4882a593Smuzhiyun pci_dma_sync_single_for_device(s->cx->pci_dev, buf->dma_handle,
26*4882a593Smuzhiyun s->buf_size, s->dma);
27*4882a593Smuzhiyun }
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun void _cx18_mdl_sync_for_device(struct cx18_stream *s, struct cx18_mdl *mdl);
30*4882a593Smuzhiyun
cx18_mdl_sync_for_device(struct cx18_stream * s,struct cx18_mdl * mdl)31*4882a593Smuzhiyun static inline void cx18_mdl_sync_for_device(struct cx18_stream *s,
32*4882a593Smuzhiyun struct cx18_mdl *mdl)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun if (list_is_singular(&mdl->buf_list))
35*4882a593Smuzhiyun cx18_buf_sync_for_device(s, list_first_entry(&mdl->buf_list,
36*4882a593Smuzhiyun struct cx18_buffer,
37*4882a593Smuzhiyun list));
38*4882a593Smuzhiyun else
39*4882a593Smuzhiyun _cx18_mdl_sync_for_device(s, mdl);
40*4882a593Smuzhiyun }
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun void cx18_buf_swap(struct cx18_buffer *buf);
43*4882a593Smuzhiyun void _cx18_mdl_swap(struct cx18_mdl *mdl);
44*4882a593Smuzhiyun
cx18_mdl_swap(struct cx18_mdl * mdl)45*4882a593Smuzhiyun static inline void cx18_mdl_swap(struct cx18_mdl *mdl)
46*4882a593Smuzhiyun {
47*4882a593Smuzhiyun if (list_is_singular(&mdl->buf_list))
48*4882a593Smuzhiyun cx18_buf_swap(list_first_entry(&mdl->buf_list,
49*4882a593Smuzhiyun struct cx18_buffer, list));
50*4882a593Smuzhiyun else
51*4882a593Smuzhiyun _cx18_mdl_swap(mdl);
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun /* cx18_queue utility functions */
55*4882a593Smuzhiyun struct cx18_queue *_cx18_enqueue(struct cx18_stream *s, struct cx18_mdl *mdl,
56*4882a593Smuzhiyun struct cx18_queue *q, int to_front);
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun static inline
cx18_enqueue(struct cx18_stream * s,struct cx18_mdl * mdl,struct cx18_queue * q)59*4882a593Smuzhiyun struct cx18_queue *cx18_enqueue(struct cx18_stream *s, struct cx18_mdl *mdl,
60*4882a593Smuzhiyun struct cx18_queue *q)
61*4882a593Smuzhiyun {
62*4882a593Smuzhiyun return _cx18_enqueue(s, mdl, q, 0); /* FIFO */
63*4882a593Smuzhiyun }
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun static inline
cx18_push(struct cx18_stream * s,struct cx18_mdl * mdl,struct cx18_queue * q)66*4882a593Smuzhiyun struct cx18_queue *cx18_push(struct cx18_stream *s, struct cx18_mdl *mdl,
67*4882a593Smuzhiyun struct cx18_queue *q)
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun return _cx18_enqueue(s, mdl, q, 1); /* LIFO */
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun void cx18_queue_init(struct cx18_queue *q);
73*4882a593Smuzhiyun struct cx18_mdl *cx18_dequeue(struct cx18_stream *s, struct cx18_queue *q);
74*4882a593Smuzhiyun struct cx18_mdl *cx18_queue_get_mdl(struct cx18_stream *s, u32 id,
75*4882a593Smuzhiyun u32 bytesused);
76*4882a593Smuzhiyun void cx18_flush_queues(struct cx18_stream *s);
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun /* queue MDL reconfiguration helpers */
79*4882a593Smuzhiyun void cx18_unload_queues(struct cx18_stream *s);
80*4882a593Smuzhiyun void cx18_load_queues(struct cx18_stream *s);
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun /* cx18_stream utility functions */
83*4882a593Smuzhiyun int cx18_stream_alloc(struct cx18_stream *s);
84*4882a593Smuzhiyun void cx18_stream_free(struct cx18_stream *s);
85