Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1421303pxk; Fri, 4 Sep 2020 09:00:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTlZrJKd3r0HDcmyYRj+r/ppTXGWCwlU+9ONQSlUimeAOPWKDLuqkShDOtc7rmOeC+JdmW X-Received: by 2002:a17:906:9443:: with SMTP id z3mr8525623ejx.156.1599235222025; Fri, 04 Sep 2020 09:00:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599235222; cv=none; d=google.com; s=arc-20160816; b=ogx7vGBNIvRkr50RKogb2KoW9yJ4BgqkAVSQ0y9vxIBNQ6lLaPU/cdFGTyOmHt0Sx3 bcEgWGpX04MKDQMLt6WTBsxlguNOXGRDQ8BURi6gizQ+9QLFhwplnfFWV+nY+uJ5TGJ7 7OoH9Dpm5R4ccwuNKyZPRVViVjZrZWibtjHC66mKCjW9Nv6lKAGo+pWOaZVNHxqgAwWE JuRkYprXP07Lrx1Rmr4WleQ/a3oPgo1Kq1QBdpDuJV+oKSkqS4oZ4Mzyvn5UxBjW84sQ Mk44GAgoHhw6dOMLnP8ScGtP3DZHFJqQUVmBpATdIZ1ECJNsZKxODRJw0Rafmvw5E9Bg /cVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=h5uFJW/6fnBFkfrDyRmkYDvlEgZwoUK08VgApDtVqc4=; b=nhYryr6H91M8trP2ErlEZWAQQsy9B/UqIxktQ5dfxVucJ9gcxjyv89/06wcElgTONP 8nHyPty4hoCeBilukbzfJkpnPQqzNtQv3UDo5Q4ajogrNhFcc9Ym6iAze5PW8El5X0Xe DOU9yazlqZEsVL49pcqqNfAEg9C92hI/N11NxIQsuCjupA2XBTpoL10b0FibyxinQ6KD N6N4yAzsBuBR8vs//GuGvR95OuPv2ENUK7C1b2xuiFsXLZIvEO6Z6WP1Ud9jXkwCnHXQ WxnbElwr6He5K4UnPCtKKtIbZhy0xS14iUI0kGbzIIWWfHrvHsO3dEeSYwtBGdGlND2Z 22HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EMAZ1OmD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr13si1448949ejc.638.2020.09.04.08.59.57; Fri, 04 Sep 2020 09:00:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EMAZ1OmD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726265AbgIDP4K (ORCPT + 99 others); Fri, 4 Sep 2020 11:56:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726941AbgIDPzW (ORCPT ); Fri, 4 Sep 2020 11:55:22 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55516C06124F for ; Fri, 4 Sep 2020 08:55:19 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id d20so6739193qka.5 for ; Fri, 04 Sep 2020 08:55:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h5uFJW/6fnBFkfrDyRmkYDvlEgZwoUK08VgApDtVqc4=; b=EMAZ1OmDd9nFxAqWSODUqd6ceL4IsY1y8RrE5+ltjJztLmCsfdK71uf11dSoSWqOnM +Vf02d28fy9I9YsR1nQ7rdmtNQOhU0RUIiz0nUe1mAlTGhDTNejFezB45NW1a4VTvvMD 8WiPfcmusc0d8CXGgs5v/AE3QiD95HlLyMUguYboj2GCrTgwWRVv4m+kMRk80d1YplUY iuW0wy4mPHUz+wbqG4brFkrRDerbs0AGM/WIY+6jerzDQO2wg3Io8Z3JmTbseq4TEXj2 PIkwmPlXmcW4PDhpX2okwL9LtgyE5EHxoQlG+xJLoGcSyTuV4kTY00rRMvHJIAl04nWy MC6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h5uFJW/6fnBFkfrDyRmkYDvlEgZwoUK08VgApDtVqc4=; b=qDzcsqCUlsr96WdtZE+yxQ+ikndhbqmzj8jn+tR/o+Ql0v32WVn60Gzga9pVFJNJvV 4IK9J6wCZF85WZiDU3LWPW7Itd/1H5l0HDi/9CpapOeTP3eFhKfO9MXSBzipfrZU+R/v 1uRTKNDSQYWjryuLQdlZEWmE/j5sHsn1HfNJQqX3CG/4dVAG/4IvSXljuMzFbiJKupVH eX4mM7vMzIVYAAe+M68XCMDXQbjaPSmUGkwg1dOfLToN+PLF3wuzmon9hP6aDIy5u8BP 2jRy9jPzThItWgZ5qpuEGLk6bq6JNWbe/yt0DPghNz07xuN4c7WfTo3fLtdAHOSnxO8z W3Bw== X-Gm-Message-State: AOAM533Qm38Fow3q5oHXDO7wgVXyVyszYu/bOjvavVRVyztGTMrymJTR YjeTcWltxTrLJ63s09NqiZ3Mmg== X-Received: by 2002:a37:e502:: with SMTP id e2mr8513643qkg.141.1599234918474; Fri, 04 Sep 2020 08:55:18 -0700 (PDT) Received: from localhost.localdomain (ec2-34-197-84-77.compute-1.amazonaws.com. [34.197.84.77]) by smtp.gmail.com with ESMTPSA id v18sm4724473qtq.15.2020.09.04.08.55.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:55:17 -0700 (PDT) From: Bjorn Andersson To: Will Deacon , Robin Murphy , Joerg Roedel , Bjorn Andersson , Sai Prakash Ranjan , Jordan Crouse , Rob Clark Cc: Sibi Sankar , linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v3 3/8] iommu/arm-smmu: Consult context bank allocator for identify domains Date: Fri, 4 Sep 2020 15:55:08 +0000 Message-Id: <20200904155513.282067-4-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200904155513.282067-1-bjorn.andersson@linaro.org> References: <20200904155513.282067-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For implementations of the ARM SMMU where stream mappings of bypass type are prohibited identity domains can be implemented by using context banks with translation disabled. Postpone the decision to skip allocating a context bank until the implementation specific context bank allocator has been consulted and if it decides to use a context bank for the identity map, don't enable translation (i.e. omit ARM_SMMU_SCTLR_M). Signed-off-by: Bjorn Andersson --- Changes since v2: - Tie this to alloc_context_bank rather than carrying a Qualcomm specific quirk in the generic code. drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 4 ++++ drivers/iommu/arm/arm-smmu/arm-smmu.c | 23 +++++++++++++++------- drivers/iommu/arm/arm-smmu/arm-smmu.h | 3 +++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c index 0663d7d26908..229fc8ff8cea 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c @@ -94,8 +94,12 @@ static int qcom_adreno_smmu_alloc_context_bank(struct arm_smmu_domain *smmu_doma struct arm_smmu_device *smmu, struct device *dev, int start) { + struct iommu_domain *domain = &smmu_domain->domain; int count; + if (domain->type == IOMMU_DOMAIN_IDENTITY) + return ARM_SMMU_CBNDX_BYPASS; + /* * Assign context bank 0 to the GPU device so the GPU hardware can * switch pagetables diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index add2e1807e21..eb5c6ca5c138 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -611,7 +611,9 @@ void arm_smmu_write_context_bank(struct arm_smmu_device *smmu, int idx) /* SCTLR */ reg = ARM_SMMU_SCTLR_CFIE | ARM_SMMU_SCTLR_CFRE | ARM_SMMU_SCTLR_AFE | - ARM_SMMU_SCTLR_TRE | ARM_SMMU_SCTLR_M; + ARM_SMMU_SCTLR_TRE; + if (cfg->m) + reg |= ARM_SMMU_SCTLR_M; if (stage1) reg |= ARM_SMMU_SCTLR_S1_ASIDPNE; if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) @@ -627,9 +629,14 @@ static int arm_smmu_alloc_context_bank(struct arm_smmu_domain *smmu_domain, struct arm_smmu_device *smmu, struct device *dev, unsigned int start) { + struct iommu_domain *domain = &smmu_domain->domain; + if (smmu->impl && smmu->impl->alloc_context_bank) return smmu->impl->alloc_context_bank(smmu_domain, smmu, dev, start); + if (domain->type == IOMMU_DOMAIN_IDENTITY) + return ARM_SMMU_CBNDX_BYPASS; + return __arm_smmu_alloc_bitmap(smmu->context_map, start, smmu->num_context_banks); } @@ -653,12 +660,6 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain, if (smmu_domain->smmu) goto out_unlock; - if (domain->type == IOMMU_DOMAIN_IDENTITY) { - smmu_domain->stage = ARM_SMMU_DOMAIN_BYPASS; - smmu_domain->smmu = smmu; - goto out_unlock; - } - /* * Mapping the requested stage onto what we support is surprisingly * complicated, mainly because the spec allows S1+S2 SMMUs without @@ -757,6 +758,10 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain, ret = arm_smmu_alloc_context_bank(smmu_domain, smmu, dev, start); if (ret < 0) { goto out_unlock; + } else if (ret == ARM_SMMU_CBNDX_BYPASS) { + smmu_domain->stage = ARM_SMMU_DOMAIN_BYPASS; + smmu_domain->smmu = smmu; + goto out_unlock; } smmu_domain->smmu = smmu; @@ -813,6 +818,10 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain, domain->geometry.force_aperture = true; + /* Enable translation for non-identity context banks */ + if (domain->type != IOMMU_DOMAIN_IDENTITY) + cfg->m = true; + /* Initialise the context bank with our page table cfg */ arm_smmu_init_context_bank(smmu_domain, &pgtbl_cfg); arm_smmu_write_context_bank(smmu, cfg->cbndx); diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h index ddf2ca4c923d..235d9a3a6ab6 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -243,6 +243,8 @@ enum arm_smmu_cbar_type { #define TLB_LOOP_TIMEOUT 1000000 /* 1s! */ #define TLB_SPIN_COUNT 10 +#define ARM_SMMU_CBNDX_BYPASS 0xffff + /* Shared driver definitions */ enum arm_smmu_arch_version { ARM_SMMU_V1, @@ -346,6 +348,7 @@ struct arm_smmu_cfg { u32 sctlr_clr; /* bits to mask in SCTLR */ enum arm_smmu_cbar_type cbar; enum arm_smmu_context_fmt fmt; + bool m; }; #define ARM_SMMU_INVALID_IRPTNDX 0xff -- 2.28.0