Add luci mirror repository
[librecmc/librecmc.git] / target / linux / generic / pending-4.9 / 341-MIPS-mm-remove-no-op-dma_map_ops-where-possible.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Tue, 5 Dec 2017 12:46:01 +0100
3 Subject: [PATCH] MIPS: mm: remove no-op dma_map_ops where possible
4
5 If no post-DMA flush is required, and the platform does not provide
6 plat_unmap_dma_mem(), there is no need to include unmap or sync_for_cpu
7 ops.
8
9 With this patch they are compiled out to improve icache footprint
10 on devices that handle lots of DMA traffic (especially network routers).
11
12 Signed-off-by: Felix Fietkau <nbd@nbd.name>
13 ---
14
15 --- a/arch/mips/Kconfig
16 +++ b/arch/mips/Kconfig
17 @@ -214,6 +214,7 @@ config BMIPS_GENERIC
18         select BRCMSTB_L2_IRQ
19         select IRQ_MIPS_CPU
20         select DMA_NONCOHERENT
21 +       select DMA_UNMAP_POST_FLUSH
22         select SYS_SUPPORTS_32BIT_KERNEL
23         select SYS_SUPPORTS_LITTLE_ENDIAN
24         select SYS_SUPPORTS_BIG_ENDIAN
25 @@ -339,6 +340,7 @@ config MACH_JAZZ
26         select CSRC_R4K
27         select DEFAULT_SGI_PARTITION if CPU_BIG_ENDIAN
28         select GENERIC_ISA_DMA
29 +       select DMA_UNMAP_POST_FLUSH
30         select HAVE_PCSPKR_PLATFORM
31         select IRQ_MIPS_CPU
32         select I8253
33 @@ -1129,6 +1131,9 @@ config DMA_NONCOHERENT
34         bool
35         select NEED_DMA_MAP_STATE
36  
37 +config DMA_UNMAP_POST_FLUSH
38 +       bool
39 +
40  config NEED_DMA_MAP_STATE
41         bool
42  
43 @@ -1653,6 +1658,7 @@ config CPU_R10000
44         select CPU_SUPPORTS_64BIT_KERNEL
45         select CPU_SUPPORTS_HIGHMEM
46         select CPU_SUPPORTS_HUGEPAGES
47 +       select DMA_UNMAP_POST_FLUSH
48         help
49           MIPS Technologies R10000-series processors.
50  
51 @@ -1898,9 +1904,11 @@ config SYS_HAS_CPU_MIPS32_R3_5
52         bool
53  
54  config SYS_HAS_CPU_MIPS32_R5
55 +       select DMA_UNMAP_POST_FLUSH
56         bool
57  
58  config SYS_HAS_CPU_MIPS32_R6
59 +       select DMA_UNMAP_POST_FLUSH
60         bool
61  
62  config SYS_HAS_CPU_MIPS64_R1
63 @@ -1910,6 +1918,7 @@ config SYS_HAS_CPU_MIPS64_R2
64         bool
65  
66  config SYS_HAS_CPU_MIPS64_R6
67 +       select DMA_UNMAP_POST_FLUSH
68         bool
69  
70  config SYS_HAS_CPU_R3000
71 --- a/arch/mips/mm/dma-default.c
72 +++ b/arch/mips/mm/dma-default.c
73 @@ -290,8 +290,9 @@ static inline void __dma_sync(struct pag
74         } while (left);
75  }
76  
77 -static void mips_dma_unmap_page(struct device *dev, dma_addr_t dma_addr,
78 -       size_t size, enum dma_data_direction direction, unsigned long attrs)
79 +static void __maybe_unused
80 +mips_dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size,
81 +                   enum dma_data_direction direction, unsigned long attrs)
82  {
83         if (cpu_needs_post_dma_flush(dev))
84                 __dma_sync(dma_addr_to_page(dev, dma_addr),
85 @@ -330,9 +331,10 @@ static dma_addr_t mips_dma_map_page(stru
86         return plat_map_dma_mem_page(dev, page) + offset;
87  }
88  
89 -static void mips_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
90 -       int nhwentries, enum dma_data_direction direction,
91 -       unsigned long attrs)
92 +static void __maybe_unused
93 +mips_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
94 +                 int nhwentries, enum dma_data_direction direction,
95 +                 unsigned long attrs)
96  {
97         int i;
98         struct scatterlist *sg;
99 @@ -346,8 +348,9 @@ static void mips_dma_unmap_sg(struct dev
100         }
101  }
102  
103 -static void mips_dma_sync_single_for_cpu(struct device *dev,
104 -       dma_addr_t dma_handle, size_t size, enum dma_data_direction direction)
105 +static void __maybe_unused
106 +mips_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
107 +                            size_t size, enum dma_data_direction direction)
108  {
109         if (cpu_needs_post_dma_flush(dev))
110                 __dma_sync(dma_addr_to_page(dev, dma_handle),
111 @@ -363,9 +366,9 @@ static void mips_dma_sync_single_for_dev
112                            dma_handle & ~PAGE_MASK, size, direction);
113  }
114  
115 -static void mips_dma_sync_sg_for_cpu(struct device *dev,
116 -       struct scatterlist *sglist, int nelems,
117 -       enum dma_data_direction direction)
118 +static void __maybe_unused
119 +mips_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sglist,
120 +                        int nelems, enum dma_data_direction direction)
121  {
122         int i;
123         struct scatterlist *sg;
124 @@ -415,12 +418,14 @@ static struct dma_map_ops mips_default_d
125         .free = mips_dma_free_coherent,
126         .mmap = mips_dma_mmap,
127         .map_page = mips_dma_map_page,
128 -       .unmap_page = mips_dma_unmap_page,
129         .map_sg = mips_dma_map_sg,
130 +#ifdef CONFIG_DMA_UNMAP_POST_FLUSH
131 +       .unmap_page = mips_dma_unmap_page,
132         .unmap_sg = mips_dma_unmap_sg,
133         .sync_single_for_cpu = mips_dma_sync_single_for_cpu,
134 -       .sync_single_for_device = mips_dma_sync_single_for_device,
135         .sync_sg_for_cpu = mips_dma_sync_sg_for_cpu,
136 +#endif
137 +       .sync_single_for_device = mips_dma_sync_single_for_device,
138         .sync_sg_for_device = mips_dma_sync_sg_for_device,
139         .dma_supported = mips_dma_supported
140  };