Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp600994lqc; Fri, 8 Mar 2024 06:49:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVXT8BTJ7TLYDj44tawXxc82FfoHoSQ6x/IJntqXjxTqC/DdxEWxe8s8mpGMiS0bcHz1aHABCvvG0lPNkmf530RJRhM3mG8rlnFYOSrGQ== X-Google-Smtp-Source: AGHT+IFB7eVftgKx7FhMcf0TKSLWiIyS8RvE70w1kFDT8rBvO9H2V1K0tTz204j2dJU3gtnPO9AJ X-Received: by 2002:a17:902:e741:b0:1dc:8fb0:2b9e with SMTP id p1-20020a170902e74100b001dc8fb02b9emr13425708plf.34.1709909358597; Fri, 08 Mar 2024 06:49:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709909358; cv=pass; d=google.com; s=arc-20160816; b=XTUrsmOd/MG8jWZqQg09QLoZqSp8GUgJgUp/7qZCzQeV/pRG0mwZbCEQjny851pYEG uza29ZCcSrFRqYvqry7nGCDgQKp98OBMwRr1Zh1P9R6wBH6Uvm5JHvRq0KIS1TvUzl8I 68hCWA7vAC4l/1C3L07EfCMeGHh62ov1wmv4rFpL5O78r1HXzFop2/4WnUIqBjqfWf9+ /yovZ2necHUR/3FYRpgRJ9q4PRj9+KMg7da2zPAn6UJ0VeXy8d/DMhDbsKYTfF2hKnZ8 gHn1FMGUKLr9/l+rjffRAI6q0X5/O4dljxLBKCxH65MRq7NWGCGSUyJJXXeZ/2DvBRmd WkYA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=RDFPISqjc9QAfkglJPaLfedMejmrKWOJkyd3LQ7Wf6s=; fh=hTJigRCoV4/ES7XxqKE71DbJJyraFtTSDFtlGOKfKPo=; b=j72vVM0Qy3CPkR1xhnBzo3jLphQ57Hh1yhVlMQejNGh12xAKFs1j9KR0kHNlut1AWi bN37SK59zaT71/dN9BswsOd82YcN3mXVsUdnI8vnhsvG5UhS5Pqxh0Zez7gNhCjCCATZ dDQ4ZPZgqaSxdmHOh3b8WuLJVx+RQCVJTac3+zS1H7M6LrdrEsW+aLBYTZtW+l/bL1r1 5OiqAZNiI8ObKNgiuDpx6m5zOxKjvpYxUmESHdHN2rE3/8Ksa3t5WOSzvnQ8yKm9zXdS EFY1pMK07S/fPrsc7lVtOl9n5K5N//nnfJ6vsDDLAhe7OZJWjPJHmBC+YXjcQCAhQENk NNHQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=Fxq0W8Jg; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-97186-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97186-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h8-20020a170902f54800b001dd6e45e83csi720448plf.611.2024.03.08.06.49.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 06:49:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97186-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=Fxq0W8Jg; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-97186-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97186-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 43C6B281DE5 for ; Fri, 8 Mar 2024 14:49:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9ADEF208B6; Fri, 8 Mar 2024 14:48:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="Fxq0W8Jg" 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 BC7BA5234; Fri, 8 Mar 2024 14:48:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709909321; cv=none; b=uqAqQGkD2fURlFjmMsGzKtSH7lQuyspBL76tlKLzPOkA0f2fKm4KfczVVIImrN/LfmbLlsVrUGt+7M1c/hQ6hl1jGpsIsSQOkrpK1qNWa5rEmcSlTqy02ZUxQW5dBdlqOOtPb1TJi4XhNARJsLR6La5N03ju7tQNeYTjvfHmal4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709909321; c=relaxed/simple; bh=f/jLm/NN0YPf6tPz5yT03XkZekGc+yhL2skRFC84968=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fR0S0aUGaaajQV8JkI6ZEjbGMMdrI+iMbKng4rl0ksnuRQ2RfzWTZ45chbCWnrgr9WEzHsndetkZYxL9Pt2e4UMh9m5psTCP3qjthcEDdQLpSRCa8g3ogOC+YyeWFirs1zgulUNWGpBeVow4hHUtmsOpyAwHUZUXrUcQ8uorWxM= 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=Fxq0W8Jg; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 428Do4Ui023313; Fri, 8 Mar 2024 15:48:13 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= selector1; bh=RDFPISqjc9QAfkglJPaLfedMejmrKWOJkyd3LQ7Wf6s=; b=Fx q0W8Jgnkehi5mVSWmeAWHDWaWhhLfn+j0/Yp6lRm448Mchw6vgWTM0TWRVdSFHtP rtEKm/3qcoUrxMQYQ/GH4+TB4Erh5REh20KwcPecOvkvVFFJTELslCQcgfZ5Eboy 6AuTr+RYqzgFYYMcLloui3E2GpvAqXVfClrhiYurwmfoEoUv5kmcLU0TJuQcDCFe bLpwddAKHClJt825yeMq2RDIaOadP31jQmiHg4QiUkltOPlhRiYSLOrNGRh7BraR x45VsNHIAy4U4pW2AKS65BSVgm4ZqiQN8fc+LNLKYgDxc5lEfjwB7MTv45srGLDF 8yMzf4VOjaNdgjBnCVRw== 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 3wkuvj56up-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 Mar 2024 15:48:13 +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 0489440047; Fri, 8 Mar 2024 15:48:10 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node4.st.com [10.75.129.133]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 2E09027D53C; Fri, 8 Mar 2024 15:47:20 +0100 (CET) Received: from SAFDAG1NODE1.st.com (10.75.90.17) by EQNDAG1NODE4.st.com (10.75.129.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 8 Mar 2024 15:47:20 +0100 Received: from localhost (10.201.21.20) by SAFDAG1NODE1.st.com (10.75.90.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 8 Mar 2024 15:47:19 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier , Jens Wiklander , "Rob Herring" , Krzysztof Kozlowski , Conor Dooley CC: , , , , , , Arnaud Pouliquen Subject: [PATCH v4 4/4] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware Date: Fri, 8 Mar 2024 15:47:08 +0100 Message-ID: <20240308144708.62362-5-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240308144708.62362-1-arnaud.pouliquen@foss.st.com> References: <20240308144708.62362-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: 8bit Content-Type: text/plain 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.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-08_08,2024-03-06_01,2023-05-22_02 The new TEE remoteproc device is used to manage remote firmware in a secure, trusted context. The 'st,stm32mp1-m4-tee' compatibility is introduced to delegate the loading of the firmware to the trusted execution context. In such cases, the firmware should be signed and adhere to the image format defined by the TEE. Signed-off-by: Arnaud Pouliquen --- Updates from V3: - remove support of the attach use case. Will be addressed in a separate thread, - add st_rproc_tee_ops::parse_fw ops, - inverse call of devm_rproc_alloc()and tee_rproc_register() to manage cross reference between the rproc struct and the tee_rproc struct in tee_rproc.c. --- drivers/remoteproc/stm32_rproc.c | 60 +++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index 8cd838df4e92..13df33c78aa2 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "remoteproc_internal.h" @@ -49,6 +50,9 @@ #define M4_STATE_STANDBY 4 #define M4_STATE_CRASH 5 +/* Remote processor unique identifier aligned with the Trusted Execution Environment definitions */ +#define STM32_MP1_M4_PROC_ID 0 + struct stm32_syscon { struct regmap *map; u32 reg; @@ -257,6 +261,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 = tee_rproc_stop(rproc); + if (err) + return err; + + return stm32_rproc_release(rproc); +} + static int stm32_rproc_prepare(struct rproc *rproc) { struct device *dev = rproc->dev.parent; @@ -693,8 +710,19 @@ static const struct rproc_ops st_rproc_ops = { .get_boot_addr = rproc_elf_get_boot_addr, }; +static const struct rproc_ops st_rproc_tee_ops = { + .prepare = stm32_rproc_prepare, + .start = tee_rproc_start, + .stop = stm32_rproc_tee_stop, + .kick = stm32_rproc_kick, + .load = tee_rproc_load_fw, + .parse_fw = tee_rproc_parse_fw, + .find_loaded_rsc_table = tee_rproc_find_loaded_rsc_table, +}; + static const struct of_device_id stm32_rproc_match[] = { - { .compatible = "st,stm32mp1-m4" }, + {.compatible = "st,stm32mp1-m4",}, + {.compatible = "st,stm32mp1-m4-tee",}, {}, }; MODULE_DEVICE_TABLE(of, stm32_rproc_match); @@ -853,6 +881,7 @@ static int stm32_rproc_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct stm32_rproc *ddata; struct device_node *np = dev->of_node; + struct tee_rproc *trproc = NULL; struct rproc *rproc; unsigned int state; int ret; @@ -861,9 +890,26 @@ static int stm32_rproc_probe(struct platform_device *pdev) 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. + */ + rproc = devm_rproc_alloc(dev, np->name, &st_rproc_tee_ops, NULL, sizeof(*ddata)); + if (!rproc) + return -ENOMEM; + + trproc = tee_rproc_register(dev, rproc, STM32_MP1_M4_PROC_ID); + if (IS_ERR(trproc)) { + dev_err_probe(dev, PTR_ERR(trproc), + "signed firmware not supported by TEE\n"); + return PTR_ERR(trproc); + } + } else { + rproc = devm_rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata)); + if (!rproc) + return -ENOMEM; + } ddata = rproc->priv; @@ -915,6 +961,9 @@ static int stm32_rproc_probe(struct platform_device *pdev) dev_pm_clear_wake_irq(dev); device_init_wakeup(dev, false); } + if (trproc) + tee_rproc_unregister(trproc); + return ret; } @@ -935,6 +984,9 @@ static void stm32_rproc_remove(struct platform_device *pdev) dev_pm_clear_wake_irq(dev); device_init_wakeup(dev, false); } + if (rproc->tee_interface) + tee_rproc_unregister(rproc->tee_interface); + } static int stm32_rproc_suspend(struct device *dev) -- 2.25.1