From patchwork Tue May 17 06:49:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 12851952 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D65FBC433FE for ; Tue, 17 May 2022 06:48:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238671AbiEQGsg (ORCPT ); Tue, 17 May 2022 02:48:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240528AbiEQGsZ (ORCPT ); Tue, 17 May 2022 02:48:25 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70071.outbound.protection.outlook.com [40.107.7.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7164146B08; Mon, 16 May 2022 23:48:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gw4Onc0YGP0g2dAOIWEQjysuH+5k9ZKxpddmfOzdcDvMc21gp3drXTv1DgJZx1SQRNXsGLuC1ys1FPrVUPYOKJDRILSVqiB48sbDkVIbw7iSR7/i0HkCIJ3vwg6VqYBThXuDrWDd/We9m7zv+TDTMryuMbBtcLyz4/Qc2Ue3XOxKktVtqGn2bPllZVNTpHlFJnjOgeIf48ePWdQHORJ7F+zuoHHBoPA69nGbF0CsuSiDq6yps89DupQjVDnNxP6MmTyR2U8iYNZ2ZzO0uDZJEettiZbXD2gdcCeawrDM6RSfayLG5vGBPuQuFWzFqYbicGGbUGdOLRkCaYu7mDO3Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nVUlkDzaLXjx+FjJJi1SM8LUxfuSsRJdEY4yS/AYgI0=; b=CgqTQbUUmzRNdywtwKhZIx1zpZ9D5g3KuRcqld5X8iMK/AEqGWfvGoTOUbxoMRY8HBzDNJl3nSB8GMSI5GJnJCw7zbL3YUuJxDjpbkkU0r0npKuFD20/6Oh1xxhj41xA3yAIoYkprfM6lAQUZtGttKl54iG/jMxlKpqjh5sc9JKI3EuYOyoqIW6qy7HABqXPZ5W8a9QBQEAllSg2G+Ubk00qoers4uMZlryckU0jnqiGZTFZFkgArbL2TjYzB/4UtUyFbgVBS25Y8rCtvfsbO7u4zaop6UpEXvQFvkcUuZvT+kyNqra6GrKp8yZLQ1cNg3N56YfB7QBsiH74yg6Lng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nVUlkDzaLXjx+FjJJi1SM8LUxfuSsRJdEY4yS/AYgI0=; b=BhEEhKNyjlwkj6RqKbx7GprhoZRwyu9mcliBZsEunCSEmViDi7jLLQL0gxDW1egn0PaKlFpvdANs3X9S3F/qr0YtakjIlwR/W1gFYeV04Itwg8Ydb6VsXIAwO9F9GvlfuWfC3CavVF8l6JmUUFh3mxylXBb/5KsgsHZ8UAPF0LQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by HE1PR0402MB2697.eurprd04.prod.outlook.com (2603:10a6:3:e1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.18; Tue, 17 May 2022 06:48:18 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::a892:e4a9:4769:13a5]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::a892:e4a9:4769:13a5%7]) with mapi id 15.20.5250.014; Tue, 17 May 2022 06:48:17 +0000 From: "Peng Fan (OSS)" To: bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-remoteproc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: devicetree@vger.kernel.org, Peng Fan Subject: [PATCH V3 6/6] remoteproc: imx_rproc: request mbox channel later Date: Tue, 17 May 2022 14:49:37 +0800 Message-Id: <20220517064937.4033441-7-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220517064937.4033441-1-peng.fan@oss.nxp.com> References: <20220517064937.4033441-1-peng.fan@oss.nxp.com> X-ClientProxiedBy: SI2P153CA0005.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::11) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 52e33be8-a22d-4c2c-a198-08da37d1395e X-MS-TrafficTypeDiagnostic: HE1PR0402MB2697:EE_ X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uXC5nxrB3OG+OKjKj0t0uGFJoPKc2cZnpfJpbz7Dw3PiOH0/eCyOwsPH9zP6cBo1kR5PnOy2IZmlfBx1COtarOI058Wk2QEWkRvW0bPl/tERJcaN7Z7LzKATaAXGnlpQzLTnK2RMPqO/0wVby3xwdZN0mG8rMMVd+2nmtSaNysuj0zERDcXjDULQgns+UxvVwtVRploj8aV0zOblPtE3ZwgOSTVSzAuQSCr/CWGxFmW2WNeR99uHnAC3vTR5962LhzFlMDu02YwcDjOVf6wO5I8B4PoBuAb2VedimC08AU/KhBLJm5MqCUJEBX4xFjFeXdCFN0taZhR/TCFWJato83zgKaVxxtd8pzBfsMSVidy0YS8uAqeRnHDR7npFnC9nYFIchuoLucRovqQXvkKSC7XDHqHy57pNZjs0KLS6m2Wi5WGPV+7FlZN3CqVd67uEMipDDlWGZ3kFYC9OIQl4hfha0q8wa62W0ZG+Bq/mdFk62U0SkcgXixplqaNyZCKSnP/1kypSKPz+e+hk4o954Lx0WE4mV4C79oN73ffVnOQMDHeO9nLcAhh6deLSL2DUKDbdQCmqCF9eW5DWXJjLSkgcMReSwycX2dnQAUtDwae1dsq2TfT0yoYmbOQGC2SL9EJJyF28tURpVaEdGIlRPovbsO1Gs5HIsWMaHXiyH9tEvLWmulVsoxSgZb+idtzrL/0R/xedWh6EUNHA2vcDzCFR7WQb7h/4M4anMYwKrw4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0PR04MB9417.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(86362001)(6506007)(2906002)(6512007)(38100700002)(6666004)(38350700002)(52116002)(316002)(8676002)(4326008)(508600001)(6486002)(26005)(66946007)(921005)(66476007)(1076003)(83380400001)(66556008)(8936002)(2616005)(186003)(7416002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-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N5cDui0qDTQ74XhId+8/2DtXnYX1UF8/JNec1rt/s0GFTTry5cAvXqKIAVkCpTt5UNU8zuboZ2ioj40MEhlAUtMUnWEADNHJTZahKasuUC6N7T1Qc6EEcg5J5KIVP9XcuOmuKsOnzAXz7r6do1EdamAx8QFs8gvXQGKFpohcM6vesFuIT6iy9K/xiBbGCbNdOwlpq34FoxdnqscCcqGwNWqA9ZwhOZE/7OQIyUNbCi3oG7cQ/YHRGgKaIC/ZFBxrNhzDHJIzmhWOYFBD5BXedsAxPeQ9JsEu/6+LI8qQVh+uQYiQR2GmzzpntrNwLdk3GWT5AVYsoXTLFhNz3tyxq4WrsZdo+K5LFOC6ft7S7XZgqB56B0TnSl4AxbIOKRSJL2/3pQr0ZBFNCEok3td7+1KnlOSIdS9eLX741KUhcL7vY/xORYPcL1PC292TR7+nOIe3ZGGXazB4prCjL1Fkr1E1GLeeJkqrhyGokaB5f9cR7woO3Ke8w5+8PgKHDhMNDB7CgFsgbQ3VBWrfSZZRMV16rDdVgoKhFzwb80sovY4iqxk+Ji7G16ylLZWtfHZn/3/SypG0dQSBrX+y2kxuqRz5w6j52aps/K19+S7CbOWdBzXMTmZDaWedeRxQ4wS6yrl5XgdFEAdU+UQSUOI+urbEZAOsM+Lw== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 52e33be8-a22d-4c2c-a198-08da37d1395e X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2022 06:48:17.9354 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zSQDx+p+ZN5ONlpbciB4c79b09lw87CEWI+F2trwYaM/cpzU+94gzDT+CH/c/vOLV3zd/cokP1KqruI4mCp4QA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0402MB2697 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org From: Peng Fan It is possible that when remote processor crash, the communication channel will be broken with garbage value in mailbox, such as when Linux is issuing a message through mailbox, remote processor crashes, we need free & rebuild the mailbox channels to make sure no garbage value in mailbox channels. So move the request/free to start/stop for managing remote procesosr in Linux, move to attach/detach for remote processor is out of control of Linux. Previous, we just request mbox when attach for CM4 boot early before Linux, but if mbox defer probe, remoteproc core will do resource cleanup and corrupt resource table for later probe. So move request mbox ealier and still keep mbox request when attach for self recovery case, but keep a check when request/free mbox. Signed-off-by: Peng Fan --- drivers/remoteproc/imx_rproc.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c index 8326193c13d6..8fe139624ecc 100644 --- a/drivers/remoteproc/imx_rproc.c +++ b/drivers/remoteproc/imx_rproc.c @@ -84,6 +84,9 @@ struct imx_rproc_mem { #define ATT_CORE_MASK 0xffff #define ATT_CORE(I) BIT((I)) +static int imx_rproc_xtr_mbox_init(struct rproc *rproc); +static void imx_rproc_free_mbox(struct rproc *rproc); + struct imx_rproc { struct device *dev; struct regmap *regmap; @@ -355,6 +358,10 @@ static int imx_rproc_start(struct rproc *rproc) struct arm_smccc_res res; int ret; + ret = imx_rproc_xtr_mbox_init(rproc); + if (ret) + return ret; + switch (dcfg->method) { case IMX_RPROC_MMIO: ret = regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask, @@ -405,6 +412,8 @@ static int imx_rproc_stop(struct rproc *rproc) if (ret) dev_err(dev, "Failed to stop remote core\n"); + else + imx_rproc_free_mbox(rproc); return ret; } @@ -584,7 +593,7 @@ static void imx_rproc_kick(struct rproc *rproc, int vqid) static int imx_rproc_attach(struct rproc *rproc) { - return 0; + return imx_rproc_xtr_mbox_init(rproc); } static struct resource_table *imx_rproc_get_loaded_rsc_table(struct rproc *rproc, size_t *table_sz) @@ -712,6 +721,9 @@ static int imx_rproc_xtr_mbox_init(struct rproc *rproc) struct mbox_client *cl; int ret; + if (priv->tx_ch && priv->rx_ch) + return 0; + if (!of_get_property(dev->of_node, "mbox-names", NULL)) return 0; @@ -744,8 +756,15 @@ static void imx_rproc_free_mbox(struct rproc *rproc) { struct imx_rproc *priv = rproc->priv; - mbox_free_channel(priv->tx_ch); - mbox_free_channel(priv->rx_ch); + if (priv->tx_ch) { + mbox_free_channel(priv->tx_ch); + priv->tx_ch = NULL; + } + + if (priv->rx_ch) { + mbox_free_channel(priv->rx_ch); + priv->rx_ch = NULL; + } } static int imx_rproc_partition_notify(struct notifier_block *nb, @@ -757,6 +776,8 @@ static int imx_rproc_partition_notify(struct notifier_block *nb, if (!((event & BIT(priv->rproc_pt)) && (*(u8 *)group == IMX_SC_IRQ_GROUP_REBOOTED))) return 0; + imx_rproc_free_mbox(priv->rproc); + rproc_report_crash(priv->rproc, RPROC_WATCHDOG); pr_info("Partition%d reset!\n", priv->rproc_pt); @@ -1026,7 +1047,6 @@ static int imx_rproc_remove(struct platform_device *pdev) clk_disable_unprepare(priv->clk); rproc_del(rproc); - imx_rproc_free_mbox(rproc); destroy_workqueue(priv->workqueue); rproc_free(rproc);