]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[console] Allow usage to be defined independently for each console
authorMichael Brown <mcb30@ipxe.org>
Mon, 26 Mar 2012 16:25:08 +0000 (17:25 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 26 Mar 2012 16:40:01 +0000 (17:40 +0100)
Add the concept of a "console usage", such as "standard output" or
"debug messages".  Allow usages to be associated with each console
independently.  For example, to send debugging output via the serial
port, while preventing it from appearing on the local console:

  #define CONSOLE_SERIAL CONSOLE_USAGE_ALL
  #define CONSOLE_PCBIOS ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_DEBUG )

If no usages are explicitly specified, then a default set of usages
will be applied.  For example:

  #define CONSOLE_SERIAL

will have the same affect as

  #define CONSOLE_SERIAL CONSOLE_USAGE_ALL

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/i386/core/video_subr.c
src/arch/i386/firmware/pcbios/bios_console.c
src/arch/i386/interface/vmware/vmconsole.c
src/core/console.c
src/core/debug.c
src/core/serial_console.c
src/include/compiler.h
src/include/ipxe/console.h
src/interface/efi/efi_console.c
src/interface/linux/linux_console.c
src/net/udp/syslog.c

index 6885ad9af26d54cbdeb4d1d46306c2c58ba0b041..7dd99e712adbe9b4099f1df1d80830212256884b 100644 (file)
 #include <ipxe/console.h>
 #include <ipxe/init.h>
 #include "vga.h"
+#include <config/console.h>
+
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_DIRECT_VGA ) && \
+       CONSOLE_EXPLICIT ( CONSOLE_DIRECT_VGA ) )
+#undef CONSOLE_DIRECT_VGA
+#define CONSOLE_DIRECT_VGA CONSOLE_USAGE_ALL
+#endif
 
 struct console_driver vga_console __console_driver;
 
@@ -97,6 +105,7 @@ static void vga_putc(int byte)
 struct console_driver vga_console __console_driver = {
        .putchar = vga_putc,
        .disabled = 1,
+       .usage = CONSOLE_DIRECT_VGA,
 };
 
 struct init_fn video_init_fn __init_fn ( INIT_EARLY ) = {
index e489971f1c9888789f53e333b056272ad92f752e..8a8795d77edcd9c2f6f2c07e81b7aef7695839fe 100644 (file)
@@ -23,6 +23,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <ipxe/console.h>
 #include <ipxe/ansiesc.h>
 #include <ipxe/keymap.h>
+#include <config/console.h>
 
 #define ATTR_BOLD              0x08
 
@@ -48,6 +49,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
 
 #define ATTR_DEFAULT           ATTR_FCOL_WHITE
 
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_PCBIOS ) && CONSOLE_EXPLICIT ( CONSOLE_PCBIOS ) )
+#undef CONSOLE_PCBIOS
+#define CONSOLE_PCBIOS CONSOLE_USAGE_ALL
+#endif
+
 /** Current character attribute */
 static unsigned int bios_attr = ATTR_DEFAULT;
 
@@ -319,4 +326,5 @@ struct console_driver bios_console __console_driver = {
        .putchar = bios_putchar,
        .getchar = bios_getchar,
        .iskey = bios_iskey,
+       .usage = CONSOLE_PCBIOS,
 };
index 930c088d7cb9ff4f0079aef405b1b67192b183d8..3096e5b531685fbb151327eb9d8d44dec26fbb36 100644 (file)
@@ -29,10 +29,17 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <ipxe/lineconsole.h>
 #include <ipxe/init.h>
 #include <ipxe/guestrpc.h>
+#include <config/console.h>
 
 /** VMware logfile console buffer size */
 #define VMCONSOLE_BUFSIZE 128
 
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_VMWARE ) && CONSOLE_EXPLICIT ( CONSOLE_VMWARE ) )
+#undef CONSOLE_VMWARE
+#define CONSOLE_VMWARE CONSOLE_USAGE_ALL
+#endif
+
 /** VMware logfile console GuestRPC channel */
 static int vmconsole_channel;
 
