Karthik Ramasubramanian has uploaded this change for review. ( https://review.coreboot.org/29358
Change subject: drivers/elog: Add support for early elog ......................................................................
drivers/elog: Add support for early elog
Add support to log events during the romstage.
BUG=b:117884485
Change-Id: Ia69515961da3bc72740f9b048a53d91af79c5b0d Signed-off-by: Karthikeyan Ramasubramanian kramasub@google.com --- M src/drivers/elog/Makefile.inc M src/drivers/elog/elog.c 2 files changed, 37 insertions(+), 6 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/58/29358/1
diff --git a/src/drivers/elog/Makefile.inc b/src/drivers/elog/Makefile.inc index 79a7cc0..e0c42e2 100644 --- a/src/drivers/elog/Makefile.inc +++ b/src/drivers/elog/Makefile.inc @@ -1,3 +1,4 @@ +romstage-$(CONFIG_ELOG) += elog.c ramstage-$(CONFIG_ELOG) += elog.c
smm-$(CONFIG_ELOG_GSMI) += elog.c gsmi.c diff --git a/src/drivers/elog/elog.c b/src/drivers/elog/elog.c index d3c01c2..7d0e0a9 100644 --- a/src/drivers/elog/elog.c +++ b/src/drivers/elog/elog.c @@ -16,6 +16,7 @@ #if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME) #include <arch/acpi.h> #endif +#include <arch/early_variables.h> #include <bootstate.h> #include <cbmem.h> #include <console/console.h> @@ -42,6 +43,15 @@ #endif
#define NV_NEEDS_ERASE (~(size_t)0) +enum elog_state { + ELOG_UNINITIALIZED = 0, + ELOG_INITIALIZED, + ELOG_BROKEN, +}; + +#define MAX_ELOG_SIZE (4 * KiB) + +#if ENV_RAMSTAGE /* * Static variables for ELOG state */ @@ -60,11 +70,29 @@ /* Device that mirrors the eventlog in memory. */ static struct mem_region_device mirror_dev;
-static enum { - ELOG_UNINITIALIZED = 0, - ELOG_INITIALIZED, - ELOG_BROKEN, -} elog_initialized = ELOG_UNINITIALIZED; +static enum elog_state elog_initialized; + +static uint8_t * get_elog_mirror_buffer(size_t elog_size) { + if (elog_size == MAX_ELOG_SIZE) + return (uint8_t *)malloc(elog_size); + return NULL; +} +#else +static u16 full_threshold CAR_GLOBAL; +static u16 shrink_size CAR_GLOBAL; +static size_t mirror_last_write CAR_GLOBAL; +static size_t nv_last_write CAR_GLOBAL; +static struct region_device nv_dev CAR_GLOBAL; +static struct mem_region_device mirror_dev CAR_GLOBAL; +static enum elog_state elog_initialized CAR_GLOBAL; +static uint8_t early_elog_buf[MAX_ELOG_SIZE] CAR_GLOBAL; + +static uint8_t * get_elog_mirror_buffer(size_t elog_size) { + if (elog_size == MAX_ELOG_SIZE) + return (uint8_t *)car_get_var_ptr(early_elog_buf); + return NULL; +} +#endif
static inline struct region_device *mirror_dev_get(void) { @@ -776,7 +804,7 @@ return -1;
elog_size = region_device_sz(&nv_dev); - mirror_buffer = malloc(elog_size); + mirror_buffer = get_elog_mirror_buffer(elog_size); if (!mirror_buffer) { printk(BIOS_ERR, "ELOG: Unable to allocate backing store\n"); return -1; @@ -800,6 +828,7 @@ full_threshold, shrink_size);
if (elog_do_add_boot_count()) { +#if ENV_RAMSTAGE elog_add_event_dword(ELOG_TYPE_BOOT, boot_count_read());
#if IS_ENABLED(CONFIG_ARCH_X86) @@ -807,6 +836,7 @@ if (IS_ENABLED(CONFIG_CMOS_POST)) cmos_post_log(); #endif +#endif /* ENV_RAMSTAGE */ } return 0; }