18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci buffer queues. 48c2ecf20Sopenharmony_ci Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com> 58c2ecf20Sopenharmony_ci Copyright (C) 2004 Chris Kennedy <c@groovy.org> 68c2ecf20Sopenharmony_ci Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef IVTV_QUEUE_H 118c2ecf20Sopenharmony_ci#define IVTV_QUEUE_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define IVTV_DMA_UNMAPPED ((u32) -1) 148c2ecf20Sopenharmony_ci#define SLICED_VBI_PIO 0 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* ivtv_buffer utility functions */ 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistatic inline int ivtv_might_use_pio(struct ivtv_stream *s) 198c2ecf20Sopenharmony_ci{ 208c2ecf20Sopenharmony_ci return s->dma == PCI_DMA_NONE || (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI); 218c2ecf20Sopenharmony_ci} 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic inline int ivtv_use_pio(struct ivtv_stream *s) 248c2ecf20Sopenharmony_ci{ 258c2ecf20Sopenharmony_ci struct ivtv *itv = s->itv; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci return s->dma == PCI_DMA_NONE || 288c2ecf20Sopenharmony_ci (SLICED_VBI_PIO && s->type == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set); 298c2ecf20Sopenharmony_ci} 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistatic inline int ivtv_might_use_dma(struct ivtv_stream *s) 328c2ecf20Sopenharmony_ci{ 338c2ecf20Sopenharmony_ci return s->dma != PCI_DMA_NONE; 348c2ecf20Sopenharmony_ci} 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistatic inline int ivtv_use_dma(struct ivtv_stream *s) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci return !ivtv_use_pio(s); 398c2ecf20Sopenharmony_ci} 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic inline void ivtv_buf_sync_for_cpu(struct ivtv_stream *s, struct ivtv_buffer *buf) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci if (ivtv_use_dma(s)) 448c2ecf20Sopenharmony_ci pci_dma_sync_single_for_cpu(s->itv->pdev, buf->dma_handle, 458c2ecf20Sopenharmony_ci s->buf_size + 256, s->dma); 468c2ecf20Sopenharmony_ci} 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cistatic inline void ivtv_buf_sync_for_device(struct ivtv_stream *s, struct ivtv_buffer *buf) 498c2ecf20Sopenharmony_ci{ 508c2ecf20Sopenharmony_ci if (ivtv_use_dma(s)) 518c2ecf20Sopenharmony_ci pci_dma_sync_single_for_device(s->itv->pdev, buf->dma_handle, 528c2ecf20Sopenharmony_ci s->buf_size + 256, s->dma); 538c2ecf20Sopenharmony_ci} 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ciint ivtv_buf_copy_from_user(struct ivtv_stream *s, struct ivtv_buffer *buf, const char __user *src, int copybytes); 568c2ecf20Sopenharmony_civoid ivtv_buf_swap(struct ivtv_buffer *buf); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* ivtv_queue utility functions */ 598c2ecf20Sopenharmony_civoid ivtv_queue_init(struct ivtv_queue *q); 608c2ecf20Sopenharmony_civoid ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_queue *q); 618c2ecf20Sopenharmony_cistruct ivtv_buffer *ivtv_dequeue(struct ivtv_stream *s, struct ivtv_queue *q); 628c2ecf20Sopenharmony_ciint ivtv_queue_move(struct ivtv_stream *s, struct ivtv_queue *from, struct ivtv_queue *steal, 638c2ecf20Sopenharmony_ci struct ivtv_queue *to, int needed_bytes); 648c2ecf20Sopenharmony_civoid ivtv_flush_queues(struct ivtv_stream *s); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* ivtv_stream utility functions */ 678c2ecf20Sopenharmony_ciint ivtv_stream_alloc(struct ivtv_stream *s); 688c2ecf20Sopenharmony_civoid ivtv_stream_free(struct ivtv_stream *s); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistatic inline void ivtv_stream_sync_for_cpu(struct ivtv_stream *s) 718c2ecf20Sopenharmony_ci{ 728c2ecf20Sopenharmony_ci if (ivtv_use_dma(s)) 738c2ecf20Sopenharmony_ci pci_dma_sync_single_for_cpu(s->itv->pdev, s->sg_handle, 748c2ecf20Sopenharmony_ci sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE); 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic inline void ivtv_stream_sync_for_device(struct ivtv_stream *s) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci if (ivtv_use_dma(s)) 808c2ecf20Sopenharmony_ci pci_dma_sync_single_for_device(s->itv->pdev, s->sg_handle, 818c2ecf20Sopenharmony_ci sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE); 828c2ecf20Sopenharmony_ci} 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci#endif 85