1 /* $NetBSD: grf_ul.c,v 1.24 1997/07/29 17:50:01 veego Exp $ */ 2 #define UL_DEBUG 3 4 /* 5 * Copyright (c) 1995 Ignatios Souvatzis 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Ignatios Souvatzis for 19 * the NetBSD project. 20 * 4. The name of the authors may not be used to endorse or promote products 21 * derived from this software without specific prior written permission 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 #include "grful.h" 35 #if NGRFUL > 0 36 37 /* Graphics routines for the University of Lowell A2410 board, 38 using the TMS34010 processor. */ 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/errno.h> 43 #include <sys/ioctl.h> 44 #include <sys/device.h> 45 #include <sys/malloc.h> 46 #include <sys/syslog.h> 47 48 #include <machine/cpu.h> 49 50 #include <amiga/amiga/device.h> 51 #include <amiga/amiga/isr.h> 52 #include <amiga/dev/zbusvar.h> 53 #include <amiga/dev/grfioctl.h> 54 #include <amiga/dev/grfvar.h> 55 #include <amiga/dev/grf_ulreg.h> 56 57 extern u_int16_t tmscode[]; 58 59 int ul_ioctl __P((struct grf_softc *, u_long, void *, dev_t)); 60 int ul_getcmap __P((struct grf_softc *, struct grf_colormap *, dev_t)); 61 int ul_putcmap __P((struct grf_softc *, struct grf_colormap *, dev_t)); 62 int ul_bitblt __P((struct grf_softc *, struct grf_bitblt *, dev_t)); 63 int ul_blank __P((struct grf_softc *, int *, dev_t)); 64 65 static int ulisr __P((void *)); 66 int ulowell_alive __P((struct grfvideo_mode *)); 67 static void ul_load_code __P((struct grf_softc *)); 68 static int ul_load_mon __P((struct grf_softc *, struct grfvideo_mode *)); 69 static int ul_getvmode __P((struct grf_softc *, struct grfvideo_mode *)); 70 static int ul_setvmode __P((struct grf_softc *, unsigned)); 71 static __inline void ul_setfb __P((struct grf_softc *, u_long)); 72 73 /* 74 * marked true early so that ulowell_cnprobe() can tell if we are alive. 75 */ 76 int ulowell_inited; 77 78 /* standard-palette definition */ 79 u_int8_t ul_std_palette[] = { 80 0,128, 0,128, 0,128, 0,128, 0,255, 0,255, 0,255, 0,255, 81 0, 0,128,128, 0, 0,128,128, 0, 0,255,255, 0, 0,255,255, 82 0, 0, 0, 0, 128,128,128,128, 0, 0, 0, 0, 255,255,255,255}; 83 84 u_int8_t ul_ovl_palette[] = { 85 128, 0, 0, 0, 86 128, 0, 0, 0, 87 128, 0, 0, 0}; 88 89 struct grfvideo_mode ul_monitor_defs[] = { 90 91 /* 92 * We give all these values in MI units, that is: 93 * horizontal timings in units of pixels 94 * vertical timings in units of lines 95 * point of reference is blanking end. 96 * 97 * The ul_load_mon transforms these values right before loading 98 * them into the chip. 99 * 100 * This leaves us with a single point where things are transformed, 101 * which should make life easier if we ever change things again. 102 */ 103 104 /* 1024x768, 60Hz */ 105 {1,"1024x768", 66667000, 1024,768,8, 1024,1088,1296,1392, 106 768,771,774,798, 0}, 107 /* 864x648, 70Hz */ 108 {2,"864x648", 50000000, 864,648,8, 864,928,992,1056, 109 648,658,663,678, 0}, 110 /* 800x600, 60Hz */ 111 {3, "800x600", 36000000, 800,600,8, 800,864,928,992, 112 600,610,615,630, 0}, 113 /* 640x400, 60 Hz, interlaced */ 114 {4, "640x400i", 14318000, 640,400,8, 640,768,832,912, 115 200,223,203,240, 1}, 116 /* 1024x768, 65Hz interlaced, s.th. is strange */ 117 {5, "1024x768?i", 44980000, 1024,768,8, 1024,1072,1136,1280, 118 488,509,512,534, 1}, 119 /* 1024x1024, 60Hz */ 120 {6, "1024x1024", 80000000, 1024,1024,8, 1024,1040,1120,1248, 121 1024,1027,1030,1055, 0}, 122 /* 736x480, 60 Hz */ 123 {7, "736x480", 28636300, 736,480,8, 736,784,848,928, 124 480,491,495,515, 0}, 125 }; 126 127 int ulowell_mon_max = sizeof (ul_monitor_defs)/sizeof (ul_monitor_defs[0]); 128 129 /* option settable */ 130 #ifndef ULOWELL_OSC1 131 #define ULOWELL_OSC1 36000000 132 #endif 133 134 #ifndef ULOWELL_OSC2 135 #define ULOWELL_OSC2 66667000 136 #endif 137 138 #ifndef ULOWELL_DEFAULT_MON 139 #define ULOWELL_DEFAULT_MON 1 140 #endif 141 142 /* patchable */ 143 int ulowell_default_mon = ULOWELL_DEFAULT_MON; 144 int ulowell_default_gfx = ULOWELL_DEFAULT_MON; 145 146 /* 147 * yes, this should be per board. We don't pay service to multiple boards, 148 * anyway. 149 */ 150 151 u_long ulowell_clock[2] = { ULOWELL_OSC2, ULOWELL_OSC1 }; 152 153 static struct grfvideo_mode *current_mon; 154 155 /* 156 * We dont use ints at the moment, but will need this later to avoid 157 * busy_waiting in gsp_write, and we use it for spurious int warnings. 158 */ 159 160 static int 161 ulisr(arg) 162 void *arg; 163 { 164 struct grf_softc *gp = arg; 165 struct gspregs *ba; 166 u_int16_t thebits; 167 168 if (gp == NULL) 169 return 0; 170 171 ba = (struct gspregs *)gp->g_regkva; 172 173 if (ba == NULL) 174 return 0; 175 176 thebits = ba->ctrl; 177 if (thebits & INTOUT) { 178 log(LOG_INFO, "grf4: got interrupt, ctrl=0x%4x\n", thebits); 179 /* clear int */ 180 ba->ctrl = thebits & ~INTOUT; 181 return 1; 182 } 183 return 0; 184 } 185 186 /* 187 * used to query the ulowell board to see if its alive. 188 * for the moment, a NOP. 189 */ 190 int 191 ulowell_alive(mdp) 192 struct grfvideo_mode *mdp; 193 { 194 return 1; 195 } 196 197 /* 198 * Load the (mostly) ite support code and the default colormaps. 199 */ 200 static void 201 ul_load_code(gp) 202 struct grf_softc *gp; 203 { 204 struct grf_ul_softc *gup; 205 struct gspregs *ba; 206 struct grfinfo *gi; 207 int i,j; 208 #if 0 209 struct grf_colormap gcm; 210 #endif 211 212 gup = (struct grf_ul_softc *)gp; 213 ba = (struct gspregs *)gp->g_regkva; 214 gi = &gp->g_display; 215 216 gi->gd_regaddr = ztwopa((caddr_t)ba); 217 gi->gd_regsize = sizeof(struct gspregs); 218 gi->gd_fbaddr = NULL; 219 gi->gd_fbsize = 0; 220 gi->gd_fbwidth = 1024; 221 gi->gd_fbheight = 1024; 222 gi->gd_colors = 256; 223 224 ba->ctrl = (ba->ctrl & ~INCR) | (LBL | INCW); 225 ba->hstadrh = 0xC000; 226 ba->hstadrl = 0x0080; 227 ba->data = 0x0; /* disable screen refresh and video output */ 228 ba->data = 0xFFFC; /* screen refresh base address */ 229 ba->data = 0xFFFF; /* no display int possible */ 230 ba->data = 0x000C; /* CAS before RAS refresh each 64 local clks */ 231 232 ba->ctrl = (ba->ctrl & ~INCW) | LBL; 233 ba->hstadrh = 0xfe80; 234 ba->hstadrl = 0; 235 ba->data = 4; 236 ba->hstadrl = 0x20; 237 ba->data = 0xFF; /* all color planes visible */ 238 239 ba->hstadrl = 0; 240 ba->data = 5; 241 ba->hstadrl = 0x20; 242 ba->data = 0; /* no color planes blinking */ 243 244 ba->hstadrl = 0; 245 ba->data = 6; 246 ba->hstadrl = 0x20; 247 ba->data = gup->gus_ovslct = 0x43; 248 /* overlay visible, no overlay blinking, overlay color 0 transparent */ 249 250 ba->hstadrl = 0; 251 ba->data = 7; 252 ba->hstadrl = 0x20; 253 ba->data = 0; /* voodoo */ 254 255 /* clear overlay planes */ 256 ba->ctrl |= INCW; 257 ba->hstadrh = 0xff80; 258 ba->hstadrl = 0x0000; 259 for (i=0xff80000; i< 0xffa0000; ++i) { 260 ba->data = 0; 261 } 262 263 /* download tms code */ 264 265 ba->ctrl = LBL | INCW | NMI | NMIM | HLT | CF; 266 267 printf("\ndownloading TMS code"); 268 i=0; 269 while ((j = tmscode[i++])) { 270 printf("."); 271 ba->hstadrh = tmscode[i++]; 272 ba->hstadrl = tmscode[i++]; 273 while (j-- > 0) { 274 ba->data = tmscode[i++]; 275 } 276 } 277 278 /* font info was uploaded in ite_ul.c(ite_ulinit). */ 279 280 #if 1 281 /* XXX load image palette with some initial values, slightly hacky */ 282 283 ba->hstadrh = 0xfe80; 284 ba->hstadrl = 0x0000; 285 ba->ctrl |= INCW; 286 ba->data = 0; 287 ba->ctrl &= ~INCW; 288 289 for (i=0; i<16; ++i) { 290 ba->data = gup->gus_imcmap[i+ 0] = ul_std_palette[i+ 0]; 291 ba->data = gup->gus_imcmap[i+256] = ul_std_palette[i+16]; 292 ba->data = gup->gus_imcmap[i+512] = ul_std_palette[i+32]; 293 } 294 295 /* 296 * XXX load shadow overlay palette with what the TMS code will load 297 * into the real one some time after the TMS code is started below. 298 * This might be considered a rude hack. 299 */ 300 bcopy(ul_ovl_palette, gup->gus_ovcmap, 3*4); 301 302 /* 303 * Unflush cache, unhalt cpu -> nmi starts to run. This MUST NOT BE 304 * DONE before the image color map initialization above, to guarantee 305 * the index register in the BT458 is not used by more than one CPU 306 * at once. 307 * 308 * XXX For the same reason, we'll have to rething ul_putcmap(). For 309 * details, look at comment there. 310 */ 311 ba->ctrl &= ~(HLT|CF); 312 313 #else 314 /* 315 * XXX I wonder why this partially ever worked. 316 * 317 * This can't possibly work this way, as we are copyin()ing data in 318 * ul_putcmap. 319 * 320 * I guess this partially worked because SFC happened to point to 321 * to supervisor data space on 68030 machines coming from the old 322 * boot loader. 323 * 324 * While this looks more correct than the hack in the other part of the 325 * loop, we would have to do our own version of the loop through 326 * colormap entries, set up command buffer, and call gsp_write(), or 327 * factor out some code. 328 */ 329 330 /* 331 * XXX This version will work for the overlay, if our queue codes 332 * initial conditions are set at load time (not start time). 333 * It further assumes that ul_putcmap only uses the 334 * GRFIMDEV/GRFOVDEV bits of the dev parameter. 335 */ 336 337 338 /* unflush cache, unhalt cpu first -> nmi starts to run */ 339 ba->ctrl &= ~(HLT|CF); 340 341 gcm.index = 0; 342 gcm.count = 16; 343 gcm.red = ul_std_palette + 0; 344 gcm.green = ul_std_palette + 16; 345 gcm.blue = ul_std_palette + 32; 346 ul_putcmap(gp, &gcm, GRFIMDEV); 347 348 gcm.index = 0; 349 gcm.count = 4; 350 gcm.red = ul_ovl_palette + 0; 351 gcm.green = ul_ovl_palette + 4; 352 gcm.blue = ul_ovl_palette + 8; 353 ul_putcmap(gp, &gcm, GRFOVDEV); 354 #endif 355 356 } 357 358 static int 359 ul_load_mon(gp, md) 360 struct grf_softc *gp; 361 struct grfvideo_mode *md; 362 { 363 struct grf_ul_softc *gup; 364 struct grfinfo *gi; 365 struct gspregs *ba; 366 u_int16_t buf[8]; 367 368 gup = (struct grf_ul_softc *)gp; 369 gi = &gp->g_display; 370 ba = (struct gspregs *)gp->g_regkva; 371 372 gi->gd_dyn.gdi_fbx = 0; 373 gi->gd_dyn.gdi_fby = 0; 374 gi->gd_dyn.gdi_dwidth = md->disp_width; 375 gi->gd_dyn.gdi_dheight = md->disp_height; 376 gi->gd_dyn.gdi_dx = 0; 377 gi->gd_dyn.gdi_dy = 0; 378 379 ba->ctrl = (ba->ctrl & ~INCR) | (LBL | INCW); /* XXX */ 380 381 ba->hstadrh = 0xC000; 382 ba->hstadrl = 0x0000; 383 384 ba->data = (md->hsync_stop - md->hsync_start)/16; 385 ba->data = (md->htotal - md->hsync_start)/16 - 1; 386 ba->data = (md->hblank_start + md->htotal - md->hsync_start)/16 - 1; 387 ba->data = md->htotal/16 - 1; 388 389 ba->data = md->vsync_stop - md->vsync_start; 390 ba->data = md->vtotal - md->vsync_start - 1; 391 ba->data = md->vblank_start + md->vtotal - md->vsync_start - 1; 392 ba->data = md->vtotal - 1; 393 394 ba->ctrl &= ~INCW; 395 ba->hstadrh = 0xFE90; 396 ba->hstadrl = 0x0000; 397 398 if (abs(md->pixel_clock - ulowell_clock[0]) > 399 abs(md->pixel_clock - ulowell_clock[1])) { 400 401 ba->data = (ba->data & 0xFC) | 2 | 1; 402 md->pixel_clock = ulowell_clock[1]; 403 404 } else { 405 ba->data = (ba->data & 0xFC) | 2 | 0; 406 md->pixel_clock = ulowell_clock[0]; 407 } 408 409 ba->ctrl |= LBL | INCW; 410 ba->hstadrh = 0xC000; 411 ba->hstadrl = 0x0080; 412 ba->data = md->disp_flags & GRF_FLAGS_LACE ? 0xb020 : 0xf020; 413 414 /* I guess this should be in the yet unimplemented mode select ioctl */ 415 /* Hm.. maybe not. We always put the console on overlay plane no 0. */ 416 /* Anyway, this _IS_ called in the mode select ioctl. */ 417 418 /* ite support code parameters: */ 419 buf[0] = GCMD_MCHG; 420 buf[1] = md->disp_width; /* display width */ 421 buf[2] = md->disp_height; /* display height */ 422 buf[3] = 0; /* LSW of frame buffer origin */ 423 buf[4] = 0xFF80; /* MSW of frame buffer origin */ 424 buf[5] = gi->gd_fbwidth * 1; /* frame buffer pitch */ 425 buf[6] = 1; /* frame buffer depth */ 426 gsp_write(ba, buf, 7); 427 428 return(1); 429 } 430 431 int ul_mode __P((struct grf_softc *, u_long, void *, u_long, int)); 432 433 void grfulattach __P((struct device *, struct device *, void *)); 434 int grfulprint __P((void *, const char *)); 435 int grfulmatch __P((struct device *, struct cfdata *, void *)); 436 437 struct cfattach grful_ca = { 438 sizeof(struct grf_ul_softc), grfulmatch, grfulattach 439 }; 440 441 struct cfdriver grful_cd = { 442 NULL, "grful", DV_DULL, NULL, 0 443 }; 444 445 /* 446 * only used in console init 447 */ 448 static struct cfdata *cfdata; 449 450 /* 451 * we make sure to only init things once. this is somewhat 452 * tricky regarding the console. 453 */ 454 int 455 grfulmatch(pdp, cfp, auxp) 456 struct device *pdp; 457 struct cfdata *cfp; 458 void *auxp; 459 { 460 #ifdef ULOWELLCONSOLE 461 static int ulconunit = -1; 462 #endif 463 struct zbus_args *zap; 464 465 zap = auxp; 466 467 /* 468 * allow only one ulowell console 469 */ 470 if (amiga_realconfig == 0) 471 #ifdef ULOWELLCONSOLE 472 if (ulconunit != -1) 473 #endif 474 return(0); 475 476 if (zap->manid != 1030 || zap->prodid != 0) 477 return(0); 478 479 #ifdef ULOWELLCONSOLE 480 if (amiga_realconfig == 0 || ulconunit != cfp->cf_unit) { 481 #endif 482 if ((unsigned)ulowell_default_mon > ulowell_mon_max) 483 ulowell_default_mon = 1; 484 485 current_mon = ul_monitor_defs + ulowell_default_mon - 1; 486 if (ulowell_alive(current_mon) == 0) 487 return(0); 488 #ifdef ULOWELLCONSOLE 489 if (amiga_realconfig == 0) { 490 ulconunit = cfp->cf_unit; 491 cfdata = cfp; 492 } 493 } 494 #endif 495 return(1); 496 } 497 498 /* 499 * attach to the grfbus (zbus) 500 */ 501 void 502 grfulattach(pdp, dp, auxp) 503 struct device *pdp, *dp; 504 void *auxp; 505 { 506 static struct grf_ul_softc congrf; 507 struct zbus_args *zap; 508 struct grf_softc *gp; 509 struct grf_ul_softc *gup; 510 511 zap = auxp; 512 513 if (dp == NULL) 514 gup = &congrf; 515 else 516 gup = (struct grf_ul_softc *)dp; 517 518 gp = &gup->gus_sc; 519 520 if (dp != NULL && congrf.gus_sc.g_regkva != 0) { 521 /* 522 * inited earlier, just copy (not device struct) 523 */ 524 bcopy(&congrf.gus_sc.g_display, &gp->g_display, 525 (char *)&gup->gus_isr - (char *)&gp->g_display); 526 527 /* ...and transfer the isr */ 528 gup->gus_isr.isr_ipl = 2; 529 gup->gus_isr.isr_intr = ulisr; 530 gup->gus_isr.isr_arg = (void *)gp; 531 /* 532 * To make sure ints are always catched, first add new isr 533 * then remove old: 534 */ 535 add_isr(&gup->gus_isr); 536 remove_isr(&congrf.gus_isr); 537 } else { 538 gp->g_regkva = (caddr_t)zap->va; 539 gp->g_fbkva = NULL; 540 gp->g_unit = GRF_ULOWELL_UNIT; 541 gp->g_flags = GF_ALIVE; 542 gp->g_mode = ul_mode; 543 gp->g_conpri = grful_cnprobe(); 544 gp->g_data = NULL; 545 546 gup->gus_isr.isr_ipl = 2; 547 gup->gus_isr.isr_intr = ulisr; 548 gup->gus_isr.isr_arg = (void *)gp; 549 add_isr(&gup->gus_isr); 550 551 (void)ul_load_code(gp); 552 (void)ul_load_mon(gp, current_mon); 553 grful_iteinit(gp); 554 } 555 if (dp != NULL) 556 printf("\n"); 557 /* 558 * attach grf 559 */ 560 amiga_config_found(cfdata, &gp->g_device, gp, grfulprint); 561 } 562 563 int 564 grfulprint(auxp, pnp) 565 void *auxp; 566 const char *pnp; 567 { 568 if (pnp) 569 printf("grf%d at %s", ((struct grf_softc *)auxp)->g_unit, 570 pnp); 571 return(UNCONF); 572 } 573 574 static int 575 ul_getvmode (gp, vm) 576 struct grf_softc *gp; 577 struct grfvideo_mode *vm; 578 { 579 struct grfvideo_mode *md; 580 581 if (vm->mode_num && vm->mode_num > ulowell_mon_max) 582 return EINVAL; 583 584 if (! vm->mode_num) 585 vm->mode_num = current_mon - ul_monitor_defs + 1; 586 587 md = ul_monitor_defs + vm->mode_num - 1; 588 strncpy (vm->mode_descr, md->mode_descr, 589 sizeof (vm->mode_descr)); 590 591 /* XXX should tell TMS to measure it */ 592 vm->pixel_clock = md->pixel_clock; 593 vm->disp_width = md->disp_width; 594 vm->disp_height = md->disp_height; 595 vm->depth = md->depth; 596 597 vm->hblank_start = md->hblank_start; 598 vm->hsync_start = md->hsync_start; 599 vm->hsync_stop = md->hsync_stop; 600 vm->htotal = md->htotal; 601 602 vm->vblank_start = md->vblank_start; 603 vm->vsync_start = md->vsync_start; 604 vm->vsync_stop = md->vsync_stop; 605 vm->vtotal = md->vtotal; 606 607 vm->disp_flags = md->disp_flags; 608 return 0; 609 } 610 611 612 static int 613 ul_setvmode (gp, mode) 614 struct grf_softc *gp; 615 unsigned mode; 616 { 617 struct grf_ul_softc *gup; 618 struct gspregs *ba; 619 int error; 620 621 if (!mode || mode > ulowell_mon_max) 622 return EINVAL; 623 624 ba = (struct gspregs *)gp->g_regkva; 625 gup = (struct grf_ul_softc *)gp; 626 current_mon = ul_monitor_defs + mode - 1; 627 628 error = ul_load_mon (gp, current_mon) ? 0 : EINVAL; 629 630 return error; 631 } 632 633 /* 634 * Set the frame buffer or overlay planes on or off. 635 * Always succeeds. 636 */ 637 638 static __inline void 639 ul_setfb(gp, cmd) 640 struct grf_softc *gp; 641 u_long cmd; 642 { 643 struct grf_ul_softc *gup; 644 struct gspregs *ba; 645 646 gup = (struct grf_ul_softc *)gp; 647 648 ba = (struct gspregs *)gp->g_regkva; 649 ba->ctrl = LBL; 650 ba->hstadrh = 0xfe80; 651 ba->hstadrl = 0x0000; 652 ba->data = 6; 653 ba->hstadrl = 0x0020; 654 655 switch (cmd) { 656 case GM_GRFON: 657 gup->gus_ovslct |= 0x40; 658 break; 659 case GM_GRFOFF: 660 gup->gus_ovslct &= ~0x40; 661 break; 662 case GM_GRFOVON: 663 gup->gus_ovslct |= 3; 664 break; 665 case GM_GRFOVOFF: 666 gup->gus_ovslct &= ~3; 667 break; 668 } 669 ba->data = gup->gus_ovslct; 670 } 671 672 /* 673 * Change the mode of the display. 674 * Return a UNIX error number or 0 for success. 675 */ 676 int 677 ul_mode(gp, cmd, arg, a2, a3) 678 struct grf_softc *gp; 679 u_long cmd; 680 void *arg; 681 u_long a2; 682 int a3; 683 { 684 int i; 685 struct grfdyninfo *gd; 686 687 switch (cmd) { 688 case GM_GRFON: 689 case GM_GRFOFF: 690 case GM_GRFOVON: 691 case GM_GRFOVOFF: 692 ul_setfb (gp, cmd); 693 return 0; 694 695 case GM_GRFCONFIG: 696 gd = (struct grfdyninfo *)arg; 697 for (i=0; i<ulowell_mon_max; ++i) { 698 if (ul_monitor_defs[i].disp_width == gd->gdi_dwidth && 699 ul_monitor_defs[i].disp_height == gd->gdi_dheight) 700 return ul_setvmode(gp, i+1); 701 } 702 return EINVAL; 703 704 case GM_GRFGETVMODE: 705 return ul_getvmode (gp, (struct grfvideo_mode *) arg); 706 707 case GM_GRFSETVMODE: 708 return ul_setvmode (gp, *(unsigned *) arg); 709 710 case GM_GRFGETNUMVM: 711 *(int *)arg = ulowell_mon_max; 712 return 0; 713 714 case GM_GRFIOCTL: 715 return ul_ioctl (gp, a2, arg, (dev_t)a3); 716 717 default: 718 break; 719 } 720 721 return EINVAL; 722 } 723 724 int 725 ul_ioctl (gp, cmd, data, dev) 726 register struct grf_softc *gp; 727 u_long cmd; 728 void *data; 729 dev_t dev; 730 { 731 switch (cmd) { 732 #if 0 733 /* 734 * XXX we have no hardware sprites, but might implement them 735 * later in TMS code. 736 */ 737 738 case GRFIOCGSPRITEPOS: 739 return ul_getspritepos (gp, (struct grf_position *) data); 740 741 case GRFIOCSSPRITEPOS: 742 return ul_setspritepos (gp, (struct grf_position *) data); 743 744 case GRFIOCSSPRITEINF: 745 return ul_setspriteinfo (gp, (struct grf_spriteinfo *) data); 746 747 case GRFIOCGSPRITEINF: 748 return ul_getspriteinfo (gp, (struct grf_spriteinfo *) data); 749 750 case GRFIOCGSPRITEMAX: 751 return ul_getspritemax (gp, (struct grf_position *) data); 752 753 #endif 754 755 case GRFIOCGETCMAP: 756 return ul_getcmap (gp, (struct grf_colormap *) data, dev); 757 758 case GRFIOCPUTCMAP: 759 return ul_putcmap (gp, (struct grf_colormap *) data, dev); 760 761 case GRFIOCBITBLT: 762 return ul_bitblt (gp, (struct grf_bitblt *) data, dev); 763 764 case GRFIOCBLANK: 765 return ul_blank (gp, (int *) data, dev); 766 } 767 768 return EINVAL; 769 } 770 771 int 772 ul_getcmap (gp, cmap, dev) 773 struct grf_softc *gp; 774 struct grf_colormap *cmap; 775 dev_t dev; 776 { 777 struct grf_ul_softc *gup; 778 u_int8_t *mymap; 779 int mxidx, error; 780 781 gup = (struct grf_ul_softc *)gp; 782 783 if (minor(dev) & GRFIMDEV) { 784 mxidx = 256; 785 mymap = gup->gus_imcmap; 786 } else { 787 mxidx = 4; 788 mymap = gup->gus_ovcmap; 789 } 790 791 if (cmap->count == 0 || cmap->index >= mxidx) 792 return 0; 793 794 if (cmap->index + cmap->count > mxidx) 795 cmap->count = mxidx - cmap->index; 796 797 /* just copyout from the shadow color map */ 798 799 if ((error = copyout(mymap + cmap->index, cmap->red, cmap->count)) 800 801 || (error = copyout(mymap + mxidx + cmap->index, cmap->green, 802 cmap->count)) 803 804 || (error = copyout(mymap + mxidx * 2 + cmap->index, cmap->blue, 805 cmap->count))) 806 807 return(error); 808 809 return(0); 810 } 811 812 int 813 ul_putcmap (gp, cmap, dev) 814 struct grf_softc *gp; 815 struct grf_colormap *cmap; 816 dev_t dev; 817 { 818 struct grf_ul_softc *gup; 819 struct gspregs *ba; 820 u_int16_t cmd[8]; 821 int x, mxidx, error; 822 u_int8_t *mymap; 823 824 gup = (struct grf_ul_softc *)gp; 825 826 if (minor(dev) & GRFIMDEV) { 827 mxidx = 256; 828 mymap = gup->gus_imcmap; 829 } else { 830 mxidx = 4; 831 mymap = gup->gus_ovcmap; 832 } 833 834 if (cmap->count == 0 || cmap->index >= mxidx) 835 return 0; 836 837 if (cmap->index + cmap->count > mxidx) 838 cmap->count = mxidx - cmap->index; 839 840 /* first copyin to our shadow color map */ 841 842 if ((error = copyin(cmap->red, mymap + cmap->index, cmap->count)) 843 844 || (error = copyin(cmap->green, mymap + cmap->index + mxidx, 845 cmap->count)) 846 847 || (error = copyin(cmap->blue, mymap + cmap->index + mxidx*2, 848 cmap->count))) 849 850 return error; 851 852 853 /* then write from there to the hardware */ 854 ba = (struct gspregs *)gp->g_regkva; 855 /* 856 * XXX This is a bad thing to do. 857 * We should always use the gsp call, or have a means to arbitrate 858 * the usage of the BT458 index register. Else there might be a 859 * race condition (when writing both colormaps at nearly the same 860 * time), where one CPU changes the index register when the other 861 * one has not finished using it. 862 */ 863 if (mxidx > 4) { 864 /* image color map: we can write, with a hack, directly */ 865 ba->ctrl = LBL; 866 ba->hstadrh = 0xfe80; 867 ba->hstadrl = 0x0000; 868 ba->ctrl |= INCW; 869 ba->data = cmap->index; 870 ba->ctrl &= ~INCW; 871 872 for (x=cmap->index; x < cmap->index + cmap->count; ++x) { 873 ba->data = (u_int16_t) mymap[x]; 874 ba->data = (u_int16_t) mymap[x + mxidx]; 875 ba->data = (u_int16_t) mymap[x + mxidx * 2]; 876 } 877 } else { 878 879 /* overlay planes color map: have to call tms to do it */ 880 cmd[0] = GCMD_CMAP; 881 cmd[1] = 1; 882 for (x=cmap->index; x < cmap->index + cmap->count; ++x) { 883 cmd[2] = x; 884 cmd[3] = mymap[x]; 885 cmd[4] = mymap[x + mxidx]; 886 cmd[5] = mymap[x + mxidx * 2]; 887 gsp_write(ba, cmd, 6); 888 } 889 } 890 return 0; 891 } 892 893 int 894 ul_blank(gp, onoff, dev) 895 struct grf_softc *gp; 896 int *onoff; 897 dev_t dev; 898 { 899 struct gspregs *gsp; 900 901 gsp = (struct gspregs *)gp->g_regkva; 902 gsp->ctrl = (gsp->ctrl & ~(INCR | INCW)) | LBL; 903 gsp->hstadrh = 0xC000; 904 gsp->hstadrl = 0x0080; 905 if (*onoff > 0) 906 gsp->data |= 0x9000; 907 else 908 gsp->data &= ~0x9000; 909 910 return 0; 911 } 912 /* 913 * !!! THIS AREA UNDER CONSTRUCTION !!! 914 */ 915 int ul_BltOpMap[16] = { 916 3, 1, 2, 0, 11, 9, 10, 8, 917 7, 5, 6, 4, 15, 13, 14, 12 918 }; 919 920 int 921 ul_bitblt (gp, bb, dev) 922 struct grf_softc *gp; 923 struct grf_bitblt *bb; 924 dev_t dev; 925 { 926 /* XXX not yet implemented, but pretty trivial */ 927 return EINVAL; 928 } 929 930 void 931 gsp_write(gsp, ptr, size) 932 struct gspregs *gsp; 933 u_short *ptr; 934 size_t size; 935 { 936 u_short put, new_put, next, oc; 937 u_long put_hi, oa; 938 size_t n; 939 940 if (size == 0 || size > 8) 941 return; 942 943 n = size; 944 945 oc = gsp->ctrl; 946 oa = GSPGETHADRS(gsp); 947 948 gsp->ctrl = (oc & ~INCR) | LBL | INCW; 949 GSPSETHADRS(gsp, GSP_MODE_ADRS); 950 gsp->data &= ~GMODE_FLUSH; 951 952 GSPSETHADRS(gsp, PUT_HI_PTR_ADRS); 953 put_hi = gsp->data << 16; 954 955 GSPSETHADRS(gsp, PUT_PTR_ADRS); 956 put = gsp->data; 957 new_put = put + (8<<4); 958 959 GSPSETHADRS(gsp, GET_PTR_ADRS); 960 next = gsp->data; 961 962 while (next == new_put) { 963 /* 964 * we should use an intr. here. unfortunately, we already 965 * are called from an interupt and can't use tsleep. 966 * so we do busy waiting, at least for the moment. 967 */ 968 969 GSPSETHADRS(gsp,GET_PTR_ADRS); 970 next = gsp->data; 971 } 972 973 GSPSETHADRS(gsp,put|put_hi); 974 gsp->data = *ptr++ | 8<<4; 975 while ( --n > 0) { 976 gsp->data = *ptr++; 977 } 978 979 GSPSETHADRS(gsp,PUT_PTR_ADRS); 980 gsp->data = new_put; 981 GSPSETHADRS(gsp,oa); 982 gsp->ctrl = oc; 983 984 return; 985 } 986 987 #endif /* NGRF */ 988