From 07056feba09dc13f5817d708c363ed256a0f94ab Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Thu, 20 May 2021 11:35:15 +0200 Subject: [PATCH] option: Decouple API from CMOS backend Prepare to allow using other backends to store options. Change-Id: I3f838d27bf476207c6dc8f2c1f15c3fa9ae47d87 Signed-off-by: Angel Pons Reviewed-on: https://review.coreboot.org/c/coreboot/+/54727 Tested-by: build bot (Jenkins) Reviewed-by: Arthur Heymans --- src/drivers/pc80/rtc/option.c | 15 +++++++++++++-- src/include/option.h | 28 +++++++++++++--------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/drivers/pc80/rtc/option.c b/src/drivers/pc80/rtc/option.c index cc4138bfd7..1474b57057 100644 --- a/src/drivers/pc80/rtc/option.c +++ b/src/drivers/pc80/rtc/option.c @@ -84,7 +84,7 @@ static struct cmos_entries *find_cmos_entry(struct cmos_option_table *ct, const return NULL; } -enum cb_err cmos_get_uint_option(unsigned int *dest, const char *name) +static enum cb_err cmos_get_uint_option(unsigned int *dest, const char *name) { struct cmos_option_table *ct; struct cmos_entries *ce; @@ -113,6 +113,12 @@ enum cb_err cmos_get_uint_option(unsigned int *dest, const char *name) return CB_SUCCESS; } +unsigned int get_uint_option(const char *name, const unsigned int fallback) +{ + unsigned int value = 0; + return cmos_get_uint_option(&value, name) == CB_SUCCESS ? value : fallback; +} + static enum cb_err set_cmos_value(unsigned long bit, unsigned long length, void *vret) { @@ -154,7 +160,7 @@ static enum cb_err set_cmos_value(unsigned long bit, unsigned long length, return CB_SUCCESS; } -enum cb_err cmos_set_uint_option(const char *name, unsigned int *value) +static enum cb_err cmos_set_uint_option(const char *name, unsigned int *value) { struct cmos_option_table *ct; struct cmos_entries *ce; @@ -180,6 +186,11 @@ enum cb_err cmos_set_uint_option(const char *name, unsigned int *value) return CB_SUCCESS; } +enum cb_err set_uint_option(const char *name, unsigned int value) +{ + return cmos_set_uint_option(name, &value); +} + int cmos_lb_cks_valid(void) { return cmos_checksum_valid(LB_CKS_RANGE_START, LB_CKS_RANGE_END, LB_CKS_LOC); diff --git a/src/include/option.h b/src/include/option.h index 74a6bbbfc2..40893788f3 100644 --- a/src/include/option.h +++ b/src/include/option.h @@ -7,25 +7,23 @@ void sanitize_cmos(void); -enum cb_err cmos_set_uint_option(const char *name, unsigned int *value); -enum cb_err cmos_get_uint_option(unsigned int *dest, const char *name); - -static inline enum cb_err set_uint_option(const char *name, unsigned int value) -{ - if (CONFIG(USE_OPTION_TABLE)) - return cmos_set_uint_option(name, &value); - - return CB_CMOS_OTABLE_DISABLED; -} +#if !CONFIG(USE_OPTION_TABLE) static inline unsigned int get_uint_option(const char *name, const unsigned int fallback) { - if (CONFIG(USE_OPTION_TABLE)) { - unsigned int value = 0; - if (cmos_get_uint_option(&value, name) == CB_SUCCESS) - return value; - } return fallback; } +static inline enum cb_err set_uint_option(const char *name, unsigned int value) +{ + return CB_CMOS_OTABLE_DISABLED; +} + +#else /* USE_OPTION_TABLE */ + +unsigned int get_uint_option(const char *name, const unsigned int fallback); +enum cb_err set_uint_option(const char *name, unsigned int value); + +#endif /* USE_OPTION_TABLE? */ + #endif /* _OPTION_H_ */