k7.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Athlon/Hammer specific Machine Check Exception Reporting
  3. * (C) Copyright 2002 Dave Jones <davej@codemonkey.org.uk>
  4. */
  5. #include <linux/init.h>
  6. #include <linux/types.h>
  7. #include <linux/kernel.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 "mce.h"
  14. /* Machine Check Handler For AMD Athlon/Duron */
  15. static fastcall void k7_machine_check(struct pt_regs * regs, long error_code)
  16. {
  17. int recover=1;
  18. u32 alow, ahigh, high, low;
  19. u32 mcgstl, mcgsth;
  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=1; i<nr_mce_banks; i++) {
  27. rdmsr (MSR_IA32_MC0_STATUS+i*4,low, high);
  28. if (high&(1<<31)) {
  29. if (high & (1<<29))
  30. recover |= 1;
  31. if (high & (1<<25))
  32. recover |= 2;
  33. printk (KERN_EMERG "Bank %d: %08x%08x", i, high, low);
  34. high &= ~(1<<31);
  35. if (high & (1<<27)) {
  36. rdmsr (MSR_IA32_MC0_MISC+i*4, alow, ahigh);
  37. printk ("[%08x%08x]", ahigh, alow);
  38. }
  39. if (high & (1<<26)) {
  40. rdmsr (MSR_IA32_MC0_ADDR+i*4, alow, ahigh);
  41. printk (" at %08x%08x", ahigh, alow);
  42. }
  43. printk ("\n");
  44. /* Clear it */
  45. wrmsr (MSR_IA32_MC0_STATUS+i*4, 0UL, 0UL);
  46. /* Serialize */
  47. wmb();
  48. add_taint(TAINT_MACHINE_CHECK);
  49. }
  50. }
  51. if (recover&2)
  52. panic ("CPU context corrupt");
  53. if (recover&1)
  54. panic ("Unable to continue");
  55. printk (KERN_EMERG "Attempting to continue.\n");
  56. mcgstl &= ~(1<<2);
  57. wrmsr (MSR_IA32_MCG_STATUS,mcgstl, mcgsth);
  58. }
  59. /* AMD K7 machine check is Intel like */
  60. void amd_mcheck_init(struct cpuinfo_x86 *c)
  61. {
  62. u32 l, h;
  63. int i;
  64. machine_check_vector = k7_machine_check;
  65. wmb();
  66. printk (KERN_INFO "Intel machine check architecture supported.\n");
  67. rdmsr (MSR_IA32_MCG_CAP, l, h);
  68. if (l & (1<<8)) /* Control register present ? */
  69. wrmsr (MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
  70. nr_mce_banks = l & 0xff;
  71. /* Clear status for MC index 0 separately, we don't touch CTL,
  72. * as some Athlons cause spurious MCEs when its enabled. */
  73. wrmsr (MSR_IA32_MC0_STATUS, 0x0, 0x0);
  74. for (i=1; i<nr_mce_banks; i++) {
  75. wrmsr (MSR_IA32_MC0_CTL+4*i, 0xffffffff, 0xffffffff);
  76. wrmsr (MSR_IA32_MC0_STATUS+4*i, 0x0, 0x0);
  77. }
  78. set_in_cr4 (X86_CR4_MCE);
  79. printk (KERN_INFO "Intel machine check reporting enabled on CPU#%d.\n",
  80. smp_processor_id());
  81. }