p4.c 6.8 KB

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