From patchwork Wed Feb 1 08:25:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 13123916 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 61334C38142 for ; Wed, 1 Feb 2023 08:26:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=uaDNSj6FOWiRSwoQfrXBrCWC+d1i7+D5Sk4uHzgCn2I=; b=v8P3pHOJn088rN XESD0VMivGDbbci3/YwLh97fTOcznUxzFDxzbZpoh0vFridxONMaVpT/Eie3VLCo2EtCmyTj48p/f soC4pYKNusL2+qFoiBEmKz+uQARLKH8g6I5YGANOGhMsMeYrZuI4sCo/1yswba0PxmQj1V2QAZ6oh UvsdPEq9OMyai+Jb52RJMQv8cSijMy2VwjsKthQCeSWYL8Iu1DLnM6su7gZHHuNEPnQlJ3JddLX/z VjJxW6y2QahnjUr72ritSzAnQuKRkz8flLy6hl+0xRPRPlqtELahWgzosFLoHJamQApbTGPuFy9QG mKGVMp5A+k4DcCKbfA0w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pN8Qf-00AmsQ-Ju; Wed, 01 Feb 2023 08:25:17 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pN8Qb-00Ampu-LG for linux-arm-kernel@lists.infradead.org; Wed, 01 Feb 2023 08:25:15 +0000 Received: by mail-pj1-x102c.google.com with SMTP id c10-20020a17090a1d0a00b0022e63a94799so1338161pjd.2 for ; Wed, 01 Feb 2023 00:25:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EhWybcKgTwds/UHsJLPm/Ip1rELEiggR3k8BSANmn/I=; b=ltlOKB2q4A2HTRmq7Dd6Ig4Vvauzv0PlgyzuE2wbGRTqcZGY3SofmipAwycEkv0A6H Gm5b8ayE3VOW014QJ0/ph3vg0cw9PBWDPFpqogh/P6up8znRkfZi4Bl2T++yh2DImAfg hwKGnGc2PmTDt5bjUNkaY5/e7/EBEIO/qeSSUvfBLlAt3Qe7tvXMU5rjwKjNlpMLEmeN FBjNqHtDakNjnJrzh3h0KRASuGXv0D4LjsI0PHKvtzVoUbN/fHW0IRPIPXdbPWfdbL7y uGymn8832EqR3WcEkA8CMvYvdhzv4m+q2j24yhuGRI4MJj7Vo1lzMtrkZtuVwQUcCMpk yjrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EhWybcKgTwds/UHsJLPm/Ip1rELEiggR3k8BSANmn/I=; b=s5/UCPelFN+pea1rEaeLJ+nk4hDOVHR8kVnLK+s+oBfCaVX/o0/83s8hPaW8kkWfnq CQeOJr/ppVze2AoTojaI9hzCbeZZzK7H1hAyGTgQ+dBhGo3ygGxeSEf6F+52ECEBgxDz PXTIsmV/LyCfU7PXwbWby7TCmSQwGQngKAkZGmOuR4Aapr3BaOaMHPo6LvMpXMatSFi3 Mh6bVTd19hMagZdMlGfGvmy18VEHKcn1szn+04D7DdgVueQYLIqDCo7XNy1jpNuIVmlk Cxrl3Gm0n5xDnJaLujenI/GzKhAGUZC/klrGRPUjmlr+ltJZPpoITg1E1cIcvPW/G+I6 UcjQ== X-Gm-Message-State: AO0yUKU3hjOloDa/fGiKC28yyXPH+LT0vfuqiAXll6d3FTDzhaNJblnT IFDjpExY2Id+il3RGgEjHoYP X-Google-Smtp-Source: AK7set8wFefYkOrTHJG39/CBWCzGmLDVbAv8tEZKj7KT7UoQ6jnnb/WxZtO0aauyj4ZllhmV4AYCIw== X-Received: by 2002:a05:6a20:2a1e:b0:bc:74c3:9499 with SMTP id e30-20020a056a202a1e00b000bc74c39499mr1623148pzh.24.1675239909774; Wed, 01 Feb 2023 00:25:09 -0800 (PST) Received: from localhost.localdomain ([59.92.99.243]) by smtp.gmail.com with ESMTPSA id 69-20020a630248000000b0045ff216a0casm9847836pgc.3.2023.02.01.00.25.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 00:25:08 -0800 (PST) From: Manivannan Sadhasivam To: will@kernel.org, joro@8bytes.org Cc: robin.murphy@arm.com, andersson@kernel.org, johan+linaro@kernel.org, steev@kali.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH] iommu/arm-smmu-qcom: Rework the logic finding the bypass quirk Date: Wed, 1 Feb 2023 13:55:00 +0530 Message-Id: <20230201082500.61656-1-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230201_002513_733732_704C339A X-CRM114-Status: GOOD ( 20.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The logic used to find the quirky firmware that intercepts the writes to S2CR register to replace bypass type streams with a fault, and ignore the fault type, is not working with the firmware on newer SoCs like SC8280XP. The current logic uses the last stream mapping group (num_mapping_groups - 1) as an index for finding quirky firmware. But on SC8280XP, this logic is not working as the number of stream mapping groups reported by the SMMU (163 as on the SC8280XP-CRD device) is not valid for some reason. So the current logic that checks the (163-1) S2CR entry fails to detect the quirky firmware on these devices and triggers invalid context fault for bypass streams. To fix this issue, rework the logic to find the first non-valid (free) stream mapping register group (SMR) and use that index to access S2CR for detecting the bypass quirk. This also warrants a change in variable name from last_s2cr to free_s2cr. Signed-off-by: Manivannan Sadhasivam Reviewed-by: Bjorn Andersson --- drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c index 78fc0e1bf215..4104f81b8d8f 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c @@ -267,23 +267,37 @@ static int qcom_smmu_init_context(struct arm_smmu_domain *smmu_domain, 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 free_s2cr; u32 reg; u32 smr; int i; + /* + * Find the first non-valid (free) stream mapping register group and + * use that index to access S2CR for detecting the bypass quirk. + */ + for (i = 0; i < smmu->num_mapping_groups; i++) { + smr = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_SMR(i)); + + if (!FIELD_GET(ARM_SMMU_SMR_VALID, smr)) + break; + } + + free_s2cr = ARM_SMMU_GR0_S2CR(i); + /* * With some firmware versions writes to S2CR of type FAULT are * ignored, and writing BYPASS will end up written as FAULT in the - * register. Perform a write to S2CR to detect if this is the case and - * if so reserve a context bank to emulate bypass streams. + * register. Perform a write to the first free S2CR to detect if + * this is the case and if so reserve a context bank to emulate + * bypass streams. */ 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); + arm_smmu_gr0_write(smmu, free_s2cr, reg); + reg = arm_smmu_gr0_read(smmu, free_s2cr); if (FIELD_GET(ARM_SMMU_S2CR_TYPE, reg) != S2CR_TYPE_BYPASS) { qsmmu->bypass_quirk = true; qsmmu->bypass_cbndx = smmu->num_context_banks - 1;