Skip to content

Commit ce0aa5d

Browse files
Yinghai LuH. Peter Anvin
authored andcommitted
x86, setup: Make the setup code also accept console=uart8250
Make the boot code also accept the console=uart8250,io,0x2f8,115200n form of early console. Also add back simple_guess_base(), otherwise those simple_strtoull(,,0) are not going to work. Signed-off-by: Yinghai Lu <yinghai@kernel.org> LKML-Reference: <4C3CCE05.4090505@kernel.org> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
1 parent fa97bdf commit ce0aa5d

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

‎arch/x86/boot/string.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,32 @@ unsigned int atou(const char *s)
6868
/* Works only for digits and letters, but small and fast */
6969
#define TOLOWER(x) ((x) | 0x20)
7070

71+
static unsigned int simple_guess_base(const char *cp)
72+
{
73+
if (cp[0] == '0') {
74+
if (TOLOWER(cp[1]) == 'x' && isxdigit(cp[2]))
75+
return 16;
76+
else
77+
return 8;
78+
} else {
79+
return 10;
80+
}
81+
}
82+
83+
/**
84+
* simple_strtoull - convert a string to an unsigned long long
85+
* @cp: The start of the string
86+
* @endp: A pointer to the end of the parsed string will be placed here
87+
* @base: The number base to use
88+
*/
89+
7190
unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
7291
{
7392
unsigned long long result = 0;
7493

94+
if (!base)
95+
base = simple_guess_base(cp);
96+
7597
if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x')
7698
cp += 2;
7799

‎arch/x86/boot/tty.c‎

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static void early_serial_init(int baud)
170170
outb(c & ~DLAB, early_serial_base + LCR);
171171
}
172172

173-
void console_init(void)
173+
static int parse_earlyprintk(void)
174174
{
175175
int baud = DEFAULT_BAUD;
176176
char arg[32];
@@ -208,6 +208,63 @@ void console_init(void)
208208
baud = DEFAULT_BAUD;
209209
}
210210

211+
return baud;
212+
}
213+
214+
#define BASE_BAUD (1843200/16)
215+
static unsigned int probe_baud(int port)
216+
{
217+
unsigned char lcr, dll, dlh;
218+
unsigned int quot;
219+
220+
lcr = inb(port + LCR);
221+
outb(lcr | DLAB, port + LCR);
222+
dll = inb(port + DLL);
223+
dlh = inb(port + DLH);
224+
outb(lcr, port + LCR);
225+
quot = (dlh << 8) | dll;
226+
227+
return BASE_BAUD / quot;
228+
}
229+
230+
static int parse_console_uart8250(void)
231+
{
232+
char optstr[64], *options;
233+
int baud = DEFAULT_BAUD;
234+
235+
/*
236+
* console=uart8250,io,0x3f8,115200n8
237+
* need to make sure it is last one console !
238+
*/
239+
if (cmdline_find_option("console", optstr, sizeof optstr) <= 0)
240+
return baud;
241+
242+
options = optstr;
243+
244+
if (!strncmp(options, "uart8250,io,", 12))
245+
early_serial_base = simple_strtoull(options + 12, &options, 0);
246+
else if (!strncmp(options, "uart,io,", 8))
247+
early_serial_base = simple_strtoull(options + 8, &options, 0);
248+
else
249+
return baud;
250+
251+
if (options && (options[0] == ','))
252+
baud = simple_strtoull(options + 1, &options, 0);
253+
else
254+
baud = probe_baud(early_serial_base);
255+
256+
return baud;
257+
}
258+
259+
void console_init(void)
260+
{
261+
int baud;
262+
263+
baud = parse_earlyprintk();
264+
265+
if (!early_serial_base)
266+
baud = parse_console_uart8250();
267+
211268
if (early_serial_base != 0)
212269
early_serial_init(baud);
213270
}

0 commit comments

Comments
 (0)