aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/pci-dma_32.c
diff options
context:
space:
mode:
authorGlauber Costa <gcosta@redhat.com>2008-04-08 12:20:57 -0400
committerIngo Molnar <mingo@elte.hu>2008-04-19 13:19:57 -0400
commit8e8edc6401205da3000cc3dfa76f3fd28a21d73c (patch)
tree9e5583cf141dcfe39228bdd1b77eb4c81f6b5b51 /arch/x86/kernel/pci-dma_32.c
parentfae9a0d8ca68a14da8d2351ad3e0bf42f3b29899 (diff)
x86: move dma_coherent functions to pci-dma.c
They are placed in an ifdef, since they are i386 specific the structure definition goes to dma-mapping.h. Signed-off-by: Glauber Costa <gcosta@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86/kernel/pci-dma_32.c')
-rw-r--r--arch/x86/kernel/pci-dma_32.c85
1 files changed, 0 insertions, 85 deletions
diff --git a/arch/x86/kernel/pci-dma_32.c b/arch/x86/kernel/pci-dma_32.c
index eea52df68a3b..818d95efc3cb 100644
--- a/arch/x86/kernel/pci-dma_32.c
+++ b/arch/x86/kernel/pci-dma_32.c
@@ -18,14 +18,6 @@
18dma_addr_t bad_dma_address __read_mostly = 0x0; 18dma_addr_t bad_dma_address __read_mostly = 0x0;
19EXPORT_SYMBOL(bad_dma_address); 19EXPORT_SYMBOL(bad_dma_address);
20 20
21struct dma_coherent_mem {
22 void *virt_base;
23 u32 device_base;
24 int size;
25 int flags;
26 unsigned long *bitmap;
27};
28
29void *dma_alloc_coherent(struct device *dev, size_t size, 21void *dma_alloc_coherent(struct device *dev, size_t size,
30 dma_addr_t *dma_handle, gfp_t gfp) 22 dma_addr_t *dma_handle, gfp_t gfp)
31{ 23{
@@ -76,80 +68,3 @@ void dma_free_coherent(struct device *dev, size_t size,
76 free_pages((unsigned long)vaddr, order); 68 free_pages((unsigned long)vaddr, order);
77} 69}
78EXPORT_SYMBOL(dma_free_coherent); 70EXPORT_SYMBOL(dma_free_coherent);
79
80int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
81 dma_addr_t device_addr, size_t size, int flags)
82{
83 void __iomem *mem_base = NULL;
84 int pages = size >> PAGE_SHIFT;
85 int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);
86
87 if ((flags & (DMA_MEMORY_MAP | DMA_MEMORY_IO)) == 0)
88 goto out;
89 if (!size)
90 goto out;
91 if (dev->dma_mem)
92 goto out;
93
94 /* FIXME: this routine just ignores DMA_MEMORY_INCLUDES_CHILDREN */
95
96 mem_base = ioremap(bus_addr, size);
97 if (!mem_base)
98 goto out;
99
100 dev->dma_mem = kzalloc(sizeof(struct dma_coherent_mem), GFP_KERNEL);
101 if (!dev->dma_mem)
102 goto out;
103 dev->dma_mem->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
104 if (!dev->dma_mem->bitmap)
105 goto free1_out;
106
107 dev->dma_mem->virt_base = mem_base;
108 dev->dma_mem->device_base = device_addr;
109 dev->dma_mem->size = pages;
110 dev->dma_mem->flags = flags;
111
112 if (flags & DMA_MEMORY_MAP)
113 return DMA_MEMORY_MAP;
114
115 return DMA_MEMORY_IO;
116
117 free1_out:
118 kfree(dev->dma_mem);
119 out:
120 if (mem_base)
121 iounmap(mem_base);
122 return 0;
123}
124EXPORT_SYMBOL(dma_declare_coherent_memory);
125
126void dma_release_declared_memory(struct device *dev)
127{
128 struct dma_coherent_mem *mem = dev->dma_mem;
129
130 if(!mem)
131 return;
132 dev->dma_mem = NULL;
133 iounmap(mem->virt_base);
134 kfree(mem->bitmap);
135 kfree(mem);
136}
137EXPORT_SYMBOL(dma_release_declared_memory);
138
139void *dma_mark_declared_memory_occupied(struct device *dev,
140 dma_addr_t device_addr, size_t size)
141{
142 struct dma_coherent_mem *mem = dev->dma_mem;
143 int pages = (size + (device_addr & ~PAGE_MASK) + PAGE_SIZE - 1) >> PAGE_SHIFT;
144 int pos, err;
145
146 if (!mem)
147 return ERR_PTR(-EINVAL);
148
149 pos = (device_addr - mem->device_base) >> PAGE_SHIFT;
150 err = bitmap_allocate_region(mem->bitmap, pos, get_order(pages));
151 if (err != 0)
152 return ERR_PTR(err);
153 return mem->virt_base + (pos << PAGE_SHIFT);
154}
155EXPORT_SYMBOL(dma_mark_declared_memory_occupied);