Skip to content

Commit 25622e0

Browse files
author
Christoph Hellwig
committed
nios2: use generic dma_noncoherent_ops
Switch to the generic noncoherent direct mapping implementation. Signed-off-by: Christoph Hellwig <[email protected]> Acked-by: Ley Foon Tan <[email protected]> Tested-by: Ley Foon Tan <[email protected]>
1 parent 7d63fb3 commit 25622e0

File tree

4 files changed

+17
-146
lines changed

4 files changed

+17
-146
lines changed

arch/nios2/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# SPDX-License-Identifier: GPL-2.0
22
config NIOS2
33
def_bool y
4+
select ARCH_HAS_SYNC_DMA_FOR_CPU
5+
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
6+
select DMA_NONCOHERENT_OPS
47
select TIMER_OF
58
select GENERIC_ATOMIC64
69
select GENERIC_CLOCKEVENTS

arch/nios2/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ generic-y += current.h
99
generic-y += device.h
1010
generic-y += div64.h
1111
generic-y += dma.h
12+
generic-y += dma-mapping.h
1213
generic-y += emergency-restart.h
1314
generic-y += exec.h
1415
generic-y += extable.h

arch/nios2/include/asm/dma-mapping.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

arch/nios2/mm/dma-mapping.c

Lines changed: 13 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212

1313
#include <linux/types.h>
1414
#include <linux/mm.h>
15-
#include <linux/export.h>
1615
#include <linux/string.h>
17-
#include <linux/scatterlist.h>
1816
#include <linux/dma-mapping.h>
1917
#include <linux/io.h>
2018
#include <linux/cache.h>
2119
#include <asm/cacheflush.h>
2220

