| 1 |
1275 |
phoenix |
/*
|
| 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 |
|
|
|
| 16 |
|
|
/* struct dma_prog_region
|
| 17 |
|
|
|
| 18 |
|
|
a small, physically-contiguous DMA buffer with random-access,
|
| 19 |
|
|
synchronous usage characteristics
|
| 20 |
|
|
*/
|
| 21 |
|
|
|
| 22 |
|
|
struct dma_prog_region {
|
| 23 |
|
|
unsigned char *kvirt; /* kernel virtual address */
|
| 24 |
|
|
struct pci_dev *dev; /* PCI device */
|
| 25 |
|
|
unsigned int n_pages; /* # of kernel pages */
|
| 26 |
|
|
dma_addr_t bus_addr; /* base bus address */
|
| 27 |
|
|
};
|
| 28 |
|
|
|
| 29 |
|
|
/* clear out all fields but do not allocate any memory */
|
| 30 |
|
|
void dma_prog_region_init(struct dma_prog_region *prog);
|
| 31 |
|
|
int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes, struct pci_dev *dev);
|
| 32 |
|
|
void dma_prog_region_free(struct dma_prog_region *prog);
|
| 33 |
|
|
|
| 34 |
|
|
static inline dma_addr_t dma_prog_region_offset_to_bus(struct dma_prog_region *prog, unsigned long offset)
|
| 35 |
|
|
{
|
| 36 |
|
|
return prog->bus_addr + offset;
|
| 37 |
|
|
}
|
| 38 |
|
|
|
| 39 |
|
|
/* struct dma_region
|
| 40 |
|
|
|
| 41 |
|
|
a large, non-physically-contiguous DMA buffer with streaming,
|
| 42 |
|
|
asynchronous usage characteristics
|
| 43 |
|
|
*/
|
| 44 |
|
|
|
| 45 |
|
|
struct dma_region {
|
| 46 |
|
|
unsigned char *kvirt; /* kernel virtual address */
|
| 47 |
|
|
struct pci_dev *dev; /* PCI device */
|
| 48 |
|
|
unsigned int n_pages; /* # of kernel pages */
|
| 49 |
|
|
unsigned int n_dma_pages; /* # of IOMMU pages */
|
| 50 |
|
|
struct scatterlist *sglist; /* IOMMU mapping */
|
| 51 |
|
|
int direction; /* PCI_DMA_TODEVICE, etc */
|
| 52 |
|
|
};
|
| 53 |
|
|
|
| 54 |
|
|
/* clear out all fields but do not allocate anything */
|
| 55 |
|
|
void dma_region_init(struct dma_region *dma);
|
| 56 |
|
|
|
| 57 |
|
|
/* allocate the buffer and map it to the IOMMU */
|
| 58 |
|
|
int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes, struct pci_dev *dev, int direction);
|
| 59 |
|
|
|
| 60 |
|
|
/* unmap and free the buffer */
|
| 61 |
|
|
void dma_region_free(struct dma_region *dma);
|
| 62 |
|
|
|
| 63 |
|
|
/* sync the IO bus' view of the buffer with the CPU's view */
|
| 64 |
|
|
void dma_region_sync(struct dma_region *dma, unsigned long offset, unsigned long len);
|
| 65 |
|
|
|
| 66 |
|
|
/* map the buffer into a user space process */
|
| 67 |
|
|
int dma_region_mmap(struct dma_region *dma, struct file *file, struct vm_area_struct *vma);
|
| 68 |
|
|
|
| 69 |
|
|
/* macro to index into a DMA region (or dma_prog_region) */
|
| 70 |
|
|
#define dma_region_i(_dma, _type, _index) ( ((_type*) ((_dma)->kvirt)) + (_index) )
|
| 71 |
|
|
|
| 72 |
|
|
/* return the DMA bus address of the byte with the given offset
|
| 73 |
|
|
relative to the beginning of the dma_region */
|
| 74 |
|
|
dma_addr_t dma_region_offset_to_bus(struct dma_region *dma, unsigned long offset);
|
| 75 |
|
|
|
| 76 |
|
|
/* round up a number of bytes to be a multiple of the PAGE_SIZE */
|
| 77 |
|
|
static inline unsigned long round_up_to_page(unsigned long len)
|
| 78 |
|
|
{
|
| 79 |
|
|
if (len % PAGE_SIZE)
|
| 80 |
|
|
len += PAGE_SIZE - (len % PAGE_SIZE);
|
| 81 |
|
|
return len;
|
| 82 |
|
|
}
|
| 83 |
|
|
|
| 84 |
|
|
#endif /* IEEE1394_DMA_H */
|