drivers/tty/vt/consolemap.c
Source file repositories/reference/linux-study-clean/drivers/tty/vt/consolemap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/vt/consolemap.c- Extension
.c- Size
- 26450 bytes
- Lines
- 901
- 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.
- 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/bitfield.hlinux/bits.hlinux/module.hlinux/kd.hlinux/errno.hlinux/mm.hlinux/slab.hlinux/init.hlinux/tty.hlinux/uaccess.hlinux/console.hlinux/consolemap.hlinux/vt_kern.hlinux/string.h
Detected Declarations
struct uni_pagedictfunction set_inverse_translfunction set_inverse_trans_unicodefunction inverse_translatefunction update_user_mapsfunction con_set_trans_oldfunction con_get_trans_oldfunction con_set_trans_newfunction con_get_trans_newfunction con_release_unimapfunction con_free_unimapfunction con_unify_unimapfunction con_insert_unipairfunction con_allocate_newfunction con_do_clear_unimapfunction con_clear_unimapfunction con_set_unimapfunction con_set_default_unimapfunction con_copy_unimapfunction con_get_unimapfunction scoped_guardfunction conv_8bit_to_unifunction conv_uni_to_8bitfunction conv_uni_to_pcfunction console_map_initexport inverse_translateexport con_set_default_unimapexport con_copy_unimap
Annotated Snippet
struct uni_pagedict {
u16 **uni_pgdir[UNI_DIRS];
unsigned long refcount;
unsigned long sum;
unsigned char *inverse_translations[LAST_MAP + 1];
u16 *inverse_trans_unicode;
};
static struct uni_pagedict *dflt;
static void set_inverse_transl(struct vc_data *conp, struct uni_pagedict *dict,
enum translation_map m)
{
unsigned short *t = translations[m];
unsigned char *inv;
if (!dict)
return;
inv = dict->inverse_translations[m];
if (!inv) {
inv = dict->inverse_translations[m] = kmalloc(MAX_GLYPH,
GFP_KERNEL);
if (!inv)
return;
}
memset(inv, 0, MAX_GLYPH);
for (unsigned int ch = 0; ch < ARRAY_SIZE(translations[m]); ch++) {
int glyph = conv_uni_to_pc(conp, t[ch]);
if (glyph >= 0 && glyph < MAX_GLYPH && inv[glyph] < 32) {
/* prefer '-' above SHY etc. */
inv[glyph] = ch;
}
}
}
static void set_inverse_trans_unicode(struct uni_pagedict *dict)
{
unsigned int d, r, g;
u16 *inv;
if (!dict)
return;
inv = dict->inverse_trans_unicode;
if (!inv) {
inv = dict->inverse_trans_unicode = kmalloc_array(MAX_GLYPH,
sizeof(*inv), GFP_KERNEL);
if (!inv)
return;
}
memset(inv, 0, MAX_GLYPH * sizeof(*inv));
for (d = 0; d < UNI_DIRS; d++) {
u16 **dir = dict->uni_pgdir[d];
if (!dir)
continue;
for (r = 0; r < UNI_DIR_ROWS; r++) {
u16 *row = dir[r];
if (!row)
continue;
for (g = 0; g < UNI_ROW_GLYPHS; g++) {
u16 glyph = row[g];
if (glyph < MAX_GLYPH && inv[glyph] < 32)
inv[glyph] = UNI(d, r, g);
}
}
}
}
unsigned short *set_translate(enum translation_map m, struct vc_data *vc)
{
inv_translate[vc->vc_num] = m;
return translations[m];
}
/*
* Inverse translation is impossible for several reasons:
* 1. The font<->character maps are not 1-1.
* 2. The text may have been written while a different translation map
* was active.
* Still, it is now possible to a certain extent to cut and paste non-ASCII.
*/
u16 inverse_translate(const struct vc_data *conp, u16 glyph, bool use_unicode)
{
struct uni_pagedict *p;
enum translation_map m;
if (glyph >= MAX_GLYPH)
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bits.h`, `linux/module.h`, `linux/kd.h`, `linux/errno.h`, `linux/mm.h`, `linux/slab.h`, `linux/init.h`.
- Detected declarations: `struct uni_pagedict`, `function set_inverse_transl`, `function set_inverse_trans_unicode`, `function inverse_translate`, `function update_user_maps`, `function con_set_trans_old`, `function con_get_trans_old`, `function con_set_trans_new`, `function con_get_trans_new`, `function con_release_unimap`.
- 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.
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.