Skip to contentSkip to conversation

soc: imx-scu: Add SoC UID(unique identifier) support

PATCH Superseded [email protected] 3 participants 5 messages Jun 28, 2019 – Jul 2, 2019 Arm i.MX and Layerscape

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 soc: imx-scu: Add SoC UID(unique identifier) support

From: Anson Huang <[email protected]>

Add i.MX SCU SoC's UID(unique identifier) support, user can read it from sysfs:

root@imx8qxpmek:~# cat /sys/devices/soc0/soc_uid
7B64280B57AC1898

---
Changes since V1:
- Improve the comment of skipping SCFW API return value check for getting UID.

---
 drivers/soc/imx/soc-imx-scu.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/soc/imx/soc-imx-scu.c +39 -0
index 676f612..3eacb54 100644
@@ -27,6 +27,40 @@ struct imx_sc_msg_misc_get_soc_id {
 	} data;
 } __packed;
 
+struct imx_sc_msg_misc_get_soc_uid {
+	struct imx_sc_rpc_msg hdr;
+	u32 uid_low;
+	u32 uid_high;
+} __packed;
+
+static ssize_t soc_uid_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct imx_sc_msg_misc_get_soc_uid msg;
+	struct imx_sc_rpc_msg *hdr = &msg.hdr;
+	u64 soc_uid;
+
+	hdr->ver = IMX_SC_RPC_VERSION;
+	hdr->svc = IMX_SC_RPC_SVC_MISC;
+	hdr->func = IMX_SC_MISC_FUNC_UNIQUE_ID;
+	hdr->size = 1;
+
+	/*
+	 * SCU FW API always returns an error even the
+	 * function is successfully executed, so skip
+	 * returned value check.
+	 */
+	imx_scu_call_rpc(soc_ipc_handle, &msg, true);
+
+	soc_uid = msg.uid_high;
+	soc_uid <<= 32;
+	soc_uid |= msg.uid_low;
+
+	return sprintf(buf, "%016llX\n", soc_uid);
+}
+
+static DEVICE_ATTR_RO(soc_uid);
+
 static int imx_scu_soc_id(void)
 {
 	struct imx_sc_msg_misc_get_soc_id msg;
@@ -102,6 +136,11 @@ static int imx_scu_soc_probe(struct platform_device *pdev)
 		goto free_revision;
 	}
 
+	ret = device_create_file(soc_device_to_device(soc_dev),
+				 &dev_attr_soc_uid);
+	if (ret)
+		goto free_revision;
+
 	return 0;
 
 free_revision:
Signature · 1 line
2.7.4
#2 lore raw
In reply to [email protected]

Hi Anson,

Quoted 38 lines · On 19-06-28 11:25, [email protected] wrote:

From: Anson Huang <[email protected]>

Add i.MX SCU SoC's UID(unique identifier) support, user can read it from sysfs:

root@imx8qxpmek:~# cat /sys/devices/soc0/soc_uid
7B64280B57AC1898

---
Changes since V1:
- Improve the comment of skipping SCFW API return value check for getting UID.

---
 drivers/soc/imx/soc-imx-scu.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/soc/imx/soc-imx-scu.c +14 -0
index 676f612..3eacb54 100644
@@ -27,6 +27,40 @@ struct imx_sc_msg_misc_get_soc_id {
 	} data;
 } __packed;
 
+struct imx_sc_msg_misc_get_soc_uid {
+	struct imx_sc_rpc_msg hdr;
+	u32 uid_low;
+	u32 uid_high;
+} __packed;
+
+static ssize_t soc_uid_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct imx_sc_msg_misc_get_soc_uid msg;
+	struct imx_sc_rpc_msg *hdr = &msg.hdr;
+	u64 soc_uid;
+
+	hdr->ver = IMX_SC_RPC_VERSION;

drivers/soc/imx/soc-imx-scu.c struct imx_sc_msg_misc_get_soc_id { · line 53

Quoted 10 lines
drivers/soc/imx/soc-imx-scu.c +10 -0
+	hdr->svc = IMX_SC_RPC_SVC_MISC;
+	hdr->func = IMX_SC_MISC_FUNC_UNIQUE_ID;
+	hdr->size = 1;
+
+	/*
+	 * SCU FW API always returns an error even the
+	 * function is successfully executed, so skip
+	 * returned value check.
+	 */
+	imx_scu_call_rpc(soc_ipc_handle, &msg, true);

Please can you add a TODO: or FIXME: tag and also provide the firmware version containing the bug? I know that developers are very busy and follow-up fixes never reach mainline ;)

