From patchwork Wed Dec 26 01:53:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cho KyongHo X-Patchwork-Id: 1910391 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 78F77DF23A for ; Wed, 26 Dec 2012 01:57:42 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TngBv-0000sF-13; Wed, 26 Dec 2012 01:53:55 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TngBX-0000oH-8i for linux-arm-kernel@lists.infradead.org; Wed, 26 Dec 2012 01:53:34 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MFM001H87WEIIE0@mailout3.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 26 Dec 2012 10:53:30 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [203.254.230.51]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id CB.E5.01231.A985AD05; Wed, 26 Dec 2012 10:53:30 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-56-50da589aeea9 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 0B.E5.01231.A985AD05; Wed, 26 Dec 2012 10:53:30 +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 <0MFM00MY67X5BY10@mmp2.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 26 Dec 2012 10:53:30 +0900 (KST) From: Cho KyongHo To: 'Linux ARM Kernel' , 'Linux IOMMU' , 'Linux Kernel' , 'Linux Samsung SOC' Subject: [PATCH v6 02/12] iommu/exynos: always use iommu fault handler Date: Wed, 26 Dec 2012 10:53:29 +0900 Message-id: <003501cde30b$cdc07520$69415f60$%cho@samsung.com> MIME-version: 1.0 X-Mailer: Microsoft Office Outlook 12.0 Thread-index: Ac3jC82lFoLN8Dj6S2GS7YL9/Bztqw== Content-language: ko DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrDIsWRmVeSWpSXmKPExsVy+t8zY91ZEbcCDOZ+FrTY9PgaqwOjx+Yl 9QGMUVw2Kak5mWWpRfp2CVwZp1uXsRV8MaiYteEwWwNjs0YXIyeHhICJxPSlB1kgbDGJC/fW s3UxcnEICSxjlLjw9S8jTNG1H58YIRLTGSVe79jEBpIQEljOJNGyOwTEZhPQklg99zhYg4jA XUaJl+d5QBqYBf4ySnw6c4i9i5GDQ1jATeJ/hwSIySKgKjFjMViUV8BWYupVDpBOXgFBiR+T 74HdwyxgIPF+Vh8rhC0vsXnNW2aQcgkBdYlHf3UhFulJtO84ygZRIiKx78U7sANYBAQkvk0+ xAJRLiux6QAzyC0SAt3sEgee32CF+EpS4uCKGywTGMVmIdk8C8nmWUg2z0KyYgEjyypG0dSC 5ILipPRcQ73ixNzi0rx0veT83E2MkCiR2sG4ssHiEKMAB6MSD+/G7zcDhFgTy4orcw8xSnAw K4nwOn8ECvGmJFZWpRblxxeV5qQWH2L0Abp8IrOUaHI+MILzSuINjY1NzExMTcwtTc1NcQgr ifM2e6QECAmkJ5akZqemFqQWwYxj4uCUamA0etXLbHx9KrPYwoutG/zSprnN/L3wgehlx+cG xR97p0VtaDHo4M/nkpsuu1b598TTex7pvvm2RNOJ29M+jb/01s2WVcsSshPtZ3ncucv1IE34 m2MC8/55Z+XSHsq6JN+1F7wR0O77hevBK+2wyRc104O+TT/tcbkk+O6UmDc9yqyrhGpPvX+v xFKckWioxVxUnAgAPltql78CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrNIsWRmVeSWpSXmKPExsVy+t9jQd1ZEbcCDI784LbY9PgaqwOjx+Yl 9QGMUQ2MNhmpiSmpRQqpecn5KZl56bZK3sHxzvGmZgaGuoaWFuZKCnmJuam2Si4+AbpumTlA U5UUyhJzSoFCAYnFxUr6dpgmhIa46VrANEbo+oYEwfUYGaCBhHWMGadbl7EVfDGomLXhMFsD Y7NGFyMnh4SAicS1H58YIWwxiQv31rN1MXJxCAlMZ5R4vWMTG0hCSGA5k0TL7hAQm01AS2L1 3ONgDSICdxklXp7nAWlgFvjLKPHpzCH2LkYODmEBN4n/HRIgJouAqsSMxWBRXgFbialXOUA6 eQUEJX5MvscCYjMLGEi8n9XHCmHLS2xe85YZpFxCQF3i0V9diEV6Eu07jrJBlIhI7HvxjnEC o8AsJJNmIZk0C8mkWUhaFjCyrGIUTS1ILihOSs811CtOzC0uzUvXS87P3cQIjsFnUjsYVzZY HGIU4GBU4uHd+P1mgBBrYllxZe4hRgkOZiURXuePQCHelMTKqtSi/Pii0pzU4kOMPkBvTmSW Ek3OB6aHvJJ4Q2MTMyNLIzMLIxNzcxzCSuK8zR4pAUIC6YklqdmpqQWpRTDjmDg4pRoYz0V6 Oemfudrx0nyL7/rrz5SFjzuaVK6TlJHJX6+Wt20/042jV8qf+zzc/MDweoFrYKdR7p2YuHdb FKPmnjhYbHhh9cLb3y+3T3ix/GDSrGv//NnSLh1+mbnWNult1u3sOwoz71TaNQbv/75JJfuB 7X/m4vQo8WUlOu+DNzl/T8xMZfH58M72ghJLcUaioRZzUXEiAE5ZldnuAgAA X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121225_205333_045733_3DA2B31C X-CRM114-Status: GOOD ( 15.75 ) 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.33 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' , 'Hyunwoong Kim' , 'Prathyush' , 'Joerg Roedel' , 'Subash Patel' , 'Rahul Sharma' 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 removes fault handler definition only for exynos-iommu driver. Instead, always call iommu fault handler when a fault is generated by a System MMU. Every new iommu_domain will have a default fault handler and it can be overridden with iommu_set_fault_handler(). The default fault handler also generates debugging messages and kernel woops. Signed-off-by: KyongHo Cho --- drivers/iommu/exynos-iommu.c | 99 ++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 63 deletions(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index b96f3b9..ef7dbd1 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -124,16 +124,6 @@ enum exynos_sysmmu_inttype { SYSMMU_FAULTS_NUM }; -/* - * @itype: type of fault. - * @pgtable_base: the physical address of page table base. This is 0 if @itype - * is SYSMMU_BUSERROR. - * @fault_addr: the device (virtual) address that the System MMU tried to - * translated. This is 0 if @itype is SYSMMU_BUSERROR. - */ -typedef int (*sysmmu_fault_handler_t)(enum exynos_sysmmu_inttype itype, - unsigned long pgtable_base, unsigned long fault_addr); - static unsigned short fault_reg_offset[SYSMMU_FAULTS_NUM] = { REG_PAGE_FAULT_ADDR, REG_AR_FAULT_ADDR, @@ -176,7 +166,6 @@ struct sysmmu_drvdata { int activations; rwlock_t lock; struct iommu_domain *domain; - sysmmu_fault_handler_t fault_handler; unsigned long pgtable; }; @@ -291,48 +280,23 @@ finish: read_unlock_irqrestore(&data->lock, flags); } -static void __set_fault_handler(struct sysmmu_drvdata *data, - sysmmu_fault_handler_t handler) -{ - unsigned long flags; - - write_lock_irqsave(&data->lock, flags); - data->fault_handler = handler; - write_unlock_irqrestore(&data->lock, flags); -} - -void exynos_sysmmu_set_fault_handler(struct device *dev, - sysmmu_fault_handler_t handler) -{ - struct sysmmu_drvdata *data = dev_get_drvdata(dev->archdata.iommu); - - __set_fault_handler(data, handler); -} - -static int default_fault_handler(enum exynos_sysmmu_inttype itype, - unsigned long pgtable_base, unsigned long fault_addr) +static void __show_fault_information(unsigned long *pgtable, unsigned long iova, + int flags) { unsigned long *ent; - if ((itype >= SYSMMU_FAULTS_NUM) || (itype < SYSMMU_PAGEFAULT)) - itype = SYSMMU_FAULT_UNKNOWN; - pr_err("%s occurred at 0x%lx(Page table base: 0x%lx)\n", - sysmmu_fault_name[itype], fault_addr, pgtable_base); + sysmmu_fault_name[flags], iova, __pa(pgtable)); - ent = section_entry(__va(pgtable_base), fault_addr); + ent = section_entry(pgtable, iova); pr_err("\tLv1 entry: 0x%lx\n", *ent); if (lv1ent_page(ent)) { - ent = page_entry(ent, fault_addr); + ent = page_entry(ent, iova); pr_err("\t Lv2 entry: 0x%lx\n", *ent); } pr_err("Generating Kernel OOPS... because it is unrecoverable.\n"); - - BUG(); - - return 0; } static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id) @@ -341,7 +305,7 @@ static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id) struct sysmmu_drvdata *data = dev_id; struct resource *irqres; struct platform_device *pdev; - enum exynos_sysmmu_inttype itype; + enum exynos_sysmmu_inttype itype = SYSMMU_FAULT_UNKNOWN; unsigned long addr = -1; int i, ret = -ENOSYS; @@ -357,9 +321,7 @@ static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id) break; } - if (i == pdev->num_resources) { - itype = SYSMMU_FAULT_UNKNOWN; - } else { + if (i < pdev->num_resources) { itype = (enum exynos_sysmmu_inttype) __ffs(__raw_readl(data->sfrbases[i] + REG_INT_STATUS)); if (WARN_ON(!((itype >= 0) && (itype < SYSMMU_FAULT_UNKNOWN)))) @@ -370,25 +332,25 @@ static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id) } if (data->domain) - ret = report_iommu_fault(data->domain, data->dev, - addr, itype); - - if ((ret == -ENOSYS) && data->fault_handler) { - unsigned long base = data->pgtable; - if (itype != SYSMMU_FAULT_UNKNOWN) - base = __raw_readl( - data->sfrbases[i] + REG_PT_BASE_ADDR); - ret = data->fault_handler(itype, base, addr); - } - - if (!ret && (itype != SYSMMU_FAULT_UNKNOWN)) + ret = report_iommu_fault(data->domain, data->dev, addr, itype); + else + __show_fault_information(__va(data->pgtable), itype, addr); + + if (ret == -ENOSYS) + pr_err("NO SYSTEM MMU FAULT HANDLER REGISTERED FOR %s\n", + dev_name(data->dev)); + else if (ret < 0) + pr_err("SYSTEM MMU FAULT HANDLER FOR %s RETURNED ERROR, %d\n", + dev_name(data->dev), ret); + else if (itype != SYSMMU_FAULT_UNKNOWN) __raw_writel(1 << itype, data->sfrbases[i] + REG_INT_CLEAR); else - dev_dbg(data->sysmmu, "(%s) %s is not handled.\n", - data->dbgname, sysmmu_fault_name[itype]); + ret = -ENOSYS; - if (itype != SYSMMU_FAULT_UNKNOWN) - sysmmu_unblock(data->sfrbases[i]); + if (ret) + BUG(); + + sysmmu_unblock(data->sfrbases[i]); read_unlock(&data->lock); @@ -668,8 +630,6 @@ static int exynos_sysmmu_probe(struct platform_device *pdev) rwlock_init(&data->lock); INIT_LIST_HEAD(&data->node); - __set_fault_handler(data, &default_fault_handler); - if (dev->parent) pm_runtime_enable(dev); @@ -708,6 +668,17 @@ static inline void pgtable_flush(void *vastart, void *vaend) virt_to_phys(vaend)); } +static int exynos_iommu_fault_handler(struct iommu_domain *domain, + struct device *dev, unsigned long iova, int flags, void *token) +{ + struct exynos_iommu_domain *priv = domain->priv; + + dev_err(dev, "System MMU Generated FAULT!\n\n"); + __show_fault_information(priv->pgtable, iova, flags); + + return -ENOSYS; +} + static int exynos_iommu_domain_init(struct iommu_domain *domain) { struct exynos_iommu_domain *priv; @@ -736,6 +707,8 @@ static int exynos_iommu_domain_init(struct iommu_domain *domain) domain->geometry.aperture_end = ~0UL; domain->geometry.force_aperture = true; + iommu_set_fault_handler(domain, &exynos_iommu_fault_handler, NULL); + domain->priv = priv; return 0;