/* Helper operations - device type dependent */
struct videobuf_qtype_ops {
        u32                     magic;
       
        void *(*alloc)          (size_t size);
        void *(*vmalloc)        (struct videobuf_buffer *buf);
        int (*iolock)           (struct videobuf_queue* q,
                                 struct videobuf_buffer *vb,
                                 struct v4l2_framebuffer *fbuf);
        int (*mmap)             (struct videobuf_queue *q,
                                 unsigned int *count,
                                 unsigned int *size,
                                 enum v4l2_memory memory);
        int (*sync)             (struct videobuf_queue* q,
                                 struct videobuf_buffer *buf);
        int (*video_copy_to_user)(struct videobuf_queue *q,
                                 char __user *data,
                                 size_t count,
                                 int nonblocking);
        int (*copy_stream)      (struct videobuf_queue *q,
                                 char __user *data,
                                 size_t count,
                                 size_t pos,
                                 int vbihack,
                                 int nonblocking);
        int (*mmap_free)        (struct videobuf_queue *q);
        int (*mmap_mapper)      (struct videobuf_queue *q,
                                struct vm_area_struct *vma);
};

struct videobuf_queue {
        struct mutex               vb_lock;
        spinlock_t                 *irqlock;
        struct device              *dev;

        wait_queue_head_t          wait; /* wait if queue is empty */

        enum v4l2_buf_type         type;
        unsigned int               inputs; /* for V4L2_BUF_FLAG_INPUT */
        unsigned int               msize;
        enum v4l2_field            field;
        enum v4l2_field            last;   /* for field=V4L2_FIELD_ALTERNATE */
        struct videobuf_buffer     *bufs[VIDEO_MAX_FRAME];
        struct videobuf_queue_ops  *ops;
        struct videobuf_qtype_ops  *int_ops;

        unsigned int               streaming:1;
        unsigned int               reading:1;
        unsigned int               is_mmapped:1;

        /* capture via mmap() + ioctl(QBUF/DQBUF) */
        struct list_head           stream;

        /* capture via read() */
        unsigned int               read_off;
        struct videobuf_buffer     *read_buf;

        /* driver private data */
        void                       *priv_data;
};


/*     
 * A small set of helper functions to manage buffers (both userland
 * and kernel) for DMA.
 *     
 * videobuf_dma_init_*()
 *      creates a buffer.  The userland version takes a userspace
 *      pointer + length.  The kernel version just wants the size and
 *      does memory allocation too using vmalloc_32().
 *     
 * videobuf_dma_*()
 *      see Documentation/PCI/PCI-DMA-mapping.txt, these functions to
 *      basically the same.  The map function does also build a
 *      scatterlist for the buffer (and unmap frees it ...)
 *
 * videobuf_dma_free()            
 *      no comment ...            
 *     
 */
       
struct videobuf_dmabuf {          
        u32                 magic;
       
        /* for userland buffer */ 
        int                 offset;
        struct page         **pages;
       
        /* for kernel buffers */  
        void                *vmalloc;

        /* for overlay buffers (pci-pci dma) */
        dma_addr_t          bus_addr;

        /* common */
        struct scatterlist  *sglist;
        int                 sglen;
        int                 nr_pages;
        int                 direction;
};



struct videobuf_dma_sg_memory
{
        u32                 magic;

        /* for mmap'ed buffers */
        struct videobuf_dmabuf  dma;
};

void videobuf_dma_init(struct videobuf_dmabuf *dma);
int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
                           unsigned long data, unsigned long size);
int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
                             int nr_pages);
int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
                              dma_addr_t addr, int nr_pages);
int videobuf_dma_free(struct videobuf_dmabuf *dma);

int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
int videobuf_dma_sync(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf);

void *videobuf_sg_alloc(size_t size);

void videobuf_queue_sg_init(struct videobuf_queue* q,
                         struct videobuf_queue_ops *ops,
                         struct device *dev,
                         spinlock_t *irqlock,
                         enum v4l2_buf_type type,
                         enum v4l2_field field,
                         unsigned int msize,
                         void *priv);

        /*FIXME: these variants are used only on *-alsa code, where videobuf is
         * used without queue
         */
int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma);
int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);



Reply via email to