drivers/elog: use offsets for checking cleared buffers

There's only 2 users of checking if the event buffer is cleared
to the EOL value. Each were passing pointers of the in-memory
mirror while also doing calculations for the size to check. Since
the in-memory mirror is one big buffer the only thing required
to know is the offset to start checking from. The check is always
done through the end of the buffer.

BUG=chrome-os-partner:55932

Change-Id: Icd4a7edc74407d6578fc93e9eb533abd3aa17277
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://review.coreboot.org/16096
Tested-by: build bot (Jenkins)
Reviewed-by: Furquan Shaikh <furquan@google.com>
This commit is contained in:
Aaron Durbin 2016-08-04 10:21:06 -05:00 committed by Martin Roth
parent bec07535ac
commit 422c440fa6
1 changed files with 19 additions and 6 deletions

View File

@ -98,14 +98,16 @@ static u8 elog_checksum_event(struct event_header *event)
}
/*
* Check if a raw buffer is filled with ELOG_TYPE_EOL byte
* Check if mirrored buffer is filled with ELOG_TYPE_EOL byte from the
* provided offset to the end of the mirrored buffer.
*/
static int elog_is_buffer_clear(void *base, u32 size)
static int elog_is_buffer_clear(size_t offset)
{
u8 *current = base;
size_t size = total_size - offset;
u8 *current = offset + (u8 *)elog_area;
u8 *end = current + size;
elog_debug("elog_is_buffer_clear(base=0x%p size=%u)\n", base, size);
elog_debug("elog_is_buffer_clear(offset=%zu size=%zu)\n", offset, size);
for (; current != end; current++) {
if (*current != ELOG_TYPE_EOL)
@ -114,6 +116,17 @@ static int elog_is_buffer_clear(void *base, u32 size)
return 1;
}
static int elog_event_buffer_is_clear(size_t offset)
{
/*
* Events are appended relative to the end of the header. Update
* offset to include the header size.
*/
offset += sizeof(struct elog_header);
return elog_is_buffer_clear(offset);
}
/*
* Check that the ELOG area has been initialized and is valid.
*/
@ -288,7 +301,7 @@ static void elog_update_event_buffer_state(void)
}
/* Ensure the remaining buffer is empty */
if (!elog_is_buffer_clear(&elog_area->data[offset], log_size - offset))
if (!elog_event_buffer_is_clear(offset))
event_buffer_state = ELOG_EVENT_BUFFER_CORRUPTED;
/* Update ELOG state */
@ -311,7 +324,7 @@ static void elog_scan_flash(void)
event_count = 0;
/* Check if the area is empty or not */
if (elog_is_buffer_clear(elog_area, total_size)) {
if (elog_is_buffer_clear(0)) {
area_state = ELOG_AREA_EMPTY;
return;
}