Linux Audio

Check our new training course

Loading...
v5.9
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * helper functions for SG DMA video4linux capture buffers
  4 *
  5 * The functions expect the hardware being able to scatter gather
  6 * (i.e. the buffers are not linear in physical memory, but fragmented
  7 * into PAGE_SIZE chunks).  They also assume the driver does not need
  8 * to touch the video data.
  9 *
 10 * (c) 2007 Mauro Carvalho Chehab, <mchehab@kernel.org>
 11 *
 12 * Highly based on video-buf written originally by:
 13 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
 14 * (c) 2006 Mauro Carvalho Chehab, <mchehab@kernel.org>
 15 * (c) 2006 Ted Walther and John Sokol
 
 
 
 
 16 */
 17#ifndef _VIDEOBUF_DMA_SG_H
 18#define _VIDEOBUF_DMA_SG_H
 19
 20#include <media/videobuf-core.h>
 21
 22/* --------------------------------------------------------------------- */
 23
 24/*
 25 * A small set of helper functions to manage buffers (both userland
 26 * and kernel) for DMA.
 27 *
 28 * videobuf_dma_init_*()
 29 *	creates a buffer.  The userland version takes a userspace
 30 *	pointer + length.  The kernel version just wants the size and
 31 *	does memory allocation too using vmalloc_32().
 32 *
 33 * videobuf_dma_*()
 34 *	see Documentation/core-api/dma-api-howto.rst, these functions to
 35 *	basically the same.  The map function does also build a
 36 *	scatterlist for the buffer (and unmap frees it ...)
 37 *
 38 * videobuf_dma_free()
 39 *	no comment ...
 40 *
 41 */
 42
 43struct videobuf_dmabuf {
 44	u32                 magic;
 45
 46	/* for userland buffer */
 47	int                 offset;
 48	size_t		    size;
 49	struct page         **pages;
 50
 51	/* for kernel buffers */
 52	void                *vaddr;
 53	struct page         **vaddr_pages;
 54	dma_addr_t          *dma_addr;
 55	struct device       *dev;
 56
 57	/* for overlay buffers (pci-pci dma) */
 58	dma_addr_t          bus_addr;
 59
 60	/* common */
 61	struct scatterlist  *sglist;
 62	int                 sglen;
 63	int                 nr_pages;
 64	int                 direction;
 65};
 66
 67struct videobuf_dma_sg_memory {
 68	u32                 magic;
 69
 70	/* for mmap'ed buffers */
 71	struct videobuf_dmabuf  dma;
 72};
 73
 74/*
 75 * Scatter-gather DMA buffer API.
 76 *
 77 * These functions provide a simple way to create a page list and a
 78 * scatter-gather list from a kernel, userspace of physical address and map the
 79 * memory for DMA operation.
 80 *
 81 * Despite the name, this is totally unrelated to videobuf, except that
 82 * videobuf-dma-sg uses the same API internally.
 83 */
 84int videobuf_dma_free(struct videobuf_dmabuf *dma);
 85
 86int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
 87struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf);
 88
 89void *videobuf_sg_alloc(size_t size);
 90
 91void videobuf_queue_sg_init(struct videobuf_queue *q,
 92			 const struct videobuf_queue_ops *ops,
 93			 struct device *dev,
 94			 spinlock_t *irqlock,
 95			 enum v4l2_buf_type type,
 96			 enum v4l2_field field,
 97			 unsigned int msize,
 98			 void *priv,
 99			 struct mutex *ext_lock);
100
101#endif /* _VIDEOBUF_DMA_SG_H */
102
v4.6
 
  1/*
  2 * helper functions for SG DMA video4linux capture buffers
  3 *
  4 * The functions expect the hardware being able to scatter gather
  5 * (i.e. the buffers are not linear in physical memory, but fragmented
  6 * into PAGE_SIZE chunks).  They also assume the driver does not need
  7 * to touch the video data.
  8 *
  9 * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
 10 *
 11 * Highly based on video-buf written originally by:
 12 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
 13 * (c) 2006 Mauro Carvalho Chehab, <mchehab@infradead.org>
 14 * (c) 2006 Ted Walther and John Sokol
 15 *
 16 * This program is free software; you can redistribute it and/or modify
 17 * it under the terms of the GNU General Public License as published by
 18 * the Free Software Foundation; either version 2
 19 */
 20#ifndef _VIDEOBUF_DMA_SG_H
 21#define _VIDEOBUF_DMA_SG_H
 22
 23#include <media/videobuf-core.h>
 24
 25/* --------------------------------------------------------------------- */
 26
 27/*
 28 * A small set of helper functions to manage buffers (both userland
 29 * and kernel) for DMA.
 30 *
 31 * videobuf_dma_init_*()
 32 *	creates a buffer.  The userland version takes a userspace
 33 *	pointer + length.  The kernel version just wants the size and
 34 *	does memory allocation too using vmalloc_32().
 35 *
 36 * videobuf_dma_*()
 37 *	see Documentation/DMA-API-HOWTO.txt, these functions to
 38 *	basically the same.  The map function does also build a
 39 *	scatterlist for the buffer (and unmap frees it ...)
 40 *
 41 * videobuf_dma_free()
 42 *	no comment ...
 43 *
 44 */
 45
 46struct videobuf_dmabuf {
 47	u32                 magic;
 48
 49	/* for userland buffer */
 50	int                 offset;
 51	size_t		    size;
 52	struct page         **pages;
 53
 54	/* for kernel buffers */
 55	void                *vaddr;
 56	struct page         **vaddr_pages;
 57	dma_addr_t          *dma_addr;
 58	struct device       *dev;
 59
 60	/* for overlay buffers (pci-pci dma) */
 61	dma_addr_t          bus_addr;
 62
 63	/* common */
 64	struct scatterlist  *sglist;
 65	int                 sglen;
 66	int                 nr_pages;
 67	int                 direction;
 68};
 69
 70struct videobuf_dma_sg_memory {
 71	u32                 magic;
 72
 73	/* for mmap'ed buffers */
 74	struct videobuf_dmabuf  dma;
 75};
 76
 77/*
 78 * Scatter-gather DMA buffer API.
 79 *
 80 * These functions provide a simple way to create a page list and a
 81 * scatter-gather list from a kernel, userspace of physical address and map the
 82 * memory for DMA operation.
 83 *
 84 * Despite the name, this is totally unrelated to videobuf, except that
 85 * videobuf-dma-sg uses the same API internally.
 86 */
 87int videobuf_dma_free(struct videobuf_dmabuf *dma);
 88
 89int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
 90struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf);
 91
 92void *videobuf_sg_alloc(size_t size);
 93
 94void videobuf_queue_sg_init(struct videobuf_queue *q,
 95			 const struct videobuf_queue_ops *ops,
 96			 struct device *dev,
 97			 spinlock_t *irqlock,
 98			 enum v4l2_buf_type type,
 99			 enum v4l2_field field,
100			 unsigned int msize,
101			 void *priv,
102			 struct mutex *ext_lock);
103
104#endif /* _VIDEOBUF_DMA_SG_H */
105