drivers/tty/vt/vt.c
Source file repositories/reference/linux-study-clean/drivers/tty/vt/vt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/vt/vt.c- Extension
.c- Size
- 124231 bytes
- Lines
- 5112
- Domain
- Driver Families
- Bucket
- drivers/tty
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/types.hlinux/sched/signal.hlinux/tty.hlinux/tty_flip.hlinux/kernel.hlinux/string.hlinux/errno.hlinux/hex.hlinux/kd.hlinux/slab.hlinux/vmalloc.hlinux/major.hlinux/mm.hlinux/console.hlinux/init.hlinux/mutex.hlinux/vt_kern.hlinux/selection.hlinux/tiocl.hlinux/kbd_kern.hlinux/consolemap.hlinux/timer.hlinux/interrupt.hlinux/workqueue.hlinux/pm.hlinux/font.hlinux/bitops.hlinux/notifier.hlinux/device.hlinux/io.hlinux/uaccess.h
Detected Declarations
struct con_driverstruct rgbstruct vc_draw_regionenum CSI_Jenum CSI_right_square_bracketenum vc_ctl_statefunction vc_font_pitchfunction vc_font_sizefunction register_vt_notifierfunction unregister_vt_notifierfunction notify_writefunction notify_updatefunction con_is_fgfunction con_should_updatefunction con_putcfunction scrolldeltafunction schedule_console_callbackfunction vc_uniscr_freefunction vc_uniscr_setfunction vc_uniscr_putcfunction vc_uniscr_insertfunction vc_uniscr_deletefunction vc_uniscr_clear_linefunction vc_uniscr_clear_linesfunction juggle_arrayfunction vc_uniscr_scrollfunction vc_uniscr_getcfunction vc_uniscr_copy_areafunction vcs_readfunction vcs_readfunction con_scrollfunction do_update_regionfunction update_regionfunction build_attrfunction update_attrfunction invert_screenfunction complement_posfunction insert_charfunction delete_charfunction add_softcursorfunction hide_softcursorfunction hide_cursorfunction set_cursorfunction set_originfunction save_screenfunction flush_scrollbackfunction clear_buffer_attributesfunction redraw_screen
Annotated Snippet
int __init vty_init(const struct file_operations *console_fops)
{
cdev_init(&vc0_cdev, console_fops);
if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||
register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
panic("Couldn't register /dev/tty0 driver\n");
tty0dev = device_create_with_groups(&tty_class, NULL,
MKDEV(TTY_MAJOR, 0), NULL,
vt_dev_groups, "tty0");
if (IS_ERR(tty0dev))
tty0dev = NULL;
vcs_init();
console_driver = tty_alloc_driver(MAX_NR_CONSOLES, TTY_DRIVER_REAL_RAW |
TTY_DRIVER_RESET_TERMIOS);
if (IS_ERR(console_driver))
panic("Couldn't allocate console driver\n");
console_driver->name = "tty";
console_driver->name_base = 1;
console_driver->major = TTY_MAJOR;
console_driver->minor_start = 1;
console_driver->type = TTY_DRIVER_TYPE_CONSOLE;
console_driver->init_termios = tty_std_termios;
if (default_utf8)
console_driver->init_termios.c_iflag |= IUTF8;
tty_set_operations(console_driver, &con_ops);
if (tty_register_driver(console_driver))
panic("Couldn't register console driver\n");
kbd_init();
console_map_init();
return 0;
}
static const struct class vtconsole_class = {
.name = "vtconsole",
};
static int do_bind_con_driver(const struct consw *csw, int first, int last,
int deflt)
{
struct module *owner = csw->owner;
const char *desc = NULL;
struct con_driver *con_driver;
int i, j = -1, k = -1, retval = -ENODEV;
if (!try_module_get(owner))
return -ENODEV;
WARN_CONSOLE_UNLOCKED();
/* check if driver is registered */
for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
con_driver = ®istered_con_driver[i];
if (con_driver->con == csw) {
desc = con_driver->desc;
retval = 0;
break;
}
}
if (retval)
goto err;
if (!(con_driver->flag & CON_DRIVER_FLAG_INIT)) {
csw->con_startup();
con_driver->flag |= CON_DRIVER_FLAG_INIT;
}
if (deflt) {
if (conswitchp)
module_put(conswitchp->owner);
__module_get(owner);
conswitchp = csw;
}
first = max(first, con_driver->first);
last = min(last, con_driver->last);
for (i = first; i <= last; i++) {
int old_was_color;
struct vc_data *vc = vc_cons[i].d;
if (con_driver_map[i])
module_put(con_driver_map[i]->owner);
__module_get(owner);
con_driver_map[i] = csw;
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/sched/signal.h`, `linux/tty.h`, `linux/tty_flip.h`, `linux/kernel.h`, `linux/string.h`, `linux/errno.h`.
- Detected declarations: `struct con_driver`, `struct rgb`, `struct vc_draw_region`, `enum CSI_J`, `enum CSI_right_square_bracket`, `enum vc_ctl_state`, `function vc_font_pitch`, `function vc_font_size`, `function register_vt_notifier`, `function unregister_vt_notifier`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: pattern 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.