aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEric Lai <eric_lai@quanta.corp-partner.google.com>2022-12-14 15:48:35 +0800
committerMartin L Roth <gaumless@gmail.com>2022-12-17 20:43:16 +0000
commit5b89bf4666424bb9b5c72d8fa2b30a124ac1026d (patch)
tree4170645a6ec2d2078a70e8e6f61df948cbd03f4b /src
parentf49fcc6bf5ced406ce614ff8cc4dd7f172b38d65 (diff)
lib: Introduce fw_config_get_field
In some cases, fw_config is used for ids like sar_id, sku_id etc. To avoid calling fw_config_probe over and over, hence provide the method to return the value then caller can use the switch case instead of if else statement. TEST=get fw_config field value on nivviks. [INFO ] fw_config get field name=DB_USB, mask=0x3, shift=0, value =0x1 Signed-off-by: Eric Lai <eric_lai@quanta.corp-partner.google.com> Change-Id: Iae89668e8fe7322d5a4dcbf88a97d7ed36619af5 Reviewed-on: https://review.coreboot.org/c/coreboot/+/70745 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-by: Tim Wawrzynczak <inforichland@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/include/fw_config.h20
-rw-r--r--src/lib/fw_config.c15
2 files changed, 35 insertions, 0 deletions
diff --git a/src/include/fw_config.h b/src/include/fw_config.h
index 7a8ad30482..04fdf98921 100644
--- a/src/include/fw_config.h
+++ b/src/include/fw_config.h
@@ -24,6 +24,11 @@ struct fw_config {
uint64_t value;
};
+struct fw_config_field {
+ const char *field_name;
+ uint64_t mask;
+};
+
/* Generate a pointer to a compound literal of the fw_config structure. */
#define FW_CONFIG(__field, __option) (&(const struct fw_config) { \
.field_name = FW_CONFIG_FIELD_##__field##_NAME, \
@@ -32,6 +37,11 @@ struct fw_config {
.value = FW_CONFIG_FIELD_##__field##_OPTION_##__option##_VALUE \
})
+#define FW_CONFIG_FIELD(__field) (&(const struct fw_config_field) { \
+ .field_name = FW_CONFIG_FIELD_##__field##_NAME, \
+ .mask = FW_CONFIG_FIELD_##__field##_MASK, \
+})
+
/**
* fw_config_get() - Provide firmware configuration value.
*
@@ -42,6 +52,16 @@ uint64_t fw_config_get(void);
#if CONFIG(FW_CONFIG)
/**
+ * fw_config_get_field() - Provide firmware configuration field value.
+ * @field: Structure containing field name and mask
+ *
+ * Return 64bit firmware configuration value determined for the system.
+ * Will return UNDEFINED_FW_CONFIG if unprovisioned, caller should treat
+ * as error value for the case.
+ */
+uint64_t fw_config_get_field(const struct fw_config_field *field);
+
+/**
* fw_config_probe() - Check if field and option matches.
* @match: Structure containing field and option to probe.
*
diff --git a/src/lib/fw_config.c b/src/lib/fw_config.c
index 72cf225cae..e1fbe74793 100644
--- a/src/lib/fw_config.c
+++ b/src/lib/fw_config.c
@@ -59,6 +59,21 @@ uint64_t fw_config_get(void)
return fw_config_value;
}
+uint64_t fw_config_get_field(const struct fw_config_field *field)
+{
+ /* If fw_config is not provisioned, then there is nothing to get. */
+ if (!fw_config_is_provisioned())
+ return UNDEFINED_FW_CONFIG;
+
+ int shift = __ffs64(field->mask);
+ const uint64_t value = (fw_config_get() & field->mask) >> shift;
+
+ printk(BIOS_INFO, "fw_config get field name=%s, mask=0x%" PRIx64 ", shift=%d, value=0x%"
+ PRIx64 "\n", field->field_name, field->mask, shift, value);
+
+ return value;
+}
+
bool fw_config_probe(const struct fw_config *match)
{
/* If fw_config is not provisioned, then there is nothing to match. */