2020-04-02 23:48:27 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2020-01-05 07:05:45 +01:00
|
|
|
|
2014-01-28 09:02:53 +01:00
|
|
|
#ifndef _OPTION_H_
|
|
|
|
#define _OPTION_H_
|
|
|
|
|
|
|
|
#include <types.h>
|
2020-01-05 07:05:45 +01:00
|
|
|
|
2020-01-04 17:04:39 +01:00
|
|
|
void sanitize_cmos(void);
|
|
|
|
|
2021-04-23 14:34:49 +02:00
|
|
|
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);
|
2020-01-05 07:05:45 +01:00
|
|
|
|
2021-04-26 17:10:28 +02:00
|
|
|
static inline enum cb_err set_uint_option(const char *name, unsigned int value)
|
2014-01-28 09:02:53 +01:00
|
|
|
{
|
2020-01-05 07:05:45 +01:00
|
|
|
if (CONFIG(USE_OPTION_TABLE))
|
2021-04-23 14:34:49 +02:00
|
|
|
return cmos_set_uint_option(name, &value);
|
2020-01-05 07:05:45 +01:00
|
|
|
|
2014-01-28 09:02:53 +01:00
|
|
|
return CB_CMOS_OTABLE_DISABLED;
|
|
|
|
}
|
|
|
|
|
2021-04-26 17:10:28 +02:00
|
|
|
static inline int get_uint_option(const char *name, const unsigned int fallback)
|
option.h: Introduce {get,set}_int_option() functions
The {get,set}_option() functions are not type-safe: they take a pointer
to void, without an associated length/size. Moreover, cmos_get_option()
does not always fully initialise the destination value (it has no means
to know how large it is), which can cause issues if the caller does not
initialise the value beforehand.
The idea behind this patch series is to replace the current type-unsafe
API with a type-safe equivalent, and ultimately decouple the option API
from CMOS. This would allow using different storage mechanisms with the
same option system, maximising flexibility.
Most, if not all users of get_option() have a value to fall back to, in
case the option could not be read. Thus, get_int_option() takes a value
to fall back to, which avoids repeating the same logic on call-sites.
These new functions will be put to use in subsequent commits.
Change-Id: I6bbc51135216f34518cfd05c3dc90fb68404c1cc
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/47107
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Rudolph <siro@das-labor.org>
2020-11-02 20:35:05 +01:00
|
|
|
{
|
2021-04-21 12:09:42 +02:00
|
|
|
if (CONFIG(USE_OPTION_TABLE)) {
|
2021-04-26 17:10:28 +02:00
|
|
|
unsigned int value = 0;
|
2021-04-23 14:34:49 +02:00
|
|
|
if (cmos_get_uint_option(&value, name) == CB_SUCCESS)
|
2021-04-21 12:09:42 +02:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
return fallback;
|
option.h: Introduce {get,set}_int_option() functions
The {get,set}_option() functions are not type-safe: they take a pointer
to void, without an associated length/size. Moreover, cmos_get_option()
does not always fully initialise the destination value (it has no means
to know how large it is), which can cause issues if the caller does not
initialise the value beforehand.
The idea behind this patch series is to replace the current type-unsafe
API with a type-safe equivalent, and ultimately decouple the option API
from CMOS. This would allow using different storage mechanisms with the
same option system, maximising flexibility.
Most, if not all users of get_option() have a value to fall back to, in
case the option could not be read. Thus, get_int_option() takes a value
to fall back to, which avoids repeating the same logic on call-sites.
These new functions will be put to use in subsequent commits.
Change-Id: I6bbc51135216f34518cfd05c3dc90fb68404c1cc
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/47107
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Rudolph <siro@das-labor.org>
2020-11-02 20:35:05 +01:00
|
|
|
}
|
|
|
|
|
2014-01-28 09:02:53 +01:00
|
|
|
#endif /* _OPTION_H_ */
|