aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMichal Simek <monstr@monstr.eu>2010-01-14 05:21:02 -0500
committerMichal Simek <monstr@monstr.eu>2010-03-11 07:56:29 -0500
commitccfe27d7000668b02d10fc3e06aa49e3e3603162 (patch)
treed8d624f6bd9aebf6a848f9762b0d8ed62ee2c5a6 /arch
parent522dba7134d6b2e5821d3457f7941ec34f668e6d (diff)
microblaze: Support DMA
Add DMA support for Microblaze. There are some part of this new feature: 1. Basic DMA support 2. Enable DMA debug option 3. Setup notifier Ad 1. dma-mapping come from powerpc and x86 version and it is based on generic dma-mapping-common.h Ad 2. DMA support debug features which is used in generic file. For more information please look at Documentation/DMA-API.txt Ad 3. notifier is very important to setup dma_ops. Without this part for example ll_temac driver failed because there are no setup dma operations. Signed-off-by: Michal Simek <monstr@monstr.eu>
Diffstat (limited to 'arch')
-rw-r--r--arch/microblaze/Kconfig5
-rw-r--r--arch/microblaze/include/asm/device.h4
-rw-r--r--arch/microblaze/include/asm/dma-mapping.h155
-rw-r--r--arch/microblaze/include/asm/io.h1
-rw-r--r--arch/microblaze/kernel/Makefile2
-rw-r--r--arch/microblaze/kernel/dma.c124
-rw-r--r--arch/microblaze/kernel/setup.c36
7 files changed, 322 insertions, 5 deletions
diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig
index b008168ae946..71ec04137417 100644
--- a/arch/microblaze/Kconfig
+++ b/arch/microblaze/Kconfig
@@ -14,6 +14,8 @@ config MICROBLAZE
14 select USB_ARCH_HAS_EHCI 14 select USB_ARCH_HAS_EHCI
15 select ARCH_WANT_OPTIONAL_GPIOLIB 15 select ARCH_WANT_OPTIONAL_GPIOLIB
16 select HAVE_OPROFILE 16 select HAVE_OPROFILE
17 select HAVE_DMA_ATTRS
18 select HAVE_DMA_API_DEBUG
17 select TRACING_SUPPORT 19 select TRACING_SUPPORT
18 20
19config SWAP 21config SWAP
@@ -76,9 +78,6 @@ config HAVE_LATENCYTOP_SUPPORT
76config PCI 78config PCI
77 def_bool n 79 def_bool n
78 80
79config NO_DMA
80 def_bool y
81
82config DTC 81config DTC
83 def_bool y 82 def_bool y
84 83
diff --git a/arch/microblaze/include/asm/device.h b/arch/microblaze/include/asm/device.h
index 78a038452c0f..402b46e630f6 100644
--- a/arch/microblaze/include/asm/device.h
+++ b/arch/microblaze/include/asm/device.h
@@ -14,6 +14,10 @@ struct device_node;
14struct dev_archdata { 14struct dev_archdata {
15 /* Optional pointer to an OF device node */ 15 /* Optional pointer to an OF device node */
16 struct device_node *of_node; 16 struct device_node *of_node;
17
18 /* DMA operations on that device */
19 struct dma_map_ops *dma_ops;
20 void *dma_data;
17}; 21};
18 22
19struct pdev_archdata { 23struct pdev_archdata {
diff --git a/arch/microblaze/include/asm/dma-mapping.h b/arch/microblaze/include/asm/dma-mapping.h
index d00e40099165..096fa96ee736 100644
--- a/arch/microblaze/include/asm/dma-mapping.h
+++ b/arch/microblaze/include/asm/dma-mapping.h
@@ -1 +1,154 @@
1#include <asm-generic/dma-mapping-broken.h> 1/*
2 * Implements the generic device dma API for microblaze and the pci
3 *
4 * Copyright (C) 2009-2010 Michal Simek <monstr@monstr.eu>
5 * Copyright (C) 2009-2010 PetaLogix
6 *
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
10 *
11 * This file is base on powerpc and x86 dma-mapping.h versions
12 * Copyright (C) 2004 IBM
13 */
14
15#ifndef _ASM_MICROBLAZE_DMA_MAPPING_H
16#define _ASM_MICROBLAZE_DMA_MAPPING_H
17
18/*
19 * See Documentation/PCI/PCI-DMA-mapping.txt and
20 * Documentation/DMA-API.txt for documentation.
21 */
22
23#include <linux/types.h>
24#include <linux/cache.h>
25#include <linux/mm.h>
26#include <linux/scatterlist.h>
27#include <linux/dma-debug.h>
28#include <linux/dma-attrs.h>
29#include <asm/io.h>
30#include <asm-generic/dma-coherent.h>
31
32#define DMA_ERROR_CODE (~(dma_addr_t)0x0)
33
34#define __dma_alloc_coherent(dev, gfp, size, handle) NULL
35#define __dma_free_coherent(size, addr) ((void)0)
36#define __dma_sync(addr, size, rw) ((void)0)
37#define __dma_sync_page(pg, off, sz, rw) ((void)0)
38
39static inline unsigned long device_to_mask(struct device *dev)
40{
41 if (dev->dma_mask && *dev->dma_mask)
42 return *dev->dma_mask;
43 /* Assume devices without mask can take 32 bit addresses */
44 return 0xfffffffful;
45}
46
47extern struct dma_map_ops *dma_ops;
48
49/*
50 * Available generic sets of operations
51 */
52extern struct dma_map_ops dma_direct_ops;
53
54static inline struct dma_map_ops *get_dma_ops(struct device *dev)
55{
56 /* We don't handle the NULL dev case for ISA for now. We could
57 * do it via an out of line call but it is not needed for now. The
58 * only ISA DMA device we support is the floppy and we have a hack
59 * in the floppy driver directly to get a device for us.
60 */
61 if (unlikely(!dev) || !dev->archdata.dma_ops)
62 return NULL;
63
64 return dev->archdata.dma_ops;
65}
66
67static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
68{
69 dev->archdata.dma_ops = ops;
70}
71
72static inline int dma_supported(struct device *dev, u64 mask)
73{
74 struct dma_map_ops *ops = get_dma_ops(dev);
75
76 if (unlikely(!ops))
77 return 0;
78 if (!ops->dma_supported)
79 return 1;
80 return ops->dma_supported(dev, mask);
81}
82
83#ifdef CONFIG_PCI
84/* We have our own implementation of pci_set_dma_mask() */
85#define HAVE_ARCH_PCI_SET_DMA_MASK
86
87#endif
88
89static inline int dma_set_mask(struct device *dev, u64 dma_mask)
90{
91 struct dma_map_ops *ops = get_dma_ops(dev);
92
93 if (unlikely(ops == NULL))
94 return -EIO;
95 if (ops->set_dma_mask)
96 return ops->set_dma_mask(dev, dma_mask);
97 if (!dev->dma_mask || !dma_supported(dev, dma_mask))
98 return -EIO;
99 *dev->dma_mask = dma_mask;
100 return 0;
101}
102
103#include <asm-generic/dma-mapping-common.h>
104
105static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
106{
107 struct dma_map_ops *ops = get_dma_ops(dev);
108 if (ops->mapping_error)
109 return ops->mapping_error(dev, dma_addr);
110
111 return (dma_addr == DMA_ERROR_CODE);
112}
113
114#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
115#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
116#define dma_is_consistent(d, h) (1)
117
118static inline void *dma_alloc_coherent(struct device *dev, size_t size,
119 dma_addr_t *dma_handle, gfp_t flag)
120{
121 struct dma_map_ops *ops = get_dma_ops(dev);
122 void *memory;
123
124 BUG_ON(!ops);
125
126 memory = ops->alloc_coherent(dev, size, dma_handle, flag);
127
128 debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
129 return memory;
130}
131
132static inline void dma_free_coherent(struct device *dev, size_t size,
133 void *cpu_addr, dma_addr_t dma_handle)
134{
135 struct dma_map_ops *ops = get_dma_ops(dev);
136
137 BUG_ON(!ops);
138 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
139 ops->free_coherent(dev, size, cpu_addr, dma_handle);
140}
141
142static inline int dma_get_cache_alignment(void)
143{
144 return L1_CACHE_BYTES;
145}
146
147static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
148 enum dma_data_direction direction)
149{
150 BUG_ON(direction == DMA_NONE);
151 __dma_sync(vaddr, size, (int)direction);
152}
153
154#endif /* _ASM_MICROBLAZE_DMA_MAPPING_H */
diff --git a/arch/microblaze/include/asm/io.h b/arch/microblaze/include/asm/io.h
index 267c7c779e53..9ac409ad906b 100644
--- a/arch/microblaze/include/asm/io.h
+++ b/arch/microblaze/include/asm/io.h
@@ -16,6 +16,7 @@
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/mm.h> /* Get struct page {...} */ 17#include <linux/mm.h> /* Get struct page {...} */
18 18
19#define PCI_DRAM_OFFSET 0
19 20
20#define IO_SPACE_LIMIT (0xFFFFFFFF) 21#define IO_SPACE_LIMIT (0xFFFFFFFF)
21 22
diff --git a/arch/microblaze/kernel/Makefile b/arch/microblaze/kernel/Makefile
index b07594eccf9b..e51bc1520825 100644
--- a/arch/microblaze/kernel/Makefile
+++ b/arch/microblaze/kernel/Makefile
@@ -14,7 +14,7 @@ endif
14 14
15extra-y := head.o vmlinux.lds 15extra-y := head.o vmlinux.lds
16 16
17obj-y += exceptions.o \ 17obj-y += dma.o exceptions.o \
18 hw_exception_handler.o init_task.o intc.o irq.o of_device.o \ 18 hw_exception_handler.o init_task.o intc.o irq.o of_device.o \
19 of_platform.o process.o prom.o prom_parse.o ptrace.o \ 19 of_platform.o process.o prom.o prom_parse.o ptrace.o \
20 setup.o signal.o sys_microblaze.o timer.o traps.o reset.o 20 setup.o signal.o sys_microblaze.o timer.o traps.o reset.o
diff --git a/arch/microblaze/kernel/dma.c b/arch/microblaze/kernel/dma.c
new file mode 100644
index 000000000000..300fea46737e
--- /dev/null
+++ b/arch/microblaze/kernel/dma.c
@@ -0,0 +1,124 @@
1/*
2 * Copyright (C) 2009-2010 PetaLogix
3 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corporation
4 *
5 * Provide default implementations of the DMA mapping callbacks for
6 * directly mapped busses.
7 */
8
9#include <linux/device.h>
10#include <linux/dma-mapping.h>
11#include <linux/dma-debug.h>
12#include <asm/bug.h>
13
14/*
15 * Generic direct DMA implementation
16 *
17 * This implementation supports a per-device offset that can be applied if
18 * the address at which memory is visible to devices is not 0. Platform code
19 * can set archdata.dma_data to an unsigned long holding the offset. By
20 * default the offset is PCI_DRAM_OFFSET.
21 */
22
23static unsigned long get_dma_direct_offset(struct device *dev)
24{
25 if (dev)
26 return (unsigned long)dev->archdata.dma_data;
27
28 return PCI_DRAM_OFFSET; /* FIXME Not sure if is correct */
29}
30
31void *dma_direct_alloc_coherent(struct device *dev, size_t size,
32 dma_addr_t *dma_handle, gfp_t flag)
33{
34 void *ret;
35 struct page *page;
36 int node = dev_to_node(dev);
37
38 /* ignore region specifiers */
39 flag &= ~(__GFP_HIGHMEM);
40
41 page = alloc_pages_node(node, flag, get_order(size));
42 if (page == NULL)
43 return NULL;
44 ret = page_address(page);
45 memset(ret, 0, size);
46 *dma_handle = virt_to_phys(ret) + get_dma_direct_offset(dev);
47
48 return ret;
49}
50
51void dma_direct_free_coherent(struct device *dev, size_t size,
52 void *vaddr, dma_addr_t dma_handle)
53{
54 free_pages((unsigned long)vaddr, get_order(size));
55}
56
57static int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl,
58 int nents, enum dma_data_direction direction,
59 struct dma_attrs *attrs)
60{
61 struct scatterlist *sg;
62 int i;
63
64 for_each_sg(sgl, sg, nents, i) {
65 sg->dma_address = sg_phys(sg) + get_dma_direct_offset(dev);
66 sg->dma_length = sg->length;
67 __dma_sync_page(sg_page(sg), sg->offset, sg->length, direction);
68 }
69
70 return nents;
71}
72
73static void dma_direct_unmap_sg(struct device *dev, struct scatterlist *sg,
74 int nents, enum dma_data_direction direction,
75 struct dma_attrs *attrs)
76{
77}
78
79static int dma_direct_dma_supported(struct device *dev, u64 mask)
80{
81 return 1;
82}
83
84static inline dma_addr_t dma_direct_map_page(struct device *dev,
85 struct page *page,
86 unsigned long offset,
87 size_t size,
88 enum dma_data_direction dir,
89 struct dma_attrs *attrs)
90{
91 BUG_ON(dir == DMA_NONE);
92 __dma_sync_page(page, offset, size, dir);
93 return page_to_phys(page) + offset + get_dma_direct_offset(dev);
94}
95
96static inline void dma_direct_unmap_page(struct device *dev,
97 dma_addr_t dma_address,
98 size_t size,
99 enum dma_data_direction direction,
100 struct dma_attrs *attrs)
101{
102}
103
104struct dma_map_ops dma_direct_ops = {
105 .alloc_coherent = dma_direct_alloc_coherent,
106 .free_coherent = dma_direct_free_coherent,
107 .map_sg = dma_direct_map_sg,
108 .unmap_sg = dma_direct_unmap_sg,
109 .dma_supported = dma_direct_dma_supported,
110 .map_page = dma_direct_map_page,
111 .unmap_page = dma_direct_unmap_page,
112};
113EXPORT_SYMBOL(dma_direct_ops);
114
115/* Number of entries preallocated for DMA-API debugging */
116#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
117
118static int __init dma_init(void)
119{
120 dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
121
122 return 0;
123}
124fs_initcall(dma_init);
diff --git a/arch/microblaze/kernel/setup.c b/arch/microblaze/kernel/setup.c
index bb8c4b9ccb80..bc325ac4efd3 100644
--- a/arch/microblaze/kernel/setup.c
+++ b/arch/microblaze/kernel/setup.c
@@ -23,6 +23,8 @@
23#include <linux/bug.h> 23#include <linux/bug.h>
24#include <linux/param.h> 24#include <linux/param.h>
25#include <linux/cache.h> 25#include <linux/cache.h>
26#include <linux/of_platform.h>
27#include <linux/dma-mapping.h>
26#include <asm/cacheflush.h> 28#include <asm/cacheflush.h>
27#include <asm/entry.h> 29#include <asm/entry.h>
28#include <asm/cpuinfo.h> 30#include <asm/cpuinfo.h>
@@ -188,3 +190,37 @@ static int microblaze_debugfs_init(void)
188} 190}
189arch_initcall(microblaze_debugfs_init); 191arch_initcall(microblaze_debugfs_init);
190#endif 192#endif
193
194static int dflt_bus_notify(struct notifier_block *nb,
195 unsigned long action, void *data)
196{
197 struct device *dev = data;
198
199 /* We are only intereted in device addition */
200 if (action != BUS_NOTIFY_ADD_DEVICE)
201 return 0;
202
203 set_dma_ops(dev, &dma_direct_ops);
204
205 return NOTIFY_DONE;
206}
207
208static struct notifier_block dflt_plat_bus_notifier = {
209 .notifier_call = dflt_bus_notify,
210 .priority = INT_MAX,
211};
212
213static struct notifier_block dflt_of_bus_notifier = {
214 .notifier_call = dflt_bus_notify,
215 .priority = INT_MAX,
216};
217
218static int __init setup_bus_notifier(void)
219{
220 bus_register_notifier(&platform_bus_type, &dflt_plat_bus_notifier);
221 bus_register_notifier(&of_platform_bus_type, &dflt_of_bus_notifier);
222
223 return 0;
224}
225
226arch_initcall(setup_bus_notifier);