aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-05-17 18:58:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-05-17 18:58:12 -0400
commit3acf4e395260e3bd30a6fa29ba7eada4bf7566ca (patch)
tree1b8e3641d63895bf8f4aa67a69f8009684f66179
parent58ddfe6c3af91d320cf5d0aba33143e7c1d8dc35 (diff)
parent3b031622f598481970400519bd5abc2a16708282 (diff)
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
-rw-r--r--arch/x86/kernel/amd_nb.c6
-rw-r--r--drivers/hwmon/Kconfig2
-rw-r--r--drivers/hwmon/k10temp.c51
3 files changed, 43 insertions, 16 deletions
diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index c88e0b127810..b481b95bd8f6 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -14,8 +14,11 @@
14#include <asm/amd_nb.h> 14#include <asm/amd_nb.h>
15 15
16#define PCI_DEVICE_ID_AMD_17H_ROOT 0x1450 16#define PCI_DEVICE_ID_AMD_17H_ROOT 0x1450
17#define PCI_DEVICE_ID_AMD_17H_M10H_ROOT 0x15d0
17#define PCI_DEVICE_ID_AMD_17H_DF_F3 0x1463 18#define PCI_DEVICE_ID_AMD_17H_DF_F3 0x1463
18#define PCI_DEVICE_ID_AMD_17H_DF_F4 0x1464 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
19 22
20/* Protect the PCI config register pairs used for SMN and DF indirect access. */ 23/* Protect the PCI config register pairs used for SMN and DF indirect access. */
21static DEFINE_MUTEX(smn_mutex); 24static DEFINE_MUTEX(smn_mutex);
@@ -24,6 +27,7 @@ static u32 *flush_words;
24 27
25static const struct pci_device_id amd_root_ids[] = { 28static const struct pci_device_id amd_root_ids[] = {
26 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_ROOT) }, 29 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_ROOT) },
30 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M10H_ROOT) },
27 {} 31 {}
28}; 32};
29 33
@@ -39,6 +43,7 @@ const struct pci_device_id amd_nb_misc_ids[] = {
39 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) }, 43 { 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) }, 44 { 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) }, 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_17H_M10H_DF_F3) },
42 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) }, 47 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) },
43 {} 48 {}
44}; 49};
@@ -51,6 +56,7 @@ static const struct pci_device_id amd_nb_link_ids[] = {
51 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F4) }, 56 { 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) }, 57 { 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) }, 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_17H_M10H_DF_F4) },
54 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F4) }, 60 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F4) },
55 {} 61 {}
56}; 62};
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index f249a4428458..6ec307c93ece 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -272,7 +272,7 @@ config SENSORS_K8TEMP
272 272
273config SENSORS_K10TEMP 273config SENSORS_K10TEMP
274 tristate "AMD Family 10h+ temperature sensor" 274 tristate "AMD Family 10h+ temperature sensor"
275 depends on X86 && PCI 275 depends on X86 && PCI && AMD_NB
276 help 276 help
277 If you say yes here you get support for the temperature 277 If you say yes here you get support for the temperature
278 sensor(s) inside your CPU. Supported are later revisions of 278 sensor(s) inside your CPU. Supported are later revisions of
diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c
index d2cc55e21374..3b73dee6fdc6 100644
--- a/drivers/hwmon/k10temp.c
+++ b/drivers/hwmon/k10temp.c
@@ -23,6 +23,7 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/pci.h> 25#include <linux/pci.h>
26#include <asm/amd_nb.h>
26#include <asm/processor.h> 27#include <asm/processor.h>
27 28
28MODULE_DESCRIPTION("AMD Family 10h+ CPU core temperature monitor"); 29MODULE_DESCRIPTION("AMD Family 10h+ CPU core temperature monitor");
@@ -40,8 +41,8 @@ static DEFINE_MUTEX(nb_smu_ind_mutex);
40#define PCI_DEVICE_ID_AMD_17H_DF_F3 0x1463 41#define PCI_DEVICE_ID_AMD_17H_DF_F3 0x1463
41#endif 42#endif
42 43
43#ifndef PCI_DEVICE_ID_AMD_17H_RR_NB 44#ifndef PCI_DEVICE_ID_AMD_17H_M10H_DF_F3
44#define PCI_DEVICE_ID_AMD_17H_RR_NB 0x15d0 45#define PCI_DEVICE_ID_AMD_17H_M10H_DF_F3 0x15eb
45#endif 46#endif
46 47
47/* CPUID function 0x80000001, ebx */ 48/* CPUID function 0x80000001, ebx */
@@ -63,10 +64,12 @@ static DEFINE_MUTEX(nb_smu_ind_mutex);
63#define NB_CAP_HTC 0x00000400 64#define NB_CAP_HTC 0x00000400
64 65
65/* 66/*
66 * For F15h M60h, functionality of REG_REPORTED_TEMPERATURE 67 * For F15h M60h and M70h, REG_HARDWARE_THERMAL_CONTROL
67 * has been moved to D0F0xBC_xD820_0CA4 [Reported Temperature 68 * and REG_REPORTED_TEMPERATURE have been moved to
68 * Control] 69 * D0F0xBC_xD820_0C64 [Hardware Temperature Control]
70 * D0F0xBC_xD820_0CA4 [Reported Temperature Control]
69 */ 71 */
72#define F15H_M60H_HARDWARE_TEMP_CTRL_OFFSET 0xd8200c64
70#define F15H_M60H_REPORTED_TEMP_CTRL_OFFSET 0xd8200ca4 73#define F15H_M60H_REPORTED_TEMP_CTRL_OFFSET 0xd8200ca4
71 74
72/* F17h M01h Access througn SMN */ 75/* F17h M01h Access througn SMN */
@@ -74,6 +77,7 @@ static DEFINE_MUTEX(nb_smu_ind_mutex);
74 77
75struct k10temp_data { 78struct k10temp_data {
76 struct pci_dev *pdev; 79 struct pci_dev *pdev;
80 void (*read_htcreg)(struct pci_dev *pdev, u32 *regval);
77 void (*read_tempreg)(struct pci_dev *pdev, u32 *regval); 81 void (*read_tempreg)(struct pci_dev *pdev, u32 *regval);
78 int temp_offset; 82 int temp_offset;
79 u32 temp_adjust_mask; 83 u32 temp_adjust_mask;
@@ -98,6 +102,11 @@ static const struct tctl_offset tctl_offset_table[] = {
98 { 0x17, "AMD Ryzen Threadripper 1910", 10000 }, 102 { 0x17, "AMD Ryzen Threadripper 1910", 10000 },
99}; 103};
100 104
105static void read_htcreg_pci(struct pci_dev *pdev, u32 *regval)
106{
107 pci_read_config_dword(pdev, REG_HARDWARE_THERMAL_CONTROL, regval);
108}
109
101static void read_tempreg_pci(struct pci_dev *pdev, u32 *regval) 110static void read_tempreg_pci(struct pci_dev *pdev, u32 *regval)
102{ 111{
103 pci_read_config_dword(pdev, REG_REPORTED_TEMPERATURE, regval); 112 pci_read_config_dword(pdev, REG_REPORTED_TEMPERATURE, regval);
@@ -114,6 +123,12 @@ static void amd_nb_index_read(struct pci_dev *pdev, unsigned int devfn,
114 mutex_unlock(&nb_smu_ind_mutex); 123 mutex_unlock(&nb_smu_ind_mutex);
115} 124}
116 125
126static void read_htcreg_nb_f15(struct pci_dev *pdev, u32 *regval)
127{
128 amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0xb8,
129 F15H_M60H_HARDWARE_TEMP_CTRL_OFFSET, regval);
130}
131
117static void read_tempreg_nb_f15(struct pci_dev *pdev, u32 *regval) 132static void read_tempreg_nb_f15(struct pci_dev *pdev, u32 *regval)
118{ 133{
119 amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0xb8, 134 amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0xb8,
@@ -122,8 +137,8 @@ static void read_tempreg_nb_f15(struct pci_dev *pdev, u32 *regval)
122 137
123static void read_tempreg_nb_f17(struct pci_dev *pdev, u32 *regval) 138static void read_tempreg_nb_f17(struct pci_dev *pdev, u32 *regval)
124{ 139{
125 amd_nb_index_read(pdev, PCI_DEVFN(0, 0), 0x60, 140 amd_smn_read(amd_pci_dev_to_node_id(pdev),
126 F17H_M01H_REPORTED_TEMP_CTRL_OFFSET, regval); 141 F17H_M01H_REPORTED_TEMP_CTRL_OFFSET, regval);
127} 142}
128 143
129static ssize_t temp1_input_show(struct device *dev, 144static ssize_t temp1_input_show(struct device *dev,
@@ -160,8 +175,7 @@ static ssize_t show_temp_crit(struct device *dev,
160 u32 regval; 175 u32 regval;
161 int value; 176 int value;
162 177
163 pci_read_config_dword(data->pdev, 178 data->read_htcreg(data->pdev, &regval);
164 REG_HARDWARE_THERMAL_CONTROL, &regval);
165 value = ((regval >> 16) & 0x7f) * 500 + 52000; 179 value = ((regval >> 16) & 0x7f) * 500 + 52000;
166 if (show_hyst) 180 if (show_hyst)
167 value -= ((regval >> 24) & 0xf) * 500; 181 value -= ((regval >> 24) & 0xf) * 500;
@@ -181,13 +195,18 @@ static umode_t k10temp_is_visible(struct kobject *kobj,
181 struct pci_dev *pdev = data->pdev; 195 struct pci_dev *pdev = data->pdev;
182 196
183 if (index >= 2) { 197 if (index >= 2) {
184 u32 reg_caps, reg_htc; 198 u32 reg;
199
200 if (!data->read_htcreg)
201 return 0;
185 202
186 pci_read_config_dword(pdev, REG_NORTHBRIDGE_CAPABILITIES, 203 pci_read_config_dword(pdev, REG_NORTHBRIDGE_CAPABILITIES,
187 &reg_caps); 204 &reg);
188 pci_read_config_dword(pdev, REG_HARDWARE_THERMAL_CONTROL, 205 if (!(reg & NB_CAP_HTC))
189 &reg_htc); 206 return 0;
190 if (!(reg_caps & NB_CAP_HTC) || !(reg_htc & HTC_ENABLE)) 207
208 data->read_htcreg(data->pdev, &reg);
209 if (!(reg & HTC_ENABLE))
191 return 0; 210 return 0;
192 } 211 }
193 return attr->mode; 212 return attr->mode;
@@ -268,11 +287,13 @@ static int k10temp_probe(struct pci_dev *pdev,
268 287
269 if (boot_cpu_data.x86 == 0x15 && (boot_cpu_data.x86_model == 0x60 || 288 if (boot_cpu_data.x86 == 0x15 && (boot_cpu_data.x86_model == 0x60 ||
270 boot_cpu_data.x86_model == 0x70)) { 289 boot_cpu_data.x86_model == 0x70)) {
290 data->read_htcreg = read_htcreg_nb_f15;
271 data->read_tempreg = read_tempreg_nb_f15; 291 data->read_tempreg = read_tempreg_nb_f15;
272 } else if (boot_cpu_data.x86 == 0x17) { 292 } else if (boot_cpu_data.x86 == 0x17) {
273 data->temp_adjust_mask = 0x80000; 293 data->temp_adjust_mask = 0x80000;
274 data->read_tempreg = read_tempreg_nb_f17; 294 data->read_tempreg = read_tempreg_nb_f17;
275 } else { 295 } else {
296 data->read_htcreg = read_htcreg_pci;
276 data->read_tempreg = read_tempreg_pci; 297 data->read_tempreg = read_tempreg_pci;
277 } 298 }
278 299
@@ -302,7 +323,7 @@ static const struct pci_device_id k10temp_id_table[] = {
302 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) }, 323 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) },
303 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) }, 324 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) },
304 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_DF_F3) }, 325 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_DF_F3) },
305 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_RR_NB) }, 326 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_M10H_DF_F3) },
306 {} 327 {}
307}; 328};
308MODULE_DEVICE_TABLE(pci, k10temp_id_table); 329MODULE_DEVICE_TABLE(pci, k10temp_id_table);