videobuf-dma-sg.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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, <[email protected]>
  11. *
  12. * Highly based on video-buf written originally by:
  13. * (c) 2001,02 Gerd Knorr <[email protected]>
  14. * (c) 2006 Mauro Carvalho Chehab, <[email protected]>
  15. * (c) 2006 Ted Walther and John Sokol
  16. */
  17. #ifndef _VIDEOBUF_DMA_SG_H
  18. #define _VIDEOBUF_DMA_SG_H
  19. #include <media/videobuf-core.h>
  20. /* --------------------------------------------------------------------- */
  21. /*
  22. * A small set of helper functions to manage buffers (both userland
  23. * and kernel) for DMA.
  24. *
  25. * videobuf_dma_init_*()
  26. * creates a buffer. The userland version takes a userspace
  27. * pointer + length. The kernel version just wants the size and
  28. * does memory allocation too using vmalloc_32().
  29. *
  30. * videobuf_dma_*()
  31. * see Documentation/core-api/dma-api-howto.rst, these functions to
  32. * basically the same. The map function does also build a
  33. * scatterlist for the buffer (and unmap frees it ...)
  34. *
  35. * videobuf_dma_free()
  36. * no comment ...
  37. *
  38. */
  39. struct videobuf_dmabuf {
  40. u32 magic;
  41. /* for userland buffer */
  42. int offset;
  43. size_t size;
  44. struct page **pages;
  45. /* for kernel buffers */
  46. void *vaddr;
  47. struct page **vaddr_pages;
  48. dma_addr_t *dma_addr;
  49. struct device *dev;
  50. /* for overlay buffers (pci-pci dma) */
  51. dma_addr_t bus_addr;
  52. /* common */
  53. struct scatterlist *sglist;
  54. int sglen;
  55. unsigned long 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. int videobuf_dma_free(struct videobuf_dmabuf *dma);
  74. int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
  75. struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf);
  76. void *videobuf_sg_alloc(size_t size);
  77. void videobuf_queue_sg_init(struct videobuf_queue *q,
  78. const struct videobuf_queue_ops *ops,
  79. struct device *dev,
  80. spinlock_t *irqlock,
  81. enum v4l2_buf_type type,
  82. enum v4l2_field field,
  83. unsigned int msize,
  84. void *priv,
  85. struct mutex *ext_lock);
  86. #endif /* _VIDEOBUF_DMA_SG_H */