Merge branch 'for-linus' of git://git.kernel.dk/linux-block
[deliverable/linux.git] / mm / cma.c
index 68ecb7a42983a589fe4c057f109e327b352c8a0b..e7d1db5330254da4a8d265b8784d1eb645693447 100644 (file)
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -23,6 +23,7 @@
 #  define DEBUG
 #endif
 #endif
+#define CREATE_TRACE_POINTS
 
 #include <linux/memblock.h>
 #include <linux/err.h>
 #include <linux/cma.h>
 #include <linux/highmem.h>
 #include <linux/io.h>
+#include <trace/events/cma.h>
 
-struct cma {
-       unsigned long   base_pfn;
-       unsigned long   count;
-       unsigned long   *bitmap;
-       unsigned int order_per_bit; /* Order of pages represented by one bit */
-       struct mutex    lock;
-};
+#include "cma.h"
 
-static struct cma cma_areas[MAX_CMA_AREAS];
-static unsigned cma_area_count;
+struct cma cma_areas[MAX_CMA_AREAS];
+unsigned cma_area_count;
 static DEFINE_MUTEX(cma_mutex);
 
-phys_addr_t cma_get_base(struct cma *cma)
+phys_addr_t cma_get_base(const struct cma *cma)
 {
        return PFN_PHYS(cma->base_pfn);
 }
 
-unsigned long cma_get_size(struct cma *cma)
+unsigned long cma_get_size(const struct cma *cma)
 {
        return cma->count << PAGE_SHIFT;
 }
 
-static unsigned long cma_bitmap_aligned_mask(struct cma *cma, int align_order)
+static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,
+                                            int align_order)
 {
        if (align_order <= cma->order_per_bit)
                return 0;
@@ -68,7 +65,8 @@ static unsigned long cma_bitmap_aligned_mask(struct cma *cma, int align_order)
  * Find a PFN aligned to the specified order and return an offset represented in
  * order_per_bits.
  */
-static unsigned long cma_bitmap_aligned_offset(struct cma *cma, int align_order)
+static unsigned long cma_bitmap_aligned_offset(const struct cma *cma,
+                                              int align_order)
 {
        if (align_order <= cma->order_per_bit)
                return 0;
@@ -77,18 +75,14 @@ static unsigned long cma_bitmap_aligned_offset(struct cma *cma, int align_order)
                - cma->base_pfn) >> cma->order_per_bit;
 }
 
-static unsigned long cma_bitmap_maxno(struct cma *cma)
-{
-       return cma->count >> cma->order_per_bit;
-}
-
-static unsigned long cma_bitmap_pages_to_bits(struct cma *cma,
-                                               unsigned long pages)
+static unsigned long cma_bitmap_pages_to_bits(const struct cma *cma,
+                                             unsigned long pages)
 {
        return ALIGN(pages, 1UL << cma->order_per_bit) >> cma->order_per_bit;
 }
 
-static void cma_clear_bitmap(struct cma *cma, unsigned long pfn, int count)
+static void cma_clear_bitmap(struct cma *cma, unsigned long pfn,
+                            unsigned int count)
 {
        unsigned long bitmap_no, bitmap_count;
 
@@ -134,6 +128,12 @@ static int __init cma_activate_area(struct cma *cma)
        } while (--i);
 
        mutex_init(&cma->lock);
+
+#ifdef CONFIG_CMA_DEBUGFS
+       INIT_HLIST_HEAD(&cma->mem_head);
+       spin_lock_init(&cma->mem_head_lock);
+#endif
+
        return 0;
 
 err:
@@ -167,7 +167,8 @@ core_initcall(cma_init_reserved_areas);
  * This function creates custom contiguous area from already reserved memory.
  */
 int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,
-                                int order_per_bit, struct cma **res_cma)
+                                unsigned int order_per_bit,
+                                struct cma **res_cma)
 {
        struct cma *cma;
        phys_addr_t alignment;
@@ -181,7 +182,7 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,
        if (!size || !memblock_is_region_reserved(base, size))
                return -EINVAL;
 
-       /* ensure minimal alignment requied by mm core */
+       /* ensure minimal alignment required by mm core */
        alignment = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order);
 
        /* alignment should be aligned with order_per_bit */
@@ -237,7 +238,7 @@ int __init cma_declare_contiguous(phys_addr_t base,
        /*
         * high_memory isn't direct mapped memory so retrieving its physical
         * address isn't appropriate.  But it would be useful to check the
-        * physical address of the highmem boundary so it's justfiable to get
+        * physical address of the highmem boundary so it's justifiable to get
         * the physical address from it.  On x86 there is a validation check for
         * this case, so the following workaround is needed to avoid it.
         */
@@ -315,13 +316,15 @@ int __init cma_declare_contiguous(phys_addr_t base,
                 */
                if (base < highmem_start && limit > highmem_start) {
                        addr = memblock_alloc_range(size, alignment,
-                                                   highmem_start, limit);
+                                                   highmem_start, limit,
+                                                   MEMBLOCK_NONE);
                        limit = highmem_start;
                }
 
                if (!addr) {
                        addr = memblock_alloc_range(size, alignment, base,
-                                                   limit);
+                                                   limit,
+                                                   MEMBLOCK_NONE);
                        if (!addr) {
                                ret = -ENOMEM;
                                goto err;
@@ -358,7 +361,7 @@ err:
  * This function allocates part of contiguous memory on specific
  * contiguous memory area.
  */
-struct page *cma_alloc(struct cma *cma, int count, unsigned int align)
+struct page *cma_alloc(struct cma *cma, unsigned int count, unsigned int align)
 {
        unsigned long mask, offset, pfn, start = 0;
        unsigned long bitmap_maxno, bitmap_no, bitmap_count;
@@ -415,6 +418,8 @@ struct page *cma_alloc(struct cma *cma, int count, unsigned int align)
                start = bitmap_no + mask + 1;
        }
 
+       trace_cma_alloc(page ? pfn : -1UL, page, count, align);
+
        pr_debug("%s(): returned %p\n", __func__, page);
        return page;
 }
@@ -429,7 +434,7 @@ struct page *cma_alloc(struct cma *cma, int count, unsigned int align)
  * It returns false when provided pages do not belong to contiguous area and
  * true otherwise.
  */
-bool cma_release(struct cma *cma, struct page *pages, int count)
+bool cma_release(struct cma *cma, const struct page *pages, unsigned int count)
 {
        unsigned long pfn;
 
@@ -447,6 +452,7 @@ bool cma_release(struct cma *cma, struct page *pages, int count)
 
        free_contig_range(pfn, count);
        cma_clear_bitmap(cma, pfn, count);
+       trace_cma_release(pfn, pages, count);
 
        return true;
 }
This page took 0.028 seconds and 5 git commands to generate.