lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250423-uid-128-v2-2-327c30fe59a9@nxp.com>
Date: Wed, 23 Apr 2025 22:37:05 +0800
From: "Peng Fan (OSS)" <peng.fan@....nxp.com>
To: Shawn Guo <shawnguo@...nel.org>, Sascha Hauer <s.hauer@...gutronix.de>, 
 Pengutronix Kernel Team <kernel@...gutronix.de>, 
 Fabio Estevam <festevam@...il.com>, Marco Felsch <m.felsch@...gutronix.de>
Cc: imx@...ts.linux.dev, linux-arm-kernel@...ts.infradead.org, 
 linux-kernel@...r.kernel.org, Peng Fan <peng.fan@....com>
Subject: [PATCH v2 2/3] soc: imx8m: Introduce soc_uid hook

From: Peng Fan <peng.fan@....com>

Cleanup code by introducing soc_uid hook, i.MX8MQ/M/N could reuse
one function imx8m_soc_uid, i.MX8MP could have its own one.

With this patch, it will easy to add 128bits UID support for i.MX8MP.

Signed-off-by: Peng Fan <peng.fan@....com>
---
 drivers/soc/imx/soc-imx8m.c | 46 +++++++++++++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 14 deletions(-)

diff --git a/drivers/soc/imx/soc-imx8m.c b/drivers/soc/imx/soc-imx8m.c
index c4879947dd2d6573854bce86b86a97159c19a875..2186f6ab3eddd6c9369c691c845b3b78acaabe23 100644
--- a/drivers/soc/imx/soc-imx8m.c
+++ b/drivers/soc/imx/soc-imx8m.c
@@ -31,7 +31,8 @@
 struct imx8_soc_data {
 	char *name;
 	const char *ocotp_compatible;
-	int (*soc_revision)(struct platform_device *pdev, u32 *socrev, u64 *socuid);
+	int (*soc_revision)(struct platform_device *pdev, u32 *socrev);
+	int (*soc_uid)(struct platform_device *pdev, u64 *socuid);
 };
 
 struct imx8_soc_drvdata {
@@ -55,7 +56,19 @@ static u32 imx8mq_soc_revision_from_atf(void)
 static inline u32 imx8mq_soc_revision_from_atf(void) { return 0; };
 #endif
 
-static int imx8mq_soc_revision(struct platform_device *pdev, u32 *socrev, u64 *socuid)
+static int imx8m_soc_uid(struct platform_device *pdev, u64 *socuid)
+{
+	struct imx8_soc_drvdata *drvdata = platform_get_drvdata(pdev);
+	void __iomem *ocotp_base = drvdata->ocotp_base;
+
+	*socuid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH);
+	*socuid <<= 32;
+	*socuid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW);
+
+	return 0;
+}
+
+static int imx8mq_soc_revision(struct platform_device *pdev, u32 *socrev)
 {
 	struct imx8_soc_drvdata *drvdata = platform_get_drvdata(pdev);
 	void __iomem *ocotp_base = drvdata->ocotp_base;
@@ -73,30 +86,24 @@ static int imx8mq_soc_revision(struct platform_device *pdev, u32 *socrev, u64 *s
 			rev = REV_B1;
 	}
 
-	*socuid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH);
-	*socuid <<= 32;
-	*socuid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW);
-
 	*socrev = rev;
 
 	return 0;
 }
 
-static int imx8mm_soc_uid(struct platform_device *pdev, u64 *socuid)
+static int imx8mp_soc_uid(struct platform_device *pdev, u64 *socuid)
 {
 	struct imx8_soc_drvdata *drvdata = platform_get_drvdata(pdev);
 	void __iomem *ocotp_base = drvdata->ocotp_base;
-	u32 offset = of_machine_is_compatible("fsl,imx8mp") ?
-		     IMX8MP_OCOTP_UID_OFFSET : 0;
 
-	*socuid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH + offset);
+	*socuid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH + IMX8MP_OCOTP_UID_OFFSET);
 	*socuid <<= 32;
-	*socuid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW + offset);
+	*socuid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW + IMX8MP_OCOTP_UID_OFFSET);
 
 	return 0;
 }
 
-static int imx8mm_soc_revision(struct platform_device *pdev, u32 *socrev, u64 *socuid)
+static int imx8mm_soc_revision(struct platform_device *pdev, u32 *socrev)
 {
 	struct device_node *np __free(device_node) =
 		of_find_compatible_node(NULL, NULL, "fsl,imx8mm-anatop");
@@ -113,7 +120,7 @@ static int imx8mm_soc_revision(struct platform_device *pdev, u32 *socrev, u64 *s
 
 	iounmap(anatop_base);
 
-	return imx8mm_soc_uid(pdev, socuid);
+	return 0;
 }
 
 static int imx8m_soc_prepare(struct platform_device *pdev, const char *ocotp_compatible)
@@ -156,24 +163,28 @@ static const struct imx8_soc_data imx8mq_soc_data = {
 	.name = "i.MX8MQ",
 	.ocotp_compatible = "fsl,imx8mq-ocotp",
 	.soc_revision = imx8mq_soc_revision,
+	.soc_uid = imx8m_soc_uid,
 };
 
 static const struct imx8_soc_data imx8mm_soc_data = {
 	.name = "i.MX8MM",
 	.ocotp_compatible = "fsl,imx8mm-ocotp",
 	.soc_revision = imx8mm_soc_revision,
+	.soc_uid = imx8m_soc_uid,
 };
 
 static const struct imx8_soc_data imx8mn_soc_data = {
 	.name = "i.MX8MN",
 	.ocotp_compatible = "fsl,imx8mm-ocotp",
 	.soc_revision = imx8mm_soc_revision,
+	.soc_uid = imx8m_soc_uid,
 };
 
 static const struct imx8_soc_data imx8mp_soc_data = {
 	.name = "i.MX8MP",
 	.ocotp_compatible = "fsl,imx8mm-ocotp",
 	.soc_revision = imx8mm_soc_revision,
+	.soc_uid = imx8mp_soc_uid,
 };
 
 static __maybe_unused const struct of_device_id imx8_soc_match[] = {
@@ -240,7 +251,14 @@ static int imx8m_soc_probe(struct platform_device *pdev)
 			return ret;
 
 		if (data->soc_revision) {
-			ret = data->soc_revision(pdev, &soc_rev, &soc_uid);
+			ret = data->soc_revision(pdev, &soc_rev);
+			if (ret) {
+				imx8m_soc_unprepare(pdev);
+				return ret;
+			}
+		}
+		if (data->soc_uid) {
+			ret = data->soc_uid(pdev, &soc_uid);
 			if (ret) {
 				imx8m_soc_unprepare(pdev);
 				return ret;

-- 
2.37.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