Tim Wawrzynczak has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/44782 )
Change subject: fw_config: Add caching to successfully probed fields ......................................................................
fw_config: Add caching to successfully probed fields
Add a backing cache for all successfully probed fw_config fields. This allows recall of the `struct fw_config` which was probed.
BUG=b:161963281 TEST=tested with follower patch
Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org Change-Id: I0d014206a4ee6cc7592e12e704a7708652330eaf --- M src/include/fw_config.h M src/lib/fw_config.c 2 files changed, 37 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/82/44782/1
diff --git a/src/include/fw_config.h b/src/include/fw_config.h index d41afd6..ca4e8c6 100644 --- a/src/include/fw_config.h +++ b/src/include/fw_config.h @@ -40,6 +40,13 @@ */ bool fw_config_probe(const struct fw_config *match);
+/** + * fw_config_for_each_found() - Call a callback for each fw_config field found + * @cb: The callback function + * @arg: A context argument that is passed to the callback + */ +void fw_config_for_each_found(void (*cb)(const struct fw_config *config, void *arg), void *arg); + #else
static inline bool fw_config_probe(const struct fw_config *match) diff --git a/src/lib/fw_config.c b/src/lib/fw_config.c index e97cfdc..9dea196 100644 --- a/src/lib/fw_config.c +++ b/src/lib/fw_config.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */
+#include <assert.h> #include <bootstate.h> #include <cbfs.h> #include <console/console.h> @@ -9,6 +10,17 @@ #include <stdbool.h> #include <stdint.h>
+#if ENV_RAMSTAGE +/* + * The maximum number of fw_config fields is limited by the 32-bit mask that is used to + * represent them. + */ +#define MAX_CACHE_ELEMENTS (8 * sizeof(uint32_t)) + +static struct fw_config cached_configs[MAX_CACHE_ELEMENTS]; +static size_t cache_count; +#endif + /** * fw_config_get() - Provide firmware configuration value. * @@ -59,6 +71,15 @@ else printk(BIOS_INFO, "fw_config match found: mask=0x%08x value=0x%08x\n", match->mask, match->value); + +#if ENV_RAMSTAGE + if (fw_config_get_cached(match->mask) == NULL) { + assert(cache_count < MAX_CACHE_ELEMENTS); + memcpy(&cached_configs[cache_count], match, sizeof(struct fw_config)); + ++cache_count; + } +#endif + return true; }
@@ -66,6 +87,15 @@ }
#if ENV_RAMSTAGE + +void fw_config_for_each_found(void (*cb)(const struct fw_config *config, void *arg), void *arg) +{ + size_t i; + + for (i = 0; i < cache_count; ++i) + cb(&cached_configs[i], arg); +} + static void fw_config_init(void *unused) { struct device *dev;