1 /* $NetBSD: qv.c,v 1.29 2014/03/16 05:20:26 dholland Exp $ */ 2 3 /*- 4 * Copyright (c) 1988 5 * The Regents of the University of California. All rights reserved. 6 * (c) UNIX System Laboratories, Inc. 7 * All or some portions of this file are derived from material licensed 8 * to the University of California by American Telephone and Telegraph 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10 * the permission of UNIX System Laboratories, Inc. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)qv.c 7.2 (Berkeley) 1/21/94 37 */ 38 39 /* 40 * derived from: @(#)qv.c 1.8 (ULTRIX) 8/21/85 41 */ 42 43 /************************************************************************ 44 * * 45 * Copyright (c) 1985 by * 46 * Digital Equipment Corporation, Maynard, MA * 47 * All rights reserved. * 48 * * 49 * This software is furnished under a license and may be used and * 50 * copied only in accordance with the terms of such license and * 51 * with the inclusion of the above copyright notice. This * 52 * software or any other copies thereof may not be provided or * 53 * otherwise made available to any other person. No title to and * 54 * ownership of the software is hereby transferred. * 55 * * 56 * This software is derived from software received from the * 57 * University of California, Berkeley, and from Bell * 58 * Laboratories. Use, duplication, or disclosure is subject to * 59 * restrictions under license agreements with University of * 60 * California and with AT&T. * 61 * * 62 * The information in this software is subject to change without * 63 * notice and should not be construed as a commitment by Digital * 64 * Equipment Corporation. * 65 * * 66 * Digital assumes no responsibility for the use or reliability * 67 * of its software on equipment which is not supplied by Digital. * 68 * * 69 ************************************************************************ 70 * 71 * This driver provides glass tty functionality to the qvss. It is a strange 72 * device in that it supports three subchannels. The first being the asr, 73 * the second being a channel that intercepts the chars headed for the screen 74 * ( like a pseudo tty ) and the third being a source of mouse state changes. 75 * NOTE: the second is conditional on #ifdef CONS_HACK in this version 76 * of the driver, as it's a total crock. 77 * 78 * There may be one and only one qvss in the system. This restriction is based 79 * on the inability to map more than one at a time. This restriction will 80 * exist until the kernel has shared memory services. This driver therefore 81 * support a single unit. No attempt was made to have it service more. 82 * 83 * (this belongs in sccs - not here) 84 * 85 * 02 Aug 85 -- rjl 86 * Changed the names of the special setup routines so that the system 87 * can have a qvss or a qdss system console. 88 * 89 * 03 Jul 85 -- rjl 90 * Added a check for virtual mode in qvputc so that the driver 91 * doesn't crash while in a dump which is done in physical mode. 92 * 93 * 10 Apr 85 -- jg 94 * Well, our theory about keyboard handling was wrong; most of the 95 * keyboard is in autorepeat, down mode. These changes are to make 96 * the qvss work the same as the Vs100, which is not necessarily 97 * completely correct, as some chord usage may fail. But since we 98 * can't easily change the Vs100, we might as well propagate the 99 * problem to another device. There are also changes for screen and 100 * mouse accellaration. 101 * 102 * 27 Mar 85 -- rjl 103 * MicroVAX-II systems have interval timers that interrupt at ipl4. 104 * Everything else is higher and thus causes us to miss clock ticks. The 105 * problem isn't severe except in the case of a device like this one that 106 * generates lots of interrupts. We aren't willing to make this change to 107 * all device drivers but it seems acceptable in this case. 108 * 109 * 3 Dec 84 -- jg 110 * To continue the tradition of building a better mouse trap, this 111 * driver has been extended to form Vs100 style event queues. If the 112 * mouse device is open, the keyboard events are intercepted and put 113 * into the shared memory queue. Unfortunately, we are ending up with 114 * one of the longest Unix device drivers. Sigh.... 115 * 116 * 20 Nov 84 -- rjl 117 * As a further complication this driver is required to function as the 118 * virtual system console. This code runs before and during auto- 119 * configuration and therefore is require to have a second path for setup. 120 * It is futher constrained to have a character output routine that 121 * is not dependent on the interrupt system. 122 * 123 */ 124 125 #include <sys/cdefs.h> 126 __KERNEL_RCSID(0, "$NetBSD: qv.c,v 1.29 2014/03/16 05:20:26 dholland Exp $"); 127 128 #include "qv.h" 129 #if NQV > 0 130 131 #include "../include/pte.h" 132 133 #include "sys/param.h" 134 #include "sys/conf.h" 135 #include "qvioctl.h" 136 #include "sys/tty.h" 137 #include "sys/buf.h" 138 #include "sys/vm.h" 139 #include "sys/file.h" 140 #include "sys/uio.h" 141 #include "sys/kernel.h" 142 #include "sys/syslog.h" 143 #include "../include/cpu.h" 144 #include "../include/mtpr.h" 145 #include "ubareg.h" 146 #include "ubavar.h" 147 148 #define CONS_HACK 149 150 struct uba_device *qvinfo[NQV]; 151 152 struct tty qv_tty[NQV*4]; 153 154 #define nNQV NQV 155 int nqv = NQV*4; 156 157 /* 158 * Definition of the driver for the auto-configuration program. 159 */ 160 int qvprobe(), qvattach(), qvkint(), qvvint(); 161 u_short qvstd[] = { 0 }; 162 struct uba_driver qvdriver = 163 { qvprobe, 0, qvattach, 0, qvstd, "qv", qvinfo }; 164 165 extern char qvmem[][512*VAX_NBPG]; 166 extern struct pte QVmap[][512]; 167 168 /* 169 * Local variables for the driver. Initialized for 15' screen 170 * so that it can be used during the boot process. 171 */ 172 173 #define QVWAITPRI (PZERO+1) 174 175 #define QVKEYBOARD 0 /* minor 0, keyboard/glass tty */ 176 #define QVPCONS 1 /* minor 1, console interceptor XXX */ 177 #define QVMOUSECHAN 2 /* minor 2, mouse */ 178 #define QVSPARE 3 /* unused */ 179 #define QVCHAN(unit) ((unit) & 03) 180 /* 181 * v_putc is the switch that is used to redirect the console cnputc to the 182 * virtual console vputc. consops is used to redirect the console 183 * device to the qvss console. 184 */ 185 extern int (*v_putc)(); 186 extern const struct cdevsw *consops; 187 /* 188 * qv_def_scrn is used to select the appropriate tables. 0=15 inch 1=19 inch, 189 * 2 = uVAXII. 190 */ 191 int qv_def_scrn = 2; 192 193 #define QVMAXEVQ 64 /* must be power of 2 */ 194 #define EVROUND(x) ((x) & (QVMAXEVQ - 1)) 195 196 /* 197 * Screen parameters 15 & 19 inch monitors. These determine the max size in 198 * pixel and character units for the display and cursor positions. 199 * Notice that the mouse defaults to original square algorithm, but X 200 * will change to its defaults once implemented. 201 */ 202 struct qv_info *qv_scn; 203 struct qv_info qv_scn_defaults[] = { 204 {0, {0, 0}, 0, {0, 0}, 0, 0, 30, 80, 768, 480, 768-16, 480-16, 205 0, 0, 0, 0, 0, QVMAXEVQ, 0, 0, {0, 0}, {0, 0, 0, 0}, 2, 4}, 206 {0, {0, 0}, 0, {0, 0}, 0, 0, 55, 120, 960, 864, 960-16, 864-16, 207 0, 0, 0, 0, 0, QVMAXEVQ, 0, 0, {0, 0}, {0, 0, 0, 0}, 2, 4}, 208 {0, {0, 0}, 0, {0, 0}, 0, 0, 56, 120,1024, 864,1024-16, 864-16, 209 0, 0, 0, 0, 0, QVMAXEVQ, 0, 0, {0, 0}, {0, 0, 0, 0}, 2, 4} 210 }; 211 212 /* 213 * Screen controller initialization parameters. The definations and use 214 * of these parameters can be found in the Motorola 68045 crtc specs. In 215 * essence they set the display parameters for the chip. The first set is 216 * for the 15" screen and the second is for the 19" separate sync. There 217 * is also a third set for a 19" composite sync monitor which we have not 218 * tested and which is not supported. 219 */ 220 static short qv_crt_parms[][16] = { 221 { 31, 25, 27, 0142, 31, 13, 30, 31, 4, 15, 040, 0, 0, 0, 0, 0 }, 222 /* VR100*/ { 39, 30, 32, 0262, 55, 5, 54, 54, 4, 15, 040, 0, 0, 0, 0, 0 }, 223 /* VR260*/ { 39, 32, 33, 0264, 56, 5, 54, 54, 4, 15, 040, 0, 0, 0, 0, 0}, 224 }; 225 226 /* 227 * Screen parameters 228 */ 229 struct qv_info *qv_scn; 230 int maxqvmem = 254*1024 - sizeof(struct qv_info) - QVMAXEVQ*sizeof(vsEvent); 231 232 /* 233 * Keyboard state 234 */ 235 struct qv_keyboard { 236 int shift; /* state variables */ 237 int cntrl; 238 int lock; 239 char last; /* last character */ 240 } qv_keyboard; 241 242 short divdefaults[15] = { LK_DOWN, /* 0 doesn't exist */ 243 LK_AUTODOWN, LK_AUTODOWN, LK_AUTODOWN, LK_DOWN, 244 LK_UPDOWN, LK_UPDOWN, LK_AUTODOWN, LK_AUTODOWN, 245 LK_AUTODOWN, LK_AUTODOWN, LK_AUTODOWN, LK_AUTODOWN, 246 LK_DOWN, LK_AUTODOWN }; 247 248 short kbdinitstring[] = { /* reset any random keyboard stuff */ 249 LK_AR_ENABLE, /* we want autorepeat by default */ 250 LK_CL_ENABLE, /* keyclick */ 251 0x84, /* keyclick volume */ 252 LK_KBD_ENABLE, /* the keyboard itself */ 253 LK_BELL_ENABLE, /* keyboard bell */ 254 0x84, /* bell volume */ 255 LK_LED_DISABLE, /* keyboard leds */ 256 LED_ALL }; 257 #define KBD_INIT_LENGTH sizeof(kbdinitstring)/sizeof(short) 258 259 #define TOY ((time.tv_sec * 100) + (time.tv_usec / 10000)) 260 261 int qv_ipl_lo = 1; /* IPL low flag */ 262 int mouseon = 0; /* mouse channel is enabled when 1*/ 263 struct proc *qvrsel; /* process waiting for select */ 264 265 int qvstart(), qvputc(), ttrstrt(); 266 267 /* 268 * Keyboard translation and font tables 269 */ 270 extern u_short q_key[], q_shift_key[], q_cursor[]; 271 extern char *q_special[], q_font[]; 272 273 dev_type_open(qvopen); 274 dev_type_close(qvclose); 275 dev_type_read(qvread); 276 dev_type_write(qvwrite); 277 dev_type_ioctl(qvioctl); 278 dev_type_stop(qvstop); 279 dev_type_poll(qvpoll); 280 dev_type_kqfilter(qvkqfilter); 281 282 const struct cdevsw qv_cdevsw = { 283 .d_open = qvopen, 284 .d_close = qvclose, 285 .d_read = qvread, 286 .d_write = qvwrite, 287 .d_ioctl = qvioctl, 288 .d_stop = qvstop, 289 .d_tty = notty, 290 .d_poll = qvpoll, 291 .d_mmap = nommap, 292 .d_kqfilter = qvkqfilter, 293 .d_flag = 0 294 }; 295 296 /* 297 * See if the qvss will interrupt. 298 */ 299 300 /*ARGSUSED*/ 301 qvprobe(void *reg, int ctlr) 302 { 303 register int br, cvec; /* these are ``value-result'' */ 304 register struct qvdevice *qvaddr = (struct qvdevice *)reg; 305 static int tvec, ovec; 306 307 #ifdef lint 308 br = 0; cvec = br; br = cvec; 309 qvkint(0); qvvint(0); 310 #endif 311 /* 312 * Allocate the next two vectors 313 */ 314 tvec = 0360; 315 ovec = cvec; 316 /* 317 * Turn on the keyboard and vertical interrupt vectors. 318 */ 319 qvaddr->qv_intcsr = 0; /* init the interrupt controller */ 320 qvaddr->qv_intcsr = 0x40; /* reset irr */ 321 qvaddr->qv_intcsr = 0x80; /* specify individual vectors */ 322 qvaddr->qv_intcsr = 0xc0; /* preset autoclear data */ 323 qvaddr->qv_intdata = 0xff; /* all setup as autoclear */ 324 325 qvaddr->qv_intcsr = 0xe0; /* preset vector address 1 */ 326 qvaddr->qv_intdata = tvec; /* give it the keyboard vector */ 327 qvaddr->qv_intcsr = 0x28; /* enable tx/rx interrupt */ 328 329 qvaddr->qv_intcsr = 0xe1; /* preset vector address 2 */ 330 qvaddr->qv_intdata = tvec+4; /* give it the vertical sysnc */ 331 qvaddr->qv_intcsr = 0x29; /* enable */ 332 333 qvaddr->qv_intcsr = 0xa1; /* arm the interrupt ctrl */ 334 335 qvaddr->qv_uartcmd = 0x15; /* set mode pntr/enable rx/tx */ 336 qvaddr->qv_uartmode = 0x17; /* noparity, 8-bit */ 337 qvaddr->qv_uartmode = 0x07; /* 1 stop bit */ 338 qvaddr->qv_uartstatus = 0x99; /* 4800 baud xmit/recv */ 339 qvaddr->qv_uartintstatus = 2; /* enable recv interrupts */ 340 341 qvaddr->qv_csr |= QV_INT_ENABLE | QV_CUR_MODE; 342 343 DELAY(10000); 344 345 qvaddr->qv_csr &= ~QV_INT_ENABLE; 346 347 /* 348 * If the qvss did interrupt it was the second vector not 349 * the first so we have to return the first so that they 350 * will be setup properly 351 */ 352 if( ovec == cvec ) { 353 return 0; 354 } else 355 cvec -= 4; 356 return (sizeof (struct qvdevice)); 357 } 358 359 /* 360 * Routine called to attach a qv. 361 */ 362 qvattach(struct uba_device *ui) 363 { 364 365 /* 366 * If not the console then we have to setup the screen 367 */ 368 if (v_putc != qvputc || ui->ui_unit != 0) 369 (void)qv_setup((struct qvdevice *)ui->ui_addr, ui->ui_unit, 1); 370 else 371 qv_scn->qvaddr = (struct qvdevice *)ui->ui_addr; 372 } 373 374 375 /*ARGSUSED*/ 376 int 377 qvopen(dev_t dev, int flag, int mode, struct proc *p) 378 { 379 register struct tty *tp; 380 register int unit, qv; 381 register struct qvdevice *qvaddr; 382 register struct uba_device *ui; 383 register struct qv_info *qp = qv_scn; 384 385 unit = minor(dev); 386 qv = unit >> 2; 387 if (unit >= nqv || (ui = qvinfo[qv])== 0 || ui->ui_alive == 0) 388 return (ENXIO); 389 if (QVCHAN(unit) == QVSPARE 390 #ifndef CONS_HACK 391 || QVCHAN(unit) == QVPCONS 392 #endif 393 ) 394 return (ENODEV); 395 tp = &qv_tty[unit]; 396 if (tp->t_state&TS_XCLUDE && u.u_uid!=0) 397 return (EBUSY); 398 qvaddr = (struct qvdevice *)ui->ui_addr; 399 qv_scn->qvaddr = qvaddr; 400 tp->t_addr = (void *)qvaddr; 401 tp->t_oproc = qvstart; 402 403 if ((tp->t_state&TS_ISOPEN) == 0) { 404 ttychars(tp); 405 tp->t_state = TS_ISOPEN|TS_CARR_ON; 406 tp->t_ispeed = B9600; 407 tp->t_ospeed = B9600; 408 if( QVCHAN(unit) == QVKEYBOARD ) { 409 /* make sure keyboard is always back to default */ 410 qvkbdreset(); 411 qvaddr->qv_csr |= QV_INT_ENABLE; 412 tp->t_iflag = TTYDEF_IFLAG; 413 tp->t_oflag = TTYDEF_OFLAG; 414 tp->t_lflag = TTYDEF_LFLAG; 415 tp->t_cflag = TTYDEF_CFLAG; 416 } 417 /* XXX ?why? else 418 tp->t_flags = RAW; 419 */ 420 } 421 /* 422 * Process line discipline specific open if its not the 423 * mouse channel. For the mouse we init the ring ptr's. 424 */ 425 if( QVCHAN(unit) != QVMOUSECHAN ) 426 return ((*tp->t_linesw->l_open)(dev, tp)); 427 else { 428 mouseon = 1; 429 /* set up event queue for later */ 430 qp->ibuff = (vsEvent *)qp - QVMAXEVQ; 431 qp->iqsize = QVMAXEVQ; 432 qp->ihead = qp->itail = 0; 433 return 0; 434 } 435 436 return (0); 437 } 438 439 /* 440 * Close a QVSS line. 441 */ 442 /*ARGSUSED*/ 443 int 444 qvclose(dev_t dev, int flag, int mode, struct proc *p) 445 { 446 register struct tty *tp; 447 register unit; 448 register struct qvdevice *qvaddr; 449 int error; 450 451 unit = minor(dev); 452 tp = &qv_tty[unit]; 453 454 /* 455 * If this is the keyboard unit (0) shutdown the 456 * interface. 457 */ 458 qvaddr = (struct qvdevice *)tp->t_addr; 459 if (QVCHAN(unit) == QVKEYBOARD ) 460 qvaddr->qv_csr &= ~QV_INT_ENABLE; 461 462 /* 463 * If unit is not the mouse channel call the line disc. 464 * otherwise clear the state flag, and put the keyboard into down/up. 465 */ 466 if (QVCHAN(unit) != QVMOUSECHAN) { 467 (*tp->t_linesw->l_close)(tp, flag); 468 error = ttyclose(tp); 469 } else { 470 mouseon = 0; 471 qv_init( qvaddr ); 472 error = 0; 473 } 474 tp->t_state = 0; 475 return (error); 476 } 477 478 int 479 qvread(dev_t dev, struct uio *uio, int flag) 480 { 481 register struct tty *tp; 482 int unit = minor( dev ); 483 484 if (QVCHAN(unit) != QVMOUSECHAN) { 485 tp = &qv_tty[unit]; 486 return ((*tp->t_linesw->l_read)(tp, uio)); 487 } 488 return (ENXIO); 489 } 490 491 int 492 qvwrite(dev_t dev, struct uio *uio, int flag) 493 { 494 register struct tty *tp; 495 int unit = minor( dev ); 496 497 /* 498 * If this is the mouse we simply fake the i/o, otherwise 499 * we let the line disp. handle it. 500 */ 501 if (QVCHAN(unit) == QVMOUSECHAN) { 502 uio->uio_offset = uio->uio_resid; 503 uio->uio_resid = 0; 504 return 0; 505 } 506 tp = &qv_tty[unit]; 507 return ((*tp->t_linesw->l_write)(tp, uio)); 508 } 509 510 int 511 qvpoll(dev_t dev, int events, struct proc *p) 512 { 513 register struct tty *tp; 514 int unit = minor( dev ); 515 516 /* 517 * XXX Should perform similar checks to deprecated `qvselect()' 518 */ 519 tp = &qv_tty[unit]; 520 return ((*tp->t_linesw->l_poll)(tp, events, p)); 521 } 522 523 /* 524 * XXX Is qvselect() even useful now? 525 * This driver looks to have suffered some serious bit-rot... 526 */ 527 528 /* 529 * Mouse activity select routine 530 */ 531 qvselect(dev_t dev, rw) 532 { 533 register int s = spl5(); 534 register struct qv_info *qp = qv_scn; 535 536 if( QVCHAN(minor(dev)) == QVMOUSECHAN ) 537 switch(rw) { 538 case FREAD: /* if events okay */ 539 if(qp->ihead != qp->itail) { 540 splx(s); 541 return(1); 542 } 543 qvrsel = u.u_procp; 544 splx(s); 545 return(0); 546 default: /* can never write */ 547 splx(s); 548 return(0); 549 } 550 else { 551 splx(s); 552 return( ttselect(dev, rw) ); 553 } 554 /*NOTREACHED*/ 555 } 556 557 /* 558 * QVSS keyboard interrupt. 559 */ 560 qvkint(int qv) 561 { 562 struct tty *tp; 563 register c; 564 struct uba_device *ui; 565 register int key; 566 register int i; 567 568 ui = qvinfo[qv]; 569 if (ui == 0 || ui->ui_alive == 0) 570 return; 571 tp = &qv_tty[qv<<2]; 572 /* 573 * Get a character from the keyboard. 574 */ 575 key = ((struct qvdevice *)ui->ui_addr)->qv_uartdata & 0xff; 576 if( mouseon == 0) { 577 /* 578 * Check for various keyboard errors 579 */ 580 if( key == LK_POWER_ERROR || key == LK_KDOWN_ERROR || 581 key == LK_INPUT_ERROR || key == LK_OUTPUT_ERROR) { 582 log(LOG_ERR, 583 "qv%d: Keyboard error, code = %x\n",qv,key); 584 return; 585 } 586 if( key < LK_LOWEST ) return; 587 /* 588 * See if its a state change key 589 */ 590 switch ( key ) { 591 case LOCK: 592 qv_keyboard.lock ^= 0xffff; /* toggle */ 593 if( qv_keyboard.lock ) 594 qv_key_out( LK_LED_ENABLE ); 595 else 596 qv_key_out( LK_LED_DISABLE ); 597 qv_key_out( LED_3 ); 598 return; 599 case SHIFT: 600 qv_keyboard.shift ^= 0xffff; 601 return; 602 case CNTRL: 603 qv_keyboard.cntrl ^= 0xffff; 604 return; 605 case ALLUP: 606 qv_keyboard.cntrl = qv_keyboard.shift = 0; 607 return; 608 case REPEAT: 609 c = qv_keyboard.last; 610 break; 611 default: 612 /* 613 * Test for control characters. If set, see if the character 614 * is elligible to become a control character. 615 */ 616 if( qv_keyboard.cntrl ) { 617 c = q_key[ key ]; 618 if( c >= ' ' && c <= '~' ) 619 c &= 0x1f; 620 } else if( qv_keyboard.lock || qv_keyboard.shift ) 621 c = q_shift_key[ key ]; 622 else 623 c = q_key[ key ]; 624 break; 625 } 626 627 qv_keyboard.last = c; 628 629 /* 630 * Check for special function keys 631 */ 632 if( c & 0x80 ) { 633 register char *string; 634 string = q_special[ c & 0x7f ]; 635 while( *string ) 636 (*tp->t_linesw->l_rint)(*string++, tp); 637 } else 638 (*tp->t_linesw->l_rint)(c, tp); 639 } else { 640 /* 641 * Mouse channel is open put it into the event queue 642 * instead. 643 */ 644 register struct qv_info *qp = qv_scn; 645 register vsEvent *vep; 646 647 if ((i = EVROUND(qp->itail+1)) == qp->ihead) 648 return; 649 vep = &qp->ibuff[qp->itail]; 650 vep->vse_direction = VSE_KBTRAW; 651 vep->vse_type = VSE_BUTTON; 652 vep->vse_device = VSE_DKB; 653 vep->vse_x = qp->mouse.x; 654 vep->vse_y = qp->mouse.y; 655 vep->vse_time = TOY; 656 vep->vse_key = key; 657 qp->itail = i; 658 if(qvrsel) { 659 selnotify(qvrsel, 0, 0); 660 qvrsel = 0; 661 } 662 } 663 } 664 665 /* 666 * Ioctl for QVSS. 667 */ 668 /*ARGSUSED*/ 669 int 670 qvioctl(dev_t dev, u_long cmd, register void *data, int flag, struct proc *p) 671 { 672 register struct tty *tp; 673 register int unit = minor(dev); 674 register struct qv_info *qp = qv_scn; 675 register struct qv_kpcmd *qk; 676 register unsigned char *cp; 677 int error; 678 679 /* 680 * Check for and process qvss specific ioctl's 681 */ 682 switch( cmd ) { 683 case QIOCGINFO: /* return screen info */ 684 memcpy(data, (void *)qp, sizeof (struct qv_info)); 685 break; 686 687 case QIOCSMSTATE: /* set mouse state */ 688 qp->mouse = *((vsCursor *)data); 689 qv_pos_cur( qp->mouse.x, qp->mouse.y ); 690 break; 691 692 case QIOCINIT: /* init screen */ 693 qv_init( qp->qvaddr ); 694 break; 695 696 case QIOCKPCMD: 697 qk = (struct qv_kpcmd *)data; 698 if(qk->nbytes == 0) qk->cmd |= 0200; 699 if(mouseon == 0) qk->cmd |= 1; /* no mode changes */ 700 qv_key_out(qk->cmd); 701 cp = &qk->par[0]; 702 while(qk->nbytes-- > 0) { /* terminate parameters */ 703 if(qk->nbytes <= 0) *cp |= 0200; 704 qv_key_out(*cp++); 705 } 706 break; 707 case QIOCADDR: /* get struct addr */ 708 *(struct qv_info **) data = qp; 709 break; 710 default: /* not ours ?? */ 711 tp = &qv_tty[unit]; 712 error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag); 713 if (error != EPASSTHROUGH) 714 return (error); 715 return ttioctl(tp, cmd, data, flag); 716 break; 717 } 718 return (0); 719 } 720 /* 721 * Initialize the screen and the scanmap 722 */ 723 qv_init(struct qvdevice *qvaddr) 724 { 725 register short *scanline; 726 register int i; 727 register short scan; 728 register char *ptr; 729 register struct qv_info *qp = qv_scn; 730 731 /* 732 * Clear the bit map 733 */ 734 for( i=0 , ptr = qp->bitmap ; i<240 ; i += 2 , ptr += 2048) 735 memset( ptr, 0, 2048 ); 736 /* 737 * Reinitialize the scanmap 738 */ 739 scan = qvaddr->qv_csr & QV_MEM_BANK; 740 scanline = qp->scanmap; 741 for(i = 0 ; i < qp->max_y ; i++ ) 742 *scanline++ = scan++; 743 744 /* 745 * Home the cursor 746 */ 747 qp->row = qp->col = 0; 748 749 /* 750 * Reset the cursor to the default type. 751 */ 752 for( i=0 ; i<16 ; i++ ) 753 qp->cursorbits[i] = q_cursor[i]; 754 qvaddr->qv_csr |= QV_CUR_MODE; 755 /* 756 * Reset keyboard to default state. 757 */ 758 qvkbdreset(); 759 } 760 761 qvreset(void) 762 { 763 } 764 qvkbdreset(void) 765 { 766 register int i; 767 qv_key_out(LK_DEFAULTS); 768 for( i=1 ; i < 15 ; i++ ) 769 qv_key_out( divdefaults[i] | (i<<3)); 770 for (i = 0; i < KBD_INIT_LENGTH; i++) 771 qv_key_out(kbdinitstring[i]); 772 } 773 774 #define abs(x) (((x) > 0) ? (x) : (-(x))) 775 /* 776 * QVSS vertical sync interrupt 777 */ 778 qvvint(int qv) 779 { 780 extern int selwait; 781 register struct qvdevice *qvaddr; 782 struct uba_device *ui; 783 register struct qv_info *qp = qv_scn; 784 int unit; 785 struct tty *tp0; 786 int i; 787 register int j; 788 /* 789 * Mouse state info 790 */ 791 static ushort omouse = 0, nmouse = 0; 792 static char omx=0, omy=0, mx=0, my=0, om_switch=0, m_switch=0; 793 register int dx, dy; 794 795 /* 796 * Test and set the qv_ipl_lo flag. If the result is not zero then 797 * someone else must have already gotten here. 798 */ 799 if( --qv_ipl_lo ) 800 return; 801 (void)spl4(); 802 ui = qvinfo[qv]; 803 unit = qv<<2; 804 qvaddr = (struct qvdevice *)ui->ui_addr; 805 tp0 = &qv_tty[QVCHAN(unit) + QVMOUSECHAN]; 806 /* 807 * See if the mouse has moved. 808 */ 809 if( omouse != (nmouse = qvaddr->qv_mouse) ) { 810 omouse = nmouse; 811 mx = nmouse & 0xff; 812 my = nmouse >> 8; 813 dy = my - omy; omy = my; 814 dx = mx - omx; omx = mx; 815 if( dy < 50 && dy > -50 && dx < 50 && dx > -50 ) { 816 register vsEvent *vep; 817 if( qp->mscale < 0 ) { /* Ray Lanza's original */ 818 if( dy < 0 ) 819 dy = -( dy * dy ); 820 else 821 dy *= dy; 822 if( dx < 0 ) 823 dx = -( dx * dx ); 824 else 825 dx *= dx; 826 } 827 else { /* Vs100 style, see WGA spec */ 828 int thresh = qp->mthreshold; 829 int scale = qp->mscale; 830 if( abs(dx) > thresh ) { 831 if ( dx < 0 ) 832 dx = (dx + thresh)*scale - thresh; 833 else 834 dx = (dx - thresh)*scale + thresh; 835 } 836 if( abs(dy) > thresh ) { 837 if ( dy < 0 ) 838 dy = (dy + thresh)*scale - thresh; 839 else 840 dy = (dy - thresh)*scale + thresh; 841 } 842 } 843 qp->mouse.x += dx; 844 qp->mouse.y -= dy; 845 if( qp->mouse.x < 0 ) 846 qp->mouse.x = 0; 847 if( qp->mouse.y < 0 ) 848 qp->mouse.y = 0; 849 if( qp->mouse.x > qp->max_cur_x ) 850 qp->mouse.x = qp->max_cur_x; 851 if( qp->mouse.y > qp->max_cur_y ) 852 qp->mouse.y = qp->max_cur_y; 853 if( tp0->t_state & TS_ISOPEN ) 854 qv_pos_cur( qp->mouse.x, qp->mouse.y ); 855 if (qp->mouse.y < qp->mbox.bottom && 856 qp->mouse.y >= qp->mbox.top && 857 qp->mouse.x < qp->mbox.right && 858 qp->mouse.x >= qp->mbox.left) goto switches; 859 qp->mbox.bottom = 0; /* trash box */ 860 if (EVROUND(qp->itail+1) == qp->ihead) 861 goto switches; 862 i = EVROUND(qp->itail - 1); 863 if ((qp->itail != qp->ihead) && (i != qp->ihead)) { 864 vep = & qp->ibuff[i]; 865 if(vep->vse_type == VSE_MMOTION) { 866 vep->vse_x = qp->mouse.x; 867 vep->vse_y = qp->mouse.y; 868 goto switches; 869 } 870 } 871 /* put event into queue and do select */ 872 vep = & qp->ibuff[qp->itail]; 873 vep->vse_type = VSE_MMOTION; 874 vep->vse_time = TOY; 875 vep->vse_x = qp->mouse.x; 876 vep->vse_y = qp->mouse.y; 877 qp->itail = EVROUND(qp->itail+1); 878 } 879 } 880 /* 881 * See if mouse switches have changed. 882 */ 883 switches:if( om_switch != ( m_switch = (qvaddr->qv_csr & QV_MOUSE_ANY) >> 8 ) ) { 884 qp->mswitches = ~m_switch & 0x7; 885 for (j = 0; j < 3; j++) { /* check each switch */ 886 register vsEvent *vep; 887 if ( ((om_switch>>j) & 1) == ((m_switch>>j) & 1) ) 888 continue; 889 /* check for room in the queue */ 890 if ((i = EVROUND(qp->itail+1)) == qp->ihead) return; 891 /* put event into queue and do select */ 892 vep = &qp->ibuff[qp->itail]; 893 vep->vse_type = VSE_BUTTON; 894 vep->vse_key = 2 - j; 895 vep->vse_direction = VSE_KBTDOWN; 896 if ( (m_switch >> j) & 1) 897 vep->vse_direction = VSE_KBTUP; 898 vep->vse_device = VSE_MOUSE; 899 vep->vse_time = TOY; 900 vep->vse_x = qp->mouse.x; 901 vep->vse_y = qp->mouse.y; 902 } 903 qp->itail = i; 904 om_switch = m_switch; 905 qp->mswitches = m_switch; 906 } 907 /* if we have proc waiting, and event has happened, wake him up */ 908 if(qvrsel && (qp->ihead != qp->itail)) { 909 selnotify(qvrsel, 0, 0); 910 qvrsel = 0; 911 } 912 /* 913 * Okay we can take another hit now 914 */ 915 qv_ipl_lo = 1; 916 } 917 918 /* 919 * Start transmission 920 */ 921 qvstart(register struct tty *tp) 922 { 923 register int unit, c; 924 register struct tty *tp0; 925 int s; 926 927 unit = minor(tp->t_dev); 928 #ifdef CONS_HACK 929 tp0 = &qv_tty[(unit&0xfc)+QVPCONS]; 930 #endif 931 unit = QVCHAN(unit); 932 933 s = spl5(); 934 /* 935 * If it's currently active, or delaying, no need to do anything. 936 */ 937 if (tp->t_state&(TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) 938 goto out; 939 /* 940 * Display chars until the queue is empty, if the second subchannel 941 * is open direct them there. Drop characters from subchannels other 942 * than 0 on the floor. 943 */ 944 945 while( tp->t_outq.c_cc ) { 946 c = getc(&tp->t_outq); 947 if (unit == QVKEYBOARD) 948 #ifdef CONS_HACK 949 if( tp0->t_state & TS_ISOPEN ){ 950 (*tp0->t_linesw->l_rint)(c, tp0); 951 } else 952 #endif 953 qvputchar( c & 0xff ); 954 } 955 /* 956 * Position the cursor to the next character location. 957 */ 958 qv_pos_cur( qv_scn->col*8, qv_scn->row*15 ); 959 960 /* 961 * If there are sleepers, and output has drained below low 962 * water mark, wake up the sleepers. 963 */ 964 ttypull(tp); 965 tp->t_state &= ~TS_BUSY; 966 out: 967 splx(s); 968 } 969 970 /* 971 * Stop output on a line, e.g. for ^S/^Q or output flush. 972 */ 973 /*ARGSUSED*/ 974 void 975 qvstop(register struct tty *tp, int flag) 976 { 977 register int s; 978 979 /* 980 * Block input/output interrupts while messing with state. 981 */ 982 s = spl5(); 983 if (tp->t_state & TS_BUSY) { 984 if ((tp->t_state&TS_TTSTOP)==0) { 985 tp->t_state |= TS_FLUSH; 986 } else 987 tp->t_state &= ~TS_BUSY; 988 } 989 splx(s); 990 } 991 992 qvputc(char c) 993 { 994 qvputchar(c); 995 if (c == '\n') 996 qvputchar('\r'); 997 } 998 999 /* 1000 * Routine to display a character on the screen. The model used is a 1001 * glass tty. It is assummed that the user will only use this emulation 1002 * during system boot and that the screen will be eventually controlled 1003 * by a window manager. 1004 * 1005 */ 1006 qvputchar( c ) 1007 register char c; 1008 { 1009 1010 register char *b_row, *f_row; 1011 register int i; 1012 register short *scanline; 1013 register int ote = 128; 1014 register struct qv_info *qp = qv_scn; 1015 1016 /* 1017 * This routine may be called in physical mode by the dump code 1018 * so we check and punt if that's the case. 1019 */ 1020 if( (mfpr(MAPEN) & 1) == 0 ) 1021 return; 1022 1023 c &= 0x7f; 1024 1025 switch ( c ) { 1026 case '\t': /* tab */ 1027 for( i = 8 - (qp->col & 0x7) ; i > 0 ; i-- ) 1028 qvputchar( ' ' ); 1029 break; 1030 1031 case '\r': /* return */ 1032 qp->col = 0; 1033 break; 1034 1035 case '\010': /* backspace */ 1036 if( --qp->col < 0 ) 1037 qp->col = 0; 1038 break; 1039 1040 case '\n': /* linefeed */ 1041 if( qp->row+1 >= qp->max_row ) 1042 qvscroll(); 1043 else 1044 qp->row++; 1045 /* 1046 * Position the cursor to the next character location. 1047 */ 1048 qv_pos_cur( qp->col*8, qp->row*15 ); 1049 break; 1050 1051 case '\007': /* bell */ 1052 /* 1053 * We don't do anything to the keyboard until after 1054 * autoconfigure. 1055 */ 1056 if( qp->qvaddr ) 1057 qv_key_out( LK_RING_BELL ); 1058 return; 1059 1060 default: 1061 if( c >= ' ' && c <= '~' ) { 1062 scanline = qp->scanmap; 1063 b_row = qp->bitmap+(scanline[qp->row*15]&0x3ff)*128+qp->col; 1064 i = c - ' '; 1065 if( i < 0 || i > 95 ) 1066 i = 0; 1067 else 1068 i *= 15; 1069 f_row = (char *)((int)q_font + i); 1070 1071 /* for( i=0 ; i<15 ; i++ , b_row += 128, f_row++ ) 1072 *b_row = *f_row;*/ 1073 /* inline expansion for speed */ 1074 *b_row = *f_row++; b_row += ote; 1075 *b_row = *f_row++; b_row += ote; 1076 *b_row = *f_row++; b_row += ote; 1077 *b_row = *f_row++; b_row += ote; 1078 *b_row = *f_row++; b_row += ote; 1079 *b_row = *f_row++; b_row += ote; 1080 *b_row = *f_row++; b_row += ote; 1081 *b_row = *f_row++; b_row += ote; 1082 *b_row = *f_row++; b_row += ote; 1083 *b_row = *f_row++; b_row += ote; 1084 *b_row = *f_row++; b_row += ote; 1085 *b_row = *f_row++; b_row += ote; 1086 *b_row = *f_row++; b_row += ote; 1087 *b_row = *f_row++; b_row += ote; 1088 *b_row = *f_row++; b_row += ote; 1089 1090 if( ++qp->col >= qp->max_col ) { 1091 qp->col = 0 ; 1092 if( qp->row+1 >= qp->max_row ) 1093 qvscroll(); 1094 else 1095 qp->row++; 1096 } 1097 } 1098 break; 1099 } 1100 } 1101 1102 /* 1103 * Position the cursor to a particular spot. 1104 */ 1105 qv_pos_cur( x, y) 1106 register int x,y; 1107 { 1108 register struct qvdevice *qvaddr; 1109 register struct qv_info *qp = qv_scn; 1110 register index; 1111 1112 if( qvaddr = qp->qvaddr ) { 1113 if( y < 0 || y > qp->max_cur_y ) 1114 y = qp->max_cur_y; 1115 if( x < 0 || x > qp->max_cur_x ) 1116 x = qp->max_cur_x; 1117 qp->cursor.x = x; /* keep track of real cursor*/ 1118 qp->cursor.y = y; /* position, indep. of mouse*/ 1119 1120 qvaddr->qv_crtaddr = 10; /* select cursor start reg */ 1121 qvaddr->qv_crtdata = y & 0xf; 1122 qvaddr->qv_crtaddr = 11; /* select cursor end reg */ 1123 qvaddr->qv_crtdata = y & 0xf; 1124 qvaddr->qv_crtaddr = 14; /* select cursor y pos. */ 1125 qvaddr->qv_crtdata = y >> 4; 1126 qvaddr->qv_xcur = x; /* pos x axis */ 1127 /* 1128 * If the mouse is being used then we change the mode of 1129 * cursor display based on the pixels under the cursor 1130 */ 1131 if( mouseon ) { 1132 index = y*128 + x/8; 1133 if( qp->bitmap[ index ] && qp->bitmap[ index+128 ] ) 1134 qvaddr->qv_csr &= ~QV_CUR_MODE; 1135 else 1136 qvaddr->qv_csr |= QV_CUR_MODE; 1137 } 1138 } 1139 } 1140 /* 1141 * Scroll the bitmap by moving the scanline map words. This could 1142 * be done by moving the bitmap but it's much too slow for a full screen. 1143 * The only drawback is that the scanline map must be reset when the user 1144 * wants to do graphics. 1145 */ 1146 qvscroll(void) 1147 { 1148 short tmpscanlines[15]; 1149 register char *b_row; 1150 register short *scanline; 1151 register struct qv_info *qp = qv_scn; 1152 1153 /* 1154 * If the mouse is on we don't scroll so that the bit map 1155 * remains sane. 1156 */ 1157 if( mouseon ) { 1158 qp->row = 0; 1159 return; 1160 } 1161 /* 1162 * Save the first 15 scanlines so that we can put them at 1163 * the bottom when done. 1164 */ 1165 memcpy((void *)tmpscanlines, (void *)qp->scanmap, sizeof tmpscanlines); 1166 1167 /* 1168 * Clear the wrapping line so that it won't flash on the bottom 1169 * of the screen. 1170 */ 1171 scanline = qp->scanmap; 1172 b_row = qp->bitmap+(*scanline&0x3ff)*128; 1173 memset( b_row, 0, 1920 ); 1174 1175 /* 1176 * Now move the scanlines down 1177 */ 1178 memcpy((void *)qp->scanmap, (void *)(qp->scanmap+15), 1179 (qp->row * 15) * sizeof (short) ); 1180 1181 /* 1182 * Now put the other lines back 1183 */ 1184 memcpy((void *)(qp->scanmap+(qp->row * 15)), (void *)tmpscanlines, 1185 sizeof (tmpscanlines) ); 1186 1187 } 1188 1189 /* 1190 * Output to the keyboard. This routine status polls the transmitter on the 1191 * keyboard to output a code. The timer is to avoid hanging on a bad device. 1192 */ 1193 qv_key_out(u_short c) 1194 { 1195 int timer = 30000; 1196 register struct qv_info *qp = qv_scn; 1197 1198 if (qp->qvaddr) { 1199 while ((qp->qvaddr->qv_uartstatus & 0x4) == 0 && timer--) 1200 ; 1201 qp->qvaddr->qv_uartdata = c; 1202 } 1203 } 1204 /* 1205 * Virtual console initialization. This routine sets up the qvss so that it can 1206 * be used as the system console. It is invoked before autoconfig and has to do 1207 * everything necessary to allow the device to serve as the system console. 1208 * In this case it must map the q-bus and device areas and initialize the qvss 1209 * screen. 1210 */ 1211 qvcons_init(void) 1212 { 1213 struct percpu *pcpu; /* pointer to percpu structure */ 1214 register struct qbus *qb; 1215 struct qvdevice *qvaddr; /* device pointer */ 1216 short *devptr; /* virtual device space */ 1217 extern cnputc(); /* standard serial console putc */ 1218 #define QVSSCSR 017200 1219 1220 /* 1221 * If secondary console already configured, 1222 * don't override the previous one. 1223 */ 1224 if (v_putc != cnputc) 1225 return 0; 1226 /* 1227 * find the percpu entry that matches this machine. 1228 */ 1229 for( pcpu = percpu ; pcpu && pcpu->pc_cputype != cpu ; pcpu++ ) 1230 ; 1231 if( pcpu == NULL ) 1232 return 0; 1233 if (pcpu->pc_io->io_type != IO_QBUS) 1234 return 0; 1235 1236 /* 1237 * Found an entry for this CPU. Because this device is Microvax specific 1238 * we assume that there is a single q-bus and don't have to worry about 1239 * multiple adapters. 1240 * 1241 * Map the device registers. 1242 */ 1243 qb = (struct qbus *)pcpu->pc_io->io_details; 1244 ioaccess(qb->qb_iopage, UMEMmap[0] + qb->qb_memsize, UBAIOPAGES * VAX_NBPG); 1245 1246 /* 1247 * See if the qvss is there. 1248 */ 1249 devptr = (short *)((char *)umem[0] + (qb->qb_memsize * VAX_NBPG)); 1250 qvaddr = (struct qvdevice *)((u_int)devptr + ubdevreg(QVSSCSR)); 1251 if (badaddr((void *)qvaddr, sizeof(short))) 1252 return 0; 1253 /* 1254 * Okay the device is there lets set it up 1255 */ 1256 if (!qv_setup(qvaddr, 0, 0)) 1257 return 0; 1258 v_putc = qvputc; 1259 consops = &qv_cdevsw; 1260 return 1; 1261 } 1262 /* 1263 * Do the board specific setup 1264 */ 1265 qv_setup(struct qvdevice *qvaddr, int unit, int probed) 1266 { 1267 void *qvssmem; /* pointer to the display mem */ 1268 register i; /* simple index */ 1269 register struct qv_info *qp; 1270 register int *pte; 1271 struct percpu *pcpu; /* pointer to percpu structure */ 1272 register struct qbus *qb; 1273 1274 /* 1275 * find the percpu entry that matches this machine. 1276 */ 1277 for( pcpu = percpu ; pcpu && pcpu->pc_cputype != cpu ; pcpu++ ) 1278 ; 1279 if( pcpu == NULL ) 1280 return(0); 1281 1282 /* 1283 * Found an entry for this CPU. Because this device is Microvax specific 1284 * we assume that there is a single q-bus and don't have to worry about 1285 * multiple adapters. 1286 * 1287 * Map the device memory. 1288 */ 1289 qb = (struct qbus *)pcpu->pc_io->io_details; 1290 1291 i = (u_int)(qvaddr->qv_csr & QV_MEM_BANK) << 7; 1292 ioaccess(qb->qb_maddr + i, QVmap[unit], 512 * VAX_NBPG); 1293 qvssmem = qvmem[unit]; 1294 pte = (int *)(QVmap[unit]); 1295 for (i=0; i < 512; i++, pte++) 1296 *pte = (*pte & ~PG_PROT) | PG_UW | PG_V; 1297 1298 qv_scn = (struct qv_info *)((u_int)qvssmem + 251*1024); 1299 qp = qv_scn; 1300 if( (qvaddr->qv_csr & QV_19INCH) && qv_def_scrn == 0) 1301 qv_def_scrn = 1; 1302 *qv_scn = qv_scn_defaults[ qv_def_scrn ]; 1303 if (probed) 1304 qp->qvaddr = qvaddr; 1305 qp->bitmap = qvssmem; 1306 qp->scanmap = (short *)((u_int)qvssmem + 254*1024); 1307 qp->cursorbits = (short *)((u_int)qvssmem + 256*1024-32); 1308 /* set up event queue for later */ 1309 qp->ibuff = (vsEvent *)qp - QVMAXEVQ; 1310 qp->iqsize = QVMAXEVQ; 1311 qp->ihead = qp->itail = 0; 1312 1313 /* 1314 * Setup the crt controller chip. 1315 */ 1316 for( i=0 ; i<16 ; i++ ) { 1317 qvaddr->qv_crtaddr = i; 1318 qvaddr->qv_crtdata = qv_crt_parms[ qv_def_scrn ][ i ]; 1319 } 1320 /* 1321 * Setup the display. 1322 */ 1323 qv_init( qvaddr ); 1324 1325 /* 1326 * Turn on the video 1327 */ 1328 qvaddr->qv_csr |= QV_VIDEO_ENA ; 1329 return 1; 1330 } 1331 #endif 1332