diff options
author | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2014-02-26 15:19:04 +0200 |
---|---|---|
committer | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2014-04-18 16:41:09 +0200 |
commit | f3390862653f9473359eb9a587842bb04671e6df (patch) | |
tree | 2a6f8171cdac86609b1552e3417816bd6877e4ff | |
parent | e8792be223f5f0c5c6bafffa4056793f3c3bfab7 (diff) | |
download | coreboot-f3390862653f9473359eb9a587842bb04671e6df.tar.xz |
console: Simplify the enable rules
Consoles on CBMEM and USB have somewhat complex rules and dependencies
when they can be active. Use simple variables to test which stage
of boot is being built for each console.
Change-Id: I2489e7731d07ca7d5dd2ea8b6501c73f05d6edd8
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: http://review.coreboot.org/5341
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@gmail.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
-rw-r--r-- | src/console/console.c | 62 | ||||
-rw-r--r-- | src/include/console/cbmem_console.h | 23 | ||||
-rw-r--r-- | src/include/console/console.h | 31 | ||||
-rw-r--r-- | src/include/console/ne2k.h | 15 | ||||
-rw-r--r-- | src/include/console/qemu_debugcon.h | 11 | ||||
-rw-r--r-- | src/include/console/spkmodem.h | 11 | ||||
-rw-r--r-- | src/include/console/uart.h | 18 | ||||
-rw-r--r-- | src/include/console/usb.h | 16 |
8 files changed, 120 insertions, 67 deletions
diff --git a/src/console/console.c b/src/console/console.c index e0e505c049..9b1c25542a 100644 --- a/src/console/console.c +++ b/src/console/console.c @@ -27,57 +27,29 @@ void console_hw_init(void) { -#if CONFIG_CONSOLE_SERIAL - uart_init(); -#endif -#if CONFIG_CONSOLE_NE2K - ne2k_init(CONFIG_CONSOLE_NE2K_IO_PORT); -#endif -#if CONFIG_CONSOLE_CBMEM && !defined(__BOOT_BLOCK__) && (CONFIG_EARLY_CBMEM_INIT || !defined(__PRE_RAM__)) - cbmemc_init(); -#endif -#if CONFIG_SPKMODEM - spkmodem_init(); -#endif -#if CONFIG_CONSOLE_USB && (CONFIG_USBDEBUG_IN_ROMSTAGE || !defined(__PRE_RAM__)) - usbdebug_init(); -#endif -#if CONFIG_CONSOLE_QEMU_DEBUGCON - qemu_debugcon_init(); -#endif + __cbmemc_init(); + __spkmodem_init(); + __qemu_debugcon_init(); + + __uart_init(); + __ne2k_init(); + __usbdebug_init(); } void console_tx_byte(unsigned char byte) { -#if CONFIG_CONSOLE_SERIAL - uart_tx_byte(byte); -#endif -#if CONFIG_CONSOLE_USB && (CONFIG_USBDEBUG_IN_ROMSTAGE || !defined(__PRE_RAM__)) - usb_tx_byte(0, byte); -#endif -#if CONFIG_CONSOLE_NE2K - ne2k_append_data_byte(byte, CONFIG_CONSOLE_NE2K_IO_PORT); -#endif -#if CONFIG_CONSOLE_CBMEM && !defined(__BOOT_BLOCK__) && (CONFIG_EARLY_CBMEM_INIT || !defined(__PRE_RAM__)) - cbmemc_tx_byte(byte); -#endif -#if CONFIG_SPKMODEM - spkmodem_tx_byte(byte); -#endif -#if CONFIG_CONSOLE_QEMU_DEBUGCON - qemu_debugcon_tx_byte(byte); -#endif + __cbmemc_tx_byte(byte); + __spkmodem_tx_byte(byte); + __qemu_debugcon_tx_byte(byte); + + __uart_tx_byte(byte); + __ne2k_tx_byte(byte); + __usb_tx_byte(byte); } void console_tx_flush(void) { -#if CONFIG_CONSOLE_SERIAL - uart_tx_flush(); -#endif -#if CONFIG_CONSOLE_NE2K - ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT); -#endif -#if CONFIG_CONSOLE_USB && (CONFIG_USBDEBUG_IN_ROMSTAGE || !defined(__PRE_RAM__)) - usb_tx_flush(0); -#endif + __uart_tx_flush(); + __ne2k_tx_flush(); + __usb_tx_flush(); } diff --git a/src/include/console/cbmem_console.h b/src/include/console/cbmem_console.h index 4f4a54f6b7..e7c6357ae4 100644 --- a/src/include/console/cbmem_console.h +++ b/src/include/console/cbmem_console.h @@ -19,14 +19,27 @@ #ifndef _CONSOLE_CBMEM_CONSOLE_H_ #define _CONSOLE_CBMEM_CONSOLE_H_ -#if CONFIG_EARLY_CBMEM_INIT || !defined(__PRE_RAM__) +#include <rules.h> +#include <stdint.h> + void cbmemc_init(void); -void cbmemc_reinit(void); void cbmemc_tx_byte(unsigned char data); + +#if CONFIG_CONSOLE_CBMEM +void cbmemc_reinit(void); +#else +static inline void cbmemc_reinit(void) {} +#endif + +#define __CBMEM_CONSOLE_ENABLE__ CONFIG_CONSOLE_CBMEM && \ + ((ENV_ROMSTAGE && CONFIG_EARLY_CBMEM_INIT) || ENV_RAMSTAGE) + +#if __CBMEM_CONSOLE_ENABLE__ +static inline void __cbmemc_init(void) { cbmemc_init(); } +static inline void __cbmemc_tx_byte(u8 data) { cbmemc_tx_byte(data); } #else -#define cbmemc_init() -#define cbmemc_reinit() -#define cbmemc_tx_byte(x) +static inline void __cbmemc_init(void) {} +static inline void __cbmemc_tx_byte(u8 data) {} #endif #endif diff --git a/src/include/console/console.h b/src/include/console/console.h index a15f608407..78426b24bf 100644 --- a/src/include/console/console.h +++ b/src/include/console/console.h @@ -21,10 +21,10 @@ #define CONSOLE_CONSOLE_H_ #include <stdint.h> +#include <rules.h> #include <console/post_codes.h> #ifndef __ROMCC__ -int console_log_level(int msg_level); void post_code(u8 value); #if CONFIG_CMOS_POST_EXTRA void post_log_extra(u32 value); @@ -40,32 +40,31 @@ void post_log_clear(void); void mainboard_post(u8 value); void __attribute__ ((noreturn)) die(const char *msg); -#if defined(__BOOT_BLOCK__) && !CONFIG_BOOTBLOCK_CONSOLE || \ - defined(__SMM__) && !CONFIG_DEBUG_SMI || \ - (defined(__PRE_RAM__) && !defined(__BOOT_BLOCK__)) && !CONFIG_EARLY_CONSOLE - -/* Do nothing. */ -static inline void printk(int LEVEL, const char *fmt, ...) {} -static inline void do_putchar(unsigned char byte) {} -static inline void console_init(void) {} - -#else +#define __CONSOLE_ENABLE__ \ + ((ENV_BOOTBLOCK && CONFIG_BOOTBLOCK_CONSOLE) || \ + (ENV_ROMSTAGE && CONFIG_EARLY_CONSOLE) || \ + ENV_RAMSTAGE || (ENV_SMM && CONFIG_DEBUG_SMI)) +#if __CONSOLE_ENABLE__ void console_init(void); +int console_log_level(int msg_level); int do_printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, 2, 3))); void do_putchar(unsigned char byte); -#define printk(LEVEL, fmt, args...) \ - do { \ - do_printk(LEVEL, fmt, ##args); \ - } while(0) +#define printk(LEVEL, fmt, args...) \ + do { do_printk(LEVEL, fmt, ##args); } while(0) +#else +static inline void console_init(void) {} +static inline int console_log_level(int msg_level) { return 0; } +static inline void printk(int LEVEL, const char *fmt, ...) {} +static inline void do_putchar(unsigned char byte) {} #endif #if CONFIG_CHROMEOS /* FIXME: Collision of varargs with AMD headers without guard. */ #include <console/vtxprintf.h> -#if !defined(__PRE_RAM__) || CONFIG_EARLY_CONSOLE +#if __CONSOLE_ENABLE__ void do_vtxprintf(const char *fmt, va_list args); #else static inline void do_vtxprintf(const char *fmt, va_list args) {}; diff --git a/src/include/console/ne2k.h b/src/include/console/ne2k.h index cb3c1ec63b..16cecb5ccd 100644 --- a/src/include/console/ne2k.h +++ b/src/include/console/ne2k.h @@ -19,6 +19,10 @@ #ifndef _NE2K_H__ #define _NE2K_H__ + +#include <rules.h> +#include <stdint.h> + void ne2k_append_data(unsigned char *d, int len, unsigned int base); int ne2k_init(unsigned int eth_nic_base); void ne2k_transmit(unsigned int eth_nic_base); @@ -26,4 +30,15 @@ void ne2k_transmit(unsigned int eth_nic_base); #ifndef __ROMCC__ #define ne2k_append_data_byte(d, base) ne2k_append_data(&d, 1, base) #endif + +#if CONFIG_CONSOLE_NE2K && (ENV_ROMSTAGE || ENV_RAMSTAGE) +static inline void __ne2k_init(void) { ne2k_init(CONFIG_CONSOLE_NE2K_IO_PORT); } +static inline void __ne2k_tx_byte(u8 data) { ne2k_append_data_byte(data, CONFIG_CONSOLE_NE2K_IO_PORT); } +static inline void __ne2k_tx_flush(void) { ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT); } +#else +static inline void __ne2k_init(void) {} +static inline void __ne2k_tx_byte(u8 data) {} +static inline void __ne2k_tx_flush(void) {} +#endif + #endif /* _NE2K_H */ diff --git a/src/include/console/qemu_debugcon.h b/src/include/console/qemu_debugcon.h index 63b1455dce..257ae581e5 100644 --- a/src/include/console/qemu_debugcon.h +++ b/src/include/console/qemu_debugcon.h @@ -1,7 +1,18 @@ #ifndef _QEMU_DEBUGCON_H_ #define _QEMU_DEBUGCON_H_ +#include <rules.h> +#include <stdint.h> + void qemu_debugcon_init(void); void qemu_debugcon_tx_byte(unsigned char data); +#if CONFIG_CONSOLE_QEMU_DEBUGCON && (ENV_ROMSTAGE || ENV_RAMSTAGE) +static inline void __qemu_debugcon_init(void) { qemu_debugcon_init(); } +static inline void __qemu_debugcon_tx_byte(u8 data) { qemu_debugcon_tx_byte(data); } +#else +static inline void __qemu_debugcon_init(void) {} +static inline void __qemu_debugcon_tx_byte(u8 data) {} +#endif + #endif diff --git a/src/include/console/spkmodem.h b/src/include/console/spkmodem.h index 450dbe8280..dfd21d4eef 100644 --- a/src/include/console/spkmodem.h +++ b/src/include/console/spkmodem.h @@ -1,7 +1,18 @@ #ifndef SPKMODEM_H #define SPKMODEM_H 1 +#include <rules.h> +#include <stdint.h> + void spkmodem_init(void); void spkmodem_tx_byte(unsigned char c); +#if CONFIG_SPKMODEM && (ENV_ROMSTAGE || ENV_RAMSTAGE) +static inline void __spkmodem_init(void) { spkmodem_init(); } +static inline void __spkmodem_tx_byte(u8 data) { spkmodem_tx_byte(data); } +#else +static inline void __spkmodem_init(void) {} +static inline void __spkmodem_tx_byte(u8 data) {} +#endif + #endif diff --git a/src/include/console/uart.h b/src/include/console/uart.h index 4551408285..5866ca4d42 100644 --- a/src/include/console/uart.h +++ b/src/include/console/uart.h @@ -20,6 +20,7 @@ #ifndef CONSOLE_UART_H #define CONSOLE_UART_H +#include <rules.h> #include <stdint.h> /* Return the clock frequency UART uses as reference clock for @@ -51,8 +52,23 @@ static inline void *uart_platform_baseptr(int idx) { return (void *)uart_platform_base(idx); } -#endif void oxford_remap(unsigned int new_base); +#define __CONSOLE_SERIAL_ENABLE__ CONFIG_CONSOLE_SERIAL && \ + (ENV_BOOTBLOCK || ENV_ROMSTAGE || ENV_RAMSTAGE || \ + (ENV_SMM && CONFIG_DEBUG_SMI)) + +#if __CONSOLE_SERIAL_ENABLE__ +static inline void __uart_init(void) { uart_init(); } +static inline void __uart_tx_byte(u8 data) { uart_tx_byte(data); } +static inline void __uart_tx_flush(void) { uart_tx_flush(); } +#else +static inline void __uart_init(void) {} +static inline void __uart_tx_byte(u8 data) {} +static inline void __uart_tx_flush(void) {} +#endif + +#endif /* __ROMCC__ */ + #endif /* CONSOLE_UART_H */ diff --git a/src/include/console/usb.h b/src/include/console/usb.h index 95911353e6..57ea4eb3df 100644 --- a/src/include/console/usb.h +++ b/src/include/console/usb.h @@ -21,6 +21,9 @@ #ifndef _CONSOLE_USB_H_ #define _CONSOLE_USB_H_ +#include <rules.h> +#include <stdint.h> + int usbdebug_init(void); void usb_tx_byte(int idx, unsigned char data); @@ -28,4 +31,17 @@ void usb_tx_flush(int idx); unsigned char usb_rx_byte(int idx); int usb_can_rx_byte(int idx); +#define __CONSOLE_USB_ENABLE__ CONFIG_CONSOLE_USB && \ + ((ENV_ROMSTAGE && CONFIG_USBDEBUG_IN_ROMSTAGE) || ENV_RAMSTAGE) + +#if __CONSOLE_USB_ENABLE__ +static inline void __usbdebug_init(void) { usbdebug_init(); } +static inline void __usb_tx_byte(u8 data) { usb_tx_byte(0, data); } +static inline void __usb_tx_flush(void) { usb_tx_flush(0); } +#else +static inline void __usbdebug_init(void) {} +static inline void __usb_tx_byte(u8 data) {} +static inline void __usb_tx_flush(void) {} +#endif + #endif /* _CONSOLE_USB_H_ */ |