]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/machine_check.c
xnu-4903.221.2.tar.gz
[apple/xnu.git] / osfmk / i386 / machine_check.c
index c70168b3c7529a38dd64f64f14e7a99bebef64d9..ce8344659532ed93c98b79b21b79f169da6caafd 100644 (file)
@@ -32,6 +32,7 @@
 #include <i386/cpuid.h>
 #include <i386/cpu_topology.h>
 #include <i386/cpu_threads.h>
+#include <i386/lapic.h>
 #include <i386/machine_cpu.h>
 #include <i386/machine_check.h>
 #include <i386/proc_reg.h>
@@ -55,10 +56,6 @@ static boolean_t     mca_MCA_present = FALSE;
 static uint32_t                mca_family = 0;
 static unsigned int    mca_error_bank_count = 0;
 static boolean_t       mca_control_MSR_present = FALSE;
-static boolean_t       mca_threshold_status_present = FALSE;
-static boolean_t       mca_sw_error_recovery_present = FALSE;
-static boolean_t       mca_extended_MSRs_present = FALSE;
-static unsigned int    mca_extended_MSRs_count = 0;
 static boolean_t       mca_cmci_present = FALSE;
 static ia32_mcg_cap_t  ia32_mcg_cap;
 decl_simple_lock_data(static, mca_lock);
@@ -93,15 +90,15 @@ mca_get_availability(void)
        uint32_t        model =    cpuid_info()->cpuid_model;
        uint32_t        stepping = cpuid_info()->cpuid_stepping;
 
-       mca_MCE_present = (features & CPUID_FEATURE_MCE) != 0;
-       mca_MCA_present = (features & CPUID_FEATURE_MCA) != 0;
-       mca_family = family;
-
        if ((model == CPUID_MODEL_HASWELL     && stepping < 3) ||
            (model == CPUID_MODEL_HASWELL_ULT && stepping < 1) ||
            (model == CPUID_MODEL_CRYSTALWELL && stepping < 1))
                panic("Haswell pre-C0 steppings are not supported");
 
+       mca_MCE_present = (features & CPUID_FEATURE_MCE) != 0;
+       mca_MCA_present = (features & CPUID_FEATURE_MCA) != 0;
+       mca_family = family;
+
        /*
         * If MCA, the number of banks etc is reported by the IA32_MCG_CAP MSR.
         */
@@ -109,13 +106,7 @@ mca_get_availability(void)
                ia32_mcg_cap.u64 = rdmsr64(IA32_MCG_CAP);
                mca_error_bank_count = ia32_mcg_cap.bits.count;
                mca_control_MSR_present = ia32_mcg_cap.bits.mcg_ctl_p;
-               mca_threshold_status_present = ia32_mcg_cap.bits.mcg_tes_p;
-               mca_sw_error_recovery_present = ia32_mcg_cap.bits.mcg_ser_p;
                mca_cmci_present = ia32_mcg_cap.bits.mcg_ext_corr_err_p;
-               if (family == 0x0F) {
-                       mca_extended_MSRs_present = ia32_mcg_cap.bits.mcg_ext_p;
-                       mca_extended_MSRs_count = ia32_mcg_cap.bits.mcg_ext_cnt;
-               }
        }
 }
 
@@ -234,7 +225,7 @@ mca_save_state(mca_state_t *mca_state)
         * and don't care about races
         */
        if (x86_package()->mca_state == NULL)
-                       x86_package()->mca_state = mca_state;
+               x86_package()->mca_state = mca_state;
 
        mca_state->mca_is_saved = TRUE;
 }
@@ -246,146 +237,23 @@ mca_check_save(void)
                mca_save_state(current_cpu_datap()->cpu_mca_state);
 }
 
