dma.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 file;
  13. struct pci_dev;
  14. struct scatterlist;
  15. struct vm_area_struct;
  16. /**
  17. * struct dma_prog_region - small contiguous DMA buffer
  18. * @kvirt: kernel virtual address
  19. * @dev: PCI device
  20. * @n_pages: number of kernel pages
  21. * @bus_addr: base bus address
  22. *
  23. * a small, physically contiguous DMA buffer with random-access, synchronous
  24. * usage characteristics
  25. */
  26. struct dma_prog_region {
  27. unsigned char *kvirt;
  28. struct pci_dev *dev;
  29. unsigned int n_pages;
  30. dma_addr_t bus_addr;
  31. };
  32. /* clear out all fields but do not allocate any memory */
  33. void dma_prog_region_init(struct dma_prog_region *prog);
  34. int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes,
  35. struct pci_dev *dev);
  36. void dma_prog_region_free(struct dma_prog_region *prog);
  37. static inline dma_addr_t dma_prog_region_offset_to_bus(
  38. struct dma_prog_region *prog, unsigned long offset)
  39. {
  40. return prog->bus_addr + offset;
  41. }
  42. /**
  43. * struct dma_region - large non-contiguous DMA buffer
  44. * @virt: kernel virtual address
  45. * @dev: PCI device
  46. * @n_pages: number of kernel pages
  47. * @n_dma_pages: number of IOMMU pages
  48. * @sglist: IOMMU mapping
  49. * @direction: PCI_DMA_TODEVICE, etc.
  50. *
  51. * a large, non-physically-contiguous DMA buffer with streaming, asynchronous
  52. * usage characteristics
  53. */
  54. struct dma_region {
  55. unsigned char *kvirt;
  56. struct pci_dev *dev;
  57. unsigned int n_pages;
  58. unsigned int n_dma_pages;
  59. struct scatterlist *sglist;
  60. int direction;
  61. };
  62. void dma_region_init(struct dma_region *dma);
  63. int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes,
  64. struct pci_dev *dev, int direction);
  65. void dma_region_free(struct dma_region *dma);
  66. void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset,
  67. unsigned long len);
  68. void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset,
  69. unsigned long len);
  70. int dma_region_mmap(struct dma_region *dma, struct file *file,
  71. struct vm_area_struct *vma);
  72. dma_addr_t dma_region_offset_to_bus(struct dma_region *dma,
  73. unsigned long offset);
  74. /**
  75. * dma_region_i - macro to index into a DMA region (or dma_prog_region)
  76. */
  77. #define dma_region_i(_dma, _type, _index) \
  78. ( ((_type*) ((_dma)->kvirt)) + (_index) )
  79. #endif /* IEEE1394_DMA_H */