Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/conskbd.c
+++ new/usr/src/uts/common/io/conskbd.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27
28 28 /*
29 29 * Console kbd multiplexor driver for Sun.
30 30 * The console "zs" port is linked under us, with the "kbd" module pushed
31 31 * on top of it.
32 32 * Minor device 0 is what programs normally use.
33 33 * Minor device 1 is used to feed predigested keystrokes to the "workstation
34 34 * console" driver, which it is linked beneath.
35 35 *
36 36 *
37 37 * This module can support multiple keyboards to be used simultaneously.
38 38 * and enable users to use at a time multiple keyboards connected to the
39 39 * same system. All the keyboards are linked under conskbd, and act as a
40 40 * keyboard with replicated keys.
41 41 *
42 42 * The DIN keyboards of SUN, for exmple , type 3/4/5, are supported via
43 43 * a two-level architecure. The lower one is one of serialport drivers, such
44 44 * as zs, se, and the upper is "kb" STREAMS module. Currenly, the serialport
45 45 * drivers don't support polled I/O interfaces, we couldn't group the keyboard
46 46 * of this kind under conskbd. So we do as the follows:
47 47 *
48 48 * A new ioctl CONSSETKBDTYPE interface between conskbd and lower
49 49 * keyboard drivers is added. When conskbd receives I_LINK or I_PLINK
50 50 * ioctl, it will send a CONSSETKBDTYPE ioctl to the driver which is
51 51 * requesting to be linked under conskbd. If the lower driver does't
52 52 * recognize this ioctl, the virtual keyboard will be disabled so that
53 53 * only one keyboard instance could be linked under conskbd.
54 54 */
55 55 #define KEYMAP_SIZE_VARIABLE
56 56
57 57 #include <sys/types.h>
58 58 #include <sys/param.h>
59 59 #include <sys/stropts.h>
60 60 #include <sys/stream.h>
61 61 #include <sys/strsubr.h>
62 62 #include <sys/strsun.h>
63 63 #include <sys/conf.h>
64 64 #include <sys/stat.h>
65 65 #include <sys/errno.h>
66 66 #include <sys/modctl.h>
67 67 #include <sys/kbio.h>
68 68 #include <sys/ddi.h>
69 69 #include <sys/sunddi.h>
70 70 #include <sys/consdev.h>
71 71 #include <sys/note.h>
72 72 #include <sys/kmem.h>
73 73 #include <sys/kstat.h>
74 74 #include <sys/policy.h>
75 75 #include <sys/kbd.h>
76 76 #include <sys/kbtrans.h>
77 77 #include <sys/promif.h>
78 78 #include <sys/vuid_event.h>
79 79 #include <sys/conskbd.h>
80 80 #include <sys/beep.h>
81 81
82 82 extern struct keyboard *kbtrans_usbkb_maptab_init(void);
83 83 extern void kbtrans_usbkb_maptab_fini(struct keyboard **);
84 84 extern int ddi_create_internal_pathname(dev_info_t *, char *, int, minor_t);
85 85
86 86 /*
87 87 * Module linkage routines for the kernel
88 88 */
89 89 static int conskbd_attach(dev_info_t *, ddi_attach_cmd_t);
90 90 static int conskbd_detach(dev_info_t *, ddi_detach_cmd_t);
91 91 static int conskbd_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
92 92
93 93 /*
94 94 * STREAMS queue processing procedures
95 95 */
96 96 static void conskbduwsrv(queue_t *);
97 97 static void conskbdlwserv(queue_t *);
98 98 static void conskbdlrput(queue_t *, mblk_t *);
99 99 static int conskbdclose(queue_t *, int, cred_t *);
100 100 static int conskbdopen(queue_t *, dev_t *, int, int, cred_t *);
101 101
102 102
103 103 /* STREAMS driver id and limit value struct */
104 104 static struct module_info conskbdm_info = {
105 105 0, /* mi_idnum */
106 106 "conskbd", /* mi_idname */
107 107 0, /* mi_minpsz */
108 108 1024, /* mi_maxpsz */
109 109 2048, /* mi_hiwat */
110 110 128 /* mi_lowat */
111 111 };
112 112
113 113 /*
114 114 * STREAMS queue processing procedure structures
115 115 */
116 116 /* upper read queue processing procedure structures */
117 117 static struct qinit conskbdurinit = {
118 118 NULL, /* qi_putp */
119 119 (int (*)())NULL, /* qi_srvp */
120 120 conskbdopen, /* qi_qopen */
121 121 conskbdclose, /* qi_qclose */
122 122 (int (*)())NULL, /* qi_qadmin */
123 123 &conskbdm_info, /* qi_minfo */
124 124 NULL /* qi_mstat */
125 125 };
126 126
127 127 /* upper write queue processing procedures structuresi */
128 128 static struct qinit conskbduwinit = {
129 129 (int (*)())putq, /* qi_putp */
130 130 (int (*)())conskbduwsrv, /* qi_srvp */
131 131 conskbdopen, /* qi_qopen */
132 132 conskbdclose, /* qi_qclose */
133 133 (int (*)())NULL, /* qi_qadmin */
134 134 &conskbdm_info, /* qi_minfo */
135 135 NULL /* qi_mstat */
136 136 };
137 137
138 138 /* lower read queue processing procedures structures */
139 139 static struct qinit conskbdlrinit = {
140 140 (int (*)())conskbdlrput, /* qi_putp */
141 141 (int (*)())NULL, /* qi_srvp */
142 142 (int (*)())NULL, /* qi_qopen */
143 143 (int (*)())NULL, /* qi_qclose */
144 144 (int (*)())NULL, /* qi_qadmin */
145 145 &conskbdm_info, /* qi_minfo */
146 146 NULL /* qi_mstat */
147 147 };
148 148
149 149 /* lower write processing procedures structures */
150 150 static struct qinit conskbdlwinit = {
151 151 putq, /* qi_putp */
152 152 (int (*)())conskbdlwserv, /* qi_srvp */
153 153 (int (*)())NULL, /* qi_qopen */
154 154 (int (*)())NULL, /* qi_qclose */
155 155 (int (*)())NULL, /* qi_qadmin */
156 156 &conskbdm_info, /* qi_minfo */
157 157 NULL /* qi_mstat */
158 158 };
159 159
160 160 /* STREAMS entity declaration structure */
161 161 static struct streamtab conskbd_str_info = {
162 162 &conskbdurinit, /* st_rdinit */
163 163 &conskbduwinit, /* st_wrinit */
164 164 &conskbdlrinit, /* st_muxrinit */
165 165 &conskbdlwinit, /* st_muxwinit */
166 166 };
167 167
168 168
169 169 /* Entry points structure */
170 170 static struct cb_ops cb_conskbd_ops = {
171 171 nulldev, /* cb_open */
172 172 nulldev, /* cb_close */
173 173 nodev, /* cb_strategy */
174 174 nodev, /* cb_print */
175 175 nodev, /* cb_dump */
176 176 nodev, /* cb_read */
177 177 nodev, /* cb_write */
178 178 nodev, /* cb_ioctl */
179 179 nodev, /* cb_devmap */
180 180 nodev, /* cb_mmap */
181 181 nodev, /* cb_segmap */
182 182 nochpoll, /* cb_chpoll */
183 183 ddi_prop_op, /* cb_prop_op */
184 184 &conskbd_str_info, /* cb_stream */
185 185 D_MP | D_MTOUTPERIM | D_MTOCEXCL /* cb_flag */
186 186 };
187 187
188 188
189 189 /*
190 190 * Device operations structure
191 191 */
192 192 static struct dev_ops conskbd_ops = {
193 193 DEVO_REV, /* devo_rev */
194 194 0, /* devo_refcnt */
195 195 conskbd_info, /* devo_getinfo */
196 196 nulldev, /* devo_identify */
197 197 nulldev, /* devo_probe */
198 198 conskbd_attach, /* devo_attach */
199 199 conskbd_detach, /* devo_detach */
200 200 nodev, /* devo_reset */
201 201 &(cb_conskbd_ops), /* devo_cb_ops */
202 202 (struct bus_ops *)NULL, /* devo_bus_ops */
203 203 NULL, /* devo_power */
204 204 ddi_quiesce_not_needed, /* quiesce */
205 205 };
206 206
207 207 /*
208 208 * Module linkage information for the kernel.
209 209 */
↓ open down ↓ |
209 lines elided |
↑ open up ↑ |
210 210 static struct modldrv modldrv = {
211 211 &mod_driverops, /* Type of module. This one is a pseudo driver */
212 212 "conskbd multiplexer driver",
213 213 &conskbd_ops, /* driver ops */
214 214 };
215 215
216 216 /*
217 217 * Module linkage structure
218 218 */
219 219 static struct modlinkage modlinkage = {
220 - MODREV_1, /* ml_rev */
221 - &modldrv, /* ml_linkage */
222 - NULL /* NULL terminates the list */
220 + MODREV_1, /* ml_rev */
221 + { &modldrv, NULL } /* ml_linkage */
223 222 };
224 223
225 224 /*
226 225 * Debug printing
227 226 */
228 227 #ifndef DPRINTF
229 228 #ifdef DEBUG
230 229 void conskbd_dprintf(const char *fmt, ...);
231 230 #define DPRINTF(l, m, args) \
232 231 (((l) >= conskbd_errlevel) && ((m) & conskbd_errmask) ? \
233 232 conskbd_dprintf args : \
234 233 (void) 0)
235 234
236 235 /*
237 236 * Severity levels for printing
238 237 */
239 238 #define PRINT_L0 0 /* print every message */
240 239 #define PRINT_L1 1 /* debug */
241 240 #define PRINT_L2 2 /* quiet */
242 241
243 242 /*
244 243 * Masks
245 244 */
246 245 #define PRINT_MASK_ALL 0xFFFFFFFFU
247 246 uint_t conskbd_errmask = PRINT_MASK_ALL;
248 247 uint_t conskbd_errlevel = PRINT_L2;
249 248
250 249 #else
251 250 #define DPRINTF(l, m, args) /* NOTHING */
252 251 #endif
253 252 #endif
254 253
255 254 /*
256 255 * Module global data are protected by outer perimeter. Modifying
257 256 * these global data is executed in outer perimeter exclusively.
258 257 * Except in conskbdopen() and conskbdclose(), which are entered
259 258 * exclusively (Refer to D_MTOCEXCL flag), all changes for the
260 259 * global variables are protected by qwriter().
261 260 */
262 261 static queue_t *conskbd_regqueue; /* regular keyboard queue above us */
263 262 static queue_t *conskbd_consqueue; /* console queue above us */
264 263
265 264
266 265 static dev_info_t *conskbd_dip; /* private copy of devinfo pointer */
267 266 static long conskbd_idle_stamp; /* seconds tstamp of latest keystroke */
268 267 static struct keyboard *conskbd_keyindex;
269 268
270 269 /*
271 270 * Normally, kstats of type KSTAT_TYPE_NAMED have multiple elements. In
272 271 * this case we use this type for a single element because the ioctl code
273 272 * for it knows how to handle mixed kernel/user data models. Also, it
274 273 * will be easier to add new statistics later.
275 274 */
276 275 static struct {
277 276 kstat_named_t idle_sec; /* seconds since last keystroke */
278 277 } conskbd_kstat = {
279 278 { "idle_sec", KSTAT_DATA_LONG, }
280 279 };
281 280
282 281 /*
283 282 * Local routines prototypes
284 283 */
285 284 static int conskbd_kstat_update(kstat_t *, int);
286 285
287 286 static void conskbd_ioctl(queue_t *, mblk_t *);
288 287 static void conskbd_ioc_plink(queue_t *, mblk_t *);
289 288 static void conskbd_ioc_punlink(queue_t *, mblk_t *);
290 289 static void conskbd_legacy_kbd_ioctl(queue_t *, mblk_t *);
291 290 static void conskbd_virtual_kbd_ioctl(queue_t *, mblk_t *);
292 291 static mblk_t *conskbd_alloc_firm_event(ushort_t, int);
293 292
294 293 static conskbd_pending_msg_t *conskbd_mux_find_msg(mblk_t *);
295 294 static void conskbd_mux_enqueue_msg(conskbd_pending_msg_t *);
296 295 static void conskbd_mux_dequeue_msg(conskbd_pending_msg_t *);
297 296 static void conskbd_link_lowque_virt(queue_t *, mblk_t *);
298 297 static void conskbd_link_lowque_legacy(queue_t *, mblk_t *);
299 298
300 299 static void conskbd_handle_downstream_msg(queue_t *, mblk_t *);
301 300 static void conskbd_kioctype_complete(conskbd_lower_queue_t *, mblk_t *);
302 301 static void conskbd_kioctrans_complete(conskbd_lower_queue_t *, mblk_t *);
303 302 static void conskbd_kioclayout_complete(conskbd_lower_queue_t *, mblk_t *);
304 303 static void conskbd_kiocsled_complete(conskbd_lower_queue_t *, mblk_t *);
305 304 static void conskbd_mux_upstream_msg(conskbd_lower_queue_t *, mblk_t *);
306 305 static void conskbd_legacy_upstream_msg(conskbd_lower_queue_t *, mblk_t *);
307 306 static void conskbd_lqs_ack_complete(conskbd_lower_queue_t *, mblk_t *);
308 307
309 308 static void conskbd_polledio_enter(cons_polledio_arg_t);
310 309 static void conskbd_polledio_exit(cons_polledio_arg_t);
311 310 static int conskbd_polledio_ischar(cons_polledio_arg_t);
312 311 static int conskbd_polledio_getchar(cons_polledio_arg_t);
313 312 static void conskbd_polledio_setled(struct kbtrans_hardware *, int);
314 313
315 314 static void conskbd_streams_setled(struct kbtrans_hardware *, int);
316 315 static boolean_t conskbd_override_kbtrans(queue_t *, mblk_t *);
317 316 static boolean_t
318 317 conskbd_polled_keycheck(struct kbtrans_hardware *,
319 318 kbtrans_key_t *, enum keystate *);
320 319
321 320 /*
322 321 * Callbacks needed by kbtrans
323 322 */
324 323 static struct kbtrans_callbacks conskbd_callbacks = {
325 324 conskbd_streams_setled,
326 325 conskbd_polledio_setled,
327 326 conskbd_polled_keycheck,
328 327 };
329 328
330 329 /*
331 330 * Single private "global" lock for the few rare conditions
332 331 * we want single-threaded.
333 332 */
334 333 static kmutex_t conskbd_msgq_lock;
335 334 static conskbd_pending_msg_t *conskbd_msg_queue;
336 335
337 336 /*
338 337 * The software state structure of virtual keyboard.
339 338 * Currently, only one virtual keyboard is supported.
340 339 */
341 340 static conskbd_state_t conskbd = { 0 };
342 341
343 342 /* This variable backs up the layout state for non-self-ID keyboards */
344 343 static int kbd_layout_bak = 0;
345 344
346 345 /*
347 346 * _init()
348 347 *
349 348 * Description:
350 349 * Driver initialization, called when driver is first loaded.
351 350 * This is how access is initially given to all the static structures.
352 351 *
353 352 * Arguments:
354 353 * None
355 354 *
356 355 * Returns:
357 356 * ddi_soft_state_init() status, see ddi_soft_state_init(9f), or
358 357 * mod_install() status, see mod_install(9f)
359 358 */
360 359 int
361 360 _init(void)
362 361 {
363 362 int error;
364 363
365 364 error = mod_install(&modlinkage);
366 365 if (error != 0) {
367 366 return (error);
368 367 }
369 368
370 369 conskbd_keyindex = kbtrans_usbkb_maptab_init();
371 370
372 371 mutex_init(&conskbd_msgq_lock, NULL, MUTEX_DRIVER, NULL);
373 372
374 373 return (error);
375 374
376 375 } /* _init() */
377 376
378 377 /*
379 378 * _fini()
380 379 *
381 380 * Description:
382 381 * Module de-initialization, called when the driver is to be unloaded.
383 382 *
384 383 * Arguments:
385 384 * None
386 385 *
387 386 * Returns:
388 387 * mod_remove() status, see mod_remove(9f)
389 388 */
390 389 int
391 390 _fini(void)
392 391 {
393 392 int error;
394 393
395 394 error = mod_remove(&modlinkage);
396 395 if (error != 0)
397 396 return (error);
398 397 mutex_destroy(&conskbd_msgq_lock);
399 398 kbtrans_usbkb_maptab_fini(&conskbd_keyindex);
400 399
401 400 return (0);
402 401
403 402 } /* _fini() */
404 403
405 404 /*
406 405 * _info()
407 406 *
408 407 * Description:
409 408 * Module information, returns information about the driver.
410 409 *
411 410 * Arguments:
412 411 * modinfo *modinfop Pointer to the opaque modinfo structure
413 412 *
414 413 * Returns:
415 414 * mod_info() status, see mod_info(9f)
416 415 */
417 416 int
418 417 _info(struct modinfo *modinfop)
419 418 {
420 419 return (mod_info(&modlinkage, modinfop));
421 420
422 421 } /* _info() */
423 422
424 423
425 424 /*
426 425 * conskbd_attach()
427 426 *
428 427 * Description:
429 428 * This routine creates two device nodes. One is the "kbd" node, which
430 429 * is used by user application programs(such as Xserver).The other is the
431 430 * "conskbd" node, which is an internal node. consconfig_dacf module will
432 431 * open this internal node, and link the conskbd under the wc (workstaion
433 432 * console).
434 433 *
435 434 * Arguments:
436 435 * dev_info_t *dip Pointer to the device's dev_info struct
437 436 * ddi_attach_cmd_t cmd Attach command
438 437 *
439 438 * Returns:
440 439 * DDI_SUCCESS The driver was initialized properly
441 440 * DDI_FAILURE The driver couldn't be initialized properly
442 441 */
443 442 /*ARGSUSED*/
444 443 static int
445 444 conskbd_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
446 445 {
447 446 kstat_t *ksp;
448 447
449 448 switch (cmd) {
450 449 case DDI_ATTACH:
451 450 break;
452 451
453 452 default:
454 453 return (DDI_FAILURE);
455 454
456 455 }
457 456 if ((ddi_create_minor_node(devi, "kbd", S_IFCHR,
458 457 0, DDI_PSEUDO, NULL) == DDI_FAILURE) ||
459 458 (ddi_create_internal_pathname(devi, "conskbd", S_IFCHR,
460 459 1) == DDI_FAILURE)) {
461 460 ddi_remove_minor_node(devi, NULL);
462 461 return (DDI_FAILURE);
463 462 }
464 463 conskbd_dip = devi;
465 464
466 465 ksp = kstat_create("conskbd", 0, "activity", "misc", KSTAT_TYPE_NAMED,
467 466 sizeof (conskbd_kstat) / sizeof (kstat_named_t),
468 467 KSTAT_FLAG_VIRTUAL);
469 468 if (ksp) {
470 469 ksp->ks_data = (void *) &conskbd_kstat;
471 470 ksp->ks_update = conskbd_kstat_update;
472 471 kstat_install(ksp);
473 472 conskbd_idle_stamp = gethrestime_sec(); /* initial value */
474 473 }
475 474
476 475 conskbd.conskbd_layout = -1; /* invalid layout */
477 476 conskbd.conskbd_led_state = -1;
478 477 conskbd.conskbd_bypassed = B_FALSE;
479 478
480 479 return (DDI_SUCCESS);
481 480
482 481 } /* conskbd_attach() */
483 482
484 483 /*
485 484 * conskbd_detach()
486 485 *
487 486 * Description:
488 487 * Detach an instance of the conskbd driver. In fact, the driver can not
489 488 * be detached.
490 489 *
491 490 * Arguments:
492 491 * dev_info_t *dip Pointer to the device's dev_info struct
493 492 * ddi_detach_cmd_t cmd Detach command
494 493 *
495 494 * Returns:
496 495 * DDI_SUCCESS The driver was detached
497 496 * DDI_FAILURE The driver couldn't be detached
498 497 */
499 498 /*ARGSUSED*/
500 499 static int
501 500 conskbd_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
502 501 {
503 502 return (DDI_FAILURE);
504 503
505 504 } /* conskbd_detach() */
506 505
507 506 /* ARGSUSED */
508 507 static int
509 508 conskbd_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
510 509 void **result)
511 510 {
512 511 register int error;
513 512
514 513 switch (infocmd) {
515 514 case DDI_INFO_DEVT2DEVINFO:
516 515 if (conskbd_dip == NULL) {
517 516 error = DDI_FAILURE;
518 517 } else {
519 518 *result = (void *) conskbd_dip;
520 519 error = DDI_SUCCESS;
521 520 }
522 521 break;
523 522 case DDI_INFO_DEVT2INSTANCE:
524 523 *result = (void *)0;
525 524 error = DDI_SUCCESS;
526 525 break;
527 526 default:
528 527 error = DDI_FAILURE;
529 528 }
530 529 return (error);
531 530
532 531 } /* conskbd_info() */
533 532
534 533 /*ARGSUSED*/
535 534 static int
536 535 conskbdopen(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *crp)
537 536 {
538 537 dev_t unit;
539 538 int err;
540 539
541 540 unit = getminor(*devp);
542 541
543 542 if (unit == 0) {
544 543 /*
545 544 * Opening "/dev/kbd".
546 545 */
547 546 conskbd_regqueue = q;
548 547 qprocson(q);
549 548 return (0);
550 549 } else if (unit != 1) {
551 550 /* we don't do that under Bozo's Big Tent */
552 551 return (ENODEV);
553 552 }
554 553
555 554 /*
556 555 * Check if already initialized
557 556 */
558 557 if (conskbd_consqueue != NULL)
559 558 return (0);
560 559
561 560 /*
562 561 * Opening the device to be linked under the console.
563 562 */
564 563 conskbd_consqueue = q;
565 564
566 565 if (secpolicy_console(crp) != 0)
567 566 return (EPERM);
568 567
569 568 /*
570 569 * initialize kbtrans module for conskbd
571 570 */
572 571 err = kbtrans_streams_init(q, sflag, (struct kbtrans_hardware *)
573 572 &conskbd, &conskbd_callbacks, &conskbd.conskbd_kbtrans, 0, 0);
574 573 if (err != 0)
575 574 return (err);
576 575 kbtrans_streams_set_keyboard(conskbd.conskbd_kbtrans, KB_USB,
577 576 conskbd_keyindex);
578 577
579 578 conskbd.conskbd_polledio.cons_polledio_version = CONSPOLLEDIO_V1;
580 579 conskbd.conskbd_polledio.cons_polledio_argument =
581 580 (cons_polledio_arg_t)&conskbd;
582 581 conskbd.conskbd_polledio.cons_polledio_putchar = NULL;
583 582 conskbd.conskbd_polledio.cons_polledio_getchar =
584 583 (int (*)(cons_polledio_arg_t)) conskbd_polledio_getchar;
585 584 conskbd.conskbd_polledio.cons_polledio_ischar =
586 585 (boolean_t (*)(cons_polledio_arg_t))conskbd_polledio_ischar;
587 586 conskbd.conskbd_polledio.cons_polledio_enter = conskbd_polledio_enter;
588 587 conskbd.conskbd_polledio.cons_polledio_exit = conskbd_polledio_exit;
589 588 qprocson(q);
590 589
591 590 return (0);
592 591
593 592 } /* conskbdopen() */
594 593
595 594
596 595 /*ARGSUSED*/
597 596 static int
598 597 conskbdclose(queue_t *q, int flag, cred_t *crp)
599 598 {
600 599 if (q == conskbd_regqueue) {
601 600
602 601 conskbd_pending_msg_t *pmsg, *prev, *next;
603 602 mblk_t *mp;
604 603
605 604 /* switch the input stream back to conskbd_consqueue */
606 605 conskbd.conskbd_directio = B_FALSE;
607 606
608 607 kbtrans_streams_untimeout(conskbd.conskbd_kbtrans);
609 608 kbtrans_streams_set_queue(conskbd.conskbd_kbtrans,
610 609 conskbd_consqueue);
611 610 qprocsoff(q);
612 611 conskbd_regqueue = NULL;
613 612
614 613 /*
615 614 * If there are any pending ioctls which conskbd hasn't
616 615 * responded to yet, remove them from conskbd_msg_queue.
617 616 * Otherwise, we might send the response to a nonexistent
618 617 * closed queue. Refer to: conskbd_mux_upstream_msg().
619 618 */
620 619 for (prev = NULL, pmsg = conskbd_msg_queue; pmsg != NULL;
621 620 pmsg = next) {
622 621 next = pmsg->kpm_next;
623 622 if (pmsg->kpm_upper_queue == WR(q)) {
624 623 if (prev == NULL)
625 624 conskbd_msg_queue = next;
626 625 else
627 626 prev->kpm_next = next;
628 627
629 628 while (pmsg->kpm_resp_list != NULL) {
630 629 mp = pmsg->kpm_resp_list;
631 630 pmsg->kpm_resp_list = mp->b_next;
632 631 mp->b_next = mp->b_prev = NULL;
633 632 freemsg(mp);
634 633 }
635 634 mutex_destroy(&pmsg->kpm_lock);
636 635 kmem_free(pmsg, sizeof (*pmsg));
637 636 } else {
638 637 prev = pmsg;
639 638 }
640 639 }
641 640 } else if (q == conskbd_consqueue) {
642 641 /*
643 642 * Well, this is probably a mistake, but we will permit you
644 643 * to close the path to the console if you really insist.
645 644 */
646 645 qprocsoff(q);
647 646 conskbd_consqueue = NULL;
648 647 }
649 648
650 649 return (0);
651 650
652 651 } /* conskbdclose() */
653 652
654 653 /*
655 654 * Service procedure for upper write queue.
656 655 * To make sure the order of messages, we don't process any
657 656 * message in qi_putq() routine of upper write queue, instead the
658 657 * qi_putq() routine, which is a standard putq() routine, puts all
659 658 * messages into a queue, and lets the following service procedure
660 659 * deal with all messages.
661 660 * This routine is invoked when ioctl commands are send down
662 661 * by a consumer of the keyboard device, eg, when the keyboard
663 662 * consumer tries to determine the keyboard layout type, or sets
664 663 * the led states.
665 664 */
666 665 static void
667 666 conskbduwsrv(queue_t *q)
668 667 {
669 668 mblk_t *mp;
670 669 queue_t *oldq;
671 670 enum kbtrans_message_response ret;
672 671 struct copyresp *csp;
673 672 struct freq_request *frqp;
674 673 int error;
675 674
676 675 while ((mp = getq(q)) != NULL) {
677 676
678 677 /*
679 678 * if the virtual keyboard is supported
680 679 */
681 680 if (conskbd.conskbd_bypassed == B_FALSE) {
682 681
683 682 if (conskbd_override_kbtrans(q, mp) == B_TRUE)
684 683 continue;
685 684 /*
686 685 * The conskbd driver is a psaudo driver. It has two
687 686 * devcice nodes, one is used by kernel, and the other
688 687 * is used by end-users. There are two STREAMS queues
689 688 * corresponding to the two device nodes, console queue
690 689 * and regular queue.
691 690 * In conskbd_override_kbtrans() routine, when receives
692 691 * KIOCSDIRECT ioctl, we need change the direction of
693 692 * keyboard input messages, and direct the input stream
694 693 * from keyboard into right queue. It causes this queue
695 694 * to be switched between regular queue and console
696 695 * queue. And here, in this routine, the in-parameter
697 696 * "q" can be any one of the two. Moreover, this module
698 697 * is executed in multithreaded environment, even if the
699 698 * q is switched to regular queue, it is possible that
700 699 * the in-parameter is still the console queue, and we
701 700 * need to return response to right queue.
702 701 * The response is sent to upstream by the kbtrans
703 702 * module. so we need to save the old queue, and wait
704 703 * kbtrans to proces message and to send response out,
705 704 * and then switch back to old queue.
706 705 */
707 706 oldq = kbtrans_streams_get_queue(
708 707 conskbd.conskbd_kbtrans);
709 708 kbtrans_streams_set_queue(
710 709 conskbd.conskbd_kbtrans, RD(q));
711 710 ret = kbtrans_streams_message(
712 711 conskbd.conskbd_kbtrans, mp);
713 712 kbtrans_streams_set_queue(
714 713 conskbd.conskbd_kbtrans, oldq);
715 714
716 715 switch (ret) {
717 716 case KBTRANS_MESSAGE_HANDLED:
718 717 continue;
719 718 case KBTRANS_MESSAGE_NOT_HANDLED:
720 719 break;
721 720 }
722 721 }
723 722
724 723 switch (mp->b_datap->db_type) {
725 724
726 725 case M_IOCTL:
727 726 conskbd_ioctl(q, mp);
728 727 break;
729 728
730 729 case M_FLUSH:
731 730 if (*mp->b_rptr & FLUSHW) {
732 731 flushq(q, FLUSHDATA);
733 732 }
734 733 /*
735 734 * here, if flush read queue, some key-up messages
736 735 * may be lost so that upper module or applications
737 736 * treat corresponding keys as being held down for
738 737 * ever.
739 738 */
740 739 freemsg(mp);
741 740 break;
742 741
743 742 case M_DATA:
744 743 /*
745 744 * virtual keyboard doesn't support this interface.
746 745 * only when it is disabled, we pass the message
747 746 * down to lower queue.
748 747 */
749 748 if ((conskbd.conskbd_bypassed) &&
750 749 (conskbd.conskbd_lqueue_nums > 0)) {
751 750 if (putq(conskbd.conskbd_lqueue_list->
752 751 lqs_queue, mp) != 1)
753 752 freemsg(mp);
754 753 } else {
755 754 freemsg(mp);
756 755 }
757 756 break;
758 757
759 758 case M_IOCDATA:
760 759 /*
761 760 * Only deal with copyresp to KIOCSETFREQ
762 761 * transparent ioctl now
763 762 */
764 763 csp = (struct copyresp *)mp->b_rptr;
765 764 if (csp->cp_rval) {
766 765 miocnak(q, mp, 0, EINVAL);
767 766 break;
768 767 }
769 768
770 769 error = 0;
771 770 switch (csp->cp_cmd) {
772 771 case KIOCSETFREQ:
773 772 frqp = (struct freq_request *)mp->
774 773 b_cont->b_rptr;
775 774
776 775 switch (frqp->type) {
777 776 case CONSOLE_BEEP:
778 777 error = beeper_freq(BEEP_CONSOLE,
779 778 (int)frqp->freq);
780 779 break;
781 780
782 781 case KBD_BEEP:
783 782 error = beeper_freq(BEEP_TYPE4,
784 783 (int)frqp->freq);
785 784 break;
786 785
787 786 default:
788 787 error = 1;
789 788 } /* frqp->type */
790 789
791 790 break;
792 791
793 792 default:
794 793 error = 1;
795 794 } /* csp->cp_cmd */
796 795
797 796 if (error == 0)
798 797 miocack(q, mp, 0, 0);
799 798 else
800 799 miocnak(q, mp, 0, EINVAL);
801 800
802 801 break;
803 802
804 803 default:
805 804 /*
806 805 * Pass an error message up.
807 806 */
808 807 mp->b_datap->db_type = M_ERROR;
809 808 if (mp->b_cont) {
810 809 freemsg(mp->b_cont);
811 810 mp->b_cont = NULL;
812 811 }
813 812 mp->b_rptr = mp->b_datap->db_base;
814 813 mp->b_wptr = mp->b_rptr + sizeof (char);
815 814 *mp->b_rptr = EINVAL;
816 815 qreply(q, mp);
817 816 }
818 817 } /* end of while */
819 818
820 819 } /* conskbduwsrv() */
821 820
822 821 static void
823 822 conskbd_ioctl(queue_t *q, mblk_t *mp)
824 823 {
825 824 struct iocblk *iocp;
826 825 int error = 0;
827 826
828 827 iocp = (struct iocblk *)mp->b_rptr;
829 828
830 829 switch (iocp->ioc_cmd) {
831 830
832 831 case I_LINK:
833 832 case I_PLINK:
834 833 if (conskbd.conskbd_bypassed == B_TRUE) {
835 834 /*
836 835 * A legacy keyboard can NOT be connected to conskbd together
837 836 * with other keyboards. So when a legacy keyboard is already
838 837 * linked under conkbd, we just reject all others.
839 838 */
840 839 miocnak(q, mp, 0, EAGAIN);
841 840 break;
842 841 }
843 842 qwriter(q, mp, conskbd_ioc_plink, PERIM_OUTER);
844 843 break;
845 844
846 845 case I_UNLINK:
847 846 case I_PUNLINK:
848 847 qwriter(q, mp, conskbd_ioc_punlink, PERIM_OUTER);
849 848 break;
850 849
851 850 case KIOCSKABORTEN:
852 851 /*
853 852 * Check if privileged
854 853 */
855 854 if ((error = secpolicy_sys_config(iocp->ioc_cr, B_FALSE))) {
856 855 miocnak(q, mp, 0, error);
857 856 return;
858 857 }
859 858
860 859 error = miocpullup(mp, sizeof (int));
861 860 if (error != 0) {
862 861 miocnak(q, mp, 0, error);
863 862 return;
864 863 }
865 864
866 865 abort_enable = *(int *)mp->b_cont->b_rptr;
867 866 miocack(q, mp, 0, 0);
868 867 break;
869 868
870 869 case KIOCSETFREQ:
871 870 if (iocp->ioc_count != TRANSPARENT) {
872 871 /*
873 872 * We don't support non-transparent ioctls,
874 873 * i.e. I_STR ioctls
875 874 */
876 875 miocnak(q, mp, 0, EINVAL);
877 876 } else {
878 877 /* Transparent ioctl */
879 878 mcopyin(mp, NULL, sizeof (struct freq_request), NULL);
880 879 qreply(q, mp);
881 880 }
882 881 break;
883 882
884 883 default:
885 884 if (conskbd.conskbd_bypassed == B_TRUE) {
886 885 conskbd_legacy_kbd_ioctl(q, mp);
887 886 } else {
888 887 conskbd_virtual_kbd_ioctl(q, mp);
889 888 }
890 889 }
891 890
892 891 } /* conskbd_ioctl() */
893 892
894 893
895 894 static void
896 895 conskbd_virtual_kbd_ioctl(queue_t *q, mblk_t *mp)
897 896 {
898 897 struct iocblk *iocp;
899 898 mblk_t *datap;
900 899 int cmd;
901 900 int error = 0;
902 901
903 902 iocp = (struct iocblk *)mp->b_rptr;
904 903
905 904 switch (iocp->ioc_cmd) {
906 905 case KIOCLAYOUT:
907 906 if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) {
908 907 miocnak(q, mp, 0, ENOMEM);
909 908 break;
910 909 }
911 910
912 911 if (conskbd.conskbd_layout == -1)
913 912 *(int *)datap->b_wptr = KBTRANS_USBKB_DEFAULT_LAYOUT;
914 913 else
915 914 *(int *)datap->b_wptr = conskbd.conskbd_layout;
916 915
917 916 datap->b_wptr += sizeof (int);
918 917 if (mp->b_cont)
919 918 freemsg(mp->b_cont);
920 919 mp->b_cont = datap;
921 920 miocack(q, mp, sizeof (int), 0);
922 921 break;
923 922
924 923 case KIOCSLAYOUT:
925 924 if (iocp->ioc_count != TRANSPARENT) {
926 925 miocnak(q, mp, 0, EINVAL);
927 926 break;
928 927 }
929 928 kbd_layout_bak = conskbd.conskbd_layout;
930 929 conskbd.conskbd_layout = *(intptr_t *)(mp->b_cont->b_rptr);
931 930 if (conskbd.conskbd_layout != kbd_layout_bak) {
932 931
933 932 /* notify the upper of the change event */
934 933 if ((datap = conskbd_alloc_firm_event(
935 934 KEYBOARD_LAYOUT_CHANGE,
936 935 conskbd.conskbd_layout)) != NULL) {
937 936 if (conskbd.conskbd_directio) {
938 937 putnext(conskbd_regqueue, datap);
939 938 } else {
940 939 freemsg(datap);
941 940 }
942 941 }
943 942 }
944 943 miocack(q, mp, 0, 0);
945 944 break;
946 945
947 946 case CONSOPENPOLLEDIO:
948 947 error = miocpullup(mp, sizeof (struct cons_polledio *));
949 948 if (error != 0) {
950 949 miocnak(q, mp, 0, error);
951 950 break;
952 951 }
953 952 if (conskbd.conskbd_lqueue_list == NULL) {
954 953 miocnak(q, mp, 0, EINVAL);
955 954 break;
956 955 }
957 956 conskbd_handle_downstream_msg(q, mp);
958 957 break;
959 958
960 959 case CONSCLOSEPOLLEDIO:
961 960 if (conskbd.conskbd_lqueue_list == NULL) {
962 961 miocnak(q, mp, 0, EINVAL);
963 962 break;
964 963 }
965 964 conskbd_handle_downstream_msg(q, mp);
966 965 break;
967 966
968 967 case CONSSETABORTENABLE:
969 968 /*
970 969 * To enable combined STOP-A(or F1-A) to trap into kmdb,
971 970 * the lower physical keyboard drivers are always told not
972 971 * to parse abort sequence(refer to consconfig_dacf module).
973 972 * Instead, lower drivers always send all keydown & keyup
974 973 * messages up to conskbd, so that when key STOP(or F1) is
975 974 * pressed on one keyboard and key A is pressed on another
976 975 * keyboard, the system could trap into kmdb.
977 976 *
978 977 * When we by kbtrans_streams_message() invoked kbtrans to
979 978 * handle ioctls in conskbduwsrv() routine, kbtrans module
980 979 * already handle the message though it returned to us a
981 980 * KBTRANS_MESSAGE_NOT_HANDLED. For virtual keyboard, no
982 981 * special initialization or un-initialization is needed.
983 982 * So we just return ACK to upper module.
984 983 */
985 984 miocack(q, mp, 0, 0);
986 985 break;
987 986
988 987 case KIOCCMD:
989 988 case KIOCMKTONE:
990 989 if (conskbd.conskbd_lqueue_list == NULL ||
991 990 mp->b_cont == NULL) {
992 991 miocnak(q, mp, 0, EINVAL);
993 992 break;
994 993 }
995 994 cmd = *(int *)mp->b_cont->b_rptr;
996 995 if (cmd == KBD_CMD_GETLAYOUT) {
997 996 freemsg(mp->b_cont);
998 997 datap = allocb(sizeof (int), BPRI_HI);
999 998 if (datap == NULL) {
1000 999 miocnak(q, mp, 0, ENOMEM);
1001 1000 return;
1002 1001 }
1003 1002 if (conskbd.conskbd_layout == -1)
1004 1003 *(int *)datap->b_wptr =
1005 1004 KBTRANS_USBKB_DEFAULT_LAYOUT;
1006 1005 else
1007 1006 *(int *)datap->b_wptr = conskbd.conskbd_layout;
1008 1007
1009 1008 mp->b_cont = datap;
1010 1009 miocack(q, mp, sizeof (int), 0);
1011 1010 return;
1012 1011 }
1013 1012 conskbd_handle_downstream_msg(q, mp);
1014 1013 break;
1015 1014
1016 1015 default:
1017 1016 miocnak(q, mp, 0, EINVAL);
1018 1017 break;
1019 1018 }
1020 1019
1021 1020 } /* conskbd_virtual_kbd_ioctl() */
1022 1021
1023 1022 static void
1024 1023 conskbd_legacy_kbd_ioctl(queue_t *q, mblk_t *mp)
1025 1024 {
1026 1025 conskbd_lower_queue_t *lq;
1027 1026 struct iocblk *iocp;
1028 1027 int error = 0;
1029 1028
1030 1029 iocp = (struct iocblk *)mp->b_rptr;
1031 1030
1032 1031 ASSERT(conskbd.conskbd_lqueue_nums == 1);
1033 1032 switch (iocp->ioc_cmd) {
1034 1033
1035 1034 case KIOCGDIRECT: {
1036 1035 mblk_t *datap;
1037 1036
1038 1037 if ((datap = allocb(sizeof (int), BPRI_MED)) == NULL) {
1039 1038 miocnak(q, mp, 0, ENOMEM);
1040 1039 break;
1041 1040 }
1042 1041
1043 1042 *(int *)datap->b_wptr = conskbd.conskbd_directio;
1044 1043 datap->b_wptr += sizeof (int);
1045 1044 if (mp->b_cont != NULL) {
1046 1045 freemsg(mp->b_cont);
1047 1046 mp->b_cont = NULL;
1048 1047 }
1049 1048 mp->b_cont = datap;
1050 1049 miocack(q, mp, sizeof (int), 0);
1051 1050 break;
1052 1051 }
1053 1052
1054 1053 case KIOCSDIRECT:
1055 1054 error = miocpullup(mp, sizeof (int));
1056 1055 if (error != 0) {
1057 1056 miocnak(q, mp, 0, error);
1058 1057 break;
1059 1058 }
1060 1059 conskbd.conskbd_directio = *(int *)mp->b_cont->b_rptr;
1061 1060
1062 1061 /*
1063 1062 * Pass this through, if there's something to pass
1064 1063 * it through to, so the system keyboard can reset
1065 1064 * itself.
1066 1065 */
1067 1066 if (conskbd.conskbd_lqueue_nums > 0) {
1068 1067 lq = conskbd.conskbd_lqueue_list;
1069 1068 ASSERT(lq && lq->lqs_next == NULL);
1070 1069 if (putq(lq->lqs_queue, mp) != 1) {
1071 1070 miocnak(q, mp, 0, ENOMEM);
1072 1071 return;
1073 1072 }
1074 1073 break;
1075 1074 }
1076 1075
1077 1076 miocack(q, mp, 0, 0);
1078 1077 break;
1079 1078
1080 1079 default:
1081 1080 /*
1082 1081 * Pass this through, if there's something to pass it
1083 1082 * through to; otherwise, reject it.
1084 1083 */
1085 1084 if (conskbd.conskbd_lqueue_nums > 0) {
1086 1085 lq = conskbd.conskbd_lqueue_list;
1087 1086 ASSERT(lq && lq->lqs_next == NULL);
1088 1087 if (putq(lq->lqs_queue, mp) != 1) {
1089 1088 miocnak(q, mp, 0, ENOMEM);
1090 1089 return;
1091 1090 }
1092 1091 break;
1093 1092 }
1094 1093
1095 1094 /* nobody below us; reject it */
1096 1095 miocnak(q, mp, 0, EINVAL);
1097 1096 break;
1098 1097 }
1099 1098
1100 1099 } /* conskbd_legacy_kbd_ioctl() */
1101 1100
1102 1101
1103 1102 /*
1104 1103 * Service procedure for lower write queue.
1105 1104 * Puts things on the queue below us, if it lets us.
1106 1105 */
1107 1106 static void
1108 1107 conskbdlwserv(queue_t *q)
1109 1108 {
1110 1109 register mblk_t *mp;
1111 1110
1112 1111 while (canput(q->q_next) && (mp = getq(q)) != NULL)
1113 1112 putnext(q, mp);
1114 1113
1115 1114 } /* conskbdlwserv() */
1116 1115
1117 1116 /*
1118 1117 * Put procedure for lower read queue.
1119 1118 * Pass everything up to minor device 0 if "directio" set, otherwise to minor
1120 1119 * device 1.
1121 1120 */
1122 1121 static void
1123 1122 conskbdlrput(queue_t *q, mblk_t *mp)
1124 1123 {
1125 1124 conskbd_lower_queue_t *lqs;
1126 1125 struct iocblk *iocp;
1127 1126 Firm_event *fe;
1128 1127
1129 1128 DPRINTF(PRINT_L1, PRINT_MASK_ALL, ("conskbdlrput\n"));
1130 1129
1131 1130 switch (mp->b_datap->db_type) {
1132 1131
1133 1132 case M_FLUSH:
1134 1133 if (*mp->b_rptr == FLUSHR) {
1135 1134 flushq(q, FLUSHDATA); /* XXX doesn't flush M_DELAY */
1136 1135 *mp->b_rptr &= ~FLUSHR; /* it has been flushed */
1137 1136 }
1138 1137 if (*mp->b_rptr == FLUSHW) {
1139 1138 flushq(WR(q), FLUSHDATA);
1140 1139 qreply(q, mp); /* give the read queues a crack at it */
1141 1140 } else
1142 1141 freemsg(mp);
1143 1142 break;
1144 1143
1145 1144 case M_DATA:
1146 1145 if (conskbd.conskbd_bypassed == B_FALSE) {
1147 1146
1148 1147 fe = (Firm_event *)mp->b_rptr;
1149 1148
1150 1149 /*
1151 1150 * This is a workaround.
1152 1151 *
1153 1152 * According to HID specification, there are the
1154 1153 * following keycode mapping between PS2 and USB,
1155 1154 *
1156 1155 * PS2 AT-101 keycode(29) ---> USB(49)
1157 1156 * PS2 AT-102 keycode(42) ---> USB(50)
1158 1157 *
1159 1158 * However, the two keys, AT-101(29) and AT-102(42),
1160 1159 * have the same scancode,0x2B, in PS2 scancode SET1
1161 1160 * which we are using. The Kb8042 driver always
1162 1161 * recognizes the two keys as PS2(29) so that we could
1163 1162 * not know which is being pressed or released when we
1164 1163 * receive scancode 0x2B. Fortunately, the two keys can
1165 1164 * not co-exist in a specific layout. In other words,
1166 1165 * in the table of keycode-to-symbol mapping, either
1167 1166 * entry 49 or 50 is a hole. So, if we're processing a
1168 1167 * keycode 49, we look at the entry for 49. If it's
1169 1168 * HOLE, remap the key to 50; If we're processing a 50,
1170 1169 * look at the entry for 50. If it's HOLE, we remap
1171 1170 * the key to 49.
1172 1171 */
1173 1172 if (fe->id == 49 || fe->id == 50) {
1174 1173 if (conskbd_keyindex->k_normal[50] == HOLE)
1175 1174 fe->id = 49;
1176 1175 else
1177 1176 fe->id = 50;
1178 1177 }
1179 1178
1180 1179 /*
1181 1180 * Remember key state of each key of lower physical
1182 1181 * keyboard. When a keyboard is umplumbed from conskbd,
1183 1182 * we will check all key states. By then, we will fake
1184 1183 * a KEY_RELEASED message for each key in KEY_PRESSED
1185 1184 * state. Otherwise, upper module will treat these keys
1186 1185 * as held-down for ever.
1187 1186 */
1188 1187 iocp = (struct iocblk *)mp->b_rptr;
1189 1188 lqs = (conskbd_lower_queue_t *)q->q_ptr;
1190 1189 if (fe->value)
1191 1190 lqs->lqs_key_state[fe->id] = KEY_PRESSED;
1192 1191 else
1193 1192 lqs->lqs_key_state[fe->id] = KEY_RELEASED;
1194 1193
1195 1194 kbtrans_streams_key(conskbd.conskbd_kbtrans,
1196 1195 fe->id, fe->value ? KEY_PRESSED : KEY_RELEASED);
1197 1196 freemsg(mp);
1198 1197 } else {
1199 1198 if (conskbd.conskbd_directio)
1200 1199 putnext(conskbd_regqueue, mp);
1201 1200 else if (conskbd_consqueue != NULL)
1202 1201 putnext(conskbd_consqueue, mp);
1203 1202 else
1204 1203 freemsg(mp);
1205 1204 }
1206 1205 conskbd_idle_stamp = gethrestime_sec();
1207 1206 break;
1208 1207
1209 1208 case M_IOCACK:
1210 1209 case M_IOCNAK:
1211 1210 iocp = (struct iocblk *)mp->b_rptr;
1212 1211 lqs = (conskbd_lower_queue_t *)q->q_ptr;
1213 1212
1214 1213 DPRINTF(PRINT_L1, PRINT_MASK_ALL, ("conskbdlrput: "
1215 1214 "ACK/NAK - cmd 0x%x\n", iocp->ioc_cmd));
1216 1215
1217 1216 conskbd_lqs_ack_complete(lqs, mp);
1218 1217 break;
1219 1218
1220 1219 case M_ERROR:
1221 1220 case M_HANGUP:
1222 1221 default:
1223 1222 freemsg(mp); /* anything useful here? */
1224 1223 break;
1225 1224 }
1226 1225
1227 1226 } /* conskbdlrput() */
1228 1227
1229 1228
1230 1229 /* ARGSUSED */
1231 1230 static int
1232 1231 conskbd_kstat_update(kstat_t *ksp, int rw)
1233 1232 {
1234 1233 if (rw == KSTAT_WRITE)
1235 1234 return (EACCES);
1236 1235
1237 1236 conskbd_kstat.idle_sec.value.l = gethrestime_sec() - conskbd_idle_stamp;
1238 1237
1239 1238 return (0);
1240 1239
1241 1240 } /* conskbd_kstat_update() */
1242 1241
1243 1242 /*
1244 1243 * STREAMS architecuture provides guarantee that the ID of each
1245 1244 * message, iocblk.ioc_id, in a stream is unique. The following
1246 1245 * routine performes the task: When receive request from upstream,
1247 1246 * it saves the request in a global link list, clones the request,
1248 1247 * and then sends a copy of the request to each of lower queues
1249 1248 * which are plumbed into conskbd. And then, when receives responses
1250 1249 * from lower queues in conskbdlrput() routine, we can know the
1251 1250 * request matching received responses by searching the global linked
1252 1251 * list to find the request which has the same message ID of the
1253 1252 * response. Then, when all lower queues response this request, we
1254 1253 * give a response to upstreams based the following policy:
1255 1254 * If any one of lower queues acks our reuqest, then we return ack
1256 1255 * to upstreams; only if all lower queues nak our request, we return
1257 1256 * nak to upstreams. If all responses are nak, the error number of
1258 1257 * the first response is sent to upstream.
1259 1258 */
1260 1259 static void
1261 1260 conskbd_handle_downstream_msg(queue_t *q, mblk_t *mp)
1262 1261 {
1263 1262 conskbd_pending_msg_t *msg;
1264 1263 conskbd_lower_queue_t *lqs;
1265 1264 struct iocblk *iocp;
1266 1265 mblk_t *clonemp;
1267 1266 int retry;
1268 1267
1269 1268 if (conskbd.conskbd_lqueue_nums == 0) {
1270 1269 miocnak(q, mp, 0, EINVAL);
1271 1270 return;
1272 1271 }
1273 1272
1274 1273 msg = (conskbd_pending_msg_t *)
1275 1274 kmem_zalloc(sizeof (conskbd_pending_msg_t), KM_SLEEP);
1276 1275 mutex_init(&msg->kpm_lock, NULL, MUTEX_DRIVER, NULL);
1277 1276 lqs = conskbd.conskbd_lqueue_list;
1278 1277 iocp = (struct iocblk *)mp->b_rptr;
1279 1278
1280 1279 ASSERT(iocp->ioc_cmd == CONSOPENPOLLEDIO ||
1281 1280 iocp->ioc_cmd == CONSCLOSEPOLLEDIO ||
1282 1281 iocp->ioc_cmd == KIOCCMD ||
1283 1282 iocp->ioc_cmd == KIOCMKTONE);
1284 1283
1285 1284 msg->kpm_upper_queue = q;
1286 1285 msg->kpm_req_msg = mp;
1287 1286 msg->kpm_req_id = iocp->ioc_id;
1288 1287 msg->kpm_req_cmd = iocp->ioc_cmd;
1289 1288 msg->kpm_req_nums = conskbd.conskbd_lqueue_nums;
1290 1289 conskbd_mux_enqueue_msg(msg);
1291 1290
1292 1291 for (retry = 0, lqs = conskbd.conskbd_lqueue_list; lqs; ) {
1293 1292
1294 1293 /*
1295 1294 * if a lower physical keyboard is not in polled I/O
1296 1295 * mode, we couldn't send CONSCLOSEPOLLEDIO to it,
1297 1296 * otherwise, system will panic.
1298 1297 */
1299 1298 if (iocp->ioc_cmd == CONSCLOSEPOLLEDIO &&
1300 1299 lqs->lqs_polledio == NULL) {
1301 1300 lqs = lqs->lqs_next;
1302 1301 msg->kpm_req_nums --;
1303 1302 retry = 0;
1304 1303 continue;
1305 1304 }
1306 1305
1307 1306 clonemp = copymsg(mp);
1308 1307 if (clonemp != NULL) {
1309 1308 if (putq(lqs->lqs_queue, clonemp) == 1) {
1310 1309 lqs = lqs->lqs_next;
1311 1310 retry = 0;
1312 1311 continue;
1313 1312 }
1314 1313
1315 1314 /*
1316 1315 * failed to invoke putq(), retry.
1317 1316 */
1318 1317 freemsg(clonemp);
1319 1318 }
1320 1319
1321 1320 /*
1322 1321 * During testing it was observed that occasionally
1323 1322 * copymsg() would fail during boot. The reason for
1324 1323 * these failures is unknown. Since we really want
1325 1324 * to successfully plumb up all the attached keyboards
1326 1325 * during boot we do a best effort here by retrying
1327 1326 * the copymsg() call in the hopes that it will
1328 1327 * succeeded upon subsequent invocations.
1329 1328 *
1330 1329 * If all the calls to copymsg() fails, it will cause
1331 1330 * the corresponding keyboard to be unavailable, or
1332 1331 * or behave weirdly,
1333 1332 *
1334 1333 * 1) for CONSOPENPOLLEDIO
1335 1334 * if copymsg()fails, the corresponding keyboard
1336 1335 * is not available in polled I/O mode once
1337 1336 * entering kmdb;
1338 1337 * 2) for CONSCLOSEPOLLEDIO
1339 1338 * if copymsg() fails, the corresponding keyboard
1340 1339 * is not available in normal mode once returning
1341 1340 * from kmdb;
1342 1341 * 3) for KIOCCMD
1343 1342 * 3.1) for KBD_CMD_NOBELL
1344 1343 * there's no beep in USB and PS2 keyboard,
1345 1344 * this ioctl actually disables the beep on
1346 1345 * system mainboard. Note that all the cloned
1347 1346 * messages sent down to lower queues do the
1348 1347 * same job for system mainboard. Therefore,
1349 1348 * even if we fail to send this ioctl to most
1350 1349 * of lower queues, the beep still would be
1351 1350 * disabled. So, no trouble exists here.
1352 1351 * 3.2) for others
1353 1352 * nothing;
1354 1353 *
1355 1354 * However, all cases could be resume next time when the
1356 1355 * same request comes again.
1357 1356 */
1358 1357 if (retry ++ >= 5) {
1359 1358 dev_t devt;
1360 1359 char path[MAXPATHLEN + 1];
1361 1360
1362 1361 devt = lqs->lqs_queue->q_stream->sd_vnode->v_rdev;
1363 1362 switch (iocp->ioc_cmd) {
1364 1363 case CONSOPENPOLLEDIO:
1365 1364 if (ddi_dev_pathname(devt, S_IFCHR,
1366 1365 path) == DDI_SUCCESS)
1367 1366 cmn_err(CE_WARN, "conskbd: "
1368 1367 "keyboard is not available"
1369 1368 " for system debugging: %s",
1370 1369 path);
1371 1370 break;
1372 1371
1373 1372 case CONSCLOSEPOLLEDIO:
1374 1373 if (ddi_dev_pathname(devt, S_IFCHR,
1375 1374 path) == DDI_SUCCESS)
1376 1375 cmn_err(CE_WARN, "conskbd: "
1377 1376 "keyboard is not available:"
1378 1377 " %s", path);
1379 1378 break;
1380 1379
1381 1380 default:
1382 1381 break;
1383 1382 }
1384 1383 msg->kpm_req_nums --;
1385 1384 lqs = lqs->lqs_next;
1386 1385 retry = 0;
1387 1386 }
1388 1387 }
1389 1388
1390 1389 if (msg->kpm_req_nums == 0) {
1391 1390 conskbd_mux_dequeue_msg(msg);
1392 1391 kmem_free(msg, sizeof (*msg));
1393 1392 miocnak(q, mp, 0, ENOMEM);
1394 1393 }
1395 1394
1396 1395 } /* conskbd_handle_downstream_msg() */
1397 1396
1398 1397
1399 1398 static void
1400 1399 conskbd_ioc_plink(queue_t *q, mblk_t *mp)
1401 1400 {
1402 1401 mblk_t *req;
1403 1402 queue_t *lowque;
1404 1403 struct linkblk *linkp;
1405 1404 conskbd_lower_queue_t *lqs;
1406 1405
1407 1406 lqs = kmem_zalloc(sizeof (*lqs), KM_SLEEP);
1408 1407 ASSERT(lqs->lqs_state == LQS_UNINITIALIZED);
1409 1408
1410 1409 linkp = (struct linkblk *)mp->b_cont->b_rptr;
1411 1410 lowque = linkp->l_qbot;
1412 1411
1413 1412 lqs->lqs_queue = lowque;
1414 1413 lqs->lqs_pending_plink = mp;
1415 1414 lqs->lqs_pending_queue = q;
1416 1415
1417 1416 req = mkiocb(CONSSETKBDTYPE);
1418 1417 if (req == NULL) {
1419 1418 miocnak(q, mp, 0, ENOMEM);
1420 1419 kmem_free(lqs, sizeof (*lqs));
1421 1420 return;
1422 1421 }
1423 1422
1424 1423 req->b_cont = allocb(sizeof (int), BPRI_MED);
1425 1424 if (req->b_cont == NULL) {
1426 1425 freemsg(req);
1427 1426 miocnak(q, mp, 0, ENOMEM);
1428 1427 kmem_free(lqs, sizeof (*lqs));
1429 1428 return;
1430 1429 }
1431 1430
1432 1431 lowque->q_ptr = lqs;
1433 1432 OTHERQ(lowque)->q_ptr = lqs;
1434 1433 *(int *)req->b_cont->b_wptr = KB_USB;
1435 1434 req->b_cont->b_wptr += sizeof (int);
1436 1435
1437 1436 lqs->lqs_state = LQS_KIOCTYPE_ACK_PENDING;
1438 1437
1439 1438 if (putq(lowque, req) != 1) {
1440 1439 freemsg(req);
1441 1440 miocnak(lqs->lqs_pending_queue,
1442 1441 lqs->lqs_pending_plink, 0, ENOMEM);
1443 1442 lowque->q_ptr = NULL;
1444 1443 OTHERQ(lowque)->q_ptr = NULL;
1445 1444 kmem_free(lqs, sizeof (*lqs));
1446 1445 }
1447 1446
1448 1447 } /* conskbd_ioc_plink() */
1449 1448
1450 1449
1451 1450 static void
1452 1451 conskbd_ioc_punlink(queue_t *q, mblk_t *mp)
1453 1452 {
1454 1453 int index;
1455 1454 struct linkblk *linkp;
1456 1455 conskbd_lower_queue_t *lqs;
1457 1456 conskbd_lower_queue_t *prev;
1458 1457
1459 1458 linkp = (struct linkblk *)mp->b_cont->b_rptr;
1460 1459 prev = conskbd.conskbd_lqueue_list;
1461 1460 for (lqs = prev; lqs; lqs = lqs->lqs_next) {
1462 1461 if (lqs->lqs_queue == linkp->l_qbot) {
1463 1462 if (prev == lqs)
1464 1463 conskbd.conskbd_lqueue_list =
1465 1464 lqs->lqs_next;
1466 1465 else
1467 1466 prev->lqs_next = lqs->lqs_next;
1468 1467
1469 1468 lqs->lqs_queue->q_ptr = NULL;
1470 1469 OTHERQ(lqs->lqs_queue)->q_ptr = NULL;
1471 1470 conskbd.conskbd_lqueue_nums --;
1472 1471 if (conskbd.conskbd_lqueue_nums == 0) {
1473 1472 kbd_layout_bak = conskbd.conskbd_layout;
1474 1473 conskbd.conskbd_layout = -1;
1475 1474 }
1476 1475
1477 1476 for (index = 0; index < KBTRANS_KEYNUMS_MAX; index ++) {
1478 1477 if (lqs->lqs_key_state[index] == KEY_PRESSED)
1479 1478 kbtrans_streams_key(
1480 1479 conskbd.conskbd_kbtrans,
1481 1480 index,
1482 1481 KEY_RELEASED);
1483 1482 }
1484 1483
1485 1484 kmem_free(lqs, sizeof (*lqs));
1486 1485 miocack(q, mp, 0, 0);
1487 1486 return;
1488 1487 }
1489 1488 prev = lqs;
1490 1489 }
1491 1490 miocnak(q, mp, 0, EINVAL);
1492 1491
1493 1492 } /* conskbd_ioc_punlink() */
1494 1493
1495 1494 /*
1496 1495 * Every physical keyboard has a corresponding STREAMS queue. We call this
1497 1496 * queue lower queue. Every lower queue has a state, refer to conskbd.h file
1498 1497 * about "enum conskbd_lqs_state".
1499 1498 * The following routine is used to handle response messages from lower queue.
1500 1499 * When receiving ack/nak message from lower queue(s), the routine determines
1501 1500 * the passage for it according to the current state of this lower queue.
1502 1501 */
1503 1502 static void
1504 1503 conskbd_lqs_ack_complete(conskbd_lower_queue_t *lqs, mblk_t *mp)
1505 1504 {
1506 1505 switch (lqs->lqs_state) {
1507 1506
1508 1507 /* S6: working in virtual keyboard mode, multi-keyboards are usable */
1509 1508 case LQS_INITIALIZED:
1510 1509 conskbd_mux_upstream_msg(lqs, mp);
1511 1510 break;
1512 1511
1513 1512 /* S5: working in legacy mode, only one keyboard is usable */
1514 1513 case LQS_INITIALIZED_LEGACY:
1515 1514 conskbd_legacy_upstream_msg(lqs, mp);
1516 1515 break;
1517 1516
1518 1517 /* S4: wait lower queue to acknowledge KIOCSLED/KIOCGLED message */
1519 1518 case LQS_KIOCSLED_ACK_PENDING:
1520 1519 conskbd_kiocsled_complete(lqs, mp);
1521 1520 break;
1522 1521
1523 1522 /* S3: wait lower queue to acknowledge KIOCLAYOUT message */
1524 1523 case LQS_KIOCLAYOUT_ACK_PENDING:
1525 1524 conskbd_kioclayout_complete(lqs, mp);
1526 1525 break;
1527 1526
1528 1527 /* S2: wait lower queue to acknowledge KIOCTRANS message */
1529 1528 case LQS_KIOCTRANS_ACK_PENDING:
1530 1529 conskbd_kioctrans_complete(lqs, mp);
1531 1530 break;
1532 1531
1533 1532 /* S1: wait lower queue to acknowledge KIOCTYPE message */
1534 1533 case LQS_KIOCTYPE_ACK_PENDING:
1535 1534 conskbd_kioctype_complete(lqs, mp);
1536 1535 break;
1537 1536
1538 1537 /* if reaching here, there must be a error */
1539 1538 default:
1540 1539 freemsg(mp);
1541 1540 cmn_err(CE_WARN, "conskbd: lqs_ack_complete() state error");
1542 1541 break;
1543 1542 }
1544 1543
1545 1544 } /* conskbd_lqs_ack_complete() */
1546 1545
1547 1546
1548 1547 static void
1549 1548 conskbd_kioctype_complete(conskbd_lower_queue_t *lqs, mblk_t *mp)
1550 1549 {
1551 1550 struct iocblk *iocp;
1552 1551 mblk_t *req;
1553 1552 queue_t *lowerque;
1554 1553 int err = ENOMEM;
1555 1554
1556 1555 ASSERT(lqs->lqs_pending_plink);
1557 1556 ASSERT(lqs->lqs_state == LQS_KIOCTYPE_ACK_PENDING);
1558 1557
1559 1558 lowerque = lqs->lqs_queue;
1560 1559
1561 1560 switch (mp->b_datap->db_type) {
1562 1561 case M_IOCACK:
1563 1562 req = mkiocb(KIOCTRANS);
1564 1563 if (req == NULL) {
1565 1564 goto err_exit;
1566 1565 }
1567 1566
1568 1567 req->b_cont = allocb(sizeof (int), BPRI_MED);
1569 1568 if (req->b_cont == NULL) {
1570 1569 freemsg(req);
1571 1570 goto err_exit;
1572 1571 }
1573 1572
1574 1573 /* Set the translate mode to TR_UNTRANS_EVENT */
1575 1574 *(int *)req->b_cont->b_wptr = TR_UNTRANS_EVENT;
1576 1575 req->b_cont->b_wptr += sizeof (int);
1577 1576
1578 1577 /* Ready to handle the response to KIOCTRANS */
1579 1578 lqs->lqs_state = LQS_KIOCTRANS_ACK_PENDING;
1580 1579
1581 1580 if (putq(lowerque, req) != 1) {
1582 1581 freemsg(req);
1583 1582 goto err_exit;
1584 1583 }
1585 1584 freemsg(mp);
1586 1585 return;
1587 1586
1588 1587 case M_IOCNAK:
1589 1588 /*
1590 1589 * The lower keyboard driver can't mimic USB keyboard,
1591 1590 * that's say, the physical keyboard is an old one, such
1592 1591 * as TYPE 3/4/5 one. In this case, the virtual keyboard
1593 1592 * is disabled, and the data from lower keyboard driver
1594 1593 * will bypass the conskbd module.
1595 1594 */
1596 1595
1597 1596 /*
1598 1597 * if there is any other keyborad already linked under the
1599 1598 * conskbd, we reject the current one.
1600 1599 */
1601 1600 if (conskbd.conskbd_lqueue_nums > 0) {
1602 1601 iocp = (struct iocblk *)mp->b_rptr;
1603 1602 err = iocp->ioc_error;
1604 1603 goto err_exit;
1605 1604 }
1606 1605
1607 1606 /*
1608 1607 * link this keyboard under conskbd.
1609 1608 */
1610 1609 qwriter(lowerque, mp, conskbd_link_lowque_legacy, PERIM_OUTER);
1611 1610 return;
1612 1611 }
1613 1612
1614 1613 err_exit:
1615 1614 miocnak(lqs->lqs_pending_queue, lqs->lqs_pending_plink, 0, err);
1616 1615 lowerque->q_ptr = NULL;
1617 1616 OTHERQ(lowerque)->q_ptr = NULL;
1618 1617 kmem_free(lqs, sizeof (*lqs));
1619 1618 freemsg(mp);
1620 1619
1621 1620 } /* conskbd_kioctype_complete() */
1622 1621
1623 1622 static void
1624 1623 conskbd_kioctrans_complete(conskbd_lower_queue_t *lqs, mblk_t *mp)
1625 1624 {
1626 1625 struct iocblk *iocp;
1627 1626 mblk_t *req;
1628 1627 queue_t *lowerque;
1629 1628 int err = ENOMEM;
1630 1629
1631 1630 ASSERT(lqs->lqs_pending_plink != NULL);
1632 1631 ASSERT(lqs->lqs_state == LQS_KIOCTRANS_ACK_PENDING);
1633 1632
1634 1633 lowerque = lqs->lqs_queue;
1635 1634
1636 1635 switch (mp->b_datap->db_type) {
1637 1636 case M_IOCACK:
1638 1637 req = mkiocb(KIOCLAYOUT);
1639 1638 if (req == NULL) {
1640 1639 goto err_exit;
1641 1640 }
1642 1641
1643 1642 req->b_cont = allocb(sizeof (int), BPRI_MED);
1644 1643 if (req->b_cont == NULL) {
1645 1644 freemsg(req);
1646 1645 goto err_exit;
1647 1646 }
1648 1647
1649 1648 /* waiting for response to KIOCLAYOUT */
1650 1649 lqs->lqs_state = LQS_KIOCLAYOUT_ACK_PENDING;
1651 1650 if (putq(lqs->lqs_queue, req) != 1) {
1652 1651 freemsg(req);
1653 1652 goto err_exit;
1654 1653 }
1655 1654 freemsg(mp);
1656 1655 return;
1657 1656
1658 1657 case M_IOCNAK:
1659 1658 iocp = (struct iocblk *)mp->b_rptr;
1660 1659 err = iocp->ioc_error;
1661 1660 goto err_exit;
1662 1661 }
1663 1662
1664 1663 err_exit:
1665 1664 miocnak(lqs->lqs_pending_queue, lqs->lqs_pending_plink, 0, err);
1666 1665 lowerque->q_ptr = NULL;
1667 1666 OTHERQ(lowerque)->q_ptr = NULL;
1668 1667 kmem_free(lqs, sizeof (*lqs));
1669 1668 freemsg(mp);
1670 1669
1671 1670 } /* conskbd_kioctrans_complete() */
1672 1671
1673 1672 /*
1674 1673 * Allocate a firm event
1675 1674 */
1676 1675 static mblk_t *
1677 1676 conskbd_alloc_firm_event(ushort_t id, int value)
1678 1677 {
1679 1678 mblk_t *mb;
1680 1679 Firm_event *fe;
1681 1680
1682 1681 if ((mb = allocb(sizeof (Firm_event), BPRI_HI)) != NULL) {
1683 1682 fe = (Firm_event *)mb->b_wptr;
1684 1683 fe->id = id;
1685 1684 fe->pair_type = FE_PAIR_NONE;
1686 1685 fe->pair = NULL;
1687 1686 fe->value = value;
1688 1687 mb->b_wptr += sizeof (Firm_event);
1689 1688 }
1690 1689
1691 1690 return (mb);
1692 1691 }
1693 1692
1694 1693 static void
1695 1694 conskbd_kioclayout_complete(conskbd_lower_queue_t *lqs, mblk_t *mp)
1696 1695 {
1697 1696 mblk_t *req;
1698 1697 int layout;
1699 1698 boolean_t fail;
1700 1699
1701 1700 ASSERT(lqs->lqs_pending_plink != NULL);
1702 1701 ASSERT(lqs->lqs_state == LQS_KIOCLAYOUT_ACK_PENDING);
1703 1702
1704 1703 switch (mp->b_datap->db_type) {
1705 1704 case M_IOCACK:
1706 1705 if (miocpullup(mp, sizeof (int)) == 0) {
1707 1706 layout = *(int *)mp->b_cont->b_rptr;
1708 1707 /*
1709 1708 * We just accept the layout of the first keyboard
1710 1709 * requesting to be linked under conskbd. If current
1711 1710 * keyboard is the first one, and if we get right
1712 1711 * layout from it, we set conskbd's layout
1713 1712 */
1714 1713 if (layout != -1 && conskbd.conskbd_layout == -1) {
1715 1714 if (layout == 0) {
1716 1715 conskbd.conskbd_layout = kbd_layout_bak;
1717 1716 } else {
1718 1717 conskbd.conskbd_layout = layout;
1719 1718 if (layout == kbd_layout_bak) {
1720 1719 break;
1721 1720 }
1722 1721 if ((req = conskbd_alloc_firm_event(
1723 1722 KEYBOARD_LAYOUT_CHANGE,
1724 1723 layout)) != NULL) {
1725 1724 if (conskbd.conskbd_directio) {
1726 1725 putnext(
1727 1726 conskbd_regqueue,
1728 1727 req);
1729 1728 } else if (conskbd_consqueue
1730 1729 != NULL) {
1731 1730 putnext(
1732 1731 conskbd_consqueue,
1733 1732 req);
1734 1733 } else {
1735 1734 freemsg(req);
1736 1735 }
1737 1736 }
1738 1737 }
1739 1738 }
1740 1739 }
1741 1740 break;
1742 1741
1743 1742
1744 1743 /* if fail, leave conskbd's layout as it is */
1745 1744 case M_IOCNAK:
1746 1745 break;
1747 1746 }
1748 1747
1749 1748 fail = B_TRUE;
1750 1749
1751 1750 if (conskbd.conskbd_led_state == -1)
1752 1751 req = mkiocb(KIOCGLED);
1753 1752 else
1754 1753 req = mkiocb(KIOCSLED);
1755 1754
1756 1755 if (req) {
1757 1756 req->b_cont = allocb(sizeof (uchar_t), BPRI_MED);
1758 1757 if (req->b_cont) {
1759 1758 if (conskbd.conskbd_led_state != -1) {
1760 1759 *(uchar_t *)req->b_cont->b_wptr =
1761 1760 conskbd.conskbd_led_state;
1762 1761 req->b_cont->b_wptr += sizeof (uchar_t);
1763 1762 }
1764 1763
1765 1764 /* waiting for response to KIOCSLED */
1766 1765 lqs->lqs_state = LQS_KIOCSLED_ACK_PENDING;
1767 1766 if (putq(lqs->lqs_queue, req) == 1) {
1768 1767 fail = B_FALSE;
1769 1768 } else {
1770 1769 freemsg(req);
1771 1770 }
1772 1771
1773 1772 } else {
1774 1773 freemsg(req);
1775 1774 }
1776 1775 }
1777 1776
1778 1777 if (fail) {
1779 1778 /*
1780 1779 * If fail to allocate KIOCSLED/KIOCGLED message or put
1781 1780 * the message into lower queue, we immediately link
1782 1781 * current keyboard under conskbd. Thus, even if fails
1783 1782 * to set/get LED, this keyboard could be available.
1784 1783 */
1785 1784 qwriter(lqs->lqs_queue,
1786 1785 mp, conskbd_link_lowque_virt, PERIM_OUTER);
1787 1786 } else {
1788 1787 freemsg(mp);
1789 1788 }
1790 1789
1791 1790 } /* conskbd_kioclayout_complete() */
1792 1791
1793 1792
1794 1793 static void
1795 1794 conskbd_kiocsled_complete(conskbd_lower_queue_t *lqs, mblk_t *mp)
1796 1795 {
1797 1796 int led_state;
1798 1797
1799 1798 ASSERT(lqs->lqs_pending_plink != NULL);
1800 1799 ASSERT(lqs->lqs_state == LQS_KIOCSLED_ACK_PENDING);
1801 1800
1802 1801 if (conskbd.conskbd_led_state == -1) {
1803 1802 switch (mp->b_datap->db_type) {
1804 1803 case M_IOCACK:
1805 1804 if (miocpullup(mp, sizeof (uchar_t)) == 0) {
1806 1805 led_state = *(uchar_t *)mp->b_cont->b_rptr;
1807 1806 conskbd.conskbd_led_state = led_state;
1808 1807 kbtrans_streams_setled(conskbd.conskbd_kbtrans,
1809 1808 led_state);
1810 1809 }
1811 1810 break;
1812 1811
1813 1812 /* if fail, leave conskbd's led_state as it is */
1814 1813 case M_IOCNAK:
1815 1814 break;
1816 1815 }
1817 1816 }
1818 1817
1819 1818 /*
1820 1819 * Basically, failure of setting/getting LED is not a fatal
1821 1820 * error, so we will plumb the lower queue into conskbd whether
1822 1821 * setting/getting LED succeeds or fails.
1823 1822 */
1824 1823 qwriter(lqs->lqs_queue, mp, conskbd_link_lowque_virt, PERIM_OUTER);
1825 1824
1826 1825 } /* conskbd_kiocsled_complete() */
1827 1826
1828 1827
1829 1828 static void
1830 1829 conskbd_mux_upstream_msg(conskbd_lower_queue_t *lqs, mblk_t *mp)
1831 1830 {
1832 1831 conskbd_pending_msg_t *msg;
1833 1832 struct iocblk *iocp;
1834 1833 int error;
1835 1834 dev_t devt;
1836 1835 char path[MAXPATHLEN + 1];
1837 1836
1838 1837 ASSERT(lqs->lqs_state == LQS_INITIALIZED);
1839 1838 msg = conskbd_mux_find_msg(mp);
1840 1839
1841 1840 if (!msg) {
1842 1841 /*
1843 1842 * Here we discard the response if:
1844 1843 *
1845 1844 * 1. It's an KIOCSLED request; see conskbd_streams_setled().
1846 1845 * 2. The application has already closed the upper stream;
1847 1846 * see conskbdclose()
1848 1847 */
1849 1848 freemsg(mp);
1850 1849 return;
1851 1850 }
1852 1851
1853 1852 /*
1854 1853 * We use the b_next field of mblk_t structure to link all
1855 1854 * response coming from lower queues into a linkage list,
1856 1855 * and make use of the b_prev field to save a pointer to
1857 1856 * the lower queue from which the current response message
1858 1857 * comes.
1859 1858 */
1860 1859 ASSERT(mp->b_next == NULL && mp->b_prev == NULL);
1861 1860 mutex_enter(&msg->kpm_lock);
1862 1861 mp->b_next = msg->kpm_resp_list;
1863 1862 mp->b_prev = (mblk_t *)lqs;
1864 1863 msg->kpm_resp_list = mp;
1865 1864 msg->kpm_resp_nums ++;
1866 1865
1867 1866 if (msg->kpm_resp_nums < msg->kpm_req_nums) {
1868 1867 mutex_exit(&msg->kpm_lock);
1869 1868 return;
1870 1869 }
1871 1870
1872 1871 ASSERT(msg->kpm_resp_nums == msg->kpm_req_nums);
1873 1872 ASSERT(mp == msg->kpm_resp_list);
1874 1873
1875 1874 mutex_exit(&msg->kpm_lock);
1876 1875
1877 1876 conskbd_mux_dequeue_msg(msg);
1878 1877
1879 1878
1880 1879 /*
1881 1880 * Here, we have the policy that, if any one lower queue ACK
1882 1881 * our reuqest, then we return ACK to upstreams; only if all
1883 1882 * lower queues NAK our request, we return NAK to upstreams.
1884 1883 * if all responses are nak, the errno of the first response
1885 1884 * is sent to upstreams
1886 1885 */
1887 1886 ASSERT(mp->b_rptr);
1888 1887 error = ((struct iocblk *)mp->b_rptr)->ioc_error;
1889 1888
1890 1889 switch (msg->kpm_req_cmd) {
1891 1890 case CONSOPENPOLLEDIO:
1892 1891 /*
1893 1892 * Here, we can safely ignore the NAK message. If any one lower
1894 1893 * queue returns NAK, the pointer to the corresponding polledio
1895 1894 * structure will remain null, that's say lqs->lqs_polledio =
1896 1895 * null. When we need to invoke polled I/O interface, we will
1897 1896 * check if the pointer is null.
1898 1897 */
1899 1898 for (mp = msg->kpm_resp_list; mp; ) {
1900 1899 cons_polledio_t *polledio;
1901 1900
1902 1901 msg->kpm_resp_list = mp->b_next;
1903 1902 lqs = (conskbd_lower_queue_t *)mp->b_prev;
1904 1903 devt = lqs->lqs_queue->q_stream->sd_vnode->v_rdev;
1905 1904 if (mp->b_datap->db_type == M_IOCACK) {
1906 1905 polledio = *(struct cons_polledio **)
1907 1906 mp->b_cont->b_rptr;
1908 1907 if (polledio->cons_polledio_version ==
1909 1908 CONSPOLLEDIO_V1) {
1910 1909 lqs->lqs_polledio = polledio;
1911 1910 error = 0;
1912 1911 } else {
1913 1912 /*
1914 1913 * USB and PS2 keyboard drivers should
1915 1914 * use the same cons_polledio structure
1916 1915 * as conskbd.
1917 1916 */
1918 1917 if (ddi_dev_pathname(devt, S_IFCHR,
1919 1918 path) == DDI_SUCCESS) {
1920 1919 cmn_err(CE_WARN, "keyboard "
1921 1920 "driver does not support "
1922 1921 "system debugging: %s",
1923 1922 path);
1924 1923 }
1925 1924 error = EINVAL;
1926 1925 }
1927 1926 } else {
1928 1927 if (ddi_dev_pathname(devt, S_IFCHR, path) ==
1929 1928 DDI_SUCCESS) {
1930 1929 cmn_err(CE_WARN, "conskbd: keyboard is"
1931 1930 " not available for system"
1932 1931 " debugging: %s", path);
1933 1932 }
1934 1933 }
1935 1934 mp->b_next = NULL;
1936 1935 mp->b_prev = NULL;
1937 1936 freemsg(mp);
1938 1937 mp = msg->kpm_resp_list;
1939 1938 }
1940 1939
1941 1940 mp = msg->kpm_req_msg;
1942 1941 if (error == 0) {
1943 1942 *(struct cons_polledio **)mp->b_cont->b_rptr =
1944 1943 &conskbd.conskbd_polledio;
1945 1944 }
1946 1945 break;
1947 1946
1948 1947 case CONSCLOSEPOLLEDIO:
1949 1948 for (mp = msg->kpm_resp_list; mp; ) {
1950 1949 msg->kpm_resp_list = mp->b_next;
1951 1950 lqs = (conskbd_lower_queue_t *)mp->b_prev;
1952 1951 if (mp->b_datap->db_type == M_IOCACK) {
1953 1952 lqs->lqs_polledio = NULL;
1954 1953 error = 0;
1955 1954 } else {
1956 1955 devt =
1957 1956 lqs->lqs_queue->q_stream->sd_vnode->v_rdev;
1958 1957
1959 1958 if (ddi_dev_pathname(devt, S_IFCHR, path) ==
1960 1959 DDI_SUCCESS) {
1961 1960 cmn_err(CE_WARN, "conskbd: keyboard is"
1962 1961 " not available: %s", path);
1963 1962 }
1964 1963 }
1965 1964
1966 1965 mp->b_next = NULL;
1967 1966 mp->b_prev = NULL;
1968 1967 freemsg(mp);
1969 1968 mp = msg->kpm_resp_list;
1970 1969 }
1971 1970 break;
1972 1971
1973 1972 case KIOCCMD:
1974 1973 case KIOCMKTONE:
1975 1974 for (mp = msg->kpm_resp_list; mp; ) {
1976 1975 msg->kpm_resp_list = mp->b_next;
1977 1976
1978 1977 if (mp->b_datap->db_type == M_IOCACK)
1979 1978 error = 0;
1980 1979 mp->b_next = NULL;
1981 1980 mp->b_prev = NULL;
1982 1981 freemsg(mp);
1983 1982 mp = msg->kpm_resp_list;
1984 1983 }
1985 1984 break;
1986 1985
1987 1986 default: /* it is impossible to reach here */
1988 1987 cmn_err(CE_WARN, "conskbd: unexpected ioctl reply");
1989 1988 }
1990 1989
1991 1990 mp = msg->kpm_req_msg;
1992 1991 if (error == 0) {
1993 1992 mp->b_datap->db_type = M_IOCACK;
1994 1993 } else {
1995 1994 mp->b_datap->db_type = M_IOCNAK;
1996 1995 }
1997 1996 iocp = (struct iocblk *)mp->b_rptr;
1998 1997 iocp->ioc_error = error;
1999 1998 qreply(msg->kpm_upper_queue, mp);
2000 1999 mutex_destroy(&msg->kpm_lock);
2001 2000 kmem_free(msg, sizeof (*msg));
2002 2001
2003 2002 } /* conskbd_mux_upstream_msg() */
2004 2003
2005 2004 static void
2006 2005 conskbd_link_lowque_legacy(queue_t *lowque, mblk_t *mp)
2007 2006 {
2008 2007 conskbd_lower_queue_t *lqs;
2009 2008
2010 2009 freemsg(mp);
2011 2010
2012 2011 /*
2013 2012 * Bypass the virutal keyboard for old hardware,
2014 2013 * Now, only current legacy keyboard can be linked
2015 2014 * under conskbd
2016 2015 */
2017 2016 conskbd.conskbd_bypassed = B_TRUE;
2018 2017
2019 2018 /*
2020 2019 * Link the lower queue under conskbd
2021 2020 */
2022 2021 lqs = (conskbd_lower_queue_t *)lowque->q_ptr;
2023 2022 lqs->lqs_state = LQS_INITIALIZED_LEGACY;
2024 2023 lqs->lqs_next = conskbd.conskbd_lqueue_list;
2025 2024 conskbd.conskbd_lqueue_list = lqs;
2026 2025 conskbd.conskbd_lqueue_nums++;
2027 2026
2028 2027 mioc2ack(lqs->lqs_pending_plink, NULL, 0, 0);
2029 2028 qreply(lqs->lqs_pending_queue, lqs->lqs_pending_plink);
2030 2029
2031 2030 } /* conskbd_link_lowque_legacy() */
2032 2031
2033 2032 static void
2034 2033 conskbd_link_lowque_virt(queue_t *lowque, mblk_t *mp)
2035 2034 {
2036 2035 int index;
2037 2036 conskbd_lower_queue_t *lqs;
2038 2037
2039 2038 freemsg(mp);
2040 2039
2041 2040 lqs = (conskbd_lower_queue_t *)lowque->q_ptr;
2042 2041
2043 2042 ASSERT(lqs->lqs_queue == lowque);
2044 2043 ASSERT(lqs->lqs_pending_plink != NULL);
2045 2044
2046 2045 /*
2047 2046 * Now, link the lower queue under conskbd
2048 2047 */
2049 2048 for (index = 0; index < KBTRANS_KEYNUMS_MAX; index ++) {
2050 2049 lqs->lqs_key_state[index] = KEY_RELEASED;
2051 2050 }
2052 2051 lqs->lqs_next = conskbd.conskbd_lqueue_list;
2053 2052 lqs->lqs_state = LQS_INITIALIZED;
2054 2053 conskbd.conskbd_lqueue_nums++;
2055 2054 conskbd.conskbd_lqueue_list = lqs;
2056 2055 mioc2ack(lqs->lqs_pending_plink, NULL, 0, 0);
2057 2056 qreply(lqs->lqs_pending_queue, lqs->lqs_pending_plink);
2058 2057
2059 2058 } /* conskbd_link_lowque_virt() */
2060 2059
2061 2060 /*ARGSUSED*/
2062 2061 static void
2063 2062 conskbd_legacy_upstream_msg(conskbd_lower_queue_t *lqs, mblk_t *mp)
2064 2063 {
2065 2064 struct iocblk *iocp;
2066 2065
2067 2066 ASSERT(lqs && lqs->lqs_state == LQS_INITIALIZED_LEGACY);
2068 2067
2069 2068 /*
2070 2069 * We assume that all of the ioctls are headed to the
2071 2070 * conskbd_regqueue if it is open. We are intercepting a few ioctls
2072 2071 * that we know belong to conskbd_consqueue, and sending them there.
2073 2072 * Any other, new ioctls that have to be routed to conskbd_consqueue
2074 2073 * should be added to this list.
2075 2074 */
2076 2075 iocp = (struct iocblk *)mp->b_rptr;
2077 2076
2078 2077 if ((iocp->ioc_cmd == CONSOPENPOLLEDIO) ||
2079 2078 (iocp->ioc_cmd == CONSCLOSEPOLLEDIO)) {
2080 2079
2081 2080 DPRINTF(PRINT_L1, PRINT_MASK_ALL,
2082 2081 ("conskbd_legacy_upstream_msg: "
2083 2082 "CONSOPEN/CLOSEPOLLEDIO ACK/NAK\n"));
2084 2083 putnext(conskbd_consqueue, mp);
2085 2084
2086 2085 } else if (conskbd_regqueue != NULL) {
2087 2086 DPRINTF(PRINT_L1, PRINT_MASK_ALL,
2088 2087 ("conskbd_legacy_upstream_msg: conskbd_regqueue != NULL"));
2089 2088
2090 2089 putnext(conskbd_regqueue, mp);
2091 2090
2092 2091 } else if (conskbd_consqueue != NULL) {
2093 2092 DPRINTF(PRINT_L1, PRINT_MASK_ALL,
2094 2093 ("conskbd_legacy_upstream_msg: conskbd_consqueue != NULL"));
2095 2094 putnext(conskbd_consqueue, mp);
2096 2095 } else {
2097 2096 /* if reached here, it must be a error */
2098 2097 cmn_err(CE_WARN,
2099 2098 "kb: no destination for IOCACK/IOCNAK!");
2100 2099 freemsg(mp);
2101 2100 }
2102 2101
2103 2102 } /* conskbd_legacy_upstream_msg() */
2104 2103
2105 2104 /*
2106 2105 * This routine is a callback routine for kbtrans module to set LED.
2107 2106 * Kbtrans will invoke it in two cases:
2108 2107 *
2109 2108 * 1) application initiated request
2110 2109 * A KIOCSLED ioctl is sent by an application. The ioctl will be
2111 2110 * be prcoessed by queue service procedure conskbduwsrv(), which
2112 2111 * in turn calls kbtrans to process the ioctl. Then kbtrans invokes
2113 2112 * conskbd_streams_setled() to set LED, after that, kbtrans will
2114 2113 * return an ACK message to upper module.
2115 2114 *
2116 2115 * 2) Kbtrans initiated the request
2117 2116 * When conskbd works in TR_ASCII translation mode, if anyone of
2118 2117 * CapsLock, NumberLock and Compose keys is pressed, kbtrans need
2119 2118 * to set LED. In this case, there is no ioctl from upper module.
2120 2119 * There is no requirement to send response to somebody.
2121 2120 *
2122 2121 * In first case, kbtrans will send response to upper module; and in the
2123 2122 * second, we don't need to send response. So conskbd_streams_setled()
2124 2123 * has no return value.
2125 2124 */
2126 2125 static void
2127 2126 conskbd_streams_setled(struct kbtrans_hardware *hw, int led_state)
2128 2127 {
2129 2128 conskbd_state_t *conskbdp = (conskbd_state_t *)hw;
2130 2129 conskbd_lower_queue_t *lqs;
2131 2130 mblk_t *req;
2132 2131
2133 2132 ASSERT(&conskbd == conskbdp);
2134 2133
2135 2134 if (led_state == -1)
2136 2135 return;
2137 2136
2138 2137 conskbdp->conskbd_led_state = led_state;
2139 2138
2140 2139 /*
2141 2140 * Basically, failing to set LED is not a fatal error, we just skip
2142 2141 * it if this happens.
2143 2142 */
2144 2143 for (lqs = conskbdp->conskbd_lqueue_list; lqs; lqs = lqs->lqs_next) {
2145 2144 req = mkiocb(KIOCSLED);
2146 2145
2147 2146 if (!req) {
2148 2147 continue;
2149 2148 }
2150 2149
2151 2150 req->b_cont = allocb(sizeof (uchar_t), BPRI_MED);
2152 2151 if (!req->b_cont) {
2153 2152 freemsg(req);
2154 2153 continue;
2155 2154 }
2156 2155 *(uchar_t *)req->b_cont->b_wptr = led_state;
2157 2156 req->b_cont->b_wptr += sizeof (uchar_t);
2158 2157 if (putq(lqs->lqs_queue, req) != 1)
2159 2158 freemsg(req);
2160 2159 }
2161 2160
2162 2161 } /* conskbd_streams_setled() */
2163 2162
2164 2163 static void
2165 2164 conskbd_polledio_setled(struct kbtrans_hardware *hw, int led_state)
2166 2165 {
2167 2166 conskbd_state_t *conskbdp = (conskbd_state_t *)hw;
2168 2167 struct cons_polledio *cb;
2169 2168 conskbd_lower_queue_t *lqs;
2170 2169
2171 2170 for (lqs = conskbdp->conskbd_lqueue_list; lqs; lqs = lqs->lqs_next) {
2172 2171 cb = lqs->lqs_polledio;
2173 2172 if ((cb != NULL) && (cb->cons_polledio_setled != NULL)) {
2174 2173 cb->cons_polledio_setled(cb->cons_polledio_argument,
2175 2174 led_state);
2176 2175 }
2177 2176 }
2178 2177
2179 2178 } /* conskbd_polledio_setled() */
2180 2179
2181 2180 static boolean_t
2182 2181 conskbd_polled_keycheck(struct kbtrans_hardware *hw,
2183 2182 kbtrans_key_t *keycode, enum keystate *state)
2184 2183 {
2185 2184 conskbd_state_t *conskbdp = (conskbd_state_t *)hw;
2186 2185 struct cons_polledio *cb;
2187 2186 conskbd_lower_queue_t *lqs;
2188 2187 boolean_t ret = B_FALSE;
2189 2188
2190 2189 for (ret = B_FALSE, lqs = conskbdp->conskbd_lqueue_list; lqs != NULL;
2191 2190 lqs = lqs->lqs_next) {
2192 2191 cb = lqs->lqs_polledio;
2193 2192 if ((cb != NULL) &&
2194 2193 (cb->cons_polledio_keycheck != NULL)) {
2195 2194 ret = cb->cons_polledio_keycheck(
2196 2195 cb->cons_polledio_argument, keycode, state);
2197 2196 }
2198 2197
2199 2198 /* Get a char from lower queue(hardware) ? */
2200 2199 if (ret == B_TRUE) {
2201 2200
2202 2201 /* A legacy keyboard ? */
2203 2202 if (conskbd.conskbd_bypassed == B_TRUE)
2204 2203 break;
2205 2204
2206 2205 /*
2207 2206 * This is the PS2 scancode 0x2B -> USB(49) /
2208 2207 * USB(50) keycode mapping workaround, for
2209 2208 * polled mode.
2210 2209 *
2211 2210 * There are two possible USB keycode mappings
2212 2211 * for PS2 scancode 0x2B and this workaround
2213 2212 * makes sure that we use the USB keycode that
2214 2213 * does not end up being mapped to a HOLE key
2215 2214 * using the current keyboard translation
2216 2215 * tables.
2217 2216 *
2218 2217 * See conskbdlrput() for a detailed
2219 2218 * explanation of the problem.
2220 2219 */
2221 2220 if (*keycode == 49 || *keycode == 50) {
2222 2221 if (conskbd_keyindex->k_normal[50] == HOLE)
2223 2222 *keycode = 49;
2224 2223 else
2225 2224 *keycode = 50;
2226 2225 }
2227 2226
2228 2227 break;
2229 2228 }
2230 2229 }
2231 2230
2232 2231 return (ret);
2233 2232
2234 2233 } /* conskbd_polled_keycheck() */
2235 2234
2236 2235 static boolean_t
2237 2236 conskbd_override_kbtrans(queue_t *q, mblk_t *mp)
2238 2237 {
2239 2238 struct iocblk *iocp;
2240 2239 int directio;
2241 2240 int error;
2242 2241
2243 2242 if (mp->b_datap->db_type != M_IOCTL)
2244 2243 return (B_FALSE);
2245 2244
2246 2245 iocp = (struct iocblk *)mp->b_rptr;
2247 2246
2248 2247 switch (iocp->ioc_cmd) {
2249 2248 case KIOCGDIRECT: {
2250 2249 /*
2251 2250 * Don't let the kbtrans-based code see this; it will
2252 2251 * respond incorrectly.
2253 2252 */
2254 2253 register mblk_t *datap;
2255 2254
2256 2255 if ((datap = allocb((int)sizeof (int), BPRI_MED)) == NULL) {
2257 2256 miocnak(q, mp, 0, ENOMEM);
2258 2257 return (B_TRUE);
2259 2258 }
2260 2259
2261 2260 *(int *)datap->b_wptr = conskbd.conskbd_directio;
2262 2261 datap->b_wptr += sizeof (int);
2263 2262 if (mp->b_cont) {
2264 2263 freemsg(mp->b_cont);
2265 2264 mp->b_cont = NULL;
2266 2265 }
2267 2266 mp->b_cont = datap;
2268 2267 miocack(q, mp, sizeof (int), 0);
2269 2268 return (B_TRUE);
2270 2269 }
2271 2270
2272 2271 case KIOCSDIRECT:
2273 2272 /*
2274 2273 * Peek at this, set our variables, and then let the kbtrans
2275 2274 * based code see it and respond to it.
2276 2275 */
2277 2276 error = miocpullup(mp, sizeof (int));
2278 2277 if (error != 0) {
2279 2278 return (B_FALSE);
2280 2279 }
2281 2280
2282 2281 directio = *(int *)mp->b_cont->b_rptr;
2283 2282 if (directio != 0 && directio != 1) {
2284 2283 miocnak(q, mp, 0, EINVAL);
2285 2284 return (B_TRUE);
2286 2285 }
2287 2286 conskbd.conskbd_directio = directio;
2288 2287
2289 2288 if (conskbd.conskbd_directio) {
2290 2289 kbtrans_streams_set_queue(
2291 2290 conskbd.conskbd_kbtrans, conskbd_regqueue);
2292 2291 } else {
2293 2292 kbtrans_streams_set_queue(
2294 2293 conskbd.conskbd_kbtrans, conskbd_consqueue);
2295 2294 }
2296 2295
2297 2296 /*
2298 2297 * Let the kbtrans-based code see this and respond to it.
2299 2298 */
2300 2299 return (B_FALSE);
2301 2300
2302 2301 default:
2303 2302 return (B_FALSE);
2304 2303 }
2305 2304
2306 2305 } /* conskbd_override_kbtrans() */
2307 2306
2308 2307
2309 2308 static void
2310 2309 conskbd_polledio_enter(cons_polledio_arg_t arg)
2311 2310 {
2312 2311 conskbd_state_t *conskbdp;
2313 2312 struct cons_polledio *cb;
2314 2313 conskbd_lower_queue_t *lqs;
2315 2314
2316 2315 conskbdp = (conskbd_state_t *)arg;
2317 2316 for (lqs = conskbdp->conskbd_lqueue_list; lqs; lqs = lqs->lqs_next) {
2318 2317 cb = lqs->lqs_polledio;
2319 2318 if ((cb != NULL) && (cb->cons_polledio_enter != NULL)) {
2320 2319 cb->cons_polledio_enter(cb->cons_polledio_argument);
2321 2320 }
2322 2321 }
2323 2322
2324 2323 } /* conskbd_polledio_enter() */
2325 2324
2326 2325 static void
2327 2326 conskbd_polledio_exit(cons_polledio_arg_t arg)
2328 2327 {
2329 2328 conskbd_state_t *conskbdp;
2330 2329 struct cons_polledio *cb;
2331 2330 conskbd_lower_queue_t *lqs;
2332 2331
2333 2332 conskbdp = (conskbd_state_t *)arg;
2334 2333 for (lqs = conskbdp->conskbd_lqueue_list; lqs; lqs = lqs->lqs_next) {
2335 2334 cb = lqs->lqs_polledio;
2336 2335 if ((cb != NULL) && (cb->cons_polledio_exit != NULL)) {
2337 2336 cb->cons_polledio_exit(cb->cons_polledio_argument);
2338 2337 }
2339 2338 }
2340 2339
2341 2340 } /* conskbd_polledio_exit() */
2342 2341
2343 2342 static int
2344 2343 conskbd_polledio_getchar(cons_polledio_arg_t arg)
2345 2344 {
2346 2345 conskbd_state_t *conskbdp;
2347 2346
2348 2347 conskbdp = (conskbd_state_t *)arg;
2349 2348
2350 2349 return (kbtrans_getchar(conskbdp->conskbd_kbtrans));
2351 2350
2352 2351 } /* conskbd_polledio_getchar() */
2353 2352
2354 2353 static int
2355 2354 conskbd_polledio_ischar(cons_polledio_arg_t arg)
2356 2355 {
2357 2356 conskbd_state_t *conskbdp;
2358 2357
2359 2358 conskbdp = (conskbd_state_t *)arg;
2360 2359
2361 2360 return (kbtrans_ischar(conskbdp->conskbd_kbtrans));
2362 2361
2363 2362 } /* conskbd_polledio_ischar() */
2364 2363
2365 2364
2366 2365 static void
2367 2366 conskbd_mux_enqueue_msg(conskbd_pending_msg_t *msg)
2368 2367 {
2369 2368 mutex_enter(&conskbd_msgq_lock);
2370 2369 msg->kpm_next = conskbd_msg_queue;
2371 2370 conskbd_msg_queue = msg;
2372 2371 mutex_exit(&conskbd_msgq_lock);
2373 2372
2374 2373 } /* conskbd_mux_enqueue_msg() */
2375 2374
2376 2375 /*
2377 2376 * the messages in conskbd_msg_queue we just enqueue
2378 2377 */
2379 2378 static conskbd_pending_msg_t *
2380 2379 conskbd_mux_find_msg(mblk_t *mp)
2381 2380 {
2382 2381 conskbd_pending_msg_t *msg;
2383 2382 struct iocblk *iocp;
2384 2383 uint_t id;
2385 2384
2386 2385 mutex_enter(&conskbd_msgq_lock);
2387 2386 msg = conskbd_msg_queue;
2388 2387
2389 2388 iocp = (struct iocblk *)mp->b_rptr;
2390 2389 ASSERT(iocp);
2391 2390 id = iocp->ioc_id;
2392 2391 while (msg && msg->kpm_req_id != id) {
2393 2392 msg = msg->kpm_next;
2394 2393 }
2395 2394 mutex_exit(&conskbd_msgq_lock);
2396 2395
2397 2396 return (msg);
2398 2397
2399 2398 } /* conskbd_mux_find_msg() */
2400 2399
2401 2400
2402 2401 static void
2403 2402 conskbd_mux_dequeue_msg(conskbd_pending_msg_t *msg)
2404 2403 {
2405 2404 conskbd_pending_msg_t *prev;
2406 2405 conskbd_pending_msg_t *p;
2407 2406
2408 2407 mutex_enter(&conskbd_msgq_lock);
2409 2408 prev = conskbd_msg_queue;
2410 2409
2411 2410 for (p = prev; p && p != msg; p = p->kpm_next)
2412 2411 prev = p;
2413 2412
2414 2413 ASSERT(p && p == msg);
2415 2414
2416 2415 if (prev == p) {
2417 2416 conskbd_msg_queue = msg->kpm_next;
2418 2417 } else {
2419 2418 prev->kpm_next = p->kpm_next;
2420 2419 }
2421 2420 p->kpm_next = NULL;
2422 2421 mutex_exit(&conskbd_msgq_lock);
2423 2422
2424 2423 } /* conskbd_mux_dequeue_msg() */
2425 2424
2426 2425 #ifdef DEBUG
2427 2426 /*ARGSUSED*/
2428 2427 void
2429 2428 conskbd_dprintf(const char *fmt, ...)
2430 2429 {
2431 2430 char buf[256];
2432 2431 va_list ap;
2433 2432
2434 2433 va_start(ap, fmt);
2435 2434 (void) vsprintf(buf, fmt, ap);
2436 2435 va_end(ap);
2437 2436
2438 2437 cmn_err(CE_CONT, "conskbd: %s", buf);
2439 2438
2440 2439 } /* conskbd_dprintf() */
2441 2440 #endif
↓ open down ↓ |
2209 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX