Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 10 | #ifndef IEEE1394_DMA_H |
| 11 | #define IEEE1394_DMA_H |
| 12 | |
Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 13 | #include <asm/types.h> |
| 14 | |
| 15 | struct pci_dev; |
| 16 | struct scatterlist; |
| 17 | struct vm_area_struct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 19 | /** |
| 20 | * struct dma_prog_region - small contiguous DMA buffer |
| 21 | * @kvirt: kernel virtual address |
| 22 | * @dev: PCI device |
| 23 | * @n_pages: number of kernel pages |
| 24 | * @bus_addr: base bus address |
| 25 | * |
| 26 | * a small, physically contiguous DMA buffer with random-access, synchronous |
| 27 | * usage characteristics |
| 28 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | struct dma_prog_region { |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 30 | unsigned char *kvirt; |
| 31 | struct pci_dev *dev; |
| 32 | unsigned int n_pages; |
| 33 | dma_addr_t bus_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | /* clear out all fields but do not allocate any memory */ |
| 37 | void dma_prog_region_init(struct dma_prog_region *prog); |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 38 | int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes, |
| 39 | struct pci_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | void dma_prog_region_free(struct dma_prog_region *prog); |
| 41 | |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 42 | static inline dma_addr_t dma_prog_region_offset_to_bus( |
| 43 | struct dma_prog_region *prog, unsigned long offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
| 45 | return prog->bus_addr + offset; |
| 46 | } |
| 47 | |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 48 | /** |
| 49 | * struct dma_region - large non-contiguous DMA buffer |
| 50 | * @virt: kernel virtual address |
| 51 | * @dev: PCI device |
| 52 | * @n_pages: number of kernel pages |
| 53 | * @n_dma_pages: number of IOMMU pages |
| 54 | * @sglist: IOMMU mapping |
| 55 | * @direction: PCI_DMA_TODEVICE, etc. |
| 56 | * |
| 57 | * a large, non-physically-contiguous DMA buffer with streaming, asynchronous |
| 58 | * usage characteristics |
| 59 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | struct dma_region { |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 61 | unsigned char *kvirt; |
| 62 | struct pci_dev *dev; |
| 63 | unsigned int n_pages; |
| 64 | unsigned int n_dma_pages; |
| 65 | struct scatterlist *sglist; |
| 66 | int direction; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /* clear out all fields but do not allocate anything */ |
| 70 | void dma_region_init(struct dma_region *dma); |
| 71 | |
| 72 | /* allocate the buffer and map it to the IOMMU */ |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 73 | int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes, |
| 74 | struct pci_dev *dev, int direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | /* unmap and free the buffer */ |
| 77 | void dma_region_free(struct dma_region *dma); |
| 78 | |
| 79 | /* sync the CPU's view of the buffer */ |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 80 | void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset, |
| 81 | unsigned long len); |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* sync the IO bus' view of the buffer */ |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 84 | void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset, |
| 85 | unsigned long len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | /* map the buffer into a user space process */ |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 88 | int dma_region_mmap(struct dma_region *dma, struct file *file, |
| 89 | struct vm_area_struct *vma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | /* macro to index into a DMA region (or dma_prog_region) */ |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 92 | #define dma_region_i(_dma, _type, _index) \ |
| 93 | ( ((_type*) ((_dma)->kvirt)) + (_index) ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | /* return the DMA bus address of the byte with the given offset |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 96 | * relative to the beginning of the dma_region */ |
| 97 | dma_addr_t dma_region_offset_to_bus(struct dma_region *dma, |
| 98 | unsigned long offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | #endif /* IEEE1394_DMA_H */ |