2007-05-08 09:22:02 -06:00
|
|
|
/*
|
|
|
|
* coretemp.c - Linux kernel module for hardware monitoring
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
|
|
|
|
*
|
|
|
|
* Inspired from many hwmon drivers
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2010-10-20 00:51:31 -06:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2007-05-08 09:22:02 -06:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/hwmon.h>
|
|
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <linux/hwmon-sysfs.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/cpu.h>
|
2011-05-19 15:45:48 -06:00
|
|
|
#include <linux/smp.h>
|
2011-09-16 13:24:02 -06:00
|
|
|
#include <linux/moduleparam.h>
|
2007-05-08 09:22:02 -06:00
|
|
|
#include <asm/msr.h>
|
|
|
|
#include <asm/processor.h>
|
2012-01-25 16:09:10 -07:00
|
|
|
#include <asm/cpu_device_id.h>
|
2007-05-08 09:22:02 -06:00
|
|
|
|
|
|
|
#define DRVNAME "coretemp"
|
|
|
|
|
2011-09-16 13:24:02 -06:00
|
|
|
/*
|
|
|
|
* force_tjmax only matters when TjMax can't be read from the CPU itself.
|
|
|
|
* When set, it replaces the driver's suboptimal heuristic.
|
|
|
|
*/
|
|
|
|
static int force_tjmax;
|
|
|
|
module_param_named(tjmax, force_tjmax, int, 0444);
|
|
|
|
MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");
|
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
#define BASE_SYSFS_ATTR_NO 2 /* Sysfs Base attr no for coretemp */
|
2012-05-01 09:15:42 -06:00
|
|
|
#define NUM_REAL_CORES 32 /* Number of Real cores per cpu */
|
2011-05-19 13:59:35 -06:00
|
|
|
#define CORETEMP_NAME_LENGTH 17 /* String Length of attrs */
|
2011-07-12 05:07:16 -06:00
|
|
|
#define MAX_CORE_ATTRS 4 /* Maximum no of basic attrs */
|
hwmon: (coretemp) Don't use threshold registers for tempX_max
With commit c814a4c7c4aad795835583344353963a0a673eb0, the meaning of tempX_max
was changed. It no longer returns the value of bits 8:15 of
MSR_IA32_TEMPERATURE_TARGET, but instead returns the value of CPU threshold
register T1. tempX_max_hyst was added to reflect the value of temperature
threshold register T0.
As it turns out, T0 and T1 are used on some systems, presumably by the BIOS.
Also, T0 and T1 don't have a well defined meaning. The thresholds may be used
as upper or lower limits, and it is not guaranteed that T0 <= T1. Thus, the new
attribute mapping does not reflect the actual usage of the threshold registers.
Also, register contents are changed during runtime by an entity other than the
hwmon driver, meaning the values cached by the driver do not reflect actual
register contents.
Revert most of c814a4c7c4aad795835583344353963a0a673eb0 to address the problem.
Support for T0 and T1 will be added back in with a separate commit, using new
attribute names.
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Durgadoss R <durgadoss.r@intel.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
2011-09-19 22:41:16 -06:00
|
|
|
#define TOTAL_ATTRS (MAX_CORE_ATTRS + 1)
|
2011-05-19 13:59:35 -06:00
|
|
|
#define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO)
|
|
|
|
|
2012-01-20 10:31:17 -07:00
|
|
|
#define TO_PHYS_ID(cpu) (cpu_data(cpu).phys_proc_id)
|
|
|
|
#define TO_CORE_ID(cpu) (cpu_data(cpu).cpu_core_id)
|
2011-12-20 17:52:22 -07:00
|
|
|
#define TO_ATTR_NO(cpu) (TO_CORE_ID(cpu) + BASE_SYSFS_ATTR_NO)
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
2011-05-23 13:06:41 -06:00
|
|
|
#define for_each_sibling(i, cpu) for_each_cpu(i, cpu_sibling_mask(cpu))
|
2011-05-19 13:59:35 -06:00
|
|
|
#else
|
2011-05-23 13:06:41 -06:00
|
|
|
#define for_each_sibling(i, cpu) for (i = 0; false; )
|
2011-05-19 13:59:35 -06:00
|
|
|
#endif
|
2007-05-08 09:22:02 -06:00
|
|
|
|
|
|
|
/*
|
2011-05-19 13:59:35 -06:00
|
|
|
* Per-Core Temperature Data
|
|
|
|
* @last_updated: The time when the current temperature value was updated
|
|
|
|
* earlier (in jiffies).
|
|
|
|
* @cpu_core_id: The CPU Core from which temperature values should be read
|
|
|
|
* This value is passed as "id" field to rdmsr/wrmsr functions.
|
|
|
|
* @status_reg: One of IA32_THERM_STATUS or IA32_PACKAGE_THERM_STATUS,
|
|
|
|
* from where the temperature values should be read.
|
2011-07-12 05:07:16 -06:00
|
|
|
* @attr_size: Total number of pre-core attrs displayed in the sysfs.
|
2011-05-19 13:59:35 -06:00
|
|
|
* @is_pkg_data: If this is 1, the temp_data holds pkgtemp data.
|
|
|
|
* Otherwise, temp_data holds coretemp data.
|
|
|
|
* @valid: If this is 1, the current temperature is valid.
|
2007-05-08 09:22:02 -06:00
|
|
|
*/
|
2011-05-19 13:59:35 -06:00
|
|
|
struct temp_data {
|
2007-05-08 09:22:02 -06:00
|
|
|
int temp;
|
2008-01-17 16:42:54 -07:00
|
|
|
int ttarget;
|
2011-05-19 13:59:35 -06:00
|
|
|
int tjmax;
|
|
|
|
unsigned long last_updated;
|
|
|
|
unsigned int cpu;
|
|
|
|
u32 cpu_core_id;
|
|
|
|
u32 status_reg;
|
2011-07-12 05:07:16 -06:00
|
|
|
int attr_size;
|
2011-05-19 13:59:35 -06:00
|
|
|
bool is_pkg_data;
|
|
|
|
bool valid;
|
2011-07-12 05:07:16 -06:00
|
|
|
struct sensor_device_attribute sd_attrs[TOTAL_ATTRS];
|
|
|
|
char attr_name[TOTAL_ATTRS][CORETEMP_NAME_LENGTH];
|
2011-05-19 13:59:35 -06:00
|
|
|
struct mutex update_lock;
|
2007-05-08 09:22:02 -06:00
|
|
|
};
|
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
/* Platform Data per Physical CPU */
|
|
|
|
struct platform_data {
|
|
|
|
struct device *hwmon_dev;
|
|
|
|
u16 phys_proc_id;
|
|
|
|
struct temp_data *core_data[MAX_CORE_DATA];
|
|
|
|
struct device_attribute name_attr;
|
|
|
|
};
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
struct pdev_entry {
|
|
|
|
struct list_head list;
|
|
|
|
struct platform_device *pdev;
|
|
|
|
u16 phys_proc_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
static LIST_HEAD(pdev_list);
|
|
|
|
static DEFINE_MUTEX(pdev_list_mutex);
|
|
|
|
|
|
|
|
static ssize_t show_name(struct device *dev,
|
|
|
|
struct device_attribute *devattr, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%s\n", DRVNAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_label(struct device *dev,
|
|
|
|
struct device_attribute *devattr, char *buf)
|
2007-05-08 09:22:02 -06:00
|
|
|
{
|
|
|
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
2011-05-19 13:59:35 -06:00
|
|
|
struct platform_data *pdata = dev_get_drvdata(dev);
|
|
|
|
struct temp_data *tdata = pdata->core_data[attr->index];
|
|
|
|
|
|
|
|
if (tdata->is_pkg_data)
|
|
|
|
return sprintf(buf, "Physical id %u\n", pdata->phys_proc_id);
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
return sprintf(buf, "Core %u\n", tdata->cpu_core_id);
|
2007-05-08 09:22:02 -06:00
|
|
|
}
|
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
static ssize_t show_crit_alarm(struct device *dev,
|
|
|
|
struct device_attribute *devattr, char *buf)
|
2007-05-08 09:22:02 -06:00
|
|
|
{
|
2011-05-19 13:59:35 -06:00
|
|
|
u32 eax, edx;
|
|
|
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
|
|
|
struct platform_data *pdata = dev_get_drvdata(dev);
|
|
|
|
struct temp_data *tdata = pdata->core_data[attr->index];
|
|
|
|
|
|
|
|
rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx);
|
|
|
|
|
|
|
|
return sprintf(buf, "%d\n", (eax >> 5) & 1);
|
2007-05-08 09:22:02 -06:00
|
|
|
}
|
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
static ssize_t show_tjmax(struct device *dev,
|
|
|
|
struct device_attribute *devattr, char *buf)
|
2007-05-08 09:22:02 -06:00
|
|
|
{
|
|
|
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
2011-05-19 13:59:35 -06:00
|
|
|
struct platform_data *pdata = dev_get_drvdata(dev);
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
return sprintf(buf, "%d\n", pdata->core_data[attr->index]->tjmax);
|
2007-05-08 09:22:02 -06:00
|
|
|
}
|
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
static ssize_t show_ttarget(struct device *dev,
|
|
|
|
struct device_attribute *devattr, char *buf)
|
|
|
|
{
|
|
|
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
|
|
|
struct platform_data *pdata = dev_get_drvdata(dev);
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
return sprintf(buf, "%d\n", pdata->core_data[attr->index]->ttarget);
|
|
|
|
}
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
static ssize_t show_temp(struct device *dev,
|
|
|
|
struct device_attribute *devattr, char *buf)
|
2007-05-08 09:22:02 -06:00
|
|
|
{
|
2011-05-19 13:59:35 -06:00
|
|
|
u32 eax, edx;
|
|
|
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
|
|
|
struct platform_data *pdata = dev_get_drvdata(dev);
|
|
|
|
struct temp_data *tdata = pdata->core_data[attr->index];
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
mutex_lock(&tdata->update_lock);
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
/* Check whether the time interval has elapsed */
|
|
|
|
if (!tdata->valid || time_after(jiffies, tdata->last_updated + HZ)) {
|
|
|
|
rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx);
|
|
|
|
tdata->valid = 0;
|
|
|
|
/* Check whether the data is valid */
|
2007-05-08 09:22:02 -06:00
|
|
|
if (eax & 0x80000000) {
|
2011-05-19 13:59:35 -06:00
|
|
|
tdata->temp = tdata->tjmax -
|
2011-05-19 15:45:48 -06:00
|
|
|
((eax >> 16) & 0x7f) * 1000;
|
2011-05-19 13:59:35 -06:00
|
|
|
tdata->valid = 1;
|
2007-05-08 09:22:02 -06:00
|
|
|
}
|
2011-05-19 13:59:35 -06:00
|
|
|
tdata->last_updated = jiffies;
|
2007-05-08 09:22:02 -06:00
|
|
|
}
|
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
mutex_unlock(&tdata->update_lock);
|
|
|
|
return tdata->valid ? sprintf(buf, "%d\n", tdata->temp) : -EAGAIN;
|
2007-05-08 09:22:02 -06:00
|
|
|
}
|
|
|
|
|
2012-06-17 10:05:05 -06:00
|
|
|
struct tjmax {
|
|
|
|
char const *id;
|
|
|
|
int tjmax;
|
|
|
|
};
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static const struct tjmax tjmax_table[] = {
|
2012-10-09 14:23:57 -06:00
|
|
|
{ "CPU 230", 100000 }, /* Model 0x1c, stepping 2 */
|
|
|
|
{ "CPU 330", 125000 }, /* Model 0x1c, stepping 2 */
|
2012-11-16 22:55:24 -07:00
|
|
|
{ "CPU CE4110", 110000 }, /* Model 0x1c, stepping 10 Sodaville */
|
2012-10-09 14:23:57 -06:00
|
|
|
{ "CPU CE4150", 110000 }, /* Model 0x1c, stepping 10 */
|
|
|
|
{ "CPU CE4170", 110000 }, /* Model 0x1c, stepping 10 */
|
2012-06-17 10:05:05 -06:00
|
|
|
};
|
|
|
|
|
2012-10-09 13:45:23 -06:00
|
|
|
struct tjmax_model {
|
|
|
|
u8 model;
|
|
|
|
u8 mask;
|
|
|
|
int tjmax;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ANY 0xff
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static const struct tjmax_model tjmax_model_table[] = {
|
2012-11-16 22:55:24 -07:00
|
|
|
{ 0x1c, 10, 100000 }, /* D4xx, K4xx, N4xx, D5xx, K5xx, N5xx */
|
2012-10-09 13:45:23 -06:00
|
|
|
{ 0x1c, ANY, 90000 }, /* Z5xx, N2xx, possibly others
|
|
|
|
* Note: Also matches 230 and 330,
|
|
|
|
* which are covered by tjmax_table
|
|
|
|
*/
|
|
|
|
{ 0x26, ANY, 90000 }, /* Atom Tunnel Creek (Exx), Lincroft (Z6xx)
|
|
|
|
* Note: TjMax for E6xxT is 110C, but CPU type
|
|
|
|
* is undetectable by software
|
|
|
|
*/
|
|
|
|
{ 0x27, ANY, 90000 }, /* Atom Medfield (Z2460) */
|
2012-11-16 22:55:24 -07:00
|
|
|
{ 0x35, ANY, 90000 }, /* Atom Clover Trail/Cloverview (Z2760) */
|
2012-10-09 13:45:23 -06:00
|
|
|
{ 0x36, ANY, 100000 }, /* Atom Cedar Trail/Cedarview (N2xxx, D2xxx) */
|
|
|
|
};
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static int adjust_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev)
|
2008-02-17 14:59:39 -07:00
|
|
|
{
|
|
|
|
/* The 100C is default for both mobile and non mobile CPUs */
|
|
|
|
|
|
|
|
int tjmax = 100000;
|
2009-09-23 14:59:42 -06:00
|
|
|
int tjmax_ee = 85000;
|
2009-09-23 14:59:42 -06:00
|
|
|
int usemsr_ee = 1;
|
2008-02-17 14:59:39 -07:00
|
|
|
int err;
|
|
|
|
u32 eax, edx;
|
2012-06-17 10:05:05 -06:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* explicit tjmax table entries override heuristics */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(tjmax_table); i++) {
|
|
|
|
if (strstr(c->x86_model_id, tjmax_table[i].id))
|
|
|
|
return tjmax_table[i].tjmax;
|
|
|
|
}
|
2008-02-17 14:59:39 -07:00
|
|
|
|
2012-10-09 13:45:23 -06:00
|
|
|
for (i = 0; i < ARRAY_SIZE(tjmax_model_table); i++) {
|
|
|
|
const struct tjmax_model *tm = &tjmax_model_table[i];
|
|
|
|
if (c->x86_model == tm->model &&
|
|
|
|
(tm->mask == ANY || c->x86_mask == tm->mask))
|
|
|
|
return tm->tjmax;
|
hwmon: (coretemp) Drop dependency on PCI for TjMax detection on Atom CPUs
So far, we use the NM10 Express Chipset PCI chip ID to detect TjMax for
Atom CPUs with model 0x1c. As it turns out, we can use the CPU stepping
(x86_mask) for the same purpose; stepping is 10 for all model 0x1c CPUs
with TjMax of 100 degrees C. This was verified by checking the output of
/proc/cpuinfo for the respective CPUs (D4xx, D5xx, N4xx, N5xx).
Other CPUs currently covered by the same code (Exx, Z6xx, Z2460) are not
supported by the NM10 Express Chipset. Most of those CPUs have TjMax of 90
degrees C, except for E6xxT models which have a TjMax of 110 degrees C.
E6xxT CPUs can however not be detected by software.
Calculate TjMax for Atom CPUs as follows. Note that the listed values are not
correct in some cases (230, 330). tjmax_table is used for those to override
the default values.
ID Stepping TjMax Models
0x1c 10 100 D4xx, N4xx, D5xx, N5xx
0x1c not 10 90 Z5xx, N2xx, 230, 330, others
0x26 - 90 Atom Tunnel Creek (Exx),
Lincroft (Z6xx)
0x27 - 90 Atom Medfield (Z2460)
0x36 - 100 Atom Cedar Trail (N2xxx, D2xxx)
Also drop the module dependency on PCI.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Jean Delvare <khali@linux-fr.org>
2012-10-09 13:27:12 -06:00
|
|
|
}
|
2010-01-10 12:52:34 -07:00
|
|
|
|
hwmon: (coretemp) Drop dependency on PCI for TjMax detection on Atom CPUs
So far, we use the NM10 Express Chipset PCI chip ID to detect TjMax for
Atom CPUs with model 0x1c. As it turns out, we can use the CPU stepping
(x86_mask) for the same purpose; stepping is 10 for all model 0x1c CPUs
with TjMax of 100 degrees C. This was verified by checking the output of
/proc/cpuinfo for the respective CPUs (D4xx, D5xx, N4xx, N5xx).
Other CPUs currently covered by the same code (Exx, Z6xx, Z2460) are not
supported by the NM10 Express Chipset. Most of those CPUs have TjMax of 90
degrees C, except for E6xxT models which have a TjMax of 110 degrees C.
E6xxT CPUs can however not be detected by software.
Calculate TjMax for Atom CPUs as follows. Note that the listed values are not
correct in some cases (230, 330). tjmax_table is used for those to override
the default values.
ID Stepping TjMax Models
0x1c 10 100 D4xx, N4xx, D5xx, N5xx
0x1c not 10 90 Z5xx, N2xx, 230, 330, others
0x26 - 90 Atom Tunnel Creek (Exx),
Lincroft (Z6xx)
0x27 - 90 Atom Medfield (Z2460)
0x36 - 100 Atom Cedar Trail (N2xxx, D2xxx)
Also drop the module dependency on PCI.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Jean Delvare <khali@linux-fr.org>
2012-10-09 13:27:12 -06:00
|
|
|
/* Early chips have no MSR for TjMax */
|
2010-01-10 12:52:34 -07:00
|
|
|
|
hwmon: (coretemp) Drop dependency on PCI for TjMax detection on Atom CPUs
So far, we use the NM10 Express Chipset PCI chip ID to detect TjMax for
Atom CPUs with model 0x1c. As it turns out, we can use the CPU stepping
(x86_mask) for the same purpose; stepping is 10 for all model 0x1c CPUs
with TjMax of 100 degrees C. This was verified by checking the output of
/proc/cpuinfo for the respective CPUs (D4xx, D5xx, N4xx, N5xx).
Other CPUs currently covered by the same code (Exx, Z6xx, Z2460) are not
supported by the NM10 Express Chipset. Most of those CPUs have TjMax of 90
degrees C, except for E6xxT models which have a TjMax of 110 degrees C.
E6xxT CPUs can however not be detected by software.
Calculate TjMax for Atom CPUs as follows. Note that the listed values are not
correct in some cases (230, 330). tjmax_table is used for those to override
the default values.
ID Stepping TjMax Models
0x1c 10 100 D4xx, N4xx, D5xx, N5xx
0x1c not 10 90 Z5xx, N2xx, 230, 330, others
0x26 - 90 Atom Tunnel Creek (Exx),
Lincroft (Z6xx)
0x27 - 90 Atom Medfield (Z2460)
0x36 - 100 Atom Cedar Trail (N2xxx, D2xxx)
Also drop the module dependency on PCI.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Jean Delvare <khali@linux-fr.org>
2012-10-09 13:27:12 -06:00
|
|
|
if (c->x86_model == 0xf && c->x86_mask < 4)
|
2012-06-17 10:05:05 -06:00
|
|
|
usemsr_ee = 0;
|
2009-09-23 14:59:42 -06:00
|
|
|
|
2011-05-19 15:45:48 -06:00
|
|
|
if (c->x86_model > 0xe && usemsr_ee) {
|
2009-09-23 14:59:42 -06:00
|
|
|
u8 platform_id;
|
2008-02-17 14:59:39 -07:00
|
|
|
|
2011-05-19 15:45:48 -06:00
|
|
|
/*
|
|
|
|
* Now we can detect the mobile CPU using Intel provided table
|
|
|
|
* http://softwarecommunity.intel.com/Wiki/Mobility/720.htm
|
|
|
|
* For Core2 cores, check MSR 0x17, bit 28 1 = Mobile CPU
|
|
|
|
*/
|
2008-02-17 14:59:39 -07:00
|
|
|
err = rdmsr_safe_on_cpu(id, 0x17, &eax, &edx);
|
|
|
|
if (err) {
|
|
|
|
dev_warn(dev,
|
|
|
|
"Unable to access MSR 0x17, assuming desktop"
|
|
|
|
" CPU\n");
|
2009-09-23 14:59:42 -06:00
|
|
|
usemsr_ee = 0;
|
2009-09-23 14:59:42 -06:00
|
|
|
} else if (c->x86_model < 0x17 && !(eax & 0x10000000)) {
|
2011-05-19 15:45:48 -06:00
|
|
|
/*
|
|
|
|
* Trust bit 28 up to Penryn, I could not find any
|
|
|
|
* documentation on that; if you happen to know
|
|
|
|
* someone at Intel please ask
|
|
|
|
*/
|
2009-09-23 14:59:42 -06:00
|
|
|
usemsr_ee = 0;
|
2009-09-23 14:59:42 -06:00
|
|
|
} else {
|
|
|
|
/* Platform ID bits 52:50 (EDX starts at bit 32) */
|
|
|
|
platform_id = (edx >> 18) & 0x7;
|
|
|
|
|
2011-05-19 15:45:48 -06:00
|
|
|
/*
|
|
|
|
* Mobile Penryn CPU seems to be platform ID 7 or 5
|
|
|
|
* (guesswork)
|
|
|
|
*/
|
|
|
|
if (c->x86_model == 0x17 &&
|
|
|
|
(platform_id == 5 || platform_id == 7)) {
|
|
|
|
/*
|
|
|
|
* If MSR EE bit is set, set it to 90 degrees C,
|
|
|
|
* otherwise 105 degrees C
|
|
|
|
*/
|
2009-09-23 14:59:42 -06:00
|
|
|
tjmax_ee = 90000;
|
|
|
|
tjmax = 105000;
|
|
|
|
}
|
2008-02-17 14:59:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-23 14:59:42 -06:00
|
|
|
if (usemsr_ee) {
|
2008-02-17 14:59:39 -07:00
|
|
|
err = rdmsr_safe_on_cpu(id, 0xee, &eax, &edx);
|
|
|
|
if (err) {
|
|
|
|
dev_warn(dev,
|
|
|
|
"Unable to access MSR 0xEE, for Tjmax, left"
|
2010-03-29 14:03:00 -06:00
|
|
|
" at default\n");
|
2008-02-17 14:59:39 -07:00
|
|
|
} else if (eax & 0x40000000) {
|
2009-09-23 14:59:42 -06:00
|
|
|
tjmax = tjmax_ee;
|
2008-02-17 14:59:39 -07:00
|
|
|
}
|
2009-09-23 14:59:42 -06:00
|
|
|
} else if (tjmax == 100000) {
|
2011-05-19 15:45:48 -06:00
|
|
|
/*
|
|
|
|
* If we don't use msr EE it means we are desktop CPU
|
|
|
|
* (with exeception of Atom)
|
|
|
|
*/
|
2008-02-17 14:59:39 -07:00
|
|
|
dev_warn(dev, "Using relative temperature scale!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return tjmax;
|
|
|
|
}
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static int get_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev)
|
2010-05-24 15:33:41 -06:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
u32 eax, edx;
|
|
|
|
u32 val;
|
|
|
|
|
2011-05-19 15:45:48 -06:00
|
|
|
/*
|
|
|
|
* A new feature of current Intel(R) processors, the
|
|
|
|
* IA32_TEMPERATURE_TARGET contains the TjMax value
|
|
|
|
*/
|
2010-05-24 15:33:41 -06:00
|
|
|
err = rdmsr_safe_on_cpu(id, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx);
|
|
|
|
if (err) {
|
2011-09-16 13:21:43 -06:00
|
|
|
if (c->x86_model > 0xe && c->x86_model != 0x1c)
|
|
|
|
dev_warn(dev, "Unable to read TjMax from CPU %u\n", id);
|
2010-05-24 15:33:41 -06:00
|
|
|
} else {
|
|
|
|
val = (eax >> 16) & 0xff;
|
|
|
|
/*
|
|
|
|
* If the TjMax is not plausible, an assumption
|
|
|
|
* will be used
|
|
|
|
*/
|
2011-06-01 12:03:41 -06:00
|
|
|
if (val) {
|
2011-09-16 13:21:43 -06:00
|
|
|
dev_dbg(dev, "TjMax is %d degrees C\n", val);
|
2010-05-24 15:33:41 -06:00
|
|
|
return val * 1000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:24:02 -06:00
|
|
|
if (force_tjmax) {
|
|
|
|
dev_notice(dev, "TjMax forced to %d degrees C by user\n",
|
|
|
|
force_tjmax);
|
|
|
|
return force_tjmax * 1000;
|
|
|
|
}
|
|
|
|
|
2010-05-24 15:33:41 -06:00
|
|
|
/*
|
|
|
|
* An assumption is made for early CPUs and unreadable MSR.
|
2011-05-31 07:54:21 -06:00
|
|
|
* NOTE: the calculated value may not be correct.
|
2010-05-24 15:33:41 -06:00
|
|
|
*/
|
2011-05-31 07:54:21 -06:00
|
|
|
return adjust_tjmax(c, id, dev);
|
2010-05-24 15:33:41 -06:00
|
|
|
}
|
|
|
|
|
2012-11-19 11:22:35 -07:00
|
|
|
static int create_name_attr(struct platform_data *pdata,
|
2012-01-16 14:51:47 -07:00
|
|
|
struct device *dev)
|
2011-05-19 13:59:35 -06:00
|
|
|
{
|
2011-05-24 05:28:31 -06:00
|
|
|
sysfs_attr_init(&pdata->name_attr.attr);
|
2011-05-19 13:59:35 -06:00
|
|
|
pdata->name_attr.attr.name = "name";
|
|
|
|
pdata->name_attr.attr.mode = S_IRUGO;
|
|
|
|
pdata->name_attr.show = show_name;
|
|
|
|
return device_create_file(dev, &pdata->name_attr);
|
|
|
|
}
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static int create_core_attrs(struct temp_data *tdata, struct device *dev,
|
|
|
|
int attr_no)
|
2011-05-19 13:59:35 -06:00
|
|
|
{
|
|
|
|
int err, i;
|
2011-09-23 04:36:53 -06:00
|
|
|
static ssize_t (*const rd_ptr[TOTAL_ATTRS]) (struct device *dev,
|
2011-05-19 13:59:35 -06:00
|
|
|
struct device_attribute *devattr, char *buf) = {
|
2011-07-12 05:07:16 -06:00
|
|
|
show_label, show_crit_alarm, show_temp, show_tjmax,
|
hwmon: (coretemp) Don't use threshold registers for tempX_max
With commit c814a4c7c4aad795835583344353963a0a673eb0, the meaning of tempX_max
was changed. It no longer returns the value of bits 8:15 of
MSR_IA32_TEMPERATURE_TARGET, but instead returns the value of CPU threshold
register T1. tempX_max_hyst was added to reflect the value of temperature
threshold register T0.
As it turns out, T0 and T1 are used on some systems, presumably by the BIOS.
Also, T0 and T1 don't have a well defined meaning. The thresholds may be used
as upper or lower limits, and it is not guaranteed that T0 <= T1. Thus, the new
attribute mapping does not reflect the actual usage of the threshold registers.
Also, register contents are changed during runtime by an entity other than the
hwmon driver, meaning the values cached by the driver do not reflect actual
register contents.
Revert most of c814a4c7c4aad795835583344353963a0a673eb0 to address the problem.
Support for T0 and T1 will be added back in with a separate commit, using new
attribute names.
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Durgadoss R <durgadoss.r@intel.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
2011-09-19 22:41:16 -06:00
|
|
|
show_ttarget };
|
2011-09-23 04:36:53 -06:00
|
|
|
static const char *const names[TOTAL_ATTRS] = {
|
2011-05-19 13:59:35 -06:00
|
|
|
"temp%d_label", "temp%d_crit_alarm",
|
2011-07-12 05:07:16 -06:00
|
|
|
"temp%d_input", "temp%d_crit",
|
hwmon: (coretemp) Don't use threshold registers for tempX_max
With commit c814a4c7c4aad795835583344353963a0a673eb0, the meaning of tempX_max
was changed. It no longer returns the value of bits 8:15 of
MSR_IA32_TEMPERATURE_TARGET, but instead returns the value of CPU threshold
register T1. tempX_max_hyst was added to reflect the value of temperature
threshold register T0.
As it turns out, T0 and T1 are used on some systems, presumably by the BIOS.
Also, T0 and T1 don't have a well defined meaning. The thresholds may be used
as upper or lower limits, and it is not guaranteed that T0 <= T1. Thus, the new
attribute mapping does not reflect the actual usage of the threshold registers.
Also, register contents are changed during runtime by an entity other than the
hwmon driver, meaning the values cached by the driver do not reflect actual
register contents.
Revert most of c814a4c7c4aad795835583344353963a0a673eb0 to address the problem.
Support for T0 and T1 will be added back in with a separate commit, using new
attribute names.
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Durgadoss R <durgadoss.r@intel.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
2011-09-19 22:41:16 -06:00
|
|
|
"temp%d_max" };
|
2011-05-19 13:59:35 -06:00
|
|
|
|
2011-07-12 05:07:16 -06:00
|
|
|
for (i = 0; i < tdata->attr_size; i++) {
|
2011-05-19 13:59:35 -06:00
|
|
|
snprintf(tdata->attr_name[i], CORETEMP_NAME_LENGTH, names[i],
|
|
|
|
attr_no);
|
2011-05-24 05:28:31 -06:00
|
|
|
sysfs_attr_init(&tdata->sd_attrs[i].dev_attr.attr);
|
2011-05-19 13:59:35 -06:00
|
|
|
tdata->sd_attrs[i].dev_attr.attr.name = tdata->attr_name[i];
|
|
|
|
tdata->sd_attrs[i].dev_attr.attr.mode = S_IRUGO;
|
|
|
|
tdata->sd_attrs[i].dev_attr.show = rd_ptr[i];
|
|
|
|
tdata->sd_attrs[i].index = attr_no;
|
|
|
|
err = device_create_file(dev, &tdata->sd_attrs[i].dev_attr);
|
|
|
|
if (err)
|
|
|
|
goto exit_free;
|
2007-05-08 09:22:02 -06:00
|
|
|
}
|
2011-05-19 13:59:35 -06:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
exit_free:
|
|
|
|
while (--i >= 0)
|
|
|
|
device_remove_file(dev, &tdata->sd_attrs[i].dev_attr);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static int chk_ucode_version(unsigned int cpu)
|
2011-05-19 13:59:35 -06:00
|
|
|
{
|
2011-09-28 09:11:00 -06:00
|
|
|
struct cpuinfo_x86 *c = &cpu_data(cpu);
|
2007-05-27 14:17:43 -06:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
/*
|
|
|
|
* Check if we have problem with errata AE18 of Core processors:
|
|
|
|
* Readings might stop update when processor visited too deep sleep,
|
|
|
|
* fixed for stepping D0 (6EC).
|
|
|
|
*/
|
2011-10-12 18:46:35 -06:00
|
|
|
if (c->x86_model == 0xe && c->x86_mask < 0xc && c->microcode < 0x39) {
|
2013-01-10 11:01:24 -07:00
|
|
|
pr_err("Errata AE18 not fixed, update BIOS or microcode of the CPU!\n");
|
2011-10-12 18:46:35 -06:00
|
|
|
return -ENODEV;
|
2007-05-27 14:17:43 -06:00
|
|
|
}
|
2011-05-19 13:59:35 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static struct platform_device *coretemp_get_pdev(unsigned int cpu)
|
2011-05-19 13:59:35 -06:00
|
|
|
{
|
|
|
|
u16 phys_proc_id = TO_PHYS_ID(cpu);
|
|
|
|
struct pdev_entry *p;
|
|
|
|
|
|
|
|
mutex_lock(&pdev_list_mutex);
|
|
|
|
|
|
|
|
list_for_each_entry(p, &pdev_list, list)
|
|
|
|
if (p->phys_proc_id == phys_proc_id) {
|
|
|
|
mutex_unlock(&pdev_list_mutex);
|
|
|
|
return p->pdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&pdev_list_mutex);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static struct temp_data *init_temp_data(unsigned int cpu, int pkg_flag)
|
2011-05-19 13:59:35 -06:00
|
|
|
{
|
|
|
|
struct temp_data *tdata;
|
|
|
|
|
|
|
|
tdata = kzalloc(sizeof(struct temp_data), GFP_KERNEL);
|
|
|
|
if (!tdata)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tdata->status_reg = pkg_flag ? MSR_IA32_PACKAGE_THERM_STATUS :
|
|
|
|
MSR_IA32_THERM_STATUS;
|
|
|
|
tdata->is_pkg_data = pkg_flag;
|
|
|
|
tdata->cpu = cpu;
|
|
|
|
tdata->cpu_core_id = TO_CORE_ID(cpu);
|
2011-07-12 05:07:16 -06:00
|
|
|
tdata->attr_size = MAX_CORE_ATTRS;
|
2011-05-19 13:59:35 -06:00
|
|
|
mutex_init(&tdata->update_lock);
|
|
|
|
return tdata;
|
|
|
|
}
|
2007-05-27 14:17:43 -06:00
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static int create_core_data(struct platform_device *pdev, unsigned int cpu,
|
|
|
|
int pkg_flag)
|
2011-05-19 13:59:35 -06:00
|
|
|
{
|
|
|
|
struct temp_data *tdata;
|
2011-09-23 04:40:08 -06:00
|
|
|
struct platform_data *pdata = platform_get_drvdata(pdev);
|
2011-05-19 13:59:35 -06:00
|
|
|
struct cpuinfo_x86 *c = &cpu_data(cpu);
|
|
|
|
u32 eax, edx;
|
|
|
|
int err, attr_no;
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2010-05-24 15:33:41 -06:00
|
|
|
/*
|
2011-05-19 13:59:35 -06:00
|
|
|
* Find attr number for sysfs:
|
|
|
|
* We map the attr number to core id of the CPU
|
|
|
|
* The attr number is always core id + 2
|
|
|
|
* The Pkgtemp will always show up as temp1_*, if available
|
2010-05-24 15:33:41 -06:00
|
|
|
*/
|
2011-05-19 13:59:35 -06:00
|
|
|
attr_no = pkg_flag ? 1 : TO_ATTR_NO(cpu);
|
2008-01-17 16:42:54 -07:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
if (attr_no > MAX_CORE_DATA - 1)
|
|
|
|
return -ERANGE;
|
|
|
|
|
2011-05-23 15:05:38 -06:00
|
|
|
/*
|
|
|
|
* Provide a single set of attributes for all HT siblings of a core
|
|
|
|
* to avoid duplicate sensors (the processor ID and core ID of all
|
2011-05-23 14:52:35 -06:00
|
|
|
* HT siblings of a core are the same).
|
|
|
|
* Skip if a HT sibling of this core is already registered.
|
2011-05-23 15:05:38 -06:00
|
|
|
* This is not an error.
|
|
|
|
*/
|
2011-05-19 13:59:35 -06:00
|
|
|
if (pdata->core_data[attr_no] != NULL)
|
|
|
|
return 0;
|
2008-01-17 16:42:54 -07:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
tdata = init_temp_data(cpu, pkg_flag);
|
|
|
|
if (!tdata)
|
|
|
|
return -ENOMEM;
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
/* Test if we can access the status register */
|
|
|
|
err = rdmsr_safe_on_cpu(cpu, tdata->status_reg, &eax, &edx);
|
|
|
|
if (err)
|
|
|
|
goto exit_free;
|
|
|
|
|
|
|
|
/* We can access status register. Get Critical Temperature */
|
2011-09-16 13:21:43 -06:00
|
|
|
tdata->tjmax = get_tjmax(c, cpu, &pdev->dev);
|
2011-05-19 13:59:35 -06:00
|
|
|
|
2011-07-12 05:07:16 -06:00
|
|
|
/*
|
hwmon: (coretemp) Don't use threshold registers for tempX_max
With commit c814a4c7c4aad795835583344353963a0a673eb0, the meaning of tempX_max
was changed. It no longer returns the value of bits 8:15 of
MSR_IA32_TEMPERATURE_TARGET, but instead returns the value of CPU threshold
register T1. tempX_max_hyst was added to reflect the value of temperature
threshold register T0.
As it turns out, T0 and T1 are used on some systems, presumably by the BIOS.
Also, T0 and T1 don't have a well defined meaning. The thresholds may be used
as upper or lower limits, and it is not guaranteed that T0 <= T1. Thus, the new
attribute mapping does not reflect the actual usage of the threshold registers.
Also, register contents are changed during runtime by an entity other than the
hwmon driver, meaning the values cached by the driver do not reflect actual
register contents.
Revert most of c814a4c7c4aad795835583344353963a0a673eb0 to address the problem.
Support for T0 and T1 will be added back in with a separate commit, using new
attribute names.
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Durgadoss R <durgadoss.r@intel.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
2011-09-19 22:41:16 -06:00
|
|
|
* Read the still undocumented bits 8:15 of IA32_TEMPERATURE_TARGET.
|
|
|
|
* The target temperature is available on older CPUs but not in this
|
|
|
|
* register. Atoms don't have the register at all.
|
2011-07-12 05:07:16 -06:00
|
|
|
*/
|
hwmon: (coretemp) Don't use threshold registers for tempX_max
With commit c814a4c7c4aad795835583344353963a0a673eb0, the meaning of tempX_max
was changed. It no longer returns the value of bits 8:15 of
MSR_IA32_TEMPERATURE_TARGET, but instead returns the value of CPU threshold
register T1. tempX_max_hyst was added to reflect the value of temperature
threshold register T0.
As it turns out, T0 and T1 are used on some systems, presumably by the BIOS.
Also, T0 and T1 don't have a well defined meaning. The thresholds may be used
as upper or lower limits, and it is not guaranteed that T0 <= T1. Thus, the new
attribute mapping does not reflect the actual usage of the threshold registers.
Also, register contents are changed during runtime by an entity other than the
hwmon driver, meaning the values cached by the driver do not reflect actual
register contents.
Revert most of c814a4c7c4aad795835583344353963a0a673eb0 to address the problem.
Support for T0 and T1 will be added back in with a separate commit, using new
attribute names.
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Durgadoss R <durgadoss.r@intel.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
2011-09-19 22:41:16 -06:00
|
|
|
if (c->x86_model > 0xe && c->x86_model != 0x1c) {
|
|
|
|
err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET,
|
|
|
|
&eax, &edx);
|
|
|
|
if (!err) {
|
|
|
|
tdata->ttarget
|
|
|
|
= tdata->tjmax - ((eax >> 8) & 0xff) * 1000;
|
|
|
|
tdata->attr_size++;
|
|
|
|
}
|
2011-07-12 05:07:16 -06:00
|
|
|
}
|
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
pdata->core_data[attr_no] = tdata;
|
|
|
|
|
|
|
|
/* Create sysfs interfaces */
|
|
|
|
err = create_core_attrs(tdata, &pdev->dev, attr_no);
|
|
|
|
if (err)
|
|
|
|
goto exit_free;
|
2007-05-08 09:22:02 -06:00
|
|
|
|
|
|
|
return 0;
|
2011-05-19 13:59:35 -06:00
|
|
|
exit_free:
|
2011-09-24 16:27:04 -06:00
|
|
|
pdata->core_data[attr_no] = NULL;
|
2011-05-19 13:59:35 -06:00
|
|
|
kfree(tdata);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static void coretemp_add_core(unsigned int cpu, int pkg_flag)
|
2011-05-19 13:59:35 -06:00
|
|
|
{
|
|
|
|
struct platform_device *pdev = coretemp_get_pdev(cpu);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (!pdev)
|
|
|
|
return;
|
|
|
|
|
2011-09-23 04:40:08 -06:00
|
|
|
err = create_core_data(pdev, cpu, pkg_flag);
|
2011-05-19 13:59:35 -06:00
|
|
|
if (err)
|
|
|
|
dev_err(&pdev->dev, "Adding Core %u failed\n", cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void coretemp_remove_core(struct platform_data *pdata,
|
|
|
|
struct device *dev, int indx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct temp_data *tdata = pdata->core_data[indx];
|
|
|
|
|
|
|
|
/* Remove the sysfs attributes */
|
2011-07-12 05:07:16 -06:00
|
|
|
for (i = 0; i < tdata->attr_size; i++)
|
2011-05-19 13:59:35 -06:00
|
|
|
device_remove_file(dev, &tdata->sd_attrs[i].dev_attr);
|
|
|
|
|
|
|
|
kfree(pdata->core_data[indx]);
|
|
|
|
pdata->core_data[indx] = NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-19 11:22:35 -07:00
|
|
|
static int coretemp_probe(struct platform_device *pdev)
|
2011-05-19 13:59:35 -06:00
|
|
|
{
|
|
|
|
struct platform_data *pdata;
|
|
|
|
int err;
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
/* Initialize the per-package data structures */
|
|
|
|
pdata = kzalloc(sizeof(struct platform_data), GFP_KERNEL);
|
|
|
|
if (!pdata)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
err = create_name_attr(pdata, &pdev->dev);
|
|
|
|
if (err)
|
|
|
|
goto exit_free;
|
|
|
|
|
2011-09-23 04:35:00 -06:00
|
|
|
pdata->phys_proc_id = pdev->id;
|
2011-05-19 13:59:35 -06:00
|
|
|
platform_set_drvdata(pdev, pdata);
|
|
|
|
|
|
|
|
pdata->hwmon_dev = hwmon_device_register(&pdev->dev);
|
|
|
|
if (IS_ERR(pdata->hwmon_dev)) {
|
|
|
|
err = PTR_ERR(pdata->hwmon_dev);
|
|
|
|
dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
|
|
|
|
goto exit_name;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
exit_name:
|
|
|
|
device_remove_file(&pdev->dev, &pdata->name_attr);
|
2007-05-08 09:22:02 -06:00
|
|
|
exit_free:
|
2011-05-19 13:59:35 -06:00
|
|
|
kfree(pdata);
|
2007-05-08 09:22:02 -06:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-11-19 11:25:51 -07:00
|
|
|
static int coretemp_remove(struct platform_device *pdev)
|
2007-05-08 09:22:02 -06:00
|
|
|
{
|
2011-05-19 13:59:35 -06:00
|
|
|
struct platform_data *pdata = platform_get_drvdata(pdev);
|
|
|
|
int i;
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
for (i = MAX_CORE_DATA - 1; i >= 0; --i)
|
|
|
|
if (pdata->core_data[i])
|
|
|
|
coretemp_remove_core(pdata, &pdev->dev, i);
|
|
|
|
|
|
|
|
device_remove_file(&pdev->dev, &pdata->name_attr);
|
|
|
|
hwmon_device_unregister(pdata->hwmon_dev);
|
|
|
|
kfree(pdata);
|
2007-05-08 09:22:02 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver coretemp_driver = {
|
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = DRVNAME,
|
|
|
|
},
|
|
|
|
.probe = coretemp_probe,
|
2012-11-19 11:21:20 -07:00
|
|
|
.remove = coretemp_remove,
|
2007-05-08 09:22:02 -06:00
|
|
|
};
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static int coretemp_device_add(unsigned int cpu)
|
2007-05-08 09:22:02 -06:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct platform_device *pdev;
|
|
|
|
struct pdev_entry *pdev_entry;
|
2010-07-09 08:22:49 -06:00
|
|
|
|
|
|
|
mutex_lock(&pdev_list_mutex);
|
|
|
|
|
2011-09-23 04:35:00 -06:00
|
|
|
pdev = platform_device_alloc(DRVNAME, TO_PHYS_ID(cpu));
|
2007-05-08 09:22:02 -06:00
|
|
|
if (!pdev) {
|
|
|
|
err = -ENOMEM;
|
2010-10-20 00:51:31 -06:00
|
|
|
pr_err("Device allocation failed\n");
|
2007-05-08 09:22:02 -06:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev_entry = kzalloc(sizeof(struct pdev_entry), GFP_KERNEL);
|
|
|
|
if (!pdev_entry) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto exit_device_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = platform_device_add(pdev);
|
|
|
|
if (err) {
|
2010-10-20 00:51:31 -06:00
|
|
|
pr_err("Device addition failed (%d)\n", err);
|
2007-05-08 09:22:02 -06:00
|
|
|
goto exit_device_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev_entry->pdev = pdev;
|
2011-09-28 09:11:00 -06:00
|
|
|
pdev_entry->phys_proc_id = pdev->id;
|
2011-05-19 13:59:35 -06:00
|
|
|
|
2007-05-08 09:22:02 -06:00
|
|
|
list_add_tail(&pdev_entry->list, &pdev_list);
|
|
|
|
mutex_unlock(&pdev_list_mutex);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
exit_device_free:
|
|
|
|
kfree(pdev_entry);
|
|
|
|
exit_device_put:
|
|
|
|
platform_device_put(pdev);
|
|
|
|
exit:
|
2010-07-09 08:22:49 -06:00
|
|
|
mutex_unlock(&pdev_list_mutex);
|
2007-05-08 09:22:02 -06:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static void coretemp_device_remove(unsigned int cpu)
|
2007-05-08 09:22:02 -06:00
|
|
|
{
|
2011-05-19 13:59:35 -06:00
|
|
|
struct pdev_entry *p, *n;
|
|
|
|
u16 phys_proc_id = TO_PHYS_ID(cpu);
|
2010-09-13 04:23:05 -06:00
|
|
|
|
2007-05-08 09:22:02 -06:00
|
|
|
mutex_lock(&pdev_list_mutex);
|
2011-05-19 13:59:35 -06:00
|
|
|
list_for_each_entry_safe(p, n, &pdev_list, list) {
|
|
|
|
if (p->phys_proc_id != phys_proc_id)
|
2010-09-13 04:23:05 -06:00
|
|
|
continue;
|
|
|
|
platform_device_unregister(p->pdev);
|
|
|
|
list_del(&p->list);
|
|
|
|
kfree(p);
|
2007-05-08 09:22:02 -06:00
|
|
|
}
|
|
|
|
mutex_unlock(&pdev_list_mutex);
|
|
|
|
}
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static bool is_any_core_online(struct platform_data *pdata)
|
2011-05-19 13:59:35 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Find online cores, except pkgtemp data */
|
|
|
|
for (i = MAX_CORE_DATA - 1; i >= 0; --i) {
|
|
|
|
if (pdata->core_data[i] &&
|
|
|
|
!pdata->core_data[i]->is_pkg_data) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static void get_core_online(unsigned int cpu)
|
2011-05-19 13:59:35 -06:00
|
|
|
{
|
|
|
|
struct cpuinfo_x86 *c = &cpu_data(cpu);
|
|
|
|
struct platform_device *pdev = coretemp_get_pdev(cpu);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CPUID.06H.EAX[0] indicates whether the CPU has thermal
|
|
|
|
* sensors. We check this bit only, all the early CPUs
|
|
|
|
* without thermal sensors will be filtered out.
|
|
|
|
*/
|
2012-06-22 11:58:06 -06:00
|
|
|
if (!cpu_has(c, X86_FEATURE_DTHERM))
|
2011-05-19 13:59:35 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!pdev) {
|
2011-09-28 09:11:00 -06:00
|
|
|
/* Check the microcode version of the CPU */
|
|
|
|
if (chk_ucode_version(cpu))
|
|
|
|
return;
|
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
/*
|
|
|
|
* Alright, we have DTS support.
|
|
|
|
* We are bringing the _first_ core in this pkg
|
|
|
|
* online. So, initialize per-pkg data structures and
|
|
|
|
* then bring this core online.
|
|
|
|
*/
|
|
|
|
err = coretemp_device_add(cpu);
|
|
|
|
if (err)
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* Check whether pkgtemp support is available.
|
|
|
|
* If so, add interfaces for pkgtemp.
|
|
|
|
*/
|
|
|
|
if (cpu_has(c, X86_FEATURE_PTS))
|
|
|
|
coretemp_add_core(cpu, 1);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Physical CPU device already exists.
|
|
|
|
* So, just add interfaces for this core.
|
|
|
|
*/
|
|
|
|
coretemp_add_core(cpu, 0);
|
|
|
|
}
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static void put_core_offline(unsigned int cpu)
|
2011-05-19 13:59:35 -06:00
|
|
|
{
|
|
|
|
int i, indx;
|
|
|
|
struct platform_data *pdata;
|
|
|
|
struct platform_device *pdev = coretemp_get_pdev(cpu);
|
|
|
|
|
|
|
|
/* If the physical CPU device does not exist, just return */
|
|
|
|
if (!pdev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pdata = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
indx = TO_ATTR_NO(cpu);
|
|
|
|
|
2012-04-30 07:18:01 -06:00
|
|
|
/* The core id is too big, just return */
|
|
|
|
if (indx > MAX_CORE_DATA - 1)
|
|
|
|
return;
|
|
|
|
|
2011-05-19 13:59:35 -06:00
|
|
|
if (pdata->core_data[indx] && pdata->core_data[indx]->cpu == cpu)
|
|
|
|
coretemp_remove_core(pdata, &pdev->dev, indx);
|
|
|
|
|
2011-05-23 15:05:38 -06:00
|
|
|
/*
|
2011-05-23 14:52:35 -06:00
|
|
|
* If a HT sibling of a core is taken offline, but another HT sibling
|
|
|
|
* of the same core is still online, register the alternate sibling.
|
|
|
|
* This ensures that exactly one set of attributes is provided as long
|
|
|
|
* as at least one HT sibling of a core is online.
|
2011-05-23 15:05:38 -06:00
|
|
|
*/
|
2011-05-23 13:06:41 -06:00
|
|
|
for_each_sibling(i, cpu) {
|
2011-05-19 13:59:35 -06:00
|
|
|
if (i != cpu) {
|
|
|
|
get_core_online(i);
|
2011-05-23 15:05:38 -06:00
|
|
|
/*
|
|
|
|
* Display temperature sensor data for one HT sibling
|
|
|
|
* per core only, so abort the loop after one such
|
|
|
|
* sibling has been found.
|
|
|
|
*/
|
2011-05-19 13:59:35 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If all cores in this pkg are offline, remove the device.
|
|
|
|
* coretemp_device_remove calls unregister_platform_device,
|
|
|
|
* which in turn calls coretemp_remove. This removes the
|
|
|
|
* pkgtemp entry and does other clean ups.
|
|
|
|
*/
|
|
|
|
if (!is_any_core_online(pdata))
|
|
|
|
coretemp_device_remove(cpu);
|
|
|
|
}
|
|
|
|
|
2013-06-19 12:02:20 -06:00
|
|
|
static int coretemp_cpu_callback(struct notifier_block *nfb,
|
2007-05-08 09:22:02 -06:00
|
|
|
unsigned long action, void *hcpu)
|
|
|
|
{
|
|
|
|
unsigned int cpu = (unsigned long) hcpu;
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case CPU_ONLINE:
|
2007-12-03 10:01:50 -07:00
|
|
|
case CPU_DOWN_FAILED:
|
2011-05-19 13:59:35 -06:00
|
|
|
get_core_online(cpu);
|
2007-05-08 09:22:02 -06:00
|
|
|
break;
|
2007-12-03 10:01:50 -07:00
|
|
|
case CPU_DOWN_PREPARE:
|
2011-05-19 13:59:35 -06:00
|
|
|
put_core_offline(cpu);
|
2007-05-08 09:22:02 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-17 05:22:51 -07:00
|
|
|
static struct notifier_block coretemp_cpu_notifier __refdata = {
|
2007-05-08 09:22:02 -06:00
|
|
|
.notifier_call = coretemp_cpu_callback,
|
|
|
|
};
|
|
|
|
|
2012-07-30 03:33:00 -06:00
|
|
|
static const struct x86_cpu_id __initconst coretemp_ids[] = {
|
2012-06-22 11:58:06 -06:00
|
|
|
{ X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_DTHERM },
|
2012-01-25 16:09:10 -07:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(x86cpu, coretemp_ids);
|
|
|
|
|
2007-05-08 09:22:02 -06:00
|
|
|
static int __init coretemp_init(void)
|
|
|
|
{
|
2012-06-17 10:05:06 -06:00
|
|
|
int i, err;
|
2007-05-08 09:22:02 -06:00
|
|
|
|
2012-01-25 16:09:10 -07:00
|
|
|
/*
|
|
|
|
* CPUID.06H.EAX[0] indicates whether the CPU has thermal
|
|
|
|
* sensors. We check this bit only, all the early CPUs
|
|
|
|
* without thermal sensors will be filtered out.
|
|
|
|
*/
|
|
|
|
if (!x86_match_cpu(coretemp_ids))
|
|
|
|
return -ENODEV;
|
2007-05-08 09:22:02 -06:00
|
|
|
|
|
|
|
err = platform_driver_register(&coretemp_driver);
|
|
|
|
if (err)
|
|
|
|
goto exit;
|
|
|
|
|
2012-09-23 12:27:32 -06:00
|
|
|
get_online_cpus();
|
2010-09-23 23:21:34 -06:00
|
|
|
for_each_online_cpu(i)
|
2011-05-19 13:59:35 -06:00
|
|
|
get_core_online(i);
|
2010-09-13 04:05:51 -06:00
|
|
|
|
|
|
|
#ifndef CONFIG_HOTPLUG_CPU
|
2007-05-08 09:22:02 -06:00
|
|
|
if (list_empty(&pdev_list)) {
|
2012-09-23 12:27:32 -06:00
|
|
|
put_online_cpus();
|
2007-05-08 09:22:02 -06:00
|
|
|
err = -ENODEV;
|
|
|
|
goto exit_driver_unreg;
|
|
|
|
}
|
2010-09-13 04:05:51 -06:00
|
|
|
#endif
|
2007-05-08 09:22:02 -06:00
|
|
|
|
|
|
|
register_hotcpu_notifier(&coretemp_cpu_notifier);
|
2012-09-23 12:27:32 -06:00
|
|
|
put_online_cpus();
|
2007-05-08 09:22:02 -06:00
|
|
|
return 0;
|
|
|
|
|
2010-08-09 18:21:09 -06:00
|
|
|
#ifndef CONFIG_HOTPLUG_CPU
|
2010-09-13 04:05:51 -06:00
|
|
|
exit_driver_unreg:
|
2007-05-08 09:22:02 -06:00
|
|
|
platform_driver_unregister(&coretemp_driver);
|
2010-08-09 18:21:09 -06:00
|
|
|
#endif
|
2007-05-08 09:22:02 -06:00
|
|
|
exit:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit coretemp_exit(void)
|
|
|
|
{
|
|
|
|
struct pdev_entry *p, *n;
|
2010-10-08 20:01:48 -06:00
|
|
|
|
2012-09-23 12:27:32 -06:00
|
|
|
get_online_cpus();
|
2007-05-08 09:22:02 -06:00
|
|
|
unregister_hotcpu_notifier(&coretemp_cpu_notifier);
|
|
|
|
mutex_lock(&pdev_list_mutex);
|
|
|
|
list_for_each_entry_safe(p, n, &pdev_list, list) {
|
|
|
|
platform_device_unregister(p->pdev);
|
|
|
|
list_del(&p->list);
|
|
|
|
kfree(p);
|
|
|
|
}
|
|
|
|
mutex_unlock(&pdev_list_mutex);
|
2012-09-23 12:27:32 -06:00
|
|
|
put_online_cpus();
|
2007-05-08 09:22:02 -06:00
|
|
|
platform_driver_unregister(&coretemp_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Rudolf Marek <r.marek@assembler.cz>");
|
|
|
|
MODULE_DESCRIPTION("Intel Core temperature monitor");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_init(coretemp_init)
|
|
|
|
module_exit(coretemp_exit)
|