dma.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 <linux/pci.h>
  12. #include <asm/scatterlist.h>
  13. /* struct dma_prog_region
  14. a small, physically-contiguous DMA buffer with random-access,
  15. synchronous usage characteristics
  16. */
  17. struct dma_prog_region {
  18. unsigned char *kvirt; /* kernel virtual address */
  19. struct pci_dev *dev; /* PCI device */
  20. unsigned int n_pages; /* # of kernel pages */
  21. dma_addr_t bus_addr; /* base bus address */
  22. };
  23. /* clear out all fields but do not allocate any memory */
  24. void dma_prog_region_init(struct dma_prog_region *prog);
  25. int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes, struct pci_dev *dev);
  26. void dma_prog_region_free(struct dma_prog_region *prog);
  27. static inline dma_addr_t dma_prog_region_offset_to_bus(struct dma_prog_region *prog, unsigned long offset)
  28. {
  29. return prog->bus_addr + offset;
  30. }
  31. /* struct dma_region
  32. a large, non-physically-contiguous DMA buffer with streaming,
  33. asynchronous usage characteristics
  34. */
  35. struct dma_region {
  36. unsigned char *kvirt; /* kernel virtual address */
  37. struct pci_dev *dev; /* PCI device */
  38. unsigned int n_pages; /* # of kernel pages */
  39. unsigned int n_dma_pages; /* # of IOMMU pages */
  40. struct scatterlist *sglist; /* IOMMU mapping */
  41. int direction; /* PCI_DMA_TODEVICE, etc */
  42. };
  43. /* clear out all fields but do not allocate anything */
  44. void dma_region_init(struct dma_region *dma);
  45. /* allocate the buffer and map it to the IOMMU */
  46. int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes, struct pci_dev *dev, int direction);
  47. /* unmap and free the buffer */
  48. void dma_region_free(struct dma_region *dma);
  49. /* sync the CPU's view of the buffer */
  50. void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset, unsigned long len);
  51. /* sync the IO bus' view of the buffer */
  52. void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset, unsigned long len);
  53. /* map the buffer into a user space process */
  54. int dma_region_mmap(struct dma_region *dma, struct file *file, struct vm_area_struct *vma);
  55. /* macro to index into a DMA region (or dma_prog_region) */
  56. #define dma_region_i(_dma, _type, _index) ( ((_type*) ((_dma)->kvirt)) + (_index) )
  57. /* return the DMA bus address of the byte with the given offset
  58. relative to the beginning of the dma_region */
  59. dma_addr_t dma_region_offset_to_bus(struct dma_region *dma, unsigned long offset);
  60. #endif /* IEEE1394_DMA_H */