mm: cma: debugfs interface
[linux/fpc-iii.git] / mm / cma_debug.c
blob3af2de6d4e5f5838bed16e77da5e5c167d932869
1 /*
2 * CMA DebugFS Interface
4 * Copyright (c) 2015 Sasha Levin <sasha.levin@oracle.com>
5 */
8 #include <linux/debugfs.h>
9 #include <linux/cma.h>
11 #include "cma.h"
13 static struct dentry *cma_debugfs_root;
15 static int cma_debugfs_get(void *data, u64 *val)
17 unsigned long *p = data;
19 *val = *p;
21 return 0;
24 DEFINE_SIMPLE_ATTRIBUTE(cma_debugfs_fops, cma_debugfs_get, NULL, "%llu\n");
26 static void cma_debugfs_add_one(struct cma *cma, int idx)
28 struct dentry *tmp;
29 char name[16];
30 int u32s;
32 sprintf(name, "cma-%d", idx);
34 tmp = debugfs_create_dir(name, cma_debugfs_root);
36 debugfs_create_file("base_pfn", S_IRUGO, tmp,
37 &cma->base_pfn, &cma_debugfs_fops);
38 debugfs_create_file("count", S_IRUGO, tmp,
39 &cma->count, &cma_debugfs_fops);
40 debugfs_create_file("order_per_bit", S_IRUGO, tmp,
41 &cma->order_per_bit, &cma_debugfs_fops);
43 u32s = DIV_ROUND_UP(cma_bitmap_maxno(cma), BITS_PER_BYTE * sizeof(u32));
44 debugfs_create_u32_array("bitmap", S_IRUGO, tmp, (u32*)cma->bitmap, u32s);
47 static int __init cma_debugfs_init(void)
49 int i;
51 cma_debugfs_root = debugfs_create_dir("cma", NULL);
52 if (!cma_debugfs_root)
53 return -ENOMEM;
55 for (i = 0; i < cma_area_count; i++)
56 cma_debugfs_add_one(&cma_areas[i], i);
58 return 0;
60 late_initcall(cma_debugfs_init);