blob: e0a34bd6539eb20ef08d7f08ca0a46bba59b1a0d [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03002/*
3 * cx18 buffer queues
4 *
5 * Derived from ivtv-queue.h
6 *
7 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
Andy Walls6afdeaf2010-05-23 18:53:35 -03008 * Copyright (C) 2008 Andy Walls <awalls@md.metrocast.net>
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03009 */
10
11#define CX18_DMA_UNMAPPED ((u32) -1)
12
13/* cx18_buffer utility functions */
14
15static inline void cx18_buf_sync_for_cpu(struct cx18_stream *s,
16 struct cx18_buffer *buf)
17{
Andy Walls3d05913d2009-01-10 21:54:39 -030018 pci_dma_sync_single_for_cpu(s->cx->pci_dev, buf->dma_handle,
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030019 s->buf_size, s->dma);
20}
21
22static inline void cx18_buf_sync_for_device(struct cx18_stream *s,
23 struct cx18_buffer *buf)
24{
Andy Walls3d05913d2009-01-10 21:54:39 -030025 pci_dma_sync_single_for_device(s->cx->pci_dev, buf->dma_handle,
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030026 s->buf_size, s->dma);
27}
28
Andy Walls52fcb3e2009-11-08 23:45:24 -030029void _cx18_mdl_sync_for_device(struct cx18_stream *s, struct cx18_mdl *mdl);
30
31static inline void cx18_mdl_sync_for_device(struct cx18_stream *s,
32 struct cx18_mdl *mdl)
33{
34 if (list_is_singular(&mdl->buf_list))
35 cx18_buf_sync_for_device(s, list_first_entry(&mdl->buf_list,
36 struct cx18_buffer,
37 list));
38 else
39 _cx18_mdl_sync_for_device(s, mdl);
40}
41
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030042void cx18_buf_swap(struct cx18_buffer *buf);
Andy Walls52fcb3e2009-11-08 23:45:24 -030043void _cx18_mdl_swap(struct cx18_mdl *mdl);
44
45static inline void cx18_mdl_swap(struct cx18_mdl *mdl)
46{
47 if (list_is_singular(&mdl->buf_list))
48 cx18_buf_swap(list_first_entry(&mdl->buf_list,
49 struct cx18_buffer, list));
50 else
51 _cx18_mdl_swap(mdl);
52}
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030053
54/* cx18_queue utility functions */
Andy Walls52fcb3e2009-11-08 23:45:24 -030055struct cx18_queue *_cx18_enqueue(struct cx18_stream *s, struct cx18_mdl *mdl,
Andy Walls66c2a6b2008-12-08 23:02:45 -030056 struct cx18_queue *q, int to_front);
Andy Wallsb80e1072008-11-28 00:04:21 -030057
58static inline
Andy Walls52fcb3e2009-11-08 23:45:24 -030059struct cx18_queue *cx18_enqueue(struct cx18_stream *s, struct cx18_mdl *mdl,
Andy Walls66c2a6b2008-12-08 23:02:45 -030060 struct cx18_queue *q)
Andy Wallsb80e1072008-11-28 00:04:21 -030061{
Andy Walls52fcb3e2009-11-08 23:45:24 -030062 return _cx18_enqueue(s, mdl, q, 0); /* FIFO */
Andy Wallsb80e1072008-11-28 00:04:21 -030063}
64
65static inline
Andy Walls52fcb3e2009-11-08 23:45:24 -030066struct cx18_queue *cx18_push(struct cx18_stream *s, struct cx18_mdl *mdl,
Andy Walls66c2a6b2008-12-08 23:02:45 -030067 struct cx18_queue *q)
Andy Wallsb80e1072008-11-28 00:04:21 -030068{
Andy Walls52fcb3e2009-11-08 23:45:24 -030069 return _cx18_enqueue(s, mdl, q, 1); /* LIFO */
Andy Wallsb80e1072008-11-28 00:04:21 -030070}
71
72void cx18_queue_init(struct cx18_queue *q);
Andy Walls52fcb3e2009-11-08 23:45:24 -030073struct cx18_mdl *cx18_dequeue(struct cx18_stream *s, struct cx18_queue *q);
74struct cx18_mdl *cx18_queue_get_mdl(struct cx18_stream *s, u32 id,
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030075 u32 bytesused);
76void cx18_flush_queues(struct cx18_stream *s);
77
Andy Walls52fcb3e2009-11-08 23:45:24 -030078/* queue MDL reconfiguration helpers */
79void cx18_unload_queues(struct cx18_stream *s);
80void cx18_load_queues(struct cx18_stream *s);
81
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030082/* cx18_stream utility functions */
83int cx18_stream_alloc(struct cx18_stream *s);
84void cx18_stream_free(struct cx18_stream *s);