Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp448344lqb; Fri, 24 May 2024 03:35:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVOnOG01I8ru4Cspa7PkZQdmxl26wUlrDC3aEAuWssWAtAU85VwEl6q+EJHs5lZA5s25m85RrV65YVVHE8UTd+KDILWlMs8OmS3J3uWFA== X-Google-Smtp-Source: AGHT+IH+uNszwmCp3/gXZaB83iapPuxbwD71mHqiKw+OYTvGHWQ+ogPam8F49SOsRtiWehmGgLrb X-Received: by 2002:a17:90a:9c3:b0:2b9:ab0b:c5b with SMTP id 98e67ed59e1d1-2bf5e18b3e8mr1631458a91.17.1716546941322; Fri, 24 May 2024 03:35:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716546941; cv=pass; d=google.com; s=arc-20160816; b=jZezIFhTFbIZqxocB+NXT36A/a2HVu+aHrNZWy381DO4Q57woIULAjF4unlWHcuHPD PpExC6s154TQQbsj+MRWEbzrSUeiLamHCiFm8HF+qH+r/2Y/Zz2sVHXkufGd3FSdOU+a lPqB+k83NF7zKh5Ebw0yl+Ltkv+xLpREK48lMFhO+3cVUzcmF9audHa2k9VoJdlGCLvL 7ZEkXzY9EgGm27XQSQxxJCViC5nZv7YSkpuYrkzUggGETH/Hqegu4WVbGo9CDwlhIuu+ mqDc/wTvXFmN/EGBIlEy+h3rwR2BmTLUaZmABuUmyjeZ4QOfW3/S0y5qQY0Au/3rkD+Z eB3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=BSpQ9x8DOtXuXfXD3rKmasZVM2xrAoNmu2LCYB0WK4U=; fh=Jh0TN2Q1fP1HXHrZHIV/kVcJxEaV1dt0AqJ6p+68Pjk=; b=KVoei2/RJJQdvG+4qkGSaORvLxnC52kh4folAQnKg8Ud3xPpj2+QnDElNp6Y7+aqEi J+KKM2Qa5sr0fzZp/fMJg+FmyjmysIy8Tu+geTgIKLP6IU/ZrgWzkERGdD6vvoLDKV6h rkri+uLNXAlqmfM9aPrg03QEG+MbdoJ8x4k2gjEfAhJZclbN4T24HffV70fTCPplZpAY jl+qdvwkfmLNvF+Qi3qrhfMa3+82DJGBjdn6lYD548UOHLmGUBJ4UoWbOyFHMILx/NxH MZkODMZuAKUI8dIhLDluU8PktDVy8+OgtkgRgDGNyu03fD1ib8RalAazZLnUTSUxjzTM cdCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-188611-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188611-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2bf5fe34769si1169342a91.96.2024.05.24.03.35.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 03:35:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188611-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-188611-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188611-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A3D23282505 for ; Fri, 24 May 2024 10:35:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E33ED85958; Fri, 24 May 2024 10:34:48 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B95985940 for ; Fri, 24 May 2024 10:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716546888; cv=none; b=Buae1LmBBCPScrATkPZt0adqCJWnsC2mr7BYa1H7TzRklq8HTGQ/MViOkXqcHLOmzUznusIQ5oiS2+XORXQ4IMLB2jIWKLP/VNww82LeGQoL78juA7loxpNPtqeDm+IiAH9/1+tzxEDQPEdbJbCWRYNDgGHnjA+/tm1p2YSKKU8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716546888; c=relaxed/simple; bh=qg+hQa3sjCvK1rsMinmlMmvRSQldE+iztqZn3l16GXQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=U3vPPjpNerpyfbn+02NFeWPEu7tmS6wPApVRgPaCMrYNf3a3JLec1wPJSdTP8RU7gcQBJIoR2PDGfKKt+km1xLZFP+swKSD+2NoUBuXb0HxjiKVU2cR5yH0tJ9ezh1IXtFOf5uiwMp12QMp4S6E//w4z6zn+r6jGwDyNvkUsoMM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sASFq-0008L1-7k; Fri, 24 May 2024 12:34:30 +0200 Received: from [2a0a:edc0:2:b01:1d::c5] (helo=pty.whiteo.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sASFp-002mYJ-9k; Fri, 24 May 2024 12:34:29 +0200 Received: from sha by pty.whiteo.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1sASFp-00Bdvd-0d; Fri, 24 May 2024 12:34:29 +0200 Date: Fri, 24 May 2024 12:34:29 +0200 From: Sascha Hauer To: Pankaj Gupta Cc: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Pengutronix Kernel Team , Fabio Estevam , Rob Herring , Krzysztof Kozlowski , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2 4/5] firmware: imx: add driver for NXP EdgeLock Enclave Message-ID: References: <20240523-imx-se-if-v2-0-5a6fd189a539@nxp.com> <20240523-imx-se-if-v2-4-5a6fd189a539@nxp.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240523-imx-se-if-v2-4-5a6fd189a539@nxp.com> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org On Thu, May 23, 2024 at 04:19:35PM +0530, Pankaj Gupta wrote: > 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(+) > > +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); You can call this unconditionally, no need to keep track if you called of_reserved_mem_device_init() successfully. > + > +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; > + } Can't this be optional? Why do you need to reserve memory in the device tree for it? Sascha -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |