drivers/tty/serial/8250/8250_core.c
Source file repositories/reference/linux-study-clean/drivers/tty/serial/8250/8250_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/serial/8250/8250_core.c- Extension
.c- Size
- 23353 bytes
- Lines
- 895
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/acpi.hlinux/hashtable.hlinux/module.hlinux/moduleparam.hlinux/ioport.hlinux/init.hlinux/console.hlinux/sysrq.hlinux/delay.hlinux/platform_device.hlinux/pm_runtime.hlinux/tty.hlinux/ratelimit.hlinux/tty_flip.hlinux/serial.hlinux/serial_8250.hlinux/nmi.hlinux/mutex.hlinux/slab.hlinux/string_helpers.hlinux/uaccess.hlinux/io.hasm/irq.h8250.h
Detected Declarations
struct irq_infofunction serial8250_interruptfunction serial_do_unlinkfunction serial_link_irq_chainfunction scoped_guardfunction serial_unlink_irq_chainfunction hash_for_each_possiblefunction serial8250_timeoutfunction serial8250_backup_timeoutfunction univ8250_setup_timerfunction univ8250_setup_irqfunction univ8250_release_irqfunction serial8250_apply_quirksfunction serial8250_register_portsfunction univ8250_console_writefunction univ8250_console_setupfunction univ8250_console_exitfunction univ8250_console_matchfunction univ8250_console_initfunction early_serial_setupfunction serial8250_suspend_portfunction serial8250_resume_portfunction serial_8250_overrun_backoff_workfunction serial8250_register_8250_portfunction mctrl_gpio_initfunction serial8250_unregister_portexport serial8250_get_portexport serial8250_suspend_portexport serial8250_resume_portexport serial8250_register_8250_portexport serial8250_unregister_port
Annotated Snippet
struct irq_info {
struct hlist_node node;
int irq;
spinlock_t lock; /* Protects list not the hash */
struct list_head *head;
};
#define IRQ_HASH_BITS 5 /* Can be adjusted later */
static DEFINE_HASHTABLE(irq_lists, IRQ_HASH_BITS);
static DEFINE_MUTEX(hash_mutex); /* Used to walk the hash */
static bool skip_txen_test;
module_param(skip_txen_test, bool, 0644);
MODULE_PARM_DESC(skip_txen_test, "Skip checking for the TXEN bug at init time");
/*
* This is the serial driver's interrupt routine.
*
* Arjan thinks the old way was overly complex, so it got simplified.
* Alan disagrees, saying that need the complexity to handle the weird
* nature of ISA shared interrupts. (This is a special exception.)
*
* In order to handle ISA shared interrupts properly, we need to check
* that all ports have been serviced, and therefore the ISA interrupt
* line has been de-asserted.
*
* This means we need to loop through all ports. checking that they
* don't have an interrupt pending.
*/
static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
{
struct irq_info *i = dev_id;
struct list_head *l, *end = NULL;
int pass_counter = 0, handled = 0;
guard(spinlock)(&i->lock);
l = i->head;
do {
struct uart_8250_port *up = list_entry(l, struct uart_8250_port, list);
struct uart_port *port = &up->port;
if (port->handle_irq(port)) {
handled = 1;
end = NULL;
} else if (end == NULL)
end = l;
l = l->next;
if (l == i->head && pass_counter++ > PASS_LIMIT)
break;
} while (l != end);
return IRQ_RETVAL(handled);
}
/*
* To support ISA shared interrupts, we need to have one interrupt
* handler that ensures that the IRQ line has been deasserted
* before returning. Failing to do this will result in the IRQ
* line being stuck active, and, since ISA irqs are edge triggered,
* no more IRQs will be seen.
*/
static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
{
spin_lock_irq(&i->lock);
if (!list_empty(i->head)) {
if (i->head == &up->list)
i->head = i->head->next;
list_del(&up->list);
} else {
BUG_ON(i->head != &up->list);
i->head = NULL;
}
spin_unlock_irq(&i->lock);
/* List empty so throw away the hash node */
if (i->head == NULL) {
hlist_del(&i->node);
kfree(i);
}
}
/*
* Either:
* - find the corresponding info in the hashtable and return it, or
* - allocate a new one, add it to the hashtable and return it.
*/
static struct irq_info *serial_get_or_create_irq_info(const struct uart_8250_port *up)
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/hashtable.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/ioport.h`, `linux/init.h`, `linux/console.h`, `linux/sysrq.h`.
- Detected declarations: `struct irq_info`, `function serial8250_interrupt`, `function serial_do_unlink`, `function serial_link_irq_chain`, `function scoped_guard`, `function serial_unlink_irq_chain`, `function hash_for_each_possible`, `function serial8250_timeout`, `function serial8250_backup_timeout`, `function univ8250_setup_timer`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.