From patchwork Tue Dec 15 12:02:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 7854011 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4BD4A9F387 for ; Tue, 15 Dec 2015 12:01:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BC28E20304 for ; Tue, 15 Dec 2015 12:01:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 96670202FE for ; Tue, 15 Dec 2015 12:01:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965215AbbLOMBO (ORCPT ); Tue, 15 Dec 2015 07:01:14 -0500 Received: from mail-pa0-f44.google.com ([209.85.220.44]:34671 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964921AbbLOMBK (ORCPT ); Tue, 15 Dec 2015 07:01:10 -0500 Received: by mail-pa0-f44.google.com with SMTP id wq6so3830394pac.1; Tue, 15 Dec 2015 04:01:10 -0800 (PST) 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=rYCOOQds+uUChAVF0V6anEY8ozr+seEf7zq7WhdSK6o=; b=JexJw5kijO2Q35c0LfXxMpBANXxkZij3v6qp9PNVHWCZCmE+JMCsNIBiRzoiYQGOHR KNa4mTd/kGJ7nfKHvOHJkSZbDqa2gcZz2Pm++S0pWcMHqtyUUy0oH54ldlny+5h7fSa3 bKUTu4jlpLiu34NTo1mD3rg5lo1T/pNWCGsVVa8knIQJ5YJ3j8rnZgw7+6zYCUTZVcK+ N+96prVhB2dUm28BBSXyS+H+4tJIg9rDiMoIveev5dKjJD8VkuTaJ68eyZ+qPzPLu9eE Z6wyRBCAVXE4FcFcHGI+JES5mTj+5Qgj/BQ+d1yq8EKjg3kWNwj4jK2/FOYEJSRd2vWE lr9Q== X-Received: by 10.66.254.234 with SMTP id al10mr53895058pad.87.1450180870296; Tue, 15 Dec 2015 04:01:10 -0800 (PST) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by smtp.gmail.com with ESMTPSA id r16sm1985859pfr.27.2015.12.15.04.01.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Dec 2015 04:01:09 -0800 (PST) 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 Dec 2015 21:02:49 +0900 Message-Id: <20151215120249.26216.25148.sendpatchset@little-apple> In-Reply-To: <20151215120212.26216.61530.sendpatchset@little-apple> References: <20151215120212.26216.61530.sendpatchset@little-apple> Subject: [PATCH 04/06] 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, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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. The purpose of this patch is to remove the use of the ARM specific mapping variable from ipmmu_irq(). Signed-off-by: Magnus Damm --- drivers/iommu/ipmmu-vmsa.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 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 --- 0007/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2015-12-15 13:14:35.540513000 +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; }; @@ -319,6 +324,7 @@ static struct iommu_gather_ops ipmmu_gat static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain) { phys_addr_t ttbr; + int ret; /* * Allocate the page table operations. @@ -348,10 +354,16 @@ 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 = bitmap_find_free_region(domain->mmu->ctx, IPMMU_CTX_MAX, 0); + if (ret < 0) { + free_io_pgtable_ops(domain->iop); + return ret; + } + + domain->context_id = ret; + domain->mmu->domains[ret] = domain; /* TTBR0 */ ttbr = domain->cfg.arm_lpae_s1_cfg.ttbr[0]; @@ -395,6 +407,8 @@ static int ipmmu_domain_init_context(str static void ipmmu_domain_destroy_context(struct ipmmu_vmsa_domain *domain) { + bitmap_release_region(domain->mmu->ctx, domain->context_id, 0); + /* * Disable the context. Flush the TLB as required when modifying the * context registers. @@ -460,16 +474,16 @@ 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 k; - io_domain = mmu->mapping->domain; - domain = to_vmsa_domain(io_domain); + /* Check interrupts for all active contexts */ + for (k = find_first_bit(mmu->ctx, IPMMU_CTX_MAX); + k < IPMMU_CTX_MAX && status == IRQ_NONE; + k = find_next_bit(mmu->ctx, IPMMU_CTX_MAX, k)) + status = ipmmu_domain_irq(mmu->domains[k]); - return ipmmu_domain_irq(domain); + return status; } /* ----------------------------------------------------------------------------- @@ -788,6 +802,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);