Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[console] Allow console input and output to be disabled independently
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Nov 28, 2013
1 parent 7271b50 commit b225174
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/arch/i386/core/video_subr.c
Expand Up @@ -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,
};

Expand Down
2 changes: 1 addition & 1 deletion src/arch/i386/interface/vmware/vmconsole.c
Expand Up @@ -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,
};

Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86/core/debugcon.c
Expand Up @@ -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;
}
}

Expand Down
36 changes: 12 additions & 24 deletions src/core/console.c
Expand Up @@ -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;
Expand All @@ -29,31 +26,28 @@ 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 );
}
}

/**
* 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;
}
Expand All @@ -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()
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/serial_console.c
Expand Up @@ -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,
};

Expand Down
77 changes: 44 additions & 33 deletions src/include/ipxe/console.h
@@ -1,6 +1,7 @@
#ifndef _IPXE_CONSOLE_H
#define _IPXE_CONSOLE_H

#include <stddef.h>
#include <stdio.h>
#include <ipxe/tables.h>

Expand All @@ -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
*
Expand All @@ -25,65 +40,61 @@ 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.
*/
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" )

Expand Down
4 changes: 2 additions & 2 deletions src/net/tcp/syslogs.c
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions src/net/udp/syslog.c
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit b225174

Please sign in to comment.