23-
static inline void __dma_sync_for_device(void *vaddr, size_t size,
24-
enum dma_data_direction direction)
21+
void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
22+
size_t size, enum dma_data_direction dir)
2523
{
26-
switch (direction) {
24+
void *vaddr = phys_to_virt(paddr);
25+
26+
switch (dir) {
2727
case DMA_FROM_DEVICE:
2828
invalidate_dcache_range((unsigned long)vaddr,
2929
(unsigned long)(vaddr + size));
@@ -42,10 +42,12 @@ static inline void __dma_sync_for_device(void *vaddr, size_t size,
4242
}
4343
}
4444

45-
static inline void __dma_sync_for_cpu(void *vaddr, size_t size,
46-
enum dma_data_direction direction)
45+
void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
46+
size_t size, enum dma_data_direction dir)
4747
{
48-
switch (direction) {
48+
void *vaddr = phys_to_virt(paddr);
49+
50+
switch (dir) {
4951
case DMA_BIDIRECTIONAL:
5052
case DMA_FROM_DEVICE:
5153
invalidate_dcache_range((unsigned long)vaddr,
@@ -58,8 +60,8 @@ static inline void __dma_sync_for_cpu(void *vaddr, size_t size,
5860
}
5961
}
6062

61-
static void *nios2_dma_alloc(struct device *dev, size_t size,
62-
dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)
63+
void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
64+
gfp_t gfp, unsigned long attrs)
6365
{
6466
void *ret;
6567

@@ -80,125 +82,10 @@ static void *nios2_dma_alloc(struct device *dev, size_t size,
8082
return ret;
8183
}
8284

83-
static void nios2_dma_free(struct device *dev, size_t size, void *vaddr,
85+
void arch_dma_free(struct device *dev, size_t size, void *vaddr,
8486
dma_addr_t dma_handle, unsigned long attrs)
8587
{
8688
unsigned long addr = (unsigned long) CAC_ADDR((unsigned long) vaddr);
8789

8890
free_pages(addr, get_order(size));
8991
}
90-
91-
static int nios2_dma_map_sg(struct device *dev, struct scatterlist *sg,
92-
int nents, enum dma_data_direction direction,
93-
unsigned long attrs)
94-
{
95-
int i;
96-
97-
for_each_sg(sg, sg, nents, i) {
98-
void *addr = sg_virt(sg);
99-
100-
if (!addr)
101-
continue;
102-
103-
sg->dma_address = sg_phys(sg);
104-
105-
if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
106-
continue;
107-
108-
__dma_sync_for_device(addr, sg->length, direction);
109-
}
110-
111-
return nents;
112-
}
113-
114-
static dma_addr_t nios2_dma_map_page(struct device *dev, struct page *page,
115-
unsigned long offset, size_t size,
116-
enum dma_data_direction direction,
117-
unsigned long attrs)
118-
{
119-
void *addr = page_address(page) + offset;
120-
121-
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
122-
__dma_sync_for_device(addr, size, direction);
123-
124-
return page_to_phys(page) + offset;
125-
}
126-
127-
static void nios2_dma_unmap_page(struct device *dev, dma_addr_t dma_address,
128-
size_t size, enum dma_data_direction direction,
129-
unsigned long attrs)
130-
{
131-
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
132-
__dma_sync_for_cpu(phys_to_virt(dma_address), size, direction);
133-
}
134-
135-
static void nios2_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
136-
int nhwentries, enum dma_data_direction direction,
137-
unsigned long attrs)
138-
{
139-
void *addr;
140-
int i;
141-
142-
if (direction == DMA_TO_DEVICE)
143-
return;
144-
145-
if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
146-
return;
147-
148-
for_each_sg(sg, sg, nhwentries, i) {
149-
addr = sg_virt(sg);
150-
if (addr)
151-
__dma_sync_for_cpu(addr, sg->length, direction);
152-
}
153-
}
154-
155-
static void nios2_dma_sync_single_for_cpu(struct device *dev,
156-
dma_addr_t dma_handle, size_t size,
157-
enum dma_data_direction direction)
158-
{
159-
__dma_sync_for_cpu(phys_to_virt(dma_handle), size, direction);
160-
}
161-
162-
static void nios2_dma_sync_single_for_device(struct device *dev,
163-
dma_addr_t dma_handle, size_t size,
164-
enum dma_data_direction direction)
165-
{
166-
__dma_sync_for_device(phys_to_virt(dma_handle), size, direction);
167-
}
168-
169-
static void nios2_dma_sync_sg_for_cpu(struct device *dev,
170-
struct scatterlist *sg, int nelems,
171-
enum dma_data_direction direction)
172-
{
173-
int i;
174-
175-
/* Make sure that gcc doesn't leave the empty loop body. */
176-
for_each_sg(sg, sg, nelems, i)
177-
__dma_sync_for_cpu(sg_virt(sg), sg->length, direction);
178-
}
179-
180-
static void nios2_dma_sync_sg_for_device(struct device *dev,
181-
struct scatterlist *sg, int nelems,
182-
enum dma_data_direction direction)
183-
{
184-
int i;
185-
186-
/* Make sure that gcc doesn't leave the empty loop body. */
187-
for_each_sg(sg, sg, nelems, i)
188-
__dma_sync_for_device(sg_virt(sg), sg->length, direction);
189-
190-
}
191-
192-
const struct dma_map_ops nios2_dma_ops = {
193-
.alloc = nios2_dma_alloc,
194-
.free = nios2_dma_free,
195-
.map_page = nios2_dma_map_page,
196-
.unmap_page = nios2_dma_unmap_page,
197-
.map_sg = nios2_dma_map_sg,
198-
.unmap_sg = nios2_dma_unmap_sg,
199-
.sync_single_for_device = nios2_dma_sync_single_for_device,
200-
.sync_single_for_cpu = nios2_dma_sync_single_for_cpu,
201-
.sync_sg_for_cpu = nios2_dma_sync_sg_for_cpu,
202-
.sync_sg_for_device = nios2_dma_sync_sg_for_device,
203-
};
204-
EXPORT_SYMBOL(nios2_dma_ops);

0 commit comments

Comments
 (0)