diff options
Diffstat (limited to 'src/drivers/elog')
-rw-r--r-- | src/drivers/elog/Kconfig | 21 | ||||
-rw-r--r-- | src/drivers/elog/elog.c | 42 | ||||
-rw-r--r-- | src/drivers/elog/elog_internal.h | 2 |
3 files changed, 22 insertions, 43 deletions
diff --git a/src/drivers/elog/Kconfig b/src/drivers/elog/Kconfig index 162cc5f361..7affd0694a 100644 --- a/src/drivers/elog/Kconfig +++ b/src/drivers/elog/Kconfig @@ -45,27 +45,6 @@ config ELOG_AREA_SIZE Default is 4K. -config ELOG_FULL_THRESHOLD - hex "Threshold at which flash is considered full" - default 0xC00 - help - When the Event Log size is larger than this it will be shrunk - to ELOG_SHRINK_SIZE. Must be greater than ELOG_AREA_SIZE, and - ELOG_AREA_SIZE - ELOG_FULL_THRESHOLD must be greater than the - maximum event size of 128. - - Default is 75% of the log, or 3K. - -config ELOG_SHRINK_SIZE - hex "Resulting size when the event log is shrunk" - default 0x400 - help - When the Event Log is shrunk it will go to this size. - ELOG_AREA_SIZE - ELOG_SHRINK_SIZE must be less than - CONFIG_ELOG_FULL_THRESHOLD. - - Default is 1K. - config ELOG_CBMEM bool "Store a copy of ELOG in CBMEM" default n diff --git a/src/drivers/elog/elog.c b/src/drivers/elog/elog.c index f5135d99a3..de18d5d82f 100644 --- a/src/drivers/elog/elog.c +++ b/src/drivers/elog/elog.c @@ -40,19 +40,6 @@ #if !IS_ENABLED(CONFIG_CHROMEOS) && CONFIG_ELOG_FLASH_BASE == 0 #error "CONFIG_ELOG_FLASH_BASE is invalid" #endif -#if CONFIG_ELOG_FULL_THRESHOLD >= CONFIG_ELOG_AREA_SIZE -#error "CONFIG_ELOG_FULL_THRESHOLD is larger than CONFIG_ELOG_AREA_SIZE" -#endif -#if (CONFIG_ELOG_AREA_SIZE - CONFIG_ELOG_FULL_THRESHOLD) < (MAX_EVENT_SIZE + 1) -#error "CONFIG_ELOG_FULL_THRESHOLD is too small" -#endif -#if CONFIG_ELOG_SHRINK_SIZE >= CONFIG_ELOG_AREA_SIZE -#error "CONFIG_ELOG_SHRINK_SIZE is larger than CONFIG_ELOG_AREA_SIZE" -#endif -#if (CONFIG_ELOG_AREA_SIZE - CONFIG_ELOG_SHRINK_SIZE) > \ - CONFIG_ELOG_FULL_THRESHOLD -#error "CONFIG_ELOG_SHRINK_SIZE is too large" -#endif #if CONFIG_ELOG_DEBUG #define elog_debug(STR...) printk(BIOS_DEBUG, STR) @@ -65,14 +52,16 @@ */ static struct elog_area *elog_area; static u16 total_size; -static u16 log_size; +static u16 log_size; /* excluding header */ static u32 flash_base; +static u16 full_threshold; /* from end of header */ +static u16 shrink_size; /* from end of header */ static elog_area_state area_state; static elog_header_state header_state; static elog_event_buffer_state event_buffer_state; -static u16 next_event_offset; +static u16 next_event_offset; /* from end of header */ static u16 event_count; static struct spi_flash *elog_spi; @@ -402,12 +391,12 @@ static int elog_shrink(void) elog_debug("elog_shrink()\n"); - if (next_event_offset < CONFIG_ELOG_SHRINK_SIZE) + if (next_event_offset < shrink_size) return 0; while (1) { /* Next event has exceeded constraints */ - if (offset > CONFIG_ELOG_SHRINK_SIZE) + if (offset > shrink_size) break; event = elog_get_event_base(offset); @@ -429,7 +418,7 @@ static int elog_shrink(void) elog_scan_flash(); /* Ensure the area was successfully erased */ - if (next_event_offset >= CONFIG_ELOG_FULL_THRESHOLD) { + if (next_event_offset >= full_threshold) { printk(BIOS_ERR, "ELOG: Flash area was not erased!\n"); return -1; } @@ -544,6 +533,9 @@ static void elog_find_flash(void) total_size = CONFIG_ELOG_AREA_SIZE; #endif log_size = total_size - sizeof(struct elog_header); + full_threshold = log_size - ELOG_MIN_AVAILABLE_ENTRIES * MAX_EVENT_SIZE; + shrink_size = MIN(total_size * ELOG_SHRINK_PERCENTAGE / 100, + full_threshold); } /* @@ -575,6 +567,13 @@ int elog_init(void) if (flash_base == 0) { printk(BIOS_ERR, "ELOG: Invalid flash base\n"); return -1; + } else if (total_size < sizeof(struct elog_header) + MAX_EVENT_SIZE) { + printk(BIOS_ERR, "ELOG: Region too small to hold any events\n"); + return -1; + } else if (log_size - shrink_size >= full_threshold) { + printk(BIOS_ERR, + "ELOG: SHRINK_PERCENTAGE set too small for MIN_AVAILABLE_ENTRIES\n"); + return -1; } elog_area = malloc(total_size); @@ -608,13 +607,12 @@ int elog_init(void) elog_area, flash_base); printk(BIOS_INFO, "ELOG: area is %d bytes, full threshold %d," - " shrink size %d\n", total_size, - CONFIG_ELOG_FULL_THRESHOLD, CONFIG_ELOG_SHRINK_SIZE); + " shrink size %d\n", total_size, full_threshold, shrink_size); elog_initialized = ELOG_INITIALIZED; /* Shrink the log if we are getting too full */ - if (next_event_offset >= CONFIG_ELOG_FULL_THRESHOLD) + if (next_event_offset >= full_threshold) if (elog_shrink() < 0) return -1; @@ -726,7 +724,7 @@ void elog_add_event_raw(u8 event_type, void *data, u8 data_size) event_type, event_size); /* Shrink the log if we are getting too full */ - if (next_event_offset >= CONFIG_ELOG_FULL_THRESHOLD) + if (next_event_offset >= full_threshold) elog_shrink(); } diff --git a/src/drivers/elog/elog_internal.h b/src/drivers/elog/elog_internal.h index dd282311a6..6194ef6c3e 100644 --- a/src/drivers/elog/elog_internal.h +++ b/src/drivers/elog/elog_internal.h @@ -31,6 +31,8 @@ struct elog_header { /* ELOG related constants */ #define ELOG_SIGNATURE 0x474f4c45 /* 'ELOG' */ #define ELOG_VERSION 1 +#define ELOG_MIN_AVAILABLE_ENTRIES 2 /* Shrink when this many can't fit */ +#define ELOG_SHRINK_PERCENTAGE 25 /* Percent of total area to remove */ /* SMBIOS event log header */ struct event_header { |