[console] Allow console input and output to be disabled independently

Signed-off-by: Michael Brown <mcb30@ipxe.org>
pull/17/head
Michael Brown 2013-11-28 05:41:45 +00:00
parent 7271b50890
commit b2251743d8
8 changed files with 64 additions and 65 deletions

View File

@ -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,
};

View File

@ -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,
};

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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,
};

View File

@ -1,6 +1,7 @@
#ifndef _IPXE_CONSOLE_H
#define _IPXE_CONSOLE_H
#include <stddef.h>
#include <stdio.h>
#include <ipxe/tables.h>
@ -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" )

View File

@ -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 */

View File

@ -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 ) {