Arthur Heymans has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/35828 )
Change subject: drivers/pc80/rtc: Cache the cmos_layout.bin in cbmem ......................................................................
drivers/pc80/rtc: Cache the cmos_layout.bin in cbmem
TODO: Move this as a cbmem lb_table record and have applications use it as such.
Change-Id: Ie2ef9f623fef8a87465ddc7f85a23282f616cdec Signed-off-by: Arthur Heymans arthur@aheymans.xyz --- M src/commonlib/include/commonlib/cbmem_id.h M src/drivers/pc80/rtc/mc146818rtc.c M src/lib/coreboot_table.c 3 files changed, 49 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/28/35828/1
diff --git a/src/commonlib/include/commonlib/cbmem_id.h b/src/commonlib/include/commonlib/cbmem_id.h index 30bf88a..26831d7 100644 --- a/src/commonlib/include/commonlib/cbmem_id.h +++ b/src/commonlib/include/commonlib/cbmem_id.h @@ -77,6 +77,7 @@ #define CBMEM_ID_ROM2 0x524f4d32 #define CBMEM_ID_ROM3 0x524f4d33 #define CBMEM_ID_FMAP 0x464d4150 +#define CBMEM_ID_CMOS_LAYOUT 0x90b91aa4
#define CBMEM_ID_TO_NAME_TABLE \ { CBMEM_ID_ACPI, "ACPI " }, \ diff --git a/src/drivers/pc80/rtc/mc146818rtc.c b/src/drivers/pc80/rtc/mc146818rtc.c index ecb02e8..b6d2f8e 100644 --- a/src/drivers/pc80/rtc/mc146818rtc.c +++ b/src/drivers/pc80/rtc/mc146818rtc.c @@ -30,6 +30,7 @@ #include <security/vboot/vbnv.h> #include <security/vboot/vbnv_layout.h> #include <types.h> +#include <cbmem.h>
/* There's no way around this include guard. option_table.h is autogenerated */ #if CONFIG(USE_OPTION_TABLE) @@ -279,6 +280,50 @@ return CB_SUCCESS; }
+static void layout_register_cache(int unused) +{ + const struct cbmem_entry *e; + struct mem_region_device mdev; + + if (!CONFIG(USE_OPTION_TABLE)) + return; + + e = cbmem_entry_find(CBMEM_ID_CMOS_LAYOUT); + + if (!e) + return; + + mem_region_device_ro_init(&mdev, cbmem_entry_start(e), cbmem_entry_size(e)); + car_set_var(layout_rdev, mdev.rdev); + car_set_ptr(layout_rdev_p, car_get_ptr(&layout_rdev)); + +} + +static void layout_setup_cache(int unused) +{ + struct region_device rdev; + struct cmos_option_table *cmos_layout_cbmem; + + if (!CONFIG(USE_OPTION_TABLE)) + return; + + if (locate_cmos_layout(&rdev) != CB_SUCCESS) + return; + + struct cmos_option_table *ct = rdev_mmap_full(&rdev); + cmos_layout_cbmem = cbmem_add(CBMEM_ID_CMOS_LAYOUT, ct->size); + if (cmos_layout_cbmem == NULL) + return; + + memcpy(cmos_layout_cbmem, ct, ct->size); + + layout_register_cache(unused); +} + +ROMSTAGE_CBMEM_INIT_HOOK(layout_setup_cache) +POSTCAR_CBMEM_INIT_HOOK(layout_register_cache) +RAMSTAGE_CBMEM_INIT_HOOK(layout_register_cache) + enum cb_err get_option(void *dest, const char *name) { struct cmos_option_table *ct; diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c index d3576e6..8665891 100644 --- a/src/lib/coreboot_table.c +++ b/src/lib/coreboot_table.c @@ -508,14 +508,14 @@ #if CONFIG(USE_OPTION_TABLE) { struct cmos_option_table *option_table = - cbfs_boot_map_with_leak("cmos_layout.bin", - CBFS_COMPONENT_CMOS_LAYOUT, NULL); + cbmem_find(CBMEM_ID_CMOS_LAYOUT); if (option_table) { struct lb_record *rec_dest = lb_new_record(head); /* Copy the option config table, it's already a * lb_record... + * TODO just use a CMBMEM pointer... */ - memcpy(rec_dest, option_table, option_table->size); + memcpy(rec_dest, option_table, option_table->size); /* Create cmos checksum entry in coreboot table */ lb_cmos_checksum(head); } else {