Kaynağa Gözat

[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 yıl önce
ebeveyn
işleme
b2251743d8

+ 1
- 1
src/arch/i386/core/video_subr.c Dosyayı Görüntüle

@@ -104,7 +104,7 @@ static void vga_putc(int byte)
104 104
 
105 105
 struct console_driver vga_console __console_driver = {
106 106
 	.putchar = vga_putc,
107
-	.disabled = 1,
107
+	.disabled = CONSOLE_DISABLED,
108 108
 	.usage = CONSOLE_DIRECT_VGA,
109 109
 };
110 110
 

+ 1
- 1
src/arch/i386/interface/vmware/vmconsole.c Dosyayı Görüntüle

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

+ 1
- 1
src/arch/x86/core/debugcon.c Dosyayı Görüntüle

@@ -74,7 +74,7 @@ static void debugcon_init ( void ) {
74 74
 	check = inb ( DEBUG_PORT );
75 75
 	if ( check != DEBUG_PORT_CHECK ) {
76 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 Dosyayı Görüntüle

@@ -11,15 +11,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
11 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 16
  * @v character		Character to be written
17
- * @ret None		-
18
- * @err None		-
19 17
  *
20 18
  * The character is written out to all enabled console devices, using
21 19
  * each device's console_driver::putchar() method.
22
- *
23 20
  */
24 21
 void putchar ( int character ) {
25 22
 	struct console_driver *console;
@@ -29,7 +26,7 @@ void putchar ( int character ) {
29 26
 		putchar ( '\r' );
30 27
 
31 28
 	for_each_table_entry ( console, CONSOLES ) {
32
-		if ( ( ! console->disabled ) &&
29
+		if ( ( ! ( console->disabled & CONSOLE_DISABLED_OUTPUT ) ) &&
33 30
 		     ( console_usage & console->usage ) &&
34 31
 		     console->putchar )
35 32
 			console->putchar ( character );
@@ -37,23 +34,20 @@ void putchar ( int 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 41
  * All enabled console devices are checked once for available input
48 42
  * using each device's console_driver::iskey() method.  The first
49 43
  * console device that has available input will be returned, if any.
50
- *
51 44
  */
52 45
 static struct console_driver * has_input ( void ) {
53 46
 	struct console_driver *console;
54 47
 
55 48
 	for_each_table_entry ( console, CONSOLES ) {
56
-		if ( ( ! console->disabled ) && console->iskey ) {
49
+		if ( ( ! ( console->disabled & CONSOLE_DISABLED_INPUT ) ) &&
50
+		     console->iskey ) {
57 51
 			if ( console->iskey () )
58 52
 				return console;
59 53
 		}
@@ -62,11 +56,9 @@ static struct console_driver * has_input ( void ) {
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 61
  * @ret character	Character read from a console.
69
- * @err None		-
70 62
  *
71 63
  * A character will be read from the first enabled console device that
72 64
  * has input available using that console's console_driver::getchar()
@@ -80,7 +72,6 @@ static struct console_driver * has_input ( void ) {
80 72
  * @endcode
81 73
  *
82 74
  * The character read will not be echoed back to any console.
83
- *
84 75
  */
85 76
 int getchar ( void ) {
86 77
 	struct console_driver *console;
@@ -116,19 +107,16 @@ int getchar ( void ) {
116 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 115
  * All enabled console devices are checked once for available input
127 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 119
  * blocking.
131
- *
132 120
  */
133 121
 int iskey ( void ) {
134 122
 	return has_input() ? 1 : 0;

+ 1
- 1
src/core/serial_console.c Dosyayı Görüntüle

@@ -30,7 +30,7 @@ struct console_driver serial_console __console_driver = {
30 30
 	.putchar = serial_putc,
31 31
 	.getchar = serial_getc,
32 32
 	.iskey = serial_ischar,
33
-	.disabled = 1,
33
+	.disabled = CONSOLE_DISABLED,
34 34
 	.usage = CONSOLE_SERIAL,
35 35
 };
36 36
 

+ 44
- 33
src/include/ipxe/console.h Dosyayı Görüntüle

@@ -1,6 +1,7 @@
1 1
 #ifndef _IPXE_CONSOLE_H
2 2
 #define _IPXE_CONSOLE_H
3 3
 
4
+#include <stddef.h>
4 5
 #include <stdio.h>
5 6
 #include <ipxe/tables.h>
6 7
 
@@ -17,6 +18,20 @@
17 18
 
18 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 36
  * A console driver
22 37
  *
@@ -25,58 +40,45 @@ FILE_LICENCE ( GPL2_OR_LATER );
25 40
  * #__console_driver.
26 41
  *
27 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 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 54
 	int disabled;
43
-
44
-	/** Write a character to the console.
55
+	/**
56
+	 * Write a character to the console
45 57
 	 *
46 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 64
 	 * @ret character	Character read
57
-	 * @err None		-
58 65
 	 *
59 66
 	 * If no character is available to be read, this method will
60 67
 	 * block.  The character read should not be echoed back to the
61 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 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 83
 	 * This is the bitwise OR of zero or more @c CONSOLE_USAGE_XXX
82 84
 	 * values.
@@ -84,6 +86,15 @@ struct console_driver {
84 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 98
 /** Console driver table */
88 99
 #define CONSOLES __table ( struct console_driver, "consoles" )
89 100
 

+ 2
- 2
src/net/tcp/syslogs.c Dosyayı Görüntüle

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

+ 2
- 2
src/net/udp/syslog.c Dosyayı Görüntüle

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

Loading…
İptal
Kaydet