From patchwork Tue Mar 15 04:21:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 8585221 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E0E21C0553 for ; Tue, 15 Mar 2016 04:18:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 05A112021B for ; Tue, 15 Mar 2016 04:18:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0DD5D20219 for ; Tue, 15 Mar 2016 04:18:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933560AbcCOESi (ORCPT ); Tue, 15 Mar 2016 00:18:38 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:35086 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933428AbcCOESg (ORCPT ); Tue, 15 Mar 2016 00:18:36 -0400 Received: by mail-pf0-f180.google.com with SMTP id n5so10381482pfn.2; Mon, 14 Mar 2016 21:18:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:date:message-id:in-reply-to:references:subject; bh=R2kTNNZDZ1M+/5cFLkYnw1BAl0JwSl97aPm5QhDvecY=; b=ufoD61zTKbFyq5tE9MzXv5hb11KWSkvWEqFYg6DL740G0ekDX5A73HtqdDa8RrnS7j nH3uZ/VvjVI086bOEcuOzULFZj+EA+eBymmWnvb5rh1U0iwaLY707+NxgwBNQ5PceK8i kumaB9ON9plh9MZcSaGSrWSTnRa3qpZ7twWfT4kQokXE1j2SWmZEsym/VdbudU0wr1pJ ZxVzO0JFduHTMTJkBOdN/PEdi7UDhSwQ37hVpSLLIDHm5cbbMdXmEpg8VMKRu6+ihOWu IPSi5iy69B/ObJsK74SHLItI64LwgECJ+x3gmqgE0dzPa89R8vYdx8frHuC/1gh5gSsp epDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:date:message-id:in-reply-to :references:subject; bh=R2kTNNZDZ1M+/5cFLkYnw1BAl0JwSl97aPm5QhDvecY=; b=jAm77PPl35xRP/1p+8AE4M2kUwbTWgfZdkRFf01b79c5mIw02pvOZBnEc7Q1+eefoQ PiXn+BP2sLZhzIbW16iwIGwk75Mt1fHDyKGxrY/WivhhahMqHCdWnLCHKMn0pDmO3mU7 T4NrsFcIjEdCQFbbmnwhWs1AWWDgNUes3z8Ad0NQ+F2qOSxqBYb9dO6CGF4G8IkyuC98 8sY5wgsGqQZr9KI67fMMC/zx1SXt+adwCI8wPpbQUGCgQPMQKpQBwp5Nds9a/w02fxT9 X5o77zE5VN0sRVCO3C+QFKq6g9tK67EjpVjDDUAUobe7LMesPdI+yMFr/lTo3BN4rFPD Dpxg== X-Gm-Message-State: AD7BkJJ77gnbMitGRg03gdwXScDM9/pkSvpHxwaEAq216ChVdumm8uUdKEf4wADWf9Jlew== X-Received: by 10.67.14.138 with SMTP id fg10mr43490251pad.145.1458015515191; Mon, 14 Mar 2016 21:18:35 -0700 (PDT) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by smtp.gmail.com with ESMTPSA id r68sm35530805pfa.33.2016.03.14.21.18.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Mar 2016 21:18:34 -0700 (PDT) From: Magnus Damm To: iommu@lists.linux-foundation.org Cc: laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be, linux-sh@vger.kernel.org, joro@8bytes.org, linux-kernel@vger.kernel.org, horms+renesas@verge.net.au, Magnus Damm Date: Tue, 15 Mar 2016 13:21:55 +0900 Message-Id: <20160315042155.22103.74587.sendpatchset@little-apple> In-Reply-To: <20160315042136.22103.26570.sendpatchset@little-apple> References: <20160315042136.22103.26570.sendpatchset@little-apple> Subject: [PATCH v2 02/04] iommu/ipmmu-vmsa: Rework interrupt code and use bitmap for context Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Magnus Damm Introduce a bitmap for context handing and convert the interrupt routine to go handle all registered contexts. At this point the number of contexts are still limited. Also remove the use of the ARM specific mapping variable from ipmmu_irq() to allow compile on ARM64. Signed-off-by: Magnus Damm --- Changes since V1: (Thanks to Laurent for feedback!) - Use simple find_first_zero()/set_bit()/clear_bit() for context management. - For allocation rely on spinlock held when calling ipmmu_domain_init_context() - For test/free use atomic bitops - Return IRQ_HANDLED if any of the contexts generated interrupts drivers/iommu/ipmmu-vmsa.c | 47 ++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 0003/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2016-03-15 12:42:18.940513000 +0900 @@ -8,6 +8,7 @@ * the Free Software Foundation; version 2 of the License. */ +#include #include #include #include @@ -26,12 +27,16 @@ #include "io-pgtable.h" +#define IPMMU_CTX_MAX 1 + struct ipmmu_vmsa_device { struct device *dev; void __iomem *base; struct list_head list; unsigned int num_utlbs; + DECLARE_BITMAP(ctx, IPMMU_CTX_MAX); + struct ipmmu_vmsa_domain *domains[IPMMU_CTX_MAX]; struct dma_iommu_mapping *mapping; }; @@ -296,6 +301,7 @@ static struct iommu_gather_ops ipmmu_gat static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain) { u64 ttbr; + int ret; /* * Allocate the page table operations. @@ -325,10 +331,17 @@ static int ipmmu_domain_init_context(str return -EINVAL; /* - * TODO: When adding support for multiple contexts, find an unused - * context. + * Find an unused context. */ - domain->context_id = 0; + ret = find_first_zero_bit(domain->mmu->ctx, IPMMU_CTX_MAX); + if (ret == IPMMU_CTX_MAX) { + free_io_pgtable_ops(domain->iop); + return -EBUSY; + } + + domain->context_id = ret; + domain->mmu->domains[ret] = domain; + set_bit(ret, domain->mmu->ctx); /* TTBR0 */ ttbr = domain->cfg.arm_lpae_s1_cfg.ttbr[0]; @@ -372,6 +385,8 @@ static int ipmmu_domain_init_context(str static void ipmmu_domain_destroy_context(struct ipmmu_vmsa_domain *domain) { + clear_bit(domain->context_id, domain->mmu->ctx); + /* * Disable the context. Flush the TLB as required when modifying the * context registers. @@ -389,10 +404,15 @@ static void ipmmu_domain_destroy_context static irqreturn_t ipmmu_domain_irq(struct ipmmu_vmsa_domain *domain) { const u32 err_mask = IMSTR_MHIT | IMSTR_ABORT | IMSTR_PF | IMSTR_TF; - struct ipmmu_vmsa_device *mmu = domain->mmu; + struct ipmmu_vmsa_device *mmu; u32 status; u32 iova; + if (!domain) + return IRQ_NONE; + + mmu = domain->mmu; + status = ipmmu_ctx_read(domain, IMSTR); if (!(status & err_mask)) return IRQ_NONE; @@ -437,16 +457,18 @@ static irqreturn_t ipmmu_domain_irq(stru static irqreturn_t ipmmu_irq(int irq, void *dev) { struct ipmmu_vmsa_device *mmu = dev; - struct iommu_domain *io_domain; - struct ipmmu_vmsa_domain *domain; - - if (!mmu->mapping) - return IRQ_NONE; + irqreturn_t status = IRQ_NONE; + unsigned int i; - io_domain = mmu->mapping->domain; - domain = to_vmsa_domain(io_domain); + /* Check interrupts for all active contexts */ + for (i = 0; i < IPMMU_CTX_MAX; i++) { + if (!test_bit(i, mmu->ctx)) + continue; + if (ipmmu_domain_irq(mmu->domains[i]) == IRQ_HANDLED) + status = IRQ_HANDLED; + } - return ipmmu_domain_irq(domain); + return status; } /* ----------------------------------------------------------------------------- @@ -774,6 +796,7 @@ static int ipmmu_probe(struct platform_d mmu->dev = &pdev->dev; mmu->num_utlbs = 32; + bitmap_zero(mmu->ctx, IPMMU_CTX_MAX); /* Map I/O memory and request IRQ. */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);