Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp12992833rwl; Wed, 4 Jan 2023 01:47:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXvSGFR9loieMv+70J4IobJ6pYmHURl9RxOxE8RAsWDZ6Cvgn232Ozdp8Z1y2u+j1wUCF0wM X-Received: by 2002:a17:907:6ea9:b0:7c0:e7ad:5296 with SMTP id sh41-20020a1709076ea900b007c0e7ad5296mr51213138ejc.55.1672825662950; Wed, 04 Jan 2023 01:47:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672825662; cv=none; d=google.com; s=arc-20160816; b=tNX1l2HL5Fp6ynK6CGRvVP4+i9NYXzxcKaDvNA2M4FsqI4DAvIcR9H7O31Aj+AHy5p qEpMJ9tq0fNgwyX9m61WQxA4JO5m3tyc8S1F6Z79cbY0K/SjmAF2sSu/57xtYsFH6F9s zt+4p8n/pQKoZ6GOk7wv0iCqe5aSqJ/Co0yMDXdkLE3Cr0roYDWFm+j9L4WPcrpe44+F xk+ihM0m2mpKy6qux1G+viR5ksG8/obvHn0HQolzA+bqWQG7hh8jZQO5Bxs5IRcahxYJ iSNJgcLLeAONmNqCHJUfbXsLIsnMSGAHPtvviIwcaTSlb8vFerRPSmDyVZ3zlzSJqoAn dHvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8CmEXY85Wfe5zRCPYTM22tY3+v8slzBjcPUwowPXH7Q=; b=KW4MsXFjMbZkpEdD8sa7AarNrAh/PjU6g8/zxr3omr3B5pmoCalilGYKf5oJCgl1xl U5Uf9VV6PAp0bTF63xlIN/MygzUZiFtSJjO89eWcagaZDCbw8wlAAjh16QvC9rvK3mpJ kzccxOrtYA6Un4IJS5/GQEXrO5qTwMEcmMoa3WpPazhi+xc5b3wgbov/HRGS8VbOzKWC WTti73R+xObVBiUIW3dGRFDBUUF5297T99M/6xJ1DlMmbB2xttftOjFXYMehTFHXkOBf gx1CIrC2nOdCclvl33wHnkkcRNkOx1b0vT59yANOsVLonYZux3EBixIMyMAq0oZcHj4S 24mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YbFROjWc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he7-20020a1709073d8700b008327270a7fesi34386380ejc.538.2023.01.04.01.47.29; Wed, 04 Jan 2023 01:47:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YbFROjWc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234532AbjADJay (ORCPT + 57 others); Wed, 4 Jan 2023 04:30:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233067AbjADJaw (ORCPT ); Wed, 4 Jan 2023 04:30:52 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00527D9B for ; Wed, 4 Jan 2023 01:30:50 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id fc4so81064647ejc.12 for ; Wed, 04 Jan 2023 01:30:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8CmEXY85Wfe5zRCPYTM22tY3+v8slzBjcPUwowPXH7Q=; b=YbFROjWcXuYpdMirg154U9mKDnTGYVd9fIuzWkgW4bVOFDMxgXQ0zHIUxFUcyrX2Zb 30BKXYeNJWNG4wOeKq0Anr2+a692z3+W/K1xC7AsfzpEfRLviiG04KgVmDJDPc+BcP4J l6riXWXBS8z1jliXdzP22d7oVVY/qT16oX8N76iWJXMs0/SCWdVEZLamFmHli+QVQoOH JVfGKyQRbvs7ibMd/j1CiCoeleZJU1egZ+AD9owYwKmFbV77po19ss0O50OcqHSpFz3T 44G3FcZ0Yp/++aj/aiYEdpko21rITUVVHczq1OHEFhSsXKv3FoZO+opchShyr6v/tWeG nTMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8CmEXY85Wfe5zRCPYTM22tY3+v8slzBjcPUwowPXH7Q=; b=BX9plNkxbN4tMUE1p2BpgJbcBW+shcjWUPNW1mgZFTYOGeqPyUB7GkKnTRAl+90slU jh70jtSR+MvaIFBxndKac4U2VYuIdwh+m3V5YDhzvWubOxdRjNsSejXZlbPxQcqiUjwr fhOIANJcCHbbcDsa2aMYbsZ81T5gHPhwNRPiluPkAMqIkYc5cWNZKniPMTfTda1Xk9Tm D9RF5N/Iyjsx/OjcKqnEcAzEQmc/tuzN4nXSv7Mf9BQC5KeS3p9cO6jAB8uB37HGPC96 cQY6QaCC/RWvByEJ6yCwFtkbTEihRdcacaeqRfbPOMWeHUkZLYJZpRMvuZmbHc/n2QnL w2Tw== X-Gm-Message-State: AFqh2kp4WNPRHJ5lH04XXFGVETfGjiSDFsY54XcNDTVXIShFTgr+zeIG Pp9TkFXeyoUwPyWydii2EEjfWM+lcvsivMlJA3zZ9w== X-Received: by 2002:a17:906:4ecb:b0:7bc:2ad:fae with SMTP id i11-20020a1709064ecb00b007bc02ad0faemr3244245ejv.724.1672824649391; Wed, 04 Jan 2023 01:30:49 -0800 (PST) MIME-Version: 1.0 References: <20230103140521.187678-1-patrick.delaunay@foss.st.com> <20230103150515.v4.3.I59210046e368cfc22bd3cca2afe1653674f8ece8@changeid> In-Reply-To: <20230103150515.v4.3.I59210046e368cfc22bd3cca2afe1653674f8ece8@changeid> From: Etienne Carriere Date: Wed, 4 Jan 2023 10:30:38 +0100 Message-ID: Subject: Re: [PATCH v4 3/3] nvmem: stm32: detect bsec pta presence for STM32MP15x To: Patrick Delaunay Cc: Alexandre TORGUE , Srinivas Kandagatla , Maxime Coquelin , Lionel DEBIEVE , Amelie DELAUNAY , Fabrice GASNIER , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Patrick, On Tue, 3 Jan 2023 at 15:08, Patrick Delaunay 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 > --- > > (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. Br, etienne > return rc; > rc = devm_add_action_or_reset(dev, stm32_bsec_optee_ta_close, priv->ctx); > if (rc) { > -- > 2.25.1 >