From patchwork Fri Sep 4 15:55:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 11757979 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B59C414EB for ; Fri, 4 Sep 2020 15:57:36 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 858D820772 for ; Fri, 4 Sep 2020 15:57:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JuHWtIHc"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SJb3QhpY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 858D820772 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=qTC7ElT0GNkf0k6uY2qxKVWVX/qbgM7p524Kh7mfhuA=; b=JuHWtIHcYapVVCujtiybzexjs wUGJJNoAymc9jMn5ASGLFdzN4EX4+l3aIMnc8MXibOSNcXNYrTGuTZ95hEvDZcvKgG2JXCl7tnM+o duKjYpOKN0HEY2ANUHbr86u2Gpb/mW6sW2HAnWRL8Lm8piXWUCtzqBe5D/g6pxrqf3kYnnAen3qeg V8dCJdLW0dlIboRNOQrlC0+pMLV9qESqT4o/RmmEsWXCA13T8Oe8vHf5nbPUaWF/R4wRTKfZdCxCx R398znkhjdAeCPicZv2rD+yuO8AqRSQfNWK6QwHBvTK/u1sMxzFLPSMDnbixDPVyVhAkGP7hDEYhx SNpm3Lpbw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kEE4F-0001JF-Fy; Fri, 04 Sep 2020 15:55:59 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kEE3e-00013S-IC for linux-arm-kernel@lists.infradead.org; Fri, 04 Sep 2020 15:55:28 +0000 Received: by mail-qt1-x841.google.com with SMTP id 92so4957272qtb.6 for ; Fri, 04 Sep 2020 08:55:21 -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=A7svwNgsY0UiMpV566sgNDGzXgT7VfisHtnxe6fo6Bo=; b=SJb3QhpYN6eU3JoTjsYO9t+QvUwc0b/xpfl5OAl/hynvIxgP9pQtQGZ7Q8P6XbdYOx 4ZmHDqCeABKsnyHLKLa/r1yj5s7wu0jme98WGPofmclJAqP1x8v1Qtsto93CKB8eFPbS d0rLzoytt+cTrw2VjSrbaM+Jqq9LKRqgmjXUemY119lVYuf68vDkVWFjJVhE+nfRUonE c+jT35sndJqqYDxgbHkVUFha3/taxEbjypD0TJEBf074vc1FB/fhvmH75GtEaBIZeTux WPHSblA16beNt6kLF9KBDd0tdQPNYaE9UaVzy8GYZnTEREbL71aqBcNgXIlp/WpxPsOV eUBQ== 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=A7svwNgsY0UiMpV566sgNDGzXgT7VfisHtnxe6fo6Bo=; b=rqwY8y06M75GySCNs1KaM8SrvxTt0CE+JObCnM98gDnupxoex7qjSzVAir5A+14CFb 0ddLerDOM5x6b9QbO9FxXTyXxaZcSU1qcfm50FDRdX0Rg5RhwBNUFoQZKklZXLC4g+MX ZWYVyil3r3v7qWCTUlZGfQsquFnV4gd+y5nK0VZrbiQEdkf4hyCsXEBKkoQYhh7JIn2L LetkeoZN3B45X4QyUJ+IWWFbfiBtHeaB+LWJfowBHnpe1ymJTUlURsyeX7fWiWWtGUkB 5fNKwimgw3OQfNaVanr1hEn6BhuT1bCQ5AJ+ZvaeyRZEpYuXmy42En88wy4gMUSq28nK ya8w== X-Gm-Message-State: AOAM531bDmWr3Nqwpyw6sP5orJN3Ps3qwE44VkQDx5GKZtoJ+rD7GYb2 qN0SA+UKIa43H3FWO4/5CzuzlQ== X-Google-Smtp-Source: ABdhPJw7ASxjDOGw6iPxO7Q3Ca/q5gyDB0Ac6+j7ID3GwnYiQlbkA7Cf3QrRkFvCmJF9BhJscynS1w== X-Received: by 2002:ac8:7145:: with SMTP id h5mr9707917qtp.110.1599234919674; Fri, 04 Sep 2020 08:55:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:55:18 -0700 (PDT) From: Bjorn Andersson To: Will Deacon , Robin Murphy , Joerg Roedel , Bjorn Andersson , Sai Prakash Ranjan , Jordan Crouse , Rob Clark Subject: [PATCH v3 4/8] iommu/arm-smmu-qcom: Emulate bypass by using context banks Date: Fri, 4 Sep 2020 15:55:09 +0000 Message-Id: <20200904155513.282067-5-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200904_115522_682298_07296191 X-CRM114-Status: GOOD ( 22.20 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:841 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-msm@vger.kernel.org, iommu@lists.linux-foundation.org, Sibi Sankar , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Some firmware found on various Qualcomm platforms traps writes to S2CR of type BYPASS and writes FAULT into the register. In particular, this prevents us from marking the streams for the display controller as BYPASS to allow continued scanout of the screen through the initialization of the ARM SMMU. This adds a Qualcomm specific cfg_probe function, which probes for the broken behavior of the S2CR registers and implements a custom alloc_context_bank() that when necessary allocates a context bank (without translation) for these domains as well. Signed-off-by: Bjorn Andersson Reviewed-by: Sai Prakash Ranjan Tested-by: Sai Prakash Ranjan --- Changes since v2: - Move quirk from arm_smmudevice to qcom_smmu, as we localize the quirk handling to the Qualcomm specific implemntation. drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c index 229fc8ff8cea..284761a1cd8e 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c @@ -11,8 +11,14 @@ struct qcom_smmu { struct arm_smmu_device smmu; + bool bypass_broken; }; +static struct qcom_smmu *to_qcom_smmu(struct arm_smmu_device *smmu) +{ + return container_of(smmu, struct qcom_smmu, smmu); +} + #define QCOM_ADRENO_SMMU_GPU_SID 0 static bool qcom_adreno_smmu_is_gpu_device(struct device *dev) @@ -162,6 +168,50 @@ static const struct of_device_id qcom_smmu_client_of_match[] __maybe_unused = { { } }; +static int qcom_smmu_alloc_context_bank(struct arm_smmu_domain *smmu_domain, + struct arm_smmu_device *smmu, + struct device *dev, int start) +{ + struct iommu_domain *domain = &smmu_domain->domain; + struct qcom_smmu *qsmmu = to_qcom_smmu(smmu); + + /* Keep identity domains as bypass, unless bypass is broken */ + if (domain->type == IOMMU_DOMAIN_IDENTITY && !qsmmu->bypass_broken) + return ARM_SMMU_CBNDX_BYPASS; + + /* + * The identity domain to emulate bypass is the only domain without a + * dev, use the last context bank for this to avoid collisions with + * active contexts during initialization. + */ + if (!dev) + start = smmu->num_context_banks - 1; + + return __arm_smmu_alloc_bitmap(smmu->context_map, start, smmu->num_context_banks); +} + +static int qcom_smmu_cfg_probe(struct arm_smmu_device *smmu) +{ + unsigned int last_s2cr = ARM_SMMU_GR0_S2CR(smmu->num_mapping_groups - 1); + struct qcom_smmu *qsmmu = to_qcom_smmu(smmu); + u32 reg; + + /* + * With some firmware writes to S2CR of type FAULT are ignored, and + * writing BYPASS will end up as FAULT in the register. Perform a write + * to S2CR to detect if this is the case with the current firmware. + */ + reg = FIELD_PREP(ARM_SMMU_S2CR_TYPE, S2CR_TYPE_BYPASS) | + FIELD_PREP(ARM_SMMU_S2CR_CBNDX, 0xff) | + FIELD_PREP(ARM_SMMU_S2CR_PRIVCFG, S2CR_PRIVCFG_DEFAULT); + arm_smmu_gr0_write(smmu, last_s2cr, reg); + reg = arm_smmu_gr0_read(smmu, last_s2cr); + if (FIELD_GET(ARM_SMMU_S2CR_TYPE, reg) != S2CR_TYPE_BYPASS) + qsmmu->bypass_broken = true; + + return 0; +} + static int qcom_smmu_def_domain_type(struct device *dev) { const struct of_device_id *match = @@ -200,6 +250,8 @@ static int qcom_smmu500_reset(struct arm_smmu_device *smmu) } static const struct arm_smmu_impl qcom_smmu_impl = { + .alloc_context_bank = qcom_smmu_alloc_context_bank, + .cfg_probe = qcom_smmu_cfg_probe, .def_domain_type = qcom_smmu_def_domain_type, .reset = qcom_smmu500_reset, };