dma.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. void dma_region_init(struct dma_region *dma);
  62. int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes,
  63. struct pci_dev *dev, int direction);
  64. void dma_region_free(struct dma_region *dma);
  65. void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset,
  66. unsigned long len);
  67. void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset,
  68. unsigned long len);
  69. int dma_region_mmap(struct dma_region *dma, struct file *file,
  70. struct vm_area_struct *vma);
  71. dma_addr_t dma_region_offset_to_bus(struct dma_region *dma,
  72. unsigned long offset);
  73. /**
  74. * dma_region_i - macro to index into a DMA region (or dma_prog_region)
  75. */
  76. #define dma_region_i(_dma, _type, _index) \
  77. ( ((_type*) ((_dma)->kvirt)) + (_index) )
  78. #endif /* IEEE1394_DMA_H */