p6.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * P6 specific Machine Check Exception Reporting
  3. * (C) Copyright 2002 Alan Cox <alan@lxorguk.ukuu.org.uk>
  4. */
  5. #include <linux/interrupt.h>
  6. #include <linux/kernel.h>
  7. #include <linux/types.h>
  8. #include <linux/init.h>
  9. #include <linux/smp.h>
  10. #include <asm/processor.h>
  11. #include <asm/system.h>
  12. #include <asm/mce.h>
  13. #include <asm/msr.h>
  14. /* Machine Check Handler For PII/PIII */
  15. static void intel_machine_check(struct pt_regs *regs, long error_code)
  16. {
  17. u32 alow, ahigh, high, low;
  18. u32 mcgstl, mcgsth;
  19. int recover = 1;
  20. int i;
  21. rdmsr(MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
  22. if (mcgstl & (1<<0)) /* Recoverable ? */
  23. recover = 0;
  24. printk(KERN_EMERG "CPU %d: Machine Check Exception: %08x%08x\n",
  25. smp_processor_id(), mcgsth, mcgstl);
  26. for (i = 0; i < nr_mce_banks; i++) {
  27. rdmsr(MSR_IA32_MC0_STATUS+i*4, low, high);
  28. if (high & (1<<31)) {
  29. char misc[20];
  30. char addr[24];
  31. misc[0] = '\0';
  32. addr[0] = '\0';
  33. if (high & (1<<29))
  34. recover |= 1;
  35. if (high & (1<<25))
  36. recover |= 2;
  37. high &= ~(1<<31);
  38. if (high & (1<<27)) {
  39. rdmsr(MSR_IA32_MC0_MISC+i*4, alow, ahigh);
  40. snprintf(misc, 20, "[%08x%08x]", ahigh, alow);
  41. }
  42. if (high & (1<<26)) {
  43. rdmsr(MSR_IA32_MC0_ADDR+i*4, alow, ahigh);
  44. snprintf(addr, 24, " at %08x%08x", ahigh, alow);
  45. }
  46. printk(KERN_EMERG "CPU %d: Bank %d: %08x%08x%s%s\n",
  47. smp_processor_id(), i, high, low, misc, addr);
  48. }
  49. }
  50. if (recover & 2)
  51. panic("CPU context corrupt");
  52. if (recover & 1)
  53. panic("Unable to continue");
  54. printk(KERN_EMERG "Attempting to continue.\n");
  55. /*
  56. * Do not clear the MSR_IA32_MCi_STATUS if the error is not
  57. * recoverable/continuable.This will allow BIOS to look at the MSRs
  58. * for errors if the OS could not log the error:
  59. */
  60. for (i = 0; i < nr_mce_banks; i++) {
  61. unsigned int msr;
  62. msr = MSR_IA32_MC0_STATUS+i*4;
  63. rdmsr(msr, low, high);
  64. if (high & (1<<31)) {
  65. /* Clear it: */
  66. wrmsr(msr, 0UL, 0UL);
  67. /* Serialize: */
  68. wmb();
  69. add_taint(TAINT_MACHINE_CHECK);
  70. }
  71. }
  72. mcgstl &= ~(1<<2);
  73. wrmsr(MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
  74. }
  75. /* Set up machine check reporting for processors with Intel style MCE: */
  76. void intel_p6_mcheck_init(struct cpuinfo_x86 *c)
  77. {
  78. u32 l, h;
  79. int i;
  80. /* Check for MCE support */
  81. if (!cpu_has(c, X86_FEATURE_MCE))
  82. return;
  83. /* Check for PPro style MCA */
  84. if (!cpu_has(c, X86_FEATURE_MCA))
  85. return;
  86. /* Ok machine check is available */
  87. machine_check_vector = intel_machine_check;
  88. /* Make sure the vector pointer is visible before we enable MCEs: */
  89. wmb();
  90. printk(KERN_INFO "Intel machine check architecture supported.\n");
  91. rdmsr(MSR_IA32_MCG_CAP, l, h);
  92. if (l & (1<<8)) /* Control register present ? */
  93. wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
  94. nr_mce_banks = l & 0xff;
  95. /*
  96. * Following the example in IA-32 SDM Vol 3:
  97. * - MC0_CTL should not be written
  98. * - Status registers on all banks should be cleared on reset
  99. */
  100. for (i = 1; i < nr_mce_banks; i++)
  101. wrmsr(MSR_IA32_MC0_CTL+4*i, 0xffffffff, 0xffffffff);
  102. for (i = 0; i < nr_mce_banks; i++)
  103. wrmsr(MSR_IA32_MC0_STATUS+4*i, 0x0, 0x0);
  104. set_in_cr4(X86_CR4_MCE);
  105. printk(KERN_INFO "Intel machine check reporting enabled on CPU#%d.\n",
  106. smp_processor_id());
  107. }