| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * omap iommu: debugfs interface |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2008-2009 Nokia Corporation |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com> |
|---|
| 7 | | - * |
|---|
| 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 |
|---|
| 10 | | - * published by the Free Software Foundation. |
|---|
| 11 | 8 | */ |
|---|
| 12 | 9 | |
|---|
| 13 | 10 | #include <linux/err.h> |
|---|
| .. | .. |
|---|
| 35 | 32 | ssize_t bytes; \ |
|---|
| 36 | 33 | const char *str = "%20s: %08x\n"; \ |
|---|
| 37 | 34 | const int maxcol = 32; \ |
|---|
| 38 | | - bytes = snprintf(p, maxcol, str, __stringify(name), \ |
|---|
| 35 | + if (len < maxcol) \ |
|---|
| 36 | + goto out; \ |
|---|
| 37 | + bytes = scnprintf(p, maxcol, str, __stringify(name), \ |
|---|
| 39 | 38 | iommu_read_reg(obj, MMU_##name)); \ |
|---|
| 40 | 39 | p += bytes; \ |
|---|
| 41 | 40 | len -= bytes; \ |
|---|
| 42 | | - if (len < maxcol) \ |
|---|
| 43 | | - goto out; \ |
|---|
| 44 | 41 | } while (0) |
|---|
| 45 | 42 | |
|---|
| 46 | 43 | static ssize_t |
|---|
| .. | .. |
|---|
| 162 | 159 | return 0; |
|---|
| 163 | 160 | } |
|---|
| 164 | 161 | |
|---|
| 165 | | -static int debug_read_tlb(struct seq_file *s, void *data) |
|---|
| 162 | +static int tlb_show(struct seq_file *s, void *data) |
|---|
| 166 | 163 | { |
|---|
| 167 | 164 | struct omap_iommu *obj = s->private; |
|---|
| 168 | 165 | |
|---|
| .. | .. |
|---|
| 213 | 210 | spin_unlock(&obj->page_table_lock); |
|---|
| 214 | 211 | } |
|---|
| 215 | 212 | |
|---|
| 216 | | -static int debug_read_pagetable(struct seq_file *s, void *data) |
|---|
| 213 | +static int pagetable_show(struct seq_file *s, void *data) |
|---|
| 217 | 214 | { |
|---|
| 218 | 215 | struct omap_iommu *obj = s->private; |
|---|
| 219 | 216 | |
|---|
| .. | .. |
|---|
| 231 | 228 | return 0; |
|---|
| 232 | 229 | } |
|---|
| 233 | 230 | |
|---|
| 234 | | -#define DEBUG_SEQ_FOPS_RO(name) \ |
|---|
| 235 | | - static int debug_open_##name(struct inode *inode, struct file *file) \ |
|---|
| 236 | | - { \ |
|---|
| 237 | | - return single_open(file, debug_read_##name, inode->i_private); \ |
|---|
| 238 | | - } \ |
|---|
| 239 | | - \ |
|---|
| 240 | | - static const struct file_operations debug_##name##_fops = { \ |
|---|
| 241 | | - .open = debug_open_##name, \ |
|---|
| 242 | | - .read = seq_read, \ |
|---|
| 243 | | - .llseek = seq_lseek, \ |
|---|
| 244 | | - .release = single_release, \ |
|---|
| 245 | | - } |
|---|
| 246 | | - |
|---|
| 247 | 231 | #define DEBUG_FOPS_RO(name) \ |
|---|
| 248 | | - static const struct file_operations debug_##name##_fops = { \ |
|---|
| 232 | + static const struct file_operations name##_fops = { \ |
|---|
| 249 | 233 | .open = simple_open, \ |
|---|
| 250 | 234 | .read = debug_read_##name, \ |
|---|
| 251 | 235 | .llseek = generic_file_llseek, \ |
|---|
| 252 | 236 | } |
|---|
| 253 | 237 | |
|---|
| 254 | 238 | DEBUG_FOPS_RO(regs); |
|---|
| 255 | | -DEBUG_SEQ_FOPS_RO(tlb); |
|---|
| 256 | | -DEBUG_SEQ_FOPS_RO(pagetable); |
|---|
| 257 | | - |
|---|
| 258 | | -#define __DEBUG_ADD_FILE(attr, mode) \ |
|---|
| 259 | | - { \ |
|---|
| 260 | | - struct dentry *dent; \ |
|---|
| 261 | | - dent = debugfs_create_file(#attr, mode, obj->debug_dir, \ |
|---|
| 262 | | - obj, &debug_##attr##_fops); \ |
|---|
| 263 | | - if (!dent) \ |
|---|
| 264 | | - goto err; \ |
|---|
| 265 | | - } |
|---|
| 266 | | - |
|---|
| 267 | | -#define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 0400) |
|---|
| 239 | +DEFINE_SHOW_ATTRIBUTE(tlb); |
|---|
| 240 | +DEFINE_SHOW_ATTRIBUTE(pagetable); |
|---|
| 268 | 241 | |
|---|
| 269 | 242 | void omap_iommu_debugfs_add(struct omap_iommu *obj) |
|---|
| 270 | 243 | { |
|---|
| .. | .. |
|---|
| 273 | 246 | if (!iommu_debug_root) |
|---|
| 274 | 247 | return; |
|---|
| 275 | 248 | |
|---|
| 276 | | - obj->debug_dir = debugfs_create_dir(obj->name, iommu_debug_root); |
|---|
| 277 | | - if (!obj->debug_dir) |
|---|
| 278 | | - return; |
|---|
| 249 | + d = debugfs_create_dir(obj->name, iommu_debug_root); |
|---|
| 250 | + obj->debug_dir = d; |
|---|
| 279 | 251 | |
|---|
| 280 | | - d = debugfs_create_u32("nr_tlb_entries", 0400, obj->debug_dir, |
|---|
| 281 | | - &obj->nr_tlb_entries); |
|---|
| 282 | | - if (!d) |
|---|
| 283 | | - return; |
|---|
| 284 | | - |
|---|
| 285 | | - DEBUG_ADD_FILE_RO(regs); |
|---|
| 286 | | - DEBUG_ADD_FILE_RO(tlb); |
|---|
| 287 | | - DEBUG_ADD_FILE_RO(pagetable); |
|---|
| 288 | | - |
|---|
| 289 | | - return; |
|---|
| 290 | | - |
|---|
| 291 | | -err: |
|---|
| 292 | | - debugfs_remove_recursive(obj->debug_dir); |
|---|
| 252 | + debugfs_create_u32("nr_tlb_entries", 0400, d, &obj->nr_tlb_entries); |
|---|
| 253 | + debugfs_create_file("regs", 0400, d, obj, ®s_fops); |
|---|
| 254 | + debugfs_create_file("tlb", 0400, d, obj, &tlb_fops); |
|---|
| 255 | + debugfs_create_file("pagetable", 0400, d, obj, &pagetable_fops); |
|---|
| 293 | 256 | } |
|---|
| 294 | 257 | |
|---|
| 295 | 258 | void omap_iommu_debugfs_remove(struct omap_iommu *obj) |
|---|
| .. | .. |
|---|
| 303 | 266 | void __init omap_iommu_debugfs_init(void) |
|---|
| 304 | 267 | { |
|---|
| 305 | 268 | iommu_debug_root = debugfs_create_dir("omap_iommu", NULL); |
|---|
| 306 | | - if (!iommu_debug_root) |
|---|
| 307 | | - pr_err("can't create debugfs dir\n"); |
|---|
| 308 | 269 | } |
|---|
| 309 | 270 | |
|---|
| 310 | 271 | void __exit omap_iommu_debugfs_exit(void) |
|---|