diff options
Diffstat (limited to 'src/drivers/elog')
-rw-r--r-- | src/drivers/elog/elog.c | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/src/drivers/elog/elog.c b/src/drivers/elog/elog.c index 768ea28468..97a9c7fa79 100644 --- a/src/drivers/elog/elog.c +++ b/src/drivers/elog/elog.c @@ -65,14 +65,14 @@ struct elog_state { enum elog_init_state elog_initialized; }; -static struct elog_state g_elog_state; +static struct elog_state elog_state; #define ELOG_SIZE (4 * KiB) static uint8_t elog_mirror_buf[ELOG_SIZE]; static inline struct region_device *mirror_dev_get(void) { - return &g_elog_state.mirror_dev.rdev; + return &elog_state.mirror_dev.rdev; } static size_t elog_events_start(void) @@ -83,7 +83,7 @@ static size_t elog_events_start(void) static size_t elog_events_total_space(void) { - return region_device_sz(&g_elog_state.nv_dev) - elog_events_start(); + return region_device_sz(&elog_state.nv_dev) - elog_events_start(); } static struct event_header *elog_get_event_buffer(size_t offset, size_t size) @@ -93,8 +93,9 @@ static struct event_header *elog_get_event_buffer(size_t offset, size_t size) static struct event_header *elog_get_next_event_buffer(size_t size) { - elog_debug("ELOG: new event at offset 0x%zx\n", g_elog_state.mirror_last_write); - return elog_get_event_buffer(g_elog_state.mirror_last_write, size); + elog_debug("ELOG: new event at offset 0x%zx\n", + elog_state.mirror_last_write); + return elog_get_event_buffer(elog_state.mirror_last_write, size); } static void elog_put_event_buffer(struct event_header *event) @@ -105,53 +106,53 @@ static void elog_put_event_buffer(struct event_header *event) static size_t elog_mirror_reset_last_write(void) { /* Return previous write value. */ - size_t prev = g_elog_state.mirror_last_write; + size_t prev = elog_state.mirror_last_write; - g_elog_state.mirror_last_write = 0; + elog_state.mirror_last_write = 0; return prev; } static void elog_mirror_increment_last_write(size_t size) { - g_elog_state.mirror_last_write += size; + elog_state.mirror_last_write += size; } static void elog_nv_reset_last_write(void) { - g_elog_state.nv_last_write = 0; + elog_state.nv_last_write = 0; } static void elog_nv_increment_last_write(size_t size) { - g_elog_state.nv_last_write += size; + elog_state.nv_last_write += size; } static void elog_nv_needs_possible_erase(void) { /* If last write is 0 it means it is already erased. */ - if (g_elog_state.nv_last_write != 0) - g_elog_state.nv_last_write = NV_NEEDS_ERASE; + if (elog_state.nv_last_write != 0) + elog_state.nv_last_write = NV_NEEDS_ERASE; } static bool elog_should_shrink(void) { - return g_elog_state.mirror_last_write >= g_elog_state.full_threshold; + return elog_state.mirror_last_write >= elog_state.full_threshold; } static bool elog_nv_needs_erase(void) { - return g_elog_state.nv_last_write == NV_NEEDS_ERASE; + return elog_state.nv_last_write == NV_NEEDS_ERASE; } static bool elog_nv_needs_update(void) { - return g_elog_state.nv_last_write != g_elog_state.mirror_last_write; + return elog_state.nv_last_write != elog_state.mirror_last_write; } static size_t elog_nv_region_to_update(size_t *offset) { - *offset = g_elog_state.nv_last_write; - return g_elog_state.mirror_last_write - g_elog_state.nv_last_write; + *offset = elog_state.nv_last_write; + return elog_state.mirror_last_write - elog_state.nv_last_write; } /* @@ -335,7 +336,7 @@ static void elog_nv_write(size_t offset, size_t size) return; /* Write the data to flash */ - if (rdev_writeat(&g_elog_state.nv_dev, address, offset, size) != size) + if (rdev_writeat(&elog_state.nv_dev, address, offset, size) != size) printk(BIOS_ERR, "ELOG: NV Write failed at 0x%zx, size 0x%zx\n", offset, size); @@ -348,11 +349,11 @@ static void elog_nv_write(size_t offset, size_t size) */ static void elog_nv_erase(void) { - size_t size = region_device_sz(&g_elog_state.nv_dev); + size_t size = region_device_sz(&elog_state.nv_dev); elog_debug("%s()\n", __func__); /* Erase the sectors in this region */ - if (rdev_eraseat(&g_elog_state.nv_dev, 0, size) != size) + if (rdev_eraseat(&elog_state.nv_dev, 0, size) != size) printk(BIOS_ERR, "ELOG: erase failure.\n"); } @@ -411,11 +412,11 @@ static int elog_scan_flash(void) void *mirror_buffer; const struct region_device *rdev = mirror_dev_get(); - size_t size = region_device_sz(&g_elog_state.nv_dev); + size_t size = region_device_sz(&elog_state.nv_dev); /* Fill memory buffer by reading from SPI */ mirror_buffer = rdev_mmap_full(rdev); - if (rdev_readat(&g_elog_state.nv_dev, mirror_buffer, 0, size) != size) { + if (rdev_readat(&elog_state.nv_dev, mirror_buffer, 0, size) != size) { rdev_munmap(rdev, mirror_buffer); printk(BIOS_ERR, "ELOG: NV read failure.\n"); return -1; @@ -580,7 +581,7 @@ static int elog_prepare_empty(void) static int elog_shrink(void) { if (elog_should_shrink()) - return elog_shrink_by_size(g_elog_state.shrink_size); + return elog_shrink_by_size(elog_state.shrink_size); return 0; } @@ -593,12 +594,13 @@ static inline u8 *elog_flash_offset_to_address(void) if (!CONFIG(BOOT_DEVICE_MEMORY_MAPPED)) return NULL; - if (!region_device_sz(&g_elog_state.nv_dev)) + if (!region_device_sz(&elog_state.nv_dev)) return NULL; /* Get a view into the read-only boot device. */ - return rdev_mmap(boot_device_ro(), region_device_offset(&g_elog_state.nv_dev), - region_device_sz(&g_elog_state.nv_dev)); + return rdev_mmap(boot_device_ro(), + region_device_offset(&elog_state.nv_dev), + region_device_sz(&elog_state.nv_dev)); } /* @@ -611,7 +613,7 @@ int elog_smbios_write_type15(unsigned long *current, int handle) int len = sizeof(struct smbios_type15); uintptr_t log_address; - size_t elog_size = region_device_sz(&g_elog_state.nv_dev); + size_t elog_size = region_device_sz(&elog_state.nv_dev); if (CONFIG(ELOG_CBMEM)) { /* Save event log buffer into CBMEM for the OS to read */ @@ -665,7 +667,7 @@ static int elog_find_flash(void) { size_t total_size; size_t reserved_space = ELOG_MIN_AVAILABLE_ENTRIES * MAX_EVENT_SIZE; - struct region_device *rdev = &g_elog_state.nv_dev; + struct region_device *rdev = &elog_state.nv_dev; elog_debug("%s()\n", __func__); @@ -688,10 +690,10 @@ static int elog_find_flash(void) total_size = MIN(ELOG_SIZE, region_device_sz(rdev)); rdev_chain(rdev, rdev, 0, total_size); - g_elog_state.full_threshold = total_size - reserved_space; - g_elog_state.shrink_size = total_size * ELOG_SHRINK_PERCENTAGE / 100; + elog_state.full_threshold = total_size - reserved_space; + elog_state.shrink_size = total_size * ELOG_SHRINK_PERCENTAGE / 100; - if (reserved_space > g_elog_state.shrink_size) { + if (reserved_space > elog_state.shrink_size) { printk(BIOS_ERR, "ELOG: SHRINK_PERCENTAGE too small\n"); return -1; } @@ -734,7 +736,7 @@ static int elog_sync_to_nv(void) if (elog_scan_flash() < 0) { printk(BIOS_ERR, "ELOG: Sync back from NV storage failed.\n"); elog_debug_dump_buffer("ELOG: Buffer from NV:\n"); - g_elog_state.elog_initialized = ELOG_BROKEN; + elog_state.elog_initialized = ELOG_BROKEN; return -1; } @@ -776,7 +778,7 @@ int elog_init(void) { void *mirror_buffer; size_t elog_size; - switch (g_elog_state.elog_initialized) { + switch (elog_state.elog_initialized) { case ELOG_UNINITIALIZED: break; case ELOG_INITIALIZED: @@ -784,7 +786,7 @@ int elog_init(void) case ELOG_BROKEN: return -1; } - g_elog_state.elog_initialized = ELOG_BROKEN; + elog_state.elog_initialized = ELOG_BROKEN; elog_debug("elog_init()\n"); @@ -792,19 +794,20 @@ int elog_init(void) if (elog_find_flash() < 0) return -1; - elog_size = region_device_sz(&g_elog_state.nv_dev); + elog_size = region_device_sz(&elog_state.nv_dev); mirror_buffer = elog_mirror_buf; if (!mirror_buffer) { printk(BIOS_ERR, "ELOG: Unable to allocate backing store\n"); return -1; } - mem_region_device_rw_init(&g_elog_state.mirror_dev, mirror_buffer, elog_size); + mem_region_device_rw_init(&elog_state.mirror_dev, mirror_buffer, + elog_size); /* * Mark as initialized to allow elog_init() to be called and deemed * successful in the prepare/shrink path which adds events. */ - g_elog_state.elog_initialized = ELOG_INITIALIZED; + elog_state.elog_initialized = ELOG_INITIALIZED; /* Load the log from flash and prepare the flash if necessary. */ if (elog_scan_flash() < 0 && elog_prepare_empty() < 0) { @@ -813,8 +816,8 @@ int elog_init(void) } printk(BIOS_INFO, "ELOG: area is %zu bytes, full threshold %d," - " shrink size %d\n", region_device_sz(&g_elog_state.nv_dev), - g_elog_state.full_threshold, g_elog_state.shrink_size); + " shrink size %d\n", region_device_sz(&elog_state.nv_dev), + elog_state.full_threshold, elog_state.shrink_size); if (ENV_PAYLOAD_LOADER) elog_add_boot_count(); |