1 /* $NetBSD: grf.c,v 1.62 2014/07/25 08:10:31 dholland Exp $ */ 2 3 /* 4 * Copyright (c) 1988 University of Utah. 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * the Systems Programming Group of the University of Utah Computer 10 * Science Department. 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 * from: Utah $Hdr: grf.c 1.31 91/01/21$ 37 * 38 * @(#)grf.c 7.8 (Berkeley) 5/7/91 39 */ 40 41 #include <sys/cdefs.h> 42 __KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.62 2014/07/25 08:10:31 dholland Exp $"); 43 44 /* 45 * Graphics display driver for the Amiga 46 * This is the hardware-independent portion of the driver. 47 * Hardware access is through the grf_softc->g_mode routine. 48 */ 49 50 #include "view.h" 51 #include "grf.h" 52 #include "kbd.h" 53 #include "wsdisplay.h" 54 55 #include <sys/param.h> 56 #include <sys/proc.h> 57 #include <sys/ioctl.h> 58 #include <sys/device.h> 59 #include <sys/file.h> 60 #include <sys/malloc.h> 61 #include <sys/systm.h> 62 #include <sys/vnode.h> 63 #include <sys/mman.h> 64 #include <sys/bus.h> 65 #include <sys/kauth.h> 66 67 #include <machine/cpu.h> 68 69 #include <dev/cons.h> 70 #include <dev/sun/fbio.h> 71 #include <dev/wscons/wsconsio.h> 72 #include <dev/wscons/wsdisplayvar.h> 73 #include <dev/rasops/rasops.h> 74 #include <dev/wscons/wsdisplay_vconsvar.h> 75 76 #include <amiga/amiga/color.h> /* DEBUG */ 77 #include <amiga/amiga/device.h> 78 #include <amiga/dev/grfioctl.h> 79 #include <amiga/dev/grfws.h> 80 #include <amiga/dev/grfvar.h> 81 #include <amiga/dev/itevar.h> 82 #include <amiga/dev/kbdvar.h> 83 #include <amiga/dev/viewioctl.h> 84 85 #include <sys/conf.h> 86 87 #if NGRF > 0 88 #include "ite.h" 89 #if NITE == 0 90 #define ite_on(u,f) 91 #define ite_off(u,f) 92 #define ite_reinit(d) 93 #endif 94 95 int grfon(dev_t); 96 int grfoff(dev_t); 97 int grfsinfo(dev_t, struct grfdyninfo *); 98 99 void grfattach(device_t, device_t, void *); 100 int grfmatch(device_t, cfdata_t, void *); 101 int grfprint(void *, const char *); 102 #ifdef DEBUG 103 void grfdebug(struct grf_softc *, const char *, ...); 104 #endif 105 /* 106 * pointers to grf drivers device structs 107 */ 108 struct grf_softc *grfsp[NGRF]; 109 110 CFATTACH_DECL_NEW(grf, 0, 111 grfmatch, grfattach, NULL, NULL); 112 113 dev_type_open(grfopen); 114 dev_type_close(grfclose); 115 dev_type_ioctl(grfioctl); 116 dev_type_mmap(grfmmap); 117 118 const struct cdevsw grf_cdevsw = { 119 .d_open = grfopen, 120 .d_close = grfclose, 121 .d_read = nullread, 122 .d_write = nullwrite, 123 .d_ioctl = grfioctl, 124 .d_stop = nostop, 125 .d_tty = notty, 126 .d_poll = nopoll, 127 .d_mmap = grfmmap, 128 .d_kqfilter = nokqfilter, 129 .d_discard = nodiscard, 130 .d_flag = 0 131 }; 132 133 /* 134 * only used in console init. 135 */ 136 static cfdata_t cfdata; 137 138 #if NWSDISPLAY > 0 139 static struct vcons_screen console_vcons; 140 141 static void grf_init_screen(void *, struct vcons_screen *, int, long *); 142 static struct rasops_info *grf_setup_rasops(struct grf_softc *, 143 struct vcons_screen *); 144 static paddr_t grf_wsmmap_md(off_t off); 145 146 cons_decl(grf); 147 #endif 148 149 /* 150 * match if the unit of grf matches its perspective 151 * low level board driver. 152 */ 153 int 154 grfmatch(device_t parent, cfdata_t cf, void *aux) 155 { 156 struct grf_softc *psc; 157 158 psc = device_private(parent); 159 if (cf->cf_unit != psc->g_unit) 160 return(0); 161 cfdata = cf; 162 return(1); 163 } 164 165 /* 166 * Attach.. plug pointer in and print some info. 167 * Then try and attach a wsdisplay or ite to us. 168 * Note: self is NULL durring console init. 169 */ 170 void 171 grfattach(device_t parent, device_t self, void *aux) 172 { 173 #if NWSDISPLAY > 0 174 struct wsemuldisplaydev_attach_args wa; 175 long defattr; 176 #endif 177 struct grf_softc *gp; 178 int maj; 179 180 gp = device_private(parent); 181 gp->g_device = self; 182 grfsp[gp->g_unit] = gp; 183 184 /* 185 * find our major device number 186 */ 187 maj = cdevsw_lookup_major(&grf_cdevsw); 188 189 gp->g_grfdev = makedev(maj, gp->g_unit); 190 if (self != NULL) { 191 printf(": width %d height %d", gp->g_display.gd_dwidth, 192 gp->g_display.gd_dheight); 193 if (gp->g_display.gd_colors == 2) 194 printf(" monochrome\n"); 195 else 196 printf(" colors %d\n", gp->g_display.gd_colors); 197 #if NWSDISPLAY > 0 198 vcons_init(&gp->g_vd, gp, gp->g_screens[0], gp->g_accessops); 199 gp->g_vd.init_screen = grf_init_screen; 200 if (gp->g_flags & GF_CONSOLE) { 201 console_vcons.scr_flags |= VCONS_SCREEN_IS_STATIC; 202 vcons_init_screen(&gp->g_vd, 203 &console_vcons, 1, &defattr); 204 gp->g_screens[0]->textops = 205 &console_vcons.scr_ri.ri_ops; 206 wsdisplay_cnattach(gp->g_screens[0], 207 &console_vcons.scr_ri, 0, 0, defattr); 208 vcons_replay_msgbuf(&console_vcons); 209 } 210 211 /* attach wsdisplay */ 212 wa.console = (gp->g_flags & GF_CONSOLE) != 0; 213 wa.scrdata = &gp->g_screenlist; 214 wa.accessops = gp->g_accessops; 215 wa.accesscookie = &gp->g_vd; 216 config_found(self, &wa, wsemuldisplaydevprint); 217 #endif /* NWSDISPLAY > 0 */ 218 } 219 220 #if NWSDISPLAY == 0 221 /* 222 * try and attach an ite 223 */ 224 amiga_config_found(cfdata, self, gp, grfprint); 225 #endif 226 } 227 228 int 229 grfprint(void *aux, const char *pnp) 230 { 231 if (pnp) 232 aprint_normal("ite at %s", pnp); 233 return(UNCONF); 234 } 235 236 /*ARGSUSED*/ 237 int 238 grfopen(dev_t dev, int flags, int devtype, struct lwp *l) 239 { 240 struct grf_softc *gp; 241 242 if (GRFUNIT(dev) >= NGRF || (gp = grfsp[GRFUNIT(dev)]) == NULL) 243 return(ENXIO); 244 245 if ((gp->g_flags & GF_ALIVE) == 0) 246 return(ENXIO); 247 248 if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE)) 249 return(EBUSY); 250 251 return(0); 252 } 253 254 /*ARGSUSED*/ 255 int 256 grfclose(dev_t dev, int flags, int mode, struct lwp *l) 257 { 258 struct grf_softc *gp; 259 260 gp = grfsp[GRFUNIT(dev)]; 261 (void)grfoff(dev); 262 gp->g_flags &= GF_ALIVE; 263 return(0); 264 } 265 266 /*ARGSUSED*/ 267 int 268 grfioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) 269 { 270 struct grf_softc *gp; 271 int error; 272 273 gp = grfsp[GRFUNIT(dev)]; 274 error = 0; 275 276 switch (cmd) { 277 case OGRFIOCGINFO: 278 /* argl.. no bank-member.. */ 279 memcpy(data, (void *)&gp->g_display, sizeof(struct grfinfo)-4); 280 break; 281 case GRFIOCGINFO: 282 memcpy(data, (void *)&gp->g_display, sizeof(struct grfinfo)); 283 break; 284 case GRFIOCON: 285 error = grfon(dev); 286 break; 287 case GRFIOCOFF: 288 error = grfoff(dev); 289 break; 290 case GRFIOCSINFO: 291 error = grfsinfo(dev, (struct grfdyninfo *) data); 292 break; 293 case GRFGETVMODE: 294 return(gp->g_mode(gp, GM_GRFGETVMODE, data, 0, 0)); 295 case GRFSETVMODE: 296 error = gp->g_mode(gp, GM_GRFSETVMODE, data, 0, 0); 297 if (error == 0 && gp->g_itedev && !(gp->g_flags & GF_GRFON)) 298 ite_reinit(gp->g_itedev); 299 break; 300 case GRFGETNUMVM: 301 return(gp->g_mode(gp, GM_GRFGETNUMVM, data, 0, 0)); 302 /* 303 * these are all hardware dependent, and have to be resolved 304 * in the respective driver. 305 */ 306 case GRFIOCPUTCMAP: 307 case GRFIOCGETCMAP: 308 case GRFIOCSSPRITEPOS: 309 case GRFIOCGSPRITEPOS: 310 case GRFIOCSSPRITEINF: 311 case GRFIOCGSPRITEINF: 312 case GRFIOCGSPRITEMAX: 313 case GRFIOCBITBLT: 314 case GRFIOCSETMON: 315 case GRFTOGGLE: /* Toggles between Cirrus boards and native ECS on 316 Amiga. 15/11/94 ill */ 317 /* 318 * We need the minor dev number to get the overlay/image 319 * information for grf_ul. 320 */ 321 return(gp->g_mode(gp, GM_GRFIOCTL, data, cmd, dev)); 322 323 case GRFIOCBLANK: /* blank ioctl, IOCON/OFF will turn ite on */ 324 case FBIOSVIDEO: 325 error = gp->g_mode(gp, GM_GRFIOCTL, data, GRFIOCBLANK, dev); 326 if (!error) 327 gp->g_blank = *(int *)data; 328 return (error); 329 330 case FBIOGVIDEO: 331 *(int *)data = gp->g_blank; 332 return (0); 333 334 default: 335 #if NVIEW > 0 336 /* 337 * check to see whether it's a command recognized by the 338 * view code if the unit is 0 339 * XXX 340 */ 341 if (GRFUNIT(dev) == 0) { 342 extern const struct cdevsw view_cdevsw; 343 344 return((*view_cdevsw.d_ioctl)(dev, cmd, data, flag, l)); 345 } 346 #endif 347 error = EPASSTHROUGH; 348 break; 349 350 } 351 return(error); 352 } 353 354 /* 355 * map the contents of a graphics display card into process' 356 * memory space. 357 */ 358 paddr_t 359 grfmmap(dev_t dev, off_t off, int prot) 360 { 361 struct grf_softc *gp; 362 struct grfinfo *gi; 363 364 gp = grfsp[GRFUNIT(dev)]; 365 gi = &gp->g_display; 366 367 /* 368 * control registers 369 */ 370 if (off >= 0 && off < gi->gd_regsize) 371 return(((paddr_t)gi->gd_regaddr + off) >> PGSHIFT); 372 373 /* 374 * frame buffer 375 */ 376 if (off >= gi->gd_regsize && off < gi->gd_regsize+gi->gd_fbsize) { 377 off -= gi->gd_regsize; 378 return(((paddr_t)gi->gd_fbaddr + off) >> PGSHIFT); 379 } 380 /* bogus */ 381 return(-1); 382 } 383 384 int 385 grfon(dev_t dev) 386 { 387 struct grf_softc *gp; 388 389 gp = grfsp[GRFUNIT(dev)]; 390 391 if (gp->g_flags & GF_GRFON) 392 return(0); 393 394 gp->g_flags |= GF_GRFON; 395 if (gp->g_itedev != NODEV) 396 ite_off(gp->g_itedev, 3); 397 398 return(gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVON : GM_GRFON, 399 NULL, 0, 0)); 400 } 401 402 int 403 grfoff(dev_t dev) 404 { 405 struct grf_softc *gp; 406 int error; 407 408 gp = grfsp[GRFUNIT(dev)]; 409 410 if ((gp->g_flags & GF_GRFON) == 0) 411 return(0); 412 413 gp->g_flags &= ~GF_GRFON; 414 error = gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF, 415 NULL, 0, 0); 416 417 /* 418 * Closely tied together no X's 419 */ 420 if (gp->g_itedev != NODEV) 421 ite_on(gp->g_itedev, 2); 422 423 return(error); 424 } 425 426 int 427 grfsinfo(dev_t dev, struct grfdyninfo *dyninfo) 428 { 429 struct grf_softc *gp; 430 int error; 431 432 gp = grfsp[GRFUNIT(dev)]; 433 error = gp->g_mode(gp, GM_GRFCONFIG, dyninfo, 0, 0); 434 435 /* 436 * Closely tied together no X's 437 */ 438 if (gp->g_itedev != NODEV) 439 ite_reinit(gp->g_itedev); 440 return(error); 441 } 442 443 #if NWSDISPLAY > 0 444 void 445 grfcnprobe(struct consdev *cd) 446 { 447 struct grf_softc *gp; 448 int unit; 449 450 /* 451 * Find the first working grf device for being console. 452 * Ignore unit 0 (grfcc), which should use amidisplaycc instead. 453 */ 454 for (unit = 1; unit < NGRF; unit++) { 455 gp = grfsp[unit]; 456 if (gp != NULL && (gp->g_flags & GF_ALIVE)) { 457 cd->cn_pri = CN_INTERNAL; 458 cd->cn_dev = NODEV; /* initialized later by wscons */ 459 return; 460 } 461 } 462 463 /* no grf console alive */ 464 cd->cn_pri = CN_DEAD; 465 } 466 467 void 468 grfcninit(struct consdev *cd) 469 { 470 struct grf_softc *gp; 471 struct rasops_info *ri; 472 long defattr; 473 int unit; 474 475 /* find console grf and set up wsdisplay for it */ 476 for (unit = 1; unit < NGRF; unit++) { 477 gp = grfsp[unit]; 478 if (gp != NULL && (gp->g_flags & GF_ALIVE)) { 479 gp->g_flags |= GF_CONSOLE; /* we are console! */ 480 gp->g_screens[0]->ncols = gp->g_display.gd_fbwidth / 481 gp->g_screens[0]->fontwidth; 482 gp->g_screens[0]->nrows = gp->g_display.gd_fbheight / 483 gp->g_screens[0]->fontheight; 484 485 ri = grf_setup_rasops(gp, &console_vcons); 486 console_vcons.scr_cookie = gp; 487 defattr = 0; /* XXX */ 488 489 wsdisplay_preattach(gp->g_screens[0], ri, 0, 0, 490 defattr); 491 #if NKBD > 0 492 /* tell kbd device it is used as console keyboard */ 493 kbd_cnattach(); 494 #endif 495 return; 496 } 497 } 498 panic("grfcninit: lost console"); 499 } 500 501 static void 502 grf_init_screen(void *cookie, struct vcons_screen *scr, int existing, 503 long *defattr) 504 { 505 struct grf_softc *gp; 506 struct rasops_info *ri __unused; 507 508 gp = cookie; 509 ri = grf_setup_rasops(gp, scr); 510 } 511 512 static struct rasops_info * 513 grf_setup_rasops(struct grf_softc *gp, struct vcons_screen *scr) 514 { 515 struct rasops_info *ri; 516 int i; 517 518 ri = &scr->scr_ri; 519 scr->scr_flags |= VCONS_DONT_READ; 520 memset(ri, 0, sizeof(struct rasops_info)); 521 522 ri->ri_rows = gp->g_screens[0]->nrows; 523 ri->ri_cols = gp->g_screens[0]->ncols; 524 ri->ri_hw = scr; 525 ri->ri_ops.cursor = gp->g_emulops->cursor; 526 ri->ri_ops.mapchar = gp->g_emulops->mapchar; 527 ri->ri_ops.copyrows = gp->g_emulops->copyrows; 528 ri->ri_ops.eraserows = gp->g_emulops->eraserows; 529 ri->ri_ops.copycols = gp->g_emulops->copycols; 530 ri->ri_ops.erasecols = gp->g_emulops->erasecols; 531 ri->ri_ops.putchar = gp->g_emulops->putchar; 532 ri->ri_ops.allocattr = gp->g_emulops->allocattr; 533 534 /* multiplication table for row-offsets */ 535 for (i = 0; i < ri->ri_rows; i++) 536 gp->g_rowoffset[i] = i * ri->ri_cols; 537 538 return ri; 539 } 540 541 paddr_t 542 grf_wsmmap(void *v, void *vs, off_t off, int prot) 543 { 544 struct vcons_data *vd; 545 struct grf_softc *gp; 546 struct grfinfo *gi; 547 548 vd = v; 549 gp = vd->cookie; 550 gi = &gp->g_display; 551 552 /* Normal fb mapping */ 553 if (off < gi->gd_fbsize) 554 return grf_wsmmap_md(((bus_addr_t)gp->g_fbkva) + off); 555 556 if (kauth_authorize_machdep(kauth_cred_get(), KAUTH_MACHDEP_UNMANAGEDMEM, 557 NULL, NULL, NULL, NULL) != 0) { 558 aprint_normal("%s: permission to mmap denied.\n", 559 device_xname(gp->g_device)); 560 return -1; 561 } 562 563 if ((off >= (bus_addr_t)gp->g_fbkva ) && 564 (off < ( (bus_addr_t)gp->g_fbkva + (size_t)gi->gd_fbsize))) 565 return grf_wsmmap_md(off); 566 567 /* Handle register mapping */ 568 if ((off >= (bus_addr_t)gi->gd_regaddr) && 569 (off < ((bus_addr_t)gi->gd_regaddr + (size_t)gi->gd_regsize))) 570 return grf_wsmmap_md(off); 571 572 return -1; 573 } 574 575 static paddr_t 576 grf_wsmmap_md(off_t off) 577 { 578 #if defined(__m68k__) 579 return (paddr_t) m68k_btop(off); 580 #else 581 return -1; /* FIXME */ 582 #endif 583 } 584 585 int 586 grf_wsioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l) 587 { 588 struct vcons_data *vd; 589 struct grf_softc *gp; 590 591 vd = v; 592 gp = vd->cookie; 593 594 switch (cmd) { 595 /* XXX: check if ptr to implementation is not null */ 596 case WSDISPLAYIO_GINFO: 597 return gp->g_wsioctl->ginfo(gp, data); 598 case WSDISPLAYIO_SMODE: 599 return gp->g_wsioctl->smode(gp, data); 600 case WSDISPLAYIO_GMODE: 601 return gp->g_wsioctl->gmode(gp, data); 602 case WSDISPLAYIO_GTYPE: 603 return gp->g_wsioctl->gtype(gp, data); 604 case WSDISPLAYIO_SVIDEO: 605 return gp->g_wsioctl->svideo(gp, data); 606 case WSDISPLAYIO_GVIDEO: 607 return gp->g_wsioctl->gvideo(gp, data); 608 case WSDISPLAYIO_GETCMAP: 609 return gp->g_wsioctl->getcmap(gp, data); 610 case WSDISPLAYIO_PUTCMAP: 611 return gp->g_wsioctl->putcmap(gp, data); 612 } 613 614 return EPASSTHROUGH; 615 } 616 617 /* wsdisplay_accessops ioctls */ 618 619 int 620 grf_wsaogetcmap(void *c, void *data) 621 { 622 u_int index, count; 623 struct grf_softc *gp; 624 struct wsdisplay_cmap *cm __unused; 625 626 cm = (struct wsdisplay_cmap*) data; 627 gp = c; 628 index = 0; 629 count = 0; 630 631 if (gp->g_wsmode == WSDISPLAYIO_MODE_EMUL) 632 return EINVAL; 633 634 if (index >= 255 || count > 256 || index + count > 256) 635 return EINVAL; 636 637 /* 638 * TODO: copyout values for r, g, b. This function should be 639 * driver-specific... 640 */ 641 642 return 0; 643 } 644 645 int 646 grf_wsaoputcmap(void *c, void *data) 647 { 648 /* 649 * We probably couldn't care less about color map in MODE_EMUL, 650 * I don't know about X11 yet. Also, these ioctls could be used by 651 * fullscreen console programs (think wsdisplay picture viewer, or 652 * the wsimgshow tool written by Yasushi Oshima). 653 */ 654 struct grf_softc *gp; 655 656 gp = c; 657 658 if (gp->g_wsmode == WSDISPLAYIO_MODE_EMUL) 659 return EINVAL; 660 /* ... */ 661 662 return 0; 663 } 664 665 int 666 grf_wsaosvideo(void *c, void *data) 667 { 668 #if 0 669 struct grf_softc *gp; 670 dev_t dev; 671 int rv; 672 673 gp = c; 674 dev = (dev_t) &gp->g_grfdev; 675 676 if (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF) { 677 if ((gp->g_flags & GF_GRFON) == 0) 678 rv = 0; 679 else { 680 gp->g_flags &= ~GF_GRFON; 681 rv = gp->g_mode(gp, (dev & GRFOVDEV) ? 682 GM_GRFOVOFF : GM_GRFOFF, NULL, 0, 0); 683 } 684 685 } else { 686 if ((gp->g_flags & GF_GRFON)) 687 rv = 0; 688 else 689 gp->g_flags |= GF_GRFON; 690 rv = gp->g_mode(gp, (dev & GRFOVDEV) ? 691 GM_GRFOVON : GM_GRFON, NULL, 0, 0); 692 } 693 694 return rv; 695 #endif 696 return 0; 697 } 698 699 int 700 grf_wsaogvideo(void *c, void *data) 701 { 702 struct grf_softc *gp; 703 704 gp = c; 705 706 if(gp->g_flags & GF_GRFON) 707 *(u_int *)data = WSDISPLAYIO_VIDEO_ON; 708 else 709 *(u_int *)data = WSDISPLAYIO_VIDEO_OFF; 710 711 return 0; 712 } 713 714 int 715 grf_wsaogtype(void *c, void *data) 716 { 717 struct grf_softc *gp __unused; 718 719 gp = c; 720 721 *(u_int *)data = WSDISPLAY_TYPE_GRF; 722 return 0; 723 } 724 725 int 726 grf_wsaogmode(void *c, void *data) 727 { 728 struct grf_softc *gp; 729 730 gp = c; 731 732 *(u_int *)data = gp->g_wsmode; 733 return 0; 734 } 735 736 int 737 grf_wsaosmode(void *c, void *data) 738 { 739 /* XXX: should provide hw-dependent impl of this in grf_xxx driver? */ 740 struct grf_softc *gp; 741 742 gp = c; 743 744 if ((*(int*) data) != gp->g_wsmode) { 745 gp->g_wsmode = (*(int*) data); 746 if ((*(int*) data) == WSDISPLAYIO_MODE_EMUL) { 747 //vcons_redraw_screen( active vcons screen ); 748 } 749 } 750 return 0; 751 } 752 753 int 754 grf_wsaoginfo(void *c, void *data) 755 { 756 struct wsdisplay_fbinfo *fbinfo; 757 struct grf_softc *gp; 758 struct grfinfo *gi; 759 760 gp = c; 761 762 fbinfo = (struct wsdisplay_fbinfo *)data; 763 gi = &gp->g_display; 764 765 /* 766 * TODO: better sanity checking, it is possible that 767 * wsdisplay is initialized, but no screen is opened 768 * (for example, device is not used). 769 */ 770 771 /* 772 * We shold return truth about current mode here because 773 * X11 wsfb driver denepds on this! 774 */ 775 fbinfo->height = gi->gd_fbheight; 776 fbinfo->width = gi->gd_fbwidth; 777 fbinfo->depth = gi->gd_planes; 778 fbinfo->cmsize = gi->gd_colors; 779 780 return 0; 781 } 782 783 #endif /* NWSDISPLAY > 0 */ 784 785 #ifdef DEBUG 786 void 787 grfdebug(struct grf_softc *gp, const char *fmt, ...) 788 { 789 static int ccol = 0, crow = 1; 790 volatile char *cp; 791 char buf[256]; 792 va_list ap; 793 int ncols; 794 char *bp; 795 796 va_start(ap, fmt); 797 vsnprintf(buf, 256, fmt, ap); 798 va_end(ap); 799 800 cp = gp->g_fbkva; 801 ncols = gp->g_display.gd_fbwidth / 8; 802 cp += (crow * ncols + ccol) << 2; 803 for (bp = buf; *bp != '\0'; bp++) { 804 if (*bp == '\n') { 805 ccol = 0; 806 crow++; 807 continue; 808 } 809 *cp++ = *bp; 810 *cp = 0x0a; 811 cp += 3; 812 ccol++; 813 } 814 } 815 #endif /* DEBUG */ 816 817 #endif /* NGRF > 0 */ 818