svn commit: r357189 - head/sys/dev/amdtemp

Conrad Meyer cem at FreeBSD.org
Tue Jan 28 01:38:52 UTC 2020


Author: cem
Date: Tue Jan 28 01:38:51 2020
New Revision: 357189
URL: https://svnweb.freebsd.org/changeset/base/357189

Log:
  amdtemp(4): Refactor shared temperature calculation logic
  
  No functional change intended.

Modified:
  head/sys/dev/amdtemp/amdtemp.c

Modified: head/sys/dev/amdtemp/amdtemp.c
==============================================================================
--- head/sys/dev/amdtemp/amdtemp.c	Tue Jan 28 01:37:20 2020	(r357188)
+++ head/sys/dev/amdtemp/amdtemp.c	Tue Jan 28 01:38:51 2020	(r357189)
@@ -651,28 +651,48 @@ amdtemp_gettemp0f(device_t dev, amdsensor_t sensor)
 }
 
 static uint32_t
-amdtemp_decode_fam10h_to_16h(int32_t sc_offset, uint32_t val)
+amdtemp_decode_fam10h_to_17h(int32_t sc_offset, uint32_t val, bool minus49)
 {
 	uint32_t temp;
 
 	/* Convert raw register subfield units (0.125C) to units of 0.1C. */
-	temp = ((val >> AMDTEMP_REPTMP10H_CURTMP_SHIFT) &
-	    AMDTEMP_REPTMP10H_CURTMP_MASK) * 5 / 4;
+	temp = (val & AMDTEMP_REPTMP10H_CURTMP_MASK) * 5 / 4;
 
+	if (minus49)
+		temp -= AMDTEMP_CURTMP_RANGE_ADJUST;
+
+	temp += AMDTEMP_ZERO_C_TO_K + sc_offset * 10;
+	return (temp);
+}
+
+static uint32_t
+amdtemp_decode_fam10h_to_16h(int32_t sc_offset, uint32_t val)
+{
+	bool minus49;
+
 	/*
 	 * On Family 15h and higher, if CurTmpTjSel is 11b, the range is
 	 * adjusted down by 49.0 degrees Celsius.  (This adjustment is not
 	 * documented in BKDGs prior to family 15h model 00h.)
 	 */
-	if (CPUID_TO_FAMILY(cpu_id) >= 0x15 &&
+	minus49 = (CPUID_TO_FAMILY(cpu_id) >= 0x15 &&
 	    ((val >> AMDTEMP_REPTMP10H_TJSEL_SHIFT) &
-	    AMDTEMP_REPTMP10H_TJSEL_MASK) == 0x3)
-		temp -= AMDTEMP_CURTMP_RANGE_ADJUST;
+	    AMDTEMP_REPTMP10H_TJSEL_MASK) == 0x3);
 
-	temp += AMDTEMP_ZERO_C_TO_K + sc_offset * 10;
-	return (temp);
+	return (amdtemp_decode_fam10h_to_17h(sc_offset,
+	    val >> AMDTEMP_REPTMP10H_CURTMP_SHIFT, minus49));
 }
 
+static uint32_t
+amdtemp_decode_fam17h_tctl(int32_t sc_offset, uint32_t val)
+{
+	bool minus49;
+
+	minus49 = ((val & AMDTEMP_17H_CUR_TMP_RANGE_SEL) != 0);
+	return (amdtemp_decode_fam10h_to_17h(sc_offset,
+	    val >> AMDTEMP_REPTMP10H_CURTMP_SHIFT, minus49));
+}
+
 static int32_t
 amdtemp_gettemp(device_t dev, amdsensor_t sensor)
 {
@@ -699,16 +719,11 @@ static int32_t
 amdtemp_gettemp17h(device_t dev, amdsensor_t sensor)
 {
 	struct amdtemp_softc *sc = device_get_softc(dev);
-	uint32_t temp, val;
+	uint32_t val;
 	int error;
 
 	error = amdsmn_read(sc->sc_smn, AMDTEMP_17H_CUR_TMP, &val);
 	KASSERT(error == 0, ("amdsmn_read"));
 
-	temp = ((val >> 21) & 0x7ff) * 5 / 4;
-	if ((val & AMDTEMP_17H_CUR_TMP_RANGE_SEL) != 0)
-		temp -= AMDTEMP_CURTMP_RANGE_ADJUST;
-	temp += AMDTEMP_ZERO_C_TO_K + sc->sc_offset * 10;
-
-	return (temp);
+	return (amdtemp_decode_fam17h_tctl(sc->sc_offset, val));
 }


More information about the svn-src-head mailing list