[coreboot-gerrit] New patch to review for coreboot: drivers/elog: remove unnecessary global state

Aaron Durbin (adurbin@chromium.org) gerrit at coreboot.org
Sat Aug 6 08:32:54 CEST 2016


Aaron Durbin (adurbin at chromium.org) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16100

-gerrit

commit 9e5ef29dc62c300bc2e77f1768834a01a3fb8173
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Fri Aug 5 15:24:33 2016 -0500

    drivers/elog: remove unnecessary global state
    
    There were 3 variables indicating the state of the event log
    region. However, there's no need to keep track of those
    individually. The only thing required is to know is if
    elog_scan_flash() failed. There's no other tracking required
    beyond that.
    
    BUG=chrome-os-partner:55932
    
    Change-Id: I88ad32091d3c37966a2ac6272f8ad95bcc8c4270
    Signed-off-by: Aaron Durbin <adurbin at chromium.org>
---
 src/drivers/elog/elog.c          | 71 ++++++++++------------------------------
 src/drivers/elog/elog_internal.h | 16 ---------
 2 files changed, 17 insertions(+), 70 deletions(-)

diff --git a/src/drivers/elog/elog.c b/src/drivers/elog/elog.c
index 40f1f9d..82f3981 100644
--- a/src/drivers/elog/elog.c
+++ b/src/drivers/elog/elog.c
@@ -50,10 +50,6 @@ static u32 flash_base;
 static u16 full_threshold;
 static u16 shrink_size;
 
-static elog_area_state area_state;
-static elog_header_state header_state;
-static elog_event_buffer_state event_buffer_state;
-
 /*
  * The non-volatile storage chases the mirrored copied. When nv_last_write
  * is less than the mirrored last write the non-volatile storage needs
@@ -221,22 +217,6 @@ static int elog_is_buffer_clear(size_t offset)
 }
 
 /*
- * Check that the ELOG area has been initialized and is valid.
- */
-static int elog_is_area_valid(void)
-{
-	elog_debug("elog_is_area_valid()\n");
-
-	if (area_state != ELOG_AREA_HAS_CONTENT)
-		return 0;
-	if (header_state != ELOG_HEADER_VALID)
-		return 0;
-	if (event_buffer_state != ELOG_EVENT_BUFFER_OK)
-		return 0;
-	return 1;
-}
-
-/*
  * Verify if the mirrored elog structure is valid.
  * Returns 1 if the header is valid, 0 otherwise
  */
@@ -355,7 +335,7 @@ static void elog_flash_erase(void)
 /*
  * Scan the event area and validate each entry and update the ELOG state.
  */
-static void elog_update_event_buffer_state(void)
+static int elog_update_event_buffer_state(void)
 {
 	size_t offset = elog_events_start();
 
@@ -370,8 +350,7 @@ static void elog_update_event_buffer_state(void)
 
 		if (rdev_readat(mirror_dev_get(), &type,
 				offset + type_offset, size) < 0) {
-			event_buffer_state = ELOG_EVENT_BUFFER_CORRUPTED;
-			break;
+			return -1;
 		}
 
 		/* The end of the event marker has been found */
@@ -381,10 +360,8 @@ static void elog_update_event_buffer_state(void)
 		/* Validate the event */
 		len = elog_is_event_valid(offset);
 
-		if (!len) {
-			event_buffer_state = ELOG_EVENT_BUFFER_CORRUPTED;
-			break;
-		}
+		if (!len)
+			return -1;
 
 		/* Move to the next event */
 		elog_tandem_increment_last_write(len);
@@ -393,19 +370,17 @@ static void elog_update_event_buffer_state(void)
 
 	/* Ensure the remaining buffer is empty */
 	if (!elog_is_buffer_clear(offset))
-		event_buffer_state = ELOG_EVENT_BUFFER_CORRUPTED;
+		return -1;
+
+	return 0;
 }
 
