From patchwork Fri Oct 6 13:31:50 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: 9989487 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 8FCD96020F for ; Fri, 6 Oct 2017 13:47:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EB0A283D9 for ; Fri, 6 Oct 2017 13:47:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6312E284B5; Fri, 6 Oct 2017 13:47:24 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED 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 F374F283AE for ; Fri, 6 Oct 2017 13:47:23 +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=xLVSSHKKPLkJn11ww1UV2IVyLavYpYlEyWGiPwkP1Rg=; b=tMJIL84FgBplaYs5oFCkS0frqJ cNRRc2IIXeC5KMNIG2KO4yZNfGAZGF78vs3fHKpX/XtGiK3ACVo6qRYiPkNo3cM/yNbubVnZ/PgjT NFdwH4hCVvmqd6M5b09D7e6XHg5MLJSCDAIZgNozD2CJhw2pGnV5WG8YCr4QvmVlpP+rAwewipiXE aHP8WSnVNT87AesjaUS3vsz3dSG1c8ZUvP7zi2k3+ewE5mJVweTDA9w4RVCLjfmMGjCliVL8k1XOu fLlATGkgEcXFHxNjWgdWpqo1PDo7w33WjsYRpaztRlYEhwceAma46P+f3dd+hyB3GdiMLyyS8Q774 +OZ7rRfg==; 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 1e0SyJ-0000I5-Bg; Fri, 06 Oct 2017 13:47:23 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e0Svn-00053q-23 for linux-arm-kernel@bombadil.infradead.org; Fri, 06 Oct 2017 13:44:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=aFev4fElEiVzk8SrrlgkJvut6AABGARzVRGergooHKE=; b=H34zFhNqQQudvST/EfYRfDT53 bbyhvmPOQNRz3in/y5JX9NfHfsi+Duqd4T52VCOya5JBhhxMNhmr7a+VoTYTLIW5dbTxOowYAm1X9 CcR0znKqtqHFZ8W9eaXmlMHDBJu9cxhbKl3c1+9yNVr7SQmXhphw7F1HNXO+dc/4ayfeCWE7uF9TZ Gv2Ugv0YbqUlE8Hd5Ivjm0pxpmfAzgNLTjscwwK9Z2Gq5HwZKYb3OacCa3gtuqApTi1ypXY2mq8Ww HbgNfKG2nGddPK7dJrMM7pc5GLug+kGyasLYNVtYK0D/l/31es5hyLHoxyr9GSOeedNrufRYI4mJm xpRoLbBew==; Received: from foss.arm.com ([217.140.101.70]) by casper.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e0SoF-0007lY-G5 for linux-arm-kernel@lists.infradead.org; Fri, 06 Oct 2017 13:37:01 +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 E9781165D; Fri, 6 Oct 2017 06:29:49 -0700 (PDT) Received: from e106794-lin.cambridge.arm.com (e106794-lin.cambridge.arm.com [10.1.211.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1B09D3F578; Fri, 6 Oct 2017 06:29:44 -0700 (PDT) From: Jean-Philippe Brucker To: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, iommu@lists.linux-foundation.org Subject: [RFCv2 PATCH 23/36] iommu/arm-smmu-v3: Share process page tables Date: Fri, 6 Oct 2017 14:31:50 +0100 Message-Id: <20171006133203.22803-24-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20171006133203.22803-1-jean-philippe.brucker@arm.com> References: <20171006133203.22803-1-jean-philippe.brucker@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171006_143659_685668_F80CA74E X-CRM114-Status: GOOD ( 14.52 ) 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: mark.rutland@arm.com, xieyisheng1@huawei.com, gabriele.paoloni@huawei.com, catalin.marinas@arm.com, will.deacon@arm.com, okaya@codeaurora.org, yi.l.liu@intel.com, lorenzo.pieralisi@arm.com, ashok.raj@intel.com, tn@semihalf.com, joro@8bytes.org, rfranz@cavium.com, lenb@kernel.org, jacob.jun.pan@linux.intel.com, alex.williamson@redhat.com, robh+dt@kernel.org, thunder.leizhen@huawei.com, bhelgaas@google.com, dwmw2@infradead.org, liubo95@huawei.com, rjw@rjwysocki.net, robdclark@gmail.com, hanjun.guo@linaro.org, sudeep.holla@arm.com, robin.murphy@arm.com, nwatters@codeaurora.org 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 | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index c86a1182c137..293f260782c2 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -43,6 +43,7 @@ #include #include "io-pgtable.h" +#include "io-pgtable-arm.h" /* MMIO registers */ #define ARM_SMMU_IDR0 0x0 @@ -2170,13 +2171,46 @@ static int arm_smmu_process_init_pgtable(struct arm_smmu_process *smmu_process, struct mm_struct *mm) { int asid; + unsigned long tcr; + unsigned long reg, par; + struct arm_smmu_ctx_desc *cfg = &smmu_process->ctx_desc; asid = mm_context_get(mm); if (!asid) return -ENOSPC; - smmu_process->ctx_desc.asid = asid; - /* TODO: init the rest */ + 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_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + par = cpuid_feature_extract_unsigned_field(reg, ID_AA64MMFR0_PARANGE_SHIFT); + tcr |= par << ARM_LPAE_TCR_IPS_SHIFT; + + tcr |= TCR_TBI0; + + cfg->asid = asid; + cfg->ttbr = virt_to_phys(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; }