blob: b0f0885c45519e1d8dfe20a4ebb945c2a52efb7c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
13#include <linux/pci.h>
14#include <asm/scatterlist.h>
15
Stefan Richtere1d118f2006-07-03 12:02:28 -040016/**
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070026struct dma_prog_region {
Stefan Richtere1d118f2006-07-03 12:02:28 -040027 unsigned char *kvirt;
28 struct pci_dev *dev;
29 unsigned int n_pages;
30 dma_addr_t bus_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031};
32
33/* clear out all fields but do not allocate any memory */
34void dma_prog_region_init(struct dma_prog_region *prog);
Stefan Richtere1d118f2006-07-03 12:02:28 -040035int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes,
36 struct pci_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037void dma_prog_region_free(struct dma_prog_region *prog);
38
Stefan Richtere1d118f2006-07-03 12:02:28 -040039static inline dma_addr_t dma_prog_region_offset_to_bus(
40 struct dma_prog_region *prog, unsigned long offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
42 return prog->bus_addr + offset;
43}
44
Stefan Richtere1d118f2006-07-03 12:02:28 -040045/**
46 * struct dma_region - large non-contiguous DMA buffer
47 * @virt: kernel virtual address
48 * @dev: PCI device
49 * @n_pages: number of kernel pages
50 * @n_dma_pages: number of IOMMU pages
51 * @sglist: IOMMU mapping
52 * @direction: PCI_DMA_TODEVICE, etc.
53 *
54 * a large, non-physically-contiguous DMA buffer with streaming, asynchronous
55 * usage characteristics
56 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057struct dma_region {
Stefan Richtere1d118f2006-07-03 12:02:28 -040058 unsigned char *kvirt;
59 struct pci_dev *dev;
60 unsigned int n_pages;
61 unsigned int n_dma_pages;
62 struct scatterlist *sglist;
63 int direction;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064};
65
66/* clear out all fields but do not allocate anything */
67void dma_region_init(struct dma_region *dma);
68
69/* allocate the buffer and map it to the IOMMU */
Stefan Richtere1d118f2006-07-03 12:02:28 -040070int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes,
71 struct pci_dev *dev, int direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73/* unmap and free the buffer */
74void dma_region_free(struct dma_region *dma);
75
76/* sync the CPU's view of the buffer */
Stefan Richtere1d118f2006-07-03 12:02:28 -040077void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset,
78 unsigned long len);
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080/* sync the IO bus' view of the buffer */
Stefan Richtere1d118f2006-07-03 12:02:28 -040081void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset,
82 unsigned long len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84/* map the buffer into a user space process */
Stefan Richtere1d118f2006-07-03 12:02:28 -040085int dma_region_mmap(struct dma_region *dma, struct file *file,
86 struct vm_area_struct *vma);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88/* macro to index into a DMA region (or dma_prog_region) */
Stefan Richtere1d118f2006-07-03 12:02:28 -040089#define dma_region_i(_dma, _type, _index) \
90 ( ((_type*) ((_dma)->kvirt)) + (_index) )
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92/* return the DMA bus address of the byte with the given offset
Stefan Richtere1d118f2006-07-03 12:02:28 -040093 * relative to the beginning of the dma_region */
94dma_addr_t dma_region_offset_to_bus(struct dma_region *dma,
95 unsigned long offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97#endif /* IEEE1394_DMA_H */