drivers/tty/vt/keyboard.c
Source file repositories/reference/linux-study-clean/drivers/tty/vt/keyboard.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/vt/keyboard.c- Extension
.c- Size
- 54047 bytes
- Lines
- 2283
- 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/consolemap.hlinux/init.hlinux/input.hlinux/jiffies.hlinux/kbd_diacr.hlinux/kbd_kern.hlinux/leds.hlinux/mm.hlinux/module.hlinux/nospec.hlinux/notifier.hlinux/reboot.hlinux/sched/debug.hlinux/sched/signal.hlinux/slab.hlinux/spinlock.hlinux/string.hlinux/tty_flip.hlinux/tty.hlinux/uaccess.hlinux/vt_kern.hasm/irq_regs.hasm/kbdleds.h
Detected Declarations
struct getset_keycode_datastruct kbd_led_triggerfunction Linusfunction register_keyboard_notifierfunction unregister_keyboard_notifierfunction getkeycode_helperfunction getkeycodefunction setkeycode_helperfunction setkeycodefunction kd_sound_helperfunction kd_nosoundfunction kd_mksoundfunction kbd_rate_helperfunction kbd_ratefunction put_queuefunction puts_queuefunction applkeyfunction to_utf8function put_queue_utf8function set_ledsfunction do_compute_shiftstatefunction for_each_set_bitfunction vt_set_leds_compute_shiftstatefunction handle_diacrfunction fn_enterfunction fn_caps_togglefunction fn_caps_onfunction fn_show_ptregsfunction fn_holdfunction fn_numfunction fn_bare_numfunction fn_lastconsfunction fn_dec_consolefunction fn_inc_consolefunction fn_send_intrfunction fn_scroll_forwfunction fn_scroll_backfunction fn_show_memfunction fn_show_statefunction fn_boot_itfunction fn_composefunction fn_spawn_confunction fn_SAKfunction fn_nullfunction k_specfunction k_lowercasefunction k_unicodefunction k_deadunicode
Annotated Snippet
struct getset_keycode_data {
struct input_keymap_entry ke;
int error;
};
static int getkeycode_helper(struct input_handle *handle, void *data)
{
struct getset_keycode_data *d = data;
d->error = input_get_keycode(handle->dev, &d->ke);
return d->error == 0; /* stop as soon as we successfully get one */
}
static int getkeycode(unsigned int scancode)
{
struct getset_keycode_data d = {
.ke = {
.flags = 0,
.len = sizeof(scancode),
.keycode = 0,
},
.error = -ENODEV,
};
memcpy(d.ke.scancode, &scancode, sizeof(scancode));
input_handler_for_each_handle(&kbd_handler, &d, getkeycode_helper);
return d.error ?: d.ke.keycode;
}
static int setkeycode_helper(struct input_handle *handle, void *data)
{
struct getset_keycode_data *d = data;
d->error = input_set_keycode(handle->dev, &d->ke);
return d->error == 0; /* stop as soon as we successfully set one */
}
static int setkeycode(unsigned int scancode, unsigned int keycode)
{
struct getset_keycode_data d = {
.ke = {
.flags = 0,
.len = sizeof(scancode),
.keycode = keycode,
},
.error = -ENODEV,
};
memcpy(d.ke.scancode, &scancode, sizeof(scancode));
input_handler_for_each_handle(&kbd_handler, &d, setkeycode_helper);
return d.error;
}
/*
* Making beeps and bells. Note that we prefer beeps to bells, but when
* shutting the sound off we do both.
*/
static int kd_sound_helper(struct input_handle *handle, void *data)
{
unsigned int *hz = data;
struct input_dev *dev = handle->dev;
if (test_bit(EV_SND, dev->evbit)) {
if (test_bit(SND_TONE, dev->sndbit)) {
input_inject_event(handle, EV_SND, SND_TONE, *hz);
if (*hz)
return 0;
}
if (test_bit(SND_BELL, dev->sndbit))
input_inject_event(handle, EV_SND, SND_BELL, *hz ? 1 : 0);
}
return 0;
}
static void kd_nosound(struct timer_list *unused)
{
static unsigned int zero;
input_handler_for_each_handle(&kbd_handler, &zero, kd_sound_helper);
}
static DEFINE_TIMER(kd_mksound_timer, kd_nosound);
Annotation
- Immediate include surface: `linux/consolemap.h`, `linux/init.h`, `linux/input.h`, `linux/jiffies.h`, `linux/kbd_diacr.h`, `linux/kbd_kern.h`, `linux/leds.h`, `linux/mm.h`.
- Detected declarations: `struct getset_keycode_data`, `struct kbd_led_trigger`, `function Linus`, `function register_keyboard_notifier`, `function unregister_keyboard_notifier`, `function getkeycode_helper`, `function getkeycode`, `function setkeycode_helper`, `function setkeycode`, `function kd_sound_helper`.
- 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.