Merge tag 'hwmon-for-linus-v4.17-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging

Pull hwmon fixes from Guenter Roeck:
"Two k10temp fixes:

- fix race condition when accessing System Management Network
registers

- fix reading critical temperatures on F15h M60h and M70h

Also add PCI ID's for the AMD Raven Ridge root bridge"

* tag 'hwmon-for-linus-v4.17-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging:
hwmon: (k10temp) Use API function to access System Management Network
x86/amd_nb: Add support for Raven Ridge CPUs
hwmon: (k10temp) Fix reading critical temperature register

+43 -16
+6
arch/x86/kernel/amd_nb.c
··· 14 #include <asm/amd_nb.h> 15 16 #define PCI_DEVICE_ID_AMD_17H_ROOT 0x1450 17 #define PCI_DEVICE_ID_AMD_17H_DF_F3 0x1463 18 #define PCI_DEVICE_ID_AMD_17H_DF_F4 0x1464 19 20 /* Protect the PCI config register pairs used for SMN and DF indirect access. */ 21 static DEFINE_MUTEX(smn_mutex); ··· 27 28 static const struct pci_device_id amd_root_ids[] = { 29 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_ROOT) }, 30 {} 31 }; 32 ··· 43 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) }, 44 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) }, 45 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_DF_F3) }, 46 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) }, 47 {} 48 }; ··· 56 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F4) }, 57 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F4) }, 58 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_DF_F4) }, 59 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F4) }, 60 {} 61 };
··· 14 #include <asm/amd_nb.h> 15 16 #define PCI_DEVICE_ID_AMD_17H_ROOT 0x1450 17 + #define PCI_DEVICE_ID_AMD_17H_M10H_ROOT 0x15d0 18 #define PCI_DEVICE_ID_AMD_17H_DF_F3 0x1463 19 #define PCI_DEVICE_ID_AMD_17H_DF_F4 0x1464 20 + #define PCI_DEVICE_ID_AMD_17H_M10H_DF_F3 0x15eb 21 + #define PCI_DEVICE_ID_AMD_17H_M10H_DF_F4 0x15ec 22 23 /* Protect the PCI config register pairs used for SMN and DF indirect access. */ 24 static DEFINE_MUTEX(smn_mutex); ··· 24 25 static const struct pci_device_id amd_root_ids[] = { 26 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_ROOT) }, 27 + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M10H_ROOT) }, 28 {} 29 }; 30 ··· 39 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) }, 40 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) }, 41 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_DF_F3) }, 42 + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M10H_DF_F3) }, 43 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) }, 44 {} 45 }; ··· 51 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F4) }, 52 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F4) }, 53 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_DF_F4) }, 54 + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M10H_DF_F4) }, 55 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F4) }, 56 {} 57 };
+1 -1
drivers/hwmon/Kconfig
··· 272 273 config SENSORS_K10TEMP 274 tristate "AMD Family 10h+ temperature sensor" 275 - depends on X86 && PCI 276 help 277 If you say yes here you get support for the temperature 278 sensor(s) inside your CPU. Supported are later revisions of
··· 272 273 config SENSORS_K10TEMP 274 tristate "AMD Family 10h+ temperature sensor" 275 + depends on X86 && PCI && AMD_NB 276 help 277 If you say yes here you get support for the temperature 278 sensor(s) inside your CPU. Supported are later revisions of
+36 -15
drivers/hwmon/k10temp.c
··· 23 #include <linux/init.h> 24 #include <linux/module.h> 25 #include <linux/pci.h> 26 #include <asm/processor.h> 27 28 MODULE_DESCRIPTION("AMD Family 10h+ CPU core temperature monitor"); ··· 41 #define PCI_DEVICE_ID_AMD_17H_DF_F3 0x1463 42 #endif 43 44 - #ifndef PCI_DEVICE_ID_AMD_17H_RR_NB 45 - #define PCI_DEVICE_ID_AMD_17H_RR_NB 0x15d0 46 #endif 47 48 /* CPUID function 0x80000001, ebx */ ··· 64 #define NB_CAP_HTC 0x00000400 65 66 /* 67 - * For F15h M60h, functionality of REG_REPORTED_TEMPERATURE 68 - * has been moved to D0F0xBC_xD820_0CA4 [Reported Temperature 69 - * Control] 70 */ 71 #define F15H_M60H_REPORTED_TEMP_CTRL_OFFSET 0xd8200ca4 72 73 /* F17h M01h Access througn SMN */ ··· 77 78 struct k10temp_data { 79 struct pci_dev *pdev; 80 void (*read_tempreg)(struct pci_dev *pdev, u32 *regval); 81 int temp_offset; 82 u32 temp_adjust_mask; ··· 102 { 0x17, "AMD Ryzen Threadripper 1910", 10000 }, 103 }; 104 105 static void read_tempreg_pci(struct pci_dev *pdev, u32 *regval) 106 { 107 pci_read_config_dword(pdev, REG_REPORTED_TEMPERATURE, regval); ··· 123 mutex_unlock(&nb_smu_ind_mutex); 124 } 125 126 static void read_tempreg_nb_f15(struct pci_dev *pdev, u32 *regval) 127 { 128 amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0xb8, ··· 137 138 static void read_tempreg_nb_f17(struct pci_dev *pdev, u32 *regval) 139 { 140 - amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0x60, 141 - F17H_M01H_REPORTED_TEMP_CTRL_OFFSET, regval); 142 } 143 144 static ssize_t temp1_input_show(struct device *dev, ··· 175 u32 regval; 176 int value; 177 178 - pci_read_config_dword(data->pdev, 179 - REG_HARDWARE_THERMAL_CONTROL, &regval); 180 value = ((regval >> 16) & 0x7f) * 500 + 52000; 181 if (show_hyst) 182 value -= ((regval >> 24) & 0xf) * 500; ··· 195 struct pci_dev *pdev = data->pdev; 196 197 if (index >= 2) { 198 - u32 reg_caps, reg_htc; 199 200 pci_read_config_dword(pdev, REG_NORTHBRIDGE_CAPABILITIES, 201 - &reg_caps); 202 - pci_read_config_dword(pdev, REG_HARDWARE_THERMAL_CONTROL, 203 - &reg_htc); 204 - if (!(reg_caps & NB_CAP_HTC) || !(reg_htc & HTC_ENABLE)) 205 return 0; 206 } 207 return attr->mode; ··· 287 288 if (boot_cpu_data.x86 == 0x15 && (boot_cpu_data.x86_model == 0x60 || 289 boot_cpu_data.x86_model == 0x70)) { 290 data->read_tempreg = read_tempreg_nb_f15; 291 } else if (boot_cpu_data.x86 == 0x17) { 292 data->temp_adjust_mask = 0x80000; 293 data->read_tempreg = read_tempreg_nb_f17; 294 } else { 295 data->read_tempreg = read_tempreg_pci; 296 } 297 ··· 323 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) }, 324 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) }, 325 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_DF_F3) }, 326 - { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_RR_NB) }, 327 {} 328 }; 329 MODULE_DEVICE_TABLE(pci, k10temp_id_table);
··· 23 #include <linux/init.h> 24 #include <linux/module.h> 25 #include <linux/pci.h> 26 + #include <asm/amd_nb.h> 27 #include <asm/processor.h> 28 29 MODULE_DESCRIPTION("AMD Family 10h+ CPU core temperature monitor"); ··· 40 #define PCI_DEVICE_ID_AMD_17H_DF_F3 0x1463 41 #endif 42 43 + #ifndef PCI_DEVICE_ID_AMD_17H_M10H_DF_F3 44 + #define PCI_DEVICE_ID_AMD_17H_M10H_DF_F3 0x15eb 45 #endif 46 47 /* CPUID function 0x80000001, ebx */ ··· 63 #define NB_CAP_HTC 0x00000400 64 65 /* 66 + * For F15h M60h and M70h, REG_HARDWARE_THERMAL_CONTROL 67 + * and REG_REPORTED_TEMPERATURE have been moved to 68 + * D0F0xBC_xD820_0C64 [Hardware Temperature Control] 69 + * D0F0xBC_xD820_0CA4 [Reported Temperature Control] 70 */ 71 + #define F15H_M60H_HARDWARE_TEMP_CTRL_OFFSET 0xd8200c64 72 #define F15H_M60H_REPORTED_TEMP_CTRL_OFFSET 0xd8200ca4 73 74 /* F17h M01h Access througn SMN */ ··· 74 75 struct k10temp_data { 76 struct pci_dev *pdev; 77 + void (*read_htcreg)(struct pci_dev *pdev, u32 *regval); 78 void (*read_tempreg)(struct pci_dev *pdev, u32 *regval); 79 int temp_offset; 80 u32 temp_adjust_mask; ··· 98 { 0x17, "AMD Ryzen Threadripper 1910", 10000 }, 99 }; 100 101 + static void read_htcreg_pci(struct pci_dev *pdev, u32 *regval) 102 + { 103 + pci_read_config_dword(pdev, REG_HARDWARE_THERMAL_CONTROL, regval); 104 + } 105 + 106 static void read_tempreg_pci(struct pci_dev *pdev, u32 *regval) 107 { 108 pci_read_config_dword(pdev, REG_REPORTED_TEMPERATURE, regval); ··· 114 mutex_unlock(&nb_smu_ind_mutex); 115 } 116 117 + static void read_htcreg_nb_f15(struct pci_dev *pdev, u32 *regval) 118 + { 119 + amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0xb8, 120 + F15H_M60H_HARDWARE_TEMP_CTRL_OFFSET, regval); 121 + } 122 + 123 static void read_tempreg_nb_f15(struct pci_dev *pdev, u32 *regval) 124 { 125 amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0xb8, ··· 122 123 static void read_tempreg_nb_f17(struct pci_dev *pdev, u32 *regval) 124 { 125 + amd_smn_read(amd_pci_dev_to_node_id(pdev), 126 + F17H_M01H_REPORTED_TEMP_CTRL_OFFSET, regval); 127 } 128 129 static ssize_t temp1_input_show(struct device *dev, ··· 160 u32 regval; 161 int value; 162 163 + data->read_htcreg(data->pdev, &regval); 164 value = ((regval >> 16) & 0x7f) * 500 + 52000; 165 if (show_hyst) 166 value -= ((regval >> 24) & 0xf) * 500; ··· 181 struct pci_dev *pdev = data->pdev; 182 183 if (index >= 2) { 184 + u32 reg; 185 + 186 + if (!data->read_htcreg) 187 + return 0; 188 189 pci_read_config_dword(pdev, REG_NORTHBRIDGE_CAPABILITIES, 190 + &reg); 191 + if (!(reg & NB_CAP_HTC)) 192 + return 0; 193 + 194 + data->read_htcreg(data->pdev, &reg); 195 + if (!(reg & HTC_ENABLE)) 196 return 0; 197 } 198 return attr->mode; ··· 268 269 if (boot_cpu_data.x86 == 0x15 && (boot_cpu_data.x86_model == 0x60 || 270 boot_cpu_data.x86_model == 0x70)) { 271 + data->read_htcreg = read_htcreg_nb_f15; 272 data->read_tempreg = read_tempreg_nb_f15; 273 } else if (boot_cpu_data.x86 == 0x17) { 274 data->temp_adjust_mask = 0x80000; 275 data->read_tempreg = read_tempreg_nb_f17; 276 } else { 277 + data->read_htcreg = read_htcreg_pci; 278 data->read_tempreg = read_tempreg_pci; 279 } 280 ··· 302 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) }, 303 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) }, 304 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_DF_F3) }, 305 + { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_M10H_DF_F3) }, 306 {} 307 }; 308 MODULE_DEVICE_TABLE(pci, k10temp_id_table);