From patchwork Mon Feb 27 19:54:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 9593901 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 8BA0960471 for ; Mon, 27 Feb 2017 20:06:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D6EF205F8 for ; Mon, 27 Feb 2017 20:06:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7252C28304; Mon, 27 Feb 2017 20:06:34 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2125E205F8 for ; Mon, 27 Feb 2017 20:06:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7YDT81E5oFctPOxkF4lKgp4+qboyw32e5Qw6XwI0OFU=; b=Gc2HZZ6hVNng3W2HPIh4VlGVv6 BGc9/GwjrsTifZI8VZ3kHiOSF9WZDgUlExykCG4T3YogCpUuU3TpVsAtBwtLzdA/eG/P1jOxSm4oD qa3emUKllWV1NpV45G9fyp3qZSsdq8RHHotU3sobf05qp2Jwq70d0nJQTN3yYXEUg93a1yLiKm3Nr lDL57t4rfl931YEnBUXCwdSwl4bBXMUZd2btwskVLXwIBHAQWNsM+/gL2MekHac4ybe+CqaTKZnZ1 P4iroX290rYhNht4PSd5djal57vG7f+0vbM/OBgcXl/667QV82p6BCb1/cIbw59V2oLN9SZ9zQGnX Hjyl9k8w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ciRZ3-0007lz-Fz; Mon, 27 Feb 2017 20:06:33 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ciRRn-000888-5A for linux-arm-kernel@lists.infradead.org; Mon, 27 Feb 2017 19:59:05 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 03CC01597; Mon, 27 Feb 2017 11:58:44 -0800 (PST) Received: from e106794-lin.cambridge.arm.com (e106794-lin.cambridge.arm.com [10.1.210.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D916C3F3E1; Mon, 27 Feb 2017 11:58:40 -0800 (PST) From: Jean-Philippe Brucker To: Subject: [RFC PATCH 14/30] iommu/arm-smmu-v3: Share process page tables Date: Mon, 27 Feb 2017 19:54:25 +0000 Message-Id: <20170227195441.5170-15-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170227195441.5170-1-jean-philippe.brucker@arm.com> References: <20170227195441.5170-1-jean-philippe.brucker@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170227_115903_365278_78B3118F X-CRM114-Status: GOOD ( 12.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Pieralisi , Shanker Donthineni , kvm@vger.kernel.org, Catalin Marinas , Joerg Roedel , Sinan Kaya , Will Deacon , iommu@lists.linux-foundation.org, Harv Abdulhamid , Alex Williamson , linux-pci@vger.kernel.org, Bjorn Helgaas , Robin Murphy , David Woodhouse , linux-arm-kernel@lists.infradead.org, Nate Watterson MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Copy the content of TCR, MAIR and TTBR of a given task into a context descriptor. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index ab49164bf09b..c3fa4616bd58 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -44,6 +44,7 @@ #include #include "io-pgtable.h" +#include "io-pgtable-arm.h" /* MMIO registers */ #define ARM_SMMU_IDR0 0x0 @@ -2191,6 +2192,9 @@ static int arm_smmu_init_task_pgtable(struct arm_smmu_task *smmu_task) { int ret; int asid; + unsigned long tcr; + unsigned long reg, par; + struct arm_smmu_s1_cfg *cfg = &smmu_task->s1_cfg; /* Pin ASID on the CPU side */ asid = mm_context_get(smmu_task->mm); @@ -2203,8 +2207,39 @@ static int arm_smmu_init_task_pgtable(struct arm_smmu_task *smmu_task) return ret; } - /* TODO: Initialize the rest of s1_cfg */ - smmu_task->s1_cfg.asid = asid; + tcr = TCR_T0SZ(VA_BITS) | TCR_IRGN0_WBWA | TCR_ORGN0_WBWA | + TCR_SH0_INNER | ARM_LPAE_TCR_EPD1; + + switch (PAGE_SIZE) { + case SZ_4K: + tcr |= TCR_TG0_4K; + break; + case SZ_16K: + tcr |= TCR_TG0_16K; + break; + case SZ_64K: + tcr |= TCR_TG0_64K; + break; + default: + WARN_ON(1); + return -EFAULT; + } + + reg = read_system_reg(SYS_ID_AA64MMFR0_EL1); + par = cpuid_feature_extract_unsigned_field(reg, ID_AA64MMFR0_PARANGE_SHIFT); + tcr |= par << ARM_LPAE_TCR_IPS_SHIFT; + + /* Enable this by default, it will be filtered when writing the CD */ + tcr |= TCR_TBI0; + + cfg->asid = asid; + cfg->ttbr = virt_to_phys(smmu_task->mm->pgd); + /* + * MAIR value is pretty much constant and global, so we can just get it + * from the current CPU register + */ + cfg->mair = read_sysreg(mair_el1); + cfg->tcr = tcr; return 0; }