mce_intel.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Intel specific MCE features.
  3. * Copyright 2004 Zwane Mwaikambo <zwane@linuxpower.ca>
  4. */
  5. #include <linux/init.h>
  6. #include <linux/interrupt.h>
  7. #include <linux/percpu.h>
  8. #include <asm/processor.h>
  9. #include <asm/msr.h>
  10. #include <asm/mce.h>
  11. #include <asm/hw_irq.h>
  12. static DEFINE_PER_CPU(unsigned long, next_check);
  13. asmlinkage void smp_thermal_interrupt(void)
  14. {
  15. struct mce m;
  16. ack_APIC_irq();
  17. irq_enter();
  18. if (time_before(jiffies, __get_cpu_var(next_check)))
  19. goto done;
  20. __get_cpu_var(next_check) = jiffies + HZ*300;
  21. memset(&m, 0, sizeof(m));
  22. m.cpu = smp_processor_id();
  23. m.bank = MCE_THERMAL_BANK;
  24. rdtscll(m.tsc);
  25. rdmsrl(MSR_IA32_THERM_STATUS, m.status);
  26. if (m.status & 0x1) {
  27. printk(KERN_EMERG
  28. "CPU%d: Temperature above threshold, cpu clock throttled\n", m.cpu);
  29. add_taint(TAINT_MACHINE_CHECK);
  30. } else {
  31. printk(KERN_EMERG "CPU%d: Temperature/speed normal\n", m.cpu);
  32. }
  33. mce_log(&m);
  34. done:
  35. irq_exit();
  36. }
  37. static void __cpuinit intel_init_thermal(struct cpuinfo_x86 *c)
  38. {
  39. u32 l, h;
  40. int tm2 = 0;
  41. unsigned int cpu = smp_processor_id();
  42. if (!cpu_has(c, X86_FEATURE_ACPI))
  43. return;
  44. if (!cpu_has(c, X86_FEATURE_ACC))
  45. return;
  46. /* first check if TM1 is already enabled by the BIOS, in which
  47. * case there might be some SMM goo which handles it, so we can't even
  48. * put a handler since it might be delivered via SMI already.
  49. */
  50. rdmsr(MSR_IA32_MISC_ENABLE, l, h);
  51. h = apic_read(APIC_LVTTHMR);
  52. if ((l & (1 << 3)) && (h & APIC_DM_SMI)) {
  53. printk(KERN_DEBUG
  54. "CPU%d: Thermal monitoring handled by SMI\n", cpu);
  55. return;
  56. }
  57. if (cpu_has(c, X86_FEATURE_TM2) && (l & (1 << 13)))
  58. tm2 = 1;
  59. if (h & APIC_VECTOR_MASK) {
  60. printk(KERN_DEBUG
  61. "CPU%d: Thermal LVT vector (%#x) already "
  62. "installed\n", cpu, (h & APIC_VECTOR_MASK));
  63. return;
  64. }
  65. h = THERMAL_APIC_VECTOR;
  66. h |= (APIC_DM_FIXED | APIC_LVT_MASKED);
  67. apic_write_around(APIC_LVTTHMR, h);
  68. rdmsr(MSR_IA32_THERM_INTERRUPT, l, h);
  69. wrmsr(MSR_IA32_THERM_INTERRUPT, l | 0x03, h);
  70. rdmsr(MSR_IA32_MISC_ENABLE, l, h);
  71. wrmsr(MSR_IA32_MISC_ENABLE, l | (1 << 3), h);
  72. l = apic_read(APIC_LVTTHMR);
  73. apic_write_around(APIC_LVTTHMR, l & ~APIC_LVT_MASKED);
  74. printk(KERN_INFO "CPU%d: Thermal monitoring enabled (%s)\n",
  75. cpu, tm2 ? "TM2" : "TM1");
  76. return;
  77. }
  78. void __cpuinit mce_intel_feature_init(struct cpuinfo_x86 *c)
  79. {
  80. intel_init_thermal(c);
  81. }