diff options
author | Marek Szyprowski <m.szyprowski@samsung.com> | 2012-05-16 09:48:21 -0400 |
---|---|---|
committer | Marek Szyprowski <m.szyprowski@samsung.com> | 2012-05-21 09:06:23 -0400 |
commit | 4ce63fcd919c32d22528e54dcd89506962933719 (patch) | |
tree | 648f7681a5c89209b627e8c3e899d953ed38685d /arch/arm/include | |
parent | f99d60341238fe73fc514129cd9ae4e44e1b2c47 (diff) |
ARM: dma-mapping: add support for IOMMU mapper
This patch add a complete implementation of DMA-mapping API for
devices which have IOMMU support.
This implementation tries to optimize dma address space usage by remapping
all possible physical memory chunks into a single dma address space chunk.
DMA address space is managed on top of the bitmap stored in the
dma_iommu_mapping structure stored in device->archdata. Platform setup
code has to initialize parameters of the dma address space (base address,
size, allocation precision order) with arm_iommu_create_mapping() function.
To reduce the size of the bitmap, all allocations are aligned to the
specified order of base 4 KiB pages.
dma_alloc_* functions allocate physical memory in chunks, each with
alloc_pages() function to avoid failing if the physical memory gets
fragmented. In worst case the allocated buffer is composed of 4 KiB page
chunks.
dma_map_sg() function minimizes the total number of dma address space
chunks by merging of physical memory chunks into one larger dma address
space chunk. If requested chunk (scatter list entry) boundaries
match physical page boundaries, most calls to dma_map_sg() requests will
result in creating only one chunk in dma address space.
dma_map_page() simply creates a mapping for the given page(s) in the dma
address space.
All dma functions also perform required cache operation like their
counterparts from the arm linear physical memory mapping version.
This patch contains code and fixes kindly provided by:
- Krishna Reddy <vdumpa@nvidia.com>,
- Andrzej Pietrasiewicz <andrzej.p@samsung.com>,
- Hiroshi DOYU <hdoyu@nvidia.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tested-By: Subash Patel <subash.ramaswamy@linaro.org>
Diffstat (limited to 'arch/arm/include')
-rw-r--r-- | arch/arm/include/asm/device.h | 3 | ||||
-rw-r--r-- | arch/arm/include/asm/dma-iommu.h | 34 |
2 files changed, 37 insertions, 0 deletions
diff --git a/arch/arm/include/asm/device.h b/arch/arm/include/asm/device.h index 6e2cb0ee770d..b69c0d3285f8 100644 --- a/arch/arm/include/asm/device.h +++ b/arch/arm/include/asm/device.h | |||
@@ -14,6 +14,9 @@ struct dev_archdata { | |||
14 | #ifdef CONFIG_IOMMU_API | 14 | #ifdef CONFIG_IOMMU_API |
15 | void *iommu; /* private IOMMU data */ | 15 | void *iommu; /* private IOMMU data */ |
16 | #endif | 16 | #endif |
17 | #ifdef CONFIG_ARM_DMA_USE_IOMMU | ||
18 | struct dma_iommu_mapping *mapping; | ||
19 | #endif | ||
17 | }; | 20 | }; |
18 | 21 | ||
19 | struct omap_device; | 22 | struct omap_device; |
diff --git a/arch/arm/include/asm/dma-iommu.h b/arch/arm/include/asm/dma-iommu.h new file mode 100644 index 000000000000..799b09409fad --- /dev/null +++ b/arch/arm/include/asm/dma-iommu.h | |||
@@ -0,0 +1,34 @@ | |||
1 | #ifndef ASMARM_DMA_IOMMU_H | ||
2 | #define ASMARM_DMA_IOMMU_H | ||
3 | |||
4 | #ifdef __KERNEL__ | ||
5 | |||
6 | #include <linux/mm_types.h> | ||
7 | #include <linux/scatterlist.h> | ||
8 | #include <linux/dma-debug.h> | ||
9 | #include <linux/kmemcheck.h> | ||
10 | |||
11 | struct dma_iommu_mapping { | ||
12 | /* iommu specific data */ | ||
13 | struct iommu_domain *domain; | ||
14 | |||
15 | void *bitmap; | ||
16 | size_t bits; | ||
17 | unsigned int order; | ||
18 | dma_addr_t base; | ||
19 | |||
20 | spinlock_t lock; | ||
21 | struct kref kref; | ||
22 | }; | ||
23 | |||
24 | struct dma_iommu_mapping * | ||
25 | arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size, | ||
26 | int order); | ||
27 | |||
28 | void arm_iommu_release_mapping(struct dma_iommu_mapping *mapping); | ||
29 | |||
30 | int arm_iommu_attach_device(struct device *dev, | ||
31 | struct dma_iommu_mapping *mapping); | ||
32 | |||
33 | #endif /* __KERNEL__ */ | ||
34 | #endif | ||