From patchwork Tue Nov 26 09:10:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 13885612 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 120D41B3F3D; Tue, 26 Nov 2024 09:13:29 +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=1732612411; cv=none; b=R+ve95HXMcZJgtdFyOcyYVnqVfeQhtuVWh7Uj8lZMsVQu2Ih52toIzdvQJ7tbF0wPXKxle+c6oxDfnxUoFqjL29rlhDE8v+tXCtodLvpeLpm9NUD9nBP5GGhcZAHQKMqtX2iYwgrXkH06eU2HnOvYVEgzQnhjOsd1UEYh9MnMzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732612411; c=relaxed/simple; bh=DOMHloKF4UN4qlkttRPn0qxlabsJq5KTXbS9OAb2WUc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nN5w6Jigm0pnvcpBmHVLuGC07azwuws04PFy7AWGn45uihrRBM4gAY5HASPGu7xXuOdJi+0urngymF7E+6RlSvWPS7ZnFx6g0lWIf16MtQ1skCU/Npguz6XMCFExZ1aYFrOOhmRP6/Uwq/KEycpn0POn1ukB7qNPLi5CZB/2+WM= 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=CzPdDa8O; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="CzPdDa8O" Received: from pps.filterd (m0369457.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AQ7VaLq030348; Tue, 26 Nov 2024 10:13:23 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= GC977nshZkMWBVY/wKvcQDvyN5arEAKIKgjZHxchAjQ=; b=CzPdDa8ONoMdXZlT Kor+Xu5/g1BSKPvbAm+p54oZtu3EwFpnQj+wrktsJLHjwn0d3R5zU4r7zMzvBB67 N12eSebyLlJZUAok+jQq0fzZNe90CMK1rayUDLhpUDoUkSSMU4Ls9V6yOEjWdWBs /cyguU3P0zeyVvNHlV+u62ziIZOaArhNuhZgidt85No5T40LgRyotJ7Q4+u9kcl1 VMn/3dKfkecnM3Dn0i055IDdRmco6Uixuu2oHk5AwE4oi7acJWsr7BUeHk3SMO9c rUte4nusagMqNxf96Z2VTFwWjMRe6oVi3Esi4UGcAwPfZJD1+vMgK9VgnTApOZZd l+IU/A== 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 433tvnhanv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Nov 2024 10:13: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 343554006F; Tue, 26 Nov 2024 10:12:18 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node6.st.com [10.75.129.135]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id F1F1A26B648; Tue, 26 Nov 2024 10:11:07 +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.37; Tue, 26 Nov 2024 10:11:07 +0100 Received: from localhost (10.48.86.121) 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.37; Tue, 26 Nov 2024 10:11:07 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: Arnaud Pouliquen , , Subject: [PATCH v14 1/8] remoteproc: core: Introduce rproc_pa_to_va helper Date: Tue, 26 Nov 2024 10:10:32 +0100 Message-ID: <20241126091042.918144-2-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> References: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE1.st.com (10.75.90.11) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 When a resource table is loaded by an external entity such as U-boot or OP-TEE, we do not necessarily get the device address(da) but the physical address(pa). This helper performs similar translation than the rproc_da_to_va() but based on a physical address. Signed-off-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 46 ++++++++++++++++++++++++++++ include/linux/remoteproc.h | 1 + 2 files changed, 47 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index f276956f2c5c..ace11ea17097 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -230,6 +230,52 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) } EXPORT_SYMBOL(rproc_da_to_va); +/** + * rproc_pa_to_va() - lookup the kernel virtual address for a physical address of a remoteproc + * memory + * + * @rproc: handle of a remote processor + * @pa: remoteproc physical address + * @len: length of the memory region @pa is pointing to + * @is_iomem: optional pointer filled in to indicate if @da is iomapped memory + * + * This function is a helper function similar to rproc_da_to_va() but it deals with physical + * addresses instead of device addresses. + * + * Return: a valid kernel address on success or NULL on failure + */ +void *rproc_pa_to_va(struct rproc *rproc, phys_addr_t pa, size_t len, bool *is_iomem) +{ + struct rproc_mem_entry *carveout; + void *ptr = NULL; + + list_for_each_entry(carveout, &rproc->carveouts, node) { + int offset = pa - carveout->dma; + + /* Verify that carveout is allocated */ + if (!carveout->va) + continue; + + /* try next carveout if da is too small */ + if (offset < 0) + continue; + + /* try next carveout if da is too large */ + if (offset + len > carveout->len) + continue; + + ptr = carveout->va + offset; + + if (is_iomem) + *is_iomem = carveout->is_iomem; + + break; + } + + return ptr; +} +EXPORT_SYMBOL(rproc_pa_to_va); + /** * rproc_find_carveout_by_name() - lookup the carveout region by a name * @rproc: handle of a remote processor diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index b4795698d8c2..8fd0d7f63c8e 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -690,6 +690,7 @@ int rproc_detach(struct rproc *rproc); int rproc_set_firmware(struct rproc *rproc, const char *fw_name); void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type); void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem); +void *rproc_pa_to_va(struct rproc *rproc, phys_addr_t pa, size_t len, bool *is_iomem); /* from remoteproc_coredump.c */ void rproc_coredump_cleanup(struct rproc *rproc); From patchwork Tue Nov 26 09:10:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 13885613 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 BED8D1B0F30; Tue, 26 Nov 2024 09:13:29 +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=1732612412; cv=none; b=HMTXnEYAA3WYqpdxOeEBOBvB7hoVQKc4uAomFnTZJZZwXvMfjMi4V5HlpnOHZvneOG5ePjArm2i9ZXqmz2uKF80A2LrxPKIWCPkqQiOBm48j91OxOwmIUEL69Ogv4O88BGo52tcOy21GprDdapwFdTBxtf4pXHDRqj7xTh4/7HM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732612412; c=relaxed/simple; bh=I4yJVh4+xfxk8E9ZFlAaaxq89CLzmi+M46ITHsxZR0A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=B0dkJwTOMAT7iYUXHP3i9qc3UEpTi7tgDp+L/04zieSYUuIl6PjzbKHKIPLHXlF33VR1UXZDcYb0QkfGW9Q8q6BfcxXM48LyiaPGxbatZ0/mAxYFd2OEhC3Y3vzlDEBRQhCnsuGd3fMJ0NkxkKDlp4kKOJfBqPYU3npxA7p/kMw= 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=sNi07hej; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="sNi07hej" Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AQ1uJmP007632; Tue, 26 Nov 2024 10:13:22 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= wIkbPPG3XZlOb8vV21W9aDEP4JJTOLJlecSPFC18NcU=; b=sNi07hej108LvbFn GfQxqj0OzVISOQwMJ/oqbvTtUbVeDyxNhPvsYojL78W+gqjArnEoyxSf0oOWbbCC +mXSP411+MHTiTpsiA3JwCHWjamKlToXROkL8GeFZq0D0lSsAGCbNFlo3H2QuM36 pRqxidVE8aH5JsU7HbtQmCoBHR+2A00yqlVg9vyCUKWjo/MRnTZovHnRwTdNA0BH hybnzyYw7DJBL9K9QZDQRD2wlQV4XqS9YD7Rov66/v/tE+ppsKaG04QC0kBQEDz+ M8dDjEarKrVs9jIH9GyocwdlUTjCUJXqhGZdOLI1bpRllLCG04ptfWcgwjx1xEdA 1CA2KA== 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 4336tfkstr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Nov 2024 10:13: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 3423240047; Tue, 26 Nov 2024 10:12: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 EA40226B649; Tue, 26 Nov 2024 10:11:09 +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.37; Tue, 26 Nov 2024 10:11:09 +0100 Received: from localhost (10.48.86.121) 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.37; Tue, 26 Nov 2024 10:11:09 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: Arnaud Pouliquen , , Subject: [PATCH v14 2/8] remoteproc: Add TEE support Date: Tue, 26 Nov 2024 10:10:33 +0100 Message-ID: <20241126091042.918144-3-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> References: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE1.st.com (10.75.90.11) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 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 driver offers a client interface to load a firmware by the secure part. This firmware could be authenticated by the secure trusted application. Signed-off-by: Arnaud Pouliquen --- Updates vs previous version: - define REMOTEPROC_TEE as bool instead of tristate, - remove the load of the firmware in rproc_tee_parse_fw as we will ensure that the firmware is loaded using the load_fw() operation. --- drivers/remoteproc/Kconfig | 10 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/remoteproc_tee.c | 508 ++++++++++++++++++++++++++++ include/linux/remoteproc.h | 4 + include/linux/remoteproc_tee.h | 105 ++++++ 5 files changed, 628 insertions(+) create mode 100644 drivers/remoteproc/remoteproc_tee.c create mode 100644 include/linux/remoteproc_tee.h diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig index 955e4e38477e..f6335321d540 100644 --- a/drivers/remoteproc/Kconfig +++ b/drivers/remoteproc/Kconfig @@ -23,6 +23,16 @@ config REMOTEPROC_CDEV It's safe to say N if you don't want to use this interface. +config REMOTEPROC_TEE + bool "Remoteproc support by a TEE application" + depends on OPTEE + help + Support a remote processor with a TEE application. The Trusted + Execution Context is responsible for loading the trusted firmware + image and managing the remote processor's lifecycle. + + It's safe to say N if you don't want to use remoteproc TEE. + config IMX_REMOTEPROC tristate "i.MX remoteproc support" depends on ARCH_MXC diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile index 5ff4e2fee4ab..f77e0abe8349 100644 --- a/drivers/remoteproc/Makefile +++ b/drivers/remoteproc/Makefile @@ -11,6 +11,7 @@ remoteproc-y += remoteproc_sysfs.o remoteproc-y += remoteproc_virtio.o remoteproc-y += remoteproc_elf_loader.o obj-$(CONFIG_REMOTEPROC_CDEV) += remoteproc_cdev.o +obj-$(CONFIG_REMOTEPROC_TEE) += remoteproc_tee.o obj-$(CONFIG_IMX_REMOTEPROC) += imx_rproc.o obj-$(CONFIG_IMX_DSP_REMOTEPROC) += imx_dsp_rproc.o obj-$(CONFIG_INGENIC_VPU_RPROC) += ingenic_rproc.o diff --git a/drivers/remoteproc/remoteproc_tee.c b/drivers/remoteproc/remoteproc_tee.c new file mode 100644 index 000000000000..4c406be0c3e5 --- /dev/null +++ b/drivers/remoteproc/remoteproc_tee.c @@ -0,0 +1,508 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) STMicroelectronics 2024 + * Author: Arnaud Pouliquen + */ + +#include +#include +#include +#include +#include +#include +#include + +#define MAX_TEE_PARAM_ARRAY_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 + +/* + * Release remote processor firmware images and associated resources. + * This command should be used in case an error occurs between the loading of + * the firmware images (A_RPROC_CMD_LOAD_FW) and the starting of the remote + * processor (TA_RPROC_CMD_START_FW) or after stopping the remote processor + * to release associated resources (TA_RPROC_CMD_STOP_FW). + * + * [in] params[0].value.a: Unique 32-bit remote processor identifier + */ +#define TA_RPROC_CMD_RELEASE_FW 6 + +struct rproc_tee_context { + struct list_head sessions; + struct tee_context *tee_ctx; + struct device *dev; +}; + +static struct rproc_tee_context *rproc_tee_ctx; + +static void rproc_tee_prepare_args(struct rproc_tee *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_ARRAY_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, + }; +} + +void rproc_tee_release_fw(struct rproc *rproc) +{ + struct tee_param param[MAX_TEE_PARAM_ARRAY_MEMBER]; + struct rproc_tee *trproc = rproc->rproc_tee_itf; + struct tee_ioctl_invoke_arg arg; + int ret; + + if (!rproc) { + ret = -EINVAL; + goto out; + } + + /* + * If the remote processor state is RPROC_DETACHED, just ignore the + * request, as the remote processor is still running. + */ + if (rproc->state == RPROC_DETACHED) + return; + + if (rproc->state != RPROC_OFFLINE) { + ret = -EBUSY; + goto out; + } + + rproc_tee_prepare_args(trproc, TA_RPROC_CMD_RELEASE_FW, &arg, param, 0); + + ret = tee_client_invoke_func(rproc_tee_ctx->tee_ctx, &arg, param); + if (ret < 0 || arg.ret != 0) { + dev_err(rproc_tee_ctx->dev, + "TA_RPROC_CMD_RELEASE_FW invoke failed TEE err: %x, ret:%x\n", + arg.ret, ret); + ret = -EIO; + } + +out: + if (ret) + /* Unexpected state without solution to come back in a stable state */ + dev_err(rproc_tee_ctx->dev, "Failed to release TEE remoteproc firmware: %d\n", ret); +} +EXPORT_SYMBOL_GPL(rproc_tee_release_fw); + +int rproc_tee_load_fw(struct rproc *rproc, const struct firmware *fw) +{ + struct tee_param param[MAX_TEE_PARAM_ARRAY_MEMBER]; + struct rproc_tee *trproc = rproc->rproc_tee_itf; + struct tee_ioctl_invoke_arg arg; + struct tee_shm *fw_shm; + int ret; + + if (!trproc) + return -EINVAL; + + fw_shm = tee_shm_register_kernel_buf(rproc_tee_ctx->tee_ctx, (void *)fw->data, fw->size); + if (IS_ERR(fw_shm)) + return PTR_ERR(fw_shm); + + rproc_tee_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(rproc_tee_ctx->tee_ctx, &arg, param); + if (ret < 0 || arg.ret != 0) { + dev_err(rproc_tee_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(rproc_tee_load_fw); + +static int rproc_tee_get_loaded_rsc_table(struct rproc *rproc, phys_addr_t *rsc_pa, + size_t *table_sz) +{ + struct tee_param param[MAX_TEE_PARAM_ARRAY_MEMBER]; + struct rproc_tee *trproc = rproc->rproc_tee_itf; + struct tee_ioctl_invoke_arg arg; + int ret; + + if (!trproc) + return -EINVAL; + + rproc_tee_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(rproc_tee_ctx->tee_ctx, &arg, param); + if (ret < 0 || arg.ret != 0) { + dev_err(rproc_tee_ctx->dev, + "TA_RPROC_FW_CMD_GET_RSC_TABLE invoke failed TEE err: %x, ret:%x\n", + arg.ret, ret); + return -EIO; + } + + *table_sz = param[2].u.value.a; + + if (*table_sz) + *rsc_pa = param[1].u.value.a; + else + *rsc_pa = 0; + + return 0; +} + +int rproc_tee_parse_fw(struct rproc *rproc, const struct firmware *fw) +{ + phys_addr_t rsc_table; + void __iomem *rsc_va; + size_t table_sz; + int ret; + + if (!rproc) + return -EINVAL; + + /* At this point, the firmware has to be loaded to be able to parse the resource table. */ + + ret = rproc_tee_get_loaded_rsc_table(rproc, &rsc_table, &table_sz); + if (ret) + goto release_fw; + + /* + * We assume here that the memory mapping is the same between the TEE and Linux kernel + * contexts. Else a new TEE remoteproc service could be needed to get a copy of the + * resource table + */ + rsc_va = ioremap_wc(rsc_table, table_sz); + if (IS_ERR_OR_NULL(rsc_va)) { + dev_err(rproc_tee_ctx->dev, "Unable to map memory region: %pa+%zx\n", + &rsc_table, table_sz); + ret = -ENOMEM; + goto release_fw; + } + + /* + * Create a copy of the resource table to have the same behavior as the ELF loader. + * This cached table will be used by the remoteproc core after the remoteproc stops + * to free resources and for crash recovery to reapply the settings. + * The cached table will be freed by the remoteproc core. + */ + rproc->cached_table = kmemdup((__force void *)rsc_va, table_sz, GFP_KERNEL); + iounmap(rsc_va); + + if (!rproc->cached_table) { + ret = -ENOMEM; + goto release_fw; + } + + rproc->table_ptr = rproc->cached_table; + rproc->table_sz = table_sz; + + return 0; + +release_fw: + rproc_tee_release_fw(rproc); + return ret; +} +EXPORT_SYMBOL_GPL(rproc_tee_parse_fw); + +struct resource_table *rproc_tee_find_loaded_rsc_table(struct rproc *rproc, + const struct firmware *fw) +{ + phys_addr_t rsc_table; + size_t table_sz; + int ret; + + ret = rproc_tee_get_loaded_rsc_table(rproc, &rsc_table, &table_sz); + if (ret) + return NULL; + + rproc->table_sz = table_sz; + if (!table_sz) + return NULL; + + /* + * At this step the memory area that contains the resource table should have been registered + * by the remote proc platform driver and allocated by rproc_alloc_registered_carveouts(). + */ + return (struct resource_table *)rproc_pa_to_va(rproc, rsc_table, table_sz, NULL); +} +EXPORT_SYMBOL_GPL(rproc_tee_find_loaded_rsc_table); + +int rproc_tee_start(struct rproc *rproc) +{ + struct tee_param param[MAX_TEE_PARAM_ARRAY_MEMBER]; + struct rproc_tee *trproc = rproc->rproc_tee_itf; + struct tee_ioctl_invoke_arg arg; + int ret = 0; + + if (!trproc) + return -EINVAL; + + rproc_tee_prepare_args(trproc, TA_RPROC_FW_CMD_START_FW, &arg, param, 0); + + ret = tee_client_invoke_func(rproc_tee_ctx->tee_ctx, &arg, param); + if (ret < 0 || arg.ret != 0) { + dev_err(rproc_tee_ctx->dev, + "TA_RPROC_FW_CMD_START_FW invoke failed TEE err: %x, ret:%x\n", + arg.ret, ret); + if (!ret) + return -EIO; + } + + return 0; +} +EXPORT_SYMBOL_GPL(rproc_tee_start); + +int rproc_tee_stop(struct rproc *rproc) +{ + struct tee_param param[MAX_TEE_PARAM_ARRAY_MEMBER]; + struct rproc_tee *trproc = rproc->rproc_tee_itf; + struct tee_ioctl_invoke_arg arg; + int ret; + + if (!trproc) + return -EINVAL; + + rproc_tee_prepare_args(trproc, TA_RPROC_FW_CMD_STOP_FW, &arg, param, 0); + + ret = tee_client_invoke_func(rproc_tee_ctx->tee_ctx, &arg, param); + if (ret < 0 || arg.ret != 0) { + dev_err(rproc_tee_ctx->dev, + "TA_RPROC_FW_CMD_STOP_FW invoke failed TEE err: %x, ret:%x\n", + arg.ret, ret); + if (!ret) + ret = -EIO; + } + + return ret; +} +EXPORT_SYMBOL_GPL(rproc_tee_stop); + +static const struct tee_client_device_id rproc_tee_id_table[] = { + {UUID_INIT(0x80a4c275, 0x0a47, 0x4905, 0x82, 0x85, 0x14, 0x86, 0xa9, 0x77, 0x1a, 0x08)}, + {} +}; + +int rproc_tee_register(struct device *dev, struct rproc *rproc, unsigned int rproc_id) +{ + struct tee_param param[MAX_TEE_PARAM_ARRAY_MEMBER]; + struct tee_ioctl_open_session_arg sess_arg; + struct tee_client_device *tee_device; + struct rproc_tee *trproc; + int ret; + + /* + * Test if the device has been probed by the TEE bus. In case of failure, we ignore the + * reason. The bus could be not yet probed or the service not available in the secure + * firmware.The assumption in such a case is that the TEE remoteproc is not probed. + */ + if (!rproc_tee_ctx) + return -EPROBE_DEFER; + + /* Prevent rproc tee module from being removed */ + if (!try_module_get(THIS_MODULE)) { + dev_err(rproc_tee_ctx->dev, "can't get owner\n"); + return -ENODEV; + } + + trproc = devm_kzalloc(dev, sizeof(*trproc), GFP_KERNEL); + if (!trproc) { + ret = -ENOMEM; + goto module_put; + } + + tee_device = to_tee_client_device(rproc_tee_ctx->dev); + memset(&sess_arg, 0, sizeof(sess_arg)); + + 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(rproc_tee_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); + ret = -EINVAL; + goto module_put; + } + + trproc->parent = dev; + trproc->rproc_id = rproc_id; + trproc->session_id = sess_arg.session; + + trproc->rproc = rproc; + rproc->rproc_tee_itf = trproc; + + list_add_tail(&trproc->node, &rproc_tee_ctx->sessions); + + return 0; + +module_put: + module_put(THIS_MODULE); + return ret; +} +EXPORT_SYMBOL_GPL(rproc_tee_register); + +int rproc_tee_unregister(struct rproc *rproc) +{ + struct rproc_tee *trproc = rproc->rproc_tee_itf; + int ret; + + if (!rproc->rproc_tee_itf) + return -ENODEV; + + ret = tee_client_close_session(rproc_tee_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); + rproc->rproc_tee_itf = NULL; + + module_put(THIS_MODULE); + + return ret; +} +EXPORT_SYMBOL_GPL(rproc_tee_unregister); + +static int rproc_tee_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 rproc_tee_probe(struct device *dev) +{ + struct tee_context *tee_ctx; + int ret; + + /* Open context with TEE driver */ + tee_ctx = tee_client_open_context(NULL, rproc_tee_ctx_match, NULL, NULL); + if (IS_ERR(tee_ctx)) + return PTR_ERR(tee_ctx); + + rproc_tee_ctx = devm_kzalloc(dev, sizeof(*rproc_tee_ctx), GFP_KERNEL); + if (!rproc_tee_ctx) { + ret = -ENOMEM; + goto err; + } + + rproc_tee_ctx->dev = dev; + rproc_tee_ctx->tee_ctx = tee_ctx; + INIT_LIST_HEAD(&rproc_tee_ctx->sessions); + + return 0; +err: + tee_client_close_context(tee_ctx); + + return ret; +} + +static int rproc_tee_remove(struct device *dev) +{ + struct rproc_tee *entry, *tmp; + + list_for_each_entry_safe(entry, tmp, &rproc_tee_ctx->sessions, node) { + tee_client_close_session(rproc_tee_ctx->tee_ctx, entry->session_id); + list_del(&entry->node); + kfree(entry); + } + + tee_client_close_context(rproc_tee_ctx->tee_ctx); + + return 0; +} + +MODULE_DEVICE_TABLE(tee, rproc_tee_id_table); + +static struct tee_client_driver rproc_tee_fw_driver = { + .id_table = rproc_tee_id_table, + .driver = { + .name = KBUILD_MODNAME, + .bus = &tee_bus_type, + .probe = rproc_tee_probe, + .remove = rproc_tee_remove, + }, +}; + +static int __init rproc_tee_fw_mod_init(void) +{ + return driver_register(&rproc_tee_fw_driver.driver); +} + +static void __exit rproc_tee_fw_mod_exit(void) +{ + driver_unregister(&rproc_tee_fw_driver.driver); +} + +module_init(rproc_tee_fw_mod_init); +module_exit(rproc_tee_fw_mod_exit); + +MODULE_DESCRIPTION(" remote processor TEE module"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 8fd0d7f63c8e..2e0ddcb2d792 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -503,6 +503,8 @@ enum rproc_features { RPROC_MAX_FEATURES, }; +struct rproc_tee; + /** * struct rproc - represents a physical remote processor device * @node: list node of this rproc object @@ -545,6 +547,7 @@ enum rproc_features { * @cdev: character device of the rproc * @cdev_put_on_release: flag to indicate if remoteproc should be shutdown on @char_dev release * @features: indicate remoteproc features + * @rproc_tee_itf: pointer to the remoteproc tee context */ struct rproc { struct list_head node; @@ -586,6 +589,7 @@ struct rproc { struct cdev cdev; bool cdev_put_on_release; DECLARE_BITMAP(features, RPROC_MAX_FEATURES); + struct rproc_tee *rproc_tee_itf; }; /** diff --git a/include/linux/remoteproc_tee.h b/include/linux/remoteproc_tee.h new file mode 100644 index 000000000000..9b498a8eff4d --- /dev/null +++ b/include/linux/remoteproc_tee.h @@ -0,0 +1,105 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright(c) 2024 STMicroelectronics + */ + +#ifndef REMOTEPROC_TEE_H +#define REMOTEPROC_TEE_H + +#include +#include +#include + +struct rproc; + +/** + * struct rproc_tee - 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 + */ +struct rproc_tee { + struct list_head node; + struct rproc *rproc; + struct device *parent; + u32 rproc_id; + u32 session_id; +}; + +#if IS_REACHABLE(CONFIG_REMOTEPROC_TEE) + +int rproc_tee_register(struct device *dev, struct rproc *rproc, unsigned int rproc_id); +int rproc_tee_unregister(struct rproc *rproc); +int rproc_tee_parse_fw(struct rproc *rproc, const struct firmware *fw); +int rproc_tee_load_fw(struct rproc *rproc, const struct firmware *fw); +void rproc_tee_release_fw(struct rproc *rproc); +struct resource_table *rproc_tee_find_loaded_rsc_table(struct rproc *rproc, + const struct firmware *fw); +int rproc_tee_start(struct rproc *rproc); +int rproc_tee_stop(struct rproc *rproc); + +#else + +static inline int rproc_tee_register(struct device *dev, struct rproc *rproc, unsigned int rproc_id) +{ + return -ENODEV; +} + +static inline int rproc_tee_parse_fw(struct rproc *rproc, const struct firmware *fw) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return 0; +} + +static inline int rproc_tee_unregister(struct rproc *rproc) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return 0; +} + +static inline int rproc_tee_load_fw(struct rproc *rproc, const struct firmware *fw) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return 0; +} + +static inline int rproc_tee_start(struct rproc *rproc) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return 0; +} + +static inline int rproc_tee_stop(struct rproc *rproc) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return 0; +} + +static inline void rproc_tee_release_fw(struct rproc *rproc) +{ + /* This shouldn't be possible */ + WARN_ON(1); +} + +static inline struct resource_table * +rproc_tee_find_loaded_rsc_table(struct rproc *rproc, const struct firmware *fw) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return NULL; +} +#endif /* CONFIG_REMOTEPROC_TEE */ +#endif /* REMOTEPROC_TEE_H */ From patchwork Tue Nov 26 09:10:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 13885611 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 A1A721B0F26; Tue, 26 Nov 2024 09:13:29 +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=1732612411; cv=none; b=PyDPTQOtZj2FSyesXmTaD7MvgH7yHzKZ9+QCQpCARQTE9lrY7OJlgKYHthMm9HOZIVDjQwjKOqfA+LtHrzIvwIVbI3OLuZyZ/EWyXsKmL7Cm72g/E84ltMJ6A+uoHYL8/F9LvHwgmDLnzLjlia4NedACXgLOcDnOHZs0VqnnnHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732612411; c=relaxed/simple; bh=MjLDhva9ihNERJEiYb3ppznzZfLb4Id5y78WoAk1000=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KEvaOHirhSeE4afN6B4/HvAbVx+hKskqibDLAxvL6EckV2ieFOblAATU31oCyFweR7ew8u2YVMGi/P5apABkUAt/G3GINednBGo1cr2i4n8QTgn3FLEhyaQsAj+vUISJtm5utsNJ0jLv2I8NNSnhVttm9WEhUjQL28tA68z0oRI= 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=hETJrqhx; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="hETJrqhx" Received: from pps.filterd (m0369458.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AQ3bWpf013828; Tue, 26 Nov 2024 10:13:23 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= g0lTgg7O/c42Vw2gvzMzOeAzWuUnj5z0drLIk2bZ1dw=; b=hETJrqhxQMtP7445 Un2Ghge68SC2/lkN/j1KrXEhG/isWgWV7LtZM9OXKAifMoQStNRdDgRExM7g4JOw 6689koWJ18+H8XnoHaYirWFmmFdGP17wYV15gG8kP292ZPNFmWtI11mchs8D0r5L fAyw3Vu3TnfW7zVbOz0NBle/Me8t9TG04/f5MTb1MT/1mfJbfMRinixzJ1/nqiBq 4HbJrMD/1z9KFcHlmM5txBp2TA1b14WZTdceVHarLJZ8HTLQHrlm3ctImhX4WSpV MdH0IiNp6ht35hzdWL7k9Nv1UmxhIARdnQJ7s8sTDWvhzPB2i7iURy6iyoUKy8xh 3wuWaA== 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 433sg49j7r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Nov 2024 10:13: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 68ADC40071; Tue, 26 Nov 2024 10:12:19 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node4.st.com [10.75.129.133]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 34B5026B64C; Tue, 26 Nov 2024 10:11:11 +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.37; Tue, 26 Nov 2024 10:11:11 +0100 Received: from localhost (10.48.86.121) 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.37; Tue, 26 Nov 2024 10:11:10 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: Arnaud Pouliquen , , Subject: [PATCH v14 3/8] remoteproc: Introduce load_fw and release_fw optional operation Date: Tue, 26 Nov 2024 10:10:34 +0100 Message-ID: <20241126091042.918144-4-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> References: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE1.st.com (10.75.90.11) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 This patch updates the rproc_ops structures to include two new optional operations. - The load_fw() op is responsible for loading the remote processor non-ELF firmware image before starting the boot sequence. This ops will be used, for instance, to call OP-TEE to authenticate an load the firmware image before accessing to its resources (a.e the resource table) - The release_fw op is responsible for releasing the remote processor firmware image. For instance to clean memories. The ops is called in the following cases: - An error occurs between the loading of the firmware image and the start of the remote processor. - after stopping the remote processor. Signed-off-by: Arnaud Pouliquen --- Update vs previous revision: - Rework the commit to introduce load_fw() op. - remove rproc_release_fw() call from rproc_start() as called in rproc_boot() and rproc_boot_recovery() in case of error. - create rproc_load_fw() and rproc_release_fw() internal functions. --- drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++- drivers/remoteproc/remoteproc_internal.h | 14 ++++++++++++++ include/linux/remoteproc.h | 6 ++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index ace11ea17097..8df4b2c59bb6 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1488,6 +1488,7 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) kfree(rproc->cached_table); rproc->cached_table = NULL; rproc->table_ptr = NULL; + rproc_release_fw(rproc); unprepare_rproc: /* release HW resources if needed */ rproc_unprepare_device(rproc); @@ -1855,8 +1856,14 @@ static int rproc_boot_recovery(struct rproc *rproc) return ret; } + ret = rproc_load_fw(rproc, firmware_p); + if (ret) + return ret; + /* boot the remote processor up again */ ret = rproc_start(rproc, firmware_p); + if (ret) + rproc_release_fw(rproc); release_firmware(firmware_p); @@ -1997,7 +2004,13 @@ int rproc_boot(struct rproc *rproc) goto downref_rproc; } + ret = rproc_load_fw(rproc, firmware_p); + if (ret) + goto downref_rproc; + ret = rproc_fw_boot(rproc, firmware_p); + if (ret) + rproc_release_fw(rproc); release_firmware(firmware_p); } @@ -2071,6 +2084,7 @@ int rproc_shutdown(struct rproc *rproc) kfree(rproc->cached_table); rproc->cached_table = NULL; rproc->table_ptr = NULL; + rproc_release_fw(rproc); out: mutex_unlock(&rproc->lock); return ret; @@ -2471,7 +2485,7 @@ static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops) if (!rproc->ops->coredump) rproc->ops->coredump = rproc_coredump; - if (rproc->ops->load) + if (rproc->ops->load || rproc->ops->load_fw) return 0; /* Default to ELF loader if no load function is specified */ diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 0cd09e67ac14..2104ca449178 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -221,4 +221,18 @@ bool rproc_u64_fit_in_size_t(u64 val) return (val <= (size_t) -1); } +static inline void rproc_release_fw(struct rproc *rproc) +{ + if (rproc->ops->release_fw) + rproc->ops->release_fw(rproc); +} + +static inline int rproc_load_fw(struct rproc *rproc, const struct firmware *fw) +{ + if (rproc->ops->load_fw) + return rproc->ops->load_fw(rproc, fw); + + return 0; +} + #endif /* REMOTEPROC_INTERNAL_H */ diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 2e0ddcb2d792..ba6fd560f7ba 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -381,6 +381,10 @@ enum rsc_handling_status { * @panic: optional callback to react to system panic, core will delay * panic at least the returned number of milliseconds * @coredump: collect firmware dump after the subsystem is shutdown + * @load_fw: optional function to load non-ELF firmware image to memory, where the remote + * processor expects to find it. + * @release_fw: optional function to release the firmware image from memories. + * This function is called after stopping the remote processor or in case of error */ struct rproc_ops { int (*prepare)(struct rproc *rproc); @@ -403,6 +407,8 @@ struct rproc_ops { u64 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw); unsigned long (*panic)(struct rproc *rproc); void (*coredump)(struct rproc *rproc); + int (*load_fw)(struct rproc *rproc, const struct firmware *fw); + void (*release_fw)(struct rproc *rproc); }; /** From patchwork Tue Nov 26 09:10:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 13885617 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 2BEF1126C0A; Tue, 26 Nov 2024 09:15:23 +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=1732612526; cv=none; b=F45NXiRgZ5HszZdW6sEh3SaGgcnQRKuYHjJXXBl9+XQNubdjQrMHHm32dNnyU//f4jxzsmFR5CsyyxME63Szfva7LpKudP9aVDDBMUa3LUxtrAFOir8Qj/ZeLVy+aD2nA1a8zpxD6LbNMS/RuLbepKywYEGxIFCvYkdfVe7r1n4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732612526; c=relaxed/simple; bh=DIApcsRarfJuvLio7GM2KLnSvShs2N0fFv/gngSFK1E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=stCRZ/GQJsjevEEu2pIcZ0HpaLRB1D2NVvuAbsLPijndXfnDjgrK4dNbf9uJn1FyKZJSolQq8G2m4N4jFKDrEKZ77d0YdXxKA6WWyFTSLfNRGfKJUPQl3W50VUzmmGu4BP6AfTF6ukx058eR3RI+AP7cpfAtPM2TAjdAh8cyWhU= 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=j2DEkQSQ; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="j2DEkQSQ" Received: from pps.filterd (m0369457.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AQ53nEO010578; Tue, 26 Nov 2024 10:14:53 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= af+pCFkEn5Uu729dokQ2oyPRG7AjK5zrbHT8BSaQwXA=; b=j2DEkQSQTe492lcG gS0U0q0v2UIULKggBuTovDLoFUw1C5CQz5f2bbY4ScSxyqdaUBmhqrxcCwrF/A0Q QFx4zcdiMGk8YvpvdHO9pmmLldStB3gaOfiu8zYQIK5lcVjTUKDO6RcEnhB1YCJZ GQx7SmuqaGh6Hv8pmYCTfcB46d8IASQNRDeHTTLq5mDd1tJ0RbnEZkpHyFffSPdg p1e2cNw/Vbw+5YfJ2jLWge/aAU/IHKqCcM+gPsEq6NouvjkHh3UEmwKwFU9wNeny 8Zc3iGdDvz1obYOqRx3xQn5vXj9yzuos83puU8R8GnQOU3TPWV1trv8iCuJUkKvh 9I0VkA== 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 433tvnhaxf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Nov 2024 10:14:53 +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 358754002D; Tue, 26 Nov 2024 10:13:00 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node6.st.com [10.75.129.135]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 2F54426B64E; Tue, 26 Nov 2024 10:11:14 +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.37; Tue, 26 Nov 2024 10:11:14 +0100 Received: from localhost (10.48.86.121) 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.37; Tue, 26 Nov 2024 10:11:13 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Neil Armstrong , Kevin Hilman , "Jerome Brunet" , Martin Blumenstingl , Matthias Brugger , AngeloGioacchino Del Regno , Patrice Chotard , Maxime Coquelin , Alexandre Torgue CC: Arnaud Pouliquen , , , , , , , , Subject: [PATCH v14 4/8] remoteproc: Rename load() operation to load_segments() in rproc_ops struct Date: Tue, 26 Nov 2024 10:10:35 +0100 Message-ID: <20241126091042.918144-5-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> References: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE1.st.com (10.75.90.11) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 With the introduction of the load_fw() operation in the rproc_ops structure, we need to clarify the difference in the use of the load() and load_fw() ops. The legacy load() is dedicated to loading the ELF segments into memory. Rename this to a more explicit name: load_segments(). Suggested-by: Mathieu Poirier Signed-off-by: Arnaud Pouliquen --- drivers/remoteproc/imx_dsp_rproc.c | 2 +- drivers/remoteproc/imx_rproc.c | 2 +- drivers/remoteproc/meson_mx_ao_arc.c | 2 +- drivers/remoteproc/mtk_scp.c | 2 +- drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/qcom_q6v5_pas.c | 4 ++-- drivers/remoteproc/qcom_q6v5_wcss.c | 4 ++-- drivers/remoteproc/qcom_wcnss.c | 2 +- drivers/remoteproc/rcar_rproc.c | 2 +- drivers/remoteproc/remoteproc_core.c | 4 ++-- drivers/remoteproc/remoteproc_internal.h | 4 ++-- drivers/remoteproc/st_remoteproc.c | 2 +- drivers/remoteproc/st_slim_rproc.c | 2 +- drivers/remoteproc/stm32_rproc.c | 2 +- drivers/remoteproc/xlnx_r5_remoteproc.c | 2 +- include/linux/remoteproc.h | 4 ++-- 17 files changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/remoteproc/imx_dsp_rproc.c b/drivers/remoteproc/imx_dsp_rproc.c index 376187ad5754..a4a85fbce907 100644 --- a/drivers/remoteproc/imx_dsp_rproc.c +++ b/drivers/remoteproc/imx_dsp_rproc.c @@ -934,7 +934,7 @@ static const struct rproc_ops imx_dsp_rproc_ops = { .start = imx_dsp_rproc_start, .stop = imx_dsp_rproc_stop, .kick = imx_dsp_rproc_kick, - .load = imx_dsp_rproc_elf_load_segments, + .load_segments = imx_dsp_rproc_elf_load_segments, .parse_fw = imx_dsp_rproc_parse_fw, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, .sanity_check = rproc_elf_sanity_check, diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c index 800015ff7ff9..f45b3207f7e9 100644 --- a/drivers/remoteproc/imx_rproc.c +++ b/drivers/remoteproc/imx_rproc.c @@ -681,7 +681,7 @@ static const struct rproc_ops imx_rproc_ops = { .stop = imx_rproc_stop, .kick = imx_rproc_kick, .da_to_va = imx_rproc_da_to_va, - .load = rproc_elf_load_segments, + .load_segments = rproc_elf_load_segments, .parse_fw = imx_rproc_parse_fw, .find_loaded_rsc_table = imx_rproc_elf_find_loaded_rsc_table, .get_loaded_rsc_table = imx_rproc_get_loaded_rsc_table, diff --git a/drivers/remoteproc/meson_mx_ao_arc.c b/drivers/remoteproc/meson_mx_ao_arc.c index f6744b538323..a1c8c0929ce3 100644 --- a/drivers/remoteproc/meson_mx_ao_arc.c +++ b/drivers/remoteproc/meson_mx_ao_arc.c @@ -137,7 +137,7 @@ static struct rproc_ops meson_mx_ao_arc_rproc_ops = { .stop = meson_mx_ao_arc_rproc_stop, .da_to_va = meson_mx_ao_arc_rproc_da_to_va, .get_boot_addr = rproc_elf_get_boot_addr, - .load = rproc_elf_load_segments, + .load_segments = rproc_elf_load_segments, .sanity_check = rproc_elf_sanity_check, }; diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c index e744c07507ee..4e9a8bf3bc6e 100644 --- a/drivers/remoteproc/mtk_scp.c +++ b/drivers/remoteproc/mtk_scp.c @@ -924,7 +924,7 @@ static int scp_stop(struct rproc *rproc) static const struct rproc_ops scp_ops = { .start = scp_start, .stop = scp_stop, - .load = scp_load, + .load_segments = scp_load, .da_to_va = scp_da_to_va, .parse_fw = scp_parse_fw, .sanity_check = rproc_elf_sanity_check, diff --git a/drivers/remoteproc/qcom_q6v5_adsp.c b/drivers/remoteproc/qcom_q6v5_adsp.c index 572dcb0f055b..aa9896930bcf 100644 --- a/drivers/remoteproc/qcom_q6v5_adsp.c +++ b/drivers/remoteproc/qcom_q6v5_adsp.c @@ -527,7 +527,7 @@ static const struct rproc_ops adsp_ops = { .stop = adsp_stop, .da_to_va = adsp_da_to_va, .parse_fw = adsp_parse_firmware, - .load = adsp_load, + .load_segments = adsp_load, .panic = adsp_panic, }; diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index 2a42215ce8e0..a8beac1deabe 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -1687,7 +1687,7 @@ static const struct rproc_ops q6v5_ops = { .start = q6v5_start, .stop = q6v5_stop, .parse_fw = qcom_q6v5_register_dump_segments, - .load = q6v5_load, + .load_segments = q6v5_load, .panic = q6v5_panic, }; diff --git a/drivers/remoteproc/qcom_q6v5_pas.c b/drivers/remoteproc/qcom_q6v5_pas.c index ef82835e98a4..9b269ce390c1 100644 --- a/drivers/remoteproc/qcom_q6v5_pas.c +++ b/drivers/remoteproc/qcom_q6v5_pas.c @@ -436,7 +436,7 @@ static const struct rproc_ops adsp_ops = { .stop = adsp_stop, .da_to_va = adsp_da_to_va, .parse_fw = qcom_register_dump_segments, - .load = adsp_load, + .load_segments = adsp_load, .panic = adsp_panic, }; @@ -446,7 +446,7 @@ static const struct rproc_ops adsp_minidump_ops = { .stop = adsp_stop, .da_to_va = adsp_da_to_va, .parse_fw = qcom_register_dump_segments, - .load = adsp_load, + .load_segments = adsp_load, .panic = adsp_panic, .coredump = adsp_minidump, }; diff --git a/drivers/remoteproc/qcom_q6v5_wcss.c b/drivers/remoteproc/qcom_q6v5_wcss.c index e913dabae992..44b5736dc8b9 100644 --- a/drivers/remoteproc/qcom_q6v5_wcss.c +++ b/drivers/remoteproc/qcom_q6v5_wcss.c @@ -771,7 +771,7 @@ static const struct rproc_ops q6v5_wcss_ipq8074_ops = { .start = q6v5_wcss_start, .stop = q6v5_wcss_stop, .da_to_va = q6v5_wcss_da_to_va, - .load = q6v5_wcss_load, + .load_segments = q6v5_wcss_load, .get_boot_addr = rproc_elf_get_boot_addr, }; @@ -779,7 +779,7 @@ static const struct rproc_ops q6v5_wcss_qcs404_ops = { .start = q6v5_qcs404_wcss_start, .stop = q6v5_wcss_stop, .da_to_va = q6v5_wcss_da_to_va, - .load = q6v5_wcss_load, + .load_segments = q6v5_wcss_load, .get_boot_addr = rproc_elf_get_boot_addr, .parse_fw = qcom_register_dump_segments, }; diff --git a/drivers/remoteproc/qcom_wcnss.c b/drivers/remoteproc/qcom_wcnss.c index a7bb9da27029..42102bc4c458 100644 --- a/drivers/remoteproc/qcom_wcnss.c +++ b/drivers/remoteproc/qcom_wcnss.c @@ -335,7 +335,7 @@ static const struct rproc_ops wcnss_ops = { .stop = wcnss_stop, .da_to_va = wcnss_da_to_va, .parse_fw = qcom_register_dump_segments, - .load = wcnss_load, + .load_segments = wcnss_load, }; static irqreturn_t wcnss_wdog_interrupt(int irq, void *dev) diff --git a/drivers/remoteproc/rcar_rproc.c b/drivers/remoteproc/rcar_rproc.c index cc17e8421f65..e36778fec072 100644 --- a/drivers/remoteproc/rcar_rproc.c +++ b/drivers/remoteproc/rcar_rproc.c @@ -142,7 +142,7 @@ static struct rproc_ops rcar_rproc_ops = { .prepare = rcar_rproc_prepare, .start = rcar_rproc_start, .stop = rcar_rproc_stop, - .load = rproc_elf_load_segments, + .load_segments = rproc_elf_load_segments, .parse_fw = rcar_rproc_parse_fw, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, .sanity_check = rproc_elf_sanity_check, diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 8df4b2c59bb6..e4ad024efcda 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2485,11 +2485,11 @@ static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops) if (!rproc->ops->coredump) rproc->ops->coredump = rproc_coredump; - if (rproc->ops->load || rproc->ops->load_fw) + if (rproc->ops->load_segments || rproc->ops->load_fw) return 0; /* Default to ELF loader if no load function is specified */ - rproc->ops->load = rproc_elf_load_segments; + rproc->ops->load_segments = rproc_elf_load_segments; rproc->ops->parse_fw = rproc_elf_load_rsc_table; rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; rproc->ops->sanity_check = rproc_elf_sanity_check; diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 2104ca449178..b898494600cf 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -167,8 +167,8 @@ u64 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw) static inline int rproc_load_segments(struct rproc *rproc, const struct firmware *fw) { - if (rproc->ops->load) - return rproc->ops->load(rproc, fw); + if (rproc->ops->load_segments) + return rproc->ops->load_segments(rproc, fw); return -EINVAL; } diff --git a/drivers/remoteproc/st_remoteproc.c b/drivers/remoteproc/st_remoteproc.c index 1340be9d0110..8d6b75e91531 100644 --- a/drivers/remoteproc/st_remoteproc.c +++ b/drivers/remoteproc/st_remoteproc.c @@ -233,7 +233,7 @@ static const struct rproc_ops st_rproc_ops = { .start = st_rproc_start, .stop = st_rproc_stop, .parse_fw = st_rproc_parse_fw, - .load = rproc_elf_load_segments, + .load_segments = rproc_elf_load_segments, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, .sanity_check = rproc_elf_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, diff --git a/drivers/remoteproc/st_slim_rproc.c b/drivers/remoteproc/st_slim_rproc.c index 5412beb0a692..0f91d8f1e7c7 100644 --- a/drivers/remoteproc/st_slim_rproc.c +++ b/drivers/remoteproc/st_slim_rproc.c @@ -201,7 +201,7 @@ static const struct rproc_ops slim_rproc_ops = { .stop = slim_rproc_stop, .da_to_va = slim_rproc_da_to_va, .get_boot_addr = rproc_elf_get_boot_addr, - .load = rproc_elf_load_segments, + .load_segments = rproc_elf_load_segments, .sanity_check = rproc_elf_sanity_check, }; diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index 8c7f7950b80e..7e8ffd9fcc57 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -667,7 +667,7 @@ static const struct rproc_ops st_rproc_ops = { .attach = stm32_rproc_attach, .detach = stm32_rproc_detach, .kick = stm32_rproc_kick, - .load = rproc_elf_load_segments, + .load_segments = rproc_elf_load_segments, .parse_fw = stm32_rproc_parse_fw, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, .get_loaded_rsc_table = stm32_rproc_get_loaded_rsc_table, diff --git a/drivers/remoteproc/xlnx_r5_remoteproc.c b/drivers/remoteproc/xlnx_r5_remoteproc.c index 5aeedeaf3c41..59cfba0a02e7 100644 --- a/drivers/remoteproc/xlnx_r5_remoteproc.c +++ b/drivers/remoteproc/xlnx_r5_remoteproc.c @@ -864,7 +864,7 @@ static const struct rproc_ops zynqmp_r5_rproc_ops = { .unprepare = zynqmp_r5_rproc_unprepare, .start = zynqmp_r5_rproc_start, .stop = zynqmp_r5_rproc_stop, - .load = rproc_elf_load_segments, + .load_segments = rproc_elf_load_segments, .parse_fw = zynqmp_r5_parse_fw, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, .sanity_check = rproc_elf_sanity_check, diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index ba6fd560f7ba..55c20424a99f 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -374,7 +374,7 @@ enum rsc_handling_status { * @find_loaded_rsc_table: find the loaded resource table from firmware image * @get_loaded_rsc_table: get resource table installed in memory * by external entity - * @load: load firmware to memory, where the remote processor + * @load_segments: load firmware ELF segment to memory, where the remote processor * expects to find it * @sanity_check: sanity check the fw image * @get_boot_addr: get boot address to entry point specified in firmware @@ -402,7 +402,7 @@ struct rproc_ops { struct rproc *rproc, const struct firmware *fw); struct resource_table *(*get_loaded_rsc_table)( struct rproc *rproc, size_t *size); - int (*load)(struct rproc *rproc, const struct firmware *fw); + int (*load_segments)(struct rproc *rproc, const struct firmware *fw); int (*sanity_check)(struct rproc *rproc, const struct firmware *fw); u64 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw); unsigned long (*panic)(struct rproc *rproc); From patchwork Tue Nov 26 09:10:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 13885610 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 4317C18F2DA; Tue, 26 Nov 2024 09:13:28 +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=1732612411; cv=none; b=K2m/jmrPyJ15xgUCOFh1FUXv5WA5tpD8ZOn+APqS2cSQFP/0gosjMh5hU5XNiA93NBs0kPXdPu5eGbN2v2xukQ7jBZyeb6nxXVcbkw3R0qpwTp1Mf7QefR/5qpNTY32boNX8oU0Yo46FSLk7KfwU17fPVR4yhnOpAX6uBkDUubY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732612411; c=relaxed/simple; bh=FrzZIV835rOf7d/aGlsTApiEMmkQ+58nU9b2ePF/+e0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CXlis5H0R+TFbFcrpwVMBS2l3iZMA1BINvL4IVqUonrVbJmKiCZ7E7mKC2R0Ee6geVjz/ZkdWcXqK88yMsZllxGtw5K0QhXIKZlOT4gF1UltBjmnoJI7sxsW/Zx5Qr7pmLE/oXx+hyzxxF4r+9xe5wUK7Gph41NyKCDTeX1ahU8= 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=16A6Kuc8; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="16A6Kuc8" Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AQ7BODx024315; Tue, 26 Nov 2024 10:13:22 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= ReO5YJNo2D7IrdzpVxvNHAheuWRLAx01DYACbeobRrs=; b=16A6Kuc8Ntpo6Rgk 4YhhwPSWh4aJ/ZYUYaJgZJDMGMr9EQHICTo4NuSCnIhOlPFbcxf34KiTccgW+ZT4 cC35xtMtpn1yZeGm9wrU0zGRJetmYOXsgspGMgONP+ctmRYfzHoOu2l0ZQJkVYqX OIfUCHG03U6UJEnqunLhNU4m4q+zkKf0nIr9uWsDRMPFSWhFal1mwpYDT+EYogUd oW9QqmqbJIZt21Izr6yjHX9mWJbv+Duk4gtRQs0rX4Koim7Zb71ApJFtb0/4FyWe S/cU4OdDlzimp743qq0PIyPsV1DndaGDGB04PzblQmOzSqGJCJIXj9G7bFqY+9Y8 ZALGZg== 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 4336tfksts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Nov 2024 10:13: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 8CC7440072; Tue, 26 Nov 2024 10:12:21 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node5.st.com [10.75.129.134]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 5DB8926B64F; Tue, 26 Nov 2024 10:11:15 +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.37; Tue, 26 Nov 2024 10:11:15 +0100 Received: from localhost (10.48.86.121) 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.37; Tue, 26 Nov 2024 10:11:14 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: Arnaud Pouliquen , , Subject: [PATCH v14 5/8] remoteproc: Make load_segments and load_fw ops exclusive and optional Date: Tue, 26 Nov 2024 10:10:36 +0100 Message-ID: <20241126091042.918144-6-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> References: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE1.st.com (10.75.90.11) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 The two methods to load the firmware to memory should be exclusive. - make load_segments optional returning 0 if not set in rproc_load_segments(), - ensure that load_segments() and load_fw() are not both set, - do not set default rproc::ops fields if load_fw() is set. Signed-off-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 4 ++++ drivers/remoteproc/remoteproc_internal.h | 2 +- include/linux/remoteproc.h | 7 +++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index e4ad024efcda..deadec0f3474 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2477,6 +2477,10 @@ static int rproc_alloc_firmware(struct rproc *rproc, static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops) { + /* A processor with a load_segments() and a load_fw() functions makes no sense. */ + if (ops->load_segments && ops->load_fw) + return -EINVAL; + rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); if (!rproc->ops) return -ENOMEM; diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index b898494600cf..3a4161eaf291 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -170,7 +170,7 @@ int rproc_load_segments(struct rproc *rproc, const struct firmware *fw) if (rproc->ops->load_segments) return rproc->ops->load_segments(rproc, fw); - return -EINVAL; + return 0; } static inline int rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 55c20424a99f..4f4c65ce74af 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -374,8 +374,9 @@ enum rsc_handling_status { * @find_loaded_rsc_table: find the loaded resource table from firmware image * @get_loaded_rsc_table: get resource table installed in memory * by external entity - * @load_segments: load firmware ELF segment to memory, where the remote processor - * expects to find it + * @load_segments: optional load firmware ELF segments to memory, where the remote processor + * expects to find it. + * This operation is exclusive with the load_fw() * @sanity_check: sanity check the fw image * @get_boot_addr: get boot address to entry point specified in firmware * @panic: optional callback to react to system panic, core will delay @@ -383,8 +384,10 @@ enum rsc_handling_status { * @coredump: collect firmware dump after the subsystem is shutdown * @load_fw: optional function to load non-ELF firmware image to memory, where the remote * processor expects to find it. + * This operation is exclusive with the load_segments() * @release_fw: optional function to release the firmware image from memories. * This function is called after stopping the remote processor or in case of error + * */ struct rproc_ops { int (*prepare)(struct rproc *rproc); From patchwork Tue Nov 26 09:10:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 13885616 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 6AB3D1B6CFB; Tue, 26 Nov 2024 09:14:00 +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=1732612442; cv=none; b=qXHiSOYumseMg9pKgJFa71GI7NcCMHyC00har/p4GEODEDsLzid2uMWBntIkr6G19PoriWTQZvtclAz0lyr4qHi6d/Rmf7Pl2MrDXOpMoQT3emtkubztfMO1X/hUHYejSVDO9j9Ol+/q313P1x6vyGqC1KnswtsclZpb+qw6AdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732612442; c=relaxed/simple; bh=RKYsAEvQRXWIAuP82l+zFeTBW2y8hvA6zPeWxu5FfUQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ue+rHFegTyVx4jCv6S6zFU6S0S8+6XeuaFyQhkW+whxz6NuvDH/yKsRZ1egoDevPkyHYqdyTiJSF3SSLPynuao39vrpX2k/O7lQmdkaqdg77Qyey1MRnmweEmXY8nrdvWf3beOkYYdqA8UEK4ANJhEVnjZ8dlMi7eLpzSSchqtI= 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=euXoHiUl; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="euXoHiUl" Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AQ7VsmW014099; Tue, 26 Nov 2024 10:13:50 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= gaYYKQhdt5+WppBYnImCivL9U494+2hjcdM9oi2RwHw=; b=euXoHiUlLOezMdTv oPPz+INVtc7NkWE7kkRoWJ6mR8GeDQIz9Gpb5DiDmblrJynQ1lBWCBl05AWnz0DU LRUAeFug13fkbT87TXyhVGVb0z9SEIYF/aG0DyhKyEEnD39FE7X8DJYxfqLoAHHo mzoqHUazvOszd6YdJnsgqUIDYjHlYlVripR236atcK+cMZ4x4wg+EL6KU6b2V+uv XQ/BfGtp+A9LeO50vBf9MsWZBJn/taKWoyPdEA42nXidPxbj1PIRH3FvVqcPl+ja nW5NPCU01FNJ4ahzAK8G7NBB10kGIM5IyzAN3DMOjJj8aasSx1s/hut0mV7xGfvd 8O1Rpw== 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 433791uya7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Nov 2024 10:13:49 +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 99BC140051; Tue, 26 Nov 2024 10:12:49 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node4.st.com [10.75.129.133]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 81DF026B651; Tue, 26 Nov 2024 10:11:16 +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.37; Tue, 26 Nov 2024 10:11:16 +0100 Received: from localhost (10.48.86.121) 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.37; Tue, 26 Nov 2024 10:11:16 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Rob Herring , "Krzysztof Kozlowski" , Conor Dooley , "Maxime Coquelin" , Alexandre Torgue , Fabien Dessenne , Arnaud Pouliquen CC: , , , , Subject: [PATCH v14 6/8] dt-bindings: remoteproc: Add compatibility for TEE support Date: Tue, 26 Nov 2024 10:10:37 +0100 Message-ID: <20241126091042.918144-7-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> References: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE1.st.com (10.75.90.11) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 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 trees: - In OP-TEE, a node is defined in the device tree with the "st,stm32mp1-m4-tee" compatible to support signed remoteproc firmware. Based on DT properties, the OP-TEE remoteproc framework is initiated to expose a trusted application service to authenticate and load the remote processor firmware provided by the Linux remoteproc framework, as well as to start and stop the remote processor. - In Linux, when the compatibility is set, the Cortex-M resets should not be declared in the device tree. In such a configuration, the reset is managed by the OP-TEE remoteproc driver and is no longer accessible from the Linux kernel. Associated with this new compatible, add the "st,proc-id" property to identify the remote processor. This ID is used to define a unique ID, common between Linux, U-Boot, and OP-TEE, to identify a coprocessor. This ID will be used in requests to the OP-TEE remoteproc Trusted Application to specify the remote processor. Signed-off-by: Arnaud Pouliquen Reviewed-by: Rob Herring (Arm) --- .../bindings/remoteproc/st,stm32-rproc.yaml | 58 ++++++++++++++++--- 1 file changed, 50 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..409123cd4667 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: @@ -43,6 +48,10 @@ properties: - description: The offset of the hold boot setting register - description: The field mask of the hold boot + st,proc-id: + description: remote processor identifier + $ref: /schemas/types.yaml#/definitions/uint32 + st,syscfg-tz: deprecated: true description: @@ -142,21 +151,43 @@ 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 + required: + - st,proc-id additionalProperties: false @@ -188,5 +219,16 @@ 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,proc-id = <0>; + st,syscfg-rsc-tbl = <&tamp 0x144 0xFFFFFFFF>; + st,syscfg-m4-state = <&tamp 0x148 0xFFFFFFFF>; + }; ... From patchwork Tue Nov 26 09:10:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 13885614 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 2A3D11B6CF0; Tue, 26 Nov 2024 09:13:46 +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=1732612428; cv=none; b=FC0/dVDS9tf+RlTl37ebQ7J6S/ZZ0m86raCYZMMiXMzDiY7zwGxAX3NKVumT6pVviCnsJ5uV+PUjycgk4s1PK7HLrT+GVgHxnXKN+viT/GlN534114mW5349CyM5OWUineE+hNfGP5JPzzwk+TqExme5i92GiA74AXD767f5l68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732612428; c=relaxed/simple; bh=PGMZdK5awwVDRLUhZUEkP/i8jR95TALsyjUYmkCVA9o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K8CN0OYc8MPLwbURvrtQa0OrOYYjaSvPy3HvnJfUxow59yMuH9v9GZ0xaNKZM6q7cLi1MwCnufqMm0+JdyTdSxQX11yYs4aMqQ2ukS4W+87Lu2rl1IQmAFrcoj/Jnxq53UwBTTxuMfjcKtnFkLzrFO494BsNQN7r6yvSN2T4fnA= 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=Pn26EfkB; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="Pn26EfkB" Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AQ3Lbj1030017; Tue, 26 Nov 2024 10:13:27 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= fhFYWPWRu1fKy+2nIifEQQLFbsyaAYIzY0cZaLes9RI=; b=Pn26EfkBMS8iV4gv LPqmYHWjofpk1Hs8vf+Iyg/e3Wj8TztL0PviT7QyxCO3RX3IKu5DBsH/XF1I5lrT GKqkUhOaOl8/6POLubt+93jyRiLCt3i3hV7unHyEwA1qDFQQmhKyCo3A528k76wf +HZUNTGdflqZrg92Ad7/s6FWMXoGXmExRh3nQMR2640v03hB3u6hobQKrFIMW9sA TLk1YRCHm164xw1pOjPnui3nwMaNmRR+eSFLoKjeV19oKZllLCJ9SEIAK6q9erWL nt82jESecY/3iw9lLjb6TuoAENZB+Lb7Zg2qkGfsju3HlVQ4DVPm5MaL/cPgCAvG KqL3iQ== 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 433529425r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Nov 2024 10:13:26 +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 9B58840075; Tue, 26 Nov 2024 10:12:33 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node6.st.com [10.75.129.135]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 9729926B654; Tue, 26 Nov 2024 10:11:17 +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.37; Tue, 26 Nov 2024 10:11:17 +0100 Received: from localhost (10.48.86.121) 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.37; Tue, 26 Nov 2024 10:11:17 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Maxime Coquelin , Alexandre Torgue CC: Arnaud Pouliquen , , , , Subject: [PATCH v14 7/8] remoteproc: stm32: Create sub-functions to request shutdown and release Date: Tue, 26 Nov 2024 10:10:38 +0100 Message-ID: <20241126091042.918144-8-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> References: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE1.st.com (10.75.90.11) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 To prepare for the support of TEE remoteproc, create sub-functions that can be used in both cases, with and without remoteproc TEE support. Signed-off-by: Arnaud Pouliquen --- drivers/remoteproc/stm32_rproc.c | 82 +++++++++++++++++++------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index 7e8ffd9fcc57..1586978c5757 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -209,6 +209,52 @@ 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, 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) { + err = mbox_send_message(ddata->mb[idx].chan, "detach"); + 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 0; +} + static int stm32_rproc_prepare(struct rproc *rproc) { struct device *dev = rproc->dev.parent; @@ -519,17 +565,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 +579,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 Tue Nov 26 09:10:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 13885615 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 2A43A1B6CFB; Tue, 26 Nov 2024 09:13:46 +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=1732612429; cv=none; b=spYM7j+f4J0rOBnEQlksrW2HisCAC78Ox0IMLcB5CzQoJ9cO6fpO73LYe24thLNkvVBcKuMkSI02y6i3PXV6gn6Nar03kJBUalaW61QLDgfOZiAcSj8OY4vjukrTSgj3rq9AHaHlFNv1DAQCQQZd3BJN723Y9VwiwKOr2Jxol9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732612429; c=relaxed/simple; bh=kj1hfdWSVjSnNWbE7Aa7J7Ymzw8bom7kkF0XyMlA3cc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jFLgRf/lH1NdYJ8X3SnGgclqFEWw48oxhU7E8npWPGTFVQOl4ewPDXD7EXcpM3aR++IULX/XOK5Sv9fGESIm5V8ZyzMyWwRVQg45fHar4OOxWR1PwkSH/z0VDMP2zQVIc9QFcol/40ZVm9VfSg2YhejioEYGFsTSW3gq66VrcZM= 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=CemEy3rc; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="CemEy3rc" Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AQ1uJmR007632; Tue, 26 Nov 2024 10:13:33 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= XDQDGSReDFtTs5dS4somR8H6zR6+6yKYIEpiiGNll7s=; b=CemEy3rc4ZCSTFtS aVEntbGWR11tyZfaxTatyNca1FzRUFmJRnj/VEuZ7XqP4C3CDNifk3epHrMehnFj W0QjOSCVBFUFDrj91gjn9VmEdB9rxV/X6UWgZmj2lwyjdaz321cHS4RYbEhZWhW8 fRSbP9Fw149LdBrkx/Yw7tEslE0AVN9KHVmQpBlQQOCb1Qv6PrApkKE+ci+2Q31P GKAGlyH4b68EAxpFoCU8i17gsvhFGL4PxV5PX5WHHpdZzdZ8Jw5IgcL7jQVV8mYC 7K4ovgPdY/PuhtLpyCQhLbV8TMjtRrsYT0Dvnl9DQWh206FSbF67Vs7HmhiwNy5z ZYbqrw== 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 4336tfksud-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Nov 2024 10:13:32 +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 1010340078; Tue, 26 Nov 2024 10:12:34 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node5.st.com [10.75.129.134]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id AF31A26B65D; Tue, 26 Nov 2024 10:11:18 +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.37; Tue, 26 Nov 2024 10:11:18 +0100 Received: from localhost (10.48.86.121) 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.37; Tue, 26 Nov 2024 10:11:18 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Maxime Coquelin , Alexandre Torgue CC: Arnaud Pouliquen , , , , Subject: [PATCH v14 8/8] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware Date: Tue, 26 Nov 2024 10:10:39 +0100 Message-ID: <20241126091042.918144-9-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> References: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SAFCAS1NODE1.st.com (10.75.90.11) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 The new TEE remoteproc driver 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. Signed-off-by: Arnaud Pouliquen --- updates vs previous version - register load_fw() ops instead of load() to call rproc_tee_load_fw() --- drivers/remoteproc/stm32_rproc.c | 57 ++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index 1586978c5757..c155822324d8 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -255,6 +256,19 @@ static int stm32_rproc_release(struct rproc *rproc) return 0; } +static int stm32_rproc_tee_stop(struct rproc *rproc) +{ + int err; + + stm32_rproc_request_shutdown(rproc); + + err = rproc_tee_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; @@ -691,8 +705,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 = rproc_tee_start, + .stop = stm32_rproc_tee_stop, + .kick = stm32_rproc_kick, + .load_fw = rproc_tee_load_fw, + .parse_fw = rproc_tee_parse_fw, + .find_loaded_rsc_table = rproc_tee_find_loaded_rsc_table, + .release_fw = rproc_tee_release_fw, +}; + static const struct of_device_id stm32_rproc_match[] = { { .compatible = "st,stm32mp1-m4" }, + { .compatible = "st,stm32mp1-m4-tee" }, {}, }; MODULE_DEVICE_TABLE(of, stm32_rproc_match); @@ -853,15 +879,36 @@ static int stm32_rproc_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; struct rproc *rproc; unsigned int state; + u32 proc_id; int ret; ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); if (ret) return ret; - rproc = devm_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. + */ + ret = of_property_read_u32(np, "st,proc-id", &proc_id); + if (ret) { + dev_err(dev, "failed to read st,rproc-id property\n"); + return ret; + } + + rproc = devm_rproc_alloc(dev, np->name, &st_rproc_tee_ops, NULL, sizeof(*ddata)); + if (!rproc) + return -ENOMEM; + + ret = rproc_tee_register(dev, rproc, proc_id); + if (ret) + return dev_err_probe(dev, ret, "signed firmware not supported by TEE\n"); + } else { + rproc = devm_rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata)); + if (!rproc) + return -ENOMEM; + } ddata = rproc->priv; @@ -913,6 +960,8 @@ static int stm32_rproc_probe(struct platform_device *pdev) dev_pm_clear_wake_irq(dev); device_init_wakeup(dev, false); } + rproc_tee_unregister(rproc); + return ret; } @@ -933,6 +982,8 @@ static void stm32_rproc_remove(struct platform_device *pdev) dev_pm_clear_wake_irq(dev); device_init_wakeup(dev, false); } + + rproc_tee_unregister(rproc); } static int stm32_rproc_suspend(struct device *dev)