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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/console.hlinux/kernel.hlinux/init.hlinux/io.hlinux/serial_core.hlinux/sizes.hlinux/of.hlinux/of_fdt.hlinux/acpi.hasm/fixmap.hasm/serial.h
Detected Declarations
function earlycon_mapfunction earlycon_initfunction earlycon_print_infofunction parse_optionsfunction register_earlyconfunction setup_earlyconfunction param_setup_earlyconfunction param_setup_earlycon_console_aliasfunction of_setup_earlycon
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
- Immediate include surface: `linux/console.h`, `linux/kernel.h`, `linux/init.h`, `linux/io.h`, `linux/serial_core.h`, `linux/sizes.h`, `linux/of.h`, `linux/of_fdt.h`.
- Detected declarations: `function earlycon_map`, `function earlycon_init`, `function earlycon_print_info`, `function parse_options`, `function register_earlycon`, `function setup_earlycon`, `function param_setup_earlycon`, `function param_setup_earlycon_console_alias`, `function of_setup_earlycon`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.