Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (coretemp) Replace x86_model checks with VFM ones

Intel CPUs have been using Family 6 for a while. The Family-model checks
in the coretemp driver implicitly assume Family 6. With the upcoming
Family 18 and 19 models, some of these checks fall apart.

While reading the temperature target MSR, cpu_has_tjmax() performs model
checks only to determine if a device warning should be printed. Instead
of expanding the checks, get rid of the function and print the warning
once unconditionally if the MSR read fails. The checks aren't worth
preventing a single line warning to dmesg.

Update the rest of the x86_model checks with VFM ones to make them more
robust. This automatically covers the upcoming Family 18 and 19 as well
as any future extended families.

Add a code comment to reflect that none of the CPUs in Family 5 or
Family 15 set X86_FEATURE_DTHERM. The VFM checks do not impact these
CPUs since the driver does not load on them.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Sohil Mehta <sohil.mehta@intel.com>
Reviewed-by: Dave Hansen <dave.hansen@linux.intel.com>
Link: https://lore.kernel.org/r/20250828201729.1145420-1-sohil.mehta@intel.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Dave Hansen and committed by
Guenter Roeck
468a20df 3d5fcffc

+36 -40
+36 -40
drivers/hwmon/coretemp.c
··· 122 122 }; 123 123 124 124 struct tjmax_model { 125 - u8 model; 126 - u8 mask; 125 + u32 vfm; 126 + u8 stepping_mask; 127 127 int tjmax; 128 128 }; 129 129 130 130 #define ANY 0xff 131 131 132 132 static const struct tjmax_model tjmax_model_table[] = { 133 - { 0x1c, 10, 100000 }, /* D4xx, K4xx, N4xx, D5xx, K5xx, N5xx */ 134 - { 0x1c, ANY, 90000 }, /* Z5xx, N2xx, possibly others 135 - * Note: Also matches 230 and 330, 136 - * which are covered by tjmax_table 137 - */ 138 - { 0x26, ANY, 90000 }, /* Atom Tunnel Creek (Exx), Lincroft (Z6xx) 139 - * Note: TjMax for E6xxT is 110C, but CPU type 140 - * is undetectable by software 141 - */ 142 - { 0x27, ANY, 90000 }, /* Atom Medfield (Z2460) */ 143 - { 0x35, ANY, 90000 }, /* Atom Clover Trail/Cloverview (Z27x0) */ 144 - { 0x36, ANY, 100000 }, /* Atom Cedar Trail/Cedarview (N2xxx, D2xxx) 145 - * Also matches S12x0 (stepping 9), covered by 146 - * PCI table 147 - */ 133 + { INTEL_ATOM_BONNELL, 10, 100000 }, /* D4xx, K4xx, N4xx, D5xx, K5xx, N5xx */ 134 + { INTEL_ATOM_BONNELL, ANY, 90000 }, /* Z5xx, N2xx, possibly others 135 + * Note: Also matches 230 and 330, 136 + * which are covered by tjmax_table 137 + */ 138 + { INTEL_ATOM_BONNELL_MID, ANY, 90000 }, /* Atom Tunnel Creek (Exx), Lincroft (Z6xx) 139 + * Note: TjMax for E6xxT is 110C, but CPU type 140 + * is undetectable by software 141 + */ 142 + { INTEL_ATOM_SALTWELL_MID, ANY, 90000 }, /* Atom Medfield (Z2460) */ 143 + { INTEL_ATOM_SALTWELL_TABLET, ANY, 90000 }, /* Atom Clover Trail/Cloverview (Z27x0) */ 144 + { INTEL_ATOM_SALTWELL, ANY, 100000 }, /* Atom Cedar Trail/Cedarview (N2xxx, D2xxx) 145 + * Also matches S12x0 (stepping 9), covered by 146 + * PCI table 147 + */ 148 148 }; 149 149 150 150 static bool is_pkg_temp_data(struct temp_data *tdata) ··· 180 180 } 181 181 pci_dev_put(host_bridge); 182 182 183 + /* 184 + * This is literally looking for "CPU XXX" in the model string. 185 + * Not checking it against the model as well. Just purely a 186 + * string search. 187 + */ 183 188 for (i = 0; i < ARRAY_SIZE(tjmax_table); i++) { 184 189 if (strstr(c->x86_model_id, tjmax_table[i].id)) 185 190 return tjmax_table[i].tjmax; ··· 192 187 193 188 for (i = 0; i < ARRAY_SIZE(tjmax_model_table); i++) { 194 189 const struct tjmax_model *tm = &tjmax_model_table[i]; 195 - if (c->x86_model == tm->model && 196 - (tm->mask == ANY || c->x86_stepping == tm->mask)) 190 + if (c->x86_vfm == tm->vfm && 191 + (tm->stepping_mask == ANY || 192 + tm->stepping_mask == c->x86_stepping)) 197 193 return tm->tjmax; 198 194 } 199 195 200 196 /* Early chips have no MSR for TjMax */ 201 197 202 - if (c->x86_model == 0xf && c->x86_stepping < 4) 198 + if (c->x86_vfm == INTEL_CORE2_MEROM && c->x86_stepping < 4) 203 199 usemsr_ee = 0; 204 200 205 - if (c->x86_model > 0xe && usemsr_ee) { 201 + if (c->x86_vfm > INTEL_CORE_YONAH && usemsr_ee) { 206 202 u8 platform_id; 207 203 208 204 /* ··· 217 211 "Unable to access MSR 0x17, assuming desktop" 218 212 " CPU\n"); 219 213 usemsr_ee = 0; 220 - } else if (c->x86_model < 0x17 && !(eax & 0x10000000)) { 214 + } else if (c->x86_vfm < INTEL_CORE2_PENRYN && 215 + !(eax & 0x10000000)) { 221 216 /* 222 217 * Trust bit 28 up to Penryn, I could not find any 223 218 * documentation on that; if you happen to know ··· 233 226 * Mobile Penryn CPU seems to be platform ID 7 or 5 234 227 * (guesswork) 235 228 */ 236 - if (c->x86_model == 0x17 && 229 + if (c->x86_vfm == INTEL_CORE2_PENRYN && 237 230 (platform_id == 5 || platform_id == 7)) { 238 231 /* 239 232 * If MSR EE bit is set, set it to 90 degrees C, ··· 265 258 return tjmax; 266 259 } 267 260 268 - static bool cpu_has_tjmax(struct cpuinfo_x86 *c) 269 - { 270 - u8 model = c->x86_model; 271 - 272 - return model > 0xe && 273 - model != 0x1c && 274 - model != 0x26 && 275 - model != 0x27 && 276 - model != 0x35 && 277 - model != 0x36; 278 - } 279 - 280 261 static int get_tjmax(struct temp_data *tdata, struct device *dev) 281 262 { 282 263 struct cpuinfo_x86 *c = &cpu_data(tdata->cpu); ··· 282 287 */ 283 288 err = rdmsr_safe_on_cpu(tdata->cpu, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx); 284 289 if (err) { 285 - if (cpu_has_tjmax(c)) 286 - dev_warn(dev, "Unable to read TjMax from CPU %u\n", tdata->cpu); 290 + dev_warn_once(dev, "Unable to read TjMax from CPU %u\n", tdata->cpu); 287 291 } else { 288 292 val = (eax >> 16) & 0xff; 289 293 if (val) ··· 454 460 * Readings might stop update when processor visited too deep sleep, 455 461 * fixed for stepping D0 (6EC). 456 462 */ 457 - if (c->x86_model == 0xe && c->x86_stepping < 0xc && c->microcode < 0x39) { 463 + if (c->x86_vfm == INTEL_CORE_YONAH && c->x86_stepping < 0xc && c->microcode < 0x39) { 458 464 pr_err("Errata AE18 not fixed, update BIOS or microcode of the CPU!\n"); 459 465 return -ENODEV; 460 466 } ··· 574 580 * MSR_IA32_TEMPERATURE_TARGET register. Atoms don't have the register 575 581 * at all. 576 582 */ 577 - if (c->x86_model > 0xe && c->x86_model != 0x1c) 583 + if (c->x86_vfm > INTEL_CORE_YONAH && c->x86_vfm != INTEL_ATOM_BONNELL) 578 584 if (get_ttarget(tdata, &pdev->dev) >= 0) 579 585 tdata->attr_size++; 580 586 ··· 787 793 /* 788 794 * CPUID.06H.EAX[0] indicates whether the CPU has thermal 789 795 * sensors. We check this bit only, all the early CPUs 790 - * without thermal sensors will be filtered out. 796 + * without thermal sensors will be filtered out. This 797 + * includes all the Family 5 and Family 15 (Pentium 4) 798 + * models, since they never set the CPUID bit. 791 799 */ 792 800 if (!x86_match_cpu(coretemp_ids)) 793 801 return -ENODEV;