diff options
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/boot/string.c | 22 | ||||
-rw-r--r-- | arch/x86/boot/tty.c | 59 |
2 files changed, 80 insertions, 1 deletions
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c index aba29df4a7bb..3cbc4058dd26 100644 --- a/arch/x86/boot/string.c +++ b/arch/x86/boot/string.c | |||
@@ -68,10 +68,32 @@ unsigned int atou(const char *s) | |||
68 | /* Works only for digits and letters, but small and fast */ | 68 | /* Works only for digits and letters, but small and fast */ |
69 | #define TOLOWER(x) ((x) | 0x20) | 69 | #define TOLOWER(x) ((x) | 0x20) |
70 | 70 | ||
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 | |||
71 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) | 90 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) |
72 | { | 91 | { |
73 | unsigned long long result = 0; | 92 | unsigned long long result = 0; |
74 | 93 | ||
94 | if (!base) | ||
95 | base = simple_guess_base(cp); | ||
96 | |||
75 | if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x') | 97 | if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x') |
76 | cp += 2; | 98 | cp += 2; |
77 | 99 | ||
diff --git a/arch/x86/boot/tty.c b/arch/x86/boot/tty.c index f3ceee20ff12..f6d52e65f97a 100644 --- a/arch/x86/boot/tty.c +++ b/arch/x86/boot/tty.c | |||
@@ -170,7 +170,7 @@ static void early_serial_init(int baud) | |||
170 | outb(c & ~DLAB, early_serial_base + LCR); | 170 | outb(c & ~DLAB, early_serial_base + LCR); |
171 | } | 171 | } |
172 | 172 | ||
173 | void console_init(void) | 173 | static int parse_earlyprintk(void) |
174 | { | 174 | { |
175 | int baud = DEFAULT_BAUD; | 175 | int baud = DEFAULT_BAUD; |
176 | char arg[32]; | 176 | char arg[32]; |
@@ -208,6 +208,63 @@ void console_init(void) | |||
208 | baud = DEFAULT_BAUD; | 208 | baud = DEFAULT_BAUD; |
209 | } | 209 | } |
210 | 210 | ||
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 | |||
211 | if (early_serial_base != 0) | 268 | if (early_serial_base != 0) |
212 | early_serial_init(baud); | 269 | early_serial_init(baud); |
213 | } | 270 | } |