18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * consolemap.c 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Mapping from internal code (such as Latin-1 or Unicode or IBM PC code) 68c2ecf20Sopenharmony_ci * to font positions. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * aeb, 950210 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Support for multiple unimaps by Jakub Jelinek <jj@ultra.linux.cz>, July 1998 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * Fix bug in inverse translation. Stanislav Voronyi <stas@cnti.uanet.kharkov.ua>, Dec 1998 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * In order to prevent the following circular lock dependency: 158c2ecf20Sopenharmony_ci * &mm->mmap_lock --> cpu_hotplug.lock --> console_lock --> &mm->mmap_lock 168c2ecf20Sopenharmony_ci * 178c2ecf20Sopenharmony_ci * We cannot allow page fault to happen while holding the console_lock. 188c2ecf20Sopenharmony_ci * Therefore, all the userspace copy operations have to be done outside 198c2ecf20Sopenharmony_ci * the console_lock critical sections. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * As all the affected functions are all called directly from vt_ioctl(), we 228c2ecf20Sopenharmony_ci * can allocate some small buffers directly on stack without worrying about 238c2ecf20Sopenharmony_ci * stack overflow. 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#include <linux/module.h> 278c2ecf20Sopenharmony_ci#include <linux/kd.h> 288c2ecf20Sopenharmony_ci#include <linux/errno.h> 298c2ecf20Sopenharmony_ci#include <linux/mm.h> 308c2ecf20Sopenharmony_ci#include <linux/slab.h> 318c2ecf20Sopenharmony_ci#include <linux/init.h> 328c2ecf20Sopenharmony_ci#include <linux/tty.h> 338c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 348c2ecf20Sopenharmony_ci#include <linux/console.h> 358c2ecf20Sopenharmony_ci#include <linux/consolemap.h> 368c2ecf20Sopenharmony_ci#include <linux/vt_kern.h> 378c2ecf20Sopenharmony_ci#include <linux/string.h> 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic unsigned short translations[][256] = { 408c2ecf20Sopenharmony_ci /* 8-bit Latin-1 mapped to Unicode -- trivial mapping */ 418c2ecf20Sopenharmony_ci { 428c2ecf20Sopenharmony_ci 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 438c2ecf20Sopenharmony_ci 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 448c2ecf20Sopenharmony_ci 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 458c2ecf20Sopenharmony_ci 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, 468c2ecf20Sopenharmony_ci 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 478c2ecf20Sopenharmony_ci 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 488c2ecf20Sopenharmony_ci 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 498c2ecf20Sopenharmony_ci 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, 508c2ecf20Sopenharmony_ci 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 518c2ecf20Sopenharmony_ci 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, 528c2ecf20Sopenharmony_ci 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 538c2ecf20Sopenharmony_ci 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 548c2ecf20Sopenharmony_ci 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 558c2ecf20Sopenharmony_ci 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 568c2ecf20Sopenharmony_ci 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 578c2ecf20Sopenharmony_ci 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, 588c2ecf20Sopenharmony_ci 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 598c2ecf20Sopenharmony_ci 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, 608c2ecf20Sopenharmony_ci 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 618c2ecf20Sopenharmony_ci 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, 628c2ecf20Sopenharmony_ci 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 638c2ecf20Sopenharmony_ci 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, 648c2ecf20Sopenharmony_ci 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 658c2ecf20Sopenharmony_ci 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, 668c2ecf20Sopenharmony_ci 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 678c2ecf20Sopenharmony_ci 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, 688c2ecf20Sopenharmony_ci 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 698c2ecf20Sopenharmony_ci 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, 708c2ecf20Sopenharmony_ci 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 718c2ecf20Sopenharmony_ci 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 728c2ecf20Sopenharmony_ci 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 738c2ecf20Sopenharmony_ci 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff 748c2ecf20Sopenharmony_ci }, 758c2ecf20Sopenharmony_ci /* VT100 graphics mapped to Unicode */ 768c2ecf20Sopenharmony_ci { 778c2ecf20Sopenharmony_ci 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 788c2ecf20Sopenharmony_ci 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 798c2ecf20Sopenharmony_ci 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 808c2ecf20Sopenharmony_ci 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, 818c2ecf20Sopenharmony_ci 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 828c2ecf20Sopenharmony_ci 0x0028, 0x0029, 0x002a, 0x2192, 0x2190, 0x2191, 0x2193, 0x002f, 838c2ecf20Sopenharmony_ci 0x2588, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 848c2ecf20Sopenharmony_ci 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, 858c2ecf20Sopenharmony_ci 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 868c2ecf20Sopenharmony_ci 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, 878c2ecf20Sopenharmony_ci 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 888c2ecf20Sopenharmony_ci 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x00a0, 898c2ecf20Sopenharmony_ci 0x25c6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, 908c2ecf20Sopenharmony_ci 0x2591, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x23ba, 918c2ecf20Sopenharmony_ci 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534, 0x252c, 928c2ecf20Sopenharmony_ci 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7, 0x007f, 938c2ecf20Sopenharmony_ci 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 948c2ecf20Sopenharmony_ci 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, 958c2ecf20Sopenharmony_ci 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 968c2ecf20Sopenharmony_ci 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, 978c2ecf20Sopenharmony_ci 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 988c2ecf20Sopenharmony_ci 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, 998c2ecf20Sopenharmony_ci 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 1008c2ecf20Sopenharmony_ci 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, 1018c2ecf20Sopenharmony_ci 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 1028c2ecf20Sopenharmony_ci 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, 1038c2ecf20Sopenharmony_ci 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 1048c2ecf20Sopenharmony_ci 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, 1058c2ecf20Sopenharmony_ci 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 1068c2ecf20Sopenharmony_ci 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 1078c2ecf20Sopenharmony_ci 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 1088c2ecf20Sopenharmony_ci 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff 1098c2ecf20Sopenharmony_ci }, 1108c2ecf20Sopenharmony_ci /* IBM Codepage 437 mapped to Unicode */ 1118c2ecf20Sopenharmony_ci { 1128c2ecf20Sopenharmony_ci 0x0000, 0x263a, 0x263b, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022, 1138c2ecf20Sopenharmony_ci 0x25d8, 0x25cb, 0x25d9, 0x2642, 0x2640, 0x266a, 0x266b, 0x263c, 1148c2ecf20Sopenharmony_ci 0x25b6, 0x25c0, 0x2195, 0x203c, 0x00b6, 0x00a7, 0x25ac, 0x21a8, 1158c2ecf20Sopenharmony_ci 0x2191, 0x2193, 0x2192, 0x2190, 0x221f, 0x2194, 0x25b2, 0x25bc, 1168c2ecf20Sopenharmony_ci 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 1178c2ecf20Sopenharmony_ci 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 1188c2ecf20Sopenharmony_ci 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 1198c2ecf20Sopenharmony_ci 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, 1208c2ecf20Sopenharmony_ci 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 1218c2ecf20Sopenharmony_ci 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, 1228c2ecf20Sopenharmony_ci 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 1238c2ecf20Sopenharmony_ci 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 1248c2ecf20Sopenharmony_ci 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 1258c2ecf20Sopenharmony_ci 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 1268c2ecf20Sopenharmony_ci 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 1278c2ecf20Sopenharmony_ci 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x2302, 1288c2ecf20Sopenharmony_ci 0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, 1298c2ecf20Sopenharmony_ci 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5, 1308c2ecf20Sopenharmony_ci 0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9, 1318c2ecf20Sopenharmony_ci 0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192, 1328c2ecf20Sopenharmony_ci 0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba, 1338c2ecf20Sopenharmony_ci 0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb, 1348c2ecf20Sopenharmony_ci 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 1358c2ecf20Sopenharmony_ci 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, 1368c2ecf20Sopenharmony_ci 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 1378c2ecf20Sopenharmony_ci 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, 1388c2ecf20Sopenharmony_ci 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 1398c2ecf20Sopenharmony_ci 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, 1408c2ecf20Sopenharmony_ci 0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, 1418c2ecf20Sopenharmony_ci 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, 1428c2ecf20Sopenharmony_ci 0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, 1438c2ecf20Sopenharmony_ci 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0 1448c2ecf20Sopenharmony_ci }, 1458c2ecf20Sopenharmony_ci /* User mapping -- default to codes for direct font mapping */ 1468c2ecf20Sopenharmony_ci { 1478c2ecf20Sopenharmony_ci 0xf000, 0xf001, 0xf002, 0xf003, 0xf004, 0xf005, 0xf006, 0xf007, 1488c2ecf20Sopenharmony_ci 0xf008, 0xf009, 0xf00a, 0xf00b, 0xf00c, 0xf00d, 0xf00e, 0xf00f, 1498c2ecf20Sopenharmony_ci 0xf010, 0xf011, 0xf012, 0xf013, 0xf014, 0xf015, 0xf016, 0xf017, 1508c2ecf20Sopenharmony_ci 0xf018, 0xf019, 0xf01a, 0xf01b, 0xf01c, 0xf01d, 0xf01e, 0xf01f, 1518c2ecf20Sopenharmony_ci 0xf020, 0xf021, 0xf022, 0xf023, 0xf024, 0xf025, 0xf026, 0xf027, 1528c2ecf20Sopenharmony_ci 0xf028, 0xf029, 0xf02a, 0xf02b, 0xf02c, 0xf02d, 0xf02e, 0xf02f, 1538c2ecf20Sopenharmony_ci 0xf030, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036, 0xf037, 1548c2ecf20Sopenharmony_ci 0xf038, 0xf039, 0xf03a, 0xf03b, 0xf03c, 0xf03d, 0xf03e, 0xf03f, 1558c2ecf20Sopenharmony_ci 0xf040, 0xf041, 0xf042, 0xf043, 0xf044, 0xf045, 0xf046, 0xf047, 1568c2ecf20Sopenharmony_ci 0xf048, 0xf049, 0xf04a, 0xf04b, 0xf04c, 0xf04d, 0xf04e, 0xf04f, 1578c2ecf20Sopenharmony_ci 0xf050, 0xf051, 0xf052, 0xf053, 0xf054, 0xf055, 0xf056, 0xf057, 1588c2ecf20Sopenharmony_ci 0xf058, 0xf059, 0xf05a, 0xf05b, 0xf05c, 0xf05d, 0xf05e, 0xf05f, 1598c2ecf20Sopenharmony_ci 0xf060, 0xf061, 0xf062, 0xf063, 0xf064, 0xf065, 0xf066, 0xf067, 1608c2ecf20Sopenharmony_ci 0xf068, 0xf069, 0xf06a, 0xf06b, 0xf06c, 0xf06d, 0xf06e, 0xf06f, 1618c2ecf20Sopenharmony_ci 0xf070, 0xf071, 0xf072, 0xf073, 0xf074, 0xf075, 0xf076, 0xf077, 1628c2ecf20Sopenharmony_ci 0xf078, 0xf079, 0xf07a, 0xf07b, 0xf07c, 0xf07d, 0xf07e, 0xf07f, 1638c2ecf20Sopenharmony_ci 0xf080, 0xf081, 0xf082, 0xf083, 0xf084, 0xf085, 0xf086, 0xf087, 1648c2ecf20Sopenharmony_ci 0xf088, 0xf089, 0xf08a, 0xf08b, 0xf08c, 0xf08d, 0xf08e, 0xf08f, 1658c2ecf20Sopenharmony_ci 0xf090, 0xf091, 0xf092, 0xf093, 0xf094, 0xf095, 0xf096, 0xf097, 1668c2ecf20Sopenharmony_ci 0xf098, 0xf099, 0xf09a, 0xf09b, 0xf09c, 0xf09d, 0xf09e, 0xf09f, 1678c2ecf20Sopenharmony_ci 0xf0a0, 0xf0a1, 0xf0a2, 0xf0a3, 0xf0a4, 0xf0a5, 0xf0a6, 0xf0a7, 1688c2ecf20Sopenharmony_ci 0xf0a8, 0xf0a9, 0xf0aa, 0xf0ab, 0xf0ac, 0xf0ad, 0xf0ae, 0xf0af, 1698c2ecf20Sopenharmony_ci 0xf0b0, 0xf0b1, 0xf0b2, 0xf0b3, 0xf0b4, 0xf0b5, 0xf0b6, 0xf0b7, 1708c2ecf20Sopenharmony_ci 0xf0b8, 0xf0b9, 0xf0ba, 0xf0bb, 0xf0bc, 0xf0bd, 0xf0be, 0xf0bf, 1718c2ecf20Sopenharmony_ci 0xf0c0, 0xf0c1, 0xf0c2, 0xf0c3, 0xf0c4, 0xf0c5, 0xf0c6, 0xf0c7, 1728c2ecf20Sopenharmony_ci 0xf0c8, 0xf0c9, 0xf0ca, 0xf0cb, 0xf0cc, 0xf0cd, 0xf0ce, 0xf0cf, 1738c2ecf20Sopenharmony_ci 0xf0d0, 0xf0d1, 0xf0d2, 0xf0d3, 0xf0d4, 0xf0d5, 0xf0d6, 0xf0d7, 1748c2ecf20Sopenharmony_ci 0xf0d8, 0xf0d9, 0xf0da, 0xf0db, 0xf0dc, 0xf0dd, 0xf0de, 0xf0df, 1758c2ecf20Sopenharmony_ci 0xf0e0, 0xf0e1, 0xf0e2, 0xf0e3, 0xf0e4, 0xf0e5, 0xf0e6, 0xf0e7, 1768c2ecf20Sopenharmony_ci 0xf0e8, 0xf0e9, 0xf0ea, 0xf0eb, 0xf0ec, 0xf0ed, 0xf0ee, 0xf0ef, 1778c2ecf20Sopenharmony_ci 0xf0f0, 0xf0f1, 0xf0f2, 0xf0f3, 0xf0f4, 0xf0f5, 0xf0f6, 0xf0f7, 1788c2ecf20Sopenharmony_ci 0xf0f8, 0xf0f9, 0xf0fa, 0xf0fb, 0xf0fc, 0xf0fd, 0xf0fe, 0xf0ff 1798c2ecf20Sopenharmony_ci } 1808c2ecf20Sopenharmony_ci}; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci/* The standard kernel character-to-font mappings are not invertible 1838c2ecf20Sopenharmony_ci -- this is just a best effort. */ 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci#define MAX_GLYPH 512 /* Max possible glyph value */ 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistatic int inv_translate[MAX_NR_CONSOLES]; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_cistruct uni_pagedir { 1908c2ecf20Sopenharmony_ci u16 **uni_pgdir[32]; 1918c2ecf20Sopenharmony_ci unsigned long refcount; 1928c2ecf20Sopenharmony_ci unsigned long sum; 1938c2ecf20Sopenharmony_ci unsigned char *inverse_translations[4]; 1948c2ecf20Sopenharmony_ci u16 *inverse_trans_unicode; 1958c2ecf20Sopenharmony_ci}; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_cistatic struct uni_pagedir *dflt; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_cistatic void set_inverse_transl(struct vc_data *conp, struct uni_pagedir *p, int i) 2008c2ecf20Sopenharmony_ci{ 2018c2ecf20Sopenharmony_ci int j, glyph; 2028c2ecf20Sopenharmony_ci unsigned short *t = translations[i]; 2038c2ecf20Sopenharmony_ci unsigned char *q; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci if (!p) return; 2068c2ecf20Sopenharmony_ci q = p->inverse_translations[i]; 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci if (!q) { 2098c2ecf20Sopenharmony_ci q = p->inverse_translations[i] = kmalloc(MAX_GLYPH, GFP_KERNEL); 2108c2ecf20Sopenharmony_ci if (!q) return; 2118c2ecf20Sopenharmony_ci } 2128c2ecf20Sopenharmony_ci memset(q, 0, MAX_GLYPH); 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci for (j = 0; j < E_TABSZ; j++) { 2158c2ecf20Sopenharmony_ci glyph = conv_uni_to_pc(conp, t[j]); 2168c2ecf20Sopenharmony_ci if (glyph >= 0 && glyph < MAX_GLYPH && q[glyph] < 32) { 2178c2ecf20Sopenharmony_ci /* prefer '-' above SHY etc. */ 2188c2ecf20Sopenharmony_ci q[glyph] = j; 2198c2ecf20Sopenharmony_ci } 2208c2ecf20Sopenharmony_ci } 2218c2ecf20Sopenharmony_ci} 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_cistatic void set_inverse_trans_unicode(struct vc_data *conp, 2248c2ecf20Sopenharmony_ci struct uni_pagedir *p) 2258c2ecf20Sopenharmony_ci{ 2268c2ecf20Sopenharmony_ci int i, j, k, glyph; 2278c2ecf20Sopenharmony_ci u16 **p1, *p2; 2288c2ecf20Sopenharmony_ci u16 *q; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci if (!p) return; 2318c2ecf20Sopenharmony_ci q = p->inverse_trans_unicode; 2328c2ecf20Sopenharmony_ci if (!q) { 2338c2ecf20Sopenharmony_ci q = p->inverse_trans_unicode = 2348c2ecf20Sopenharmony_ci kmalloc_array(MAX_GLYPH, sizeof(u16), GFP_KERNEL); 2358c2ecf20Sopenharmony_ci if (!q) 2368c2ecf20Sopenharmony_ci return; 2378c2ecf20Sopenharmony_ci } 2388c2ecf20Sopenharmony_ci memset(q, 0, MAX_GLYPH * sizeof(u16)); 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci for (i = 0; i < 32; i++) { 2418c2ecf20Sopenharmony_ci p1 = p->uni_pgdir[i]; 2428c2ecf20Sopenharmony_ci if (!p1) 2438c2ecf20Sopenharmony_ci continue; 2448c2ecf20Sopenharmony_ci for (j = 0; j < 32; j++) { 2458c2ecf20Sopenharmony_ci p2 = p1[j]; 2468c2ecf20Sopenharmony_ci if (!p2) 2478c2ecf20Sopenharmony_ci continue; 2488c2ecf20Sopenharmony_ci for (k = 0; k < 64; k++) { 2498c2ecf20Sopenharmony_ci glyph = p2[k]; 2508c2ecf20Sopenharmony_ci if (glyph >= 0 && glyph < MAX_GLYPH 2518c2ecf20Sopenharmony_ci && q[glyph] < 32) 2528c2ecf20Sopenharmony_ci q[glyph] = (i << 11) + (j << 6) + k; 2538c2ecf20Sopenharmony_ci } 2548c2ecf20Sopenharmony_ci } 2558c2ecf20Sopenharmony_ci } 2568c2ecf20Sopenharmony_ci} 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ciunsigned short *set_translate(int m, struct vc_data *vc) 2598c2ecf20Sopenharmony_ci{ 2608c2ecf20Sopenharmony_ci inv_translate[vc->vc_num] = m; 2618c2ecf20Sopenharmony_ci return translations[m]; 2628c2ecf20Sopenharmony_ci} 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci/* 2658c2ecf20Sopenharmony_ci * Inverse translation is impossible for several reasons: 2668c2ecf20Sopenharmony_ci * 1. The font<->character maps are not 1-1. 2678c2ecf20Sopenharmony_ci * 2. The text may have been written while a different translation map 2688c2ecf20Sopenharmony_ci * was active. 2698c2ecf20Sopenharmony_ci * Still, it is now possible to a certain extent to cut and paste non-ASCII. 2708c2ecf20Sopenharmony_ci */ 2718c2ecf20Sopenharmony_ciu16 inverse_translate(const struct vc_data *conp, int glyph, int use_unicode) 2728c2ecf20Sopenharmony_ci{ 2738c2ecf20Sopenharmony_ci struct uni_pagedir *p; 2748c2ecf20Sopenharmony_ci int m; 2758c2ecf20Sopenharmony_ci if (glyph < 0 || glyph >= MAX_GLYPH) 2768c2ecf20Sopenharmony_ci return 0; 2778c2ecf20Sopenharmony_ci else { 2788c2ecf20Sopenharmony_ci p = *conp->vc_uni_pagedir_loc; 2798c2ecf20Sopenharmony_ci if (!p) 2808c2ecf20Sopenharmony_ci return glyph; 2818c2ecf20Sopenharmony_ci else if (use_unicode) { 2828c2ecf20Sopenharmony_ci if (!p->inverse_trans_unicode) 2838c2ecf20Sopenharmony_ci return glyph; 2848c2ecf20Sopenharmony_ci else 2858c2ecf20Sopenharmony_ci return p->inverse_trans_unicode[glyph]; 2868c2ecf20Sopenharmony_ci } else { 2878c2ecf20Sopenharmony_ci m = inv_translate[conp->vc_num]; 2888c2ecf20Sopenharmony_ci if (!p->inverse_translations[m]) 2898c2ecf20Sopenharmony_ci return glyph; 2908c2ecf20Sopenharmony_ci else 2918c2ecf20Sopenharmony_ci return p->inverse_translations[m][glyph]; 2928c2ecf20Sopenharmony_ci } 2938c2ecf20Sopenharmony_ci } 2948c2ecf20Sopenharmony_ci} 2958c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(inverse_translate); 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_cistatic void update_user_maps(void) 2988c2ecf20Sopenharmony_ci{ 2998c2ecf20Sopenharmony_ci int i; 3008c2ecf20Sopenharmony_ci struct uni_pagedir *p, *q = NULL; 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci for (i = 0; i < MAX_NR_CONSOLES; i++) { 3038c2ecf20Sopenharmony_ci if (!vc_cons_allocated(i)) 3048c2ecf20Sopenharmony_ci continue; 3058c2ecf20Sopenharmony_ci p = *vc_cons[i].d->vc_uni_pagedir_loc; 3068c2ecf20Sopenharmony_ci if (p && p != q) { 3078c2ecf20Sopenharmony_ci set_inverse_transl(vc_cons[i].d, p, USER_MAP); 3088c2ecf20Sopenharmony_ci set_inverse_trans_unicode(vc_cons[i].d, p); 3098c2ecf20Sopenharmony_ci q = p; 3108c2ecf20Sopenharmony_ci } 3118c2ecf20Sopenharmony_ci } 3128c2ecf20Sopenharmony_ci} 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci/* 3158c2ecf20Sopenharmony_ci * Load customizable translation table 3168c2ecf20Sopenharmony_ci * arg points to a 256 byte translation table. 3178c2ecf20Sopenharmony_ci * 3188c2ecf20Sopenharmony_ci * The "old" variants are for translation directly to font (using the 3198c2ecf20Sopenharmony_ci * 0xf000-0xf0ff "transparent" Unicodes) whereas the "new" variants set 3208c2ecf20Sopenharmony_ci * Unicodes explicitly. 3218c2ecf20Sopenharmony_ci */ 3228c2ecf20Sopenharmony_ciint con_set_trans_old(unsigned char __user * arg) 3238c2ecf20Sopenharmony_ci{ 3248c2ecf20Sopenharmony_ci int i; 3258c2ecf20Sopenharmony_ci unsigned short inbuf[E_TABSZ]; 3268c2ecf20Sopenharmony_ci unsigned char ubuf[E_TABSZ]; 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci if (copy_from_user(ubuf, arg, E_TABSZ)) 3298c2ecf20Sopenharmony_ci return -EFAULT; 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci for (i = 0; i < E_TABSZ ; i++) 3328c2ecf20Sopenharmony_ci inbuf[i] = UNI_DIRECT_BASE | ubuf[i]; 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci console_lock(); 3358c2ecf20Sopenharmony_ci memcpy(translations[USER_MAP], inbuf, sizeof(inbuf)); 3368c2ecf20Sopenharmony_ci update_user_maps(); 3378c2ecf20Sopenharmony_ci console_unlock(); 3388c2ecf20Sopenharmony_ci return 0; 3398c2ecf20Sopenharmony_ci} 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ciint con_get_trans_old(unsigned char __user * arg) 3428c2ecf20Sopenharmony_ci{ 3438c2ecf20Sopenharmony_ci int i, ch; 3448c2ecf20Sopenharmony_ci unsigned short *p = translations[USER_MAP]; 3458c2ecf20Sopenharmony_ci unsigned char outbuf[E_TABSZ]; 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci console_lock(); 3488c2ecf20Sopenharmony_ci for (i = 0; i < E_TABSZ ; i++) 3498c2ecf20Sopenharmony_ci { 3508c2ecf20Sopenharmony_ci ch = conv_uni_to_pc(vc_cons[fg_console].d, p[i]); 3518c2ecf20Sopenharmony_ci outbuf[i] = (ch & ~0xff) ? 0 : ch; 3528c2ecf20Sopenharmony_ci } 3538c2ecf20Sopenharmony_ci console_unlock(); 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci return copy_to_user(arg, outbuf, sizeof(outbuf)) ? -EFAULT : 0; 3568c2ecf20Sopenharmony_ci} 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ciint con_set_trans_new(ushort __user * arg) 3598c2ecf20Sopenharmony_ci{ 3608c2ecf20Sopenharmony_ci unsigned short inbuf[E_TABSZ]; 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci if (copy_from_user(inbuf, arg, sizeof(inbuf))) 3638c2ecf20Sopenharmony_ci return -EFAULT; 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci console_lock(); 3668c2ecf20Sopenharmony_ci memcpy(translations[USER_MAP], inbuf, sizeof(inbuf)); 3678c2ecf20Sopenharmony_ci update_user_maps(); 3688c2ecf20Sopenharmony_ci console_unlock(); 3698c2ecf20Sopenharmony_ci return 0; 3708c2ecf20Sopenharmony_ci} 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ciint con_get_trans_new(ushort __user * arg) 3738c2ecf20Sopenharmony_ci{ 3748c2ecf20Sopenharmony_ci unsigned short outbuf[E_TABSZ]; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci console_lock(); 3778c2ecf20Sopenharmony_ci memcpy(outbuf, translations[USER_MAP], sizeof(outbuf)); 3788c2ecf20Sopenharmony_ci console_unlock(); 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci return copy_to_user(arg, outbuf, sizeof(outbuf)) ? -EFAULT : 0; 3818c2ecf20Sopenharmony_ci} 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci/* 3848c2ecf20Sopenharmony_ci * Unicode -> current font conversion 3858c2ecf20Sopenharmony_ci * 3868c2ecf20Sopenharmony_ci * A font has at most 512 chars, usually 256. 3878c2ecf20Sopenharmony_ci * But one font position may represent several Unicode chars. 3888c2ecf20Sopenharmony_ci * A hashtable is somewhat of a pain to deal with, so use a 3898c2ecf20Sopenharmony_ci * "paged table" instead. Simulation has shown the memory cost of 3908c2ecf20Sopenharmony_ci * this 3-level paged table scheme to be comparable to a hash table. 3918c2ecf20Sopenharmony_ci */ 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ciextern u8 dfont_unicount[]; /* Defined in console_defmap.c */ 3948c2ecf20Sopenharmony_ciextern u16 dfont_unitable[]; 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_cistatic void con_release_unimap(struct uni_pagedir *p) 3978c2ecf20Sopenharmony_ci{ 3988c2ecf20Sopenharmony_ci u16 **p1; 3998c2ecf20Sopenharmony_ci int i, j; 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci if (p == dflt) dflt = NULL; 4028c2ecf20Sopenharmony_ci for (i = 0; i < 32; i++) { 4038c2ecf20Sopenharmony_ci p1 = p->uni_pgdir[i]; 4048c2ecf20Sopenharmony_ci if (p1 != NULL) { 4058c2ecf20Sopenharmony_ci for (j = 0; j < 32; j++) 4068c2ecf20Sopenharmony_ci kfree(p1[j]); 4078c2ecf20Sopenharmony_ci kfree(p1); 4088c2ecf20Sopenharmony_ci } 4098c2ecf20Sopenharmony_ci p->uni_pgdir[i] = NULL; 4108c2ecf20Sopenharmony_ci } 4118c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) { 4128c2ecf20Sopenharmony_ci kfree(p->inverse_translations[i]); 4138c2ecf20Sopenharmony_ci p->inverse_translations[i] = NULL; 4148c2ecf20Sopenharmony_ci } 4158c2ecf20Sopenharmony_ci kfree(p->inverse_trans_unicode); 4168c2ecf20Sopenharmony_ci p->inverse_trans_unicode = NULL; 4178c2ecf20Sopenharmony_ci} 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci/* Caller must hold the console lock */ 4208c2ecf20Sopenharmony_civoid con_free_unimap(struct vc_data *vc) 4218c2ecf20Sopenharmony_ci{ 4228c2ecf20Sopenharmony_ci struct uni_pagedir *p; 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci p = *vc->vc_uni_pagedir_loc; 4258c2ecf20Sopenharmony_ci if (!p) 4268c2ecf20Sopenharmony_ci return; 4278c2ecf20Sopenharmony_ci *vc->vc_uni_pagedir_loc = NULL; 4288c2ecf20Sopenharmony_ci if (--p->refcount) 4298c2ecf20Sopenharmony_ci return; 4308c2ecf20Sopenharmony_ci con_release_unimap(p); 4318c2ecf20Sopenharmony_ci kfree(p); 4328c2ecf20Sopenharmony_ci} 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_cistatic int con_unify_unimap(struct vc_data *conp, struct uni_pagedir *p) 4358c2ecf20Sopenharmony_ci{ 4368c2ecf20Sopenharmony_ci int i, j, k; 4378c2ecf20Sopenharmony_ci struct uni_pagedir *q; 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci for (i = 0; i < MAX_NR_CONSOLES; i++) { 4408c2ecf20Sopenharmony_ci if (!vc_cons_allocated(i)) 4418c2ecf20Sopenharmony_ci continue; 4428c2ecf20Sopenharmony_ci q = *vc_cons[i].d->vc_uni_pagedir_loc; 4438c2ecf20Sopenharmony_ci if (!q || q == p || q->sum != p->sum) 4448c2ecf20Sopenharmony_ci continue; 4458c2ecf20Sopenharmony_ci for (j = 0; j < 32; j++) { 4468c2ecf20Sopenharmony_ci u16 **p1, **q1; 4478c2ecf20Sopenharmony_ci p1 = p->uni_pgdir[j]; q1 = q->uni_pgdir[j]; 4488c2ecf20Sopenharmony_ci if (!p1 && !q1) 4498c2ecf20Sopenharmony_ci continue; 4508c2ecf20Sopenharmony_ci if (!p1 || !q1) 4518c2ecf20Sopenharmony_ci break; 4528c2ecf20Sopenharmony_ci for (k = 0; k < 32; k++) { 4538c2ecf20Sopenharmony_ci if (!p1[k] && !q1[k]) 4548c2ecf20Sopenharmony_ci continue; 4558c2ecf20Sopenharmony_ci if (!p1[k] || !q1[k]) 4568c2ecf20Sopenharmony_ci break; 4578c2ecf20Sopenharmony_ci if (memcmp(p1[k], q1[k], 64*sizeof(u16))) 4588c2ecf20Sopenharmony_ci break; 4598c2ecf20Sopenharmony_ci } 4608c2ecf20Sopenharmony_ci if (k < 32) 4618c2ecf20Sopenharmony_ci break; 4628c2ecf20Sopenharmony_ci } 4638c2ecf20Sopenharmony_ci if (j == 32) { 4648c2ecf20Sopenharmony_ci q->refcount++; 4658c2ecf20Sopenharmony_ci *conp->vc_uni_pagedir_loc = q; 4668c2ecf20Sopenharmony_ci con_release_unimap(p); 4678c2ecf20Sopenharmony_ci kfree(p); 4688c2ecf20Sopenharmony_ci return 1; 4698c2ecf20Sopenharmony_ci } 4708c2ecf20Sopenharmony_ci } 4718c2ecf20Sopenharmony_ci return 0; 4728c2ecf20Sopenharmony_ci} 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_cistatic int 4758c2ecf20Sopenharmony_cicon_insert_unipair(struct uni_pagedir *p, u_short unicode, u_short fontpos) 4768c2ecf20Sopenharmony_ci{ 4778c2ecf20Sopenharmony_ci int i, n; 4788c2ecf20Sopenharmony_ci u16 **p1, *p2; 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci p1 = p->uni_pgdir[n = unicode >> 11]; 4818c2ecf20Sopenharmony_ci if (!p1) { 4828c2ecf20Sopenharmony_ci p1 = p->uni_pgdir[n] = kmalloc_array(32, sizeof(u16 *), 4838c2ecf20Sopenharmony_ci GFP_KERNEL); 4848c2ecf20Sopenharmony_ci if (!p1) return -ENOMEM; 4858c2ecf20Sopenharmony_ci for (i = 0; i < 32; i++) 4868c2ecf20Sopenharmony_ci p1[i] = NULL; 4878c2ecf20Sopenharmony_ci } 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci p2 = p1[n = (unicode >> 6) & 0x1f]; 4908c2ecf20Sopenharmony_ci if (!p2) { 4918c2ecf20Sopenharmony_ci p2 = p1[n] = kmalloc_array(64, sizeof(u16), GFP_KERNEL); 4928c2ecf20Sopenharmony_ci if (!p2) return -ENOMEM; 4938c2ecf20Sopenharmony_ci memset(p2, 0xff, 64*sizeof(u16)); /* No glyphs for the characters (yet) */ 4948c2ecf20Sopenharmony_ci } 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci p2[unicode & 0x3f] = fontpos; 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci p->sum += (fontpos << 20U) + unicode; 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci return 0; 5018c2ecf20Sopenharmony_ci} 5028c2ecf20Sopenharmony_ci 5038c2ecf20Sopenharmony_ci/* Caller must hold the lock */ 5048c2ecf20Sopenharmony_cistatic int con_do_clear_unimap(struct vc_data *vc) 5058c2ecf20Sopenharmony_ci{ 5068c2ecf20Sopenharmony_ci struct uni_pagedir *p, *q; 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci p = *vc->vc_uni_pagedir_loc; 5098c2ecf20Sopenharmony_ci if (!p || --p->refcount) { 5108c2ecf20Sopenharmony_ci q = kzalloc(sizeof(*p), GFP_KERNEL); 5118c2ecf20Sopenharmony_ci if (!q) { 5128c2ecf20Sopenharmony_ci if (p) 5138c2ecf20Sopenharmony_ci p->refcount++; 5148c2ecf20Sopenharmony_ci return -ENOMEM; 5158c2ecf20Sopenharmony_ci } 5168c2ecf20Sopenharmony_ci q->refcount=1; 5178c2ecf20Sopenharmony_ci *vc->vc_uni_pagedir_loc = q; 5188c2ecf20Sopenharmony_ci } else { 5198c2ecf20Sopenharmony_ci if (p == dflt) dflt = NULL; 5208c2ecf20Sopenharmony_ci p->refcount++; 5218c2ecf20Sopenharmony_ci p->sum = 0; 5228c2ecf20Sopenharmony_ci con_release_unimap(p); 5238c2ecf20Sopenharmony_ci } 5248c2ecf20Sopenharmony_ci return 0; 5258c2ecf20Sopenharmony_ci} 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ciint con_clear_unimap(struct vc_data *vc) 5288c2ecf20Sopenharmony_ci{ 5298c2ecf20Sopenharmony_ci int ret; 5308c2ecf20Sopenharmony_ci console_lock(); 5318c2ecf20Sopenharmony_ci ret = con_do_clear_unimap(vc); 5328c2ecf20Sopenharmony_ci console_unlock(); 5338c2ecf20Sopenharmony_ci return ret; 5348c2ecf20Sopenharmony_ci} 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ciint con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list) 5378c2ecf20Sopenharmony_ci{ 5388c2ecf20Sopenharmony_ci int err = 0, err1, i; 5398c2ecf20Sopenharmony_ci struct uni_pagedir *p, *q; 5408c2ecf20Sopenharmony_ci struct unipair *unilist, *plist; 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci if (!ct) 5438c2ecf20Sopenharmony_ci return 0; 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_ci unilist = vmemdup_user(list, array_size(sizeof(struct unipair), ct)); 5468c2ecf20Sopenharmony_ci if (IS_ERR(unilist)) 5478c2ecf20Sopenharmony_ci return PTR_ERR(unilist); 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci console_lock(); 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci /* Save original vc_unipagdir_loc in case we allocate a new one */ 5528c2ecf20Sopenharmony_ci p = *vc->vc_uni_pagedir_loc; 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci if (!p) { 5558c2ecf20Sopenharmony_ci err = -EINVAL; 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci goto out_unlock; 5588c2ecf20Sopenharmony_ci } 5598c2ecf20Sopenharmony_ci 5608c2ecf20Sopenharmony_ci if (p->refcount > 1) { 5618c2ecf20Sopenharmony_ci int j, k; 5628c2ecf20Sopenharmony_ci u16 **p1, *p2, l; 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci err1 = con_do_clear_unimap(vc); 5658c2ecf20Sopenharmony_ci if (err1) { 5668c2ecf20Sopenharmony_ci err = err1; 5678c2ecf20Sopenharmony_ci goto out_unlock; 5688c2ecf20Sopenharmony_ci } 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci /* 5718c2ecf20Sopenharmony_ci * Since refcount was > 1, con_clear_unimap() allocated a 5728c2ecf20Sopenharmony_ci * a new uni_pagedir for this vc. Re: p != q 5738c2ecf20Sopenharmony_ci */ 5748c2ecf20Sopenharmony_ci q = *vc->vc_uni_pagedir_loc; 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci /* 5778c2ecf20Sopenharmony_ci * uni_pgdir is a 32*32*64 table with rows allocated 5788c2ecf20Sopenharmony_ci * when its first entry is added. The unicode value must 5798c2ecf20Sopenharmony_ci * still be incremented for empty rows. We are copying 5808c2ecf20Sopenharmony_ci * entries from "p" (old) to "q" (new). 5818c2ecf20Sopenharmony_ci */ 5828c2ecf20Sopenharmony_ci l = 0; /* unicode value */ 5838c2ecf20Sopenharmony_ci for (i = 0; i < 32; i++) { 5848c2ecf20Sopenharmony_ci p1 = p->uni_pgdir[i]; 5858c2ecf20Sopenharmony_ci if (p1) 5868c2ecf20Sopenharmony_ci for (j = 0; j < 32; j++) { 5878c2ecf20Sopenharmony_ci p2 = p1[j]; 5888c2ecf20Sopenharmony_ci if (p2) { 5898c2ecf20Sopenharmony_ci for (k = 0; k < 64; k++, l++) 5908c2ecf20Sopenharmony_ci if (p2[k] != 0xffff) { 5918c2ecf20Sopenharmony_ci /* 5928c2ecf20Sopenharmony_ci * Found one, copy entry for unicode 5938c2ecf20Sopenharmony_ci * l with fontpos value p2[k]. 5948c2ecf20Sopenharmony_ci */ 5958c2ecf20Sopenharmony_ci err1 = con_insert_unipair(q, l, p2[k]); 5968c2ecf20Sopenharmony_ci if (err1) { 5978c2ecf20Sopenharmony_ci p->refcount++; 5988c2ecf20Sopenharmony_ci *vc->vc_uni_pagedir_loc = p; 5998c2ecf20Sopenharmony_ci con_release_unimap(q); 6008c2ecf20Sopenharmony_ci kfree(q); 6018c2ecf20Sopenharmony_ci err = err1; 6028c2ecf20Sopenharmony_ci goto out_unlock; 6038c2ecf20Sopenharmony_ci } 6048c2ecf20Sopenharmony_ci } 6058c2ecf20Sopenharmony_ci } else { 6068c2ecf20Sopenharmony_ci /* Account for row of 64 empty entries */ 6078c2ecf20Sopenharmony_ci l += 64; 6088c2ecf20Sopenharmony_ci } 6098c2ecf20Sopenharmony_ci } 6108c2ecf20Sopenharmony_ci else 6118c2ecf20Sopenharmony_ci /* Account for empty table */ 6128c2ecf20Sopenharmony_ci l += 32 * 64; 6138c2ecf20Sopenharmony_ci } 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci /* 6168c2ecf20Sopenharmony_ci * Finished copying font table, set vc_uni_pagedir to new table 6178c2ecf20Sopenharmony_ci */ 6188c2ecf20Sopenharmony_ci p = q; 6198c2ecf20Sopenharmony_ci } else if (p == dflt) { 6208c2ecf20Sopenharmony_ci dflt = NULL; 6218c2ecf20Sopenharmony_ci } 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_ci /* 6248c2ecf20Sopenharmony_ci * Insert user specified unicode pairs into new table. 6258c2ecf20Sopenharmony_ci */ 6268c2ecf20Sopenharmony_ci for (plist = unilist; ct; ct--, plist++) { 6278c2ecf20Sopenharmony_ci err1 = con_insert_unipair(p, plist->unicode, plist->fontpos); 6288c2ecf20Sopenharmony_ci if (err1) 6298c2ecf20Sopenharmony_ci err = err1; 6308c2ecf20Sopenharmony_ci } 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci /* 6338c2ecf20Sopenharmony_ci * Merge with fontmaps of any other virtual consoles. 6348c2ecf20Sopenharmony_ci */ 6358c2ecf20Sopenharmony_ci if (con_unify_unimap(vc, p)) 6368c2ecf20Sopenharmony_ci goto out_unlock; 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci for (i = 0; i <= 3; i++) 6398c2ecf20Sopenharmony_ci set_inverse_transl(vc, p, i); /* Update inverse translations */ 6408c2ecf20Sopenharmony_ci set_inverse_trans_unicode(vc, p); 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ciout_unlock: 6438c2ecf20Sopenharmony_ci console_unlock(); 6448c2ecf20Sopenharmony_ci kvfree(unilist); 6458c2ecf20Sopenharmony_ci return err; 6468c2ecf20Sopenharmony_ci} 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci/** 6498c2ecf20Sopenharmony_ci * con_set_default_unimap - set default unicode map 6508c2ecf20Sopenharmony_ci * @vc: the console we are updating 6518c2ecf20Sopenharmony_ci * 6528c2ecf20Sopenharmony_ci * Loads the unimap for the hardware font, as defined in uni_hash.tbl. 6538c2ecf20Sopenharmony_ci * The representation used was the most compact I could come up 6548c2ecf20Sopenharmony_ci * with. This routine is executed at video setup, and when the 6558c2ecf20Sopenharmony_ci * PIO_FONTRESET ioctl is called. 6568c2ecf20Sopenharmony_ci * 6578c2ecf20Sopenharmony_ci * The caller must hold the console lock 6588c2ecf20Sopenharmony_ci */ 6598c2ecf20Sopenharmony_ciint con_set_default_unimap(struct vc_data *vc) 6608c2ecf20Sopenharmony_ci{ 6618c2ecf20Sopenharmony_ci int i, j, err = 0, err1; 6628c2ecf20Sopenharmony_ci u16 *q; 6638c2ecf20Sopenharmony_ci struct uni_pagedir *p; 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci if (dflt) { 6668c2ecf20Sopenharmony_ci p = *vc->vc_uni_pagedir_loc; 6678c2ecf20Sopenharmony_ci if (p == dflt) 6688c2ecf20Sopenharmony_ci return 0; 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci dflt->refcount++; 6718c2ecf20Sopenharmony_ci *vc->vc_uni_pagedir_loc = dflt; 6728c2ecf20Sopenharmony_ci if (p && !--p->refcount) { 6738c2ecf20Sopenharmony_ci con_release_unimap(p); 6748c2ecf20Sopenharmony_ci kfree(p); 6758c2ecf20Sopenharmony_ci } 6768c2ecf20Sopenharmony_ci return 0; 6778c2ecf20Sopenharmony_ci } 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ci /* The default font is always 256 characters */ 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_ci err = con_do_clear_unimap(vc); 6828c2ecf20Sopenharmony_ci if (err) 6838c2ecf20Sopenharmony_ci return err; 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_ci p = *vc->vc_uni_pagedir_loc; 6868c2ecf20Sopenharmony_ci q = dfont_unitable; 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_ci for (i = 0; i < 256; i++) 6898c2ecf20Sopenharmony_ci for (j = dfont_unicount[i]; j; j--) { 6908c2ecf20Sopenharmony_ci err1 = con_insert_unipair(p, *(q++), i); 6918c2ecf20Sopenharmony_ci if (err1) 6928c2ecf20Sopenharmony_ci err = err1; 6938c2ecf20Sopenharmony_ci } 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci if (con_unify_unimap(vc, p)) { 6968c2ecf20Sopenharmony_ci dflt = *vc->vc_uni_pagedir_loc; 6978c2ecf20Sopenharmony_ci return err; 6988c2ecf20Sopenharmony_ci } 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci for (i = 0; i <= 3; i++) 7018c2ecf20Sopenharmony_ci set_inverse_transl(vc, p, i); /* Update all inverse translations */ 7028c2ecf20Sopenharmony_ci set_inverse_trans_unicode(vc, p); 7038c2ecf20Sopenharmony_ci dflt = p; 7048c2ecf20Sopenharmony_ci return err; 7058c2ecf20Sopenharmony_ci} 7068c2ecf20Sopenharmony_ciEXPORT_SYMBOL(con_set_default_unimap); 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci/** 7098c2ecf20Sopenharmony_ci * con_copy_unimap - copy unimap between two vts 7108c2ecf20Sopenharmony_ci * @dst_vc: target 7118c2ecf20Sopenharmony_ci * @src_vc: source 7128c2ecf20Sopenharmony_ci * 7138c2ecf20Sopenharmony_ci * The caller must hold the console lock when invoking this method 7148c2ecf20Sopenharmony_ci */ 7158c2ecf20Sopenharmony_ciint con_copy_unimap(struct vc_data *dst_vc, struct vc_data *src_vc) 7168c2ecf20Sopenharmony_ci{ 7178c2ecf20Sopenharmony_ci struct uni_pagedir *q; 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_ci if (!*src_vc->vc_uni_pagedir_loc) 7208c2ecf20Sopenharmony_ci return -EINVAL; 7218c2ecf20Sopenharmony_ci if (*dst_vc->vc_uni_pagedir_loc == *src_vc->vc_uni_pagedir_loc) 7228c2ecf20Sopenharmony_ci return 0; 7238c2ecf20Sopenharmony_ci con_free_unimap(dst_vc); 7248c2ecf20Sopenharmony_ci q = *src_vc->vc_uni_pagedir_loc; 7258c2ecf20Sopenharmony_ci q->refcount++; 7268c2ecf20Sopenharmony_ci *dst_vc->vc_uni_pagedir_loc = q; 7278c2ecf20Sopenharmony_ci return 0; 7288c2ecf20Sopenharmony_ci} 7298c2ecf20Sopenharmony_ciEXPORT_SYMBOL(con_copy_unimap); 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci/** 7328c2ecf20Sopenharmony_ci * con_get_unimap - get the unicode map 7338c2ecf20Sopenharmony_ci * @vc: the console to read from 7348c2ecf20Sopenharmony_ci * 7358c2ecf20Sopenharmony_ci * Read the console unicode data for this console. Called from the ioctl 7368c2ecf20Sopenharmony_ci * handlers. 7378c2ecf20Sopenharmony_ci */ 7388c2ecf20Sopenharmony_ciint con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct, struct unipair __user *list) 7398c2ecf20Sopenharmony_ci{ 7408c2ecf20Sopenharmony_ci int i, j, k, ret = 0; 7418c2ecf20Sopenharmony_ci ushort ect; 7428c2ecf20Sopenharmony_ci u16 **p1, *p2; 7438c2ecf20Sopenharmony_ci struct uni_pagedir *p; 7448c2ecf20Sopenharmony_ci struct unipair *unilist; 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci unilist = kvmalloc_array(ct, sizeof(struct unipair), GFP_KERNEL); 7478c2ecf20Sopenharmony_ci if (!unilist) 7488c2ecf20Sopenharmony_ci return -ENOMEM; 7498c2ecf20Sopenharmony_ci 7508c2ecf20Sopenharmony_ci console_lock(); 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci ect = 0; 7538c2ecf20Sopenharmony_ci if (*vc->vc_uni_pagedir_loc) { 7548c2ecf20Sopenharmony_ci p = *vc->vc_uni_pagedir_loc; 7558c2ecf20Sopenharmony_ci for (i = 0; i < 32; i++) { 7568c2ecf20Sopenharmony_ci p1 = p->uni_pgdir[i]; 7578c2ecf20Sopenharmony_ci if (p1) 7588c2ecf20Sopenharmony_ci for (j = 0; j < 32; j++) { 7598c2ecf20Sopenharmony_ci p2 = *(p1++); 7608c2ecf20Sopenharmony_ci if (p2) 7618c2ecf20Sopenharmony_ci for (k = 0; k < 64; k++, p2++) { 7628c2ecf20Sopenharmony_ci if (*p2 >= MAX_GLYPH) 7638c2ecf20Sopenharmony_ci continue; 7648c2ecf20Sopenharmony_ci if (ect < ct) { 7658c2ecf20Sopenharmony_ci unilist[ect].unicode = 7668c2ecf20Sopenharmony_ci (i<<11)+(j<<6)+k; 7678c2ecf20Sopenharmony_ci unilist[ect].fontpos = *p2; 7688c2ecf20Sopenharmony_ci } 7698c2ecf20Sopenharmony_ci ect++; 7708c2ecf20Sopenharmony_ci } 7718c2ecf20Sopenharmony_ci } 7728c2ecf20Sopenharmony_ci } 7738c2ecf20Sopenharmony_ci } 7748c2ecf20Sopenharmony_ci console_unlock(); 7758c2ecf20Sopenharmony_ci if (copy_to_user(list, unilist, min(ect, ct) * sizeof(struct unipair))) 7768c2ecf20Sopenharmony_ci ret = -EFAULT; 7778c2ecf20Sopenharmony_ci put_user(ect, uct); 7788c2ecf20Sopenharmony_ci kvfree(unilist); 7798c2ecf20Sopenharmony_ci return ret ? ret : (ect <= ct) ? 0 : -ENOMEM; 7808c2ecf20Sopenharmony_ci} 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ci/* 7838c2ecf20Sopenharmony_ci * Always use USER_MAP. These functions are used by the keyboard, 7848c2ecf20Sopenharmony_ci * which shouldn't be affected by G0/G1 switching, etc. 7858c2ecf20Sopenharmony_ci * If the user map still contains default values, i.e. the 7868c2ecf20Sopenharmony_ci * direct-to-font mapping, then assume user is using Latin1. 7878c2ecf20Sopenharmony_ci * 7888c2ecf20Sopenharmony_ci * FIXME: at some point we need to decide if we want to lock the table 7898c2ecf20Sopenharmony_ci * update element itself via the keyboard_event_lock for consistency with the 7908c2ecf20Sopenharmony_ci * keyboard driver as well as the consoles 7918c2ecf20Sopenharmony_ci */ 7928c2ecf20Sopenharmony_ci/* may be called during an interrupt */ 7938c2ecf20Sopenharmony_ciu32 conv_8bit_to_uni(unsigned char c) 7948c2ecf20Sopenharmony_ci{ 7958c2ecf20Sopenharmony_ci unsigned short uni = translations[USER_MAP][c]; 7968c2ecf20Sopenharmony_ci return uni == (0xf000 | c) ? c : uni; 7978c2ecf20Sopenharmony_ci} 7988c2ecf20Sopenharmony_ci 7998c2ecf20Sopenharmony_ciint conv_uni_to_8bit(u32 uni) 8008c2ecf20Sopenharmony_ci{ 8018c2ecf20Sopenharmony_ci int c; 8028c2ecf20Sopenharmony_ci for (c = 0; c < 0x100; c++) 8038c2ecf20Sopenharmony_ci if (translations[USER_MAP][c] == uni || 8048c2ecf20Sopenharmony_ci (translations[USER_MAP][c] == (c | 0xf000) && uni == c)) 8058c2ecf20Sopenharmony_ci return c; 8068c2ecf20Sopenharmony_ci return -1; 8078c2ecf20Sopenharmony_ci} 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_ciint 8108c2ecf20Sopenharmony_ciconv_uni_to_pc(struct vc_data *conp, long ucs) 8118c2ecf20Sopenharmony_ci{ 8128c2ecf20Sopenharmony_ci int h; 8138c2ecf20Sopenharmony_ci u16 **p1, *p2; 8148c2ecf20Sopenharmony_ci struct uni_pagedir *p; 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_ci /* Only 16-bit codes supported at this time */ 8178c2ecf20Sopenharmony_ci if (ucs > 0xffff) 8188c2ecf20Sopenharmony_ci return -4; /* Not found */ 8198c2ecf20Sopenharmony_ci else if (ucs < 0x20) 8208c2ecf20Sopenharmony_ci return -1; /* Not a printable character */ 8218c2ecf20Sopenharmony_ci else if (ucs == 0xfeff || (ucs >= 0x200b && ucs <= 0x200f)) 8228c2ecf20Sopenharmony_ci return -2; /* Zero-width space */ 8238c2ecf20Sopenharmony_ci /* 8248c2ecf20Sopenharmony_ci * UNI_DIRECT_BASE indicates the start of the region in the User Zone 8258c2ecf20Sopenharmony_ci * which always has a 1:1 mapping to the currently loaded font. The 8268c2ecf20Sopenharmony_ci * UNI_DIRECT_MASK indicates the bit span of the region. 8278c2ecf20Sopenharmony_ci */ 8288c2ecf20Sopenharmony_ci else if ((ucs & ~UNI_DIRECT_MASK) == UNI_DIRECT_BASE) 8298c2ecf20Sopenharmony_ci return ucs & UNI_DIRECT_MASK; 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_ci if (!*conp->vc_uni_pagedir_loc) 8328c2ecf20Sopenharmony_ci return -3; 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_ci p = *conp->vc_uni_pagedir_loc; 8358c2ecf20Sopenharmony_ci if ((p1 = p->uni_pgdir[ucs >> 11]) && 8368c2ecf20Sopenharmony_ci (p2 = p1[(ucs >> 6) & 0x1f]) && 8378c2ecf20Sopenharmony_ci (h = p2[ucs & 0x3f]) < MAX_GLYPH) 8388c2ecf20Sopenharmony_ci return h; 8398c2ecf20Sopenharmony_ci 8408c2ecf20Sopenharmony_ci return -4; /* not found */ 8418c2ecf20Sopenharmony_ci} 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ci/* 8448c2ecf20Sopenharmony_ci * This is called at sys_setup time, after memory and the console are 8458c2ecf20Sopenharmony_ci * initialized. It must be possible to call kmalloc(..., GFP_KERNEL) 8468c2ecf20Sopenharmony_ci * from this function, hence the call from sys_setup. 8478c2ecf20Sopenharmony_ci */ 8488c2ecf20Sopenharmony_civoid __init 8498c2ecf20Sopenharmony_ciconsole_map_init(void) 8508c2ecf20Sopenharmony_ci{ 8518c2ecf20Sopenharmony_ci int i; 8528c2ecf20Sopenharmony_ci 8538c2ecf20Sopenharmony_ci for (i = 0; i < MAX_NR_CONSOLES; i++) 8548c2ecf20Sopenharmony_ci if (vc_cons_allocated(i) && !*vc_cons[i].d->vc_uni_pagedir_loc) 8558c2ecf20Sopenharmony_ci con_set_default_unimap(vc_cons[i].d); 8568c2ecf20Sopenharmony_ci} 8578c2ecf20Sopenharmony_ci 858