Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #include <acpi/acpi.h> |
| 4 | #include <acpi/acpigen.h> |
| 5 | #include <arch/bert_storage.h> |
| 6 | #include <console/console.h> |
| 7 | #include <intelblocks/acpi.h> |
| 8 | #include <intelblocks/crashlog.h> |
| 9 | |
Felix Held | fba47926 | 2021-05-28 16:11:43 +0200 | [diff] [blame] | 10 | static bool boot_error_src_present(void) |
| 11 | { |
Felix Held | fba47926 | 2021-05-28 16:11:43 +0200 | [diff] [blame] | 12 | if (!discover_crashlog()) { |
| 13 | printk(BIOS_SPEW, "Crashlog discovery result: crashlog not found\n"); |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | collect_pmc_and_cpu_crashlog_from_srams(); |
| 18 | |
| 19 | /* Discovery tables sizes can be larger than the actual valid collected data */ |
| 20 | u32 crashlog_size = cl_get_total_data_size(); |
| 21 | |
| 22 | return (crashlog_size > 0); |
| 23 | } |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 24 | |
Jonathan Zhang | 01acc03 | 2022-10-26 17:53:25 -0700 | [diff] [blame^] | 25 | static enum cb_err record_crashlog_into_bert(void **region, size_t *length) |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 26 | { |
| 27 | acpi_generic_error_status_t *status = NULL; |
| 28 | size_t cpu_record_size, pmc_record_size; |
Francois Toguo Fotso | c175146 | 2021-05-27 01:10:16 -0700 | [diff] [blame] | 29 | size_t gesb_header_size; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 30 | void *cl_data = NULL; |
| 31 | |
Felix Held | fba47926 | 2021-05-28 16:11:43 +0200 | [diff] [blame] | 32 | if (!boot_error_src_present()) { |
| 33 | return CB_ERR; |
| 34 | } |
| 35 | |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 36 | if (!cl_get_total_data_size()) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 37 | printk(BIOS_ERR, "No crashlog record present\n"); |
Felix Held | 2940548 | 2021-05-28 16:01:57 +0200 | [diff] [blame] | 38 | return CB_ERR; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | status = bert_new_event(&CPER_SEC_FW_ERR_REC_REF_GUID); |
Francois Toguo Fotso | c175146 | 2021-05-27 01:10:16 -0700 | [diff] [blame] | 42 | gesb_header_size = sizeof(*status); |
| 43 | |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 44 | if (!status) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 45 | printk(BIOS_ERR, "unable to allocate GSB\n"); |
Felix Held | 2940548 | 2021-05-28 16:01:57 +0200 | [diff] [blame] | 46 | return CB_ERR; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | if (cl_get_total_data_size() > bert_storage_remaining()) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 50 | printk(BIOS_ERR, "Crashlog entry would exceed " |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 51 | "available region\n"); |
Felix Held | 2940548 | 2021-05-28 16:01:57 +0200 | [diff] [blame] | 52 | return CB_ERR; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | cpu_record_size = cl_get_cpu_record_size(); |
| 56 | if (cpu_record_size) { |
| 57 | cl_data = new_cper_fw_error_crashlog(status, cpu_record_size); |
| 58 | if (!cl_data) { |
Arthur Heymans | 4cd8f61 | 2022-05-13 16:38:37 +0200 | [diff] [blame] | 59 | printk(BIOS_ERR, "Crashlog CPU entry(size %zu) " |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 60 | "would exceed available region\n", |
| 61 | cpu_record_size); |
Felix Held | 2940548 | 2021-05-28 16:01:57 +0200 | [diff] [blame] | 62 | return CB_ERR; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 63 | } |
Arthur Heymans | 4cd8f61 | 2022-05-13 16:38:37 +0200 | [diff] [blame] | 64 | printk(BIOS_DEBUG, "cl_data %p, cpu_record_size %zu\n", |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 65 | cl_data, cpu_record_size); |
| 66 | cl_fill_cpu_records(cl_data); |
| 67 | } |
| 68 | |
| 69 | pmc_record_size = cl_get_pmc_record_size(); |
| 70 | if (pmc_record_size) { |
| 71 | /* Allocate new FW ERR structure in case CPU crashlog is present */ |
| 72 | if (cpu_record_size && !bert_append_fw_err(status)) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 73 | printk(BIOS_ERR, "Crashlog PMC entry would " |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 74 | "exceed available region\n"); |
Felix Held | 2940548 | 2021-05-28 16:01:57 +0200 | [diff] [blame] | 75 | return CB_ERR; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | cl_data = new_cper_fw_error_crashlog(status, pmc_record_size); |
| 79 | if (!cl_data) { |
Arthur Heymans | 4cd8f61 | 2022-05-13 16:38:37 +0200 | [diff] [blame] | 80 | printk(BIOS_ERR, "Crashlog PMC entry(size %zu) " |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 81 | "would exceed available region\n", |
| 82 | pmc_record_size); |
Felix Held | 2940548 | 2021-05-28 16:01:57 +0200 | [diff] [blame] | 83 | return CB_ERR; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 84 | } |
Arthur Heymans | 4cd8f61 | 2022-05-13 16:38:37 +0200 | [diff] [blame] | 85 | printk(BIOS_DEBUG, "cl_data %p, pmc_record_size %zu\n", |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 86 | cl_data, pmc_record_size); |
| 87 | cl_fill_pmc_records(cl_data); |
| 88 | } |
| 89 | |
Francois Toguo Fotso | c175146 | 2021-05-27 01:10:16 -0700 | [diff] [blame] | 90 | *length = status->data_length + gesb_header_size; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 91 | *region = (void *)status; |
| 92 | |
Felix Held | 2940548 | 2021-05-28 16:01:57 +0200 | [diff] [blame] | 93 | return CB_SUCCESS; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 94 | } |
Jonathan Zhang | 01acc03 | 2022-10-26 17:53:25 -0700 | [diff] [blame^] | 95 | |
| 96 | enum cb_err acpi_soc_get_bert_region(void **region, size_t *length) |
| 97 | { |
| 98 | if (CONFIG(SOC_INTEL_CRASHLOG)) { |
| 99 | return record_crashlog_into_bert(region, length); |
| 100 | } else { |
| 101 | /* Check if MCA error has been added into BERT. */ |
| 102 | if (bert_should_generate_acpi_table()) { |
| 103 | bert_errors_region(region, length); |
| 104 | if (!*region) { |
| 105 | printk(BIOS_ERR, "Can't find BERT storage area\n"); |
| 106 | return CB_ERR; |
| 107 | } |
| 108 | } |
| 109 | return CB_SUCCESS; |
| 110 | } |
| 111 | } |