Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp6810585rwb; Wed, 18 Jan 2023 09:36:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXud91faF2JPWGRMQGqfXMfp4gfhGOTieghwCC3a+Oj1otCpHcIc18dRufdx8OazXY3cijfn X-Received: by 2002:a17:907:c019:b0:867:ef3f:dd85 with SMTP id ss25-20020a170907c01900b00867ef3fdd85mr4437585ejc.56.1674063393377; Wed, 18 Jan 2023 09:36:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674063393; cv=none; d=google.com; s=arc-20160816; b=yZ/Q4OsEzwUtig8SlByK0ToDK1e9AFbtxgJSD4I6CHuQCwz7Cb7ghfjNTIVWuk7afz WxaSdOtQA3OAsMvB8Uh4WPkMxeE81I6tQ5hBzf/A1x7ixsPX/HOGCY/24rDxykM8dTw9 5B76xYnoPS7TAGQXE5g6ssZg6/gmeSo04gQDH/yoS/F3gQRsMP1+QYmGN0T0TjDECaFh twNM0k7skO2Hrfb8wuf84pboxL0dJZT3tnqsJNiMtdbrRusbWpRL15QQTkj/6BktCuPi d/y4vKVjbXtbrHIQYFup0a6tdny//ln1M8jAY3wBCRpz3ZhAor2HPJixyT0wwtiDfwK9 kjSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZyZacvmPX30CnzTNwDG1lwIQ0Nni4QdJteNf/VXJ/S8=; b=KjS+61I1IAoiv9h4Y1XrPBc/Ssgo95ZZ/01h9RwS5rwURLkPq07YHl58JhGHIN5iQ7 6CmOnQf6Y5CbNnkqoJ2LOFz6l7G3GAdclprqB6TRKsxu/Hhmi+EyyxOrj6gYnW7f17mj l6sKa7LeLmPoYL/0SjsikTBVIiSwIYSx8BkrcKt9PDzVgY35J8tdnRlDQtRO/4zmlelN kLNLsM6OCTunvaiu8TfOoXMlhZyz5z1H/pSqcP57xPbTdF1WR3NgJgk/bw+5E1KxBo4K MI5j1Vis0k1rNOYO1AYn6snXFWd4ZloIhO9V1oNuGXqisCY1NaPcZpYY8YS+n6b7AN8b OePQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=1xDLVJPr; 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=foss.st.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc9-20020a1709071c0900b0086d6cc19f9bsi17576951ejc.166.2023.01.18.09.36.22; Wed, 18 Jan 2023 09:36:33 -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=@foss.st.com header.s=selector1 header.b=1xDLVJPr; 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=foss.st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbjARRaK (ORCPT + 45 others); Wed, 18 Jan 2023 12:30:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230212AbjARRaE (ORCPT ); Wed, 18 Jan 2023 12:30:04 -0500 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB8EF4AA56 for ; Wed, 18 Jan 2023 09:30:01 -0800 (PST) Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30IHHSYM013300; Wed, 18 Jan 2023 18:29:51 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=ZyZacvmPX30CnzTNwDG1lwIQ0Nni4QdJteNf/VXJ/S8=; b=1xDLVJPrDMSNWFhGPGMhI01oyod1zhndHSgCXMtMcGDXpQZZekbqz6lUAfpeAQ3hXZwT jJFlI7MKTpjSi2QCb8OIvVr51F1uNvWPvMGxdKG78Cmcn5w/ibL+p/S1jFpfTY2r0rAm 9jeLwBg28ipR6ZGkfnYovzhpc1hkoPWVnzAInAx/agqvX5dPUr1f3Qx5QoQvTaaRxe4J 52qySX24f2MGAm4NQkxN4YTXWxUVlu55mmyG+KeX2mm+IV4jn96LtmuwTFNRyzgJMT/E DzY/B9ghg8+9knj3bi08Qp1REvI18E6UlCNKnB4dwm2kDXDwfwdTJwpv48o8eBRLhNbO qg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3n5mc4uhmb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Jan 2023 18:29:51 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DF0C410002A; Wed, 18 Jan 2023 18:29:50 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node3.st.com [10.75.129.71]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id DA2EE228A21; Wed, 18 Jan 2023 18:29:50 +0100 (CET) Received: from localhost (10.48.0.157) by SHFDAG1NODE3.st.com (10.75.129.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.13; Wed, 18 Jan 2023 18:29:50 +0100 From: Patrick Delaunay To: Alexandre TORGUE , Srinivas Kandagatla , Maxime Coquelin CC: Etienne CARRIERE , Fabrice GASNIER , Amelie DELAUNAY , Lionel DEBIEVE , Patrick Delaunay , , , Subject: [PATCH v6 3/3] nvmem: stm32: detect bsec pta presence for STM32MP15x Date: Wed, 18 Jan 2023 18:29:39 +0100 Message-ID: <20230118182856.v6.3.I59210046e368cfc22bd3cca2afe1653674f8ece8@changeid> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230118172940.841094-1-patrick.delaunay@foss.st.com> References: <20230118172940.841094-1-patrick.delaunay@foss.st.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.48.0.157] X-ClientProxiedBy: SHFCAS1NODE1.st.com (10.75.129.72) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-18_05,2023-01-18_01,2022-06-22_01 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,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 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 Reviewed-by: Etienne Carriere --- Changes in v6: - added reviewed by Etienne Carriere Changes in v5: - update the BSEC SMC detection logic in stm32_romem_probe() after Etienne Carierre review to support NVMEM probe after OP-TEE probe 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 | 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