videobuf-dma-sg.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #include <media/videobuf-core.h>
  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/DMA-API-HOWTO.txt, 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. struct videobuf_dmabuf {
  43. u32 magic;
  44. /* for userland buffer */
  45. int offset;
  46. size_t size;
  47. struct page **pages;
  48. /* for kernel buffers */
  49. void *vaddr;
  50. /* for overlay buffers (pci-pci dma) */
  51. dma_addr_t bus_addr;
  52. /* common */
  53. struct scatterlist *sglist;
  54. int sglen;
  55. int nr_pages;
  56. int direction;
  57. };
  58. struct videobuf_dma_sg_memory {
  59. u32 magic;
  60. /* for mmap'ed buffers */
  61. struct videobuf_dmabuf dma;
  62. };
  63. /*
  64. * Scatter-gather DMA buffer API.
  65. *
  66. * These functions provide a simple way to create a page list and a
  67. * scatter-gather list from a kernel, userspace of physical address and map the
  68. * memory for DMA operation.
  69. *
  70. * Despite the name, this is totally unrelated to videobuf, except that
  71. * videobuf-dma-sg uses the same API internally.
  72. */
  73. void videobuf_dma_init(struct videobuf_dmabuf *dma);
  74. int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
  75. unsigned long data, unsigned long size);
  76. int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
  77. int nr_pages);
  78. int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
  79. dma_addr_t addr, int nr_pages);
  80. int videobuf_dma_free(struct videobuf_dmabuf *dma);
  81. int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma);
  82. int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
  83. struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf);
  84. void *videobuf_sg_alloc(size_t size);
  85. void videobuf_queue_sg_init(struct videobuf_queue *q,
  86. const struct videobuf_queue_ops *ops,
  87. struct device *dev,
  88. spinlock_t *irqlock,
  89. enum v4l2_buf_type type,
  90. enum v4l2_field field,
  91. unsigned int msize,
  92. void *priv,
  93. struct mutex *ext_lock);
  94. #endif /* _VIDEOBUF_DMA_SG_H */