From e807c34a5e34e8dd7cb959458de593ea1070fde4 Mon Sep 17 00:00:00 2001 From: Duncan Laurie Date: Mon, 10 Jun 2013 09:53:33 -0700 Subject: cmos post: Guard with spinlock The CMOS post code storage mechanism does back-to-back CMOS reads and writes that may be interleaved during CPU bringup, leading to corruption of the log or of other parts of CMOS. Change-Id: I704813cc917a659fe034b71c2ff9eb9b80f7c949 Signed-off-by: Duncan Laurie Reviewed-on: https://gerrit.chromium.org/gerrit/58102 Reviewed-by: Aaron Durbin Reviewed-on: http://review.coreboot.org/4227 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer --- src/console/post.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/console') diff --git a/src/console/post.c b/src/console/post.c index f55683e4d1..11c631d4dc 100644 --- a/src/console/post.c +++ b/src/console/post.c @@ -23,6 +23,7 @@ #include #if CONFIG_CMOS_POST #include +#include #endif #include @@ -44,10 +45,14 @@ void __attribute__((weak)) mainboard_post(uint8_t value) #if CONFIG_CMOS_POST +DECLARE_SPIN_LOCK(cmos_post_lock) + #if !defined(__PRE_RAM__) void cmos_post_log(void) { - u8 code; + u8 code = 0; + + spin_lock(&cmos_post_lock); /* Get post code from other bank */ switch (cmos_read(CMOS_POST_BANK_OFFSET)) { @@ -57,10 +62,10 @@ void cmos_post_log(void) case CMOS_POST_BANK_1_MAGIC: code = cmos_read(CMOS_POST_BANK_0_OFFSET); break; - default: - return; } + spin_unlock(&cmos_post_lock); + /* Check last post code in previous boot against normal list */ switch (code) { case POST_OS_BOOT: @@ -80,6 +85,8 @@ void cmos_post_log(void) static void cmos_post_code(u8 value) { + spin_lock(&cmos_post_lock); + switch (cmos_read(CMOS_POST_BANK_OFFSET)) { case CMOS_POST_BANK_0_MAGIC: cmos_write(value, CMOS_POST_BANK_0_OFFSET); @@ -88,6 +95,8 @@ static void cmos_post_code(u8 value) cmos_write(value, CMOS_POST_BANK_1_OFFSET); break; } + + spin_unlock(&cmos_post_lock); } #endif /* CONFIG_CMOS_POST */ -- cgit v1.2.3