Skip to content

Commit 70b0d22

Browse files
Yinghai LuH. Peter Anvin
authored andcommitted
x86, setup: Only set early_serial_base after port is initialized
putchar is using early_serial_base to check if port is initialized. So we only assign it after early_serial_init() is called, in case we need use VGA to debug early serial console. Also add display for port addr and baud. -v2: update to current tip Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: Yinghai Lu <yinghai@kernel.org> LKML-Reference: <4C3E0171.6050008@kernel.org> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
1 parent ce0aa5d commit 70b0d22

1 file changed

Lines changed: 33 additions & 30 deletions

File tree

‎arch/x86/boot/tty.c‎

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -152,35 +152,40 @@ int getchar_timeout(void)
152152
return 0; /* Timeout! */
153153
}
154154

155-
static void early_serial_init(int baud)
155+
static void early_serial_init(int port, int baud)
156156
{
157157
unsigned char c;
158158
unsigned divisor;
159159

160-
outb(0x3, early_serial_base + LCR); /* 8n1 */
161-
outb(0, early_serial_base + IER); /* no interrupt */
162-
outb(0, early_serial_base + FCR); /* no fifo */
163-
outb(0x3, early_serial_base + MCR); /* DTR + RTS */
160+
outb(0x3, port + LCR); /* 8n1 */
161+
outb(0, port + IER); /* no interrupt */
162+
outb(0, port + FCR); /* no fifo */
163+
outb(0x3, port + MCR); /* DTR + RTS */
164164

165165
divisor = 115200 / baud;
166-
c = inb(early_serial_base + LCR);
167-
outb(c | DLAB, early_serial_base + LCR);
168-
outb(divisor & 0xff, early_serial_base + DLL);
169-
outb((divisor >> 8) & 0xff, early_serial_base + DLH);
170-
outb(c & ~DLAB, early_serial_base + LCR);
166+
c = inb(port + LCR);
167+
outb(c | DLAB, port + LCR);
168+
outb(divisor & 0xff, port + DLL);
169+
outb((divisor >> 8) & 0xff, port + DLH);
170+
outb(c & ~DLAB, port + LCR);
171+
172+
early_serial_base = port;
173+
174+
printf("Early serial console at I/O port 0x%x baud: %d\n", port, baud);
171175
}
172176

173-
static int parse_earlyprintk(void)
177+
static void parse_earlyprintk(void)
174178
{
175179
int baud = DEFAULT_BAUD;
176180
char arg[32];
177181
int pos = 0;
182+
int port = 0;
178183

179184
if (cmdline_find_option("earlyprintk", arg, sizeof arg) > 0) {
180185
char *e;
181186

182187
if (!strncmp(arg, "serial", 6)) {
183-
early_serial_base = DEFAULT_SERIAL_PORT;
188+
port = DEFAULT_SERIAL_PORT;
184189
pos += 6;
185190
}
186191

@@ -189,15 +194,15 @@ static int parse_earlyprintk(void)
189194

190195
if (!strncmp(arg, "ttyS", 4)) {
191196
static const int bases[] = { 0x3f8, 0x2f8 };
192-
int port = 0;
197+
int idx = 0;
193198

194199
if (!strncmp(arg + pos, "ttyS", 4))
195200
pos += 4;
196201

197202
if (arg[pos++] == '1')
198-
port = 1;
203+
idx = 1;
199204

200-
early_serial_base = bases[port];
205+
port = bases[idx];
201206
}
202207

203208
if (arg[pos] == ',')
@@ -208,7 +213,8 @@ static int parse_earlyprintk(void)
208213
baud = DEFAULT_BAUD;
209214
}
210215

211-
return baud;
216+
if (port)
217+
early_serial_init(port, baud);
212218
}
213219

214220
#define BASE_BAUD (1843200/16)
@@ -227,44 +233,41 @@ static unsigned int probe_baud(int port)
227233
return BASE_BAUD / quot;
228234
}
229235

230-
static int parse_console_uart8250(void)
236+
static void parse_console_uart8250(void)
231237
{
232238
char optstr[64], *options;
233239
int baud = DEFAULT_BAUD;
240+
int port = 0;
234241

235242
/*
236243
* console=uart8250,io,0x3f8,115200n8
237244
* need to make sure it is last one console !
238245
*/
239246
if (cmdline_find_option("console", optstr, sizeof optstr) <= 0)
240-
return baud;
247+
return;
241248

242249
options = optstr;
243250

244251
if (!strncmp(options, "uart8250,io,", 12))
245-
early_serial_base = simple_strtoull(options + 12, &options, 0);
252+
port = simple_strtoull(options + 12, &options, 0);
246253
else if (!strncmp(options, "uart,io,", 8))
247-
early_serial_base = simple_strtoull(options + 8, &options, 0);
254+
port = simple_strtoull(options + 8, &options, 0);
248255
else
249-
return baud;
256+
return;
250257

251258
if (options && (options[0] == ','))
252259
baud = simple_strtoull(options + 1, &options, 0);
253260
else
254-
baud = probe_baud(early_serial_base);
261+
baud = probe_baud(port);
255262

256-
return baud;
263+
if (port)
264+
early_serial_init(port, baud);
257265
}
258266

259267
void console_init(void)
260268
{
261-
int baud;
262-
263-
baud = parse_earlyprintk();
269+
parse_earlyprintk();
264270

265271
if (!early_serial_base)
266-
baud = parse_console_uart8250();
267-
268-
if (early_serial_base != 0)
269-
early_serial_init(baud);
272+
parse_console_uart8250();
270273
}

0 commit comments

Comments
 (0)