aboutsummaryrefslogtreecommitdiffstats
path: root/arch/frv/mb93090-mb00/pci-dma-nommu.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/frv/mb93090-mb00/pci-dma-nommu.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/frv/mb93090-mb00/pci-dma-nommu.c')
-rw-r--r--arch/frv/mb93090-mb00/pci-dma-nommu.c152
1 files changed, 152 insertions, 0 deletions
diff --git a/arch/frv/mb93090-mb00/pci-dma-nommu.c b/arch/frv/mb93090-mb00/pci-dma-nommu.c
new file mode 100644
index 000000000000..819895cf0b9e
--- /dev/null
+++ b/arch/frv/mb93090-mb00/pci-dma-nommu.c
@@ -0,0 +1,152 @@
1/* pci-dma-nommu.c: Dynamic DMA mapping support for the FRV
2 *
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Woodhouse (dwmw2@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/types.h>
13#include <linux/slab.h>
14#include <linux/dma-mapping.h>
15#include <linux/list.h>
16#include <linux/pci.h>
17#include <asm/io.h>
18
19#if 1
20#define DMA_SRAM_START dma_coherent_mem_start
21#define DMA_SRAM_END dma_coherent_mem_end
22#else // Use video RAM on Matrox
23#define DMA_SRAM_START 0xe8900000
24#define DMA_SRAM_END 0xe8a00000
25#endif
26
27struct dma_alloc_record {
28 struct list_head list;
29 unsigned long ofs;
30 unsigned long len;
31};
32
33static DEFINE_SPINLOCK(dma_alloc_lock);
34static LIST_HEAD(dma_alloc_list);
35
36void *dma_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, int gfp)
37{
38 struct dma_alloc_record *new;
39 struct list_head *this = &dma_alloc_list;
40 unsigned long flags;
41 unsigned long start = DMA_SRAM_START;
42 unsigned long end;
43
44 if (!DMA_SRAM_START) {
45 printk("%s called without any DMA area reserved!\n", __func__);
46 return NULL;
47 }
48
49 new = kmalloc(sizeof (*new), GFP_ATOMIC);
50 if (!new)
51 return NULL;
52
53 /* Round up to a reasonable alignment */
54 new->len = (size + 31) & ~31;
55
56 spin_lock_irqsave(&dma_alloc_lock, flags);
57
58 list_for_each (this, &dma_alloc_list) {
59 struct dma_alloc_record *this_r = list_entry(this, struct dma_alloc_record, list);
60 end = this_r->ofs;
61
62 if (end - start >= size)
63 goto gotone;
64
65 start = this_r->ofs + this_r->len;
66 }
67 /* Reached end of list. */
68 end = DMA_SRAM_END;
69 this = &dma_alloc_list;
70
71 if (end - start >= size) {
72 gotone:
73 new->ofs = start;
74 list_add_tail(&new->list, this);
75 spin_unlock_irqrestore(&dma_alloc_lock, flags);
76
77 *dma_handle = start;
78 return (void *)start;
79 }
80
81 kfree(new);
82 spin_unlock_irqrestore(&dma_alloc_lock, flags);
83 return NULL;
84}
85
86void dma_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle)
87{
88 struct dma_alloc_record *rec;
89 unsigned long flags;
90
91 spin_lock_irqsave(&dma_alloc_lock, flags);
92
93 list_for_each_entry(rec, &dma_alloc_list, list) {
94 if (rec->ofs == dma_handle) {
95 list_del(&rec->list);
96 kfree(rec);
97 spin_unlock_irqrestore(&dma_alloc_lock, flags);
98 return;
99 }
100 }
101 spin_unlock_irqrestore(&dma_alloc_lock, flags);
102 BUG();
103}
104
105/*
106 * Map a single buffer of the indicated size for DMA in streaming mode.
107 * The 32-bit bus address to use is returned.
108 *
109 * Once the device is given the dma address, the device owns this memory
110 * until either pci_unmap_single or pci_dma_sync_single is performed.
111 */
112dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
113 enum dma_data_direction direction)
114{
115 if (direction == DMA_NONE)
116 BUG();
117
118 frv_cache_wback_inv((unsigned long) ptr, (unsigned long) ptr + size);
119
120 return virt_to_bus(ptr);
121}
122
123/*
124 * Map a set of buffers described by scatterlist in streaming
125 * mode for DMA. This is the scather-gather version of the
126 * above pci_map_single interface. Here the scatter gather list
127 * elements are each tagged with the appropriate dma address
128 * and length. They are obtained via sg_dma_{address,length}(SG).
129 *
130 * NOTE: An implementation may be able to use a smaller number of
131 * DMA address/length pairs than there are SG table elements.
132 * (for example via virtual mapping capabilities)
133 * The routine returns the number of addr/length pairs actually
134 * used, at most nents.
135 *
136 * Device ownership issues as mentioned above for pci_map_single are
137 * the same here.
138 */
139int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
140 enum dma_data_direction direction)
141{
142 int i;
143
144 for (i=0; i<nents; i++)
145 frv_cache_wback_inv(sg_dma_address(&sg[i]),
146 sg_dma_address(&sg[i]) + sg_dma_len(&sg[i]));
147
148 if (direction == DMA_NONE)
149 BUG();
150
151 return nents;
152}