fmap: new API using region_device

Instead of being pointer based use the region infrastrucutre.
Additionally, this removes the need for arch-specific compilation
paths. The users of the new API can use the region APIs to memory
map or read the region provided by the new fmap API.

Change-Id: Ie36e9ff9cb554234ec394b921f029eeed6845aee
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/9170
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Aaron Durbin
2015-03-28 23:56:22 -05:00
parent b6981c0f9c
commit 0424c95a6d
16 changed files with 293 additions and 147 deletions

View File

@ -26,6 +26,7 @@
#include <pc80/mc146818rtc.h>
#endif
#include <bcd.h>
#include <fmap.h>
#include <rtc.h>
#include <smbios.h>
#include <spi-generic.h>
@ -35,7 +36,6 @@
#include <elog.h>
#include "elog_internal.h"
#include <vendorcode/google/chromeos/fmap.h>
#if !IS_ENABLED(CONFIG_CHROMEOS) && CONFIG_ELOG_FLASH_BASE == 0
#error "CONFIG_ELOG_FLASH_BASE is invalid"
@ -85,26 +85,6 @@ static inline u32 get_rom_size(void)
return rom_size;
}
/*
* Convert a memory mapped flash address into a flash offset
*/
static inline u32 elog_flash_address_to_offset(u8 *address)
{
#if CONFIG_ARCH_X86
/* For x86, assume address is memory-mapped near 4GB */
u32 rom_size;
if (!elog_spi)
return 0;
rom_size = get_rom_size();
return (u32)address - ((u32)~0UL - rom_size + 1);
#else
return (u32)(uintptr_t)address;
#endif
}
/*
* Pointer to an event log header in the event data area
*/
@ -517,21 +497,22 @@ static void elog_find_flash(void)
{
elog_debug("elog_find_flash()\n");
#if CONFIG_CHROMEOS
/* Find the ELOG base and size in FMAP */
u8 *flash_base_ptr;
int fmap_size = find_fmap_entry("RW_ELOG", (void **)&flash_base_ptr);
if (fmap_size < 0) {
printk(BIOS_WARNING, "ELOG: Unable to find RW_ELOG in FMAP\n");
flash_base = total_size = 0;
if (IS_ENABLED(CONFIG_CHROMEOS)) {
/* Find the ELOG base and size in FMAP */
struct region r;
if (fmap_locate_area("RW_ELOG", &r) < 0) {
printk(BIOS_WARNING,
"ELOG: Unable to find RW_ELOG in FMAP\n");
flash_base = total_size = 0;
} else {
flash_base = region_offset(&r);
total_size = MIN(region_sz(&r), CONFIG_ELOG_AREA_SIZE);
}
} else {
flash_base = elog_flash_address_to_offset(flash_base_ptr);
total_size = MIN(fmap_size, CONFIG_ELOG_AREA_SIZE);
flash_base = CONFIG_ELOG_FLASH_BASE;
total_size = CONFIG_ELOG_AREA_SIZE;
}
#else
flash_base = CONFIG_ELOG_FLASH_BASE;
total_size = CONFIG_ELOG_AREA_SIZE;
#endif
log_size = total_size - sizeof(struct elog_header);
full_threshold = log_size - ELOG_MIN_AVAILABLE_ENTRIES * MAX_EVENT_SIZE;
shrink_size = MIN(total_size * ELOG_SHRINK_PERCENTAGE / 100,