p4.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * P4 specific Machine Check Exception Reporting
  3. */
  4. #include <linux/init.h>
  5. #include <linux/types.h>
  6. #include <linux/kernel.h>
  7. #include <linux/config.h>
  8. #include <linux/irq.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/smp.h>
  11. #include <asm/processor.h>
  12. #include <asm/system.h>
  13. #include <asm/msr.h>
  14. #include <asm/apic.h>
  15. #include "mce.h"
  16. /* as supported by the P4/Xeon family */
  17. struct intel_mce_extended_msrs {
  18. u32 eax;
  19. u32 ebx;
  20. u32 ecx;
  21. u32 edx;
  22. u32 esi;
  23. u32 edi;
  24. u32 ebp;
  25. u32 esp;
  26. u32 eflags;
  27. u32 eip;
  28. /* u32 *reserved[]; */
  29. };
  30. static int mce_num_extended_msrs = 0;
  31. #ifdef CONFIG_X86_MCE_P4THERMAL
  32. static void unexpected_thermal_interrupt(struct pt_regs *regs)
  33. {
  34. printk(KERN_ERR "CPU%d: Unexpected LVT TMR interrupt!\n",
  35. smp_processor_id());
  36. add_taint(TAINT_MACHINE_CHECK);
  37. }
  38. /* P4/Xeon Thermal transition interrupt handler */
  39. static void intel_thermal_interrupt(struct pt_regs *regs)
  40. {
  41. u32 l, h;
  42. unsigned int cpu = smp_processor_id();
  43. static unsigned long next[NR_CPUS];
  44. ack_APIC_irq();
  45. if (time_after(next[cpu], jiffies))
  46. return;
  47. next[cpu] = jiffies + HZ*5;
  48. rdmsr(MSR_IA32_THERM_STATUS, l, h);
  49. if (l & 0x1) {
  50. printk(KERN_EMERG "CPU%d: Temperature above threshold\n", cpu);
  51. printk(KERN_EMERG "CPU%d: Running in modulated clock mode\n",
  52. cpu);
  53. add_taint(TAINT_MACHINE_CHECK);
  54. } else {
  55. printk(KERN_INFO "CPU%d: Temperature/speed normal\n", cpu);
  56. }
  57. }
  58. /* Thermal interrupt handler for this CPU setup */
  59. static void (*vendor_thermal_interrupt)(struct pt_regs *regs) = unexpected_thermal_interrupt;
  60. fastcall void smp_thermal_interrupt(struct pt_regs *regs)
  61. {
  62. irq_enter();
  63. vendor_thermal_interrupt(regs);
  64. irq_exit();
  65. }
  66. /* P4/Xeon Thermal regulation detect and init */
  67. static void __devinit intel_init_thermal(struct cpuinfo_x86 *c)
  68. {
  69. u32 l, h;
  70. unsigned int cpu = smp_processor_id();
  71. /* Thermal monitoring */
  72. if (!cpu_has(c, X86_FEATURE_ACPI))
  73. return; /* -ENODEV */
  74. /* Clock modulation */
  75. if (!cpu_has(c, X86_FEATURE_ACC))
  76. return; /* -ENODEV */
  77. /* first check if its enabled already, in which case there might
  78. * be some SMM goo which handles it, so we can't even put a handler
  79. * since it might be delivered via SMI already -zwanem.
  80. */
  81. rdmsr (MSR_IA32_MISC_ENABLE, l, h);
  82. h = apic_read(APIC_LVTTHMR);
  83. if ((l & (1<<3)) && (h & APIC_DM_SMI)) {
  84. printk(KERN_DEBUG "CPU%d: Thermal monitoring handled by SMI\n",
  85. cpu);
  86. return; /* -EBUSY */
  87. }
  88. /* check whether a vector already exists, temporarily masked? */
  89. if (h & APIC_VECTOR_MASK) {
  90. printk(KERN_DEBUG "CPU%d: Thermal LVT vector (%#x) already "
  91. "installed\n",
  92. cpu, (h & APIC_VECTOR_MASK));
  93. return; /* -EBUSY */
  94. }
  95. /* The temperature transition interrupt handler setup */
  96. h = THERMAL_APIC_VECTOR; /* our delivery vector */
  97. h |= (APIC_DM_FIXED | APIC_LVT_MASKED); /* we'll mask till we're ready */
  98. apic_write_around(APIC_LVTTHMR, h);
  99. rdmsr (MSR_IA32_THERM_INTERRUPT, l, h);
  100. wrmsr (MSR_IA32_THERM_INTERRUPT, l | 0x03 , h);
  101. /* ok we're good to go... */
  102. vendor_thermal_interrupt = intel_thermal_interrupt;
  103. rdmsr (MSR_IA32_MISC_ENABLE, l, h);
  104. wrmsr (MSR_IA32_MISC_ENABLE, l | (1<<3), h);
  105. l = apic_read (APIC_LVTTHMR);
  106. apic_write_around (APIC_LVTTHMR, l & ~APIC_LVT_MASKED);
  107. printk (KERN_INFO "CPU%d: Thermal monitoring enabled\n", cpu);
  108. return;
  109. }
  110. #endif /* CONFIG_X86_MCE_P4THERMAL */
  111. /* P4/Xeon Extended MCE MSR retrieval, return 0 if unsupported */
  112. static inline int intel_get_extended_msrs(struct intel_mce_extended_msrs *r)
  113. {
  114. u32 h;
  115. if (mce_num_extended_msrs == 0)
  116. goto done;
  117. rdmsr (MSR_IA32_MCG_EAX, r->eax, h);
  118. rdmsr (MSR_IA32_MCG_EBX, r->ebx, h);
  119. rdmsr (MSR_IA32_MCG_ECX, r->ecx, h);
  120. rdmsr (MSR_IA32_MCG_EDX, r->edx, h);
  121. rdmsr (MSR_IA32_MCG_ESI, r->esi, h);
  122. rdmsr (MSR_IA32_MCG_EDI, r->edi, h);
  123. rdmsr (MSR_IA32_MCG_EBP, r->ebp, h);
  124. rdmsr (MSR_IA32_MCG_ESP, r->esp, h);
  125. rdmsr (MSR_IA32_MCG_EFLAGS, r->eflags, h);
  126. rdmsr (MSR_IA32_MCG_EIP, r->eip, h);
  127. /* can we rely on kmalloc to do a dynamic
  128. * allocation for the reserved registers?
  129. */
  130. done:
  131. return mce_num_extended_msrs;
  132. }
  133. static fastcall void intel_machine_check(struct pt_regs * regs, long error_code)
  134. {
  135. int recover=1;
  136. u32 alow, ahigh, high, low;
  137. u32 mcgstl, mcgsth;
  138. int i;
  139. struct intel_mce_extended_msrs dbg;
  140. rdmsr (MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
  141. if (mcgstl & (1<<0)) /* Recoverable ? */
  142. recover=0;
  143. printk (KERN_EMERG "CPU %d: Machine Check Exception: %08x%08x\n",
  144. smp_processor_id(), mcgsth, mcgstl);
  145. if (intel_get_extended_msrs(&dbg)) {
  146. printk (KERN_DEBUG "CPU %d: EIP: %08x EFLAGS: %08x\n",
  147. smp_processor_id(), dbg.eip, dbg.eflags);
  148. printk (KERN_DEBUG "\teax: %08x ebx: %08x ecx: %08x edx: %08x\n",
  149. dbg.eax, dbg.ebx, dbg.ecx, dbg.edx);
  150. printk (KERN_DEBUG "\tesi: %08x edi: %08x ebp: %08x esp: %08x\n",
  151. dbg.esi, dbg.edi, dbg.ebp, dbg.esp);
  152. }
  153. for (i=0; i<nr_mce_banks; i++) {
  154. rdmsr (MSR_IA32_MC0_STATUS+i*4,low, high);
  155. if (high & (1<<31)) {
  156. if (high & (1<<29))
  157. recover |= 1;
  158. if (high & (1<<25))
  159. recover |= 2;
  160. printk (KERN_EMERG "Bank %d: %08x%08x", i, high, low);
  161. high &= ~(1<<31);
  162. if (high & (1<<27)) {
  163. rdmsr (MSR_IA32_MC0_MISC+i*4, alow, ahigh);
  164. printk ("[%08x%08x]", ahigh, alow);
  165. }
  166. if (high & (1<<26)) {
  167. rdmsr (MSR_IA32_MC0_ADDR+i*4, alow, ahigh);
  168. printk (" at %08x%08x", ahigh, alow);
  169. }
  170. printk ("\n");
  171. }
  172. }
  173. if (recover & 2)
  174. panic ("CPU context corrupt");
  175. if (recover & 1)
  176. panic ("Unable to continue");
  177. printk(KERN_EMERG "Attempting to continue.\n");
  178. /*
  179. * Do not clear the MSR_IA32_MCi_STATUS if the error is not
  180. * recoverable/continuable.This will allow BIOS to look at the MSRs
  181. * for errors if the OS could not log the error.
  182. */
  183. for (i=0; i<nr_mce_banks; i++) {
  184. u32 msr;
  185. msr = MSR_IA32_MC0_STATUS+i*4;
  186. rdmsr (msr, low, high);
  187. if (high&(1<<31)) {
  188. /* Clear it */
  189. wrmsr(msr, 0UL, 0UL);
  190. /* Serialize */
  191. wmb();
  192. add_taint(TAINT_MACHINE_CHECK);
  193. }
  194. }
  195. mcgstl &= ~(1<<2);
  196. wrmsr (MSR_IA32_MCG_STATUS,mcgstl, mcgsth);
  197. }
  198. void __devinit intel_p4_mcheck_init(struct cpuinfo_x86 *c)
  199. {
  200. u32 l, h;
  201. int i;
  202. machine_check_vector = intel_machine_check;
  203. wmb();
  204. printk (KERN_INFO "Intel machine check architecture supported.\n");
  205. rdmsr (MSR_IA32_MCG_CAP, l, h);
  206. if (l & (1<<8)) /* Control register present ? */
  207. wrmsr (MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
  208. nr_mce_banks = l & 0xff;
  209. for (i=0; i<nr_mce_banks; i++) {
  210. wrmsr (MSR_IA32_MC0_CTL+4*i, 0xffffffff, 0xffffffff);
  211. wrmsr (MSR_IA32_MC0_STATUS+4*i, 0x0, 0x0);
  212. }
  213. set_in_cr4 (X86_CR4_MCE);
  214. printk (KERN_INFO "Intel machine check reporting enabled on CPU#%d.\n",
  215. smp_processor_id());
  216. /* Check for P4/Xeon extended MCE MSRs */
  217. rdmsr (MSR_IA32_MCG_CAP, l, h);
  218. if (l & (1<<9)) {/* MCG_EXT_P */
  219. mce_num_extended_msrs = (l >> 16) & 0xff;
  220. printk (KERN_INFO "CPU%d: Intel P4/Xeon Extended MCE MSRs (%d)"
  221. " available\n",
  222. smp_processor_id(), mce_num_extended_msrs);
  223. #ifdef CONFIG_X86_MCE_P4THERMAL
  224. /* Check for P4/Xeon Thermal monitor */
  225. intel_init_thermal(c);
  226. #endif
  227. }
  228. }