From patchwork Thu May 23 10:49:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 13671613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E94EFC25B79 for ; Thu, 23 May 2024 10:53:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=PPEDGgibT8USszYqyrxlZFwLxBE7KutiVwlP4RaN2hI=; b=wFiqJm+HeFNmYdwVFLYogg1/Nq hiIeDqVWfggMjR3BNVN0fUQAT8gvfuEoFEMxxTdKFLzPkIvfeGuS0BHMgGqeu8XGr/8Uc/LL4Eq/5 0mO6czWyfcA5JVA5xdhs+68jfGfg9vP/225ouGqAMBycay9EzMyKuB1FDDvCD52I6bxwSGBzwnR1h kkZ8l4DpuBilNVzgxHsCXZxp6I9uGnZDkM9fQ9NDfScPl8WcCA7kIkgUy1Mx+h9SOBlJsRxrVppPV wM4te3k8yfrWmdTwjjrFwmPuSdFjli/ROT27UJ6Us+I8isZB/xioaTAtNJr0FOVTOPh2CuFxuLN/a LPwG+Lmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sA644-00000005wwS-21ki; Thu, 23 May 2024 10:52:52 +0000 Received: from mail-db3eur04on0622.outbound.protection.outlook.com ([2a01:111:f400:fe0c::622] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sA63z-00000005wpw-3hlx for linux-arm-kernel@lists.infradead.org; Thu, 23 May 2024 10:52:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oAWCVR6kGYtH+9Cwuaaf4ZWvlmXSA688P+WP5eFbn9abj9Yz/fuEdr0Cl4ckxUjqHTQx9VjyqzFPT7UDeNjMoxV+2aLgHS8CbPADmnJ7Y7Sk5NP/9ibvDBU6L9ux+WA2RXEPRDUYpFJIqpWMi6zjuewUqhvGnjj29CHuyuqUXS/4mMUKkPL8FVQrSjj/HZ8XdAtOU1BT8Wicp1/abUaajNvz3CwgZpouVqU5ygJVYa74bkS/nEe7TUVGYEsWeXTLg+BcVS/mNhR5BvQWMFxH6e3SgawkJ1VMWi8zIr0zBlNN33WsjyrX3bbD2iSStULMTvFLPhYiXWZ/zXV7dkihMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wUUkBLMg0O8LrsxQpmu3PouhOIOH0gJxqVubz2X/YPI=; b=YLozlUIYH7KQc6hZIBCpPc6nyv11TWiNRCTSBahx7g/UTlT/eaOX5A193sy0HAz8wFHbrJgvGM9KBV8fWA1sMR70MGbQfmQl9u4bwg6ByDGZvDyBM6yDlNDW0w08JyMHTx8wFNRaEZCnHG958LU36K4hlX+3mifjURsYaLpj2gHKxBIirpj1gVWty2rwFL9L3uVdgawI15EAQYCyVydRFgZrONHexu/IwQo7Ce9bUCV4WhoNin6NPe37VBlMFiWgGjQbZW9X0KK4AZ6QUxcaLfH7ADAiX8Vs2sZcQ0UzT4zvN1NWwJbAWoYHOofoXT395PfWXaSXfH1vHZABgYqPRA== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wUUkBLMg0O8LrsxQpmu3PouhOIOH0gJxqVubz2X/YPI=; b=IJe5wlnn3qXoxhTn+lEotQQy61vBRuFjLxcop71f1tisPvxN7bs73eS0yStawiSTkPl4AGzepUnBW1ts+FvjitulA7wm4f42x9mFILN6YySdzf5xTNGhXkclAi2+bn84ipS+BjBn9r4XGbRcjyFptzoBgbv0ddI0NCX6nWQgQs0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8604.eurprd04.prod.outlook.com (2603:10a6:20b:43b::21) by AM8PR04MB7474.eurprd04.prod.outlook.com (2603:10a6:20b:1d9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36; Thu, 23 May 2024 10:52:31 +0000 Received: from AM9PR04MB8604.eurprd04.prod.outlook.com ([fe80::e751:223e:aa3d:5827]) by AM9PR04MB8604.eurprd04.prod.outlook.com ([fe80::e751:223e:aa3d:5827%4]) with mapi id 15.20.7587.035; Thu, 23 May 2024 10:52:31 +0000 From: Pankaj Gupta Date: Thu, 23 May 2024 16:19:32 +0530 Subject: [PATCH v2 1/5] Documentation/firmware: add imx/se to other_interfaces Message-Id: <20240523-imx-se-if-v2-1-5a6fd189a539@nxp.com> References: <20240523-imx-se-if-v2-0-5a6fd189a539@nxp.com> In-Reply-To: <20240523-imx-se-if-v2-0-5a6fd189a539@nxp.com> To: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Rob Herring , Krzysztof Kozlowski 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, Pankaj Gupta X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1716461396; l=6534; i=pankaj.gupta@nxp.com; s=20240523; h=from:subject:message-id; bh=EUeRLH1u3HnFhFGQ8WFYu1U3Bzgyf144085PpyjlZlA=; b=JkxurDtEA24/RbdCmoLqw5ywhcljghkKxJbkhG/Hm2EHk3zy/Pd2Th3/l4eo0X3EQjR1UaAGp cHqvV8luWZKAfN4Ow7v0cQ5BdcglbHQZK1qnuFm8D06redlFXauDCIM X-Developer-Key: i=pankaj.gupta@nxp.com; a=ed25519; pk=OA0pBQoupy5lV0XfKzD8B0OOBVB6tpAoIf+0x1bYGRg= X-ClientProxiedBy: SI2PR01CA0027.apcprd01.prod.exchangelabs.com (2603:1096:4:192::7) To AM9PR04MB8604.eurprd04.prod.outlook.com (2603:10a6:20b:43b::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8604:EE_|AM8PR04MB7474:EE_ X-MS-Office365-Filtering-Correlation-Id: aacb6be4-5423-460b-f759-08dc7b1671dd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|366007|1800799015|52116005|376005|38350700005|921011; X-Microsoft-Antispam-Message-Info: =?utf-8?q?miiyHMVd0838B1Yb8IzeYEbN7Rk5+FY?= =?utf-8?q?dk0aijzEv5U3WG01JF17fJ14wlXPEihLHE/e56DuEAAQvfXPLSFQyr6UXUtzEUYEl?= =?utf-8?q?EWsqc0t2ozuDztsxK/zwKOlrkCZ2gtzz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TVlXlTaeeFlL7/NJ80G?= =?utf-8?q?lI9pMQ1fBVWHAVLtiWIYNlwAOT3Se4Nw9eRkO9Ij7NL6YaP0IT0l5tUAFXhAs8aRZ?= =?utf-8?q?g/POk0bEmdO7XqHZzjpyVfqtfBn2eioSy5Hi4zGDZnnevU54gVFIGrjdnu3O7JsD3?= =?utf-8?q?Ky4dwKLhLzY/Oy0CuSxs0fAKEY2n4kMN+97VsvwSuk53N21zDo7KI/RC9a18akYuy?= =?utf-8?q?bkgpF5lMJzQ5R1oBaF/uw3M8bwZZQm1K64ID5s4EepLas9O6DOWukae8TfIHNo7Vy?= =?utf-8?q?ioRozFq494BFj5R5XnEoCLlD4di7Po+0Z2qfvQ0UxDU0M50jgxIowwcA=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8604.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(366007)(1800799015)(52116005)(376005)(38350700005)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?c0TNQTVFTTecL00m/6QKDqZw7d8k?= =?utf-8?q?8Q6/MQUexEgADR6jg706TdnJz6pZnoXYV9/0zjvxW91FLr2og3XsLP2U5cCfFhku+?= =?utf-8?q?kg24EUhNEk4UOq/0+IBA1FwnGijwRbS/6PAM80LdNBmSgHYnR6qmUuJJSNLNjCkBN?= =?utf-8?q?1HDyDEkPOQ46jq86sYLBa2I7Kv4Br72X9TcqkFiiO/3SgjskfAV+Kj7zlw4UAFYNs?= =?utf-8?q?udOd/0QbpiBapJY6akc26TMxtSDr74iK6H1qs7Llz3HvIxYFu3gErH+IBQPDX7xBw?= =?utf-8?q?woEnqqJ6wJkRHMDGmFSiyVBd1HAaPY0enZp0Arl+/tLjVq7oCyCzMSlxguFSfA8iB?= =?utf-8?q?agtz/dSGs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9AeCPd945HXdaZ5keIsWCdZkcclJ9f2Zxi8ZWP?= =?utf-8?q?qZfGukKHHKtq8VF9oKzT0bn1G/7XosbZKz21O0Urq7X9VDLGSAAwAUyBZpCfV/2XU?= =?utf-8?q?umj73VMuGf8lsjA2d3lkVmBMLJgH2IVeIZGg5H4rgLb5MhYl/kcEBgjK9KgOwkkWN?= =?utf-8?q?urOkNv390ftVFSWWxeMs406DolBRV4evjHr2RRWn4JhBcHh7Zz3hSCdiO9drIdWp6?= =?utf-8?q?+PNgcWg5fXlVEH44nNCPLGWmP0fML+A2n6v33bsx7KPfVQDKK/QCtTq37OuFSl/0B?= =?utf-8?q?GjHoiFU1VNZW?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: aacb6be4-5423-460b-f759-08dc7b1671dd X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8604.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 10:52:31.0942 (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: o/4C4jPFwYm1GaRW03p6oMvjuZDh1yAy8RTnPcJXXdZLkggIEuCoYSgc5jYeW7ukbh+f1UWYMIQOvNde91bRKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7474 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240523_035248_124503_62302E82 X-CRM114-Status: GOOD ( 13.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 | 119 +++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/Documentation/driver-api/firmware/other_interfaces.rst b/Documentation/driver-api/firmware/other_interfaces.rst index 06ac89adaafb..65e69396e22a 100644 --- a/Documentation/driver-api/firmware/other_interfaces.rst +++ b/Documentation/driver-api/firmware/other_interfaces.rst @@ -49,3 +49,122 @@ 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 exists. + +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 +MU(s), 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 +-------------------------------- +All those SE interfaces 'se-if' that is/are dedicated to a particular SE, will be +enumerated and provisioned under the very single 'SE' node. + +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, + user-space 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 uses 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 Thu May 23 10:49:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 13671615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7389FC25B75 for ; Thu, 23 May 2024 10:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=j0rZN0u8+/q4YrCnLaYAORrS4j8j4ZYF1IS8++hDrCE=; b=VmJi3fyQSP6TMphh3+Q3xn6M5F qcaWz6b+R2wqyvz5Qgfc+Ua8yEH1Rw+5V9QODNHYmsKMjXsEC5c3iDGc4eY6fSf9lf1rBaYdCtzD8 px67yfn6lsmDzFxddD64XuKLbFrAGXWY+KMzT8jAGeQou8xVrpuLwBywOVPurZ53EXlLgh9w5PS10 KRB+gXfThjDIIsvfU9jELFQDu6Q3bSFxyCJcEoBGd4TOmgMGvLpWkjWjs67cMqts12G927GbRcfyR c8s1xxrMR+aqlfAuI//HZmzcTe8D97ylLsTEKcvI3HxqCkIB6yT5XIG+kQvm4mjI4ioYIL58Xo/61 a4edaTQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sA64I-00000005x3C-1CDz; Thu, 23 May 2024 10:53:06 +0000 Received: from mail-db3eur04on0622.outbound.protection.outlook.com ([2a01:111:f400:fe0c::622] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sA642-00000005wpw-2Dbt for linux-arm-kernel@lists.infradead.org; Thu, 23 May 2024 10:52:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tf5rA2xJssz9gORdVbWpdLPaqXgajtxYuOGtOwOdE8ZnM8MX7zvgoxXa38PqW00zY8iRNVOSCS6Dx0FF/VUPuuPRTmMWO/M6ShEVgcs+1vdhUjwD2xj7yRDK8AkBcVUVs7iIZ0wMp0NgEp5Cke0w6YS0J5eTpX3lGKSD3LcTrci4pz2PWr1POjw8QtD3Yz+aSqR5wOqPlFu6lsCMuDBzolYxqNesklztYwsJeSExI/42MP9sfZagmLeVWzQMJiSiJud+xUPiyspZYgIuqFqevDAoF9zNj2CuuorcwOWeMoScrOzPKr4RS6A0FQv/D/fnsHFe1BLnds3mjD0S3niajA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MZltA1ZA8XBbyBwdEZ4b9dyfEx7WJ7IojPm5PxeAyb0=; b=RkJj8OFvBZQ23o/BvuHJNPhp2fEvdpnQyjczuaoQG0GvTacvf91i3pDvOnqYHMRvwIqhBNOMmOLiZqzK3mSOQK1V/V7eh2I9fWNdrgbFpa0MF6/nMr4UaevWqDrNcBjNjW2YhhftCfUtCztT5uzQtLDnTpvHAbQZzC7rRmDvMPjJHp+22m+ovgsI7ReX0hjZ/F+GmcTBcsu14nBnzAydOIx5Q2M0YxVFhxvKtF/8e0Lz6FWTaaqU+OA6R+H41VDsDmgOFfH6swlZyfy9RGlfJ4BlhfW0ajRIGvC2YZtoiN6Rg6MONpk0XUx+evOTv9Gknc6zXrGsDahM3CapQBEm8Q== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MZltA1ZA8XBbyBwdEZ4b9dyfEx7WJ7IojPm5PxeAyb0=; b=VqF5C9GOtXVBS4/wuZIwfnMFcsA/PP95T90L/sDfTu3FxdsfPPQkUrUaPT4A/ea94WjA0W9Afg3wTvlW47J5M+nDl2TpK04vYbE6nFJyJVG2DwZ6MTbiXyyDolwZogjsFpjMhqI5ue7bARNKvrfojleY4x0AFmBnxP2HNt+5ZMg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8604.eurprd04.prod.outlook.com (2603:10a6:20b:43b::21) by AM8PR04MB7474.eurprd04.prod.outlook.com (2603:10a6:20b:1d9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36; Thu, 23 May 2024 10:52:37 +0000 Received: from AM9PR04MB8604.eurprd04.prod.outlook.com ([fe80::e751:223e:aa3d:5827]) by AM9PR04MB8604.eurprd04.prod.outlook.com ([fe80::e751:223e:aa3d:5827%4]) with mapi id 15.20.7587.035; Thu, 23 May 2024 10:52:37 +0000 From: Pankaj Gupta Date: Thu, 23 May 2024 16:19:33 +0530 Subject: [PATCH v2 2/5] dt-bindings: arm: fsl: add imx-se-fw binding doc Message-Id: <20240523-imx-se-if-v2-2-5a6fd189a539@nxp.com> References: <20240523-imx-se-if-v2-0-5a6fd189a539@nxp.com> In-Reply-To: <20240523-imx-se-if-v2-0-5a6fd189a539@nxp.com> To: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Rob Herring , Krzysztof Kozlowski 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, Pankaj Gupta X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1716461396; l=5119; i=pankaj.gupta@nxp.com; s=20240523; h=from:subject:message-id; bh=MuhBVsZUiI5VFPmv9lk7WXE1TbDKt5rB2RVcpcQVO7I=; b=w6fbQBlSTkOflp/dwQjjCb6ENBEUre9TP+QIs3bCen6ZoiCugS2nXXC+vdfMBbVtOebEXxVsQ w38+bL0zmojB4dlkLmptmCvEdZPLugN9fTJkoMcwquQeo2f2kBTwLD1 X-Developer-Key: i=pankaj.gupta@nxp.com; a=ed25519; pk=OA0pBQoupy5lV0XfKzD8B0OOBVB6tpAoIf+0x1bYGRg= X-ClientProxiedBy: SI2PR01CA0027.apcprd01.prod.exchangelabs.com (2603:1096:4:192::7) To AM9PR04MB8604.eurprd04.prod.outlook.com (2603:10a6:20b:43b::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8604:EE_|AM8PR04MB7474:EE_ X-MS-Office365-Filtering-Correlation-Id: 6833a1db-9e41-4bc5-8508-08dc7b167565 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|366007|1800799015|52116005|376005|38350700005|921011; X-Microsoft-Antispam-Message-Info: =?utf-8?q?tRvVYOOYbcf5zyqFhuNvrGwmPC8Tp+v?= =?utf-8?q?sQvKfGxDAHw5GLAfgiUYI1LuoK1/gsNXAr3ms1Pcfgyzv/0LAAQWuwSdizNW+2o3x?= =?utf-8?q?YQ7cPy9QfGpjcSmKL+Kl04hBD3woE8Yw2PhK+c6OR70IsKHDUJ9BaIWigi/MIGHSD?= =?utf-8?q?SWttNGNQeC2DT+srS4Bdw551lw8UwYEVfP8vm+1Ek6n7FY7of6VZl3ywDONmoYjYH?= =?utf-8?q?knD/2B1nFyFrsd6tn/CjPdeAHaoQ8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KVIN+vjLUtSoNGugFm?= =?utf-8?q?ESrYDu1YSYvZ7Zc+bfPX6n2E8eb6Qt0zvl4Uw9yyuuivCLpMnO+mDufr0pVQxGIXT?= =?utf-8?q?7KIvyf0g6FDhgQbaMxygx0Hp+/Xoag6sgL8b7CH+ie5xpH3h9i16PbH68=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8604.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(366007)(1800799015)(52116005)(376005)(38350700005)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?TfkDT0hYC4p4VoszPXWs2Q7PDV3U?= =?utf-8?q?Niuqr8Q2I1PhYpWVa91ZdEMZtY8TzvKhKCOLMgaunhu7cnN1iLJUYQHf+nUuAWLRZ?= =?utf-8?q?bPZrmhI+pX3hjyWqIMZapK7BEdOnFI9tz+KNQIfKxny4VKr2g+60ZONwdcEcsd75V?= =?utf-8?q?AivahJr3C1oUAqrCWU7z1uYM5L/hd6j9ALL9BD/Poz1UVnjy8iyfaNxxK4U0F/RvT?= =?utf-8?q?rygcFKiWoHoiDL9dFRRhzoo2Hq5jQeacRr8xIBuwps/1EbyA8qACRPB9hp3OGbuDx?= =?utf-8?q?gIasK0B2ehLxAMlowj8fr4TfgiSM1JtozhwRlqAGSs5XS48IwYtae0KmjiN6hpESe?= =?utf-8?q?JDHuWupMofX7GFINfVT3RGFPOjuRBi5QiJ76GwqOw11UHtUhvVkoBGsrr2hGqCjSD?= =?utf-8?q?XLbE642N7dzchw49TwB+49icr+5KWvzfQmUn4jYoxFEzKQjbnJFwBzd4stkj6wJcR?= =?utf-8?q?wWVuojHS+Y+jxAF+KFwJWjYeOu/j/TJyVWO4uaTLO7ciN/zVFFIRPSDEUCpJjih25?= =?utf-8?q?P9Y7rK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3+kegWLo/IyrfHQLbK4k+VbzqLmz7uKqvGuYgty?= =?utf-8?q?g+ek2I56GPo8xZur5Bm71EmJCNaSY27KWaUeT+SuBc9F7JtQC0QoT8kGOMgeiLTeM?= =?utf-8?q?t4h3n0kMKo/+?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6833a1db-9e41-4bc5-8508-08dc7b167565 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8604.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 10:52:37.0689 (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: 2DMusY5Vva3/iwmDYXbwNbiuMSru6hAmlGjR7d7lN6j4Je7jGeEcHn7V5lp/54Mu/CYJPdbWycc0vqupxFSbOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7474 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240523_035250_626531_A1043A0F X-CRM114-Status: GOOD ( 15.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- .../devicetree/bindings/firmware/fsl,imx-se.yaml | 154 +++++++++++++++++++++ 1 file changed, 154 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..b27f84db6f91 --- /dev/null +++ b/Documentation/devicetree/bindings/firmware/fsl,imx-se.yaml @@ -0,0 +1,154 @@ +# 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 is based on the + messaging unit(s). + +properties: + $nodename: + pattern: "^[0-9a-z]*-if@[0-9a-f]+$" + + compatible: + enum: + - fsl,imx8ulp-ele + - fsl,imx93-ele + - fsl,imx95-ele + + reg: + maxItems: 1 + description: Identifier of the communication interface to secure-enclave. + + mboxes: + description: contain a list of phandles to mailboxes. + items: + - description: Specify the mailbox used to send message to se firmware + - description: Specify the mailbox used to receive message from se firmware + + mbox-names: + items: + - const: tx + - const: rx + - const: txdb + - const: rxdb + minItems: 2 + + memory-region: + description: contains a list of phandles to reserved external memory. + items: + - description: It is used by secure-enclave firmware. It is an optional + property based on compatible and identifier to communication interface. + (see bindings/reserved-memory/reserved-memory.txt) + + sram: + description: contains a list of phandles to sram. + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + - description: Phandle to the device SRAM. It is an optional property + based on compatible and identifier to communication interface. + +allOf: + # memory-region + - if: + properties: + compatible: + contains: + enum: + - fsl,imx8ulp-ele + - fsl,imx93-ele + then: + required: + - memory-region + else: + not: + required: + - memory-region + + # sram + - if: + properties: + compatible: + contains: + enum: + - fsl,imx8ulp-ele + then: + required: + - sram + else: + not: + required: + - sram + +required: + - compatible + - reg + - mboxes + - mbox-names + +additionalProperties: false + +examples: + - | + firmware { + #address-cells = <1>; + #size-cells = <0>; + ele-if@0 { + compatible = "fsl,imx8ulp-ele"; + reg = <0x0>; + mboxes = <&s4muap 0 0>, <&s4muap 1 0>; + mbox-names = "tx", "rx"; + sram = <&sram0>; + memory-region = <&ele_reserved>; + }; + }; + - | + firmware { + #address-cells = <1>; + #size-cells = <0>; + ele-if@0 { + compatible = "fsl,imx93-ele"; + reg = <0x0>; + mboxes = <&s4muap 0 0>, <&s4muap 1 0>; + mbox-names = "tx", "rx"; + memory-region = <&ele_reserved>; + }; + }; + - | + firmware { + #address-cells = <1>; + #size-cells = <0>; + v2x-if@0 { + compatible = "fsl,imx95-v2x"; + reg = <0x0>; + mboxes = <&v2x_mu 0 0>, <&v2x_mu 1 0>; + mbox-names = "tx", "rx"; + }; + v2x-if@1 { + compatible = "fsl,imx95-v2x"; + reg = <0x1>; + mboxes = <&v2x_mu6 0 0>, <&v2x_mu6 1 0>; + mbox-names = "txdb", "rxdb"; + }; + v2x-if@2 { + compatible = "fsl,imx95-v2x"; + reg = <0x2>; + mboxes = <&v2x_mu7 0 0>, <&v2x_mu7 1 0>; + mbox-names = "tx", "rx"; + }; + }; +... From patchwork Thu May 23 10:49:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 13671616 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50B67C25B75 for ; Thu, 23 May 2024 10:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=BNuOBD4C+NfCHuYxJfyn1QF7lwBplPPwkL0Ubwm2ZCg=; b=FZIy+cAmfiuOauL3zatr3yJGf8 SWB46UF64g//HZyqfZdm+DaEsrObeKpaQ8UIaZ9ddBW+GwI0v/S6MQC9stvZfHiqIrqDn/CldQShr 3d1FYgugmLGcKBKrpMOd3tF3S+Dj4Ul2qn8Nv8M6W7yIly8O5mwVBrzoFwzL651FShQ1SDliyS9h/ zMcaj4zqHWEqT3wTJduHk1Wnm1HJwuzppKNA8qRDYtrISgGQUS/RZbUmkl0aSlaJXS0ebuTqE06mM b5es5TPNYNMEHnzJKHwWFowroZ8Hr+aaNRfkxg8zr3BL5F4s8LImsxiJ1FldkmfannRsPU1pzvzPY 5VktZEPA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sA64J-00000005x3m-28k9; Thu, 23 May 2024 10:53:08 +0000 Received: from mail-db8eur05on20602.outbound.protection.outlook.com ([2a01:111:f400:7e1a::602] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sA642-00000005wpv-3CJf for linux-arm-kernel@lists.infradead.org; Thu, 23 May 2024 10:52:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g9QwDw5s/P8dKmTn4pi0d6RXX1RKH6cGLKUk7fOodP6mwI2toenp8O0frXVpbajAKdXBxCIBGf6kaTISl6GtaXlQu7oT4rlKjK7qKUIeayYxpmdvUOauLFC8vXGV0ZKLGu3QZjJlRhGtGQi9Yr8lPaWTEebOugYLdTkXp5y9DxKuHTh40ZkDGyVzGg0yde5KCa5yIUQyPcQ3qurqT2QoMoMJ8Pz3P/qkzcIdt5AzZoTTIiLYb0kP8zjVp2goAr1cZ9ki3VPPATs8M/+WLJcUUQN9XIxqJfmMc0qCg77WG2zXdK4r3ejVxAYUSd1wf2Ba9osIqC3q8kbHqeake9vywg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lFIBcXJB06KrE3tsEaa3tWXz5wvR/OOHA+nSukvl1p8=; b=TSSSzCx6dud9E+HPl5j7u4CZg8Csn0kXCLhZJsT5faxvCjTYArN4hoJ/WcWuaVvDdlOmxygpNoXKrIb2Nbl3al6TT6mbVGaWTbk6X2mDzCPe5DdtjtsenFbFJOGCXXnMG74Sc1UuuIGg3cGNP7SF2sXc7+7te22xh3uGX3OkynopcKHS4my/fnSjXdQ6jzLB21h0IJRJhBanf6U4aN26PhCi02r8bstGjbGTqR+aaOaV9HXowyfqi4MQE+SzYYtG9zGLFuhGNDuwC+xk6sMEN5lw4u4RGUwKuF26S6+W0zl+wWkhw6MhIWtaC3HudYL3ft1fTkEnzAYkEYcp3akj2A== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lFIBcXJB06KrE3tsEaa3tWXz5wvR/OOHA+nSukvl1p8=; b=Da+awofquRbDS7mNSDpsfncqx216sbsl2SBiYmvDaBWGdNu3JHxE6yEwq9+kXxMX9LWwLKCVkQMH7GU17RyLalADtSP9XQ6R+FpE5AtpCeRelMw3iVjqwag7HKwCl96qGtXoaag2nk8SF2JGxu+sq7GaQwxkXFK0mWJsrkivAqc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8604.eurprd04.prod.outlook.com (2603:10a6:20b:43b::21) by PAXPR04MB9571.eurprd04.prod.outlook.com (2603:10a6:102:24e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.34; Thu, 23 May 2024 10:52:43 +0000 Received: from AM9PR04MB8604.eurprd04.prod.outlook.com ([fe80::e751:223e:aa3d:5827]) by AM9PR04MB8604.eurprd04.prod.outlook.com ([fe80::e751:223e:aa3d:5827%4]) with mapi id 15.20.7587.035; Thu, 23 May 2024 10:52:43 +0000 From: Pankaj Gupta Date: Thu, 23 May 2024 16:19:34 +0530 Subject: [PATCH v2 3/5] arm64: dts: imx8ulp-evk: add nxp secure enclave firmware Message-Id: <20240523-imx-se-if-v2-3-5a6fd189a539@nxp.com> References: <20240523-imx-se-if-v2-0-5a6fd189a539@nxp.com> In-Reply-To: <20240523-imx-se-if-v2-0-5a6fd189a539@nxp.com> To: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Rob Herring , Krzysztof Kozlowski 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, Pankaj Gupta X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1716461396; l=2655; i=pankaj.gupta@nxp.com; s=20240523; h=from:subject:message-id; bh=CtJ/9FTiq7DaG4rGNNzuWMxNzyVd800PfyXkOB1QQ7E=; b=ksQFOGmKQBbuqhjL7n87sDcZMrLTO+Uji/m1vdodmOJprUmDdOehWgWsXeuBgeuu53ZLMasWQ 81kGJcCblzPCr4onptYffJ8F0dz6VKazl2Vs6YiylIfoO9QskGq6Xxs X-Developer-Key: i=pankaj.gupta@nxp.com; a=ed25519; pk=OA0pBQoupy5lV0XfKzD8B0OOBVB6tpAoIf+0x1bYGRg= X-ClientProxiedBy: SI2PR01CA0027.apcprd01.prod.exchangelabs.com (2603:1096:4:192::7) To AM9PR04MB8604.eurprd04.prod.outlook.com (2603:10a6:20b:43b::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8604:EE_|PAXPR04MB9571:EE_ X-MS-Office365-Filtering-Correlation-Id: fead4d1f-d239-43d1-9c52-08dc7b167913 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|366007|52116005|7416005|1800799015|38350700005|921011; X-Microsoft-Antispam-Message-Info: =?utf-8?q?+Mk+RJwsE5TYDdBREZu9RBhIrL8GW8L?= =?utf-8?q?wDDJYd9rbuZzpMFuwGooBBn5GB5N/ZRlSkkj7XScrRCrb0lf7P40PDDTHjrADmsPn?= =?utf-8?q?Q8ed0Dib0mK/A+InbaqOR8nSzWdYf0h9TYTf+NoMqRl4kPtatyQzZlUEsnppLJFDy?= =?utf-8?q?QOAiVaTVs1EOW6ZZccT1HW9I+RO15r8GpgoQ8zxbjS8a/AI3iwwbyw8LFPt5O169m?= =?utf-8?q?olo3OtGMZqlUOdA67Lk3hmTiZ1V8UHcAL4d0NR/AqK0E+de7tLoKQjTcYZ1epmybw?= =?utf-8?q?kt+xEZjBIh+tq5BX4mNLfHj/7/SRoIeQh/IjmAsebybbJ8mzc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u1kpK36q?= =?utf-8?q?1jNL8ezrjmk1R5SuV/33N8wE1+cHP4bom6Op8AAiwn5OG20PyfaW08WUJ57U80SeV?= =?utf-8?q?nbb2CQ3g0ulGqkJ0EXsvSD33ddFjNujvNXGoomNwWycWvo0mWi6mwMK0=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8604.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(366007)(52116005)(7416005)(1800799015)(38350700005)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Kuf07S/zSZnTCF//N2BrNR2rJzBb?= =?utf-8?q?wnTHBfB4YjqUHrNU+nEKyZMjvjuNRpUvF+xgpZ5aOsQCUJ7op6717vTdeZDr+FGwI?= =?utf-8?q?dk2QAUbHXbk1PqiOk3SaCQGDoUbkKY8PQMkWQ9NWNV7KSVhnJ3qMKBjvPiNftZufW?= =?utf-8?q?Wouy2iaqCtvjc0bpW+ERpApU/uk4xWlhomjz98C5jITTkTXIr8OpcG7QSZWHQ+N/T?= =?utf-8?q?S+P5S8hPNC34gaYrgkjIZmgbsaL6ldfDuiEf2XbaX6jFWLHT7WNveuk0DhmVsqdL5?= =?utf-8?q?cdHcOXaIaZYUnsCDhnhllO/cRaXTGfmlVcO6cUUS4LnFXCKJiygdWVuesWDv5bA3W?= =?utf-8?q?RdH73AjQhsFBDM7L25ROXMTg99fHe9UP347pcsYX2Q8xxpIu3LCEhGkPTfV49yFpp?= =?utf-8?q?yrt04oFjWzTL9w0fQ+ZrY0QNJRkdfsRYy7kLsmOD7HvOCMl+MNCRgk6QT+ve2hJWt?= =?utf-8?q?qRM5d4Jqm2J7ivgHUHaHoXeR7yw40/1MPO9Y1H2VW5opovRh5MNWkOu9rYQ8eISqo?= =?utf-8?q?qyg7kLAWoQXmR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Yy1cxlvXKJw/7rz51bRekcZEcnZIKmtJfhZHUcUPe2OD4W?= =?utf-8?q?EHxG7xEV+1t3xcbx/b6jbfO26P4xXIApn/GiEaejv1W4Fdwuuf19JDoAFH151EwlC?= =?utf-8?q?AvgGQr96SofQ?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fead4d1f-d239-43d1-9c52-08dc7b167913 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8604.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 10:52:43.2144 (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: aCHiu5mwLjQRPhsD1YTiENzc6dLVUyFVQ8xGIff3/fBpt2t4FtvYhJs+u9FGqkbYrw7bX9r93c+uvF7rnmwvlA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9571 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240523_035250_882366_6251A23F X-CRM114-Status: GOOD ( 12.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 | 14 ++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/freescale/imx8ulp-evk.dts b/arch/arm64/boot/dts/freescale/imx8ulp-evk.dts index 24bb253b938d..ca8958f28a83 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>; @@ -146,6 +157,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 c460afaa76f5..0d74995b7049 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,14 @@ scmi_sensor: protocol@15 { #thermal-sensor-cells = <1>; }; }; + + ele_if0: ele-if@0 { + compatible = "fsl,imx8ulp-ele"; + reg = <0x0>; + mbox-names = "tx", "rx"; + mboxes = <&s4muap 0 0>, <&s4muap 1 0>; + sram = <&sram0>; + }; }; cm33: remoteproc-cm33 { From patchwork Thu May 23 10:49:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 13671617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0CF1C25B79 for ; Thu, 23 May 2024 10:53:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=KLcUFLJA7iVwlmY+ouqtLIOe+POg84xeV+H05O/qUzE=; b=g0iwMoL8VQvKNWX/OAvqR0vXY8 vD3N4m7Fwv/lYKAh8llKXdZzda4cIDTVSngCl6AQf7aMv1uW4xRuIXLzoCO9gu/brJ/05r6OQiK31 nupT9G9FfdCv23V3U3ThRA4x/OGQTYvD76kiFpn57jM56Mfj1HpqUyUD/RXbq6qBxqHlE9GzHH+Ye nrio2WRbCEoe/1mZkcFMoq7cSqKL1Jn3Lg4An+nHSdHGyWuN4LFoNeFC/n9id6l4Q8pDdFLVr9Mux oJCWkZfrFyR1v/iryo+wfyOgyjpm0Xn64l2AFgjRoO0IBMmA9nMlGriFfaTVklhY+QaV0PyHLQeTd TBF0YbxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sA64M-00000005x6P-3I76; Thu, 23 May 2024 10:53:10 +0000 Received: from mail-db8eur05on20602.outbound.protection.outlook.com ([2a01:111:f400:7e1a::602] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sA645-00000005wpv-1FJC for linux-arm-kernel@lists.infradead.org; Thu, 23 May 2024 10:52:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AEO2pUX25XupddcrjD+qlogemwly6PlWViz1JXCsb66Y9pQy+d7A1WRbi7N/DOP2kRy5AHj6TryL6KZRV3/Cfdj9NQK9HtV3g8pRYcxt7lgK5DVLupUPCZm/yFvOWORHmH3cEaBsnhUGOcsIBxBeQzXy92jJU0Vu+mOky6iRE1v4CJVHn6/pOnd5+lmTjZ6FoxG13d4LrPIkrWOpML+/u4AsbvV+RJ+oWVjsWtJ8V6aPj67rkxCz9YbQb+Qn2xnzFMlaFVlRkN9KvmcwPbberRcXlXnUT0BfT3rb+kShwJQJYZ3NoAIxtI9o5fwNRALvjtrO0d/JRxq/gGwU/r1cLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JuVDZEAGHFuCi1aXzBBcaZv3fDXCwJK48Zk14jokGo8=; b=G0ZfD+XC83XLyPse2zlfjr/lku6MhooGDD71XNf3Ct+L166eYvGjcssIPd4k0+VG36B8alHIRSDwiGrMFyrpU3em/wMAruBYWgWbAB7ni7O0HUiYDlUljxozewXIExsDNjoJGVotUMSOVfyr8XGr0Hk5SBb2BOFAtTvPLll993dW1sEuSh0guxWbcx8vIkgpDHZAp2+SNLCYuS3cbDqroYmWXy2tX+ht+liTwZ4zObbxDpMG5uOiOFbo/Ti+mvVkfby/mdAJXuudIpA2ru0bl8oDwyyHk9GY9xMczcEOQr/KsgHrGZ7y9UHjwwmFvvBYj0sLbOkdSKTdxrvxrTzJPA== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JuVDZEAGHFuCi1aXzBBcaZv3fDXCwJK48Zk14jokGo8=; b=WCKzsp2sZgbDMbLJOlluZIa2cOxJsneWYPCPwmZGKptZwus/CvxIBQJxk3vuN65ZBDsBJfLgTc49rOy6v5hfOfrAkXwcsstH8Xkz1tWdKfE1j8WkMMg9ptvg4MnPJFKpETFMdZg/nbMeJqdBxLpuTSTtVbRrmHWfBeAW9hbjvJM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8604.eurprd04.prod.outlook.com (2603:10a6:20b:43b::21) by PAXPR04MB9571.eurprd04.prod.outlook.com (2603:10a6:102:24e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.34; Thu, 23 May 2024 10:52:49 +0000 Received: from AM9PR04MB8604.eurprd04.prod.outlook.com ([fe80::e751:223e:aa3d:5827]) by AM9PR04MB8604.eurprd04.prod.outlook.com ([fe80::e751:223e:aa3d:5827%4]) with mapi id 15.20.7587.035; Thu, 23 May 2024 10:52:49 +0000 From: Pankaj Gupta Date: Thu, 23 May 2024 16:19:35 +0530 Subject: [PATCH v2 4/5] firmware: imx: add driver for NXP EdgeLock Enclave Message-Id: <20240523-imx-se-if-v2-4-5a6fd189a539@nxp.com> References: <20240523-imx-se-if-v2-0-5a6fd189a539@nxp.com> In-Reply-To: <20240523-imx-se-if-v2-0-5a6fd189a539@nxp.com> To: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Rob Herring , Krzysztof Kozlowski 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, Pankaj Gupta X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1716461396; l=36134; i=pankaj.gupta@nxp.com; s=20240523; h=from:subject:message-id; bh=lELFSLt29nhjHLsOlwUsB0+6BgFayX8/VLd0LBimq+M=; b=4tRc8xvtw8qmQzNiFjInIFh80fm0A3nNQDKoPw3KaA7rCCcM8MXq1rYPjxM1KPbCbKbjIgxPX 7p7DMHRz+0lDP2vwPassPO16T1C9eA/VWv/WcXhhg8wpFmqzy8rmmHc X-Developer-Key: i=pankaj.gupta@nxp.com; a=ed25519; pk=OA0pBQoupy5lV0XfKzD8B0OOBVB6tpAoIf+0x1bYGRg= X-ClientProxiedBy: SI2PR01CA0027.apcprd01.prod.exchangelabs.com (2603:1096:4:192::7) To AM9PR04MB8604.eurprd04.prod.outlook.com (2603:10a6:20b:43b::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8604:EE_|PAXPR04MB9571:EE_ X-MS-Office365-Filtering-Correlation-Id: 599297d5-bc11-4487-89f5-08dc7b167ce3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|366007|52116005|7416005|1800799015|38350700005|921011; X-Microsoft-Antispam-Message-Info: =?utf-8?q?cfZK59dNwtDdUL6WWadZ3CVzkzZPqjj?= =?utf-8?q?Vx9IPXz0Ab/dgHudyMQ831UqESTZyqqDPU+XsbUthLIo1YZIkvZupI/7auq58aA1j?= =?utf-8?q?uSGvI+R1KQdGfVBsX1f+HMYirbgS+02vNSbmiJCSe44LiSBDka1hmjQj6sxfnm+E5?= =?utf-8?q?Mb65eUNDqSw2fL7HYLvjeNW1anXYjTgkQftEA7PN4IpHNQeVLE9kDcot5sBeFZ2dN?= =?utf-8?q?VeTz7X5luqS9+cxg04XM6B16tmBXgl0LsDujhzyBw2xsC1rWNt8cC7r9v3oacYVgf?= =?utf-8?q?zWOdSg2iOJhuoIYnDbiEORUmr7YAST4bj4HB+3D/2ewbPxLoLhygVI9zGdAQV47Y9?= =?utf-8?q?1j8GFeu3gHJ5mE2TKYKrHuN1A95j2q41o/bOqOc2sCLp3yzJudsu3930umO10l142?= =?utf-8?q?HbC0OpB3aTMt42djCzuG/0Vr4qfwjougSfYFuPk8cv/wTQJpYhrxtLWrUxg+Yd2Ic?= =?utf-8?q?4ZyGRP3PW4L6oHuzA4QhKAS6pZwCYKPGneDdb7M+cCIYKUGnThR9aHF/k0saJwmVr?= =?utf-8?q?JUTTPfAUnsgXLR9esGfDK+fV8INap4XC90/AiVj/ES0N5677dIlLTJuebEA1TQkYt?= =?utf-8?q?ofTZgMoVd1pqO6UhYjJziPgnEVVmGdNp+zwJxQa90aZNVah+OovUX5hfoajLLk1YM?= =?utf-8?q?IPg66ZN2YHU00JCqO1oMnijOPlUr3TIZDIYURqpHOBN1FGH9kXKPNj21Eco7QHdAQ?= =?utf-8?q?RES1QGEKqX4DfLazuJt/QWD+WOW3t8BXp16isaMjvhIuq2V5p4NjnkmqtiDkzN2/q?= =?utf-8?q?btYHh2WStX0+k+63PB3LVYeKGRRS5zEQa24Aw25+YDBKl16BUB4F/GXNbASDsyIZT?= =?utf-8?q?CjgNXeSNVgFbM+KHaqpGJTPGugA02hzn+PMVjh1UYjEa9q0k2sLmSf2frxLOEyyLK?= =?utf-8?q?PUACrPVuATzJy8wgSpRZ3VQcLw6uG/6h3IF6y5lIWWVM78ZNGjLdUbHisxxKsuTT3?= =?utf-8?q?OlTC2jvXx9uPDm3jb11aN3anPZgt7EZQcvwIt5/fJbaTSUeeRvCHn51kusWxt+zXf?= =?utf-8?q?GOZS5dPBKnvpGXD7du6R2etSuRAoy2IXuX20n5dWZJraPnCQpwuSk2s5Enxdpu/f5?= =?utf-8?q?TZLr+kTVbjrPvhUNhnPVE+58IbwZ0ayuSkCgZQHlFregcbxK+np6rKgbHAOu4ruTb?= =?utf-8?q?JXkuJ2p4CrqQMh0tkndtTVuobs3OfbmGZ399l2DZ3BJpH7xd2mv9P8zDf54MWJKyI?= =?utf-8?q?3a2MbGa9tN9UIJAl1RuZsyg2mbaVt1CFCxrZ2KPOy9rKNwXQps3dhQqiTTho/RR/J?= =?utf-8?q?qERuHuTno4r9lp47eUQATKFc3FqktuZQ4i+ObDr2CSXig+u7a8tKyqQM=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8604.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(366007)(52116005)(7416005)(1800799015)(38350700005)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?RGqMVcV4KKE2Zo/3KTFVuqwTf2Ef?= =?utf-8?q?ZUquqAr03j6RLbTxPaUfJC7Q64ThzMk84PiIh6vsWsE7kaHEwMQRE5veJ2GXyTUB5?= =?utf-8?q?6xcqpA9Xo/kkXLyatMH8JVMy29dZq4+nzqGORftzMHOJQykzy80HuMWkOMZlWMpMZ?= =?utf-8?q?4f8t2twVZxIQBJlTO4I2R3baA+ZmtmRCnA7a79zi3AZ41OW9cR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Yx1k?= =?utf-8?q?/YNDn9oAZtAI9BDnnFGUKWuJKN+Ka90LqfnmfVDq0qRCjxsokPIaCJoo61v7rK60t?= =?utf-8?q?aWYbQorLPdtT0RZCrd86iqh15uLocyEwnZWMAX6ftCAUnZSOSK6ZV8UC+gy+vrcpM?= =?utf-8?q?FXVa13v368TDMvA/YrVtaKyglAIYKhTF7Swriyk3V4VDDYSt5AdTCmkYb+3GI8HJw?= =?utf-8?q?ViiA2vMI3YpqkRGgC8DONvIW+hYbHQ62tGynkMqUQ/aqPPkYXyfL2MitPovk9j2ez?= =?utf-8?q?IN7/+SlSvwHKHHfc5JEQqngrwh0PjipXANHMFBXp7vnbGHM8M/fP/r9lJB3xhajZN?= =?utf-8?q?LK59gf9HS+zW1o2CD95+AZsRtrmxZ7ZXGKIQ2C0AcSP+TXgiQel2umEsC+s7q0eLQ?= =?utf-8?q?RnXtv2sLhwUsQp5B1YqrBjqRHsrSeO38lci1DPfwy0G3Xam5NXbecKKqXsUlQ+T/K?= =?utf-8?q?KnDzQIZ5zRrJ?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 599297d5-bc11-4487-89f5-08dc7b167ce3 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8604.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 10:52:49.7059 (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: ZpZQoQxxbGE459MH+sTQDKQijCsr4XU0ljXVDDD/2bUgazXksQNcfaXQ5lB3MChYQ1UF+ouWN90JkaJLyZD7nw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9571 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240523_035253_644816_4BE7BE45 X-CRM114-Status: GOOD ( 24.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 | 12 + drivers/firmware/imx/Makefile | 2 + drivers/firmware/imx/ele_base_msg.c | 286 +++++++++++++++++++ drivers/firmware/imx/ele_base_msg.h | 92 +++++++ drivers/firmware/imx/ele_common.c | 239 ++++++++++++++++ drivers/firmware/imx/ele_common.h | 43 +++ drivers/firmware/imx/se_ctrl.c | 531 ++++++++++++++++++++++++++++++++++++ drivers/firmware/imx/se_ctrl.h | 99 +++++++ include/linux/firmware/imx/se_api.h | 14 + 9 files changed, 1318 insertions(+) diff --git a/drivers/firmware/imx/Kconfig b/drivers/firmware/imx/Kconfig index 183613f82a11..56bdca9bd917 100644 --- a/drivers/firmware/imx/Kconfig +++ b/drivers/firmware/imx/Kconfig @@ -22,3 +22,15 @@ config IMX_SCU This driver manages the IPC interface between host CPU and the SCU firmware running on M4. + +config IMX_SEC_ENCLAVE + tristate "i.MX Embedded Secure Enclave - EdgeLock Enclave Firmware driver." + depends on IMX_MBOX && ARCH_MXC && ARM64 + 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 8f9f04a513a8..aa9033e0e9e3 100644 --- a/drivers/firmware/imx/Makefile +++ b/drivers/firmware/imx/Makefile @@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 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 +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..f072c613dba1 --- /dev/null +++ b/drivers/firmware/imx/ele_base_msg.c @@ -0,0 +1,286 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 NXP + */ + +#include +#include +#include + +#include "ele_base_msg.h" +#include "ele_common.h" + +int ele_get_info(struct device *dev, struct ele_dev_info *s_info) +{ + struct se_if_priv *priv = dev_get_drvdata(dev); + struct se_api_msg *tx_msg __free(kfree) = NULL; + struct se_api_msg *rx_msg __free(kfree) = NULL; + phys_addr_t get_info_addr = 0; + u32 *get_info_data = NULL; + u32 status; + int ret = 0; + + memset(s_info, 0x0, sizeof(*s_info)); + + if (priv->mem_pool_name) + get_info_data = get_phy_buf_mem_pool(dev, + priv->mem_pool_name, + &get_info_addr, + ELE_GET_INFO_BUFF_SZ); + else + get_info_data = dma_alloc_coherent(dev, + ELE_GET_INFO_BUFF_SZ, + &get_info_addr, + GFP_KERNEL); + if (!get_info_data) { + ret = -ENOMEM; + dev_dbg(dev, + "%s: Failed to allocate get_info_addr.\n", + __func__); + goto exit; + } + + 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 = plat_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(struct ele_dev_info); + ret = imx_ele_msg_send_rcv(priv, tx_msg, rx_msg); + if (ret < 0) + goto exit; + + ret = validate_rsp_hdr(priv, + &priv->rx_msg->header, + ELE_GET_INFO_REQ, + ELE_GET_INFO_RSP_MSG_SZ, + true); + if (ret) + goto exit; + + status = RES_STATUS(priv->rx_msg->data[0]); + if (status != priv->success_tag) { + dev_err(dev, "Command Id[%d], Response Failure = 0x%x", + ELE_GET_INFO_REQ, status); + ret = -EPERM; + } + + memcpy(s_info, get_info_data, sizeof(struct ele_dev_info)); + +exit: + if (get_info_addr) { + if (priv->mem_pool_name) + free_phybuf_mem_pool(dev, priv->mem_pool_name, + get_info_data, ELE_GET_INFO_BUFF_SZ); + else + dma_free_coherent(dev, + ELE_GET_INFO_BUFF_SZ, + get_info_data, + get_info_addr); + } + + return ret; +} + +int ele_fetch_soc_info(struct device *dev, u16 *soc_rev, u64 *serial_num) +{ + struct ele_dev_info s_info = {0}; + int err = 0; + + err = ele_get_info(dev, &s_info); + if (err < 0) { + dev_err(dev, "Error"); + return err; + } + + *soc_rev = s_info.d_info.soc_rev; + *serial_num = GET_SERIAL_NUM_FROM_UID(s_info.d_info.uid, MAX_UID_SIZE >> 2); + + return err; +} + +int ele_ping(struct device *dev) +{ + struct se_if_priv *priv = dev_get_drvdata(dev); + struct se_api_msg *tx_msg __free(kfree) = NULL; + struct se_api_msg *rx_msg __free(kfree) = NULL; + u32 status; + int ret = 0; + + 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 = plat_fill_cmd_msg_hdr(priv, + (struct se_msg_hdr *)&tx_msg->header, + ELE_PING_REQ, ELE_PING_REQ_SZ, + true); + if (ret) { + dev_err(dev, "Error: plat_fill_cmd_msg_hdr failed.\n"); + goto exit; + } + + ret = imx_ele_msg_send_rcv(priv, tx_msg, rx_msg); + if (ret) + goto exit; + + ret = validate_rsp_hdr(priv, + &priv->rx_msg->header, + ELE_PING_REQ, + ELE_PING_RSP_SZ, + true); + if (ret) + goto exit; + + status = RES_STATUS(priv->rx_msg->data[0]); + if (status != priv->success_tag) { + dev_err(dev, "Command Id[%d], Response Failure = 0x%x", + ELE_PING_REQ, status); + ret = -EPERM; + } +exit: + return ret; +} + +int ele_service_swap(struct device *dev, + phys_addr_t addr, + u32 addr_size, u16 flag) +{ + struct se_if_priv *priv = dev_get_drvdata(dev); + struct se_api_msg *tx_msg __free(kfree) = NULL; + struct se_api_msg *rx_msg __free(kfree) = NULL; + u32 status; + int ret = 0; + + 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 = plat_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] = plat_add_msg_crc((uint32_t *)&tx_msg[0], + ELE_SERVICE_SWAP_REQ_MSG_SZ); + ret = imx_ele_msg_send_rcv(priv, tx_msg, rx_msg); + if (ret < 0) + goto exit; + + ret = validate_rsp_hdr(priv, + &priv->rx_msg->header, + ELE_SERVICE_SWAP_REQ, + ELE_SERVICE_SWAP_RSP_MSG_SZ, + true); + if (ret) + goto exit; + + status = RES_STATUS(priv->rx_msg->data[0]); + if (status != priv->success_tag) { + dev_err(dev, "Command Id[%d], Response Failure = 0x%x", + ELE_SERVICE_SWAP_REQ, status); + ret = -EPERM; + } else { + if (flag == ELE_IMEM_EXPORT) + ret = priv->rx_msg->data[1]; + else + ret = 0; + } +exit: + + return ret; +} + +int ele_fw_authenticate(struct device *dev, phys_addr_t addr) +{ + struct se_if_priv *priv = dev_get_drvdata(dev); + struct se_api_msg *tx_msg __free(kfree) = NULL; + struct se_api_msg *rx_msg __free(kfree) = NULL; + u32 status; + int ret = 0; + + 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 = plat_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[0] = addr; + tx_msg->data[1] = addr >> 32; + tx_msg->data[2] = addr; + + ret = imx_ele_msg_send_rcv(priv, tx_msg, rx_msg); + if (ret < 0) + goto exit; + + ret = validate_rsp_hdr(priv, + &priv->rx_msg->header, + ELE_FW_AUTH_REQ, + ELE_FW_AUTH_RSP_MSG_SZ, + true); + if (ret) + goto exit; + + status = RES_STATUS(priv->rx_msg->data[0]); + if (status != priv->success_tag) { + dev_err(dev, "Command Id[%d], Response Failure = 0x%x", + ELE_FW_AUTH_REQ, status); + ret = -EPERM; + } +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..f00414f9d86d --- /dev/null +++ b/drivers/firmware/imx/ele_base_msg.h @@ -0,0 +1,92 @@ +/* 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 + +#define WORD_SZ 4 +#define ELE_NONE_VAL 0x0 + +#define ELE_SUCCESS_IND 0xD6 + +#define ELE_GET_INFO_REQ 0xDA +#define ELE_GET_INFO_REQ_MSG_SZ 0x10 +#define ELE_GET_INFO_RSP_MSG_SZ 0x08 + +#define ELE_GET_INFO_BUFF_SZ 0x100 + +#define DEFAULT_IMX_SOC_VER 0xA000 +#define SOC_VER_MASK 0xFFFF0000 +#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 + +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 GET_SERIAL_NUM_FROM_UID(x, uid_word_sz) \ + (((u64)(((u32 *)(x))[(uid_word_sz) - 1]) << 32) | ((u32 *)(x))[0]) + +#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 device *dev, struct ele_dev_info *s_info); +int ele_fetch_soc_info(struct device *dev, u16 *soc_rev, u64 *serial_num); +int ele_ping(struct device *dev); +int ele_service_swap(struct device *dev, + phys_addr_t addr, + u32 addr_size, u16 flag); +int ele_fw_authenticate(struct device *dev, 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..c286c3d84d82 --- /dev/null +++ b/drivers/firmware/imx/ele_common.c @@ -0,0 +1,239 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 NXP + */ + +#include "ele_base_msg.h" +#include "ele_common.h" + +u32 plat_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 imx_ele_msg_rcv(struct se_if_priv *priv) +{ + u32 wait; + int err = 0; + + lockdep_assert_held(&priv->se_if_cmd_lock); + + wait = msecs_to_jiffies(1000); + if (!wait_for_completion_timeout(&priv->done, wait)) { + dev_err(priv->dev, + "Error: wait_for_completion timed out.\n"); + err = -ETIMEDOUT; + } + + return err; +} + +int imx_ele_msg_send(struct se_if_priv *priv, void *tx_msg) +{ + struct se_msg_hdr *header; + int err; + + header = (struct se_msg_hdr *) tx_msg; + + if (header->tag == priv->cmd_tag) + lockdep_assert_held(&priv->se_if_cmd_lock); + + scoped_guard(mutex, &priv->se_if_lock); + + err = mbox_send_message(priv->tx_chan, tx_msg); + if (err < 0) { + dev_err(priv->dev, "Error: mbox_send_message failure.\n"); + return err; + } + + return err; +} + +/* API used for send/receive blocking call. */ +int imx_ele_msg_send_rcv(struct se_if_priv *priv, void *tx_msg, void *rx_msg) +{ + int err; + + scoped_guard(mutex, &priv->se_if_cmd_lock); + if (priv->waiting_rsp_dev) { + dev_warn(priv->dev, + "There should be no misc dev-ctx, waiting for resp.\n"); + priv->waiting_rsp_dev = NULL; + } + priv->rx_msg = rx_msg; + err = imx_ele_msg_send(priv, tx_msg); + if (err < 0) + goto exit; + + err = imx_ele_msg_rcv(priv); + +exit: + return err; +} + +/* + * Callback called by mailbox FW, when data is received. + */ +void se_if_rx_callback(struct mbox_client *mbox_cl, void *msg) +{ + struct device *dev = mbox_cl->dev; + struct se_if_priv *priv; + struct se_msg_hdr *header; + + priv = dev_get_drvdata(dev); + + /* The function can be called with NULL msg */ + if (!msg) { + dev_err(dev, "Message is invalid\n"); + return; + } + + header = (struct se_msg_hdr *) msg; + + if (header->tag == priv->rsp_tag) { + if (!priv->waiting_rsp_dev) { + /* + * Reading the EdgeLock Enclave response + * to the command, sent by other + * linux kernel services. + */ + spin_lock(&priv->lock); + memcpy(priv->rx_msg, msg, header->size << 2); + + complete(&priv->done); + spin_unlock(&priv->lock); + return; + } + } else { + dev_err(dev, "Failed to select a device for message: %.8x\n", + *((u32 *) header)); + return; + } +} + +int validate_rsp_hdr(struct se_if_priv *priv, + struct se_msg_hdr *header, + uint8_t msg_id, + uint8_t sz, + bool is_base_api) +{ + int ret = -EINVAL; + + if (header->tag != priv->rsp_tag) { + dev_err(priv->dev, + "MSG[0x%x] Hdr: Resp tag mismatch. (0x%x != 0x%x)", + msg_id, header->tag, priv->rsp_tag); + return ret; + } + + if (header->command != msg_id) { + dev_err(priv->dev, + "MSG Header: Cmd id mismatch. (0x%x != 0x%x)", + header->command, msg_id); + return ret; + } + + 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 ret; + } + + if (is_base_api && (header->ver != priv->base_api_ver)) { + dev_err(priv->dev, + "MSG[0x%x] Hdr: Base API Vers mismatch. (0x%x != 0x%x)", + msg_id, header->ver, priv->base_api_ver); + return ret; + } else if (!is_base_api && header->ver != priv->fw_api_ver) { + dev_err(priv->dev, + "MSG[0x%x] Hdr: FW API Vers mismatch. (0x%x != 0x%x)", + msg_id, header->ver, priv->fw_api_ver); + return ret; + } + + ret = 0; + + return ret; +} + +int se_save_imem_state(struct device *dev) +{ + struct se_if_priv *priv = dev_get_drvdata(dev); + 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(dev, + priv->imem.phyaddr, + ELE_IMEM_SIZE, + ELE_IMEM_EXPORT); + if (ret < 0) + dev_err(dev, "Failed to export IMEM\n"); + else + dev_info(dev, + "Exported %d bytes of encrypted IMEM\n", + ret); + + return ret; +} + +int se_restore_imem_state(struct device *dev) +{ + struct se_if_priv *priv = dev_get_drvdata(dev); + struct ele_dev_info s_info; + int ret; + + /* get info from ELE */ + ret = ele_get_info(dev, &s_info); + if (ret) { + dev_err(dev, "Failed to get info from ELE.\n"); + return ret; + } + + /* 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(dev, + priv->imem.phyaddr, + priv->imem.size, + ELE_IMEM_IMPORT); + if (ret) { + dev_err(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(dev, &s_info); + if (ret) { + dev_err(dev, "Failed to get info from ELE.\n"); + goto exit; + } + + if (s_info.d_addn_info.imem_state == ELE_IMEM_STATE_OK) + dev_info(dev, "Successfully restored IMEM\n"); + else + dev_err(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..76777ac629d6 --- /dev/null +++ b/drivers/firmware/imx/ele_common.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2024 NXP + */ + + +#ifndef __ELE_COMMON_H__ +#define __ELE_COMMON_H__ + +#include "se_ctrl.h" + +#define IMX_ELE_FW_DIR "imx/ele/" + +uint32_t plat_add_msg_crc(uint32_t *msg, uint32_t msg_len); +int imx_ele_msg_rcv(struct se_if_priv *priv); +int imx_ele_msg_send(struct se_if_priv *priv, void *tx_msg); +int imx_ele_msg_send_rcv(struct se_if_priv *priv, void *tx_msg, void *rx_msg); +void se_if_rx_callback(struct mbox_client *mbox_cl, void *msg); +int validate_rsp_hdr(struct se_if_priv *priv, + struct se_msg_hdr *header, + 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 plat_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->cmd_tag; + hdr->ver = (is_base_api) ? priv->base_api_ver : priv->fw_api_ver; + hdr->command = cmd; + hdr->size = len >> 2; + + return 0; +} + +int se_save_imem_state(struct device *dev); +int se_restore_imem_state(struct device *dev); + +#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..0642d349b3d3 --- /dev/null +++ b/drivers/firmware/imx/se_ctrl.c @@ -0,0 +1,531 @@ +// 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 RESERVED_DMA_POOL BIT(0) + +struct imx_se_node_info { + u8 se_if_id; + u8 se_if_did; + u8 max_dev_ctx; + u8 cmd_tag; + u8 rsp_tag; + u8 success_tag; + u8 base_api_ver; + u8 fw_api_ver; + u8 *se_name; + u8 *mbox_tx_name; + u8 *mbox_rx_name; + u8 *pool_name; + u8 *fw_name_in_rfs; + bool soc_register; + bool reserved_dma_ranges; + bool imem_mgmt; + int (*se_fetch_soc_info)(struct device *dev, u16 *soc_rev, u64 *serial_num); +}; + +struct imx_se_node_info_list { + u8 num_mu; + u16 soc_id; + struct imx_se_node_info info[]; +}; + +static const struct imx_se_node_info_list imx8ulp_info = { + .num_mu = 1, + .soc_id = SOC_ID_OF_IMX8ULP, + .info = { + { + .se_if_id = 2, + .se_if_did = 7, + .max_dev_ctx = 4, + .cmd_tag = 0x17, + .rsp_tag = 0xe1, + .success_tag = 0xd6, + .base_api_ver = MESSAGING_VERSION_6, + .fw_api_ver = MESSAGING_VERSION_7, + .se_name = "hsm1", + .mbox_tx_name = "tx", + .mbox_rx_name = "rx", + .pool_name = "sram", + .fw_name_in_rfs = IMX_ELE_FW_DIR + "mx8ulpa2ext-ahab-container.img", + .soc_register = true, + .reserved_dma_ranges = true, + .imem_mgmt = true, + .se_fetch_soc_info = ele_fetch_soc_info, + }, + }, +}; + +static const struct imx_se_node_info_list imx93_info = { + .num_mu = 1, + .soc_id = SOC_ID_OF_IMX93, + .info = { + { + .se_if_id = 2, + .se_if_did = 3, + .max_dev_ctx = 4, + .cmd_tag = 0x17, + .rsp_tag = 0xe1, + .success_tag = 0xd6, + .base_api_ver = MESSAGING_VERSION_6, + .fw_api_ver = MESSAGING_VERSION_7, + .se_name = "hsm1", + .mbox_tx_name = "tx", + .mbox_rx_name = "rx", + .reserved_dma_ranges = true, + .imem_mgmt = true, + .soc_register = true, + }, + }, +}; + +static const struct of_device_id se_match[] = { + { .compatible = "fsl,imx8ulp-ele", .data = (void *)&imx8ulp_info}, + { .compatible = "fsl,imx93-ele", .data = (void *)&imx93_info}, + {}, +}; + +static struct imx_se_node_info + *get_imx_se_node_info(struct imx_se_node_info_list *info_list, + const u32 idx) +{ + if (idx > info_list->num_mu) + return NULL; + + return &info_list->info[idx]; +} + +void *get_phy_buf_mem_pool(struct device *dev, + u8 *mem_pool_name, + dma_addr_t *buf, + u32 size) +{ + struct device_node *of_node = dev->of_node; + struct gen_pool *mem_pool; + + mem_pool = of_gen_pool_get(of_node, mem_pool_name, 0); + if (!mem_pool) { + dev_err(dev, + "Unable to get sram pool = %s\n", + mem_pool_name); + return 0; + } + + return gen_pool_dma_alloc(mem_pool, size, buf); +} + +void free_phybuf_mem_pool(struct device *dev, + u8 *mem_pool_name, + u32 *buf, + u32 size) +{ + struct device_node *of_node = dev->of_node; + struct gen_pool *mem_pool; + + mem_pool = of_gen_pool_get(of_node, mem_pool_name, 0); + if (!mem_pool) + dev_err(dev, + "%s: Failed: Unable to get sram pool.\n", + __func__); + + gen_pool_free(mem_pool, (u64)buf, size); +} + +static int imx_fetch_se_soc_info(struct device *dev) +{ + struct se_if_priv *priv = dev_get_drvdata(dev); + struct imx_se_node_info_list *info_list; + const struct imx_se_node_info *info; + struct soc_device_attribute *attr; + struct soc_device *sdev; + u64 serial_num; + u16 soc_rev; + int err = 0; + + info = priv->info; + info_list = (struct imx_se_node_info_list *) + device_get_match_data(dev); + + /* This function should be called once. + * Check if the soc_rev is zero to continue. + */ + if (priv->soc_rev) + return err; + + err = info->se_fetch_soc_info(dev, &soc_rev, &serial_num); + if (err < 0) { + dev_err(dev, "Failed to fetch SoC Info."); + return err; + } + + priv->soc_rev = soc_rev; + if (!info->soc_register) + return 0; + + attr = devm_kzalloc(dev, sizeof(*attr), GFP_KERNEL); + if (!attr) + return -ENOMEM; + + if (FIELD_GET(DEV_GETINFO_MIN_VER_MASK, soc_rev)) + attr->revision = devm_kasprintf(dev, GFP_KERNEL, "%x.%x", + FIELD_GET(DEV_GETINFO_MIN_VER_MASK, + soc_rev), + FIELD_GET(DEV_GETINFO_MAJ_VER_MASK, + soc_rev)); + else + attr->revision = devm_kasprintf(dev, GFP_KERNEL, "%x", + FIELD_GET(DEV_GETINFO_MAJ_VER_MASK, + soc_rev)); + + switch (info_list->soc_id) { + case SOC_ID_OF_IMX8ULP: + attr->soc_id = devm_kasprintf(dev, GFP_KERNEL, + "i.MX8ULP"); + break; + case SOC_ID_OF_IMX93: + attr->soc_id = devm_kasprintf(dev, GFP_KERNEL, + "i.MX93"); + break; + } + + err = of_property_read_string(of_root, "model", + &attr->machine); + if (err) + return -EINVAL; + + attr->family = devm_kasprintf(dev, GFP_KERNEL, "Freescale i.MX"); + + attr->serial_number + = devm_kasprintf(dev, GFP_KERNEL, "%016llX", serial_num); + + sdev = soc_device_register(attr); + if (IS_ERR(sdev)) + return PTR_ERR(sdev); + + return 0; +} + +/* 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 int se_probe_if_cleanup(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct se_if_priv *priv; + int ret = 0; + + priv = dev_get_drvdata(dev); + if (!priv) { + ret = 0; + dev_dbg(dev, "SE-MU Priv data is NULL;"); + return ret; + } + + if (priv->tx_chan) + mbox_free_channel(priv->tx_chan); + if (priv->rx_chan) + mbox_free_channel(priv->rx_chan); + + /* free the buffer in se remove, previously allocated + * in se probe to store encrypted IMEM + */ + if (priv->imem.buf) { + dmam_free_coherent(dev, + ELE_IMEM_SIZE, + priv->imem.buf, + priv->imem.phyaddr); + priv->imem.buf = NULL; + } + + if (priv->flags & RESERVED_DMA_POOL) { + of_reserved_mem_device_release(dev); + priv->flags &= (~RESERVED_DMA_POOL); + } + + return ret; +} + +static void se_load_firmware(const struct firmware *fw, void *context) +{ + struct se_if_priv *priv = (struct se_if_priv *) context; + const struct imx_se_node_info *info = priv->info; + const u8 *se_fw_name = info->fw_name_in_rfs; + phys_addr_t se_fw_phyaddr; + u8 *se_fw_buf; + + if (!fw) { + if (priv->fw_fail > MAX_FW_LOAD_RETRIES) + dev_dbg(priv->dev, + "External FW not found, using ROM FW.\n"); + else { + /*add a bit delay to wait for firmware priv released */ + msleep(20); + + /* Load firmware one more time if timeout */ + request_firmware_nowait(THIS_MODULE, + FW_ACTION_UEVENT, info->fw_name_in_rfs, + priv->dev, GFP_KERNEL, priv, + se_load_firmware); + priv->fw_fail++; + dev_dbg(priv->dev, "Value of retries = 0x%x.\n", + priv->fw_fail); + } + + return; + } + + /* allocate buffer to store the SE FW */ + se_fw_buf = dmam_alloc_coherent(priv->dev, fw->size, + &se_fw_phyaddr, + GFP_KERNEL); + if (!se_fw_buf) { + dev_err(priv->dev, "Failed to alloc SE fw buffer memory\n"); + goto exit; + } + + memcpy(se_fw_buf, fw->data, fw->size); + + if (ele_fw_authenticate(priv->dev, se_fw_phyaddr)) + dev_err(priv->dev, + "Failed to authenticate & load SE firmware %s.\n", + se_fw_name); + +exit: + dmam_free_coherent(priv->dev, + fw->size, + se_fw_buf, + se_fw_phyaddr); + + release_firmware(fw); +} + +static int se_if_probe(struct platform_device *pdev) +{ + struct imx_se_node_info_list *info_list; + struct device *dev = &pdev->dev; + struct imx_se_node_info *info; + struct se_if_priv *priv; + u32 idx; + int ret; + + if (of_property_read_u32(dev->of_node, "reg", &idx)) { + ret = -EINVAL; + goto exit; + } + + info_list = (struct imx_se_node_info_list *) + device_get_match_data(dev); + info = get_imx_se_node_info(info_list, idx); + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) { + ret = -ENOMEM; + goto exit; + } + + dev_set_drvdata(dev, priv); + + /* 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, info->mbox_tx_name); + if (ret) + goto exit; + + ret = se_if_request_channel(dev, &priv->rx_chan, + &priv->se_mb_cl, info->mbox_rx_name); + if (ret) + goto exit; + + priv->dev = dev; + priv->info = info; + + /* Initialize the mutex. */ + mutex_init(&priv->se_if_lock); + mutex_init(&priv->se_if_cmd_lock); + + priv->cmd_receiver_dev = NULL; + priv->waiting_rsp_dev = NULL; + priv->max_dev_ctx = info->max_dev_ctx; + priv->cmd_tag = info->cmd_tag; + priv->rsp_tag = info->rsp_tag; + priv->mem_pool_name = info->pool_name; + priv->success_tag = info->success_tag; + priv->base_api_ver = info->base_api_ver; + priv->fw_api_ver = info->fw_api_ver; + + init_completion(&priv->done); + spin_lock_init(&priv->lock); + + 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); + priv->flags &= (~RESERVED_DMA_POOL); + goto exit; + } + priv->flags |= RESERVED_DMA_POOL; + } + + if (info->fw_name_in_rfs) { + ret = request_firmware_nowait(THIS_MODULE, + FW_ACTION_UEVENT, + info->fw_name_in_rfs, + dev, GFP_KERNEL, priv, + se_load_firmware); + if (ret) + dev_warn(dev, "Failed to get firmware [%s].\n", + info->fw_name_in_rfs); + } + + ret = imx_fetch_se_soc_info(dev); + if (ret) { + dev_err(dev, + "failed[%pe] to fetch SoC Info\n", ERR_PTR(ret)); + goto exit; + } + + if (info->imem_mgmt) { + /* allocate buffer where SE store encrypted IMEM */ + priv->imem.buf = dmam_alloc_coherent(dev, ELE_IMEM_SIZE, + &priv->imem.phyaddr, + GFP_KERNEL); + if (!priv->imem.buf) { + dev_err(dev, + "dmam-alloc-failed: To store encr-IMEM.\n"); + ret = -ENOMEM; + goto exit; + } + } + + dev_info(dev, "i.MX secure-enclave: %s interface to firmware, configured.\n", + info->se_name); + return devm_of_platform_populate(dev); + +exit: + /* if execution control reaches here, if probe fails. + * hence doing the cleanup + */ + if (se_probe_if_cleanup(pdev)) + dev_err(dev, + "Failed to clean-up the child node probe.\n"); + + return ret; +} + +static int se_remove(struct platform_device *pdev) +{ + if (se_probe_if_cleanup(pdev)) + dev_err(&pdev->dev, + "i.MX Secure Enclave is not cleanly un-probed."); + + return 0; +} + +static int se_suspend(struct device *dev) +{ + struct se_if_priv *priv = dev_get_drvdata(dev); + const struct imx_se_node_info *info + = priv->info; + + if (info && info->imem_mgmt) + priv->imem.size = se_save_imem_state(dev); + + return 0; +} + +static int se_resume(struct device *dev) +{ + struct se_if_priv *priv = dev_get_drvdata(dev); + const struct imx_se_node_info *info + = priv->info; + + if (info && info->imem_mgmt) + se_restore_imem_state(dev); + + 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_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..7d4f439a6158 --- /dev/null +++ b/drivers/firmware/imx/se_ctrl.h @@ -0,0 +1,99 @@ +/* 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 MESSAGING_VERSION_6 0x6 +#define MESSAGING_VERSION_7 0x7 + +struct se_imem_buf { + u8 *buf; + phys_addr_t phyaddr; + u32 size; +}; + +/* 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_priv { + struct se_if_device_ctx *cmd_receiver_dev; + /* Update to the waiting_rsp_dev, to be protected + * under se_if_lock. + */ + struct se_if_device_ctx *waiting_rsp_dev; + /* + * prevent parallel access to the se interface registers + * e.g. a user trying to send a command while the other one is + * sending a response. + */ + struct mutex se_if_lock; + /* + * prevent a command to be sent on the se interface while another one is + * still processing. (response to a command is allowed) + */ + struct mutex se_if_cmd_lock; + struct device *dev; + u8 *mem_pool_name; + u8 cmd_tag; + u8 rsp_tag; + u8 success_tag; + u8 base_api_ver; + u8 fw_api_ver; + u32 fw_fail; + u16 soc_rev; + const void *info; + + struct mbox_client se_mb_cl; + struct mbox_chan *tx_chan, *rx_chan; + + /* 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 completion done; + spinlock_t lock; + /* + * Flag to retain the state of initialization done at + * the time of se-if probe. + */ + uint32_t flags; + u8 max_dev_ctx; + struct se_if_device_ctx **ctxs; + struct se_imem_buf imem; +}; + +void *get_phy_buf_mem_pool(struct device *dev, + u8 *mem_pool_name, + dma_addr_t *buf, + u32 size); +phys_addr_t get_phy_buf_mem_pool1(struct device *dev, + u8 *mem_pool_name, + u32 **buf, + u32 size); +void free_phybuf_mem_pool(struct device *dev, + u8 *mem_pool_name, + u32 *buf, + u32 size); +#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 Thu May 23 10:49:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 13671618 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8081CC25B79 for ; Thu, 23 May 2024 10:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=T7J0xurYOJkGt52ooBxlPKN8mj+R8TUMHZocgqMMX1I=; b=EwZlZR2KlNAcycBiDqz/AB3+aJ ADwMM0uUHMMmRVFIrczmyoYKnLSHF76uCZ6aXnJtCo1g6GFClmHv9HkUxNSJKnt7GE+HX9L2UoL8j 1iZD4M7FTCdf3GE2jTs39S5w6ooquTEVJ06tvTD1S7rNkygA6JyneFxvYkFqnlTa0CwvIOh21l6/W aRDGsmjTBGoqAKIdrSlcWSwSSOIb7vBPE3GXzJ9SLOloWoBMIhgPx+3djju6k/jgjvwC60ANClaDg e5iWGjmlaz7kRCgwz494mOEapV3ZjkyTVgVZBYKxZiQvS61jKxMZztLo/h+A64REbAdBc4STvMXGR +EiqnUfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sA64Q-00000005x9r-3vIw; Thu, 23 May 2024 10:53:14 +0000 Received: from mail-he1eur04on20600.outbound.protection.outlook.com ([2a01:111:f403:260f::600] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sA64F-00000005wzV-0Mgl for linux-arm-kernel@lists.infradead.org; Thu, 23 May 2024 10:53:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gG6OR4qPhrmQB9oBnDYU67w19CqHDqmy1xhTCO4mgA2hog3eCgueprYwkmB+bVsXdGhqjKrjyMnitomFK4d4UvFpVeO9JZegiXuHifai/skTIwKwXK6MQWUyIhfLnQGVeR88xHRH5RlvtMpiUK82MioMp4KCbQEl3of8ACR0RqyssfTh2ohwXpncr/l74KZS4m1gBfusU/xADcOdhS/GMBdOrNVzu7oVWPl5fkzvG2voTiEMb5cyI/1S94Xdt7kqsauRVYGPEnwZoBMiz/bhodXHn6B1lXcyczl5+Rb+Xk5BmblOjwcbyBW7LqBdeO/L6IL0Jk1GJri5jBOTSpkeWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lSxrDooHWmjfxrZsMyO/CQuz0Lp7EtU6XeR8zO+LvxE=; b=dq4rWLUsEAdnZngnVFuxWAn1HwWKMJUW5PW7QvlzpZ1R5Bho7yVY1eGBnoDgS91RqzPZt+pIp0wac5c0Rn3hIQYIDNq/2mtM7x8fBySpHlbZwjqBjKj4S55RSpCeZar1CMlxfNZdBPa55Vp0f5ohwf85kUcbZ36PRf+gpaKDW4ID+1vG85SyHfRqwSrn5EJHjK47Xy5uqgWX/tLwwSPq3XBKgAtD8ATL1cyfPIyK2DCRm+ZWa74gkGEoRO9uSZvJjOTN0MYB8w7LrF/51gD3pq7i8ftvsAFT06DLuIcQFe48qtMqWBQl6TlMCwj4ZUrXem3AZMJyfzGCS0Kbqe7mFQ== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lSxrDooHWmjfxrZsMyO/CQuz0Lp7EtU6XeR8zO+LvxE=; b=EkKEKLfGXtP/RfWM99Q5ZZsON7jC5530JowoPaLVrz92TwGABxRsAz5ifvldZZL068TU/yMPEdXHYctZ3fskC03+RcMvsHQ1Rr2tiynuFtjuXkLi1nvwIGyARyO9RdrplgIBHfH6UCJp5qRVg1MeA2IBWH+qvyfOb7+sa18+Kjs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8604.eurprd04.prod.outlook.com (2603:10a6:20b:43b::21) by PAXPR04MB9571.eurprd04.prod.outlook.com (2603:10a6:102:24e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.34; Thu, 23 May 2024 10:52:55 +0000 Received: from AM9PR04MB8604.eurprd04.prod.outlook.com ([fe80::e751:223e:aa3d:5827]) by AM9PR04MB8604.eurprd04.prod.outlook.com ([fe80::e751:223e:aa3d:5827%4]) with mapi id 15.20.7587.035; Thu, 23 May 2024 10:52:55 +0000 From: Pankaj Gupta Date: Thu, 23 May 2024 16:19:36 +0530 Subject: [PATCH v2 5/5] firmware: imx: adds miscdev Message-Id: <20240523-imx-se-if-v2-5-5a6fd189a539@nxp.com> References: <20240523-imx-se-if-v2-0-5a6fd189a539@nxp.com> In-Reply-To: <20240523-imx-se-if-v2-0-5a6fd189a539@nxp.com> To: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Rob Herring , Krzysztof Kozlowski 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, Pankaj Gupta X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1716461396; l=30764; i=pankaj.gupta@nxp.com; s=20240523; h=from:subject:message-id; bh=nNtsekLbSKS/7Kw8xz32XubYeLBMrFRe9/7nwmSYOnw=; b=/jgKs1XN3HnTs29hDs3OM20uF53JuV8iKb1z3ZRqz7izSeMcN5F2E5QDE0S6H5BhohwLRLkR5 c/o8LD2kEYBCyTbvhIeZiy4mRHvYLvR82nw456SBEHz0/PYAo4nz9gL X-Developer-Key: i=pankaj.gupta@nxp.com; a=ed25519; pk=OA0pBQoupy5lV0XfKzD8B0OOBVB6tpAoIf+0x1bYGRg= X-ClientProxiedBy: SI2PR01CA0027.apcprd01.prod.exchangelabs.com (2603:1096:4:192::7) To AM9PR04MB8604.eurprd04.prod.outlook.com (2603:10a6:20b:43b::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8604:EE_|PAXPR04MB9571:EE_ X-MS-Office365-Filtering-Correlation-Id: bbda1a89-f28c-4dff-fed5-08dc7b168095 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|366007|52116005|7416005|1800799015|38350700005|921011; X-Microsoft-Antispam-Message-Info: =?utf-8?q?QdIHhMnyiQMvfhEdaWEpF44idN9Fh4L?= =?utf-8?q?HM+Bf+9t6z25bY4+zwYDzm1vzamaw1ledxWLgtliyfFuY3hllhd2v/zqebm+V15FE?= =?utf-8?q?Q1sSmOHwYWuHNp5tcX3hBsuUCyLF1diBk4YWHy3x9hFcx6nM/eFaKe8ChaNQIh7uH?= =?utf-8?q?THb6SEteA51Ib+927G+gi3QLUPSWspMPvlJltKIPyPpqZRNA26t6P4ybLZ+rwcvyG?= =?utf-8?q?zwM+rT7ag97wK2VT+knpO3kBm2E1zzxpZA2ZTP/bq63DEROutEPTJtdRTl1VGKEks?= =?utf-8?q?yg8y/6VFe0Rnv30K6bKgE92BaqLaw15nEqFzr8w1+JHfFM/+yIHDvKI/j1SfVVIfI?= =?utf-8?q?RmP/jcZWzT9gWhYBy9hgsl1zKp4lG1kwhMActK5I+brZsetfDRBqItDO3PxBlfxlz?= =?utf-8?q?m5Dt5WlS06XVQLAgVmCJXUaL7J3MlJlVD5djyLNwGk8cMwNQ7g7hK5iUVs7QnOEhA?= =?utf-8?q?PV7ynQ9dGiAtrE4h+qI/D9l7j5BTVdnLu+bCKjq1QvA5qSwtkXAlIGelsuYNDn1/r?= =?utf-8?q?zf0RhJtImmiSpu6By8vSWS4XsGMMByOog/ikHYqz/Tie2K8atq1ffxXvOCyRyWE1Y?= =?utf-8?q?I93nUG4dQS3YdPl+0aiqCs6jF4wTuudH05VLU1Fj7IHEy1R4Yvpo4XUEsDTJ7lInD?= =?utf-8?q?gYqXzBMtswYGxfycr4RkQovlFBFfSbJirxu397iUaJd3tUEfzSJwoVQaVh1sPS6Cn?= =?utf-8?q?uvGEGc2NDP7izc0R7VJHtbqURDJzpb100td8sn1LZLP17NhkNbamAfAQ73jd7VAuG?= =?utf-8?q?B8nZg1gPExheWZamV1yh4LZ0dAYn/qkFdR80EFa81wbBsxN2pUfXQUqdSsh4Lixq1?= =?utf-8?q?/3zu7UU91CHz6uzDIV+ocTjnGlGtVwwZEhTkQp9E0eYPxoga7xy01SW5hnjZdKHF4?= =?utf-8?q?R7YNZyQnLd3fWaA6yEOenfVfcWp/9A4BXnyjXWWeiMuVcWFyWZKVsLdMUQi1yCLQT?= =?utf-8?q?fQrjm2NRC0c1uYSMx2A0jFH/Zaaqs+xEU98s7H5DLWkNAyZ0/pma5lGlkuvnDF5me?= =?utf-8?q?sKRS2SyYGcNDKcvjRuvqwco9r+NNZ/NX0uEws9hQulfA5FrceYpL5Ck3fiMjk3/JP?= =?utf-8?q?zT73C+stlrQADDvMPOnlGMNMHOhTPbWTBrse8Zrm8lT4jTEERRCY+k/HHVJBkptVf?= =?utf-8?q?rlc40OFr3c5GbUfX3kWv6DDuoeyySa9bSHcyxMxUNeUdcIUlRvpDRLRcL2336CyYj?= =?utf-8?q?a1fd3nu0OyJVwiglDOtWnQqSnSu2Tl9PONQV53u2eqIHCpx59FFdR2W0w=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8604.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(366007)(52116005)(7416005)(1800799015)(38350700005)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?1iTwCQ/tFyfIhkhvIAQtMTib8+f2?= =?utf-8?q?hMomA+aE4ynp8W1oqG4Tky1t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MUolvYO+oBCpWc2QBm4b1z6jkYgKfiw?= =?utf-8?q?dcGhoEn9j38wD03AGUUK3oA2pTvb0psMatbRN1z9xvjmjZqh3NwK8uBX0IGJOymxH?= =?utf-8?q?Y5LMSZui5YfbkhXUtpIYqjZSYMiEGy/puuyOTYrSpc+pvdYOctKCCpQF5G402Q/8r?= =?utf-8?q?8hKNF81s7rPIPjFdKPd7U0SabQdOXkufnR82IdcrJbvwpUl1c7RkqGtHy2uz8FVMO?= =?utf-8?q?OIkH9d5RPx+Hzhk2Mf6BNLEBwOWD+O/9GjevYDGNBDDUuUM4WHr2jm8rdlCtYZF+h?= =?utf-8?q?+rHxAzQ0YrrGxiUJfNNHL9I8PmknKcZVlLRPi9gvJKE3ylNppgDKPKDsx5/ga7Q8z?= =?utf-8?q?nvYIfIBMsImYR4V+yg7OZ8QD4kH5uhrLdHNlQVI1WyNOLrMQIGQvHdqlnPNzWU16d?= =?utf-8?q?g5qNDeGUGUirQ3Pxfp/1lCIVHnXGTFKHSomL+J2BYFMQTeRERGp7Jkjk0K8lruraX?= =?utf-8?q?04aTHfDkJPmKq4hbZB3AQGgSw5LiLV/bmA+SSoxoLSNv+tWXamzB8HHLwek64yM/2?= =?utf-8?q?NIgeOIAkBubSMgUA2sY+IMSwheiu4jIKWQxtikCpqdOyBnyD72OXoAjk+mhXp1K9h?= =?utf-8?q?89YDfJFApCgm?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: bbda1a89-f28c-4dff-fed5-08dc7b168095 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8604.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 10:52:55.7368 (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: 7+k7O3DP1He+IV0qMV9bR4KdLAg7DeihJSzkRYJQYKuv5DfnE+xIzABmtcHSLUAPsQFsdoe6VuK7qZtqsV7Qbw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9571 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240523_035303_462726_A5BBC3E0 X-CRM114-Status: GOOD ( 26.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 | 42 +++ drivers/firmware/imx/ele_common.c | 108 +++++- drivers/firmware/imx/ele_common.h | 3 + drivers/firmware/imx/se_ctrl.c | 689 ++++++++++++++++++++++++++++++++++++++ drivers/firmware/imx/se_ctrl.h | 46 +++ include/uapi/linux/se_ioctl.h | 88 +++++ 6 files changed, 974 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/se-cdev b/Documentation/ABI/testing/se-cdev new file mode 100644 index 000000000000..699525af6b86 --- /dev/null +++ b/Documentation/ABI/testing/se-cdev @@ -0,0 +1,42 @@ +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 user-space 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 + - get mu info + - setting a dev-ctx as receiver that is slave to fw + - get SoC info + + 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 + wakeup_intruptible, 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 free up the I/O contexts that was 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_common.c b/drivers/firmware/imx/ele_common.c index c286c3d84d82..15fabc369b21 100644 --- a/drivers/firmware/imx/ele_common.c +++ b/drivers/firmware/imx/ele_common.c @@ -78,12 +78,98 @@ int imx_ele_msg_send_rcv(struct se_if_priv *priv, void *tx_msg, void *rx_msg) return err; } +int imx_ele_miscdev_msg_rcv(struct se_if_device_ctx *dev_ctx) +{ + struct se_msg_hdr *header = {0}; + int err; + + if (dev_ctx->priv->waiting_rsp_dev == dev_ctx) + lockdep_assert_held(&dev_ctx->priv->se_if_cmd_lock); + + err = wait_event_interruptible(dev_ctx->wq, dev_ctx->pending_hdr != 0); + if (err) + dev_err(dev_ctx->dev, + "%s: Err[0x%x]:Interrupted by signal.\n", + dev_ctx->miscdev.name, err); + + header = (struct se_msg_hdr *) dev_ctx->temp_resp; + + if (header->tag == dev_ctx->priv->rsp_tag) { + if (dev_ctx->priv->waiting_rsp_dev != dev_ctx) + dev_warn(dev_ctx->dev, + "%s: Device context waiting for response mismatch.\n", + dev_ctx->miscdev.name); + else + dev_ctx->priv->waiting_rsp_dev = NULL; + + mutex_unlock(&dev_ctx->priv->se_if_cmd_lock); + } + + return err; +} + +int imx_ele_miscdev_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; + + header = (struct se_msg_hdr *) tx_msg; + + /* + * Check that the size passed as argument matches the size + * carried in the message. + */ + err = header->size << 2; + + if (err != tx_msg_sz) { + err = -EINVAL; + dev_err(priv->dev, + "%s: User buffer too small\n", + dev_ctx->miscdev.name); + goto exit; + } + /* Check the message is valid according to tags */ + if (header->tag == priv->cmd_tag) { + mutex_lock(&priv->se_if_cmd_lock); + priv->waiting_rsp_dev = dev_ctx; + } else if (header->tag == priv->rsp_tag) { + /* Check the device context can send the command */ + if (dev_ctx != priv->cmd_receiver_dev) { + dev_err(priv->dev, + "%s: Channel not configured to send resp to FW.", + dev_ctx->miscdev.name); + err = -EPERM; + goto exit; + } + } else { + dev_err(priv->dev, + "%s: The message does not have a valid TAG\n", + dev_ctx->miscdev.name); + err = -EINVAL; + goto exit; + } + err = imx_ele_msg_send(priv, tx_msg); + if (err < 0) { + if (header->tag == priv->cmd_tag) { + priv->waiting_rsp_dev = NULL; + mutex_unlock(&dev_ctx->priv->se_if_cmd_lock); + } + } else + err = header->size << 2; +exit: + return err; +} + /* * Callback called by mailbox FW, when data is received. */ void se_if_rx_callback(struct mbox_client *mbox_cl, void *msg) { struct device *dev = mbox_cl->dev; + struct se_if_device_ctx *dev_ctx; + struct se_api_msg *rx_msg; struct se_if_priv *priv; struct se_msg_hdr *header; @@ -97,8 +183,15 @@ void se_if_rx_callback(struct mbox_client *mbox_cl, void *msg) header = (struct se_msg_hdr *) msg; - if (header->tag == priv->rsp_tag) { - if (!priv->waiting_rsp_dev) { + /* Incoming command: wake up the receiver if any. */ + if (header->tag == priv->cmd_tag) { + dev_dbg(dev, "Selecting cmd receiver\n"); + dev_ctx = priv->cmd_receiver_dev; + } else if (header->tag == priv->rsp_tag) { + if (priv->waiting_rsp_dev) { + dev_dbg(dev, "Selecting rsp waiter\n"); + dev_ctx = priv->waiting_rsp_dev; + } else { /* * Reading the EdgeLock Enclave response * to the command, sent by other @@ -116,6 +209,17 @@ void se_if_rx_callback(struct mbox_client *mbox_cl, void *msg) *((u32 *) header)); return; } + /* Init reception */ + rx_msg = kzalloc(header->size << 2, GFP_KERNEL); + if (rx_msg) + memcpy(rx_msg, msg, header->size << 2); + + dev_ctx->temp_resp = (u32 *)rx_msg; + dev_ctx->temp_resp_size = header->size; + + /* Allow user to read */ + dev_ctx->pending_hdr = 1; + wake_up_interruptible(&dev_ctx->wq); } int validate_rsp_hdr(struct se_if_priv *priv, diff --git a/drivers/firmware/imx/ele_common.h b/drivers/firmware/imx/ele_common.h index 76777ac629d6..11b9b36d4fda 100644 --- a/drivers/firmware/imx/ele_common.h +++ b/drivers/firmware/imx/ele_common.h @@ -12,6 +12,9 @@ #define IMX_ELE_FW_DIR "imx/ele/" uint32_t plat_add_msg_crc(uint32_t *msg, uint32_t msg_len); +int imx_ele_miscdev_msg_rcv(struct se_if_device_ctx *priv); +int imx_ele_miscdev_msg_send(struct se_if_device_ctx *dev_ctx, + void *tx_msg, int tx_msg_sz); int imx_ele_msg_rcv(struct se_if_priv *priv); int imx_ele_msg_send(struct se_if_priv *priv, void *tx_msg); int imx_ele_msg_send_rcv(struct se_if_priv *priv, void *tx_msg, void *rx_msg); diff --git a/drivers/firmware/imx/se_ctrl.c b/drivers/firmware/imx/se_ctrl.c index 0642d349b3d3..3acaecd8f3bc 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" @@ -232,6 +233,590 @@ static int imx_fetch_se_soc_info(struct device *dev) return 0; } +/* + * 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_api_msg *tx_msg __free(kfree); + struct se_if_device_ctx *dev_ctx; + struct se_if_priv *priv; + int err; + + dev_ctx = container_of(fp->private_data, + struct se_if_device_ctx, + miscdev); + priv = dev_ctx->priv; + dev_dbg(priv->dev, + "%s: write from buf (%p)%zu, ppos=%lld\n", + dev_ctx->miscdev.name, + buf, size, ((ppos) ? *ppos : 0)); + + if (down_interruptible(&dev_ctx->fops_lock)) + return -EBUSY; + + if (dev_ctx->status != SE_IF_CTX_OPENED) { + err = -EINVAL; + goto exit; + } + + if (size < SE_MU_HDR_SZ) { + dev_err(priv->dev, + "%s: User buffer too small(%zu < %d)\n", + dev_ctx->miscdev.name, + size, SE_MU_HDR_SZ); + err = -ENOSPC; + goto exit; + } + tx_msg = memdup_user(buf, size); + if (!tx_msg) { + err = -ENOMEM; + goto exit; + } + + print_hex_dump_debug("from user ", DUMP_PREFIX_OFFSET, 4, 4, + tx_msg, size, false); + + err = imx_ele_miscdev_msg_send(dev_ctx, tx_msg, size); + +exit: + up(&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; + struct se_buf_desc *b_desc; + struct se_if_priv *priv; + u32 size_to_copy; + int err; + + dev_ctx = container_of(fp->private_data, + struct se_if_device_ctx, + miscdev); + priv = dev_ctx->priv; + dev_dbg(priv->dev, + "%s: read to buf %p(%zu), ppos=%lld\n", + dev_ctx->miscdev.name, + buf, size, ((ppos) ? *ppos : 0)); + + if (down_interruptible(&dev_ctx->fops_lock)) + return -EBUSY; + + if (dev_ctx->status != SE_IF_CTX_OPENED) { + err = -EINVAL; + goto exit; + } + + err = imx_ele_miscdev_msg_rcv(dev_ctx); + if (err) + goto exit; + + /* Buffer containing the message from FW, is + * allocated in callback function. + * Check if buffer allocation failed. + */ + if (!dev_ctx->temp_resp) { + err = -ENOMEM; + goto exit; + } + + dev_dbg(priv->dev, + "%s: %s %s\n", + dev_ctx->miscdev.name, + __func__, + "message received, start transmit to user"); + + /* + * Check that the size passed as argument is larger than + * the one carried in the message. + */ + size_to_copy = dev_ctx->temp_resp_size << 2; + if (size_to_copy > size) { + dev_dbg(priv->dev, + "%s: User buffer too small (%zu < %d)\n", + dev_ctx->miscdev.name, + size, size_to_copy); + size_to_copy = size; + } + + /* + * We may need to copy the output data to user before + * delivering the completion message. + */ + while (!list_empty(&dev_ctx->pending_out)) { + b_desc = list_first_entry_or_null(&dev_ctx->pending_out, + struct se_buf_desc, + link); + if (!b_desc) + continue; + + if (b_desc->usr_buf_ptr && b_desc->shared_buf_ptr) { + + dev_dbg(priv->dev, + "%s: Copy output data to user\n", + dev_ctx->miscdev.name); + if (copy_to_user(b_desc->usr_buf_ptr, + b_desc->shared_buf_ptr, + b_desc->size)) { + dev_err(priv->dev, + "%s: Failure copying output data to user.", + dev_ctx->miscdev.name); + err = -EFAULT; + goto exit; + } + } + + if (b_desc->shared_buf_ptr) + memset(b_desc->shared_buf_ptr, 0, b_desc->size); + + __list_del_entry(&b_desc->link); + kfree(b_desc); + } + + /* Copy data from the buffer */ + print_hex_dump_debug("to user ", DUMP_PREFIX_OFFSET, 4, 4, + dev_ctx->temp_resp, size_to_copy, false); + if (copy_to_user(buf, dev_ctx->temp_resp, size_to_copy)) { + dev_err(priv->dev, + "%s: Failed to copy to user\n", + dev_ctx->miscdev.name); + err = -EFAULT; + goto exit; + } + + err = size_to_copy; + kfree(dev_ctx->temp_resp); + + /* free memory allocated on the shared buffers. */ + dev_ctx->secure_mem.pos = 0; + dev_ctx->non_secure_mem.pos = 0; + + dev_ctx->pending_hdr = 0; + +exit: + /* + * Clean the used Shared Memory space, + * whether its Input Data copied from user buffers, or + * Data received from FW. + */ + while (!list_empty(&dev_ctx->pending_in) || + !list_empty(&dev_ctx->pending_out)) { + if (!list_empty(&dev_ctx->pending_in)) + b_desc = list_first_entry_or_null(&dev_ctx->pending_in, + struct se_buf_desc, + link); + else + b_desc = list_first_entry_or_null(&dev_ctx->pending_out, + struct se_buf_desc, + link); + + if (!b_desc) + continue; + + if (b_desc->shared_buf_ptr) + memset(b_desc->shared_buf_ptr, 0, b_desc->size); + + __list_del_entry(&b_desc->link); + kfree(b_desc); + } + + up(&dev_ctx->fops_lock); + return err; +} + +static int se_ioctl_get_mu_info(struct se_if_device_ctx *dev_ctx, + u64 arg) +{ + struct se_if_priv *priv = dev_get_drvdata(dev_ctx->dev); + struct imx_se_node_info *if_node_info; + struct se_ioctl_get_if_info info; + int err = 0; + + if_node_info = (struct imx_se_node_info *)priv->info; + + info.se_if_id = if_node_info->se_if_id; + info.interrupt_idx = 0; + info.tz = 0; + info.did = if_node_info->se_if_did; + info.cmd_tag = if_node_info->cmd_tag; + info.rsp_tag = if_node_info->rsp_tag; + info.success_tag = if_node_info->success_tag; + info.base_api_ver = if_node_info->base_api_ver; + info.fw_api_ver = if_node_info->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->miscdev.name, + info.se_if_id, info.interrupt_idx, info.tz, info.did); + + if (copy_to_user((u8 *)arg, &info, sizeof(info))) { + dev_err(dev_ctx->priv->dev, + "%s: Failed to copy mu info to user\n", + dev_ctx->miscdev.name); + 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}; + struct se_buf_desc *b_desc = NULL; + int err = 0; + u32 pos; + + if (copy_from_user(&io, (u8 *)arg, sizeof(io))) { + dev_err(dev_ctx->priv->dev, + "%s: Failed copy iobuf config from user\n", + dev_ctx->miscdev.name); + err = -EFAULT; + goto exit; + } + + dev_dbg(dev_ctx->priv->dev, + "%s: io [buf: %p(%d) flag: %x]\n", + dev_ctx->miscdev.name, + 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; + } + + /* Select the shared memory to be used for this buffer. */ + if (io.flags & SE_MU_IO_FLAGS_USE_SEC_MEM) { + /* App requires to use secure memory for this buffer.*/ + dev_err(dev_ctx->priv->dev, + "%s: Failed allocate SEC MEM memory\n", + dev_ctx->miscdev.name); + err = -EFAULT; + goto exit; + } else { + /* No specific requirement for this buffer. */ + shared_mem = &dev_ctx->non_secure_mem; + } + + /* Check there is enough space in the shared memory. */ + if (shared_mem->size < shared_mem->pos + || io.length >= shared_mem->size - shared_mem->pos) { + dev_err(dev_ctx->priv->dev, + "%s: Not enough space in shared memory\n", + dev_ctx->miscdev.name); + 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; + + if ((io.flags & SE_MU_IO_FLAGS_USE_SEC_MEM) && + !(io.flags & SE_MU_IO_FLAGS_USE_SHORT_ADDR)) { + /*Add base address to get full address.*/ + dev_err(dev_ctx->priv->dev, + "%s: Failed allocate SEC MEM memory\n", + dev_ctx->miscdev.name); + err = -EFAULT; + goto exit; + } + + 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->miscdev.name); + err = -EFAULT; + goto exit; + } + } + + b_desc = kzalloc(sizeof(*b_desc), GFP_KERNEL); + if (!b_desc) { + err = -ENOMEM; + goto exit; + } + +copy: + /* Provide the EdgeLock Enclave address to user space only if success.*/ + if (copy_to_user((u8 *)arg, &io, sizeof(io))) { + dev_err(dev_ctx->priv->dev, + "%s: Failed to copy iobuff setup to user\n", + dev_ctx->miscdev.name); + kfree(b_desc); + err = -EFAULT; + goto exit; + } + + if (b_desc) { + b_desc->shared_buf_ptr = shared_mem->ptr + 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, &dev_ctx->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, &dev_ctx->pending_out); + } + } + +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) +{ + struct imx_se_node_info_list *info_list; + struct se_ioctl_get_soc_info soc_info; + int err = -EINVAL; + + info_list = (struct imx_se_node_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 = dev_ctx->priv->soc_rev; + + err = (int)copy_to_user((u8 *)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->miscdev.name); + err = -EFAULT; + goto exit; + } + +exit: + return err; +} + +/* Open a character device. */ +static int se_if_fops_open(struct inode *nd, struct file *fp) +{ + struct se_if_device_ctx *dev_ctx = container_of(fp->private_data, + struct se_if_device_ctx, + miscdev); + int err = 0; + + /* Avoid race if opened at the same time */ + if (down_trylock(&dev_ctx->fops_lock)) + return -EBUSY; + + /* Authorize only 1 instance. */ + if (dev_ctx->status != SE_IF_CTX_FREE) { + err = -EBUSY; + goto exit; + } + + /* + * Allocate some memory for data exchanges with S40x. + * This will be used for data not requiring secure memory. + */ + dev_ctx->non_secure_mem.ptr = dmam_alloc_coherent(dev_ctx->dev, + MAX_DATA_SIZE_PER_USER, + &dev_ctx->non_secure_mem.dma_addr, + GFP_KERNEL); + if (!dev_ctx->non_secure_mem.ptr) { + err = -ENOMEM; + goto exit; + } + + dev_ctx->non_secure_mem.size = MAX_DATA_SIZE_PER_USER; + dev_ctx->non_secure_mem.pos = 0; + dev_ctx->status = SE_IF_CTX_OPENED; + + dev_ctx->pending_hdr = 0; + + goto exit; + + dmam_free_coherent(dev_ctx->priv->dev, MAX_DATA_SIZE_PER_USER, + dev_ctx->non_secure_mem.ptr, + dev_ctx->non_secure_mem.dma_addr); + +exit: + up(&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 = container_of(fp->private_data, + struct se_if_device_ctx, + miscdev); + struct se_if_priv *priv = dev_ctx->priv; + struct se_buf_desc *b_desc; + + /* Avoid race if closed at the same time */ + if (down_trylock(&dev_ctx->fops_lock)) + return -EBUSY; + + /* The device context has not been opened */ + if (dev_ctx->status != SE_IF_CTX_OPENED) + goto exit; + + /* check if this device was registered as command receiver. */ + if (priv->cmd_receiver_dev == dev_ctx) + priv->cmd_receiver_dev = NULL; + + /* check if this device was registered as waiting response. */ + if (priv->waiting_rsp_dev == dev_ctx) { + priv->waiting_rsp_dev = NULL; + mutex_unlock(&priv->se_if_cmd_lock); + } + + /* Unmap secure memory shared buffer. */ + if (dev_ctx->secure_mem.ptr) + devm_iounmap(dev_ctx->dev, dev_ctx->secure_mem.ptr); + + dev_ctx->secure_mem.ptr = NULL; + dev_ctx->secure_mem.dma_addr = 0; + dev_ctx->secure_mem.size = 0; + dev_ctx->secure_mem.pos = 0; + + /* Free non-secure shared buffer. */ + dmam_free_coherent(dev_ctx->priv->dev, MAX_DATA_SIZE_PER_USER, + dev_ctx->non_secure_mem.ptr, + dev_ctx->non_secure_mem.dma_addr); + + dev_ctx->non_secure_mem.ptr = NULL; + dev_ctx->non_secure_mem.dma_addr = 0; + dev_ctx->non_secure_mem.size = 0; + dev_ctx->non_secure_mem.pos = 0; + + while (!list_empty(&dev_ctx->pending_in) || + !list_empty(&dev_ctx->pending_out)) { + if (!list_empty(&dev_ctx->pending_in)) + b_desc = list_first_entry_or_null(&dev_ctx->pending_in, + struct se_buf_desc, + link); + else + b_desc = list_first_entry_or_null(&dev_ctx->pending_out, + struct se_buf_desc, + link); + + if (!b_desc) + continue; + + if (b_desc->shared_buf_ptr) + memset(b_desc->shared_buf_ptr, 0, b_desc->size); + + __list_del_entry(&b_desc->link); + kfree(b_desc); + } + + dev_ctx->status = SE_IF_CTX_FREE; + +exit: + up(&dev_ctx->fops_lock); + 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 = container_of(fp->private_data, + struct se_if_device_ctx, + miscdev); + struct se_if_priv *se_if_priv = dev_ctx->priv; + int err = -EINVAL; + + /* Prevent race during change of device context */ + if (down_interruptible(&dev_ctx->fops_lock)) + return -EBUSY; + + switch (cmd) { + case SE_IOCTL_ENABLE_CMD_RCV: + if (!se_if_priv->cmd_receiver_dev) { + se_if_priv->cmd_receiver_dev = dev_ctx; + err = 0; + } + 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; + + default: + err = -EINVAL; + dev_dbg(se_if_priv->dev, + "%s: IOCTL %.8x not supported\n", + dev_ctx->miscdev.name, + cmd); + } + + up(&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 unregister a character device */ +static void if_misc_deregister(void *miscdevice) +{ + misc_deregister(miscdevice); +} + /* interface for managed res to free a mailbox channel */ static void if_mbox_free_channel(void *mbox_chan) { @@ -270,6 +855,7 @@ static int se_probe_if_cleanup(struct platform_device *pdev) struct device *dev = &pdev->dev; struct se_if_priv *priv; int ret = 0; + int i; priv = dev_get_drvdata(dev); if (!priv) { @@ -294,6 +880,17 @@ static int se_probe_if_cleanup(struct platform_device *pdev) priv->imem.buf = NULL; } + if (priv->ctxs) { + for (i = 0; i < priv->max_dev_ctx; i++) { + if (priv->ctxs[i]) { + devm_remove_action(dev, + if_misc_deregister, + &priv->ctxs[i]->miscdev); + misc_deregister(&priv->ctxs[i]->miscdev); + } + } + } + if (priv->flags & RESERVED_DMA_POOL) { of_reserved_mem_device_release(dev); priv->flags &= (~RESERVED_DMA_POOL); @@ -302,6 +899,84 @@ static int se_probe_if_cleanup(struct platform_device *pdev) return ret; } +static int init_device_context(struct device *dev) +{ + const struct imx_se_node_info *info; + struct se_if_device_ctx *dev_ctx; + struct se_if_priv *priv; + u8 *devname; + int ret = 0; + int i; + + priv = dev_get_drvdata(dev); + + if (!priv) { + ret = -EINVAL; + dev_err(dev, "Invalid SE-MU Priv data"); + return ret; + } + info = priv->info; + + priv->ctxs = devm_kzalloc(dev, sizeof(dev_ctx) * priv->max_dev_ctx, + GFP_KERNEL); + + if (!priv->ctxs) { + ret = -ENOMEM; + return ret; + } + + /* Create users */ + for (i = 0; i < priv->max_dev_ctx; i++) { + dev_ctx = devm_kzalloc(dev, sizeof(*dev_ctx), GFP_KERNEL); + if (!dev_ctx) { + ret = -ENOMEM; + return ret; + } + + dev_ctx->dev = dev; + dev_ctx->status = SE_IF_CTX_FREE; + dev_ctx->priv = priv; + + priv->ctxs[i] = dev_ctx; + + /* Default value invalid for an header. */ + init_waitqueue_head(&dev_ctx->wq); + + INIT_LIST_HEAD(&dev_ctx->pending_out); + INIT_LIST_HEAD(&dev_ctx->pending_in); + sema_init(&dev_ctx->fops_lock, 1); + + devname = devm_kasprintf(dev, GFP_KERNEL, "%s_ch%d", + info->se_name, i); + if (!devname) { + ret = -ENOMEM; + return ret; + } + + dev_ctx->miscdev.name = devname; + dev_ctx->miscdev.minor = MISC_DYNAMIC_MINOR; + dev_ctx->miscdev.fops = &se_if_fops; + dev_ctx->miscdev.parent = dev; + ret = misc_register(&dev_ctx->miscdev); + if (ret) { + dev_err(dev, "failed to register misc device %d\n", + ret); + return ret; + } + + ret = devm_add_action(dev, if_misc_deregister, + &dev_ctx->miscdev); + if (ret) { + dev_err(dev, + "failed[%d] to add action to the misc-dev\n", + ret); + return ret; + } + } + + return ret; +} + static void se_load_firmware(const struct firmware *fw, void *context) { struct se_if_priv *priv = (struct se_if_priv *) context; @@ -461,6 +1136,16 @@ static int se_if_probe(struct platform_device *pdev) } } + if (info->max_dev_ctx) { + ret = init_device_context(dev); + if (ret) { + dev_err(dev, + "Failed[0x%x] to create device contexts.\n", + ret); + goto exit; + } + } + dev_info(dev, "i.MX secure-enclave: %s interface to firmware, configured.\n", info->se_name); return devm_of_platform_populate(dev); @@ -502,6 +1187,10 @@ static int se_resume(struct device *dev) struct se_if_priv *priv = dev_get_drvdata(dev); const struct imx_se_node_info *info = priv->info; + int i; + + for (i = 0; i < priv->max_dev_ctx; i++) + wake_up_interruptible(&priv->ctxs[i]->wq); if (info && info->imem_mgmt) se_restore_imem_state(dev); diff --git a/drivers/firmware/imx/se_ctrl.h b/drivers/firmware/imx/se_ctrl.h index 7d4f439a6158..41d9cedb05d7 100644 --- a/drivers/firmware/imx/se_ctrl.h +++ b/drivers/firmware/imx/se_ctrl.h @@ -13,15 +13,61 @@ #define MAX_FW_LOAD_RETRIES 50 #define RES_STATUS(x) FIELD_GET(0x000000ff, x) +#define MAX_DATA_SIZE_PER_USER (65 * 1024) #define MESSAGING_VERSION_6 0x6 #define MESSAGING_VERSION_7 0x7 +#define SE_MU_IO_FLAGS_USE_SEC_MEM (0x02u) +#define SE_MU_IO_FLAGS_USE_SHORT_ADDR (0x04u) + struct se_imem_buf { u8 *buf; phys_addr_t phyaddr; u32 size; }; +struct se_buf_desc { + u8 *shared_buf_ptr; + u8 *usr_buf_ptr; + u32 size; + struct list_head link; +}; + +/* Status of a char device */ +enum se_if_dev_ctx_status_t { + SE_IF_CTX_FREE, + SE_IF_CTX_OPENED +}; + +struct se_shared_mem { + dma_addr_t dma_addr; + u32 size; + u32 pos; + u8 *ptr; +}; + +/* Private struct for each char device instance. */ +struct se_if_device_ctx { + struct device *dev; + struct se_if_priv *priv; + struct miscdevice miscdev; + + enum se_if_dev_ctx_status_t status; + wait_queue_head_t wq; + struct semaphore fops_lock; + + u32 pending_hdr; + struct list_head pending_in; + struct list_head pending_out; + + struct se_shared_mem secure_mem; + struct se_shared_mem non_secure_mem; + + u32 *temp_resp; + u32 temp_resp_size; + struct notifier_block se_notify; +}; + /* Header of the messages exchange with the EdgeLock Enclave */ struct se_msg_hdr { u8 ver; diff --git a/include/uapi/linux/se_ioctl.h b/include/uapi/linux/se_ioctl.h new file mode 100644 index 000000000000..f68a36e9da2c --- /dev/null +++ b/include/uapi/linux/se_ioctl.h @@ -0,0 +1,88 @@ +/* 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 { + u8 *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_signed_message { + u8 *message; + u32 msg_size; + u32 error_code; +}; + +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) + +#endif