-static void elog_scan_flash(void)
+static int elog_scan_flash(void)
 {
 	elog_debug("elog_scan_flash()\n");
 	void *mirror_buffer;
 	const struct region_device *rdev = mirror_dev_get();
 
-	area_state = ELOG_AREA_UNDEFINED;
-	header_state = ELOG_HEADER_INVALID;
-	event_buffer_state = ELOG_EVENT_BUFFER_OK;
-
 	/* Fill memory buffer by reading from SPI */
 	mirror_buffer = rdev_mmap_full(rdev);
 	elog_spi->read(elog_spi, flash_base, total_size, mirror_buffer);
@@ -415,24 +390,17 @@ static void elog_scan_flash(void)
 	elog_tandem_reset_last_write();
 
 	/* Check if the area is empty or not */
-	if (elog_is_buffer_clear(0)) {
-		area_state = ELOG_AREA_EMPTY;
-		return;
-	}
-
-	area_state = ELOG_AREA_HAS_CONTENT;
+	if (elog_is_buffer_clear(0))
+		return -1;
 
 	/* Indicate that header possibly written. */
 	elog_tandem_increment_last_write(elog_events_start());
 
 	/* Validate the header */
-	if (!elog_is_header_valid()) {
-		header_state = ELOG_HEADER_INVALID;
-		return;
-	}
+	if (!elog_is_header_valid())
+		return -1;
 
-	header_state = ELOG_HEADER_VALID;
-	elog_update_event_buffer_state();
+	return elog_update_event_buffer_state();
 }
 
 static void elog_write_header_in_mirror(void)
@@ -566,7 +534,7 @@ static int elog_prepare_empty(void)
 	elog_debug("elog_prepare_empty()\n");
 	elog_shrink_by_size(elog_events_total_space());
 
-	if (!elog_is_area_valid())
+	if (elog_initialized != ELOG_INITIALIZED)
 		return -1;
 
 	return 0;
@@ -704,10 +672,8 @@ static int elog_sync_to_nv(void)
 	if (!erase_needed)
 		return 0;
 
-	elog_scan_flash();
-
 	/* Mark broken if the scan failed after a sync. */
-	if (!elog_is_area_valid()) {
+	if (elog_scan_flash() < 0) {
 		printk(BIOS_ERR, "ELOG: Sync back from NV storage failed.\n");
 		elog_initialized = ELOG_BROKEN;
 		return -1;
@@ -763,15 +729,12 @@ int elog_init(void)
 	}
 	mem_region_device_rw_init(&mirror_dev, mirror_buffer, total_size);
 
-	/* Load the log from flash */
-	elog_scan_flash();
-
 	/* Mark as initialized to allow elog_init() to be called and deemed
 	 * successful in the prepare/shrink path which adds events. */
 	elog_initialized = ELOG_INITIALIZED;
 
-	/* Prepare the flash if necessary */
-	if (!elog_is_area_valid()) {
+	/* Load the log from flash and prepare the flash if necessary. */
+	if (elog_scan_flash() < 0) {
 		printk(BIOS_ERR, "ELOG: flash area invalid\n");
 		if (elog_prepare_empty() < 0) {
 			printk(BIOS_ERR, "ELOG: Unable to prepare flash\n");
diff --git a/src/drivers/elog/elog_internal.h b/src/drivers/elog/elog_internal.h
index ef21bf0..a09bbef 100644
--- a/src/drivers/elog/elog_internal.h
+++ b/src/drivers/elog/elog_internal.h
@@ -45,20 +45,4 @@ struct event_header {
 /* SMBIOS Type 15 related constants */
 #define ELOG_HEADER_TYPE_OEM		0x88
 
-typedef enum elog_area_state {
-	ELOG_AREA_UNDEFINED,		/* Initial boot strap state */
-	ELOG_AREA_EMPTY,		/* Entire area is empty */
-	ELOG_AREA_HAS_CONTENT,		/* Area has some content */
-} elog_area_state;
-
-typedef enum elog_header_state {
-	ELOG_HEADER_INVALID,
-	ELOG_HEADER_VALID,
-} elog_header_state;
-
-typedef enum elog_event_buffer_state {
-	ELOG_EVENT_BUFFER_OK,
-	ELOG_EVENT_BUFFER_CORRUPTED,
-} elog_event_buffer_state;
-
 #endif /* ELOG_INTERNAL_H_ */



More information about the coreboot-gerrit mailing list