From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: Peter Griffin <peter.griffin@linaro.org>,
arnd@arndb.de, robh+dt@kernel.org,
krzysztof.kozlowski+dt@linaro.org, linux@roeck-us.net,
wim@linux-watchdog.org, conor+dt@kernel.org,
alim.akhtar@samsung.com, jaewon02.kim@samsung.com,
chanho61.park@samsung.com, semen.protsenko@linaro.org
Cc: kernel-team@android.com, tudor.ambarus@linaro.org,
andre.draszik@linaro.org, saravanak@google.com,
willmcvicker@google.com, linux-fsd@tesla.com,
linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org
Subject: Re: [PATCH 2/9] soc: samsung: exynos-pmu: Add exynos_pmu_update/read/write APIs and SoC quirks
Date: Tue, 23 Jan 2024 12:17:01 +0100 [thread overview]
Message-ID: <26b9a75c-3721-4d7a-985e-772d9f67e6d5@linaro.org> (raw)
In-Reply-To: <20240122225710.1952066-3-peter.griffin@linaro.org>
On 22/01/2024 23:57, Peter Griffin wrote:
> Newer Exynos SoCs have atomic set/clear bit hardware for PMU registers as
> these registers can be accessed by multiple masters. Some platforms also
> protect the PMU registers for security hardening reasons so they can't be
> written by normal world and are only write acessible in el3 via a SMC call.
Typo? accessible?
>
> Add support for both of these usecases using SoC specific quirks that are
> determined from the DT compatible string.>
> Drivers which need to read and write PMU registers should now use these
> new exynos_pmu_*() APIs instead of obtaining a regmap using
> syscon_regmap_lookup_by_phandle()
>
> Depending on the SoC specific quirks, the exynos_pmu_*() APIs will access
> the PMU register in the appropriate way.
>
> Signed-off-by: Peter Griffin <peter.griffin@linaro.org>
> ---
> drivers/soc/samsung/exynos-pmu.c | 209 ++++++++++++++++++++++++-
> drivers/soc/samsung/exynos-pmu.h | 4 +
> include/linux/soc/samsung/exynos-pmu.h | 28 ++++
> 3 files changed, 234 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/soc/samsung/exynos-pmu.c b/drivers/soc/samsung/exynos-pmu.c
> index 250537d7cfd6..e9e933ede568 100644
> --- a/drivers/soc/samsung/exynos-pmu.c
> +++ b/drivers/soc/samsung/exynos-pmu.c
> @@ -5,6 +5,7 @@
> //
> // Exynos - CPU PMU(Power Management Unit) support
>
> +#include <linux/arm-smccc.h>
> #include <linux/of.h>
> #include <linux/of_address.h>
> #include <linux/mfd/core.h>
> @@ -12,29 +13,204 @@
> #include <linux/of_platform.h>
> #include <linux/platform_device.h>
> #include <linux/delay.h>
> +#include <linux/regmap.h>
>
> #include <linux/soc/samsung/exynos-regs-pmu.h>
> #include <linux/soc/samsung/exynos-pmu.h>
>
> #include "exynos-pmu.h"
>
> +/**
> + * DOC: Quirk flags for different Exynos PMU IP-cores
> + *
> + * This driver supports multiple Exynos based SoCs, each of which might have a
> + * different set of registers and features supported.
> + *
> + * Quirk flags described below serve the purpose of telling the driver about
> + * mentioned SoC traits, and can be specified in driver data for each particular
> + * supported device.
> + *
> + * %QUIRK_HAS_ATOMIC_BITSETHW: PMU IP has special atomic bit set/clear HW
> + * to protect against PMU registers being accessed from multiple bus masters.
> + *
> + * %QUIRK_PMU_ALIVE_WRITE_SEC: PMU registers are *not* write accesible from
> + * normal world. This is found on some SoCs as a security hardening measure. PMU
> + * registers on these SoCs can only be written via a SMC call and registers are
> + * checked by EL3 firmware against an allowlist before the write can procede.
> + * Note: This quirk should only be set for platforms whose el3 firmware
> + * implements the TENSOR_SMC_PMU_SEC_REG interface below.
> + */
> +
> +#define QUIRK_HAS_ATOMIC_BITSETHW BIT(0)
> +#define QUIRK_PMU_ALIVE_WRITE_SEC BIT(1)
> +
> +#define PMUALIVE_MASK GENMASK(14, 0)
> +
> struct exynos_pmu_context {
> struct device *dev;
> const struct exynos_pmu_data *pmu_data;
> + struct regmap *pmureg;
> + void __iomem *pmu_base_addr;
> + phys_addr_t pmu_base_pa;
> + /* protect PMU reg atomic update operations */
> + spinlock_t update_lock;
> };
>
> -void __iomem *pmu_base_addr;
> static struct exynos_pmu_context *pmu_context;
>
> +/*
> + * Some SoCs are configured so that PMU_ALIVE registers can only be written
> + * from el3. As Linux needs to write some of these registers, the following
> + * SMC register read/write/read,write,modify interface is used.
> + *
> + * Note: This SMC interface is known to be implemented on gs101 and derivative
> + * SoCs.
> + */
> +#define TENSOR_SMC_PMU_SEC_REG (0x82000504)
> +#define TENSOR_PMUREG_READ 0
> +#define TENSOR_PMUREG_WRITE 1
> +#define TENSOR_PMUREG_RMW 2
These are tensor specific...
> +
> +int set_priv_reg(phys_addr_t reg, u32 val)
...but this not...
> +{
> + struct arm_smccc_res res;
> +
> + arm_smccc_smc(TENSOR_SMC_PMU_SEC_REG,
... and this is again.
Some naming should be clarified, e.g. tensor specific functions should
have some prefix as well, e.g. tensor_writel(), tensor_cmpxchg() or
something similar.
> + reg,
> + TENSOR_PMUREG_WRITE,
> + val, 0, 0, 0, 0, &res);
> +
> + if (res.a0)
> + pr_warn("%s(): SMC failed: %lu\n", __func__, res.a0);
> +
> + return (int)res.a0;
> +}
> +
> +int rmw_priv_reg(phys_addr_t reg, u32 mask, u32 val)
> +{
> + struct arm_smccc_res res;
> +
> + arm_smccc_smc(TENSOR_SMC_PMU_SEC_REG,
> + reg,
> + TENSOR_PMUREG_RMW,
> + mask, val, 0, 0, 0, &res);
> +
> + if (res.a0)
> + pr_warn("%s(): SMC failed: %lu\n", __func__, res.a0);
> +
> + return (int)res.a0;
> +}
> +
> +/*
> + * For SoCs that have set/clear bit hardware (as indicated by
> + * QUIRK_HAS_ATOMIC_BITSETHW) this function can be used when
> + * the PMU register will be accessed by multiple masters.
> + *
> + * For example, to set bits 13:8 in PMU reg offset 0x3e80
> + * exynos_pmu_set_bit_atomic(0x3e80, 0x3f00, 0x3f00);
> + *
> + * To clear bits 13:8 in PMU offset 0x3e80
> + * exynos_pmu_set_bit_atomic(0x3e80, 0x0, 0x3f00);
> + */
> +static inline void exynos_pmu_set_bit_atomic(unsigned int offset,
> + u32 val, u32 mask)
> +{
> + unsigned long flags;
> + unsigned int i;
> +
> + spin_lock_irqsave(&pmu_context->update_lock, flags);
> + for (i = 0; i < 32; i++) {
> + if (mask & BIT(i)) {
> + if (val & BIT(i)) {
> + offset |= 0xc000;
> + pmu_raw_writel(i, offset);
> + } else {
> + offset |= 0x8000;
> + pmu_raw_writel(i, offset);
> + }
> + }
> + }
> + spin_unlock_irqrestore(&pmu_context->update_lock, flags);
> +}
> +
> +int exynos_pmu_update_bits(unsigned int offset, unsigned int mask,
> + unsigned int val)
> +{
> + if (pmu_context->pmu_data &&
> + pmu_context->pmu_data->quirks & QUIRK_PMU_ALIVE_WRITE_SEC)
> + return rmw_priv_reg(pmu_context->pmu_base_pa + offset,
> + mask, val);
> +
> + return regmap_update_bits(pmu_context->pmureg, offset, mask, val);
> +}
> +EXPORT_SYMBOL(exynos_pmu_update_bits);
You need kerneldoc for all exported functions.
Also, EXPORT_SYMBOL_GPL
> +
> void pmu_raw_writel(u32 val, u32 offset)
> {
> - writel_relaxed(val, pmu_base_addr + offset);
> + if (pmu_context->pmu_data &&
> + pmu_context->pmu_data->quirks & QUIRK_PMU_ALIVE_WRITE_SEC)
> + return (void)set_priv_reg(pmu_context->pmu_base_pa + offset,
> + val);
> +
> + return writel_relaxed(val, pmu_context->pmu_base_addr + offset);
> }
>
...
> diff --git a/drivers/soc/samsung/exynos-pmu.h b/drivers/soc/samsung/exynos-pmu.h
> index 1c652ffd79b4..570c6e4dc8c3 100644
> --- a/drivers/soc/samsung/exynos-pmu.h
> +++ b/drivers/soc/samsung/exynos-pmu.h
> @@ -25,8 +25,12 @@ struct exynos_pmu_data {
> void (*pmu_init)(void);
> void (*powerdown_conf)(enum sys_powerdown);
> void (*powerdown_conf_extra)(enum sys_powerdown);
> + u32 quirks;
> };
>
> +int set_priv_reg(phys_addr_t reg, u32 val);
> +int rmw_priv_reg(phys_addr_t reg, u32 mask, u32 val);
Why these are in the header?
Best regards,
Krzysztof
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-01-23 11:17 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-22 22:57 [PATCH 0/9] Add exynos_pmu_update/read/write() APIs to exynos-pmu Peter Griffin
2024-01-22 22:57 ` [PATCH 1/9] dt-bindings: watchdog: samsung-wdt: deprecate samsung,syscon-phandle Peter Griffin
2024-01-23 11:09 ` Krzysztof Kozlowski
2024-01-22 22:57 ` [PATCH 2/9] soc: samsung: exynos-pmu: Add exynos_pmu_update/read/write APIs and SoC quirks Peter Griffin
2024-01-23 8:10 ` Arnd Bergmann
2024-01-24 10:21 ` Peter Griffin
2024-01-23 11:17 ` Krzysztof Kozlowski [this message]
2024-01-24 10:41 ` Peter Griffin
2024-01-23 18:56 ` Sam Protsenko
2024-01-24 10:02 ` Peter Griffin
2024-01-24 20:23 ` Sam Protsenko
2024-01-25 10:48 ` Peter Griffin
2024-01-26 17:26 ` kernel test robot
2024-01-26 23:07 ` kernel test robot
2024-01-22 22:57 ` [PATCH 3/9] watchdog: s3c2410_wdt: update to use new exynos_pmu_*() apis Peter Griffin
2024-01-23 10:33 ` Guenter Roeck
2024-01-23 15:35 ` Peter Griffin
2024-01-23 11:19 ` Krzysztof Kozlowski
2024-01-23 17:30 ` Peter Griffin
2024-01-23 18:12 ` Krzysztof Kozlowski
2024-01-24 3:37 ` Saravana Kannan
2024-01-24 6:27 ` Krzysztof Kozlowski
2024-01-24 21:27 ` Saravana Kannan
2024-01-25 7:37 ` Krzysztof Kozlowski
2024-01-25 11:46 ` Lee Jones
2024-01-26 2:23 ` Saravana Kannan
2024-01-26 8:43 ` Lee Jones
2024-01-26 2:17 ` Saravana Kannan
2024-01-25 13:19 ` Peter Griffin
2024-01-30 20:27 ` Rob Herring
2024-01-26 17:04 ` kernel test robot
2024-01-22 22:57 ` [PATCH 4/9] arm64: dts: fsd: remove deprecated samsung,syscon-phandle Peter Griffin
2024-01-22 22:57 ` [PATCH 5/9] arm64: dts: exynosautov9: " Peter Griffin
2024-01-22 22:57 ` [PATCH 6/9] arm64: dts: exynos850: " Peter Griffin
2024-01-22 22:57 ` [PATCH 7/9] arm64: dts: exynos7: " Peter Griffin
2024-01-22 22:57 ` [PATCH 8/9] ARM: dts: samsung: exynos4: " Peter Griffin
2024-01-22 22:57 ` [PATCH 9/9] ARM: dts: exynos5250: " Peter Griffin
2024-01-23 7:41 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=26b9a75c-3721-4d7a-985e-772d9f67e6d5@linaro.org \
--to=krzysztof.kozlowski@linaro.org \
--cc=alim.akhtar@samsung.com \
--cc=andre.draszik@linaro.org \
--cc=arnd@arndb.de \
--cc=chanho61.park@samsung.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jaewon02.kim@samsung.com \
--cc=kernel-team@android.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-fsd@tesla.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=peter.griffin@linaro.org \
--cc=robh+dt@kernel.org \
--cc=saravanak@google.com \
--cc=semen.protsenko@linaro.org \
--cc=tudor.ambarus@linaro.org \
--cc=willmcvicker@google.com \
--cc=wim@linux-watchdog.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).