Regards,
Marco

Quoted 30 lines
drivers/soc/imx/soc-imx-scu.c +15 -0
+
+	soc_uid = msg.uid_high;
+	soc_uid <<= 32;
+	soc_uid |= msg.uid_low;
+
+	return sprintf(buf, "%016llX\n", soc_uid);
+}
+
+static DEVICE_ATTR_RO(soc_uid);
+
 static int imx_scu_soc_id(void)
 {
 	struct imx_sc_msg_misc_get_soc_id msg;
@@ -102,6 +136,11 @@ static int imx_scu_soc_probe(struct platform_device *pdev)
 		goto free_revision;
 	}
 
+	ret = device_create_file(soc_device_to_device(soc_dev),
+				 &dev_attr_soc_uid);
+	if (ret)
+		goto free_revision;
+
 	return 0;
 
 free_revision:
Signature · 1 line
2.7.4
Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#3 lore raw

Hi, Marco

Quoted 7 lines
Quoted 7 lines
drivers/soc/imx/soc-imx-scu.c +7 -0
+	hdr->ver = IMX_SC_RPC_VERSION;
+	hdr->svc = IMX_SC_RPC_SVC_MISC;
+	hdr->func = IMX_SC_MISC_FUNC_UNIQUE_ID;
+	hdr->size = 1;
+
+	/*
+	 * SCU FW API always returns an error even the
Quoted 8 lines

drivers/soc/imx/soc-imx-scu.c struct imx_sc_msg_misc_get_soc_id { · line 53

Quoted 4 lines
drivers/soc/imx/soc-imx-scu.c +4 -0
+	 * function is successfully executed, so skip
+	 * returned value check.
+	 */
+	imx_scu_call_rpc(soc_ipc_handle, &msg, true);

Please can you add a TODO: or FIXME: tag and also provide the firmware version containing the bug? I know that developers are very busy and follow- up fixes never reach mainline ;)

As I replied in previous mail, I will send out a V3 with below comment:

+ /*

+        * SCU FW API does NOT have returned value for
+        * this function, so skip returned value check.
+        */

+ imx_scu_call_rpc(soc_ipc_handle, &msg, true);

Thanks,
Anson.

Quoted 3 lines

Regards,
Marco

#4 lore raw

Hi, Marco

Quoted 24 lines
Quoted 7 lines
Quoted 7 lines
drivers/soc/imx/soc-imx-scu.c +7 -0
+	hdr->ver = IMX_SC_RPC_VERSION;
+	hdr->svc = IMX_SC_RPC_SVC_MISC;
+	hdr->func = IMX_SC_MISC_FUNC_UNIQUE_ID;
+	hdr->size = 1;
+
+	/*
+	 * SCU FW API always returns an error even the
Quoted 8 lines

drivers/soc/imx/soc-imx-scu.c struct imx_sc_msg_misc_get_soc_id { · line 53

Quoted 4 lines
drivers/soc/imx/soc-imx-scu.c +4 -0
+	 * function is successfully executed, so skip
+	 * returned value check.
+	 */
+	imx_scu_call_rpc(soc_ipc_handle, &msg, true);

Please can you add a TODO: or FIXME: tag and also provide the firmware version containing the bug? I know that developers are very busy and follow- up fixes never reach mainline ;)

As I replied in previous mail, I will send out a V3 with below comment:

drivers/soc/imx/soc-imx-scu.c +5 -0
+       /*
+        * SCU FW API does NOT have returned value for
+        * this function, so skip returned value check.
+        */
+       imx_scu_call_rpc(soc_ipc_handle, &msg, true);
Quoted 2 lines

Thanks,
Anson.

Sorry, after further thought, regarding for SCU API without response, we should pass the "false" as imx_scu_call_rpc()'s 3rd parameter, so I will remove the comment and use below in V3:

+ ret = imx_scu_call_rpc(soc_ipc_handle, &msg, false);
+ if (ret) {
+ pr_err("%s: get soc uid failed, ret %d\n", __func__, ret);
+ return ret;
+ }

Thanks,
Anson