From nobody Mon Feb 9 22:18:58 2026 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 4C2BA3382C7 for ; Thu, 5 Feb 2026 21:42:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770327761; cv=none; b=LJcp73ZPZdCwsc7NSG3ehdmY4nXhdeylOWryEJm2EV5e/EpOjM0IelXaH6tdCnLdh+HUV8WfBUJuz8KmWqpSKzdUC5enlfPcV+5Rt2a39mTdDeaihgt5Di/Oq3kxzw0Ec43JiJtvLY6lRcDLUGmwAa2oH+Qq9TGohGHP/atRsjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770327761; c=relaxed/simple; bh=jXkGYVSXRYzVNLKTp6IqXxnquXxIdr4z/VDG1x0ZADM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Htc/WuM5gNkFv7IYhHMbZPhBDuGAorviEPBvl10JnY5FVALTrVxnG0+XWMHJ5u6s5couY24+4X/4VcMRf9RiqUmEipSpQ34pZ/8jLQfyIvvQAo6GYPUvoFMquW5Nm2LiGSny2MSSfTpPRmTHP/1h9pJN6UOi9vh8fhFVggtdf8g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=gUcr/VkK; arc=none smtp.client-ip=209.85.208.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gUcr/VkK" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-65814266b08so2224591a12.3 for ; Thu, 05 Feb 2026 13:42:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770327759; x=1770932559; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gtN6jc9h6sN3C2/z3TIutmLFJBrc9UMMYm4XTm15s9g=; b=gUcr/VkKbHL3lGVB7lRCqxftE8Lz0D0ip1YkGagxmZax+cjl1r1BFEOANvMqCJUFai sDamPx8Oued5mT8nqbHP4VLZTj6ubPkP8KIxPv3IU1FljJS75VloU3764n0D7ibMArWB TBlctqu+nPZi6ns5norEDmgKwwFE7SiIFzPu26NEB+TpRU8ysmob02VD3ag46rXRL1J1 kNelgFiPiYEypV7BMCw4s35sm3NL80nfIdxhlPlgxiKeuFBJBSRhmDl8x8B2hD65v341 vU2OzK7ZnGCM4UEP4RfpOH74Wl9xrxt7SO+u6N25H+lddMOT2aFsK80Fgev+o0hTTSPx MjwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770327759; x=1770932559; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=gtN6jc9h6sN3C2/z3TIutmLFJBrc9UMMYm4XTm15s9g=; b=h4/7JIkynO7vk3HRMezVcGmBQDFNarI5ALQrnYwkoko775uuyCXwvAq6QvuVwNMNhx /xmPpyVihxINKJPpPPQ0W2saZYLJ/IWweOKKHHAm2YCFOt+D82Om3oJSqFceUsGhYHl6 LHPku4OmSpWe12/B0SHCEU/AePRHNFnyjUGv5FWC4TeZ5dvRySBlUxu2C/8/fSrUUQA/ KhjMtVRwrfq7Zzb24NpCaG6O/i4TEcgGs/p1XJjr22jfhYwsF6nx9eoZOW8FnNmcqxci VgWfWtZxnPn3zn90Sbr0GgY4Zr/WQraAL4tynp9gY0tRMRbFXlOwSZkdzJWEAKWYSxQo rZ1g== X-Forwarded-Encrypted: i=1; AJvYcCU5L4Xk3KO/YnFjFHbYMcAEXK+dC5p9pG9B1+REGnvjzV8lf4kwksOHhAQukeKsIeFZOCqUKDc8crHDGSs=@vger.kernel.org X-Gm-Message-State: AOJu0YzPYPcgqc0M8t1bj4Z+n1lzqlFcUxDtL9fXZQCwEeXQkbMQQgZn SzDnS0HJYt73LjxrzifV3uyIKe6Ke6JlJGiQ/YOzzL7Y+7fx/Ts/mNUGlq7UPd//8G8= X-Gm-Gg: AZuq6aJY4FlGNkjhsk3zgY8p47S8e1kmrchMQBl7HWbxl2lMwwdp7SAPMCvbDY/kAC9 fh8TlSG+XHIflINmpjXr4RCJazQReRFEziEyF20JIlrLuZL9IycH7hdBclIHiSfwAoxxMWhc85h AcXwd3SdiADguYTwSve0Xd2NCAAwAvSdYnXvVt3QwouLp0Vg3qCI4rmGE0+SSMd+5wI+BRpn/Kh SwP50QLMQnXnx6jglbqvH8sB1HmjJqhhnKMc2y2ITcMNecHif+KLD0tODZ9cAsgPLIFUqHpKo6Q Dz7pi1n1yFOOTQLBdq7d7YdHMeHALEogqQNk6LrYdLiRoK6qXtf06rdDrG+BPKWLSuxUq5znFau vWbbQ7FqEd5iKcNA25ZJycCvbi8xO3Vym8i54rpDthWe5BCMUitiTcmWONmvBrugODErySXj63G yKYYquYsWtZdwDV7xuJd6cbMWRh1r+L6GfccCVdYHHBuWMACzljxWLSD9XZEnAcDtJZRF6XDsQm Thmhw== X-Received: by 2002:a17:906:f594:b0:b88:4b1f:5aff with SMTP id a640c23a62f3a-b8edf34e9d1mr24378566b.44.1770327758570; Thu, 05 Feb 2026 13:42:38 -0800 (PST) Received: from puffmais2.c.googlers.com (244.175.141.34.bc.googleusercontent.com. [34.141.175.244]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8eda7a0074sm21859966b.18.2026.02.05.13.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 13:42:38 -0800 (PST) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Thu, 05 Feb 2026 21:42:37 +0000 Subject: [PATCH v5 09/10] pmdomain: samsung: implement SMC to save / restore TZ config Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260205-gs101-pd-v5-9-ede49cdb57a6@linaro.org> References: <20260205-gs101-pd-v5-0-ede49cdb57a6@linaro.org> In-Reply-To: <20260205-gs101-pd-v5-0-ede49cdb57a6@linaro.org> To: Krzysztof Kozlowski , Alim Akhtar , Rob Herring , Conor Dooley , Krzysztof Kozlowski , Ulf Hansson , Liam Girdwood , Mark Brown Cc: Peter Griffin , Tudor Ambarus , Juan Yescas , Will McVicker , kernel-team@android.com, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Draszik?= X-Mailer: b4 0.14.2 Newer Exynos platforms have a Distributed Trust Zone Protection Control (DTZPC) linked to each power domain. It controls the access permissions to various registers from secure and non-secure world. An SMC call is required to instruct the firmware that the power domain is about to be turned off and again once it was turned on. This allows the firmware to save and restore the DTZPC configuration. Without, register access to various registers becomes impossible from Linux (causing SError), as the PoR configuration doesn't allow access. Neither the requirement for the SMC call, nor its arguments appear to be specific to gs101, as at least Exynos E850 also uses the same as can be seen in [1], hence prefix the new macros simply with EXYNOS_. At least on gs101, this SMC call isn't implemented for all power domains (e.g. it's missing for HSI2 (UFS)), therefore we issue a test SMC to store the configuration during probe, and if it fails we mark a domain as always-on to avoid the SErrors and to avoid unnecessarily retrying for each domain on/off. Link: https://lore.kernel.org/all/20230308233822.31180-4-semen.protsenko@li= naro.org/ [1] Signed-off-by: Andr=C3=A9 Draszik --- drivers/pmdomain/samsung/exynos-pm-domains.c | 96 ++++++++++++++++++++++++= ++-- 1 file changed, 90 insertions(+), 6 deletions(-) diff --git a/drivers/pmdomain/samsung/exynos-pm-domains.c b/drivers/pmdomai= n/samsung/exynos-pm-domains.c index 41a232b3cdaf0f4be413b25d9373b99c6a3db602..f59986b56213dfcc470d9cccc61= a36a81954bdcc 100644 --- a/drivers/pmdomain/samsung/exynos-pm-domains.c +++ b/drivers/pmdomain/samsung/exynos-pm-domains.c @@ -9,6 +9,7 @@ // conjunction with runtime-pm. Support for both device-tree and non-devic= e-tree // based power domain support is included. =20 +#include #include #include #include @@ -16,12 +17,19 @@ #include #include #include +#include #include #include =20 +#define EXYNOS_SMC_CMD_PREPARE_PD_ONOFF 0x82000410 +#define EXYNOS_GET_IN_PD_DOWN 0 +#define EXYNOS_WAKEUP_PD_DOWN 1 +#define EXYNOS_RUNTIME_PM_TZPC_GROUP 2 + struct exynos_pm_domain_config { /* Value for LOCAL_PWR_CFG and STATUS fields for each domain */ u32 local_pwr_cfg; + u32 smc_offset; bool use_parent_regmap; }; =20 @@ -32,11 +40,28 @@ struct exynos_pm_domain { struct regmap *regmap; struct device *dev; struct generic_pm_domain pd; - u32 local_pwr_cfg; + const struct exynos_pm_domain_config *cfg; u32 configuration_reg; u32 status_reg; + phys_addr_t ac_pa; }; =20 +static int exynos_pd_access_controller_power(struct exynos_pm_domain *pd, + bool power_on) +{ + struct arm_smccc_res res; + + if (!pd->ac_pa || !pd->cfg->smc_offset) + return 0; + + arm_smccc_smc(EXYNOS_SMC_CMD_PREPARE_PD_ONOFF, + power_on ? EXYNOS_WAKEUP_PD_DOWN : EXYNOS_GET_IN_PD_DOWN, + pd->ac_pa + pd->cfg->smc_offset, + EXYNOS_RUNTIME_PM_TZPC_GROUP, 0, 0, 0, 0, &res); + + return res.a0; +} + static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on) { struct exynos_pm_domain *pd; @@ -45,7 +70,17 @@ static int exynos_pd_power(struct generic_pm_domain *dom= ain, bool power_on) =20 pd =3D container_of(domain, struct exynos_pm_domain, pd); =20 - pwr =3D power_on ? pd->local_pwr_cfg : 0; + if (!power_on) { + err =3D exynos_pd_access_controller_power(pd, power_on); + if (err) { + dev_err(pd->dev, + "SMC for power domain %s %sable failed: %d\n", + domain->name, power_on ? "en" : "dis", err); + return err; + } + } + + pwr =3D power_on ? pd->cfg->local_pwr_cfg : 0; err =3D regmap_write(pd->regmap, pd->configuration_reg, pwr); if (err) { dev_err(pd->dev, @@ -60,7 +95,7 @@ static int exynos_pd_power(struct generic_pm_domain *doma= in, bool power_on) unsigned int val; =20 err =3D regmap_read(pd->regmap, pd->status_reg, &val); - if (err || ((val & pd->local_pwr_cfg) !=3D pwr)) { + if (err || ((val & pd->cfg->local_pwr_cfg) !=3D pwr)) { cpu_relax(); usleep_range(80, 100); continue; @@ -72,9 +107,21 @@ static int exynos_pd_power(struct generic_pm_domain *do= main, bool power_on) if (!timeout && !err) /* Only return timeout if no other error also occurred. */ err =3D -ETIMEDOUT; - if (err) + if (err) { dev_err(pd->dev, "Power domain %s %sable failed: %d\n", domain->name, power_on ? "en" : "dis", err); + return err; + } + + if (power_on) { + err =3D exynos_pd_access_controller_power(pd, power_on); + if (err) { + dev_err(pd->dev, + "SMC for power domain %s %sable failed: %d\n", + domain->name, power_on ? "en" : "dis", err); + return err; + } + } =20 return err; } @@ -99,6 +146,7 @@ static const struct exynos_pm_domain_config exynos5433_c= fg =3D { =20 static const struct exynos_pm_domain_config gs101_cfg =3D { .local_pwr_cfg =3D BIT(0), + .smc_offset =3D 0x0204, .use_parent_regmap =3D true, }; =20 @@ -126,6 +174,38 @@ static const char *exynos_get_domain_name(struct devic= e *dev, return devm_kstrdup_const(dev, name, GFP_KERNEL); } =20 +static int exynos_pd_get_access_controller(struct exynos_pm_domain *pd) +{ + struct device_node *ac_np; + struct resource ac_res; + int ret; + + ac_np =3D of_parse_phandle(pd->dev->of_node, "samsung,dtzpc", 0); + if (!ac_np) + return 0; + + ret =3D of_address_to_resource(ac_np, 0, &ac_res); + of_node_put(ac_np); + if (ret) + return dev_err_probe(pd->dev, ret, + "failed to get access controller\n"); + + pd->ac_pa =3D ac_res.start; + + /* + * For some domains, TZ save/restore might not be implemented. If that + * is the case, simply mark it as always on, as otherwise a power cycle + * will lead to lost TZ configuration, making it impossible to access + * registers from Linux afterwards. + */ + if (exynos_pd_access_controller_power(pd, false) =3D=3D -ENOENT) { + pd->ac_pa =3D 0; + pd->pd.flags |=3D GENPD_FLAG_ALWAYS_ON; + } + + return 0; +} + static int exynos_pd_probe(struct platform_device *pdev) { const struct exynos_pm_domain_config *pm_domain_cfg; @@ -195,10 +275,14 @@ static int exynos_pd_probe(struct platform_device *pd= ev) =20 pd->pd.power_off =3D exynos_pd_power_off; pd->pd.power_on =3D exynos_pd_power_on; - pd->local_pwr_cfg =3D pm_domain_cfg->local_pwr_cfg; + pd->cfg =3D pm_domain_cfg; pd->configuration_reg +=3D 0; pd->status_reg +=3D 4; =20 + ret =3D exynos_pd_get_access_controller(pd); + if (ret) + return ret; + /* * Some Samsung platforms with bootloaders turning on the splash-screen * and handing it over to the kernel, requires the power-domains to be @@ -212,7 +296,7 @@ static int exynos_pd_probe(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "failed to read status"); =20 - on =3D val & pd->local_pwr_cfg; + on =3D val & pd->cfg->local_pwr_cfg; =20 pm_genpd_init(&pd->pd, NULL, !on); ret =3D of_genpd_add_provider_simple(np, &pd->pd); --=20 2.53.0.rc2.204.g2597b5adb4-goog