p4.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * P4 specific Machine Check Exception Reporting
  3. */
  4. #include <linux/interrupt.h>
  5. #include <linux/kernel.h>
  6. #include <linux/types.h>
  7. #include <linux/init.h>
  8. #include <linux/smp.h>
  9. #include <asm/therm_throt.h>
  10. #include <asm/processor.h>
  11. #include <asm/system.h>
  12. #include <asm/apic.h>
  13. #include <asm/msr.h>
  14. #include "mce.h"
  15. /* as supported by the P4/Xeon family */
  16. struct intel_mce_extended_msrs {
  17. u32 eax;
  18. u32 ebx;
  19. u32 ecx;
  20. u32 edx;
  21. u32 esi;
  22. u32 edi;
  23. u32 ebp;
  24. u32 esp;
  25. u32 eflags;
  26. u32 eip;
  27. /* u32 *reserved[]; */
  28. };
  29. static int mce_num_extended_msrs;
  30. #ifdef CONFIG_X86_MCE_P4THERMAL
  31. static void unexpected_thermal_interrupt(struct pt_regs *regs)
  32. {
  33. printk(KERN_ERR "CPU%d: Unexpected LVT TMR interrupt!\n",
  34. smp_processor_id());
  35. add_taint(TAINT_MACHINE_CHECK);
  36. }
  37. /* P4/Xeon Thermal transition interrupt handler: */
  38. static void intel_thermal_interrupt(struct pt_regs *regs)
  39. {
  40. __u64 msr_val;
  41. ack_APIC_irq();
  42. rdmsrl(MSR_IA32_THERM_STATUS, msr_val);
  43. therm_throt_process(msr_val & THERM_STATUS_PROCHOT);
  44. }
  45. /* Thermal interrupt handler for this CPU setup: */
  46. static void (*vendor_thermal_interrupt)(struct pt_regs *regs) =
  47. unexpected_thermal_interrupt;
  48. void smp_thermal_interrupt(struct pt_regs *regs)
  49. {
  50. irq_enter();
  51. vendor_thermal_interrupt(regs);
  52. __get_cpu_var(irq_stat).irq_thermal_count++;
  53. irq_exit();
  54. }
  55. void intel_set_thermal_handler(void)
  56. {
  57. vendor_thermal_interrupt = intel_thermal_interrupt;
  58. }
  59. #endif /* CONFIG_X86_MCE_P4THERMAL */
  60. /* P4/Xeon Extended MCE MSR retrieval, return 0 if unsupported */
  61. static void intel_get_extended_msrs(struct intel_mce_extended_msrs *r)
  62. {
  63. u32 h;
  64. rdmsr(MSR_IA32_MCG_EAX, r->eax, h);
  65. rdmsr(MSR_IA32_MCG_EBX, r->ebx, h);
  66. rdmsr(MSR_IA32_MCG_ECX, r->ecx, h);
  67. rdmsr(MSR_IA32_MCG_EDX, r->edx, h);
  68. rdmsr(MSR_IA32_MCG_ESI, r->esi, h);
  69. rdmsr(MSR_IA32_MCG_EDI, r->edi, h);
  70. rdmsr(MSR_IA32_MCG_EBP, r->ebp, h);
  71. rdmsr(MSR_IA32_MCG_ESP, r->esp, h);
  72. rdmsr(MSR_IA32_MCG_EFLAGS, r->eflags, h);
  73. rdmsr(MSR_IA32_MCG_EIP, r->eip, h);
  74. }
  75. static void intel_machine_check(struct pt_regs *regs, long error_code)
  76. {
  77. u32 alow, ahigh, high, low;
  78. u32 mcgstl, mcgsth;
  79. int recover = 1;
  80. int i;
  81. rdmsr(MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
  82. if (mcgstl & (1<<0)) /* Recoverable ? */
  83. recover = 0;
  84. printk(KERN_EMERG "CPU %d: Machine Check Exception: %08x%08x\n",
  85. smp_processor_id(), mcgsth, mcgstl);
  86. if (mce_num_extended_msrs > 0) {
  87. struct intel_mce_extended_msrs dbg;
  88. intel_get_extended_msrs(&dbg);
  89. printk(KERN_DEBUG "CPU %d: EIP: %08x EFLAGS: %08x\n"
  90. "\teax: %08x ebx: %08x ecx: %08x edx: %08x\n"
  91. "\tesi: %08x edi: %08x ebp: %08x esp: %08x\n",
  92. smp_processor_id(), dbg.eip, dbg.eflags,
  93. dbg.eax, dbg.ebx, dbg.ecx, dbg.edx,
  94. dbg.esi, dbg.edi, dbg.ebp, dbg.esp);
  95. }
  96. for (i = 0; i < nr_mce_banks; i++) {
  97. rdmsr(MSR_IA32_MC0_STATUS+i*4, low, high);
  98. if (high & (1<<31)) {
  99. char misc[20];
  100. char addr[24];
  101. misc[0] = addr[0] = '\0';
  102. if (high & (1<<29))
  103. recover |= 1;
  104. if (high & (1<<25))
  105. recover |= 2;
  106. high &= ~(1<<31);
  107. if (high & (1<<27)) {
  108. rdmsr(MSR_IA32_MC0_MISC+i*4, alow, ahigh);
  109. snprintf(misc, 20, "[%08x%08x]", ahigh, alow);
  110. }
  111. if (high & (1<<26)) {
  112. rdmsr(MSR_IA32_MC0_ADDR+i*4, alow, ahigh);
  113. snprintf(addr, 24, " at %08x%08x", ahigh, alow);
  114. }
  115. printk(KERN_EMERG "CPU %d: Bank %d: %08x%08x%s%s\n",
  116. smp_processor_id(), i, high, low, misc, addr);
  117. }
  118. }
  119. if (recover & 2)
  120. panic("CPU context corrupt");
  121. if (recover & 1)
  122. panic("Unable to continue");
  123. printk(KERN_EMERG "Attempting to continue.\n");
  124. /*
  125. * Do not clear the MSR_IA32_MCi_STATUS if the error is not
  126. * recoverable/continuable.This will allow BIOS to look at the MSRs
  127. * for errors if the OS could not log the error.
  128. */
  129. for (i = 0; i < nr_mce_banks; i++) {
  130. u32 msr;
  131. msr = MSR_IA32_MC0_STATUS+i*4;
  132. rdmsr(msr, low, high);
  133. if (high&(1<<31)) {
  134. /* Clear it */
  135. wrmsr(msr, 0UL, 0UL);
  136. /* Serialize */
  137. wmb();
  138. add_taint(TAINT_MACHINE_CHECK);
  139. }
  140. }
  141. mcgstl &= ~(1<<2);
  142. wrmsr(MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
  143. }
  144. void intel_p4_mcheck_init(struct cpuinfo_x86 *c)
  145. {
  146. u32 l, h;
  147. int i;
  148. machine_check_vector = intel_machine_check;
  149. wmb();
  150. printk(KERN_INFO "Intel machine check architecture supported.\n");
  151. rdmsr(MSR_IA32_MCG_CAP, l, h);
  152. if (l & (1<<8)) /* Control register present ? */
  153. wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
  154. nr_mce_banks = l & 0xff;
  155. for (i = 0; i < nr_mce_banks; i++) {
  156. wrmsr(MSR_IA32_MC0_CTL+4*i, 0xffffffff, 0xffffffff);
  157. wrmsr(MSR_IA32_MC0_STATUS+4*i, 0x0, 0x0);
  158. }
  159. set_in_cr4(X86_CR4_MCE);
  160. printk(KERN_INFO "Intel machine check reporting enabled on CPU#%d.\n",
  161. smp_processor_id());
  162. /* Check for P4/Xeon extended MCE MSRs */
  163. rdmsr(MSR_IA32_MCG_CAP, l, h);
  164. if (l & (1<<9)) {/* MCG_EXT_P */
  165. mce_num_extended_msrs = (l >> 16) & 0xff;
  166. printk(KERN_INFO "CPU%d: Intel P4/Xeon Extended MCE MSRs (%d)"
  167. " available\n",
  168. smp_processor_id(), mce_num_extended_msrs);
  169. #ifdef CONFIG_X86_MCE_P4THERMAL
  170. /* Check for P4/Xeon Thermal monitor */
  171. intel_init_thermal(c);
  172. #endif
  173. }
  174. }