From patchwork Tue Jan 21 15:08:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13946401 Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2085.outbound.protection.outlook.com [40.107.103.85]) (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 B87A51F3FD2 for ; Tue, 21 Jan 2025 15:09:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.103.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737472143; cv=fail; b=urpDkcVbH7J6gQg4TR2C5Y2F1QYibAmpKkRIQk9XVoaIn6scV8FVpKPvkZnMxD/dS6Za9ovptP3w2ZQBtOR+fcy8heYEbv7q5pw25xYQteO2Bp1ihk89DB3oRlTwPnaom74oNLeT8Dttv0TGUDJwG/+rV9FEmC5XSJUtu7rXGio= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737472143; c=relaxed/simple; bh=w4R9UMOdk5kPMASY79OCtlw8Xo3C5+4PM2wRK4t+hWM=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=CGRFO004TXBLNsvmrSm2+eoObibNj06ykXyCyUpAuqFgguueWrQqUfPHO/s9A7XTmqKb4KoS4GDMXgEfDtKeN1vT95WWC3QK5RarA0AsfwWH9cm9C92Crmx7aaJMkkwRO/GTvKatQ+vKwGj9flW3KoMV+qg5QzXLhB0Z5A2et30= 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=qf92HbgU; arc=fail smtp.client-ip=40.107.103.85 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="qf92HbgU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=evHDAmcq5YUdwM3t7Q0fYYv5CdD+s6gmbENqjiY/NDyDGNMLd4J85252g6Trxg5bQnw7z0QJ3M302wZaVjwuE72KAmcNIGPC52jMHyzPohR+KhucyGRGKGeUYVIerY7otf3Z2K5gVW4w0LOZxeyXM8+D+nVl6KVPvlk/3wCsRw/a25rcJ4wX6hZzrIUHy3D5JznFfLwmNQvIKUVetOWlhi+xG2KhhGQc4VQGzsSs5VO5OSRwu7HutFU7Z+l5kuqpYSnyxO9llZbJNlBkc5CZes8c8b5gHEluoSTJIpbf5gZlbd8azYBx38VGQ4ysyYevDO1UKJ6pzXuHxoDw94Fztw== 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=x0ARC/RmMaxo8ILmen/egoAknRkBKuQNt2UgoWny2e0=; b=GMM6ohMdhC+zdb2eUToJ8MRahWIdnEfihFoiROA7xQe35aoUzzfBDDKabjQX+A/Dh7J9uvLQWoOaDi6qauS49FtPvXwx3r274gd4dhxzJ0shNkDNj8eOJFJUlMtMXrahLBa6CXZlJsizVw75jza7c3NTGfGK2fYk2CkHvjp9JJftuapJEAUZSat1hmUHKpcZOmFIOfHwWnQgp4jeQCYcR1VcEeBiktYyByZK4lV7BO3YBiTD7hkbWsdym+lI3fHCgn8v1sSmQJmBVGgpDn1THHk9E6+QJhCXIFBK4+v4w4fRkYzKVQjhYc91hcxbcmI9FREbMlXO9TRp8zqktVFFEQ== 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=x0ARC/RmMaxo8ILmen/egoAknRkBKuQNt2UgoWny2e0=; b=qf92HbgUh6773EF6spW0hjhyD+aqNLKUxMa851r0jP3LvAnl4zvsJjiAwiuxomWSDgr+5Ft2OCkIU7IiP9bg9eZ3nQTAI/op5tnA4IC20F+40ouX8HxCvhiYL5yNH370hei2zhVxbnxvJzUVfgvJlCUk4xk6DXFOalBu30BAymEW2cVUpNHWNrhosemoHwtyusN4yjG2jExL/DuRmoItNt3koHeU2opU9Gexp4obtgkGgkZ7fxEuaIRcKH0vB+Zif1Vs3QsyF6hDh0slajvT9YTomlY7K6smSTt9YT3yqveN75wqJ36JGC6VwJDyuQOCC3P/aWC9XrMB9sPLZ7qfAA== 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 AM7PR04MB6853.eurprd04.prod.outlook.com (2603:10a6:20b:107::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.22; Tue, 21 Jan 2025 15:08:58 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%5]) with mapi id 15.20.8356.020; Tue, 21 Jan 2025 15:08:58 +0000 From: "Peng Fan (OSS)" Date: Tue, 21 Jan 2025 23:08:11 +0800 Subject: [PATCH 1/5] firmware: arm_scmi: imx: Add i.MX95 LMM protocol Message-Id: <20250121-imx-lmm-cpu-v1-1-0eab7e073e4e@nxp.com> References: <20250121-imx-lmm-cpu-v1-0-0eab7e073e4e@nxp.com> In-Reply-To: <20250121-imx-lmm-cpu-v1-0-0eab7e073e4e@nxp.com> To: Sudeep Holla , Cristian Marussi , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: linux-kernel@vger.kernel.org, arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, Peng Fan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1737472103; l=9570; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=3VXrTHu1D4IdJfg6JFOee0D8LNmoa9UQv759Ph+nEo0=; b=sJ353smbiuenU1Xdfe5BlRH9eg9yS3af1RHhBTBU5F0ChPzlhoXgdCV0uFIB5CdNcXEqLQ+UU C64moMhnOG6CYizcBAp7xg7uX7O9zLN/TWlkfqfmdGieRpGbgnSJDlU X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR01CA0045.apcprd01.prod.exchangelabs.com (2603:1096:4:193::19) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|AM7PR04MB6853:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e3a68d6-d74e-421b-1331-08dd3a2d87dc 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|376014|52116014|7416014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?WF4u7F6cXIwLs8iyChRtawnB3zrEtqS?= =?utf-8?q?dB5iqRCgHWIzGyO1eQFuIOhc2pKLTBdwSmnwrugQ0+DFUJ8nsSxNxO1Vbouk5Lk33?= =?utf-8?q?Nvfv2ipEAJNOyhSX2unzXm57tpWCA1efAmejB+09HlIb0R6mvF+QcghCkIIakvNSj?= =?utf-8?q?9PLWZvyu3a8EG/sQxqtW2k/h1cE7Z3b2FhEAotaDwVzfCKJxjDSMUrifi63jKHE6C?= =?utf-8?q?TPF8w9SlNxBM+ZBduIbNSvTyUGRKUtm3djN1nOkzLCCpHL2j3u14MhbQczc65+4ie?= =?utf-8?q?dUQ0LklyS8Ml19F6jJPi9SinJE+InMDpfEPdgN3h81+zF0mZ38ZR2QuXFMbLBwsEX?= =?utf-8?q?iOqYTM7YACPkMp3RUu+glbal4/5r4mguVXpc1SlwhuqZ0A0pXvXnkYOrl8zbB5Gmc?= =?utf-8?q?VFez76mecEA9b7GRUcRyTYx/riW0OtiQ5VjJfB1btFCnYNPNzLIlWGm328C8opv21?= =?utf-8?q?QmwFS52PxaiFOGKWAgns2DpWMGkCKqszdwxlLQk1H7Qz2ROYR1Bat1oaU29L133F+?= =?utf-8?q?4poe5YLtuVX4RMgaiSHvZVsypP+sANfuun27L/Sec8cQqHTn5Votx82pSvZSXtwbs?= =?utf-8?q?IFlkS0V5p+AkkO3ufW+viZ6pFOpFtUqXZjlK6KkmOTrEorZIXveIgpVxDFc4fl6OD?= =?utf-8?q?PFBbWXCieN/Cq1ZC+PXTiLHOKZAQ9XyhvEdrFnd/TDf9ZWBNp4ZxvjGvqCEfbOq/x?= =?utf-8?q?kHz6bTM4DktGLHsVgqXew60uwCOXySnlyD1h5L2+vPqAsr2rL0WfEspuwxHr0lBUt?= =?utf-8?q?Xgt17nHsPpVfdwIIhU78FSLdFQWjjhaAa+pD31KlWPoLjO6Jkm15TTqiUbhpGInYO?= =?utf-8?q?K4e3zxkW7UU1ozAGRk2r1ncZog7WivLUdDPUvQvSMTaOEshrQHrpmPi1EWcXC8Z87?= =?utf-8?q?5YSfDSlf0c9+o3axLanskF2BrWHnCDp2YBm97SKcawzXrCTnfE7rF7tUvY4FfV+Ag?= =?utf-8?q?qj28DK8meLTu6ozpv0Ii/GGzO3PE+EIhz59o5fhp5ohJZuDfGn/MjPpAbaEoeyXgr?= =?utf-8?q?n0UR1xS/4z199LOSVsYd1Nnr/RzLhcTZXkIVE5kWx3i5k5miQeaqCd2ptksdaax7z?= =?utf-8?q?ug6eZTMEnPoXlPs3dVAdjlj2WDFTL3E+/MTvoOKj+572VeyZL1V9r5Wu6q1YmmZYm?= =?utf-8?q?WhC45jrB5p9zfNDAeUGhwBuGaJ5REYS3HoBNiO/LeqQC58TsOPnqsUf5NTfRi0BqN?= =?utf-8?q?xlrBQDo1hcpJrlS2D6B5GBZL1D/L882jXcmEI8AomBGTC9nrZg9P9VYJpCFGZHljV?= =?utf-8?q?L/NSwcBnDSH4/Is3ESz38N6Z2oay9VULG7AfiLYiO/3wB1QSc6WDAAwc49Cdzb2jY?= =?utf-8?q?CkJ3yXKgDS8Bq/lDAs+EBuYZ5A7J7zCIgrNmCc86r1Kd+5Wyvr6qF0rdb5gWnF8ez?= =?utf-8?q?nWSxoVY7WKT?= 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)(376014)(52116014)(7416014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?qLcLo1B2esXd94bqzNmze2fnV8wb?= =?utf-8?q?QWFuo3fnYc4bBUHk1VRwUZ7uSlvUSEZnGkv814W1Ri+XB2PT0RRHeHUAfThr+f+cU?= =?utf-8?q?KFyRYo3WLTqeVtUPWA9QLe/0APFA9l8SYlJUMXy78oyo+lwpVWBd87dzIfFHdVWkv?= =?utf-8?q?0aPpOYQQCQey2/jm475SJrNgfT6ngoAD96oI3G0j5Enh+x7MafFlFHWAZcX5IoBV1?= =?utf-8?q?XqGhJJJflMSW/D2XaRXU6dFlb79u45dVSU4hQWxBmSNg6aMYYbK+IVUsT4y1zro0F?= =?utf-8?q?h+KQVCPqUEqkllVWMCgLLbxfIhzyeIpqM58XSIhk6o4X7qw+U1Wl0be+guPfCTGJJ?= =?utf-8?q?Ie8nBqgkWl/kToyEXv8tRYTBC78EOaw/RMLWdmzUyZ6wh4BLtNe7Pnyq890VtW4/7?= =?utf-8?q?oW2dKe9hDT+BOa7AqFJGAZ2R3A2qx/p9aZRxzmmhvoV/7Rotx44+R9hR82KsUenar?= =?utf-8?q?3ys6lvV8I85uG6bvy0z2uQifIxo3OYry2LWQSCy3I9cqQX6Cjx5ZGcFkp8t2k0KrI?= =?utf-8?q?WK2Lj1B+XzVmQriHbFJRiqFBU/jUf1HcGvETHlLGXMqyqF0+HXlkkh5OD4DLd+RI8?= =?utf-8?q?MmH0enBuVIj+5ITdS9InOILXVA/kL6vrz2BKh2USBVQXzfx34Opfh/24VedarYvu0?= =?utf-8?q?0RtvM4wUdoEBQtxOzj6J1bThYoqpi4sqjw0p4/Zn2aQ7gW+8NifFMz1fCqSM3peXj?= =?utf-8?q?9ophIEd2/U08NWYKjdC216iWGM3yt0DvQjIy6/M1+RC9epgArfQFudVPy19xiyn/B?= =?utf-8?q?Hnfuk0gMTqBpZq8PuKSEeStQJc02Zhs5noUeDDtwp3Y028x0FB1OV4rPPOUKux7wq?= =?utf-8?q?0QwdS/KQEmbO/pjFWMY3VBVfu/+zsa7WVyvOU4F1ARgaaYp6VO4s72FA1rMArgZMv?= =?utf-8?q?rx9AY6HP7Lh5iAnFIDs1kZYJxELjtLEZZgigDY4oTdNZTnPMJNFZI0cipulgO7N6/?= =?utf-8?q?PVTkCoz7dTmsv4pRZoObhUDhtvt2KkrQeRpdEphqKHCsZDu0qjl92iFDHySqRbRM7?= =?utf-8?q?5kqu4hW483yGWcbolCv+SvKpiCIEmdyEHQt27C5cAvU7RDs+rOQ6uKqNvIwoo1eS+?= =?utf-8?q?0z7QbNBq1cljfwdVlrwjXIdV9AOsAgjMwqLle30gOuyLE5+cqvkgebfv0mHaKgpRn?= =?utf-8?q?A6Gk345X/kKa7vljQFr+vrjkJEQjBgGDnNZg0N2kdJcFo+YIGm9MhJY9dzaajqu5A?= =?utf-8?q?a7qKNcrpwfWw5mJOwdM7QX/F72Qh5zcXamKiLZia6Q8XoU6hLRYj6bvTDNY83k+q/?= =?utf-8?q?36v1tPM1zJq2BGmDOG/OPYpAXIXcrtqtp1axr6AkuvnkFAiDVfWZ9o4ca2Rc3LNl/?= =?utf-8?q?0FVM8WbmQTFRbjgFqsaSCAHnBa9Ysfb4IpK0uvM6YSzaiLPmE6u0Tl2hwrTyQn4im?= =?utf-8?q?LEtnhAVI1zmY/3d/dWzGQeCk718T9IfRZR5jH6ZDxslfqJVaAF8AZ+t9sJSsCBKuC?= =?utf-8?q?w9btfA0U05irup1DmRVCQcDMdMdWT14IiF6sanp6e/3I7gaIDLM2QtkR4M+ZCI8VC?= =?utf-8?q?shXv/fIDKMF4?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e3a68d6-d74e-421b-1331-08dd3a2d87dc X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jan 2025 15:08:58.5643 (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: 0QCqyICgt2rW97iSrf9VnGZrqrCnIPRq0z5aUsA8HGUkr6mWbzkpptuZBdNWWCgpy9s+b037WiCbhVXXqoDgJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB6853 From: Peng Fan Add Logical Machine Management(LMM) protocol which is intended for boot, shutdown, and reset of other logical machines (LM). It is usually used to allow one LM to manager another used as an offload or accelerator engine. Signed-off-by: Peng Fan --- drivers/firmware/arm_scmi/vendors/imx/Kconfig | 11 + drivers/firmware/arm_scmi/vendors/imx/Makefile | 1 + drivers/firmware/arm_scmi/vendors/imx/imx-sm-lmm.c | 235 +++++++++++++++++++++ include/linux/scmi_imx_protocol.h | 29 +++ 4 files changed, 276 insertions(+) diff --git a/drivers/firmware/arm_scmi/vendors/imx/Kconfig b/drivers/firmware/arm_scmi/vendors/imx/Kconfig index a01bf5e47301d2f93c9bfc7eebc77e083ea4ed75..1a936fc87d2350e2a21bccd45dfbeebfa3b90286 100644 --- a/drivers/firmware/arm_scmi/vendors/imx/Kconfig +++ b/drivers/firmware/arm_scmi/vendors/imx/Kconfig @@ -12,6 +12,17 @@ config IMX_SCMI_BBM_EXT To compile this driver as a module, choose M here: the module will be called imx-sm-bbm. +config IMX_SCMI_LMM_EXT + tristate "i.MX SCMI LMM EXTENSION" + depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF) + default y if ARCH_MXC + help + This enables i.MX System Logical Machine Protocol to + manage Logical Machines boot, shutdown and etc. + + To compile this driver as a module, choose M here: the + module will be called imx-sm-lmm. + config IMX_SCMI_MISC_EXT tristate "i.MX SCMI MISC EXTENSION" depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF) diff --git a/drivers/firmware/arm_scmi/vendors/imx/Makefile b/drivers/firmware/arm_scmi/vendors/imx/Makefile index d3ee6d5449244a4f5cdf6abcf1845f312c512325..f39a99ccaf9af757475e8b112d224669444d7ddc 100644 --- a/drivers/firmware/arm_scmi/vendors/imx/Makefile +++ b/drivers/firmware/arm_scmi/vendors/imx/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_IMX_SCMI_BBM_EXT) += imx-sm-bbm.o +obj-$(CONFIG_IMX_SCMI_LMM_EXT) += imx-sm-lmm.o obj-$(CONFIG_IMX_SCMI_MISC_EXT) += imx-sm-misc.o diff --git a/drivers/firmware/arm_scmi/vendors/imx/imx-sm-lmm.c b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-lmm.c new file mode 100644 index 0000000000000000000000000000000000000000..808cbedba5de4b4314948c06c60bebea057efbe7 --- /dev/null +++ b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-lmm.c @@ -0,0 +1,235 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * System control and Management Interface (SCMI) NXP LMM Protocol + * + * Copyright 2025 NXP + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "../../protocols.h" +#include "../../notify.h" + +#define SCMI_PROTOCOL_SUPPORTED_VERSION 0x10000 + +enum scmi_imx_lmm_protocol_cmd { + SCMI_IMX_LMM_ATTRIBUTES = 0x3, + SCMI_IMX_LMM_BOOT = 0x4, + SCMI_IMX_LMM_RESET = 0x5, + SCMI_IMX_LMM_SHUTDOWN = 0x6, + SCMI_IMX_LMM_WAKE = 0x7, + SCMI_IMX_LMM_SUSPEND = 0x8, + SCMI_IMX_LMM_NOTIFY = 0x9, + SCMI_IMX_LMM_RESET_REASON = 0xA, + SCMI_IMX_LMM_POWER_ON = 0xB, +}; + +struct scmi_imx_lmm_priv { + u32 nr_lmm; +}; + +#define SCMI_IMX_LMM_PROTO_ATTR_NUM_LM(x) (((x) & 0xFFU)) +struct scmi_msg_imx_lmm_protocol_attributes { + __le32 attributes; +}; + +struct scmi_msg_imx_lmm_attributes_out { + __le32 lmid; + __le32 attributes; + __le32 state; + __le32 errstatus; + u8 name[LMM_MAX_NAME]; +}; + +struct scmi_imx_lmm_shutdown_in { + __le32 lmid; +#define LMM_FLAGS_GRACEFUL(x) ((x) & BIT(0)) + __le32 flags; +}; + +static int scmi_imx_lmm_validate_lmid(const struct scmi_protocol_handle *ph, u32 lmid) +{ + struct scmi_imx_lmm_priv *priv = ph->get_priv(ph); + + if (lmid >= priv->nr_lmm) + return -EINVAL; + + return 0; +} + +static int scmi_imx_lmm_attributes(const struct scmi_protocol_handle *ph, + u32 lmid, struct scmi_imx_lmm_info *info) +{ + struct scmi_msg_imx_lmm_attributes_out *out; + struct scmi_xfer *t; + int ret; + + ret = ph->xops->xfer_get_init(ph, SCMI_IMX_LMM_ATTRIBUTES, sizeof(u32), 0, &t); + if (ret) + return ret; + + put_unaligned_le32(lmid, t->tx.buf); + ret = ph->xops->do_xfer(ph, t); + if (!ret) { + out = t->rx.buf; + info->lmid = le32_to_cpu(out->lmid); + info->state = le32_to_cpu(out->state); + info->errstatus = le32_to_cpu(out->errstatus); + strscpy(info->name, out->name); + dev_dbg(ph->dev, "i.MX LMM: Logical Machine(%d), name: %s\n", + info->lmid, out->name); + } else { + dev_err(ph->dev, "i.MX LMM: Failed to get info of Logical Machine(%u)\n", lmid); + } + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_imx_lmm_boot(const struct scmi_protocol_handle *ph, u32 lmid) +{ + struct scmi_xfer *t; + int ret; + + ret = scmi_imx_lmm_validate_lmid(ph, lmid); + if (ret) + return ret; + + ret = ph->xops->xfer_get_init(ph, SCMI_IMX_LMM_BOOT, sizeof(u32), + 0, &t); + if (ret) + return ret; + + put_unaligned_le32(lmid, t->tx.buf); + ret = ph->xops->do_xfer(ph, t); + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_imx_lmm_power_on(const struct scmi_protocol_handle *ph, u32 lmid) +{ + struct scmi_xfer *t; + int ret; + + ret = scmi_imx_lmm_validate_lmid(ph, lmid); + if (ret) + return ret; + + ret = ph->xops->xfer_get_init(ph, SCMI_IMX_LMM_POWER_ON, sizeof(u32), + 0, &t); + if (ret) + return ret; + + put_unaligned_le32(lmid, t->tx.buf); + ret = ph->xops->do_xfer(ph, t); + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_imx_lmm_shutdown(const struct scmi_protocol_handle *ph, u32 lmid, + u32 flags) +{ + struct scmi_imx_lmm_shutdown_in *in; + struct scmi_xfer *t; + int ret; + + ret = scmi_imx_lmm_validate_lmid(ph, lmid); + if (ret) + return ret; + + ret = ph->xops->xfer_get_init(ph, SCMI_IMX_LMM_SHUTDOWN, sizeof(*in), + 0, &t); + if (ret) + return ret; + + in = t->tx.buf; + in->lmid = cpu_to_le32(lmid); + in->flags = cpu_to_le32(flags); + ret = ph->xops->do_xfer(ph, t); + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static const struct scmi_imx_lmm_proto_ops scmi_imx_lmm_proto_ops = { + .lmm_boot = scmi_imx_lmm_boot, + .lmm_info = scmi_imx_lmm_attributes, + .lmm_power_on = scmi_imx_lmm_power_on, + .lmm_shutdown = scmi_imx_lmm_shutdown, +}; + +static int scmi_imx_lmm_protocol_attributes_get(const struct scmi_protocol_handle *ph, + struct scmi_imx_lmm_priv *priv) +{ + struct scmi_msg_imx_lmm_protocol_attributes *attr; + struct scmi_xfer *t; + int ret; + + ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0, + sizeof(*attr), &t); + if (ret) + return ret; + + attr = t->rx.buf; + + ret = ph->xops->do_xfer(ph, t); + if (!ret) { + priv->nr_lmm = SCMI_IMX_LMM_PROTO_ATTR_NUM_LM(attr->attributes); + dev_info(ph->dev, "i.MX LMM: %d Logical Machines\n", + priv->nr_lmm); + } + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_imx_lmm_protocol_init(const struct scmi_protocol_handle *ph) +{ + struct scmi_imx_lmm_priv *info; + u32 version; + int ret; + + ret = ph->xops->version_get(ph, &version); + if (ret) + return ret; + + dev_info(ph->dev, "NXP SM LMM Version %d.%d\n", + PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version)); + + info = devm_kzalloc(ph->dev, sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + ret = scmi_imx_lmm_protocol_attributes_get(ph, info); + if (ret) + return ret; + + return ph->set_priv(ph, info, version); +} + +static const struct scmi_protocol scmi_imx_lmm = { + .id = SCMI_PROTOCOL_IMX_LMM, + .owner = THIS_MODULE, + .instance_init = &scmi_imx_lmm_protocol_init, + .ops = &scmi_imx_lmm_proto_ops, + .supported_version = SCMI_PROTOCOL_SUPPORTED_VERSION, + .vendor_id = SCMI_IMX_VENDOR, + .sub_vendor_id = SCMI_IMX_SUBVENDOR, +}; +module_scmi_protocol(scmi_imx_lmm); + +MODULE_DESCRIPTION("i.MX SCMI LMM driver"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/scmi_imx_protocol.h b/include/linux/scmi_imx_protocol.h index 53b356a26414279f4aaaa8287c32209ed1ad57b4..456559f021696ae51f40ed11e6f85089d430ce71 100644 --- a/include/linux/scmi_imx_protocol.h +++ b/include/linux/scmi_imx_protocol.h @@ -11,8 +11,10 @@ #include #include #include +#include #include +#define SCMI_PROTOCOL_IMX_LMM 0x80 #define SCMI_PROTOCOL_IMX_BBM 0x81 #define SCMI_PROTOCOL_IMX_MISC 0x84 @@ -57,4 +59,31 @@ struct scmi_imx_misc_proto_ops { int (*misc_ctrl_req_notify)(const struct scmi_protocol_handle *ph, u32 ctrl_id, u32 evt_id, u32 flags); }; + +#define LMM_ID_DISCOVER 0xFFFFFFFFU +#define LMM_MAX_NAME 16 + +enum scmi_imx_lmm_state { + LMM_STATE_LM_OFF, + LMM_STATE_LM_ON, + LMM_STATE_LM_SUSPEND, + LMM_STATE_LM_POWERED, +}; + +struct scmi_imx_lmm_info { + u32 lmid; + enum scmi_imx_lmm_state state; + u32 errstatus; + u8 name[LMM_MAX_NAME]; +}; + +struct scmi_imx_lmm_proto_ops { + int (*lmm_boot)(const struct scmi_protocol_handle *ph, u32 lmid); + int (*lmm_info)(const struct scmi_protocol_handle *ph, u32 lmid, + struct scmi_imx_lmm_info *info); + int (*lmm_power_on)(const struct scmi_protocol_handle *ph, u32 lmid); + int (*lmm_shutdown)(const struct scmi_protocol_handle *ph, u32 lmid, + u32 flags); +}; + #endif