Skip to contentSkip to conversation

platform/x86/amd: pmc: Add sysfs files for SMU

PATCH In review Mario Limonciello 2 participants 2 messages Sep 14, 2022 – Sep 19, 2022 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 platform/x86/amd: pmc: Add sysfs files for SMU

The CPU/APU SMU FW version and program is currently discoverable by turning on dynamic debugging or examining debugfs for the amdgpu driver. To make this more discoverable, create a dedicated sysfs file for it that userspace can parse without debugging enabled.

---
v1->v2:
* Feedback from Barnabás Pőcze
- Fix documentation EOF missing newline
- Use ATTRIBUTE_GROUPS macro
- Add missing NULL at end of attr

 Documentation/ABI/testing/sysfs-amd-pmc | 14 +++++++++
 drivers/platform/x86/amd/pmc.c          | 39 +++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-amd-pmc
Documentation/ABI/testing/sysfs-amd-pmc new file +14 -0
new file mode 100644
index 000000000000..5d71c2298f5b
@@ -0,0 +1,14 @@
+What:		/sys/bus/platform/drivers/amd_pmc/*/smu_fw_version
+Date:		October 2022
+Contact:	Mario Limonciello <[email protected]>
+Description:	Reading this file reports the version of the firmware loaded to
+		System Management Unit (SMU) contained in AMD CPUs and
+		APUs.
+
+What:		/sys/bus/platform/drivers/amd_pmc/*/smu_program
+Date:		October 2022
+Contact:	Mario Limonciello <[email protected]>
+Description:	Reading this file reports the program corresponding to the SMU
+		firmware version.  The program field is used to disambiguate two
+		APU/CPU models that can share the same firmware binary.
+
drivers/platform/x86/amd/pmc.c +39 -0
index 700eb19e8450..6373c1bce649 100644
@@ -455,6 +455,44 @@ static int amd_pmc_get_smu_version(struct amd_pmc_dev *dev)
 	return 0;
 }
 
+static ssize_t smu_fw_version_show(struct device *d, struct device_attribute *attr,
+				   char *buf)
+{
+	struct amd_pmc_dev *dev = dev_get_drvdata(d);
+
+	if (!dev->major) {
+		int rc = amd_pmc_get_smu_version(dev);
+
+		if (rc)
+			return rc;
+	}
+	return sysfs_emit(buf, "%u.%u.%u\n", dev->major, dev->minor, dev->rev);
+}
+
+static ssize_t smu_program_show(struct device *d, struct device_attribute *attr,
+				   char *buf)
+{
+	struct amd_pmc_dev *dev = dev_get_drvdata(d);
+
+	if (!dev->major) {
+		int rc = amd_pmc_get_smu_version(dev);
+
+		if (rc)
+			return rc;
+	}
+	return sysfs_emit(buf, "%u\n", dev->smu_program);
+}
+
+static DEVICE_ATTR_RO(smu_fw_version);
+static DEVICE_ATTR_RO(smu_program);
+
+static struct attribute *pmc_attrs[] = {
+	&dev_attr_smu_fw_version.attr,
+	&dev_attr_smu_program.attr,
+	NULL,
+};
+ATTRIBUTE_GROUPS(pmc);
+
 static int amd_pmc_idlemask_show(struct seq_file *s, void *unused)
 {
 	struct amd_pmc_dev *dev = s->private;
@@ -935,6 +973,7 @@ static struct platform_driver amd_pmc_driver = {
 	.driver = {
 		.name = "amd_pmc",
 		.acpi_match_table = amd_pmc_acpi_ids,
+		.dev_groups = pmc_groups,
 	},
 	.probe = amd_pmc_probe,
 	.remove = amd_pmc_remove,
Signature · 1 line
2.34.1
#1 lore raw

Hi,

Quoted 6 lines · Mario Limonciello

The CPU/APU SMU FW version and program is currently discoverable by turning on dynamic debugging or examining debugfs for the amdgpu driver. To make this more discoverable, create a dedicated sysfs file for it that userspace can parse without debugging enabled.

Thank you for your patch, I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.

Regards,

Hans

Quoted 89 lines

---
v1->v2:
* Feedback from Barnabás Pőcze
- Fix documentation EOF missing newline
- Use ATTRIBUTE_GROUPS macro
- Add missing NULL at end of attr

 Documentation/ABI/testing/sysfs-amd-pmc | 14 +++++++++
 drivers/platform/x86/amd/pmc.c          | 39 +++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-amd-pmc
Documentation/ABI/testing/sysfs-amd-pmc new file +14 -0
new file mode 100644
index 000000000000..5d71c2298f5b
@@ -0,0 +1,14 @@
+What:		/sys/bus/platform/drivers/amd_pmc/*/smu_fw_version
+Date:		October 2022
+Contact:	Mario Limonciello <[email protected]>
+Description:	Reading this file reports the version of the firmware loaded to
+		System Management Unit (SMU) contained in AMD CPUs and
+		APUs.
+
+What:		/sys/bus/platform/drivers/amd_pmc/*/smu_program
+Date:		October 2022
+Contact:	Mario Limonciello <[email protected]>
+Description:	Reading this file reports the program corresponding to the SMU
+		firmware version.  The program field is used to disambiguate two
+		APU/CPU models that can share the same firmware binary.
+
drivers/platform/x86/amd/pmc.c +39 -0
index 700eb19e8450..6373c1bce649 100644
@@ -455,6 +455,44 @@ static int amd_pmc_get_smu_version(struct amd_pmc_dev *dev)
 	return 0;
 }
 
+static ssize_t smu_fw_version_show(struct device *d, struct device_attribute *attr,
+				   char *buf)
+{
+	struct amd_pmc_dev *dev = dev_get_drvdata(d);
+
+	if (!dev->major) {
+		int rc = amd_pmc_get_smu_version(dev);
+
+		if (rc)
+			return rc;
+	}
+	return sysfs_emit(buf, "%u.%u.%u\n", dev->major, dev->minor, dev->rev);
+}
+
+static ssize_t smu_program_show(struct device *d, struct device_attribute *attr,
+				   char *buf)
+{
+	struct amd_pmc_dev *dev = dev_get_drvdata(d);
+
+	if (!dev->major) {
+		int rc = amd_pmc_get_smu_version(dev);
+
+		if (rc)
+			return rc;
+	}
+	return sysfs_emit(buf, "%u\n", dev->smu_program);
+}
+
+static DEVICE_ATTR_RO(smu_fw_version);
+static DEVICE_ATTR_RO(smu_program);
+
+static struct attribute *pmc_attrs[] = {
+	&dev_attr_smu_fw_version.attr,
+	&dev_attr_smu_program.attr,
+	NULL,
+};
+ATTRIBUTE_GROUPS(pmc);
+
 static int amd_pmc_idlemask_show(struct seq_file *s, void *unused)
 {
 	struct amd_pmc_dev *dev = s->private;
@@ -935,6 +973,7 @@ static struct platform_driver amd_pmc_driver = {
 	.driver = {
 		.name = "amd_pmc",
 		.acpi_match_table = amd_pmc_acpi_ids,
+		.dev_groups = pmc_groups,
 	},
 	.probe = amd_pmc_probe,
 	.remove = amd_pmc_remove,