| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* ebcdic keycode functions for s390 console drivers |
| 4 |
* |
| 5 |
* S390 version |
| 6 |
* Copyright IBM Corp. 2003 |
| 7 |
* Author(s): Martin Schwidefsky ([email protected]), |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <linux/export.h> |
| 11 |
#include <linux/module.h> |
| 12 |
#include <linux/sched/signal.h> |
| 13 |
#include <linux/slab.h> |
| 14 |
#include <linux/sysrq.h> |
| 15 |
|
| 16 |
#include <linux/consolemap.h> |
| 17 |
#include <linux/kbd_kern.h> |
| 18 |
#include <linux/kbd_diacr.h> |
| 19 |
#include <linux/uaccess.h> |
| 20 |
|
| 21 |
#include "keyboard.h" |
| 22 |
|
| 23 |
/* |
| 24 |
* Handler Tables. |
| 25 |
*/ |
| 26 |
#define K_HANDLERS\ |
| 27 |
k_self, k_fn, k_spec, k_ignore,\ |
| 28 |
k_dead, k_ignore, k_ignore, k_ignore,\ |
| 29 |
k_ignore, k_ignore, k_ignore, k_ignore,\ |
| 30 |
k_ignore, k_ignore, k_ignore, k_ignore |
| 31 |
|
| 32 |
typedef void (k_handler_fn)(struct kbd_data *, unsigned char); |
| 33 |
static k_handler_fn K_HANDLERS; |
| 34 |
static k_handler_fn *k_handler[16] = { K_HANDLERS }; |
| 35 |
|
| 36 |
/* maximum values each key_handler can handle */ |
| 37 |
static const int kbd_max_vals[] = { |
| 38 |
255, ARRAY_SIZE(func_table) - 1, NR_FN_HANDLER - 1, 0, |
| 39 |
NR_DEAD - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 40 |
}; |
| 41 |
static const int KBD_NR_TYPES = ARRAY_SIZE(kbd_max_vals); |
| 42 |
|
| 43 |
static const unsigned char ret_diacr[NR_DEAD] = { |
| 44 |
'`', /* dead_grave */ |
| 45 |
'\'', /* dead_acute */ |
| 46 |
'^', /* dead_circumflex */ |
| 47 |
'~', /* dead_tilda */ |
| 48 |
'"', /* dead_diaeresis */ |
| 49 |
',', /* dead_cedilla */ |
| 50 |
'_', /* dead_macron */ |
| 51 |
'U', /* dead_breve */ |
| 52 |
'.', /* dead_abovedot */ |
| 53 |
'*', /* dead_abovering */ |
| 54 |
'=', /* dead_doubleacute */ |
| 55 |
'c', /* dead_caron */ |
| 56 |
'k', /* dead_ogonek */ |
| 57 |
'i', /* dead_iota */ |
| 58 |
'#', /* dead_voiced_sound */ |
| 59 |
'o', /* dead_semivoiced_sound */ |
| 60 |
'!', /* dead_belowdot */ |
| 61 |
'?', /* dead_hook */ |
| 62 |
'+', /* dead_horn */ |
| 63 |
'-', /* dead_stroke */ |
| 64 |
')', /* dead_abovecomma */ |
| 65 |
'(', /* dead_abovereversedcomma */ |
| 66 |
':', /* dead_doublegrave */ |
| 67 |
'n', /* dead_invertedbreve */ |
| 68 |
';', /* dead_belowcomma */ |
| 69 |
'$', /* dead_currency */ |
| 70 |
'@', /* dead_greek */ |
| 71 |
}; |
| 72 |
|
| 73 |
/* |
| 74 |
* Alloc/free of kbd_data structures. |
| 75 |
*/ |
| 76 |
struct kbd_data * |
| 77 |
kbd_alloc(void) { |
| 78 |
struct kbd_data *kbd; |
| 79 |
int i; |
| 80 |
|
| 81 |
kbd = kzalloc_obj(struct kbd_data); |
| 82 |
if (!kbd) |
| 83 |
goto out; |
| 84 |
kbd->key_maps = kzalloc(sizeof(ebc_key_maps), GFP_KERNEL); |
| 85 |
if (!kbd->key_maps) |
| 86 |
goto out_kbd; |
| 87 |
for (i = 0; i < ARRAY_SIZE(ebc_key_maps); i++) { |
| 88 |
if (ebc_key_maps[i]) { |
| 89 |
kbd->key_maps[i] = kmemdup(ebc_key_maps[i], |
| 90 |
sizeof(u_short) * NR_KEYS, |
| 91 |
GFP_KERNEL); |
| 92 |
if (!kbd->key_maps[i]) |
| 93 |
goto out_maps; |
| 94 |
} |
| 95 |
} |
| 96 |
kbd->func_table = kzalloc(sizeof(ebc_func_table), GFP_KERNEL); |
| 97 |
if (!kbd->func_table) |
| 98 |
goto out_maps; |
| 99 |
for (i = 0; i < ARRAY_SIZE(ebc_func_table); i++) { |
| 100 |
if (ebc_func_table[i]) { |
| 101 |
kbd->func_table[i] = kstrdup(ebc_func_table[i], |
| 102 |
GFP_KERNEL); |
| 103 |
if (!kbd->func_table[i]) |
| 104 |
goto out_func; |
| 105 |
} |
| 106 |
} |
| 107 |
kbd->fn_handler = |
| 108 |
kzalloc_objs(fn_handler_fn *, NR_FN_HANDLER); |
| 109 |
if (!kbd->fn_handler) |
| 110 |
goto out_func; |
| 111 |
kbd->accent_table = kmemdup(ebc_accent_table, |
| 112 |
sizeof(struct kbdiacruc) * MAX_DIACR, |
| 113 |
GFP_KERNEL); |
| 114 |
if (!kbd->accent_table) |
| 115 |
goto out_fn_handler; |
| 116 |
kbd->accent_table_size = ebc_accent_table_size; |
| 117 |
return kbd; |
| 118 |
|
| 119 |
out_fn_handler: |
| 120 |
kfree(kbd->fn_handler); |
| 121 |
out_func: |
| 122 |
for (i = 0; i < ARRAY_SIZE(ebc_func_table); i++) |
| 123 |
kfree(kbd->func_table[i]); |
| 124 |
kfree(kbd->func_table); |
| 125 |
out_maps: |
| 126 |
for (i = 0; i < ARRAY_SIZE(ebc_key_maps); i++) |
| 127 |
kfree(kbd->key_maps[i]); |
| 128 |
kfree(kbd->key_maps); |
| 129 |
out_kbd: |
| 130 |
kfree(kbd); |
| 131 |
out: |
| 132 |
return NULL; |
| 133 |
} |
| 134 |
|
| 135 |
void |
| 136 |
kbd_free(struct kbd_data *kbd) |
| 137 |
{ |
| 138 |
int i; |
| 139 |
|
| 140 |
kfree(kbd->accent_table); |
| 141 |
kfree(kbd->fn_handler); |
| 142 |
for (i = 0; i < ARRAY_SIZE(ebc_func_table); i++) |
| 143 |
kfree(kbd->func_table[i]); |
| 144 |
kfree(kbd->func_table); |
| 145 |
for (i = 0; i < ARRAY_SIZE(ebc_key_maps); i++) |
| 146 |
kfree(kbd->key_maps[i]); |
| 147 |
kfree(kbd->key_maps); |
| 148 |
kfree(kbd); |
| 149 |
} |
| 150 |
|
| 151 |
/* |
| 152 |
* Generate ascii -> ebcdic translation table from kbd_data. |
| 153 |
*/ |
| 154 |
void |
| 155 |
kbd_ascebc(struct kbd_data *kbd, unsigned char *ascebc) |
| 156 |
{ |
| 157 |
unsigned short *keymap, keysym; |
| 158 |
int i, j, k; |
| 159 |
|
| 160 |
memset(ascebc, 0x40, 256); |
| 161 |
for (i = 0; i < ARRAY_SIZE(ebc_key_maps); i++) { |
| 162 |
keymap = kbd->key_maps[i]; |
| 163 |
if (!keymap) |
| 164 |
continue; |
| 165 |
for (j = 0; j < NR_KEYS; j++) { |
| 166 |
k = ((i & 1) << 7) + j; |
| 167 |
keysym = keymap[j]; |
| 168 |
if (KTYP(keysym) == (KT_LATIN | 0xf0) || |
| 169 |
KTYP(keysym) == (KT_LETTER | 0xf0)) |
| 170 |
ascebc[KVAL(keysym)] = k; |
| 171 |
else if (KTYP(keysym) == (KT_DEAD | 0xf0)) |
| 172 |
ascebc[ret_diacr[KVAL(keysym)]] = k; |
| 173 |
} |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
#if 0 |
| 178 |
/* |
| 179 |
* Generate ebcdic -> ascii translation table from kbd_data. |
| 180 |
*/ |
| 181 |
void |
| 182 |
kbd_ebcasc(struct kbd_data *kbd, unsigned char *ebcasc) |
| 183 |
{ |
| 184 |
unsigned short *keymap, keysym; |
| 185 |
int i, j, k; |
| 186 |
|
| 187 |
memset(ebcasc, ' ', 256); |
| 188 |
for (i = 0; i < ARRAY_SIZE(ebc_key_maps); i++) { |
| 189 |
keymap = kbd->key_maps[i]; |
| 190 |
if (!keymap) |
| 191 |
continue; |
| 192 |
for (j = 0; j < NR_KEYS; j++) { |
| 193 |
keysym = keymap[j]; |
| 194 |
k = ((i & 1) << 7) + j; |
| 195 |
if (KTYP(keysym) == (KT_LATIN | 0xf0) || |
| 196 |
KTYP(keysym) == (KT_LETTER | 0xf0)) |
| 197 |
ebcasc[k] = KVAL(keysym); |
| 198 |
else if (KTYP(keysym) == (KT_DEAD | 0xf0)) |
| 199 |
ebcasc[k] = ret_diacr[KVAL(keysym)]; |
| 200 |
} |
| 201 |
} |
| 202 |
} |
| 203 |
#endif |
| 204 |
|
| 205 |
/* |
| 206 |
* We have a combining character DIACR here, followed by the character CH. |
| 207 |
* If the combination occurs in the table, return the corresponding value. |
| 208 |
* Otherwise, if CH is a space or equals DIACR, return DIACR. |
| 209 |
* Otherwise, conclude that DIACR was not combining after all, |
| 210 |
* queue it and return CH. |
| 211 |
*/ |
| 212 |
static unsigned int |
| 213 |
handle_diacr(struct kbd_data *kbd, unsigned int ch) |
| 214 |
{ |
| 215 |
int i, d; |
| 216 |
|
| 217 |
d = kbd->diacr; |
| 218 |
kbd->diacr = 0; |
| 219 |
|
| 220 |
for (i = 0; i < kbd->accent_table_size; i++) { |
| 221 |
if (kbd->accent_table[i].diacr == d && |
| 222 |
kbd->accent_table[i].base == ch) |
| 223 |
return kbd->accent_table[i].result; |
| 224 |
} |
| 225 |
|
| 226 |
if (ch == ' ' || ch == d) |
| 227 |
return d; |
| 228 |
|
| 229 |
kbd_put_queue(kbd->port, d); |
| 230 |
return ch; |
| 231 |
} |
| 232 |
|
| 233 |
/* |
| 234 |
* Handle dead key. |
| 235 |
*/ |
| 236 |
static void |
| 237 |
k_dead(struct kbd_data *kbd, unsigned char value) |
| 238 |
{ |
| 239 |
value = ret_diacr[value]; |
| 240 |
kbd->diacr = (kbd->diacr ? handle_diacr(kbd, value) : value); |
| 241 |
} |
| 242 |
|
| 243 |
/* |
| 244 |
* Normal character handler. |
| 245 |
*/ |
| 246 |
static void |
| 247 |
k_self(struct kbd_data *kbd, unsigned char value) |
| 248 |
{ |
| 249 |
if (kbd->diacr) |
| 250 |
value = handle_diacr(kbd, value); |
| 251 |
kbd_put_queue(kbd->port, value); |
| 252 |
} |
| 253 |
|
| 254 |
/* |
| 255 |
* Special key handlers |
| 256 |
*/ |
| 257 |
static void |
| 258 |
k_ignore(struct kbd_data *kbd, unsigned char value) |
| 259 |
{ |
| 260 |
} |
| 261 |
|
| 262 |
/* |
| 263 |
* Function key handler. |
| 264 |
*/ |
| 265 |
static void |
| 266 |
k_fn(struct kbd_data *kbd, unsigned char value) |
| 267 |
{ |
| 268 |
if (kbd->func_table[value]) |
| 269 |
kbd_puts_queue(kbd->port, kbd->func_table[value]); |
| 270 |
} |
| 271 |
|
| 272 |
static void |
| 273 |
k_spec(struct kbd_data *kbd, unsigned char value) |
| 274 |
{ |
| 275 |
if (value >= NR_FN_HANDLER) |
| 276 |
return; |
| 277 |
if (kbd->fn_handler[value]) |
| 278 |
kbd->fn_handler[value](kbd); |
| 279 |
} |
| 280 |
|
| 281 |
/* |
| 282 |
* Put utf8 character to tty flip buffer. |
| 283 |
* UTF-8 is defined for words of up to 31 bits, |
| 284 |
* but we need only 16 bits here |
| 285 |
*/ |
| 286 |
static void |
| 287 |
to_utf8(struct tty_port *port, ushort c) |
| 288 |
{ |
| 289 |
if (c < 0x80) |
| 290 |
/* 0******* */ |
| 291 |
kbd_put_queue(port, c); |
| 292 |
else if (c < 0x800) { |
| 293 |
/* 110***** 10****** */ |
| 294 |
kbd_put_queue(port, 0xc0 | (c >> 6)); |
| 295 |
kbd_put_queue(port, 0x80 | (c & 0x3f)); |
| 296 |
} else { |
| 297 |
/* 1110**** 10****** 10****** */ |
| 298 |
kbd_put_queue(port, 0xe0 | (c >> 12)); |
| 299 |
kbd_put_queue(port, 0x80 | ((c >> 6) & 0x3f)); |
| 300 |
kbd_put_queue(port, 0x80 | (c & 0x3f)); |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
/* |
| 305 |
* Process keycode. |
| 306 |
*/ |
| 307 |
void |
| 308 |
kbd_keycode(struct kbd_data *kbd, unsigned int keycode) |
| 309 |
{ |
| 310 |
unsigned short keysym; |
| 311 |
unsigned char type, value; |
| 312 |
|
| 313 |
if (!kbd) |
| 314 |
return; |
| 315 |
|
| 316 |
if (keycode >= 384) |
| 317 |
keysym = kbd->key_maps[5][keycode - 384]; |
| 318 |
else if (keycode >= 256) |
| 319 |
keysym = kbd->key_maps[4][keycode - 256]; |
| 320 |
else if (keycode >= 128) |
| 321 |
keysym = kbd->key_maps[1][keycode - 128]; |
| 322 |
else |
| 323 |
keysym = kbd->key_maps[0][keycode]; |
| 324 |
|
| 325 |
type = KTYP(keysym); |
| 326 |
if (type >= 0xf0) { |
| 327 |
type -= 0xf0; |
| 328 |
if (type == KT_LETTER) |
| 329 |
type = KT_LATIN; |
| 330 |
value = KVAL(keysym); |
| 331 |
#ifdef CONFIG_MAGIC_SYSRQ /* Handle the SysRq Hack */ |
| 332 |
if (kbd->sysrq) { |
| 333 |
if (kbd->sysrq == K(KT_LATIN, '-')) { |
| 334 |
kbd->sysrq = 0; |
| 335 |
handle_sysrq(value); |
| 336 |
return; |
| 337 |
} |
| 338 |
if (value == '-') { |
| 339 |
kbd->sysrq = K(KT_LATIN, '-'); |
| 340 |
return; |
| 341 |
} |
| 342 |
/* Incomplete sysrq sequence. */ |
| 343 |
(*k_handler[KTYP(kbd->sysrq)])(kbd, KVAL(kbd->sysrq)); |
| 344 |
kbd->sysrq = 0; |
| 345 |
} else if ((type == KT_LATIN && value == '^') || |
| 346 |
(type == KT_DEAD && ret_diacr[value] == '^')) { |
| 347 |
kbd->sysrq = K(type, value); |
| 348 |
return; |
| 349 |
} |
| 350 |
#endif |
| 351 |
(*k_handler[type])(kbd, value); |
| 352 |
} else |
| 353 |
to_utf8(kbd->port, keysym); |
| 354 |
} |
| 355 |
|
| 356 |
/* |
| 357 |
* Ioctl stuff. |
| 358 |
*/ |
| 359 |
static int |
| 360 |
do_kdsk_ioctl(struct kbd_data *kbd, struct kbentry __user *user_kbe, |
| 361 |
int cmd, int perm) |
| 362 |
{ |
| 363 |
struct kbentry tmp; |
| 364 |
unsigned long kb_index, kb_table; |
| 365 |
ushort *key_map, val, ov; |
| 366 |
|
| 367 |
if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry))) |
| 368 |
return -EFAULT; |
| 369 |
kb_index = (unsigned long) tmp.kb_index; |
| 370 |
#if NR_KEYS < 256 |
| 371 |
if (kb_index >= NR_KEYS) |
| 372 |
return -EINVAL; |
| 373 |
#endif |
| 374 |
kb_table = (unsigned long) tmp.kb_table; |
| 375 |
#if MAX_NR_KEYMAPS < 256 |
| 376 |
if (kb_table >= MAX_NR_KEYMAPS) |
| 377 |
return -EINVAL; |
| 378 |
kb_table = array_index_nospec(kb_table , MAX_NR_KEYMAPS); |
| 379 |
#endif |
| 380 |
|
| 381 |
switch (cmd) { |
| 382 |
case KDGKBENT: |
| 383 |
key_map = kbd->key_maps[kb_table]; |
| 384 |
if (key_map) { |
| 385 |
val = U(key_map[kb_index]); |
| 386 |
if (KTYP(val) >= KBD_NR_TYPES) |
| 387 |
val = K_HOLE; |
| 388 |
} else |
| 389 |
val = (kb_index ? K_HOLE : K_NOSUCHMAP); |
| 390 |
return put_user(val, &user_kbe->kb_value); |
| 391 |
case KDSKBENT: |
| 392 |
if (!perm) |
| 393 |
return -EPERM; |
| 394 |
if (!kb_index && tmp.kb_value == K_NOSUCHMAP) { |
| 395 |
/* disallocate map */ |
| 396 |
key_map = kbd->key_maps[kb_table]; |
| 397 |
if (key_map) { |
| 398 |
kbd->key_maps[kb_table] = NULL; |
| 399 |
kfree(key_map); |
| 400 |
} |
| 401 |
break; |
| 402 |
} |
| 403 |
|
| 404 |
if (KTYP(tmp.kb_value) >= KBD_NR_TYPES) |
| 405 |
return -EINVAL; |
| 406 |
if (KVAL(tmp.kb_value) > kbd_max_vals[KTYP(tmp.kb_value)]) |
| 407 |
return -EINVAL; |
| 408 |
|
| 409 |
if (!(key_map = kbd->key_maps[kb_table])) { |
| 410 |
int j; |
| 411 |
|
| 412 |
key_map = kmalloc(sizeof(plain_map), |
| 413 |
GFP_KERNEL); |
| 414 |
if (!key_map) |
| 415 |
return -ENOMEM; |
| 416 |
kbd->key_maps[kb_table] = key_map; |
| 417 |
for (j = 0; j < NR_KEYS; j++) |
| 418 |
key_map[j] = U(K_HOLE); |
| 419 |
} |
| 420 |
ov = U(key_map[kb_index]); |
| 421 |
if (tmp.kb_value == ov) |
| 422 |
break; /* nothing to do */ |
| 423 |
/* |
| 424 |
* Attention Key. |
| 425 |
*/ |
| 426 |
if (((ov == K_SAK) || (tmp.kb_value == K_SAK)) && |
| 427 |
!capable(CAP_SYS_ADMIN)) |
| 428 |
return -EPERM; |
| 429 |
key_map[kb_index] = U(tmp.kb_value); |
| 430 |
break; |
| 431 |
} |
| 432 |
return 0; |
| 433 |
} |
| 434 |
|
| 435 |
static int |
| 436 |
do_kdgkb_ioctl(struct kbd_data *kbd, struct kbsentry __user *u_kbs, |
| 437 |
int cmd, int perm) |
| 438 |
{ |
| 439 |
unsigned char kb_func; |
| 440 |
char *p; |
| 441 |
int len; |
| 442 |
|
| 443 |
/* Get u_kbs->kb_func. */ |
| 444 |
if (get_user(kb_func, &u_kbs->kb_func)) |
| 445 |
return -EFAULT; |
| 446 |
#if MAX_NR_FUNC < 256 |
| 447 |
if (kb_func >= MAX_NR_FUNC) |
| 448 |
return -EINVAL; |
| 449 |
#endif |
| 450 |
|
| 451 |
switch (cmd) { |
| 452 |
case KDGKBSENT: |
| 453 |
p = kbd->func_table[kb_func]; |
| 454 |
if (p) { |
| 455 |
len = strlen(p); |
| 456 |
if (len >= sizeof(u_kbs->kb_string)) |
| 457 |
len = sizeof(u_kbs->kb_string) - 1; |
| 458 |
if (copy_to_user(u_kbs->kb_string, p, len)) |
| 459 |
return -EFAULT; |
| 460 |
} else |
| 461 |
len = 0; |
| 462 |
if (put_user('\0', u_kbs->kb_string + len)) |
| 463 |
return -EFAULT; |
| 464 |
break; |
| 465 |
case KDSKBSENT: |
| 466 |
if (!perm) |
| 467 |
return -EPERM; |
| 468 |
p = strndup_user(u_kbs->kb_string, sizeof(u_kbs->kb_string)); |
| 469 |
if (IS_ERR(p)) |
| 470 |
return PTR_ERR(p); |
| 471 |
kfree(kbd->func_table[kb_func]); |
| 472 |
kbd->func_table[kb_func] = p; |
| 473 |
break; |
| 474 |
} |
| 475 |
return 0; |
| 476 |
} |
| 477 |
|
| 478 |
int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg) |
| 479 |
{ |
| 480 |
struct tty_struct *tty; |
| 481 |
void __user *argp; |
| 482 |
unsigned int ct; |
| 483 |
int perm; |
| 484 |
|
| 485 |
argp = (void __user *)arg; |
| 486 |
|
| 487 |
/* |
| 488 |
* To have permissions to do most of the vt ioctls, we either have |
| 489 |
* to be the owner of the tty, or have CAP_SYS_TTY_CONFIG. |
| 490 |
*/ |
| 491 |
tty = tty_port_tty_get(kbd->port); |
| 492 |
/* FIXME this test is pretty racy */ |
| 493 |
perm = current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG); |
| 494 |
tty_kref_put(tty); |
| 495 |
switch (cmd) { |
| 496 |
case KDGKBTYPE: |
| 497 |
return put_user(KB_101, (char __user *)argp); |
| 498 |
case KDGKBENT: |
| 499 |
case KDSKBENT: |
| 500 |
return do_kdsk_ioctl(kbd, argp, cmd, perm); |
| 501 |
case KDGKBSENT: |
| 502 |
case KDSKBSENT: |
| 503 |
return do_kdgkb_ioctl(kbd, argp, cmd, perm); |
| 504 |
case KDGKBDIACR: |
| 505 |
{ |
| 506 |
struct kbdiacrs __user *a = argp; |
| 507 |
struct kbdiacr diacr; |
| 508 |
int i; |
| 509 |
|
| 510 |
if (put_user(kbd->accent_table_size, &a->kb_cnt)) |
| 511 |
return -EFAULT; |
| 512 |
for (i = 0; i < kbd->accent_table_size; i++) { |
| 513 |
diacr.diacr = kbd->accent_table[i].diacr; |
| 514 |
diacr.base = kbd->accent_table[i].base; |
| 515 |
diacr.result = kbd->accent_table[i].result; |
| 516 |
if (copy_to_user(a->kbdiacr + i, &diacr, sizeof(struct kbdiacr))) |
| 517 |
return -EFAULT; |
| 518 |
} |
| 519 |
return 0; |
| 520 |
} |
| 521 |
case KDGKBDIACRUC: |
| 522 |
{ |
| 523 |
struct kbdiacrsuc __user *a = argp; |
| 524 |
|
| 525 |
ct = kbd->accent_table_size; |
| 526 |
if (put_user(ct, &a->kb_cnt)) |
| 527 |
return -EFAULT; |
| 528 |
if (copy_to_user(a->kbdiacruc, kbd->accent_table, |
| 529 |
ct * sizeof(struct kbdiacruc))) |
| 530 |
return -EFAULT; |
| 531 |
return 0; |
| 532 |
} |
| 533 |
case KDSKBDIACR: |
| 534 |
{ |
| 535 |
struct kbdiacrs __user *a = argp; |
| 536 |
struct kbdiacr diacr; |
| 537 |
int i; |
| 538 |
|
| 539 |
if (!perm) |
| 540 |
return -EPERM; |
| 541 |
if (get_user(ct, &a->kb_cnt)) |
| 542 |
return -EFAULT; |
| 543 |
if (ct >= MAX_DIACR) |
| 544 |
return -EINVAL; |
| 545 |
kbd->accent_table_size = ct; |
| 546 |
for (i = 0; i < ct; i++) { |
| 547 |
if (copy_from_user(&diacr, a->kbdiacr + i, sizeof(struct kbdiacr))) |
| 548 |
return -EFAULT; |
| 549 |
kbd->accent_table[i].diacr = diacr.diacr; |
| 550 |
kbd->accent_table[i].base = diacr.base; |
| 551 |
kbd->accent_table[i].result = diacr.result; |
| 552 |
} |
| 553 |
return 0; |
| 554 |
} |
| 555 |
case KDSKBDIACRUC: |
| 556 |
{ |
| 557 |
struct kbdiacrsuc __user *a = argp; |
| 558 |
|
| 559 |
if (!perm) |
| 560 |
return -EPERM; |
| 561 |
if (get_user(ct, &a->kb_cnt)) |
| 562 |
return -EFAULT; |
| 563 |
if (ct >= MAX_DIACR) |
| 564 |
return -EINVAL; |
| 565 |
kbd->accent_table_size = ct; |
| 566 |
if (copy_from_user(kbd->accent_table, a->kbdiacruc, |
| 567 |
ct * sizeof(struct kbdiacruc))) |
| 568 |
return -EFAULT; |
| 569 |
return 0; |
| 570 |
} |
| 571 |
default: |
| 572 |
return -ENOIOCTLCMD; |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
EXPORT_SYMBOL(kbd_ioctl); |
| 577 |
EXPORT_SYMBOL(kbd_ascebc); |
| 578 |
EXPORT_SYMBOL(kbd_free); |
| 579 |
EXPORT_SYMBOL(kbd_alloc); |
| 580 |
EXPORT_SYMBOL(kbd_keycode); |