videobuf-dma-sg.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * helper functions for PCI DMA video4linux capture buffers
  3. *
  4. * The functions expect the hardware being able to scatter gatter
  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. #include <media/videobuf-core.h>
  21. /* --------------------------------------------------------------------- */
  22. /*
  23. * Return a scatterlist for some page-aligned vmalloc()'ed memory
  24. * block (NULL on errors). Memory for the scatterlist is allocated
  25. * using kmalloc. The caller must free the memory.
  26. */
  27. struct scatterlist* videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages);
  28. /*
  29. * Return a scatterlist for a an array of userpages (NULL on errors).
  30. * Memory for the scatterlist is allocated using kmalloc. The caller
  31. * must free the memory.
  32. */
  33. struct scatterlist* videobuf_pages_to_sg(struct page **pages, int nr_pages,
  34. int offset);
  35. /* --------------------------------------------------------------------- */
  36. /*
  37. * A small set of helper functions to manage buffers (both userland
  38. * and kernel) for DMA.
  39. *
  40. * videobuf_dma_init_*()
  41. * creates a buffer. The userland version takes a userspace
  42. * pointer + length. The kernel version just wants the size and
  43. * does memory allocation too using vmalloc_32().
  44. *
  45. * videobuf_dma_*()
  46. * see Documentation/DMA-mapping.txt, these functions to
  47. * basically the same. The map function does also build a
  48. * scatterlist for the buffer (and unmap frees it ...)
  49. *
  50. * videobuf_dma_free()
  51. * no comment ...
  52. *
  53. */
  54. struct videobuf_dmabuf {
  55. u32 magic;
  56. /* for userland buffer */
  57. int offset;
  58. struct page **pages;
  59. /* for kernel buffers */
  60. void *vmalloc;
  61. /* Stores the userspace pointer to vmalloc area */
  62. void *varea;
  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 videbuf_pci_sg_memory
  72. {
  73. u32 magic;
  74. /* for mmap'ed buffers */
  75. struct videobuf_dmabuf dma;
  76. };
  77. /* FIXME: To be removed soon */
  78. typedef int (vb_map_sg_t)(void *dev, struct scatterlist *sglist, int nr_pages,
  79. int direction);
  80. /* FIXME: To be removed soon */
  81. struct videobuf_dma_sg_ops
  82. {
  83. vb_map_sg_t *vb_map_sg;
  84. vb_map_sg_t *vb_dma_sync_sg;
  85. vb_map_sg_t *vb_unmap_sg;
  86. };
  87. void videobuf_dma_init(struct videobuf_dmabuf *dma);
  88. int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
  89. unsigned long data, unsigned long size);
  90. int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
  91. int nr_pages);
  92. int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
  93. dma_addr_t addr, int nr_pages);
  94. int videobuf_dma_free(struct videobuf_dmabuf *dma);
  95. int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
  96. int videobuf_dma_sync(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
  97. int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
  98. struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf);
  99. void *videobuf_pci_alloc (size_t size);
  100. void videobuf_queue_pci_init(struct videobuf_queue* q,
  101. struct videobuf_queue_ops *ops,
  102. void *dev,
  103. spinlock_t *irqlock,
  104. enum v4l2_buf_type type,
  105. enum v4l2_field field,
  106. unsigned int msize,
  107. void *priv);
  108. /*FIXME: these variants are used only on *-alsa code, where videobuf is
  109. * used without queue
  110. */
  111. int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma);
  112. int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma);
  113. /* FIXME: temporary routine for vivi and tm6000, while lacking implementation
  114. * of videobuf-vmalloc
  115. */
  116. void videobuf_set_pci_ops (struct videobuf_queue* q,
  117. struct videobuf_dma_sg_ops *ops);