* This scans all the machine check banks of the current CPU to see if * there are any machine checks. Any non-recoverable errors are * reported immediately via mca_log(). The current thread must be * pinned when this is called. The 'mode' parameter indicates if we * are being called from the MC exception handler, the CMCI handler, * or the periodic poller. In the MC exception case this fu
| 754 | * count of the number of valid MC records found. |
| 755 | */ |
| 756 | static int |
| 757 | mca_scan(enum scan_mode mode, int *recoverablep) |
| 758 | { |
| 759 | struct mca_record rec; |
| 760 | uint64_t mcg_cap, ucmask; |
| 761 | int count, i, recoverable, valid; |
| 762 | |
| 763 | count = 0; |
| 764 | recoverable = 1; |
| 765 | ucmask = MC_STATUS_UC | MC_STATUS_PCC; |
| 766 | |
| 767 | /* When handling a MCE#, treat the OVER flag as non-restartable. */ |
| 768 | if (mode == MCE) |
| 769 | ucmask |= MC_STATUS_OVER; |
| 770 | mcg_cap = rdmsr(MSR_MCG_CAP); |
| 771 | for (i = 0; i < (mcg_cap & MCG_CAP_COUNT); i++) { |
| 772 | #ifdef DEV_APIC |
| 773 | /* |
| 774 | * For a CMCI, only check banks this CPU is |
| 775 | * responsible for. |
| 776 | */ |
| 777 | if (mode == CMCI && !(PCPU_GET(cmci_mask) & 1 << i)) |
| 778 | continue; |
| 779 | #endif |
| 780 | |
| 781 | valid = mca_check_status(i, &rec); |
| 782 | if (valid) { |
| 783 | count++; |
| 784 | if (rec.mr_status & ucmask) { |
| 785 | recoverable = 0; |
| 786 | mtx_lock_spin(&mca_lock); |
| 787 | mca_log(&rec); |
| 788 | mtx_unlock_spin(&mca_lock); |
| 789 | } |
| 790 | mca_record_entry(mode, &rec); |
| 791 | } |
| 792 | |
| 793 | #ifdef DEV_APIC |
| 794 | /* |
| 795 | * If this is a bank this CPU monitors via CMCI, |
| 796 | * update the threshold. |
| 797 | */ |
| 798 | if (PCPU_GET(cmci_mask) & 1 << i) { |
| 799 | if (cmc_state != NULL) |
| 800 | cmci_update(mode, i, valid, &rec); |
| 801 | else |
| 802 | amd_thresholding_update(mode, i, valid); |
| 803 | } |
| 804 | #endif |
| 805 | } |
| 806 | if (recoverablep != NULL) |
| 807 | *recoverablep = recoverable; |
| 808 | return (count); |
| 809 | } |
| 810 | |
| 811 | /* |
| 812 | * Store a new record on the mca_records list while enforcing |
no test coverage detected