dma.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * DMA region bookkeeping routines
  3. *
  4. * Copyright (C) 2002 Maas Digital LLC
  5. *
  6. * This code is licensed under the GPL. See the file COPYING in the root
  7. * directory of the kernel sources for details.
  8. */
  9. #ifndef IEEE1394_DMA_H
  10. #define IEEE1394_DMA_H
  11. #include <asm/types.h>
  12. struct pci_dev;
  13. struct scatterlist;
  14. struct vm_area_struct;
  15. /**
  16. * struct dma_prog_region - small contiguous DMA buffer
  17. * @kvirt: kernel virtual address
  18. * @dev: PCI device
  19. * @n_pages: number of kernel pages
  20. * @bus_addr: base bus address
  21. *
  22. * a small, physically contiguous DMA buffer with random-access, synchronous
  23. * usage characteristics
  24. */
  25. struct dma_prog_region {
  26. unsigned char *kvirt;
  27. struct pci_dev *dev;
  28. unsigned int n_pages;
  29. dma_addr_t bus_addr;
  30. };
  31. /* clear out all fields but do not allocate any memory */
  32. void dma_prog_region_init(struct dma_prog_region *prog);
  33. int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes,
  34. struct pci_dev *dev);
  35. void dma_prog_region_free(struct dma_prog_region *prog);
  36. static inline dma_addr_t dma_prog_region_offset_to_bus(
  37. struct dma_prog_region *prog, unsigned long offset)
  38. {
  39. return prog->bus_addr + offset;
  40. }
  41. /**
  42. * struct dma_region - large non-contiguous DMA buffer
  43. * @virt: kernel virtual address
  44. * @dev: PCI device
  45. * @n_pages: number of kernel pages
  46. * @n_dma_pages: number of IOMMU pages
  47. * @sglist: IOMMU mapping
  48. * @direction: PCI_DMA_TODEVICE, etc.
  49. *
  50. * a large, non-physically-contiguous DMA buffer with streaming, asynchronous
  51. * usage characteristics
  52. */
  53. struct dma_region {
  54. unsigned char *kvirt;
  55. struct pci_dev *dev;
  56. unsigned int n_pages;
  57. unsigned int n_dma_pages;
  58. struct scatterlist *sglist;
  59. int direction;
  60. };
  61. /* clear out all fields but do not allocate anything */
  62. void dma_region_init(struct dma_region *dma);
  63. /* allocate the buffer and map it to the IOMMU */
  64. int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes,
  65. struct pci_dev *dev, int direction);
  66. /* unmap and free the buffer */
  67. void dma_region_free(struct dma_region *dma);
  68. /* sync the CPU's view of the buffer */
  69. void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset,
  70. unsigned long len);
  71. /* sync the IO bus' view of the buffer */
  72. void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset,
  73. unsigned long len);
  74. /* map the buffer into a user space process */
  75. int dma_region_mmap(struct dma_region *dma, struct file *file,
  76. struct vm_area_struct *vma);
  77. /* macro to index into a DMA region (or dma_prog_region) */
  78. #define dma_region_i(_dma, _type, _index) \
  79. ( ((_type*) ((_dma)->kvirt)) + (_index) )
  80. /* return the DMA bus address of the byte with the given offset
  81. * relative to the beginning of the dma_region */
  82. dma_addr_t dma_region_offset_to_bus(struct dma_region *dma,
  83. unsigned long offset);
  84. #endif /* IEEE1394_DMA_H */