-static void mca_dump_64bit_state(void)
-{
-       kdb_printf("Extended Machine Check State:\n");
-       kdb_printf("  IA32_MCG_RAX:    0x%016qx\n", rdmsr64(IA32_MCG_RAX));
-       kdb_printf("  IA32_MCG_RBX:    0x%016qx\n", rdmsr64(IA32_MCG_RBX));
-       kdb_printf("  IA32_MCG_RCX:    0x%016qx\n", rdmsr64(IA32_MCG_RCX));
-       kdb_printf("  IA32_MCG_RDX:    0x%016qx\n", rdmsr64(IA32_MCG_RDX));
-       kdb_printf("  IA32_MCG_RSI:    0x%016qx\n", rdmsr64(IA32_MCG_RSI));
-       kdb_printf("  IA32_MCG_RDI:    0x%016qx\n", rdmsr64(IA32_MCG_RDI));
-       kdb_printf("  IA32_MCG_RBP:    0x%016qx\n", rdmsr64(IA32_MCG_RBP));
-       kdb_printf("  IA32_MCG_RSP:    0x%016qx\n", rdmsr64(IA32_MCG_RSP));
-       kdb_printf("  IA32_MCG_RFLAGS: 0x%016qx\n", rdmsr64(IA32_MCG_RFLAGS));
-       kdb_printf("  IA32_MCG_RIP:    0x%016qx\n", rdmsr64(IA32_MCG_RIP));
-       kdb_printf("  IA32_MCG_MISC:   0x%016qx\n", rdmsr64(IA32_MCG_MISC));
-       kdb_printf("  IA32_MCG_R8:     0x%016qx\n", rdmsr64(IA32_MCG_R8));
-       kdb_printf("  IA32_MCG_R9:     0x%016qx\n", rdmsr64(IA32_MCG_R9));
-       kdb_printf("  IA32_MCG_R10:    0x%016qx\n", rdmsr64(IA32_MCG_R10));
-       kdb_printf("  IA32_MCG_R11:    0x%016qx\n", rdmsr64(IA32_MCG_R11));
-       kdb_printf("  IA32_MCG_R12:    0x%016qx\n", rdmsr64(IA32_MCG_R12));
-       kdb_printf("  IA32_MCG_R13:    0x%016qx\n", rdmsr64(IA32_MCG_R13));
-       kdb_printf("  IA32_MCG_R14:    0x%016qx\n", rdmsr64(IA32_MCG_R14));
-       kdb_printf("  IA32_MCG_R15:    0x%016qx\n", rdmsr64(IA32_MCG_R15));
-}
-
-static uint32_t rdmsr32(uint32_t msr)
-{
-       return (uint32_t) rdmsr64(msr);
-}
-
-static void mca_dump_32bit_state(void)
-{
-       kdb_printf("Extended Machine Check State:\n");
-       kdb_printf("  IA32_MCG_EAX:    0x%08x\n", rdmsr32(IA32_MCG_EAX));
-       kdb_printf("  IA32_MCG_EBX:    0x%08x\n", rdmsr32(IA32_MCG_EBX));
-       kdb_printf("  IA32_MCG_ECX:    0x%08x\n", rdmsr32(IA32_MCG_ECX));
-       kdb_printf("  IA32_MCG_EDX:    0x%08x\n", rdmsr32(IA32_MCG_EDX));
-       kdb_printf("  IA32_MCG_ESI:    0x%08x\n", rdmsr32(IA32_MCG_ESI));
-       kdb_printf("  IA32_MCG_EDI:    0x%08x\n", rdmsr32(IA32_MCG_EDI));
-       kdb_printf("  IA32_MCG_EBP:    0x%08x\n", rdmsr32(IA32_MCG_EBP));
-       kdb_printf("  IA32_MCG_ESP:    0x%08x\n", rdmsr32(IA32_MCG_ESP));
-       kdb_printf("  IA32_MCG_EFLAGS: 0x%08x\n", rdmsr32(IA32_MCG_EFLAGS));
-       kdb_printf("  IA32_MCG_EIP:    0x%08x\n", rdmsr32(IA32_MCG_EIP));
-       kdb_printf("  IA32_MCG_MISC:   0x%08x\n", rdmsr32(IA32_MCG_MISC));
-}
-
 static void
 mca_report_cpu_info(void)
 {
        i386_cpu_info_t *infop = cpuid_info();
 
-       kdb_printf(" family: %d model: %d stepping: %d microcode: %d\n",
+       paniclog_append_noflush(" family: %d model: %d stepping: %d microcode: %d\n",
                infop->cpuid_family,
                infop->cpuid_model,
                infop->cpuid_stepping,
                infop->cpuid_microcode_version);
-       kdb_printf(" %s\n", infop->cpuid_brand_string);
-}
-
-static const char *mc8_memory_operation[] = {
-       [MC8_MMM_GENERIC] =             "generic",
-       [MC8_MMM_READ] =                "read",
-       [MC8_MMM_WRITE] =               "write",
-       [MC8_MMM_ADDRESS_COMMAND] =     "address/command",
-       [MC8_MMM_RESERVED] =            "reserved"
-};
-
-static void
-mca_dump_bank_mc8(mca_state_t *state, int i)
-{
-       mca_mci_bank_t                  *bank;
-       ia32_mci_status_t               status;
-       struct ia32_mc8_specific        mc8;
-       int                             mmm;
-
-       bank = &state->mca_error_bank[i];
-       status = bank->mca_mci_status;
-       mc8 = status.bits_mc8;
-       mmm = MIN(mc8.memory_operation, MC8_MMM_RESERVED);
-
-       kdb_printf(
-               " IA32_MC%d_STATUS(0x%x): 0x%016qx %svalid\n",
-               i, IA32_MCi_STATUS(i), status.u64, IF(!status.bits.val, "in"));
-       if (!status.bits.val)
-               return;
+       paniclog_append_noflush(" signature: 0x%x\n",
+               infop->cpuid_signature);
+       paniclog_append_noflush(" %s\n",
+               infop->cpuid_brand_string);
 
-       kdb_printf(
-               "  Channel number:         %d%s\n"
-               "  Memory Operation:       %s\n"
-               "  Machine-specific error: %s%s%s%s%s%s%s%s%s\n"
-               "  COR_ERR_CNT:            %d\n",
-               mc8.channel_number,
-               IF(mc8.channel_number == 15, " (unknown)"),
-               mc8_memory_operation[mmm],
-               IF(mc8.read_ecc,            "Read ECC "),
-               IF(mc8.ecc_on_a_scrub,      "ECC on scrub "),
-               IF(mc8.write_parity,        "Write parity "),
-               IF(mc8.redundant_memory,    "Redundant memory "),
-               IF(mc8.sparing,             "Sparing/Resilvering "),
-               IF(mc8.access_out_of_range, "Access out of Range "),
-               IF(mc8.rtid_out_of_range,   "RTID out of Range "),
-               IF(mc8.address_parity,      "Address Parity "),
-               IF(mc8.byte_enable_parity,  "Byte Enable Parity "),
-               mc8.cor_err_cnt);
-       kdb_printf(
-               "  Status bits:\n%s%s%s%s%s%s",
-               IF(status.bits.pcc,         "   Processor context corrupt\n"),
-               IF(status.bits.addrv,       "   ADDR register valid\n"),
-               IF(status.bits.miscv,       "   MISC register valid\n"),
-               IF(status.bits.en,          "   Error enabled\n"),
-               IF(status.bits.uc,          "   Uncorrected error\n"),
-               IF(status.bits.over,        "   Error overflow\n"));
-       if (status.bits.addrv)
-               kdb_printf(
-                       " IA32_MC%d_ADDR(0x%x): 0x%016qx\n",
-                       i, IA32_MCi_ADDR(i), bank->mca_mci_addr);
-       if (status.bits.miscv) {
-               ia32_mc8_misc_t mc8_misc;
-
-               mc8_misc.u64 = bank->mca_mci_misc;
-               kdb_printf(
-                       " IA32_MC%d_MISC(0x%x): 0x%016qx\n"
-                       "  RTID:     %d\n"
-                       "  DIMM:     %d\n"
-                       "  Channel:  %d\n"
-                       "  Syndrome: 0x%x\n",
-                       i, IA32_MCi_MISC(i), mc8_misc.u64,
-                       mc8_misc.bits.rtid,
-                       mc8_misc.bits.dimm,
-                       mc8_misc.bits.channel,
-                       (int) mc8_misc.bits.syndrome);
-       }
 }
 
-static const char *mca_threshold_status[] = {
-       [THRESHOLD_STATUS_NO_TRACKING] =        "No tracking",
-       [THRESHOLD_STATUS_GREEN] =              "Green",
-       [THRESHOLD_STATUS_YELLOW] =             "Yellow",
-       [THRESHOLD_STATUS_RESERVED] =           "Reserved"
-};
-
 static void
 mca_dump_bank(mca_state_t *state, int i)
 {
@@ -394,54 +262,18 @@ mca_dump_bank(mca_state_t *state, int i)
 
        bank = &state->mca_error_bank[i];
        status = bank->mca_mci_status;
-       kdb_printf(
-               " IA32_MC%d_STATUS(0x%x): 0x%016qx %svalid\n",
-               i, IA32_MCi_STATUS(i), status.u64, IF(!status.bits.val, "in"));
        if (!status.bits.val)
                return;
 
-       kdb_printf(
-               "  MCA error code:            0x%04x\n",
-               status.bits.mca_error);
-       kdb_printf(
-               "  Model specific error code: 0x%04x\n",
-               status.bits.model_specific_error);
-       if (!mca_threshold_status_present) {
-               kdb_printf(
-                       "  Other information:         0x%08x\n",
-                       status.bits.other_information);
-       } else {
-               int     threshold = status.bits_tes_p.threshold;
-               kdb_printf(
-                       "  Other information:         0x%08x\n"
-                       "  Threshold-based status:    %s\n",
-                       status.bits_tes_p.other_information,
-                       (status.bits_tes_p.uc == 0) ?
-                           mca_threshold_status[threshold] :
-                           "Undefined");
-       }
-       if (mca_threshold_status_present &&
-           mca_sw_error_recovery_present) {
-               kdb_printf(
-                       "  Software Error Recovery:\n%s%s",
-                       IF(status.bits_tes_p.ar, "   Recovery action reqd\n"),
-                       IF(status.bits_tes_p.s,  "   Signaling UCR error\n"));
-       }
-       kdb_printf(
-               "  Status bits:\n%s%s%s%s%s%s",
-               IF(status.bits.pcc,   "   Processor context corrupt\n"),
-               IF(status.bits.addrv, "   ADDR register valid\n"),
-               IF(status.bits.miscv, "   MISC register valid\n"),
-               IF(status.bits.en,    "   Error enabled\n"),
-               IF(status.bits.uc,    "   Uncorrected error\n"),
-               IF(status.bits.over,  "   Error overflow\n"));
+       paniclog_append_noflush(" IA32_MC%d_STATUS(0x%x): 0x%016qx\n",
+               i, IA32_MCi_STATUS(i), status.u64);
+
        if (status.bits.addrv)
-               kdb_printf(
-                       " IA32_MC%d_ADDR(0x%x): 0x%016qx\n",
+               paniclog_append_noflush(" IA32_MC%d_ADDR(0x%x):   0x%016qx\n",
                        i, IA32_MCi_ADDR(i), bank->mca_mci_addr);
+
        if (status.bits.miscv)
-               kdb_printf(
-                       " IA32_MC%d_MISC(0x%x): 0x%016qx\n",
+               paniclog_append_noflush(" IA32_MC%d_MISC(0x%x):   0x%016qx\n",
                        i, IA32_MCi_MISC(i), bank->mca_mci_misc);
 }
 
@@ -453,19 +285,7 @@ mca_cpu_dump_error_banks(mca_state_t *state)
        if (!state->mca_is_valid)
                return;
 
-       kdb_printf("MCA error-reporting registers:\n");
        for (i = 0; i < mca_error_bank_count; i++ ) {
-               if (i == 8 && state == x86_package()->mca_state) {
-                       /*
-                        * Fatal Memory Error
-                        */
-
-                       /* Dump MC8 for this package */
-                       kdb_printf(" Package %d logged:\n",
-                                  x86_package()->ppkg_num);
-                       mca_dump_bank_mc8(state, 8);
-                       continue;
-               }
                mca_dump_bank(state, i);
        }
 }
@@ -512,22 +332,11 @@ mca_dump(void)
        /*
         * Report machine-check capabilities:
         */
-       kdb_printf(
-               "Machine-check capabilities 0x%016qx:\n", ia32_mcg_cap.u64);
+       paniclog_append_noflush("Machine-check capabilities: 0x%016qx\n", ia32_mcg_cap.u64);
 
        mca_report_cpu_info();
 
-       kdb_printf(
-               " %d error-reporting banks\n%s%s%s", mca_error_bank_count,
-               IF(mca_control_MSR_present,
-                  " control MSR present\n"),
-               IF(mca_threshold_status_present,
-                  " threshold-based error status present\n"),
-               IF(mca_cmci_present,
-                  " extended corrected memory error handling present\n"));
-       if (mca_extended_MSRs_present)
-               kdb_printf(
-                       " %d extended MSRs present\n", mca_extended_MSRs_count);
+       paniclog_append_noflush(" %d error-reporting banks\n", mca_error_bank_count);
  
        /*
         * Dump all processor state:
@@ -536,49 +345,28 @@ mca_dump(void)
                mca_state_t             *mcsp = cpu_datap(i)->cpu_mca_state;
                ia32_mcg_status_t       status;
 
-               kdb_printf("Processor %d: ", i);
                if (mcsp == NULL ||
                    mcsp->mca_is_saved == FALSE ||
-                   mcsp->mca_mcg_status.u64 == 0) {
-                       kdb_printf("no machine-check status reported\n");
-                       continue;
-               }
-               if (!mcsp->mca_is_valid) {
-                       kdb_printf("no valid machine-check state\n");
+                   mcsp->mca_mcg_status.u64 == 0 ||
+                   !mcsp->mca_is_valid) {
                        continue;
                }
                status = mcsp->mca_mcg_status;
-               kdb_printf(
-                       "machine-check status 0x%016qx:\n%s%s%s", status.u64,
-                       IF(status.bits.ripv, " restart IP valid\n"),
-                       IF(status.bits.eipv, " error IP valid\n"),
-                       IF(status.bits.mcip, " machine-check in progress\n"));
-
+               paniclog_append_noflush("Processor %d: IA32_MCG_STATUS: 0x%016qx\n",
+                       i, status.u64);
                mca_cpu_dump_error_banks(mcsp);
        }
 
-       /*
-        * Dump any extended machine state:
-        */
-       if (mca_extended_MSRs_present) {
-               if (cpu_mode_is64bit())
-                       mca_dump_64bit_state();
-               else
-                       mca_dump_32bit_state();
-       }
-
        /* Update state to release any other threads. */
        mca_dump_state = DUMPED;
 }
 
 
+#if DEVELOPMENT || DEBUG
 extern void mca_exception_panic(void);
-extern void mtrr_lapic_cached(void);
+extern void lapic_trigger_MC(void);
 void mca_exception_panic(void)
 {
-#if DEBUG
-       mtrr_lapic_cached();
-#else
-       kprintf("mca_exception_panic() requires DEBUG build\n");
-#endif
+       lapic_trigger_MC();
 }
+#endif