From patchwork Wed Nov 21 05:08:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cho KyongHo X-Patchwork-Id: 1778201 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 73938DF288 for ; Wed, 21 Nov 2012 05:11:36 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tb2Yt-00062O-Ui; Wed, 21 Nov 2012 05:09:24 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tb2Xd-0005He-LS for linux-arm-kernel@lists.infradead.org; Wed, 21 Nov 2012 05:08:09 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MDT002QHNLAATN0@mailout4.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 21 Nov 2012 14:08:03 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [203.254.230.48]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id C3.9A.12699.3B16CA05; Wed, 21 Nov 2012 14:08:03 +0900 (KST) X-AuditID: cbfee61b-b7f616d00000319b-63-50ac61b3b1db Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 72.9A.12699.3B16CA05; Wed, 21 Nov 2012 14:08:03 +0900 (KST) Received: from DOPULLIPCHO06 ([12.23.118.152]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MDT00N47NLE1FA0@mmp2.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 21 Nov 2012 14:08:03 +0900 (KST) From: Cho KyongHo To: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 12/12] iommu/exynos: add debugfs entries for System MMU Date: Wed, 21 Nov 2012 14:08:02 +0900 Message-id: <003301cdc7a6$2ef0bd40$8cd237c0$%cho@samsung.com> MIME-version: 1.0 X-Mailer: Microsoft Office Outlook 12.0 Thread-index: Ac3Hpi7L+qK+q+WbQnW5/TTvTh6Icw== Content-language: ko DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPIsWRmVeSWpSXmKPExsVy+t8zA93NiWsCDA6dlrTY9PgaqwOjx+Yl 9QGMUVw2Kak5mWWpRfp2CVwZqzbZF5yxr/j0cRVbA+Meky5GTg4JAROJic+XsEPYYhIX7q1n 62Lk4hASWMYocX/vDhaYotblW9ghEtMZJY4v+APlLGeS+Pf7DhtIFZuAlsTquccZQRIiAr2M Ehf6vzKBOMwCPxglFr95wwxSJSzgJXF/3jOgDg4OFgFViWWXDEDCvAK2Eh279rND2IISPybf A1vNDDR0/c7jTBC2vMTmNW+ZQVolBNQlHv3VBQmLCOhJTPi1jhWiRERi34t3jCA2i4CAxLfJ h1ggymUlNh1gBrlGQqCfXeLq/mVMEJ9JShxccYNlAqPYLCSbZyHZPAvJ5llIVixgZFnFKJpa kFxQnJSea6RXnJhbXJqXrpecn7uJERIr0jsYVzVYHGIU4GBU4uGV2Lc6QIg1say4MvcQowQH s5IIL4P8mgAh3pTEyqrUovz4otKc1OJDjD5Al09klhJNzgfGcV5JvKGxsYmZiamJuaWpuSkO YSVx3maPlAAhgfTEktTs1NSC1CKYcUwcnFINjErPc3RLXzDH1aQ6rp6oubut8ZzSwilPSiw0 ZtwLsuOKVJ6o5X3ls+WaryZrvP+L3GSuDBFbHmL089JX1foFc6SMLe5tiqu5rLTiSz33qmTR BW+lBJYcOr1HtfjXV6du879xttevpx3XvSLkJW3QarxHZ59kdTfzyk4JzsLklA27xbtkBa7J KrEUZyQaajEXFScCAD+04ObCAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrHIsWRmVeSWpSXmKPExsVy+t9jQd3NiWsCDJY+FbTY9PgaqwOjx+Yl 9QGMUQ2MNhmpiSmpRQqpecn5KZl56bZK3sHxzvGmZgaGuoaWFuZKCnmJuam2Si4+AbpumTlA U5UUyhJzSoFCAYnFxUr6dpgmhIa46VrANEbo+oYEwfUYGaCBhHWMGas22Recsa/49HEVWwPj HpMuRk4OCQETidblW9ghbDGJC/fWs3UxcnEICUxnlDi+4A87hLOcSeLf7ztsIFVsAloSq+ce ZwRJiAj0Mkpc6P/KBOIwC/xglFj85g0zSJWwgJfE/XnPgDo4OFgEVCWWXTIACfMK2Ep07NrP DmELSvyYfI8FxGYGGrp+53EmCFteYvOat8wgrRIC6hKP/uqChEUE9CQm/FrHClEiIrHvxTvG CYwCs5BMmoVk0iwkk2YhaVnAyLKKUTS1ILmgOCk910ivODG3uDQvXS85P3cTIzgSn0nvYFzV YHGIUYCDUYmHV2Lf6gAh1sSy4srcQ4wSHMxKIrwM8msChHhTEiurUovy44tKc1KLDzH6AP05 kVlKNDkfmCTySuINjU3MjCyNzCyMTMzNcQgrifM2e6QECAmkJ5akZqemFqQWwYxj4uCUamA0 4Qk5fC9wFU/FCqlvNwIOsuf/Xfv0mEvKRMsIRyMusQy2rKtzDnaZK7FLrdJravOfKuPQzOk6 +cidhvNbHjQ4xznlrtn8OLyixfft4guB7Xz+55m3O7nUrG0NYb+bHvBn+bNS924Ge9ezbB8/ zD+8Qv/iSv9vOZWHRHWaWMMWN8xLPRr6jF+JpTgj0VCLuag4EQCfbsmy8QIAAA== X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121121_000808_090766_0715D736 X-CRM114-Status: GOOD ( 19.54 ) X-Spam-Score: -7.6 (-------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-7.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [203.254.224.34 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 T_MANY_HDRS_LCASE Odd capitalization of multiple message headers Cc: 'Kukjin Kim' , prathyush.k@samsung.com, 'Joerg Roedel' , sw0312.kim@samsung.com, 'Subash Patel' , 'Sanghyun Lee' , rahul.sharma@samsung.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This commit adds debugfs directory and nodes for inspecting internal state of System MMU. Change-Id: I4afcdd925609d381e7329ec118ffe52e38dc340e Signed-off-by: KyongHo Cho --- drivers/iommu/exynos-iommu.c | 204 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 198 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 886fae5..5dd49c6 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -26,12 +26,17 @@ #include #include #include +#include +#include +#include #include #include #include #include +#define MODULE_NAME "exynos-sysmmu" + /* We does not consider super section mapping (16MB) */ #define SECT_ORDER 20 #define LPAGE_ORDER 16 @@ -237,6 +242,7 @@ struct sysmmu_drvdata { spinlock_t lock; struct sysmmu_prefbuf pbufs[MAX_NUM_PBUF]; int num_pbufs; + struct dentry *debugfs_root; struct iommu_domain *domain; sysmmu_fault_handler_t fault_handler; unsigned long pgtable; @@ -1093,6 +1099,8 @@ static void __init __sysmmu_init_mmuname(struct device *sysmmu, } } +static void __create_debugfs_entry(struct sysmmu_drvdata *drvdata); + static int __init exynos_sysmmu_probe(struct platform_device *pdev) { int i, ret; @@ -1163,6 +1171,8 @@ static int __init exynos_sysmmu_probe(struct platform_device *pdev) __set_fault_handler(data, &default_fault_handler); + __create_debugfs_entry(data); + platform_set_drvdata(pdev, data); dev->archdata.iommu = &sysmmu_placeholder; @@ -1267,7 +1277,7 @@ static struct platform_driver exynos_sysmmu_driver __refdata = { .probe = exynos_sysmmu_probe, .driver = { .owner = THIS_MODULE, - .name = "exynos-sysmmu", + .name = MODULE_NAME, .pm = &__pm_ops, .of_match_table = of_match_ptr(sysmmu_of_match), } @@ -1644,6 +1654,8 @@ static struct iommu_ops exynos_iommu_ops = { .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE, }; +static struct dentry *sysmmu_debugfs_root; /* /sys/kernel/debug/sysmmu */ + static int __init exynos_iommu_init(void) { int ret; @@ -1655,17 +1667,197 @@ static int __init exynos_iommu_init(void) return -ENOMEM; } - ret = platform_driver_register(&exynos_sysmmu_driver); + ret = bus_set_iommu(&platform_bus_type, &exynos_iommu_ops); + if (ret) { + kmem_cache_destroy(lv2table_kmem_cache); + pr_err("%s: Failed to register IOMMU ops\n", __func__); + return -EFAULT; + } - if (ret == 0) - ret = bus_set_iommu(&platform_bus_type, &exynos_iommu_ops); + sysmmu_debugfs_root = debugfs_create_dir("sysmmu", NULL); + if (!sysmmu_debugfs_root) + pr_err("%s: Failed to create debugfs entry, 'sysmmu'\n", + __func__); + if (IS_ERR(sysmmu_debugfs_root)) + sysmmu_debugfs_root = NULL; + ret = platform_driver_register(&exynos_sysmmu_driver); if (ret) { - pr_err("%s: Failed to register exynos-iommu driver.\n", - __func__); kmem_cache_destroy(lv2table_kmem_cache); + pr_err("%s: Failed to register System MMU driver\n", __func__); } return ret; } subsys_initcall(exynos_iommu_init); + +static int debug_string_show(struct seq_file *s, void *unused) +{ + char *str = s->private; + + seq_printf(s, "%s\n", str); + + return 0; +} + +static int debug_sysmmu_list_show(struct seq_file *s, void *unused) +{ + struct sysmmu_drvdata *drvdata = s->private; + struct platform_device *pdev = to_platform_device(drvdata->sysmmu); + int idx, maj, min, ret; + + seq_printf(s, "SysMMU Name | Ver | SFR Base\n"); + + if (pm_runtime_enabled(drvdata->sysmmu)) { + ret = pm_runtime_get_sync(drvdata->sysmmu); + if (ret < 0) + return ret; + } + + for (idx = 0; idx < drvdata->nsfrs; idx++) { + struct resource *res; + + res = platform_get_resource(pdev, IORESOURCE_MEM, idx); + if (!res) + break; + + maj = __sysmmu_version(drvdata, idx, &min); + + if (drvdata->mmuname) { + if (maj == 0) + seq_printf(s, "%11.s | N/A | 0x%08x\n", + drvdata->mmuname[idx], res->start); + else + seq_printf(s, "%11.s | %d.%d | 0x%08x\n", + drvdata->mmuname[idx], maj, min, res->start); + } else { + if (maj == 0) + seq_printf(s, "N/A | 0x%08x\n", res->start); + else + seq_printf(s, "%d.%d | 0x%08x\n", + maj, min, res->start); + } + } + + if (pm_runtime_enabled(drvdata->sysmmu)) + pm_runtime_put(drvdata->sysmmu); + + return 0; +} + +static int debug_next_sibling_show(struct seq_file *s, void *unused) +{ + struct device *dev = s->private; + + if (dev->parent && + !strncmp(dev_name(dev->parent), + MODULE_NAME, strlen(MODULE_NAME))) + seq_printf(s, "%s\n", dev_name(dev->parent)); + return 0; +} + +static int __show_master(struct device *dev, void *data) +{ + struct seq_file *s = data; + + if (strncmp(dev_name(dev), MODULE_NAME, strlen(MODULE_NAME))) + seq_printf(s, "%s\n", dev_name(dev)); + return 0; +} + +static int debug_master_show(struct seq_file *s, void *unused) +{ + struct device *dev = s->private; + + device_for_each_child(dev, s, __show_master); + return 0; +} + +static int debug_string_open(struct inode *inode, struct file *file) +{ + return single_open(file, debug_string_show, inode->i_private); +} + +static int debug_sysmmu_list_open(struct inode *inode, struct file *file) +{ + return single_open(file, debug_sysmmu_list_show, inode->i_private); +} + +static int debug_next_sibling_open(struct inode *inode, struct file *file) +{ + return single_open(file, debug_next_sibling_show, inode->i_private); +} + +static int debug_master_open(struct inode *inode, struct file *file) +{ + return single_open(file, debug_master_show, inode->i_private); +} + +static const struct file_operations debug_string_fops = { + .open = debug_string_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static const struct file_operations debug_sysmmu_list_fops = { + .open = debug_sysmmu_list_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static const struct file_operations debug_next_sibling_fops = { + .open = debug_next_sibling_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static const struct file_operations debug_master_fops = { + .open = debug_master_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static void __init __create_debugfs_entry(struct sysmmu_drvdata *drvdata) +{ + if (!sysmmu_debugfs_root) + return; + + drvdata->debugfs_root = debugfs_create_dir(dev_name(drvdata->sysmmu), + sysmmu_debugfs_root); + if (!drvdata->debugfs_root) + dev_err(drvdata->sysmmu, "Failed to create debugfs dentry\n"); + if (IS_ERR(drvdata->debugfs_root)) + drvdata->debugfs_root = NULL; + + if (!drvdata->debugfs_root) + return; + + if (!debugfs_create_u32("enable", 0664, drvdata->debugfs_root, + &drvdata->activations)) + dev_err(drvdata->sysmmu, + "Failed to create debugfs file 'enable'\n"); + + if (!debugfs_create_x32("pagetable", 0664, drvdata->debugfs_root, + (u32 *)&drvdata->pgtable)) + dev_err(drvdata->sysmmu, + "Failed to create debugfs file 'pagetable'\n"); + + if (!debugfs_create_file("sysmmu_list", 0444, drvdata->debugfs_root, + drvdata, &debug_sysmmu_list_fops)) + dev_err(drvdata->sysmmu, + "Failed to create debugfs file 'sysmmu_list'\n"); + + if (!debugfs_create_file("next_sibling", 0x444, drvdata->debugfs_root, + drvdata->sysmmu, &debug_next_sibling_fops)) + dev_err(drvdata->sysmmu, + "Failed to create debugfs file 'next_siblings'\n"); + + if (!debugfs_create_file("master", 0x444, drvdata->debugfs_root, + drvdata->sysmmu, &debug_master_fops)) + dev_err(drvdata->sysmmu, + "Failed to create debugfs file 'next_siblings'\n"); +}