smd_debug.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /* arch/arm/mach-msm/smd_debug.c
  2. *
  3. * Copyright (C) 2007 Google, Inc.
  4. * Author: Brian Swetland <swetland@google.com>
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/debugfs.h>
  17. #include <linux/list.h>
  18. #include <mach/msm_iomap.h>
  19. #include "smd_private.h"
  20. #if defined(CONFIG_DEBUG_FS)
  21. static char *chstate(unsigned n)
  22. {
  23. switch (n) {
  24. case SMD_SS_CLOSED:
  25. return "CLOSED";
  26. case SMD_SS_OPENING:
  27. return "OPENING";
  28. case SMD_SS_OPENED:
  29. return "OPENED";
  30. case SMD_SS_FLUSHING:
  31. return "FLUSHING";
  32. case SMD_SS_CLOSING:
  33. return "CLOSING";
  34. case SMD_SS_RESET:
  35. return "RESET";
  36. case SMD_SS_RESET_OPENING:
  37. return "ROPENING";
  38. default:
  39. return "UNKNOWN";
  40. }
  41. }
  42. static int dump_ch(char *buf, int max, struct smd_channel *ch)
  43. {
  44. volatile struct smd_half_channel *s = ch->send;
  45. volatile struct smd_half_channel *r = ch->recv;
  46. return scnprintf(
  47. buf, max,
  48. "ch%02d:"
  49. " %8s(%05d/%05d) %c%c%c%c%c%c%c <->"
  50. " %8s(%05d/%05d) %c%c%c%c%c%c%c '%s'\n", ch->n,
  51. chstate(s->state), s->tail, s->head,
  52. s->fDSR ? 'D' : 'd',
  53. s->fCTS ? 'C' : 'c',
  54. s->fCD ? 'C' : 'c',
  55. s->fRI ? 'I' : 'i',
  56. s->fHEAD ? 'W' : 'w',
  57. s->fTAIL ? 'R' : 'r',
  58. s->fSTATE ? 'S' : 's',
  59. chstate(r->state), r->tail, r->head,
  60. r->fDSR ? 'D' : 'd',
  61. r->fCTS ? 'R' : 'r',
  62. r->fCD ? 'C' : 'c',
  63. r->fRI ? 'I' : 'i',
  64. r->fHEAD ? 'W' : 'w',
  65. r->fTAIL ? 'R' : 'r',
  66. r->fSTATE ? 'S' : 's',
  67. ch->name
  68. );
  69. }
  70. static int debug_read_stat(char *buf, int max)
  71. {
  72. char *msg;
  73. int i = 0;
  74. msg = smem_find(ID_DIAG_ERR_MSG, SZ_DIAG_ERR_MSG);
  75. if (raw_smsm_get_state(SMSM_STATE_MODEM) & SMSM_RESET)
  76. i += scnprintf(buf + i, max - i,
  77. "smsm: ARM9 HAS CRASHED\n");
  78. i += scnprintf(buf + i, max - i, "smsm: a9: %08x a11: %08x\n",
  79. raw_smsm_get_state(SMSM_STATE_MODEM),
  80. raw_smsm_get_state(SMSM_STATE_APPS));
  81. #ifdef CONFIG_ARCH_MSM_SCORPION
  82. i += scnprintf(buf + i, max - i, "smsm dem: apps: %08x modem: %08x "
  83. "qdsp6: %08x power: %08x time: %08x\n",
  84. raw_smsm_get_state(SMSM_STATE_APPS_DEM),
  85. raw_smsm_get_state(SMSM_STATE_MODEM_DEM),
  86. raw_smsm_get_state(SMSM_STATE_QDSP6_DEM),
  87. raw_smsm_get_state(SMSM_STATE_POWER_MASTER_DEM),
  88. raw_smsm_get_state(SMSM_STATE_TIME_MASTER_DEM));
  89. #endif
  90. if (msg) {
  91. msg[SZ_DIAG_ERR_MSG - 1] = 0;
  92. i += scnprintf(buf + i, max - i, "diag: '%s'\n", msg);
  93. }
  94. return i;
  95. }
  96. static int debug_read_mem(char *buf, int max)
  97. {
  98. unsigned n;
  99. struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE;
  100. struct smem_heap_entry *toc = shared->heap_toc;
  101. int i = 0;
  102. i += scnprintf(buf + i, max - i,
  103. "heap: init=%d free=%d remain=%d\n",
  104. shared->heap_info.initialized,
  105. shared->heap_info.free_offset,
  106. shared->heap_info.heap_remaining);
  107. for (n = 0; n < SMEM_NUM_ITEMS; n++) {
  108. if (toc[n].allocated == 0)
  109. continue;
  110. i += scnprintf(buf + i, max - i,
  111. "%04d: offset %08x size %08x\n",
  112. n, toc[n].offset, toc[n].size);
  113. }
  114. return i;
  115. }
  116. static int debug_read_ch(char *buf, int max)
  117. {
  118. struct smd_channel *ch;
  119. unsigned long flags;
  120. int i = 0;
  121. spin_lock_irqsave(&smd_lock, flags);
  122. list_for_each_entry(ch, &smd_ch_list_dsp, ch_list)
  123. i += dump_ch(buf + i, max - i, ch);
  124. list_for_each_entry(ch, &smd_ch_list_modem, ch_list)
  125. i += dump_ch(buf + i, max - i, ch);
  126. list_for_each_entry(ch, &smd_ch_closed_list, ch_list)
  127. i += dump_ch(buf + i, max - i, ch);
  128. spin_unlock_irqrestore(&smd_lock, flags);
  129. return i;
  130. }
  131. static int debug_read_version(char *buf, int max)
  132. {
  133. struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE;
  134. unsigned version = shared->version[VERSION_MODEM];
  135. return sprintf(buf, "%d.%d\n", version >> 16, version & 0xffff);
  136. }
  137. static int debug_read_build_id(char *buf, int max)
  138. {
  139. unsigned size;
  140. void *data;
  141. data = smem_item(SMEM_HW_SW_BUILD_ID, &size);
  142. if (!data)
  143. return 0;
  144. if (size >= max)
  145. size = max;
  146. memcpy(buf, data, size);
  147. return size;
  148. }
  149. static int debug_read_alloc_tbl(char *buf, int max)
  150. {
  151. struct smd_alloc_elm *shared;
  152. int n, i = 0;
  153. shared = smem_find(ID_CH_ALLOC_TBL, sizeof(*shared) * 64);
  154. for (n = 0; n < 64; n++) {
  155. if (shared[n].ref_count == 0)
  156. continue;
  157. i += scnprintf(buf + i, max - i,
  158. "%03d: %-20s cid=%02d type=%03d "
  159. "kind=%02d ref_count=%d\n",
  160. n, shared[n].name, shared[n].cid,
  161. shared[n].ctype & 0xff,
  162. (shared[n].ctype >> 8) & 0xf,
  163. shared[n].ref_count);
  164. }
  165. return i;
  166. }
  167. #define DEBUG_BUFMAX 4096
  168. static char debug_buffer[DEBUG_BUFMAX];
  169. static ssize_t debug_read(struct file *file, char __user *buf,
  170. size_t count, loff_t *ppos)
  171. {
  172. int (*fill)(char *buf, int max) = file->private_data;
  173. int bsize = fill(debug_buffer, DEBUG_BUFMAX);
  174. return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
  175. }
  176. static int debug_open(struct inode *inode, struct file *file)
  177. {
  178. file->private_data = inode->i_private;
  179. return 0;
  180. }
  181. static const struct file_operations debug_ops = {
  182. .read = debug_read,
  183. .open = debug_open,
  184. .llseek = default_llseek,
  185. };
  186. static void debug_create(const char *name, mode_t mode,
  187. struct dentry *dent,
  188. int (*fill)(char *buf, int max))
  189. {
  190. debugfs_create_file(name, mode, dent, fill, &debug_ops);
  191. }
  192. static int smd_debugfs_init(void)
  193. {
  194. struct dentry *dent;
  195. dent = debugfs_create_dir("smd", 0);
  196. if (IS_ERR(dent))
  197. return 1;
  198. debug_create("ch", 0444, dent, debug_read_ch);
  199. debug_create("stat", 0444, dent, debug_read_stat);
  200. debug_create("mem", 0444, dent, debug_read_mem);
  201. debug_create("version", 0444, dent, debug_read_version);
  202. debug_create("tbl", 0444, dent, debug_read_alloc_tbl);
  203. debug_create("build", 0444, dent, debug_read_build_id);
  204. return 0;
  205. }
  206. late_initcall(smd_debugfs_init);
  207. #endif
  208. #define MAX_NUM_SLEEP_CLIENTS 64
  209. #define MAX_SLEEP_NAME_LEN 8
  210. #define NUM_GPIO_INT_REGISTERS 6
  211. #define GPIO_SMEM_NUM_GROUPS 2
  212. #define GPIO_SMEM_MAX_PC_INTERRUPTS 8
  213. struct tramp_gpio_save {
  214. unsigned int enable;
  215. unsigned int detect;
  216. unsigned int polarity;
  217. };
  218. struct tramp_gpio_smem {
  219. uint16_t num_fired[GPIO_SMEM_NUM_GROUPS];
  220. uint16_t fired[GPIO_SMEM_NUM_GROUPS][GPIO_SMEM_MAX_PC_INTERRUPTS];
  221. uint32_t enabled[NUM_GPIO_INT_REGISTERS];
  222. uint32_t detection[NUM_GPIO_INT_REGISTERS];
  223. uint32_t polarity[NUM_GPIO_INT_REGISTERS];
  224. };
  225. void smsm_print_sleep_info(void)
  226. {
  227. unsigned long flags;
  228. uint32_t *ptr;
  229. #ifndef CONFIG_ARCH_MSM_SCORPION
  230. struct tramp_gpio_smem *gpio;
  231. struct smsm_interrupt_info *int_info;
  232. #endif
  233. spin_lock_irqsave(&smem_lock, flags);
  234. ptr = smem_alloc(SMEM_SMSM_SLEEP_DELAY, sizeof(*ptr));
  235. if (ptr)
  236. pr_info("SMEM_SMSM_SLEEP_DELAY: %x\n", *ptr);
  237. ptr = smem_alloc(SMEM_SMSM_LIMIT_SLEEP, sizeof(*ptr));
  238. if (ptr)
  239. pr_info("SMEM_SMSM_LIMIT_SLEEP: %x\n", *ptr);
  240. ptr = smem_alloc(SMEM_SLEEP_POWER_COLLAPSE_DISABLED, sizeof(*ptr));
  241. if (ptr)
  242. pr_info("SMEM_SLEEP_POWER_COLLAPSE_DISABLED: %x\n", *ptr);
  243. #ifndef CONFIG_ARCH_MSM_SCORPION
  244. int_info = smem_alloc(SMEM_SMSM_INT_INFO, sizeof(*int_info));
  245. if (int_info)
  246. pr_info("SMEM_SMSM_INT_INFO %x %x %x\n",
  247. int_info->interrupt_mask,
  248. int_info->pending_interrupts,
  249. int_info->wakeup_reason);
  250. gpio = smem_alloc(SMEM_GPIO_INT, sizeof(*gpio));
  251. if (gpio) {
  252. int i;
  253. for (i = 0; i < NUM_GPIO_INT_REGISTERS; i++)
  254. pr_info("SMEM_GPIO_INT: %d: e %x d %x p %x\n",
  255. i, gpio->enabled[i], gpio->detection[i],
  256. gpio->polarity[i]);
  257. for (i = 0; i < GPIO_SMEM_NUM_GROUPS; i++)
  258. pr_info("SMEM_GPIO_INT: %d: f %d: %d %d...\n",
  259. i, gpio->num_fired[i], gpio->fired[i][0],
  260. gpio->fired[i][1]);
  261. }
  262. #else
  263. #endif
  264. spin_unlock_irqrestore(&smem_lock, flags);
  265. }