@@ -87,6 +94,7 @@ static void vmconsole_putchar ( int character ) {
 struct console_driver vmconsole __console_driver = {
        .putchar = vmconsole_putchar,
        .disabled = 1,
+       .usage = CONSOLE_VMWARE,
 };
 
 /**
index f27edf468b9c209b65b7f40b7cf99790fcb073c3..a26a3ef6398a9685c89a645e5024845ee8bb7f70 100644 (file)
@@ -7,6 +7,9 @@
 
 FILE_LICENCE ( GPL2_OR_LATER );
 
+/** Current console usage */
+int console_usage = CONSOLE_USAGE_STDOUT;
+
 /**
  * Write a single character to each console device.
  *
@@ -26,7 +29,9 @@ void putchar ( int character ) {
                putchar ( '\r' );
 
        for_each_table_entry ( console, CONSOLES ) {
-               if ( ( ! console->disabled ) && console->putchar )
+               if ( ( ! console->disabled ) &&
+                    ( console_usage & console->usage ) &&
+                    console->putchar )
                        console->putchar ( character );
        }
 }
index 8fca8d90d194c3289d5e80c2fa3788804f125c90..fc90c64a173495e45a5bb4fdfaecd11c8aa0dd23 100644 (file)
@@ -21,16 +21,38 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <stdio.h>
 #include <stdint.h>
 #include <stdarg.h>
-#include <ipxe/io.h>
+#include <ipxe/console.h>
+
+/**
+ * Print debug message
+ *
+ * @v fmt              Format string
+ * @v ...              Arguments
+ */
+void dbg_printf ( const char *fmt, ... ) {
+       int saved_usage;
+       va_list args;
+
+       /* Mark console as in use for debugging messages */
+       saved_usage = console_set_usage ( CONSOLE_USAGE_DEBUG );
+
+       /* Print message */
+       va_start ( args, fmt );
+       vprintf ( fmt, args );
+       va_end ( args );
+
+       /* Restore console usage */
+       console_set_usage ( saved_usage );
+}
 
 /**
  * Pause until a key is pressed
  *
  */
 void dbg_pause ( void ) {
-       printf ( "\nPress a key..." );
+       dbg_printf ( "\nPress a key..." );
        getchar();
-       printf ( "\r              \r" );
+       dbg_printf ( "\r              \r" );
 }
 
 /**
@@ -38,9 +60,9 @@ void dbg_pause ( void ) {
  *
  */
 void dbg_more ( void ) {
-       printf ( "---more---" );
+       dbg_printf ( "---more---" );
        getchar();
-       printf ( "\r          \r" );
+       dbg_printf ( "\r          \r" );
 }
 
 /**
@@ -57,27 +79,27 @@ static void dbg_hex_dump_da_row ( unsigned long dispaddr, const void *data,
        unsigned int i;
        uint8_t byte;
 
-       printf ( "%08lx :", ( dispaddr + offset ) );
+       dbg_printf ( "%08lx :", ( dispaddr + offset ) );
        for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
                if ( i >= len ) {
-                       printf ( "   " );
+                       dbg_printf ( "   " );
                        continue;
                }
-               printf ( "%c%02x",
-                        ( ( ( i % 16 ) == 8 ) ? '-' : ' ' ), bytes[i] );
+               dbg_printf ( "%c%02x",
+                            ( ( ( i % 16 ) == 8 ) ? '-' : ' ' ), bytes[i] );
        }
-       printf ( " : " );
+       dbg_printf ( " : " );
        for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
                if ( i >= len ) {
-                       printf ( " " );
+                       dbg_printf ( " " );
                        continue;
                }
                byte = bytes[i];
                if ( ( byte < 0x20 ) || ( byte >= 0x7f ) )
                        byte = '.';
-               printf ( "%c", byte );
+               dbg_printf ( "%c", byte );
        }
-       printf ( "\n" );
+       dbg_printf ( "\n" );
 }
 
 /**
@@ -157,8 +179,8 @@ static int dbg_autocolour ( unsigned long stream ) {
  * @v stream           Message stream ID
  */
 void dbg_autocolourise ( unsigned long stream ) {
-       printf ( "\033[%dm",
-                ( stream ? ( 31 + dbg_autocolour ( stream ) ) : 0 ) );
+       dbg_printf ( "\033[%dm",
+                    ( stream ? ( 31 + dbg_autocolour ( stream ) ) : 0 ) );
 }
 
 /**
@@ -166,5 +188,5 @@ void dbg_autocolourise ( unsigned long stream ) {
  *
  */
 void dbg_decolourise ( void ) {
-       printf ( "\033[0m" );
+       dbg_printf ( "\033[0m" );
 }
index b05a06b1740b2a3e162ef0c88f17f82e9bfbac4a..52bd53760b2dff0b0572a009d0bc3b1113035bc2 100644 (file)
@@ -1,6 +1,7 @@
 #include <ipxe/init.h>
 #include <ipxe/serial.h>
 #include <ipxe/console.h>
+#include <config/console.h>
 
 /** @file
  *
@@ -8,6 +9,12 @@
  *
  */
 
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_SERIAL ) && CONSOLE_EXPLICIT ( CONSOLE_SERIAL ) )
+#undef CONSOLE_SERIAL
+#define CONSOLE_SERIAL CONSOLE_USAGE_ALL
+#endif
+
 struct console_driver serial_console __console_driver;
 
 static void serial_console_init ( void ) {
@@ -21,6 +28,7 @@ struct console_driver serial_console __console_driver = {
        .getchar = serial_getc,
        .iskey = serial_ischar,
        .disabled = 1,
+       .usage = CONSOLE_SERIAL,
 };
 
 /**
index 9a751d3bb8f8327fe0a09bc82f392b52ffadb6dc..ed9af237d01adac8f351a545d34cee4df9a7c912 100644 (file)
@@ -260,19 +260,9 @@ REQUEST_EXPANDED ( CONFIG_SYMBOL );
 
 #ifndef ASSEMBLY
 
-/** printf() for debugging
- *
- * This function exists so that the DBG() macros can expand to
- * printf() calls without dragging the printf() prototype into scope.
- *
- * As far as the compiler is concerned, dbg_printf() and printf() are
- * completely unrelated calls; it's only at the assembly stage that
- * references to the dbg_printf symbol are collapsed into references
- * to the printf symbol.
- */
-extern int __attribute__ (( format ( printf, 1, 2 ) )) 
-dbg_printf ( const char *fmt, ... ) asm ( "printf" );
-
+/** printf() for debugging */
+extern void __attribute__ (( format ( printf, 1, 2 ) ))
+dbg_printf ( const char *fmt, ... );
 extern void dbg_autocolourise ( unsigned long id );
 extern void dbg_decolourise ( void );
 extern void dbg_hex_dump_da ( unsigned long dispaddr,
index 5188f98558501a2ef8bb5a13f14c6bbbd90e9745..f70dd714a8b3a6aa4f7a02f1e9d86cf75e8900ed 100644 (file)
@@ -75,6 +75,13 @@ struct console_driver {
         *
         */
        int ( *iskey ) ( void );
+
+       /** Console usage bitmask
+        *
+        * This is the bitwise OR of zero or more @c CONSOLE_USAGE_XXX
+        * values.
+        */
+       int usage;
 };
 
 /** Console driver table */
@@ -99,7 +106,49 @@ struct console_driver {
  */
 #define __console_driver __table_entry ( CONSOLES, 01 )
 
-/* Function prototypes */
+/**
+ * @defgroup consoleusage Console usages
+ * @{
+ */
+
+/** Standard output */
+#define CONSOLE_USAGE_STDOUT 0x0001
+
+/** Debug messages */
+#define CONSOLE_USAGE_DEBUG 0x0002
+
+/** All console usages */
+#define CONSOLE_USAGE_ALL ( CONSOLE_USAGE_STDOUT | CONSOLE_USAGE_DEBUG )
+
+/** @} */
+
+/**
+ * Test to see if console has an explicit usage
+ *
+ * @v console          Console definition (e.g. CONSOLE_PCBIOS)
+ * @ret explicit       Console has an explicit usage
+ *
+ * This relies upon the trick that the expression ( 2 * N + 1 ) will
+ * be valid even if N is defined to be empty, since it will then
+ * evaluate to give ( 2 * + 1 ) == ( 2 * +1 ) == 2.
+ */
+#define CONSOLE_EXPLICIT( console ) ( ( 2 * console + 1 ) != 2 )
+
+extern int console_usage;
+
+/**
+ * Set console usage
+ *
+ * @v usage            New console usage
+ * @ret old_usage      Previous console usage
+ */
+static inline __attribute__ (( always_inline )) int
+console_set_usage ( int usage ) {
+       int old_usage = console_usage;
+
+       console_usage = usage;
+       return old_usage;
+}
 
 extern int iskey ( void );
 extern int getkey ( unsigned long timeout );
index 1303a4278821f90eb77e921d7ecbffb2ce1ef3f2..54b0c080421690947e2d86de1081d8678167a3c1 100644 (file)
@@ -23,6 +23,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <ipxe/efi/efi.h>
 #include <ipxe/ansiesc.h>
 #include <ipxe/console.h>
+#include <config/console.h>
 
 #define ATTR_BOLD              0x08
 
@@ -48,6 +49,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
 
 #define ATTR_DEFAULT           ATTR_FCOL_WHITE
 
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_EFI ) && CONSOLE_EXPLICIT ( CONSOLE_EFI ) )
+#undef CONSOLE_EFI
+#define CONSOLE_EFI CONSOLE_USAGE_ALL
+#endif
+
 /** Current character attribute */
 static unsigned int efi_attr = ATTR_DEFAULT;
 
@@ -273,4 +280,5 @@ struct console_driver efi_console __console_driver = {
        .putchar = efi_putchar,
        .getchar = efi_getchar,
        .iskey = efi_iskey,
+       .usage = CONSOLE_EFI,
 };
index aeb7c6618324bec49cbdd1ac6a4a83c9ac6b5f11..c79e52631d2707edc88590498289297d9780ea56 100644 (file)
@@ -33,6 +33,14 @@ FILE_LICENCE(GPL2_OR_LATER);
 #include <linux/termios.h>
 #include <asm/errno.h>
 
+#include <config/console.h>
+
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_LINUX ) && CONSOLE_EXPLICIT ( CONSOLE_LINUX ) )
+#undef CONSOLE_LINUX
+#define CONSOLE_LINUX CONSOLE_USAGE_ALL
+#endif
+
 static void linux_console_putchar(int c)
 {
        /* write to stdout */
@@ -79,6 +87,7 @@ struct console_driver linux_console __console_driver = {
        .putchar = linux_console_putchar,
        .getchar = linux_console_getchar,
        .iskey = linux_console_iskey,
+       .usage = CONSOLE_LINUX,
 };
 
 static int linux_tcgetattr(int fd, struct termios *termios_p)
index 5a8a865a5bf163ed11f26d65f49891da14edf448..8788e1c45e3f571df23ea43a529b31002ab2bcbf 100644 (file)
@@ -34,6 +34,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <ipxe/console.h>
 #include <ipxe/lineconsole.h>
 #include <ipxe/syslog.h>
+#include <config/console.h>
+
+/* Set default console usage if applicable */
+#if ! ( defined ( CONSOLE_SYSLOG ) && CONSOLE_EXPLICIT ( CONSOLE_SYSLOG ) )
+#undef CONSOLE_SYSLOG
+#define CONSOLE_SYSLOG CONSOLE_USAGE_ALL
+#endif
 
 /** The syslog server */
 static struct sockaddr_tcpip logserver = {
@@ -106,6 +113,7 @@ static void syslog_putchar ( int character ) {
 struct console_driver syslog_console __console_driver = {
        .putchar = syslog_putchar,
        .disabled = 1,
+       .usage = CONSOLE_SYSLOG,
 };
 
 /******************************************************************************