1 /* $NetBSD: summitfb.c,v 1.34 2025/04/28 04:46:58 macallan Exp $ */ 2 3 /* $OpenBSD: sti_pci.c,v 1.7 2009/02/06 22:51:04 miod Exp $ */ 4 5 /* 6 * Copyright (c) 2006, 2007 Miodrag Vallat. 7 ^ 2024 Michael Lorenz 8 * 9 * Permission to use, copy, modify, and distribute this software for any 10 * purpose with or without fee is hereby granted, provided that the above 11 * copyright notice, this permission notice, and the disclaimer below 12 * appear in all copies. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 15 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 */ 22 23 /* 24 * a native driver for HP Visualize FX graphics cards, so far tested only on 25 * my FX4 26 * STI portions are from Miodrag Vallat's sti_pci.c 27 */ 28 29 #include <sys/cdefs.h> 30 __KERNEL_RCSID(0, "$NetBSD: summitfb.c,v 1.34 2025/04/28 04:46:58 macallan Exp $"); 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/kmem.h> 35 #include <sys/device.h> 36 #include <sys/mutex.h> 37 38 #include <dev/pci/pcivar.h> 39 #include <dev/pci/pcireg.h> 40 #include <dev/pci/pcidevs.h> 41 #include <dev/pci/pciio.h> 42 43 #include <dev/wscons/wsdisplayvar.h> 44 #include <dev/wscons/wsconsio.h> 45 #include <dev/wsfont/wsfont.h> 46 #include <dev/rasops/rasops.h> 47 #include <dev/wscons/wsdisplay_vconsvar.h> 48 #include <dev/pci/wsdisplay_pci.h> 49 #include <dev/wscons/wsdisplay_glyphcachevar.h> 50 51 #include <dev/ic/stireg.h> 52 #include <dev/ic/summitreg.h> 53 #include <dev/ic/stivar.h> 54 55 #include "opt_summitfb.h" 56 57 #ifdef SUMMITFB_DEBUG 58 #define DPRINTF(s) printf s 59 #else 60 #define DPRINTF(s) __nothing 61 #endif 62 63 int summitfb_match(device_t, cfdata_t, void *); 64 void summitfb_attach(device_t, device_t, void *); 65 66 struct summitfb_softc { 67 device_t sc_dev; 68 pci_chipset_tag_t sc_pc; 69 pcitag_t sc_tag; 70 71 /* stuff we need in order to use the STI ROM */ 72 struct sti_softc sc_base; 73 struct sti_screen sc_scr; 74 bus_space_handle_t sc_romh; 75 76 int sc_width, sc_height; 77 int sc_locked; 78 struct vcons_screen sc_console_screen; 79 struct wsscreen_descr sc_defaultscreen_descr; 80 const struct wsscreen_descr *sc_screens[1]; 81 struct wsscreen_list sc_screenlist; 82 struct vcons_data vd; 83 int sc_mode; 84 u_char sc_cmap_red[256]; 85 u_char sc_cmap_green[256]; 86 u_char sc_cmap_blue[256]; 87 uint32_t sc_write_mode, sc_read_mode; 88 /* cursor stuff */ 89 int sc_cursor_x, sc_cursor_y; 90 int sc_hot_x, sc_hot_y, sc_enabled; 91 /* font-in-vram */ 92 struct wsdisplay_font *sc_font; 93 int sc_font_start; /* x of font area */ 94 int sc_cols; /* chars per line in font area */ 95 uint32_t sc_palette[16]; 96 int sc_video_on; 97 glyphcache sc_gc; 98 }; 99 100 CFATTACH_DECL_NEW(summitfb, sizeof(struct summitfb_softc), 101 summitfb_match, summitfb_attach, NULL, NULL); 102 103 int summitfb_readbar(struct sti_softc *, struct pci_attach_args *, u_int, 104 int); 105 int summitfb_check_rom(struct summitfb_softc *, struct pci_attach_args *); 106 void summitfb_enable_rom(struct sti_softc *); 107 void summitfb_disable_rom(struct sti_softc *); 108 void summitfb_enable_rom_internal(struct summitfb_softc *); 109 void summitfb_disable_rom_internal(struct summitfb_softc *); 110 111 void summitfb_setup(struct summitfb_softc *); 112 113 /* XXX these really need to go into their own header */ 114 int sti_pci_is_console(struct pci_attach_args *, bus_addr_t *); 115 int sti_rom_setup(struct sti_rom *, bus_space_tag_t, bus_space_tag_t, 116 bus_space_handle_t, bus_addr_t *, u_int); 117 int sti_screen_setup(struct sti_screen *, int); 118 void sti_describe_screen(struct sti_softc *, struct sti_screen *); 119 120 #define PCI_ROM_SIZE(mr) \ 121 (PCI_MAPREG_ROM_ADDR(mr) & -PCI_MAPREG_ROM_ADDR(mr)) 122 123 /* wsdisplay stuff */ 124 static int summitfb_ioctl(void *, void *, u_long, void *, int, 125 struct lwp *); 126 static paddr_t summitfb_mmap(void *, void *, off_t, int); 127 static void summitfb_init_screen(void *, struct vcons_screen *, int, 128 long *); 129 130 static int summitfb_putcmap(struct summitfb_softc *, 131 struct wsdisplay_cmap *); 132 static int summitfb_getcmap(struct summitfb_softc *, 133 struct wsdisplay_cmap *); 134 static void summitfb_restore_palette(struct summitfb_softc *); 135 static int summitfb_putpalreg(struct summitfb_softc *, uint8_t, uint8_t, 136 uint8_t, uint8_t); 137 138 static inline void summitfb_setup_fb(struct summitfb_softc *); 139 static void summitfb_clearfb(struct summitfb_softc *); 140 static void summitfb_rectfill(struct summitfb_softc *, int, int, int, int, 141 uint32_t); 142 static void summitfb_bitblt(void *, int, int, int, int, int, 143 int, int); 144 145 static void summitfb_cursor(void *, int, int, int); 146 static void summitfb_putchar(void *, int, int, u_int, long); 147 static void summitfb_putchar_aa(void *, int, int, u_int, long); 148 static void summitfb_copycols(void *, int, int, int, int); 149 static void summitfb_erasecols(void *, int, int, int, long); 150 static void summitfb_copyrows(void *, int, int, int); 151 static void summitfb_eraserows(void *, int, int, long); 152 153 static void summitfb_move_cursor(struct summitfb_softc *, int, int); 154 static int summitfb_do_cursor(struct summitfb_softc *, 155 struct wsdisplay_cursor *); 156 157 static void summitfb_set_video(struct summitfb_softc *, int); 158 159 static void summitfb_copyfont(struct summitfb_softc *); 160 161 struct wsdisplay_accessops summitfb_accessops = { 162 .ioctl = summitfb_ioctl, 163 .mmap = summitfb_mmap, 164 .alloc_screen = NULL, 165 .free_screen = NULL, 166 .show_screen = NULL, 167 .load_font = NULL, 168 .pollc = NULL, 169 .scroll = NULL, 170 }; 171 172 static inline void summitfb_wait_fifo(struct summitfb_softc *, uint32_t); 173 static inline void summitfb_wait(struct summitfb_softc *); 174 175 int sti_fetchfonts(struct sti_screen *, struct sti_inqconfout *, uint32_t, 176 u_int); 177 178 int 179 summitfb_match(device_t parent, cfdata_t cf, void *aux) 180 { 181 struct pci_attach_args *paa = aux; 182 183 if (PCI_VENDOR(paa->pa_id) != PCI_VENDOR_HP) 184 return 0; 185 186 if (PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_FX4) 187 return 10; /* beat out sti at pci */ 188 189 return 0; 190 } 191 192 static inline uint32_t 193 summitfb_read4(struct summitfb_softc *sc, uint32_t offset) 194 { 195 struct sti_rom *rom = sc->sc_base.sc_rom; 196 bus_space_tag_t memt = rom->memt; 197 bus_space_handle_t memh = rom->regh[2]; 198 199 return bus_space_read_stream_4(memt, memh, offset - 0x400000); 200 } 201 202 static inline void 203 summitfb_write4(struct summitfb_softc *sc, uint32_t offset, uint32_t val) 204 { 205 struct sti_rom *rom = sc->sc_base.sc_rom; 206 bus_space_tag_t memt = rom->memt; 207 bus_space_handle_t memh = rom->regh[2]; 208 209 bus_space_write_stream_4(memt, memh, offset - 0x400000, val); 210 } 211 212 static inline void 213 summitfb_write_mode(struct summitfb_softc *sc, uint32_t mode) 214 { 215 if (sc->sc_write_mode == mode) 216 return; 217 summitfb_wait(sc); 218 summitfb_write4(sc, VISFX_VRAM_WRITE_MODE, mode); 219 sc->sc_write_mode = mode; 220 } 221 222 static inline void 223 summitfb_read_mode(struct summitfb_softc *sc, uint32_t mode) 224 { 225 if (sc->sc_read_mode == mode) 226 return; 227 summitfb_wait(sc); 228 summitfb_write4(sc, VISFX_VRAM_READ_MODE, mode); 229 sc->sc_read_mode = mode; 230 } 231 232 void 233 summitfb_attach(device_t parent, device_t self, void *aux) 234 { 235 struct summitfb_softc *sc = device_private(self); 236 struct pci_attach_args *paa = aux; 237 struct sti_rom *rom; 238 struct rasops_info *ri; 239 struct wsemuldisplaydev_attach_args aa; 240 struct sti_dd *dd; 241 unsigned long defattr = 0; 242 int ret, is_console = 0; 243 244 sc->sc_dev = self; 245 246 sc->sc_pc = paa->pa_pc; 247 sc->sc_tag = paa->pa_tag; 248 sc->sc_base.sc_dev = self; 249 sc->sc_base.sc_enable_rom = summitfb_enable_rom; 250 sc->sc_base.sc_disable_rom = summitfb_disable_rom; 251 252 aprint_normal("\n"); 253 254 if (summitfb_check_rom(sc, paa) != 0) 255 return; 256 257 ret = sti_pci_is_console(paa, sc->sc_base. bases); 258 if (ret != 0) { 259 sc->sc_base.sc_flags |= STI_CONSOLE; 260 is_console = 1; 261 } 262 rom = kmem_zalloc(sizeof(*rom), KM_SLEEP); 263 rom->rom_softc = &sc->sc_base; 264 ret = sti_rom_setup(rom, paa->pa_iot, paa->pa_memt, sc->sc_romh, 265 sc->sc_base.bases, STI_CODEBASE_MAIN); 266 if (ret != 0) { 267 kmem_free(rom, sizeof(*rom)); 268 return; 269 } 270 271 sc->sc_base.sc_rom = rom; 272 dd = &rom->rom_dd; 273 274 sc->sc_scr.scr_rom = sc->sc_base.sc_rom; 275 ret = sti_screen_setup(&sc->sc_scr, STI_FBMODE); 276 277 sti_fetchfonts(&sc->sc_scr, NULL, dd->dd_fntaddr, 0); 278 wsfont_init(); 279 summitfb_copyfont(sc); 280 281 sc->sc_width = sc->sc_scr.scr_cfg.scr_width; 282 sc->sc_height = sc->sc_scr.scr_cfg.scr_height; 283 sc->sc_write_mode = 0xffffffff; 284 sc->sc_read_mode = 0xffffffff; 285 286 #ifdef SUMMITFB_DEBUG 287 sc->sc_height -= 200; 288 #endif 289 290 sc->sc_defaultscreen_descr = (struct wsscreen_descr){ 291 .name = "default", 292 .ncols = 0, .nrows = 0, 293 .textops = NULL, 294 .fontwidth = 8, .fontheight = 16, 295 .capabilities = WSSCREEN_WSCOLORS | WSSCREEN_HILIT | 296 WSSCREEN_UNDERLINE | WSSCREEN_RESIZE, 297 .modecookie = NULL, 298 }; 299 300 sc->sc_screens[0] = &sc->sc_defaultscreen_descr; 301 sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens}; 302 sc->sc_mode = WSDISPLAYIO_MODE_EMUL; 303 sc->sc_locked = 0; 304 305 vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr, 306 &summitfb_accessops); 307 sc->vd.init_screen = summitfb_init_screen; 308 sc->vd.show_screen_cookie = &sc->sc_gc; 309 sc->vd.show_screen_cb = glyphcache_adapt; 310 ri = &sc->sc_console_screen.scr_ri; 311 312 sc->sc_gc.gc_bitblt = summitfb_bitblt; 313 sc->sc_gc.gc_blitcookie = sc; 314 sc->sc_gc.gc_rop = RopSrc; 315 316 summitfb_setup(sc); 317 318 vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1, &defattr); 319 sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC; 320 321 sc->sc_defaultscreen_descr.textops = &ri->ri_ops; 322 sc->sc_defaultscreen_descr.capabilities = ri->ri_caps; 323 sc->sc_defaultscreen_descr.nrows = ri->ri_rows; 324 sc->sc_defaultscreen_descr.ncols = ri->ri_cols; 325 326 /* 327 * STI lies to us - it reports a 2048x2048 framebuffer but blitter 328 * ops wrap around below 1024 and we seem to have only about 250 329 * usable columns to the right. Should still be enough to cache 330 * a font or four. 331 * So, the framebuffer seems to be 1536x1024, which is odd since the 332 * FX4 is supposed to support resolutions higher than 1280x1024. 333 * I guess video memory is allocated in 512x512 chunks 334 */ 335 glyphcache_init(&sc->sc_gc, 336 sc->sc_height, 337 sc->sc_height, 338 (sc->sc_width + 511) & (~511), 339 ri->ri_font->fontwidth, 340 ri->ri_font->fontheight, 341 defattr); 342 343 summitfb_restore_palette(sc); 344 summitfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height, 345 ri->ri_devcmap[(defattr >> 16) & 0xff]); 346 summitfb_setup_fb(sc); 347 348 if (is_console) { 349 wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0, 350 defattr); 351 352 vcons_replay_msgbuf(&sc->sc_console_screen); 353 } 354 355 aprint_normal_dev(sc->sc_dev, "%s at %dx%d\n", sc->sc_scr.name, 356 sc->sc_width, sc->sc_height); 357 358 /* no suspend/resume support yet */ 359 pmf_device_register(sc->sc_dev, NULL, NULL); 360 361 aa.console = is_console; 362 aa.scrdata = &sc->sc_screenlist; 363 aa.accessops = &summitfb_accessops; 364 aa.accesscookie = &sc->vd; 365 366 config_found(sc->sc_dev, &aa, wsemuldisplaydevprint, CFARGS_NONE); 367 } 368 369 /* 370 * Grovel the STI ROM image. 371 */ 372 int 373 summitfb_check_rom(struct summitfb_softc *spc, struct pci_attach_args *pa) 374 { 375 struct sti_softc *sc = &spc->sc_base; 376 pcireg_t address, mask; 377 bus_space_handle_t romh; 378 bus_size_t romsize, subsize, stiromsize; 379 bus_addr_t selected, offs, suboffs; 380 uint32_t tmp; 381 int i; 382 int rc; 383 384 /* sort of inline sti_pci_enable_rom(sc) */ 385 address = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM); 386 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM, 387 ~PCI_MAPREG_ROM_ENABLE); 388 mask = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM); 389 address |= PCI_MAPREG_ROM_ENABLE; 390 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM, address); 391 sc->sc_flags |= STI_ROM_ENABLED; 392 393 /* 394 * Map the complete ROM for now. 395 */ 396 romsize = PCI_ROM_SIZE(mask); 397 DPRINTF(("%s: mapping rom @ %lx for %lx\n", __func__, 398 (long)PCI_MAPREG_ROM_ADDR(address), (long)romsize)); 399 400 rc = bus_space_map(pa->pa_memt, PCI_MAPREG_ROM_ADDR(address), romsize, 401 0, &romh); 402 if (rc != 0) { 403 aprint_error_dev(sc->sc_dev, "can't map PCI ROM (%d)\n", rc); 404 goto fail2; 405 } 406 407 summitfb_disable_rom_internal(spc); 408 409 /* 410 * Iterate over the ROM images, pick the best candidate. 411 */ 412 selected = (bus_addr_t)-1; 413 for (offs = 0; offs < romsize; offs += subsize) { 414 summitfb_enable_rom_internal(spc); 415 /* 416 * Check for a valid ROM header. 417 */ 418 tmp = bus_space_read_4(pa->pa_memt, romh, offs + 0); 419 tmp = le32toh(tmp); 420 if (tmp != 0x55aa0000) { 421 summitfb_disable_rom_internal(spc); 422 if (offs == 0) { 423 aprint_error_dev(sc->sc_dev, 424 "invalid PCI ROM header signature" 425 " (%08x)\n", tmp); 426 rc = EINVAL; 427 } 428 break; 429 } 430 431 /* 432 * Check ROM type. 433 */ 434 tmp = bus_space_read_4(pa->pa_memt, romh, offs + 4); 435 tmp = le32toh(tmp); 436 if (tmp != 0x00000001) { /* 1 == STI ROM */ 437 summitfb_disable_rom_internal(spc); 438 if (offs == 0) { 439 aprint_error_dev(sc->sc_dev, 440 "invalid PCI ROM type (%08x)\n", tmp); 441 rc = EINVAL; 442 } 443 break; 444 } 445 446 subsize = (bus_addr_t)bus_space_read_2(pa->pa_memt, romh, 447 offs + 0x0c); 448 subsize <<= 9; 449 450 #ifdef SUMMITFB_DEBUG 451 summitfb_disable_rom_internal(spc); 452 DPRINTF(("ROM offset %08x size %08x type %08x", 453 (u_int)offs, (u_int)subsize, tmp)); 454 summitfb_enable_rom_internal(spc); 455 #endif 456 457 /* 458 * Check for a valid ROM data structure. 459 * We do not need it except to know what architecture the ROM 460 * code is for. 461 */ 462 463 suboffs = offs + bus_space_read_2(pa->pa_memt, romh, 464 offs + 0x18); 465 tmp = bus_space_read_4(pa->pa_memt, romh, suboffs + 0); 466 tmp = le32toh(tmp); 467 if (tmp != 0x50434952) { /* PCIR */ 468 summitfb_disable_rom_internal(spc); 469 if (offs == 0) { 470 aprint_error_dev(sc->sc_dev, "invalid PCI data" 471 " signature (%08x)\n", tmp); 472 rc = EINVAL; 473 } else { 474 DPRINTF((" invalid PCI data signature %08x\n", 475 tmp)); 476 continue; 477 } 478 } 479 480 tmp = bus_space_read_1(pa->pa_memt, romh, suboffs + 0x14); 481 summitfb_disable_rom_internal(spc); 482 DPRINTF((" code %02x", tmp)); 483 484 switch (tmp) { 485 #ifdef __hppa__ 486 case 0x10: 487 if (selected == (bus_addr_t)-1) 488 selected = offs; 489 break; 490 #endif 491 #ifdef __i386__ 492 case 0x00: 493 if (selected == (bus_addr_t)-1) 494 selected = offs; 495 break; 496 #endif 497 default: 498 DPRINTF((" (wrong architecture)")); 499 break; 500 } 501 DPRINTF(("%s\n", selected == offs ? " -> SELECTED" : "")); 502 } 503 504 if (selected == (bus_addr_t)-1) { 505 if (rc == 0) { 506 aprint_error_dev(sc->sc_dev, "found no ROM with " 507 "correct microcode architecture\n"); 508 rc = ENOEXEC; 509 } 510 goto fail; 511 } 512 513 /* 514 * Read the STI region BAR assignments. 515 */ 516 517 summitfb_enable_rom_internal(spc); 518 offs = selected + bus_space_read_2(pa->pa_memt, romh, selected + 0x0e); 519 for (i = 0; i < STI_REGION_MAX; i++) { 520 rc = summitfb_readbar(sc, pa, i, 521 bus_space_read_1(pa->pa_memt, romh, offs + i)); 522 if (rc != 0) 523 goto fail; 524 } 525 526 /* 527 * Find out where the STI ROM itself lies, and its size. 528 */ 529 530 offs = selected + 531 bus_space_read_4(pa->pa_memt, romh, selected + 0x08); 532 stiromsize = bus_space_read_4(pa->pa_memt, romh, offs + 0x18); 533 stiromsize = le32toh(stiromsize); 534 summitfb_disable_rom_internal(spc); 535 536 /* 537 * Replace our mapping with a smaller mapping of only the area 538 * we are interested in. 539 */ 540 541 DPRINTF(("remapping rom @ %lx for %lx\n", 542 (long)(PCI_MAPREG_ROM_ADDR(address) + offs), (long)stiromsize)); 543 bus_space_unmap(pa->pa_memt, romh, romsize); 544 rc = bus_space_map(pa->pa_memt, PCI_MAPREG_ROM_ADDR(address) + offs, 545 stiromsize, 0, &spc->sc_romh); 546 if (rc != 0) { 547 aprint_error_dev(sc->sc_dev, "can't map STI ROM (%d)\n", 548 rc); 549 goto fail2; 550 } 551 summitfb_disable_rom_internal(spc); 552 sc->sc_flags &= ~STI_ROM_ENABLED; 553 554 return 0; 555 556 fail: 557 bus_space_unmap(pa->pa_memt, romh, romsize); 558 fail2: 559 summitfb_disable_rom_internal(spc); 560 561 return rc; 562 } 563 564 /* 565 * Decode a BAR register. 566 */ 567 int 568 summitfb_readbar(struct sti_softc *sc, struct pci_attach_args *pa, 569 u_int region, int bar) 570 { 571 bus_addr_t addr; 572 bus_size_t size; 573 uint32_t cf; 574 int rc; 575 576 if (bar == 0) { 577 sc->bases[region] = 0; 578 return 0; 579 } 580 581 #ifdef DIAGNOSTIC 582 if (bar < PCI_MAPREG_START || bar > PCI_MAPREG_PPB_END) { 583 summitfb_disable_rom(sc); 584 printf("%s: unexpected bar %02x for region %d\n", 585 device_xname(sc->sc_dev), bar, region); 586 summitfb_enable_rom(sc); 587 } 588 #endif 589 590 cf = pci_conf_read(pa->pa_pc, pa->pa_tag, bar); 591 592 rc = pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, PCI_MAPREG_TYPE(cf), 593 &addr, &size, NULL); 594 595 if (rc != 0) { 596 summitfb_disable_rom(sc); 597 aprint_error_dev(sc->sc_dev, "invalid bar %02x" 598 " for region %d\n", 599 bar, region); 600 summitfb_enable_rom(sc); 601 return rc; 602 } 603 604 sc->bases[region] = addr; 605 return 0; 606 } 607 608 /* 609 * Enable PCI ROM. 610 */ 611 void 612 summitfb_enable_rom_internal(struct summitfb_softc *spc) 613 { 614 pcireg_t address; 615 616 KASSERT(spc != NULL); 617 618 address = pci_conf_read(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM); 619 address |= PCI_MAPREG_ROM_ENABLE; 620 pci_conf_write(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM, address); 621 } 622 623 void 624 summitfb_enable_rom(struct sti_softc *sc) 625 { 626 struct summitfb_softc *spc = device_private(sc->sc_dev); 627 628 if (!ISSET(sc->sc_flags, STI_ROM_ENABLED)) { 629 summitfb_enable_rom_internal(spc); 630 } 631 SET(sc->sc_flags, STI_ROM_ENABLED); 632 } 633 634 /* 635 * Disable PCI ROM. 636 */ 637 void 638 summitfb_disable_rom_internal(struct summitfb_softc *spc) 639 { 640 pcireg_t address; 641 642 KASSERT(spc != NULL); 643 644 address = pci_conf_read(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM); 645 address &= ~PCI_MAPREG_ROM_ENABLE; 646 pci_conf_write(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM, address); 647 } 648 649 void 650 summitfb_disable_rom(struct sti_softc *sc) 651 { 652 struct summitfb_softc *spc = device_private(sc->sc_dev); 653 654 if (ISSET(sc->sc_flags, STI_ROM_ENABLED)) { 655 summitfb_disable_rom_internal(spc); 656 } 657 CLR(sc->sc_flags, STI_ROM_ENABLED); 658 } 659 660 static inline void 661 summitfb_wait(struct summitfb_softc *sc) 662 { 663 664 while (summitfb_read4(sc, VISFX_STATUS) != 0) 665 continue; 666 } 667 668 static inline void 669 summitfb_setup_fb(struct summitfb_softc *sc) 670 { 671 672 summitfb_wait(sc); 673 if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) { 674 summitfb_write_mode(sc, VISFX_WRITE_MODE_PLAIN); 675 summitfb_read_mode(sc, VISFX_WRITE_MODE_PLAIN); 676 summitfb_write4(sc, VISFX_APERTURE_ACCESS, VISFX_DEPTH_8); 677 /* make overlay opaque */ 678 summitfb_write4(sc, VISFX_OTR, OTR_T | OTR_L1 | OTR_L0); 679 } else { 680 summitfb_write_mode(sc, OTC01 | BIN8F | BUFFL); 681 summitfb_read_mode(sc, OTC01 | BIN8F | BUFFL); 682 summitfb_write4(sc, VISFX_APERTURE_ACCESS, VISFX_DEPTH_32); 683 /* make overlay transparent */ 684 summitfb_write4(sc, VISFX_OTR, OTR_A); 685 } 686 summitfb_write4(sc, VISFX_IBO, RopSrc); 687 } 688 689 void 690 summitfb_setup(struct summitfb_softc *sc) 691 { 692 int i; 693 694 sc->sc_hot_x = 0; 695 sc->sc_hot_y = 0; 696 sc->sc_enabled = 0; 697 sc->sc_video_on = 1; 698 699 summitfb_wait(sc); 700 #if 1 701 /* these control byte swapping */ 702 summitfb_write4(sc, 0xb08044, 0x1b); /* MFU_BSCTD */ 703 summitfb_write4(sc, 0xb08048, 0x1b); /* MFU_BSCCTL */ 704 705 summitfb_write4(sc, 0x920860, 0xe4); /* FBC_RBS */ 706 summitfb_write4(sc, 0x921114, 0); /* CPE, clip plane enable */ 707 summitfb_write4(sc, 0x9211d8, 0); /* FCDA */ 708 709 summitfb_write4(sc, 0xa00818, 0); /* WORG window origin */ 710 summitfb_write4(sc, 0xa0081c, 0); /* FBS front buffer select*/ 711 summitfb_write4(sc, 0xa00850, 0); /* MISC_CTL */ 712 summitfb_write4(sc, 0xa0086c, 0); /* WCE window clipping enable */ 713 #endif 714 /* initialize drawiing engine */ 715 summitfb_wait(sc); 716 summitfb_write4(sc, VISFX_CONTROL, 0); // clear WFC 717 summitfb_write4(sc, VISFX_APERTURE_ACCESS, VISFX_DEPTH_8); 718 summitfb_write4(sc, VISFX_PIXEL_MASK, 0xffffffff); 719 summitfb_write4(sc, VISFX_PLANE_MASK, 0xffffffff); 720 summitfb_write4(sc, VISFX_FOE, FOE_BLEND_ROP); 721 summitfb_write4(sc, VISFX_IBO, RopSrc); 722 summitfb_write_mode(sc, VISFX_WRITE_MODE_PLAIN); 723 summitfb_read_mode(sc, OTC04 | BIN8I | BUFovl); 724 summitfb_write4(sc, VISFX_CLIP_TL, 0); 725 summitfb_write4(sc, VISFX_CLIP_WH, 726 ((sc->sc_scr.fbwidth) << 16) | (sc->sc_scr.fbheight)); 727 /* turn off the cursor sprite */ 728 summitfb_write4(sc, VISFX_CURSOR_POS, 0); 729 /* disable throttling by moving the throttle window way off screen */ 730 summitfb_write4(sc, VISFX_TCR, 0x10001000); 731 732 /* make sure the overlay is opaque */ 733 summitfb_write4(sc, VISFX_OTR, OTR_T | OTR_L1 | OTR_L0); 734 735 /* 736 * initialize XLUT, I mean attribute table 737 * set all to 24bit, CFS1 738 */ 739 for (i = 0; i < 16; i++) 740 summitfb_write4(sc, VISFX_IAA(i), IAA_8F | IAA_CFS1); 741 /* RGB8, no LUT */ 742 summitfb_write4(sc, VISFX_CFS(1), CFS_8F | CFS_BYPASS); 743 /* overlay is 8bit, uses LUT 0 */ 744 summitfb_write4(sc, VISFX_CFS(16), CFS_8I | CFS_LUT0); 745 summitfb_write4(sc, VISFX_CFS(17), CFS_8I | CFS_LUT0); 746 747 /* zero the attribute plane */ 748 summitfb_write_mode(sc, OTC04 | BINapln); 749 summitfb_wait_fifo(sc, 12); 750 summitfb_write4(sc, VISFX_PLANE_MASK, 0xff); 751 summitfb_write4(sc, VISFX_IBO, 0); /* GXclear */ 752 summitfb_write4(sc, VISFX_FG_COLOUR, 0); 753 summitfb_write4(sc, VISFX_START, 0); 754 summitfb_write4(sc, VISFX_SIZE, (sc->sc_width << 16) | sc->sc_height); 755 summitfb_wait(sc); 756 summitfb_write4(sc, VISFX_PLANE_MASK, 0xffffffff); 757 758 /* turn off force attr so the above takes effect */ 759 summitfb_write4(sc, VISFX_FATTR, 0); 760 761 summitfb_setup_fb(sc); 762 } 763 764 static int 765 summitfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, 766 struct lwp *l) 767 { 768 struct vcons_data *vd = v; 769 struct summitfb_softc *sc = vd->cookie; 770 struct wsdisplay_fbinfo *wdf; 771 struct vcons_screen *ms = vd->active; 772 773 switch (cmd) { 774 case WSDISPLAYIO_GTYPE: 775 *(u_int *)data = WSDISPLAY_TYPE_STI; 776 return 0; 777 778 case GCID: 779 *(u_int *)data = sc->sc_scr.scr_rom->rom_dd.dd_grid[0]; 780 return 0; 781 782 /* PCI config read/write passthrough. */ 783 case PCI_IOC_CFGREAD: 784 case PCI_IOC_CFGWRITE: 785 return pci_devioctl(sc->sc_pc, sc->sc_tag, 786 cmd, data, flag, l); 787 788 case WSDISPLAYIO_GET_BUSID: 789 return wsdisplayio_busid_pci(sc->sc_dev, sc->sc_pc, 790 sc->sc_tag, data); 791 792 case WSDISPLAYIO_GINFO: 793 if (ms == NULL) 794 return ENODEV; 795 wdf = data; 796 wdf->height = ms->scr_ri.ri_height; 797 wdf->width = ms->scr_ri.ri_width; 798 wdf->depth = ms->scr_ri.ri_depth; 799 wdf->cmsize = 256; 800 return 0; 801 802 case WSDISPLAYIO_GETCMAP: 803 return summitfb_getcmap(sc, 804 (struct wsdisplay_cmap *)data); 805 806 case WSDISPLAYIO_PUTCMAP: 807 return summitfb_putcmap(sc, 808 (struct wsdisplay_cmap *)data); 809 810 case WSDISPLAYIO_LINEBYTES: 811 *(u_int *)data = 2048; 812 return 0; 813 814 case WSDISPLAYIO_SMODE: { 815 int new_mode = *(int *)data; 816 817 if (new_mode != sc->sc_mode) { 818 sc->sc_mode = new_mode; 819 if(new_mode == WSDISPLAYIO_MODE_EMUL) { 820 summitfb_setup(sc); 821 summitfb_restore_palette(sc); 822 glyphcache_wipe(&sc->sc_gc); 823 summitfb_rectfill(sc, 0, 0, sc->sc_width, 824 sc->sc_height, ms->scr_ri.ri_devcmap[ 825 (ms->scr_defattr >> 16) & 0xff]); 826 vcons_redraw_screen(ms); 827 summitfb_set_video(sc, 1); 828 } else 829 summitfb_clearfb(sc); 830 summitfb_setup_fb(sc); 831 } 832 return 0; 833 } 834 835 case WSDISPLAYIO_GET_FBINFO: { 836 struct wsdisplayio_fbinfo *fbi = data; 837 int ret; 838 839 ret = wsdisplayio_get_fbinfo(&ms->scr_ri, fbi); 840 //fbi->fbi_fbsize = sc->sc_height * 2048; 841 fbi->fbi_stride = 8192; 842 fbi->fbi_bitsperpixel = 32; 843 fbi->fbi_pixeltype = WSFB_RGB; 844 fbi->fbi_subtype.fbi_rgbmasks.red_offset = 16; 845 fbi->fbi_subtype.fbi_rgbmasks.red_size = 8; 846 fbi->fbi_subtype.fbi_rgbmasks.green_offset = 8; 847 fbi->fbi_subtype.fbi_rgbmasks.green_size = 8; 848 fbi->fbi_subtype.fbi_rgbmasks.blue_offset = 0; 849 fbi->fbi_subtype.fbi_rgbmasks.blue_size = 8; 850 fbi->fbi_subtype.fbi_rgbmasks.alpha_size = 0; 851 fbi->fbi_fbsize = sc->sc_scr.fbheight * 8192; 852 return ret; 853 } 854 855 case WSDISPLAYIO_GCURPOS: { 856 struct wsdisplay_curpos *cp = data; 857 858 cp->x = sc->sc_cursor_x; 859 cp->y = sc->sc_cursor_y; 860 return 0; 861 } 862 863 case WSDISPLAYIO_SCURPOS: { 864 struct wsdisplay_curpos *cp = data; 865 866 summitfb_move_cursor(sc, cp->x, cp->y); 867 return 0; 868 } 869 870 case WSDISPLAYIO_GCURMAX: { 871 struct wsdisplay_curpos *cp = data; 872 873 cp->x = 64; 874 cp->y = 64; 875 return 0; 876 } 877 878 case WSDISPLAYIO_SCURSOR: { 879 struct wsdisplay_cursor *cursor = data; 880 881 return summitfb_do_cursor(sc, cursor); 882 } 883 884 case WSDISPLAYIO_SVIDEO: 885 summitfb_set_video(sc, *(int *)data); 886 return 0; 887 case WSDISPLAYIO_GVIDEO: 888 *(u_int *)data = sc->sc_video_on ? 889 WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF; 890 return 0; 891 } 892 return EPASSTHROUGH; 893 } 894 895 static paddr_t 896 summitfb_mmap(void *v, void *vs, off_t offset, int prot) 897 { 898 struct vcons_data *vd = v; 899 struct summitfb_softc *sc = vd->cookie; 900 struct sti_rom *rom = sc->sc_base.sc_rom; 901 paddr_t pa = -1; 902 903 if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) 904 return -1; 905 906 if (offset >= 0 && offset < 0x01000000) { 907 /* framebuffer */ 908 pa = bus_space_mmap(rom->memt, sc->sc_scr.fbaddr, offset, 909 prot, BUS_SPACE_MAP_LINEAR); 910 } else if (offset >= 0x80000000 && offset < 0x81000000) { 911 /* blitter registers etc. */ 912 pa = bus_space_mmap(rom->memt, rom->regh[0], 913 offset - 0x80000000, prot, BUS_SPACE_MAP_LINEAR); 914 } 915 916 return pa; 917 } 918 919 static void 920 summitfb_init_screen(void *cookie, struct vcons_screen *scr, 921 int existing, long *defattr) 922 { 923 struct summitfb_softc *sc = cookie; 924 struct rasops_info *ri = &scr->scr_ri; 925 926 ri->ri_depth = 8; 927 ri->ri_width = sc->sc_width; 928 ri->ri_height = sc->sc_height; 929 ri->ri_stride = 2048; 930 ri->ri_flg = RI_CENTER | RI_8BIT_IS_RGB 931 | RI_ENABLE_ALPHA | RI_PREFER_ALPHA 932 ; 933 934 ri->ri_bits = (void *)sc->sc_scr.fbaddr; 935 rasops_init(ri, 0, 0); 936 ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_UNDERLINE | 937 WSSCREEN_RESIZE; 938 scr->scr_flags |= VCONS_LOADFONT; 939 940 rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight, 941 sc->sc_width / ri->ri_font->fontwidth); 942 943 ri->ri_hw = scr; 944 945 ri->ri_ops.copyrows = summitfb_copyrows; 946 ri->ri_ops.copycols = summitfb_copycols; 947 ri->ri_ops.eraserows = summitfb_eraserows; 948 ri->ri_ops.erasecols = summitfb_erasecols; 949 ri->ri_ops.cursor = summitfb_cursor; 950 sc->sc_font = NULL; 951 if (FONT_IS_ALPHA(ri->ri_font)) { 952 ri->ri_ops.putchar = summitfb_putchar_aa; 953 } else 954 ri->ri_ops.putchar = summitfb_putchar; 955 } 956 957 static int 958 summitfb_putcmap(struct summitfb_softc *sc, struct wsdisplay_cmap *cm) 959 { 960 u_char *r, *g, *b; 961 u_int index = cm->index; 962 u_int count = cm->count; 963 int i, error; 964 u_char rbuf[256], gbuf[256], bbuf[256]; 965 966 if (cm->index >= 256 || cm->count > 256 || 967 (cm->index + cm->count) > 256) 968 return EINVAL; 969 error = copyin(cm->red, &rbuf[index], count); 970 if (error) 971 return error; 972 error = copyin(cm->green, &gbuf[index], count); 973 if (error) 974 return error; 975 error = copyin(cm->blue, &bbuf[index], count); 976 if (error) 977 return error; 978 979 memcpy(&sc->sc_cmap_red[index], &rbuf[index], count); 980 memcpy(&sc->sc_cmap_green[index], &gbuf[index], count); 981 memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count); 982 983 r = &sc->sc_cmap_red[index]; 984 g = &sc->sc_cmap_green[index]; 985 b = &sc->sc_cmap_blue[index]; 986 987 for (i = 0; i < count; i++) { 988 summitfb_putpalreg(sc, index, *r, *g, *b); 989 index++; 990 r++, g++, b++; 991 } 992 return 0; 993 } 994 995 static int 996 summitfb_getcmap(struct summitfb_softc *sc, struct wsdisplay_cmap *cm) 997 { 998 u_int index = cm->index; 999 u_int count = cm->count; 1000 int error; 1001 1002 if (index >= 255 || count > 256 || index + count > 256) 1003 return EINVAL; 1004 1005 error = copyout(&sc->sc_cmap_red[index], cm->red, count); 1006 if (error) 1007 return error; 1008 error = copyout(&sc->sc_cmap_green[index], cm->green, count); 1009 if (error) 1010 return error; 1011 error = copyout(&sc->sc_cmap_blue[index], cm->blue, count); 1012 if (error) 1013 return error; 1014 1015 return 0; 1016 } 1017 1018 static void 1019 summitfb_restore_palette(struct summitfb_softc *sc) 1020 { 1021 uint8_t cmap[768]; 1022 int i, j; 1023 1024 j = 0; 1025 rasops_get_cmap(&sc->sc_console_screen.scr_ri, cmap, sizeof(cmap)); 1026 for (i = 0; i < 256; i++) { 1027 sc->sc_cmap_red[i] = cmap[j]; 1028 sc->sc_cmap_green[i] = cmap[j + 1]; 1029 sc->sc_cmap_blue[i] = cmap[j + 2]; 1030 summitfb_putpalreg(sc, i, cmap[j], cmap[j + 1], cmap[j + 2]); 1031 j += 3; 1032 } 1033 for (i = 0; i < 16; i++) { 1034 sc->sc_palette[i] = (rasops_cmap[i * 3] << 16) | 1035 (rasops_cmap[i * 3 + 1] << 8) | 1036 rasops_cmap[i * 3 + 2]; 1037 } 1038 1039 } 1040 1041 static int 1042 summitfb_putpalreg(struct summitfb_softc *sc, uint8_t idx, 1043 uint8_t r, uint8_t g, uint8_t b) 1044 { 1045 1046 summitfb_write4(sc, VISFX_COLOR_INDEX, idx); 1047 summitfb_write4(sc, VISFX_COLOR_VALUE, (r << 16) | ( g << 8) | b); 1048 summitfb_write4(sc, VISFX_COLOR_MASK, 0xff); 1049 return 0; 1050 } 1051 1052 static inline void 1053 summitfb_wait_fifo(struct summitfb_softc *sc, uint32_t slots) 1054 { 1055 uint32_t reg; 1056 1057 do { 1058 reg = summitfb_read4(sc, VISFX_FIFO); 1059 } while (reg < slots); 1060 } 1061 1062 static void 1063 summitfb_clearfb(struct summitfb_softc *sc) 1064 { 1065 summitfb_write_mode(sc, OTC32 | BIN8F | BUFBL | BUFFL | 0x8c0); 1066 summitfb_wait_fifo(sc, 10); 1067 summitfb_write4(sc, VISFX_IBO, RopSrc); 1068 summitfb_write4(sc, VISFX_FG_COLOUR, 0); 1069 summitfb_write4(sc, VISFX_START, 0); 1070 summitfb_write4(sc, VISFX_SIZE, (sc->sc_width << 16) | sc->sc_height); 1071 } 1072 1073 static void 1074 summitfb_rectfill(struct summitfb_softc *sc, int x, int y, int wi, int he, 1075 uint32_t bg) 1076 { 1077 1078 summitfb_write_mode(sc, VISFX_WRITE_MODE_FILL); 1079 summitfb_wait_fifo(sc, 10); 1080 summitfb_write4(sc, VISFX_IBO, RopSrc); 1081 summitfb_write4(sc, VISFX_FG_COLOUR, bg); 1082 summitfb_write4(sc, VISFX_START, (x << 16) | y); 1083 summitfb_write4(sc, VISFX_SIZE, (wi << 16) | he); 1084 } 1085 1086 static void 1087 summitfb_bitblt(void *cookie, int xs, int ys, int xd, int yd, int wi, 1088 int he, int rop) 1089 { 1090 struct summitfb_softc *sc = cookie; 1091 uint32_t read_mode, write_mode; 1092 1093 read_mode = OTC04 | BIN8I; 1094 write_mode = OTC04 | BIN8I; 1095 if (ys >= sc->sc_height) { 1096 read_mode |= BUFBL; 1097 ys -= sc->sc_height; 1098 } 1099 if (yd >= sc->sc_height) { 1100 write_mode |= BUFBL; 1101 yd -= sc->sc_height; 1102 } 1103 summitfb_write_mode(sc, write_mode); 1104 summitfb_read_mode(sc, read_mode); 1105 summitfb_wait_fifo(sc, 10); 1106 summitfb_write4(sc, VISFX_IBO, rop); 1107 summitfb_write4(sc, VISFX_COPY_SRC, (xs << 16) | ys); 1108 summitfb_write4(sc, VISFX_COPY_WH, (wi << 16) | he); 1109 summitfb_write4(sc, VISFX_COPY_DST, (xd << 16) | yd); 1110 1111 } 1112 1113 static void 1114 summitfb_nuke_cursor(struct rasops_info *ri) 1115 { 1116 struct vcons_screen *scr = ri->ri_hw; 1117 struct summitfb_softc *sc = scr->scr_cookie; 1118 int wi, he, x, y; 1119 1120 if (ri->ri_flg & RI_CURSOR) { 1121 wi = ri->ri_font->fontwidth; 1122 he = ri->ri_font->fontheight; 1123 x = ri->ri_ccol * wi + ri->ri_xorigin; 1124 y = ri->ri_crow * he + ri->ri_yorigin; 1125 summitfb_bitblt(sc, x, y, x, y, wi, he, RopInv); 1126 ri->ri_flg &= ~RI_CURSOR; 1127 } 1128 } 1129 1130 static void 1131 summitfb_cursor(void *cookie, int on, int row, int col) 1132 { 1133 struct rasops_info *ri = cookie; 1134 struct vcons_screen *scr = ri->ri_hw; 1135 struct summitfb_softc *sc = scr->scr_cookie; 1136 int x, y, wi, he; 1137 1138 wi = ri->ri_font->fontwidth; 1139 he = ri->ri_font->fontheight; 1140 1141 if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) { 1142 if (on) { 1143 if (ri->ri_flg & RI_CURSOR) { 1144 summitfb_nuke_cursor(ri); 1145 } 1146 x = col * wi + ri->ri_xorigin; 1147 y = row * he + ri->ri_yorigin; 1148 summitfb_bitblt(sc, x, y, x, y, wi, he, RopInv); 1149 ri->ri_flg |= RI_CURSOR; 1150 } 1151 ri->ri_crow = row; 1152 ri->ri_ccol = col; 1153 } else { 1154 ri->ri_crow = row; 1155 ri->ri_ccol = col; 1156 ri->ri_flg &= ~RI_CURSOR; 1157 } 1158 1159 } 1160 1161 static void 1162 summitfb_putchar(void *cookie, int row, int col, u_int c, long attr) 1163 { 1164 struct rasops_info *ri = cookie; 1165 struct wsdisplay_font *font = PICK_FONT(ri, c); 1166 struct vcons_screen *scr = ri->ri_hw; 1167 struct summitfb_softc *sc = scr->scr_cookie; 1168 void *data; 1169 int i, x, y, wi, he; 1170 uint32_t bg, fg, mask; 1171 1172 if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL) 1173 return; 1174 1175 if (!CHAR_IN_FONT(c, font)) 1176 return; 1177 1178 if (row == ri->ri_crow && col == ri->ri_ccol) { 1179 ri->ri_flg &= ~RI_CURSOR; 1180 } 1181 1182 wi = font->fontwidth; 1183 he = font->fontheight; 1184 1185 x = ri->ri_xorigin + col * wi; 1186 y = ri->ri_yorigin + row * he; 1187 1188 bg = ri->ri_devcmap[(attr >> 16) & 0xf]; 1189 1190 /* if we're drawing a space we're done here */ 1191 if (c == 0x20) { 1192 summitfb_rectfill(sc, x, y, wi, he, bg); 1193 return; 1194 } 1195 1196 fg = ri->ri_devcmap[(attr >> 24) & 0x0f]; 1197 1198 summitfb_write_mode(sc, VISFX_WRITE_MODE_EXPAND); 1199 summitfb_wait_fifo(sc, 12); 1200 summitfb_write4(sc, VISFX_IBO, RopSrc); 1201 summitfb_write4(sc, VISFX_FG_COLOUR, fg); 1202 summitfb_write4(sc, VISFX_BG_COLOUR, bg); 1203 mask = 0xffffffff << (32 - wi); 1204 summitfb_write4(sc, VISFX_PIXEL_MASK, mask); 1205 /* not a tpyo, coordinates *are* backwards for this register */ 1206 summitfb_write4(sc, VISFX_VRAM_WRITE_DEST, (y << 16) | x); 1207 1208 data = WSFONT_GLYPH(c, font); 1209 1210 if (ri->ri_font->stride == 1) { 1211 uint8_t *data8 = data; 1212 for (i = 0; i < he; i++) { 1213 mask = *data8; 1214 summitfb_write4(sc, VISFX_VRAM_WRITE_DATA_INCRY, 1215 mask << 24); 1216 data8++; 1217 } 1218 } else { 1219 uint16_t *data16 = data; 1220 for (i = 0; i < he; i++) { 1221 mask = *data16; 1222 summitfb_write4(sc, VISFX_VRAM_WRITE_DATA_INCRY, 1223 mask << 16); 1224 data16++; 1225 } 1226 } 1227 } 1228 1229 static void 1230 summitfb_putchar_aa(void *cookie, int row, int col, u_int c, long attr) 1231 { 1232 struct rasops_info *ri = cookie; 1233 struct wsdisplay_font *font = PICK_FONT(ri, c); 1234 struct vcons_screen *scr = ri->ri_hw; 1235 struct summitfb_softc *sc = scr->scr_cookie; 1236 int x, y, wi, he, rv = GC_NOPE, i, j; 1237 uint32_t bg, fg, tmp; 1238 uint8_t *data; 1239 1240 if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL) 1241 return; 1242 1243 if (!CHAR_IN_FONT(c, font)) 1244 return; 1245 1246 if (row == ri->ri_crow && col == ri->ri_ccol) { 1247 ri->ri_flg &= ~RI_CURSOR; 1248 } 1249 1250 wi = font->fontwidth; 1251 he = font->fontheight; 1252 1253 x = ri->ri_xorigin + col * wi; 1254 y = ri->ri_yorigin + row * he; 1255 1256 bg = ri->ri_devcmap[(attr >> 16) & 0xf]; 1257 1258 if (c == 0x20) { 1259 summitfb_rectfill(sc, x, y, wi, he, bg); 1260 return; 1261 } 1262 1263 rv = glyphcache_try(&sc->sc_gc, c, x, y, attr); 1264 if (rv == GC_OK) 1265 return; 1266 1267 /* 1268 * first we clear the background - we should be able to use the CBR 1269 * register as constant background but so far I couldn't make that work 1270 */ 1271 summitfb_rectfill(sc, x, y, wi, he, bg); 1272 1273 summitfb_write_mode(sc, OTC01 | BIN332F | BUFovl); 1274 /* we need the foreground colour as full RGB8 */ 1275 fg = sc->sc_palette[(attr >> 24) & 0xf]; 1276 1277 /* 1278 * set the blending equation to 1279 * src_color * src_alpha + dst_color * (1 - src_alpha) 1280 */ 1281 summitfb_write4(sc, VISFX_IBO, 1282 IBO_ADD | SRC(IBO_SRC) | DST(IBO_ONE_MINUS_SRC)); 1283 1284 /* get the glyph */ 1285 data = WSFONT_GLYPH(c, font); 1286 for (i = 0; i < he; i++) { 1287 /* 1288 * make some room in the pipeline 1289 * with just plain ROPs we can just hammer the FIFO without 1290 * having to worry about overflowing it but I suspect with 1291 * alpha blending enabled things may be a little slower 1292 */ 1293 summitfb_wait_fifo(sc, wi * 2); 1294 /* start a new line */ 1295 summitfb_write4(sc, VISFX_VRAM_WRITE_DEST, ((y + i) << 16) | x); 1296 for (j = 0; j < wi; j++) { 1297 tmp = *data; 1298 /* alpha & RGB -> ARGB */ 1299 summitfb_write4(sc, VISFX_VRAM_WRITE_DATA_INCRX, 1300 (tmp << 24) | fg); 1301 data++; 1302 } 1303 } 1304 1305 if (rv == GC_ADD) 1306 glyphcache_add(&sc->sc_gc, c, x, y); 1307 } 1308 1309 static void 1310 summitfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols) 1311 { 1312 struct rasops_info *ri = cookie; 1313 struct vcons_screen *scr = ri->ri_hw; 1314 struct summitfb_softc *sc = scr->scr_cookie; 1315 int32_t xs, xd, y, width, height; 1316 1317 if (sc->sc_locked == 0 && sc->sc_mode == WSDISPLAYIO_MODE_EMUL) { 1318 1319 if (ri->ri_crow == row && 1320 ri->ri_ccol >= srccol && ri->ri_ccol < (srccol + ncols) && 1321 (ri->ri_flg & RI_CURSOR)) { 1322 summitfb_nuke_cursor(ri); 1323 } 1324 1325 xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol; 1326 xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol; 1327 y = ri->ri_yorigin + ri->ri_font->fontheight * row; 1328 width = ri->ri_font->fontwidth * ncols; 1329 height = ri->ri_font->fontheight; 1330 summitfb_bitblt(sc, xs, y, xd, y, width, height, RopSrc); 1331 1332 if (ri->ri_crow == row && 1333 ri->ri_ccol >= dstcol && ri->ri_ccol < (dstcol + ncols)) 1334 ri->ri_flg &= ~RI_CURSOR; 1335 } 1336 } 1337 1338 static void 1339 summitfb_erasecols(void *cookie, int row, int startcol, int ncols, 1340 long fillattr) 1341 { 1342 struct rasops_info *ri = cookie; 1343 struct vcons_screen *scr = ri->ri_hw; 1344 struct summitfb_softc *sc = scr->scr_cookie; 1345 int32_t x, y, width, height, fg, bg, ul; 1346 1347 if (sc->sc_locked == 0 && sc->sc_mode == WSDISPLAYIO_MODE_EMUL) { 1348 x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol; 1349 y = ri->ri_yorigin + ri->ri_font->fontheight * row; 1350 width = ri->ri_font->fontwidth * ncols; 1351 height = ri->ri_font->fontheight; 1352 rasops_unpack_attr(fillattr, &fg, &bg, &ul); 1353 1354 summitfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]); 1355 1356 if (ri->ri_crow == row && 1357 ri->ri_ccol >= startcol && 1358 ri->ri_ccol < (startcol + ncols)) 1359 ri->ri_flg &= ~RI_CURSOR; 1360 } 1361 } 1362 1363 static void 1364 summitfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows) 1365 { 1366 struct rasops_info *ri = cookie; 1367 struct vcons_screen *scr = ri->ri_hw; 1368 struct summitfb_softc *sc = scr->scr_cookie; 1369 int32_t x, ys, yd, width, height; 1370 1371 if (sc->sc_locked == 0 && sc->sc_mode == WSDISPLAYIO_MODE_EMUL) { 1372 1373 if (ri->ri_crow >= srcrow && ri->ri_crow < (srcrow + nrows) && 1374 (ri->ri_flg & RI_CURSOR)) { 1375 summitfb_nuke_cursor(ri); 1376 } 1377 1378 x = ri->ri_xorigin; 1379 ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow; 1380 yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow; 1381 width = ri->ri_emuwidth; 1382 height = ri->ri_font->fontheight * nrows; 1383 summitfb_bitblt(sc, x, ys, x, yd, width, height, RopSrc); 1384 1385 if (ri->ri_crow >= dstrow && ri->ri_crow < (dstrow + nrows)) 1386 ri->ri_flg &= ~RI_CURSOR; 1387 } 1388 } 1389 1390 static void 1391 summitfb_eraserows(void *cookie, int row, int nrows, long fillattr) 1392 { 1393 struct rasops_info *ri = cookie; 1394 struct vcons_screen *scr = ri->ri_hw; 1395 struct summitfb_softc *sc = scr->scr_cookie; 1396 int32_t x, y, width, height, fg, bg, ul; 1397 1398 if (sc->sc_locked == 0 && sc->sc_mode == WSDISPLAYIO_MODE_EMUL) { 1399 x = ri->ri_xorigin; 1400 y = ri->ri_yorigin + ri->ri_font->fontheight * row; 1401 width = ri->ri_emuwidth; 1402 height = ri->ri_font->fontheight * nrows; 1403 rasops_unpack_attr(fillattr, &fg, &bg, &ul); 1404 1405 summitfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]); 1406 1407 if (ri->ri_crow >= row && ri->ri_crow < (row + nrows)) 1408 ri->ri_flg &= ~RI_CURSOR; 1409 } 1410 } 1411 1412 static void 1413 summitfb_move_cursor(struct summitfb_softc *sc, int x, int y) 1414 { 1415 uint32_t pos; 1416 1417 sc->sc_cursor_x = x; 1418 x -= sc->sc_hot_x; 1419 sc->sc_cursor_y = y; 1420 y -= sc->sc_hot_y; 1421 1422 if (x < 0) 1423 x = 0x1000 - x; 1424 if (y < 0) 1425 y = 0x1000 - y; 1426 pos = (x << 16) | y; 1427 if (sc->sc_enabled) 1428 pos |= 0x80000000; 1429 summitfb_write4(sc, VISFX_CURSOR_POS, pos); 1430 } 1431 1432 static int 1433 summitfb_do_cursor(struct summitfb_softc *sc, struct wsdisplay_cursor *cur) 1434 { 1435 1436 if (cur->which & WSDISPLAY_CURSOR_DOCUR) { 1437 sc->sc_enabled = cur->enable; 1438 cur->which |= WSDISPLAY_CURSOR_DOPOS; 1439 } 1440 if (cur->which & WSDISPLAY_CURSOR_DOHOT) { 1441 sc->sc_hot_x = cur->hot.x; 1442 sc->sc_hot_y = cur->hot.y; 1443 cur->which |= WSDISPLAY_CURSOR_DOPOS; 1444 } 1445 if (cur->which & WSDISPLAY_CURSOR_DOPOS) { 1446 summitfb_move_cursor(sc, cur->pos.x, cur->pos.y); 1447 } 1448 if (cur->which & WSDISPLAY_CURSOR_DOCMAP) { 1449 uint32_t rgb; 1450 uint8_t r[2], g[2], b[2]; 1451 1452 copyin(cur->cmap.blue, b, 2); 1453 copyin(cur->cmap.green, g, 2); 1454 copyin(cur->cmap.red, r, 2); 1455 summitfb_write4(sc, VISFX_CURSOR_INDEX, 0); 1456 rgb = r[0] << 16 | g[0] << 8 | b[0]; 1457 summitfb_write4(sc, VISFX_CURSOR_BG, rgb); 1458 rgb = r[1] << 16 | g[1] << 8 | b[1]; 1459 summitfb_write4(sc, VISFX_CURSOR_FG, rgb); 1460 1461 } 1462 if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) { 1463 1464 uint32_t buffer[128], latch, tmp; 1465 int i; 1466 1467 copyin(cur->mask, buffer, 512); 1468 summitfb_write4(sc, VISFX_CURSOR_INDEX, 0); 1469 for (i = 0; i < 128; i += 2) { 1470 latch = 0; 1471 tmp = buffer[i] & 0x80808080; 1472 latch |= tmp >> 7; 1473 tmp = buffer[i] & 0x40404040; 1474 latch |= tmp >> 5; 1475 tmp = buffer[i] & 0x20202020; 1476 latch |= tmp >> 3; 1477 tmp = buffer[i] & 0x10101010; 1478 latch |= tmp >> 1; 1479 tmp = buffer[i] & 0x08080808; 1480 latch |= tmp << 1; 1481 tmp = buffer[i] & 0x04040404; 1482 latch |= tmp << 3; 1483 tmp = buffer[i] & 0x02020202; 1484 latch |= tmp << 5; 1485 tmp = buffer[i] & 0x01010101; 1486 latch |= tmp << 7; 1487 summitfb_write4(sc, VISFX_CURSOR_DATA, latch); 1488 latch = 0; 1489 tmp = buffer[i + 1] & 0x80808080; 1490 latch |= tmp >> 7; 1491 tmp = buffer[i + 1] & 0x40404040; 1492 latch |= tmp >> 5; 1493 tmp = buffer[i + 1] & 0x20202020; 1494 latch |= tmp >> 3; 1495 tmp = buffer[i + 1] & 0x10101010; 1496 latch |= tmp >> 1; 1497 tmp = buffer[i + 1] & 0x08080808; 1498 latch |= tmp << 1; 1499 tmp = buffer[i + 1] & 0x04040404; 1500 latch |= tmp << 3; 1501 tmp = buffer[i + 1] & 0x02020202; 1502 latch |= tmp << 5; 1503 tmp = buffer[i + 1] & 0x01010101; 1504 latch |= tmp << 7; 1505 summitfb_write4(sc, VISFX_CURSOR_DATA, latch); 1506 } 1507 1508 summitfb_write4(sc, VISFX_CURSOR_INDEX, 0x80); 1509 copyin(cur->image, buffer, 512); 1510 for (i = 0; i < 128; i += 2) { 1511 latch = 0; 1512 tmp = buffer[i] & 0x80808080; 1513 latch |= tmp >> 7; 1514 tmp = buffer[i] & 0x40404040; 1515 latch |= tmp >> 5; 1516 tmp = buffer[i] & 0x20202020; 1517 latch |= tmp >> 3; 1518 tmp = buffer[i] & 0x10101010; 1519 latch |= tmp >> 1; 1520 tmp = buffer[i] & 0x08080808; 1521 latch |= tmp << 1; 1522 tmp = buffer[i] & 0x04040404; 1523 latch |= tmp << 3; 1524 tmp = buffer[i] & 0x02020202; 1525 latch |= tmp << 5; 1526 tmp = buffer[i] & 0x01010101; 1527 latch |= tmp << 7; 1528 summitfb_write4(sc, VISFX_CURSOR_DATA, latch); 1529 latch = 0; 1530 tmp = buffer[i + 1] & 0x80808080; 1531 latch |= tmp >> 7; 1532 tmp = buffer[i + 1] & 0x40404040; 1533 latch |= tmp >> 5; 1534 tmp = buffer[i + 1] & 0x20202020; 1535 latch |= tmp >> 3; 1536 tmp = buffer[i + 1] & 0x10101010; 1537 latch |= tmp >> 1; 1538 tmp = buffer[i + 1] & 0x08080808; 1539 latch |= tmp << 1; 1540 tmp = buffer[i + 1] & 0x04040404; 1541 latch |= tmp << 3; 1542 tmp = buffer[i + 1] & 0x02020202; 1543 latch |= tmp << 5; 1544 tmp = buffer[i + 1] & 0x01010101; 1545 latch |= tmp << 7; 1546 summitfb_write4(sc, VISFX_CURSOR_DATA, latch); 1547 } 1548 } 1549 1550 return 0; 1551 } 1552 1553 static void 1554 summitfb_set_video(struct summitfb_softc *sc, int on) 1555 { 1556 1557 if (sc->sc_video_on == on) 1558 return; 1559 1560 sc->sc_video_on = on; 1561 1562 summitfb_wait(sc); 1563 if (on) { 1564 summitfb_write4(sc, VISFX_MPC, MPC_VIDEO_ON); 1565 } else { 1566 summitfb_write4(sc, VISFX_MPC, MPC_VSYNC_OFF | MPC_HSYNC_OFF); 1567 } 1568 } 1569 1570 static void 1571 summitfb_copyfont(struct summitfb_softc *sc) 1572 { 1573 struct sti_font *fp = &sc->sc_scr.scr_curfont; 1574 uint8_t *font = sc->sc_scr.scr_romfont; 1575 uint8_t *fontbuf, *fontdata, *src, *dst; 1576 struct wsdisplay_font *f; 1577 int bufsize, i, si; 1578 1579 if (font == NULL) 1580 return; 1581 1582 bufsize = sizeof(struct wsdisplay_font) + 32 + fp->bpc * (fp->last - fp->first); 1583 DPRINTF(("%s: %dx%d %d\n", __func__, fp->width, fp->height, bufsize)); 1584 fontbuf = kmem_alloc(bufsize, KM_SLEEP); 1585 f = (struct wsdisplay_font *)fontbuf; 1586 f->name = fontbuf + sizeof(struct wsdisplay_font); 1587 fontdata = fontbuf + sizeof(struct wsdisplay_font) + 32; 1588 strcpy(fontbuf + sizeof(struct wsdisplay_font), "HP ROM"); 1589 f->firstchar = fp->first; 1590 f->numchars = (fp->last + 1) - fp->first; 1591 f->encoding = WSDISPLAY_FONTENC_ISO; 1592 f->fontwidth = fp->width; 1593 f->fontheight = fp->height; 1594 f->stride = (fp->width + 7) >> 3; 1595 f->bitorder = WSDISPLAY_FONTORDER_L2R; 1596 f->byteorder = WSDISPLAY_FONTORDER_L2R; 1597 f->data = fontdata; 1598 /* skip over font struct */ 1599 font += sizeof(struct sti_font); 1600 /* now copy and rearrange the glyphs into ISO order */ 1601 /* first, copy the characters up to 0x7f */ 1602 memcpy(fontdata, font, (0x80 - fp->first) * fp->bpc); 1603 /* zero 0x80 to 0x9f */ 1604 memset(fontdata + 0x80 * fp->bpc, 0, 0x20 * fp->bpc); 1605 /* rearrange 0xa0 till last */ 1606 for (i = 0xa0; i < (fp->last + 1); i++) { 1607 dst = fontdata + fp->bpc * i; 1608 si = sti_unitoroman[i - 0xa0]; 1609 if (si != 0) { 1610 src = font + fp->bpc * si; 1611 memcpy(dst, src, fp->bpc); 1612 } else { 1613 /* no mapping - zero this cell */ 1614 memset(dst, 0, fp->bpc); 1615 } 1616 } 1617 wsfont_add(f, 0); 1618 } 1619