From patchwork Thu Mar 25 13:03:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 12164069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8037BC433E0 for ; Thu, 25 Mar 2021 13:08:22 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 E475161A17 for ; Thu, 25 Mar 2021 13:08:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E475161A17 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=kC4DgOnuGgh2Sjju0fdoera0J5molkr/40+dM3ZLkFk=; b=kp6O8lSzqqmRG1ysNJg9xDTFP BbsSDmE4s6AM4UXQpdmehvBsH80lTeniEugWfDz6y29HXj/NS+aXhzhJBpc3YpgnEy6LVzaewl4FN cVHnww7BiRd8cs5J8AVxPg+yq0gDqeg2cFIGlaP0RdTOA9qhh2AljcPAS6KoSRAzYDRnr0PDfn63S UAS+9/t7ZJnTdgy0gnseiq2a+zaXo80VVlsIiN2vltgA5AWMUF8gb1xCIJ9t8rgP21M4QzUAgLEyO bOkxT8DAg+7f1kYc+SmC9Q9i9TL6eIM/IbFBb6bzGF0qlKj1GDUcg1xzz+sQkzGpcC9zNZwNNEel4 WmHlgZ1Bw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lPPgQ-001TAI-HH; Thu, 25 Mar 2021 13:05:54 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lPPe6-001Srw-Jo for linux-arm-kernel@lists.infradead.org; Thu, 25 Mar 2021 13:05:32 +0000 Received: by mail-wr1-x429.google.com with SMTP id z2so2204072wrl.5 for ; Thu, 25 Mar 2021 06:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bM4o41o0uKiCCdNc1xklJaXj4qpc+jHNYM7w+kQ4+qg=; b=U4V0FXpRhge+rQbpMnsw738aWFzOHoH9nKRQ4RFXGn0nboWX18kWT6XdIPwWm1vL6q atFtWWgo1paCfmqEG0tnLm0g4piD2/1VUCz+GW7iovm7yRT7Q11Sc2V+K1OqXSzFUojn vRh3CKFcVmUPtowChih/rZQvQnTFW/CLGtk4NISdm4rQMbi5t3wSdyjZaHne2bbFzJDX P5InDuLpPvf39kC28YMzmLianBflz3MRCbgb4Vi3lOEf0GvLXlpmj+8ALL2i4Igm7Pgq Jj+p7FirkxXuleA9m/OCJflpckBYjrdLw48EPsH0dcnlbPJKEbPPPobnFYhDDOGZHlbS AeNg== 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=bM4o41o0uKiCCdNc1xklJaXj4qpc+jHNYM7w+kQ4+qg=; b=rxB58CTQNTDcvT70SseOgCOyId32tXL+oZrxAcvzhjbXX+pFb17Rb6uuXeXrYFmdKD EMm1TBxpqL/nSBwldYdAr7lYT3rhskq/Fk4AuZyiSEu4lpPwg0sH5KgF3oEBtRiSxeL4 FlNrAwUMRwvRb0ga3ado+kvVn8Ebnptl5RDOiVb+X3ooVtspQUm3q5mfSvwHu1JNEVis ZYApP7/Wuzo8YoXe+fQZz1Zm/m/6z51KAFH+aP9bQH5qka+BL8ekSHlbhznIRmMkx+DD Nol0SIreNdA50aOaP+x4pgMtfEDRUQEBNcTNTsTr6njdv2Ekip9hX0/6K/HV6ojWEV0s bi0Q== X-Gm-Message-State: AOAM530BpxpEE40CbLRIRh6ygs0kRdXoBYDKGf1aUk9CFErNDOJw5EN1 ywafjsBqNYqXdVE75FT9zHE= X-Google-Smtp-Source: ABdhPJx67P1LH5jgle7JqCerP8+RaNQGzDrk4nvFL4I+tYklmaeH1WswkVYp3xtEYZECCBUpdUTJUw== X-Received: by 2002:adf:ce8a:: with SMTP id r10mr8907889wrn.17.1616677410043; Thu, 25 Mar 2021 06:03:30 -0700 (PDT) Received: from localhost ([62.96.65.119]) by smtp.gmail.com with ESMTPSA id h25sm6904366wml.32.2021.03.25.06.03.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 06:03:28 -0700 (PDT) From: Thierry Reding To: Thierry Reding , Will Deacon , Robin Murphy , Joerg Roedel , Krzysztof Kozlowski Subject: [PATCH 3/9] memory: tegra: Implement SID override programming Date: Thu, 25 Mar 2021 14:03:26 +0100 Message-Id: <20210325130332.778208-4-thierry.reding@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325130332.778208-1-thierry.reding@gmail.com> References: <20210325130332.778208-1-thierry.reding@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210325_130530_829248_9404965A X-CRM114-Status: GOOD ( 22.70 ) 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: , Cc: iommu@lists.linux-foundation.org, Jon Hunter , Nicolin Chen , linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Thierry Reding Instead of programming all SID overrides during early boot, perform the operation on-demand after the SMMU translations have been set up for a device. This reuses data from device tree to match memory clients for a device and programs the SID specified in device tree, which corresponds to the SID used for the SMMU context banks for the device. Signed-off-by: Thierry Reding --- drivers/memory/tegra/tegra186.c | 70 +++++++++++++++++++++++++++++++++ include/soc/tegra/mc.h | 10 +++++ 2 files changed, 80 insertions(+) diff --git a/drivers/memory/tegra/tegra186.c b/drivers/memory/tegra/tegra186.c index efa922d51d83..a89e8e40d875 100644 --- a/drivers/memory/tegra/tegra186.c +++ b/drivers/memory/tegra/tegra186.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -19,6 +20,10 @@ #include #endif +#define MC_SID_STREAMID_OVERRIDE_MASK GENMASK(7, 0) +#define MC_SID_STREAMID_SECURITY_WRITE_ACCESS_DISABLED BIT(16) +#define MC_SID_STREAMID_SECURITY_OVERRIDE BIT(8) + struct tegra186_mc_client { const char *name; unsigned int id; @@ -1808,6 +1813,71 @@ static struct platform_driver tegra186_mc_driver = { }; module_platform_driver(tegra186_mc_driver); +static void tegra186_mc_client_sid_override(struct tegra_mc *mc, + const struct tegra186_mc_client *client, + unsigned int sid) +{ + u32 value, old; + + value = readl(mc->regs + client->regs.security); + if ((value & MC_SID_STREAMID_SECURITY_OVERRIDE) == 0) { + /* + * If the secure firmware has locked this down the override + * for this memory client, there's nothing we can do here. + */ + if (value & MC_SID_STREAMID_SECURITY_WRITE_ACCESS_DISABLED) + return; + + /* + * Otherwise, try to set the override itself. Typically the + * secure firmware will never have set this configuration. + * Instead, it will either have disabled write access to + * this field, or it will already have set an explicit + * override itself. + */ + WARN_ON((value & MC_SID_STREAMID_SECURITY_OVERRIDE) == 0); + + value |= MC_SID_STREAMID_SECURITY_OVERRIDE; + writel(value, mc->regs + client->regs.security); + } + + value = readl(mc->regs + client->regs.override); + old = value & MC_SID_STREAMID_OVERRIDE_MASK; + + if (old != sid) { + dev_dbg(mc->dev, "overriding SID %x for %s with %x\n", old, + client->name, sid); + writel(sid, mc->regs + client->regs.override); + } +} + +int tegra186_mc_probe_device(struct tegra_mc *mc, struct device *dev) +{ + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct of_phandle_args args; + unsigned int i, index = 0; + + while (!of_parse_phandle_with_args(dev->of_node, "interconnects", "#interconnect-cells", + index, &args)) { + if (args.np == mc->dev->of_node && args.args_count != 0) { + for (i = 0; i < mc->soc->num_clients; i++) { + const struct tegra186_mc_client *client = &mc->soc->clients[i]; + + if (client->id == args.args[0]) { + u32 sid = fwspec->ids[0] & MC_SID_STREAMID_OVERRIDE_MASK; + + tegra186_mc_client_sid_override(mc, client, sid); + } + } + } + + index++; + } + + return 0; +} +EXPORT_SYMBOL_GPL(tegra186_mc_probe_device); + MODULE_AUTHOR("Thierry Reding "); MODULE_DESCRIPTION("NVIDIA Tegra186 Memory Controller driver"); MODULE_LICENSE("GPL v2"); diff --git a/include/soc/tegra/mc.h b/include/soc/tegra/mc.h index 7be8441c6e9e..73d5ecf0e76a 100644 --- a/include/soc/tegra/mc.h +++ b/include/soc/tegra/mc.h @@ -168,4 +168,14 @@ devm_tegra_memory_controller_get(struct device *dev) } #endif +#if IS_ENABLED(CONFIG_ARCH_TEGRA_186_SOC) || \ + IS_ENABLED(CONFIG_ARCH_TEGRA_194_SOC) +int tegra186_mc_probe_device(struct tegra_mc *mc, struct device *dev); +#else +static inline int tegra186_mc_probe_device(struct tegra_mc *mc, struct device *dev) +{ + return 0; +} +#endif + #endif /* __SOC_TEGRA_MC_H__ */