From patchwork Thu Aug 22 13:48:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13773461 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011040.outbound.protection.outlook.com [52.101.65.40]) (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 4C2AC1CBEA0; Thu, 22 Aug 2024 13:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724334026; cv=fail; b=FWJuB7ga36Z3ZWCQv62ghIaelL+pFIvb70Eug1hKftqXBC7beJu9Ve7jOoGMMjxJVcsIAuBayMkGualki9rUZRPjbU3Dgrq+gw8mwEmFk7GFjJHHIdK3YhnyvmJj9WeMMlpOgoapxWiQhyUGkEfNAT1rLpUvtArZwEUBJ8iEyYA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724334026; c=relaxed/simple; bh=w+TPPT45cb9WV15Y7zDr9x9H68pC59Lum7yjE4ZAfys=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=Wpe1dNTPsbQ5RmX4mjcFic1PSWUFLkNDKQQHdbBEiSunZA/CupIY2+FP71mDN9VNipu7KgRtxVrlAwiBo7H2tsUO1KwBwTfhDQCnUvPdJBLhp+fdplOfqzI4HNU9fyetdC0USeS2/lqXfqiVmK7fYXig6eRuqx5qlzFqu0LUUBM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=Frvwsf3h; arc=fail smtp.client-ip=52.101.65.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="Frvwsf3h" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Kjgj4ZWc4+Fou4zaoesShcwvFRIggk8T+TdM2UKayjhPxaAWIZD3uNtH8DNsL8g/7o6Ac1zOhPhrr+rKCQEWrUcDN6rSnlCc+E8q3IIeJbyUYusOc5MIgthCc7Perwhz2mnHUH9ulUxjBPjXv4AjfiRQOLmFIxr4DX9wN/ErxYKmg/5lhqCO0F05qIGbADSJxGjmOMrHKiD+YWfj2NKf0xk3msIxbFpckkfeXilaicpcQMsWzlqF9SroEUW5y+ePX7u0rMxd6hYOmBiAR0xJGYFDLLhM+ntCZBFLnWabSjV/4MsnGrz3lYrlBZzSJ3o34LSpjcuhQz6ewVQ8wWti7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=hwSo8qLVHExplBhnhsSjw7wuPhKRRWPn68FrIT4/cMc=; b=pM24E9TLx42FzQn2wHf+8E6u3laRmYDa+eiAseIBLv0PFbWtTusbIlpBtAnnfJEYcZbkoFTLvxjFQwl5MxkGVYaFg6tYyZZOsCP2eCNl/U3LNdt+D3r8U4Y+XyLrw5b/uOtaLhyLsFQnMglCf4Cwv5IbyHZtOHg4tqo/0Tjm3sKDyuCXN5BcphCV2JrwZkyB7Y0ocW8G1ktAmIV5T94UKPw7e/qgsJjp3e+jJ+tV4Fm1m4C2TljeTsqHV0/hoGcMq/vmdjfGJdh2IA5qy6oDFo4b8UyEq654IB5KzIFLe2LyYGTpHqs1HfKySpUxVsGCWzdB6wySiModUCyMfvfuOQ== 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=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hwSo8qLVHExplBhnhsSjw7wuPhKRRWPn68FrIT4/cMc=; b=Frvwsf3hWHuW3DR03uVdjTfWGi4eRoX2EwOYxHdraWP9gWgU1m7bCCIvIkhV7Am69JDd2VqOxUEgerUaVFlPKoNMplr8r0wDiZNU8DY3dxzj0UwstIq5qF+m2ooB/WFfiL7mTe/SAcAiGUiKQ6s7TcfpqmgvsDeBN8eS5z9MT4FtEa80ZP8Fkjkus4W3J22UIukq4VI79WxrjzTGWumehK71i0bJOJu33g8azKX2lMZpu9uKnxzC/64c3p/WqRDciEwEVOfajGUXvZ3LR6H3skkbd2NSYi4aCToC8WPLVC2564cQFwgZxMIDzmhJd/JuW49Su+sK3VhxXLXCvngE8Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) by AS8PR04MB8449.eurprd04.prod.outlook.com (2603:10a6:20b:407::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.19; Thu, 22 Aug 2024 13:40:20 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%6]) with mapi id 15.20.7897.014; Thu, 22 Aug 2024 13:40:20 +0000 From: "Peng Fan (OSS)" Date: Thu, 22 Aug 2024 21:48:50 +0800 Subject: [PATCH v3 2/2] remoteproc: imx_rproc: Add support for poweroff and reboot Message-Id: <20240822-imx_rproc-v3-2-6d943723945d@nxp.com> References: <20240822-imx_rproc-v3-0-6d943723945d@nxp.com> In-Reply-To: <20240822-imx_rproc-v3-0-6d943723945d@nxp.com> To: Bjorn Andersson , Mathieu Poirier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Daniel Baluta , Iuliana Prodan , Marek Vasut Cc: linux-remoteproc@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Peng Fan X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1724334552; l=4226; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=HUszYL2Nyr15Mk1+3EqrILWezvor7LPShO2UpXI1BSQ=; b=42FEQh9UatXbDWHWlKEI6BQYTDNobEe1Nu8cnk61kVo5ufkaadnEQDc7dyh1/6/IQFquLUxCk rNBc2gaKHjmCgLKq5tqssvdn9PcqYGM15+yHAjisyxTLfJYgk01Om5H X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR02CA0051.apcprd02.prod.outlook.com (2603:1096:4:54::15) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|AS8PR04MB8449:EE_ X-MS-Office365-Filtering-Correlation-Id: 0055b7c4-b99e-45a5-0234-08dcc2aff77e X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|52116014|7416014|1800799024|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?wx5Sdi172SubwtvCPaNedL5KmrtdeUe?= =?utf-8?q?6rJ8IGRfh3hjd54A811t50bs5LSiE/27v8fSq+NI6KljIkIcs6U+TElQbzkO83VnZ?= =?utf-8?q?/Bp/kNr+0iqTI2lqdgBRme3EMMjLI43Bit6Nf4hWXw63zUldkRlwHNiBR10Ai5fmB?= =?utf-8?q?IoaIHt5hrUApuC1xvBL0FOsXDsMXnjWbFnDFg8EVWcpjm0PlWGSdcaQ5LroIuHOzp?= =?utf-8?q?wC0lnr5S5rV7DzIojtOHL7mUmHaaf0B3zHUiMaxobVxqJ6mAl9waEikZ6a0q2r+Ky?= =?utf-8?q?0++2MZR8tWtYkyQY3qFXiGtii2tx6JDFSBnTpjA2+yqKqLQzhNlF/ZUi6p9JRsCX/?= =?utf-8?q?ei3gR3km8GUkDDDkd5OlEElbJaSZgOsrkLlIO7Omq7+lz47bPYu17NfuG2kg0MKMh?= =?utf-8?q?MVmCfYW8rxif3YYFL45kq4fBeaq3/WfukT173GvyPNLXUJTS8/CuwtKusu2hU1Jeg?= =?utf-8?q?QPaimfUfKe0nkz/5KrFImtX86wnAp32+y9JjeRRiBuXt0i19BZ6+DJLv4+MDK2Rfo?= =?utf-8?q?oZKpSIykifrhV4dBDJxd/c+s11iyLmqnfzks8rJq+C0lPAZa7P4m8LMkRKsGnLStk?= =?utf-8?q?M/8gNSRWooH7zNHU3//VM9oK4zBOZCKenml0bPR7elBJozJfYMM9x2j46UZq+HYJT?= =?utf-8?q?i7vGdE/pwK8z+J9Y5JBcRR65OJDul3gTOtD0CQXjwYkmcaNpsfPHMKO6k2jVVsxoo?= =?utf-8?q?RkY2x7ug3AFoWGCBvgQplNaWsT48wGcHaqXD9W+ctf5iX1KYD1hvRuFsiv7yTV5Zx?= =?utf-8?q?l8WbNXfNibVxPtXQgSQ6/pxx/qxDt8SuG9yzyz0+HVWfoXzI3qE++ssFwL140wT/h?= =?utf-8?q?zKFdr8RrplZk4fuerYIpARJFVk3b5kQ5V+IuwcXgLAFq/lmXvG5r1LdeJ8tTGLZB8?= =?utf-8?q?xnEDVu0N4utWJOwlhO8vzRCNoTYjKe1LrY3UbLgkfwG7FdI1mOeqp8wcK6JANrels?= =?utf-8?q?54xftxvsMgvJWYiiWCaIleM3OVLPljfJ+R6My6Jo6MqT/TlBPQ4wi94PPxaR7oU8w?= =?utf-8?q?qT5xkBWPvbOEyVRyu4vGkizuwRNSRE3xFdTzM6s47iR/avsE0/06FtsP/Uym2MGch?= =?utf-8?q?KfTZT0ICjTw3/a6t8p9vVoTuc8ahZZnoNc3lckk5QQrIVor2XiWYV3J/ZL7FJWW/+?= =?utf-8?q?dEU2WaLg5AvV8wiEPwUZLPUYAoD3l+sr48jPjraKcC2bI8yGIOUyhSbSuH8CHOv1D?= =?utf-8?q?AXzF9LX2v5APwDGPRqGbH0mBKRxef9uBamH9azdQFWofIAh8VW8g7SNGScujWETCM?= =?utf-8?q?+htXDFKPYVHoL281AjYj06kh6SSKkwfVfDqsdwqEj6qTVji2DK1Aa9ryp+OxxNVUV?= =?utf-8?q?cI61QWoahoGbRGsKPTKIFB2CqgeEx3aaHg=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8459.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(52116014)(7416014)(1800799024)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?RU5oqIapqcR4mfzd+nygE3rYoNUP?= =?utf-8?q?LSYtSP1SvqbY2unli5AxbsUawKSlohaXf6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h1keac2vK?= =?utf-8?q?fRsj1Waj2AydE99SyjIPwbN84Gs3Z2ITHuKHTOuVnhmnwSeQqQVUM8Vta2gjON/ot?= =?utf-8?q?uBK0x74F/9VZdi5THiRiS+lCSGZ8r4qa3L39EIUrDRIMyZ7VmE/gvsBSEYJyT7A1t?= =?utf-8?q?hxcfpg/94xnIl/uNsKt7NXtYzAf39j7+2IiJG0sreq8xwqI5rbLliGPGzDE89IVlo?= =?utf-8?q?2GrRqAuwKjWDivg7Psyxr/wA+9nUz2Sk4iPD51VonX4UTrxYcABrqvTR4M8dfJhWm?= =?utf-8?q?MHL1fwYrPn+TVwpqjybaVbX5cR1rvn6Ib81h6IMzJgrM8o51S1DLUld/5Kx3xmHcV?= =?utf-8?q?wSCyoworoc3rgR6JUW4dqcst2qVNP3wO9dzPOj3NEvnpBCLNzgf9Wa+mMgx8rW0Ug?= =?utf-8?q?t3ALB8SZPOOLwqHFO6AJ43E//95gnTLtenmclxNACT1sJdggnv3HxGcJZvjthcUxL?= =?utf-8?q?sE2XF0kwy253h2fjTdBsX0HHxHYMWr67H4k/tEz5RsqTi44ulK5/LAy26K7Cr/ayk?= =?utf-8?q?lwRDpO/AOKReLLAO/zFZTXfNohhx4LaoeTgH1rn1cZHZ8OwsOQx938vlfz7J3zHYG?= =?utf-8?q?jri3W/2uDcdt?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0055b7c4-b99e-45a5-0234-08dcc2aff77e X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2024 13:40:20.7994 (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: dg/dNBUANyDjlrLLlWuVz5DPYoIsusEF05VgZcXXdBDurLx5SZ+P3p/o1uHWKCQVfFQEKKgTag+qgjHNUyLyBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8449 From: Peng Fan On some NXP platforms (e.g i.MX7ULP) the poweroff and reboot operations are done via a separate remote core. Typically Linux needs to send a message to the remote core and requests for poweroff or reboot. By default the communication between Linux core and the remote core is is done via a blocking mailbox mechanism but Linux doesn't allow blocking operations in the system off (reboot, power off) handlers. So, we need to make sure the mailbox message send operations do not block for this specific operations. Fortunately, Linux allows us to register handlers that are called in preparation of the system off operations. Thus, before carrying the power off or reboot preparations, just destroy the existing mailboxes and create them as non-blocking. Note that power off and restart are totally different operations and are not complementary. We introduce a new flag in the imx remoteproc per device data which tells us when a device needs this special setup. For now, only imx7ulp needs it. Signed-off-by: Peng Fan Reviewed-by: Daniel Baluta --- drivers/remoteproc/imx_rproc.c | 42 ++++++++++++++++++++++++++++++++++++++++++ drivers/remoteproc/imx_rproc.h | 4 ++++ 2 files changed, 46 insertions(+) diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c index 22677f581067..800015ff7ff9 100644 --- a/drivers/remoteproc/imx_rproc.c +++ b/drivers/remoteproc/imx_rproc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -333,6 +334,7 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx7ulp = { .att = imx_rproc_att_imx7ulp, .att_size = ARRAY_SIZE(imx_rproc_att_imx7ulp), .method = IMX_RPROC_NONE, + .flags = IMX_RPROC_NEED_SYSTEM_OFF, }; static const struct imx_rproc_dcfg imx_rproc_cfg_imx7d = { @@ -1050,6 +1052,22 @@ static int imx_rproc_clk_enable(struct imx_rproc *priv) return 0; } +static int imx_rproc_sys_off_handler(struct sys_off_data *data) +{ + struct rproc *rproc = data->cb_data; + int ret; + + imx_rproc_free_mbox(rproc); + + ret = imx_rproc_xtr_mbox_init(rproc, false); + if (ret) { + dev_err(&rproc->dev, "Failed to request non-blocking mbox\n"); + return NOTIFY_BAD; + } + + return NOTIFY_DONE; +} + static int imx_rproc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1104,6 +1122,30 @@ static int imx_rproc_probe(struct platform_device *pdev) if (rproc->state != RPROC_DETACHED) rproc->auto_boot = of_property_read_bool(np, "fsl,auto-boot"); + if (dcfg->flags & IMX_RPROC_NEED_SYSTEM_OFF) { + /* + * setup mailbox to non-blocking mode in + * [SYS_OFF_MODE_POWER_OFF_PREPARE, SYS_OFF_MODE_RESTART_PREPARE] + * phase before invoking [SYS_OFF_MODE_POWER_OFF, SYS_OFF_MODE_RESTART] + * atomic chain, see kernel/reboot.c. + */ + ret = devm_register_sys_off_handler(dev, SYS_OFF_MODE_POWER_OFF_PREPARE, + SYS_OFF_PRIO_DEFAULT, + imx_rproc_sys_off_handler, rproc); + if (ret) { + dev_err(dev, "register power off handler failure\n"); + goto err_put_clk; + } + + ret = devm_register_sys_off_handler(dev, SYS_OFF_MODE_RESTART_PREPARE, + SYS_OFF_PRIO_DEFAULT, + imx_rproc_sys_off_handler, rproc); + if (ret) { + dev_err(dev, "register restart handler failure\n"); + goto err_put_clk; + } + } + ret = rproc_add(rproc); if (ret) { dev_err(dev, "rproc_add failed\n"); diff --git a/drivers/remoteproc/imx_rproc.h b/drivers/remoteproc/imx_rproc.h index 79a1b8956d14..17a7d051c531 100644 --- a/drivers/remoteproc/imx_rproc.h +++ b/drivers/remoteproc/imx_rproc.h @@ -26,6 +26,9 @@ enum imx_rproc_method { IMX_RPROC_SCU_API, }; +/* dcfg flags */ +#define IMX_RPROC_NEED_SYSTEM_OFF BIT(0) + struct imx_rproc_dcfg { u32 src_reg; u32 src_mask; @@ -36,6 +39,7 @@ struct imx_rproc_dcfg { const struct imx_rproc_att *att; size_t att_size; enum imx_rproc_method method; + u32 flags; }; #endif /* _IMX_RPROC_H */