mce_intel.c 2.3 KB

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