[coreboot-gerrit] Patch set updated for coreboot: ee4b331 drivers/pc80/mc146818rtc: Reduce superfluous preprocessor use

Alexandru Gagniuc (mr.nuke.me@gmail.com) gerrit at coreboot.org
Fri Jan 30 07:24:25 CET 2015


Alexandru Gagniuc (mr.nuke.me at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/8306

-gerrit

commit ee4b331d9a4a561a526c0fd042afec3d07232a82
Author: Alexandru Gagniuc <mr.nuke.me at 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 at gmail.com>
---
 src/drivers/pc80/mc146818rtc.c | 87 ++++++++++++++++++++----------------------
 src/include/pc80/mc146818rtc.h |  2 +-
 2 files changed, 42 insertions(+), 47 deletions(-)

diff --git a/src/drivers/pc80/mc146818rtc.c b/src/drivers/pc80/mc146818rtc.c
index fc3adf0..dcaaa3c 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
+#if !defined(__SMM__) || IS_ENABLED(CONFIG_USE_OPTION_TABLE)
 static int cmos_checksum_valid(int range_start, int range_end, int cks_loc)
 {
 	int i;
@@ -71,21 +69,19 @@ 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__
+#if !defined(__PRE_RAM__) && !defined(__SMM__)
 	/*
 	 * Avoid clearing pending interrupts and resetting the RTC control
 	 * register in the resume path because the Linux kernel relies on
@@ -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);



More information about the coreboot-gerrit mailing list