drivers/tty/serial/serial_core.c
Source file repositories/reference/linux-study-clean/drivers/tty/serial/serial_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/serial/serial_core.c- Extension
.c- Size
- 93469 bytes
- Lines
- 3588
- Domain
- Driver Families
- Bucket
- drivers/tty
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/tty.hlinux/tty_flip.hlinux/slab.hlinux/sched/signal.hlinux/init.hlinux/console.hlinux/gpio/consumer.hlinux/kernel.hlinux/of.hlinux/pm_runtime.hlinux/proc_fs.hlinux/seq_file.hlinux/device.hlinux/serial.hlinux/serial_core.hlinux/sysrq.hlinux/delay.hlinux/mutex.hlinux/math64.hlinux/security.hlinux/irq.hlinux/uaccess.hserial_base.h
Detected Declarations
struct uart_matchfunction uart_dcd_enabledfunction uart_port_dereffunction uart_port_unlock_dereffunction uart_write_wakeupfunction uart_stopfunction __uart_startfunction uart_startfunction uart_update_mctrlfunction uart_port_dtr_rtsfunction uart_change_line_settingsfunction uart_alloc_xmit_buffunction uart_free_xmit_buffunction uart_port_startupfunction uart_startupfunction uart_shutdownfunction uart_update_timeoutfunction ratefunction divisorfunction uart_put_charfunction uart_flush_charsfunction uart_writefunction uart_write_roomfunction uart_chars_in_bufferfunction uart_flush_bufferfunction uart_xchar_outfunction uart_send_xcharfunction uart_throttlefunction uart_unthrottlefunction uart_get_infofunction uart_get_info_userfunction uart_change_portfunction uart_set_infofunction uart_set_info_userfunction uart_get_lsr_infofunction uart_tiocmgetfunction uart_tiocmsetfunction uart_break_ctlfunction uart_do_autoconfigfunction uart_enable_msfunction inputsfunction interruptsfunction uart_check_rs485_flagsfunction uart_sanitize_serial_rs485_delaysfunction uart_sanitize_serial_rs485function uart_set_rs485_terminationfunction uart_set_rs485_rx_during_txfunction uart_rs485_config
Annotated Snippet
struct uart_match {
struct uart_port *port;
struct uart_driver *driver;
};
static int serial_match_port(struct device *dev, const void *data)
{
const struct uart_match *match = data;
struct tty_driver *tty_drv = match->driver->tty_driver;
dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) +
match->port->line;
return dev->devt == devt; /* Actually, only one tty per port */
}
int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport)
{
struct uart_state *state = drv->state + uport->line;
struct tty_port *port = &state->port;
struct device *tty_dev;
struct uart_match match = {uport, drv};
guard(mutex)(&port->mutex);
tty_dev = device_find_child(&uport->port_dev->dev, &match, serial_match_port);
if (tty_dev && device_may_wakeup(tty_dev)) {
enable_irq_wake(uport->irq);
put_device(tty_dev);
return 0;
}
put_device(tty_dev);
/*
* Nothing to do if the console is not suspending
* except stop_rx to prevent any asynchronous data
* over RX line. However ensure that we will be
* able to Re-start_rx later.
*/
if (!console_suspend_enabled && uart_console(uport)) {
if (uport->ops->start_rx) {
guard(uart_port_lock_irq)(uport);
uport->ops->stop_rx(uport);
}
device_set_awake_path(uport->dev);
return 0;
}
uport->suspended = 1;
if (tty_port_initialized(port)) {
const struct uart_ops *ops = uport->ops;
int tries;
unsigned int mctrl;
tty_port_set_suspended(port, true);
tty_port_set_initialized(port, false);
scoped_guard(uart_port_lock_irq, uport) {
ops->stop_tx(uport);
if (!(uport->rs485.flags & SER_RS485_ENABLED))
ops->set_mctrl(uport, 0);
/* save mctrl so it can be restored on resume */
mctrl = uport->mctrl;
uport->mctrl = 0;
ops->stop_rx(uport);
}
/*
* Wait for the transmitter to empty.
*/
for (tries = 3; !ops->tx_empty(uport) && tries; tries--)
msleep(10);
if (!tries)
dev_err(uport->dev, "%s: Unable to drain transmitter\n",
uport->name);
ops->shutdown(uport);
uport->mctrl = mctrl;
}
/*
* Suspend the console device before suspending the port.
*/
if (uart_console(uport))
console_suspend(uport->cons);
uart_change_pm(state, UART_PM_STATE_OFF);
return 0;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/tty.h`, `linux/tty_flip.h`, `linux/slab.h`, `linux/sched/signal.h`, `linux/init.h`, `linux/console.h`, `linux/gpio/consumer.h`.
- Detected declarations: `struct uart_match`, `function uart_dcd_enabled`, `function uart_port_deref`, `function uart_port_unlock_deref`, `function uart_write_wakeup`, `function uart_stop`, `function __uart_start`, `function uart_start`, `function uart_update_mctrl`, `function uart_port_dtr_rts`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.