Commit 9ae27c57 authored by Russell King's avatar Russell King

[ARM] Move dma_alloc_coherent() to consistent.c

parent c0f1e790
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* DMA uncached mapping support. * DMA uncached mapping support.
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/types.h> #include <linux/module.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h> #include <linux/string.h>
...@@ -145,6 +145,7 @@ void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle, ...@@ -145,6 +145,7 @@ void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle,
struct vm_region *c; struct vm_region *c;
unsigned long order, flags; unsigned long order, flags;
void *ret = NULL; void *ret = NULL;
int res;
if (!consistent_pte) { if (!consistent_pte) {
printk(KERN_ERR "consistent_alloc: not initialised\n"); printk(KERN_ERR "consistent_alloc: not initialised\n");
...@@ -177,14 +178,19 @@ void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle, ...@@ -177,14 +178,19 @@ void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle,
if (!c) if (!c)
goto no_remap; goto no_remap;
spin_lock_irqsave(&consistent_lock, flags);
vm_region_dump(&consistent_head, "before alloc");
/* /*
* Attempt to allocate a virtual address in the * Attempt to allocate a virtual address in the
* consistent mapping region. * consistent mapping region.
*/ */
if (!vm_region_alloc(&consistent_head, c, size)) { spin_lock_irqsave(&consistent_lock, flags);
vm_region_dump(&consistent_head, "before alloc");
res = vm_region_alloc(&consistent_head, c, size);
vm_region_dump(&consistent_head, "after alloc");
spin_unlock_irqrestore(&consistent_lock, flags);
if (!res) {
pte_t *pte = consistent_pte + CONSISTENT_OFFSET(c->vm_start); pte_t *pte = consistent_pte + CONSISTENT_OFFSET(c->vm_start);
struct page *end = page + (1 << order); struct page *end = page + (1 << order);
pgprot_t prot = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | pgprot_t prot = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
...@@ -218,9 +224,6 @@ void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle, ...@@ -218,9 +224,6 @@ void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle,
ret = (void *)c->vm_start; ret = (void *)c->vm_start;
} }
vm_region_dump(&consistent_head, "after alloc");
spin_unlock_irqrestore(&consistent_lock, flags);
no_remap: no_remap:
if (ret == NULL) { if (ret == NULL) {
kfree(c); kfree(c);
...@@ -230,6 +233,22 @@ void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle, ...@@ -230,6 +233,22 @@ void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle,
return ret; return ret;
} }
/*
* Since we have the DMA mask available to us here, we could try to do
* a normal allocation, and only fall back to a "DMA" allocation if the
* resulting bus address does not satisfy the dma_mask requirements.
*/
void *
dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, int gfp)
{
if (dev == NULL || *dev->dma_mask != 0xffffffff)
gfp |= GFP_DMA;
return consistent_alloc(gfp, size, handle, 0);
}
EXPORT_SYMBOL(dma_alloc_coherent);
/* /*
* free a page as defined by the above mapping. * free a page as defined by the above mapping.
*/ */
......
...@@ -42,12 +42,12 @@ extern struct bus_type sa1111_bus_type; ...@@ -42,12 +42,12 @@ extern struct bus_type sa1111_bus_type;
/* /*
* Return whether the given device DMA address mask can be supported * Return whether the given device DMA address mask can be supported
* properly. For example, if your device can only drive the low 24-bits * properly. For example, if your device can only drive the low 24-bits
* during PCI bus mastering, then you would pass 0x00ffffff as the mask * during bus mastering, then you would pass 0x00ffffff as the mask
* to this function. * to this function.
*/ */
static inline int dma_supported(struct device *dev, u64 mask) static inline int dma_supported(struct device *dev, u64 mask)
{ {
return 1; return dev->dma_mask && *dev->dma_mask != 0;
} }
static inline int dma_set_mask(struct device *dev, u64 dma_mask) static inline int dma_set_mask(struct device *dev, u64 dma_mask)
...@@ -81,14 +81,8 @@ static inline int dma_is_consistent(dma_addr_t handle) ...@@ -81,14 +81,8 @@ static inline int dma_is_consistent(dma_addr_t handle)
* return the CPU-viewed address, and sets @handle to be the * return the CPU-viewed address, and sets @handle to be the
* device-viewed address. * device-viewed address.
*/ */
static inline void * extern void *
dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, int gfp) dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, int gfp);
{
if (dev == NULL || dmadev_is_sa1111(dev) || *dev->dma_mask != 0xffffffff)
gfp |= GFP_DMA;
return consistent_alloc(gfp, size, handle, 0);
}
/** /**
* dma_free_coherent - free memory allocated by dma_alloc_coherent * dma_free_coherent - free memory allocated by dma_alloc_coherent
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment