[coreboot-gerrit] New patch to review for coreboot: 8e7411f console: Hide global console_loglevel

Kyösti Mälkki (kyosti.malkki@gmail.com) gerrit at coreboot.org
Tue Mar 4 18:01:25 CET 2014


Kyösti Mälkki (kyosti.malkki at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/5333

-gerrit

commit 8e7411f1292336c0ebab7b0dbd3602a2c519eb45
Author: Kyösti Mälkki <kyosti.malkki at gmail.com>
Date:   Fri Feb 28 14:37:27 2014 +0200

    console: Hide global console_loglevel
    
    Change-Id: I7bdc468bc3f74516abb2c583bdb5b6d7555d987c
    Signed-off-by: Kyösti Mälkki <kyosti.malkki at gmail.com>
---
 src/arch/x86/lib/romcc_console.c | 21 +++++++--------------
 src/console/init.c               | 10 ++++++++++
 src/console/printk.c             |  6 +-----
 src/include/console/console.h    | 10 +---------
 4 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/src/arch/x86/lib/romcc_console.c b/src/arch/x86/lib/romcc_console.c
index a7f2dd6..43de28b 100644
--- a/src/arch/x86/lib/romcc_console.c
+++ b/src/arch/x86/lib/romcc_console.c
@@ -17,18 +17,11 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include <stdint.h>
-#include <console/loglevel.h>
-#include <console/post_codes.h>
 #include <console/uart.h>
 #include <console/ne2k.h>
 
-/* __PRE_RAM__ */
-/* Using a global varible can cause problems when we reset the stack
- * from cache as ram to ram. If we make this a define USE_SHARED_STACK
- * we could use the same code on all architectures.
- */
-#define console_loglevel CONFIG_DEFAULT_CONSOLE_LOGLEVEL
+/* While in romstage, console loglevel is built-time constant. */
+#define console_show(msg_level) (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= msg_level)
 
 #if CONFIG_CONSOLE_SERIAL && CONFIG_DRIVERS_UART_8250IO
 #include "drivers/uart/util.c"
@@ -70,7 +63,7 @@ static void __console_tx_nibble(unsigned nibble)
 
 static void __console_tx_char(int loglevel, unsigned char byte)
 {
-	if (console_loglevel >= loglevel) {
+	if (console_show(loglevel)) {
 		__console_tx_byte(byte);
 		__console_tx_flush();
 	}
@@ -78,7 +71,7 @@ static void __console_tx_char(int loglevel, unsigned char byte)
 
 static void __console_tx_hex8(int loglevel, unsigned char value)
 {
-	if (console_loglevel >= loglevel) {
+	if (console_show(loglevel)) {
 		__console_tx_nibble((value >>  4U) & 0x0fU);
 		__console_tx_nibble(value & 0x0fU);
 		__console_tx_flush();
@@ -87,7 +80,7 @@ static void __console_tx_hex8(int loglevel, unsigned char value)
 
 static void __console_tx_hex16(int loglevel, unsigned short value)
 {
-	if (console_loglevel >= loglevel) {
+	if (console_show(loglevel)) {
 		__console_tx_nibble((value >> 12U) & 0x0fU);
 		__console_tx_nibble((value >>  8U) & 0x0fU);
 		__console_tx_nibble((value >>  4U) & 0x0fU);
@@ -98,7 +91,7 @@ static void __console_tx_hex16(int loglevel, unsigned short value)
 
 static void __console_tx_hex32(int loglevel, unsigned int value)
 {
-	if (console_loglevel >= loglevel) {
+	if (console_show(loglevel)) {
 		__console_tx_nibble((value >> 28U) & 0x0fU);
 		__console_tx_nibble((value >> 24U) & 0x0fU);
 		__console_tx_nibble((value >> 20U) & 0x0fU);
@@ -113,7 +106,7 @@ static void __console_tx_hex32(int loglevel, unsigned int value)
 
 static void __console_tx_string(int loglevel, const char *str)
 {
-	if (console_loglevel >= loglevel) {
+	if (console_show(loglevel)) {
 		unsigned char ch;
 		while((ch = *str++) != '\0') {
 			if (ch == '\n')
diff --git a/src/console/init.c b/src/console/init.c
index bbbcfb3..85ae880 100644
--- a/src/console/init.c
+++ b/src/console/init.c
@@ -25,6 +25,16 @@
 #include <console/uart.h>
 #include <option.h>
 
+#if !defined(__ROMCC__)
+/* While in romstage, console loglevel is built-time constant. */
+static ROMSTAGE_CONST int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
+
+int console_show(int msg_level)
+{
+	return (console_loglevel >= msg_level);
+}
+#endif
+
 void console_init(void)
 {
 #if !defined(__PRE_RAM__)
diff --git a/src/console/printk.c b/src/console/printk.c
index 6c2e6e4..a3b91ad 100644
--- a/src/console/printk.c
+++ b/src/console/printk.c
@@ -11,9 +11,6 @@
 #include <console/console.h>
 #include <trace.h>
 
-int console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
-int default_console_loglevel = CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
-
 DECLARE_SPIN_LOCK(console_lock)
 
 int do_printk(int msg_level, const char *fmt, ...)
@@ -21,9 +18,8 @@ int do_printk(int msg_level, const char *fmt, ...)
 	va_list args;
 	int i;
 
-	if (msg_level > console_loglevel) {
+	if (!console_show(msg_level))
 		return 0;
-	}
 
 #if CONFIG_SQUELCH_EARLY_SMP && defined(__PRE_RAM__)
 	if (!boot_cpu())
diff --git a/src/include/console/console.h b/src/include/console/console.h
index 6d1b01a..f4b3c46 100644
--- a/src/include/console/console.h
+++ b/src/include/console/console.h
@@ -40,18 +40,10 @@ struct console_driver {
 /* Defined by the linker... */
 extern struct console_driver console_drivers[];
 extern struct console_driver econsole_drivers[];
-
-extern int console_loglevel;
-#else
-/* __PRE_RAM__ */
-/* Using a global variable can cause problems when we reset the stack
- * from cache as ram to ram. If we make this a define USE_SHARED_STACK
- * we could use the same code on all architectures.
- */
-#define console_loglevel CONFIG_DEFAULT_CONSOLE_LOGLEVEL
 #endif
 
 #ifndef __ROMCC__
+int console_show(int msg_level);
 void console_init(void);
 void console_hw_init(void);
 void console_tx_byte(unsigned char byte);



More information about the coreboot-gerrit mailing list