1 /* $OpenBSD: creator.c,v 1.29 2003/06/24 19:41:33 miod Exp $ */ 2 3 /* 4 * Copyright (c) 2002 Jason L. Wright (jason@thought.net) 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/types.h> 30 #include <sys/param.h> 31 #include <sys/systm.h> 32 #include <sys/kernel.h> 33 #include <sys/device.h> 34 #include <sys/conf.h> 35 #include <sys/timeout.h> 36 37 #include <machine/bus.h> 38 #include <machine/autoconf.h> 39 #include <machine/openfirm.h> 40 41 #include <dev/wscons/wsconsio.h> 42 #include <dev/wscons/wsdisplayvar.h> 43 #include <dev/wscons/wscons_raster.h> 44 #include <dev/rasops/rasops.h> 45 #include <machine/fbvar.h> 46 47 #include <sparc64/dev/creatorreg.h> 48 #include <sparc64/dev/creatorvar.h> 49 50 struct wsscreen_descr creator_stdscreen = { 51 "std", 52 }; 53 54 const struct wsscreen_descr *creator_scrlist[] = { 55 &creator_stdscreen, 56 /* XXX other formats? */ 57 }; 58 59 struct wsscreen_list creator_screenlist = { 60 sizeof(creator_scrlist) / sizeof(struct wsscreen_descr *), 61 creator_scrlist 62 }; 63 64 int creator_ioctl(void *, u_long, caddr_t, int, struct proc *); 65 int creator_alloc_screen(void *, const struct wsscreen_descr *, void **, 66 int *, int *, long *); 67 void creator_free_screen(void *, void *); 68 int creator_show_screen(void *, void *, int, void (*cb)(void *, int, int), 69 void *); 70 paddr_t creator_mmap(void *, off_t, int); 71 void creator_ras_fifo_wait(struct creator_softc *, int); 72 void creator_ras_wait(struct creator_softc *); 73 void creator_ras_init(struct creator_softc *); 74 void creator_ras_copyrows(void *, int, int, int); 75 void creator_ras_erasecols(void *, int, int, int, long int); 76 void creator_ras_eraserows(void *, int, int, long int); 77 void creator_ras_updatecursor(struct rasops_info *); 78 void creator_ras_fill(struct creator_softc *); 79 void creator_ras_setfg(struct creator_softc *, int32_t); 80 int creator_setcursor(struct creator_softc *, struct wsdisplay_cursor *); 81 int creator_updatecursor(struct creator_softc *, u_int); 82 void creator_curs_enable(struct creator_softc *, u_int); 83 84 struct wsdisplay_accessops creator_accessops = { 85 creator_ioctl, 86 creator_mmap, 87 creator_alloc_screen, 88 creator_free_screen, 89 creator_show_screen, 90 NULL, /* load font */ 91 NULL, /* scrollback */ 92 NULL, /* getchar */ 93 NULL, /* burner */ 94 }; 95 96 struct cfdriver creator_cd = { 97 NULL, "creator", DV_DULL 98 }; 99 100 void 101 creator_attach(struct creator_softc *sc) 102 { 103 struct wsemuldisplaydev_attach_args waa; 104 char *model; 105 int btype; 106 107 printf(":"); 108 109 /* 110 * Prom reports only the length of the fcode header, we need 111 * the whole thing. 112 */ 113 sc->sc_sizes[0] = 0x00400000; 114 115 if (sc->sc_type == FFB_CREATOR) { 116 btype = getpropint(sc->sc_node, "board_type", 0); 117 if ((btype & 7) == 3) 118 printf(" Creator3D"); 119 else 120 printf(" Creator"); 121 } else 122 printf(" Elite3D"); 123 124 model = getpropstring(sc->sc_node, "model"); 125 if (model == NULL || strlen(model) == 0) 126 model = "unknown"; 127 128 DAC_WRITE(sc, FFB_DAC_TYPE, DAC_TYPE_GETREV); 129 sc->sc_dacrev = DAC_READ(sc, FFB_DAC_VALUE) >> 28; 130 131 printf(", model %s, dac %u\n", model, sc->sc_dacrev); 132 133 if (sc->sc_type == FFB_AFB) 134 sc->sc_dacrev = 10; 135 136 fb_setsize(&sc->sc_sunfb, 32, 1152, 900, sc->sc_node, 0); 137 /* linesize has a fixed value, compensate */ 138 sc->sc_sunfb.sf_linebytes = 8192; 139 sc->sc_sunfb.sf_fbsize = sc->sc_sunfb.sf_height * 8192; 140 141 sc->sc_sunfb.sf_ro.ri_bits = (void *)bus_space_vaddr(sc->sc_bt, 142 sc->sc_pixel_h); 143 sc->sc_sunfb.sf_ro.ri_hw = sc; 144 fbwscons_init(&sc->sc_sunfb, sc->sc_console ? 0 : RI_CLEAR); 145 146 if ((sc->sc_sunfb.sf_dev.dv_cfdata->cf_flags & CREATOR_CFFLAG_NOACCEL) 147 == 0) { 148 sc->sc_sunfb.sf_ro.ri_ops.eraserows = creator_ras_eraserows; 149 sc->sc_sunfb.sf_ro.ri_ops.erasecols = creator_ras_erasecols; 150 sc->sc_sunfb.sf_ro.ri_ops.copyrows = creator_ras_copyrows; 151 creator_ras_init(sc); 152 } 153 154 creator_stdscreen.capabilities = sc->sc_sunfb.sf_ro.ri_caps; 155 creator_stdscreen.nrows = sc->sc_sunfb.sf_ro.ri_rows; 156 creator_stdscreen.ncols = sc->sc_sunfb.sf_ro.ri_cols; 157 creator_stdscreen.textops = &sc->sc_sunfb.sf_ro.ri_ops; 158 159 if (sc->sc_console) { 160 sc->sc_sunfb.sf_ro.ri_updatecursor = creator_ras_updatecursor; 161 fbwscons_console_init(&sc->sc_sunfb, &creator_stdscreen, -1, 162 NULL); 163 } 164 165 waa.console = sc->sc_console; 166 waa.scrdata = &creator_screenlist; 167 waa.accessops = &creator_accessops; 168 waa.accesscookie = sc; 169 config_found(&sc->sc_sunfb.sf_dev, &waa, wsemuldisplaydevprint); 170 } 171 172 int 173 creator_ioctl(v, cmd, data, flags, p) 174 void *v; 175 u_long cmd; 176 caddr_t data; 177 int flags; 178 struct proc *p; 179 { 180 struct creator_softc *sc = v; 181 struct wsdisplay_cursor *curs; 182 struct wsdisplay_fbinfo *wdf; 183 struct wsdisplay_curpos *pos; 184 u_char r[2], g[2], b[2]; 185 int error; 186 187 switch (cmd) { 188 case WSDISPLAYIO_GTYPE: 189 *(u_int *)data = WSDISPLAY_TYPE_SUNFFB; 190 break; 191 case WSDISPLAYIO_SMODE: 192 sc->sc_mode = *(u_int *)data; 193 break; 194 case WSDISPLAYIO_GINFO: 195 wdf = (void *)data; 196 wdf->height = sc->sc_sunfb.sf_height; 197 wdf->width = sc->sc_sunfb.sf_width; 198 wdf->depth = 32; 199 wdf->cmsize = 0; 200 break; 201 case WSDISPLAYIO_LINEBYTES: 202 *(u_int *)data = sc->sc_sunfb.sf_linebytes; 203 break; 204 case WSDISPLAYIO_GCURSOR: 205 curs = (struct wsdisplay_cursor *)data; 206 if (curs->which & WSDISPLAY_CURSOR_DOCUR) 207 curs->enable = sc->sc_curs_enabled; 208 if (curs->which & WSDISPLAY_CURSOR_DOPOS) { 209 curs->pos.x = sc->sc_curs_pos.x; 210 curs->pos.y = sc->sc_curs_pos.y; 211 } 212 if (curs->which & WSDISPLAY_CURSOR_DOHOT) { 213 curs->hot.x = sc->sc_curs_hot.x; 214 curs->hot.y = sc->sc_curs_hot.y; 215 } 216 if (curs->which & WSDISPLAY_CURSOR_DOCMAP) { 217 curs->cmap.index = 0; 218 curs->cmap.count = 2; 219 r[0] = sc->sc_curs_fg >> 0; 220 g[0] = sc->sc_curs_fg >> 8; 221 b[0] = sc->sc_curs_fg >> 16; 222 r[1] = sc->sc_curs_bg >> 0; 223 g[1] = sc->sc_curs_bg >> 8; 224 b[1] = sc->sc_curs_bg >> 16; 225 error = copyout(r, curs->cmap.red, sizeof(r)); 226 if (error) 227 return (error); 228 error = copyout(g, curs->cmap.green, sizeof(g)); 229 if (error) 230 return (error); 231 error = copyout(b, curs->cmap.blue, sizeof(b)); 232 if (error) 233 return (error); 234 } 235 if (curs->which & WSDISPLAY_CURSOR_DOSHAPE) { 236 size_t l; 237 238 curs->size.x = sc->sc_curs_size.x; 239 curs->size.y = sc->sc_curs_size.y; 240 l = (sc->sc_curs_size.x * sc->sc_curs_size.y) / NBBY; 241 error = copyout(sc->sc_curs_image, curs->image, l); 242 if (error) 243 return (error); 244 error = copyout(sc->sc_curs_mask, curs->mask, l); 245 if (error) 246 return (error); 247 } 248 break; 249 case WSDISPLAYIO_SCURPOS: 250 pos = (struct wsdisplay_curpos *)data; 251 sc->sc_curs_pos.x = pos->x; 252 sc->sc_curs_pos.y = pos->y; 253 creator_updatecursor(sc, WSDISPLAY_CURSOR_DOPOS); 254 break; 255 case WSDISPLAYIO_GCURPOS: 256 pos = (struct wsdisplay_curpos *)data; 257 pos->x = sc->sc_curs_pos.x; 258 pos->y = sc->sc_curs_pos.y; 259 break; 260 case WSDISPLAYIO_SCURSOR: 261 curs = (struct wsdisplay_cursor *)data; 262 return (creator_setcursor(sc, curs)); 263 case WSDISPLAYIO_GCURMAX: 264 pos = (struct wsdisplay_curpos *)data; 265 pos->x = CREATOR_CURS_MAX; 266 pos->y = CREATOR_CURS_MAX; 267 break; 268 case WSDISPLAYIO_SVIDEO: 269 case WSDISPLAYIO_GVIDEO: 270 case WSDISPLAYIO_GETCMAP: 271 case WSDISPLAYIO_PUTCMAP: 272 default: 273 return -1; /* not supported yet */ 274 } 275 276 return (0); 277 } 278 279 int 280 creator_setcursor(struct creator_softc *sc, struct wsdisplay_cursor *curs) 281 { 282 u_int8_t r[2], g[2], b[2], image[128], mask[128]; 283 int error; 284 size_t imcount; 285 286 /* 287 * Do stuff that can generate errors first, then we'll blast it 288 * all at once. 289 */ 290 if (curs->which & WSDISPLAY_CURSOR_DOCMAP) { 291 if (curs->cmap.count < 2) 292 return (EINVAL); 293 error = copyin(curs->cmap.red, r, sizeof(r)); 294 if (error) 295 return (error); 296 error = copyin(curs->cmap.green, g, sizeof(g)); 297 if (error) 298 return (error); 299 error = copyin(curs->cmap.blue, b, sizeof(b)); 300 if (error) 301 return (error); 302 } 303 304 if (curs->which & WSDISPLAY_CURSOR_DOSHAPE) { 305 if (curs->size.x > CREATOR_CURS_MAX || 306 curs->size.y > CREATOR_CURS_MAX) 307 return (EINVAL); 308 imcount = (curs->size.x * curs->size.y) / NBBY; 309 error = copyin(curs->image, image, imcount); 310 if (error) 311 return (error); 312 error = copyin(curs->mask, mask, imcount); 313 if (error) 314 return (error); 315 } 316 317 /* 318 * Ok, everything is in kernel space and sane, update state. 319 */ 320 321 if (curs->which & WSDISPLAY_CURSOR_DOCUR) 322 sc->sc_curs_enabled = curs->enable; 323 if (curs->which & WSDISPLAY_CURSOR_DOPOS) { 324 sc->sc_curs_pos.x = curs->pos.x; 325 sc->sc_curs_pos.y = curs->pos.y; 326 } 327 if (curs->which & WSDISPLAY_CURSOR_DOHOT) { 328 sc->sc_curs_hot.x = curs->hot.x; 329 sc->sc_curs_hot.y = curs->hot.y; 330 } 331 if (curs->which & WSDISPLAY_CURSOR_DOCMAP) { 332 sc->sc_curs_fg = ((r[0] << 0) | (g[0] << 8) | (b[0] << 16)); 333 sc->sc_curs_bg = ((r[1] << 0) | (g[1] << 8) | (b[1] << 16)); 334 } 335 if (curs->which & WSDISPLAY_CURSOR_DOSHAPE) { 336 sc->sc_curs_size.x = curs->size.x; 337 sc->sc_curs_size.y = curs->size.y; 338 bcopy(image, sc->sc_curs_image, imcount); 339 bcopy(mask, sc->sc_curs_mask, imcount); 340 } 341 342 creator_updatecursor(sc, curs->which); 343 344 return (0); 345 } 346 347 void 348 creator_curs_enable(struct creator_softc *sc, u_int ena) 349 { 350 u_int32_t v; 351 352 DAC_WRITE(sc, FFB_DAC_TYPE2, DAC_TYPE2_CURSENAB); 353 if (sc->sc_dacrev <= 2) 354 v = ena ? 3 : 0; 355 else 356 v = ena ? 0 : 3; 357 DAC_WRITE(sc, FFB_DAC_VALUE2, v); 358 } 359 360 int 361 creator_updatecursor(struct creator_softc *sc, u_int which) 362 { 363 creator_curs_enable(sc, 0); 364 365 if (which & WSDISPLAY_CURSOR_DOCMAP) { 366 DAC_WRITE(sc, FFB_DAC_TYPE2, DAC_TYPE2_CURSCMAP); 367 DAC_WRITE(sc, FFB_DAC_VALUE2, sc->sc_curs_fg); 368 DAC_WRITE(sc, FFB_DAC_VALUE2, sc->sc_curs_bg); 369 } 370 371 if (which & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) { 372 u_int32_t x, y; 373 374 x = sc->sc_curs_pos.x + CREATOR_CURS_MAX - sc->sc_curs_hot.x; 375 y = sc->sc_curs_pos.y + CREATOR_CURS_MAX - sc->sc_curs_hot.y; 376 DAC_WRITE(sc, FFB_DAC_TYPE2, DAC_TYPE2_CURSPOS); 377 DAC_WRITE(sc, FFB_DAC_VALUE2, 378 ((x & 0xffff) << 16) | (y & 0xffff)); 379 } 380 381 if (which & WSDISPLAY_CURSOR_DOCUR) 382 creator_curs_enable(sc, sc->sc_curs_enabled); 383 384 return (0); 385 } 386 387 int 388 creator_alloc_screen(v, type, cookiep, curxp, curyp, attrp) 389 void *v; 390 const struct wsscreen_descr *type; 391 void **cookiep; 392 int *curxp, *curyp; 393 long *attrp; 394 { 395 struct creator_softc *sc = v; 396 397 if (sc->sc_nscreens > 0) 398 return (ENOMEM); 399 400 *cookiep = &sc->sc_sunfb.sf_ro; 401 *curyp = 0; 402 *curxp = 0; 403 sc->sc_sunfb.sf_ro.ri_ops.alloc_attr(&sc->sc_sunfb.sf_ro, 404 0, 0, 0, attrp); 405 sc->sc_nscreens++; 406 return (0); 407 } 408 409 void 410 creator_free_screen(v, cookie) 411 void *v; 412 void *cookie; 413 { 414 struct creator_softc *sc = v; 415 416 sc->sc_nscreens--; 417 } 418 419 int 420 creator_show_screen(v, cookie, waitok, cb, cbarg) 421 void *v; 422 void *cookie; 423 int waitok; 424 void (*cb)(void *, int, int); 425 void *cbarg; 426 { 427 return (0); 428 } 429 430 const struct creator_mappings { 431 bus_addr_t uoff; 432 bus_addr_t poff; 433 bus_size_t ulen; 434 } creator_map[] = { 435 { FFB_VOFF_SFB8R, FFB_POFF_SFB8R, FFB_VLEN_SFB8R }, 436 { FFB_VOFF_SFB8G, FFB_POFF_SFB8G, FFB_VLEN_SFB8G }, 437 { FFB_VOFF_SFB8B, FFB_POFF_SFB8B, FFB_VLEN_SFB8B }, 438 { FFB_VOFF_SFB8X, FFB_POFF_SFB8X, FFB_VLEN_SFB8X }, 439 { FFB_VOFF_SFB32, FFB_POFF_SFB32, FFB_VLEN_SFB32 }, 440 { FFB_VOFF_SFB64, FFB_POFF_SFB64, FFB_VLEN_SFB64 }, 441 { FFB_VOFF_FBC_REGS, FFB_POFF_FBC_REGS, FFB_VLEN_FBC_REGS }, 442 { FFB_VOFF_BM_FBC_REGS, FFB_POFF_BM_FBC_REGS, FFB_VLEN_BM_FBC_REGS }, 443 { FFB_VOFF_DFB8R, FFB_POFF_DFB8R, FFB_VLEN_DFB8R }, 444 { FFB_VOFF_DFB8G, FFB_POFF_DFB8G, FFB_VLEN_DFB8G }, 445 { FFB_VOFF_DFB8B, FFB_POFF_DFB8B, FFB_VLEN_DFB8B }, 446 { FFB_VOFF_DFB8X, FFB_POFF_DFB8X, FFB_VLEN_DFB8X }, 447 { FFB_VOFF_DFB24, FFB_POFF_DFB24, FFB_VLEN_DFB24 }, 448 { FFB_VOFF_DFB32, FFB_POFF_DFB32, FFB_VLEN_DFB32 }, 449 { FFB_VOFF_DFB422A, FFB_POFF_DFB422A, FFB_VLEN_DFB422A }, 450 { FFB_VOFF_DFB422AD, FFB_POFF_DFB422AD, FFB_VLEN_DFB422AD }, 451 { FFB_VOFF_DFB24B, FFB_POFF_DFB24B, FFB_VLEN_DFB24B }, 452 { FFB_VOFF_DFB422B, FFB_POFF_DFB422B, FFB_VLEN_DFB422B }, 453 { FFB_VOFF_DFB422BD, FFB_POFF_DFB422BD, FFB_VLEN_DFB422BD }, 454 { FFB_VOFF_SFB16Z, FFB_POFF_SFB16Z, FFB_VLEN_SFB16Z }, 455 { FFB_VOFF_SFB8Z, FFB_POFF_SFB8Z, FFB_VLEN_SFB8Z }, 456 { FFB_VOFF_SFB422, FFB_POFF_SFB422, FFB_VLEN_SFB422 }, 457 { FFB_VOFF_SFB422D, FFB_POFF_SFB422D, FFB_VLEN_SFB422D }, 458 { FFB_VOFF_FBC_KREGS, FFB_POFF_FBC_KREGS, FFB_VLEN_FBC_KREGS }, 459 { FFB_VOFF_DAC, FFB_POFF_DAC, FFB_VLEN_DAC }, 460 { FFB_VOFF_PROM, FFB_POFF_PROM, FFB_VLEN_PROM }, 461 { FFB_VOFF_EXP, FFB_POFF_EXP, FFB_VLEN_EXP }, 462 }; 463 #define CREATOR_NMAPPINGS (sizeof(creator_map)/sizeof(creator_map[0])) 464 465 paddr_t 466 creator_mmap(vsc, off, prot) 467 void *vsc; 468 off_t off; 469 int prot; 470 { 471 paddr_t x; 472 struct creator_softc *sc = vsc; 473 int i; 474 475 switch (sc->sc_mode) { 476 case WSDISPLAYIO_MODE_MAPPED: 477 /* Turn virtual offset into physical offset */ 478 for (i = 0; i < CREATOR_NMAPPINGS; i++) { 479 if (off >= creator_map[i].uoff && 480 off < (creator_map[i].uoff + creator_map[i].ulen)) 481 break; 482 } 483 if (i == CREATOR_NMAPPINGS) 484 break; 485 486 off -= creator_map[i].uoff; 487 off += creator_map[i].poff; 488 off += sc->sc_addrs[0]; 489 490 /* Map based on physical offset */ 491 for (i = 0; i < sc->sc_nreg; i++) { 492 /* Before this set? */ 493 if (off < sc->sc_addrs[i]) 494 continue; 495 /* After this set? */ 496 if (off >= (sc->sc_addrs[i] + sc->sc_sizes[i])) 497 continue; 498 499 x = bus_space_mmap(sc->sc_bt, 0, off, prot, 500 BUS_SPACE_MAP_LINEAR); 501 return (x); 502 } 503 break; 504 case WSDISPLAYIO_MODE_DUMBFB: 505 if (sc->sc_nreg < FFB_REG_DFB24) 506 break; 507 if (off >= 0 && off < sc->sc_sizes[FFB_REG_DFB24]) 508 return (bus_space_mmap(sc->sc_bt, 509 sc->sc_addrs[FFB_REG_DFB24], off, prot, 510 BUS_SPACE_MAP_LINEAR)); 511 break; 512 } 513 514 return (-1); 515 } 516 517 void 518 creator_ras_fifo_wait(sc, n) 519 struct creator_softc *sc; 520 int n; 521 { 522 int32_t cache = sc->sc_fifo_cache; 523 524 if (cache < n) { 525 do { 526 cache = FBC_READ(sc, FFB_FBC_UCSR); 527 cache = (cache & FBC_UCSR_FIFO_MASK) - 8; 528 } while (cache < n); 529 } 530 sc->sc_fifo_cache = cache - n; 531 } 532 533 void 534 creator_ras_wait(sc) 535 struct creator_softc *sc; 536 { 537 u_int32_t ucsr, r; 538 539 while (1) { 540 ucsr = FBC_READ(sc, FFB_FBC_UCSR); 541 if ((ucsr & (FBC_UCSR_FB_BUSY|FBC_UCSR_RP_BUSY)) == 0) 542 break; 543 r = ucsr & (FBC_UCSR_READ_ERR | FBC_UCSR_FIFO_OVFL); 544 if (r != 0) 545 FBC_WRITE(sc, FFB_FBC_UCSR, r); 546 } 547 } 548 549 void 550 creator_ras_init(sc) 551 struct creator_softc *sc; 552 { 553 creator_ras_fifo_wait(sc, 7); 554 FBC_WRITE(sc, FFB_FBC_PPC, 555 FBC_PPC_VCE_DIS | FBC_PPC_TBE_OPAQUE | 556 FBC_PPC_APE_DIS | FBC_PPC_CS_CONST); 557 FBC_WRITE(sc, FFB_FBC_FBC, 558 FFB_FBC_WB_A | FFB_FBC_RB_A | FFB_FBC_SB_BOTH | 559 FFB_FBC_XE_OFF | FFB_FBC_RGBE_MASK); 560 FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_NEW); 561 FBC_WRITE(sc, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE); 562 FBC_WRITE(sc, FFB_FBC_PMASK, 0xffffffff); 563 FBC_WRITE(sc, FFB_FBC_FONTINC, 0x10000); 564 sc->sc_fg_cache = 0; 565 FBC_WRITE(sc, FFB_FBC_FG, sc->sc_fg_cache); 566 creator_ras_wait(sc); 567 } 568 569 void 570 creator_ras_eraserows(cookie, row, n, attr) 571 void *cookie; 572 int row, n; 573 long int attr; 574 { 575 struct rasops_info *ri = cookie; 576 struct creator_softc *sc = ri->ri_hw; 577 578 if (row < 0) { 579 n += row; 580 row = 0; 581 } 582 if (row + n > ri->ri_rows) 583 n = ri->ri_rows - row; 584 if (n <= 0) 585 return; 586 587 creator_ras_fill(sc); 588 creator_ras_setfg(sc, ri->ri_devcmap[(attr >> 16) & 0xf]); 589 creator_ras_fifo_wait(sc, 4); 590 if ((n == ri->ri_rows) && (ri->ri_flg & RI_FULLCLEAR)) { 591 FBC_WRITE(sc, FFB_FBC_BY, 0); 592 FBC_WRITE(sc, FFB_FBC_BX, 0); 593 FBC_WRITE(sc, FFB_FBC_BH, ri->ri_height); 594 FBC_WRITE(sc, FFB_FBC_BW, ri->ri_width); 595 } else { 596 row *= ri->ri_font->fontheight; 597 FBC_WRITE(sc, FFB_FBC_BY, ri->ri_yorigin + row); 598 FBC_WRITE(sc, FFB_FBC_BX, ri->ri_xorigin); 599 FBC_WRITE(sc, FFB_FBC_BH, n * ri->ri_font->fontheight); 600 FBC_WRITE(sc, FFB_FBC_BW, ri->ri_emuwidth); 601 } 602 creator_ras_wait(sc); 603 } 604 605 void 606 creator_ras_erasecols(cookie, row, col, n, attr) 607 void *cookie; 608 int row, col, n; 609 long int attr; 610 { 611 struct rasops_info *ri = cookie; 612 struct creator_softc *sc = ri->ri_hw; 613 614 if ((row < 0) || (row >= ri->ri_rows)) 615 return; 616 if (col < 0) { 617 n += col; 618 col = 0; 619 } 620 if (col + n > ri->ri_cols) 621 n = ri->ri_cols - col; 622 if (n <= 0) 623 return; 624 n *= ri->ri_font->fontwidth; 625 col *= ri->ri_font->fontwidth; 626 row *= ri->ri_font->fontheight; 627 628 creator_ras_fill(sc); 629 creator_ras_setfg(sc, ri->ri_devcmap[(attr >> 16) & 0xf]); 630 creator_ras_fifo_wait(sc, 4); 631 FBC_WRITE(sc, FFB_FBC_BY, ri->ri_yorigin + row); 632 FBC_WRITE(sc, FFB_FBC_BX, ri->ri_xorigin + col); 633 FBC_WRITE(sc, FFB_FBC_BH, ri->ri_font->fontheight); 634 FBC_WRITE(sc, FFB_FBC_BW, n - 1); 635 creator_ras_wait(sc); 636 } 637 638 void 639 creator_ras_fill(sc) 640 struct creator_softc *sc; 641 { 642 creator_ras_fifo_wait(sc, 2); 643 FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_NEW); 644 FBC_WRITE(sc, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE); 645 creator_ras_wait(sc); 646 } 647 648 void 649 creator_ras_copyrows(cookie, src, dst, n) 650 void *cookie; 651 int src, dst, n; 652 { 653 struct rasops_info *ri = cookie; 654 struct creator_softc *sc = ri->ri_hw; 655 656 if (dst == src) 657 return; 658 if (src < 0) { 659 n += src; 660 src = 0; 661 } 662 if ((src + n) > ri->ri_rows) 663 n = ri->ri_rows - src; 664 if (dst < 0) { 665 n += dst; 666 dst = 0; 667 } 668 if ((dst + n) > ri->ri_rows) 669 n = ri->ri_rows - dst; 670 if (n <= 0) 671 return; 672 n *= ri->ri_font->fontheight; 673 src *= ri->ri_font->fontheight; 674 dst *= ri->ri_font->fontheight; 675 676 creator_ras_fifo_wait(sc, 8); 677 FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_OLD | (FBC_ROP_OLD << 8)); 678 FBC_WRITE(sc, FFB_FBC_DRAWOP, FBC_DRAWOP_VSCROLL); 679 FBC_WRITE(sc, FFB_FBC_BY, ri->ri_yorigin + src); 680 FBC_WRITE(sc, FFB_FBC_BX, ri->ri_xorigin); 681 FBC_WRITE(sc, FFB_FBC_DY, ri->ri_yorigin + dst); 682 FBC_WRITE(sc, FFB_FBC_DX, ri->ri_xorigin); 683 FBC_WRITE(sc, FFB_FBC_BH, n); 684 FBC_WRITE(sc, FFB_FBC_BW, ri->ri_emuwidth); 685 creator_ras_wait(sc); 686 } 687 688 void 689 creator_ras_setfg(sc, fg) 690 struct creator_softc *sc; 691 int32_t fg; 692 { 693 creator_ras_fifo_wait(sc, 1); 694 if (fg == sc->sc_fg_cache) 695 return; 696 sc->sc_fg_cache = fg; 697 FBC_WRITE(sc, FFB_FBC_FG, fg); 698 creator_ras_wait(sc); 699 } 700 701 void 702 creator_ras_updatecursor(ri) 703 struct rasops_info *ri; 704 { 705 struct creator_softc *sc = ri->ri_hw; 706 707 if (sc->sc_sunfb.sf_crowp != NULL) 708 *sc->sc_sunfb.sf_crowp = ri->ri_crow; 709 if (sc->sc_sunfb.sf_ccolp != NULL) 710 *sc->sc_sunfb.sf_ccolp = ri->ri_ccol; 711 } 712