Print this page
8368 remove warlock leftovers from usr/src/uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/wscons.c
+++ new/usr/src/uts/common/io/wscons.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 (c) 1987, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 /*
27 27 * "Workstation console" multiplexor driver for Sun.
28 28 *
29 29 * Sends output to the primary frame buffer using the PROM monitor;
30 30 * gets input from a stream linked below us that is the "keyboard
31 31 * driver", below which is linked the primary keyboard.
32 32 */
33 33
34 34 /*
35 35 * Locking Policy:
36 36 * This module has a D_MTPERMOD inner perimeter which means STREAMS
37 37 * only allows one thread to enter this module through STREAMS entry
38 38 * points each time -- open() close() put() srv() qtimeout().
39 39 * So for the most time we do not need locking in this module, but with
40 40 * the following exceptions:
41 41 *
42 42 * - wc shares three global variables (wc_dip, vc_active_console,
43 43 * vc_cons_user, vc_avl_root) with virtual console devname part
44 44 * (fs/dev/sdev_vtops.c) which get compiled into genunix.
45 45 *
46 46 * - wc_modechg_cb() is a callback function which will triggered when
47 47 * framebuffer display mode is changed.
48 48 *
49 49 * - vt_send_hotkeys() is triggered by timeout() which is not STREAMS MT
50 50 * safe.
51 51 *
52 52 * Based on the fact that virtual console devname part and wc_modechg_cb()
53 53 * only do read access to the above mentioned shared four global variables,
54 54 * It is safe to do locking this way:
55 55 * 1) all read access to the four global variables in THIS WC MODULE do not
56 56 * need locking;
57 57 * 2) all write access to the four global variables in THIS WC MODULE must
58 58 * hold vc_lock;
59 59 * 3) any access to the four global variables in either DEVNAME PART or the
60 60 * CALLBACK must hold vc_lock;
61 61 * 4) other global variables which are only shared in this wc module and only
62 62 * accessible through STREAMS entry points such as "vc_last_console",
63 63 * "vc_inuse_max_minor", "vc_target_console" and "vc_waitactive_list"
64 64 * do not need explict locking.
65 65 *
66 66 * wc_modechg_cb() does read access to vc_state_t::vc_flags,
67 67 * vc_state_t::vc_state_lock is used to protect concurrently accesses to
68 68 * vc_state_t::vc_flags which may happen from both through STREAMS entry
69 69 * points and wc_modechg_cb().
70 70 * Since wc_modechg_cb() only does read access to vc_state_t::vc_flags,
71 71 * The other parts of wc module (except wc_modechg_cb()) only has to hold
72 72 * vc_state_t::vc_flags when writing to vc_state_t::vc_flags.
73 73 *
74 74 * vt_send_hotkeys() could access vt_pending_vtno at the same time with
75 75 * the rest of wc module, vt_pending_vtno_lock is used to protect
76 76 * vt_pending_vtno.
77 77 *
78 78 * Lock order: vc_lock -> vc_state_t::vc_state_lock.
79 79 * No overlap between vc_lock and vt_pending_vtno_lock.
80 80 */
81 81
82 82 #include <sys/types.h>
83 83 #include <sys/param.h>
84 84 #include <sys/signal.h>
85 85 #include <sys/cred.h>
86 86 #include <sys/vnode.h>
87 87 #include <sys/termios.h>
88 88 #include <sys/termio.h>
89 89 #include <sys/ttold.h>
90 90 #include <sys/stropts.h>
91 91 #include <sys/stream.h>
92 92 #include <sys/strsun.h>
93 93 #include <sys/tty.h>
94 94 #include <sys/buf.h>
95 95 #include <sys/uio.h>
96 96 #include <sys/stat.h>
97 97 #include <sys/sysmacros.h>
98 98 #include <sys/errno.h>
99 99 #include <sys/proc.h>
100 100 #include <sys/procset.h>
101 101 #include <sys/fault.h>
102 102 #include <sys/siginfo.h>
103 103 #include <sys/debug.h>
104 104 #include <sys/session.h>
105 105 #include <sys/kmem.h>
106 106 #include <sys/cpuvar.h>
107 107 #include <sys/kbio.h>
108 108 #include <sys/strredir.h>
109 109 #include <sys/fs/snode.h>
110 110 #include <sys/consdev.h>
111 111 #include <sys/conf.h>
112 112 #include <sys/cmn_err.h>
113 113 #include <sys/console.h>
114 114 #include <sys/promif.h>
115 115 #include <sys/note.h>
116 116 #include <sys/polled_io.h>
117 117 #include <sys/systm.h>
118 118 #include <sys/ddi.h>
119 119 #include <sys/sunddi.h>
120 120 #include <sys/sunndi.h>
121 121 #include <sys/esunddi.h>
122 122 #include <sys/sunldi.h>
↓ open down ↓ |
122 lines elided |
↑ open up ↑ |
123 123 #include <sys/debug.h>
124 124 #include <sys/console.h>
125 125 #include <sys/ddi_impldefs.h>
126 126 #include <sys/policy.h>
127 127 #include <sys/modctl.h>
128 128 #include <sys/tem.h>
129 129 #include <sys/wscons.h>
130 130 #include <sys/vt_impl.h>
131 131
132 132 /* streams stuff */
133 -_NOTE(SCHEME_PROTECTS_DATA("Unshared data", copyreq))
134 -_NOTE(SCHEME_PROTECTS_DATA("Unshared data", copyresp))
135 -_NOTE(SCHEME_PROTECTS_DATA("Unshared data", datab))
136 -_NOTE(SCHEME_PROTECTS_DATA("Unshared data", iocblk))
137 -_NOTE(SCHEME_PROTECTS_DATA("Unshared data", msgb))
138 -_NOTE(SCHEME_PROTECTS_DATA("Unshared data", queue))
139 -
140 133 #define MINLINES 10
141 134 #define MAXLINES 48
142 135 #define LOSCREENLINES 34
143 136 #define HISCREENLINES 48
144 137
145 138 #define MINCOLS 10
146 139 #define MAXCOLS 120
147 140 #define LOSCREENCOLS 80
148 141 #define HISCREENCOLS 120
149 142
150 143 struct wscons_state {
151 144 dev_t wc_dev; /* major/minor for this device */
152 145 #ifdef _HAVE_TEM_FIRMWARE
153 146 int wc_defer_output; /* set if output device is "slow" */
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
154 147 #endif /* _HAVE_TEM_FIRMWARE */
155 148 queue_t *wc_kbdqueue; /* "console keyboard" device queue */
156 149 /* below us */
157 150 cons_polledio_t wc_polledio; /* polled I/O function pointers */
158 151 cons_polledio_t *wc_kb_polledio; /* keyboard's polledio */
159 152 unsigned int wc_kb_getpolledio_id; /* id for kb CONSOPENPOLLEDIO */
160 153 queue_t *wc_pending_wq;
161 154 mblk_t *wc_pending_link; /* I_PLINK pending for kb polledio */
162 155 } wscons;
163 156
164 -/*
165 - * This module has a D_MTPERMOD inner perimeter, so we don't need to protect
166 - * the variables only shared within this module
167 - */
168 -_NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", wscons))
169 -_NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", wscons_state))
170 -_NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vt_stat))
171 -_NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vc_waitactive_msg))
172 -_NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", tty_common))
173 -_NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vt_mode))
174 -_NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vt_dispinfo))
175 -_NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", winsize))
176 -_NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vc_last_console))
177 -
178 157 #ifdef _HAVE_TEM_FIRMWARE
179 158 ssize_t wc_cons_wrtvec(promif_redir_arg_t arg, uchar_t *s, size_t n);
180 159 #endif /* _HAVE_TEM_FIRMWARE */
181 160
182 161 static int wcopen(queue_t *, dev_t *, int, int, cred_t *);
183 162 static int wcclose(queue_t *, int, cred_t *);
184 163 static int wcuwput(queue_t *, mblk_t *);
185 164 static int wclrput(queue_t *, mblk_t *);
186 165
187 166 static struct module_info wcm_info = {
188 167 0,
189 168 "wc",
190 169 0,
191 170 INFPSZ,
192 171 2048,
193 172 128
194 173 };
195 174
196 175 static struct qinit wcurinit = {
197 176 putq,
198 177 NULL,
199 178 wcopen,
200 179 wcclose,
201 180 NULL,
202 181 &wcm_info,
203 182 NULL
204 183 };
205 184
206 185 static struct qinit wcuwinit = {
207 186 wcuwput,
208 187 NULL,
209 188 wcopen,
210 189 wcclose,
211 190 NULL,
212 191 &wcm_info,
213 192 NULL
214 193 };
215 194
216 195 static struct qinit wclrinit = {
217 196 wclrput,
218 197 NULL,
219 198 NULL,
220 199 NULL,
221 200 NULL,
222 201 &wcm_info,
223 202 NULL
224 203 };
225 204
226 205 /*
227 206 * We always putnext directly to the underlying queue.
228 207 */
229 208 static struct qinit wclwinit = {
230 209 NULL,
231 210 NULL,
232 211 NULL,
233 212 NULL,
234 213 NULL,
235 214 &wcm_info,
236 215 NULL
237 216 };
238 217
239 218 static struct streamtab wcinfo = {
240 219 &wcurinit,
241 220 &wcuwinit,
242 221 &wclrinit,
243 222 &wclwinit,
244 223 };
245 224
246 225 static int wc_info(dev_info_t *, ddi_info_cmd_t, void *, void **result);
247 226 static int wc_attach(dev_info_t *, ddi_attach_cmd_t);
248 227
249 228 DDI_DEFINE_STREAM_OPS(wc_ops, nulldev, nulldev, wc_attach, nodev, nodev,
250 229 wc_info, D_MTPERMOD | D_MP, &wcinfo, ddi_quiesce_not_supported);
251 230
252 231 static void wcreioctl(void *);
253 232 static void wcioctl(queue_t *, mblk_t *);
254 233 #ifdef _HAVE_TEM_FIRMWARE
255 234 static void wcopoll(void *);
256 235 static void wconsout(void *);
257 236 #endif /* _HAVE_TEM_FIRMWARE */
258 237 static void wcrstrt(void *);
259 238 static void wcstart(void *);
260 239 static void wc_open_kb_polledio(struct wscons_state *wc, queue_t *q,
261 240 mblk_t *mp);
262 241 static void wc_close_kb_polledio(struct wscons_state *wc, queue_t *q,
263 242 mblk_t *mp);
264 243 static void wc_polled_putchar(cons_polledio_arg_t arg,
265 244 unsigned char c);
266 245 static boolean_t wc_polled_ischar(cons_polledio_arg_t arg);
267 246 static int wc_polled_getchar(cons_polledio_arg_t arg);
268 247 static void wc_polled_enter(cons_polledio_arg_t arg);
269 248 static void wc_polled_exit(cons_polledio_arg_t arg);
270 249 void wc_get_size(vc_state_t *pvc);
271 250 static void wc_modechg_cb(tem_modechg_cb_arg_t arg);
272 251
273 252 static struct dev_ops wc_ops;
274 253
275 254 /*
276 255 * Debug printing
277 256 */
278 257 #ifndef DPRINTF
279 258 #ifdef DEBUG
280 259 /*PRINTFLIKE1*/
281 260 static void wc_dprintf(const char *fmt, ...) __KPRINTFLIKE(1);
282 261 #define DPRINTF(l, m, args) \
283 262 (((l) >= wc_errlevel) && ((m) & wc_errmask) ? \
284 263 wc_dprintf args : \
285 264 (void) 0)
286 265 /*
287 266 * Severity levels for printing
288 267 */
289 268 #define PRINT_L0 0 /* print every message */
290 269 #define PRINT_L1 1 /* debug */
291 270 #define PRINT_L2 2 /* quiet */
292 271
293 272 /*
294 273 * Masks
295 274 */
296 275 #define PRINT_MASK_ALL 0xFFFFFFFFU
297 276 uint_t wc_errmask = PRINT_MASK_ALL;
298 277 uint_t wc_errlevel = PRINT_L2;
299 278
300 279 #else
301 280 #define DPRINTF(l, m, args) /* NOTHING */
302 281 #endif
303 282 #endif
304 283
305 284 /*
306 285 * Module linkage information for the kernel.
307 286 */
308 287 static struct modldrv modldrv = {
309 288 &mod_driverops, /* Type of module. This one is a pseudo driver */
310 289 "Workstation multiplexer Driver 'wc'",
311 290 &wc_ops, /* driver ops */
312 291 };
313 292
314 293 static struct modlinkage modlinkage = {
315 294 MODREV_1,
316 295 &modldrv,
317 296 NULL
318 297 };
319 298
320 299 int
321 300 _init(void)
322 301 {
323 302 int rc;
324 303 if ((rc = mod_install(&modlinkage)) == 0)
325 304 vt_init();
326 305 return (rc);
327 306 }
328 307
329 308 int
330 309 _fini(void)
331 310 {
332 311 return (mod_remove(&modlinkage));
333 312 }
334 313
335 314 int
336 315 _info(struct modinfo *modinfop)
337 316 {
338 317 return (mod_info(&modlinkage, modinfop));
339 318 }
340 319
341 320 /*ARGSUSED*/
342 321 static int
343 322 wc_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
344 323 {
345 324 /* create minor node for workstation hard console */
346 325 if (ddi_create_minor_node(devi, "wscons", S_IFCHR,
347 326 0, DDI_PSEUDO, NULL) == DDI_FAILURE) {
348 327 ddi_remove_minor_node(devi, NULL);
349 328 return (DDI_FAILURE);
350 329 }
351 330
352 331 mutex_enter(&vc_lock);
353 332
354 333 wc_dip = devi;
355 334
356 335 bzero(&(wscons.wc_polledio), sizeof (wscons.wc_polledio));
357 336
358 337 vt_resize(VC_DEFAULT_COUNT);
359 338
360 339 mutex_exit(&vc_lock);
361 340
362 341 return (DDI_SUCCESS);
363 342 }
364 343
365 344 /* ARGSUSED */
366 345 static int
367 346 wc_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
368 347 void **result)
369 348 {
370 349 int error;
371 350
372 351 switch (infocmd) {
373 352 case DDI_INFO_DEVT2DEVINFO:
374 353 if (wc_dip == NULL) {
375 354 error = DDI_FAILURE;
376 355 } else {
377 356 *result = (void *) wc_dip;
378 357 error = DDI_SUCCESS;
379 358 }
380 359 break;
381 360 case DDI_INFO_DEVT2INSTANCE:
382 361 *result = (void *)0;
383 362 error = DDI_SUCCESS;
384 363 break;
385 364 default:
386 365 error = DDI_FAILURE;
387 366 }
388 367 return (error);
389 368 }
390 369
391 370 #ifdef _HAVE_TEM_FIRMWARE
392 371 /*
↓ open down ↓ |
205 lines elided |
↑ open up ↑ |
393 372 * Output buffer. Protected by the per-module inner perimeter.
394 373 */
395 374 #define MAXHIWAT 2000
396 375 static char obuf[MAXHIWAT];
397 376 #endif /* _HAVE_TEM_FIRMWARE */
398 377
399 378 static void
400 379 wc_init_polledio(void)
401 380 {
402 381 static boolean_t polledio_inited = B_FALSE;
403 - _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data",
404 - polledio_inited))
405 382
406 383 if (polledio_inited)
407 384 return;
408 385
409 386 polledio_inited = B_TRUE;
410 387
411 388 /*
412 389 * Initialize the parts of the polled I/O struct that
413 390 * are common to both input and output modes, but which
414 391 * don't flag to the upper layers, which if any of the
415 392 * two modes are available. We don't know at this point
416 393 * if system is configured CONS_KFB, but we will when
417 394 * consconfig_dacf asks us with CONSOPENPOLLED I/O.
418 395 */
419 396 bzero(&(wscons.wc_polledio), sizeof (wscons.wc_polledio));
420 397 wscons.wc_polledio.cons_polledio_version =
421 398 CONSPOLLEDIO_V0;
422 399 wscons.wc_polledio.cons_polledio_argument =
423 400 (cons_polledio_arg_t)&wscons;
424 401 wscons.wc_polledio.cons_polledio_enter =
425 402 wc_polled_enter;
426 403 wscons.wc_polledio.cons_polledio_exit =
427 404 wc_polled_exit;
428 405
429 406 #ifdef _HAVE_TEM_FIRMWARE
430 407 /*
431 408 * If we're talking directly to a framebuffer, we assume
432 409 * that it's a "slow" device, so that rendering should
433 410 * be deferred to a timeout or softcall so that we write
434 411 * a bunch of characters at once.
435 412 */
436 413 wscons.wc_defer_output = prom_stdout_is_framebuffer();
437 414 #endif /* _HAVE_TEM_FIRMWARE */
438 415 }
439 416
440 417 /*ARGSUSED*/
441 418 static int
442 419 wcopen(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *crp)
443 420 {
444 421 int minor;
445 422
446 423 wc_init_polledio();
447 424 minor = (int)getminor(*devp);
448 425 return (vt_open(minor, q, crp));
449 426 }
450 427
451 428 /*ARGSUSED*/
452 429 static int
453 430 wcclose(queue_t *q, int flag, cred_t *crp)
454 431 {
455 432 vc_state_t *pvc = (vc_state_t *)q->q_ptr;
456 433
457 434 qprocsoff(q);
458 435
459 436 mutex_enter(&vc_lock);
460 437
461 438 /*
462 439 * If we are closing the VT node which
463 440 * /dev/vt/console_user points to, revert
464 441 * /dev/vt/console to /dev/console
465 442 */
466 443 if (vc_cons_user == pvc->vc_minor)
467 444 vc_cons_user = VT_MINOR_INVALID;
468 445
469 446 if (pvc->vc_minor == 0 || pvc->vc_minor == vc_active_console) {
470 447
471 448 /*
472 449 * If we lose the system console,
473 450 * no any other active consoles.
474 451 */
475 452 if (pvc->vc_minor == 0 && pvc->vc_minor == vc_active_console) {
476 453 vc_active_console = VT_MINOR_INVALID;
477 454 vc_last_console = VT_MINOR_INVALID;
478 455 }
479 456
480 457 /*
481 458 * just clean for our primary console
482 459 * and active console
483 460 */
484 461 mutex_enter(&pvc->vc_state_lock);
485 462 vt_clean(q, pvc);
486 463 mutex_exit(&pvc->vc_state_lock);
487 464
488 465 mutex_exit(&vc_lock);
489 466
490 467 return (0);
491 468 }
492 469 vt_close(q, pvc, crp);
493 470
494 471 mutex_exit(&vc_lock);
495 472
496 473 return (0);
497 474 }
498 475
499 476 /*
500 477 * Put procedure for upper write queue.
501 478 * Respond to M_STOP, M_START, M_IOCTL, and M_FLUSH messages here;
502 479 * queue up M_BREAK, M_DELAY, and M_DATA messages for processing by
503 480 * the start routine, and then call the start routine; discard
504 481 * everything else.
505 482 */
506 483 static int
507 484 wcuwput(queue_t *q, mblk_t *mp)
508 485 {
509 486 vc_state_t *pvc = (vc_state_t *)q->q_ptr;
510 487
511 488 switch (mp->b_datap->db_type) {
512 489
513 490 case M_STOP:
514 491 mutex_enter(&pvc->vc_state_lock);
515 492 pvc->vc_flags |= WCS_STOPPED;
516 493 mutex_exit(&pvc->vc_state_lock);
517 494
518 495 freemsg(mp);
519 496 break;
520 497
521 498 case M_START:
522 499 mutex_enter(&pvc->vc_state_lock);
523 500 pvc->vc_flags &= ~WCS_STOPPED;
524 501 mutex_exit(&pvc->vc_state_lock);
525 502
526 503 wcstart(pvc);
527 504 freemsg(mp);
528 505 break;
529 506
530 507 case M_IOCTL: {
531 508 struct iocblk *iocp;
532 509 struct linkblk *linkp;
533 510
534 511 iocp = (struct iocblk *)(void *)mp->b_rptr;
535 512 switch (iocp->ioc_cmd) {
536 513
537 514 case I_LINK: /* stupid, but permitted */
538 515 case I_PLINK:
539 516 if (wscons.wc_kbdqueue != NULL) {
540 517 /* somebody already linked */
541 518 miocnak(q, mp, 0, EINVAL);
542 519 return (0);
543 520 }
544 521 linkp = (struct linkblk *)(void *)mp->b_cont->b_rptr;
545 522 wscons.wc_kbdqueue = WR(linkp->l_qbot);
546 523 mp->b_datap->db_type = M_IOCACK;
547 524 iocp->ioc_count = 0;
548 525 wc_open_kb_polledio(&wscons, q, mp);
549 526 break;
550 527
551 528 case I_UNLINK: /* stupid, but permitted */
552 529 case I_PUNLINK:
553 530 linkp = (struct linkblk *)(void *)mp->b_cont->b_rptr;
554 531 if (wscons.wc_kbdqueue != WR(linkp->l_qbot)) {
555 532 /* not us */
556 533 miocnak(q, mp, 0, EINVAL);
557 534 return (0);
558 535 }
559 536
560 537 mp->b_datap->db_type = M_IOCACK;
561 538 iocp->ioc_count = 0;
562 539 wc_close_kb_polledio(&wscons, q, mp);
563 540 break;
564 541
565 542 case TCSETSW:
566 543 case TCSETSF:
567 544 case TCSETAW:
568 545 case TCSETAF:
569 546 case TCSBRK:
570 547 /*
571 548 * The changes do not take effect until all
572 549 * output queued before them is drained.
573 550 * Put this message on the queue, so that
574 551 * "wcstart" will see it when it's done
575 552 * with the output before it. Poke the
576 553 * start routine, just in case.
577 554 */
578 555 (void) putq(q, mp);
579 556 wcstart(pvc);
580 557 break;
581 558
582 559 case CONSSETABORTENABLE:
583 560 case CONSGETABORTENABLE:
584 561 case KIOCSDIRECT:
585 562 if (wscons.wc_kbdqueue != NULL) {
586 563 wscons.wc_pending_wq = q;
587 564 (void) putnext(wscons.wc_kbdqueue, mp);
588 565 break;
589 566 }
590 567 /* fall through */
591 568
592 569 default:
593 570 /*
594 571 * Do it now.
595 572 */
596 573 wcioctl(q, mp);
597 574 break;
598 575 }
599 576 break;
600 577 }
601 578
602 579 case M_FLUSH:
603 580 if (*mp->b_rptr & FLUSHW) {
604 581 /*
605 582 * Flush our write queue.
606 583 */
607 584 flushq(q, FLUSHDATA); /* XXX doesn't flush M_DELAY */
608 585 *mp->b_rptr &= ~FLUSHW; /* it has been flushed */
609 586 }
610 587 if (*mp->b_rptr & FLUSHR) {
611 588 flushq(RD(q), FLUSHDATA);
612 589 qreply(q, mp); /* give the read queues a crack at it */
613 590 } else
614 591 freemsg(mp);
615 592 break;
616 593
617 594 case M_BREAK:
618 595 /*
619 596 * Ignore these, as they make no sense.
620 597 */
621 598 freemsg(mp);
622 599 break;
623 600
624 601 case M_DELAY:
625 602 case M_DATA:
626 603 /*
627 604 * Queue the message up to be transmitted,
628 605 * and poke the start routine.
629 606 */
630 607 (void) putq(q, mp);
631 608 wcstart(pvc);
632 609 break;
633 610
634 611 case M_IOCDATA:
635 612 vt_miocdata(q, mp);
636 613 break;
637 614
638 615 default:
639 616 /*
640 617 * "No, I don't want a subscription to Chain Store Age,
641 618 * thank you anyway."
642 619 */
643 620 freemsg(mp);
644 621 break;
645 622 }
646 623
647 624 return (0);
648 625 }
649 626
650 627 /*
651 628 * Retry an "ioctl", now that "qbufcall" claims we may be able to allocate
652 629 * the buffer we need.
653 630 */
654 631 /*ARGSUSED*/
655 632 static void
656 633 wcreioctl(void *arg)
657 634 {
658 635 vc_state_t *pvc = (vc_state_t *)arg;
659 636 queue_t *q;
660 637 mblk_t *mp;
661 638
662 639 pvc->vc_bufcallid = 0;
663 640 q = pvc->vc_ttycommon.t_writeq;
664 641 if ((mp = pvc->vc_ttycommon.t_iocpending) != NULL) {
665 642 /* not pending any more */
666 643 pvc->vc_ttycommon.t_iocpending = NULL;
667 644 wcioctl(q, mp);
668 645 }
669 646 }
670 647
671 648 static int
672 649 wc_getterm(mblk_t *mp)
673 650 {
674 651 char *term;
675 652 intptr_t arg;
676 653 int flag = ((struct iocblk *)(void *)mp->b_rptr)->ioc_flag;
677 654
678 655 STRUCT_DECL(cons_getterm, wcterm);
679 656 STRUCT_INIT(wcterm, flag);
680 657
681 658 arg = *((intptr_t *)(void *)mp->b_cont->b_rptr);
682 659
683 660 if (ddi_copyin((void *)arg, STRUCT_BUF(wcterm),
684 661 STRUCT_SIZE(wcterm), flag) != 0) {
685 662 return (EFAULT);
686 663 }
687 664
688 665 if (consmode == CONS_FW) {
689 666 /* PROM terminal emulator */
690 667 term = "sun";
691 668 } else {
692 669 /* Kernel terminal emulator */
693 670 ASSERT(consmode == CONS_KFB);
694 671 term = "sun-color";
695 672 }
696 673
697 674 if (STRUCT_FGET(wcterm, cn_term_len) <
698 675 strlen(term) + 1) {
699 676 return (EOVERFLOW);
700 677 }
701 678
702 679 if (ddi_copyout(term,
703 680 STRUCT_FGETP(wcterm, cn_term_type),
704 681 strlen(term) + 1, flag) != 0) {
705 682 return (EFAULT);
706 683 }
707 684
708 685 return (0);
709 686 }
710 687
711 688 /*
712 689 * Process an "ioctl" message sent down to us.
713 690 */
714 691 static void
715 692 wcioctl(queue_t *q, mblk_t *mp)
716 693 {
717 694 vc_state_t *pvc = (vc_state_t *)q->q_ptr;
718 695 struct iocblk *iocp;
719 696 size_t datasize;
720 697 int error;
721 698 long len;
722 699
723 700 iocp = (struct iocblk *)(void *)mp->b_rptr;
724 701
725 702 if ((iocp->ioc_cmd & VTIOC) == VTIOC ||
726 703 (iocp->ioc_cmd & KDIOC) == KDIOC) {
727 704 vt_ioctl(q, mp);
728 705 return;
729 706 }
730 707
731 708 switch (iocp->ioc_cmd) {
732 709 case TIOCSWINSZ:
733 710 /*
734 711 * Ignore all attempts to set the screen size; the
735 712 * value in the EEPROM is guaranteed (modulo PROM bugs)
736 713 * to be the value used by the PROM monitor code, so it
737 714 * is by definition correct. Many programs (e.g.,
738 715 * "login" and "tset") will attempt to reset the size
739 716 * to (0, 0) or (34, 80), neither of which is
740 717 * necessarily correct.
741 718 * We just ACK the message, so as not to disturb
742 719 * programs that set the sizes.
743 720 */
744 721 iocp->ioc_count = 0; /* no data returned */
745 722 mp->b_datap->db_type = M_IOCACK;
746 723 qreply(q, mp);
747 724 return;
748 725
749 726 case CONSOPENPOLLEDIO:
750 727 DPRINTF(PRINT_L1, PRINT_MASK_ALL,
751 728 ("wcioctl: CONSOPENPOLLEDIO\n"));
752 729
753 730 error = miocpullup(mp, sizeof (struct cons_polledio *));
754 731 if (error != 0) {
755 732 miocnak(q, mp, 0, error);
756 733 return;
757 734 }
758 735
759 736 /*
760 737 * We are given an appropriate-sized data block,
761 738 * and return a pointer to our structure in it.
762 739 */
763 740 if (consmode == CONS_KFB)
764 741 wscons.wc_polledio.cons_polledio_putchar =
765 742 wc_polled_putchar;
766 743 *(struct cons_polledio **)(void *)mp->b_cont->b_rptr =
767 744 &wscons.wc_polledio;
768 745
769 746 mp->b_datap->db_type = M_IOCACK;
770 747
771 748 qreply(q, mp);
772 749 break;
773 750
774 751 case CONS_GETTERM:
775 752 if ((error = wc_getterm(mp)) != 0)
776 753 miocnak(q, mp, 0, error);
777 754 else
778 755 miocack(q, mp, 0, 0);
779 756 return;
780 757
781 758 case WC_OPEN_FB:
782 759 /*
783 760 * Start out pessimistic, so that we can just jump to
784 761 * the reply to bail out.
785 762 */
786 763 mp->b_datap->db_type = M_IOCNAK;
787 764
788 765 /*
789 766 * First test: really, this should be done only from
790 767 * inside the kernel. Unfortunately, that information
791 768 * doesn't seem to be available in a streams ioctl,
792 769 * so restrict it to root only. (Perhaps we could check
793 770 * for ioc_cr == kcred.)
794 771 */
795 772 if ((iocp->ioc_error = secpolicy_console(iocp->ioc_cr)) != 0)
796 773 goto open_fail;
797 774
798 775 /*
799 776 * Some miscellaneous checks...
800 777 */
801 778 iocp->ioc_error = EINVAL;
802 779
803 780 /*
804 781 * If we don't have exactly one continuation block, fail.
805 782 */
806 783 if (mp->b_cont == NULL ||
807 784 mp->b_cont->b_cont != NULL)
808 785 goto open_fail;
809 786
810 787 /*
811 788 * If there's no null terminator in the string, fail.
812 789 */
813 790 /* LINTED E_PTRDIFF_OVERFLOW */
814 791 len = mp->b_cont->b_wptr - mp->b_cont->b_rptr;
815 792 if (memchr(mp->b_cont->b_rptr, 0, len) == NULL)
816 793 goto open_fail;
817 794
818 795 /*
819 796 * NOTE: should eventually get default
820 797 * dimensions from a property, e.g. screen-#rows.
821 798 */
822 799 iocp->ioc_error = tem_info_init((char *)mp->b_cont->b_rptr,
823 800 iocp->ioc_cr);
824 801 /*
825 802 * Of course, if the terminal emulator initialization
826 803 * failed, fail.
827 804 */
828 805 if (iocp->ioc_error != 0)
829 806 goto open_fail;
830 807
831 808 #ifdef _HAVE_TEM_FIRMWARE
832 809 if (prom_stdout_is_framebuffer()) {
833 810 /*
834 811 * Drivers in the console stream may emit additional
835 812 * messages before we are ready. This causes text
836 813 * overwrite on the screen. So we set the redirection
837 814 * here. It is safe because the ioctl in consconfig_dacf
838 815 * will succeed and consmode will be set to CONS_KFB.
839 816 */
840 817 prom_set_stdout_redirect(wc_cons_wrtvec,
841 818 (promif_redir_arg_t)NULL);
842 819
843 820 }
844 821 #endif /* _HAVE_TEM_FIRMWARE */
845 822
846 823 tem_register_modechg_cb(wc_modechg_cb,
847 824 (tem_modechg_cb_arg_t)&wscons);
848 825
849 826 /*
850 827 * ... and succeed.
851 828 */
852 829 mp->b_datap->db_type = M_IOCACK;
853 830
854 831 open_fail:
855 832 qreply(q, mp);
856 833 break;
857 834
858 835 case WC_CLOSE_FB:
859 836 /*
860 837 * There's nothing that can call this, so it's not
861 838 * really implemented.
862 839 */
863 840 mp->b_datap->db_type = M_IOCNAK;
864 841 /*
865 842 * However, if it were implemented, it would clearly
866 843 * be root-only.
867 844 */
868 845 if ((iocp->ioc_error = secpolicy_console(iocp->ioc_cr)) != 0)
869 846 goto close_fail;
870 847
871 848 iocp->ioc_error = EINVAL;
872 849
873 850 close_fail:
874 851 qreply(q, mp);
875 852 break;
876 853
877 854 default:
878 855
879 856 /*
880 857 * The only way in which "ttycommon_ioctl" can fail is
881 858 * if the "ioctl" requires a response containing data
882 859 * to be returned to the user, and no mblk could be
883 860 * allocated for the data. No such "ioctl" alters our
884 861 * state. Thus, we always go ahead and do any
885 862 * state-changes the "ioctl" calls for. If we couldn't
886 863 * allocate the data, "ttycommon_ioctl" has stashed the
887 864 * "ioctl" away safely, so we just call "qbufcall" to
888 865 * request that we be called back when we stand a
889 866 * better chance of allocating the data.
890 867 */
891 868 datasize = ttycommon_ioctl(&pvc->vc_ttycommon, q, mp, &error);
892 869 if (datasize != 0) {
893 870 if (pvc->vc_bufcallid != 0)
894 871 qunbufcall(q, pvc->vc_bufcallid);
895 872 pvc->vc_bufcallid = qbufcall(q, datasize, BPRI_HI,
896 873 wcreioctl, pvc);
897 874 return;
898 875 }
899 876
900 877 if (error < 0) {
901 878 if (iocp->ioc_cmd == TCSBRK)
902 879 error = 0;
903 880 else
904 881 error = EINVAL;
905 882 }
906 883 if (error != 0) {
907 884 iocp->ioc_error = error;
908 885 mp->b_datap->db_type = M_IOCNAK;
909 886 }
910 887 qreply(q, mp);
911 888 break;
912 889 }
913 890 }
914 891
915 892 /*
916 893 * This function gets the polled I/O structures from the lower
917 894 * keyboard driver. If any initialization or resource allocation
918 895 * needs to be done by the lower driver, it will be done when
919 896 * the lower driver services this message.
920 897 */
921 898 static void
922 899 wc_open_kb_polledio(struct wscons_state *wscons, queue_t *q, mblk_t *mp)
923 900 {
924 901 mblk_t *mp2;
925 902 struct iocblk *iocp;
926 903
927 904 DPRINTF(PRINT_L1, PRINT_MASK_ALL,
928 905 ("wc_open_kb_polledio: sending CONSOPENPOLLEDIO\n"));
929 906
930 907 mp2 = mkiocb(CONSOPENPOLLEDIO);
931 908
932 909 if (mp2 == NULL) {
933 910 /*
934 911 * If we can't get an mblk, then wait for it.
935 912 */
936 913 goto nomem;
937 914 }
938 915
939 916 mp2->b_cont = allocb(sizeof (struct cons_polledio *), BPRI_HI);
940 917
941 918 if (mp2->b_cont == NULL) {
942 919 /*
943 920 * If we can't get an mblk, then wait for it, and release
944 921 * the mblk that we have already allocated.
945 922 */
946 923 freemsg(mp2);
947 924 goto nomem;
948 925 }
949 926
950 927 iocp = (struct iocblk *)(void *)mp2->b_rptr;
951 928
952 929 iocp->ioc_count = sizeof (struct cons_polledio *);
953 930 mp2->b_cont->b_wptr = mp2->b_cont->b_rptr +
954 931 sizeof (struct cons_polledio *);
955 932
956 933 wscons->wc_pending_wq = q;
957 934 wscons->wc_pending_link = mp;
958 935 wscons->wc_kb_getpolledio_id = iocp->ioc_id;
959 936
960 937 putnext(wscons->wc_kbdqueue, mp2);
961 938
962 939 return;
963 940
964 941 nomem:
965 942 iocp = (struct iocblk *)(void *)mp->b_rptr;
966 943 iocp->ioc_error = ENOMEM;
967 944 mp->b_datap->db_type = M_IOCNAK;
968 945 qreply(q, mp);
969 946 }
970 947
971 948 /*
972 949 * This function releases the polled I/O structures from the lower
973 950 * keyboard driver. If any de-initialization needs to be done, or
974 951 * any resources need to be released, it will be done when the lower
975 952 * driver services this message.
976 953 */
977 954 static void
978 955 wc_close_kb_polledio(struct wscons_state *wscons, queue_t *q, mblk_t *mp)
979 956 {
980 957 mblk_t *mp2;
981 958 struct iocblk *iocp;
982 959
983 960 DPRINTF(PRINT_L1, PRINT_MASK_ALL,
984 961 ("wc_close_kb_polledio: sending CONSCLOSEPOLLEDIO\n"));
985 962
986 963 mp2 = mkiocb(CONSCLOSEPOLLEDIO);
987 964
988 965 if (mp2 == NULL) {
989 966 /*
990 967 * If we can't get an mblk, then wait for it.
991 968 */
992 969 goto nomem;
993 970 }
994 971
995 972 mp2->b_cont = allocb(sizeof (struct cons_polledio *), BPRI_HI);
996 973
997 974 if (mp2->b_cont == NULL) {
998 975 /*
999 976 * If we can't get an mblk, then wait for it, and release
1000 977 * the mblk that we have already allocated.
1001 978 */
1002 979 freemsg(mp2);
1003 980
1004 981 goto nomem;
1005 982 }
1006 983
1007 984 iocp = (struct iocblk *)(void *)mp2->b_rptr;
1008 985
1009 986 iocp->ioc_count = 0;
1010 987
1011 988 wscons->wc_pending_wq = q;
1012 989 wscons->wc_pending_link = mp;
1013 990 wscons->wc_kb_getpolledio_id = iocp->ioc_id;
1014 991
1015 992 putnext(wscons->wc_kbdqueue, mp2);
1016 993
1017 994 return;
1018 995
1019 996 nomem:
1020 997 iocp = (struct iocblk *)(void *)mp->b_rptr;
1021 998 iocp->ioc_error = ENOMEM;
1022 999 mp->b_datap->db_type = M_IOCNAK;
1023 1000 qreply(q, mp);
1024 1001 }
1025 1002
1026 1003 #ifdef _HAVE_TEM_FIRMWARE
1027 1004 /* ARGSUSED */
1028 1005 static void
1029 1006 wcopoll(void *arg)
1030 1007 {
1031 1008 vc_state_t *pvc = (vc_state_t *)arg;
1032 1009 queue_t *q;
1033 1010
1034 1011 q = pvc->vc_ttycommon.t_writeq;
1035 1012 pvc->vc_timeoutid = 0;
1036 1013
1037 1014 mutex_enter(&pvc->vc_state_lock);
1038 1015
1039 1016 /* See if we can continue output */
1040 1017 if ((pvc->vc_flags & WCS_BUSY) && pvc->vc_pendc != -1) {
1041 1018 if (prom_mayput((char)pvc->vc_pendc) == 0) {
1042 1019 pvc->vc_pendc = -1;
1043 1020 pvc->vc_flags &= ~WCS_BUSY;
1044 1021 if (!(pvc->vc_flags&(WCS_DELAY|WCS_STOPPED)))
1045 1022 wcstart(pvc);
1046 1023 } else
1047 1024 pvc->vc_timeoutid = qtimeout(q, wcopoll, pvc, 1);
1048 1025 }
1049 1026
1050 1027 mutex_exit(&pvc->vc_state_lock);
1051 1028 }
1052 1029 #endif /* _HAVE_TEM_FIRMWARE */
1053 1030
1054 1031 /*
1055 1032 * Restart output on the console after a timeout.
1056 1033 */
1057 1034 /* ARGSUSED */
1058 1035 static void
1059 1036 wcrstrt(void *arg)
1060 1037 {
1061 1038 vc_state_t *pvc = (vc_state_t *)arg;
1062 1039
1063 1040 ASSERT(pvc->vc_ttycommon.t_writeq != NULL);
1064 1041
1065 1042 mutex_enter(&pvc->vc_state_lock);
1066 1043 pvc->vc_flags &= ~WCS_DELAY;
1067 1044 mutex_exit(&pvc->vc_state_lock);
1068 1045
1069 1046 wcstart(pvc);
1070 1047 }
1071 1048
1072 1049 /*
1073 1050 * get screen terminal for current output
1074 1051 */
1075 1052 static tem_vt_state_t
1076 1053 wc_get_screen_tem(vc_state_t *pvc)
1077 1054 {
1078 1055 if (!tem_initialized(pvc->vc_tem) ||
1079 1056 tem_get_fbmode(pvc->vc_tem) != KD_TEXT)
1080 1057 return (NULL);
1081 1058
1082 1059 return (pvc->vc_tem);
1083 1060 }
1084 1061
1085 1062 /*
1086 1063 * Start console output
1087 1064 */
1088 1065 static void
1089 1066 wcstart(void *arg)
1090 1067 {
1091 1068 vc_state_t *pvc = (vc_state_t *)arg;
1092 1069 tem_vt_state_t ptem = NULL;
1093 1070 #ifdef _HAVE_TEM_FIRMWARE
1094 1071 int c;
1095 1072 ssize_t cc;
1096 1073 #endif /* _HAVE_TEM_FIRMWARE */
1097 1074 queue_t *q;
1098 1075 mblk_t *bp;
1099 1076 mblk_t *nbp;
1100 1077
1101 1078 /*
1102 1079 * If we're waiting for something to happen (delay timeout to
1103 1080 * expire, current transmission to finish, output to be
1104 1081 * restarted, output to finish draining), don't grab anything
1105 1082 * new.
1106 1083 */
1107 1084 if (pvc->vc_flags & (WCS_DELAY|WCS_BUSY|WCS_STOPPED))
1108 1085 return;
1109 1086
1110 1087 q = pvc->vc_ttycommon.t_writeq;
1111 1088 /*
1112 1089 * assumes that we have been called by whoever holds the
1113 1090 * exclusionary lock on the write-side queue (protects
1114 1091 * vc_flags and vc_pendc).
1115 1092 */
1116 1093 for (;;) {
1117 1094 if ((bp = getq(q)) == NULL)
1118 1095 return; /* nothing to transmit */
1119 1096
1120 1097 /*
1121 1098 * We have a new message to work on.
1122 1099 * Check whether it's a delay or an ioctl (the latter
1123 1100 * occurs if the ioctl in question was waiting for the output
1124 1101 * to drain). If it's one of those, process it immediately.
1125 1102 */
1126 1103 switch (bp->b_datap->db_type) {
1127 1104
1128 1105 case M_DELAY:
1129 1106 /*
1130 1107 * Arrange for "wcrstrt" to be called when the
1131 1108 * delay expires; it will turn WCS_DELAY off,
1132 1109 * and call "wcstart" to grab the next message.
1133 1110 */
1134 1111 if (pvc->vc_timeoutid != 0)
1135 1112 (void) quntimeout(q, pvc->vc_timeoutid);
1136 1113 pvc->vc_timeoutid = qtimeout(q, wcrstrt, pvc,
1137 1114 (clock_t)(*(unsigned char *)bp->b_rptr + 6));
1138 1115
1139 1116 mutex_enter(&pvc->vc_state_lock);
1140 1117 pvc->vc_flags |= WCS_DELAY;
1141 1118 mutex_exit(&pvc->vc_state_lock);
1142 1119
1143 1120 freemsg(bp);
1144 1121 return; /* wait for this to finish */
1145 1122
1146 1123 case M_IOCTL:
1147 1124 /*
1148 1125 * This ioctl was waiting for the output ahead of
1149 1126 * it to drain; obviously, it has. Do it, and
1150 1127 * then grab the next message after it.
1151 1128 */
1152 1129 wcioctl(q, bp);
1153 1130 continue;
1154 1131 }
1155 1132
1156 1133 #ifdef _HAVE_TEM_FIRMWARE
1157 1134 if (consmode == CONS_KFB) {
1158 1135 #endif /* _HAVE_TEM_FIRMWARE */
1159 1136 if ((ptem = wc_get_screen_tem(pvc)) != NULL) {
1160 1137
1161 1138 for (nbp = bp; nbp != NULL; nbp = nbp->b_cont) {
1162 1139 if (nbp->b_wptr > nbp->b_rptr) {
1163 1140 (void) tem_write(ptem,
1164 1141 nbp->b_rptr,
1165 1142 /* LINTED */
1166 1143 nbp->b_wptr - nbp->b_rptr,
1167 1144 kcred);
1168 1145 }
1169 1146 }
1170 1147
1171 1148 }
1172 1149
1173 1150 freemsg(bp);
1174 1151
1175 1152 #ifdef _HAVE_TEM_FIRMWARE
1176 1153 continue;
1177 1154 }
1178 1155
1179 1156 /* consmode = CONS_FW */
1180 1157 if (pvc->vc_minor != 0) {
1181 1158 freemsg(bp);
1182 1159 continue;
1183 1160 }
1184 1161
1185 1162 /* LINTED E_PTRDIFF_OVERFLOW */
1186 1163 if ((cc = bp->b_wptr - bp->b_rptr) == 0) {
1187 1164 freemsg(bp);
1188 1165 continue;
1189 1166 }
1190 1167 /*
1191 1168 * Direct output to the frame buffer if this device
1192 1169 * is not the "hardware" console.
1193 1170 */
1194 1171 if (wscons.wc_defer_output) {
1195 1172 /*
1196 1173 * Never do output here;
1197 1174 * it takes forever.
1198 1175 */
1199 1176 mutex_enter(&pvc->vc_state_lock);
1200 1177 pvc->vc_flags |= WCS_BUSY;
1201 1178 mutex_exit(&pvc->vc_state_lock);
1202 1179
1203 1180 pvc->vc_pendc = -1;
1204 1181 (void) putbq(q, bp);
1205 1182 if (q->q_count > 128) { /* do it soon */
1206 1183 softcall(wconsout, pvc);
1207 1184 } else { /* wait a bit */
1208 1185 if (pvc->vc_timeoutid != 0)
1209 1186 (void) quntimeout(q,
1210 1187 pvc->vc_timeoutid);
1211 1188 pvc->vc_timeoutid = qtimeout(q, wconsout,
1212 1189 pvc, hz / 30);
1213 1190 }
1214 1191 return;
1215 1192 }
1216 1193 for (;;) {
1217 1194 c = *bp->b_rptr++;
1218 1195 cc--;
1219 1196 if (prom_mayput((char)c) != 0) {
1220 1197
1221 1198 mutex_enter(&pvc->vc_state_lock);
1222 1199 pvc->vc_flags |= WCS_BUSY;
1223 1200 mutex_exit(&pvc->vc_state_lock);
1224 1201
1225 1202 pvc->vc_pendc = c;
1226 1203 if (pvc->vc_timeoutid != 0)
1227 1204 (void) quntimeout(q,
1228 1205 pvc->vc_timeoutid);
1229 1206 pvc->vc_timeoutid = qtimeout(q, wcopoll,
1230 1207 pvc, 1);
1231 1208 if (bp != NULL)
1232 1209 /* not done with this message yet */
1233 1210 (void) putbq(q, bp);
1234 1211 return;
1235 1212 }
1236 1213 while (cc <= 0) {
1237 1214 nbp = bp;
1238 1215 bp = bp->b_cont;
1239 1216 freeb(nbp);
1240 1217 if (bp == NULL)
1241 1218 return;
1242 1219 /* LINTED E_PTRDIFF_OVERFLOW */
1243 1220 cc = bp->b_wptr - bp->b_rptr;
1244 1221 }
1245 1222 }
1246 1223 #endif /* _HAVE_TEM_FIRMWARE */
1247 1224 }
1248 1225 }
1249 1226
1250 1227 #ifdef _HAVE_TEM_FIRMWARE
1251 1228 /*
1252 1229 * Output to frame buffer console.
1253 1230 * It takes a long time to scroll.
1254 1231 */
1255 1232 /* ARGSUSED */
1256 1233 static void
1257 1234 wconsout(void *arg)
1258 1235 {
1259 1236 vc_state_t *pvc = (vc_state_t *)arg;
1260 1237 uchar_t *cp;
1261 1238 ssize_t cc;
1262 1239 queue_t *q;
1263 1240 mblk_t *bp;
1264 1241 mblk_t *nbp;
1265 1242 char *current_position;
1266 1243 ssize_t bytes_left;
1267 1244
1268 1245 if ((q = pvc->vc_ttycommon.t_writeq) == NULL) {
1269 1246 return; /* not attached to a stream */
1270 1247 }
1271 1248
1272 1249 /*
1273 1250 * Set up to copy up to MAXHIWAT bytes.
1274 1251 */
1275 1252 current_position = &obuf[0];
1276 1253 bytes_left = MAXHIWAT;
1277 1254 while ((bp = getq(q)) != NULL) {
1278 1255 if (bp->b_datap->db_type == M_IOCTL) {
1279 1256 /*
1280 1257 * This ioctl was waiting for the output ahead of
1281 1258 * it to drain; obviously, it has. Put it back
1282 1259 * so that "wcstart" can handle it, and transmit
1283 1260 * what we've got.
1284 1261 */
1285 1262 (void) putbq(q, bp);
1286 1263 goto transmit;
1287 1264 }
1288 1265
1289 1266 do {
1290 1267 cp = bp->b_rptr;
1291 1268 /* LINTED E_PTRDIFF_OVERFLOW */
1292 1269 cc = bp->b_wptr - cp;
1293 1270 while (cc != 0) {
1294 1271 if (bytes_left == 0) {
1295 1272 /*
1296 1273 * Out of buffer space; put this
1297 1274 * buffer back on the queue, and
1298 1275 * transmit what we have.
1299 1276 */
1300 1277 bp->b_rptr = cp;
1301 1278 (void) putbq(q, bp);
1302 1279 goto transmit;
1303 1280 }
1304 1281 *current_position++ = *cp++;
1305 1282 cc--;
1306 1283 bytes_left--;
1307 1284 }
1308 1285 nbp = bp;
1309 1286 bp = bp->b_cont;
1310 1287 freeb(nbp);
1311 1288 } while (bp != NULL);
1312 1289 }
1313 1290
1314 1291 transmit:
1315 1292 if ((cc = MAXHIWAT - bytes_left) != 0)
1316 1293 console_puts(obuf, cc);
1317 1294
1318 1295 mutex_enter(&pvc->vc_state_lock);
1319 1296 pvc->vc_flags &= ~WCS_BUSY;
1320 1297 mutex_exit(&pvc->vc_state_lock);
1321 1298
1322 1299 wcstart(pvc);
1323 1300 }
1324 1301 #endif /* _HAVE_TEM_FIRMWARE */
1325 1302
1326 1303 /*
1327 1304 * Put procedure for lower read queue.
1328 1305 * Pass everything up to queue above "upper half".
1329 1306 */
1330 1307 static int
1331 1308 wclrput(queue_t *q, mblk_t *mp)
1332 1309 {
1333 1310 vc_state_t *pvc;
1334 1311 queue_t *upq;
1335 1312 struct iocblk *iocp;
1336 1313
1337 1314 pvc = vt_minor2vc(VT_ACTIVE);
1338 1315
1339 1316 DPRINTF(PRINT_L1, PRINT_MASK_ALL,
1340 1317 ("wclrput: wclrput type = 0x%x\n", mp->b_datap->db_type));
1341 1318
1342 1319 switch (mp->b_datap->db_type) {
1343 1320
1344 1321 case M_FLUSH:
1345 1322 if (*mp->b_rptr == FLUSHW || *mp->b_rptr == FLUSHRW) {
1346 1323 /*
1347 1324 * Flush our write queue.
1348 1325 */
1349 1326 /* XXX doesn't flush M_DELAY */
1350 1327 flushq(WR(q), FLUSHDATA);
1351 1328 *mp->b_rptr = FLUSHR; /* it has been flushed */
1352 1329 }
1353 1330 if (*mp->b_rptr == FLUSHR || *mp->b_rptr == FLUSHRW) {
1354 1331 flushq(q, FLUSHDATA);
1355 1332 *mp->b_rptr = FLUSHW; /* it has been flushed */
1356 1333 qreply(q, mp); /* give the read queues a crack at it */
1357 1334 } else
1358 1335 freemsg(mp);
1359 1336 break;
1360 1337
1361 1338 case M_DATA:
1362 1339 if (consmode == CONS_KFB && vt_check_hotkeys(mp)) {
1363 1340 freemsg(mp);
1364 1341 break;
1365 1342 }
1366 1343
1367 1344 if ((upq = pvc->vc_ttycommon.t_readq) != NULL) {
1368 1345 if (!canput(upq->q_next)) {
1369 1346 ttycommon_qfull(&pvc->vc_ttycommon, upq);
1370 1347 wcstart(pvc);
1371 1348 freemsg(mp);
1372 1349 } else {
1373 1350 putnext(upq, mp);
1374 1351 }
1375 1352 } else
1376 1353 freemsg(mp);
1377 1354 break;
1378 1355
1379 1356 case M_IOCACK:
1380 1357 case M_IOCNAK:
1381 1358 iocp = (struct iocblk *)(void *)mp->b_rptr;
1382 1359 if (wscons.wc_pending_link != NULL &&
1383 1360 iocp->ioc_id == wscons.wc_kb_getpolledio_id) {
1384 1361 switch (mp->b_datap->db_type) {
1385 1362
1386 1363 case M_IOCACK:
1387 1364 switch (iocp->ioc_cmd) {
1388 1365
1389 1366 case CONSOPENPOLLEDIO:
1390 1367 DPRINTF(PRINT_L1, PRINT_MASK_ALL,
1391 1368 ("wclrput: "
1392 1369 "ACK CONSOPENPOLLEDIO\n"));
1393 1370 wscons.wc_kb_polledio =
1394 1371 *(struct cons_polledio **)
1395 1372 (void *)mp->b_cont->b_rptr;
1396 1373 wscons.wc_polledio.
1397 1374 cons_polledio_getchar =
1398 1375 wc_polled_getchar;
1399 1376 wscons.wc_polledio.
1400 1377 cons_polledio_ischar =
1401 1378 wc_polled_ischar;
1402 1379 break;
1403 1380
1404 1381 case CONSCLOSEPOLLEDIO:
1405 1382 DPRINTF(PRINT_L1, PRINT_MASK_ALL,
1406 1383 ("wclrput: "
1407 1384 "ACK CONSCLOSEPOLLEDIO\n"));
1408 1385 wscons.wc_kb_polledio = NULL;
1409 1386 wscons.wc_kbdqueue = NULL;
1410 1387 wscons.wc_polledio.
1411 1388 cons_polledio_getchar = NULL;
1412 1389 wscons.wc_polledio.
1413 1390 cons_polledio_ischar = NULL;
1414 1391 break;
1415 1392 default:
1416 1393 DPRINTF(PRINT_L1, PRINT_MASK_ALL,
1417 1394 ("wclrput: "
1418 1395 "ACK UNKNOWN\n"));
1419 1396 }
1420 1397
1421 1398 break;
1422 1399 case M_IOCNAK:
1423 1400 /*
1424 1401 * Keyboard may or may not support polled I/O.
1425 1402 * This ioctl may have been rejected because
1426 1403 * we only have the wc->conskbd chain built,
1427 1404 * and the keyboard driver has not been linked
1428 1405 * underneath conskbd yet.
1429 1406 */
1430 1407 DPRINTF(PRINT_L1, PRINT_MASK_ALL,
1431 1408 ("wclrput: NAK\n"));
1432 1409
1433 1410 switch (iocp->ioc_cmd) {
1434 1411
1435 1412 case CONSCLOSEPOLLEDIO:
1436 1413 wscons.wc_kb_polledio = NULL;
1437 1414 wscons.wc_kbdqueue = NULL;
1438 1415 wscons.wc_polledio.
1439 1416 cons_polledio_getchar = NULL;
1440 1417 wscons.wc_polledio.
1441 1418 cons_polledio_ischar = NULL;
1442 1419 break;
1443 1420 }
1444 1421 break;
1445 1422 }
1446 1423
1447 1424 /*
1448 1425 * Discard the response, replace it with the
1449 1426 * pending response to the I_PLINK, then let it
1450 1427 * flow upward.
1451 1428 */
1452 1429 freemsg(mp);
1453 1430 mp = wscons.wc_pending_link;
1454 1431 wscons.wc_pending_link = NULL;
1455 1432 wscons.wc_kb_getpolledio_id = 0;
1456 1433 }
1457 1434 /* FALLTHROUGH */
1458 1435
1459 1436 default: /* inc M_ERROR, M_HANGUP, M_IOCACK, M_IOCNAK, ... */
1460 1437 if (wscons.wc_pending_wq != NULL) {
1461 1438 qreply(wscons.wc_pending_wq, mp);
1462 1439 wscons.wc_pending_wq = NULL;
1463 1440 break;
1464 1441 }
1465 1442
1466 1443 if ((upq = pvc->vc_ttycommon.t_readq) != NULL) {
1467 1444 putnext(upq, mp);
1468 1445 } else {
1469 1446 DPRINTF(PRINT_L1, PRINT_MASK_ALL,
1470 1447 ("wclrput: Message DISCARDED\n"));
1471 1448 freemsg(mp);
1472 1449 }
1473 1450 break;
1474 1451 }
1475 1452
1476 1453 return (0);
1477 1454 }
1478 1455
1479 1456 #ifdef _HAVE_TEM_FIRMWARE
1480 1457 /*
1481 1458 * This routine exists so that prom_write() can redirect writes
1482 1459 * to the framebuffer through the kernel terminal emulator, if
1483 1460 * that configuration is selected during consconfig.
1484 1461 * When the kernel terminal emulator is enabled, consconfig_dacf
1485 1462 * sets up the PROM output redirect vector to enter this function.
1486 1463 * During panic the console will already be powered up as part of
1487 1464 * calling into the prom_*() layer.
1488 1465 */
1489 1466 /* ARGSUSED */
1490 1467 ssize_t
1491 1468 wc_cons_wrtvec(promif_redir_arg_t arg, uchar_t *s, size_t n)
1492 1469 {
1493 1470 vc_state_t *pvc;
1494 1471
1495 1472 pvc = vt_minor2vc(VT_ACTIVE);
1496 1473
1497 1474 if (pvc->vc_tem == NULL)
1498 1475 return (0);
1499 1476
1500 1477 ASSERT(consmode == CONS_KFB);
1501 1478
1502 1479 if (panicstr)
1503 1480 polled_io_cons_write(s, n);
1504 1481 else
1505 1482 (void) tem_write(pvc->vc_tem, s, n, kcred);
1506 1483
1507 1484 return (n);
1508 1485 }
1509 1486 #endif /* _HAVE_TEM_FIRMWARE */
1510 1487
1511 1488 /*
1512 1489 * These are for systems without OBP, and for devices that cannot be
1513 1490 * shared between Solaris and the OBP.
1514 1491 */
1515 1492 static void
1516 1493 wc_polled_putchar(cons_polledio_arg_t arg, unsigned char c)
1517 1494 {
1518 1495 vc_state_t *pvc;
1519 1496
1520 1497 pvc = vt_minor2vc(VT_ACTIVE);
1521 1498
1522 1499 if (c == '\n')
1523 1500 wc_polled_putchar(arg, '\r');
1524 1501
1525 1502 if (pvc->vc_tem == NULL) {
1526 1503 /*
1527 1504 * We have no terminal emulator configured. We have no
1528 1505 * recourse but to drop the output on the floor.
1529 1506 */
1530 1507 return;
1531 1508 }
1532 1509
1533 1510 tem_safe_polled_write(pvc->vc_tem, &c, 1);
1534 1511 }
1535 1512
1536 1513 /*
1537 1514 * These are for systems without OBP, and for devices that cannot be
1538 1515 * shared between Solaris and the OBP.
1539 1516 */
1540 1517 static int
1541 1518 wc_polled_getchar(cons_polledio_arg_t arg)
1542 1519 {
1543 1520 struct wscons_state *wscons = (struct wscons_state *)arg;
1544 1521
1545 1522 if (wscons->wc_kb_polledio == NULL) {
1546 1523 prom_printf("wscons: getchar with no keyboard support");
1547 1524 prom_printf("Halted...");
1548 1525 for (;;)
1549 1526 /* HANG FOREVER */;
1550 1527 }
1551 1528
1552 1529 return (wscons->wc_kb_polledio->cons_polledio_getchar(
1553 1530 wscons->wc_kb_polledio->cons_polledio_argument));
1554 1531 }
1555 1532
1556 1533 static boolean_t
1557 1534 wc_polled_ischar(cons_polledio_arg_t arg)
1558 1535 {
1559 1536 struct wscons_state *wscons = (struct wscons_state *)arg;
1560 1537
1561 1538 if (wscons->wc_kb_polledio == NULL)
1562 1539 return (B_FALSE);
1563 1540
1564 1541 return (wscons->wc_kb_polledio->cons_polledio_ischar(
1565 1542 wscons->wc_kb_polledio->cons_polledio_argument));
1566 1543 }
1567 1544
1568 1545 static void
1569 1546 wc_polled_enter(cons_polledio_arg_t arg)
1570 1547 {
1571 1548 struct wscons_state *wscons = (struct wscons_state *)arg;
1572 1549
1573 1550 if (wscons->wc_kb_polledio == NULL)
1574 1551 return;
1575 1552
1576 1553 if (wscons->wc_kb_polledio->cons_polledio_enter != NULL) {
1577 1554 wscons->wc_kb_polledio->cons_polledio_enter(
1578 1555 wscons->wc_kb_polledio->cons_polledio_argument);
1579 1556 }
1580 1557 }
1581 1558
1582 1559 static void
1583 1560 wc_polled_exit(cons_polledio_arg_t arg)
1584 1561 {
1585 1562 struct wscons_state *wscons = (struct wscons_state *)arg;
1586 1563
1587 1564 if (wscons->wc_kb_polledio == NULL)
1588 1565 return;
1589 1566
1590 1567 if (wscons->wc_kb_polledio->cons_polledio_exit != NULL) {
1591 1568 wscons->wc_kb_polledio->cons_polledio_exit(
1592 1569 wscons->wc_kb_polledio->cons_polledio_argument);
1593 1570 }
1594 1571 }
1595 1572
1596 1573
1597 1574 #ifdef DEBUG
1598 1575 static void
1599 1576 wc_dprintf(const char *fmt, ...)
1600 1577 {
1601 1578 char buf[256];
1602 1579 va_list ap;
1603 1580
1604 1581 va_start(ap, fmt);
1605 1582 (void) vsprintf(buf, fmt, ap);
1606 1583 va_end(ap);
1607 1584
1608 1585 cmn_err(CE_WARN, "wc: %s", buf);
1609 1586 }
1610 1587 #endif
1611 1588
1612 1589 /*ARGSUSED*/
1613 1590 static void
1614 1591 update_property(vc_state_t *pvc, char *name, ushort_t value)
1615 1592 {
1616 1593 char data[8];
1617 1594
1618 1595 (void) snprintf(data, sizeof (data), "%u", value);
1619 1596
1620 1597 (void) ddi_prop_update_string(wscons.wc_dev, wc_dip, name, data);
1621 1598 }
1622 1599
1623 1600 /*
1624 1601 * Gets the number of text rows and columns and the
1625 1602 * width and height (in pixels) of the console.
1626 1603 */
1627 1604 void
1628 1605 wc_get_size(vc_state_t *pvc)
1629 1606 {
1630 1607 struct winsize *t = &pvc->vc_ttycommon.t_size;
1631 1608 ushort_t r = LOSCREENLINES, c = LOSCREENCOLS, x = 0, y = 0;
1632 1609
1633 1610 if (pvc->vc_tem != NULL)
1634 1611 tem_get_size(&r, &c, &x, &y);
1635 1612 #ifdef _HAVE_TEM_FIRMWARE
1636 1613 else
1637 1614 console_get_size(&r, &c, &x, &y);
1638 1615 #endif /* _HAVE_TEM_FIRMWARE */
1639 1616
1640 1617 mutex_enter(&pvc->vc_ttycommon.t_excl);
1641 1618 t->ws_col = c;
1642 1619 t->ws_row = r;
1643 1620 t->ws_xpixel = x;
1644 1621 t->ws_ypixel = y;
1645 1622 mutex_exit(&pvc->vc_ttycommon.t_excl);
1646 1623
1647 1624 if (pvc->vc_minor != 0)
1648 1625 return;
1649 1626
1650 1627 /* only for the wscons:0 */
1651 1628 update_property(pvc, "screen-#cols", c);
1652 1629 update_property(pvc, "screen-#rows", r);
1653 1630 update_property(pvc, "screen-width", x);
1654 1631 update_property(pvc, "screen-height", y);
1655 1632 }
1656 1633
1657 1634 /*ARGSUSED*/
1658 1635 static void
1659 1636 wc_modechg_cb(tem_modechg_cb_arg_t arg)
1660 1637 {
1661 1638 minor_t index;
1662 1639 vc_state_t *pvc;
1663 1640
1664 1641 mutex_enter(&vc_lock);
1665 1642 for (index = 0; index < VC_INSTANCES_COUNT; index++) {
1666 1643 pvc = vt_minor2vc(index);
1667 1644
1668 1645 mutex_enter(&pvc->vc_state_lock);
1669 1646
1670 1647 if ((pvc->vc_flags & WCS_ISOPEN) &&
1671 1648 (pvc->vc_flags & WCS_INIT))
1672 1649 wc_get_size(pvc);
1673 1650
1674 1651 mutex_exit(&pvc->vc_state_lock);
1675 1652 }
1676 1653 mutex_exit(&vc_lock);
1677 1654 }
↓ open down ↓ |
1263 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX