smem_debug.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* arch/arm/mach-msm/smem_debug.c
  2. *
  3. * Copyright (C) 2007 Google, Inc.
  4. * Copyright (c) 2009-2013,2016-2017 The Linux Foundation. All rights reserved.
  5. * Author: Brian Swetland <swetland@google.com>
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #include <linux/debugfs.h>
  18. #include <linux/list.h>
  19. #include <linux/ctype.h>
  20. #include <linux/jiffies.h>
  21. #include <soc/qcom/smem.h>
  22. #include "smem_private.h"
  23. #if defined(CONFIG_DEBUG_FS)
  24. #define SZ_SMEM_ALLOCATION_TABLE 8192
  25. static void debug_read_mem(struct seq_file *s)
  26. {
  27. unsigned int n;
  28. struct smem_heap_info *heap_info;
  29. struct smem_heap_entry *toc;
  30. heap_info = smem_find(SMEM_HEAP_INFO, sizeof(struct smem_heap_info),
  31. 0,
  32. SMEM_ANY_HOST_FLAG);
  33. if (!heap_info) {
  34. seq_puts(s, "SMEM_HEAP_INFO is NULL\n");
  35. return;
  36. }
  37. toc = smem_find(SMEM_ALLOCATION_TABLE, SZ_SMEM_ALLOCATION_TABLE,
  38. 0, SMEM_ANY_HOST_FLAG);
  39. if (!toc) {
  40. seq_puts(s, "SMEM_ALLOCATION_TABLE is NULL\n");
  41. return;
  42. }
  43. seq_printf(s, "heap: init=%d free=%d remain=%d\n",
  44. heap_info->initialized,
  45. heap_info->free_offset,
  46. heap_info->heap_remaining);
  47. for (n = 0; n < smem_max_items; n++) {
  48. if (toc[n].allocated == 0)
  49. continue;
  50. seq_printf(s, "%04d: offset %08x size %08x\n",
  51. n, toc[n].offset, toc[n].size);
  52. }
  53. }
  54. static void debug_read_smem_version(struct seq_file *s)
  55. {
  56. uint32_t n, version;
  57. for (n = 0; n < 32; n++) {
  58. version = smem_get_version(n);
  59. seq_printf(s, "entry %d:%x smem = %d proc_comm = %d\n",
  60. n, version, version >> 16, version & 0xffff);
  61. }
  62. }
  63. static void debug_read_build_id(struct seq_file *s)
  64. {
  65. unsigned int size;
  66. void *data;
  67. data = smem_get_entry(SMEM_HW_SW_BUILD_ID, &size, 0,
  68. SMEM_ANY_HOST_FLAG);
  69. if (!data)
  70. return;
  71. seq_write(s, data, size);
  72. }
  73. static int debugfs_show(struct seq_file *s, void *data)
  74. {
  75. void (*show)(struct seq_file *) = s->private;
  76. show(s);
  77. return 0;
  78. }
  79. static int debug_open(struct inode *inode, struct file *file)
  80. {
  81. return single_open(file, debugfs_show, inode->i_private);
  82. }
  83. static const struct file_operations debug_ops = {
  84. .open = debug_open,
  85. .release = single_release,
  86. .read = seq_read,
  87. .llseek = seq_lseek,
  88. };
  89. static void debug_create(const char *name, umode_t mode,
  90. struct dentry *dent,
  91. void (*show)(struct seq_file *))
  92. {
  93. struct dentry *file;
  94. file = debugfs_create_file(name, mode, dent, show, &debug_ops);
  95. if (!file)
  96. pr_err("%s: unable to create file '%s'\n", __func__, name);
  97. }
  98. static int __init smem_debugfs_init(void)
  99. {
  100. struct dentry *dent;
  101. dent = debugfs_create_dir("smem", 0);
  102. if (IS_ERR(dent))
  103. return PTR_ERR(dent);
  104. debug_create("mem", 0444, dent, debug_read_mem);
  105. debug_create("version", 0444, dent, debug_read_smem_version);
  106. /* NNV: this is google only stuff */
  107. debug_create("build", 0444, dent, debug_read_build_id);
  108. return 0;
  109. }
  110. late_initcall(smem_debugfs_init);
  111. #endif