Sasha Levin | 28b24c1 | 2015-04-14 15:44:57 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * CMA DebugFS Interface |
| 3 | * |
| 4 | * Copyright (c) 2015 Sasha Levin <sasha.levin@oracle.com> |
| 5 | */ |
| 6 | |
| 7 | |
| 8 | #include <linux/debugfs.h> |
| 9 | #include <linux/cma.h> |
| 10 | |
| 11 | #include "cma.h" |
| 12 | |
| 13 | static struct dentry *cma_debugfs_root; |
| 14 | |
| 15 | static int cma_debugfs_get(void *data, u64 *val) |
| 16 | { |
| 17 | unsigned long *p = data; |
| 18 | |
| 19 | *val = *p; |
| 20 | |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | DEFINE_SIMPLE_ATTRIBUTE(cma_debugfs_fops, cma_debugfs_get, NULL, "%llu\n"); |
| 25 | |
| 26 | static void cma_debugfs_add_one(struct cma *cma, int idx) |
| 27 | { |
| 28 | struct dentry *tmp; |
| 29 | char name[16]; |
| 30 | int u32s; |
| 31 | |
| 32 | sprintf(name, "cma-%d", idx); |
| 33 | |
| 34 | tmp = debugfs_create_dir(name, cma_debugfs_root); |
| 35 | |
| 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); |
| 42 | |
| 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); |
| 45 | } |
| 46 | |
| 47 | static int __init cma_debugfs_init(void) |
| 48 | { |
| 49 | int i; |
| 50 | |
| 51 | cma_debugfs_root = debugfs_create_dir("cma", NULL); |
| 52 | if (!cma_debugfs_root) |
| 53 | return -ENOMEM; |
| 54 | |
| 55 | for (i = 0; i < cma_area_count; i++) |
| 56 | cma_debugfs_add_one(&cma_areas[i], i); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | late_initcall(cma_debugfs_init); |