drivers/tty/serial/earlycon.c

Source file repositories/reference/linux-study-clean/drivers/tty/serial/earlycon.c

File Facts

System
Linux kernel
Corpus path
drivers/tty/serial/earlycon.c
Extension
.c
Size
8962 bytes
Lines
354
Domain
Driver Families
Bucket
drivers/tty
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (buf[len]) {
			if (buf[len] != ',')
				continue;
			buf += len + 1;
		} else
			buf = NULL;

		return register_earlycon(buf, match);
	}

	if (empty_compatible) {
		empty_compatible = false;
		goto again;
	}

	return -ENOENT;
}

/*
 * This defers the initialization of the early console until after ACPI has
 * been initialized.
 */
bool earlycon_acpi_spcr_enable __initdata;

/* early_param wrapper for setup_earlycon() */
static int __init param_setup_earlycon(char *buf)
{
	int err;

	/* Just 'earlycon' is a valid param for devicetree and ACPI SPCR. */
	if (!buf || !buf[0]) {
		if (IS_ENABLED(CONFIG_ACPI_SPCR_TABLE)) {
			earlycon_acpi_spcr_enable = true;
			return 0;
		} else if (!buf) {
			return early_init_dt_scan_chosen_stdout();
		}
	}

	err = setup_earlycon(buf);
	if (err == -ENOENT || err == -EALREADY)
		return 0;
	return err;
}
early_param("earlycon", param_setup_earlycon);

/*
 * The `console` parameter is overloaded. It's handled here as an early param
 * and in `printk.c` as a late param. It's possible to specify an early
 * `bootconsole` using `earlycon=uartXXXX` (handled above), or via
 * the `console=uartXXX` alias. See the comment in `8250_early.c`.
 */
static int __init param_setup_earlycon_console_alias(char *buf)
{
	/*
	 * A plain `console` parameter must not enable the SPCR `bootconsole`
	 * like a plain `earlycon` does.
	 *
	 * A `console=` parameter that specifies an empty value is used to
	 * disable the `console`, not the `earlycon` `bootconsole`. The
	 * disabling of the `console` is handled by `printk.c`.
	 */
	if (!buf || !buf[0])
		return 0;

	return param_setup_earlycon(buf);
}
early_param("console", param_setup_earlycon_console_alias);

#ifdef CONFIG_OF_EARLY_FLATTREE

int __init of_setup_earlycon(const struct earlycon_id *match,
			     unsigned long node,
			     const char *options)
{
	int err;
	struct uart_port *port = &early_console_dev.port;
	const __be32 *val;
	bool big_endian;
	u64 addr;

	if (console_is_registered(&early_con))
		return -EALREADY;

	spin_lock_init(&port->lock);
	port->iotype = UPIO_MEM;
	addr = of_flat_dt_translate_address(node);
	if (addr == OF_BAD_ADDR) {
		pr_warn("[%s] bad address\n", match->name);
		return -ENXIO;

Annotation

Implementation Notes