Commit 4a26d43be9a7b0b30a7f737db87ce0d066033a98

Authored by Suman Anna

Merge branch 'iommu-linux-4.1.y' of git://git.ti.com/rpmsg/iommu into rproc-linux-4.1.y

Merge in the updated iommu feature branch into remoteproc tree to
pull in a minor OMAP IOMMU debugfs fix from upstream.

* 'iommu-linux-4.1.y' of git://git.ti.com/rpmsg/iommu:
  iommu/omap: Fix debug_read_tlb() to use seq_printf()

Signed-off-by: Suman Anna <s-anna@ti.com>

Showing 1 changed file Inline Diff

drivers/iommu/omap-iommu-debug.c
1 /* 1 /*
2 * omap iommu: debugfs interface 2 * omap iommu: debugfs interface
3 * 3 *
4 * Copyright (C) 2008-2009 Nokia Corporation 4 * Copyright (C) 2008-2009 Nokia Corporation
5 * 5 *
6 * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com> 6 * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as 9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13 #include <linux/err.h> 13 #include <linux/err.h>
14 #include <linux/io.h> 14 #include <linux/io.h>
15 #include <linux/slab.h> 15 #include <linux/slab.h>
16 #include <linux/uaccess.h> 16 #include <linux/uaccess.h>
17 #include <linux/pm_runtime.h> 17 #include <linux/pm_runtime.h>
18 #include <linux/debugfs.h> 18 #include <linux/debugfs.h>
19 #include <linux/platform_data/iommu-omap.h> 19 #include <linux/platform_data/iommu-omap.h>
20 20
21 #include "omap-iopgtable.h" 21 #include "omap-iopgtable.h"
22 #include "omap-iommu.h" 22 #include "omap-iommu.h"
23 23
24 static DEFINE_MUTEX(iommu_debug_lock); 24 static DEFINE_MUTEX(iommu_debug_lock);
25 25
26 static struct dentry *iommu_debug_root; 26 static struct dentry *iommu_debug_root;
27 27
28 static inline bool is_omap_iommu_detached(struct omap_iommu *obj) 28 static inline bool is_omap_iommu_detached(struct omap_iommu *obj)
29 { 29 {
30 return !obj->domain; 30 return !obj->domain;
31 } 31 }
32 32
33 #define pr_reg(name) \ 33 #define pr_reg(name) \
34 do { \ 34 do { \
35 ssize_t bytes; \ 35 ssize_t bytes; \
36 const char *str = "%20s: %08x\n"; \ 36 const char *str = "%20s: %08x\n"; \
37 const int maxcol = 32; \ 37 const int maxcol = 32; \
38 bytes = snprintf(p, maxcol, str, __stringify(name), \ 38 bytes = snprintf(p, maxcol, str, __stringify(name), \
39 iommu_read_reg(obj, MMU_##name)); \ 39 iommu_read_reg(obj, MMU_##name)); \
40 p += bytes; \ 40 p += bytes; \
41 len -= bytes; \ 41 len -= bytes; \
42 if (len < maxcol) \ 42 if (len < maxcol) \
43 goto out; \ 43 goto out; \
44 } while (0) 44 } while (0)
45 45
46 static ssize_t 46 static ssize_t
47 omap2_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len) 47 omap2_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len)
48 { 48 {
49 char *p = buf; 49 char *p = buf;
50 50
51 pr_reg(REVISION); 51 pr_reg(REVISION);
52 pr_reg(IRQSTATUS); 52 pr_reg(IRQSTATUS);
53 pr_reg(IRQENABLE); 53 pr_reg(IRQENABLE);
54 pr_reg(WALKING_ST); 54 pr_reg(WALKING_ST);
55 pr_reg(CNTL); 55 pr_reg(CNTL);
56 pr_reg(FAULT_AD); 56 pr_reg(FAULT_AD);
57 pr_reg(TTB); 57 pr_reg(TTB);
58 pr_reg(LOCK); 58 pr_reg(LOCK);
59 pr_reg(LD_TLB); 59 pr_reg(LD_TLB);
60 pr_reg(CAM); 60 pr_reg(CAM);
61 pr_reg(RAM); 61 pr_reg(RAM);
62 pr_reg(GFLUSH); 62 pr_reg(GFLUSH);
63 pr_reg(FLUSH_ENTRY); 63 pr_reg(FLUSH_ENTRY);
64 pr_reg(READ_CAM); 64 pr_reg(READ_CAM);
65 pr_reg(READ_RAM); 65 pr_reg(READ_RAM);
66 pr_reg(EMU_FAULT_AD); 66 pr_reg(EMU_FAULT_AD);
67 out: 67 out:
68 return p - buf; 68 return p - buf;
69 } 69 }
70 70
71 static ssize_t omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, 71 static ssize_t omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf,
72 ssize_t bytes) 72 ssize_t bytes)
73 { 73 {
74 if (!obj || !buf) 74 if (!obj || !buf)
75 return -EINVAL; 75 return -EINVAL;
76 76
77 pm_runtime_get_sync(obj->dev); 77 pm_runtime_get_sync(obj->dev);
78 78
79 bytes = omap2_iommu_dump_ctx(obj, buf, bytes); 79 bytes = omap2_iommu_dump_ctx(obj, buf, bytes);
80 80
81 pm_runtime_put_sync(obj->dev); 81 pm_runtime_put_sync(obj->dev);
82 82
83 return bytes; 83 return bytes;
84 } 84 }
85 85
86 static ssize_t debug_read_regs(struct file *file, char __user *userbuf, 86 static ssize_t debug_read_regs(struct file *file, char __user *userbuf,
87 size_t count, loff_t *ppos) 87 size_t count, loff_t *ppos)
88 { 88 {
89 struct omap_iommu *obj = file->private_data; 89 struct omap_iommu *obj = file->private_data;
90 char *p, *buf; 90 char *p, *buf;
91 ssize_t bytes; 91 ssize_t bytes;
92 92
93 if (is_omap_iommu_detached(obj)) 93 if (is_omap_iommu_detached(obj))
94 return -EPERM; 94 return -EPERM;
95 95
96 buf = kmalloc(count, GFP_KERNEL); 96 buf = kmalloc(count, GFP_KERNEL);
97 if (!buf) 97 if (!buf)
98 return -ENOMEM; 98 return -ENOMEM;
99 p = buf; 99 p = buf;
100 100
101 mutex_lock(&iommu_debug_lock); 101 mutex_lock(&iommu_debug_lock);
102 102
103 bytes = omap_iommu_dump_ctx(obj, p, count); 103 bytes = omap_iommu_dump_ctx(obj, p, count);
104 bytes = simple_read_from_buffer(userbuf, count, ppos, buf, bytes); 104 bytes = simple_read_from_buffer(userbuf, count, ppos, buf, bytes);
105 105
106 mutex_unlock(&iommu_debug_lock); 106 mutex_unlock(&iommu_debug_lock);
107 kfree(buf); 107 kfree(buf);
108 108
109 return bytes; 109 return bytes;
110 } 110 }
111 111
112 static int 112 static int
113 __dump_tlb_entries(struct omap_iommu *obj, struct cr_regs *crs, int num) 113 __dump_tlb_entries(struct omap_iommu *obj, struct cr_regs *crs, int num)
114 { 114 {
115 int i; 115 int i;
116 struct iotlb_lock saved; 116 struct iotlb_lock saved;
117 struct cr_regs tmp; 117 struct cr_regs tmp;
118 struct cr_regs *p = crs; 118 struct cr_regs *p = crs;
119 119
120 pm_runtime_get_sync(obj->dev); 120 pm_runtime_get_sync(obj->dev);
121 iotlb_lock_get(obj, &saved); 121 iotlb_lock_get(obj, &saved);
122 122
123 for_each_iotlb_cr(obj, num, i, tmp) { 123 for_each_iotlb_cr(obj, num, i, tmp) {
124 if (!iotlb_cr_valid(&tmp)) 124 if (!iotlb_cr_valid(&tmp))
125 continue; 125 continue;
126 *p++ = tmp; 126 *p++ = tmp;
127 } 127 }
128 128
129 iotlb_lock_set(obj, &saved); 129 iotlb_lock_set(obj, &saved);
130 pm_runtime_put_sync(obj->dev); 130 pm_runtime_put_sync(obj->dev);
131 131
132 return p - crs; 132 return p - crs;
133 } 133 }
134 134
135 static ssize_t iotlb_dump_cr(struct omap_iommu *obj, struct cr_regs *cr, 135 static ssize_t iotlb_dump_cr(struct omap_iommu *obj, struct cr_regs *cr,
136 char *buf) 136 struct seq_file *s)
137 { 137 {
138 char *p = buf; 138 return seq_printf(s, "%08x %08x %01x\n", cr->cam, cr->ram,
139 139 (cr->cam & MMU_CAM_P) ? 1 : 0);
140 /* FIXME: Need more detail analysis of cam/ram */
141 p += sprintf(p, "%08x %08x %01x\n", cr->cam, cr->ram,
142 (cr->cam & MMU_CAM_P) ? 1 : 0);
143
144 return p - buf;
145 } 140 }
146 141
147 static size_t omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, 142 static size_t omap_dump_tlb_entries(struct omap_iommu *obj, struct seq_file *s)
148 ssize_t bytes)
149 { 143 {
150 int i, num; 144 int i, num;
151 struct cr_regs *cr; 145 struct cr_regs *cr;
152 char *p = buf;
153 146
154 num = bytes / sizeof(*cr); 147 num = obj->nr_tlb_entries;
155 num = min(obj->nr_tlb_entries, num);
156 148
157 cr = kcalloc(num, sizeof(*cr), GFP_KERNEL); 149 cr = kcalloc(num, sizeof(*cr), GFP_KERNEL);
158 if (!cr) 150 if (!cr)
159 return 0; 151 return 0;
160 152
161 num = __dump_tlb_entries(obj, cr, num); 153 num = __dump_tlb_entries(obj, cr, num);
162 for (i = 0; i < num; i++) 154 for (i = 0; i < num; i++)
163 p += iotlb_dump_cr(obj, cr + i, p); 155 iotlb_dump_cr(obj, cr + i, s);
164 kfree(cr); 156 kfree(cr);
165 157
166 return p - buf; 158 return 0;
167 } 159 }
168 160
169 static ssize_t debug_read_tlb(struct file *file, char __user *userbuf, 161 static int debug_read_tlb(struct seq_file *s, void *data)
170 size_t count, loff_t *ppos)
171 { 162 {
172 struct omap_iommu *obj = file->private_data; 163 struct omap_iommu *obj = s->private;
173 char *p, *buf;
174 ssize_t bytes, rest;
175 164
176 if (is_omap_iommu_detached(obj)) 165 if (is_omap_iommu_detached(obj))
177 return -EPERM; 166 return -EPERM;
178 167
179 buf = kmalloc(count, GFP_KERNEL);
180 if (!buf)
181 return -ENOMEM;
182 p = buf;
183
184 mutex_lock(&iommu_debug_lock); 168 mutex_lock(&iommu_debug_lock);
185 169
186 p += sprintf(p, "%8s %8s\n", "cam:", "ram:"); 170 seq_printf(s, "%8s %8s\n", "cam:", "ram:");
187 p += sprintf(p, "-----------------------------------------\n"); 171 seq_puts(s, "-----------------------------------------\n");
188 rest = count - (p - buf); 172 omap_dump_tlb_entries(obj, s);
189 p += omap_dump_tlb_entries(obj, p, rest);
190 173
191 bytes = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
192
193 mutex_unlock(&iommu_debug_lock); 174 mutex_unlock(&iommu_debug_lock);
194 kfree(buf);
195 175
196 return bytes; 176 return 0;
197 } 177 }
198 178
199 static void dump_ioptable(struct seq_file *s) 179 static void dump_ioptable(struct seq_file *s)
200 { 180 {
201 int i, j; 181 int i, j;
202 u32 da; 182 u32 da;
203 u32 *iopgd, *iopte; 183 u32 *iopgd, *iopte;
204 struct omap_iommu *obj = s->private; 184 struct omap_iommu *obj = s->private;
205 185
206 spin_lock(&obj->page_table_lock); 186 spin_lock(&obj->page_table_lock);
207 187
208 iopgd = iopgd_offset(obj, 0); 188 iopgd = iopgd_offset(obj, 0);
209 for (i = 0; i < PTRS_PER_IOPGD; i++, iopgd++) { 189 for (i = 0; i < PTRS_PER_IOPGD; i++, iopgd++) {
210 if (!*iopgd) 190 if (!*iopgd)
211 continue; 191 continue;
212 192
213 if (!(*iopgd & IOPGD_TABLE)) { 193 if (!(*iopgd & IOPGD_TABLE)) {
214 da = i << IOPGD_SHIFT; 194 da = i << IOPGD_SHIFT;
215 seq_printf(s, "1: 0x%08x 0x%08x\n", da, *iopgd); 195 seq_printf(s, "1: 0x%08x 0x%08x\n", da, *iopgd);
216 continue; 196 continue;
217 } 197 }
218 198
219 iopte = iopte_offset(iopgd, 0); 199 iopte = iopte_offset(iopgd, 0);
220 for (j = 0; j < PTRS_PER_IOPTE; j++, iopte++) { 200 for (j = 0; j < PTRS_PER_IOPTE; j++, iopte++) {
221 if (!*iopte) 201 if (!*iopte)
222 continue; 202 continue;
223 203
224 da = (i << IOPGD_SHIFT) + (j << IOPTE_SHIFT); 204 da = (i << IOPGD_SHIFT) + (j << IOPTE_SHIFT);
225 seq_printf(s, "2: 0x%08x 0x%08x\n", da, *iopte); 205 seq_printf(s, "2: 0x%08x 0x%08x\n", da, *iopte);
226 } 206 }
227 } 207 }
228 208
229 spin_unlock(&obj->page_table_lock); 209 spin_unlock(&obj->page_table_lock);
230 } 210 }
231 211
232 static int debug_read_pagetable(struct seq_file *s, void *data) 212 static int debug_read_pagetable(struct seq_file *s, void *data)
233 { 213 {
234 struct omap_iommu *obj = s->private; 214 struct omap_iommu *obj = s->private;
235 215
236 if (is_omap_iommu_detached(obj)) 216 if (is_omap_iommu_detached(obj))
237 return -EPERM; 217 return -EPERM;
238 218
239 mutex_lock(&iommu_debug_lock); 219 mutex_lock(&iommu_debug_lock);
240 220
241 seq_printf(s, "L: %8s %8s\n", "da:", "pte:"); 221 seq_printf(s, "L: %8s %8s\n", "da:", "pte:");
242 seq_puts(s, "--------------------------\n"); 222 seq_puts(s, "--------------------------\n");
243 dump_ioptable(s); 223 dump_ioptable(s);
244 224
245 mutex_unlock(&iommu_debug_lock); 225 mutex_unlock(&iommu_debug_lock);
246 226
247 return 0; 227 return 0;
248 } 228 }
249 229
250 #define DEBUG_SEQ_FOPS_RO(name) \ 230 #define DEBUG_SEQ_FOPS_RO(name) \
251 static int debug_open_##name(struct inode *inode, struct file *file) \ 231 static int debug_open_##name(struct inode *inode, struct file *file) \
252 { \ 232 { \
253 return single_open(file, debug_read_##name, inode->i_private); \ 233 return single_open(file, debug_read_##name, inode->i_private); \
254 } \ 234 } \
255 \ 235 \
256 static const struct file_operations debug_##name##_fops = { \ 236 static const struct file_operations debug_##name##_fops = { \
257 .open = debug_open_##name, \ 237 .open = debug_open_##name, \
258 .read = seq_read, \ 238 .read = seq_read, \
259 .llseek = seq_lseek, \ 239 .llseek = seq_lseek, \
260 .release = single_release, \ 240 .release = single_release, \
261 } 241 }
262 242
263 #define DEBUG_FOPS_RO(name) \ 243 #define DEBUG_FOPS_RO(name) \
264 static const struct file_operations debug_##name##_fops = { \ 244 static const struct file_operations debug_##name##_fops = { \
265 .open = simple_open, \ 245 .open = simple_open, \
266 .read = debug_read_##name, \ 246 .read = debug_read_##name, \
267 .llseek = generic_file_llseek, \ 247 .llseek = generic_file_llseek, \
268 } 248 }
269 249
270 DEBUG_FOPS_RO(regs); 250 DEBUG_FOPS_RO(regs);
271 DEBUG_FOPS_RO(tlb); 251 DEBUG_SEQ_FOPS_RO(tlb);
272 DEBUG_SEQ_FOPS_RO(pagetable); 252 DEBUG_SEQ_FOPS_RO(pagetable);
273 253
274 #define __DEBUG_ADD_FILE(attr, mode) \ 254 #define __DEBUG_ADD_FILE(attr, mode) \
275 { \ 255 { \
276 struct dentry *dent; \ 256 struct dentry *dent; \
277 dent = debugfs_create_file(#attr, mode, obj->debug_dir, \ 257 dent = debugfs_create_file(#attr, mode, obj->debug_dir, \
278 obj, &debug_##attr##_fops); \ 258 obj, &debug_##attr##_fops); \
279 if (!dent) \ 259 if (!dent) \
280 goto err; \ 260 goto err; \
281 } 261 }
282 262
283 #define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 0400) 263 #define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 0400)
284 264
285 void omap_iommu_debugfs_add(struct omap_iommu *obj) 265 void omap_iommu_debugfs_add(struct omap_iommu *obj)
286 { 266 {
287 struct dentry *d; 267 struct dentry *d;
288 268
289 if (!iommu_debug_root) 269 if (!iommu_debug_root)
290 return; 270 return;
291 271
292 obj->debug_dir = debugfs_create_dir(obj->name, iommu_debug_root); 272 obj->debug_dir = debugfs_create_dir(obj->name, iommu_debug_root);
293 if (!obj->debug_dir) 273 if (!obj->debug_dir)
294 return; 274 return;
295 275
296 d = debugfs_create_u8("nr_tlb_entries", 0400, obj->debug_dir, 276 d = debugfs_create_u8("nr_tlb_entries", 0400, obj->debug_dir,
297 (u8 *)&obj->nr_tlb_entries); 277 (u8 *)&obj->nr_tlb_entries);
298 if (!d) 278 if (!d)
299 return; 279 return;
300 280
301 DEBUG_ADD_FILE_RO(regs); 281 DEBUG_ADD_FILE_RO(regs);
302 DEBUG_ADD_FILE_RO(tlb); 282 DEBUG_ADD_FILE_RO(tlb);
303 DEBUG_ADD_FILE_RO(pagetable); 283 DEBUG_ADD_FILE_RO(pagetable);
304 284
305 return; 285 return;
306 286
307 err: 287 err:
308 debugfs_remove_recursive(obj->debug_dir); 288 debugfs_remove_recursive(obj->debug_dir);
309 } 289 }
310 290
311 void omap_iommu_debugfs_remove(struct omap_iommu *obj) 291 void omap_iommu_debugfs_remove(struct omap_iommu *obj)
312 { 292 {
313 if (!obj->debug_dir) 293 if (!obj->debug_dir)
314 return; 294 return;
315 295
316 debugfs_remove_recursive(obj->debug_dir); 296 debugfs_remove_recursive(obj->debug_dir);
317 } 297 }
318 298
319 void __init omap_iommu_debugfs_init(void) 299 void __init omap_iommu_debugfs_init(void)
320 { 300 {
321 iommu_debug_root = debugfs_create_dir("omap_iommu", NULL); 301 iommu_debug_root = debugfs_create_dir("omap_iommu", NULL);
322 if (!iommu_debug_root) 302 if (!iommu_debug_root)
323 pr_err("can't create debugfs dir\n"); 303 pr_err("can't create debugfs dir\n");
324 } 304 }
325 305
326 void __exit omap_iommu_debugfs_exit(void) 306 void __exit omap_iommu_debugfs_exit(void)
327 { 307 {
328 debugfs_remove(iommu_debug_root); 308 debugfs_remove(iommu_debug_root);
329 } 309 }
330 310