ソースを参照

[Serial] Split serial console from serial driver

tags/v0.9.4
Stefan Hajnoczi 16年前
コミット
831db76ff7
5個のファイルの変更62行の追加32行の削除
  1. 1
    1
      src/core/config.c
  2. 13
    29
      src/core/serial.c
  3. 31
    0
      src/core/serial_console.c
  4. 3
    2
      src/include/gpxe/init.h
  5. 14
    0
      src/include/gpxe/serial.h

+ 1
- 1
src/core/config.c ファイルの表示

@@ -54,7 +54,7 @@
54 54
 REQUIRE_OBJECT ( bios_console );
55 55
 #endif
56 56
 #ifdef CONSOLE_SERIAL
57
-REQUIRE_OBJECT ( serial );
57
+REQUIRE_OBJECT ( serial_console );
58 58
 #endif
59 59
 #ifdef CONSOLE_DIRECT_VGA
60 60
 REQUIRE_OBJECT ( video_subr );

+ 13
- 29
src/core/serial.c ファイルの表示

@@ -12,10 +12,10 @@
12 12
  */
13 13
 
14 14
 #include "stddef.h"
15
-#include "console.h"
16 15
 #include <gpxe/init.h>
17 16
 #include "io.h"
18 17
 #include <unistd.h>
18
+#include <gpxe/serial.h>
19 19
 #include "config/serial.h"
20 20
 
21 21
 /* Set default values if none specified */
@@ -91,13 +91,11 @@
91 91
 #define uart_writeb(val,addr) outb((val),(addr))
92 92
 #endif
93 93
 
94
-struct console_driver serial_console __console_driver;
95
-
96 94
 /*
97 95
  * void serial_putc(int ch);
98 96
  *	Write character `ch' to port UART_BASE.
99 97
  */
100
-static void serial_putc ( int ch ) {
98
+void serial_putc ( int ch ) {
101 99
 	int i;
102 100
 	int status;
103 101
 	i = 1000; /* timeout */
@@ -116,7 +114,7 @@ static void serial_putc ( int ch ) {
116 114
  * int serial_getc(void);
117 115
  *	Read a character from port UART_BASE.
118 116
  */
119
-static int serial_getc ( void ) {
117
+int serial_getc ( void ) {
120 118
 	int status;
121 119
 	int ch;
122 120
 	do {
@@ -135,7 +133,7 @@ static int serial_getc ( void ) {
135 133
  *       If there is a character in the input buffer of port UART_BASE,
136 134
  *       return nonzero; otherwise return 0.
137 135
  */
138
-static int serial_ischar ( void ) {
136
+int serial_ischar ( void ) {
139 137
 	int status;
140 138
 	status = uart_readb(UART_BASE + UART_LSR);	/* line status reg; */
141 139
 	return status & 1;		/* rx char available */
@@ -217,7 +215,6 @@ static void serial_init ( void ) {
217 215
 		/* line status reg */
218 216
 		status = uart_readb(UART_BASE + UART_LSR);
219 217
 	} while(status & UART_LSR_DR);
220
-	serial_console.disabled = 0;
221 218
  out:
222 219
 	return;
223 220
 }
@@ -229,10 +226,6 @@ static void serial_init ( void ) {
229 226
  */
230 227
 static void serial_fini ( void ) {
231 228
 	int i, status;
232
-	if (serial_console.disabled) {
233
-		/* no serial interface */
234
-		return;
235
-	}
236 229
 	/* Flush the output buffer to avoid dropping characters,
237 230
 	 * if we are reinitializing the serial port.
238 231
 	 */
@@ -243,26 +236,17 @@ static void serial_fini ( void ) {
243 236
 	/* Don't mark it as disabled; it's still usable */
244 237
 }
245 238
 
246
-struct console_driver serial_console __console_driver = {
247
-	.putchar = serial_putc,
248
-	.getchar = serial_getc,
249
-	.iskey = serial_ischar,
250
-	.disabled = 1,
251
-};
252
-
253
-/** Serial console startup function */
254
-struct startup_fn serial_startup_fn __startup_fn ( STARTUP_NORMAL ) = {
255
-	.startup = serial_init,
256
-	.shutdown = serial_fini,
257
-};
258
-
259 239
 /**
260
- * Serial console initialisation function
240
+ * Serial driver initialisation function
261 241
  *
262
- * Initialise console early on so that it is available to capture
263
- * early debug messages.  It is safe to call serial_init() multiple
264
- * times.
242
+ * Initialise serial port early on so that it is available to capture
243
+ * early debug messages.
265 244
  */
266
-struct init_fn serial_init_fn __init_fn ( INIT_CONSOLE ) = {
245
+struct init_fn serial_init_fn __init_fn ( INIT_SERIAL ) = {
267 246
 	.initialise = serial_init,
268 247
 };
248
+
249
+/** Serial driver startup function */
250
+struct startup_fn serial_startup_fn __startup_fn ( STARTUP_NORMAL ) = {
251
+	.shutdown = serial_fini,
252
+};

+ 31
- 0
src/core/serial_console.c ファイルの表示

@@ -0,0 +1,31 @@
1
+#include <gpxe/init.h>
2
+#include <gpxe/serial.h>
3
+#include "console.h"
4
+
5
+/** @file
6
+ *
7
+ * Serial console
8
+ *
9
+ */
10
+
11
+struct console_driver serial_console __console_driver;
12
+
13
+static void serial_console_init ( void ) {
14
+	/* Serial driver initialization should already be done,
15
+	 * time to enable the serial console. */
16
+	serial_console.disabled = 0;
17
+}
18
+
19
+struct console_driver serial_console __console_driver = {
20
+	.putchar = serial_putc,
21
+	.getchar = serial_getc,
22
+	.iskey = serial_ischar,
23
+	.disabled = 1,
24
+};
25
+
26
+/**
27
+ * Serial console initialisation function
28
+ */
29
+struct init_fn serial_console_init_fn __init_fn ( INIT_CONSOLE ) = {
30
+	.initialise = serial_console_init,
31
+};

+ 3
- 2
src/include/gpxe/init.h ファイルの表示

@@ -22,8 +22,9 @@ struct init_fn {
22 22
  */
23 23
 
24 24
 #define INIT_EARLY	01	/**< Early initialisation */
25
-#define	INIT_CONSOLE	02	/**< Console initialisation */
26
-#define INIT_NORMAL	03	/**< Normal initialisation */
25
+#define INIT_SERIAL	02	/**< Serial driver initialisation */
26
+#define	INIT_CONSOLE	03	/**< Console initialisation */
27
+#define INIT_NORMAL	04	/**< Normal initialisation */
27 28
 
28 29
 /** @} */
29 30
 

+ 14
- 0
src/include/gpxe/serial.h ファイルの表示

@@ -0,0 +1,14 @@
1
+#ifndef _GPXE_SERIAL_H
2
+#define _GPXE_SERIAL_H
3
+
4
+/** @file
5
+ *
6
+ * Serial driver functions
7
+ *
8
+ */
9
+
10
+extern void serial_putc ( int ch );
11
+extern int serial_getc ( void );
12
+extern int serial_ischar ( void );
13
+
14
+#endif /* _GPXE_SERIAL_H */

読み込み中…
キャンセル
保存