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/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 ssize_t
debug_read_regs(struct file
*file
, char __user
*userbuf
,
28 size_t count
, loff_t
*ppos
)
30 struct omap_iommu
*obj
= file
->private_data
;
34 buf
= kmalloc(count
, GFP_KERNEL
);
39 mutex_lock(&iommu_debug_lock
);
41 bytes
= omap_iommu_dump_ctx(obj
, p
, count
);
42 bytes
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, bytes
);
44 mutex_unlock(&iommu_debug_lock
);
50 static ssize_t
debug_read_tlb(struct file
*file
, char __user
*userbuf
,
51 size_t count
, loff_t
*ppos
)
53 struct omap_iommu
*obj
= file
->private_data
;
57 buf
= kmalloc(count
, GFP_KERNEL
);
62 mutex_lock(&iommu_debug_lock
);
64 p
+= sprintf(p
, "%8s %8s\n", "cam:", "ram:");
65 p
+= sprintf(p
, "-----------------------------------------\n");
66 rest
= count
- (p
- buf
);
67 p
+= omap_dump_tlb_entries(obj
, p
, rest
);
69 bytes
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, p
- buf
);
71 mutex_unlock(&iommu_debug_lock
);
77 #define dump_ioptable_entry_one(lv, da, val) \
81 const int maxcol = 22; \
82 const char *str = "%d: %08x %08x\n"; \
83 bytes = snprintf(p, maxcol, str, lv, da, val); \
91 static ssize_t
dump_ioptable(struct omap_iommu
*obj
, char *buf
, ssize_t len
)
97 spin_lock(&obj
->page_table_lock
);
99 iopgd
= iopgd_offset(obj
, 0);
100 for (i
= 0; i
< PTRS_PER_IOPGD
; i
++, iopgd
++) {
108 if (!(*iopgd
& IOPGD_TABLE
)) {
109 da
= i
<< IOPGD_SHIFT
;
111 err
= dump_ioptable_entry_one(1, da
, *iopgd
);
117 iopte
= iopte_offset(iopgd
, 0);
119 for (j
= 0; j
< PTRS_PER_IOPTE
; j
++, iopte
++) {
123 da
= (i
<< IOPGD_SHIFT
) + (j
<< IOPTE_SHIFT
);
124 err
= dump_ioptable_entry_one(2, da
, *iopgd
);
130 spin_unlock(&obj
->page_table_lock
);
135 static ssize_t
debug_read_pagetable(struct file
*file
, char __user
*userbuf
,
136 size_t count
, loff_t
*ppos
)
138 struct omap_iommu
*obj
= file
->private_data
;
142 buf
= (char *)__get_free_page(GFP_KERNEL
);
147 p
+= sprintf(p
, "L: %8s %8s\n", "da:", "pa:");
148 p
+= sprintf(p
, "-----------------------------------------\n");
150 mutex_lock(&iommu_debug_lock
);
152 bytes
= PAGE_SIZE
- (p
- buf
);
153 p
+= dump_ioptable(obj
, p
, bytes
);
155 bytes
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, p
- buf
);
157 mutex_unlock(&iommu_debug_lock
);
158 free_page((unsigned long)buf
);
163 #define DEBUG_FOPS_RO(name) \
164 static const struct file_operations debug_##name##_fops = { \
165 .open = simple_open, \
166 .read = debug_read_##name, \
167 .llseek = generic_file_llseek, \
172 DEBUG_FOPS_RO(pagetable
);
174 #define __DEBUG_ADD_FILE(attr, mode) \
176 struct dentry *dent; \
177 dent = debugfs_create_file(#attr, mode, obj->debug_dir, \
178 obj, &debug_##attr##_fops); \
183 #define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 0400)
185 void omap_iommu_debugfs_add(struct omap_iommu
*obj
)
189 if (!iommu_debug_root
)
192 obj
->debug_dir
= debugfs_create_dir(obj
->name
, iommu_debug_root
);
196 d
= debugfs_create_u8("nr_tlb_entries", 0400, obj
->debug_dir
,
197 (u8
*)&obj
->nr_tlb_entries
);
201 DEBUG_ADD_FILE_RO(regs
);
202 DEBUG_ADD_FILE_RO(tlb
);
203 DEBUG_ADD_FILE_RO(pagetable
);
208 debugfs_remove_recursive(obj
->debug_dir
);
211 void omap_iommu_debugfs_remove(struct omap_iommu
*obj
)
216 debugfs_remove_recursive(obj
->debug_dir
);
219 void __init
omap_iommu_debugfs_init(void)
221 iommu_debug_root
= debugfs_create_dir("omap_iommu", NULL
);
222 if (!iommu_debug_root
)
223 pr_err("can't create debugfs dir\n");
226 void __exit
omap_iommu_debugfs_exit(void)
228 debugfs_remove(iommu_debug_root
);
This page took 0.04228 seconds and 5 git commands to generate.