]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/iommu/omap-iommu-debug.c
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>
15 #include <linux/slab.h>
16 #include <linux/uaccess.h>
17 #include <linux/pm_runtime.h>
18 #include <linux/debugfs.h>
19 #include <linux/platform_data/iommu-omap.h>
21 #include "omap-iopgtable.h"
22 #include "omap-iommu.h"
24 static DEFINE_MUTEX(iommu_debug_lock
);
26 static struct dentry
*iommu_debug_root
;
28 static inline bool is_omap_iommu_detached(struct omap_iommu
*obj
)
33 #define pr_reg(name) \
36 const char *str = "%20s: %08x\n"; \
37 const int maxcol = 32; \
38 bytes = snprintf(p, maxcol, str, __stringify(name), \
39 iommu_read_reg(obj, MMU_##name)); \
47 omap2_iommu_dump_ctx(struct omap_iommu
*obj
, char *buf
, ssize_t len
)
71 static ssize_t
omap_iommu_dump_ctx(struct omap_iommu
*obj
, char *buf
,
77 pm_runtime_get_sync(obj
->dev
);
79 bytes
= omap2_iommu_dump_ctx(obj
, buf
, bytes
);
81 pm_runtime_put_sync(obj
->dev
);
86 static ssize_t
debug_read_regs(struct file
*file
, char __user
*userbuf
,
87 size_t count
, loff_t
*ppos
)
89 struct omap_iommu
*obj
= file
->private_data
;
93 if (is_omap_iommu_detached(obj
))
96 buf
= kmalloc(count
, GFP_KERNEL
);
101 mutex_lock(&iommu_debug_lock
);
103 bytes
= omap_iommu_dump_ctx(obj
, p
, count
);
104 bytes
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, bytes
);
106 mutex_unlock(&iommu_debug_lock
);
113 __dump_tlb_entries(struct omap_iommu
*obj
, struct cr_regs
*crs
, int num
)
116 struct iotlb_lock saved
;
118 struct cr_regs
*p
= crs
;
120 pm_runtime_get_sync(obj
->dev
);
121 iotlb_lock_get(obj
, &saved
);
123 for_each_iotlb_cr(obj
, num
, i
, tmp
) {
124 if (!iotlb_cr_valid(&tmp
))
129 iotlb_lock_set(obj
, &saved
);
130 pm_runtime_put_sync(obj
->dev
);
135 static ssize_t
iotlb_dump_cr(struct omap_iommu
*obj
, struct cr_regs
*cr
,
138 return seq_printf(s
, "%08x %08x %01x\n", cr
->cam
, cr
->ram
,
139 (cr
->cam
& MMU_CAM_P
) ? 1 : 0);
142 static size_t omap_dump_tlb_entries(struct omap_iommu
*obj
, struct seq_file
*s
)
147 num
= obj
->nr_tlb_entries
;
149 cr
= kcalloc(num
, sizeof(*cr
), GFP_KERNEL
);
153 num
= __dump_tlb_entries(obj
, cr
, num
);
154 for (i
= 0; i
< num
; i
++)
155 iotlb_dump_cr(obj
, cr
+ i
, s
);
161 static int debug_read_tlb(struct seq_file
*s
, void *data
)
163 struct omap_iommu
*obj
= s
->private;
165 if (is_omap_iommu_detached(obj
))
168 mutex_lock(&iommu_debug_lock
);
170 seq_printf(s
, "%8s %8s\n", "cam:", "ram:");
171 seq_puts(s
, "-----------------------------------------\n");
172 omap_dump_tlb_entries(obj
, s
);
174 mutex_unlock(&iommu_debug_lock
);
179 static void dump_ioptable(struct seq_file
*s
)
184 struct omap_iommu
*obj
= s
->private;
186 spin_lock(&obj
->page_table_lock
);
188 iopgd
= iopgd_offset(obj
, 0);
189 for (i
= 0; i
< PTRS_PER_IOPGD
; i
++, iopgd
++) {
193 if (!(*iopgd
& IOPGD_TABLE
)) {
194 da
= i
<< IOPGD_SHIFT
;
195 seq_printf(s
, "1: 0x%08x 0x%08x\n", da
, *iopgd
);
199 iopte
= iopte_offset(iopgd
, 0);
200 for (j
= 0; j
< PTRS_PER_IOPTE
; j
++, iopte
++) {
204 da
= (i
<< IOPGD_SHIFT
) + (j
<< IOPTE_SHIFT
);
205 seq_printf(s
, "2: 0x%08x 0x%08x\n", da
, *iopte
);
209 spin_unlock(&obj
->page_table_lock
);
212 static int debug_read_pagetable(struct seq_file
*s
, void *data
)
214 struct omap_iommu
*obj
= s
->private;
216 if (is_omap_iommu_detached(obj
))
219 mutex_lock(&iommu_debug_lock
);
221 seq_printf(s
, "L: %8s %8s\n", "da:", "pte:");
222 seq_puts(s
, "--------------------------\n");
225 mutex_unlock(&iommu_debug_lock
);
230 #define DEBUG_SEQ_FOPS_RO(name) \
231 static int debug_open_##name(struct inode *inode, struct file *file) \
233 return single_open(file, debug_read_##name, inode->i_private); \
236 static const struct file_operations debug_##name##_fops = { \
237 .open = debug_open_##name, \
239 .llseek = seq_lseek, \
240 .release = single_release, \
243 #define DEBUG_FOPS_RO(name) \
244 static const struct file_operations debug_##name##_fops = { \
245 .open = simple_open, \
246 .read = debug_read_##name, \
247 .llseek = generic_file_llseek, \
251 DEBUG_SEQ_FOPS_RO(tlb
);
252 DEBUG_SEQ_FOPS_RO(pagetable
);
254 #define __DEBUG_ADD_FILE(attr, mode) \
256 struct dentry *dent; \
257 dent = debugfs_create_file(#attr, mode, obj->debug_dir, \
258 obj, &debug_##attr##_fops); \
263 #define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 0400)
265 void omap_iommu_debugfs_add(struct omap_iommu
*obj
)
269 if (!iommu_debug_root
)
272 obj
->debug_dir
= debugfs_create_dir(obj
->name
, iommu_debug_root
);
276 d
= debugfs_create_u8("nr_tlb_entries", 0400, obj
->debug_dir
,
277 (u8
*)&obj
->nr_tlb_entries
);
281 DEBUG_ADD_FILE_RO(regs
);
282 DEBUG_ADD_FILE_RO(tlb
);
283 DEBUG_ADD_FILE_RO(pagetable
);
288 debugfs_remove_recursive(obj
->debug_dir
);
291 void omap_iommu_debugfs_remove(struct omap_iommu
*obj
)
296 debugfs_remove_recursive(obj
->debug_dir
);
299 void __init
omap_iommu_debugfs_init(void)
301 iommu_debug_root
= debugfs_create_dir("omap_iommu", NULL
);
302 if (!iommu_debug_root
)
303 pr_err("can't create debugfs dir\n");
306 void __exit
omap_iommu_debugfs_exit(void)
308 debugfs_remove(iommu_debug_root
);