Browse Source

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

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
b2251743d8

+ 1
- 1
src/arch/i386/core/video_subr.c View File

104
 
104
 
105
 struct console_driver vga_console __console_driver = {
105
 struct console_driver vga_console __console_driver = {
106
 	.putchar = vga_putc,
106
 	.putchar = vga_putc,
107
-	.disabled = 1,
107
+	.disabled = CONSOLE_DISABLED,
108
 	.usage = CONSOLE_DIRECT_VGA,
108
 	.usage = CONSOLE_DIRECT_VGA,
109
 };
109
 };
110
 
110
 

+ 1
- 1
src/arch/i386/interface/vmware/vmconsole.c View File

102
 /** VMware logfile console driver */
102
 /** VMware logfile console driver */
103
 struct console_driver vmconsole __console_driver = {
103
 struct console_driver vmconsole __console_driver = {
104
 	.putchar = vmconsole_putchar,
104
 	.putchar = vmconsole_putchar,
105
-	.disabled = 1,
105
+	.disabled = CONSOLE_DISABLED,
106
 	.usage = CONSOLE_VMWARE,
106
 	.usage = CONSOLE_VMWARE,
107
 };
107
 };
108
 
108
 

+ 1
- 1
src/arch/x86/core/debugcon.c View File

74
 	check = inb ( DEBUG_PORT );
74
 	check = inb ( DEBUG_PORT );
75
 	if ( check != DEBUG_PORT_CHECK ) {
75
 	if ( check != DEBUG_PORT_CHECK ) {
76
 		DBG ( "Debug port not present; disabling console\n" );
76
 		DBG ( "Debug port not present; disabling console\n" );
77
-		debugcon_console.disabled = 1;
77
+		debugcon_console.disabled = CONSOLE_DISABLED;
78
 	}
78
 	}
79
 }
79
 }
80
 
80
 

+ 12
- 24
src/core/console.c View File

11
 int console_usage = CONSOLE_USAGE_STDOUT;
11
 int console_usage = CONSOLE_USAGE_STDOUT;
12
 
12
 
13
 /**
13
 /**
14
- * Write a single character to each console device.
14
+ * Write a single character to each console device
15
  *
15
  *
16
  * @v character		Character to be written
16
  * @v character		Character to be written
17
- * @ret None		-
18
- * @err None		-
19
  *
17
  *
20
  * The character is written out to all enabled console devices, using
18
  * The character is written out to all enabled console devices, using
21
  * each device's console_driver::putchar() method.
19
  * each device's console_driver::putchar() method.
22
- *
23
  */
20
  */
