From patchwork Wed Feb 14 17:21:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 201069 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1374826dyb; Wed, 14 Feb 2024 09:27:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWsm+VGyQA3Dg8KHDlfjL7XYM+OiTcXWzrot4HSrCD56vvOmaq1+3dKN1nO9Cm1qE/2tJLJAMW8dkOiknomc7dqgA7uKA== X-Google-Smtp-Source: AGHT+IHxd09BQ33RWC0U3axqOjHukFv5SrN+Q7ihoKcLzfGNq6bNOR7pSPmyLByEm731JgnkqbA+ X-Received: by 2002:a0c:f5d3:0:b0:68f:f77:c244 with SMTP id q19-20020a0cf5d3000000b0068f0f77c244mr898203qvm.39.1707931673474; Wed, 14 Feb 2024 09:27:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707931673; cv=pass; d=google.com; s=arc-20160816; b=ZMxUAPet2oOA5GaUhhte4lYMQM7U9JC5z9BV7FAaevr9nmJhq70bM4jtMIuk0lLj61 7Wgej6wZFys3aQvmI4LtF5DfJp7yVZEzZScLPQMcZyDpAO6OAA+I4X9lCUPUlFaRzVK/ K8sCTxUXpepbFLy1niwrjd+R+k/EjrVdllGtyhBH1Vu5986utOdq9am6VWnRuJf17ah9 FaNt/qyMiol/klTKPFdY/rz2NjnGZP9lbNaZa7VjsU6jb4ISY770Y/+tPSFPAU8ZsiO3 RGcMWawhSaLolYMkyhhP+o3qCmIM3bg6NT2vxaT0+XSnSrVyEexs0dqwukpUOPw19lXG gbkQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=K2Graluvn6S/uk5IoYFuUnt/03+G2vYPHh6CzkWCGJA=; fh=vfJG2rOm6jGVTwcbsFyldC8yFLl5T9ywArWiGZmtcCM=; b=Xyj9N75KkUkeYwmaNAjq0591kQ9+apiOdNI875MvBn5YbIZVdm1AHatRI4utRZ/xFL VaaASiLdqiRtt2w7pgmUYpo8kq7zBRJ1lRwLGQ0xkUu4DvF2gSsGe3JjkXn2AHDG83MS 8TbO/Z8cQb78GvYNN4wr9Y7QmU3tFWkZRtGYicZd6PrFVlW759pARFMX/17ogbQpjsYk QG1R2WSbKZfOrPJPbk0DzPvg+UXLBeHfMpDnBkQMNwmDeSrbKu0S6+ZFNfAXH/yMsA7X 0bjO9BCnXqLhbjJ9lnQs88bBZrVpCUZfcRwvIwh3wV10rCP4u7+rmI3Mwh1G+LC1230T LoXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=nEhYObNi; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65666-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65666-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com X-Forwarded-Encrypted: i=2; AJvYcCV8/e2hc4vV3wAhg8d9M1+0tCa7/0oF9RGslvGlAJgIHj4DkD6atOzpGn0/Zdfr3HMIixnAxiS/+c3GAgX3VDA0J+wL3g== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jl9-20020ad45e89000000b0068d14dd8c21si5797540qvb.421.2024.02.14.09.27.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:27:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65666-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=nEhYObNi; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65666-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65666-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 03BEB1C217D9 for ; Wed, 14 Feb 2024 17:27:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA14012BE8D; Wed, 14 Feb 2024 17:22:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="nEhYObNi" Received: from mx08-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F37521272A4; Wed, 14 Feb 2024 17:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931363; cv=none; b=oChUOpbllylywkn0n05dQ9u/twjVi2S6qmZofnoQE7Z7D0G7Mwj9QDINA1ue2RO3QZDZu1BUv/l+/zH5QgZmdw6fH8NYbnxMftRwaJudCIKiE1XdMJsANaJ1cJwXDOxMVvZlaH2Jzlo4JonsP49jIpv91bhrY/4sXMUr2AvELOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931363; c=relaxed/simple; bh=2o5qpjSxqpjzu8CKyQg3o28GztWBaSv/PU+gt+3faWk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HP+N24QU5V8X9FM9qWLVokl9AFdmQz1Geh5rF61Kg5nw/N3WeCVeIf3tvxg2cZtXSvTW9BGVnuaYezoqlhSX3SgpXS3U0hBaQkuZPPpFzZV8WSFoqXFkJSPKxeJqADYtzI8EknM01RqiQIAemifKO/1AdeHsk1vSIMkRZnbdf90= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=nEhYObNi; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0369457.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41EGQZGS026985; Wed, 14 Feb 2024 18:22:22 +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=K2Graluvn6S/uk5IoYFuUnt/03+G2vYPHh6CzkWCGJA=; b=nE hYObNiaWdBgLhdKjbKYRrAEP/f0bg5x+/nGFfH06R06GC6FgICRHp1QGi53jJ65u NKuW6H5G1j/hf9AwmZWfUGXaQtdQinGy84IWJtxmKuBHxFczbtXSHT08q1t8b76L h5bQke8YHFtJ+0PB+iteX78f5WO4hgxMxDamvVyYZiU/Lz3QkuLxQ/jVGNYm09c6 hFUBteSAlIYqJKp6j+Kx8xyMdfZz+vNj1sqAWNAEzTiV1ORNDYFOs2O1lugJt6P2 T7oz4trGam8iVXtW842Qkj92AYa6m4WXE++1GfHj6yMyYYxc3geR6e7b8CUpzZhC DyGvkStLylHsbF9qLnNw== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3w6mynnh05-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 18:22:21 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id DB3E540044; Wed, 14 Feb 2024 18:22:16 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node6.st.com [10.75.129.135]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 26EA12CA54B; Wed, 14 Feb 2024 18:21:32 +0100 (CET) Received: from SAFDAG1NODE1.st.com (10.75.90.17) by EQNDAG1NODE6.st.com (10.75.129.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:32 +0100 Received: from localhost (10.201.20.75) by SAFDAG1NODE1.st.com (10.75.90.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:31 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Jens Wiklander , "Rob Herring" , Krzysztof Kozlowski , Conor Dooley CC: , , , , , , Arnaud Pouliquen Subject: [PATCH v3 1/7] remoteproc: Add TEE support Date: Wed, 14 Feb 2024 18:21:21 +0100 Message-ID: <20240214172127.1022199-2-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> References: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE2.st.com (10.75.90.13) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-14_10,2024-02-14_01,2023-05-22_02 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790896162279595942 X-GMAIL-MSGID: 1790896162279595942 From: Arnaud Pouliquen Add a remoteproc TEE (Trusted Execution Environment) driver that will be probed by the TEE bus. If the associated Trusted application is supported on secure part this device offers a client interface to load a firmware in the secure part. This firmware could be authenticated and decrypted by the secure trusted application. Signed-off-by: Arnaud Pouliquen --- update from V2 - Use 'tee_rproc' prefix for all functions - rename tee_rproc_get_loaded_rsc_table to tee_rproc_find_loaded_rsc_table - redefine fonction to better match with the rproc_ops structure format - replace 'struct tee_rproc' parameter by 'struct rproc' parameter - rename 'rproc_tee_get_rsc_table()' to tee_rproc_get_loaded_rsc_table() and rework it to remove the cached_table management. - introduce tee_rproc_get_context() to get the tee_rproc struct from the rproc struct - rename tee_rproc_get_loaded_rsc_table() to tee_rproc_find_loaded_rsc_table() - remove useless check on tee_rproc_ctx structure in tee_rproc_register() and tee_rproc_unregister() - fix test on the return of tee_rproc_ctx = devm_kzalloc() - remove useless includes and unused tee_rproc_mem structure. --- drivers/remoteproc/Kconfig | 9 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/tee_remoteproc.c | 397 ++++++++++++++++++++++++++++ include/linux/tee_remoteproc.h | 102 +++++++ 4 files changed, 509 insertions(+) create mode 100644 drivers/remoteproc/tee_remoteproc.c create mode 100644 include/linux/tee_remoteproc.h diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig index 48845dc8fa85..85299606806c 100644 --- a/drivers/remoteproc/Kconfig +++ b/drivers/remoteproc/Kconfig @@ -365,6 +365,15 @@ config XLNX_R5_REMOTEPROC It's safe to say N if not interested in using RPU r5f cores. + +config TEE_REMOTEPROC + tristate "trusted firmware support by a TEE application" + depends on OPTEE + help + Support for trusted remote processors firmware. The firmware + authentication and/or decryption are managed by a trusted application. + This can be either built-in or a loadable module. + endif # REMOTEPROC endmenu diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile index 91314a9b43ce..fa8daebce277 100644 --- a/drivers/remoteproc/Makefile +++ b/drivers/remoteproc/Makefile @@ -36,6 +36,7 @@ obj-$(CONFIG_RCAR_REMOTEPROC) += rcar_rproc.o obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o +obj-$(CONFIG_TEE_REMOTEPROC) += tee_remoteproc.o obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o obj-$(CONFIG_XLNX_R5_REMOTEPROC) += xlnx_r5_remoteproc.o diff --git a/drivers/remoteproc/tee_remoteproc.c b/drivers/remoteproc/tee_remoteproc.c new file mode 100644 index 000000000000..ac727e062d00 --- /dev/null +++ b/drivers/remoteproc/tee_remoteproc.c @@ -0,0 +1,397 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) STMicroelectronics 2023 - All Rights Reserved + * Author: Arnaud Pouliquen + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "remoteproc_internal.h" + +#define MAX_TEE_PARAM_ARRY_MEMBER 4 + +/* + * Authentication of the firmware and load in the remote processor memory + * + * [in] params[0].value.a: unique 32bit identifier of the remote processor + * [in] params[1].memref: buffer containing the image of the buffer + */ +#define TA_RPROC_FW_CMD_LOAD_FW 1 + +/* + * Start the remote processor + * + * [in] params[0].value.a: unique 32bit identifier of the remote processor + */ +#define TA_RPROC_FW_CMD_START_FW 2 + +/* + * Stop the remote processor + * + * [in] params[0].value.a: unique 32bit identifier of the remote processor + */ +#define TA_RPROC_FW_CMD_STOP_FW 3 + +/* + * Return the address of the resource table, or 0 if not found + * No check is done to verify that the address returned is accessible by + * the non secure context. If the resource table is loaded in a protected + * memory the access by the non secure context will lead to a data abort. + * + * [in] params[0].value.a: unique 32bit identifier of the remote processor + * [out] params[1].value.a: 32bit LSB resource table memory address + * [out] params[1].value.b: 32bit MSB resource table memory address + * [out] params[2].value.a: 32bit LSB resource table memory size + * [out] params[2].value.b: 32bit MSB resource table memory size + */ +#define TA_RPROC_FW_CMD_GET_RSC_TABLE 4 + +/* + * Return the address of the core dump + * + * [in] params[0].value.a: unique 32bit identifier of the remote processor + * [out] params[1].memref: address of the core dump image if exist, + * else return Null + */ +#define TA_RPROC_FW_CMD_GET_COREDUMP 5 + +struct tee_rproc__context { + struct list_head sessions; + struct tee_context *tee_ctx; + struct device *dev; +}; + +static struct tee_rproc__context *tee_rproc_ctx; + +static void prepare_args(struct tee_rproc *trproc, int cmd, + struct tee_ioctl_invoke_arg *arg, + struct tee_param *param, unsigned int num_params) +{ + memset(arg, 0, sizeof(*arg)); + memset(param, 0, MAX_TEE_PARAM_ARRY_MEMBER * sizeof(*param)); + + arg->func = cmd; + arg->session = trproc->session_id; + arg->num_params = num_params + 1; + + param[0] = (struct tee_param) { + .attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT, + .u.value.a = trproc->rproc_id, + }; +} + +static struct tee_rproc *tee_rproc_get_context(struct rproc *rproc) +{ + struct tee_rproc *entry, *tmp; + + list_for_each_entry_safe(entry, tmp, &tee_rproc_ctx->sessions, node) { + if (entry->rproc == rproc) + return entry; + } + + return NULL; +} + +int tee_rproc_load_fw(struct rproc *rproc, const struct firmware *fw) +{ + struct tee_ioctl_invoke_arg arg; + struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER]; + struct tee_rproc *trproc = tee_rproc_get_context(rproc); + struct tee_shm *fw_shm; + int ret; + + if (!trproc) + return -EINVAL; + + fw_shm = tee_shm_register_kernel_buf(tee_rproc_ctx->tee_ctx, (void *)fw->data, fw->size); + if (IS_ERR(fw_shm)) + return PTR_ERR(fw_shm); + + prepare_args(trproc, TA_RPROC_FW_CMD_LOAD_FW, &arg, param, 1); + + /* Provide the address of the firmware image */ + param[1] = (struct tee_param) { + .attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT, + .u.memref = { + .shm = fw_shm, + .size = fw->size, + .shm_offs = 0, + }, + }; + + ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param); + if (ret < 0 || arg.ret != 0) { + dev_err(tee_rproc_ctx->dev, + "TA_RPROC_FW_CMD_LOAD_FW invoke failed TEE err: %x, ret:%x\n", + arg.ret, ret); + if (!ret) + ret = -EIO; + } + + tee_shm_free(fw_shm); + + return ret; +} +EXPORT_SYMBOL_GPL(tee_rproc_load_fw); + +struct resource_table *tee_rproc_get_loaded_rsc_table(struct rproc *rproc, size_t *table_sz) +{ + struct tee_ioctl_invoke_arg arg; + struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER]; + struct tee_rproc *trproc = tee_rproc_get_context(rproc); + int ret; + + if (!trproc) + return ERR_PTR(-EINVAL); + + prepare_args(trproc, TA_RPROC_FW_CMD_GET_RSC_TABLE, &arg, param, 2); + + param[1].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT; + param[2].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT; + + ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param); + if (ret < 0 || arg.ret != 0) { + dev_err(tee_rproc_ctx->dev, + "TA_RPROC_FW_CMD_GET_RSC_TABLE invoke failed TEE err: %x, ret:%x\n", + arg.ret, ret); + return ERR_PTR(-EIO); + } + + *table_sz = param[2].u.value.a; + + /* If the size is null no resource table defined in the image */ + if (!*table_sz) + return NULL; + + /* Store the resource table address that would be updated by the remote core. */ + trproc->rsc_table = ioremap_wc(param[1].u.value.a, *table_sz); + if (IS_ERR_OR_NULL(trproc->rsc_table)) { + dev_err(tee_rproc_ctx->dev, "Unable to map memory region: %lld+%zx\n", + param[1].u.value.a, *table_sz); + return ERR_PTR(-ENOMEM); + } + + return trproc->rsc_table; +} +EXPORT_SYMBOL_GPL(tee_rproc_get_loaded_rsc_table); + +struct resource_table *tee_rproc_find_loaded_rsc_table(struct rproc *rproc, + const struct firmware *fw) +{ + struct tee_rproc *trproc = tee_rproc_get_context(rproc); + size_t table_sz; + + if (!trproc) + return ERR_PTR(-EINVAL); + + if (!trproc->rsc_table) + trproc->rsc_table = tee_rproc_get_loaded_rsc_table(rproc, &table_sz); + + return trproc->rsc_table; +} +EXPORT_SYMBOL_GPL(tee_rproc_find_loaded_rsc_table); + +int tee_rproc_start(struct rproc *rproc) +{ + struct tee_ioctl_invoke_arg arg; + struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER]; + struct tee_rproc *trproc = tee_rproc_get_context(rproc); + int ret; + + if (!trproc) + return -EINVAL; + + prepare_args(trproc, TA_RPROC_FW_CMD_START_FW, &arg, param, 0); + + ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param); + if (ret < 0 || arg.ret != 0) { + dev_err(tee_rproc_ctx->dev, + "TA_RPROC_FW_CMD_START_FW invoke failed TEE err: %x, ret:%x\n", + arg.ret, ret); + if (!ret) + ret = -EIO; + } + + return ret; +} +EXPORT_SYMBOL_GPL(tee_rproc_start); + +int tee_rproc_stop(struct rproc *rproc) +{ + struct tee_ioctl_invoke_arg arg; + struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER]; + struct tee_rproc *trproc = tee_rproc_get_context(rproc); + int ret; + + if (!trproc) + return -EINVAL; + + prepare_args(trproc, TA_RPROC_FW_CMD_STOP_FW, &arg, param, 0); + + ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param); + if (ret < 0 || arg.ret != 0) { + dev_err(tee_rproc_ctx->dev, + "TA_RPROC_FW_CMD_STOP_FW invoke failed TEE err: %x, ret:%x\n", + arg.ret, ret); + if (!ret) + ret = -EIO; + } + if (trproc->rsc_table) + iounmap(trproc->rsc_table); + trproc->rsc_table = NULL; + + return ret; +} +EXPORT_SYMBOL_GPL(tee_rproc_stop); + +static const struct tee_client_device_id stm32_tee_rproc_id_table[] = { + {UUID_INIT(0x80a4c275, 0x0a47, 0x4905, + 0x82, 0x85, 0x14, 0x86, 0xa9, 0x77, 0x1a, 0x08)}, + {} +}; + +struct tee_rproc *tee_rproc_register(struct device *dev, unsigned int rproc_id) +{ + struct tee_client_device *tee_device; + struct tee_ioctl_open_session_arg sess_arg; + struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER]; + struct tee_rproc *trproc; + int ret; + + /* + * The device is not probed by the TEE bus. We ignore the reason (bus could be not yet + * probed or service not available in the secure firmware) + * Assumption here is that the TEE bus is not probed. + */ + if (!tee_rproc_ctx) + return ERR_PTR(-EPROBE_DEFER); + + trproc = devm_kzalloc(dev, sizeof(*trproc), GFP_KERNEL); + if (!trproc) + return ERR_PTR(-ENOMEM); + + tee_device = to_tee_client_device(tee_rproc_ctx->dev); + memset(&sess_arg, 0, sizeof(sess_arg)); + + /* Open session with rproc_tee load the OP-TEE Trusted Application */ + memcpy(sess_arg.uuid, tee_device->id.uuid.b, TEE_IOCTL_UUID_LEN); + + sess_arg.clnt_login = TEE_IOCTL_LOGIN_REE_KERNEL; + sess_arg.num_params = 1; + + param[0] = (struct tee_param) { + .attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT, + .u.value.a = rproc_id, + }; + + ret = tee_client_open_session(tee_rproc_ctx->tee_ctx, &sess_arg, param); + if (ret < 0 || sess_arg.ret != 0) { + dev_err(dev, "tee_client_open_session failed, err: %x\n", sess_arg.ret); + return ERR_PTR(-EINVAL); + } + + trproc->parent = dev; + trproc->rproc_id = rproc_id; + trproc->session_id = sess_arg.session; + + list_add_tail(&trproc->node, &tee_rproc_ctx->sessions); + + return trproc; +} +EXPORT_SYMBOL_GPL(tee_rproc_register); + +int tee_rproc_unregister(struct tee_rproc *trproc) +{ + int ret; + + ret = tee_client_close_session(tee_rproc_ctx->tee_ctx, trproc->session_id); + if (ret < 0) + dev_err(trproc->parent, "tee_client_close_session failed, err: %x\n", ret); + + list_del(&trproc->node); + + return ret; +} +EXPORT_SYMBOL_GPL(tee_rproc_unregister); + +static int tee_rproc_ctx_match(struct tee_ioctl_version_data *ver, const void *data) +{ + /* Today we support only the OP-TEE, could be extend to other tees */ + return (ver->impl_id == TEE_IMPL_ID_OPTEE); +} + +static int tee_rproc_probe(struct device *dev) +{ + struct tee_context *tee_ctx; + int ret; + + /* Open context with TEE driver */ + tee_ctx = tee_client_open_context(NULL, tee_rproc_ctx_match, NULL, NULL); + if (IS_ERR(tee_ctx)) + return PTR_ERR(tee_ctx); + + tee_rproc_ctx = devm_kzalloc(dev, sizeof(*tee_ctx), GFP_KERNEL); + if (!tee_rproc_ctx) { + ret = -ENOMEM; + goto err; + } + + tee_rproc_ctx->dev = dev; + tee_rproc_ctx->tee_ctx = tee_ctx; + INIT_LIST_HEAD(&tee_rproc_ctx->sessions); + + return 0; +err: + tee_client_close_context(tee_ctx); + + return ret; +} + +static int tee_rproc_remove(struct device *dev) +{ + struct tee_rproc *entry, *tmp; + + list_for_each_entry_safe(entry, tmp, &tee_rproc_ctx->sessions, node) { + tee_client_close_session(tee_rproc_ctx->tee_ctx, entry->session_id); + list_del(&entry->node); + kfree(entry); + } + + tee_client_close_context(tee_rproc_ctx->tee_ctx); + + return 0; +} + +MODULE_DEVICE_TABLE(tee, stm32_tee_rproc_id_table); + +static struct tee_client_driver tee_rproc_fw_driver = { + .id_table = stm32_tee_rproc_id_table, + .driver = { + .name = KBUILD_MODNAME, + .bus = &tee_bus_type, + .probe = tee_rproc_probe, + .remove = tee_rproc_remove, + }, +}; + +static int __init tee_rproc_fw_mod_init(void) +{ + return driver_register(&tee_rproc_fw_driver.driver); +} + +static void __exit tee_rproc_fw_mod_exit(void) +{ + driver_unregister(&tee_rproc_fw_driver.driver); +} + +module_init(tee_rproc_fw_mod_init); +module_exit(tee_rproc_fw_mod_exit); + +MODULE_DESCRIPTION(" TEE remote processor control driver"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/tee_remoteproc.h b/include/linux/tee_remoteproc.h new file mode 100644 index 000000000000..7c9e91e989ba --- /dev/null +++ b/include/linux/tee_remoteproc.h @@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright(c) 2023 STMicroelectronics - All Rights Reserved + */ + +#ifndef TEE_REMOTEPROC_H +#define TEE_REMOTEPROC_H + +#include +#include +#include + +struct rproc; + +/** + * struct tee_rproc - TEE remoteproc structure + * @node: Reference in list + * @rproc: Remoteproc reference + * @parent: Parent device + * @rproc_id: Identifier of the target firmware + * @session_id: TEE session identifier + * @rsc_table: Resource table virtual address. + */ +struct tee_rproc { + struct list_head node; + struct rproc *rproc; + struct device *parent; + u32 rproc_id; + u32 session_id; + struct resource_table *rsc_table; +}; + +#if IS_ENABLED(CONFIG_TEE_REMOTEPROC) + +struct tee_rproc *tee_rproc_register(struct device *dev, unsigned int rproc_id); +int tee_rproc_unregister(struct tee_rproc *trproc); + +int tee_rproc_load_fw(struct rproc *rproc, const struct firmware *fw); +struct resource_table *tee_rproc_get_loaded_rsc_table(struct rproc *rproc, size_t *table_sz); +struct resource_table *tee_rproc_find_loaded_rsc_table(struct rproc *rproc, + const struct firmware *fw); +int tee_rproc_start(struct rproc *rproc); +int tee_rproc_stop(struct rproc *rproc); + +#else + +static inline struct tee_rproc *tee_rproc_register(struct device *dev, unsigned int rproc_id) +{ + return ERR_PTR(-ENODEV); +} + +static inline int tee_rproc_unregister(struct tee_rproc *trproc) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return 0; +} + +static inline int tee_rproc_load_fw(struct rproc *rproc, const struct firmware *fw) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return 0; +} + +static inline int tee_rproc_start(struct rproc *rproc) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return 0; +} + +static inline int tee_rproc_stop(struct rproc *rproc) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return 0; +} + +static inline struct resource_table * +tee_rproc_get_loaded_rsc_table(struct rproc *rproc, size_t *table_sz) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return NULL; +} + +static inline struct resource_table * +tee_rproc_find_loaded_rsc_table(struct rproc *rproc, const struct firmware *fw) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return NULL; +} +#endif /* CONFIG_TEE_REMOTEPROC */ +#endif /* TEE_REMOTEPROC_H */ From patchwork Wed Feb 14 17:21:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 201067 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1374577dyb; Wed, 14 Feb 2024 09:27:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWdwxN+s5WzfZzRFVlSp9Vog7JMlDBSecHyGBwVTaHl/4EMuGU3DtLjflAuTS0432aM0yDT+nuDhDU1Yb3+tYuW6sf8XQ== X-Google-Smtp-Source: AGHT+IH1RilvHx+g1tCbtosM1n+bp3TI70EI9/5QLD0kgSYOm6dk2EJnE1IGHpNNzgDzTf6YGgKO X-Received: by 2002:ae9:e005:0:b0:785:d0db:d71a with SMTP id m5-20020ae9e005000000b00785d0dbd71amr3162354qkk.51.1707931647411; Wed, 14 Feb 2024 09:27:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707931647; cv=pass; d=google.com; s=arc-20160816; b=Owr0tGTkOUvoquSpCDacoyVYFtXWVeC0nVIVOAgrFhX5Cl1HXDnJ8vw23jQSVflLkz DGSSYhrKCppKpT7/Z/6TqhRlxP5OUpFzUgjozQfjjaD+urDhEvEhWM+tvdVbsjG1t0vb N2zBLO7BRnlf5+6WJJLvO3Cbsc9/JqtzllXukFlZUaizoqVeqBqsK7LB4rG7pGvJqFMU 0nDsotjYjou6jvaWoFTpXK4K83HcpJUrsEMNTOHlcueYag4Fo/OaTX0+HOw5Uu8mi9C4 x5YBQgeBUTZ1EZsCFHsUsAuDtk0AbBcEC3rYHnSnLExzTV/GSLJw+AIcuo0/zpX7FjY4 mhrA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qBtgOyq14dsl5L0CUVufOoZV2xCltEiuqjmF3gmRqZM=; fh=CXk3dvHSuqXBgjp/UxloolAeoie+GXWgKesDK6H7mxA=; b=t1uok+4F5OxP7ViWHbBcUVNGZ/yEPzweNCipdAMnOZZjwlAIVG5+3qHCS5gNin0qF0 ddS/nvuvMdKX6HELCKy+lDn6eDyV89yNoErzHUu/33hf+doPuO/RkwWL7myKzUJd+SUI F7YqoXQ3pP67LXDkgIGVvChOw/d0bdp+qnMPG0zxxx8ZtXy7HLiD7c6t1Ti8mnlUMQIU 2arxe7fLgcU59fXi5ZKWVQkqxQPw1esJbhIT7sVYSkI4oKchvYv1hUyQjT8hmbp46FBA 3CDq2AGX45sezaaE3pT4UrZppuj/OVOMr7qUKanXesYdl/TZwuYTKYErvkg/5k2NTlG9 X5GQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=oXXFiV+5; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65664-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65664-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com X-Forwarded-Encrypted: i=2; AJvYcCXpXAfWIVo9ok7buTn0a9tqa+Bdbl7GFvdRMhMq8b1NX9CNnInBL5qyuCRrxPTGrqBsmcShIzVkQ58gfaw75QDw3V4B5A== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j20-20020a05620a0a5400b00785d8901d7esi6785554qka.246.2024.02.14.09.27.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:27:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65664-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=oXXFiV+5; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65664-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65664-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 293051C20F16 for ; Wed, 14 Feb 2024 17:27:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 600E712AAC6; Wed, 14 Feb 2024 17:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="oXXFiV+5" Received: from mx08-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE25D1272A2; Wed, 14 Feb 2024 17:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931362; cv=none; b=BL/p3EyuDdPhTuySAPKqMJk5/7wtVN6tubs7CltFv8YXxnXg9PpVm2eBwt7V88G6E28+xQkrm/SiAxI96w7oazkbbUAt4kRMThOjmqug2cjJVisE3AoEiE7h6pRq17TCU3WmqBPMfaVyZDYfTd6eHSWeY8hVxwU5jNTipNtLCdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931362; c=relaxed/simple; bh=8ga+HEE2O98HlzKy35lUTwq3IfvDawkIKEoVuNBe9Bk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WieGVTvCrJ+Vnnt9hxz5RqSt62oeTOgOXJsS2g+rpx7ksRTNwoKYi7OVTV7UyM64ZCjPfJ8IwQnjYIJ0mCe/MQpfu+9ZZVVXswBml9u+LtQygt47OBr7Zaf8a8jyftwK1tsp8AIgjEXnNSnmlCtmWYkRTQvTUN6+Psps/ze62cI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=oXXFiV+5; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0369457.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41ED58rC027428; Wed, 14 Feb 2024 18:22:22 +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=qBtgOyq14dsl5L0CUVufOoZV2xCltEiuqjmF3gmRqZM=; b=oX XFiV+5xGSmCtA5NmSoHOCaSPaLwTxGxZlFK/YhIO0zQyxjglHU50wBeMRMNORau/ raLvy48cot9DbKrs6dr3FYyE2K2+k/FVq+x73c3BacEPMvD9EVvrzf5hXKXVgDMA Men5H+fpuVa0H6W1uIQaV7EAicfYrKBkx9K0No/FEcNiK16sWfYtKUgXIke4rRUt 3+5eUpOzItxnBrhMkIoa+OQYQIuYQ0PgDdMny4zZtSsnWzDfZbzbtrhTIdQ4pMaN Xku5IPFOYl3+9tFX9Daf7HLPOhwHgMZXvuBgQ2YkG8vTNctbwdy8kielNeBuNJ9l j6JScewlezYm2Bk8uXdA== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3w6mynnh06-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 18:22:22 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 5054940048; Wed, 14 Feb 2024 18:22:19 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node5.st.com [10.75.129.134]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id ED61A2CA548; Wed, 14 Feb 2024 18:21:32 +0100 (CET) Received: from SAFDAG1NODE1.st.com (10.75.90.17) by EQNDAG1NODE5.st.com (10.75.129.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:32 +0100 Received: from localhost (10.201.20.75) by SAFDAG1NODE1.st.com (10.75.90.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:32 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Jens Wiklander , "Rob Herring" , Krzysztof Kozlowski , Conor Dooley CC: , , , , , , Arnaud Pouliquen Subject: [PATCH v3 2/7] remoteproc: Extract the firmware load from the start Date: Wed, 14 Feb 2024 18:21:22 +0100 Message-ID: <20240214172127.1022199-3-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> References: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE2.st.com (10.75.90.13) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-14_10,2024-02-14_01,2023-05-22_02 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790896134676900212 X-GMAIL-MSGID: 1790896134676900212 With the introduction of tee_remoteproc, the firmware has to be loaded first before parsing the resource table. This constraint is linked to the firmware authentication, that contains the resource table. In OP-TEE, this authentication is correlated with the load of the firmware (the loaded segments authenticated after being copied to the destination memory). Removing rproc_load_segments will allow it to be called earlier in the boot sequence. Signed-off-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 695cce218e8c..283ca071e35c 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1269,13 +1269,6 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) struct device *dev = &rproc->dev; int ret; - /* load the ELF segments to memory */ - ret = rproc_load_segments(rproc, fw); - if (ret) { - dev_err(dev, "Failed to load program segments: %d\n", ret); - return ret; - } - /* * The starting device has been given the rproc->cached_table as the * resource table. The address of the vring along with the other @@ -1430,6 +1423,13 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) goto clean_up_resources; } + /* load the ELF segments to memory */ + ret = rproc_load_segments(rproc, fw); + if (ret) { + dev_err(dev, "Failed to load program segments: %d\n", ret); + return ret; + } + ret = rproc_start(rproc, fw); if (ret) goto clean_up_resources; @@ -1808,6 +1808,13 @@ static int rproc_boot_recovery(struct rproc *rproc) return ret; } + /* load the ELF segments to memory */ + ret = rproc_load_segments(rproc, firmware_p); + if (ret) { + dev_err(dev, "Failed to load program segments: %d\n", ret); + return ret; + } + /* boot the remote processor up again */ ret = rproc_start(rproc, firmware_p); From patchwork Wed Feb 14 17:21:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 201065 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1374534dyb; Wed, 14 Feb 2024 09:27:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXbTrMaN+eNZT6TOo3iUJKINprLqMT83Ond0J2I+VzEWpckWtlfhLZBwKh8GcRD7+Neask4/Pk9OMxwLCtAaa5EkiDR5g== X-Google-Smtp-Source: AGHT+IFhr0Bb5z5709/4priRHzWkQABj8kRoo799l6MvjaIr/F19p8V9FRmGqPcuc1hqM4aVCkri X-Received: by 2002:a19:f711:0:b0:511:aa98:78de with SMTP id z17-20020a19f711000000b00511aa9878demr1379234lfe.49.1707931643388; Wed, 14 Feb 2024 09:27:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707931643; cv=pass; d=google.com; s=arc-20160816; b=kqTi9VArj/bX7ZbtHFkVq3wt9Ei4FiDl7GeEDNmPUBbt+Bq6jkp+HDMSqpizQkCjEO ab+lb1KmVRPuH9UrIek154TiQJcouamxp0Z210Mzox41IIt/MXIEw+ZqMm8ADIQTaFCz t+Rr0vdcWlXzoPQ91XswQ5hqvtFnr5v1euxvmQdvmyAuvfhsMbDGG3IFSaNKqYfjbqkm ORpxp6cyyhALwZs9jwoMVLB15tv1wIkw+N7zEaGmBD4AqIUO6dpYOXEMEItyE7bAHbms T3WZ24eNeajikne4L5WhLkayKAbzYRFossUzPL+Zj8NH/lhJNo6uLTVEXxYlYg0ugcLW SaHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=/xRSgnYV0eg6fwcJrQsSBoZNZwjEYDji4NLNmw4GryI=; fh=4Cy11hN8XVR5SYm9JmZ2/luML9ZxJU3JKME1m4TXOlg=; b=KGYD/DvY9iS3nidLO0B//r78cDHqOU2X4AYbCbs61YcJRFP1paC2AkRq1c6ir7QPZM SeDjSbfXIZkhxmBO7Oi5GspGia5mraTpBVAji4OdjTc+luKhlONuDeO7g4Q8kfDd0K09 tqA6T7C+s1N5JxGDOibmEsrHhBV7ZNNG+6FF8iXGfqmWscklm+ziAaf7zaXRsAsSyfHG +F1nCCHk226Al7S0SHEwdHwFFAfSqgg0XYksU5k6fhTI+3KX9NWU4PQgTMsWCLSUxQSP yPzGXFiluWJnrd1Cj8XXWZT7ydaTxGtlFcK4uz7LUvkMQFK39gKWqCTi5WI6JjCZtwVa Yu9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=rd8CoPG6; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65662-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65662-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com X-Forwarded-Encrypted: i=2; AJvYcCWzWWxyBN1Q254Jzyd77yNO8fHVQkV2X5eMg+K23XeXxXwB788WI/7bJfDozk4ywnvR6ghu45Qnb4imm0p+IQNBlSs1KQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i15-20020a1709061ccf00b00a3cf224c06fsi2050911ejh.284.2024.02.14.09.27.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:27:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65662-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=rd8CoPG6; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65662-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65662-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 025791F2180E for ; Wed, 14 Feb 2024 17:27:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 194DC12A173; Wed, 14 Feb 2024 17:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="rd8CoPG6" Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A19884A24; Wed, 14 Feb 2024 17:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931362; cv=none; b=h/LA78PwkYu2oyTCKmdccMBhC1ipf8HSic78nJNXv6zHeainfR57F/Bywc3wOIyDlRR9AlSkUIbN1pOpQy0YHBdmF/g56ygAYXAahbSmg1MWHbnDGbVUPXJ7GO27WK75+z3gxUFJ+G9ghNd3iFakvjHbMdXAdyEkpjbi3Qa5LLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931362; c=relaxed/simple; bh=45+ZI0onSdA3aIo1s59eVulQGX8hv5CVs3B4xK1z4Vs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WigSzKzAY1N/EghxiSh6O/rdkW2lVl1j7iMtlD/2GT24diwVx4uqJ6ippcIvw6RoZgICUTcAK9I71lImDDh1rQE2PfU3m8OEqzJW5KPJGEGFAkb37V0O963MPfQJ0IXUiAd8uCNW4rnY55CrEY0njZRH7OwLxIjGZ7vXqUYbZok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=rd8CoPG6; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41EGl1KZ006294; Wed, 14 Feb 2024 18:22:22 +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=/xRSgnYV0eg6fwcJrQsSBoZNZwjEYDji4NLNmw4GryI=; b=rd 8CoPG6RIUClGrR9e7aV4n4q/n84iEC/UZuZIIwbAXp4xRLdzQ8Ab8uWGi3wzHXEv ytN1ZesQ1CFLRjfiQmBEt/UgNqQjkGolrjbiH7jCus6Ohkzl2EJDpG0BrdwyHM9c SH/U2mQERrsCeZy2vIhyQZDEp+3lbXk9VZUgAa1VWW3CXrCljo3GbRab98Ilwfkh I5RXZnyvl0y4y0AJF+abk5Ui7uP6/AEsKdP22TjVgfcJBzkZM3fhWH7ShqGUzP5o cgeBkqdAyUS4tq+7On23YhLghmUD7Cpn9wVVgrCkMRNLvYK2dhpx2m9K+wqpIGK0 m0H7a+ei+cw0J58wADww== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3w62shywsp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 18:22:22 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id CD3B040046; Wed, 14 Feb 2024 18:22:18 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node4.st.com [10.75.129.133]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id B9DE72CA54C; Wed, 14 Feb 2024 18:21:33 +0100 (CET) Received: from SAFDAG1NODE1.st.com (10.75.90.17) by EQNDAG1NODE4.st.com (10.75.129.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:33 +0100 Received: from localhost (10.201.20.75) by SAFDAG1NODE1.st.com (10.75.90.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:33 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Jens Wiklander , "Rob Herring" , Krzysztof Kozlowski , Conor Dooley CC: , , , , , , Arnaud Pouliquen Subject: [PATCH v3 3/7] remoteproc: core: Add check on cached_table pointer Date: Wed, 14 Feb 2024 18:21:23 +0100 Message-ID: <20240214172127.1022199-4-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> References: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE2.st.com (10.75.90.13) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-14_10,2024-02-14_01,2023-05-22_02 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790896130640123081 X-GMAIL-MSGID: 1790896130640123081 Add a check on the optional rproc->cached_table to perform the memory copy only if it is not null. 2 use cases to support: - starting on boot, in which case rproc->cached_table can be null, - starting on crash recovery, where the cached table is used to save the resource table configuration on stop and re-apply the configuration on the re-start. Signed-off-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 283ca071e35c..34b0093689da 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1278,7 +1278,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) * that any subsequent changes will be applied to the loaded version. */ loaded_table = rproc_find_loaded_rsc_table(rproc, fw); - if (loaded_table) { + if (loaded_table && rproc->cached_table) { memcpy(loaded_table, rproc->cached_table, rproc->table_sz); rproc->table_ptr = loaded_table; } From patchwork Wed Feb 14 17:21:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 201066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1374554dyb; Wed, 14 Feb 2024 09:27:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW8ASviUtoFNvWxeDPm8sFLI/tnVTLMD/83HkIHf27J0DjJoCno5J1SBQujrXQkt1y062ewNpqvKWRnrBHRxb42wNvKoQ== X-Google-Smtp-Source: AGHT+IH/n+sLVrKzgnXWY76a3PVrxGsPBpFhLa52ZlR6y+SVRx3/0JvMEbBAhtZByM7qvaFDyEwN X-Received: by 2002:a17:906:56ca:b0:a3d:296f:40f5 with SMTP id an10-20020a17090656ca00b00a3d296f40f5mr2493379ejc.31.1707931645476; Wed, 14 Feb 2024 09:27:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707931645; cv=pass; d=google.com; s=arc-20160816; b=PsX5JQHNC/H2ICp8cco9FpRQGxhaFouWOzQ5WPMv87HdOugXJFhVPsEuzXudFkqOsT uRUSIKi5oG3p9Z20ihzUhfOENmPdt2w/tO2q6s8lzHUGtETm9g1zI6FlEAOiN+ChYtvs RatySA34cq4YGNPscyTulM1lcBMYGd6dsiBXpH+DyBK2sxcPPHKlEu6gLFMpfRFIS8NE w8hdQgA5pscl/zGOMjZVJCSVGqvhw5EXcMT2GUge7GLA07m65CL1r/qFhfIAUd8/wKkA YKMpUXGO/YOOaUcIrjTSBGdRB8QFcoO/lTyTcXt04GbxyQU7qv9FZzYSSY2AjQ5tZAgX 1Tdg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=QJGdR7T1RAMulvzBV6KzWPdgGJO8ZLSH7zr0wo/PFu0=; fh=/+FsliWl0QjGVrNghYe9Aa7Z1U9hq94rRYFmOGbkvnE=; b=fwUdO2rV544aoGn5JYh1Wq9FAZyU3SSwBhV7ENsQXPvyiNE4M+b4SX2JDeWV7zjTPH Fjn2i7wWRuKw2WlM7GRn1KaZLareI4pSHnI2qzF1PXkcOCTb3zThQKBLnegdIC8nzv/j JiB/l0sOQlehJHFqNfz686aX5BtIzkD0Nz3Es53pVPyqE9rc7oclinaaOZQmMy74gry6 rS0R2c4yQVQYk59qRMN7a9UFIVQi4jSZS7prPcCD0gMoG/h33XCZS02ZXsYTNB8RbGPG q6eMJ+rWnmuPcHp44Tx1xP1onEjEPjcQtji0Yr4WpYcGVf3NAUxmZzL+w/xuNGjkxHMN remg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b="1Pl/ii5H"; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65661-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65661-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com X-Forwarded-Encrypted: i=2; AJvYcCUy96L+usmo5P2Icwm/u54AgpDSfxXzE879wDoQhHHPABAJfDbweDiixuzPv7KM/VFUHfUD+cONGWhAU00ondVLDrI8Ag== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ji16-20020a170907981000b00a3d5d9fd987si498456ejc.966.2024.02.14.09.27.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:27:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65661-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b="1Pl/ii5H"; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65661-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65661-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D9A111F22C0C for ; Wed, 14 Feb 2024 17:27:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 346CB12A17A; Wed, 14 Feb 2024 17:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="1Pl/ii5H" Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B994684047; Wed, 14 Feb 2024 17:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931361; cv=none; b=sJ3M3j7y88MmTr5A71omdjBgU7bzvhJF632fR+Zez95HSdYiBRIDWWfkg70hgABpVuq1YyLY2By/HebhNruDiHOxy8f8qWkGQJ65SB3+dGSO2odY7iRbuWcx6jpnOKE4h3vfqloT9vXrPUGVfuRH+LHU7l7Ep3hGOvegVvCdSJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931361; c=relaxed/simple; bh=CRyc1Zow9q2eOb3Vup4ogTxRj24JHuvpDHUTFQSCXCw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=B/qErHQdhz+VdPwjBzoTwLh02VvxAT/Q07QwG4fRWWZLBJ0ddz+wAJyBBhHHDjuMbQvNJhl15fu3EnBDOUgRAIDF0OWZ7puJ+63Fu3LstKPKCQJteENklvwfGL75unj4EXo28OFRdHPTX04HFt3max8m/JwloFL2gpLkovpvfX8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=1Pl/ii5H; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41EGZZKW017077; Wed, 14 Feb 2024 18:22:25 +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=QJGdR7T1RAMulvzBV6KzWPdgGJO8ZLSH7zr0wo/PFu0=; b=1P l/ii5HQj2gOqq+CGCFTkUZ2WXCEN/8WgQ+2XBiQtKIf+dPkpMiTzJkKF/lcUkgd0 ywbeRiFmkJ+euWbOmhMGFy5gh+aWk8B3wuSfHFWT2kGmVbbm4rvdbwShcyAuB9Es 38cogwrNL4ZjzqF6VVvbRnAlSofSgDupp3XHjdjFz5mUTozKpuZb1JtX6RTQusQM fL+DluvQVfmQ2Pj3TAnGVxHVMvqzD/YX5ai8fVcaTQA0a6K7AhyF5i9UYBTmwNUL VRmzXZ1bci/xJ/ZRXHXXGRlvXzmi83zEMWi0aXsIz6uWZDtKSmpv0P7Fgapj+aap h1afNitzJr9tCRBJUmDA== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3w62shywsu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 18:22:25 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 392D840047; Wed, 14 Feb 2024 18:22:19 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node6.st.com [10.75.129.135]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 91F852CA54D; Wed, 14 Feb 2024 18:21:34 +0100 (CET) Received: from SAFDAG1NODE1.st.com (10.75.90.17) by EQNDAG1NODE6.st.com (10.75.129.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:34 +0100 Received: from localhost (10.201.20.75) by SAFDAG1NODE1.st.com (10.75.90.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:34 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Jens Wiklander , "Rob Herring" , Krzysztof Kozlowski , Conor Dooley CC: , , , , , , Arnaud Pouliquen Subject: [PATCH v3 4/7] remoteproc: core: Implement the support of an alternative boot Date: Wed, 14 Feb 2024 18:21:24 +0100 Message-ID: <20240214172127.1022199-5-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> References: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE2.st.com (10.75.90.13) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-14_10,2024-02-14_01,2023-05-22_02 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790896133240186896 X-GMAIL-MSGID: 1790896133240186896 Implement a new method to load a firmware and start the remote processor. In this method the firmware is loaded first and then the loaded resource table is obtained. Signed-off-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 86 +++++++++++++++++++++++++++- include/linux/remoteproc.h | 2 + 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 34b0093689da..47956e07365e 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "remoteproc_internal.h" @@ -1493,6 +1494,86 @@ static int rproc_set_rsc_table(struct rproc *rproc) return 0; } +/* + * Alternative method to load a firmware and boot a remote processor with it. + * Similar to rproc_fw_boot but the resource table is obtained and parsed only after loading the + * firmware. + */ +static int rproc_alt_fw_boot(struct rproc *rproc, const struct firmware *fw) +{ + struct device *dev = &rproc->dev; + const char *name = rproc->firmware; + int ret; + + dev_info(dev, "Booting a private format image %s, size %zd\n", name, fw->size); + + /* + * if enabling an IOMMU isn't relevant for this rproc, this is + * just a nop + */ + ret = rproc_enable_iommu(rproc); + if (ret) { + dev_err(dev, "can't enable iommu: %d\n", ret); + return ret; + } + + /* Prepare rproc for firmware loading if needed */ + ret = rproc_prepare_device(rproc); + if (ret) { + dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret); + goto disable_iommu; + } + + /* load the image to memory */ + ret = rproc_load_segments(rproc, fw); + if (ret) { + dev_err(dev, "Failed to load firmware: %d\n", ret); + return ret; + } + + ret = rproc_set_rsc_table(rproc); + if (ret) { + dev_err(dev, "can't load resource table: %d\n", ret); + goto unprepare_device; + } + + /* reset max_notifyid */ + rproc->max_notifyid = -1; + + /* reset handled vdev */ + rproc->nb_vdev = 0; + + /* handle fw resources which are required to boot rproc */ + ret = rproc_handle_resources(rproc, rproc_loading_handlers); + if (ret) { + dev_err(dev, "Failed to process resources: %d\n", ret); + goto clean_up_resources; + } + + /* Allocate carveout resources associated to rproc */ + ret = rproc_alloc_registered_carveouts(rproc); + if (ret) { + dev_err(dev, "Failed to allocate associated carveouts: %d\n", + ret); + goto clean_up_resources; + } + + ret = rproc_start(rproc, fw); + if (ret) + goto clean_up_resources; + + return 0; + +clean_up_resources: + rproc_resource_cleanup(rproc); +unprepare_device: + /* release HW resources if needed */ + rproc_unprepare_device(rproc); +disable_iommu: + rproc_disable_iommu(rproc); + return ret; +} + static int rproc_reset_rsc_table_on_detach(struct rproc *rproc) { struct resource_table *table_ptr; @@ -1957,7 +2038,10 @@ int rproc_boot(struct rproc *rproc) goto downref_rproc; } - ret = rproc_fw_boot(rproc, firmware_p); + if (rproc->alt_boot) + ret = rproc_alt_fw_boot(rproc, firmware_p); + else + ret = rproc_fw_boot(rproc, firmware_p); release_firmware(firmware_p); } diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index b4795698d8c2..ba219a77e055 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -544,6 +544,7 @@ enum rproc_features { * @elf_machine: firmware ELF machine * @cdev: character device of the rproc * @cdev_put_on_release: flag to indicate if remoteproc should be shutdown on @char_dev release + * @alt_boot flag to indicate if remoteproc should use the alternate boot method. * @features: indicate remoteproc features */ struct rproc { @@ -585,6 +586,7 @@ struct rproc { u16 elf_machine; struct cdev cdev; bool cdev_put_on_release; + bool alt_boot; DECLARE_BITMAP(features, RPROC_MAX_FEATURES); }; From patchwork Wed Feb 14 17:21:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 201068 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1374622dyb; Wed, 14 Feb 2024 09:27:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWNzitRuf0u07miHUVYBuSaJSSmEFNbysJxqRvxFsSlJ63pzNIKvWSHWwjzZX0CRm2fMw/ngFxFiSXMfajOsEqsZlXqJw== X-Google-Smtp-Source: AGHT+IFSUMF/EpYm7yvQ5Yosr6Ik72upLaRmxZfkSff+lyRWq7imDymaInH13bgpapPkPZrZvTH0 X-Received: by 2002:ac8:5f85:0:b0:42c:4571:4157 with SMTP id j5-20020ac85f85000000b0042c45714157mr3780603qta.47.1707931651489; Wed, 14 Feb 2024 09:27:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707931651; cv=pass; d=google.com; s=arc-20160816; b=tzwgtZxrrZ5L9qGRsPm1VPQ9z7B1a1vrdKbRQAO2VEt7B5VKtGxCs41EcVl5rM2w1O k7cCdxVeG/G3GbzmYKH7WvMSX0Ny0d1ahcPjYWHuV38c/meic6iSaGocbqSHX61jRHSs XKbpGG1anwECcfaRFqE98tmijAOPShf50ExDLKPIZNci9CFVvThT5eZ7lde/5m9FjHZq iQ82Pn/JzBwePAHEJktsIM/DmBiVbFjNLBkU52GbyAij5tsoBskltMxzNqY5OJcDbmHz C21HRaRgVCsJKYR1hMPXx1wOT+iMry8ilg2+sGcKf4TPjfmAQPc/CHItT2dikhjDgtXE sgsA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9EG7+XkrPEpea5V06f07KXHol0lpljrozkJw2bM13jg=; fh=UTZAaeoVJhFtaayUDkvOHiFqzYR+HnqGJk9y9ftO9x8=; b=lhOyfGV+nRO9I5kktxWPNNBlVm9svtBucOGCaVxavxk9o8pr3rpSkUi11wGSPSof3e nSn89cYWT+ibSBWtW7g7PBtWLjOQ0g3N+zm2jom2cGL3KHm0Hf8/XN530avF3Ig8h+tC OQisIoKN4oQcnIq9x0NlD4YyNlQi3gZ4nVlYS4TS4lf0CEqQ4ks5+UiDcI2uFLVxXrmd Nk6IvN8jhaXw579oPBNYxYL2fg7QZA+ANXqcptrIMKzNJ48e871nuxPNYnrFTGn3onjN uiDmhZWwzKU2ojwSytgwEEv2xOjFMoZIHzZ+SnXq9oLvk4p5awwj2syh3rjGKiXz0BFM 70uA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b="5tX/Oacz"; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65663-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65663-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com X-Forwarded-Encrypted: i=2; AJvYcCUumvon0YxJ4zf7cPQCG+NCJRVEhDpT0T2JDVsKwEBpMBWXQDR0XwSeV5pKPqR3iqyFjr5cYZlgrwuKW+Bbxc8A91UHhA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t18-20020ac87612000000b0042c0d7794bdsi5386953qtq.403.2024.02.14.09.27.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:27:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65663-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b="5tX/Oacz"; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65663-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65663-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3B8661C2080D for ; Wed, 14 Feb 2024 17:27:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C90A12AAE0; Wed, 14 Feb 2024 17:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="5tX/Oacz" Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8648E8662D; Wed, 14 Feb 2024 17:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931362; cv=none; b=hhk63KVV5i+NUyYoQmeBEBc+abXEEaGMNHxbAn2qdlF/xlV6sL5VBwILLoKiYTlsvXDj+6N9pE/kbcQobfuRlMs7exP2SaIeHrSIJA9MfmtG7r8JoLQcwtSTAlYDhdJ9H46Opw67LqL0VN+TwRBXAR0dWeJ0ap75uecofvtIFs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931362; c=relaxed/simple; bh=Aaa2jNzeBt4IVHxAmwNTBPziNw4IvtOWAfB8bps0trQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ozUy2105pZY6Ok+Xqxw2U3+2BBBVBvgeMxdfKZUZvwriu1yKgqNBWzziKAPuVoab0agne3rR66824ncnRHealHIorTjtfsPpTFw6+IR5gMYA/SkvbrI7Nl5DW8ri8LQyuT/fdhTqnF58JrHSd4fErT4kPbMqCbUQ/O2oYr3MqnQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=5tX/Oacz; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41EEb56X003989; Wed, 14 Feb 2024 18:22:22 +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=9EG7+XkrPEpea5V06f07KXHol0lpljrozkJw2bM13jg=; b=5t X/OaczfdhutsrptiR4+GV4okj5l21VtTuahDrfbiNrgDj75hnWEFu8keC+/IW7CA jLPdVYe+nJhG/74mftyYIM9kjR5I5ZCeAJiui58yiC2z5mqwxsAGoFSKrjX4r2S1 hRS0GsmAOEN3PThaL83THalRXEskOMS4pzY8RwyGgoZUK7Lo5j11FFB2M9LkeN8q kOUMoWBwEElCOz8NSXcho+xHR7Gk2/NgB/yAxqdjOdMqJbTD+oVI2rfmelWAW+9v vz2tM9KhSFECgS07g0EfL3YlPBp5PfME8ylhb2RKU22H1yMqST7gRsVVqjKdga6r qXZPLfuVSThJ+n250g3g== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3w62ktqx96-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 18:22:21 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 7C80C40045; Wed, 14 Feb 2024 18:22:18 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node5.st.com [10.75.129.134]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 63EBE2CA54E; Wed, 14 Feb 2024 18:21:35 +0100 (CET) Received: from SAFDAG1NODE1.st.com (10.75.90.17) by EQNDAG1NODE5.st.com (10.75.129.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:35 +0100 Received: from localhost (10.201.20.75) by SAFDAG1NODE1.st.com (10.75.90.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:34 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Jens Wiklander , "Rob Herring" , Krzysztof Kozlowski , Conor Dooley CC: , , , , , , Arnaud Pouliquen Subject: [PATCH v3 5/7] dt-bindings: remoteproc: Add compatibility for TEE support Date: Wed, 14 Feb 2024 18:21:25 +0100 Message-ID: <20240214172127.1022199-6-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> References: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE2.st.com (10.75.90.13) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-14_10,2024-02-14_01,2023-05-22_02 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790896138956178100 X-GMAIL-MSGID: 1790896138956178100 The "st,stm32mp1-m4-tee" compatible is utilized in a system configuration where the Cortex-M4 firmware is loaded by the Trusted execution Environment (TEE). For instance, this compatible is used in both the Linux and OP-TEE device-tree: - In OP-TEE, a node is defined in the device tree with the st,stm32mp1-m4-tee to support signed remoteproc firmware. Based on DT properties, OP-TEE authenticates, loads, starts, and stops the firmware. - On Linux, when the compatibility is set, the Cortex-M resets should not be declared in the device tree. Signed-off-by: Arnaud Pouliquen Reviewed-by: Rob Herring --- V1 to V2 updates - update "st,stm32mp1-m4" compatible description to generalize - remove the 'reset-names' requirement in one conditional branch, as the property is already part of the condition test. --- .../bindings/remoteproc/st,stm32-rproc.yaml | 51 ++++++++++++++++--- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml b/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml index 370af61d8f28..36ea54016b76 100644 --- a/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml +++ b/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml @@ -16,7 +16,12 @@ maintainers: properties: compatible: - const: st,stm32mp1-m4 + enum: + - st,stm32mp1-m4 + - st,stm32mp1-m4-tee + description: + Use "st,stm32mp1-m4" for the Cortex-M4 coprocessor management by non-secure context + Use "st,stm32mp1-m4-tee" for the Cortex-M4 coprocessor management by secure context reg: description: @@ -142,21 +147,41 @@ properties: required: - compatible - reg - - resets allOf: - if: properties: - reset-names: - not: - contains: - const: hold_boot + compatible: + contains: + const: st,stm32mp1-m4 then: + if: + properties: + reset-names: + not: + contains: + const: hold_boot + then: + required: + - st,syscfg-holdboot + else: + properties: + st,syscfg-holdboot: false + required: + - reset-names required: - - st,syscfg-holdboot - else: + - resets + + - if: + properties: + compatible: + contains: + const: st,stm32mp1-m4-tee + then: properties: st,syscfg-holdboot: false + reset-names: false + resets: false additionalProperties: false @@ -188,5 +213,15 @@ examples: st,syscfg-rsc-tbl = <&tamp 0x144 0xFFFFFFFF>; st,syscfg-m4-state = <&tamp 0x148 0xFFFFFFFF>; }; + - | + #include + m4@10000000 { + compatible = "st,stm32mp1-m4-tee"; + reg = <0x10000000 0x40000>, + <0x30000000 0x40000>, + <0x38000000 0x10000>; + st,syscfg-rsc-tbl = <&tamp 0x144 0xFFFFFFFF>; + st,syscfg-m4-state = <&tamp 0x148 0xFFFFFFFF>; + }; ... From patchwork Wed Feb 14 17:21:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 201072 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1377023dyb; Wed, 14 Feb 2024 09:31:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVR2CDpv00lnYCa2Tdy31tpgvK/1rA4xnRyRdWsadxaPxN0csEUjuM2STVs1N/Td1rdV2TloAQpl/R/eG+3xIqw6aDZlA== X-Google-Smtp-Source: AGHT+IELEE8hJwJSl/yIolvB/Wl88dfmGO5gEMPPRX4llUfFWrhD+BrRgODzDAszkbt+JjKVKuYi X-Received: by 2002:a05:6a00:3d54:b0:6e0:f3f4:8da2 with SMTP id lp20-20020a056a003d5400b006e0f3f48da2mr3551520pfb.2.1707931874397; Wed, 14 Feb 2024 09:31:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707931874; cv=pass; d=google.com; s=arc-20160816; b=FZmAlxOAYBNxMj4mY0/KTJnbyDl0BGbUqOffxiOv1iYahbBx4hVNE0VoYwQBra30Nz auOe2MRgL/eP6CtPy8Jgw3BLlALNHCfHKxe7VNmsvNcPkyWcrsD8zfy0UDD9YvKARyx0 Ot1e1EfojsaftGY1VsIgt3egQE5htUNa6cQ8Z+LmQlUnl0NyprR7fgxfg9gZguGujj50 lHXX0qSgHGCEATo4SsUloOqHol85rT+KoXre5AOHo8KXq5Nu5QKf6u4QBqjcXg5WDbWo uzMWeL/k6IVBRb8L6SwdF2IA4dJWNJP9pGS/vPScV8lWdPHXnoKY+ovLGFwL1h29TA38 K4WA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JgTqkog598RbC204zCHUiytINQsebXi6rfWzdONWWfk=; fh=zgREzdhY3dfyw5CqKC1QMhxIqf0N7qEmUTEATB1Ym2k=; b=r+rrXecz7hYrMIfp+SWsXDKk6Z9p5d7XS4LAPgv6TRXbyTfeaUeA2dqOARdWF5ZpLE by+qu2mQH4Ey+u9h/u81kKVsG5DNcmFQtSrDbZFxJsu109HHETLZEu3kwG+5Tc021LXF +66nwXoNvpSlhI9NiY23a4WmThrQmeFJqQTGg2RGpS5I6w2tWgHO7CVzuKvBziMTiXiw miSj2LgcTZHRdWO0cOLsFAWbNoUmpLWoymXpkmNuXZ5GJf605Y5sPa5ECkU5Tb2tqlN+ L2gqhGiVmXe+dRwmW9qeWIJtVMaepkT7+Osb8yaq8buBitgIBIo7bYZbH/UG1ACD08pN Bzcw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=tZdSiDjZ; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65668-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65668-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com X-Forwarded-Encrypted: i=2; AJvYcCUfHNvUbsTZhHxj36yLj2hwCBGDiuw7pauFaLoLa6M6y0eCawCQWZhteWyqOoxzSmmDoIpNoeq2CMJ2dus5BaLXbW7oQA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i123-20020a62c181000000b006e07c7c4eadsi8762051pfg.129.2024.02.14.09.31.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:31:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65668-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=tZdSiDjZ; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65668-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65668-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 25ACF285F3E for ; Wed, 14 Feb 2024 17:28:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7F9E12BF3D; Wed, 14 Feb 2024 17:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="tZdSiDjZ" Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A9D81272DB; Wed, 14 Feb 2024 17:23:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.132.182.106 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931383; cv=none; b=Hr91YQS+5OAhUuksXYTJ5eqN9z1NZI73gpCgXqGGdOjjn0SBzp/S8r9Weo1M8XoqVF9hlLH1dWwjl0Zn2JYRZiGU+vcPiyR7hmEEby7mJR+MCZpkjCFiaojH5HBM6ePjmpk7C6Hz87hiV1PqjD6dfhmpotmG0C+DdKN1AhPuSI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931383; c=relaxed/simple; bh=xbP+qBkAgbP8SmfFKf4c6P+KDk0bMEaf2tvnAZRQWuk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TD7ob+ecVb1gQX5rUZK6Fh5HKCwTJ93yXsjFfeUU8HVEKz6rg8Jc1KFtTx5gH4cRif2jWeNUJBojf7sVPT1KCH4ulZpS4SZEelg/olJvy3xJiOxDZZ6RLzAlPb9gCq8nZSGvaoiKe1Sri5tXhS5mweVuqgT9wKtvFTkOF9VSYOE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=tZdSiDjZ; arc=none smtp.client-ip=185.132.182.106 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0288072.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41EFqjp8028749; Wed, 14 Feb 2024 18:22:48 +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=JgTqkog598RbC204zCHUiytINQsebXi6rfWzdONWWfk=; b=tZ dSiDjZ7KVmoK+EEauKGw5tpdse5RCi8Sx7TDQij9IeP/V1EUVw7LC/81trxXV2J9 W2k8xXHV7jz6m83jx6FAomeYhWA2Iy4hmIvwKy65W6BZxoPKXLxY2SwomndSL+nK /+LtBt+lsNqjniTfyYxwQ+o5lNwObikHhqOQDfHxVvvHNHzDVhWev2OzshA7zHez Lw6qjxOtPGvWQQuyByKQEaZ/cUwAseJSDzCi/QCtfVX88UdLfeufB3JBmayN8TbA 4lS22dOsqzZ01y43RspufH0gdZuWfrtpt+FJTFRVVYAPDoMRFOtG/ExNWoQ64+9C QRBtNO0coltrq79RWtnQ== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3w62jsgb7f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 18:22:48 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 91A4F4002D; Wed, 14 Feb 2024 18:22:44 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node4.st.com [10.75.129.133]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 3B53D2CA54F; Wed, 14 Feb 2024 18:21:36 +0100 (CET) Received: from SAFDAG1NODE1.st.com (10.75.90.17) by EQNDAG1NODE4.st.com (10.75.129.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:36 +0100 Received: from localhost (10.201.20.75) by SAFDAG1NODE1.st.com (10.75.90.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:35 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Jens Wiklander , "Rob Herring" , Krzysztof Kozlowski , Conor Dooley CC: , , , , , , Arnaud Pouliquen Subject: [PATCH v3 6/7] remoteproc: stm32: Create sub-functions to request shutdown and release Date: Wed, 14 Feb 2024 18:21:26 +0100 Message-ID: <20240214172127.1022199-7-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> References: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE2.st.com (10.75.90.13) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-14_10,2024-02-14_01,2023-05-22_02 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790896373443879727 X-GMAIL-MSGID: 1790896373443879727 To prepare for the support of TEE remoteproc, create sub-functions that can be used in both cases, with and without TEE support. Signed-off-by: Arnaud Pouliquen --- drivers/remoteproc/stm32_rproc.c | 84 +++++++++++++++++++------------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index 4f469f0bcf8b..fcc0001e2657 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -209,6 +209,54 @@ static int stm32_rproc_mbox_idx(struct rproc *rproc, const unsigned char *name) return -EINVAL; } +static void stm32_rproc_request_shutdown(struct rproc *rproc) +{ + struct stm32_rproc *ddata = rproc->priv; + int err, dummy_data, idx; + + /* Request shutdown of the remote processor */ + if (rproc->state != RPROC_OFFLINE && rproc->state != RPROC_CRASHED) { + idx = stm32_rproc_mbox_idx(rproc, STM32_MBX_SHUTDOWN); + if (idx >= 0 && ddata->mb[idx].chan) { + /* A dummy data is sent to allow to block on transmit. */ + err = mbox_send_message(ddata->mb[idx].chan, + &dummy_data); + if (err < 0) + dev_warn(&rproc->dev, "warning: remote FW shutdown without ack\n"); + } + } +} + +static int stm32_rproc_release(struct rproc *rproc) +{ + struct stm32_rproc *ddata = rproc->priv; + unsigned int err = 0; + + /* To allow platform Standby power mode, set remote proc Deep Sleep. */ + if (ddata->pdds.map) { + err = regmap_update_bits(ddata->pdds.map, ddata->pdds.reg, + ddata->pdds.mask, 1); + if (err) { + dev_err(&rproc->dev, "failed to set pdds\n"); + return err; + } + } + + /* Update coprocessor state to OFF if available. */ + if (ddata->m4_state.map) { + err = regmap_update_bits(ddata->m4_state.map, + ddata->m4_state.reg, + ddata->m4_state.mask, + M4_STATE_OFF); + if (err) { + dev_err(&rproc->dev, "failed to set copro state\n"); + return err; + } + } + + return err; +} + static int stm32_rproc_prepare(struct rproc *rproc) { struct device *dev = rproc->dev.parent; @@ -519,17 +567,9 @@ static int stm32_rproc_detach(struct rproc *rproc) static int stm32_rproc_stop(struct rproc *rproc) { struct stm32_rproc *ddata = rproc->priv; - int err, idx; + int err; - /* request shutdown of the remote processor */ - if (rproc->state != RPROC_OFFLINE && rproc->state != RPROC_CRASHED) { - idx = stm32_rproc_mbox_idx(rproc, STM32_MBX_SHUTDOWN); - if (idx >= 0 && ddata->mb[idx].chan) { - err = mbox_send_message(ddata->mb[idx].chan, "detach"); - if (err < 0) - dev_warn(&rproc->dev, "warning: remote FW shutdown without ack\n"); - } - } + stm32_rproc_request_shutdown(rproc); err = stm32_rproc_set_hold_boot(rproc, true); if (err) @@ -541,29 +581,7 @@ static int stm32_rproc_stop(struct rproc *rproc) return err; } - /* to allow platform Standby power mode, set remote proc Deep Sleep */ - if (ddata->pdds.map) { - err = regmap_update_bits(ddata->pdds.map, ddata->pdds.reg, - ddata->pdds.mask, 1); - if (err) { - dev_err(&rproc->dev, "failed to set pdds\n"); - return err; - } - } - - /* update coprocessor state to OFF if available */ - if (ddata->m4_state.map) { - err = regmap_update_bits(ddata->m4_state.map, - ddata->m4_state.reg, - ddata->m4_state.mask, - M4_STATE_OFF); - if (err) { - dev_err(&rproc->dev, "failed to set copro state\n"); - return err; - } - } - - return 0; + return stm32_rproc_release(rproc); } static void stm32_rproc_kick(struct rproc *rproc, int vqid) From patchwork Wed Feb 14 17:21:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 201070 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1375612dyb; Wed, 14 Feb 2024 09:29:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUaNexNet7iLme8MXv2bLa1ktnQnGgHkQ2rrfnImoWHarlmQddP9dEZnBzJjFJkCcq9FLex2j+BfZl7DVyUM3YGbloyrw== X-Google-Smtp-Source: AGHT+IEB8l4lXBLoKlg1un1PflghaBqGtbT79pGM1ghjFq+pFXcK1JmS2jXpba7Pw6Hoj+EDxOy3 X-Received: by 2002:a05:6512:48c7:b0:511:7b35:9563 with SMTP id er7-20020a05651248c700b005117b359563mr2277574lfb.19.1707931751725; Wed, 14 Feb 2024 09:29:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707931751; cv=pass; d=google.com; s=arc-20160816; b=xUEMbY4iTlaS5jNxKelanVfj0c96kK3auTQM1wELqrJtoqCCIEp3T/q0S7tI1orIyo kLUzoTh3793vI2YOvEoe/1Fh6FlDApmyBacjB7kUGGOfmvgb8U+H/N19Um5nN/ocxGmo vXD9K11ectUiWX2Ga5vJ66hE2QmIY4SYmABc7I+qgse97kB9WHjuCtLrC2k+Lwh2ENYR CYXdWeBZQTsHBrOTQ63+5w226HH571TMbBoLem45063XnIIgnd3gaq0QZ7scW0iZ4qrD MroqMgjYCQm+pk4bP1ghgEArTMR5cW774eqnvkXHBS6Dp6hgNvUH+JgX3u0Vusw/g8uc QHBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=c2yeVpc3MZbl0q16caO2boLot7TbDyFbU6polZTQNW0=; fh=ewkEmNhU2Gr4CiOOXugHKfcpKF+2u2m+nzRthgJOoZ8=; b=DJqaMPMDAEUIuXcdzp0pME4kWZNeEv90jyMjEXpjFnUQX7OAtshRWzJlDBQp7tPara vYBZZP01+tRFzE/sUa2au0Yq5XO1jvgrkxCN+Q+qN6MdW2u2CSAZHCcarfXaggWfNva3 xK9/zgkOKqHdnFYp5iwz8gGQd1v8+7egBP7PaWBTDftU0Ovq9j5P9TopZMfliv/4KrbN HDtrJ7FbaNp5Ul40gK39QNwOI0iqemUom+DCvQ8rHL3eMLAS2WRxsmlo20Qmg7291Wsw MaQvr+zS6IcVd9YznehGqsI9mzDaTP+uGoyadtvSYRoV4UiOyRwm32cPxYvWDzWIUljC 1qZw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=E1YIRe4g; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65671-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65671-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com X-Forwarded-Encrypted: i=2; AJvYcCX1I3kJck2jrxiYR91SxGxGkW33rPKcIJgVGrIpn2ek1OxYDmfCNc/DU0jlygYpPDuz5qk/oLBgVyqY0uWFLHOxZNOmnw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a24-20020a170906671800b00a3c09428362si2315390ejp.653.2024.02.14.09.29.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:29:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65671-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=E1YIRe4g; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-65671-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65671-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1D29C1F23BD3 for ; Wed, 14 Feb 2024 17:29:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9817C84FAE; Wed, 14 Feb 2024 17:23:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="E1YIRe4g" Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CCD684FA0; Wed, 14 Feb 2024 17:23:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.132.182.106 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931405; cv=none; b=rhv2G2+a9nmMSMHkFmnuVJCBuMuzoPQ6tEl+FX6pPnT3U2joWYf+oJO/EYSLOPq3qQ92xcHirgxNrR63OQWcgkcwypTyqjYAoGUr46/i2D2YnR9FNaq7Gub7Lxa8TDqujjPLKQ6BQex+jvUmV2IFkNQhO8u4sORqC4CP1FXNPrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707931405; c=relaxed/simple; bh=83FYFITJxZ0ToyIf4Cort5eRKEEZpBch36s5bpwbgko=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NQYvgHA4n8YeUPD/lAP0m2HHUAwf3Nxy3fB+NQBhWeyOFo2vzbler312ssHGDh0HuZJZzMGAUryWcw/EN1yUECXr/ypmuk/jZA4m/vKM6RMtb9PF7a5slMRRoilSPy1jIhFSP30OM76+jSMRqwsBhs/JeIiv9VYM8g3rHxW8ijU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=E1YIRe4g; arc=none smtp.client-ip=185.132.182.106 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0369458.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41EHEGZl026396; Wed, 14 Feb 2024 18:23:11 +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=c2yeVpc3MZbl0q16caO2boLot7TbDyFbU6polZTQNW0=; b=E1 YIRe4geOgTlnVbLobG5AGMxz1beN9c2eAI21IzPJHM+jnLA2KW4RQm2nIQoxZR3V QaJ8/yT9vjGCN58BuypGE3Zv2TP/V/3qIG83Ejb3l0FK97dhoY2AUsSpGklK0u/G 4ZTSDxfWEwdtw3BgcK3NpreepMqDnRpnlELYXrFkjq8C1FxyPXtQhi2XhhA5//n4 x6085imLiYi4qt3lnxHl59KK6rKb2rbkgKiCdApY0cf2fCeV8Sy4ENZGz/oRPloE Xdjny4hY9ngyegILyOWrFW1hc0EHszGcJTkPCr8pGdHJSeUmacmnzA69vuvlAE/0 Tw4IWsAwtZPll6txZuEQ== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3w6kk4wwef-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Feb 2024 18:23:11 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 841CB4002D; Wed, 14 Feb 2024 18:23:05 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node6.st.com [10.75.129.135]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 129D42CA550; Wed, 14 Feb 2024 18:21:37 +0100 (CET) Received: from SAFDAG1NODE1.st.com (10.75.90.17) by EQNDAG1NODE6.st.com (10.75.129.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:36 +0100 Received: from localhost (10.201.20.75) by SAFDAG1NODE1.st.com (10.75.90.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 14 Feb 2024 18:21:36 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Jens Wiklander , "Rob Herring" , Krzysztof Kozlowski , Conor Dooley CC: , , , , , , Arnaud Pouliquen Subject: [PATCH v3 7/7] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware Date: Wed, 14 Feb 2024 18:21:27 +0100 Message-ID: <20240214172127.1022199-8-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> References: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE2.st.com (10.75.90.13) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-14_10,2024-02-14_01,2023-05-22_02 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790896244631937307 X-GMAIL-MSGID: 1790896244631937307 The new TEE remoteproc device is used to manage remote firmware in a secure, trusted context. The 'st,stm32mp1-m4-tee' compatibility is introduced to delegate the loading of the firmware to the trusted execution context. In such cases, the firmware should be signed and adhere to the image format defined by the TEE. A new "to_attach" field is introduced to differentiate the use cases "firmware loaded by the boot stage" and "firmware loaded by the TEE". Signed-off-by: Arnaud Pouliquen --- V2 to V3 update: - remove stm32_rproc_tee_elf_sanity_check(), stm32_rproc_tee_elf_load() stm32_rproc_tee_elf_find_loaded_rsc_table() and stm32_rproc_tee_start() that are bnow unused - use new rproc::alt_boot field to sepcify that the alternate fboot method is used - use stm32_rproc::to_attach field to differenciate attch mode from remoteproc tee boot mode. - remove the used of stm32_rproc::fw_loaded --- drivers/remoteproc/stm32_rproc.c | 85 +++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 6 deletions(-) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index fcc0001e2657..9cfcf66462e0 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "remoteproc_internal.h" @@ -49,6 +50,9 @@ #define M4_STATE_STANDBY 4 #define M4_STATE_CRASH 5 +/* Remote processor unique identifier aligned with the Trusted Execution Environment definitions */ +#define STM32_MP1_M4_PROC_ID 0 + struct stm32_syscon { struct regmap *map; u32 reg; @@ -90,6 +94,8 @@ struct stm32_rproc { struct stm32_mbox mb[MBOX_NB_MBX]; struct workqueue_struct *workqueue; bool hold_boot_smc; + bool to_attach; + struct tee_rproc *trproc; void __iomem *rsc_va; }; @@ -253,10 +259,30 @@ static int stm32_rproc_release(struct rproc *rproc) return err; } } + ddata->to_attach = false; return err; } +static int stm32_rproc_tee_attach(struct rproc *rproc) +{ + /* Nothing to do, remote proc already started by the secured context. */ + return 0; +} + +static int stm32_rproc_tee_stop(struct rproc *rproc) +{ + int err; + + stm32_rproc_request_shutdown(rproc); + + err = tee_rproc_stop(rproc); + if (err) + return err; + + return stm32_rproc_release(rproc); +} + static int stm32_rproc_prepare(struct rproc *rproc) { struct device *dev = rproc->dev.parent; @@ -637,10 +663,14 @@ stm32_rproc_get_loaded_rsc_table(struct rproc *rproc, size_t *table_sz) { struct stm32_rproc *ddata = rproc->priv; struct device *dev = rproc->dev.parent; + struct tee_rproc *trproc = ddata->trproc; phys_addr_t rsc_pa; u32 rsc_da; int err; + if (trproc && !ddata->to_attach) + return tee_rproc_get_loaded_rsc_table(rproc, table_sz); + /* The resource table has already been mapped, nothing to do */ if (ddata->rsc_va) goto done; @@ -693,8 +723,20 @@ static const struct rproc_ops st_rproc_ops = { .get_boot_addr = rproc_elf_get_boot_addr, }; +static const struct rproc_ops st_rproc_tee_ops = { + .prepare = stm32_rproc_prepare, + .start = tee_rproc_start, + .stop = stm32_rproc_tee_stop, + .attach = stm32_rproc_tee_attach, + .kick = stm32_rproc_kick, + .get_loaded_rsc_table = stm32_rproc_get_loaded_rsc_table, + .find_loaded_rsc_table = tee_rproc_find_loaded_rsc_table, + .load = tee_rproc_load_fw, +}; + static const struct of_device_id stm32_rproc_match[] = { - { .compatible = "st,stm32mp1-m4" }, + {.compatible = "st,stm32mp1-m4",}, + {.compatible = "st,stm32mp1-m4-tee",}, {}, }; MODULE_DEVICE_TABLE(of, stm32_rproc_match); @@ -853,6 +895,7 @@ static int stm32_rproc_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct stm32_rproc *ddata; struct device_node *np = dev->of_node; + struct tee_rproc *trproc = NULL; struct rproc *rproc; unsigned int state; int ret; @@ -861,12 +904,33 @@ static int stm32_rproc_probe(struct platform_device *pdev) if (ret) return ret; - rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata)); - if (!rproc) - return -ENOMEM; + if (of_device_is_compatible(np, "st,stm32mp1-m4-tee")) { + /* + * Delegate the firmware management to the secure context. + * The firmware loaded has to be signed. + */ + trproc = tee_rproc_register(dev, STM32_MP1_M4_PROC_ID); + if (IS_ERR(trproc)) { + dev_err_probe(dev, PTR_ERR(trproc), + "signed firmware not supported by TEE\n"); + return PTR_ERR(trproc); + } + } - ddata = rproc->priv; + rproc = rproc_alloc(dev, np->name, + trproc ? &st_rproc_tee_ops : &st_rproc_ops, + NULL, sizeof(*ddata)); + if (!rproc) { + ret = -ENOMEM; + goto free_tee; + } + ddata = rproc->priv; + ddata->trproc = trproc; + if (trproc) { + rproc->alt_boot = true; + trproc->rproc = rproc; + } rproc_coredump_set_elf_info(rproc, ELFCLASS32, EM_NONE); ret = stm32_rproc_parse_dt(pdev, ddata, &rproc->auto_boot); @@ -881,8 +945,10 @@ static int stm32_rproc_probe(struct platform_device *pdev) if (ret) goto free_rproc; - if (state == M4_STATE_CRUN) + if (state == M4_STATE_CRUN) { rproc->state = RPROC_DETACHED; + ddata->to_attach = true; + } rproc->has_iommu = false; ddata->workqueue = create_workqueue(dev_name(dev)); @@ -916,6 +982,10 @@ static int stm32_rproc_probe(struct platform_device *pdev) device_init_wakeup(dev, false); } rproc_free(rproc); +free_tee: + if (trproc) + tee_rproc_unregister(trproc); + return ret; } @@ -923,6 +993,7 @@ static void stm32_rproc_remove(struct platform_device *pdev) { struct rproc *rproc = platform_get_drvdata(pdev); struct stm32_rproc *ddata = rproc->priv; + struct tee_rproc *trproc = ddata->trproc; struct device *dev = &pdev->dev; if (atomic_read(&rproc->power) > 0) @@ -937,6 +1008,8 @@ static void stm32_rproc_remove(struct platform_device *pdev) device_init_wakeup(dev, false); } rproc_free(rproc); + if (trproc) + tee_rproc_unregister(trproc); } static int stm32_rproc_suspend(struct device *dev)