Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * omap iommu: debugfs interface |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 Nokia Corporation |
| 5 | * |
| 6 | * 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 | */ |
| 12 | |
| 13 | #include <linux/err.h> |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 14 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 16 | #include <linux/uaccess.h> |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 17 | #include <linux/debugfs.h> |
Tony Lindgren | 2ab7c84 | 2012-11-02 12:24:14 -0700 | [diff] [blame] | 18 | #include <linux/platform_data/iommu-omap.h> |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 19 | |
Ido Yariv | 2f7702a | 2012-11-02 12:24:00 -0700 | [diff] [blame] | 20 | #include "omap-iopgtable.h" |
Tony Lindgren | ed1c7de | 2012-11-02 12:24:06 -0700 | [diff] [blame] | 21 | #include "omap-iommu.h" |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 22 | |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 23 | static DEFINE_MUTEX(iommu_debug_lock); |
| 24 | |
| 25 | static struct dentry *iommu_debug_root; |
| 26 | |
Suman Anna | c5cf5c5 | 2014-10-22 17:22:34 -0500 | [diff] [blame] | 27 | static inline bool is_omap_iommu_detached(struct omap_iommu *obj) |
| 28 | { |
| 29 | return !obj->domain; |
| 30 | } |
| 31 | |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 32 | static ssize_t debug_read_regs(struct file *file, char __user *userbuf, |
| 33 | size_t count, loff_t *ppos) |
| 34 | { |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 35 | struct omap_iommu *obj = file->private_data; |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 36 | char *p, *buf; |
| 37 | ssize_t bytes; |
| 38 | |
Suman Anna | c5cf5c5 | 2014-10-22 17:22:34 -0500 | [diff] [blame] | 39 | if (is_omap_iommu_detached(obj)) |
| 40 | return -EPERM; |
| 41 | |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 42 | buf = kmalloc(count, GFP_KERNEL); |
| 43 | if (!buf) |
| 44 | return -ENOMEM; |
| 45 | p = buf; |
| 46 | |
| 47 | mutex_lock(&iommu_debug_lock); |
| 48 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 49 | bytes = omap_iommu_dump_ctx(obj, p, count); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 50 | bytes = simple_read_from_buffer(userbuf, count, ppos, buf, bytes); |
| 51 | |
| 52 | mutex_unlock(&iommu_debug_lock); |
| 53 | kfree(buf); |
| 54 | |
| 55 | return bytes; |
| 56 | } |
| 57 | |
| 58 | static ssize_t debug_read_tlb(struct file *file, char __user *userbuf, |
| 59 | size_t count, loff_t *ppos) |
| 60 | { |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 61 | struct omap_iommu *obj = file->private_data; |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 62 | char *p, *buf; |
| 63 | ssize_t bytes, rest; |
| 64 | |
Suman Anna | c5cf5c5 | 2014-10-22 17:22:34 -0500 | [diff] [blame] | 65 | if (is_omap_iommu_detached(obj)) |
| 66 | return -EPERM; |
| 67 | |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 68 | buf = kmalloc(count, GFP_KERNEL); |
| 69 | if (!buf) |
| 70 | return -ENOMEM; |
| 71 | p = buf; |
| 72 | |
| 73 | mutex_lock(&iommu_debug_lock); |
| 74 | |
| 75 | p += sprintf(p, "%8s %8s\n", "cam:", "ram:"); |
| 76 | p += sprintf(p, "-----------------------------------------\n"); |
| 77 | rest = count - (p - buf); |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 78 | p += omap_dump_tlb_entries(obj, p, rest); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 79 | |
| 80 | bytes = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf); |
| 81 | |
| 82 | mutex_unlock(&iommu_debug_lock); |
| 83 | kfree(buf); |
| 84 | |
| 85 | return bytes; |
| 86 | } |
| 87 | |
Suman Anna | 9c83e9f | 2014-10-22 17:22:35 -0500 | [diff] [blame] | 88 | static void dump_ioptable(struct seq_file *s) |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 89 | { |
Suman Anna | 9c83e9f | 2014-10-22 17:22:35 -0500 | [diff] [blame] | 90 | int i, j; |
| 91 | u32 da; |
| 92 | u32 *iopgd, *iopte; |
| 93 | struct omap_iommu *obj = s->private; |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 94 | |
| 95 | spin_lock(&obj->page_table_lock); |
| 96 | |
| 97 | iopgd = iopgd_offset(obj, 0); |
| 98 | for (i = 0; i < PTRS_PER_IOPGD; i++, iopgd++) { |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 99 | if (!*iopgd) |
| 100 | continue; |
| 101 | |
| 102 | if (!(*iopgd & IOPGD_TABLE)) { |
| 103 | da = i << IOPGD_SHIFT; |
Suman Anna | 9c83e9f | 2014-10-22 17:22:35 -0500 | [diff] [blame] | 104 | seq_printf(s, "1: 0x%08x 0x%08x\n", da, *iopgd); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 105 | continue; |
| 106 | } |
| 107 | |
| 108 | iopte = iopte_offset(iopgd, 0); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 109 | for (j = 0; j < PTRS_PER_IOPTE; j++, iopte++) { |
| 110 | if (!*iopte) |
| 111 | continue; |
| 112 | |
| 113 | da = (i << IOPGD_SHIFT) + (j << IOPTE_SHIFT); |
Suman Anna | 9c83e9f | 2014-10-22 17:22:35 -0500 | [diff] [blame] | 114 | seq_printf(s, "2: 0x%08x 0x%08x\n", da, *iopte); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 115 | } |
| 116 | } |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 117 | |
Suman Anna | 9c83e9f | 2014-10-22 17:22:35 -0500 | [diff] [blame] | 118 | spin_unlock(&obj->page_table_lock); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Suman Anna | 9c83e9f | 2014-10-22 17:22:35 -0500 | [diff] [blame] | 121 | static int debug_read_pagetable(struct seq_file *s, void *data) |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 122 | { |
Suman Anna | 9c83e9f | 2014-10-22 17:22:35 -0500 | [diff] [blame] | 123 | struct omap_iommu *obj = s->private; |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 124 | |
Suman Anna | c5cf5c5 | 2014-10-22 17:22:34 -0500 | [diff] [blame] | 125 | if (is_omap_iommu_detached(obj)) |
| 126 | return -EPERM; |
| 127 | |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 128 | mutex_lock(&iommu_debug_lock); |
| 129 | |
Suman Anna | 9c83e9f | 2014-10-22 17:22:35 -0500 | [diff] [blame] | 130 | seq_printf(s, "L: %8s %8s\n", "da:", "pte:"); |
| 131 | seq_puts(s, "--------------------------\n"); |
| 132 | dump_ioptable(s); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 133 | |
| 134 | mutex_unlock(&iommu_debug_lock); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 135 | |
Suman Anna | 9c83e9f | 2014-10-22 17:22:35 -0500 | [diff] [blame] | 136 | return 0; |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Suman Anna | 9c83e9f | 2014-10-22 17:22:35 -0500 | [diff] [blame] | 139 | #define DEBUG_SEQ_FOPS_RO(name) \ |
| 140 | static int debug_open_##name(struct inode *inode, struct file *file) \ |
| 141 | { \ |
| 142 | return single_open(file, debug_read_##name, inode->i_private); \ |
| 143 | } \ |
| 144 | \ |
| 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, \ |
| 150 | } |
| 151 | |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 152 | #define DEBUG_FOPS_RO(name) \ |
| 153 | static const struct file_operations debug_##name##_fops = { \ |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 154 | .open = simple_open, \ |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 155 | .read = debug_read_##name, \ |
Arnd Bergmann | c0b0aca | 2010-07-06 19:16:33 +0200 | [diff] [blame] | 156 | .llseek = generic_file_llseek, \ |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 157 | }; |
| 158 | |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 159 | DEBUG_FOPS_RO(regs); |
| 160 | DEBUG_FOPS_RO(tlb); |
Suman Anna | 9c83e9f | 2014-10-22 17:22:35 -0500 | [diff] [blame] | 161 | DEBUG_SEQ_FOPS_RO(pagetable); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 162 | |
| 163 | #define __DEBUG_ADD_FILE(attr, mode) \ |
| 164 | { \ |
| 165 | struct dentry *dent; \ |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 166 | dent = debugfs_create_file(#attr, mode, obj->debug_dir, \ |
| 167 | obj, &debug_##attr##_fops); \ |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 168 | if (!dent) \ |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 169 | goto err; \ |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Joe Perches | ff3a2b7 | 2014-02-25 15:01:40 -0800 | [diff] [blame] | 172 | #define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 0400) |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 173 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 174 | void omap_iommu_debugfs_add(struct omap_iommu *obj) |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 175 | { |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 176 | struct dentry *d; |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 177 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 178 | if (!iommu_debug_root) |
| 179 | return; |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 180 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 181 | obj->debug_dir = debugfs_create_dir(obj->name, iommu_debug_root); |
| 182 | if (!obj->debug_dir) |
| 183 | return; |
Ohad Ben-Cohen | 46451d6 | 2012-02-22 10:52:51 +0200 | [diff] [blame] | 184 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 185 | d = debugfs_create_u8("nr_tlb_entries", 0400, obj->debug_dir, |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 186 | (u8 *)&obj->nr_tlb_entries); |
| 187 | if (!d) |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 188 | return; |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 189 | |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 190 | DEBUG_ADD_FILE_RO(regs); |
| 191 | DEBUG_ADD_FILE_RO(tlb); |
Suman Anna | 3ca5db0 | 2014-10-22 17:22:29 -0500 | [diff] [blame] | 192 | DEBUG_ADD_FILE_RO(pagetable); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 193 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 194 | return; |
Ohad Ben-Cohen | 46451d6 | 2012-02-22 10:52:51 +0200 | [diff] [blame] | 195 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 196 | err: |
| 197 | debugfs_remove_recursive(obj->debug_dir); |
Ohad Ben-Cohen | 46451d6 | 2012-02-22 10:52:51 +0200 | [diff] [blame] | 198 | } |
| 199 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 200 | void omap_iommu_debugfs_remove(struct omap_iommu *obj) |
Ohad Ben-Cohen | 46451d6 | 2012-02-22 10:52:51 +0200 | [diff] [blame] | 201 | { |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 202 | if (!obj->debug_dir) |
| 203 | return; |
Ohad Ben-Cohen | 46451d6 | 2012-02-22 10:52:51 +0200 | [diff] [blame] | 204 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 205 | debugfs_remove_recursive(obj->debug_dir); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 208 | void __init omap_iommu_debugfs_init(void) |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 209 | { |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 210 | iommu_debug_root = debugfs_create_dir("omap_iommu", NULL); |
| 211 | if (!iommu_debug_root) |
| 212 | pr_err("can't create debugfs dir\n"); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 213 | } |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 214 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 215 | void __exit omap_iommu_debugfs_exit(void) |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 216 | { |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 217 | debugfs_remove(iommu_debug_root); |
Hiroshi DOYU | 14e0e67 | 2009-08-28 10:54:41 -0700 | [diff] [blame] | 218 | } |