From mboxrd@z Thu Jan 1 00:00:00 1970 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 ABF27C3DA6F for ; Thu, 24 Aug 2023 18:37:39 +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:In-Reply-To:From:References:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Np35qZaaS0Ui1iD6VtoI4KHJ1Ws0ak7zwcYIDK79LF4=; b=g3Qxh1d8n8b8Nk pjG/6u9lfaLs2PVD7sjqOvE4q5vZoxNg4TODTvzwBBGOBxPZy2Gs1jOzjIflpn17G3GWUEFJ5e1AJ 1Iypte/mCluLbR+LVmpwJPSpms9IiTlz+ewz0X9MEEVpGRp4Fwmzh2lsIotQ0E32sfeTGALp23Hbg uqIgnTixeXaiwDhlMIuaihu2JZ3/KjpI3awMYIT1GjIuepP4B3T19qko0EmkJfN9JN+J2o4UiyuwO mraiOb5OUUVjlZfVCklTRHgXTyYLI0syxx4igX3u3T9aQvzofKjDnKa/2UQ5XXutAwx8pT+/CwKu1 QnO3qxyMbzPhXZ+K7XIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZFCg-003bqj-2g; Thu, 24 Aug 2023 18:37:10 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZFCd-003bpz-0k for linux-arm-kernel@lists.infradead.org; Thu, 24 Aug 2023 18:37:09 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-51a52a7d859so2527693a12.0 for ; Thu, 24 Aug 2023 11:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692902223; x=1693507023; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=zvkwv2oqTP+pO4hYA4rG3ApU1P4yvVukZ5H0zf1EQAk=; b=cA7+UHVVECJqrEE6p/VJbSOVeYpIYp/36VZMxoyg6KWGWNmGA+KGFC13OC5EvJU3ib t04RKuHyl2uH08pv+mR1Jg3WejFg0hcPL3n+eix5+gWC6p6/fGBHT6bwUvy2Ill2lMWo 6X/gdaLNCDWxwjN7VzeHbffd6yQYd6D/sKs24xITfEpB0Mj47e+Orizs35wLrXeZ0vnQ JO+2+ZfivJGKFlKkiWj1qdqWfRzonaDgPqoO45pg7/IKrYqQKVZfxW7Qb+nqxUFsQWpl Unwfsz6SyxpjgCZRZjHmFC+y9pdxE/pF3iDJ3nxewpNsyz+TR+bd9hwwIvzA7wmQEz7h HuTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692902223; x=1693507023; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zvkwv2oqTP+pO4hYA4rG3ApU1P4yvVukZ5H0zf1EQAk=; b=YySBwcRP1V1LSltDzf0RHcnyuBge120zJVBhlz3YyjgeloT/UFCZLqfqS/XV7zClCh lbyYjukIUfxkugLyw2A8A+JXJB2UPcZKdYYN2EmQ+ugvsogkUG5RjfS2ggP4J6yhjb1D vN2lzkr3rB7GlDvNqo5uaqQnKzes5Dg2dn4/DuM4tf6GVzKBuC+tTBo3qc7Ie0dZkETS kz4rdp7Nzz8O0p3CxdYMtrIdaQc8TuhcbLWCsBLav9aFUWFMz7Uq0tCAVX0pyNpNz3Dk tk6nqCdJcZ6l4fZviukRWNdTRJOkJ3cSwmZ98LfIA0mMP2PdqZ2dhvyFT4UAHGXf0WxU WAvQ== X-Gm-Message-State: AOJu0Yx5I2biXNakmOFZ3/HKiIZdRprNVybT+tSofAedYAt3a4pcCFzf Fpol364AmLRKZn5nlvzUCSlDkg== X-Google-Smtp-Source: AGHT+IFH0SjCZSGrn7Os/RP0/GeyRTvMpzBP69ReY9cPwGMFt6KWOEV/ME/DCBYhsKqHrUz2iRxPKg== X-Received: by 2002:aa7:d502:0:b0:525:b29d:8dc8 with SMTP id y2-20020aa7d502000000b00525b29d8dc8mr20912857edq.5.1692902223431; Thu, 24 Aug 2023 11:37:03 -0700 (PDT) Received: from [192.168.0.22] ([77.252.47.198]) by smtp.gmail.com with ESMTPSA id f15-20020aa7d84f000000b0052228721f84sm44909eds.77.2023.08.24.11.37.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Aug 2023 11:37:03 -0700 (PDT) Message-ID: <41581c90-3ee0-c969-2b54-ee512d637788@linaro.org> Date: Thu, 24 Aug 2023 20:37:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH v5 09/11] firmware: imx: enclave-fw: add handling for save/restore IMEM region Content-Language: en-US To: Pankaj Gupta , shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, clin@suse.com, conor+dt@kernel.org, pierre.gondois@arm.com, ping.bai@nxp.com, xiaoning.wang@nxp.com, wei.fang@nxp.com, peng.fan@nxp.com, haibo.chen@nxp.com, festevam@gmail.com, linux-imx@nxp.com, davem@davemloft.net, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, gaurav.jain@nxp.com, alexander.stein@ew.tq-group.com, sahil.malhotra@nxp.com, aisheng.dong@nxp.com, V.Sethi@nxp.com References: <20230823073330.1712721-1-pankaj.gupta@nxp.com> <20230823073330.1712721-10-pankaj.gupta@nxp.com> From: Krzysztof Kozlowski In-Reply-To: <20230823073330.1712721-10-pankaj.gupta@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_113707_293078_AC8B8AB9 X-CRM114-Status: GOOD ( 21.93 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 23/08/2023 09:33, Pankaj Gupta wrote: > Some IMEM region is lost during kernel power down. Due to this, > firmware's functionaity cannot work correctly. > > Saving encrypted IMEM region in kernel memory during power down, > and restore IMEM region on resume. > > Signed-off-by: Gaurav Jain > Signed-off-by: Pankaj Gupta > @@ -959,6 +962,17 @@ static int se_probe_cleanup(struct platform_device *pdev) > priv->flags &= (~RESERVED_DMA_POOL); > } > > + /* free the buffer in ele-mu remove, previously allocated > + * in ele-mu probe to store encrypted IMEM > + */ Use Linux coding style comments. > + if (priv->imem.buf) { > + dmam_free_coherent(&pdev->dev, > + ELE_IMEM_SIZE, > + priv->imem.buf, > + priv->imem.phyaddr); > + priv->imem.buf = NULL; > + } > + > if (priv->ctxs) { > for (i = 0; i < priv->max_dev_ctx; i++) { > if (priv->ctxs[i]) > @@ -1160,6 +1174,19 @@ static int se_fw_probe(struct platform_device *pdev) > dev_err(dev, "Failed to init ele-trng\n"); > } > > + if (info->imem_mgmt) { > + /* allocate buffer where ELE 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; > + } > + } > + > pr_info("i.MX secure-enclave: %s's mu#%d interface to firmware, configured.\n", > info->se_name, > priv->ele_mu_id); > @@ -1196,17 +1223,31 @@ static int se_fw_remove(struct platform_device *pdev) > #ifdef CONFIG_PM_SLEEP > static int se_fw_suspend(struct device *dev) > { > + struct ele_mu_priv *priv = dev_get_drvdata(dev); > + const struct of_device_id *of_id = of_match_device(se_fw_match, dev); No. > + struct imx_info *info = (of_id != NULL) ? (struct imx_info *)of_id->data > + : NULL; > + > + if (info && info->imem_mgmt) > + priv->imem.size = save_imem(dev); > + > return 0; > } > > static int se_fw_resume(struct device *dev) > { > struct ele_mu_priv *priv = dev_get_drvdata(dev); > + const struct of_device_id *of_id = of_match_device(se_fw_match, dev); Why do you keep matching device every time? Don't. > + struct imx_info *info = (of_id != NULL) ? (struct imx_info *)of_id->data > + : NULL; > int i; > > for (i = 0; i < priv->max_dev_ctx; i++) > wake_up_interruptible(&priv->ctxs[i]->wq); > > + if (info && info->imem_mgmt) > + restore_imem(dev, info->pool_name); > + > return 0; > } > #endif > diff --git a/drivers/firmware/imx/se_fw.h b/drivers/firmware/imx/se_fw.h > index b3502affbc85..acb967f2357c 100644 > --- a/drivers/firmware/imx/se_fw.h > +++ b/drivers/firmware/imx/se_fw.h > @@ -165,4 +165,12 @@ struct ele_mu_priv { > struct ele_imem_buf imem; > }; > > +phys_addr_t get_phy_buf_mem_pool(struct device *dev, > + char *mem_pool_name, > + u32 **buf, > + uint32_t size); > +void free_phybuf_mem_pool(struct device *dev, > + char *mem_pool_name, > + u32 *buf, > + uint32_t size); > #endif > diff --git a/include/linux/firmware/imx/ele_base_msg.h b/include/linux/firmware/imx/ele_base_msg.h > index 8a5c385210fc..6fbea7a8d7c9 100644 > --- a/include/linux/firmware/imx/ele_base_msg.h > +++ b/include/linux/firmware/imx/ele_base_msg.h > @@ -37,12 +37,23 @@ > #define ELE_GET_TRNG_STATE_RETRY_COUNT 0x5 > #define CSAL_TRNG_STATE_MASK 0x0000ffff > > +#define ELE_SERVICE_SWAP_REQ 0xDF > +#define ELE_SERVICE_SWAP_REQ_MSG_SZ 0x03 > +#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_BASE_API_VERSION 0x6 > -#define ELE_SUCCESS_IND 0xD6 > -#define ELE_FAILURE_IND 0x29 No, you just added them. Don't add wrong code to remove it in next patch. Best regards, Krzysztof _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel