27 #include <linux/kernel.h>
28 #include <linux/module.h>
42 #define ERST_PFX "ERST: "
45 #define ERST_STATUS_SUCCESS 0x0
46 #define ERST_STATUS_NOT_ENOUGH_SPACE 0x1
47 #define ERST_STATUS_HARDWARE_NOT_AVAILABLE 0x2
48 #define ERST_STATUS_FAILED 0x3
49 #define ERST_STATUS_RECORD_STORE_EMPTY 0x4
50 #define ERST_STATUS_RECORD_NOT_FOUND 0x5
52 #define ERST_TAB_ENTRY(tab) \
53 ((struct acpi_whea_header *)((char *)(tab) + \
54 sizeof(struct acpi_table_erst)))
58 #define FIRMWARE_TIMEOUT (1 * NSEC_PER_MSEC)
59 #define FIRMWARE_MAX_STALL 50
67 #define ERST_RANGE_RESERVED 0x0001
68 #define ERST_RANGE_NVRAM 0x0002
69 #define ERST_RANGE_SLOW 0x0004
75 static struct erst_erange {
94 switch (command_status) {
109 static int erst_timedout(
u64 *
t,
u64 spin_unit)
111 if ((
s64)*t < spin_unit) {
113 "Firmware does not respond in time\n");
190 "Too long stall time for stall instruction: %llx.\n",
194 stall_time = ctx->
value;
210 "Too long stall time for stall while true instruction: %llx.\n",
214 stall_time = ctx->
var1;
220 if (val != ctx->
value)
228 static int erst_exec_skip_next_instruction_if_true(
238 if (val == ctx->
value) {
275 "MOVE_DATA can not be used in interrupt context");
321 .run = erst_exec_load_var1,
325 .run = erst_exec_load_var2,
329 .run = erst_exec_store_var1,
333 .run = erst_exec_add,
337 .run = erst_exec_subtract,
341 .run = erst_exec_add_value,
345 .run = erst_exec_subtract_value,
349 .run = erst_exec_stall,
353 .run = erst_exec_stall_while_true,
357 .run = erst_exec_skip_next_instruction_if_true,
361 .run = erst_exec_goto,
365 .run = erst_exec_set_src_address_base,
369 .run = erst_exec_set_dst_address_base,
373 .run = erst_exec_move_data,
383 static int erst_get_erange(
struct erst_erange *
range)
388 erst_exec_ctx_init(&ctx);
392 range->base = apei_exec_ctx_get_output(&ctx);
396 range->size = apei_exec_ctx_get_output(&ctx);
400 range->attr = apei_exec_ctx_get_output(&ctx);
405 static ssize_t __erst_get_record_count(
void)
410 erst_exec_ctx_init(&ctx);
414 return apei_exec_ctx_get_output(&ctx);
426 count = __erst_get_record_count();
433 #define ERST_RECORD_ID_CACHE_SIZE_MIN 16
434 #define ERST_RECORD_ID_CACHE_SIZE_MAX 1024
449 static int __erst_get_next_record_id(
u64 *record_id)
454 erst_exec_ctx_init(&ctx);
458 *record_id = apei_exec_ctx_get_output(&ctx);
483 static int __erst_record_id_cache_add_one(
void)
485 u64 id, prev_id, first_id;
493 rc = __erst_get_next_record_id(&
id);
502 if (
id == prev_id ||
id == first_id)
508 entries = erst_record_id_cache.
entries;
509 for (i = 0; i < erst_record_id_cache.
len; i++) {
510 if (entries[i] ==
id)
514 if (i < erst_record_id_cache.
len)
516 if (erst_record_id_cache.
len >= erst_record_id_cache.
size) {
517 int new_size, alloc_size;
520 new_size = erst_record_id_cache.
size * 2;
523 if (new_size <= erst_record_id_cache.
size) {
524 if (printk_ratelimit())
526 "too many record ID!\n");
529 alloc_size = new_size *
sizeof(entries[0]);
533 new_entries =
vmalloc(alloc_size);
536 memcpy(new_entries, entries,
537 erst_record_id_cache.
len *
sizeof(entries[0]));
542 erst_record_id_cache.
entries = entries = new_entries;
543 erst_record_id_cache.
size = new_size;
546 erst_record_id_cache.
len++;
566 BUG_ON(*pos < 0 || *pos > erst_record_id_cache.
len);
569 entries = erst_record_id_cache.
entries;
570 for (; *pos < erst_record_id_cache.
len; (*pos)++)
574 if (*pos < erst_record_id_cache.
len) {
575 *record_id = entries[*
pos];
581 rc = __erst_record_id_cache_add_one();
586 *record_id = erst_record_id_cache.
entries[*
pos];
601 static void __erst_record_id_cache_compact(
void)
609 entries = erst_record_id_cache.
entries;
610 for (i = 0; i < erst_record_id_cache.
len; i++) {
614 memcpy(&entries[wpos], &entries[i],
sizeof(entries[i]));
617 erst_record_id_cache.
len = wpos;
632 __erst_record_id_cache_compact();
637 static int __erst_write_to_storage(
u64 offset)
644 erst_exec_ctx_init(&ctx);
648 apei_exec_ctx_set_input(&ctx, offset);
659 val = apei_exec_ctx_get_output(&ctx);
668 val = apei_exec_ctx_get_output(&ctx);
673 return erst_errno(val);
676 static int __erst_read_from_storage(
u64 record_id,
u64 offset)
683 erst_exec_ctx_init(&ctx);
687 apei_exec_ctx_set_input(&ctx, offset);
691 apei_exec_ctx_set_input(&ctx, record_id);
702 val = apei_exec_ctx_get_output(&ctx);
711 val = apei_exec_ctx_get_output(&ctx);
716 return erst_errno(val);
719 static int __erst_clear_from_storage(
u64 record_id)
726 erst_exec_ctx_init(&ctx);
730 apei_exec_ctx_set_input(&ctx, record_id);
741 val = apei_exec_ctx_get_output(&ctx);
750 val = apei_exec_ctx_get_output(&ctx);
755 return erst_errno(val);
759 static void pr_unimpl_nvram(
void)
761 if (printk_ratelimit())
763 "NVRAM ERST Log Address Range is not implemented yet\n");
772 static int __erst_read_to_erange_from_nvram(
u64 record_id,
u64 *offset)
778 static int __erst_clear_from_nvram(
u64 record_id)
799 rc = __erst_write_to_nvram(record);
810 rcd_erange = erst_erange.vaddr;
814 rc = __erst_write_to_storage(0);
821 static int __erst_read_to_erange(
u64 record_id,
u64 *offset)
826 return __erst_read_to_erange_from_nvram(
829 rc = __erst_read_from_storage(record_id, 0);
844 rc = __erst_read_to_erange(record_id, &offset);
847 rcd_tmp = erst_erange.vaddr +
offset;
850 memcpy(record, rcd_tmp, len);
870 len = __erst_read(record_id, record, buflen);
890 rc = __erst_clear_from_nvram(record_id);
892 rc = __erst_clear_from_storage(record_id);
896 entries = erst_record_id_cache.
entries;
897 for (i = 0; i < erst_record_id_cache.
len; i++) {
898 if (entries[i] == record_id)
901 __erst_record_id_cache_compact();
908 static int __init setup_erst_disable(
char *
str)
914 __setup(
"erst_disable", setup_erst_disable);
932 static int erst_open_pstore(
struct pstore_info *psi);
933 static int erst_close_pstore(
struct pstore_info *psi);
946 .open = erst_open_pstore,
947 .close = erst_close_pstore,
949 .write = erst_writer,
950 .erase = erst_clearer
953 #define CPER_CREATOR_PSTORE \
954 UUID_LE(0x75a574e3, 0x5052, 0x4b29, 0x8a, 0x8e, 0xbe, 0x2c, \
955 0x64, 0x90, 0xb8, 0x9d)
956 #define CPER_SECTION_TYPE_DMESG \
957 UUID_LE(0xc197e04e, 0xd545, 0x4a70, 0x9c, 0x17, 0xa5, 0x54, \
958 0x94, 0x19, 0xeb, 0x12)
959 #define CPER_SECTION_TYPE_MCE \
960 UUID_LE(0xfe08ffbe, 0x95e4, 0x4be7, 0xbc, 0x73, 0x40, 0x96, \
961 0x04, 0x4a, 0x38, 0xfc)
969 static int reader_pos;
971 static int erst_open_pstore(
struct pstore_info *psi)
983 static int erst_close_pstore(
struct pstore_info *psi)
998 size_t rcd_len =
sizeof(*rcd) + erst_info.
bufsize;
1023 else if (len <
sizeof(*rcd)) {
1037 if (uuid_le_cmp(rcd->
sec_hdr.section_type,
1040 else if (uuid_le_cmp(rcd->
sec_hdr.section_type,
1054 return (rc < 0) ? rc : (len -
sizeof(*rcd));
1062 (erst_info.
buf -
sizeof(*rcd));
1065 memset(rcd, 0,
sizeof(*rcd));
1069 rcd->
hdr.section_count = 1;
1074 rcd->
hdr.record_length =
sizeof(*rcd) +
size;
1080 rcd->
sec_hdr.section_offset =
sizeof(*rcd);
1084 rcd->
sec_hdr.validation_bits = 0;
1099 *
id = rcd->
hdr.record_id;
1110 static int __init erst_init(
void)
1124 "Error Record Serialization Table (ERST) support is disabled.\n");
1139 rc = erst_check_table(erst_tab);
1145 apei_resources_init(&erst_resources);
1146 erst_exec_ctx_init(&ctx);
1156 rc = erst_get_erange(&erst_erange);
1160 "The corresponding hardware device or firmware implementation "
1161 "is not available.\n");
1164 "Failed to get Error Log Address Range.\n");
1171 "Can not request iomem region <0x%16llx-0x%16llx> for ERST.\n",
1172 (
unsigned long long)erst_erange.base,
1173 (
unsigned long long)erst_erange.base + erst_erange.size);
1180 if (!erst_erange.vaddr)
1181 goto err_release_erange;
1187 erst_info.
bufsize = erst_erange.size -
1196 "Error Record Serialization Table (ERST) support is initialized.\n");