Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 1 | /* |
| 2 | buffer queues. |
| 3 | Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com> |
| 4 | Copyright (C) 2004 Chris Kennedy <c@groovy.org> |
| 5 | Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl> |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
| 22 | #define IVTV_DMA_UNMAPPED ((u32) -1) |
Hans Verkuil | dc02d50 | 2007-05-19 14:07:16 -0300 | [diff] [blame] | 23 | #define SLICED_VBI_PIO 1 |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 24 | |
| 25 | /* ivtv_buffer utility functions */ |
Hans Verkuil | dc02d50 | 2007-05-19 14:07:16 -0300 | [diff] [blame] | 26 | |
| 27 | static inline int ivtv_might_use_pio(struct ivtv_stream *s) |
| 28 | { |
| 29 | return s->dma == PCI_DMA_NONE || (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI); |
| 30 | } |
| 31 | |
| 32 | static inline int ivtv_use_pio(struct ivtv_stream *s) |
| 33 | { |
| 34 | struct ivtv *itv = s->itv; |
| 35 | |
| 36 | return s->dma == PCI_DMA_NONE || |
| 37 | (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set); |
| 38 | } |
| 39 | |
| 40 | static inline int ivtv_might_use_dma(struct ivtv_stream *s) |
| 41 | { |
| 42 | return s->dma != PCI_DMA_NONE; |
| 43 | } |
| 44 | |
| 45 | static inline int ivtv_use_dma(struct ivtv_stream *s) |
| 46 | { |
| 47 | return !ivtv_use_pio(s); |
| 48 | } |
| 49 | |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 50 | static inline void ivtv_buf_sync_for_cpu(struct ivtv_stream *s, struct ivtv_buffer *buf) |
| 51 | { |
Hans Verkuil | dc02d50 | 2007-05-19 14:07:16 -0300 | [diff] [blame] | 52 | if (ivtv_use_dma(s)) |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 53 | pci_dma_sync_single_for_cpu(s->itv->dev, buf->dma_handle, |
| 54 | s->buf_size + 256, s->dma); |
| 55 | } |
| 56 | |
| 57 | static inline void ivtv_buf_sync_for_device(struct ivtv_stream *s, struct ivtv_buffer *buf) |
| 58 | { |
Hans Verkuil | dc02d50 | 2007-05-19 14:07:16 -0300 | [diff] [blame] | 59 | if (ivtv_use_dma(s)) |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 60 | pci_dma_sync_single_for_device(s->itv->dev, buf->dma_handle, |
| 61 | s->buf_size + 256, s->dma); |
| 62 | } |
| 63 | |
| 64 | int ivtv_buf_copy_from_user(struct ivtv_stream *s, struct ivtv_buffer *buf, const char __user *src, int copybytes); |
| 65 | void ivtv_buf_swap(struct ivtv_buffer *buf); |
| 66 | |
| 67 | /* ivtv_queue utility functions */ |
| 68 | void ivtv_queue_init(struct ivtv_queue *q); |
| 69 | void ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_queue *q); |
| 70 | struct ivtv_buffer *ivtv_dequeue(struct ivtv_stream *s, struct ivtv_queue *q); |
| 71 | int ivtv_queue_move(struct ivtv_stream *s, struct ivtv_queue *from, struct ivtv_queue *steal, |
| 72 | struct ivtv_queue *to, int needed_bytes); |
| 73 | void ivtv_flush_queues(struct ivtv_stream *s); |
| 74 | |
| 75 | /* ivtv_stream utility functions */ |
| 76 | int ivtv_stream_alloc(struct ivtv_stream *s); |
| 77 | void ivtv_stream_free(struct ivtv_stream *s); |
| 78 | |
| 79 | static inline void ivtv_stream_sync_for_cpu(struct ivtv_stream *s) |
| 80 | { |
Hans Verkuil | dc02d50 | 2007-05-19 14:07:16 -0300 | [diff] [blame] | 81 | if (ivtv_use_dma(s)) |
| 82 | pci_dma_sync_single_for_cpu(s->itv->dev, s->SG_handle, |
| 83 | sizeof(struct ivtv_SG_element) * s->buffers, PCI_DMA_TODEVICE); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static inline void ivtv_stream_sync_for_device(struct ivtv_stream *s) |
| 87 | { |
Hans Verkuil | dc02d50 | 2007-05-19 14:07:16 -0300 | [diff] [blame] | 88 | if (ivtv_use_dma(s)) |
| 89 | pci_dma_sync_single_for_device(s->itv->dev, s->SG_handle, |
| 90 | sizeof(struct ivtv_SG_element) * s->buffers, PCI_DMA_TODEVICE); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 91 | } |