From nobody Fri Apr 10 01:05:53 2026 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 39FF52E762C for ; Thu, 5 Mar 2026 06:12:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772691126; cv=none; b=FjPnEfK55sbKMCuvxn+PDrqpimBRz42cX1rY00qJaUlaK8enyNf+H1AhM70Am+ksIgXNHcZxWwat41dz+kiQZIAEkjtJ+16B2BhoBLg4JLICHX1uqqV/9GzIgHEa5pP5iZjBz7VFvw6+PsyCjwAJFCQmdCM51RS8uFTKsQZY4tA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772691126; c=relaxed/simple; bh=U+pgoXFtqVjylMufxL+ijffy+ks+RYDFMMjRK6SVUv8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T60tcsCNpSbxyH4Sgz0F/puhLJLrtPqMCLdVmev9K4F6hvO/fMIihAcGfI5QPCVqgAqiDYC3/F8AlHsnfZ2Yt3PO+o7hrNavZk1Bfr1QOU90zE0QwtaUBPRGuMhMBZTXw9nSp2J7u4Yaq/9aFkQPA1laeGIGWORN5YY9qagM4rI= 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=NTTSdiXA; arc=none smtp.client-ip=209.85.218.54 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="NTTSdiXA" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-b939cfc1e83so610662066b.0 for ; Wed, 04 Mar 2026 22:12:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1772691122; x=1773295922; 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=v9aOQtXPMrRyOq0vhd4Vrs9+A7t+qYPDJvOzQNfneMs=; b=NTTSdiXAMcokGV5pPK1MVvQnZ95L+JviWZpqPNu57t5IN5c7WCwKsfKb8bUihLLwM7 DSlksU9QLvNN6XeVSbmzDEJ0OeWbHxCo7A4bJc7nWd260X49HxlhhfpnNhUv1LXiATqz FCiT9j/iwxWHx3H3uMMI9ehyjwUvEyQBmCqKtQ89uoJrIBSiLfUzwDgxB5O4c0eQ0Co7 x1HK0yfRVeJMgJjVtHbZQDcucVB9fPVOR1m7x90z+LaL9SNWg6ofVxUBDLOUq1PNigHF jrpPWCil7qJQopWFgCY578aYl6h758oNz5K1yadKM0PjpbexRw4B0dNHKgmzGUC3HVp0 lf2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772691122; x=1773295922; 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=v9aOQtXPMrRyOq0vhd4Vrs9+A7t+qYPDJvOzQNfneMs=; b=AzBbj3pneu8lK7FsR/Q6qB9w5GttSWErjxHlhsU0W4wl6VHM+bcHVwkOJ9oCGvixsS Kawd3hWOzAGq7Oc8oGeKeT+C9oE+ZZ5rU6X+4BlWk8+NtyOfD1sZxF8tw0nMIdnE2CkE 4gdIVLPD+2S1FQ11P9iEXwjWf6C+vET8UIe93vujfArzIE6CgzQvdn8T5x83Y212zi+c JOj8DeQv/DNbb23pYbGWRBodrW1Y0urRTTIy6pqbPuTWhWHOeP/KWaDpohnKuD7uWrJR mmYBHT45h0XB95u4jchJBtqF2NRfLVadWVkgaWWIDV5HMRHY6Co0KhWwduImRvor0YRn UE3A== X-Forwarded-Encrypted: i=1; AJvYcCW5HuJ2tymZjXfHwbepA18vdkJrmds4PmkbxeOf1fMYPI6Mt7NvmLl3G/+yWZ2ihCQylQKBNxPrWwyYdog=@vger.kernel.org X-Gm-Message-State: AOJu0YzjXgzLXVhjlFQDzM117wA7+9dwIy2dHjLJBJ4Qk94aVYl7t1Jt 94eCUw0/A/rAv4mNoDbYcFJdj3XcN6YxgRnUCXQscceuZs+NnhkbCIa81bjp0/aT7CI= X-Gm-Gg: ATEYQzy8UMvDBgkbfpz2kh7U5trHlwu2nrC6OUvz0MUjUqy86SYlBH5yaH2vfSBrEB9 0D1s3p7ksXHfm73MAXarrOEAcF4U4uqg7r87skmhNUwvejCFsSQ40Zmqbp7mCK54UJfG7rtV+VD xOVUAgPkveK5lrT3JmdW3NxFVkayouIu6YYdCi8rNzIHfyvl6j5fj/7vZM8BO+6aPOz71WLUDez geWjMIH9WRLLzj8KAFbLk1fr8yEbSj3WdIA3nTpFr0KTOViuqMgg+/xMAeelz/BYtL6ik7AIAIl AwlCiW8j8qptegbLKjx62N3IbwdieBG30cZg40RwuS3IiQZp0LqCs2/e4h0g9KB4dJ8/2iD2UTx 6QwzqnQ0GcsYxC08Qb0QdBXqjzTvl6mneM1E6OHrUnzXHV4/S6BtORMRcdDVwu8ssZonIp74K+z dxC1DY5aNkeuAtlPglS4kkY76HO5PduuXPEKJ23m2WgGydzD6n4MFeLm+SZjLm4lUWWZYRFoBO7 z/Rd7BiNGBh8a8= X-Received: by 2002:a17:907:e106:b0:b94:e64:fe6a with SMTP id a640c23a62f3a-b940e65317amr30805866b.49.1772691121509; Wed, 04 Mar 2026 22:12:01 -0800 (PST) Received: from puffmais2.c.googlers.com (221.210.91.34.bc.googleusercontent.com. [34.91.210.221]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b935aec3243sm849355966b.53.2026.03.04.22.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2026 22:12:01 -0800 (PST) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Thu, 05 Mar 2026 06:11:58 +0000 Subject: [PATCH v6 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: <20260305-gs101-pd-v6-9-8cb953c1a723@linaro.org> References: <20260305-gs101-pd-v6-0-8cb953c1a723@linaro.org> In-Reply-To: <20260305-gs101-pd-v6-0-8cb953c1a723@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.3 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 41a232b3cdaf..f59986b56213 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.473.g4a7958ca14-goog