2 * CMA DebugFS Interface
4 * Copyright (c) 2015 Sasha Levin <sasha.levin@oracle.com>
8 #include <linux/debugfs.h>
10 #include <linux/list.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
17 struct hlist_node node;
22 static struct dentry *cma_debugfs_root;
24 static int cma_debugfs_get(void *data, u64 *val)
26 unsigned long *p = data;
33 DEFINE_SIMPLE_ATTRIBUTE(cma_debugfs_fops, cma_debugfs_get, NULL, "%llu\n");
35 static void cma_add_to_cma_mem_list(struct cma *cma, struct cma_mem *mem)
37 spin_lock(&cma->mem_head_lock);
38 hlist_add_head(&mem->node, &cma->mem_head);
39 spin_unlock(&cma->mem_head_lock);
42 static int cma_alloc_mem(struct cma *cma, int count)
47 mem = kzalloc(sizeof(*mem), GFP_KERNEL);
51 p = cma_alloc(cma, count, CONFIG_CMA_ALIGNMENT);
60 cma_add_to_cma_mem_list(cma, mem);
65 static int cma_alloc_write(void *data, u64 val)
68 struct cma *cma = data;
70 return cma_alloc_mem(cma, pages);
73 DEFINE_SIMPLE_ATTRIBUTE(cma_alloc_fops, NULL, cma_alloc_write, "%llu\n");
75 static void cma_debugfs_add_one(struct cma *cma, int idx)
81 sprintf(name, "cma-%d", idx);
83 tmp = debugfs_create_dir(name, cma_debugfs_root);
85 debugfs_create_file("alloc", S_IWUSR, cma_debugfs_root, cma,
88 debugfs_create_file("base_pfn", S_IRUGO, tmp,
89 &cma->base_pfn, &cma_debugfs_fops);
90 debugfs_create_file("count", S_IRUGO, tmp,
91 &cma->count, &cma_debugfs_fops);
92 debugfs_create_file("order_per_bit", S_IRUGO, tmp,
93 &cma->order_per_bit, &cma_debugfs_fops);
95 u32s = DIV_ROUND_UP(cma_bitmap_maxno(cma), BITS_PER_BYTE * sizeof(u32));
96 debugfs_create_u32_array("bitmap", S_IRUGO, tmp, (u32*)cma->bitmap, u32s);
99 static int __init cma_debugfs_init(void)
103 cma_debugfs_root = debugfs_create_dir("cma", NULL);
104 if (!cma_debugfs_root)
107 for (i = 0; i < cma_area_count; i++)
108 cma_debugfs_add_one(&cma_areas[i], i);
112 late_initcall(cma_debugfs_init);