drivers/tty/hvc/hvc_console.c
Source file repositories/reference/linux-study-clean/drivers/tty/hvc/hvc_console.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/hvc/hvc_console.c- Extension
.c- Size
- 25359 bytes
- Lines
- 1067
- 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/console.hlinux/cpumask.hlinux/init.hlinux/kbd_kern.hlinux/kernel.hlinux/kthread.hlinux/list.hlinux/major.hlinux/atomic.hlinux/sysrq.hlinux/tty.hlinux/tty_flip.hlinux/sched.hlinux/spinlock.hlinux/delay.hlinux/freezer.hlinux/slab.hlinux/serial_core.hlinux/uaccess.hhvc_console.h
Detected Declarations
function list_for_each_entryfunction __hvc_flushfunction hvc_console_flushfunction hvc_flushfunction hvc_console_setupfunction hvc_console_setupfunction hvc_instantiatefunction hvc_port_destructfunction hvc_check_consolefunction hvc_instantiatefunction hvc_kickfunction hvc_unthrottlefunction hvc_installfunction hvc_openfunction hvc_closefunction hvc_closefunction hvc_cleanupfunction hvc_hangupfunction hvc_pushfunction hvc_writefunction hvc_set_winszfunction hvc_write_roomfunction hvc_chars_in_bufferfunction driverfunction hvc_pollfunction __hvc_resizefunction hvc_pollfunction list_for_each_entryfunction hvc_tiocmgetfunction hvc_tiocmsetfunction hvc_poll_initfunction hvc_poll_get_charfunction hvc_poll_put_charfunction hvc_removefunction hvc_initexport hvc_instantiateexport hvc_kickexport hvc_pollexport __hvc_resizeexport hvc_allocexport hvc_remove
Annotated Snippet
if (hp->index == index) {
tty_port_get(&hp->port);
spin_unlock_irqrestore(&hp->lock, flags);
mutex_unlock(&hvc_structs_mutex);
return hp;
}
spin_unlock_irqrestore(&hp->lock, flags);
}
hp = NULL;
mutex_unlock(&hvc_structs_mutex);
return hp;
}
static int __hvc_flush(const struct hv_ops *ops, uint32_t vtermno, bool wait)
{
if (wait)
might_sleep();
if (ops->flush)
return ops->flush(vtermno, wait);
return 0;
}
static int hvc_console_flush(const struct hv_ops *ops, uint32_t vtermno)
{
return __hvc_flush(ops, vtermno, false);
}
/*
* Wait for the console to flush before writing more to it. This sleeps.
*/
static int hvc_flush(struct hvc_struct *hp)
{
return __hvc_flush(hp->ops, hp->vtermno, true);
}
/*
* Initial console vtermnos for console API usage prior to full console
* initialization. Any vty adapter outside this range will not have usable
* console interfaces but can still be used as a tty device. This has to be
* static because kmalloc will not work during early console init.
*/
static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
{[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
/*
* Console APIs, NOT TTY. These APIs are available immediately when
* hvc_console_setup() finds adapters.
*/
static void hvc_console_print(struct console *co, const char *b,
unsigned count)
{
char c[N_OUTBUF] __ALIGNED__;
unsigned i = 0, n = 0;
int r, donecr = 0, index = co->index;
/* Console access attempt outside of acceptable console range. */
if (index >= MAX_NR_HVC_CONSOLES)
return;
/* This console adapter was removed so it is not usable. */
if (vtermnos[index] == -1)
return;
while (count > 0 || i > 0) {
if (count > 0 && i < sizeof(c)) {
if (b[n] == '\n' && !donecr) {
c[i++] = '\r';
donecr = 1;
} else {
c[i++] = b[n++];
donecr = 0;
--count;
}
} else {
r = cons_ops[index]->put_chars(vtermnos[index], c, i);
if (r <= 0) {
/* throw away characters on error
* but spin in case of -EAGAIN */
if (r != -EAGAIN) {
i = 0;
} else {
hvc_console_flush(cons_ops[index],
vtermnos[index]);
}
} else {
i -= r;
Annotation
- Immediate include surface: `linux/console.h`, `linux/cpumask.h`, `linux/init.h`, `linux/kbd_kern.h`, `linux/kernel.h`, `linux/kthread.h`, `linux/list.h`, `linux/major.h`.
- Detected declarations: `function list_for_each_entry`, `function __hvc_flush`, `function hvc_console_flush`, `function hvc_flush`, `function hvc_console_setup`, `function hvc_console_setup`, `function hvc_instantiate`, `function hvc_port_destruct`, `function hvc_check_console`, `function hvc_instantiate`.
- 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.