mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Patrick DELAUNAY <patrick.delaunay@foss.st.com>
To: Etienne Carriere <etienne.carriere@linaro.org>
Cc: Alexandre TORGUE <alexandre.torgue@foss.st.com>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Lionel DEBIEVE <lionel.debieve@foss.st.com>,
	Amelie DELAUNAY <amelie.delaunay@foss.st.com>,
	Fabrice GASNIER <fabrice.gasnier@foss.st.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>
Subject: Re: [PATCH v4 3/3] nvmem: stm32: detect bsec pta presence for STM32MP15x
Date: Wed, 4 Jan 2023 14:02:21 +0100	[thread overview]
Message-ID: <5d7dac5f-2a39-316f-2123-fe2e7808eec0@foss.st.com> (raw)
In-Reply-To: <CAN5uoS-dXLSs9DiJFBTAOJbPZPp4BUfxqZ7ND_irzBbUEwaUHg@mail.gmail.com>

Hi,

On 1/4/23 10:30, Etienne Carriere wrote:
> Hi Patrick,
>
> On Tue, 3 Jan 2023 at 15:08, Patrick Delaunay
> <patrick.delaunay@foss.st.com> wrote:
>> 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>
>> ---
>>
>> (no changes since v3)
>>
>> Changes in v3:
>> - use of_find_compatible_node in optee_presence_check function
>>    instead of of_find_node_by_path("/firmware/optee")
>>
>> Changes in v2:
>> - Added patch in the serie for BSEC PTA support on STM32MP15x
>>    with dynamic detection of OP-TEE presence and SMC support (legacy mode)
>>
>>   drivers/nvmem/stm32-romem.c | 33 +++++++++++++++++++++++++++++++--
>>   1 file changed, 31 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/nvmem/stm32-romem.c b/drivers/nvmem/stm32-romem.c
>> index 2edc61925e52..1b90c78301fa 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,10 +220,14 @@ 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)
>> +                       if (rc == -EPROBE_DEFER) {
>> +                               /* BSEC PTA is required or SMC not ready */
>> +                               if (cfg->ta || !stm32_bsec_smc_check())
>> +                                       return -EPROBE_DEFER;
>> +                       } else if (rc)
> Could you fix the logic? The sequence here fails to fallback to BSEC
> SMC service if optee does not embed BSEC PTA service and optee driver
> is probed before stm32_romem.


Yes, I will modify it...


my patch is working only if OP-TEE is probed after BSEC NVMEM when RC = 
defered


stm32_bsec_smc_check() is  not called the OP-TEE is already porbed

(not deferred) but TA is not integrated


>
> Br,
> etienne
>
>>                                  return rc;
>>                          rc = devm_add_action_or_reset(dev, stm32_bsec_optee_ta_close, priv->ctx);
>>                          if (rc) {
>> --
>> 2.25.1
>>

      reply	other threads:[~2023-01-04 13:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-03 14:05 [PATCH v4 0/3] nvmem: stm32: add OP-TEE support for STM32MP13x Patrick Delaunay
2023-01-03 14:05 ` [PATCH v4 1/3] ARM: dts: stm32mp13: fix compatible for BSEC Patrick Delaunay
2023-01-03 14:05 ` [PATCH v4 2/3] nvmem: stm32: add OP-TEE support for STM32MP13x Patrick Delaunay
2023-01-04  9:24   ` Etienne Carriere
2023-01-04 12:55     ` Patrick DELAUNAY
2023-01-03 14:05 ` [PATCH v4 3/3] nvmem: stm32: detect bsec pta presence for STM32MP15x Patrick Delaunay
2023-01-04  9:30   ` Etienne Carriere
2023-01-04 13:02     ` Patrick DELAUNAY [this message]

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=5d7dac5f-2a39-316f-2123-fe2e7808eec0@foss.st.com \
    --to=patrick.delaunay@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=amelie.delaunay@foss.st.com \
    --cc=etienne.carriere@linaro.org \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=lionel.debieve@foss.st.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=srinivas.kandagatla@linaro.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

all inboxes | Powered by JetHome®