cma_debug.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * CMA DebugFS Interface
  3. *
  4. * Copyright (c) 2015 Sasha Levin <sasha.levin@oracle.com>
  5. */
  6. #include <linux/debugfs.h>
  7. #include <linux/cma.h>
  8. #include "cma.h"
  9. static struct dentry *cma_debugfs_root;
  10. static int cma_debugfs_get(void *data, u64 *val)
  11. {
  12. unsigned long *p = data;
  13. *val = *p;
  14. return 0;
  15. }
  16. DEFINE_SIMPLE_ATTRIBUTE(cma_debugfs_fops, cma_debugfs_get, NULL, "%llu\n");
  17. static void cma_debugfs_add_one(struct cma *cma, int idx)
  18. {
  19. struct dentry *tmp;
  20. char name[16];
  21. int u32s;
  22. sprintf(name, "cma-%d", idx);
  23. tmp = debugfs_create_dir(name, cma_debugfs_root);
  24. debugfs_create_file("base_pfn", S_IRUGO, tmp,
  25. &cma->base_pfn, &cma_debugfs_fops);
  26. debugfs_create_file("count", S_IRUGO, tmp,
  27. &cma->count, &cma_debugfs_fops);
  28. debugfs_create_file("order_per_bit", S_IRUGO, tmp,
  29. &cma->order_per_bit, &cma_debugfs_fops);
  30. u32s = DIV_ROUND_UP(cma_bitmap_maxno(cma), BITS_PER_BYTE * sizeof(u32));
  31. debugfs_create_u32_array("bitmap", S_IRUGO, tmp, (u32*)cma->bitmap, u32s);
  32. }
  33. static int __init cma_debugfs_init(void)
  34. {
  35. int i;
  36. cma_debugfs_root = debugfs_create_dir("cma", NULL);
  37. if (!cma_debugfs_root)
  38. return -ENOMEM;
  39. for (i = 0; i < cma_area_count; i++)
  40. cma_debugfs_add_one(&cma_areas[i], i);
  41. return 0;
  42. }
  43. late_initcall(cma_debugfs_init);