Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp672269imp; Wed, 20 Feb 2019 07:06:42 -0800 (PST) X-Google-Smtp-Source: AHgI3IYHC4d7JTdsJfGBGhUWQo9vnYUhup/398/mvSct7IFqmVKaUMdsuPO1WJZ6ct4i7PpYyG+o X-Received: by 2002:a17:902:6b46:: with SMTP id g6mr37246161plt.21.1550675202185; Wed, 20 Feb 2019 07:06:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550675202; cv=none; d=google.com; s=arc-20160816; b=gINu5pjHDZrFqQ3pBHqtzLfnN5pEa9OH7Huhep+9avHQtAfdyEAmIKS2js/5SmAU6X 1ljgGjPPMuP4dYuaurPUEENK4VFjaJDGHJwHYr6K3gg+sH1IeLxN4h+ygV498NKJrSyJ /zNKC/nJuKpy3B9/2tXycu7AlpfUPk5OKCKc+uwSZ90rfoRM6GyLSASVGdz58uJOGQkR ewngvaSzeQag90W7C2xoBebgAiIHrd7ORk0xL9kuPt+zy1/xMTmv5AS3BSSb04Grcpxa A6fBDRsCQ5HPAIdbWZL6iY9YD9LFkjaPJUo1OQgRImsn8rO+1JiQa+naZr8jj/dM8MXw Tw9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=yCczFoKCFikG+XnkSquSb+qDMD9m0RftAfLQ2S1+kS8=; b=LMUTiFGZdMgjL3cSqE801ys9VfZ2dvK9mBfr19imw54cfcBRnjY/EScGwoa5/g1Bup 2xIk1Ki/qLV7UD0FPmoN0x8zlO2rwFITRPyd9SCt+b/WL3z8mfMJfqk05Dv/OHK+Zc7o goH9cHp+/S4DTvRddnd1QCu9FKl5SEpcReq4QDHVbl2F9zJqq0klK6chODm2+Mctrifd kkschwaBqZEoc8ZOGnVf9hfuASgY0UyDKqrG2SJin2FfsEynUhYv02eV4o/37PERGW4a Ta3NcL8+1dZMd1vhZbNvgiM/6iPw/kxoMOebEZM27J4tUYn7wuYEWKN1bmpoehuuhwVe 4B5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d35si20130767pla.48.2019.02.20.07.06.16; Wed, 20 Feb 2019 07:06:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727184AbfBTPFl (ORCPT + 99 others); Wed, 20 Feb 2019 10:05:41 -0500 Received: from xavier.telenet-ops.be ([195.130.132.52]:35360 "EHLO xavier.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726878AbfBTPFi (ORCPT ); Wed, 20 Feb 2019 10:05:38 -0500 Received: from ramsan ([84.194.111.163]) by xavier.telenet-ops.be with bizsmtp id f35b1z00r3XaVaC0135bmY; Wed, 20 Feb 2019 16:05:35 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1gwTRH-0002IR-MD; Wed, 20 Feb 2019 16:05:35 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1gwTRH-0000ez-KV; Wed, 20 Feb 2019 16:05:35 +0100 From: Geert Uytterhoeven To: Joerg Roedel , Magnus Damm Cc: Laurent Pinchart , iommu@lists.linux-foundation.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 6/7] iommu/ipmmu-vmsa: Extract hardware context initialization Date: Wed, 20 Feb 2019 16:05:30 +0100 Message-Id: <20190220150531.2462-7-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220150531.2462-1-geert+renesas@glider.be> References: <20190220150531.2462-1-geert+renesas@glider.be> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ipmmu_domain_init_context() takes care of (1) initializing the software domain, and (2) initializing the hardware context for the domain. Extract the code to initialize the hardware context into a new subroutine ipmmu_context_init(), to prepare for later reuse. Signed-off-by: Geert Uytterhoeven --- drivers/iommu/ipmmu-vmsa.c | 91 ++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 0a21e734466eb1bd..92a766dd8b459f0c 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -404,52 +404,10 @@ static void ipmmu_domain_free_context(struct ipmmu_vmsa_device *mmu, spin_unlock_irqrestore(&mmu->lock, flags); } -static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain) +static void ipmmu_context_init(struct ipmmu_vmsa_domain *domain) { u64 ttbr; u32 tmp; - int ret; - - /* - * Allocate the page table operations. - * - * VMSA states in section B3.6.3 "Control of Secure or Non-secure memory - * access, Long-descriptor format" that the NStable bit being set in a - * table descriptor will result in the NStable and NS bits of all child - * entries being ignored and considered as being set. The IPMMU seems - * not to comply with this, as it generates a secure access page fault - * if any of the NStable and NS bits isn't set when running in - * non-secure mode. - */ - domain->cfg.quirks = IO_PGTABLE_QUIRK_ARM_NS; - domain->cfg.pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K; - domain->cfg.ias = 32; - domain->cfg.oas = 40; - domain->cfg.tlb = &ipmmu_gather_ops; - domain->io_domain.geometry.aperture_end = DMA_BIT_MASK(32); - domain->io_domain.geometry.force_aperture = true; - /* - * TODO: Add support for coherent walk through CCI with DVM and remove - * cache handling. For now, delegate it to the io-pgtable code. - */ - domain->cfg.iommu_dev = domain->mmu->root->dev; - - /* - * Find an unused context. - */ - ret = ipmmu_domain_allocate_context(domain->mmu->root, domain); - if (ret < 0) - return ret; - - domain->context_id = ret; - - domain->iop = alloc_io_pgtable_ops(ARM_32_LPAE_S1, &domain->cfg, - domain); - if (!domain->iop) { - ipmmu_domain_free_context(domain->mmu->root, - domain->context_id); - return -EINVAL; - } /* TTBR0 */ ttbr = domain->cfg.arm_lpae_s1_cfg.ttbr[0]; @@ -495,7 +453,54 @@ static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain) */ ipmmu_ctx_write_all(domain, IMCTR, IMCTR_INTEN | IMCTR_FLUSH | IMCTR_MMUEN); +} + +static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain) +{ + int ret; + + /* + * Allocate the page table operations. + * + * VMSA states in section B3.6.3 "Control of Secure or Non-secure memory + * access, Long-descriptor format" that the NStable bit being set in a + * table descriptor will result in the NStable and NS bits of all child + * entries being ignored and considered as being set. The IPMMU seems + * not to comply with this, as it generates a secure access page fault + * if any of the NStable and NS bits isn't set when running in + * non-secure mode. + */ + domain->cfg.quirks = IO_PGTABLE_QUIRK_ARM_NS; + domain->cfg.pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K; + domain->cfg.ias = 32; + domain->cfg.oas = 40; + domain->cfg.tlb = &ipmmu_gather_ops; + domain->io_domain.geometry.aperture_end = DMA_BIT_MASK(32); + domain->io_domain.geometry.force_aperture = true; + /* + * TODO: Add support for coherent walk through CCI with DVM and remove + * cache handling. For now, delegate it to the io-pgtable code. + */ + domain->cfg.iommu_dev = domain->mmu->root->dev; + + /* + * Find an unused context. + */ + ret = ipmmu_domain_allocate_context(domain->mmu->root, domain); + if (ret < 0) + return ret; + + domain->context_id = ret; + + domain->iop = alloc_io_pgtable_ops(ARM_32_LPAE_S1, &domain->cfg, + domain); + if (!domain->iop) { + ipmmu_domain_free_context(domain->mmu->root, + domain->context_id); + return -EINVAL; + } + ipmmu_context_init(domain); return 0; } -- 2.17.1