]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/dma-coherent.c
[ARM] 5321/1: Kirkwood: fix typo in Makefile
[linux-2.6-omap-h63xx.git] / kernel / dma-coherent.c
index 56dff5cb0f2901a186c8b3ba59a57cdcd9135f23..f013a0c2e111b09b2045d600d3d3c9944b3ffe9a 100644 (file)
@@ -77,21 +77,35 @@ void *dma_mark_declared_memory_occupied(struct device *dev,
 {
        struct dma_coherent_mem *mem = dev->dma_mem;
        int pos, err;
-       int pages = (size + (device_addr & ~PAGE_MASK) + PAGE_SIZE - 1);
 
-       pages >>= PAGE_SHIFT;
+       size += device_addr & ~PAGE_MASK;
 
        if (!mem)
                return ERR_PTR(-EINVAL);
 
        pos = (device_addr - mem->device_base) >> PAGE_SHIFT;
-       err = bitmap_allocate_region(mem->bitmap, pos, get_order(pages));
+       err = bitmap_allocate_region(mem->bitmap, pos, get_order(size));
        if (err != 0)
                return ERR_PTR(err);
        return mem->virt_base + (pos << PAGE_SHIFT);
 }
 EXPORT_SYMBOL(dma_mark_declared_memory_occupied);
 
+/**
+ * dma_alloc_from_coherent() - try to allocate memory from the per-device coherent area
+ *
+ * @dev:       device from which we allocate memory
+ * @size:      size of requested memory area
+ * @dma_handle:        This will be filled with the correct dma handle
+ * @ret:       This pointer will be filled with the virtual address
+ *             to allocated area.
+ *
+ * This function should be only called from per-arch dma_alloc_coherent()
+ * to support allocation from per-device coherent memory pools.
+ *
+ * Returns 0 if dma_alloc_coherent should continue with allocating from
+ * generic memory areas, or !0 if dma_alloc_coherent should return @ret.
+ */
 int dma_alloc_from_coherent(struct device *dev, ssize_t size,
                                       dma_addr_t *dma_handle, void **ret)
 {
@@ -110,7 +124,21 @@ int dma_alloc_from_coherent(struct device *dev, ssize_t size,
        }
        return (mem != NULL);
 }
-
+EXPORT_SYMBOL(dma_alloc_from_coherent);
+
+/**
+ * dma_release_from_coherent() - try to free the memory allocated from per-device coherent memory pool
+ * @dev:       device from which the memory was allocated
+ * @order:     the order of pages allocated
+ * @vaddr:     virtual address of allocated pages
+ *
+ * This checks whether the memory was allocated from the per-device
+ * coherent memory pool and if so, releases that memory.
+ *
+ * Returns 1 if we correctly released the memory, or 0 if
+ * dma_release_coherent() should proceed with releasing memory from
+ * generic pools.
+ */
 int dma_release_from_coherent(struct device *dev, int order, void *vaddr)
 {
        struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL;
@@ -124,3 +152,4 @@ int dma_release_from_coherent(struct device *dev, int order, void *vaddr)
        }
        return 0;
 }
+EXPORT_SYMBOL(dma_release_from_coherent);