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