From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 008AD271804; Tue, 25 Feb 2025 14:35:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740494136; cv=none; b=dbG+xvBs18usevUaZKedHK9/B87d6Qao2Uh578i68FIjpoxLRYgcNfBi+UalnN36u51mse8TU8+YejUoVobavEcGZlEvXy6/EOZZ5WSa6Qbss5kPhpXjY1kmwjAkP/bHSjnrAR281RND4NRPwwu0Vxu+vmfPhyr9HXWnmQil26o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740494136; c=relaxed/simple; bh=3RH8fJI7O7+XwuWHvHjGY2VKpY8CIAhCDBwg1mAJSBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gGHx7PZGlFw8XOYf7+4PQ011l5OHLLQup82Ppdw+c9Nxi1p4viUcQW90oCZU9Fa0yqRq5S3CWtXYLowrtTdC3m+Kkj7yB7fTsEoa23mBmMJetJP1rMlcnjcxIJyt8IZlIS6mJs7qmhaq4NSDS33KUPtvQeBTnNfMC5jqiqjcbMo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JR+SYYVv; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JR+SYYVv" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5e05717755bso8626819a12.0; Tue, 25 Feb 2025 06:35:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740494132; x=1741098932; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AtoW4Q851/XHBw9G9n+uept1PIWT1f6s1ekTEE8bRXM=; b=JR+SYYVvKKz5i3kFJtQvTh7RtXbIZXMGy9UwfSORZAdESd0s4vVaDreuXN7+46xO7T C8RvCsXSjhzXZGkro0cBU71gVzbIEs16bjaXi496zlz+55GiyW1udGNUAyMSiNYJsHC7 VEm64NfS7RrQrS0wRhJVlV7lEicmwpGJDLX7N3d4yhD+YtDFd0tR6f6z3FUbQv9rwt5i 6MYTGGG1spkyS1woeZRlQBOBS6HZesotIHbkkxDfeYzci+yzUEajqVXSaPfZj0MSD0J7 91wjshlwxWdQyP1rSjVpbTXnIIu8t5YTN4dEexFLHPEFDDfShX+IGgeMWxRWJM3RPEq1 wCoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740494132; x=1741098932; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AtoW4Q851/XHBw9G9n+uept1PIWT1f6s1ekTEE8bRXM=; b=aj2Ev2V5Gx44lvICzQybh5zgO5nSpEo2+L57zG4DnNmtHgAwck5/aD5Fg4XUJ9IU5I Ww1sW4GRt/ZI8omgQ4V+/x8snT2aIdoG/gb8XlSlKcM5qG3KJWhFiSBs7bqYlZyNrNnt v6W8xhpipBf3TfFrt0yGiVhK/sMd5M50S160gt4o1UKjXrTel82qYuqeWDDXL0aUxv7G RC3gVMDSNEq9LAv0EL6mA2nLLn37KAQl1B5Y3TDVHYYE2+b2/sFUMGSFqCgywcJogsiN RU0y6NZ9jAZK1ecA8Bd8Y4jaD9ObsLN6iSstFHXkyvTFZEpSSLd1fvq22taaMCKTEPWc CUWw== X-Forwarded-Encrypted: i=1; AJvYcCV1P7k31Z1cQuk/RvkGrwJ1S+v0pbs7IsQd/1u6H8bw2yqodXjYlUUAERElQv6h6B1npCLbvlvDOmUC@vger.kernel.org, AJvYcCWgr/DQnbHcT33qFubs/VuGwJ+i7Es3ztAIo8mixcww+JaGZL1YPoGC/r9gh56skq90YmpjlxSI8Fz7@vger.kernel.org, AJvYcCX9AZzKR5I4AoLuqiFFqk0n7gJ7AddAFnAZHZYiSYqgSZoHU+83Hbb1EoTFoUC2DWGg2OSQx3CfvNUi8kQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yyd5wOf2MyvkHSTxdbEVI2H3q6ApTTdynsqH5BtZFjP1BTbqz9W sZmynBeR62mp4Q7zJsqWpPv0vGbdCYQOhr09FH2v72Fxl5FIeZfi X-Gm-Gg: ASbGncsh+L2oF3hkmSngf9aFQ0rQcblpxlJ7EZIkTuh+HeLqEkpsNzIAW1DpaEZ/dM3 ocvflE1lKZG3cp5neBLYQQajGw5kZm9AFea2PWz3srrWp6RrWfSXKh7MZuT8W8/1jFzKVItdaHo RS2lQDDrWkJ8Vcv5phSVciaki6uMCDBK8xvMNozYTyZlaGpLhcGwzD7Q6ctt/Rzmjk9i/VLT+2Y R8vJffjjlIX83D2jOAB9ymkySroyJVzclYFYQlP5WK7diueq7yEL0mbjAk7MKNnSCzgkHrtAZCd xV3HgJVASKjiXJTIHQ== X-Google-Smtp-Source: AGHT+IFuGv7aJlToY1xmXO7A7hdLTgI3Ot9A3XOx6OjMG+Sai5Zej595MPpa7X44Rchm6UqhLh2efA== X-Received: by 2002:a05:6402:2115:b0:5de:a6a8:5ecb with SMTP id 4fb4d7f45d1cf-5e4444813a8mr3548027a12.3.1740494131991; Tue, 25 Feb 2025 06:35:31 -0800 (PST) Received: from xeon.. ([188.163.112.51]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e460ff8629sm1298750a12.59.2025.02.25.06.35.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 06:35:31 -0800 (PST) From: Svyatoslav Ryhel To: Krzysztof Kozlowski , Rob Herring , Conor Dooley , Thierry Reding , Jonathan Hunter , Peter De Schrijver , Prashant Gaikwad , Michael Turquette , Stephen Boyd , Svyatoslav Ryhel , Jonathan Cameron , Georgi Djakov , Dmitry Osipenko Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-tegra@vger.kernel.org, linux-clk@vger.kernel.org Subject: [PATCH v1 3/9] drivers: memory: tegra: implement EMEM regs and ICC ops for T114 Date: Tue, 25 Feb 2025 16:34:55 +0200 Message-ID: <20250225143501.68966-4-clamor95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250225143501.68966-1-clamor95@gmail.com> References: <20250225143501.68966-1-clamor95@gmail.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Prepare Internal Memory Controller for introduction of External Memory Controller. Signed-off-by: Svyatoslav Ryhel --- drivers/memory/tegra/tegra114.c | 193 ++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) diff --git a/drivers/memory/tegra/tegra114.c b/drivers/memory/tegra/tegra114.c index d03a5d162dbd..c615857f7fad 100644 --- a/drivers/memory/tegra/tegra114.c +++ b/drivers/memory/tegra/tegra114.c @@ -3,6 +3,7 @@ * Copyright (C) 2014 NVIDIA CORPORATION. All rights reserved. */ +#include #include #include @@ -1165,6 +1166,195 @@ static const struct tegra_mc_reset tegra114_mc_resets[] = { TEGRA114_MC_RESET(VI, 0x200, 0x204, 17), }; +static void tegra114_mc_tune_client_latency(struct tegra_mc *mc, + const struct tegra_mc_client *client, + unsigned int bandwidth_mbytes_sec) +{ + u32 arb_tolerance_compensation_nsec, arb_tolerance_compensation_div; + unsigned int fifo_size = client->fifo_size; + u32 arb_nsec, la_ticks, value; + + /* see 20.3.1.1 Client Configuration in Tegra4 TRM v01p */ + if (bandwidth_mbytes_sec) + arb_nsec = fifo_size * NSEC_PER_USEC / bandwidth_mbytes_sec; + else + arb_nsec = U32_MAX; + + /* + * Latency allowness should be set with consideration for the module's + * latency tolerance and internal buffering capabilities. + * + * Display memory clients use isochronous transfers and have very low + * tolerance to a belated transfers. Hence we need to compensate the + * memory arbitration imperfection for them in order to prevent FIFO + * underflow condition when memory bus is busy. + * + * VI clients also need a stronger compensation. + */ + switch (client->swgroup) { + case TEGRA_SWGROUP_MPCORE: + case TEGRA_SWGROUP_PTC: + /* + * We always want lower latency for these clients, hence + * don't touch them. + */ + return; + + case TEGRA_SWGROUP_DC: + case TEGRA_SWGROUP_DCB: + arb_tolerance_compensation_nsec = 1050; + arb_tolerance_compensation_div = 2; + break; + + case TEGRA_SWGROUP_VI: + arb_tolerance_compensation_nsec = 1050; + arb_tolerance_compensation_div = 1; + break; + + default: + arb_tolerance_compensation_nsec = 150; + arb_tolerance_compensation_div = 1; + break; + } + + if (arb_nsec > arb_tolerance_compensation_nsec) + arb_nsec -= arb_tolerance_compensation_nsec; + else + arb_nsec = 0; + + arb_nsec /= arb_tolerance_compensation_div; + + /* + * Latency allowance is a number of ticks a request from a particular + * client may wait in the EMEM arbiter before it becomes a high-priority + * request. + */ + la_ticks = arb_nsec / mc->tick; + la_ticks = min(la_ticks, client->regs.la.mask); + + value = mc_readl(mc, client->regs.la.reg); + value &= ~(client->regs.la.mask << client->regs.la.shift); + value |= la_ticks << client->regs.la.shift; + mc_writel(mc, value, client->regs.la.reg); +} + +static int tegra114_mc_icc_set(struct icc_node *src, struct icc_node *dst) +{ + struct tegra_mc *mc = icc_provider_to_tegra_mc(src->provider); + const struct tegra_mc_client *client = &mc->soc->clients[src->id]; + u64 peak_bandwidth = icc_units_to_bps(src->peak_bw); + + /* + * Skip pre-initialization that is done by icc_node_add(), which sets + * bandwidth to maximum for all clients before drivers are loaded. + * + * This doesn't make sense for us because we don't have drivers for all + * clients and it's okay to keep configuration left from bootloader + * during boot, at least for today. + */ + if (src == dst) + return 0; + + /* convert bytes/sec to megabytes/sec */ + do_div(peak_bandwidth, 1000000); + + tegra114_mc_tune_client_latency(mc, client, peak_bandwidth); + + return 0; +} + +static int tegra114_mc_icc_aggreate(struct icc_node *node, u32 tag, u32 avg_bw, + u32 peak_bw, u32 *agg_avg, u32 *agg_peak) +{ + /* + * ISO clients need to reserve extra bandwidth up-front because + * there could be high bandwidth pressure during initial filling + * of the client's FIFO buffers. Secondly, we need to take into + * account impurities of the memory subsystem. + */ + if (tag & TEGRA_MC_ICC_TAG_ISO) + peak_bw = tegra_mc_scale_percents(peak_bw, 400); + + *agg_avg += avg_bw; + *agg_peak = max(*agg_peak, peak_bw); + + return 0; +} + +static struct icc_node_data * +tegra114_mc_of_icc_xlate_extended(const struct of_phandle_args *spec, void *data) +{ + struct tegra_mc *mc = icc_provider_to_tegra_mc(data); + const struct tegra_mc_client *client; + unsigned int i, idx = spec->args[0]; + struct icc_node_data *ndata; + struct icc_node *node; + + list_for_each_entry(node, &mc->provider.nodes, node_list) { + if (node->id != idx) + continue; + + ndata = kzalloc(sizeof(*ndata), GFP_KERNEL); + if (!ndata) + return ERR_PTR(-ENOMEM); + + client = &mc->soc->clients[idx]; + ndata->node = node; + + switch (client->swgroup) { + case TEGRA_SWGROUP_DC: + case TEGRA_SWGROUP_DCB: + case TEGRA_SWGROUP_PTC: + case TEGRA_SWGROUP_VI: + /* these clients are isochronous by default */ + ndata->tag = TEGRA_MC_ICC_TAG_ISO; + break; + + default: + ndata->tag = TEGRA_MC_ICC_TAG_DEFAULT; + break; + } + + return ndata; + } + + for (i = 0; i < mc->soc->num_clients; i++) { + if (mc->soc->clients[i].id == idx) + return ERR_PTR(-EPROBE_DEFER); + } + + dev_err(mc->dev, "invalid ICC client ID %u\n", idx); + + return ERR_PTR(-EINVAL); +} + +static const struct tegra_mc_icc_ops tegra114_mc_icc_ops = { + .xlate_extended = tegra114_mc_of_icc_xlate_extended, + .aggregate = tegra114_mc_icc_aggreate, + .set = tegra114_mc_icc_set, +}; + +static const unsigned long tegra114_mc_emem_regs[] = { + MC_EMEM_ARB_CFG, + MC_EMEM_ARB_OUTSTANDING_REQ, + MC_EMEM_ARB_TIMING_RCD, + MC_EMEM_ARB_TIMING_RP, + MC_EMEM_ARB_TIMING_RC, + MC_EMEM_ARB_TIMING_RAS, + MC_EMEM_ARB_TIMING_FAW, + MC_EMEM_ARB_TIMING_RRD, + MC_EMEM_ARB_TIMING_RAP2PRE, + MC_EMEM_ARB_TIMING_WAP2PRE, + MC_EMEM_ARB_TIMING_R2R, + MC_EMEM_ARB_TIMING_W2W, + MC_EMEM_ARB_TIMING_R2W, + MC_EMEM_ARB_TIMING_W2R, + MC_EMEM_ARB_DA_TURNS, + MC_EMEM_ARB_DA_COVERS, + MC_EMEM_ARB_MISC0, + MC_EMEM_ARB_RING1_THROTTLE, +}; + const struct tegra_mc_soc tegra114_mc_soc = { .clients = tegra114_mc_clients, .num_clients = ARRAY_SIZE(tegra114_mc_clients), @@ -1172,10 +1362,13 @@ const struct tegra_mc_soc tegra114_mc_soc = { .atom_size = 32, .client_id_mask = 0x7f, .smmu = &tegra114_smmu_soc, + .emem_regs = tegra114_mc_emem_regs, + .num_emem_regs = ARRAY_SIZE(tegra114_mc_emem_regs), .intmask = MC_INT_INVALID_SMMU_PAGE | MC_INT_SECURITY_VIOLATION | MC_INT_DECERR_EMEM, .reset_ops = &tegra_mc_reset_ops_common, .resets = tegra114_mc_resets, .num_resets = ARRAY_SIZE(tegra114_mc_resets), + .icc_ops = &tegra114_mc_icc_ops, .ops = &tegra30_mc_ops, }; -- 2.43.0