From nobody Tue Dec 16 06:14:53 2025 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 593E41D5CC4; Tue, 3 Jun 2025 10:12:50 +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=1748945572; cv=none; b=SCQazOo+63J3zrKE5nBEG1hyDKRhcSsW1zIIFI3rvGLBFOv0rgZY36pR1tbgsQHlyPDwYamEzrgS7+93hXU9PE2cH20S/NSib38W9lyonoM0+0ziQyX8Y1zMlX92yFU2vGpehlwdKGV5uiiWGO4LToR1gDx7ZCIUDSgg8PQ0qlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748945572; c=relaxed/simple; bh=9ZNrdZU8zpE46LpjNcZYopIMzDw4z1oNfhDPV+7bOl8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sAs1Nuuqmo6QNB0vHKUhYQuHAnTdLL8xXPIpM9oW7coreHFjDz3J4mI1Pw397zspT6Dbqm+xuyDqIJqBa0MZQNN970BHpITJRlqUPMllvDN7HB3OfRLUhM3xjuRIKhW+zpZTXVtjekymufo+RuzIrQccxH+JhTHXkEvRE+TU+kY= 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=yht7N+TX; 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="yht7N+TX" Received: from pps.filterd (m0288072.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5539j9K4022373; Tue, 3 Jun 2025 12:12:36 +0200 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= TfuFzpVGN+MuYBbe8YZ88d8gChYgGppgvNnOd/zUZeE=; b=yht7N+TXEpLJUUTM f58xMiLWxZ9RoDhyd8as1q/Y5+aW6+VJgazOt5Y94ja0Ey0g7CI58Vgt9jUCjDgZ n2XyZHctqUQiycmOF1d8y+0QzIij7lDdUwN5i+Qo5iwMzzQnjiJvlvIRboKEs0PU nCD90z6GlbRFhMV21iOsKqBkgRvm70d7piEE4u/zj1E875lJjCIyDIayGYBxXFIc t84U8j07AFhO33vO07ErLboFSnYqI0c15GVpjO541DGLRn+SwVw+odthDQBHRnvV h8ib4FQ25FAljvAYSLsh1Dx6OpwJMdT6s/qorX4NFelLmRItVDoBFJW+xpmUebkJ jx+vJQ== 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 471g8tbd6e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Jun 2025 12:12:36 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id D31BC4005A; Tue, 3 Jun 2025 12:11:26 +0200 (CEST) Received: from Webmail-eu.st.com (eqndag1node4.st.com [10.75.129.133]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 7F566A8BCDE; Tue, 3 Jun 2025 12:10:12 +0200 (CEST) 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.39; Tue, 3 Jun 2025 12:10:12 +0200 Received: from localhost (10.252.31.160) 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.39; Tue, 3 Jun 2025 12:10:12 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Jens Wiklander , "Rob Herring" , Krzysztof Kozlowski , "Conor Dooley" CC: , , , , , , Arnaud Pouliquen Subject: [RESEND PATCH v16 3/6] remoteproc: Introduce release_fw optional operation Date: Tue, 3 Jun 2025 12:08:05 +0200 Message-ID: <20250603100808.1074812-4-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250603100808.1074812-1-arnaud.pouliquen@foss.st.com> References: <20250603100808.1074812-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 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: EQNCAS1NODE4.st.com (10.75.129.82) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-03_01,2025-06-02_01,2025-03-28_01 Content-Type: text/plain; charset="utf-8" The release_fw operation is the inverse operation of the load, responsible for releasing the remote processor resources configured from the loading of the remoteproc firmware (e.g., memories). The operation is called in the following cases: - An error occurs on boot of the remote processor. - An error occurs on recovery start of the remote processor. - After stopping the remote processor. This operation is needed for the remoteproc_tee implementation after stop and on error. Indeed, as the remoteproc image is loaded when we parse the resource table, there are many situations where something can go wrong before the start of the remote processor(resource handling, carveout allocation, ...). Signed-off-by: Arnaud Pouliquen --- Updates vs previous version: - remove the rproc:load_fw() ops introduced in previous version - remove duplicate call of rproc_release_fw in rproc_fw_boot and rproc_boot --- drivers/remoteproc/remoteproc_core.c | 6 ++++++ drivers/remoteproc/remoteproc_internal.h | 6 ++++++ include/linux/remoteproc.h | 3 +++ 3 files changed, 15 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remo= teproc_core.c index 79aded30fc87..7868984ba5b6 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1857,6 +1857,8 @@ static int rproc_boot_recovery(struct rproc *rproc) =20 /* boot the remote processor up again */ ret =3D rproc_start(rproc, firmware_p); + if (ret) + rproc_release_fw(rproc); =20 release_firmware(firmware_p); =20 @@ -1998,6 +2000,8 @@ int rproc_boot(struct rproc *rproc) } =20 ret =3D rproc_fw_boot(rproc, firmware_p); + if (ret) + rproc_release_fw(rproc); =20 release_firmware(firmware_p); } @@ -2067,6 +2071,8 @@ int rproc_shutdown(struct rproc *rproc) =20 rproc_disable_iommu(rproc); =20 + rproc_release_fw(rproc); + /* Free the copy of the resource table */ kfree(rproc->cached_table); rproc->cached_table =3D NULL; diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/= remoteproc_internal.h index 0cd09e67ac14..c7fb908f8652 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -221,4 +221,10 @@ bool rproc_u64_fit_in_size_t(u64 val) return (val <=3D (size_t) -1); } =20 +static inline void rproc_release_fw(struct rproc *rproc) +{ + if (rproc->ops->release_fw) + rproc->ops->release_fw(rproc); +} + #endif /* REMOTEPROC_INTERNAL_H */ diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 8fd0d7f63c8e..80128461972b 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -381,6 +381,8 @@ 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 + * @release_fw: optional function to release the loaded firmware, called a= fter + * stopping the remote processor or in case of error */ struct rproc_ops { int (*prepare)(struct rproc *rproc); @@ -403,6 +405,7 @@ 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); + void (*release_fw)(struct rproc *rproc); }; =20 /** --=20 2.25.1