24
 void putchar ( int character ) {
21
 void putchar ( int character ) {
25
 	struct console_driver *console;
22
 	struct console_driver *console;
29
 		putchar ( '\r' );
26
 		putchar ( '\r' );
30
 
27
 
31
 	for_each_table_entry ( console, CONSOLES ) {
28
 	for_each_table_entry ( console, CONSOLES ) {
32
-		if ( ( ! console->disabled ) &&
29
+		if ( ( ! ( console->disabled & CONSOLE_DISABLED_OUTPUT ) ) &&
33
 		     ( console_usage & console->usage ) &&
30
 		     ( console_usage & console->usage ) &&
34
 		     console->putchar )
31
 		     console->putchar )
35
 			console->putchar ( character );
32
 			console->putchar ( character );
37
 }
34
 }
38
 
35
 
39
 /**
36
 /**
40
- * Check to see if any input is available on any console.
37
+ * Check to see if any input is available on any console
41
  *
38
  *
42
- * @v None		-
43
- * @ret console		Console device that has input available, if any.
44
- * @ret NULL		No console device has input available.
45
- * @err None		-
39
+ * @ret console		Console device that has input available, or NULL
46
  *
40
  *
47
  * All enabled console devices are checked once for available input
41
  * All enabled console devices are checked once for available input
48
  * using each device's console_driver::iskey() method.  The first
42
  * using each device's console_driver::iskey() method.  The first
49
  * console device that has available input will be returned, if any.
43
  * console device that has available input will be returned, if any.
50
- *
51
  */
44
  */
52
 static struct console_driver * has_input ( void ) {
45
 static struct console_driver * has_input ( void ) {
53
 	struct console_driver *console;
46
 	struct console_driver *console;
54
 
47
 
55
 	for_each_table_entry ( console, CONSOLES ) {
48
 	for_each_table_entry ( console, CONSOLES ) {
56
-		if ( ( ! console->disabled ) && console->iskey ) {
49
+		if ( ( ! ( console->disabled & CONSOLE_DISABLED_INPUT ) ) &&
50
+		     console->iskey ) {
57
 			if ( console->iskey () )
51
 			if ( console->iskey () )
58
 				return console;
52
 				return console;
59
 		}
53
 		}
62
 }
56
 }
63
 
57
 
64
 /**
58
 /**
65
- * Read a single character from any console.
59
+ * Read a single character from any console
66
  *
60
  *
67
- * @v None		-
68
  * @ret character	Character read from a console.
61
  * @ret character	Character read from a console.
69
- * @err None		-
70
  *
62
  *
71
  * A character will be read from the first enabled console device that
63
  * A character will be read from the first enabled console device that
72
  * has input available using that console's console_driver::getchar()
64
  * has input available using that console's console_driver::getchar()
80
  * @endcode
72
  * @endcode
81
  *
73
  *
82
  * The character read will not be echoed back to any console.
74
  * The character read will not be echoed back to any console.
83
- *
84
  */
75
  */
85
 int getchar ( void ) {
76
 int getchar ( void ) {
86
 	struct console_driver *console;
77
 	struct console_driver *console;
116
 	return character;
107
 	return character;
117
 }
108
 }
118
 
109
 
119
-/** Check for available input on any console.
110
+/**
111
+ * Check for available input on any console
120
  *
112
  *
121
- * @v None		-
122
- * @ret True		Input is available on a console
123
- * @ret False		Input is not available on any console
124
- * @err None		-
113
+ * @ret is_available	Input is available on a console
125
  *
114
  *
126
  * All enabled console devices are checked once for available input
115
  * All enabled console devices are checked once for available input
127
  * using each device's console_driver::iskey() method.  If any console
116
  * using each device's console_driver::iskey() method.  If any console
128
- * device has input available, this call will return True.  If this
129
- * call returns True, you can then safely call getchar() without
117
+ * device has input available, this call will return true.  If this
118
+ * call returns true, you can then safely call getchar() without
130
  * blocking.
119
  * blocking.
131
- *
132
  */
120
  */
133
 int iskey ( void ) {
121
 int iskey ( void ) {
134
 	return has_input() ? 1 : 0;
122
 	return has_input() ? 1 : 0;

+ 1
- 1
src/core/serial_console.c View File

30
 	.putchar = serial_putc,
30
 	.putchar = serial_putc,
31
 	.getchar = serial_getc,
31
 	.getchar = serial_getc,
32
 	.iskey = serial_ischar,
32
 	.iskey = serial_ischar,
33
-	.disabled = 1,
33
+	.disabled = CONSOLE_DISABLED,
34
 	.usage = CONSOLE_SERIAL,
34
 	.usage = CONSOLE_SERIAL,
35
 };
35
 };
36
 
36
 

+ 44
- 33
src/include/ipxe/console.h View File

1
 #ifndef _IPXE_CONSOLE_H
1
 #ifndef _IPXE_CONSOLE_H
2
 #define _IPXE_CONSOLE_H
2
 #define _IPXE_CONSOLE_H
3
 
3
 
4
+#include <stddef.h>
4
 #include <stdio.h>
5
 #include <stdio.h>
5
 #include <ipxe/tables.h>
6
 #include <ipxe/tables.h>
6
 
7
 
17
 
18
 
18
 FILE_LICENCE ( GPL2_OR_LATER );
19
 FILE_LICENCE ( GPL2_OR_LATER );
19
 
20
 
21
+struct pixel_buffer;
22
+
23
+/** A console configuration */
24
+struct console_configuration {
25
+	/** Width */
26
+	unsigned int width;
27
+	/** Height */
28
+	unsigned int height;
29
+	/** Colour depth */
30
+	unsigned int bpp;
31
+	/** Background picture, if any */
32
+	struct pixel_buffer *pixbuf;
33
+};
34
+
20
 /**
35
 /**
21
  * A console driver
36
  * A console driver
22
  *
37
  *
25
  * #__console_driver.
40
  * #__console_driver.
26
  *
41
  *
27
  * @note Consoles that cannot be used before their initialisation
42
  * @note Consoles that cannot be used before their initialisation
28
- * function has completed should set #disabled=1 initially.  This
29
- * allows other console devices to still be used to print out early
30
- * debugging messages.
31
- *
43
+ * function has completed should set #disabled initially.  This allows
44
+ * other console devices to still be used to print out early debugging
45
+ * messages.
32
  */
46
  */
33
 struct console_driver {
47
 struct console_driver {
34
-	/** Console is disabled.
35
-	 *
36
-	 * The console's putchar(), getchar() and iskey() methods will
37
-	 * not be called while #disabled==1.  Typically the console's
38
-	 * initialisation functions will set #disabled=0 upon
39
-	 * completion.
48
+	/**
49
+	 * Console disabled flags
40
 	 *
50
 	 *
51
+	 * This is the bitwise OR of zero or more console disabled
52
+	 * flags.
41
 	 */
53
 	 */
42
 	int disabled;
54
 	int disabled;
43
-
44
-	/** Write a character to the console.
55
+	/**
56
+	 * Write a character to the console
45
 	 *
57
 	 *
46
 	 * @v character		Character to be written
58
 	 * @v character		Character to be written
47
-	 * @ret None		-
48
-	 * @err None		-
49
-	 *
50
 	 */
59
 	 */
51
-	void ( *putchar ) ( int character );
52
-
53
-	/** Read a character from the console.
60
+	void ( * putchar ) ( int character );
61
+	/**
62
+	 * Read a character from the console
54
 	 *
63
 	 *
55
-	 * @v None		-
56
 	 * @ret character	Character read
64
 	 * @ret character	Character read
57
-	 * @err None		-
58
 	 *
65
 	 *
59
 	 * If no character is available to be read, this method will
66
 	 * If no character is available to be read, this method will
60
 	 * block.  The character read should not be echoed back to the
67
 	 * block.  The character read should not be echoed back to the
61
 	 * console.
68
 	 * console.
62
-	 *
63
 	 */
69
 	 */
64
-	int ( *getchar ) ( void );
65
-
66
-	/** Check for available input.
70
+	int ( * getchar ) ( void );
71
+	/**
72
+	 * Check for available input
67
 	 *
73
 	 *
68
-	 * @v None		-
69
-	 * @ret True		Input is available
70
-	 * @ret False		Input is not available
71
-	 * @err None		-
74
+	 * @ret is_available	Input is available
72
 	 *
75
 	 *
73
-	 * This should return True if a subsequent call to getchar()
76
+	 * This should return true if a subsequent call to getchar()
74
 	 * will not block.
77
 	 * will not block.
75
-	 *
76
 	 */
78
 	 */
77
-	int ( *iskey ) ( void );
78
-
79
-	/** Console usage bitmask
79
+	int ( * iskey ) ( void );
80
+	/**
81
+	 * Console usage bitmask
80
 	 *
82
 	 *
81
 	 * This is the bitwise OR of zero or more @c CONSOLE_USAGE_XXX
83
 	 * This is the bitwise OR of zero or more @c CONSOLE_USAGE_XXX
82
 	 * values.
84
 	 * values.
84
 	int usage;
86
 	int usage;
85
 };
87
 };
86
 
88
 
89
+/** Console is disabled for input */
90
+#define CONSOLE_DISABLED_INPUT 0x0001
91
+
92
+/** Console is disabled for output */
93
+#define CONSOLE_DISABLED_OUTPUT 0x0002
94
+
95
+/** Console is disabled for all uses */
96
+#define CONSOLE_DISABLED ( CONSOLE_DISABLED_INPUT | CONSOLE_DISABLED_OUTPUT )
97
+
87
 /** Console driver table */
98
 /** Console driver table */
88
 #define CONSOLES __table ( struct console_driver, "consoles" )
99
 #define CONSOLES __table ( struct console_driver, "consoles" )
89
 
100
 

+ 2
- 2
src/net/tcp/syslogs.c View File

178
 /** Encrypted syslog console driver */
178
 /** Encrypted syslog console driver */
179
 struct console_driver syslogs_console __console_driver = {
179
 struct console_driver syslogs_console __console_driver = {
180
 	.putchar = syslogs_putchar,
180
 	.putchar = syslogs_putchar,
181
-	.disabled = 1,
181
+	.disabled = CONSOLE_DISABLED,
182
 	.usage = CONSOLE_SYSLOGS,
182
 	.usage = CONSOLE_SYSLOGS,
183
 };
183
 };
184
 
184
 
227
 	old_server = NULL;
227
 	old_server = NULL;
228
 
228
 
229
 	/* Reset encrypted syslog connection */
229
 	/* Reset encrypted syslog connection */
230
-	syslogs_console.disabled = 1;
230
+	syslogs_console.disabled = CONSOLE_DISABLED;
231
 	intf_restart ( &syslogs, 0 );
231
 	intf_restart ( &syslogs, 0 );
232
 
232
 
233
 	/* Do nothing unless we have a log server */
233
 	/* Do nothing unless we have a log server */

+ 2
- 2
src/net/udp/syslog.c View File

176
 /** Syslog console driver */
176
 /** Syslog console driver */
177
 struct console_driver syslog_console __console_driver = {
177
 struct console_driver syslog_console __console_driver = {
178
 	.putchar = syslog_putchar,
178
 	.putchar = syslog_putchar,
179
-	.disabled = 1,
179
+	.disabled = CONSOLE_DISABLED,
180
 	.usage = CONSOLE_SYSLOG,
180
 	.usage = CONSOLE_SYSLOG,
181
 };
181
 };
182
 
182
 
222
 	}
222
 	}
223
 
223
 
224
 	/* Fetch log server */
224
 	/* Fetch log server */
225
-	syslog_console.disabled = 1;
225
+	syslog_console.disabled = CONSOLE_DISABLED;
226
 	old_addr.s_addr = sin_logserver->sin_addr.s_addr;
226
 	old_addr.s_addr = sin_logserver->sin_addr.s_addr;
227
 	if ( ( len = fetch_ipv4_setting ( NULL, &syslog_setting,
227
 	if ( ( len = fetch_ipv4_setting ( NULL, &syslog_setting,
228
 					  &sin_logserver->sin_addr ) ) >= 0 ) {
228
 					  &sin_logserver->sin_addr ) ) >= 0 ) {

Loading…
Cancel
Save