Переглянути джерело

[console] Add concept of generic console configuration

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 роки тому
джерело
коміт
c501c980e0

+ 4
- 0
src/arch/i386/image/bootsector.c Переглянути файл

@@ -30,6 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
30 30
 #include <realmode.h>
31 31
 #include <biosint.h>
32 32
 #include <bootsector.h>
33
+#include <ipxe/console.h>
33 34
 
34 35
 /** Vector for storing original INT 18 handler
35 36
  *
@@ -60,6 +61,9 @@ int call_bootsector ( unsigned int segment, unsigned int offset,
60 61
 		      unsigned int drive ) {
61 62
 	int discard_b, discard_D, discard_d;
62 63
 
64
+	/* Reset console, since boot sector will probably use it */
65
+	console_reset();
66
+
63 67
 	DBG ( "Booting from boot sector at %04x:%04x\n", segment, offset );
64 68
 
65 69
 	/* Hook INTs 18 and 19 to capture failure paths */

+ 4
- 0
src/arch/i386/image/pxe_image.c Переглянути файл

@@ -33,6 +33,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
33 33
 #include <ipxe/segment.h>
34 34
 #include <ipxe/netdevice.h>
35 35
 #include <ipxe/features.h>
36
+#include <ipxe/console.h>
36 37
 
37 38
 FEATURE ( FEATURE_IMAGE, "PXE", DHCP_EB_FEATURE_PXE, 1 );
38 39
 
@@ -74,6 +75,9 @@ static int pxe_exec ( struct image *image ) {
74 75
 	/* Set PXE command line */
75 76
 	pxe_cmdline = image->cmdline;
76 77
 
78
+	/* Reset console since PXE NBP will probably use it */
79
+	console_reset();
80
+
77 81
 	/* Start PXE NBP */
78 82
 	rc = pxe_start_nbp();
79 83
 

+ 32
- 0
src/core/console.c Переглянути файл

@@ -121,3 +121,35 @@ int getchar ( void ) {
121 121
 int iskey ( void ) {
122 122
 	return has_input() ? 1 : 0;
123 123
 }
124
+
125
+/**
126
+ * Configure console
127
+ *
128
+ * @v config		Console configuration
129
+ * @ret rc		Return status code
130
+ *
131
+ * The configuration is passed to all configurable consoles, including
132
+ * those which are currently disabled.  Consoles may choose to enable
133
+ * or disable themselves depending upon the configuration.
134
+ *
135
+ * If configuration fails, then all consoles will be reset.
136
+ */
137
+int console_configure ( struct console_configuration *config ) {
138
+	struct console_driver *console;
139
+	int rc;
140
+
141
+	/* Try to configure each console */
142
+	for_each_table_entry ( console, CONSOLES ) {
143
+		if ( ( console->configure ) &&
144
+		     ( ( rc = console->configure ( config ) ) != 0 ) )
145
+				goto err;
146
+	}
147
+
148
+	return 0;
149
+
150
+ err:
151
+	/* Reset all consoles, avoiding a potential infinite loop */
152
+	if ( config )
153
+		console_reset();
154
+	return rc;
155
+}

+ 4
- 0
src/core/init.c Переглянути файл

@@ -20,6 +20,7 @@
20 20
 FILE_LICENCE ( GPL2_OR_LATER );
21 21
 
22 22
 #include <ipxe/device.h>
23
+#include <ipxe/console.h>
23 24
 #include <ipxe/init.h>
24 25
 
25 26
 /** @file
@@ -95,5 +96,8 @@ void shutdown ( int flags ) {
95 96
 			startup_fn->shutdown ( flags );
96 97
 	}
97 98
 
99
+	/* Reset console */
100
+	console_reset();
101
+
98 102
 	started = 0;
99 103
 }

+ 17
- 0
src/include/ipxe/console.h Переглянути файл

@@ -77,6 +77,13 @@ struct console_driver {
77 77
 	 * will not block.
78 78
 	 */
79 79
 	int ( * iskey ) ( void );
80
+	/**
81
+	 * Configure console
82
+	 *
83
+	 * @v config		Console configuration, or NULL to reset
84
+	 * @ret rc		Return status code
85
+	 */
86
+	int ( * configure ) ( struct console_configuration *config );
80 87
 	/**
81 88
 	 * Console usage bitmask
82 89
 	 *
@@ -170,5 +177,15 @@ console_set_usage ( int usage ) {
170 177
 
171 178
 extern int iskey ( void );
172 179
 extern int getkey ( unsigned long timeout );
180
+extern int console_configure ( struct console_configuration *config );
181
+
182
+/**
183
+ * Reset console
184
+ *
185
+ */
186
+static inline __attribute__ (( always_inline )) void console_reset ( void ) {
187
+
188
+	console_configure ( NULL );
189
+}
173 190
 
174 191
 #endif /* _IPXE_CONSOLE_H */

Завантаження…
Відмінити
Зберегти