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

[ARM] Move dma_alloc_coherent() to consistent.c

parent c0f1e790
......@@ -10,7 +10,7 @@
* DMA uncached mapping support.
*/
#include <linux/config.h>
#include <linux/types.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/string.h>
......@@ -145,6 +145,7 @@ void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle,
struct vm_region *c;
unsigned long order, flags;
void *ret = NULL;
int res;
if (!consistent_pte) {
printk(KERN_ERR "consistent_alloc: not initialised\n");
......@@ -177,14 +178,19 @@ void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle,
if (!c)
goto no_remap;
spin_lock_irqsave(&consistent_lock, flags);
vm_region_dump(&consistent_head, "before alloc");
/*
* Attempt to allocate a virtual address in the
* 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);
struct page *end = page + (1 << order);
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,
ret = (void *)c->vm_start;
}
vm_region_dump(&consistent_head, "after alloc");
spin_unlock_irqrestore(&consistent_lock, flags);
no_remap:
if (ret == NULL) {
kfree(c);
......@@ -230,6 +233,22 @@ void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle,
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.
*/
......
......@@ -42,12 +42,12 @@ extern struct bus_type sa1111_bus_type;
/*
* Return whether the given device DMA address mask can be supported
* 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.
*/
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)
......@@ -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
* device-viewed address.
*/
static inline void *
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);
}
extern void *
dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, int gfp);
/**
* 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