23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/module.h>
27 #include <linux/slab.h>
34 #include <linux/list.h>
37 #include <linux/pci.h>
41 #include <asm/processor.h>
44 #define DRVNAME "coretemp"
50 static int force_tjmax;
54 #define BASE_SYSFS_ATTR_NO 2
55 #define NUM_REAL_CORES 32
56 #define CORETEMP_NAME_LENGTH 17
57 #define MAX_CORE_ATTRS 4
58 #define TOTAL_ATTRS (MAX_CORE_ATTRS + 1)
59 #define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO)
61 #define TO_PHYS_ID(cpu) (cpu_data(cpu).phys_proc_id)
62 #define TO_CORE_ID(cpu) (cpu_data(cpu).cpu_core_id)
63 #define TO_ATTR_NO(cpu) (TO_CORE_ID(cpu) + BASE_SYSFS_ATTR_NO)
66 #define for_each_sibling(i, cpu) for_each_cpu(i, cpu_sibling_mask(cpu))
68 #define for_each_sibling(i, cpu) for (i = 0; false; )
146 return sprintf(buf,
"%d\n", (eax >> 5) & 1);
182 if (eax & 0x80000000) {
184 ((eax >> 16) & 0x7f) * 1000;
200 {
"CPU D410", 100000 },
201 {
"CPU D425", 100000 },
202 {
"CPU D510", 100000 },
203 {
"CPU D525", 100000 },
204 {
"CPU N450", 100000 },
205 {
"CPU N455", 100000 },
206 {
"CPU N470", 100000 },
207 {
"CPU N475", 100000 },
208 {
"CPU 230", 100000 },
209 {
"CPU 330", 125000 },
210 {
"CPU CE4110", 110000 },
211 {
"CPU CE4150", 110000 },
212 {
"CPU CE4170", 110000 },
221 int tjmax_ee = 85000;
229 for (i = 0; i <
ARRAY_SIZE(tjmax_table); i++) {
231 return tjmax_table[i].tjmax;
248 && (host_bridge->
device == 0xa000
249 || host_bridge->
device == 0xa010))
271 "Unable to access MSR 0x17, assuming desktop"
274 }
else if (c->
x86_model < 0x17 && !(eax & 0x10000000)) {
283 platform_id = (edx >> 18) & 0x7;
290 (platform_id == 5 || platform_id == 7)) {
305 "Unable to access MSR 0xEE, for Tjmax, left"
307 }
else if (eax & 0x40000000) {
310 }
else if (tjmax == 100000) {
315 dev_warn(dev,
"Using relative temperature scale!\n");
335 dev_warn(dev,
"Unable to read TjMax from CPU %u\n",
id);
337 val = (eax >> 16) & 0xff;
343 dev_dbg(dev,
"TjMax is %d degrees C\n", val);
349 dev_notice(dev,
"TjMax forced to %d degrees C by user\n",
351 return force_tjmax * 1000;
358 return adjust_tjmax(c,
id, dev);
372 struct device *dev,
int attr_no)
377 show_label, show_crit_alarm,
show_temp, show_tjmax,
380 "temp%d_label",
"temp%d_crit_alarm",
381 "temp%d_input",
"temp%d_crit",
405 static int __cpuinit chk_ucode_version(
unsigned int cpu)
415 pr_err(
"Errata AE18 not fixed, update BIOS or "
416 "microcode of the CPU!\n");
430 if (p->phys_proc_id == phys_proc_id) {
459 unsigned int cpu,
int pkg_flag)
488 tdata = init_temp_data(cpu, pkg_flag);
498 tdata->
tjmax = get_tjmax(c, cpu, &pdev->
dev);
510 = tdata->
tjmax - ((eax >> 8) & 0xff) * 1000;
518 err = create_core_attrs(tdata, &pdev->
dev, attr_no);
529 static void __cpuinit coretemp_add_core(
unsigned int cpu,
int pkg_flag)
537 err = create_core_data(pdev, cpu, pkg_flag);
539 dev_err(&pdev->
dev,
"Adding Core %u failed\n", cpu);
542 static void coretemp_remove_core(
struct platform_data *pdata,
543 struct device *dev,
int indx)
566 err = create_name_attr(pdata, &pdev->
dev);
571 platform_set_drvdata(pdev, pdata);
576 dev_err(&pdev->
dev,
"Class registration failed (%d)\n", err);
583 platform_set_drvdata(pdev,
NULL);
596 coretemp_remove_core(pdata, &pdev->
dev, i);
600 platform_set_drvdata(pdev,
NULL);
610 .probe = coretemp_probe,
614 static int __cpuinit coretemp_device_add(
unsigned int cpu)
625 pr_err(
"Device allocation failed\n");
629 pdev_entry = kzalloc(
sizeof(
struct pdev_entry),
GFP_KERNEL);
632 goto exit_device_put;
637 pr_err(
"Device addition failed (%d)\n", err);
638 goto exit_device_free;
658 static void __cpuinit coretemp_device_remove(
unsigned int cpu)
660 struct pdev_entry *
p, *
n;
688 static void __cpuinit get_core_online(
unsigned int cpu)
704 if (chk_ucode_version(cpu))
713 err = coretemp_device_add(cpu);
721 coretemp_add_core(cpu, 1);
727 coretemp_add_core(cpu, 0);
730 static void __cpuinit put_core_offline(
unsigned int cpu)
740 pdata = platform_get_drvdata(pdev);
749 coretemp_remove_core(pdata, &pdev->
dev, indx);
774 if (!is_any_core_online(pdata))
775 coretemp_device_remove(cpu);
779 unsigned long action,
void *hcpu)
781 unsigned int cpu = (
unsigned long) hcpu;
786 get_core_online(cpu);
789 put_core_offline(cpu);
796 .notifier_call = coretemp_cpu_callback,
805 static int __init coretemp_init(
void)
825 #ifndef CONFIG_HOTPLUG_CPU
826 if (list_empty(&pdev_list)) {
829 goto exit_driver_unreg;
837 #ifndef CONFIG_HOTPLUG_CPU
845 static void __exit coretemp_exit(
void)
847 struct pdev_entry *
p, *
n;