Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * omap iommu: debugfs interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2008-2009 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/platform_data/iommu-omap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "omap-iopgtable.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "omap-iommu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static DEFINE_MUTEX(iommu_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static struct dentry *iommu_debug_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static inline bool is_omap_iommu_detached(struct omap_iommu *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	return !obj->domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define pr_reg(name)							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		ssize_t bytes;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		const char *str = "%20s: %08x\n";			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		const int maxcol = 32;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		bytes = snprintf(p, maxcol, str, __stringify(name),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 				 iommu_read_reg(obj, MMU_##name));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		p += bytes;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		len -= bytes;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		if (len < maxcol)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			goto out;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) omap2_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	pr_reg(REVISION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	pr_reg(IRQSTATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	pr_reg(IRQENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	pr_reg(WALKING_ST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	pr_reg(CNTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	pr_reg(FAULT_AD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	pr_reg(TTB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	pr_reg(LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	pr_reg(LD_TLB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	pr_reg(CAM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	pr_reg(RAM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	pr_reg(GFLUSH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	pr_reg(FLUSH_ENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	pr_reg(READ_CAM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	pr_reg(READ_RAM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	pr_reg(EMU_FAULT_AD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	return p - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static ssize_t omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 				   ssize_t bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (!obj || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	pm_runtime_get_sync(obj->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	bytes = omap2_iommu_dump_ctx(obj, buf, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	pm_runtime_put_sync(obj->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static ssize_t debug_read_regs(struct file *file, char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			       size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct omap_iommu *obj = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	char *p, *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	ssize_t bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (is_omap_iommu_detached(obj))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	buf = kmalloc(count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	mutex_lock(&iommu_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	bytes = omap_iommu_dump_ctx(obj, p, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (bytes < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	bytes = simple_read_from_buffer(userbuf, count, ppos, buf, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	mutex_unlock(&iommu_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) __dump_tlb_entries(struct omap_iommu *obj, struct cr_regs *crs, int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct iotlb_lock saved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct cr_regs tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct cr_regs *p = crs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	pm_runtime_get_sync(obj->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	iotlb_lock_get(obj, &saved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	for_each_iotlb_cr(obj, num, i, tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		if (!iotlb_cr_valid(&tmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		*p++ = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	iotlb_lock_set(obj, &saved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	pm_runtime_put_sync(obj->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return  p - crs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static ssize_t iotlb_dump_cr(struct omap_iommu *obj, struct cr_regs *cr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			     struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	seq_printf(s, "%08x %08x %01x\n", cr->cam, cr->ram,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		   (cr->cam & MMU_CAM_P) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static size_t omap_dump_tlb_entries(struct omap_iommu *obj, struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	int i, num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct cr_regs *cr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	num = obj->nr_tlb_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	cr = kcalloc(num, sizeof(*cr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (!cr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	num = __dump_tlb_entries(obj, cr, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	for (i = 0; i < num; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		iotlb_dump_cr(obj, cr + i, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	kfree(cr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static int tlb_show(struct seq_file *s, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	struct omap_iommu *obj = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (is_omap_iommu_detached(obj))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	mutex_lock(&iommu_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	seq_printf(s, "%8s %8s\n", "cam:", "ram:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	seq_puts(s, "-----------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	omap_dump_tlb_entries(obj, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	mutex_unlock(&iommu_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static void dump_ioptable(struct seq_file *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	u32 da;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	u32 *iopgd, *iopte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct omap_iommu *obj = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	spin_lock(&obj->page_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	iopgd = iopgd_offset(obj, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	for (i = 0; i < PTRS_PER_IOPGD; i++, iopgd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		if (!*iopgd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		if (!(*iopgd & IOPGD_TABLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			da = i << IOPGD_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			seq_printf(s, "1: 0x%08x 0x%08x\n", da, *iopgd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		iopte = iopte_offset(iopgd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		for (j = 0; j < PTRS_PER_IOPTE; j++, iopte++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			if (!*iopte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			da = (i << IOPGD_SHIFT) + (j << IOPTE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			seq_printf(s, "2: 0x%08x 0x%08x\n", da, *iopte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	spin_unlock(&obj->page_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static int pagetable_show(struct seq_file *s, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	struct omap_iommu *obj = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (is_omap_iommu_detached(obj))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	mutex_lock(&iommu_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	seq_printf(s, "L: %8s %8s\n", "da:", "pte:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	seq_puts(s, "--------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	dump_ioptable(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	mutex_unlock(&iommu_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #define DEBUG_FOPS_RO(name)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	static const struct file_operations name##_fops = {	        \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		.open = simple_open,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		.read = debug_read_##name,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		.llseek = generic_file_llseek,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) DEBUG_FOPS_RO(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) DEFINE_SHOW_ATTRIBUTE(tlb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) DEFINE_SHOW_ATTRIBUTE(pagetable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) void omap_iommu_debugfs_add(struct omap_iommu *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct dentry *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (!iommu_debug_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	d = debugfs_create_dir(obj->name, iommu_debug_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	obj->debug_dir = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	debugfs_create_u32("nr_tlb_entries", 0400, d, &obj->nr_tlb_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	debugfs_create_file("regs", 0400, d, obj, &regs_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	debugfs_create_file("tlb", 0400, d, obj, &tlb_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	debugfs_create_file("pagetable", 0400, d, obj, &pagetable_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) void omap_iommu_debugfs_remove(struct omap_iommu *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (!obj->debug_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	debugfs_remove_recursive(obj->debug_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) void __init omap_iommu_debugfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	iommu_debug_root = debugfs_create_dir("omap_iommu", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) void __exit omap_iommu_debugfs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	debugfs_remove(iommu_debug_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }