linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org,
	Patrick Delaunay <patrick.delaunay@foss.st.com>,
	Etienne Carriere <etienne.carriere@linaro.org>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Subject: [PATCH 32/37] nvmem: stm32: detect bsec pta presence for STM32MP15x
Date: Fri, 27 Jan 2023 11:16:00 +0000	[thread overview]
Message-ID: <20230127111605.25958-33-srinivas.kandagatla@linaro.org> (raw)
In-Reply-To: <20230127111605.25958-1-srinivas.kandagatla@linaro.org>

From: Patrick Delaunay <patrick.delaunay@foss.st.com>

On STM32MP15x SoC, the SMC backend is optional when OP-TEE is used;
the PTA BSEC should be used as it is done on STM32MP13x platform,
but the BSEC SMC can be also used: it is a legacy mode in OP-TEE,
not recommended but used in previous OP-TEE firmware.

The presence of OP-TEE is dynamically detected in STM32MP15x device tree
and the supported NVMEM backend is dynamically detected:
- PTA with stm32_bsec_pta_find
- SMC with stm32_bsec_check

With OP-TEE but without PTA and SMC detection, the probe is deferred for
STM32MP15x devices.

On STM32MP13x platform, only the PTA is supported with cfg->ta = true
and this detection is skipped.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/stm32-romem.c | 38 +++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/drivers/nvmem/stm32-romem.c b/drivers/nvmem/stm32-romem.c
index 978a63edf297..ba779e26937a 100644
--- a/drivers/nvmem/stm32-romem.c
+++ b/drivers/nvmem/stm32-romem.c
@@ -159,6 +159,31 @@ static int stm32_bsec_pta_write(void *context, unsigned int offset, void *buf,
 	return stm32_bsec_optee_ta_write(priv->ctx, priv->lower, offset, buf, bytes);
 }
 
+static bool stm32_bsec_smc_check(void)
+{
+	u32 val;
+	int ret;
+
+	/* check that the OP-TEE support the BSEC SMC (legacy mode) */
+	ret = stm32_bsec_smc(STM32_SMC_READ_SHADOW, 0, 0, &val);
+
+	return !ret;
+}
+
+static bool optee_presence_check(void)
+{
+	struct device_node *np;
+	bool tee_detected = false;
+
+	/* check that the OP-TEE node is present and available. */
+	np = of_find_compatible_node(NULL, NULL, "linaro,optee-tz");
+	if (np && of_device_is_available(np))
+		tee_detected = true;
+	of_node_put(np);
+
+	return tee_detected;
+}
+
 static int stm32_romem_probe(struct platform_device *pdev)
 {
 	const struct stm32_romem_cfg *cfg;
@@ -195,11 +220,16 @@ static int stm32_romem_probe(struct platform_device *pdev)
 	} else {
 		priv->cfg.size = cfg->size;
 		priv->lower = cfg->lower;
-		if (cfg->ta) {
+		if (cfg->ta || optee_presence_check()) {
 			rc = stm32_bsec_optee_ta_open(&priv->ctx);
-			/* wait for OP-TEE client driver to be up and ready */
-			if (rc)
-				return rc;
+			if (rc) {
+				/* wait for OP-TEE client driver to be up and ready */
+				if (rc == -EPROBE_DEFER)
+					return -EPROBE_DEFER;
+				/* BSEC PTA is required or SMC not supported */
+				if (cfg->ta || !stm32_bsec_smc_check())
+					return rc;
+			}
 		}
 		if (priv->ctx) {
 			rc = devm_add_action_or_reset(dev, stm32_bsec_optee_ta_close, priv->ctx);
-- 
2.25.1


  parent reply	other threads:[~2023-01-27 11:19 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-27 11:15 [PATCH 00/37] nvmem: patches for 6.3 Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 01/37] nvmem: sunxi_sid: Drop the workaround on A64 Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 02/37] dt-bindings: nvmem: Fix qcom,qfprom compatibles enum ordering Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 03/37] dt-bindings: nvmem: Add compatible for MSM8976 Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 04/37] dt-bindings: nvmem: qfprom: add sdm670 compatible Srinivas Kandagatla
2023-01-27 23:39   ` Richard Acayan
2023-01-27 11:15 ` [PATCH 05/37] dt-bindings: nvmem: Add compatible for SM8150 Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 06/37] dt-bindings: nvmem: Add compatible for SM8250 Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 07/37] nvmem: core: remove spurious white space Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 08/37] net: add helper eth_addr_add() Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 09/37] of: base: add of_parse_phandle_with_optional_args() Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 10/37] of: property: make #.*-cells optional for simple props Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 11/37] of: property: add #nvmem-cell-cells property Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 12/37] nvmem: core: add an index parameter to the cell Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 13/37] nvmem: core: move struct nvmem_cell_info to nvmem-provider.h Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 14/37] nvmem: core: drop the removal of the cells in nvmem_add_cells() Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 15/37] nvmem: core: add nvmem_add_one_cell() Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 16/37] nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of() Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 17/37] nvmem: core: introduce NVMEM layouts Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 18/37] nvmem: core: add per-cell post processing Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 19/37] nvmem: core: allow to modify a cell before adding it Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 20/37] nvmem: imx-ocotp: replace global post processing with layouts Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 21/37] nvmem: cell: drop global cell_post_process Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 22/37] nvmem: core: provide own priv pointer in post process callback Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 23/37] nvmem: layouts: add sl28vpd layout Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 24/37] MAINTAINERS: add myself as sl28vpd nvmem layout driver Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 25/37] nvmem: layouts: Add ONIE tlv " Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 26/37] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 27/37] nvmem: core: return -ENOENT if nvmem cell is not found Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 28/37] nvmem: layouts: Fix spelling mistake "platforn" -> "platform" Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 29/37] dt-bindings: nvmem: " Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 30/37] nvmem: core: fix nvmem_layout_get_match_data() Srinivas Kandagatla
2023-01-27 11:15 ` [PATCH 31/37] nvmem: stm32: add OP-TEE support for STM32MP13x Srinivas Kandagatla
2023-01-27 11:16 ` Srinivas Kandagatla [this message]
2023-01-27 11:16 ` [PATCH 33/37] nvmem: rave-sp-eeprm: fix kernel-doc bad line warning Srinivas Kandagatla
2023-01-27 11:16 ` [PATCH 34/37] of: property: fix #nvmem-cell-cells parsing Srinivas Kandagatla
2023-01-27 11:16 ` [PATCH 35/37] nvmem: qcom-spmi-sdam: register at device init time Srinivas Kandagatla
2023-01-27 11:16 ` [PATCH 36/37] dt-bindings: nvmem: qfprom: add IPQ8074 compatible Srinivas Kandagatla
2023-01-27 11:16 ` [PATCH 37/37] nvmem: stm32: fix OPTEE dependency Srinivas Kandagatla
2023-01-28 13:43 ` [PATCH 00/37] nvmem: patches for 6.3 Greg KH
2023-01-30 11:27   ` Srinivas Kandagatla
2023-01-30 11:59     ` Greg KH
2023-01-30 15:54       ` Srinivas Kandagatla
2023-02-06  7:45         ` Greg KH
2023-02-06  7:46           ` Greg KH
2023-02-06 10:13             ` Srinivas Kandagatla

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=20230127111605.25958-33-srinivas.kandagatla@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --cc=etienne.carriere@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patrick.delaunay@foss.st.com \
    /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).