forked from mirrors/linux
		
	serial: earlycon: Refactor parse_options into serial core
Prepare to support console-defined matching; refactor the command line parameter string processing from parse_options() into a new core function, uart_parse_earlycon(), which decodes command line parameters of the form: earlycon=<name>,io|mmio|mmio32,<addr>,<options> console=<name>,io|mmio|mmio32,<addr>,<options> earlycon=<name>,0x<addr>,<options> console=<name>,0x<addr>,<options> Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
		
							parent
							
								
									1e1257860f
								
							
						
					
					
						commit
						73abaf87f0
					
				
					 3 changed files with 61 additions and 26 deletions
				
			
		| 
						 | 
					@ -54,44 +54,31 @@ static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
 | 
				
			||||||
	return base;
 | 
						return base;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int __init parse_options(struct earlycon_device *device,
 | 
					static int __init parse_options(struct earlycon_device *device, char *options)
 | 
				
			||||||
				char *options)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct uart_port *port = &device->port;
 | 
						struct uart_port *port = &device->port;
 | 
				
			||||||
	int mmio, mmio32, length;
 | 
						int length;
 | 
				
			||||||
	unsigned long addr;
 | 
						unsigned long addr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!options)
 | 
						if (uart_parse_earlycon(options, &port->iotype, &addr, &options))
 | 
				
			||||||
		return -ENODEV;
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mmio = !strncmp(options, "mmio,", 5);
 | 
						switch (port->iotype) {
 | 
				
			||||||
	mmio32 = !strncmp(options, "mmio32,", 7);
 | 
						case UPIO_MEM32:
 | 
				
			||||||
	if (mmio || mmio32) {
 | 
							port->regshift = 2;	/* fall-through */
 | 
				
			||||||
		port->iotype = (mmio ? UPIO_MEM : UPIO_MEM32);
 | 
						case UPIO_MEM:
 | 
				
			||||||
		options += mmio ? 5 : 7;
 | 
					 | 
				
			||||||
		addr = simple_strtoul(options, NULL, 0);
 | 
					 | 
				
			||||||
		port->mapbase = addr;
 | 
							port->mapbase = addr;
 | 
				
			||||||
		if (mmio32)
 | 
							break;
 | 
				
			||||||
			port->regshift = 2;
 | 
						case UPIO_PORT:
 | 
				
			||||||
	} else if (!strncmp(options, "io,", 3)) {
 | 
					 | 
				
			||||||
		port->iotype = UPIO_PORT;
 | 
					 | 
				
			||||||
		options += 3;
 | 
					 | 
				
			||||||
		addr = simple_strtoul(options, NULL, 0);
 | 
					 | 
				
			||||||
		port->iobase = addr;
 | 
							port->iobase = addr;
 | 
				
			||||||
		mmio = 0;
 | 
							break;
 | 
				
			||||||
	} else if (!strncmp(options, "0x", 2)) {
 | 
						default:
 | 
				
			||||||
		port->iotype = UPIO_MEM;
 | 
					 | 
				
			||||||
		addr = simple_strtoul(options, NULL, 0);
 | 
					 | 
				
			||||||
		port->mapbase = addr;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	port->uartclk = BASE_BAUD * 16;
 | 
						port->uartclk = BASE_BAUD * 16;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	options = strchr(options, ',');
 | 
					 | 
				
			||||||
	if (options) {
 | 
						if (options) {
 | 
				
			||||||
		options++;
 | 
					 | 
				
			||||||
		device->baud = simple_strtoul(options, NULL, 0);
 | 
							device->baud = simple_strtoul(options, NULL, 0);
 | 
				
			||||||
		length = min(strcspn(options, " ") + 1,
 | 
							length = min(strcspn(options, " ") + 1,
 | 
				
			||||||
			     (size_t)(sizeof(device->options)));
 | 
								     (size_t)(sizeof(device->options)));
 | 
				
			||||||
| 
						 | 
					@ -100,7 +87,7 @@ static int __init parse_options(struct earlycon_device *device,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (port->iotype == UPIO_MEM || port->iotype == UPIO_MEM32)
 | 
						if (port->iotype == UPIO_MEM || port->iotype == UPIO_MEM32)
 | 
				
			||||||
		pr_info("Early serial console at MMIO%s 0x%llx (options '%s')\n",
 | 
							pr_info("Early serial console at MMIO%s 0x%llx (options '%s')\n",
 | 
				
			||||||
			mmio32 ? "32" : "",
 | 
								(port->iotype == UPIO_MEM32) ? "32" : "",
 | 
				
			||||||
			(unsigned long long)port->mapbase,
 | 
								(unsigned long long)port->mapbase,
 | 
				
			||||||
			device->options);
 | 
								device->options);
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1808,6 +1808,52 @@ uart_get_console(struct uart_port *ports, int nr, struct console *co)
 | 
				
			||||||
	return ports + idx;
 | 
						return ports + idx;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 *	uart_parse_earlycon - Parse earlycon options
 | 
				
			||||||
 | 
					 *	@p:	  ptr to 2nd field (ie., just beyond '<name>,')
 | 
				
			||||||
 | 
					 *	@iotype:  ptr for decoded iotype (out)
 | 
				
			||||||
 | 
					 *	@addr:    ptr for decoded mapbase/iobase (out)
 | 
				
			||||||
 | 
					 *	@options: ptr for <options> field; NULL if not present (out)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *	Decodes earlycon kernel command line parameters of the form
 | 
				
			||||||
 | 
					 *	   earlycon=<name>,io|mmio|mmio32,<addr>,<options>
 | 
				
			||||||
 | 
					 *	   console=<name>,io|mmio|mmio32,<addr>,<options>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *	The optional form
 | 
				
			||||||
 | 
					 *	   earlycon=<name>,0x<addr>,<options>
 | 
				
			||||||
 | 
					 *	   console=<name>,0x<addr>,<options>
 | 
				
			||||||
 | 
					 *	is also accepted; the returned @iotype will be UPIO_MEM.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *	Returns 0 on success or -EINVAL on failure
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr,
 | 
				
			||||||
 | 
								char **options)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (strncmp(p, "mmio,", 5) == 0) {
 | 
				
			||||||
 | 
							*iotype = UPIO_MEM;
 | 
				
			||||||
 | 
							p += 5;
 | 
				
			||||||
 | 
						} else if (strncmp(p, "mmio32,", 7) == 0) {
 | 
				
			||||||
 | 
							*iotype = UPIO_MEM32;
 | 
				
			||||||
 | 
							p += 7;
 | 
				
			||||||
 | 
						} else if (strncmp(p, "io,", 3) == 0) {
 | 
				
			||||||
 | 
							*iotype = UPIO_PORT;
 | 
				
			||||||
 | 
							p += 3;
 | 
				
			||||||
 | 
						} else if (strncmp(p, "0x", 2) == 0) {
 | 
				
			||||||
 | 
							*iotype = UPIO_MEM;
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						*addr = simple_strtoul(p, NULL, 0);
 | 
				
			||||||
 | 
						p = strchr(p, ',');
 | 
				
			||||||
 | 
						if (p)
 | 
				
			||||||
 | 
							p++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						*options = p;
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EXPORT_SYMBOL_GPL(uart_parse_earlycon);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 *	uart_parse_options - Parse serial port baud/parity/bits/flow control.
 | 
					 *	uart_parse_options - Parse serial port baud/parity/bits/flow control.
 | 
				
			||||||
 *	@options: pointer to option string
 | 
					 *	@options: pointer to option string
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -354,6 +354,8 @@ early_param("earlycon", name ## _setup_earlycon);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct uart_port *uart_get_console(struct uart_port *ports, int nr,
 | 
					struct uart_port *uart_get_console(struct uart_port *ports, int nr,
 | 
				
			||||||
				   struct console *c);
 | 
									   struct console *c);
 | 
				
			||||||
 | 
					int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr,
 | 
				
			||||||
 | 
								char **options);
 | 
				
			||||||
void uart_parse_options(char *options, int *baud, int *parity, int *bits,
 | 
					void uart_parse_options(char *options, int *baud, int *parity, int *bits,
 | 
				
			||||||
			int *flow);
 | 
								int *flow);
 | 
				
			||||||
int uart_set_options(struct uart_port *port, struct console *co, int baud,
 | 
					int uart_set_options(struct uart_port *port, struct console *co, int baud,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue