ARM: dts: add 'dr_mode' property to hsotg devices for exynos boards
[linux/fpc-iii.git] / drivers / iommu / omap-iommu-debug.c
blobf3d20a2039d20417093fd70c6192b905e7c3ccf8
1 /*
2 * omap iommu: debugfs interface
4 * Copyright (C) 2008-2009 Nokia Corporation
6 * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
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.
13 #include <linux/err.h>
14 #include <linux/io.h>
15 #include <linux/slab.h>
16 #include <linux/uaccess.h>
17 #include <linux/debugfs.h>
18 #include <linux/platform_data/iommu-omap.h>
20 #include "omap-iopgtable.h"
21 #include "omap-iommu.h"
23 static DEFINE_MUTEX(iommu_debug_lock);
25 static struct dentry *iommu_debug_root;
27 static inline bool is_omap_iommu_detached(struct omap_iommu *obj)
29 return !obj->domain;
32 static ssize_t debug_read_regs(struct file *file, char __user *userbuf,
33 size_t count, loff_t *ppos)
35 struct omap_iommu *obj = file->private_data;
36 char *p, *buf;
37 ssize_t bytes;
39 if (is_omap_iommu_detached(obj))
40 return -EPERM;
42 buf = kmalloc(count, GFP_KERNEL);
43 if (!buf)
44 return -ENOMEM;
45 p = buf;
47 mutex_lock(&iommu_debug_lock);
49 bytes = omap_iommu_dump_ctx(obj, p, count);
50 bytes = simple_read_from_buffer(userbuf, count, ppos, buf, bytes);
52 mutex_unlock(&iommu_debug_lock);
53 kfree(buf);
55 return bytes;
58 static ssize_t debug_read_tlb(struct file *file, char __user *userbuf,
59 size_t count, loff_t *ppos)
61 struct omap_iommu *obj = file->private_data;
62 char *p, *buf;
63 ssize_t bytes, rest;
65 if (is_omap_iommu_detached(obj))
66 return -EPERM;
68 buf = kmalloc(count, GFP_KERNEL);
69 if (!buf)
70 return -ENOMEM;
71 p = buf;
73 mutex_lock(&iommu_debug_lock);
75 p += sprintf(p, "%8s %8s\n", "cam:", "ram:");
76 p += sprintf(p, "-----------------------------------------\n");
77 rest = count - (p - buf);
78 p += omap_dump_tlb_entries(obj, p, rest);
80 bytes = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
82 mutex_unlock(&iommu_debug_lock);
83 kfree(buf);
85 return bytes;
88 static void dump_ioptable(struct seq_file *s)
90 int i, j;
91 u32 da;
92 u32 *iopgd, *iopte;
93 struct omap_iommu *obj = s->private;
95 spin_lock(&obj->page_table_lock);
97 iopgd = iopgd_offset(obj, 0);
98 for (i = 0; i < PTRS_PER_IOPGD; i++, iopgd++) {
99 if (!*iopgd)
100 continue;
102 if (!(*iopgd & IOPGD_TABLE)) {
103 da = i << IOPGD_SHIFT;
104 seq_printf(s, "1: 0x%08x 0x%08x\n", da, *iopgd);
105 continue;
108 iopte = iopte_offset(iopgd, 0);
109 for (j = 0; j < PTRS_PER_IOPTE; j++, iopte++) {
110 if (!*iopte)
111 continue;
113 da = (i << IOPGD_SHIFT) + (j << IOPTE_SHIFT);
114 seq_printf(s, "2: 0x%08x 0x%08x\n", da, *iopte);
118 spin_unlock(&obj->page_table_lock);
121 static int debug_read_pagetable(struct seq_file *s, void *data)
123 struct omap_iommu *obj = s->private;
125 if (is_omap_iommu_detached(obj))
126 return -EPERM;
128 mutex_lock(&iommu_debug_lock);
130 seq_printf(s, "L: %8s %8s\n", "da:", "pte:");
131 seq_puts(s, "--------------------------\n");
132 dump_ioptable(s);
134 mutex_unlock(&iommu_debug_lock);
136 return 0;
139 #define DEBUG_SEQ_FOPS_RO(name) \
140 static int debug_open_##name(struct inode *inode, struct file *file) \
142 return single_open(file, debug_read_##name, inode->i_private); \
145 static const struct file_operations debug_##name##_fops = { \
146 .open = debug_open_##name, \
147 .read = seq_read, \
148 .llseek = seq_lseek, \
149 .release = single_release, \
152 #define DEBUG_FOPS_RO(name) \
153 static const struct file_operations debug_##name##_fops = { \
154 .open = simple_open, \
155 .read = debug_read_##name, \
156 .llseek = generic_file_llseek, \
159 DEBUG_FOPS_RO(regs);
160 DEBUG_FOPS_RO(tlb);
161 DEBUG_SEQ_FOPS_RO(pagetable);
163 #define __DEBUG_ADD_FILE(attr, mode) \
165 struct dentry *dent; \
166 dent = debugfs_create_file(#attr, mode, obj->debug_dir, \
167 obj, &debug_##attr##_fops); \
168 if (!dent) \
169 goto err; \
172 #define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 0400)
174 void omap_iommu_debugfs_add(struct omap_iommu *obj)
176 struct dentry *d;
178 if (!iommu_debug_root)
179 return;
181 obj->debug_dir = debugfs_create_dir(obj->name, iommu_debug_root);
182 if (!obj->debug_dir)
183 return;
185 d = debugfs_create_u8("nr_tlb_entries", 0400, obj->debug_dir,
186 (u8 *)&obj->nr_tlb_entries);
187 if (!d)
188 return;
190 DEBUG_ADD_FILE_RO(regs);
191 DEBUG_ADD_FILE_RO(tlb);
192 DEBUG_ADD_FILE_RO(pagetable);
194 return;
196 err:
197 debugfs_remove_recursive(obj->debug_dir);
200 void omap_iommu_debugfs_remove(struct omap_iommu *obj)
202 if (!obj->debug_dir)
203 return;
205 debugfs_remove_recursive(obj->debug_dir);
208 void __init omap_iommu_debugfs_init(void)
210 iommu_debug_root = debugfs_create_dir("omap_iommu", NULL);
211 if (!iommu_debug_root)
212 pr_err("can't create debugfs dir\n");
215 void __exit omap_iommu_debugfs_exit(void)
217 debugfs_remove(iommu_debug_root);