Alexandru Gagniuc (mr.nuke.me@gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/8306
-gerrit
commit f05d9614aea9f9088f0482a5dba7d687bc477d0a Author: Alexandru Gagniuc mr.nuke.me@gmail.com Date: Fri Jan 30 00:07:12 2015 -0600
drivers/pc80/mc146818rtc: Reduce superfluous preprocessor use
cmos_init() had layers of preprocessor directives, which resulted in a complete mess. Refactor it to make use of the IS_ENABLED() macro. This improves readability significantly.
Change-Id: I07f00084d809adbb55031b2079f71136ade3028e Signed-off-by: Alexandru Gagniuc mr.nuke.me@gmail.com --- src/drivers/pc80/mc146818rtc.c | 85 ++++++++++++++++++++---------------------- src/include/pc80/mc146818rtc.h | 2 +- 2 files changed, 41 insertions(+), 46 deletions(-)
diff --git a/src/drivers/pc80/mc146818rtc.c b/src/drivers/pc80/mc146818rtc.c index fc3adf0..67298d1 100644 --- a/src/drivers/pc80/mc146818rtc.c +++ b/src/drivers/pc80/mc146818rtc.c @@ -26,10 +26,8 @@ #include <boot/coreboot_tables.h> #include <rtc.h> #include <string.h> -#if CONFIG_USE_OPTION_TABLE #include "option_table.h" #include <cbfs.h> -#endif
static void cmos_reset_date(void) @@ -48,7 +46,7 @@ static void cmos_reset_date(void) rtc_set(&time); }
-#if CONFIG_USE_OPTION_TABLE +#ifndef __SMM__ static int cmos_checksum_valid(int range_start, int range_end, int cks_loc) { int i; @@ -71,19 +69,17 @@ static void cmos_set_checksum(int range_start, int range_end, int cks_loc) cmos_write(((sum >> 8) & 0x0ff), cks_loc); cmos_write(((sum >> 0) & 0x0ff), cks_loc + 1); } -#endif
#define RTC_CONTROL_DEFAULT (RTC_24H) #define RTC_FREQ_SELECT_DEFAULT (RTC_REF_CLCK_32KHZ | RTC_RATE_1024HZ)
-#ifndef __SMM__ -void cmos_init(int invalid) +void cmos_init(bool invalid) { - int cmos_invalid = 0; - int checksum_invalid = 0; -#if CONFIG_USE_OPTION_TABLE - unsigned char x; -#endif + bool cmos_invalid = false; + bool checksum_invalid = false; + bool clear_cmos; + size_t i; + uint8_t x;
#ifndef __PRE_RAM__ /* @@ -98,38 +94,37 @@ void cmos_init(int invalid)
printk(BIOS_DEBUG, "RTC Init\n");
-#if CONFIG_USE_OPTION_TABLE - /* See if there has been a CMOS power problem. */ - x = cmos_read(RTC_VALID); - cmos_invalid = !(x & RTC_VRT); + if (IS_ENABLED(CONFIG_USE_OPTION_TABLE)) { + /* See if there has been a CMOS power problem. */ + x = cmos_read(RTC_VALID); + cmos_invalid = !(x & RTC_VRT);
- /* See if there is a CMOS checksum error */ - checksum_invalid = !cmos_checksum_valid(PC_CKS_RANGE_START, - PC_CKS_RANGE_END,PC_CKS_LOC); + /* See if there is a CMOS checksum error */ + checksum_invalid = !cmos_checksum_valid(PC_CKS_RANGE_START, + PC_CKS_RANGE_END, PC_CKS_LOC);
-#define CLEAR_CMOS 0 -#else -#define CLEAR_CMOS 1 -#endif + clear_cmos = false; + } else { + clear_cmos = true; + }
if (invalid || cmos_invalid || checksum_invalid) { -#if CLEAR_CMOS - int i; - - cmos_write(0, 0x01); - cmos_write(0, 0x03); - cmos_write(0, 0x05); - for (i = 10; i < 128; i++) - cmos_write(0, i); -#endif + if(clear_cmos) { + cmos_write(0, 0x01); + cmos_write(0, 0x03); + cmos_write(0, 0x05); + for (i = 10; i < 128; i++) + cmos_write(0, i); + } + if (cmos_invalid) cmos_reset_date();
printk(BIOS_WARNING, "RTC:%s%s%s%s\n", - invalid?" Clear requested":"", - cmos_invalid?" Power Problem":"", - checksum_invalid?" Checksum invalid":"", - CLEAR_CMOS?" zeroing cmos":""); + invalid ? " Clear requested":"", + cmos_invalid ? " Power Problem":"", + checksum_invalid ? " Checksum invalid":"", + clear_cmos ? " zeroing cmos":""); }
/* Setup the real time clock */ @@ -139,16 +134,16 @@ void cmos_init(int invalid) /* Ensure all reserved bits are 0 in register D */ cmos_write(RTC_VRT, RTC_VALID);
-#if CONFIG_USE_OPTION_TABLE - /* See if there is a LB CMOS checksum error */ - checksum_invalid = !cmos_checksum_valid(LB_CKS_RANGE_START, - LB_CKS_RANGE_END,LB_CKS_LOC); - if (checksum_invalid) - printk(BIOS_DEBUG, "RTC: coreboot checksum invalid\n"); - - /* Make certain we have a valid checksum */ - cmos_set_checksum(PC_CKS_RANGE_START, PC_CKS_RANGE_END, PC_CKS_LOC); -#endif + if(IS_ENABLED(CONFIG_USE_OPTION_TABLE)) { + /* See if there is a LB CMOS checksum error */ + checksum_invalid = !cmos_checksum_valid(LB_CKS_RANGE_START, + LB_CKS_RANGE_END,LB_CKS_LOC); + if (checksum_invalid) + printk(BIOS_DEBUG, "RTC: coreboot checksum invalid\n"); + + /* Make certain we have a valid checksum */ + cmos_set_checksum(PC_CKS_RANGE_START, PC_CKS_RANGE_END, PC_CKS_LOC); + }
/* Clear any pending interrupts */ cmos_read(RTC_INTR_FLAGS); diff --git a/src/include/pc80/mc146818rtc.h b/src/include/pc80/mc146818rtc.h index 90ae7ae..ab9656d 100644 --- a/src/include/pc80/mc146818rtc.h +++ b/src/include/pc80/mc146818rtc.h @@ -169,7 +169,7 @@ static inline void cmos_write32(u8 offset, u32 value) #endif
#if !defined(__ROMCC__) -void cmos_init(int invalid); +void cmos_init(bool invalid); void cmos_check_update_date(void); #if CONFIG_USE_OPTION_TABLE enum cb_err set_option(const char *name, void *val);