Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 May 2025 19:21:13 GMT
From:      Ravi Pokala <rpokala@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 2a042fab4f91 - main - amdsmn(4), amdtemp(4): Add support for AMD Family 1Ah (Zen5) CPUs
Message-ID:  <202505101921.54AJLDc5028435@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by rpokala:

URL: https://cgit.FreeBSD.org/src/commit/?id=2a042fab4f91a525daa6255b69892fb434c62831

commit 2a042fab4f91a525daa6255b69892fb434c62831
Author:     Ravi Pokala <rpokala@FreeBSD.org>
AuthorDate: 2025-05-10 06:26:42 +0000
Commit:     Ravi Pokala <rpokala@FreeBSD.org>
CommitDate: 2025-05-10 19:20:37 +0000

    amdsmn(4), amdtemp(4): Add support for AMD Family 1Ah (Zen5) CPUs
    
    I found the '1AH_MxxH_ROOT' PCI device IDs in the Linux "AMD K8
    Northbridge" driver [1][5]. Since Family 19h (Zen3, Zen4) uses the same
    registers as Family 17h (Zen1, Zen2), I tried using those same registers
    for Family 1Ah (Zen5) as well, and they worked.
    
    I pulled the 1Ah model ranges from Linux as well [2][3][4][6].
    
    Added some additional logging under 'bootverbose', and used a local
    variable and macro for the stepping, rather than repeatedly using the
    mask directly.
    
    Consistently report the CPUID (family, model, stepping) using two,
    zero-padded, un-prefixed, uppercase nybbles, with an 'h' suffix. This is
    the format used in documentation and in Linux.
    
    My own testing with various models of Zen4 EPYC 9xx4 ("Genoa") shows
    that their CPUID models are in the range 0x10 .. 0x1f. Similar testing
    with various models of Zen5 EPYC 9xx5 ("Turin") shows that their CPUID
    models are in the range 0x00 ... 0x2f.
    
    [1] 2023-08-10: https://github.com/torvalds/linux/commit/c640166
    [2] 2024-01-23: https://github.com/torvalds/linux/commit/3e4147f
    [3] 2024-01-25: https://github.com/torvalds/linux/commit/b9328fd
    [4] 2024-04-24: https://github.com/torvalds/linux/commit/2718a7f
    [5] 2024-07-28: https://github.com/torvalds/linux/commit/59c3400
    [6] 2024-07-30: https://github.com/torvalds/linux/commit/bf5641e
    
    Sponsored by:   Vdura
    MFC after:      3 days
    Reviewed by:    delphij
    Differential Revision:  https://reviews.freebsd.org/D50278
---
 sys/dev/amdsmn/amdsmn.c   | 26 +++++++++++++++++++++++--
 sys/dev/amdtemp/amdtemp.c | 49 +++++++++++++++++++++++++++++++++--------------
 2 files changed, 59 insertions(+), 16 deletions(-)

diff --git a/sys/dev/amdsmn/amdsmn.c b/sys/dev/amdsmn/amdsmn.c
index 1fc93a68fbf3..803491e9b0f5 100644
--- a/sys/dev/amdsmn/amdsmn.c
+++ b/sys/dev/amdsmn/amdsmn.c
@@ -25,7 +25,7 @@
  */
 
 /*
- * Driver for the AMD Family 15h and 17h CPU System Management Network.
+ * Driver for the AMD Family 15h, 17h, 19h, 1Ah CPU System Management Network.
  */
 
 #include <sys/param.h>
@@ -62,6 +62,10 @@
 #define	PCI_DEVICE_ID_AMD_19H_M40H_ROOT		0x14b5
 #define	PCI_DEVICE_ID_AMD_19H_M60H_ROOT		0x14d8	/* Also F1AH M40H */
 #define	PCI_DEVICE_ID_AMD_19H_M70H_ROOT		0x14e8
+#define	PCI_DEVICE_ID_AMD_1AH_M00H_ROOT		0x153a
+#define	PCI_DEVICE_ID_AMD_1AH_M20H_ROOT		0x1507
+#define	PCI_DEVICE_ID_AMD_1AH_M60H_ROOT		0x1122
+
 
 struct pciid;
 struct amdsmn_softc {
@@ -129,6 +133,24 @@ static const struct pciid {
 		.amdsmn_addr_reg = F17H_SMN_ADDR_REG,
 		.amdsmn_data_reg = F17H_SMN_DATA_REG,
 	},
+	{
+		.amdsmn_vendorid = CPU_VENDOR_AMD,
+		.amdsmn_deviceid = PCI_DEVICE_ID_AMD_1AH_M00H_ROOT,
+		.amdsmn_addr_reg = F17H_SMN_ADDR_REG,
+		.amdsmn_data_reg = F17H_SMN_DATA_REG,
+	},
+	{
+		.amdsmn_vendorid = CPU_VENDOR_AMD,
+		.amdsmn_deviceid = PCI_DEVICE_ID_AMD_1AH_M20H_ROOT,
+		.amdsmn_addr_reg = F17H_SMN_ADDR_REG,
+		.amdsmn_data_reg = F17H_SMN_DATA_REG,
+	},
+	{
+		.amdsmn_vendorid = CPU_VENDOR_AMD,
+		.amdsmn_deviceid = PCI_DEVICE_ID_AMD_1AH_M60H_ROOT,
+		.amdsmn_addr_reg = F17H_SMN_ADDR_REG,
+		.amdsmn_data_reg = F17H_SMN_DATA_REG,
+	},
 };
 
 /*
@@ -216,7 +238,7 @@ amdsmn_probe(device_t dev)
 	default:
 		return (ENXIO);
 	}
-	device_set_descf(dev, "AMD Family %xh System Management Network",
+	device_set_descf(dev, "AMD Family %02Xh System Management Network",
 	    family);
 
 	return (BUS_PROBE_GENERIC);
diff --git a/sys/dev/amdtemp/amdtemp.c b/sys/dev/amdtemp/amdtemp.c
index b609c0944499..3ce826a2c0ec 100644
--- a/sys/dev/amdtemp/amdtemp.c
+++ b/sys/dev/amdtemp/amdtemp.c
@@ -117,6 +117,9 @@ struct amdtemp_softc {
 #define	DEVICEID_AMD_HOSTB19H_M40H_ROOT	0x14b5
 #define	DEVICEID_AMD_HOSTB19H_M60H_ROOT	0x14d8	/* Also F1AH M40H */
 #define	DEVICEID_AMD_HOSTB19H_M70H_ROOT	0x14e8
+#define	DEVICEID_AMD_HOSTB1AH_M00H_ROOT	0x153a
+#define	DEVICEID_AMD_HOSTB1AH_M20H_ROOT	0x1507
+#define	DEVICEID_AMD_HOSTB1AH_M60H_ROOT	0x1122
 
 static const struct amdtemp_product {
 	uint16_t	amdtemp_vendorid;
@@ -145,6 +148,9 @@ static const struct amdtemp_product {
 	{ VENDORID_AMD, DEVICEID_AMD_HOSTB19H_M40H_ROOT, false },
 	{ VENDORID_AMD,	DEVICEID_AMD_HOSTB19H_M60H_ROOT, false },
 	{ VENDORID_AMD,	DEVICEID_AMD_HOSTB19H_M70H_ROOT, false },
+	{ VENDORID_AMD,	DEVICEID_AMD_HOSTB1AH_M00H_ROOT, false },
+	{ VENDORID_AMD,	DEVICEID_AMD_HOSTB1AH_M20H_ROOT, false },
+	{ VENDORID_AMD,	DEVICEID_AMD_HOSTB1AH_M60H_ROOT, false },
 };
 
 /*
@@ -166,7 +172,7 @@ static const struct amdtemp_product {
 #define	AMDTEMP_15H_M60H_REPTMP_CTRL	0xd8200ca4
 
 /*
- * Reported Temperature, Family 17h
+ * Reported Temperature, Family 17h - 1Ah
  *
  * According to AMD OSRR for 17H, section 4.2.1, bits 31-21 of this register
  * provide the current temp.  bit 19, when clear, means the temp is reported in
@@ -294,21 +300,33 @@ amdtemp_identify(driver_t *driver, device_t parent)
 static int
 amdtemp_probe(device_t dev)
 {
-	uint32_t family, model;
+	uint32_t family, model, stepping;
 
-	if (resource_disabled("amdtemp", 0))
+	if (resource_disabled("amdtemp", 0)) {
+		if (bootverbose)
+			device_printf(dev, "Resource disabled\n");
 		return (ENXIO);
-	if (!amdtemp_match(device_get_parent(dev), NULL))
+	}
+	if (!amdtemp_match(device_get_parent(dev), NULL)) {
+		if (bootverbose)
+			device_printf(dev, "amdtemp_match() failed\n");
 		return (ENXIO);
+	}
 
 	family = CPUID_TO_FAMILY(cpu_id);
 	model = CPUID_TO_MODEL(cpu_id);
+	stepping = CPUID_TO_STEPPING(cpu_id);
 
 	switch (family) {
 	case 0x0f:
-		if ((model == 0x04 && (cpu_id & CPUID_STEPPING) == 0) ||
-		    (model == 0x05 && (cpu_id & CPUID_STEPPING) <= 1))
+		if ((model == 0x04 && stepping == 0) ||
+		    (model == 0x05 && stepping <= 1)) {
+			if (bootverbose)
+				device_printf(dev,
+				    "Unsupported (Family=%02Xh, Model=%02Xh, Stepping=%02Xh)\n",
+				    family, model, stepping);
 			return (ENXIO);
+		}
 		break;
 	case 0x10:
 	case 0x11:
@@ -323,7 +341,8 @@ amdtemp_probe(device_t dev)
 	default:
 		return (ENXIO);
 	}
-	device_set_desc(dev, "AMD CPU On-Die Thermal Sensors");
+	device_set_descf(dev, "AMD Family %02Xh CPU On-Die Thermal Sensors",
+	    family);
 
 	return (BUS_PROBE_GENERIC);
 }
@@ -484,7 +503,7 @@ amdtemp_attach(device_t dev)
 		needsmn = true;
 		break;
 	default:
-		device_printf(dev, "Bogus family 0x%x\n", family);
+		device_printf(dev, "Bogus family %02Xh\n", family);
 		return (ENXIO);
 	}
 
@@ -493,7 +512,7 @@ amdtemp_attach(device_t dev)
 		    device_get_parent(dev), "amdsmn", -1);
 		if (sc->sc_smn == NULL) {
 			if (bootverbose)
-				device_printf(dev, "No SMN device found\n");
+				device_printf(dev, "No amdsmn(4) device found\n");
 			return (ENXIO);
 		}
 	}
@@ -509,7 +528,7 @@ amdtemp_attach(device_t dev)
 		device_printf(dev,
 		    "Erratum 319: temperature measurement may be inaccurate\n");
 	if (bootverbose)
-		device_printf(dev, "Found %d cores and %d sensors.\n",
+		device_printf(dev, "Found %d cores and %d sensors\n",
 		    sc->sc_ncores,
 		    sc->sc_ntemps > 1 ? sc->sc_ntemps * sc->sc_ncores : 1);
 
@@ -857,7 +876,7 @@ amdtemp_probe_ccd_sensors17h(device_t dev, uint32_t model)
 		break;
 	default:
 		device_printf(dev,
-		    "Unrecognized Family 17h Model: %02xh\n", model);
+		    "Unrecognized Family 17h Model: %02Xh\n", model);
 		return;
 	}
 
@@ -877,7 +896,7 @@ amdtemp_probe_ccd_sensors19h(device_t dev, uint32_t model)
 		maxreg = 8;
 		_Static_assert((int)NUM_CCDS >= 8, "");
 		break;
-	case 0x10 ... 0x1f:
+	case 0x10 ... 0x1f: /* Zen4 EPYC "Genoa" */
 		sc->sc_temp_base = AMDTEMP_ZEN4_10H_CCD_TMP_BASE;
 		maxreg = 12;
 		_Static_assert((int)NUM_CCDS >= 12, "");
@@ -891,7 +910,7 @@ amdtemp_probe_ccd_sensors19h(device_t dev, uint32_t model)
 		break;
 	default:
 		device_printf(dev,
-		    "Unrecognized Family 19h Model: %02xh\n", model);
+		    "Unrecognized Family 19h Model: %02Xh\n", model);
 		return;
 	}
 
@@ -905,14 +924,16 @@ amdtemp_probe_ccd_sensors1ah(device_t dev, uint32_t model)
 	uint32_t maxreg;
 
 	switch (model) {
+	case 0x00 ... 0x2f: /* Zen5 EPYC "Turin" */
 	case 0x40 ... 0x4f: /* Zen5 Ryzen "Granite Ridge" */
+	case 0x60 ... 0x7f: /* ??? */
 		sc->sc_temp_base = AMDTEMP_ZEN4_CCD_TMP_BASE;
 		maxreg = 8;
 		_Static_assert((int)NUM_CCDS >= 8, "");
 		break;
 	default:
 		device_printf(dev,
-		    "Unrecognized Family 1ah Model: %02xh\n", model);
+		    "Unrecognized Family 1Ah Model: %02Xh\n", model);
 		return;
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202505101921.54AJLDc5028435>