From b2251743d80f94445f40f64b75b63d33fe1d8725 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 28 Nov 2013 05:41:45 +0000 Subject: [console] Allow console input and output to be disabled independently Signed-off-by: Michael Brown --- src/arch/i386/core/video_subr.c | 2 +- src/arch/i386/interface/vmware/vmconsole.c | 2 +- src/arch/x86/core/debugcon.c | 2 +- src/core/console.c | 36 +++++--------- src/core/serial_console.c | 2 +- src/include/ipxe/console.h | 77 +++++++++++++++++------------- src/net/tcp/syslogs.c | 4 +- src/net/udp/syslog.c | 4 +- 8 files changed, 64 insertions(+), 65 deletions(-) (limited to 'src') diff --git a/src/arch/i386/core/video_subr.c b/src/arch/i386/core/video_subr.c index 306c6d56..3f701bd9 100644 --- a/src/arch/i386/core/video_subr.c +++ b/src/arch/i386/core/video_subr.c @@ -104,7 +104,7 @@ static void vga_putc(int byte) struct console_driver vga_console __console_driver = { .putchar = vga_putc, - .disabled = 1, + .disabled = CONSOLE_DISABLED, .usage = CONSOLE_DIRECT_VGA, }; diff --git a/src/arch/i386/interface/vmware/vmconsole.c b/src/arch/i386/interface/vmware/vmconsole.c index 48510520..c6b9fff1 100644 --- a/src/arch/i386/interface/vmware/vmconsole.c +++ b/src/arch/i386/interface/vmware/vmconsole.c @@ -102,7 +102,7 @@ static void vmconsole_putchar ( int character ) { /** VMware logfile console driver */ struct console_driver vmconsole __console_driver = { .putchar = vmconsole_putchar, - .disabled = 1, + .disabled = CONSOLE_DISABLED, .usage = CONSOLE_VMWARE, }; diff --git a/src/arch/x86/core/debugcon.c b/src/arch/x86/core/debugcon.c index b89480aa..263cb4af 100644 --- a/src/arch/x86/core/debugcon.c +++ b/src/arch/x86/core/debugcon.c @@ -74,7 +74,7 @@ static void debugcon_init ( void ) { check = inb ( DEBUG_PORT ); if ( check != DEBUG_PORT_CHECK ) { DBG ( "Debug port not present; disabling console\n" ); - debugcon_console.disabled = 1; + debugcon_console.disabled = CONSOLE_DISABLED; } } diff --git a/src/core/console.c b/src/core/console.c index a26a3ef6..73baf7f6 100644 --- a/src/core/console.c +++ b/src/core/console.c @@ -11,15 +11,12 @@ FILE_LICENCE ( GPL2_OR_LATER ); int console_usage = CONSOLE_USAGE_STDOUT; /** - * Write a single character to each console device. + * Write a single character to each console device * * @v character Character to be written - * @ret None - - * @err None - * * The character is written out to all enabled console devices, using * each device's console_driver::putchar() method. - * */ void putchar ( int character ) { struct console_driver *console; @@ -29,7 +26,7 @@ void putchar ( int character ) { putchar ( '\r' ); for_each_table_entry ( console, CONSOLES ) { - if ( ( ! console->disabled ) && + if ( ( ! ( console->disabled & CONSOLE_DISABLED_OUTPUT ) ) && ( console_usage & console->usage ) && console->putchar ) console->putchar ( character ); @@ -37,23 +34,20 @@ void putchar ( int character ) { } /** - * Check to see if any input is available on any console. + * Check to see if any input is available on any console * - * @v None - - * @ret console Console device that has input available, if any. - * @ret NULL No console device has input available. - * @err None - + * @ret console Console device that has input available, or NULL * * All enabled console devices are checked once for available input * using each device's console_driver::iskey() method. The first * console device that has available input will be returned, if any. - * */ static struct console_driver * has_input ( void ) { struct console_driver *console; for_each_table_entry ( console, CONSOLES ) { - if ( ( ! console->disabled ) && console->iskey ) { + if ( ( ! ( console->disabled & CONSOLE_DISABLED_INPUT ) ) && + console->iskey ) { if ( console->iskey () ) return console; } @@ -62,11 +56,9 @@ static struct console_driver * has_input ( void ) { } /** - * Read a single character from any console. + * Read a single character from any console * - * @v None - * @ret character Character read from a console. - * @err None - * * A character will be read from the first enabled console device that * has input available using that console's console_driver::getchar() @@ -80,7 +72,6 @@ static struct console_driver * has_input ( void ) { * @endcode * * The character read will not be echoed back to any console. - * */ int getchar ( void ) { struct console_driver *console; @@ -116,19 +107,16 @@ int getchar ( void ) { return character; } -/** Check for available input on any console. +/** + * Check for available input on any console * - * @v None - - * @ret True Input is available on a console - * @ret False Input is not available on any console - * @err None - + * @ret is_available Input is available on a console * * All enabled console devices are checked once for available input * using each device's console_driver::iskey() method. If any console - * device has input available, this call will return True. If this - * call returns True, you can then safely call getchar() without + * device has input available, this call will return true. If this + * call returns true, you can then safely call getchar() without * blocking. - * */ int iskey ( void ) { return has_input() ? 1 : 0; diff --git a/src/core/serial_console.c b/src/core/serial_console.c index 3852a308..de9b84ca 100644 --- a/src/core/serial_console.c +++ b/src/core/serial_console.c @@ -30,7 +30,7 @@ struct console_driver serial_console __console_driver = { .putchar = serial_putc, .getchar = serial_getc, .iskey = serial_ischar, - .disabled = 1, + .disabled = CONSOLE_DISABLED, .usage = CONSOLE_SERIAL, }; diff --git a/src/include/ipxe/console.h b/src/include/ipxe/console.h index e2bf4be9..2fcc4150 100644 --- a/src/include/ipxe/console.h +++ b/src/include/ipxe/console.h @@ -1,6 +1,7 @@ #ifndef _IPXE_CONSOLE_H #define _IPXE_CONSOLE_H +#include #include #include @@ -17,6 +18,20 @@ FILE_LICENCE ( GPL2_OR_LATER ); +struct pixel_buffer; + +/** A console configuration */ +struct console_configuration { + /** Width */ + unsigned int width; + /** Height */ + unsigned int height; + /** Colour depth */ + unsigned int bpp; + /** Background picture, if any */ + struct pixel_buffer *pixbuf; +}; + /** * A console driver * @@ -25,58 +40,45 @@ FILE_LICENCE ( GPL2_OR_LATER ); * #__console_driver. * * @note Consoles that cannot be used before their initialisation - * function has completed should set #disabled=1 initially. This - * allows other console devices to still be used to print out early - * debugging messages. - * + * function has completed should set #disabled initially. This allows + * other console devices to still be used to print out early debugging + * messages. */ struct console_driver { - /** Console is disabled. - * - * The console's putchar(), getchar() and iskey() methods will - * not be called while #disabled==1. Typically the console's - * initialisation functions will set #disabled=0 upon - * completion. + /** + * Console disabled flags * + * This is the bitwise OR of zero or more console disabled + * flags. */ int disabled; - - /** Write a character to the console. + /** + * Write a character to the console * * @v character Character to be written - * @ret None - - * @err None - - * */ - void ( *putchar ) ( int character ); - - /** Read a character from the console. + void ( * putchar ) ( int character ); + /** + * Read a character from the console * - * @v None - * @ret character Character read - * @err None - * * If no character is available to be read, this method will * block. The character read should not be echoed back to the * console. - * */ - int ( *getchar ) ( void ); - - /** Check for available input. + int ( * getchar ) ( void ); + /** + * Check for available input * - * @v None - - * @ret True Input is available - * @ret False Input is not available - * @err None - + * @ret is_available Input is available * - * This should return True if a subsequent call to getchar() + * This should return true if a subsequent call to getchar() * will not block. - * */ - int ( *iskey ) ( void ); - - /** Console usage bitmask + int ( * iskey ) ( void ); + /** + * Console usage bitmask * * This is the bitwise OR of zero or more @c CONSOLE_USAGE_XXX * values. @@ -84,6 +86,15 @@ struct console_driver { int usage; }; +/** Console is disabled for input */ +#define CONSOLE_DISABLED_INPUT 0x0001 + +/** Console is disabled for output */ +#define CONSOLE_DISABLED_OUTPUT 0x0002 + +/** Console is disabled for all uses */ +#define CONSOLE_DISABLED ( CONSOLE_DISABLED_INPUT | CONSOLE_DISABLED_OUTPUT ) + /** Console driver table */ #define CONSOLES __table ( struct console_driver, "consoles" ) diff --git a/src/net/tcp/syslogs.c b/src/net/tcp/syslogs.c index a4dc2975..bcda8b45 100644 --- a/src/net/tcp/syslogs.c +++ b/src/net/tcp/syslogs.c @@ -178,7 +178,7 @@ static void syslogs_putchar ( int character ) { /** Encrypted syslog console driver */ struct console_driver syslogs_console __console_driver = { .putchar = syslogs_putchar, - .disabled = 1, + .disabled = CONSOLE_DISABLED, .usage = CONSOLE_SYSLOGS, }; @@ -227,7 +227,7 @@ static int apply_syslogs_settings ( void ) { old_server = NULL; /* Reset encrypted syslog connection */ - syslogs_console.disabled = 1; + syslogs_console.disabled = CONSOLE_DISABLED; intf_restart ( &syslogs, 0 ); /* Do nothing unless we have a log server */ diff --git a/src/net/udp/syslog.c b/src/net/udp/syslog.c index 4bfba51e..4210083d 100644 --- a/src/net/udp/syslog.c +++ b/src/net/udp/syslog.c @@ -176,7 +176,7 @@ static void syslog_putchar ( int character ) { /** Syslog console driver */ struct console_driver syslog_console __console_driver = { .putchar = syslog_putchar, - .disabled = 1, + .disabled = CONSOLE_DISABLED, .usage = CONSOLE_SYSLOG, }; @@ -222,7 +222,7 @@ static int apply_syslog_settings ( void ) { } /* Fetch log server */ - syslog_console.disabled = 1; + syslog_console.disabled = CONSOLE_DISABLED; old_addr.s_addr = sin_logserver->sin_addr.s_addr; if ( ( len = fetch_ipv4_setting ( NULL, &syslog_setting, &sin_logserver->sin_addr ) ) >= 0 ) { -- cgit v1.2.3-55-g7522