blob: 93d5749f54bd70a318cdb330e95706a6529ee3d2 [file] [log] [blame]
Felix Held2ecf1562021-07-14 00:30:53 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <amdblocks/mca.h>
4#include <cpu/amd/msr.h>
5#include <cpu/x86/msr.h>
6#include <acpi/acpi.h>
7#include <console/console.h>
8#include <arch/bert_storage.h>
9#include <cper.h>
10#include <types.h>
Felix Helda83a58f2021-07-14 00:51:40 +020011#include "mca_common_defs.h"
Felix Held2ecf1562021-07-14 00:30:53 +020012
13static inline size_t mca_report_size_reqd(void)
14{
15 size_t size;
16
17 size = sizeof(acpi_generic_error_status_t);
18
19 size += sizeof(acpi_hest_generic_data_v300_t);
20 size += sizeof(cper_proc_generic_error_section_t);
21
22 size += sizeof(acpi_hest_generic_data_v300_t);
23 size += sizeof(cper_ia32x64_proc_error_section_t);
24
25 /* Check Error */
26 size += cper_ia32x64_check_sz();
27
28 /* Context of MCG_CAP, MCG_STAT, MCG_CTL */
29 size += cper_ia32x64_ctx_sz_bytype(CPER_IA32X64_CTX_MSR, 3);
30
31 /* Context of MCi_CTL, MCi_STATUS, MCi_ADDR, MCi_MISC */
32 size += cper_ia32x64_ctx_sz_bytype(CPER_IA32X64_CTX_MSR, 4);
33
34 /* Context of CTL_MASK */
35 size += cper_ia32x64_ctx_sz_bytype(CPER_IA32X64_CTX_MSR, 1);
36
37 return size;
38}
39
Felix Held2ecf1562021-07-14 00:30:53 +020040/* Convert an error reported by an MCA bank into BERT information to be reported
41 * by the OS. The ACPI driver doesn't recognize/parse the IA32/X64 structure,
42 * which is the best method to report MSR context. As a result, add two
43 * structures: A "processor generic error" that is parsed, and an IA32/X64 one
44 * to capture complete information.
45 *
46 * Future work may attempt to interpret the specific Family 15h error symptoms
47 * found in the MCA registers. This data could enhance the reporting of the
48 * Processor Generic section and the failing error/check added to the
49 * IA32/X64 section.
50 */
51void build_bert_mca_error(struct mca_bank_status *mci)
52{
53 acpi_generic_error_status_t *status;
54 acpi_hest_generic_data_v300_t *gen_entry;
55 acpi_hest_generic_data_v300_t *x86_entry;
56 cper_proc_generic_error_section_t *gen_sec;
57 cper_ia32x64_proc_error_section_t *x86_sec;
58 cper_ia32x64_proc_error_info_t *chk;
59 cper_ia32x64_context_t *ctx;
60
61 if (mca_report_size_reqd() > bert_storage_remaining())
62 goto failed;
63
64 status = bert_new_event(&CPER_SEC_PROC_GENERIC_GUID);
65 if (!status)
66 goto failed;
67
68 gen_entry = acpi_hest_generic_data3(status);
69 gen_sec = section_of_acpientry(gen_sec, gen_entry);
70
71 fill_generic_section(gen_sec, mci);
72
73 x86_entry = bert_append_ia32x64(status);
74 x86_sec = section_of_acpientry(x86_sec, x86_entry);
75
76 chk = new_cper_ia32x64_check(status, x86_sec, error_to_chktype(mci));
77 if (!chk)
78 goto failed;
79
80 ctx = cper_new_ia32x64_context_msr(status, x86_sec, IA32_MCG_CAP, 3);
81 if (!ctx)
82 goto failed;
83 ctx = cper_new_ia32x64_context_msr(status, x86_sec, IA32_MC_CTL(mci->bank), 4);
84 if (!ctx)
85 goto failed;
86 ctx = cper_new_ia32x64_context_msr(status, x86_sec, MC_CTL_MASK(mci->bank), 1);
87 if (!ctx)
88 goto failed;
89
90 return;
91
92failed:
93 /* We're here because of a hardware error, don't break something else */
94 printk(BIOS_ERR, "Error: Not enough room in BERT region for Machine Check error\n");
95}