rk: ion: to view the CMA heap debug information through bitmap
authorCMY <cmy@rock-chips.com>
Thu, 6 Mar 2014 03:04:50 +0000 (11:04 +0800)
committerCMY <cmy@rock-chips.com>
Thu, 6 Mar 2014 03:08:26 +0000 (11:08 +0800)
drivers/staging/android/ion/rockchip/rockchip_ion.c

index 3f23567f941c0c92edb2d5d1050e631d04d3b0b5..c5152e2ffd8706a96b83dd4ff202dbf36158b5f7 100755 (executable)
@@ -21,6 +21,7 @@
 #include <linux/uaccess.h>
 #include "../ion_priv.h"
 #include <linux/dma-buf.h>
+#include <asm-generic/dma-contiguous.h>
 
 #ifdef CONFIG_OF
 #include <linux/of.h>
@@ -156,6 +157,52 @@ free_heaps:
        return ERR_PTR(ret);
 }
 
+// struct "cma" quoted from drivers/base/dma-contiguous.c
+struct cma {
+       unsigned long   base_pfn;
+       unsigned long   count;
+       unsigned long   *bitmap;
+};
+
+// struct "ion_cma_heap" quoted from drivers/staging/android/ion/ion_cma_heap.c
+struct ion_cma_heap {
+       struct ion_heap heap;
+       struct device *dev;
+};
+
+static int ion_cma_heap_debug_show(struct ion_heap *heap, struct seq_file *s,
+                                     void *unused)
+{
+
+       struct ion_cma_heap *cma_heap = container_of(heap,
+                                                       struct ion_cma_heap,
+                                                       heap);
+       struct device *dev = cma_heap->dev;
+       struct cma *cma = dev_get_cma_area(dev);
+       unsigned long bit_nr;
+       int i;
+
+       dev_dbg(dev, "%s: %p(%d,%d,%p)\n", __func__, cma, cma->base_pfn, cma->count, cma->bitmap);
+
+       bit_nr = (cma->count/sizeof(unsigned long))>>3;
+
+       for(i = (bit_nr>>3) - 1; i>= 0; i--){
+               seq_printf(s, "%.3uM> Bits[%.3d - %.3d]: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
+                               i+1, i*8 + 7, i*8,
+                               cma->bitmap[i*8 + 7],
+                               cma->bitmap[i*8 + 6],
+                               cma->bitmap[i*8 + 5],
+                               cma->bitmap[i*8 + 4],
+                               cma->bitmap[i*8 + 3],
+                               cma->bitmap[i*8 + 2],
+                               cma->bitmap[i*8 + 1],
+                               cma->bitmap[i*8]);
+       }
+       seq_printf(s, "Heap size: %luM, heap base: 0x%lx\n", (cma->count)>>8, cma->base_pfn);
+
+       return 0;
+}
+
 struct ion_client *rockchip_ion_client_create(const char *name)
 {
        return ion_client_create(idev, name);
@@ -278,6 +325,8 @@ static int rockchip_ion_probe(struct platform_device *pdev)
                        err = PTR_ERR(heaps[i]);
                        goto err;
                }
+               if (ION_HEAP_TYPE_DMA==heap_data->type)
+                       heaps[i]->debug_show = ion_cma_heap_debug_show;
                ion_device_add_heap(idev, heaps[i]);
        }
        platform_set_drvdata(pdev, idev);