videobuf-dma-sg.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. * Return a scatterlist for some page-aligned vmalloc()'ed memory
  26. * block (NULL on errors). Memory for the scatterlist is allocated
  27. * using kmalloc. The caller must free the memory.
  28. */
  29. struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages);
  30. /*
  31. * Return a scatterlist for a an array of userpages (NULL on errors).
  32. * Memory for the scatterlist is allocated using kmalloc. The caller
  33. * must free the memory.
  34. */
  35. struct scatterlist *videobuf_pages_to_sg(struct page **pages, int nr_pages,
  36. int offset);
  37. /* --------------------------------------------------------------------- */
  38. /*
  39. * A small set of helper functions to manage buffers (both userland
  40. * and kernel) for DMA.
  41. *
  42. * videobuf_dma_init_*()
  43. * creates a buffer. The userland version takes a userspace
  44. * pointer + length. The kernel version just wants the size and
  45. * does memory allocation too using vmalloc_32().
  46. *
  47. * videobuf_dma_*()
  48. * see Documentation/PCI/PCI-DMA-mapping.txt, these functions to
  49. * basically the same. The map function does also build a
  50. * scatterlist for the buffer (and unmap frees it ...)
  51. *
  52. * videobuf_dma_free()
  53. * no comment ...
  54. *
  55. */
  56. struct videobuf_dmabuf {
  57. u32 magic;
  58. /* for userland buffer */
  59. int offset;
  60. struct page **pages;
  61. /* for kernel buffers */
  62. void *vmalloc;
  63. /* for overlay buffers (pci-pci dma) */
  64. dma_addr_t bus_addr;
  65. /* common */
  66. struct scatterlist *sglist;
  67. int sglen;
  68. int nr_pages;
  69. int direction;
  70. };
  71. struct videobuf_dma_sg_memory {
  72. u32 magic;
  73. /* for mmap'ed buffers */
  74. struct videobuf_dmabuf dma;
  75. };
  76. /*
  77. * Scatter-gather DMA buffer API.
  78. *
  79. * These functions provide a simple way to create a page list and a
  80. * scatter-gather list from a kernel, userspace of physical address and map the
  81. * memory for DMA operation.
  82. *
  83. * Despite the name, this is totally unrelated to videobuf, except that
  84. * videobuf-dma-sg uses the same API internally.
  85. */
  86. void videobuf_dma_init(struct videobuf_dmabuf *dma);
  87. int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
  88. unsigned long data, unsigned long size);
  89. int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
  90. int nr_pages);
  91. int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
  92. dma_addr_t addr, int nr_pages);
  93. int videobuf_dma_free(struct videobuf_dmabuf *dma);
  94. int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma);
  95. int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
  96. struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf);
  97. void *videobuf_sg_alloc(size_t size);
  98. void videobuf_queue_sg_init(struct videobuf_queue *q,
  99. const struct videobuf_queue_ops *ops,
  100. struct device *dev,
  101. spinlock_t *irqlock,
  102. enum v4l2_buf_type type,
  103. enum v4l2_field field,
  104. unsigned int msize,
  105. void *priv);
  106. #endif /* _VIDEOBUF_DMA_SG_H */