blob: 3bb40a7fa2834091da0e4742b7a4633c7a5eebf1 [file] [log] [blame]
Brian Swetland03e00cd2009-07-01 17:58:37 -07001/* 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
17#include <linux/debugfs.h>
18#include <linux/list.h>
19
20#include <mach/msm_iomap.h>
21
22#include "smd_private.h"
23
24#if defined(CONFIG_DEBUG_FS)
25
26static char *chstate(unsigned n)
27{
28 switch (n) {
29 case SMD_SS_CLOSED:
30 return "CLOSED";
31 case SMD_SS_OPENING:
32 return "OPENING";
33 case SMD_SS_OPENED:
34 return "OPENED";
35 case SMD_SS_FLUSHING:
36 return "FLUSHING";
37 case SMD_SS_CLOSING:
38 return "CLOSING";
39 case SMD_SS_RESET:
40 return "RESET";
41 case SMD_SS_RESET_OPENING:
42 return "ROPENING";
43 default:
44 return "UNKNOWN";
45 }
46}
47
48
49static int dump_ch(char *buf, int max, struct smd_channel *ch)
50{
51 volatile struct smd_half_channel *s = ch->send;
52 volatile struct smd_half_channel *r = ch->recv;
53
54 return scnprintf(
55 buf, max,
56 "ch%02d:"
57 " %8s(%05d/%05d) %c%c%c%c%c%c%c <->"
58 " %8s(%05d/%05d) %c%c%c%c%c%c%c\n", ch->n,
59 chstate(s->state), s->tail, s->head,
60 s->fDSR ? 'D' : 'd',
61 s->fCTS ? 'C' : 'c',
62 s->fCD ? 'C' : 'c',
63 s->fRI ? 'I' : 'i',
64 s->fHEAD ? 'W' : 'w',
65 s->fTAIL ? 'R' : 'r',
66 s->fSTATE ? 'S' : 's',
67 chstate(r->state), r->tail, r->head,
68 r->fDSR ? 'D' : 'd',
69 r->fCTS ? 'R' : 'r',
70 r->fCD ? 'C' : 'c',
71 r->fRI ? 'I' : 'i',
72 r->fHEAD ? 'W' : 'w',
73 r->fTAIL ? 'R' : 'r',
74 r->fSTATE ? 'S' : 's'
75 );
76}
77
78static int debug_read_stat(char *buf, int max)
79{
80 char *msg;
81 int i = 0;
82
83 msg = smem_find(ID_DIAG_ERR_MSG, SZ_DIAG_ERR_MSG);
84
85 if (raw_smsm_get_state(SMSM_STATE_MODEM) & SMSM_RESET)
86 i += scnprintf(buf + i, max - i,
87 "smsm: ARM9 HAS CRASHED\n");
88
89 i += scnprintf(buf + i, max - i, "smsm: a9: %08x a11: %08x\n",
90 raw_smsm_get_state(SMSM_STATE_MODEM),
91 raw_smsm_get_state(SMSM_STATE_APPS));
92#ifdef CONFIG_ARCH_MSM_SCORPION
93 i += scnprintf(buf + i, max - i, "smsm dem: apps: %08x modem: %08x "
94 "qdsp6: %08x power: %08x time: %08x\n",
95 raw_smsm_get_state(SMSM_STATE_APPS_DEM),
96 raw_smsm_get_state(SMSM_STATE_MODEM_DEM),
97 raw_smsm_get_state(SMSM_STATE_QDSP6_DEM),
98 raw_smsm_get_state(SMSM_STATE_POWER_MASTER_DEM),
99 raw_smsm_get_state(SMSM_STATE_TIME_MASTER_DEM));
100#endif
101 if (msg) {
102 msg[SZ_DIAG_ERR_MSG - 1] = 0;
103 i += scnprintf(buf + i, max - i, "diag: '%s'\n", msg);
104 }
105 return i;
106}
107
108static int debug_read_mem(char *buf, int max)
109{
110 unsigned n;
111 struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE;
112 struct smem_heap_entry *toc = shared->heap_toc;
113 int i = 0;
114
115 i += scnprintf(buf + i, max - i,
116 "heap: init=%d free=%d remain=%d\n",
117 shared->heap_info.initialized,
118 shared->heap_info.free_offset,
119 shared->heap_info.heap_remaining);
120
121 for (n = 0; n < SMEM_NUM_ITEMS; n++) {
122 if (toc[n].allocated == 0)
123 continue;
124 i += scnprintf(buf + i, max - i,
125 "%04d: offset %08x size %08x\n",
126 n, toc[n].offset, toc[n].size);
127 }
128 return i;
129}
130
131static int debug_read_ch(char *buf, int max)
132{
133 struct smd_channel *ch;
134 unsigned long flags;
135 int i = 0;
136
137 spin_lock_irqsave(&smd_lock, flags);
138 list_for_each_entry(ch, &smd_ch_list, ch_list)
139 i += dump_ch(buf + i, max - i, ch);
140 list_for_each_entry(ch, &smd_ch_closed_list, ch_list)
141 i += dump_ch(buf + i, max - i, ch);
142 spin_unlock_irqrestore(&smd_lock, flags);
143
144 return i;
145}
146
147static int debug_read_version(char *buf, int max)
148{
149 struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE;
150 unsigned version = shared->version[VERSION_MODEM];
151 return sprintf(buf, "%d.%d\n", version >> 16, version & 0xffff);
152}
153
154static int debug_read_build_id(char *buf, int max)
155{
156 unsigned size;
157 void *data;
158
159 data = smem_item(SMEM_HW_SW_BUILD_ID, &size);
160 if (!data)
161 return 0;
162
163 if (size >= max)
164 size = max;
165 memcpy(buf, data, size);
166
167 return size;
168}
169
170static int debug_read_alloc_tbl(char *buf, int max)
171{
172 struct smd_alloc_elm *shared;
173 int n, i = 0;
174
175 shared = smem_find(ID_CH_ALLOC_TBL, sizeof(*shared) * 64);
176
177 for (n = 0; n < 64; n++) {
178 if (shared[n].ref_count == 0)
179 continue;
180 i += scnprintf(buf + i, max - i,
181 "%03d: %-20s cid=%02d type=%03d "
182 "kind=%02d ref_count=%d\n",
183 n, shared[n].name, shared[n].cid,
184 shared[n].ctype & 0xff,
185 (shared[n].ctype >> 8) & 0xf,
186 shared[n].ref_count);
187 }
188
189 return i;
190}
191
192#define DEBUG_BUFMAX 4096
193static char debug_buffer[DEBUG_BUFMAX];
194
195static ssize_t debug_read(struct file *file, char __user *buf,
196 size_t count, loff_t *ppos)
197{
198 int (*fill)(char *buf, int max) = file->private_data;
199 int bsize = fill(debug_buffer, DEBUG_BUFMAX);
200 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
201}
202
203static int debug_open(struct inode *inode, struct file *file)
204{
205 file->private_data = inode->i_private;
206 return 0;
207}
208
209static const struct file_operations debug_ops = {
210 .read = debug_read,
211 .open = debug_open,
212};
213
214static void debug_create(const char *name, mode_t mode,
215 struct dentry *dent,
216 int (*fill)(char *buf, int max))
217{
218 debugfs_create_file(name, mode, dent, fill, &debug_ops);
219}
220
221static void smd_debugfs_init(void)
222{
223 struct dentry *dent;
224
225 dent = debugfs_create_dir("smd", 0);
226 if (IS_ERR(dent))
227 return;
228
229 debug_create("ch", 0444, dent, debug_read_ch);
230 debug_create("stat", 0444, dent, debug_read_stat);
231 debug_create("mem", 0444, dent, debug_read_mem);
232 debug_create("version", 0444, dent, debug_read_version);
233 debug_create("tbl", 0444, dent, debug_read_alloc_tbl);
234 debug_create("build", 0444, dent, debug_read_build_id);
235}
236
237late_initcall(smd_debugfs_init);
238#endif
239
240
241#define MAX_NUM_SLEEP_CLIENTS 64
242#define MAX_SLEEP_NAME_LEN 8
243
244#define NUM_GPIO_INT_REGISTERS 6
245#define GPIO_SMEM_NUM_GROUPS 2
246#define GPIO_SMEM_MAX_PC_INTERRUPTS 8
247
248struct tramp_gpio_save {
249 unsigned int enable;
250 unsigned int detect;
251 unsigned int polarity;
252};
253
254struct tramp_gpio_smem {
255 uint16_t num_fired[GPIO_SMEM_NUM_GROUPS];
256 uint16_t fired[GPIO_SMEM_NUM_GROUPS][GPIO_SMEM_MAX_PC_INTERRUPTS];
257 uint32_t enabled[NUM_GPIO_INT_REGISTERS];
258 uint32_t detection[NUM_GPIO_INT_REGISTERS];
259 uint32_t polarity[NUM_GPIO_INT_REGISTERS];
260};
261
262
263void smsm_print_sleep_info(void)
264{
265 unsigned long flags;
266 uint32_t *ptr;
267 struct tramp_gpio_smem *gpio;
268 struct smsm_interrupt_info *int_info;
269
270
271 spin_lock_irqsave(&smem_lock, flags);
272
273 ptr = smem_alloc(SMEM_SMSM_SLEEP_DELAY, sizeof(*ptr));
274 if (ptr)
275 pr_info("SMEM_SMSM_SLEEP_DELAY: %x\n", *ptr);
276
277 ptr = smem_alloc(SMEM_SMSM_LIMIT_SLEEP, sizeof(*ptr));
278 if (ptr)
279 pr_info("SMEM_SMSM_LIMIT_SLEEP: %x\n", *ptr);
280
281 ptr = smem_alloc(SMEM_SLEEP_POWER_COLLAPSE_DISABLED, sizeof(*ptr));
282 if (ptr)
283 pr_info("SMEM_SLEEP_POWER_COLLAPSE_DISABLED: %x\n", *ptr);
284
285#ifndef CONFIG_ARCH_MSM_SCORPION
286 int_info = smem_alloc(SMEM_SMSM_INT_INFO, sizeof(*int_info));
287 if (int_info)
288 pr_info("SMEM_SMSM_INT_INFO %x %x %x\n",
289 int_info->interrupt_mask,
290 int_info->pending_interrupts,
291 int_info->wakeup_reason);
292
293 gpio = smem_alloc(SMEM_GPIO_INT, sizeof(*gpio));
294 if (gpio) {
295 int i;
296 for (i = 0; i < NUM_GPIO_INT_REGISTERS; i++)
297 pr_info("SMEM_GPIO_INT: %d: e %x d %x p %x\n",
298 i, gpio->enabled[i], gpio->detection[i],
299 gpio->polarity[i]);
300
301 for (i = 0; i < GPIO_SMEM_NUM_GROUPS; i++)
302 pr_info("SMEM_GPIO_INT: %d: f %d: %d %d...\n",
303 i, gpio->num_fired[i], gpio->fired[i][0],
304 gpio->fired[i][1]);
305 }
306#else
307#endif
308 spin_unlock_irqrestore(&smem_lock, flags);
309}
310