Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Yinghai Lu and committed by
H. Peter Anvin
70b0d22d ce0aa5dd

+33 -30
+33 -30
arch/x86/boot/tty.c
··· 152 152 return 0; /* Timeout! */ 153 153 } 154 154 155 - static void early_serial_init(int baud) 155 + static void early_serial_init(int port, int baud) 156 156 { 157 157 unsigned char c; 158 158 unsigned divisor; 159 159 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 */ 164 164 165 165 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); 171 175 } 172 176 173 - static int parse_earlyprintk(void) 177 + static void parse_earlyprintk(void) 174 178 { 175 179 int baud = DEFAULT_BAUD; 176 180 char arg[32]; 177 181 int pos = 0; 182 + int port = 0; 178 183 179 184 if (cmdline_find_option("earlyprintk", arg, sizeof arg) > 0) { 180 185 char *e; 181 186 182 187 if (!strncmp(arg, "serial", 6)) { 183 - early_serial_base = DEFAULT_SERIAL_PORT; 188 + port = DEFAULT_SERIAL_PORT; 184 189 pos += 6; 185 190 } 186 191 ··· 194 189 195 190 if (!strncmp(arg, "ttyS", 4)) { 196 191 static const int bases[] = { 0x3f8, 0x2f8 }; 197 - int port = 0; 192 + int idx = 0; 198 193 199 194 if (!strncmp(arg + pos, "ttyS", 4)) 200 195 pos += 4; 201 196 202 197 if (arg[pos++] == '1') 203 - port = 1; 198 + idx = 1; 204 199 205 - early_serial_base = bases[port]; 200 + port = bases[idx]; 206 201 } 207 202 208 203 if (arg[pos] == ',') ··· 213 208 baud = DEFAULT_BAUD; 214 209 } 215 210 216 - return baud; 211 + if (port) 212 + early_serial_init(port, baud); 217 213 } 218 214 219 215 #define BASE_BAUD (1843200/16) ··· 233 227 return BASE_BAUD / quot; 234 228 } 235 229 236 - static int parse_console_uart8250(void) 230 + static void parse_console_uart8250(void) 237 231 { 238 232 char optstr[64], *options; 239 233 int baud = DEFAULT_BAUD; 234 + int port = 0; 240 235 241 236 /* 242 237 * console=uart8250,io,0x3f8,115200n8 243 238 * need to make sure it is last one console ! 244 239 */ 245 240 if (cmdline_find_option("console", optstr, sizeof optstr) <= 0) 246 - return baud; 241 + return; 247 242 248 243 options = optstr; 249 244 250 245 if (!strncmp(options, "uart8250,io,", 12)) 251 - early_serial_base = simple_strtoull(options + 12, &options, 0); 246 + port = simple_strtoull(options + 12, &options, 0); 252 247 else if (!strncmp(options, "uart,io,", 8)) 253 - early_serial_base = simple_strtoull(options + 8, &options, 0); 248 + port = simple_strtoull(options + 8, &options, 0); 254 249 else 255 - return baud; 250 + return; 256 251 257 252 if (options && (options[0] == ',')) 258 253 baud = simple_strtoull(options + 1, &options, 0); 259 254 else 260 - baud = probe_baud(early_serial_base); 255 + baud = probe_baud(port); 261 256 262 - return baud; 257 + if (port) 258 + early_serial_init(port, baud); 263 259 } 264 260 265 261 void console_init(void) 266 262 { 267 - int baud; 268 - 269 - baud = parse_earlyprintk(); 263 + parse_earlyprintk(); 270 264 271 265 if (!early_serial_base) 272 - baud = parse_console_uart8250(); 273 - 274 - if (early_serial_base != 0) 275 - early_serial_init(baud); 266 + parse_console_uart8250(); 276 267 }