Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2436413ioo; Sat, 28 May 2022 13:38:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUeM8nlNKlmYj+KvW4a+aQS93GUIq0rxKXI8yL+9nkSnQXSc6Jor0xElSCg02a7hEbf+v+ X-Received: by 2002:a17:902:f64c:b0:156:4349:7e9b with SMTP id m12-20020a170902f64c00b0015643497e9bmr49773094plg.139.1653770283243; Sat, 28 May 2022 13:38:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653770283; cv=none; d=google.com; s=arc-20160816; b=RWiqFYHERtwtsJVMs/33O+oOxvJLnOapijdrMuScYL+krXv3RpY9Az0Fb/ZmC2GCI+ fopY2Y6V+N4AksVlP8tzOS0DeHnoDN7YXryhwP13MM+fx9L7hgzAAq+aC3aJ4qdNfidH vWC0W/CapnmTZUv/nMmrQVZJm+hDUmhzwpvTiXWTKrRFyvCGtFaYWzTWX5ers+Z+ncCQ h3DMDv3Bcr/ifZSt7HHTiY9NZcAdBgp7KlKY8TzHSyZNRQawegAfcnoGUT3iKEEiINZy /S9Buhkho4o/dwokqV29ZR9Dy3y6dSOzYMGgFDVWqWztEB0+YSl3u3VxOScWa/9F9k+m zp5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4dqAQvPfSnfIFbWa1ecrzrPIR0sY5HcpgRr+ZUalFZQ=; b=CvGb+a25xhnS2lR3zKnLU6BhCUXhZvSy0LZRoJoW5e8lkuyy05ezmfK7KlapAnpNlg X/m7RSvn+4IuLZKmQ4PlMJHVYuGjvzHaXfgwKT90T7sNe9PM7RNb0oqONsenXsCAo9WJ U1k9KXZOogtMgCcKJFndhvWChiwARLALlQL5GWBIy1LHHSQJ4GdkpaiVWoqS9f4k5otO AXMWS34h7aw2BTfuTgQOTE4xjCtAKb/kH4+afWo5E2sX2wy/EiCikgJEnszIIqLytk+p 8/hqRytUDsjfceyseLnM8m8G895fI+Atpupetmn01U0Jp15Gqjj2xYnxeYFpgUmRy+qX AgpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r133-20020a632b8b000000b003fbabc7eff9si6897344pgr.622.2022.05.28.13.38.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:38:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3E92EA26C2; Sat, 28 May 2022 12:40:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354758AbiE0V3x (ORCPT + 99 others); Fri, 27 May 2022 17:29:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354752AbiE0V3q (ORCPT ); Fri, 27 May 2022 17:29:46 -0400 Received: from relay03.th.seeweb.it (relay03.th.seeweb.it [5.144.164.164]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27EF46C563 for ; Fri, 27 May 2022 14:29:42 -0700 (PDT) Received: from localhost.localdomain (abxh119.neoplus.adsl.tpnet.pl [83.9.1.119]) by m-r1.th.seeweb.it (Postfix) with ESMTPA id 768342057C; Fri, 27 May 2022 23:29:39 +0200 (CEST) From: Konrad Dybcio To: ~postmarketos/upstreaming@lists.sr.ht, linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org Cc: martin.botka@somainline.org, angelogioacchino.delregno@somainline.org, marijn.suijten@somainline.org, jamipkettunen@somainline.org, Konrad Dybcio , Rob Clark , Will Deacon , Robin Murphy , Joerg Roedel , linux-kernel@vger.kernel.org Subject: [PATCH 3/6] iommu/qcom: Properly reset the IOMMU context Date: Fri, 27 May 2022 23:28:58 +0200 Message-Id: <20220527212901.29268-4-konrad.dybcio@somainline.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220527212901.29268-1-konrad.dybcio@somainline.org> References: <20220527212901.29268-1-konrad.dybcio@somainline.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: AngeloGioacchino Del Regno To avoid context faults reset the context entirely on detach and to ensure a fresh clean start also do a complete reset before programming the context for domain initialization. Signed-off-by: AngeloGioacchino Del Regno Signed-off-by: Marijn Suijten Signed-off-by: Konrad Dybcio --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 75f353866c40..129e322f56a6 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -223,6 +223,23 @@ static irqreturn_t qcom_iommu_fault(int irq, void *dev) return IRQ_HANDLED; } +static void qcom_iommu_reset_ctx(struct qcom_iommu_ctx *ctx) +{ + iommu_writel(ctx, ARM_SMMU_CB_FAR, 0); + iommu_writel(ctx, ARM_SMMU_CB_FSR, 0); + iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR1, 0); + iommu_writel(ctx, ARM_SMMU_CB_PAR, 0); + iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR0, 0); + iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); + iommu_writel(ctx, ARM_SMMU_CB_TCR2, 0); + iommu_writel(ctx, ARM_SMMU_CB_TCR, 0); + iommu_writeq(ctx, ARM_SMMU_CB_TTBR0, 0); + iommu_writeq(ctx, ARM_SMMU_CB_TTBR1, 0); + + /* Should we issue a TLBSYNC there instead? */ + wmb(); +} + static int qcom_iommu_init_domain(struct iommu_domain *domain, struct qcom_iommu_dev *qcom_iommu, struct device *dev) @@ -273,6 +290,8 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain, ctx->secure_init = true; } + qcom_iommu_reset_ctx(ctx); + /* TCR */ iommu_writel(ctx, ARM_SMMU_CB_TCR2, arm_smmu_lpae_tcr2(&pgtbl_cfg)); @@ -406,8 +425,8 @@ static void qcom_iommu_detach_dev(struct iommu_domain *domain, struct device *de for (i = 0; i < fwspec->num_ids; i++) { struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]); - /* Disable the context bank: */ - iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); + /* Disable and reset the context bank */ + qcom_iommu_reset_ctx(ctx); ctx->domain = NULL; } -- 2.36.1