diff options
author | Ganesan Ramalingam <ganesanr@broadcom.com> | 2013-06-10 02:28:09 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2013-06-13 11:46:40 -0400 |
commit | 79f8511c83f13689913f54d2f189297c226ec064 (patch) | |
tree | 2dc7e379aa8e4284c651194ed200c9cf919afc0d | |
parent | 4954a9a211f1863e3ca3958fd56ad06e1bddc22d (diff) |
MIPS: Netlogic: SWIOTLB dma ops for 32-bit DMA
Add SWIOTLB config option and related files to Netlogic platform.
Some XLP SoC components like the SD/MMC interface cannot do DMA beyond
32-bit physical address. The SD/MMC driver can use memory outside this
range for IO, to support this we have to add bounce buffers implemented
by SWIOTLB.
Signed-off-by: Jayachandran C <jchandra@broadcom.com>
Cc: linux-mips@linux-mips.org
Cc: Ganesan Ramalingam <ganesanr@broadcom.com>
Patchwork: https://patchwork.linux-mips.org/patch/5410/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r-- | arch/mips/include/asm/netlogic/common.h | 3 | ||||
-rw-r--r-- | arch/mips/netlogic/Kconfig | 11 | ||||
-rw-r--r-- | arch/mips/netlogic/common/Makefile | 1 | ||||
-rw-r--r-- | arch/mips/netlogic/common/nlm-dma.c | 107 |
4 files changed, 122 insertions, 0 deletions
diff --git a/arch/mips/include/asm/netlogic/common.h b/arch/mips/include/asm/netlogic/common.h index aef560a51a7e..70351b95ef88 100644 --- a/arch/mips/include/asm/netlogic/common.h +++ b/arch/mips/include/asm/netlogic/common.h | |||
@@ -76,6 +76,9 @@ void nlm_node_init(int node); | |||
76 | extern struct plat_smp_ops nlm_smp_ops; | 76 | extern struct plat_smp_ops nlm_smp_ops; |
77 | extern char nlm_reset_entry[], nlm_reset_entry_end[]; | 77 | extern char nlm_reset_entry[], nlm_reset_entry_end[]; |
78 | 78 | ||
79 | /* SWIOTLB */ | ||
80 | extern struct dma_map_ops nlm_swiotlb_dma_ops; | ||
81 | |||
79 | extern unsigned int nlm_threads_per_core; | 82 | extern unsigned int nlm_threads_per_core; |
80 | extern cpumask_t nlm_cpumask; | 83 | extern cpumask_t nlm_cpumask; |
81 | 84 | ||
diff --git a/arch/mips/netlogic/Kconfig b/arch/mips/netlogic/Kconfig index e0873a31ebaa..2447bf97d35a 100644 --- a/arch/mips/netlogic/Kconfig +++ b/arch/mips/netlogic/Kconfig | |||
@@ -51,4 +51,15 @@ endif | |||
51 | config NLM_COMMON | 51 | config NLM_COMMON |
52 | bool | 52 | bool |
53 | 53 | ||
54 | config IOMMU_HELPER | ||
55 | bool | ||
56 | |||
57 | config NEED_SG_DMA_LENGTH | ||
58 | bool | ||
59 | |||
60 | config SWIOTLB | ||
61 | def_bool y | ||
62 | select NEED_SG_DMA_LENGTH | ||
63 | select IOMMU_HELPER | ||
64 | |||
54 | endif | 65 | endif |
diff --git a/arch/mips/netlogic/common/Makefile b/arch/mips/netlogic/common/Makefile index 291372a086f5..b29549741e05 100644 --- a/arch/mips/netlogic/common/Makefile +++ b/arch/mips/netlogic/common/Makefile | |||
@@ -1,3 +1,4 @@ | |||
1 | obj-y += irq.o time.o | 1 | obj-y += irq.o time.o |
2 | obj-y += nlm-dma.o | ||
2 | obj-$(CONFIG_SMP) += smp.o smpboot.o | 3 | obj-$(CONFIG_SMP) += smp.o smpboot.o |
3 | obj-$(CONFIG_EARLY_PRINTK) += earlycons.o | 4 | obj-$(CONFIG_EARLY_PRINTK) += earlycons.o |
diff --git a/arch/mips/netlogic/common/nlm-dma.c b/arch/mips/netlogic/common/nlm-dma.c new file mode 100644 index 000000000000..f3d4ae87abc7 --- /dev/null +++ b/arch/mips/netlogic/common/nlm-dma.c | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2003-2013 Broadcom Corporation | ||
3 | * All Rights Reserved | ||
4 | * | ||
5 | * This software is available to you under a choice of one of two | ||
6 | * licenses. You may choose to be licensed under the terms of the GNU | ||
7 | * General Public License (GPL) Version 2, available from the file | ||
8 | * COPYING in the main directory of this source tree, or the Broadcom | ||
9 | * license below: | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * | ||
15 | * 1. Redistributions of source code must retain the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer. | ||
17 | * 2. Redistributions in binary form must reproduce the above copyright | ||
18 | * notice, this list of conditions and the following disclaimer in | ||
19 | * the documentation and/or other materials provided with the | ||
20 | * distribution. | ||
21 | * | ||
22 | * THIS SOFTWARE IS PROVIDED BY BROADCOM ``AS IS'' AND ANY EXPRESS OR | ||
23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | * ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM OR CONTRIBUTORS BE LIABLE | ||
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
29 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
30 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
32 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | #include <linux/dma-mapping.h> | ||
35 | #include <linux/scatterlist.h> | ||
36 | #include <linux/bootmem.h> | ||
37 | #include <linux/export.h> | ||
38 | #include <linux/swiotlb.h> | ||
39 | #include <linux/types.h> | ||
40 | #include <linux/init.h> | ||
41 | #include <linux/mm.h> | ||
42 | |||
43 | #include <asm/bootinfo.h> | ||
44 | |||
45 | static char *nlm_swiotlb; | ||
46 | |||
47 | static void *nlm_dma_alloc_coherent(struct device *dev, size_t size, | ||
48 | dma_addr_t *dma_handle, gfp_t gfp, struct dma_attrs *attrs) | ||
49 | { | ||
50 | void *ret; | ||
51 | |||
52 | if (dma_alloc_from_coherent(dev, size, dma_handle, &ret)) | ||
53 | return ret; | ||
54 | |||
55 | /* ignore region specifiers */ | ||
56 | gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); | ||
57 | |||
58 | #ifdef CONFIG_ZONE_DMA32 | ||
59 | if (dev->coherent_dma_mask <= DMA_BIT_MASK(32)) | ||
60 | gfp |= __GFP_DMA32; | ||
61 | #endif | ||
62 | |||
63 | /* Don't invoke OOM killer */ | ||
64 | gfp |= __GFP_NORETRY; | ||
65 | |||
66 | return swiotlb_alloc_coherent(dev, size, dma_handle, gfp); | ||
67 | } | ||
68 | |||
69 | static void nlm_dma_free_coherent(struct device *dev, size_t size, | ||
70 | void *vaddr, dma_addr_t dma_handle, struct dma_attrs *attrs) | ||
71 | { | ||
72 | int order = get_order(size); | ||
73 | |||
74 | if (dma_release_from_coherent(dev, order, vaddr)) | ||
75 | return; | ||
76 | |||
77 | swiotlb_free_coherent(dev, size, vaddr, dma_handle); | ||
78 | } | ||
79 | |||
80 | struct dma_map_ops nlm_swiotlb_dma_ops = { | ||
81 | .alloc = nlm_dma_alloc_coherent, | ||
82 | .free = nlm_dma_free_coherent, | ||
83 | .map_page = swiotlb_map_page, | ||
84 | .unmap_page = swiotlb_unmap_page, | ||
85 | .map_sg = swiotlb_map_sg_attrs, | ||
86 | .unmap_sg = swiotlb_unmap_sg_attrs, | ||
87 | .sync_single_for_cpu = swiotlb_sync_single_for_cpu, | ||
88 | .sync_single_for_device = swiotlb_sync_single_for_device, | ||
89 | .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, | ||
90 | .sync_sg_for_device = swiotlb_sync_sg_for_device, | ||
91 | .mapping_error = swiotlb_dma_mapping_error, | ||
92 | .dma_supported = swiotlb_dma_supported | ||
93 | }; | ||
94 | |||
95 | void __init plat_swiotlb_setup(void) | ||
96 | { | ||
97 | size_t swiotlbsize; | ||
98 | unsigned long swiotlb_nslabs; | ||
99 | |||
100 | swiotlbsize = 1 << 20; /* 1 MB for now */ | ||
101 | swiotlb_nslabs = swiotlbsize >> IO_TLB_SHIFT; | ||
102 | swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE); | ||
103 | swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT; | ||
104 | |||
105 | nlm_swiotlb = alloc_bootmem_low_pages(swiotlbsize); | ||
106 | swiotlb_init_with_tbl(nlm_swiotlb, swiotlb_nslabs, 1); | ||
107 | } | ||