drivers/pc80/rtc: Factor out CMOS entry lookup
The procedure is identical for reads and writes. Factor it out. Change-Id: I22b1d334270881734b34312f1fee01aa110a6db4 Signed-off-by: Angel Pons <th3fanbus@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/52636 Reviewed-by: Patrick Rudolph <siro@das-labor.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
08f08c9fa4
commit
109a9ec339
|
@ -68,30 +68,33 @@ static struct cmos_option_table *get_cmos_layout(void)
|
||||||
return ct;
|
return ct;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct cmos_entries *find_cmos_entry(struct cmos_option_table *ct, const char *name)
|
||||||
|
{
|
||||||
|
/* Figure out how long name is */
|
||||||
|
const size_t namelen = strnlen(name, CMOS_MAX_NAME_LENGTH);
|
||||||
|
struct cmos_entries *ce;
|
||||||
|
|
||||||
|
/* Find the requested entry record */
|
||||||
|
ce = (struct cmos_entries *)((unsigned char *)ct + ct->header_length);
|
||||||
|
for (; ce->tag == LB_TAG_OPTION;
|
||||||
|
ce = (struct cmos_entries *)((unsigned char *)ce + ce->size)) {
|
||||||
|
if (memcmp(ce->name, name, namelen) == 0)
|
||||||
|
return ce;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
enum cb_err cmos_get_option(void *dest, const char *name)
|
enum cb_err cmos_get_option(void *dest, const char *name)
|
||||||
{
|
{
|
||||||
struct cmos_option_table *ct;
|
struct cmos_option_table *ct;
|
||||||
struct cmos_entries *ce;
|
struct cmos_entries *ce;
|
||||||
size_t namelen;
|
|
||||||
int found = 0;
|
|
||||||
|
|
||||||
/* Figure out how long name is */
|
|
||||||
namelen = strnlen(name, CMOS_MAX_NAME_LENGTH);
|
|
||||||
|
|
||||||
ct = get_cmos_layout();
|
ct = get_cmos_layout();
|
||||||
if (!ct)
|
if (!ct)
|
||||||
return CB_CMOS_LAYOUT_NOT_FOUND;
|
return CB_CMOS_LAYOUT_NOT_FOUND;
|
||||||
|
|
||||||
/* find the requested entry record */
|
ce = find_cmos_entry(ct, name);
|
||||||
ce = (struct cmos_entries *)((unsigned char *)ct + ct->header_length);
|
if (!ce) {
|
||||||
for (; ce->tag == LB_TAG_OPTION;
|
|
||||||
ce = (struct cmos_entries *)((unsigned char *)ce + ce->size)) {
|
|
||||||
if (memcmp(ce->name, name, namelen) == 0) {
|
|
||||||
found = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
printk(BIOS_DEBUG, "No CMOS option '%s'.\n", name);
|
printk(BIOS_DEBUG, "No CMOS option '%s'.\n", name);
|
||||||
return CB_CMOS_OPTION_NOT_FOUND;
|
return CB_CMOS_OPTION_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
@ -151,26 +154,13 @@ enum cb_err cmos_set_option(const char *name, void *value)
|
||||||
struct cmos_option_table *ct;
|
struct cmos_option_table *ct;
|
||||||
struct cmos_entries *ce;
|
struct cmos_entries *ce;
|
||||||
unsigned long length;
|
unsigned long length;
|
||||||
size_t namelen;
|
|
||||||
int found = 0;
|
|
||||||
|
|
||||||
/* Figure out how long name is */
|
|
||||||
namelen = strnlen(name, CMOS_MAX_NAME_LENGTH);
|
|
||||||
|
|
||||||
ct = get_cmos_layout();
|
ct = get_cmos_layout();
|
||||||
if (!ct)
|
if (!ct)
|
||||||
return CB_CMOS_LAYOUT_NOT_FOUND;
|
return CB_CMOS_LAYOUT_NOT_FOUND;
|
||||||
|
|
||||||
/* find the requested entry record */
|
ce = find_cmos_entry(ct, name);
|
||||||
ce = (struct cmos_entries *)((unsigned char *)ct + ct->header_length);
|
if (!ce) {
|
||||||
for (; ce->tag == LB_TAG_OPTION;
|
|
||||||
ce = (struct cmos_entries *)((unsigned char *)ce + ce->size)) {
|
|
||||||
if (memcmp(ce->name, name, namelen) == 0) {
|
|
||||||
found = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
printk(BIOS_DEBUG, "WARNING: No CMOS option '%s'.\n", name);
|
printk(BIOS_DEBUG, "WARNING: No CMOS option '%s'.\n", name);
|
||||||
return CB_CMOS_OPTION_NOT_FOUND;
|
return CB_CMOS_OPTION_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue