From patchwork Wed Oct 16 16:18:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 13838639 Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2065.outbound.protection.outlook.com [40.107.103.65]) (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 067CB210C3A for ; Wed, 16 Oct 2024 16:23:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.103.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729095813; cv=fail; b=cbTmczceSqrd1ScVRf28p8Rm7QYDI4r0++f0bYt+mEpzz4VHWeRGg5AkzXpsOtbQGCwW0/Dl5VFFUvmEyXFg/9Yi2c/yVIsy2U6ky2USQ4V+YJ5G9iqXX+whsr/rzfMOi70XVNaVl21gqqwoMfusrv4o2ZOK2P56TxqxWTmCk+A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729095813; c=relaxed/simple; bh=FwHu8HOgjdeesS4jBLvkey7Y+WnnBYkcgUp1hGR75ZU=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=sDpJWWudY0oCmi6YlS43i7JMR3IwNWEmo8t0ZqJIqcShBRVlt1C8xoim1XFp0WbTyqRo/2QNJYKR9ztWA0QaPaClL65kTOWqcIG6S6iJECmjcb3VtWZccROHR8QEJ77YBfJhFCiONprzBuOg1Rse/TTFBtXOcXimPovXLuk4dxg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=Pe8z+T36; arc=fail smtp.client-ip=40.107.103.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="Pe8z+T36" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YdEO+JmG7TAB8vWALFxbECfV533RWOOqLRloIG307xU4BgezG3SIwFFYBdQWsKgraqVWewDldPxVmSgdTLwy/1sOFtUucPQyZ+hw5Qje6xUBAcdtfTXKx7Jop+5uxXT9SN30u1w7V37PlJ21/1W93EE84xNT/3KD59GIEONrpfRTgWOTPB8hpfIzMPd2jKtuSgBnPu3QhFyusN9dvF6LEBqsIMB/Kzzhd7iSS9pdNts/8dfTQmHYo+U58de1IcFrRXWTGCLAalL8993cTADzwvWrWKaYz9MfvLwMjgWoI8PmUnlFuCWJzA4X8oF7sz2QeF1v8eYIo1cL65gA6WaI8Q== 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=rydjPSyjFpE1b+KVUJhSPw9jPLhoKfIzwxtGoWGJhg4=; b=SpIq4F1iyUdX7VGB9donFcTJNXa1Bo83q2N3vKzdbKl2E+nJiOQuICULcAJ8ZCgwlmC3+WmWaxJaiEMpbge8h2YotUUX796ai4vYFZJ5MWSzAI3Ru/vtAirEJXHxyMpkvdUbSJKa/KMAphRAblHkyukcXHOLaso0MWcQISjLZ836kK12us+pxXK2+CiVVUq+aqAt+RnXUFWs4H9JIFuR5XCA7awxaJlGGqv+1D+4EC4XnyXi1GUdRe5mly40+woDbFmtFlW3Xs1HXv7b/vxtnIlNnUxOne1mjlwpLQEkGGiEl86uKyIM1ZvioZOjr1cjknjWtYzODNSoBwSe3ZO3Ag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rydjPSyjFpE1b+KVUJhSPw9jPLhoKfIzwxtGoWGJhg4=; b=Pe8z+T36LLLGox2Q/X8kq2Y5BU9NireGzPpxYWQYhWrQxwCFBDOabR5WrTG7CcssqqPkmi8PeHP8xKrsucEnxNGEblPhFES+qztK2Upq2f/nCIoE9iY87DdTpqzKxFSd4LPutGhrAWoS6Cx3PofI6SAwniUXgyn88SG4+SyA6rAE+5T7QVtXf85J8r8d5/x0yLpQ4tHrZ1tiw9uPMfbGkNX1zEjkbw3OxnWbmddq5mhUxTmxd+U0I4CAwO2YGIrJO9fKm/p2q7QyXgJuAUpUaQSxU4aT8KYzp6lqs2PBDXEYX0HlNZ6QDofxEdUMIAcWxx2C8l9bkmiCXo4CWioUiQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8599.eurprd04.prod.outlook.com (2603:10a6:10:2da::7) by AM0PR04MB6884.eurprd04.prod.outlook.com (2603:10a6:208:183::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18; Wed, 16 Oct 2024 16:23:27 +0000 Received: from DU2PR04MB8599.eurprd04.prod.outlook.com ([fe80::763:eb3b:6607:1e72]) by DU2PR04MB8599.eurprd04.prod.outlook.com ([fe80::763:eb3b:6607:1e72%5]) with mapi id 15.20.8069.016; Wed, 16 Oct 2024 16:23:27 +0000 From: Pankaj Gupta Date: Wed, 16 Oct 2024 21:48:58 +0530 Subject: [PATCH v9 1/5] Documentation/firmware: add imx/se to other_interfaces Message-Id: <20241016-imx-se-if-v9-1-fd8fa0c04eab@nxp.com> References: <20241016-imx-se-if-v9-0-fd8fa0c04eab@nxp.com> In-Reply-To: <20241016-imx-se-if-v9-0-fd8fa0c04eab@nxp.com> To: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Pankaj Gupta Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729095547; l=6679; i=pankaj.gupta@nxp.com; s=20240523; h=from:subject:message-id; bh=FwHu8HOgjdeesS4jBLvkey7Y+WnnBYkcgUp1hGR75ZU=; b=ET9o4TYtEmE2iOu2H5udFFqOsZeGIGrT9EzdjnNf/UG9wp53DmDKoEM+gECNvxxvVTkTQU+yt kjauYXvTUxVAJVwej7oUNiulDy7o+y3MoIzorR6T0I5mbATbXkKIxtC X-Developer-Key: i=pankaj.gupta@nxp.com; a=ed25519; pk=OA0pBQoupy5lV0XfKzD8B0OOBVB6tpAoIf+0x1bYGRg= X-ClientProxiedBy: SG2PR02CA0037.apcprd02.prod.outlook.com (2603:1096:3:18::25) To DU2PR04MB8599.eurprd04.prod.outlook.com (2603:10a6:10:2da::7) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8599:EE_|AM0PR04MB6884:EE_ X-MS-Office365-Filtering-Correlation-Id: a7dac2b9-7a42-444b-ede3-08dcedfedd64 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|7416014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?ut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w5IUxB6Y29nfoE1b6jYtUGTHlI?= =?utf-8?q?N1FnwM5ZnsU2kpBsSJKIr3a3Ff5+fcdJ4Rj5AInpJeiUDVBO7PJ9YaUvTtTGhFbdw?= =?utf-8?q?y5ceOuQLpDS/yhCvEzyF84sOq0ZQKr9l54GM5s54bUnrZLTm9eUA/IrD4SRyXqtFR?= =?utf-8?q?2wQk06haigFX4LC82bvcCz3hOlpP07LwAcmmtWX4yL14KD9D/arIsV3biJautOb53?= =?utf-8?q?pGmKXkJGE3kzJX4rL5qNmR+vMn5OR8vMagAWoyEJA8k1ch/tNHJ9z4IdpIbSdNAHF?= =?utf-8?q?KM/3WbzyIb9NvnJ2rgDs9drUr+CBHSB+ud25kztsFHogOVClf3WQ6/R3GYUGVy12I?= =?utf-8?q?XxDHnMBp5bK45griMhjt8O0YwXGJqDMs9XV6eqOIJEFp6HIzWpWYYNa33aGp7pLrG?= =?utf-8?q?UDzPCRkEsRDznNLiBLfk7qjOySuyqnPeNAA=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8599.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(1800799024)(7416014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?PK1M2c8tV3Qk4jjU97S7IXTpkBXb?= =?utf-8?q?FCGIEFIPcxBJgGzxAtUd0mf3D7NKwcYf0M4IdrreMYyrvjIgX/qkEtB1+q3NfU4Nh?= =?utf-8?q?krn1Gk4NPv9rPd2vaqtba4Z3+jLXFO3S+3fDG3ur3McXcDiTyV8r9W/9G9WC21Nct?= =?utf-8?q?a3GGWY9inj37XPTnl7qJ94KjFP9S/qZkm9Lf/3ZZyRd4+b57ReVB29hLwZB2pjYeR?= =?utf-8?q?ZG1xkUIuITpBbPKa9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xUcWmKbWx5bU1fGlPPGslAfnMmMo?= =?utf-8?q?6DmJCI9U/yt3CJPj/1JDQ6n3IFrvkFlaoJHWR78jMYJabNGMooZby0MAEyZuasol5?= =?utf-8?q?TZp61Mm+K4XI5kbi9bOiXWPuB9b55V4VI0/uWAKKYdbbOwFQyn20BqWnxpUqNkfhB?= =?utf-8?q?OwAZjLLhWD6HODnylZXOnNuC8+AhRn+lcrKa2ukEgqtCHU1Z+7NcACQv0EaVkv9sT?= =?utf-8?q?GyAGygU5HXkKL0m62l+s5lCmNdY80zWfi5Y4Ob2C+rYP2moAxSaWhxdmtmlNX4gBu?= =?utf-8?q?1tbQFIigejnfXbNQnesH9kJtz1oYlzToNkeuf7fAHmd1x/8uZyD5HAt2yXFxhqybi?= =?utf-8?q?ideyuvjPcO1P2uZ+3YdWBVypWILAzVdx3aJxoBVvJ1whdOPiT4TN4UMstwaJuPbez?= =?utf-8?q?ig1V02XWyMj8?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a7dac2b9-7a42-444b-ede3-08dcedfedd64 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8599.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 16:23:27.2783 (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: /IlQPbIAXW/EkobGLpxU2RTMQGhtpxKaJWW+6bB2Q3IKnMnOvqzzwrDPx/J4yLcofyl8o9fzKVBpRvWp2KDmuw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6884 Documents i.MX SoC's Service layer and C_DEV driver for selected SoC(s) that contains the NXP hardware IP(s) for Secure Enclaves(se) like: - NXP EdgeLock Enclave on i.MX93 & i.MX8ULP Signed-off-by: Pankaj Gupta --- .../driver-api/firmware/other_interfaces.rst | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/Documentation/driver-api/firmware/other_interfaces.rst b/Documentation/driver-api/firmware/other_interfaces.rst index 06ac89adaafb..a3a95b54a174 100644 --- a/Documentation/driver-api/firmware/other_interfaces.rst +++ b/Documentation/driver-api/firmware/other_interfaces.rst @@ -49,3 +49,124 @@ of the requests on to a secure monitor (EL3). .. kernel-doc:: drivers/firmware/stratix10-svc.c :export: + +NXP Secure Enclave Firmware Interface +===================================== + +Introduction +------------ +The NXP's i.MX HW IP like EdgeLock Enclave, V2X etc., creates an embedded secure +enclave within the SoC boundary to enable features like + - Hardware Security Module (HSM) + - Security Hardware Extension (SHE) + - Vehicular to Anything (V2X) + +Each of the above feature is enabled through dedicated NXP H/W IP on the SoC. +On a single SoC, multiple hardware IP (or can say more than one secure enclave) +can exist. + +NXP SoCs enabled with the such secure enclaves(SEs) IPs are: +i.MX93, i.MX8ULP + +To communicate with one or more co-existing SE(s) on SoC, there is/are dedicated +messaging units(MU) per SE. Each co-existing SE can have one or multiple exclusive +MUs, dedicated to itself. None of the MU is shared between two SEs. +Communication of the MU is realized using the Linux mailbox driver. + +NXP Secure Enclave(SE) Interface +-------------------------------- +Although MU(s) is/are not shared between SE(s). But for SoC like i.MX95 which has +multiple SE(s) like HSM, V2X-HSM, V2X-SHE; all the SE(s) and their interfaces 'se-if' +that is/are dedicated to a particular SE will be enumerated and provisioned using the +single compatible node("fsl,imx95-se"). + +Each 'se-if' comprise of twp layers: +- (C_DEV Layer) User-Space software-access interface. +- (Service Layer) OS-level software-access interface. + + +--------------------------------------------+ + | Character Device(C_DEV) | + | | + | +---------+ +---------+ +---------+ | + | | misc #1 | | misc #2 | ... | misc #n | | + | | dev | | dev | | dev | | + | +---------+ +---------+ +---------+ | + | +-------------------------+ | + | | Misc. Dev Synchr. Logic | | + | +-------------------------+ | + | | + +--------------------------------------------+ + + +--------------------------------------------+ + | Service Layer | + | | + | +-----------------------------+ | + | | Message Serialization Logic | | + | +-----------------------------+ | + | +---------------+ | + | | imx-mailbox | | + | | mailbox.c | | + | +---------------+ | + | | + +--------------------------------------------+ + +- service layer: + This layer is responsible for ensuring the communication protocol that is defined + for communication with firmware. + + FW Communication protocol ensures two things: + - Serializing the messages to be sent over an MU. + + - FW can handle one command message at a time. + +- c_dev: + This layer offers character device contexts, created as '/dev/_mux_chx'. + Using these multiple device contexts that are getting multiplexed over a single MU, + userspace application(s) can call fops like write/read to send the command message, + and read back the command response message to/from Firmware. + fops like read & write use the above defined service layer API(s) to communicate with + Firmware. + + Misc-device(/dev/_mux_chn) synchronization protocol: + + Non-Secure + Secure + | + | + +---------+ +-------------+ | + | se_fw.c +<---->+imx-mailbox.c| | + | | | mailbox.c +<-->+------+ +------+ + +---+-----+ +-------------+ | MU X +<-->+ ELE | + | +------+ +------+ + +----------------+ | + | | | + v v | + logical logical | + receiver waiter | + + + | + | | | + | | | + | +----+------+ | + | | | | + | | | | + device_ctx device_ctx device_ctx | + | + User 0 User 1 User Y | + +------+ +------+ +------+ | + |misc.c| |misc.c| |misc.c| | + kernel space +------+ +------+ +------+ | + | + +------------------------------------------------------ | + | | | | + userspace /dev/ele_muXch0 | | | + /dev/ele_muXch1 | | + /dev/ele_muXchY | + | + +When a user sends a command to the firmware, it registers its device_ctx +as waiter of a response from firmware. + +Enclave's Firmware owns the storage management, over Linux filesystem. +For this c_dev provisions a dedicated slave device called "receiver". + +.. kernel-doc:: drivers/firmware/imx/se_fw.c + :export: From patchwork Wed Oct 16 16:18:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 13838640 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2066.outbound.protection.outlook.com [40.107.21.66]) (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 6D364210196 for ; Wed, 16 Oct 2024 16:23:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729095819; cv=fail; b=lQSQoihqNA9/Cv9EJPA4ylQ/ks39JKM89yu5enVIDbW2joChK34Mbf/C9/5UDkMSdDOT3CBYQqghdEdBJWAqlfdssr7isaq2lGxFcaPCtPfDPA4vNIDLavkJLhb3xMnXZuwBENTMOE5IWxDG1ZCix0hO4VMS3YApoX9mnxfBxKE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729095819; c=relaxed/simple; bh=8bCTvi7AgU4MQ5HET0AOHmcMvn388Mh4NN86zRFZhtg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=PdYABxTFWAW9JCq1o4+bnirhApSXTbvYuilcozr3XDcj0giQtUmDqwEf42H7xOs2FwyHRHghqo1XHO/lBFQE6TWdznn0MVXN4eQ9//szmk7HJGV7+E99azWUQmAZyH/erv99jPL0Ab9DQCkYliNqNl/9lPB9NjKb7OrusPeY3Hw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=Rk/dDmWv; arc=fail smtp.client-ip=40.107.21.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="Rk/dDmWv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WDPmnsi9GjVdp4Yo95AQkuZ8pDxnC6sECJ0mTrUtQqQEGoUx0AIRk+xJsSE76dzarlYJsgTboaOtqit/TXU6bP4G4w2TvVteTED223s1/yOUTtpSbj4jyDAgfws5WqsAn5v90QtcjHe5K0b9GZVMYCyclv4VzoNnWLqpbZvc//0zYQV3ognz5OBZ53D44ax9rkttsUbHV8eTGQBQoKjFfg2y5PjiHro8PDbJMtj+LF+VwG3ggQVUE5vrtuk4YNR1MIe7OzIlfxdtu/gN51Ixw4wKHOywNMxTGjjJnFYiBXdTeUmLPgZgDq8kIq32lKTWC5gpxhD14SDm7fEMNmwtpA== 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=dZoRgTn45yJn+Pnp3LFTUwhkGYSMYn5cLf7fH4YbYkY=; b=AtHPWe7cQRmHoRYQdeFBZGJ64i3l1IaYwSMMu+t/MVcjU02F2bZ2Sttr5RHQ1+uSpMpg2ozil5sWEjBltHRSraIgKHlCb411TsUr9hQGxlO/PnG4Ow2xRup4lN5RFf1Dh8QuoY4ApZTyqUEwCMv0VhJxvEg3lIeo687RwG5P2dGPuLuNk5XZizhqla5PITVEGEgNQLnimlY3Jgw89QEKBehWvS5pHAXslRiuDHQx7Np1u9PjfHoyTZiZBt0mDgCgZ9L2vv+/QggyjBj9n3vPg6suQxyCRJSPMpmO5p98vaeA+HS7aEPFA1riDPMTEVaswCoSF65M0wj438GxZ7Tbfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dZoRgTn45yJn+Pnp3LFTUwhkGYSMYn5cLf7fH4YbYkY=; b=Rk/dDmWvLKGalem5ujNroyOSzeD07wMucU0zYnN/aBC45/VGKgZURRz0NB0mnzr+MvAaGZafLOfd5ja9/sIz9jB03EiGCuhMkp72owx9nWVN8VQ2madzjbrcf8eUbfKPy37i2PCyKdfVsTjXx0WmxLtKzlFvYJkdH0WwHsmEL7QH8pJcnYJ+XfUAPCwEWWckSr/GgWzMTQTKuIM0M/GPS0MUlxIl9EL/RIYIrXzhXV+gR8Susin1Z1MXtmwSWosHsTCUJHkX5MTz0JCPd0spAg6lsiOkpbZf7wFo66S/BonbDATAYRHuQKg/JRDbAFo65JZGAfER3Nptk8UBOJtCkQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8599.eurprd04.prod.outlook.com (2603:10a6:10:2da::7) by AM0PR04MB7043.eurprd04.prod.outlook.com (2603:10a6:208:19b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Wed, 16 Oct 2024 16:23:32 +0000 Received: from DU2PR04MB8599.eurprd04.prod.outlook.com ([fe80::763:eb3b:6607:1e72]) by DU2PR04MB8599.eurprd04.prod.outlook.com ([fe80::763:eb3b:6607:1e72%5]) with mapi id 15.20.8069.016; Wed, 16 Oct 2024 16:23:32 +0000 From: Pankaj Gupta Date: Wed, 16 Oct 2024 21:48:59 +0530 Subject: [PATCH v9 2/5] dt-bindings: arm: fsl: add imx-se-fw binding doc Message-Id: <20241016-imx-se-if-v9-2-fd8fa0c04eab@nxp.com> References: <20241016-imx-se-if-v9-0-fd8fa0c04eab@nxp.com> In-Reply-To: <20241016-imx-se-if-v9-0-fd8fa0c04eab@nxp.com> To: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Pankaj Gupta Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Conor Dooley X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729095547; l=3191; i=pankaj.gupta@nxp.com; s=20240523; h=from:subject:message-id; bh=8bCTvi7AgU4MQ5HET0AOHmcMvn388Mh4NN86zRFZhtg=; b=6jC393S6RTAMwrZrDut6I/99L4XpU1HiFdM6iGMaf9iDR2yaItkhSl4u5A7LoIIKDQkibXjFC D26TkIbWs9lDQSVJM8oHhBtnX4JYcKZi3YMX5bhzp+Wc4t7kyKiXHLs X-Developer-Key: i=pankaj.gupta@nxp.com; a=ed25519; pk=OA0pBQoupy5lV0XfKzD8B0OOBVB6tpAoIf+0x1bYGRg= X-ClientProxiedBy: SG2PR02CA0037.apcprd02.prod.outlook.com (2603:1096:3:18::25) To DU2PR04MB8599.eurprd04.prod.outlook.com (2603:10a6:10:2da::7) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8599:EE_|AM0PR04MB7043:EE_ X-MS-Office365-Filtering-Correlation-Id: 07e7f804-8431-41d9-d148-08dcedfee043 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016|52116014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?ho2u8TGKmcNkUg0lAWseREOnPjMASS6?= =?utf-8?q?EjJvdskhcn5nF/NstCcXPfFNcMQ0AG5UUZhVetNK5YWubrChaB7gKHrVSwUw/rASP?= =?utf-8?q?2f1RyzXvQjZ8R6es9VQ0FNWnf7s3t9ze/8+bNFv9qS085n7tcPI3ZFK9PN1YqX7+x?= =?utf-8?q?6nOAmlGmOlwcO2/VyCFMLC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7+1bv65AMinaWBughc8Tu91NobOK4bqv0DfyrzFEdtO?= =?utf-8?q?TVvDEA6UkWulwIwGOkp+Bk4Jh93Fk4FYBRwK964tubpGfL95vA5P47GbMRXHzfb0/?= =?utf-8?q?1EVGdOt3yVjN2hFKaxCZhjl0WmlCGPebBI+yT627p1n64GBJ2kNrWxM/qn4jpZcUR?= =?utf-8?q?5Pb6izC/8+luTcpQNfI79eJJpnR0884R0spw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8599.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?/ONGWcqX9wdVEd9SDJO6gcDTWG1u?= =?utf-8?q?IUENk/XYLErWclExXgoJChM3zYPJ//cii3D9H0qtcSHYg2OBYJc0eW1iknuJ5MeZz?= =?utf-8?q?U/Yn0/A82VDVsYA7CdQ01mC76lk2nUy6mHPfjhvOka3v0uJi47ZGq8zN1ySrsBjH0?= =?utf-8?q?AvnKukF9bb+oNxIwtUY+juIM9JTkjpngP9pelOjFW54R2ZAa+Of/8t4zfFSBMJO5G?= =?utf-8?q?y0olFAdT9eFKVr4XdgBMYi5MyoOn4pNJcA4dQWU+vWuuKkCH7UmNaj1mW/FYR9aQN?= =?utf-8?q?IByatas7Y3xml2m++Iu37nPynt5G1f8eqvYNnpWYSMqjF+vDjsq3YT0DIydcqFTX0?= =?utf-8?q?lWAyrs0FHdjnlwEcFexacLaq52THJ56rPaH83HkwhsMCa/oQx+EZJ6Lyc1ztDjksi?= =?utf-8?q?3gS/EZRxXQ8F4ICehyIKA4mH+Bms5w03nPI6WRS0pIjNtOir9wSh9kgoucVUvnBkG?= =?utf-8?q?WB7pwK+U63nrCuaTGVCp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irrO/m4wBJ/QkBNcv2ZDdfXSH42qHjSwSxtu?= =?utf-8?q?uydFbeA/oXURhtgPxpQSzgSehkuffVIuSYb9I8Y/TAGP2gm4Ug0kmORIAVn0ExCvv?= =?utf-8?q?4mqN58vmzomJrRHAdHGlrS8WtPBviqXJagg6KTDIIomNdCw3pInhEg7jcMe5kMG7y?= =?utf-8?q?KSlo0TP+zpsE?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 07e7f804-8431-41d9-d148-08dcedfee043 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8599.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 16:23:32.0637 (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: zoFPoc6nBt72emmSF7MIUTa/GQK2Tl6+TuONCrJJgqfH+gMkSpppqHad+kRDmMZAgf7MgdO2MYky4auS67YYfw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB7043 The NXP security hardware IP(s) like: i.MX EdgeLock Enclave, V2X etc., creates an embedded secure enclave within the SoC boundary to enable features like: - HSM - SHE - V2X Secure-Enclave(s) communication interface are typically via message unit, i.e., based on mailbox linux kernel driver. This driver enables communication ensuring well defined message sequence protocol between Application Core and enclave's firmware. Driver configures multiple misc-device on the MU, for multiple user-space applications, to be able to communicate over single MU. It exists on some i.MX processors. e.g. i.MX8ULP, i.MX93 etc. Signed-off-by: Pankaj Gupta Reviewed-by: Rob Herring (Arm) Reviewed-by: Conor Dooley --- .../devicetree/bindings/firmware/fsl,imx-se.yaml | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/Documentation/devicetree/bindings/firmware/fsl,imx-se.yaml b/Documentation/devicetree/bindings/firmware/fsl,imx-se.yaml new file mode 100644 index 000000000000..0b617f61640f --- /dev/null +++ b/Documentation/devicetree/bindings/firmware/fsl,imx-se.yaml @@ -0,0 +1,91 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/firmware/fsl,imx-se.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP i.MX HW Secure Enclave(s) EdgeLock Enclave + +maintainers: + - Pankaj Gupta + +description: | + NXP's SoC may contain one or multiple embedded secure-enclave HW + IP(s) like i.MX EdgeLock Enclave, V2X etc. These NXP's HW IP(s) + enables features like + - Hardware Security Module (HSM), + - Security Hardware Extension (SHE), and + - Vehicular to Anything (V2X) + + Communication interface to the secure-enclaves(se) is based on the + messaging unit(s). + +properties: + compatible: + enum: + - fsl,imx8ulp-se + - fsl,imx93-se + - fsl,imx95-se + + mboxes: + items: + - description: mailbox phandle to send message to se firmware + - description: mailbox phandle to receive message from se firmware + + mbox-names: + items: + - const: tx + - const: rx + + memory-region: + maxItems: 1 + + sram: + maxItems: 1 + +required: + - compatible + - mboxes + - mbox-names + +allOf: + # memory-region + - if: + properties: + compatible: + contains: + enum: + - fsl,imx8ulp-se + - fsl,imx93-se + then: + required: + - memory-region + else: + properties: + memory-region: false + + # sram + - if: + properties: + compatible: + contains: + enum: + - fsl,imx8ulp-se + then: + required: + - sram + + else: + properties: + sram: false + +additionalProperties: false + +examples: + - | + secure-enclave { + compatible = "fsl,imx95-se"; + mboxes = <&ele_mu0 0 0>, <&ele_mu0 1 0>; + mbox-names = "tx", "rx"; + }; +... From patchwork Wed Oct 16 16:19:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 13838641 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2060.outbound.protection.outlook.com [40.107.105.60]) (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 C64F42101A8 for ; Wed, 16 Oct 2024 16:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729095821; cv=fail; b=IL0mtP+vO25x/kkJRvegia6elxhp/OrwUGncXiNQNPHvfHTh+aFwXcGrONw2imugwslx/DRsAlqh4x0EXl5hEfHAhCyDPbl/WFpr5Wo1BjmmNJR1NzeNmhdxeWrwxsvnDe0l1XlsoTtVp6wMvMpY77+WPfMsCWbez+Nq/sPsuE4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729095821; c=relaxed/simple; bh=mAzNbzRWOh6wFu0SMI2UVtcJ4QuBAqfaQJrwAklpA20=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=VJc7q+qeW2vO+23H82IJWk6HPt4dZkXu8LCpe5Cj+vW/INLKTX8OBtZoSzmo6kP9ZXzBYLG3w3WIHNljcOCKcaSGMTQviEPGQGF0Grz1jOOnu2tuXnSsbZi0rTv9bDCG9CiuUmYZ+G3Us7SupBCcPEuM4kE+LBZEcon6dyPfNfw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=O2OWtURB; arc=fail smtp.client-ip=40.107.105.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="O2OWtURB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XI7BUKbmcKjDU3XQo5CfNAY4vODpey+khXOF9rzQDT5XaqfQwCptRcRRjDJouOiEDDOHYPyo0gRcb4kDnDsL/98cLFN1frCRbwZeAyhCXE47L3TVolKeqk3goQ7RRyo0IBaTAZTp3eubC3qfNvYcIuT/ygx19UJ+wNlzxnflwZEkBvTTTt9OB3h+4eZX24SW5S4y47mytrw9NPyb+dfPMElpiZdF9K9uiUTCykTmZxmM5PKrcrq8+rFqUZbwhaUfYj0MKo5K7bszIdRYzafvqTByhxITQSWQq2WXEawqwTN3h9QEo71nfyUzyST44VIhcmJwXIyPyZ/oxV9+9RkqgA== 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=wK/QCHsvwxI5jajMDK5bmLW2wqApLKVfmMXXvNmjNTE=; b=k74SUytHIWZrvJlTxJC6B+uY+6B0DwR22wwBo1x2sNGV1Lt5MJog8OFhjLncwnOMoYM0lbdF7P93ugPS+a9Y8jRkjI719QFWKZXWZbkrucjg2gnakvV9sxthFxCL6cKsdO0dmwAe4BoZPDHKt5JBBXM5oqXOMPCbrDgcSpyV8mjfC9tEMLwhZphV897a66n8UCGXHOMISzxpRBLREdG3Zvco0eSD8lf5jX/ObeBxKHFTK6evXPQfn8HkbdXlnxYUTErvVdI6aMo6BtfHg0Aw372NGSUsBke7vLNogb2s5wKdbVPe0cMleQHc7sTSbhWeqDbDdYwKECGo6QQDZjQGuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wK/QCHsvwxI5jajMDK5bmLW2wqApLKVfmMXXvNmjNTE=; b=O2OWtURB3AMFQBNkBGr8QVXjzLsMEJIKKwkEfZ7tXSqHjaxCQhB8jvouQvdKIFLU+5DWxyqKXYmn2IW1d7E3T1gbom5NqBvF7OzHns6plAxHId33SJ200ij+Zor83jPcIgx6C9rQdqwNeT52Fk5Od/1duLLd50sT1TJhcTBusvqBKhR5T615hXmox3ez+MqAPbmRF1Vk+mWw6e88htfo9OiD3PSTkm8NwZqGooJMqMk1GiVF4uhDuOpr2xzKQ9ouUJhFQZ0aRjhqSkDp+PYE/enCFlavZienhMkOyujlx+p8ORH25IX5oKHLV5GxjFE7vjPrlRpTq8HfJYzcNOJkZQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8599.eurprd04.prod.outlook.com (2603:10a6:10:2da::7) by AM0PR04MB6884.eurprd04.prod.outlook.com (2603:10a6:208:183::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18; Wed, 16 Oct 2024 16:23:36 +0000 Received: from DU2PR04MB8599.eurprd04.prod.outlook.com ([fe80::763:eb3b:6607:1e72]) by DU2PR04MB8599.eurprd04.prod.outlook.com ([fe80::763:eb3b:6607:1e72%5]) with mapi id 15.20.8069.016; Wed, 16 Oct 2024 16:23:36 +0000 From: Pankaj Gupta Date: Wed, 16 Oct 2024 21:49:00 +0530 Subject: [PATCH v9 3/5] arm64: dts: imx8ulp-evk: add nxp secure enclave firmware Message-Id: <20241016-imx-se-if-v9-3-fd8fa0c04eab@nxp.com> References: <20241016-imx-se-if-v9-0-fd8fa0c04eab@nxp.com> In-Reply-To: <20241016-imx-se-if-v9-0-fd8fa0c04eab@nxp.com> To: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Pankaj Gupta Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729095547; l=2640; i=pankaj.gupta@nxp.com; s=20240523; h=from:subject:message-id; bh=mAzNbzRWOh6wFu0SMI2UVtcJ4QuBAqfaQJrwAklpA20=; b=XikNrMjx4ba9m2jWXnH7XQggr85by1m8IpTAqNEHBkPeXvLvIJJjUIylRPKyTTRfdOvpB7xpj a4GpNKjoTpmA5cmfMFh05L/5BCewZI6iabxXbSZ6N8UPGllezrdkVGl X-Developer-Key: i=pankaj.gupta@nxp.com; a=ed25519; pk=OA0pBQoupy5lV0XfKzD8B0OOBVB6tpAoIf+0x1bYGRg= X-ClientProxiedBy: SG2PR02CA0037.apcprd02.prod.outlook.com (2603:1096:3:18::25) To DU2PR04MB8599.eurprd04.prod.outlook.com (2603:10a6:10:2da::7) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8599:EE_|AM0PR04MB6884:EE_ X-MS-Office365-Filtering-Correlation-Id: f04b428f-e1c5-4431-3618-08dcedfee2fb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|7416014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?NGAteGvCKoTy47n+0OQbzTmY30/gyd3?= =?utf-8?q?Nuj3/Um7w0pYhWQ1PGINJjt3Qjhm6E8cXqZCALZGrodCsgj6zZ+As/9WY8kIMpDTg?= =?utf-8?q?wpopjUiaxuzTk/uvPEL0yZ6oYoVSAkL1naKpn5jVdT83akGqEXxsF9DuLiEP/87hb?= =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?q?+qyZZpzKfBQWgpEclYD8k2NUiDbRE3Vgs1OMeBoUjOGcEEpAdjqmB1F//n2F1wE31?= =?utf-8?q?LxvBlPAmXfKHoZ3XCbfaFRNFITUr4VfJenS4wL5NKZWkbaJINHngscqe5IFJKKPEE?= =?utf-8?q?U3TDDcZO3tk05CAwCN5nkX28ItUHoJZUGGG17gPwe3wwWkMJvdA8A9DIPfPfpJVPF?= =?utf-8?q?9ssEYDT31qO4UzGuJeyf1BELzvDQwueUHNKhzQQeN3ZgDTsIbUkfdbEVfYpasGWQl?= =?utf-8?q?WJh9Fj9AhYnBiLDn6AVuv4maxDP+vpoyRLw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8599.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(1800799024)(7416014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?CV63gcsVeDUm+LzFr3Fb1J6VmhCs?= =?utf-8?q?cUzOvv6WazXV0sR4RkOw3W+Se11bLbG4K2QXs/Ro35z3hbiDYPmmxU3sx+X5VM5Lr?= =?utf-8?q?ZCRTo3Xq+AlGB8dUHQtwuHsGrjUfzcRbEk/nFrIQHcEkkHLTUQdRQ7dx+vJemIS8c?= =?utf-8?q?a05MVuvEHx0HlUlRITbV7sbtDfEVJkjKL77mhQDloHWXTkMdg0wDjUguHNJ1cy64t?= =?utf-8?q?CLq6cQbpEObTU/OyE7xah83sZ8OzUZsod7parU+sOJaip0aJyh/iA0P3BKLbLRzl2?= =?utf-8?q?2z3KgX+l38Mq462zzbcOA6LMMUbEJdhy3xu4Rjgm4FXyEFllP+mRoyfe9B/J6Y9Dm?= =?utf-8?q?9mBluC8vj2iGl5b1sqwgOeW1r+m569N7MC3RmTLQIV7VcyMvM3E+U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t8ajY?= =?utf-8?q?4AooB/c6B5JCKBNOZwWPMLM97hLHJrEAaBC/qsGjOAe67HtkUCp0AuoaMYcSsqpdn?= =?utf-8?q?Li+SfY57zJxQ4tuIFTGypn702iPYJ3pxHiAXV2FLObAcfFyYg+hXiSMmFP2SItesQ?= =?utf-8?q?zoXsqVP+X1G5oWBAxKxFsVFE5G/dvnbh+HcZYRIyc1hjj1NWwkfqr/dp11TDkIbJj?= =?utf-8?q?npUCCRkVEMusn2YsAAhpBZPT/pgphYwbp/YqV2HZ/61K5vOvDD/zXnqSCWjK+kpsO?= =?utf-8?q?jqHFlfzIBBxZ?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f04b428f-e1c5-4431-3618-08dcedfee2fb X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8599.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 16:23:36.6488 (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: O6AH+CQnqBYKvyk9u2b6FBb+InMbU/uiVSVe8opbmffUANrLZzKC1jdgc/pSJsNh1MIzvmw40UsjayieSh1YSg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6884 Add support for NXP secure enclave called EdgeLock Enclave firmware (se-fw) for imx8ulp-evk. EdgeLock Enclave has a hardware limitation of restricted access to DDR address: 0x80000000 to 0xAFFFFFFF, so reserve 1MB of DDR memory region from 0x80000000. Signed-off-by: Pankaj Gupta --- arch/arm64/boot/dts/freescale/imx8ulp-evk.dts | 17 ++++++++++++++++- arch/arm64/boot/dts/freescale/imx8ulp.dtsi | 13 +++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/freescale/imx8ulp-evk.dts b/arch/arm64/boot/dts/freescale/imx8ulp-evk.dts index e937e5f8fa8b..f5963f4043c4 100644 --- a/arch/arm64/boot/dts/freescale/imx8ulp-evk.dts +++ b/arch/arm64/boot/dts/freescale/imx8ulp-evk.dts @@ -1,6 +1,6 @@ // SPDX-License-Identifier: (GPL-2.0+ OR MIT) /* - * Copyright 2021 NXP + * Copyright 2021, 2024 NXP */ /dts-v1/; @@ -19,6 +19,17 @@ memory@80000000 { device_type = "memory"; reg = <0x0 0x80000000 0 0x80000000>; }; + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + ele_reserved: ele-reserved@90000000 { + compatible = "shared-dma-pool"; + reg = <0 0x90000000 0 0x100000>; + no-map; + }; + }; reserved-memory { #address-cells = <2>; @@ -204,6 +215,10 @@ &usdhc0 { status = "okay"; }; +&ele_if0 { + memory-region = <&ele_reserved>; +}; + &fec { pinctrl-names = "default", "sleep"; pinctrl-0 = <&pinctrl_enet>; diff --git a/arch/arm64/boot/dts/freescale/imx8ulp.dtsi b/arch/arm64/boot/dts/freescale/imx8ulp.dtsi index e32d5afcf4a9..f98629b7f4cc 100644 --- a/arch/arm64/boot/dts/freescale/imx8ulp.dtsi +++ b/arch/arm64/boot/dts/freescale/imx8ulp.dtsi @@ -1,6 +1,6 @@ // SPDX-License-Identifier: (GPL-2.0+ OR MIT) /* - * Copyright 2021 NXP + * Copyright 2021, 2024 NXP */ #include @@ -152,7 +152,7 @@ sosc: clock-sosc { #clock-cells = <0>; }; - sram@2201f000 { + sram0: sram@2201f000 { compatible = "mmio-sram"; reg = <0x0 0x2201f000 0x0 0x1000>; @@ -167,6 +167,8 @@ scmi_buf: scmi-sram-section@0 { }; firmware { + #address-cells = <1>; + #size-cells = <0>; scmi { compatible = "arm,scmi-smc"; arm,smc-id = <0xc20000fe>; @@ -184,6 +186,13 @@ scmi_sensor: protocol@15 { #thermal-sensor-cells = <1>; }; }; + + ele_if0: secure-enclave { + compatible = "fsl,imx8ulp-se"; + mbox-names = "tx", "rx"; + mboxes = <&s4muap 0 0>, <&s4muap 1 0>; + sram = <&sram0>; + }; }; cm33: remoteproc-cm33 { From patchwork Wed Oct 16 16:19:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 13838642 Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2083.outbound.protection.outlook.com [40.107.103.83]) (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 1E591210C1A for ; Wed, 16 Oct 2024 16:23:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.103.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729095828; cv=fail; b=sDzbi0gw0Q9sFl7kSZ1b71VTCLo8OWOdoLVZ4fOQywcsKG+hcFAs0BU+9Xt+SN97RMbPVFA/qlN/JcenvNpYPhPd0TnlCFA2Z4Ze93Y3thy08zKlXNZCEiw+1xKdrzY4tNmCAzrskB65WAqfWdG/Yf5tim2+zCtNh049VBZUpRI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729095828; c=relaxed/simple; bh=EpQSowENmv2+76MaNuhYEIyM0LGtLX4F0BAw4YtV4+0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=Deoa90+vZyaYvxg1T5VDnhh6RtHABHzEcSvzdnefNHpRXqYdmSx0sScnnnQ7lTfln0nng/jvUDhKChh54Zb1s2996YMovR+emM4DYCwl7TwSQG9cvwwZY4AJF1EheMwdGYCJA8YDpari9xCAKdRiHLD0K/kOfc098acoN6T/Gqw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=aypiDoo/; arc=fail smtp.client-ip=40.107.103.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="aypiDoo/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VoBBerNF+jO2tmm8fnPUhOqg/F1IxbVhqN40cEKIbAyICcWOpUbF0KkAqVHQodrroOPHBhZXotC9Ga3v+PdGRL5lmvvGBP5+EEcJcm3c7iRY8sUUCghV8n24VGaz+tRoMIUEmAvkrayZqGf8uV+1nAMMesD3tThiV0NLauABF525sL73JW7eoZ/WKy+y6V9nuySbWM/AFOdozj3ZKn18OjReJMJqBJ+hZ920KPsw0/S351t4LAM7ag4wfRREbL6wWTfuYvxuirlZClq+VEXdXbl/irgkMOsvklCIODgLcPFa8oRfMZvfQW/zXdU98EjfthFeD46HCSFHyZ6+EkgOAw== 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=llS7Hd4F08G34AzdOg3c2PFe2GXVhj9lg3S7I4WmT3o=; b=VpfC4FnZhpBd6pLxvak3Upz7TJuarwRzCw7rDshpQt3+EsRvLGg32LrWbPazUGiNU7IZY+tsdvWOffQbUSM/jDZ9RvEJvCLhqSuqYyEBTjMRWG7n2E5bvtd2i0fECAToyJHOFFEeqxnnPZGHmAWg9DLR8xs0rmCc+CvD5J0ZXR4S62QkHtnsZWTlwGTEpfDClWvBL61eMhM1gdCMBYxLvyrnoAe33Ll6HIeqtFNffe3KBSkWzjtGlSTg4jyQZQQ/eq0ridqDx3GlBOxEXoy/8oHFxQhtTQln1NgL6VxIiTIKiB1FbyRmiWIV8yyMpswk8IW0M8/yl7tmMHejs2XODA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=llS7Hd4F08G34AzdOg3c2PFe2GXVhj9lg3S7I4WmT3o=; b=aypiDoo/pduLrpAnVnJMp/nB/12tPqi+JuKGtYv6CKDSLeBnlESd94CgdVjmJ2pJpf+WPkBmi4HzeMl8nkjySIQ1hMezMa1aRpma5nUwWXzhs0wG01Fxy2P7xFUwoRiUdc2jwaj1iPT9B9wYLa/sXTAx/f/AvkXp9STv/kLRcaW7zJBFCNfg5viPoF3efc7sQZq4vrZwR1gAESXDOJSRlM2CTRD8D2UbxeG00xlkSkMKWSJ6O6tymE2VDudajYwhW2CF8kODYKz1TNFDxpoFtc37NJbLhhI5twW62Qh8esHIlILRco/t4e51bHKgLTXUFrjYUmNxaQI1DEhfQ4wg2Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8599.eurprd04.prod.outlook.com (2603:10a6:10:2da::7) by AM0PR04MB6884.eurprd04.prod.outlook.com (2603:10a6:208:183::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18; Wed, 16 Oct 2024 16:23:41 +0000 Received: from DU2PR04MB8599.eurprd04.prod.outlook.com ([fe80::763:eb3b:6607:1e72]) by DU2PR04MB8599.eurprd04.prod.outlook.com ([fe80::763:eb3b:6607:1e72%5]) with mapi id 15.20.8069.016; Wed, 16 Oct 2024 16:23:41 +0000 From: Pankaj Gupta Date: Wed, 16 Oct 2024 21:49:01 +0530 Subject: [PATCH v9 4/5] firmware: imx: add driver for NXP EdgeLock Enclave Message-Id: <20241016-imx-se-if-v9-4-fd8fa0c04eab@nxp.com> References: <20241016-imx-se-if-v9-0-fd8fa0c04eab@nxp.com> In-Reply-To: <20241016-imx-se-if-v9-0-fd8fa0c04eab@nxp.com> To: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Pankaj Gupta Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729095547; l=39201; i=pankaj.gupta@nxp.com; s=20240523; h=from:subject:message-id; bh=EpQSowENmv2+76MaNuhYEIyM0LGtLX4F0BAw4YtV4+0=; b=BJvt8paJdPNcPRFT+HGOdGO46zzqvzlGyVuaDonyivAwdNnzpBPtm/CK3/sQ3/mqAAePV1ZkK 8Tw3jKvMYTWCPP6VXtJIMJWmcuiFkNkz7nG2EOgOQUPBWv7m2xZCUKq X-Developer-Key: i=pankaj.gupta@nxp.com; a=ed25519; pk=OA0pBQoupy5lV0XfKzD8B0OOBVB6tpAoIf+0x1bYGRg= X-ClientProxiedBy: SG2PR02CA0037.apcprd02.prod.outlook.com (2603:1096:3:18::25) To DU2PR04MB8599.eurprd04.prod.outlook.com (2603:10a6:10:2da::7) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8599:EE_|AM0PR04MB6884:EE_ X-MS-Office365-Filtering-Correlation-Id: c0b91ca0-66f6-471c-3ac5-08dcedfee5bb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|7416014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?eUbKGE2z61TA1BvskBRhoN/A7vZ2Glz?= =?utf-8?q?ai0FXpyiFNZJYQnm++Vo0Dy267gm7SOdPUCsfSBSmaPfPFJ5x94lHpnXhUOPawa4O?= =?utf-8?q?0ijTJl0YUuu7Ni/VdK+PZAzMwAuo4qf9RlpYY4D4aCfK7PWQOtQ3GWhQhfjlCg2wH?= =?utf-8?q?ZbSqwvGo5NPEzCyk6Ff4VOPuxheibsxE6qUCMs2MKomacfg8+6Viv9OT/Mz1UH8jK?= =?utf-8?q?S1P7ehFV3U0UmRDVjtTXzLhSA2j7HIkx3cvEgcYT52dk+iiW9LDKf/MKn2GuNqw1x?= =?utf-8?q?s0Pe/zJ98GBJCjm3nbTQu5ar0xGAX0vc25i2P777bgi839OoA3K3ocQzbYh290xH5?= =?utf-8?q?2gonr1TgI6hBAGSbEvD1/UjsEzNALf/PGggtoMs3P4bzLf1eq0KxAAa19Oe5L/Ur3?= =?utf-8?q?bjs8iXt/fdtpvVosvc23T9hjkVzhl+zQ0mq4QTwMwOfy6u/KBywqyZ2dyt9meOd0h?= =?utf-8?q?dPJgtaflAfkp9lxVEp4suXuZYZRVggd9N4jAU4jvvl7ScTWfQVOXI9YdCBMD3LJzl?= =?utf-8?q?dZ/WDkPAGFwRQLMSbeYyst9DG+Bw9XuYB2t7a+1EH7kKR7xYx6jiUUWcXomBqKqMg?= =?utf-8?q?2QJvTZDniAVlSq1Z6ynnRGnlusqloDw3b6bYMlCgBMDpuW1AFawULWCV0xyqw+oyx?= =?utf-8?q?5KlamcJAJQ355cQTIhf9D9BBWnz6MAe50q/HAilYqlz3uOK7cSVoCgiz1S4w7hE3j?= =?utf-8?q?Ji0uZgnNoPxZyG5GhhSaEJMgt7ID9KzhGOh7wje2Q/1suqS0M2w2lYAhRcHA911KR?= =?utf-8?q?WhCtpQjqMSeiX63rPPkx70cgiH2peZVEQam2rySxzMYB3qlTIYO80lb+JB8dhmUqI?= =?utf-8?q?XXlXlF6+H9rSsn6mST67jPsDWWGqNRRjhv0kj9+z6F0xQjTXh93QBWrCpBl4nubNr?= =?utf-8?q?EbwpN8DARBNXkqQnT/NkN8Tui4Dgo4t4GIY89IwI006WIZJ1Y5v9wZZfr1MQNjj6a?= =?utf-8?q?3U8Kes96cb4xBANnbyo+U+ze9mTiRmR6fzEI9NeQGc1U1vZTS40uXkmO6MhxfzRRy?= =?utf-8?q?87eJ3yh+eG3y+Kx6+BgAi0dOhGNibaKIYjTj5y+MprQ8N3QHdvzR2kVt8p5/sP+Sk?= =?utf-8?q?y5ryB9jYDwIgZmBpdD4AztD75EgqgwLbfFyL33kPSHjz2RxRwvm4rEw/hV1tGf3U8?= =?utf-8?q?VZ1D5olRcdrUsvPp1kMDUNtQCtHgg1Q7ZVKfXA+IPNMXiuqGvsiSavspOFpcfLj+O?= =?utf-8?q?K/kDFOQr1B7eP1O2fJqvPhV5xE14j1gPv18aAZxuAbgh5K9YbRga9/ha1cnDPNaae?= =?utf-8?q?Qr3/jLr10htFtUmRTUp3psneANe9LOoGX5g=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8599.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(1800799024)(7416014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?1xdLfObtl7aYF6raCZfuY+/uIJ8A?= =?utf-8?q?pBXJVKoVIlFkFOWc6c3piRWtChIsrMIFojNr1N01iT4W1+2MNRHmE2jdBedc/kkXx?= =?utf-8?q?HYMBoq8rmTrrS1lq0Bm1Pe/X+zL/k7X3ACut5eEVXrfWXmUoTiJxjlDoWHEwIOf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?= =?utf-8?q?sz5B4ttyVfYHqhx289s4YnuciDkidwbqmyS2dnVgIu5gNYDwlLQGrJMHbJiz4gUAh?= =?utf-8?q?67q8Y6kHRYW+p6xAZpgrM86/5FEf3fa6RmRtaGronl9Xkgm6TsFCO02tAwoM6reAg?= =?utf-8?q?Ghd2kAn1SAm0xR5xHOtWGlVX0va7ZRt6a+iN/6SantErP7TcauCh0OZILOvuiHXxF?= =?utf-8?q?D/85pusV9i+jaaz5crVlgBz5zat6QhQ/TI/0WafFbxCMMDd0jSLUVyaULPMm45MX3?= =?utf-8?q?PTCSSgEv2hmiJuuKWlFAFTOQlhGLpPwpBFWYYIdC4WD/x63xDNvYaUnLfo0X3ScO6?= =?utf-8?q?SfrY22eIZTLIqRjOoBS7ZYt1hJmf0Bm2IGzVeDugPXISqRJ06VHDkEeoW83whijx8?= =?utf-8?q?Somg63cuwjTMFrEH6dkHhpFJrf26JO72FEUu0FsgxUSQLNrSYwSRiM9rPL2ReM/zJ?= =?utf-8?q?QlFDUJiSpmFL0voPn0ZbNHgQ+MhWpqY/DFIwphhHvUTVfwJAEb/i8nenUqcK0errk?= =?utf-8?q?Y8VoaFUwXCUS?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0b91ca0-66f6-471c-3ac5-08dcedfee5bb X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8599.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 16:23:41.2366 (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: sd5rukU3jTREg9hPr6uQAwnX23SsUfkY+TqlJNOoJ30r4+c/lNWFFBOs+rLPXFNsge4z3T3fYqBd7g6GkVAHAg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6884 NXP hardware IP(s) for secure-enclaves like Edgelock Enclave(ELE), are embedded in the SoC to support the features like HSM, SHE & V2X, using message based communication interface. The secure enclave FW communicates on a dedicated messaging unit(MU) based interface(s) with application core, where kernel is running. It exists on specific i.MX processors. e.g. i.MX8ULP, i.MX93. This patch adds the driver for communication interface to secure-enclave, for exchanging messages with NXP secure enclave HW IP(s) like EdgeLock Enclave (ELE) from Kernel-space, used by kernel management layers like - DM-Crypt. Signed-off-by: Pankaj Gupta --- drivers/firmware/imx/Kconfig | 13 + drivers/firmware/imx/Makefile | 2 + drivers/firmware/imx/ele_base_msg.c | 279 ++++++++++++++++++ drivers/firmware/imx/ele_base_msg.h | 94 ++++++ drivers/firmware/imx/ele_common.c | 320 +++++++++++++++++++++ drivers/firmware/imx/ele_common.h | 51 ++++ drivers/firmware/imx/se_ctrl.c | 552 ++++++++++++++++++++++++++++++++++++ drivers/firmware/imx/se_ctrl.h | 94 ++++++ include/linux/firmware/imx/se_api.h | 14 + 9 files changed, 1419 insertions(+) diff --git a/drivers/firmware/imx/Kconfig b/drivers/firmware/imx/Kconfig index 477d3f32d99a..ccd9f9e0652e 100644 --- a/drivers/firmware/imx/Kconfig +++ b/drivers/firmware/imx/Kconfig @@ -33,3 +33,16 @@ config IMX_SCMI_MISC_DRV core that could provide misc functions such as board control. This driver can also be built as a module. + +config IMX_SEC_ENCLAVE + tristate "i.MX Embedded Secure Enclave - EdgeLock Enclave Firmware driver." + depends on IMX_MBOX && ARCH_MXC && ARM64 + select FW_LOADER + default m if ARCH_MXC + + help + It is possible to use APIs exposed by the iMX Secure Enclave HW IP called: + - EdgeLock Enclave Firmware (for i.MX8ULP, i.MX93), + like base, HSM, V2X & SHE using the SAB protocol via the shared Messaging + Unit. This driver exposes these interfaces via a set of file descriptors + allowing to configure shared memory, send and receive messages. diff --git a/drivers/firmware/imx/Makefile b/drivers/firmware/imx/Makefile index 8d046c341be8..4e1d2706535d 100644 --- a/drivers/firmware/imx/Makefile +++ b/drivers/firmware/imx/Makefile @@ -2,3 +2,5 @@ obj-$(CONFIG_IMX_DSP) += imx-dsp.o obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o rm.o imx-scu-soc.o obj-${CONFIG_IMX_SCMI_MISC_DRV} += sm-misc.o +sec_enclave-objs = se_ctrl.o ele_common.o ele_base_msg.o +obj-${CONFIG_IMX_SEC_ENCLAVE} += sec_enclave.o diff --git a/drivers/firmware/imx/ele_base_msg.c b/drivers/firmware/imx/ele_base_msg.c new file mode 100644 index 000000000000..53c83eddd52a --- /dev/null +++ b/drivers/firmware/imx/ele_base_msg.c @@ -0,0 +1,279 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 NXP + */ + +#include + +#include +#include +#include + +#include "ele_base_msg.h" +#include "ele_common.h" + +int ele_get_info(struct se_if_priv *priv, struct ele_dev_info *s_info) +{ + struct se_api_msg *tx_msg __free(kfree) = NULL; + struct se_api_msg *rx_msg __free(kfree) = NULL; + dma_addr_t get_info_addr = 0; + u32 *get_info_data = NULL; + int ret = 0; + + if (!priv) { + ret = -EINVAL; + return ret; + } + + memset(s_info, 0x0, sizeof(*s_info)); + + if (priv->mem_pool) + get_info_data = gen_pool_dma_alloc(priv->mem_pool, + ELE_GET_INFO_BUFF_SZ, + &get_info_addr); + else + get_info_data = dma_alloc_coherent(priv->dev, + ELE_GET_INFO_BUFF_SZ, + &get_info_addr, + GFP_KERNEL); + if (!get_info_data) { + ret = -ENOMEM; + dev_dbg(priv->dev, + "%s: Failed to allocate get_info_addr.\n", + __func__); + return ret; + } + + tx_msg = kzalloc(ELE_GET_INFO_REQ_MSG_SZ, GFP_KERNEL); + if (!tx_msg) { + ret = -ENOMEM; + goto exit; + } + + rx_msg = kzalloc(ELE_GET_INFO_RSP_MSG_SZ, GFP_KERNEL); + if (!rx_msg) { + ret = -ENOMEM; + goto exit; + } + + ret = se_fill_cmd_msg_hdr(priv, + (struct se_msg_hdr *)&tx_msg->header, + ELE_GET_INFO_REQ, + ELE_GET_INFO_REQ_MSG_SZ, + true); + if (ret) + goto exit; + + tx_msg->data[0] = upper_32_bits(get_info_addr); + tx_msg->data[1] = lower_32_bits(get_info_addr); + tx_msg->data[2] = sizeof(*s_info); + ret = ele_msg_send_rcv(priv, + tx_msg, + ELE_GET_INFO_REQ_MSG_SZ, + rx_msg, + ELE_GET_INFO_RSP_MSG_SZ); + if (ret < 0) + goto exit; + + ret = se_val_rsp_hdr_n_status(priv, + rx_msg, + ELE_GET_INFO_REQ, + ELE_GET_INFO_RSP_MSG_SZ, + true); + + memcpy(s_info, get_info_data, sizeof(*s_info)); + +exit: + if (priv->mem_pool) + gen_pool_free(priv->mem_pool, + (u64) get_info_data, + ELE_GET_INFO_BUFF_SZ); + else + dma_free_coherent(priv->dev, + ELE_GET_INFO_BUFF_SZ, + get_info_data, + get_info_addr); + + return ret; +} + +int ele_fetch_soc_info(struct se_if_priv *priv, u16 *soc_rev, u64 *serial_num) +{ + struct ele_dev_info s_info = {0}; + int err; + + err = ele_get_info(priv, &s_info); + if (err < 0) + return err; + + if (soc_rev) + *soc_rev = s_info.d_info.soc_rev; + if (serial_num) + *serial_num = GET_SERIAL_NUM_FROM_UID(s_info.d_info.uid, MAX_UID_SIZE >> 2); + + return err; +} + +int ele_ping(struct se_if_priv *priv) +{ + struct se_api_msg *tx_msg __free(kfree) = NULL; + struct se_api_msg *rx_msg __free(kfree) = NULL; + int ret = 0; + + if (!priv) { + ret = -EINVAL; + goto exit; + } + + tx_msg = kzalloc(ELE_PING_REQ_SZ, GFP_KERNEL); + if (!tx_msg) { + ret = -ENOMEM; + goto exit; + } + + rx_msg = kzalloc(ELE_PING_RSP_SZ, GFP_KERNEL); + if (!rx_msg) { + ret = -ENOMEM; + goto exit; + } + + ret = se_fill_cmd_msg_hdr(priv, + (struct se_msg_hdr *)&tx_msg->header, + ELE_PING_REQ, ELE_PING_REQ_SZ, true); + if (ret) { + dev_err(priv->dev, "Error: se_fill_cmd_msg_hdr failed.\n"); + goto exit; + } + + ret = ele_msg_send_rcv(priv, + tx_msg, + ELE_PING_REQ_SZ, + rx_msg, + ELE_PING_RSP_SZ); + if (ret < 0) + goto exit; + + ret = se_val_rsp_hdr_n_status(priv, + rx_msg, + ELE_PING_REQ, + ELE_PING_RSP_SZ, + true); +exit: + return ret; +} + +int ele_service_swap(struct se_if_priv *priv, + phys_addr_t addr, + u32 addr_size, u16 flag) +{ + struct se_api_msg *tx_msg __free(kfree) = NULL; + struct se_api_msg *rx_msg __free(kfree) = NULL; + int ret = 0; + + if (!priv) { + ret = -EINVAL; + goto exit; + } + + tx_msg = kzalloc(ELE_SERVICE_SWAP_REQ_MSG_SZ, GFP_KERNEL); + if (!tx_msg) { + ret = -ENOMEM; + goto exit; + } + + rx_msg = kzalloc(ELE_SERVICE_SWAP_RSP_MSG_SZ, GFP_KERNEL); + if (!rx_msg) { + ret = -ENOMEM; + goto exit; + } + + ret = se_fill_cmd_msg_hdr(priv, + (struct se_msg_hdr *)&tx_msg->header, + ELE_SERVICE_SWAP_REQ, + ELE_SERVICE_SWAP_REQ_MSG_SZ, true); + if (ret) + goto exit; + + tx_msg->data[0] = flag; + tx_msg->data[1] = addr_size; + tx_msg->data[2] = ELE_NONE_VAL; + tx_msg->data[3] = lower_32_bits(addr); + tx_msg->data[4] = se_add_msg_crc((uint32_t *)&tx_msg[0], + ELE_SERVICE_SWAP_REQ_MSG_SZ); + ret = ele_msg_send_rcv(priv, + tx_msg, + ELE_SERVICE_SWAP_REQ_MSG_SZ, + rx_msg, + ELE_SERVICE_SWAP_RSP_MSG_SZ); + if (ret < 0) + goto exit; + + ret = se_val_rsp_hdr_n_status(priv, + rx_msg, + ELE_SERVICE_SWAP_REQ, + ELE_SERVICE_SWAP_RSP_MSG_SZ, + true); + if (ret) + goto exit; + + if (flag == ELE_IMEM_EXPORT) + ret = rx_msg->data[1]; + else + ret = 0; + +exit: + + return ret; +} + +int ele_fw_authenticate(struct se_if_priv *priv, phys_addr_t addr) +{ + struct se_api_msg *tx_msg __free(kfree) = NULL; + struct se_api_msg *rx_msg __free(kfree) = NULL; + int ret = 0; + + if (!priv) { + ret = -EINVAL; + goto exit; + } + + tx_msg = kzalloc(ELE_FW_AUTH_REQ_SZ, GFP_KERNEL); + if (!tx_msg) { + ret = -ENOMEM; + goto exit; + } + + rx_msg = kzalloc(ELE_FW_AUTH_RSP_MSG_SZ, GFP_KERNEL); + if (!rx_msg) { + ret = -ENOMEM; + goto exit; + } + + ret = se_fill_cmd_msg_hdr(priv, + (struct se_msg_hdr *)&tx_msg->header, + ELE_FW_AUTH_REQ, + ELE_FW_AUTH_REQ_SZ, + true); + if (ret) + goto exit; + + tx_msg->data[1] = upper_32_bits(addr); + tx_msg->data[0] = lower_32_bits(addr); + tx_msg->data[2] = addr; + + ret = ele_msg_send_rcv(priv, + tx_msg, + ELE_FW_AUTH_REQ_SZ, + rx_msg, + ELE_FW_AUTH_RSP_MSG_SZ); + if (ret < 0) + goto exit; + + ret = se_val_rsp_hdr_n_status(priv, + rx_msg, + ELE_FW_AUTH_REQ, + ELE_FW_AUTH_RSP_MSG_SZ, + true); +exit: + return ret; +} diff --git a/drivers/firmware/imx/ele_base_msg.h b/drivers/firmware/imx/ele_base_msg.h new file mode 100644 index 000000000000..e390d35fc787 --- /dev/null +++ b/drivers/firmware/imx/ele_base_msg.h @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2024 NXP + * + * Header file for the EdgeLock Enclave Base API(s). + */ + +#ifndef ELE_BASE_MSG_H +#define ELE_BASE_MSG_H + +#include +#include + +#include "se_ctrl.h" + +#define ELE_NONE_VAL 0x0 + +#define ELE_GET_INFO_REQ 0xDA +#define ELE_GET_INFO_REQ_MSG_SZ 0x10 +#define ELE_GET_INFO_RSP_MSG_SZ 0x08 + +#define SOC_ID_MASK 0x0000FFFF + +#define MAX_UID_SIZE (16) +#define DEV_GETINFO_ROM_PATCH_SHA_SZ (32) +#define DEV_GETINFO_FW_SHA_SZ (32) +#define DEV_GETINFO_OEM_SRKH_SZ (64) +#define DEV_GETINFO_MIN_VER_MASK 0xFF +#define DEV_GETINFO_MAJ_VER_MASK 0xFF00 +#define ELE_DEV_INFO_EXTRA_SZ 0x60 + +struct dev_info { + uint8_t cmd; + uint8_t ver; + uint16_t length; + uint16_t soc_id; + uint16_t soc_rev; + uint16_t lmda_val; + uint8_t ssm_state; + uint8_t dev_atts_api_ver; + uint8_t uid[MAX_UID_SIZE]; + uint8_t sha_rom_patch[DEV_GETINFO_ROM_PATCH_SHA_SZ]; + uint8_t sha_fw[DEV_GETINFO_FW_SHA_SZ]; +}; + +struct dev_addn_info { + uint8_t oem_srkh[DEV_GETINFO_OEM_SRKH_SZ]; + uint8_t trng_state; + uint8_t csal_state; + uint8_t imem_state; + uint8_t reserved2; +}; + +struct ele_dev_info { + struct dev_info d_info; + struct dev_addn_info d_addn_info; +}; + +#define ELE_GET_INFO_BUFF_SZ (sizeof(struct ele_dev_info) \ + + ELE_DEV_INFO_EXTRA_SZ) + +#define GET_SERIAL_NUM_FROM_UID(x, uid_word_sz) \ + (((u64)(((u32 *)(x))[(uid_word_sz) - 1]) << 32) | ((u32 *)(x))[0]) + +#define ELE_DEBUG_DUMP_REQ 0x21 +#define ELE_DEBUG_DUMP_RSP_SZ 0x14 + +#define ELE_PING_REQ 0x01 +#define ELE_PING_REQ_SZ 0x04 +#define ELE_PING_RSP_SZ 0x08 + +#define ELE_SERVICE_SWAP_REQ 0xDF +#define ELE_SERVICE_SWAP_REQ_MSG_SZ 0x18 +#define ELE_SERVICE_SWAP_RSP_MSG_SZ 0x0C +#define ELE_IMEM_SIZE 0x10000 +#define ELE_IMEM_STATE_OK 0xCA +#define ELE_IMEM_STATE_BAD 0xFE +#define ELE_IMEM_STATE_WORD 0x27 +#define ELE_IMEM_STATE_MASK 0x00ff0000 +#define ELE_IMEM_EXPORT 0x1 +#define ELE_IMEM_IMPORT 0x2 + +#define ELE_FW_AUTH_REQ 0x02 +#define ELE_FW_AUTH_REQ_SZ 0x10 +#define ELE_FW_AUTH_RSP_MSG_SZ 0x08 + +int ele_get_info(struct se_if_priv *priv, struct ele_dev_info *s_info); +int ele_fetch_soc_info(struct se_if_priv *priv, u16 *soc_rev, u64 *serial_num); +int ele_ping(struct se_if_priv *priv); +int ele_service_swap(struct se_if_priv *priv, + phys_addr_t addr, + u32 addr_size, u16 flag); +int ele_fw_authenticate(struct se_if_priv *priv, phys_addr_t addr); +#endif diff --git a/drivers/firmware/imx/ele_common.c b/drivers/firmware/imx/ele_common.c new file mode 100644 index 000000000000..f7c760bbc7a3 --- /dev/null +++ b/drivers/firmware/imx/ele_common.c @@ -0,0 +1,320 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 NXP + */ + +#include "ele_base_msg.h" +#include "ele_common.h" + +u32 se_add_msg_crc(u32 *msg, u32 msg_len) +{ + u32 nb_words = msg_len / (u32)sizeof(u32); + u32 crc = 0; + u32 i; + + for (i = 0; i < nb_words - 1; i++) + crc ^= *(msg + i); + + return crc; +} + +int ele_msg_rcv(struct se_if_priv *priv, + struct se_clbk_handle *se_clbk_hdl) +{ + int err = 0; + + do { + /* If callback is executed before entrying to wait state, + * it will immediately come out after entering the wait state, + * but completion_done(&se_clbk_hdl->done), will return false + * after exiting the wait state, with err = 0. + */ + err = wait_for_completion_interruptible(&se_clbk_hdl->done); + if (err == -ERESTARTSYS) { + if (priv->waiting_rsp_clbk_hdl.rx_msg) { + priv->waiting_rsp_clbk_hdl.signal_rcvd = true; + continue; + } + dev_err(priv->dev, + "Err[0x%x]:Interrupted by signal.\n", + err); + err = -EINTR; + break; + } + } while (err != 0); + + return err ? err : se_clbk_hdl->rx_msg_sz; +} + +int ele_msg_send(struct se_if_priv *priv, + void *tx_msg, + int tx_msg_sz) +{ + struct se_msg_hdr *header; + int err; + + header = tx_msg; + + /* + * Check that the size passed as argument matches the size + * carried in the message. + */ + if (header->size << 2 != tx_msg_sz) { + err = -EINVAL; + dev_err(priv->dev, + "User buf hdr: 0x%x, sz mismatced with input-sz (%d != %d).", + *(u32 *)header, + header->size << 2, tx_msg_sz); + goto exit; + } + + err = mbox_send_message(priv->tx_chan, tx_msg); + if (err < 0) { + dev_err(priv->dev, "Error: mbox_send_message failure.\n"); + return err; + } + err = tx_msg_sz; + +exit: + return err; +} + +/* API used for send/receive blocking call. */ +int ele_msg_send_rcv(struct se_if_priv *priv, + void *tx_msg, + int tx_msg_sz, + void *rx_msg, + int exp_rx_msg_sz) +{ + int err; + + guard(mutex)(&priv->se_if_cmd_lock); + + priv->waiting_rsp_clbk_hdl.rx_msg_sz = exp_rx_msg_sz; + priv->waiting_rsp_clbk_hdl.rx_msg = rx_msg; + + err = ele_msg_send(priv, tx_msg, tx_msg_sz); + if (err < 0) + goto exit; + + err = ele_msg_rcv(priv, &priv->waiting_rsp_clbk_hdl); + + if (priv->waiting_rsp_clbk_hdl.signal_rcvd) { + err = -EINTR; + priv->waiting_rsp_clbk_hdl.signal_rcvd = false; + } + +exit: + return err; +} + +static bool exception_for_size(struct se_if_priv *priv, + struct se_msg_hdr *header) +{ + /* List of API(s) that can be accepte variable length + * response buffer. + */ + if (header->command == ELE_DEBUG_DUMP_REQ && + header->ver == priv->if_defs->base_api_ver && + header->size >= 0 && + header->size <= ELE_DEBUG_DUMP_RSP_SZ) + return true; + + return false; +} + +/* + * Callback called by mailbox FW, when data is received. + */ +void se_if_rx_callback(struct mbox_client *mbox_cl, void *msg) +{ + struct se_clbk_handle *se_clbk_hdl; + struct device *dev = mbox_cl->dev; + struct se_msg_hdr *header; + struct se_if_priv *priv; + u32 rx_msg_sz; + + priv = dev_get_drvdata(dev); + + /* The function can be called with NULL msg */ + if (!msg) { + dev_err(dev, "Message is invalid\n"); + return; + } + + header = msg; + rx_msg_sz = header->size << 2; + + /* Incoming command: wake up the receiver if any. */ + if (header->tag == priv->if_defs->cmd_tag) { + se_clbk_hdl = &priv->cmd_receiver_clbk_hdl; + dev_dbg(dev, + "Selecting cmd receiver for mesg header:0x%x.", + *(u32 *) header); + + /* Pre-allocated buffer of MAX_NVM_MSG_LEN + * as the NVM command are initiated by FW. + * Size is revealed as part of this call function. + */ + if (rx_msg_sz > MAX_NVM_MSG_LEN) { + dev_err(dev, + "CMD-RCVER NVM: hdr(0x%x) with different sz(%d != %d).\n", + *(u32 *) header, + rx_msg_sz, se_clbk_hdl->rx_msg_sz); + + se_clbk_hdl->rx_msg_sz = MAX_NVM_MSG_LEN; + } + se_clbk_hdl->rx_msg_sz = rx_msg_sz; + + } else if (header->tag == priv->if_defs->rsp_tag) { + se_clbk_hdl = &priv->waiting_rsp_clbk_hdl; + dev_dbg(dev, + "Selecting resp waiter for mesg header:0x%x.", + *(u32 *) header); + + if (rx_msg_sz != se_clbk_hdl->rx_msg_sz + && !exception_for_size(priv, header)) { + dev_err(dev, + "Rsp to CMD: hdr(0x%x) with different sz(%d != %d).\n", + *(u32 *) header, + rx_msg_sz, se_clbk_hdl->rx_msg_sz); + + se_clbk_hdl->rx_msg_sz = min(rx_msg_sz, se_clbk_hdl->rx_msg_sz); + } + } else { + dev_err(dev, "Failed to select a device for message: %.8x\n", + *((u32 *) header)); + return; + } + + memcpy(se_clbk_hdl->rx_msg, msg, se_clbk_hdl->rx_msg_sz); + + /* Allow user to read */ + complete(&se_clbk_hdl->done); +} + +int se_val_rsp_hdr_n_status(struct se_if_priv *priv, + struct se_api_msg *msg, + uint8_t msg_id, + uint8_t sz, + bool is_base_api) +{ + u32 status; + struct se_msg_hdr *header = &msg->header; + + if (header->tag != priv->if_defs->rsp_tag) { + dev_err(priv->dev, + "MSG[0x%x] Hdr: Resp tag mismatch. (0x%x != 0x%x)", + msg_id, header->tag, priv->if_defs->rsp_tag); + return -EINVAL; + } + + if (header->command != msg_id) { + dev_err(priv->dev, + "MSG Header: Cmd id mismatch. (0x%x != 0x%x)", + header->command, msg_id); + return -EINVAL; + } + + if (header->size != (sz >> 2)) { + dev_err(priv->dev, + "MSG[0x%x] Hdr: Cmd size mismatch. (0x%x != 0x%x)", + msg_id, header->size, (sz >> 2)); + return -EINVAL; + } + + if (is_base_api && (header->ver != priv->if_defs->base_api_ver)) { + dev_err(priv->dev, + "MSG[0x%x] Hdr: Base API Vers mismatch. (0x%x != 0x%x)", + msg_id, header->ver, priv->if_defs->base_api_ver); + return -EINVAL; + } else if (!is_base_api && header->ver != priv->if_defs->fw_api_ver) { + dev_err(priv->dev, + "MSG[0x%x] Hdr: FW API Vers mismatch. (0x%x != 0x%x)", + msg_id, header->ver, priv->if_defs->fw_api_ver); + return -EINVAL; + } + + status = RES_STATUS(msg->data[0]); + if (status != priv->if_defs->success_tag) { + dev_err(priv->dev, "Command Id[%d], Response Failure = 0x%x", + header->command, status); + return -EPERM; + } + + return 0; +} + +int se_save_imem_state(struct se_if_priv *priv, struct se_imem_buf *imem) +{ + int ret; + + /* EXPORT command will save encrypted IMEM to given address, + * so later in resume, IMEM can be restored from the given + * address. + * + * Size must be at least 64 kB. + */ + ret = ele_service_swap(priv, + imem->phyaddr, + ELE_IMEM_SIZE, + ELE_IMEM_EXPORT); + if (ret < 0) + dev_err(priv->dev, "Failed to export IMEM\n"); + else + dev_info(priv->dev, + "Exported %d bytes of encrypted IMEM\n", + ret); + + return ret; +} + +int se_restore_imem_state(struct se_if_priv *priv, struct se_imem_buf *imem) +{ + struct ele_dev_info s_info; + int ret; + + /* get info from ELE */ + ret = ele_get_info(priv, &s_info); + if (ret) { + dev_err(priv->dev, "Failed to get info from ELE.\n"); + return ret; + } + imem->state = s_info.d_addn_info.imem_state; + + /* Get IMEM state, if 0xFE then import IMEM */ + if (s_info.d_addn_info.imem_state == ELE_IMEM_STATE_BAD) { + /* IMPORT command will restore IMEM from the given + * address, here size is the actual size returned by ELE + * during the export operation + */ + ret = ele_service_swap(priv, + imem->phyaddr, + imem->size, + ELE_IMEM_IMPORT); + if (ret) { + dev_err(priv->dev, "Failed to import IMEM\n"); + goto exit; + } + } else + goto exit; + + /* After importing IMEM, check if IMEM state is equal to 0xCA + * to ensure IMEM is fully loaded and + * ELE functionality can be used. + */ + ret = ele_get_info(priv, &s_info); + if (ret) { + dev_err(priv->dev, "Failed to get info from ELE.\n"); + goto exit; + } + imem->state = s_info.d_addn_info.imem_state; + + if (s_info.d_addn_info.imem_state == ELE_IMEM_STATE_OK) + dev_info(priv->dev, "Successfully restored IMEM\n"); + else + dev_err(priv->dev, "Failed to restore IMEM\n"); + +exit: + return ret; +} diff --git a/drivers/firmware/imx/ele_common.h b/drivers/firmware/imx/ele_common.h new file mode 100644 index 000000000000..3d8b6f83fb9d --- /dev/null +++ b/drivers/firmware/imx/ele_common.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2024 NXP + */ + + +#ifndef __ELE_COMMON_H__ +#define __ELE_COMMON_H__ + +#include "se_ctrl.h" + +#define ELE_SUCCESS_IND 0xD6 + +#define IMX_ELE_FW_DIR "imx/ele/" + +uint32_t se_add_msg_crc(uint32_t *msg, uint32_t msg_len); +int ele_msg_rcv(struct se_if_priv *priv, + struct se_clbk_handle *se_clbk_hdl); +int ele_msg_send(struct se_if_priv *priv, + void *tx_msg, + int tx_msg_sz); +int ele_msg_send_rcv(struct se_if_priv *priv, + void *tx_msg, + int tx_msg_sz, + void *rx_msg, + int exp_rx_msg_sz); +void se_if_rx_callback(struct mbox_client *mbox_cl, void *msg); +int se_val_rsp_hdr_n_status(struct se_if_priv *priv, + struct se_api_msg *msg, + uint8_t msg_id, + uint8_t sz, + bool is_base_api); + +/* Fill a command message header with a given command ID and length in bytes. */ +static inline int se_fill_cmd_msg_hdr(struct se_if_priv *priv, + struct se_msg_hdr *hdr, + u8 cmd, u32 len, + bool is_base_api) +{ + hdr->tag = priv->if_defs->cmd_tag; + hdr->ver = (is_base_api) ? priv->if_defs->base_api_ver : priv->if_defs->fw_api_ver; + hdr->command = cmd; + hdr->size = len >> 2; + + return 0; +} + +int se_save_imem_state(struct se_if_priv *priv, struct se_imem_buf *imem); +int se_restore_imem_state(struct se_if_priv *priv, struct se_imem_buf *imem); + +#endif /*__ELE_COMMON_H__ */ diff --git a/drivers/firmware/imx/se_ctrl.c b/drivers/firmware/imx/se_ctrl.c new file mode 100644 index 000000000000..40d815d0ac9b --- /dev/null +++ b/drivers/firmware/imx/se_ctrl.c @@ -0,0 +1,552 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 NXP + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ele_base_msg.h" +#include "ele_common.h" +#include "se_ctrl.h" + +#define MBOX_TX_NAME "tx" +#define MBOX_RX_NAME "rx" +#define SE_TYPE_HSM "hsm" + +struct se_fw_load_info { + const u8 *prim_fw_nm_in_rfs; + const u8 *seco_fw_nm_in_rfs; + struct mutex se_fw_load; + bool is_fw_loaded; + bool handle_susp_resm; + struct se_imem_buf imem; +}; + +struct se_if_node_info { + u8 se_if_id; + u8 se_if_did; + struct se_if_defines if_defs; + u8 *se_name; + u8 *pool_name; + bool soc_register; + bool reserved_dma_ranges; + int (*se_fetch_soc_info)(struct se_if_priv *priv, u16 *soc_rev, u64 *serial_num); +}; + +struct se_if_node_info_list { + const u8 num_mu; + const u16 soc_id; + struct se_fw_load_info load_hsm_fw; + const struct se_if_node_info info[]; +}; + +static u16 se_soc_rev; +static struct se_if_node_info_list imx8ulp_info = { + .num_mu = 1, + .soc_id = SOC_ID_OF_IMX8ULP, + .load_hsm_fw = { + .prim_fw_nm_in_rfs = IMX_ELE_FW_DIR + "mx8ulpa2-ahab-container.img", + .seco_fw_nm_in_rfs = IMX_ELE_FW_DIR + "mx8ulpa2ext-ahab-container.img", + .is_fw_loaded = false, + .handle_susp_resm = true, + .imem = { + .state = ELE_IMEM_STATE_OK, + }, + }, + .info = { + { + .se_if_id = 0, + .se_if_did = 7, + .if_defs = { + .cmd_tag = 0x17, + .rsp_tag = 0xe1, + .success_tag = ELE_SUCCESS_IND, + .base_api_ver = MESSAGING_VERSION_6, + .fw_api_ver = MESSAGING_VERSION_7, + }, + .se_name = SE_TYPE_HSM"1", + .pool_name = "sram", + .soc_register = true, + .reserved_dma_ranges = true, + .se_fetch_soc_info = ele_fetch_soc_info, + }, + }, +}; + +static struct se_if_node_info_list imx93_info = { + .num_mu = 1, + .soc_id = SOC_ID_OF_IMX93, + .load_hsm_fw = { + .prim_fw_nm_in_rfs = NULL, + .seco_fw_nm_in_rfs = NULL, + .is_fw_loaded = true, + .handle_susp_resm = false, + }, + .info = { + { + .se_if_id = 2, + .se_if_did = 3, + .if_defs = { + .cmd_tag = 0x17, + .rsp_tag = 0xe1, + .success_tag = ELE_SUCCESS_IND, + .base_api_ver = MESSAGING_VERSION_6, + .fw_api_ver = MESSAGING_VERSION_7, + }, + .se_name = SE_TYPE_HSM"1", + .reserved_dma_ranges = true, + .soc_register = true, + }, + }, +}; + +static const struct of_device_id se_match[] = { + { .compatible = "fsl,imx8ulp-se", .data = (void *)&imx8ulp_info}, + { .compatible = "fsl,imx93-se", .data = (void *)&imx93_info}, + {}, +}; + +static const struct se_if_node_info + *get_se_if_node_info(const struct se_if_node_info_list *info_list, + const u32 idx) +{ + return &info_list->info[idx]; +} + +static int se_soc_info(struct se_if_priv *priv) +{ + const struct se_if_node_info *info; + struct se_if_node_info_list *info_list; + struct soc_device_attribute *attr; + struct soc_device *sdev; + u64 serial_num; + int err = 0; + + info = container_of(priv->if_defs, + typeof(*info), + if_defs); + info_list = container_of(info, + typeof(*info_list), + info[info->se_if_id]); + + /* This function should be called once. + * Check if the se_soc_rev is zero to continue. + */ + if (se_soc_rev) + return err; + + if (info->se_fetch_soc_info) { + err = info->se_fetch_soc_info(priv, &se_soc_rev, &serial_num); + if (err < 0) { + dev_err(priv->dev, "Failed to fetch SoC Info."); + return err; + } + } else { + dev_err(priv->dev, "Failed to fetch SoC revision."); + if (info->soc_register) + dev_err(priv->dev, "Failed to do SoC registration."); + err = -EINVAL; + return err; + } + + if (!info->soc_register) + return 0; + + attr = devm_kzalloc(priv->dev, sizeof(*attr), GFP_KERNEL); + if (!attr) + return -ENOMEM; + + if (FIELD_GET(DEV_GETINFO_MIN_VER_MASK, se_soc_rev)) + attr->revision = devm_kasprintf(priv->dev, GFP_KERNEL, "%x.%x", + FIELD_GET(DEV_GETINFO_MIN_VER_MASK, + se_soc_rev), + FIELD_GET(DEV_GETINFO_MAJ_VER_MASK, + se_soc_rev)); + else + attr->revision = devm_kasprintf(priv->dev, GFP_KERNEL, "%x", + FIELD_GET(DEV_GETINFO_MAJ_VER_MASK, + se_soc_rev)); + + switch (info_list->soc_id) { + case SOC_ID_OF_IMX8ULP: + attr->soc_id = devm_kasprintf(priv->dev, GFP_KERNEL, + "i.MX8ULP"); + break; + case SOC_ID_OF_IMX93: + attr->soc_id = devm_kasprintf(priv->dev, GFP_KERNEL, + "i.MX93"); + break; + } + + err = of_property_read_string(of_root, "model", + &attr->machine); + if (err) + return -EINVAL; + + attr->family = devm_kasprintf(priv->dev, GFP_KERNEL, "Freescale i.MX"); + + attr->serial_number + = devm_kasprintf(priv->dev, GFP_KERNEL, "%016llX", serial_num); + + sdev = soc_device_register(attr); + if (IS_ERR(sdev)) + return PTR_ERR(sdev); + + return 0; +} + +static struct se_fw_load_info *get_load_fw_instance(struct se_if_priv *priv) +{ + const struct se_if_node_info *info = container_of(priv->if_defs, + typeof(*info), + if_defs); + struct se_if_node_info_list *info_list; + struct se_fw_load_info *load_fw = NULL; + + info_list = container_of(info, + typeof(*info_list), + info[info->se_if_id]); + + if (!memcmp(SE_TYPE_HSM, info->se_name, strlen(SE_TYPE_HSM))) + load_fw = &info_list->load_hsm_fw; + else + dev_err(priv->dev, "Invalid load fw configuration."); + + return load_fw; +} + +static int se_load_firmware(struct se_if_priv *priv) +{ + struct se_fw_load_info *load_fw = get_load_fw_instance(priv); + const struct firmware *fw; + phys_addr_t se_fw_phyaddr; + const u8 *se_img_file_to_load; + u8 *se_fw_buf; + int ret; + + guard(mutex)(&load_fw->se_fw_load); + if (load_fw->is_fw_loaded) + return 0; + + se_img_file_to_load = load_fw->seco_fw_nm_in_rfs; + if (load_fw->prim_fw_nm_in_rfs) { + /* allocate buffer where SE store encrypted IMEM */ + load_fw->imem.buf = dmam_alloc_coherent(priv->dev, ELE_IMEM_SIZE, + &load_fw->imem.phyaddr, + GFP_KERNEL); + if (!load_fw->imem.buf) { + dev_err(priv->dev, + "dmam-alloc-failed: To store encr-IMEM.\n"); + ret = -ENOMEM; + goto exit; + } + if (load_fw->imem.state == ELE_IMEM_STATE_BAD) + se_img_file_to_load + = load_fw->prim_fw_nm_in_rfs; + } + + do { + ret = request_firmware(&fw, se_img_file_to_load, priv->dev); + if (ret) + goto exit; + + dev_info(priv->dev, "loading firmware %s\n", se_img_file_to_load); + + /* allocate buffer to store the SE FW */ + se_fw_buf = dma_alloc_coherent(priv->dev, fw->size, + &se_fw_phyaddr, GFP_KERNEL); + if (!se_fw_buf) { + ret = -ENOMEM; + goto exit; + } + + memcpy(se_fw_buf, fw->data, fw->size); + ret = ele_fw_authenticate(priv, se_fw_phyaddr); + if (ret < 0) { + dev_err(priv->dev, + "Error %pe: Authenticate & load SE firmware %s.\n", + ERR_PTR(ret), + se_img_file_to_load); + ret = -EPERM; + } + + dma_free_coherent(priv->dev, + fw->size, + se_fw_buf, + se_fw_phyaddr); + + release_firmware(fw); + + if (!ret && load_fw->imem.state == ELE_IMEM_STATE_BAD && + se_img_file_to_load == load_fw->prim_fw_nm_in_rfs) + se_img_file_to_load = load_fw->seco_fw_nm_in_rfs; + else + se_img_file_to_load = NULL; + + } while (se_img_file_to_load); + + if (!ret) + load_fw->is_fw_loaded = true; + +exit: + return ret; +} + +/* interface for managed res to free a mailbox channel */ +static void if_mbox_free_channel(void *mbox_chan) +{ + mbox_free_channel(mbox_chan); +} + +static int se_if_request_channel(struct device *dev, + struct mbox_chan **chan, + struct mbox_client *cl, + const char *name) +{ + struct mbox_chan *t_chan; + int ret = 0; + + t_chan = mbox_request_channel_byname(cl, name); + if (IS_ERR(t_chan)) { + ret = PTR_ERR(t_chan); + return dev_err_probe(dev, ret, + "Failed to request %s channel.", name); + } + + ret = devm_add_action(dev, if_mbox_free_channel, t_chan); + if (ret) { + dev_err(dev, "failed to add devm removal of mbox %s\n", name); + goto exit; + } + + *chan = t_chan; + +exit: + return ret; +} + +static void se_if_probe_cleanup(void *plat_dev) +{ + struct platform_device *pdev = plat_dev; + struct device *dev = &pdev->dev; + struct se_fw_load_info *load_fw; + struct se_if_priv *priv; + + priv = dev_get_drvdata(dev); + load_fw = get_load_fw_instance(priv); + + /* In se_if_request_channel(), passed the clean-up functional + * pointer reference as action to devm_add_action(). + * No need to free the mbox channels here. + */ + + /* free the buffer in se remove, previously allocated + * in se probe to store encrypted IMEM + */ + if (load_fw && load_fw->imem.buf) { + dmam_free_coherent(dev, + ELE_IMEM_SIZE, + load_fw->imem.buf, + load_fw->imem.phyaddr); + load_fw->imem.buf = NULL; + } + + /* No need to check, if reserved memory is allocated + * before calling for its release. Or clearing the + * un-set bit. + */ + of_reserved_mem_device_release(dev); +} + +static int se_if_probe(struct platform_device *pdev) +{ + const struct se_if_node_info_list *info_list; + const struct se_if_node_info *info; + struct device *dev = &pdev->dev; + struct se_fw_load_info *load_fw; + struct se_if_priv *priv; + u32 idx; + int ret; + + idx = GET_IDX_FROM_DEV_NODE_NAME(dev->of_node); + info_list = device_get_match_data(dev); + if (idx >= info_list->num_mu) { + dev_err(dev, + "Incorrect node name :%s\n", + dev->of_node->full_name); + dev_err(dev, + "%s-, acceptable index range is 0..%d\n", + dev->of_node->name, + info_list->num_mu - 1); + ret = -EINVAL; + return ret; + } + + info = get_se_if_node_info(info_list, idx); + if (!info) { + ret = -EINVAL; + goto exit; + } + + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) { + ret = -ENOMEM; + goto exit; + } + + priv->dev = dev; + priv->if_defs = &info->if_defs; + dev_set_drvdata(dev, priv); + + ret = devm_add_action(dev, se_if_probe_cleanup, pdev); + if (ret) + goto exit; + + + /* Mailbox client configuration */ + priv->se_mb_cl.dev = dev; + priv->se_mb_cl.tx_block = false; + priv->se_mb_cl.knows_txdone = true; + priv->se_mb_cl.rx_callback = se_if_rx_callback; + + ret = se_if_request_channel(dev, &priv->tx_chan, + &priv->se_mb_cl, MBOX_TX_NAME); + if (ret) + goto exit; + + ret = se_if_request_channel(dev, &priv->rx_chan, + &priv->se_mb_cl, MBOX_RX_NAME); + if (ret) + goto exit; + + mutex_init(&priv->se_if_cmd_lock); + + init_completion(&priv->waiting_rsp_clbk_hdl.done); + init_completion(&priv->cmd_receiver_clbk_hdl.done); + + if (info->pool_name) { + priv->mem_pool = of_gen_pool_get(dev->of_node, + info->pool_name, 0); + if (!priv->mem_pool) { + dev_err(dev, + "Unable to get sram pool = %s\n", + info->pool_name); + goto exit; + } + } + + if (info->reserved_dma_ranges) { + ret = of_reserved_mem_device_init(dev); + if (ret) { + dev_err(dev, + "failed to init reserved memory region %d\n", + ret); + goto exit; + } + } + + ret = se_soc_info(priv); + if (ret) { + dev_err(dev, + "failed[%pe] to fetch SoC Info\n", ERR_PTR(ret)); + goto exit; + } + + load_fw = get_load_fw_instance(priv); + /* By default, there is no pending FW to be loaded.*/ + if (load_fw->is_fw_loaded) { + mutex_init(&load_fw->se_fw_load); + ret = se_load_firmware(priv); + if (ret) + dev_warn(dev, "Failed to load firmware."); + ret = 0; + } + dev_info(dev, "i.MX secure-enclave: %s interface to firmware, configured.\n", + info->se_name); + return ret; + +exit: + /* if execution control reaches here, if probe fails. + */ + return dev_err_probe(dev, ret, "%s: Probe failed.", __func__); + + return ret; +} + +static void se_if_remove(struct platform_device *pdev) +{ + se_if_probe_cleanup(pdev); +} + +static int se_suspend(struct device *dev) +{ + struct se_if_priv *priv = dev_get_drvdata(dev); + struct se_fw_load_info *load_fw; + int ret = 0; + + load_fw = get_load_fw_instance(priv); + + if (load_fw->handle_susp_resm) { + ret = se_save_imem_state(priv, &load_fw->imem); + if (ret < 0) + goto exit; + load_fw->imem.size = ret; + } +exit: + return ret; +} + +static int se_resume(struct device *dev) +{ + struct se_if_priv *priv = dev_get_drvdata(dev); + struct se_fw_load_info *load_fw; + + load_fw = get_load_fw_instance(priv); + + if (load_fw->handle_susp_resm) + se_restore_imem_state(priv, &load_fw->imem); + + return 0; +} + +static const struct dev_pm_ops se_pm = { + RUNTIME_PM_OPS(se_suspend, se_resume, NULL) +}; + +static struct platform_driver se_driver = { + .driver = { + .name = "fsl-se-fw", + .of_match_table = se_match, + .pm = &se_pm, + }, + .probe = se_if_probe, + .remove = se_if_remove, +}; +MODULE_DEVICE_TABLE(of, se_match); + +module_platform_driver(se_driver); +MODULE_AUTHOR("Pankaj Gupta "); +MODULE_DESCRIPTION("iMX Secure Enclave Driver."); +MODULE_LICENSE("GPL"); diff --git a/drivers/firmware/imx/se_ctrl.h b/drivers/firmware/imx/se_ctrl.h new file mode 100644 index 000000000000..de0d4a1bcb9e --- /dev/null +++ b/drivers/firmware/imx/se_ctrl.h @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2024 NXP + */ + +#ifndef SE_MU_H +#define SE_MU_H + +#include +#include +#include + +#define MAX_FW_LOAD_RETRIES 50 + +#define RES_STATUS(x) FIELD_GET(0x000000ff, x) +#define MAX_NVM_MSG_LEN (256) +#define MESSAGING_VERSION_6 0x6 +#define MESSAGING_VERSION_7 0x7 +#define NODE_NAME "secure-enclave" + +#define GET_ASCII_TO_U8(diff, tens_chr, ones_chr) \ + ((diff > 2) ? (((tens_chr - '0') * 10) + (ones_chr - '0')) :\ + (tens_chr - '0')) + +#define GET_IDX_FROM_DEV_NODE_NAME(dev_of_node) \ + ((strlen(dev_of_node->full_name) > strlen(NODE_NAME)) ?\ + GET_ASCII_TO_U8((strlen(dev_of_node->full_name) - strlen(NODE_NAME)),\ + dev_of_node->full_name[strlen(NODE_NAME) + 1], \ + dev_of_node->full_name[strlen(NODE_NAME) + 2]) : 0) + +struct se_clbk_handle { + struct completion done; + bool signal_rcvd; + atomic_t pending_hdr; + u32 rx_msg_sz; + /* Assignment of the rx_msg buffer to held till the + * received content as part callback function, is copied. + */ + struct se_api_msg *rx_msg; +}; + +struct se_imem_buf { + u8 *buf; + phys_addr_t phyaddr; + u32 size; + u32 state; +}; + +/* Header of the messages exchange with the EdgeLock Enclave */ +struct se_msg_hdr { + u8 ver; + u8 size; + u8 command; + u8 tag; +} __packed; + +#define SE_MU_HDR_SZ 4 + +struct se_api_msg { + struct se_msg_hdr header; + u32 data[]; +}; + +struct se_if_defines { + const void *info; + u8 cmd_tag; + u8 rsp_tag; + u8 success_tag; + u8 base_api_ver; + u8 fw_api_ver; +}; + +struct se_if_priv { + struct device *dev; + + struct se_clbk_handle cmd_receiver_clbk_hdl; + /* Update to the waiting_rsp_dev, to be protected + * under se_if_cmd_lock. + */ + struct se_clbk_handle waiting_rsp_clbk_hdl; + /* + * prevent new command to be sent on the se interface while previous + * command is still processing. (response is awaited) + */ + struct mutex se_if_cmd_lock; + + struct mbox_client se_mb_cl; + struct mbox_chan *tx_chan, *rx_chan; + + struct gen_pool *mem_pool; + const struct se_if_defines *if_defs; +}; + +#endif diff --git a/include/linux/firmware/imx/se_api.h b/include/linux/firmware/imx/se_api.h new file mode 100644 index 000000000000..c47f84906837 --- /dev/null +++ b/include/linux/firmware/imx/se_api.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2024 NXP + */ + +#ifndef __SE_API_H__ +#define __SE_API_H__ + +#include + +#define SOC_ID_OF_IMX8ULP 0x084D +#define SOC_ID_OF_IMX93 0x9300 + +#endif /* __SE_API_H__ */ From patchwork Wed Oct 16 16:19:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 13838643 Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2083.outbound.protection.outlook.com [40.107.103.83]) (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 BB8D2210C30 for ; Wed, 16 Oct 2024 16:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.103.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729095831; cv=fail; b=RxcvcvUahCHKLw6k8kp7SQZSiY1D03/7xw/HwTGeeFK15jjtspA7AAFl0tklMdhnXftHjwW/EIYZ39F8XtYsG2rN8Bt+CC0bXtkO5fU8qF78hQzQZLtB9srbx71KiiMf1ll9VEjpm8ilZeLLTGWw2YcVS3J+N+LS3XVtdTKTqlQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729095831; c=relaxed/simple; bh=xWgDpdNSCn+E+vZkwmdFHphGMaJ5PhzTrqsP91jNJ8s=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=D9dK2L96Nz6a+Abw6ojd8QVYWqSBS+7JLmnJQdrRMf5v45cjmButewc1Pf78UJ4falSTnSodxuqmqmotUy7k8yM7MlqOqVxHJmJIYd9L0WybF37JMS2zU52Ot22lR6SpvlEVRDDt0t+IThpCCRgYk3zd3tyxxnL2cJFizW6TtMc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=oChTYEXC; arc=fail smtp.client-ip=40.107.103.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="oChTYEXC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MWDxLvo5HMmVz+8VX6o/EyRC/F7Azx3NzLYX58eK7afsUMiiBQFmnr+x2S3yCwWbu+t2VQ4/vbulZX5foO0XiYhBLn32bKKWHhZW1XLtZ6RnaFYeeCJPOQ55whFR5uixwoUM87XfTwOzepGTBj5De8p2jI/UguKeprs43kcvTBiWvETkAaAg2sI8yvww6uQ6GF0mBQ5ji3qOte31Gv9lGjF1gBjQcSstN79okAsoPikO93r3CmjVFNWtUELnkLVXhECdnp3GZ+fhVun1cXDtg0ta3jlX7To9O01HKNERuViPqF8R0aibHTMGDdWPgfaWOhO/L04c4uiauZM06REGDQ== 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=1BvO9qJPX/lBcUMzwlmpeM3J0Ez2h4HC4nr4GbH0qOA=; b=MUS+ZdSBarZlYC7HM1QoNVfFnZsbYs0uZ+doPZm0pF3u+wFMb0+GQUNzYs6s3LvWwU1Bn4w9J8qmcSsAOBUfqNQphCWhwhpbHguv9uqOKPD9yaiYNpf52CaOi9O3pZE/sFF4I+WqAej2vsmyRJygZ+OI2M7iCngAI7NPlY6iHF/pZAHCepqmMfTzuXEkO145ZEU9DfLnvoDl4bp6vgzsfSF9dqPTv9VYuo0O19DC8f6FGhTFHaxeYIbH5lvJ08pak6pjxyTWZ6PmhAID90Hfbw+gXAyeF5GXEjGd/PwvHQFJqxJt4e0HFKd7D+eCRft9EfyyanuvBVBemKd5SUb6cA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1BvO9qJPX/lBcUMzwlmpeM3J0Ez2h4HC4nr4GbH0qOA=; b=oChTYEXC6uSBNx+MCnwPE+v2jrUZwmD5A38FmOYNjnMuMD+zUCB7sgmI0YgVEotMx2jIjbKKLAiievchbDqhvpXYmGqoTNdFfaW6gRxAiA5buNbc8YizOqOhsu/y0717bvJiZr3Uazalb8X2PsOw1NAGSvvcot3P+WfKrSJV6V5EChcwe6y9vV09mPQ2bhwqQ6cs8D/JoGDtnUJAj7/QtjE9mKQCpWYQr9seTkemV4ByBf7GafuwZzn/qOUnqMm4ty9WAErMpj9WuTrisQlIrj4euXV7qwIgGBtIwhj3TpqW8xZKVYB0RERb/PmMlMCA6+mE4HeTnuOmfLcgp5RbNw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8599.eurprd04.prod.outlook.com (2603:10a6:10:2da::7) by AM0PR04MB6884.eurprd04.prod.outlook.com (2603:10a6:208:183::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18; Wed, 16 Oct 2024 16:23:46 +0000 Received: from DU2PR04MB8599.eurprd04.prod.outlook.com ([fe80::763:eb3b:6607:1e72]) by DU2PR04MB8599.eurprd04.prod.outlook.com ([fe80::763:eb3b:6607:1e72%5]) with mapi id 15.20.8069.016; Wed, 16 Oct 2024 16:23:46 +0000 From: Pankaj Gupta Date: Wed, 16 Oct 2024 21:49:02 +0530 Subject: [PATCH v9 5/5] firmware: imx: adds miscdev Message-Id: <20241016-imx-se-if-v9-5-fd8fa0c04eab@nxp.com> References: <20241016-imx-se-if-v9-0-fd8fa0c04eab@nxp.com> In-Reply-To: <20241016-imx-se-if-v9-0-fd8fa0c04eab@nxp.com> To: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Pankaj Gupta Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729095547; l=36725; i=pankaj.gupta@nxp.com; s=20240523; h=from:subject:message-id; bh=xWgDpdNSCn+E+vZkwmdFHphGMaJ5PhzTrqsP91jNJ8s=; b=653KXwvR+s3IrGoGILPlNhFxjxgedi3pUjza/lgGUA8fncvw9Larj/BdJ0i45Iqk3YNLJM3U0 k58W2jyw8zmCysTphtFL2l/ngep/tZ4IOTNAA4dA52mRAqQny3fBX0k X-Developer-Key: i=pankaj.gupta@nxp.com; a=ed25519; pk=OA0pBQoupy5lV0XfKzD8B0OOBVB6tpAoIf+0x1bYGRg= X-ClientProxiedBy: SG2PR02CA0037.apcprd02.prod.outlook.com (2603:1096:3:18::25) To DU2PR04MB8599.eurprd04.prod.outlook.com (2603:10a6:10:2da::7) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8599:EE_|AM0PR04MB6884:EE_ X-MS-Office365-Filtering-Correlation-Id: fa2da472-791f-4a50-cd25-08dcedfee893 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|7416014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?1+o16MhxMuqCfD5Ub8QY9Lu7SNp5U3s?= =?utf-8?q?vrbQzx6gKGlRTocptLFi5VLvF4gmWLRyikBHONnsTHGFPl8vWnK72LzFAjj56Z66v?= =?utf-8?q?EBixc+Np2uCaWIIQ+zVZJOuI8r1Y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TsVIxrwqnKIfRREY1sO?= =?utf-8?q?PCjhJFwhmCK2zoGvKJp81TGavlwiIcN31hq52cFwEkeouorXN2z51o77vGfONtftT?= =?utf-8?q?YuHZWinX32n8RqCLAsJrEhdS209je5tQ+LcYAbn8spxgCptUQ5THtUlQowSqm0hO3?= =?utf-8?q?CND7Hr/Kc7uJRX+xwrpJxVuff04bfP9tLUOQ6bYOt9yg9NsOmmZFU2S2a15/Jj48d?= =?utf-8?q?GOcnsmWKyRQAlQzL/vP2RwDaKp1Ez/5lqmjORc3hkAFtbdyy2yY4SZGYxwcjjl4pu?= =?utf-8?q?WDQbOmCnEsK4xnYSWrQwX1kU5Y8JTh0GhAJNv/JAeDbMiStAHlBb9uJc=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8599.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(1800799024)(7416014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?ttIrJJfgxSC11O3OdkLn5Sp2NySy?= =?utf-8?q?bM36zNdtsmDyeqMdRNLgsNuMQx3qcXFvgJMTxvmJnVms3NRkfu6VnphQD+OWimYDM?= =?utf-8?q?XAs6nEgyDHwwkLLDNaz7Y5ZHhLhE+9pF3j6D1qbZMkkJ2MHclJnD4KecMiruMPYzH?= =?utf-8?q?WX9EPsyfWerXkzcS295jTmI7MIM875ZMIt3MXUfmJ7yDWkT1IWoW64EnMY36mzOaf?= =?utf-8?q?FNpG0eusnAuas/mSjPQUYWPZgily5MCwAjruvldLGL/lB7AVXC7X8l40nR+X3lOZ7?= =?utf-8?q?cp/XztRXtI0R9ZRW6uyuLVtn20ahOC9DIFK+1fEHoVYOT/gqy3AiO/GwHAp72DVdy?= =?utf-8?q?Nzqm0n8gOZClbVHQ245hZ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61FjhEr/B2VHz1L0kaCLipC2+sCmbEsg8kujWl?= =?utf-8?q?FG43OpX33J84xxRPjTKC5zARO8cQhAk03yDSseEkQc4wqAgcwwoLjifE0Ox0W4yzP?= =?utf-8?q?oYcXOEY0oBYm4glMIyxn/v8DpCrlnpHNZVIe3wihkkVNESCwd6nxhppgFP2cK26gB?= =?utf-8?q?4tLKXA150Io7JnbCtsPxfCH1crvt7P8X/hIEGaBpQ3msPABeP6+hljHGtA4C+VO26?= =?utf-8?q?x3OITbiX3Za7FNpsduy2lwXVtiI6iczHf/JdGXRv+FNsgBsDzHz7YytVVvKRW0vKG?= =?utf-8?q?KcufZJBSORx3?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa2da472-791f-4a50-cd25-08dcedfee893 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8599.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 16:23:46.0789 (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: K1Aw+V0Ado40esLrzbRb6NJx8CAQ9l+8YMGEpzHGamzlznISqSQK3ElzOg+uD0VUyTr0CD0GgOYxhXyqEwBkTw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6884 Adds the driver for communication interface to secure-enclave, for exchanging messages with NXP secure enclave HW IP(s) like EdgeLock Enclave from: - User-Space Applications via character driver. ABI documentation for the NXP secure-enclave driver. User-space library using this driver: - i.MX Secure Enclave library: -- URL: https://github.com/nxp-imx/imx-secure-enclave.git, - i.MX Secure Middle-Ware: -- URL: https://github.com/nxp-imx/imx-smw.git Signed-off-by: Pankaj Gupta --- Documentation/ABI/testing/se-cdev | 43 ++ drivers/firmware/imx/ele_base_msg.c | 8 +- drivers/firmware/imx/ele_common.c | 39 +- drivers/firmware/imx/ele_common.h | 6 +- drivers/firmware/imx/se_ctrl.c | 779 ++++++++++++++++++++++++++++++++++++ drivers/firmware/imx/se_ctrl.h | 42 +- include/uapi/linux/se_ioctl.h | 94 +++++ 7 files changed, 990 insertions(+), 21 deletions(-) diff --git a/Documentation/ABI/testing/se-cdev b/Documentation/ABI/testing/se-cdev new file mode 100644 index 000000000000..3451c909ccc4 --- /dev/null +++ b/Documentation/ABI/testing/se-cdev @@ -0,0 +1,43 @@ +What: /dev/_mu[0-9]+_ch[0-9]+ +Date: May 2024 +KernelVersion: 6.8 +Contact: linux-imx@nxp.com, pankaj.gupta@nxp.com +Description: + NXP offers multiple hardware IP(s) for secure enclaves like EdgeLock- + Enclave(ELE), SECO. The character device file descriptors + /dev/_mu*_ch* are the interface between userspace NXP's secure- + enclave shared library and the kernel driver. + + The ioctl(2)-based ABI is defined and documented in + [include]. + ioctl(s) are used primarily for: + - shared memory management + - allocation of I/O buffers + - getting mu info + - setting a dev-ctx as receiver to receive all the commands from FW + - getting SoC info + - send command and receive command response + + The following file operations are supported: + + open(2) + Currently the only useful flags are O_RDWR. + + read(2) + Every read() from the opened character device context is waiting on + wait_event_interruptible, that gets set by the registered mailbox callback + function, indicating a message received from the firmware on message- + unit. + + write(2) + Every write() to the opened character device context needs to acquire + mailbox_lock before sending message on to the message unit. + + close(2) + Stops and frees up the I/O contexts that were associated + with the file descriptor. + +Users: https://github.com/nxp-imx/imx-secure-enclave.git, + https://github.com/nxp-imx/imx-smw.git + crypto/skcipher, + drivers/nvmem/imx-ocotp-ele.c diff --git a/drivers/firmware/imx/ele_base_msg.c b/drivers/firmware/imx/ele_base_msg.c index 53c83eddd52a..329badcc3d14 100644 --- a/drivers/firmware/imx/ele_base_msg.c +++ b/drivers/firmware/imx/ele_base_msg.c @@ -67,7 +67,7 @@ int ele_get_info(struct se_if_priv *priv, struct ele_dev_info *s_info) tx_msg->data[0] = upper_32_bits(get_info_addr); tx_msg->data[1] = lower_32_bits(get_info_addr); tx_msg->data[2] = sizeof(*s_info); - ret = ele_msg_send_rcv(priv, + ret = ele_msg_send_rcv(priv->priv_dev_ctx, tx_msg, ELE_GET_INFO_REQ_MSG_SZ, rx_msg, @@ -145,7 +145,7 @@ int ele_ping(struct se_if_priv *priv) goto exit; } - ret = ele_msg_send_rcv(priv, + ret = ele_msg_send_rcv(priv->priv_dev_ctx, tx_msg, ELE_PING_REQ_SZ, rx_msg, @@ -200,7 +200,7 @@ int ele_service_swap(struct se_if_priv *priv, tx_msg->data[3] = lower_32_bits(addr); tx_msg->data[4] = se_add_msg_crc((uint32_t *)&tx_msg[0], ELE_SERVICE_SWAP_REQ_MSG_SZ); - ret = ele_msg_send_rcv(priv, + ret = ele_msg_send_rcv(priv->priv_dev_ctx, tx_msg, ELE_SERVICE_SWAP_REQ_MSG_SZ, rx_msg, @@ -261,7 +261,7 @@ int ele_fw_authenticate(struct se_if_priv *priv, phys_addr_t addr) tx_msg->data[0] = lower_32_bits(addr); tx_msg->data[2] = addr; - ret = ele_msg_send_rcv(priv, + ret = ele_msg_send_rcv(priv->priv_dev_ctx, tx_msg, ELE_FW_AUTH_REQ_SZ, rx_msg, diff --git a/drivers/firmware/imx/ele_common.c b/drivers/firmware/imx/ele_common.c index f7c760bbc7a3..97f34e4e5d2c 100644 --- a/drivers/firmware/imx/ele_common.c +++ b/drivers/firmware/imx/ele_common.c @@ -18,9 +18,10 @@ u32 se_add_msg_crc(u32 *msg, u32 msg_len) return crc; } -int ele_msg_rcv(struct se_if_priv *priv, +int ele_msg_rcv(struct se_if_device_ctx *dev_ctx, struct se_clbk_handle *se_clbk_hdl) { + struct se_if_priv *priv = dev_ctx->priv; int err = 0; do { @@ -31,12 +32,13 @@ int ele_msg_rcv(struct se_if_priv *priv, */ err = wait_for_completion_interruptible(&se_clbk_hdl->done); if (err == -ERESTARTSYS) { - if (priv->waiting_rsp_clbk_hdl.rx_msg) { + if (priv->waiting_rsp_clbk_hdl.dev_ctx) { priv->waiting_rsp_clbk_hdl.signal_rcvd = true; continue; } dev_err(priv->dev, - "Err[0x%x]:Interrupted by signal.\n", + "%s: Err[0x%x]:Interrupted by signal.\n", + se_clbk_hdl->dev_ctx->devname, err); err = -EINTR; break; @@ -46,10 +48,11 @@ int ele_msg_rcv(struct se_if_priv *priv, return err ? err : se_clbk_hdl->rx_msg_sz; } -int ele_msg_send(struct se_if_priv *priv, +int ele_msg_send(struct se_if_device_ctx *dev_ctx, void *tx_msg, int tx_msg_sz) { + struct se_if_priv *priv = dev_ctx->priv; struct se_msg_hdr *header; int err; @@ -62,7 +65,8 @@ int ele_msg_send(struct se_if_priv *priv, if (header->size << 2 != tx_msg_sz) { err = -EINVAL; dev_err(priv->dev, - "User buf hdr: 0x%x, sz mismatced with input-sz (%d != %d).", + "%s: User buf hdr: 0x%x, sz mismatced with input-sz (%d != %d).", + dev_ctx->devname, *(u32 *)header, header->size << 2, tx_msg_sz); goto exit; @@ -70,7 +74,9 @@ int ele_msg_send(struct se_if_priv *priv, err = mbox_send_message(priv->tx_chan, tx_msg); if (err < 0) { - dev_err(priv->dev, "Error: mbox_send_message failure.\n"); + dev_err(priv->dev, + "%s: Error: mbox_send_message failure.", + dev_ctx->devname); return err; } err = tx_msg_sz; @@ -80,29 +86,32 @@ int ele_msg_send(struct se_if_priv *priv, } /* API used for send/receive blocking call. */ -int ele_msg_send_rcv(struct se_if_priv *priv, +int ele_msg_send_rcv(struct se_if_device_ctx *dev_ctx, void *tx_msg, int tx_msg_sz, void *rx_msg, int exp_rx_msg_sz) { int err; + struct se_if_priv *priv = dev_ctx->priv; guard(mutex)(&priv->se_if_cmd_lock); + priv->waiting_rsp_clbk_hdl.dev_ctx = dev_ctx; priv->waiting_rsp_clbk_hdl.rx_msg_sz = exp_rx_msg_sz; priv->waiting_rsp_clbk_hdl.rx_msg = rx_msg; - err = ele_msg_send(priv, tx_msg, tx_msg_sz); + err = ele_msg_send(dev_ctx, tx_msg, tx_msg_sz); if (err < 0) goto exit; - err = ele_msg_rcv(priv, &priv->waiting_rsp_clbk_hdl); + err = ele_msg_rcv(dev_ctx, &priv->waiting_rsp_clbk_hdl); if (priv->waiting_rsp_clbk_hdl.signal_rcvd) { err = -EINTR; priv->waiting_rsp_clbk_hdl.signal_rcvd = false; } + priv->waiting_rsp_clbk_hdl.dev_ctx = NULL; exit: return err; @@ -149,7 +158,8 @@ void se_if_rx_callback(struct mbox_client *mbox_cl, void *msg) if (header->tag == priv->if_defs->cmd_tag) { se_clbk_hdl = &priv->cmd_receiver_clbk_hdl; dev_dbg(dev, - "Selecting cmd receiver for mesg header:0x%x.", + "Selecting cmd receiver:%s for mesg header:0x%x.", + se_clbk_hdl->dev_ctx->devname, *(u32 *) header); /* Pre-allocated buffer of MAX_NVM_MSG_LEN @@ -158,7 +168,8 @@ void se_if_rx_callback(struct mbox_client *mbox_cl, void *msg) */ if (rx_msg_sz > MAX_NVM_MSG_LEN) { dev_err(dev, - "CMD-RCVER NVM: hdr(0x%x) with different sz(%d != %d).\n", + "%s: CMD-RCVER NVM: hdr(0x%x) with different sz(%d != %d).\n", + se_clbk_hdl->dev_ctx->devname, *(u32 *) header, rx_msg_sz, se_clbk_hdl->rx_msg_sz); @@ -169,13 +180,15 @@ void se_if_rx_callback(struct mbox_client *mbox_cl, void *msg) } else if (header->tag == priv->if_defs->rsp_tag) { se_clbk_hdl = &priv->waiting_rsp_clbk_hdl; dev_dbg(dev, - "Selecting resp waiter for mesg header:0x%x.", + "Selecting resp waiter:%s for mesg header:0x%x.", + se_clbk_hdl->dev_ctx->devname, *(u32 *) header); if (rx_msg_sz != se_clbk_hdl->rx_msg_sz && !exception_for_size(priv, header)) { dev_err(dev, - "Rsp to CMD: hdr(0x%x) with different sz(%d != %d).\n", + "%s: Rsp to CMD: hdr(0x%x) with different sz(%d != %d).\n", + se_clbk_hdl->dev_ctx->devname, *(u32 *) header, rx_msg_sz, se_clbk_hdl->rx_msg_sz); diff --git a/drivers/firmware/imx/ele_common.h b/drivers/firmware/imx/ele_common.h index 3d8b6f83fb9d..9bded800c103 100644 --- a/drivers/firmware/imx/ele_common.h +++ b/drivers/firmware/imx/ele_common.h @@ -14,12 +14,12 @@ #define IMX_ELE_FW_DIR "imx/ele/" uint32_t se_add_msg_crc(uint32_t *msg, uint32_t msg_len); -int ele_msg_rcv(struct se_if_priv *priv, +int ele_msg_rcv(struct se_if_device_ctx *dev_ctx, struct se_clbk_handle *se_clbk_hdl); -int ele_msg_send(struct se_if_priv *priv, +int ele_msg_send(struct se_if_device_ctx *dev_ctx, void *tx_msg, int tx_msg_sz); -int ele_msg_send_rcv(struct se_if_priv *priv, +int ele_msg_send_rcv(struct se_if_device_ctx *dev_ctx, void *tx_msg, int tx_msg_sz, void *rx_msg, diff --git a/drivers/firmware/imx/se_ctrl.c b/drivers/firmware/imx/se_ctrl.c index 40d815d0ac9b..f41c6441eac1 100644 --- a/drivers/firmware/imx/se_ctrl.c +++ b/drivers/firmware/imx/se_ctrl.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "ele_base_msg.h" #include "ele_common.h" @@ -313,6 +314,762 @@ static int se_load_firmware(struct se_if_priv *priv) return ret; } +static int init_se_shared_mem(struct se_if_device_ctx *dev_ctx) +{ + struct se_shared_mem_mgmt_info *se_shared_mem_mgmt = &dev_ctx->se_shared_mem_mgmt; + struct se_if_priv *priv = dev_ctx->priv; + + INIT_LIST_HEAD(&se_shared_mem_mgmt->pending_out); + INIT_LIST_HEAD(&se_shared_mem_mgmt->pending_in); + + /* + * Allocate some memory for data exchanges with S40x. + * This will be used for data not requiring secure memory. + */ + se_shared_mem_mgmt->non_secure_mem.ptr + = dma_alloc_coherent(priv->dev, + MAX_DATA_SIZE_PER_USER, + &se_shared_mem_mgmt->non_secure_mem.dma_addr, + GFP_KERNEL); + if (!se_shared_mem_mgmt->non_secure_mem.ptr) + return -ENOMEM; + + se_shared_mem_mgmt->non_secure_mem.size = MAX_DATA_SIZE_PER_USER; + se_shared_mem_mgmt->non_secure_mem.pos = 0; + + return 0; +} + +static void cleanup_se_shared_mem(struct se_if_device_ctx *dev_ctx) +{ + struct se_shared_mem_mgmt_info *se_shared_mem_mgmt = &dev_ctx->se_shared_mem_mgmt; + struct se_if_priv *priv = dev_ctx->priv; + + /* Unmap secure memory shared buffer. */ + if (se_shared_mem_mgmt->secure_mem.ptr) + devm_iounmap(priv->dev, + (void __iomem *)se_shared_mem_mgmt->secure_mem.ptr); + + se_shared_mem_mgmt->secure_mem.ptr = NULL; + se_shared_mem_mgmt->secure_mem.dma_addr = 0; + se_shared_mem_mgmt->secure_mem.size = 0; + se_shared_mem_mgmt->secure_mem.pos = 0; + + /* Free non-secure shared buffer. */ + dma_free_coherent(priv->dev, MAX_DATA_SIZE_PER_USER, + se_shared_mem_mgmt->non_secure_mem.ptr, + se_shared_mem_mgmt->non_secure_mem.dma_addr); + + se_shared_mem_mgmt->non_secure_mem.ptr = NULL; + se_shared_mem_mgmt->non_secure_mem.dma_addr = 0; + se_shared_mem_mgmt->non_secure_mem.size = 0; + se_shared_mem_mgmt->non_secure_mem.pos = 0; +} + +/* Need to copy the output data to user-device context. + */ +static int se_dev_ctx_cpy_out_data(struct se_if_device_ctx *dev_ctx) +{ + struct se_shared_mem_mgmt_info *se_shared_mem_mgmt = &dev_ctx->se_shared_mem_mgmt; + struct se_if_priv *priv = dev_ctx->priv; + struct se_buf_desc *b_desc, *temp; + bool do_cpy = true; + + list_for_each_entry_safe(b_desc, temp, &se_shared_mem_mgmt->pending_out, link) { + if (b_desc->usr_buf_ptr && b_desc->shared_buf_ptr && do_cpy) { + + dev_dbg(priv->dev, + "Copying output data to user."); + if (do_cpy && copy_to_user(b_desc->usr_buf_ptr, + b_desc->shared_buf_ptr, + b_desc->size)) { + dev_err(priv->dev, + "Failure copying output data to user."); + do_cpy = false; + } + } + + if (b_desc->shared_buf_ptr) + memset(b_desc->shared_buf_ptr, 0, b_desc->size); + + list_del(&b_desc->link); + kfree(b_desc); + } + + return do_cpy ? 0 : -EFAULT; +} + +/* + * Clean the used Shared Memory space, + * whether its Input Data copied from user buffers, or + * Data received from FW. + */ +static void se_dev_ctx_shared_mem_cleanup(struct se_if_device_ctx *dev_ctx) +{ + struct se_shared_mem_mgmt_info *se_shared_mem_mgmt = &dev_ctx->se_shared_mem_mgmt; + struct list_head *pending_lists[] = {&se_shared_mem_mgmt->pending_in, + &se_shared_mem_mgmt->pending_out}; + struct se_buf_desc *b_desc, *temp; + int i; + + for (i = 0; i < 2; i++) { + list_for_each_entry_safe(b_desc, temp, + pending_lists[i], link) { + + if (b_desc->shared_buf_ptr) + memset(b_desc->shared_buf_ptr, 0, b_desc->size); + + list_del(&b_desc->link); + kfree(b_desc); + } + } + se_shared_mem_mgmt->secure_mem.pos = 0; + se_shared_mem_mgmt->non_secure_mem.pos = 0; +} + +static int add_b_desc_to_pending_list(void *shared_ptr_with_pos, + struct se_ioctl_setup_iobuf *io, + struct se_if_device_ctx *dev_ctx) +{ + struct se_shared_mem_mgmt_info *se_shared_mem_mgmt = &dev_ctx->se_shared_mem_mgmt; + struct se_buf_desc *b_desc = NULL; + + b_desc = kzalloc(sizeof(*b_desc), GFP_KERNEL); + if (!b_desc) + return -ENOMEM; + + b_desc->shared_buf_ptr = shared_ptr_with_pos; + b_desc->usr_buf_ptr = io->user_buf; + b_desc->size = io->length; + + if (io->flags & SE_IO_BUF_FLAGS_IS_INPUT) { + /* + * buffer is input: + * add an entry in the "pending input buffers" list so + * that copied data can be cleaned from shared memory + * later. + */ + list_add_tail(&b_desc->link, &se_shared_mem_mgmt->pending_in); + } else { + /* + * buffer is output: + * add an entry in the "pending out buffers" list so data + * can be copied to user space when receiving Secure-Enclave + * response. + */ + list_add_tail(&b_desc->link, &se_shared_mem_mgmt->pending_out); + } + + return 0; +} + +/* interface for managed res to unregister a character device */ +static void if_misc_deregister(void *miscdevice) +{ + misc_deregister(miscdevice); +} + +static int init_device_context(struct se_if_priv *priv, int ch_id, + struct se_if_device_ctx **new_dev_ctx, + const struct file_operations *se_if_fops) +{ + const struct se_if_node_info *info = container_of(priv->if_defs, + typeof(*info), + if_defs); + struct se_if_device_ctx *dev_ctx; + int ret = 0; + + if (ch_id) + dev_ctx = kzalloc(sizeof(*dev_ctx), GFP_KERNEL); + else + dev_ctx = devm_kzalloc(priv->dev, sizeof(*dev_ctx), GFP_KERNEL); + + if (!dev_ctx) { + ret = -ENOMEM; + return ret; + } + + dev_ctx->priv = priv; + + if (ch_id) + dev_ctx->devname = kasprintf(GFP_KERNEL, "%s_ch%d", + info->se_name, ch_id); + else + dev_ctx->devname = devm_kasprintf(priv->dev, + GFP_KERNEL, "%s_ch%d", + info->se_name, ch_id); + if (!dev_ctx->devname) { + ret = -ENOMEM; + if (ch_id) + kfree(dev_ctx); + + return ret; + } + + mutex_init(&dev_ctx->fops_lock); + + *new_dev_ctx = dev_ctx; + + if (ch_id) { + list_add_tail(&dev_ctx->link, &priv->dev_ctx_list); + priv->active_devctx_count++; + + ret = init_se_shared_mem(dev_ctx); + if (ret < 0) { + kfree(dev_ctx->devname); + kfree(dev_ctx); + *new_dev_ctx = NULL; + return ret; + } + + return ret; + } + + /* Only for ch_id = 0: + * - register the misc device. + * - add action + */ + dev_ctx->miscdev = devm_kzalloc(priv->dev, sizeof(*dev_ctx->miscdev), GFP_KERNEL); + if (!dev_ctx->miscdev) { + ret = -ENOMEM; + *new_dev_ctx = NULL; + return ret; + } + + dev_ctx->miscdev->name = dev_ctx->devname; + dev_ctx->miscdev->minor = MISC_DYNAMIC_MINOR; + dev_ctx->miscdev->fops = se_if_fops; + dev_ctx->miscdev->parent = priv->dev; + ret = misc_register(dev_ctx->miscdev); + if (ret) { + dev_err(priv->dev, "failed to register misc device %d\n", + ret); + return ret; + } + + ret = devm_add_action(priv->dev, if_misc_deregister, + dev_ctx->miscdev); + if (ret) { + dev_err(priv->dev, + "failed[%d] to add action to the misc-dev\n", + ret); + misc_deregister(dev_ctx->miscdev); + } + + return ret; +} + +static int se_ioctl_cmd_snd_rcv_rsp_handler(struct se_if_device_ctx *dev_ctx, + u64 arg) +{ + const struct se_if_node_info *info = container_of(dev_ctx->priv->if_defs, + typeof(*info), + if_defs); + struct se_ioctl_cmd_snd_rcv_rsp_info cmd_snd_rcv_rsp_info; + struct se_if_node_info_list *info_list + = container_of(info, + typeof(*info_list), + info[info->se_if_id]); + struct se_if_priv *priv = dev_ctx->priv; + struct se_api_msg *tx_msg __free(kfree) = NULL; + struct se_api_msg *rx_msg __free(kfree) = NULL; + int err = 0; + + if (copy_from_user(&cmd_snd_rcv_rsp_info, (u8 __user *)arg, + sizeof(cmd_snd_rcv_rsp_info))) { + dev_err(priv->dev, + "%s: Failed to copy cmd_snd_rcv_rsp_info from user\n", + dev_ctx->devname); + err = -EFAULT; + goto exit; + } + + if (cmd_snd_rcv_rsp_info.tx_buf_sz < SE_MU_HDR_SZ) { + dev_err(priv->dev, + "%s: User buffer too small(%d < %d)\n", + dev_ctx->devname, + cmd_snd_rcv_rsp_info.tx_buf_sz, + SE_MU_HDR_SZ); + err = -ENOSPC; + goto exit; + } + + rx_msg = kzalloc(cmd_snd_rcv_rsp_info.rx_buf_sz, GFP_KERNEL); + if (!rx_msg) { + err = -ENOMEM; + goto exit; + } + + tx_msg = memdup_user(cmd_snd_rcv_rsp_info.tx_buf, + cmd_snd_rcv_rsp_info.tx_buf_sz); + if (IS_ERR(tx_msg)) { + err = PTR_ERR(tx_msg); + goto exit; + } + + if (tx_msg->header.tag != priv->if_defs->cmd_tag) { + err = -EINVAL; + goto exit; + } + + if (tx_msg->header.ver == priv->if_defs->fw_api_ver && + !info_list->load_hsm_fw.is_fw_loaded) { + err = se_load_firmware(priv); + if (err) { + dev_err(priv->dev, "Could not send the message as FW is not loaded."); + err = -EPERM; + goto exit; + } + } + err = ele_msg_send_rcv(dev_ctx, + tx_msg, + cmd_snd_rcv_rsp_info.tx_buf_sz, + rx_msg, + cmd_snd_rcv_rsp_info.rx_buf_sz); + if (err < 0) + goto exit; + + dev_dbg(priv->dev, + "%s: %s %s\n", + dev_ctx->devname, + __func__, + "message received, start transmit to user"); + + /* We may need to copy the output data to user before + * delivering the completion message. + */ + err = se_dev_ctx_cpy_out_data(dev_ctx); + if (err < 0) + goto exit; + + /* Copy data from the buffer */ + print_hex_dump_debug("to user ", DUMP_PREFIX_OFFSET, 4, 4, + rx_msg, + cmd_snd_rcv_rsp_info.rx_buf_sz, false); + + if (copy_to_user(cmd_snd_rcv_rsp_info.rx_buf, rx_msg, + cmd_snd_rcv_rsp_info.rx_buf_sz)) { + dev_err(priv->dev, + "%s: Failed to copy to user\n", + dev_ctx->devname); + err = -EFAULT; + } + +exit: + se_dev_ctx_shared_mem_cleanup(dev_ctx); + + if (copy_to_user((void __user *)arg, &cmd_snd_rcv_rsp_info, + sizeof(cmd_snd_rcv_rsp_info))) { + dev_err(priv->dev, + "%s: Failed to copy cmd_snd_rcv_rsp_info from user\n", + dev_ctx->devname); + err = -EFAULT; + } + + return err; +} + +static int se_ioctl_get_mu_info(struct se_if_device_ctx *dev_ctx, + u64 arg) +{ + struct se_if_priv *priv = dev_ctx->priv; + struct se_if_node_info *info; + struct se_ioctl_get_if_info if_info; + int err = 0; + + info = container_of(priv->if_defs, typeof(*info), if_defs); + + if_info.se_if_id = info->se_if_id; + if_info.interrupt_idx = 0; + if_info.tz = 0; + if_info.did = info->se_if_did; + if_info.cmd_tag = priv->if_defs->cmd_tag; + if_info.rsp_tag = priv->if_defs->rsp_tag; + if_info.success_tag = priv->if_defs->success_tag; + if_info.base_api_ver = priv->if_defs->base_api_ver; + if_info.fw_api_ver = priv->if_defs->fw_api_ver; + + dev_dbg(priv->dev, + "%s: info [se_if_id: %d, irq_idx: %d, tz: 0x%x, did: 0x%x]\n", + dev_ctx->devname, + if_info.se_if_id, if_info.interrupt_idx, + if_info.tz, if_info.did); + + if (copy_to_user((u8 __user *)arg, &if_info, sizeof(if_info))) { + dev_err(priv->dev, + "%s: Failed to copy mu info to user\n", + dev_ctx->devname); + err = -EFAULT; + goto exit; + } + +exit: + return err; +} + +/* + * Copy a buffer of data to/from the user and return the address to use in + * messages + */ +static int se_ioctl_setup_iobuf_handler(struct se_if_device_ctx *dev_ctx, + u64 arg) +{ + struct se_shared_mem *shared_mem = NULL; + struct se_ioctl_setup_iobuf io = {0}; + int err = 0; + u32 pos; + + if (copy_from_user(&io, (u8 __user *)arg, sizeof(io))) { + dev_err(dev_ctx->priv->dev, + "%s: Failed copy iobuf config from user\n", + dev_ctx->devname); + err = -EFAULT; + goto exit; + } + + dev_dbg(dev_ctx->priv->dev, + "%s: io [buf: %p(%d) flag: %x]\n", + dev_ctx->devname, + io.user_buf, io.length, io.flags); + + if (io.length == 0 || !io.user_buf) { + /* + * Accept NULL pointers since some buffers are optional + * in FW commands. In this case we should return 0 as + * pointer to be embedded into the message. + * Skip all data copy part of code below. + */ + io.ele_addr = 0; + goto copy; + } + + /* No specific requirement for this buffer. */ + shared_mem = &dev_ctx->se_shared_mem_mgmt.non_secure_mem; + + /* Check there is enough space in the shared memory. */ + if (shared_mem->size < shared_mem->pos || + round_up(io.length, 8u) >= (shared_mem->size - shared_mem->pos)) { + dev_err(dev_ctx->priv->dev, + "%s: Not enough space in shared memory\n", + dev_ctx->devname); + err = -ENOMEM; + goto exit; + } + + /* Allocate space in shared memory. 8 bytes aligned. */ + pos = shared_mem->pos; + shared_mem->pos += round_up(io.length, 8u); + io.ele_addr = (u64)shared_mem->dma_addr + pos; + + memset(shared_mem->ptr + pos, 0, io.length); + if ((io.flags & SE_IO_BUF_FLAGS_IS_INPUT) || + (io.flags & SE_IO_BUF_FLAGS_IS_IN_OUT)) { + /* + * buffer is input: + * copy data from user space to this allocated buffer. + */ + if (copy_from_user(shared_mem->ptr + pos, io.user_buf, + io.length)) { + dev_err(dev_ctx->priv->dev, + "%s: Failed copy data to shared memory\n", + dev_ctx->devname); + err = -EFAULT; + goto exit; + } + } + + err = add_b_desc_to_pending_list(shared_mem->ptr + pos, + &io, + dev_ctx); + if (err < 0) + dev_err(dev_ctx->priv->dev, + "%s: Failed to allocate/link b_desc.", + dev_ctx->devname); + +copy: + /* Provide the EdgeLock Enclave address to user space only if success.*/ + if (copy_to_user((u8 __user *)arg, &io, sizeof(io))) { + dev_err(dev_ctx->priv->dev, + "%s: Failed to copy iobuff setup to user.", + dev_ctx->devname); + err = -EFAULT; + goto exit; + } +exit: + return err; +} + +/* IOCTL to provide SoC information */ +static int se_ioctl_get_se_soc_info_handler(struct se_if_device_ctx *dev_ctx, + u64 arg) +{ + const struct se_if_node_info_list *info_list; + struct se_ioctl_get_soc_info soc_info; + int err = -EINVAL; + + info_list = device_get_match_data(dev_ctx->priv->dev); + if (!info_list) + goto exit; + + soc_info.soc_id = info_list->soc_id; + soc_info.soc_rev = se_soc_rev; + + err = (int)copy_to_user((u8 __user *)arg, (u8 *)(&soc_info), sizeof(soc_info)); + if (err) { + dev_err(dev_ctx->priv->dev, + "%s: Failed to copy soc info to user\n", + dev_ctx->devname); + err = -EFAULT; + goto exit; + } + +exit: + return err; +} + +/* + * File operations for user-space + */ + +/* Write a message to the MU. */ +static ssize_t se_if_fops_write(struct file *fp, const char __user *buf, + size_t size, loff_t *ppos) +{ + struct se_if_device_ctx *dev_ctx = fp->private_data; + struct se_api_msg *tx_msg __free(kfree) = NULL; + struct se_if_priv *priv = dev_ctx->priv; + int err; + + dev_dbg(priv->dev, + "%s: write from buf (%p)%zu, ppos=%lld\n", + dev_ctx->devname, + buf, size, ((ppos) ? *ppos : 0)); + + if (mutex_lock_interruptible(&dev_ctx->fops_lock)) + return -EBUSY; + + if (dev_ctx != priv->cmd_receiver_clbk_hdl.dev_ctx) { + err = -EINVAL; + goto exit; + } + + if (size < SE_MU_HDR_SZ) { + dev_err(priv->dev, + "%s: User buffer too small(%zu < %d)\n", + dev_ctx->devname, + size, SE_MU_HDR_SZ); + err = -ENOSPC; + goto exit; + } + + tx_msg = memdup_user(buf, size); + if (IS_ERR(tx_msg)) { + err = PTR_ERR(tx_msg); + goto exit; + } + + print_hex_dump_debug("from user ", DUMP_PREFIX_OFFSET, 4, 4, + tx_msg, size, false); + + err = ele_msg_send(dev_ctx, tx_msg, size); + if (err < 0) + goto exit; +exit: + mutex_unlock(&dev_ctx->fops_lock); + return err; +} + +/* + * Read a message from the MU. + * Blocking until a message is available. + */ +static ssize_t se_if_fops_read(struct file *fp, char __user *buf, + size_t size, loff_t *ppos) +{ + struct se_if_device_ctx *dev_ctx = fp->private_data; + struct se_if_priv *priv = dev_ctx->priv; + int err; + + dev_dbg(priv->dev, + "%s: read to buf %p(%zu), ppos=%lld\n", + dev_ctx->devname, + buf, size, ((ppos) ? *ppos : 0)); + + if (mutex_lock_interruptible(&dev_ctx->fops_lock)) + return -EBUSY; + + if (dev_ctx != priv->cmd_receiver_clbk_hdl.dev_ctx) { + err = -EINVAL; + goto exit; + } + + err = ele_msg_rcv(dev_ctx, &priv->cmd_receiver_clbk_hdl); + if (err < 0) { + dev_err(priv->dev, + "%s: Err[0x%x]:Interrupted by signal.\n", + dev_ctx->devname, err); + dev_dbg(priv->dev, + "Current active dev-ctx count = %d.\n", + dev_ctx->priv->active_devctx_count); + goto exit; + } + + /* We may need to copy the output data to user before + * delivering the completion message. + */ + err = se_dev_ctx_cpy_out_data(dev_ctx); + if (err < 0) + goto exit; + + /* Copy data from the buffer */ + print_hex_dump_debug("to user ", DUMP_PREFIX_OFFSET, 4, 4, + priv->cmd_receiver_clbk_hdl.rx_msg, + priv->cmd_receiver_clbk_hdl.rx_msg_sz, + false); + + if (copy_to_user(buf, priv->cmd_receiver_clbk_hdl.rx_msg, + priv->cmd_receiver_clbk_hdl.rx_msg_sz)) { + dev_err(priv->dev, + "%s: Failed to copy to user\n", + dev_ctx->devname); + err = -EFAULT; + } + err = priv->cmd_receiver_clbk_hdl.rx_msg_sz; +exit: + priv->cmd_receiver_clbk_hdl.rx_msg_sz = 0; + + se_dev_ctx_shared_mem_cleanup(dev_ctx); + + mutex_unlock(&dev_ctx->fops_lock); + return err; +} + +/* Open a character device. */ +static int se_if_fops_open(struct inode *nd, struct file *fp) +{ + struct miscdevice *miscdev = fp->private_data; + struct se_if_priv *priv = dev_get_drvdata(miscdev->parent); + struct se_if_device_ctx *misc_dev_ctx = priv->priv_dev_ctx; + struct se_if_device_ctx *dev_ctx; + int err = 0; + + if (mutex_lock_interruptible(&misc_dev_ctx->fops_lock)) + return -EBUSY; + + priv->dev_ctx_mono_count++; + err = init_device_context(priv, + priv->dev_ctx_mono_count ? + priv->dev_ctx_mono_count + : priv->dev_ctx_mono_count++, + &dev_ctx, NULL); + if (err) { + dev_err(priv->dev, + "Failed[0x%x] to create device contexts.\n", + err); + goto exit; + } + + fp->private_data = dev_ctx; + +exit: + mutex_unlock(&misc_dev_ctx->fops_lock); + return err; +} + +/* Close a character device. */ +static int se_if_fops_close(struct inode *nd, struct file *fp) +{ + struct se_if_device_ctx *dev_ctx = fp->private_data; + struct se_if_priv *priv = dev_ctx->priv; + + if (mutex_lock_interruptible(&dev_ctx->fops_lock)) + return -EBUSY; + + /* check if this device was registered as command receiver. */ + if (priv->cmd_receiver_clbk_hdl.dev_ctx == dev_ctx) { + priv->cmd_receiver_clbk_hdl.dev_ctx = NULL; + kfree(priv->cmd_receiver_clbk_hdl.rx_msg); + priv->cmd_receiver_clbk_hdl.rx_msg = NULL; + } + + se_dev_ctx_shared_mem_cleanup(dev_ctx); + cleanup_se_shared_mem(dev_ctx); + + priv->active_devctx_count--; + list_del(&dev_ctx->link); + + mutex_unlock(&dev_ctx->fops_lock); + kfree(dev_ctx->devname); + kfree(dev_ctx); + + return 0; +} + +/* IOCTL entry point of a character device */ +static long se_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) +{ + struct se_if_device_ctx *dev_ctx = fp->private_data; + struct se_if_priv *priv = dev_ctx->priv; + int err; + + /* Prevent race during change of device context */ + if (mutex_lock_interruptible(&dev_ctx->fops_lock)) + return -EBUSY; + + switch (cmd) { + case SE_IOCTL_ENABLE_CMD_RCV: + if (!priv->cmd_receiver_clbk_hdl.dev_ctx) { + if (!priv->cmd_receiver_clbk_hdl.rx_msg) { + priv->cmd_receiver_clbk_hdl.rx_msg + = kzalloc(MAX_NVM_MSG_LEN, + GFP_KERNEL); + if (!priv->cmd_receiver_clbk_hdl.rx_msg) { + err = -ENOMEM; + break; + } + } + priv->cmd_receiver_clbk_hdl.rx_msg_sz = MAX_NVM_MSG_LEN; + priv->cmd_receiver_clbk_hdl.dev_ctx = dev_ctx; + err = 0; + } else { + err = -EBUSY; + } + break; + case SE_IOCTL_GET_MU_INFO: + err = se_ioctl_get_mu_info(dev_ctx, arg); + break; + case SE_IOCTL_SETUP_IOBUF: + err = se_ioctl_setup_iobuf_handler(dev_ctx, arg); + break; + case SE_IOCTL_GET_SOC_INFO: + err = se_ioctl_get_se_soc_info_handler(dev_ctx, arg); + break; + case SE_IOCTL_CMD_SEND_RCV_RSP: + err = se_ioctl_cmd_snd_rcv_rsp_handler(dev_ctx, arg); + break; + default: + err = -EINVAL; + dev_dbg(priv->dev, + "%s: IOCTL %.8x not supported\n", + dev_ctx->devname, + cmd); + } + + mutex_unlock(&dev_ctx->fops_lock); + + return (long)err; +} + +/* Char driver setup */ +static const struct file_operations se_if_fops = { + .open = se_if_fops_open, + .owner = THIS_MODULE, + .release = se_if_fops_close, + .unlocked_ioctl = se_ioctl, + .read = se_if_fops_read, + .write = se_if_fops_write, +}; + /* interface for managed res to free a mailbox channel */ static void if_mbox_free_channel(void *mbox_chan) { @@ -348,6 +1105,7 @@ static int se_if_request_channel(struct device *dev, static void se_if_probe_cleanup(void *plat_dev) { + struct se_if_device_ctx *dev_ctx, *t_dev_ctx; struct platform_device *pdev = plat_dev; struct device *dev = &pdev->dev; struct se_fw_load_info *load_fw; @@ -372,6 +1130,18 @@ static void se_if_probe_cleanup(void *plat_dev) load_fw->imem.buf = NULL; } + if (priv->dev_ctx_mono_count) { + list_for_each_entry_safe(dev_ctx, t_dev_ctx, &priv->dev_ctx_list, link) { + list_del(&dev_ctx->link); + priv->active_devctx_count--; + } + } + + if (priv->priv_dev_ctx && priv->priv_dev_ctx->miscdev) { + devm_remove_action(dev, if_misc_deregister, &priv->priv_dev_ctx->miscdev); + misc_deregister(priv->priv_dev_ctx->miscdev); + } + /* No need to check, if reserved memory is allocated * before calling for its release. Or clearing the * un-set bit. @@ -456,6 +1226,7 @@ static int se_if_probe(struct platform_device *pdev) goto exit; } } + INIT_LIST_HEAD(&priv->dev_ctx_list); if (info->reserved_dma_ranges) { ret = of_reserved_mem_device_init(dev); @@ -467,6 +1238,14 @@ static int se_if_probe(struct platform_device *pdev) } } + ret = init_device_context(priv, 0, &priv->priv_dev_ctx, &se_if_fops); + if (ret) { + dev_err(dev, + "Failed[0x%x] to create device contexts.\n", + ret); + goto exit; + } + ret = se_soc_info(priv); if (ret) { dev_err(dev, diff --git a/drivers/firmware/imx/se_ctrl.h b/drivers/firmware/imx/se_ctrl.h index de0d4a1bcb9e..a7f740e83a7c 100644 --- a/drivers/firmware/imx/se_ctrl.h +++ b/drivers/firmware/imx/se_ctrl.h @@ -13,6 +13,7 @@ #define MAX_FW_LOAD_RETRIES 50 #define RES_STATUS(x) FIELD_GET(0x000000ff, x) +#define MAX_DATA_SIZE_PER_USER (65 * 1024) #define MAX_NVM_MSG_LEN (256) #define MESSAGING_VERSION_6 0x6 #define MESSAGING_VERSION_7 0x7 @@ -31,7 +32,7 @@ struct se_clbk_handle { struct completion done; bool signal_rcvd; - atomic_t pending_hdr; + struct se_if_device_ctx *dev_ctx; u32 rx_msg_sz; /* Assignment of the rx_msg buffer to held till the * received content as part callback function, is copied. @@ -46,6 +47,40 @@ struct se_imem_buf { u32 state; }; +struct se_buf_desc { + u8 *shared_buf_ptr; + void __user *usr_buf_ptr; + u32 size; + struct list_head link; +}; + +struct se_shared_mem { + dma_addr_t dma_addr; + u32 size; + u32 pos; + u8 *ptr; +}; + +struct se_shared_mem_mgmt_info { + struct list_head pending_in; + struct list_head pending_out; + + struct se_shared_mem secure_mem; + struct se_shared_mem non_secure_mem; +}; + +/* Private struct for each char device instance. */ +struct se_if_device_ctx { + struct se_if_priv *priv; + struct miscdevice *miscdev; + const char *devname; + + struct mutex fops_lock; + + struct se_shared_mem_mgmt_info se_shared_mem_mgmt; + struct list_head link; +}; + /* Header of the messages exchange with the EdgeLock Enclave */ struct se_msg_hdr { u8 ver; @@ -89,6 +124,11 @@ struct se_if_priv { struct gen_pool *mem_pool; const struct se_if_defines *if_defs; + + struct se_if_device_ctx *priv_dev_ctx; + struct list_head dev_ctx_list; + u32 active_devctx_count; + u32 dev_ctx_mono_count; }; #endif diff --git a/include/uapi/linux/se_ioctl.h b/include/uapi/linux/se_ioctl.h new file mode 100644 index 000000000000..582e3fef086e --- /dev/null +++ b/include/uapi/linux/se_ioctl.h @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause*/ +/* + * Copyright 2024 NXP + */ + +#ifndef SE_IOCTL_H +#define SE_IOCTL_H + +/* IOCTL definitions. */ + +struct se_ioctl_setup_iobuf { + void __user *user_buf; + u32 length; + u32 flags; + u64 ele_addr; +}; + +struct se_ioctl_shared_mem_cfg { + u32 base_offset; + u32 size; +}; + +struct se_ioctl_get_if_info { + u8 se_if_id; + u8 interrupt_idx; + u8 tz; + u8 did; + u8 cmd_tag; + u8 rsp_tag; + u8 success_tag; + u8 base_api_ver; + u8 fw_api_ver; +}; + +struct se_ioctl_cmd_snd_rcv_rsp_info { + u32 __user *tx_buf; + int tx_buf_sz; + u32 __user *rx_buf; + int rx_buf_sz; +}; + +struct se_ioctl_get_soc_info { + u16 soc_id; + u16 soc_rev; +}; + +/* IO Buffer Flags */ +#define SE_IO_BUF_FLAGS_IS_OUTPUT (0x00u) +#define SE_IO_BUF_FLAGS_IS_INPUT (0x01u) +#define SE_IO_BUF_FLAGS_USE_SEC_MEM (0x02u) +#define SE_IO_BUF_FLAGS_USE_SHORT_ADDR (0x04u) +#define SE_IO_BUF_FLAGS_IS_IN_OUT (0x10u) + +/* IOCTLS */ +#define SE_IOCTL 0x0A /* like MISC_MAJOR. */ + +/* + * ioctl to designated the current fd as logical-reciever. + * This is ioctl is send when the nvm-daemon, a slave to the + * firmware is started by the user. + */ +#define SE_IOCTL_ENABLE_CMD_RCV _IO(SE_IOCTL, 0x01) + +/* + * ioctl to get the buffer allocated from the memory, which is shared + * between kernel and FW. + * Post allocation, the kernel tagged the allocated memory with: + * Output + * Input + * Input-Output + * Short address + * Secure-memory + */ +#define SE_IOCTL_SETUP_IOBUF _IOWR(SE_IOCTL, 0x03, \ + struct se_ioctl_setup_iobuf) + +/* + * ioctl to get the mu information, that is used to exchange message + * with FW, from user-spaced. + */ +#define SE_IOCTL_GET_MU_INFO _IOR(SE_IOCTL, 0x04, \ + struct se_ioctl_get_if_info) +/* + * ioctl to get SoC Info from user-space. + */ +#define SE_IOCTL_GET_SOC_INFO _IOR(SE_IOCTL, 0x06, \ + struct se_ioctl_get_soc_info) + +/* + * ioctl to send command and receive response from user-space. + */ +#define SE_IOCTL_CMD_SEND_RCV_RSP _IOWR(SE_IOCTL, 0x07, \ + struct se_ioctl_cmd_snd_rcv_rsp_info) +#endif