From patchwork Mon Jun 6 03:57:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 9157169 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8CBDD60467 for ; Mon, 6 Jun 2016 04:08:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8387927B13 for ; Mon, 6 Jun 2016 04:08:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7881B281D2; Mon, 6 Jun 2016 04:08:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DD1927B13 for ; Mon, 6 Jun 2016 04:08:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753066AbcFFEIQ (ORCPT ); Mon, 6 Jun 2016 00:08:16 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35683 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752991AbcFFEIN (ORCPT ); Mon, 6 Jun 2016 00:08:13 -0400 Received: by mail-pf0-f193.google.com with SMTP id z187so2593288pfz.2; Sun, 05 Jun 2016 21:08:13 -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=8S9e2hvZVcJeULi8uobHIiuSspXCS4fiFERJ7P4liB0=; b=Fcn2u2a85hVEnPTodk3O1wzgYExqOj0W94dOxOSXxEilIdQnC5TOiEpYOrMXs2Ino5 5/z8wwqukYWmEFqY+0iw8DzNGlnzhGqYhlE7GqYBpZh5wpxRmo8hzJeNgTYui+WnpdSx CMJS9ua4Px1YeMZIx8NzKRPAQcKE0+snDB//IXFIb9BnHXWoFOw7nLL7kbmhkSpe2DV5 igZxRHNkAb28QV4P0a4clAuJYFpUeQoMZct5unTSS/rTKFhVCm4mfVe3ogYN2olnREGE 2OXg2PvdnavxkyC505/PkQLhqIVjWaw2+lcLpRGZd7ZNZ7COxQrcFbc2wuCREyr5XKTS E4iw== 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=8S9e2hvZVcJeULi8uobHIiuSspXCS4fiFERJ7P4liB0=; b=AQyV0EEEQsuqkX3npdcmjUW1Z4tEq/E4SFatQqbJQaZIf2AhX6iqyRlCfLuh1Pd3HE zX728NKRAmjg9OvCTWdhHq9mCeO6uaGKVODCo47VlXH+tRiyEQCpxGUvbinD2bBXlpJl krDTsbFYYzjndtyLq0kyym46RCFBahlazkfEAv1EtH0IP/H1vnK704MzGa8JRR+SI7/w 9JOZeMu933wwLlyDGONVRs6CxlEK8XQpe77OtF/KhAzU/GV3m5PxgEHjAes6ykCK8v2F h8IfOrswPhBgvme4C0IPIewtP4NX7JuzdhH6/hOV3d2Jng/NE5Jz+iWlAZ9eN1MRldjR MZMg== X-Gm-Message-State: ALyK8tIxb1y3erqCjVQGONM4LFGz4Z9pxwiDu9ty6O9179nR+9ZxatmErfUV48vq/21edQ== X-Received: by 10.98.70.76 with SMTP id t73mr23017605pfa.123.1465186092760; Sun, 05 Jun 2016 21:08:12 -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 y1sm23446617pfa.25.2016.06.05.21.08.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Jun 2016 21:08:11 -0700 (PDT) From: Magnus Damm To: iommu@lists.linux-foundation.org Cc: laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be, joro@8bytes.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, horms+renesas@verge.net.au, Magnus Damm Date: Mon, 06 Jun 2016 12:57:52 +0900 Message-Id: <20160606035752.31763.99685.sendpatchset@little-apple> In-Reply-To: <20160606035723.31763.66500.sendpatchset@little-apple> References: <20160606035723.31763.66500.sendpatchset@little-apple> Subject: [PATCH v2 03/11] iommu/ipmmu-vmsa: Enable multi context support Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Magnus Damm Add support for up to 8 contexts. Each context is mapped to one domain. One domain is associated with each device, however one or more uTLBs for a single device are kept in the same domain. Signed-off-by: Magnus Damm --- Changes since V1: - Support up to 8 contexts instead of 4 - Use feature flag and runtime handling - Default to single context drivers/iommu/ipmmu-vmsa.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) --- 0011/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2016-06-06 10:34:37.680607110 +0900 @@ -30,11 +30,12 @@ #include "io-pgtable.h" -#define IPMMU_CTX_MAX 1 +#define IPMMU_CTX_MAX 8 struct ipmmu_features { bool use_ns_alias_offset; bool has_cache_leaf_nodes; + bool has_eight_ctx; }; struct ipmmu_vmsa_device { @@ -44,6 +45,7 @@ struct ipmmu_vmsa_device { const struct ipmmu_features *features; bool is_leaf; unsigned int num_utlbs; + unsigned int num_ctx; spinlock_t lock; /* Protects ctx and domains[] */ DECLARE_BITMAP(ctx, IPMMU_CTX_MAX); struct ipmmu_vmsa_domain *domains[IPMMU_CTX_MAX]; @@ -347,11 +349,12 @@ static int ipmmu_domain_allocate_context spin_lock_irqsave(&mmu->lock, flags); - ret = find_first_zero_bit(mmu->ctx, IPMMU_CTX_MAX); - if (ret != IPMMU_CTX_MAX) { + ret = find_first_zero_bit(mmu->ctx, mmu->num_ctx); + if (ret != mmu->num_ctx) { mmu->domains[ret] = domain; set_bit(ret, mmu->ctx); - } + } else + ret = -EBUSY; spin_unlock_irqrestore(&mmu->lock, flags); @@ -394,9 +397,9 @@ static int ipmmu_domain_init_context(str * Find an unused context. */ ret = ipmmu_domain_allocate_context(domain->root, domain); - if (ret == IPMMU_CTX_MAX) { + if (ret < 0) { free_io_pgtable_ops(domain->iop); - return -EBUSY; + return ret; } domain->context_id = ret; @@ -531,7 +534,7 @@ static irqreturn_t ipmmu_irq(int irq, vo /* * Check interrupts for all active contexts. */ - for (i = 0; i < IPMMU_CTX_MAX; i++) { + for (i = 0; i < mmu->num_ctx; i++) { if (!mmu->domains[i]) continue; if (ipmmu_domain_irq(mmu->domains[i]) == IRQ_HANDLED) @@ -601,6 +604,13 @@ static int ipmmu_attach_device(struct io domain->mmu = mmu; domain->root = root; ret = ipmmu_domain_init_context(domain); + if (ret < 0) { + dev_err(dev, "Unable to initialize IPMMU context\n"); + domain->mmu = NULL; + } else { + dev_info(dev, "Using IPMMU context %u\n", + domain->context_id); + } } else if (domain->mmu != mmu) { /* * Something is wrong, we can't attach two devices using @@ -969,13 +979,14 @@ static void ipmmu_device_reset(struct ip unsigned int i; /* Disable all contexts. */ - for (i = 0; i < 4; ++i) + for (i = 0; i < mmu->num_ctx; ++i) ipmmu_write(mmu, i * IM_CTX_SIZE + IMCTR, 0); } static const struct ipmmu_features ipmmu_features_default = { .use_ns_alias_offset = true, .has_cache_leaf_nodes = false, + .has_eight_ctx = false, }; static const struct of_device_id ipmmu_of_ids[] = { @@ -1034,6 +1045,17 @@ static int ipmmu_probe(struct platform_d if (mmu->features->use_ns_alias_offset) mmu->base += IM_NS_ALIAS_OFFSET; + /* + * The number of contexts varies with generation and instance. + * Newer SoCs get a total of 8 contexts enabled, older ones just one. + */ + if (mmu->features->has_eight_ctx) + mmu->num_ctx = 8; + else + mmu->num_ctx = 1; + + WARN_ON(mmu->num_ctx > IPMMU_CTX_MAX); + irq = platform_get_irq(pdev, 0); /*