dma.h 2.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * DMA region bookkeeping routines
 *
 * Copyright (C) 2002 Maas Digital LLC
 *
 * This code is licensed under the GPL.  See the file COPYING in the root
 * directory of the kernel sources for details.
 */

#ifndef IEEE1394_DMA_H
#define IEEE1394_DMA_H

13 14 15 16 17
#include <asm/types.h>

struct pci_dev;
struct scatterlist;
struct vm_area_struct;
L
Linus Torvalds 已提交
18

19 20 21 22 23 24 25 26 27 28
/**
 * struct dma_prog_region - small contiguous DMA buffer
 * @kvirt:    kernel virtual address
 * @dev:      PCI device
 * @n_pages:  number of kernel pages
 * @bus_addr: base bus address
 *
 * a small, physically contiguous DMA buffer with random-access, synchronous
 * usage characteristics
 */
L
Linus Torvalds 已提交
29
struct dma_prog_region {
30 31 32 33
	unsigned char *kvirt;
	struct pci_dev *dev;
	unsigned int n_pages;
	dma_addr_t bus_addr;
L
Linus Torvalds 已提交
34 35 36 37
};

/* clear out all fields but do not allocate any memory */
void dma_prog_region_init(struct dma_prog_region *prog);
38 39
int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes,
			  struct pci_dev *dev);
L
Linus Torvalds 已提交
40 41
void dma_prog_region_free(struct dma_prog_region *prog);

42 43
static inline dma_addr_t dma_prog_region_offset_to_bus(
		struct dma_prog_region *prog, unsigned long offset)
L
Linus Torvalds 已提交
44 45 46 47
{
	return prog->bus_addr + offset;
}

48 49 50 51 52 53 54 55 56 57 58 59
/**
 * struct dma_region - large non-contiguous DMA buffer
 * @virt:        kernel virtual address
 * @dev:         PCI device
 * @n_pages:     number of kernel pages
 * @n_dma_pages: number of IOMMU pages
 * @sglist:      IOMMU mapping
 * @direction:   PCI_DMA_TODEVICE, etc.
 *
 * a large, non-physically-contiguous DMA buffer with streaming, asynchronous
 * usage characteristics
 */
L
Linus Torvalds 已提交
60
struct dma_region {
61 62 63 64 65 66
	unsigned char *kvirt;
	struct pci_dev *dev;
	unsigned int n_pages;
	unsigned int n_dma_pages;
	struct scatterlist *sglist;
	int direction;
L
Linus Torvalds 已提交
67 68 69 70 71 72
};

/* clear out all fields but do not allocate anything */
void dma_region_init(struct dma_region *dma);

/* allocate the buffer and map it to the IOMMU */
73 74
int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes,
		     struct pci_dev *dev, int direction);
L
Linus Torvalds 已提交
75 76 77 78 79

/* unmap and free the buffer */
void dma_region_free(struct dma_region *dma);

/* sync the CPU's view of the buffer */
80 81 82
void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset,
			     unsigned long len);

L
Linus Torvalds 已提交
83
/* sync the IO bus' view of the buffer */
84 85
void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset,
				unsigned long len);
L
Linus Torvalds 已提交
86 87

/* map the buffer into a user space process */
88 89
int  dma_region_mmap(struct dma_region *dma, struct file *file,
		     struct vm_area_struct *vma);
L
Linus Torvalds 已提交
90 91

/* macro to index into a DMA region (or dma_prog_region) */
92 93
#define dma_region_i(_dma, _type, _index) \
	( ((_type*) ((_dma)->kvirt)) + (_index) )
L
Linus Torvalds 已提交
94 95

/* return the DMA bus address of the byte with the given offset
96 97 98
 * relative to the beginning of the dma_region */
dma_addr_t dma_region_offset_to_bus(struct dma_region *dma,
				    unsigned long offset);
L
Linus Torvalds 已提交
99 100

#endif /* IEEE1394_DMA_H */