summitfb.c revision 1.5 1 /* $NetBSD: summitfb.c,v 1.5 2024/11/20 05:24:46 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 EG PCI graphics cards
25 * STI portions are from Miodrag Vallat's sti_pci.c
26 */
27
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: summitfb.c,v 1.5 2024/11/20 05:24:46 macallan Exp $");
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kmem.h>
34 #include <sys/device.h>
35 #include <sys/mutex.h>
36
37 #include <dev/pci/pcivar.h>
38 #include <dev/pci/pcireg.h>
39 #include <dev/pci/pcidevs.h>
40 #include <dev/pci/pciio.h>
41
42 #include <dev/wscons/wsdisplayvar.h>
43 #include <dev/wscons/wsconsio.h>
44 #include <dev/wsfont/wsfont.h>
45 #include <dev/rasops/rasops.h>
46 #include <dev/wscons/wsdisplay_vconsvar.h>
47 #include <dev/pci/wsdisplay_pci.h>
48 #include <dev/wscons/wsdisplay_glyphcachevar.h>
49
50 #include <dev/ic/stireg.h>
51 #include <dev/ic/summitreg.h>
52 #include <dev/ic/stivar.h>
53
54 #include "opt_summitfb.h"
55
56 #ifdef SUMMITFB_DEBUG
57 #define DPRINTF(s) printf s
58 #else
59 #define DPRINTF(s) __nothing
60 #endif
61
62 int summitfb_match(device_t, cfdata_t, void *);
63 void summitfb_attach(device_t, device_t, void *);
64
65 struct summitfb_softc {
66 device_t sc_dev;
67 pci_chipset_tag_t sc_pc;
68 pcitag_t sc_tag;
69
70 /* stuff we need in order to use the STI ROM */
71 struct sti_softc sc_base;
72 struct sti_screen sc_scr;
73 bus_space_handle_t sc_romh;
74
75 int sc_width, sc_height;
76 int sc_locked;
77 struct vcons_screen sc_console_screen;
78 struct wsscreen_descr sc_defaultscreen_descr;
79 const struct wsscreen_descr *sc_screens[1];
80 struct wsscreen_list sc_screenlist;
81 struct vcons_data vd;
82 int sc_mode;
83 void (*sc_putchar)(void *, int, int, u_int, long);
84 u_char sc_cmap_red[256];
85 u_char sc_cmap_green[256];
86 u_char sc_cmap_blue[256];
87 kmutex_t sc_hwlock;
88 uint32_t sc_hwmode;
89 #define HW_FB 0
90 #define HW_FILL 1
91 #define HW_BLIT 2
92 /* cursor stuff */
93 int sc_cursor_x, sc_cursor_y;
94 int sc_hot_x, sc_hot_y, sc_enabled;
95 int sc_video_on;
96 glyphcache sc_gc;
97 };
98
99 CFATTACH_DECL_NEW(summitfb, sizeof(struct summitfb_softc),
100 summitfb_match, summitfb_attach, NULL, NULL);
101
102 int summitfb_readbar(struct sti_softc *, struct pci_attach_args *, u_int,
103 int);
104 int summitfb_check_rom(struct summitfb_softc *, struct pci_attach_args *);
105 void summitfb_enable_rom(struct sti_softc *);
106 void summitfb_disable_rom(struct sti_softc *);
107 void summitfb_enable_rom_internal(struct summitfb_softc *);
108 void summitfb_disable_rom_internal(struct summitfb_softc *);
109
110 void summitfb_setup(struct summitfb_softc *);
111
112 /* XXX these really need to go into their own header */
113 int sti_pci_is_console(struct pci_attach_args *, bus_addr_t *);
114 int sti_rom_setup(struct sti_rom *, bus_space_tag_t, bus_space_tag_t,
115 bus_space_handle_t, bus_addr_t *, u_int);
116 int sti_screen_setup(struct sti_screen *, int);
117 void sti_describe_screen(struct sti_softc *, struct sti_screen *);
118
119 #define PCI_ROM_SIZE(mr) \
120 (PCI_MAPREG_ROM_ADDR(mr) & -PCI_MAPREG_ROM_ADDR(mr))
121
122 /* wsdisplay stuff */
123 static int summitfb_ioctl(void *, void *, u_long, void *, int,
124 struct lwp *);
125 static paddr_t summitfb_mmap(void *, void *, off_t, int);
126 static void summitfb_init_screen(void *, struct vcons_screen *, int,
127 long *);
128
129 static int summitfb_putcmap(struct summitfb_softc *,
130 struct wsdisplay_cmap *);
131 static int summitfb_getcmap(struct summitfb_softc *,
132 struct wsdisplay_cmap *);
133 static void summitfb_restore_palette(struct summitfb_softc *);
134 static int summitfb_putpalreg(struct summitfb_softc *, uint8_t, uint8_t,
135 uint8_t, uint8_t);
136
137 static inline void summitfb_setup_fb(struct summitfb_softc *);
138
139 static void summitfb_rectfill(struct summitfb_softc *, int, int, int, int,
140 uint32_t);
141 static void summitfb_bitblt(void *, int, int, int, int, int,
142 int, int);
143
144 static void summitfb_cursor(void *, int, int, int);
145 static void summitfb_putchar(void *, int, int, u_int, long);
146 static void summitfb_putchar_aa(void *, int, int, u_int, long);
147 static void summitfb_copycols(void *, int, int, int, int);
148 static void summitfb_erasecols(void *, int, int, int, long);
149 static void summitfb_copyrows(void *, int, int, int);
150 static void summitfb_eraserows(void *, int, int, long);
151
152 static void summitfb_move_cursor(struct summitfb_softc *, int, int);
153 static int summitfb_do_cursor(struct summitfb_softc *,
154 struct wsdisplay_cursor *);
155
156 static void summitfb_set_video(struct summitfb_softc *, int);
157
158 struct wsdisplay_accessops summitfb_accessops = {
159 .ioctl = summitfb_ioctl,
160 .mmap = summitfb_mmap,
161 .alloc_screen = NULL,
162 .free_screen = NULL,
163 .show_screen = NULL,
164 .load_font = NULL,
165 .pollc = NULL,
166 .scroll = NULL,
167 };
168
169 static inline void summitfb_wait_fifo(struct summitfb_softc *, uint32_t);
170
171 int
172 summitfb_match(device_t parent, cfdata_t cf, void *aux)
173 {
174 struct pci_attach_args *paa = aux;
175
176 if (PCI_VENDOR(paa->pa_id) != PCI_VENDOR_HP)
177 return 0;
178
179 if (PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_FX4)
180 return 10; /* beat out sti at pci */
181
182 return 0;
183 }
184
185 static inline uint32_t
186 summitfb_read4(struct summitfb_softc *sc, uint32_t offset)
187 {
188 struct sti_rom *rom = sc->sc_base.sc_rom;
189 bus_space_tag_t memt = rom->memt;
190 bus_space_handle_t memh = rom->regh[2];
191
192 return bus_space_read_stream_4(memt, memh, offset - 0x400000);
193 }
194
195 static inline void
196 summitfb_write4(struct summitfb_softc *sc, uint32_t offset, uint32_t val)
197 {
198 struct sti_rom *rom = sc->sc_base.sc_rom;
199 bus_space_tag_t memt = rom->memt;
200 bus_space_handle_t memh = rom->regh[2];
201
202 bus_space_write_stream_4(memt, memh, offset - 0x400000, val);
203 }
204
205 static inline uint8_t
206 summitfb_read1(struct summitfb_softc *sc, uint32_t offset)
207 {
208 struct sti_rom *rom = sc->sc_base.sc_rom;
209 bus_space_tag_t memt = rom->memt;
210 bus_space_handle_t memh = rom->regh[2];
211
212 return bus_space_read_1(memt, memh, offset);
213 }
214
215 static inline void
216 summitfb_write1(struct summitfb_softc *sc, uint32_t offset, uint8_t val)
217 {
218 struct sti_rom *rom = sc->sc_base.sc_rom;
219 bus_space_tag_t memt = rom->memt;
220 bus_space_handle_t memh = rom->regh[2];
221
222 bus_space_write_1(memt, memh, offset, val);
223 }
224
225 void
226 summitfb_attach(device_t parent, device_t self, void *aux)
227 {
228 struct summitfb_softc *sc = device_private(self);
229 struct pci_attach_args *paa = aux;
230 struct sti_rom *rom;
231 struct rasops_info *ri;
232 struct wsemuldisplaydev_attach_args aa;
233 unsigned long defattr = 0;
234 int ret, is_console = 0;
235
236 sc->sc_dev = self;
237
238 sc->sc_pc = paa->pa_pc;
239 sc->sc_tag = paa->pa_tag;
240 sc->sc_base.sc_dev = self;
241 sc->sc_base.sc_enable_rom = summitfb_enable_rom;
242 sc->sc_base.sc_disable_rom = summitfb_disable_rom;
243
244 /* we can *not* be interrupted when doing colour map accesses */
245 mutex_init(&sc->sc_hwlock, MUTEX_DEFAULT, IPL_HIGH);
246
247 aprint_normal("\n");
248
249 if (summitfb_check_rom(sc, paa) != 0)
250 return;
251
252 ret = sti_pci_is_console(paa, sc->sc_base. bases);
253 if (ret != 0) {
254 sc->sc_base.sc_flags |= STI_CONSOLE;
255 is_console = 1;
256 }
257 rom = kmem_zalloc(sizeof(*rom), KM_SLEEP);
258 rom->rom_softc = &sc->sc_base;
259 ret = sti_rom_setup(rom, paa->pa_iot, paa->pa_memt, sc->sc_romh,
260 sc->sc_base.bases, STI_CODEBASE_MAIN);
261 if (ret != 0) {
262 kmem_free(rom, sizeof(*rom));
263 return;
264 }
265
266 sc->sc_base.sc_rom = rom;
267
268 sc->sc_scr.scr_rom = sc->sc_base.sc_rom;
269 ret = sti_screen_setup(&sc->sc_scr, STI_FBMODE);
270
271 sc->sc_width = sc->sc_scr.scr_cfg.scr_width;
272 sc->sc_height = sc->sc_scr.scr_cfg.scr_height;
273
274 aprint_normal_dev(sc->sc_dev, "%s at %dx%d\n", sc->sc_scr.name,
275 sc->sc_width, sc->sc_height);
276 summitfb_setup(sc);
277
278 #ifdef SUMMITFB_DEBUG
279 sc->sc_height -= 200;
280 #endif
281
282 sc->sc_defaultscreen_descr = (struct wsscreen_descr){
283 .name = "default",
284 .ncols = 0, .nrows = 0,
285 .textops = NULL,
286 .fontwidth = 8, .fontheight = 16,
287 .capabilities = WSSCREEN_WSCOLORS | WSSCREEN_HILIT |
288 WSSCREEN_UNDERLINE | WSSCREEN_RESIZE,
289 .modecookie = NULL,
290 };
291
292 sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
293 sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
294 sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
295 sc->sc_locked = 0;
296
297 vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
298 &summitfb_accessops);
299 sc->vd.init_screen = summitfb_init_screen;
300 sc->vd.show_screen_cookie = &sc->sc_gc;
301 sc->vd.show_screen_cb = glyphcache_adapt;
302
303 ri = &sc->sc_console_screen.scr_ri;
304
305 sc->sc_gc.gc_bitblt = summitfb_bitblt;
306 sc->sc_gc.gc_blitcookie = sc;
307 sc->sc_gc.gc_rop = RopSrc;
308
309 vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1, &defattr);
310 sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
311
312 sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
313 sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
314 sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
315 sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
316
317 glyphcache_init(&sc->sc_gc, sc->sc_height + 5,
318 sc->sc_scr.fbheight - sc->sc_height - 5,
319 sc->sc_scr.fbwidth,
320 ri->ri_font->fontwidth,
321 ri->ri_font->fontheight,
322 defattr);
323
324 summitfb_restore_palette(sc);
325 summitfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
326 ri->ri_devcmap[(defattr >> 16) & 0xff]);
327 summitfb_setup_fb(sc);
328
329 if (is_console) {
330 wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
331 defattr);
332
333 vcons_replay_msgbuf(&sc->sc_console_screen);
334 }
335
336 /* no suspend/resume support yet */
337 pmf_device_register(sc->sc_dev, NULL, NULL);
338
339 aa.console = is_console;
340 aa.scrdata = &sc->sc_screenlist;
341 aa.accessops = &summitfb_accessops;
342 aa.accesscookie = &sc->vd;
343
344 config_found(sc->sc_dev, &aa, wsemuldisplaydevprint, CFARGS_NONE);
345 }
346
347 /*
348 * Grovel the STI ROM image.
349 */
350 int
351 summitfb_check_rom(struct summitfb_softc *spc, struct pci_attach_args *pa)
352 {
353 struct sti_softc *sc = &spc->sc_base;
354 pcireg_t address, mask;
355 bus_space_handle_t romh;
356 bus_size_t romsize, subsize, stiromsize;
357 bus_addr_t selected, offs, suboffs;
358 uint32_t tmp;
359 int i;
360 int rc;
361
362 /* sort of inline sti_pci_enable_rom(sc) */
363 address = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM);
364 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM,
365 ~PCI_MAPREG_ROM_ENABLE);
366 mask = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM);
367 address |= PCI_MAPREG_ROM_ENABLE;
368 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM, address);
369 sc->sc_flags |= STI_ROM_ENABLED;
370
371 /*
372 * Map the complete ROM for now.
373 */
374 romsize = PCI_ROM_SIZE(mask);
375 DPRINTF(("%s: mapping rom @ %lx for %lx\n", __func__,
376 (long)PCI_MAPREG_ROM_ADDR(address), (long)romsize));
377
378 rc = bus_space_map(pa->pa_memt, PCI_MAPREG_ROM_ADDR(address), romsize,
379 0, &romh);
380 if (rc != 0) {
381 aprint_error_dev(sc->sc_dev, "can't map PCI ROM (%d)\n", rc);
382 goto fail2;
383 }
384
385 summitfb_disable_rom_internal(spc);
386 /*
387 * Iterate over the ROM images, pick the best candidate.
388 */
389
390 selected = (bus_addr_t)-1;
391 for (offs = 0; offs < romsize; offs += subsize) {
392 summitfb_enable_rom_internal(spc);
393 /*
394 * Check for a valid ROM header.
395 */
396 tmp = bus_space_read_4(pa->pa_memt, romh, offs + 0);
397 tmp = le32toh(tmp);
398 if (tmp != 0x55aa0000) {
399 summitfb_disable_rom_internal(spc);
400 if (offs == 0) {
401 aprint_error_dev(sc->sc_dev,
402 "invalid PCI ROM header signature"
403 " (%08x)\n", tmp);
404 rc = EINVAL;
405 }
406 break;
407 }
408
409 /*
410 * Check ROM type.
411 */
412 tmp = bus_space_read_4(pa->pa_memt, romh, offs + 4);
413 tmp = le32toh(tmp);
414 if (tmp != 0x00000001) { /* 1 == STI ROM */
415 summitfb_disable_rom_internal(spc);
416 if (offs == 0) {
417 aprint_error_dev(sc->sc_dev,
418 "invalid PCI ROM type (%08x)\n", tmp);
419 rc = EINVAL;
420 }
421 break;
422 }
423
424 subsize = (bus_addr_t)bus_space_read_2(pa->pa_memt, romh,
425 offs + 0x0c);
426 subsize <<= 9;
427
428 #ifdef SUMMITFB_DEBUG
429 summitfb_disable_rom_internal(spc);
430 DPRINTF(("ROM offset %08x size %08x type %08x",
431 (u_int)offs, (u_int)subsize, tmp));
432 summitfb_enable_rom_internal(spc);
433 #endif
434
435 /*
436 * Check for a valid ROM data structure.
437 * We do not need it except to know what architecture the ROM
438 * code is for.
439 */
440
441 suboffs = offs +(bus_addr_t)bus_space_read_2(pa->pa_memt, romh,
442 offs + 0x18);
443 tmp = bus_space_read_4(pa->pa_memt, romh, suboffs + 0);
444 tmp = le32toh(tmp);
445 if (tmp != 0x50434952) { /* PCIR */
446 summitfb_disable_rom_internal(spc);
447 if (offs == 0) {
448 aprint_error_dev(sc->sc_dev, "invalid PCI data"
449 " signature (%08x)\n", tmp);
450 rc = EINVAL;
451 } else {
452 DPRINTF((" invalid PCI data signature %08x\n",
453 tmp));
454 continue;
455 }
456 }
457
458 tmp = bus_space_read_1(pa->pa_memt, romh, suboffs + 0x14);
459 summitfb_disable_rom_internal(spc);
460 DPRINTF((" code %02x", tmp));
461
462 switch (tmp) {
463 #ifdef __hppa__
464 case 0x10:
465 if (selected == (bus_addr_t)-1)
466 selected = offs;
467 break;
468 #endif
469 #ifdef __i386__
470 case 0x00:
471 if (selected == (bus_addr_t)-1)
472 selected = offs;
473 break;
474 #endif
475 default:
476 DPRINTF((" (wrong architecture)"));
477 break;
478 }
479 DPRINTF(("%s\n", selected == offs ? " -> SELECTED" : ""));
480 }
481
482 if (selected == (bus_addr_t)-1) {
483 if (rc == 0) {
484 aprint_error_dev(sc->sc_dev, "found no ROM with "
485 "correct microcode architecture\n");
486 rc = ENOEXEC;
487 }
488 goto fail;
489 }
490
491 /*
492 * Read the STI region BAR assignments.
493 */
494
495 summitfb_enable_rom_internal(spc);
496 offs = selected +
497 (bus_addr_t)bus_space_read_2(pa->pa_memt, romh, selected + 0x0e);
498 for (i = 0; i < STI_REGION_MAX; i++) {
499 rc = summitfb_readbar(sc, pa, i,
500 bus_space_read_1(pa->pa_memt, romh, offs + i));
501 if (rc != 0)
502 goto fail;
503 }
504
505 /*
506 * Find out where the STI ROM itself lies, and its size.
507 */
508
509 offs = selected +
510 (bus_addr_t)bus_space_read_4(pa->pa_memt, romh, selected + 0x08);
511 stiromsize = (bus_addr_t)bus_space_read_4(pa->pa_memt, romh,
512 offs + 0x18);
513 stiromsize = le32toh(stiromsize);
514 summitfb_disable_rom_internal(spc);
515
516 /*
517 * Replace our mapping with a smaller mapping of only the area
518 * we are interested in.
519 */
520
521 DPRINTF(("remapping rom @ %lx for %lx\n",
522 (long)(PCI_MAPREG_ROM_ADDR(address) + offs), (long)stiromsize));
523 bus_space_unmap(pa->pa_memt, romh, romsize);
524 rc = bus_space_map(pa->pa_memt, PCI_MAPREG_ROM_ADDR(address) + offs,
525 stiromsize, 0, &spc->sc_romh);
526 if (rc != 0) {
527 aprint_error_dev(sc->sc_dev, "can't map STI ROM (%d)\n",
528 rc);
529 goto fail2;
530 }
531 summitfb_disable_rom_internal(spc);
532 sc->sc_flags &= ~STI_ROM_ENABLED;
533
534 return 0;
535
536 fail:
537 bus_space_unmap(pa->pa_memt, romh, romsize);
538 fail2:
539 summitfb_disable_rom_internal(spc);
540
541 return rc;
542 }
543
544 /*
545 * Decode a BAR register.
546 */
547 int
548 summitfb_readbar(struct sti_softc *sc, struct pci_attach_args *pa,
549 u_int region, int bar)
550 {
551 bus_addr_t addr;
552 bus_size_t size;
553 uint32_t cf;
554 int rc;
555
556 if (bar == 0) {
557 sc->bases[region] = 0;
558 return 0;
559 }
560
561 #ifdef DIAGNOSTIC
562 if (bar < PCI_MAPREG_START || bar > PCI_MAPREG_PPB_END) {
563 summitfb_disable_rom(sc);
564 printf("%s: unexpected bar %02x for region %d\n",
565 device_xname(sc->sc_dev), bar, region);
566 summitfb_enable_rom(sc);
567 }
568 #endif
569
570 cf = pci_conf_read(pa->pa_pc, pa->pa_tag, bar);
571
572 rc = pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, PCI_MAPREG_TYPE(cf),
573 &addr, &size, NULL);
574
575 if (rc != 0) {
576 summitfb_disable_rom(sc);
577 aprint_error_dev(sc->sc_dev, "invalid bar %02x"
578 " for region %d\n",
579 bar, region);
580 summitfb_enable_rom(sc);
581 return rc;
582 }
583
584 sc->bases[region] = addr;
585 return 0;
586 }
587
588 /*
589 * Enable PCI ROM.
590 */
591 void
592 summitfb_enable_rom_internal(struct summitfb_softc *spc)
593 {
594 pcireg_t address;
595
596 KASSERT(spc != NULL);
597
598 address = pci_conf_read(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM);
599 address |= PCI_MAPREG_ROM_ENABLE;
600 pci_conf_write(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM, address);
601 }
602
603 void
604 summitfb_enable_rom(struct sti_softc *sc)
605 {
606 struct summitfb_softc *spc = device_private(sc->sc_dev);
607
608 if (!ISSET(sc->sc_flags, STI_ROM_ENABLED)) {
609 summitfb_enable_rom_internal(spc);
610 }
611 SET(sc->sc_flags, STI_ROM_ENABLED);
612 }
613
614 /*
615 * Disable PCI ROM.
616 */
617 void
618 summitfb_disable_rom_internal(struct summitfb_softc *spc)
619 {
620 pcireg_t address;
621
622 KASSERT(spc != NULL);
623
624 address = pci_conf_read(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM);
625 address &= ~PCI_MAPREG_ROM_ENABLE;
626 pci_conf_write(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM, address);
627 }
628
629 void
630 summitfb_disable_rom(struct sti_softc *sc)
631 {
632 struct summitfb_softc *spc = device_private(sc->sc_dev);
633
634 if (ISSET(sc->sc_flags, STI_ROM_ENABLED)) {
635 summitfb_disable_rom_internal(spc);
636 }
637 CLR(sc->sc_flags, STI_ROM_ENABLED);
638 }
639
640 static inline void
641 summitfb_wait(struct summitfb_softc *sc)
642 {
643
644 while (summitfb_read4(sc, VISFX_STATUS) != 0)
645 continue;
646 }
647
648 static inline void
649 summitfb_setup_fb(struct summitfb_softc *sc)
650 {
651
652 sc->sc_hwmode = HW_FB;
653 summitfb_wait(sc);
654 summitfb_write4(sc, VISFX_VRAM_WRITE_MODE, VISFX_WRITE_MODE_PLAIN);
655 }
656
657 void
658 summitfb_setup(struct summitfb_softc *sc)
659 {
660
661 sc->sc_hwmode = HW_FB;
662 sc->sc_hot_x = 0;
663 sc->sc_hot_y = 0;
664 sc->sc_enabled = 0;
665 sc->sc_video_on = 1;
666
667 /*
668 * STI hands us the frame buffer in 32bit access mode,
669 * one of these puts us into 8bit FB access mode
670 */
671 #if 1
672 summitfb_write4(sc, 0xb08044, 0x1b);
673 summitfb_write4(sc, 0xb08048, 0x1b);
674 summitfb_write4(sc, 0x920860, 0xe4);
675 summitfb_write4(sc, 0xa00818, 0);
676 summitfb_write4(sc, 0xa00404, 0);
677 summitfb_write4(sc, 0x921110, 0);
678 summitfb_write4(sc, 0x9211d8, 0);
679 summitfb_write4(sc, 0xa0086c, 0);
680 summitfb_write4(sc, 0x921114, 0);
681 summitfb_write4(sc, 0xac1050, 0);
682 summitfb_write4(sc, 0xa00858, 0xb0);
683 #endif
684
685 summitfb_write4(sc, VISFX_PIXEL_MASK, 0xffffffff);
686 summitfb_write4(sc, VISFX_PLANE_MASK, 0xffffffff);
687
688 summitfb_setup_fb(sc);
689 }
690
691 static int
692 summitfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
693 struct lwp *l)
694 {
695 struct vcons_data *vd = v;
696 struct summitfb_softc *sc = vd->cookie;
697 struct wsdisplay_fbinfo *wdf;
698 struct vcons_screen *ms = vd->active;
699
700 switch (cmd) {
701 case WSDISPLAYIO_GTYPE:
702 *(u_int *)data = WSDISPLAY_TYPE_STI;
703 return 0;
704
705 case GCID:
706 *(u_int *)data = sc->sc_scr.scr_rom->rom_dd.dd_grid[0];
707 return 0;
708
709 /* PCI config read/write passthrough. */
710 case PCI_IOC_CFGREAD:
711 case PCI_IOC_CFGWRITE:
712 return pci_devioctl(sc->sc_pc, sc->sc_tag,
713 cmd, data, flag, l);
714
715 case WSDISPLAYIO_GET_BUSID:
716 return wsdisplayio_busid_pci(sc->sc_dev, sc->sc_pc,
717 sc->sc_tag, data);
718
719 case WSDISPLAYIO_GINFO:
720 if (ms == NULL)
721 return ENODEV;
722 wdf = data;
723 wdf->height = ms->scr_ri.ri_height;
724 wdf->width = ms->scr_ri.ri_width;
725 wdf->depth = ms->scr_ri.ri_depth;
726 wdf->cmsize = 256;
727 return 0;
728
729 case WSDISPLAYIO_GETCMAP:
730 return summitfb_getcmap(sc,
731 (struct wsdisplay_cmap *)data);
732
733 case WSDISPLAYIO_PUTCMAP:
734 return summitfb_putcmap(sc,
735 (struct wsdisplay_cmap *)data);
736
737 case WSDISPLAYIO_LINEBYTES:
738 *(u_int *)data = 2048;
739 return 0;
740
741 case WSDISPLAYIO_SMODE: {
742 int new_mode = *(int *)data;
743
744 if (new_mode != sc->sc_mode) {
745 sc->sc_mode = new_mode;
746 if(new_mode == WSDISPLAYIO_MODE_EMUL) {
747 summitfb_setup(sc);
748 summitfb_restore_palette(sc);
749 //glyphcache_wipe(&sc->sc_gc);
750 summitfb_rectfill(sc, 0, 0, sc->sc_width,
751 sc->sc_height, ms->scr_ri.ri_devcmap[
752 (ms->scr_defattr >> 16) & 0xff]);
753 summitfb_setup_fb(sc);
754 vcons_redraw_screen(ms);
755 summitfb_set_video(sc, 1);
756 }
757 }
758 return 0;
759 }
760
761 case WSDISPLAYIO_GET_FBINFO: {
762 struct wsdisplayio_fbinfo *fbi = data;
763 int ret;
764
765 ret = wsdisplayio_get_fbinfo(&ms->scr_ri, fbi);
766 fbi->fbi_fbsize = sc->sc_scr.fbheight * 2048;
767 return ret;
768 }
769
770 case WSDISPLAYIO_GCURPOS: {
771 struct wsdisplay_curpos *cp = data;
772
773 cp->x = sc->sc_cursor_x;
774 cp->y = sc->sc_cursor_y;
775 return 0;
776 }
777
778 case WSDISPLAYIO_SCURPOS: {
779 struct wsdisplay_curpos *cp = data;
780
781 summitfb_move_cursor(sc, cp->x, cp->y);
782 return 0;
783 }
784
785 case WSDISPLAYIO_GCURMAX: {
786 struct wsdisplay_curpos *cp = data;
787
788 cp->x = 64;
789 cp->y = 64;
790 return 0;
791 }
792
793 case WSDISPLAYIO_SCURSOR: {
794 struct wsdisplay_cursor *cursor = data;
795
796 return summitfb_do_cursor(sc, cursor);
797 }
798
799 case WSDISPLAYIO_SVIDEO:
800 summitfb_set_video(sc, *(int *)data);
801 return 0;
802 case WSDISPLAYIO_GVIDEO:
803 *(u_int *)data = sc->sc_video_on ?
804 WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF;
805 return 0;
806 }
807 return EPASSTHROUGH;
808 }
809
810 static paddr_t
811 summitfb_mmap(void *v, void *vs, off_t offset, int prot)
812 {
813 struct vcons_data *vd = v;
814 struct summitfb_softc *sc = vd->cookie;
815 struct sti_rom *rom = sc->sc_base.sc_rom;
816 paddr_t pa = -1;
817
818 if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)
819 return -1;
820
821 if (offset >= 0 && offset < sc->sc_scr.fblen) {
822 /* framebuffer */
823 pa = bus_space_mmap(rom->memt, sc->sc_scr.fbaddr, offset,
824 prot, BUS_SPACE_MAP_LINEAR);
825 } else if (offset >= 0x80000000 && offset < 0x80400000) {
826 /* blitter registers etc. */
827 pa = bus_space_mmap(rom->memt, rom->regh[0],
828 offset - 0x80000000, prot, BUS_SPACE_MAP_LINEAR);
829 }
830
831 return pa;
832 }
833
834 static void
835 summitfb_init_screen(void *cookie, struct vcons_screen *scr,
836 int existing, long *defattr)
837 {
838 struct summitfb_softc *sc = cookie;
839 struct rasops_info *ri = &scr->scr_ri;
840
841 ri->ri_depth = 8;
842 ri->ri_width = sc->sc_width;
843 ri->ri_height = sc->sc_height;
844 ri->ri_stride = 2048;
845 ri->ri_flg = RI_CENTER | RI_8BIT_IS_RGB /*|
846 RI_ENABLE_ALPHA | RI_PREFER_ALPHA*/;
847
848 ri->ri_bits = (void *)sc->sc_scr.fbaddr;
849 rasops_init(ri, 0, 0);
850 ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_UNDERLINE |
851 WSSCREEN_RESIZE;
852 scr->scr_flags |= VCONS_LOADFONT | VCONS_DONT_READ;
853
854 rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
855 sc->sc_width / ri->ri_font->fontwidth);
856
857 ri->ri_hw = scr;
858 if (0) {
859 sc->sc_putchar = ri->ri_ops.putchar;
860 ri->ri_ops.copyrows = summitfb_copyrows;
861 ri->ri_ops.copycols = summitfb_copycols;
862 ri->ri_ops.eraserows = summitfb_eraserows;
863 ri->ri_ops.erasecols = summitfb_erasecols;
864 ri->ri_ops.cursor = summitfb_cursor;
865 if (FONT_IS_ALPHA(ri->ri_font)) {
866 ri->ri_ops.putchar = summitfb_putchar_aa;
867 } else
868 ri->ri_ops.putchar = summitfb_putchar;
869 }
870 }
871
872 static int
873 summitfb_putcmap(struct summitfb_softc *sc, struct wsdisplay_cmap *cm)
874 {
875 u_char *r, *g, *b;
876 u_int index = cm->index;
877 u_int count = cm->count;
878 int i, error;
879 u_char rbuf[256], gbuf[256], bbuf[256];
880
881 if (cm->index >= 256 || cm->count > 256 ||
882 (cm->index + cm->count) > 256)
883 return EINVAL;
884 error = copyin(cm->red, &rbuf[index], count);
885 if (error)
886 return error;
887 error = copyin(cm->green, &gbuf[index], count);
888 if (error)
889 return error;
890 error = copyin(cm->blue, &bbuf[index], count);
891 if (error)
892 return error;
893
894 memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
895 memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
896 memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
897
898 r = &sc->sc_cmap_red[index];
899 g = &sc->sc_cmap_green[index];
900 b = &sc->sc_cmap_blue[index];
901
902 for (i = 0; i < count; i++) {
903 summitfb_putpalreg(sc, index, *r, *g, *b);
904 index++;
905 r++, g++, b++;
906 }
907 return 0;
908 }
909
910 static int
911 summitfb_getcmap(struct summitfb_softc *sc, struct wsdisplay_cmap *cm)
912 {
913 u_int index = cm->index;
914 u_int count = cm->count;
915 int error;
916
917 if (index >= 255 || count > 256 || index + count > 256)
918 return EINVAL;
919
920 error = copyout(&sc->sc_cmap_red[index], cm->red, count);
921 if (error)
922 return error;
923 error = copyout(&sc->sc_cmap_green[index], cm->green, count);
924 if (error)
925 return error;
926 error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
927 if (error)
928 return error;
929
930 return 0;
931 }
932
933 static void
934 summitfb_restore_palette(struct summitfb_softc *sc)
935 {
936 uint8_t cmap[768];
937 int i, j;
938
939 j = 0;
940 rasops_get_cmap(&sc->sc_console_screen.scr_ri, cmap, sizeof(cmap));
941 for (i = 0; i < 256; i++) {
942 sc->sc_cmap_red[i] = cmap[j];
943 sc->sc_cmap_green[i] = cmap[j + 1];
944 sc->sc_cmap_blue[i] = cmap[j + 2];
945 summitfb_putpalreg(sc, i, cmap[j], cmap[j + 1], cmap[j + 2]);
946 j += 3;
947 }
948 }
949
950 static int
951 summitfb_putpalreg(struct summitfb_softc *sc, uint8_t idx,
952 uint8_t r, uint8_t g, uint8_t b)
953 {
954
955 mutex_enter(&sc->sc_hwlock);
956 summitfb_write4(sc, VISFX_COLOR_INDEX, 0xc0005100 + idx);
957 summitfb_write4(sc, VISFX_COLOR_VALUE, (r << 16) | ( g << 8) | b);
958 summitfb_write4(sc, VISFX_COLOR_MASK, 0xff);
959 summitfb_write4(sc, 0x80004c, 0xc);
960 summitfb_write4(sc, 0x800000, 0);
961 mutex_exit(&sc->sc_hwlock);
962 return 0;
963 }
964
965 static inline void
966 summitfb_wait_fifo(struct summitfb_softc *sc, uint32_t slots)
967 {
968 #if 0
969 uint32_t reg;
970
971 do {
972 reg = summitfb_read4(sc, NGLE_REG_34);
973 } while (reg < slots);
974 #endif
975 }
976
977 static void
978 summitfb_rectfill(struct summitfb_softc *sc, int x, int y, int wi, int he,
979 uint32_t bg)
980 {
981
982 summitfb_wait(sc);
983 summitfb_write4(sc, VISFX_VRAM_WRITE_MODE, VISFX_WRITE_MODE_FILL);
984 summitfb_write4(sc, VISFX_FG_COLOUR, bg);
985 summitfb_write4(sc, VISFX_BG_COLOUR, bg);
986 summitfb_write4(sc, VISFX_START, (x << 16) | y);
987 summitfb_write4(sc, VISFX_SIZE, (wi << 16) | he);
988 }
989
990 static void
991 summitfb_bitblt(void *cookie, int xs, int ys, int xd, int yd, int wi,
992 int he, int rop)
993 {
994 #if 0
995 struct summitfb_softc *sc = cookie;
996 #endif
997 }
998
999 static void
1000 summitfb_nuke_cursor(struct rasops_info *ri)
1001 {
1002 struct vcons_screen *scr = ri->ri_hw;
1003 struct summitfb_softc *sc = scr->scr_cookie;
1004 int wi, he, x, y;
1005
1006 if (ri->ri_flg & RI_CURSOR) {
1007 wi = ri->ri_font->fontwidth;
1008 he = ri->ri_font->fontheight;
1009 x = ri->ri_ccol * wi + ri->ri_xorigin;
1010 y = ri->ri_crow * he + ri->ri_yorigin;
1011 summitfb_bitblt(sc, x, y, x, y, wi, he, RopInv);
1012 ri->ri_flg &= ~RI_CURSOR;
1013 }
1014 }
1015
1016 static void
1017 summitfb_cursor(void *cookie, int on, int row, int col)
1018 {
1019 struct rasops_info *ri = cookie;
1020 struct vcons_screen *scr = ri->ri_hw;
1021 struct summitfb_softc *sc = scr->scr_cookie;
1022 int x, y, wi, he;
1023
1024 wi = ri->ri_font->fontwidth;
1025 he = ri->ri_font->fontheight;
1026
1027 if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
1028 if (on) {
1029 if (ri->ri_flg & RI_CURSOR) {
1030 summitfb_nuke_cursor(ri);
1031 }
1032 x = col * wi + ri->ri_xorigin;
1033 y = row * he + ri->ri_yorigin;
1034 summitfb_bitblt(sc, x, y, x, y, wi, he, RopInv);
1035 ri->ri_flg |= RI_CURSOR;
1036 }
1037 ri->ri_crow = row;
1038 ri->ri_ccol = col;
1039 } else {
1040 ri->ri_crow = row;
1041 ri->ri_ccol = col;
1042 ri->ri_flg &= ~RI_CURSOR;
1043 }
1044
1045 }
1046
1047 static void
1048 summitfb_putchar(void *cookie, int row, int col, u_int c, long attr)
1049 {
1050 #if 0
1051 struct rasops_info *ri = cookie;
1052 struct wsdisplay_font *font = PICK_FONT(ri, c);
1053 struct vcons_screen *scr = ri->ri_hw;
1054 struct summitfb_softc *sc = scr->scr_cookie;
1055 //void *data;
1056 int x, y, wi, he, rv = GC_NOPE;
1057 uint32_t bg, fg, mask;
1058
1059 if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL)
1060 return;
1061
1062 if (!CHAR_IN_FONT(c, font))
1063 return;
1064
1065 if (row == ri->ri_crow && col == ri->ri_ccol) {
1066 ri->ri_flg &= ~RI_CURSOR;
1067 }
1068
1069 wi = font->fontwidth;
1070 he = font->fontheight;
1071
1072 x = ri->ri_xorigin + col * wi;
1073 y = ri->ri_yorigin + row * he;
1074
1075 bg = ri->ri_devcmap[(attr >> 16) & 0xf];
1076
1077 /* if we're drawing a space we're done here */
1078 if (c == 0x20) {
1079 summitfb_rectfill(sc, x, y, wi, he, bg);
1080 return;
1081 }
1082
1083 fg = ri->ri_devcmap[(attr >> 24) & 0x0f];
1084
1085 rv = glyphcache_try(&sc->sc_gc, c, x, y, attr);
1086 if (rv == GC_OK)
1087 return;
1088
1089 /* clear the character cell */
1090 summitfb_rectfill(sc, x, y, wi, he, bg);
1091
1092 //data = WSFONT_GLYPH(c, font);
1093 /* ... */
1094 if (rv == GC_ADD)
1095 glyphcache_add(&sc->sc_gc, c, x, y);
1096 #endif
1097 }
1098
1099 static void
1100 summitfb_putchar_aa(void *cookie, int row, int col, u_int c, long attr)
1101 {
1102 struct rasops_info *ri = cookie;
1103 struct wsdisplay_font *font = PICK_FONT(ri, c);
1104 struct vcons_screen *scr = ri->ri_hw;
1105 struct summitfb_softc *sc = scr->scr_cookie;
1106 int x, y, wi, he, rv = GC_NOPE;
1107 uint32_t bg;
1108
1109 if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL)
1110 return;
1111
1112 if (!CHAR_IN_FONT(c, font))
1113 return;
1114
1115 if (row == ri->ri_crow && col == ri->ri_ccol) {
1116 ri->ri_flg &= ~RI_CURSOR;
1117 }
1118
1119 wi = font->fontwidth;
1120 he = font->fontheight;
1121
1122 x = ri->ri_xorigin + col * wi;
1123 y = ri->ri_yorigin + row * he;
1124
1125 bg = ri->ri_devcmap[(attr >> 16) & 0xf];
1126
1127 if (c == 0x20) {
1128 summitfb_rectfill(sc, x, y, wi, he, bg);
1129 return;
1130 }
1131
1132 rv = glyphcache_try(&sc->sc_gc, c, x, y, attr);
1133 if (rv == GC_OK)
1134 return;
1135
1136 if (sc->sc_hwmode != HW_FB) summitfb_setup_fb(sc);
1137 sc->sc_putchar(cookie, row, col, c, attr);
1138
1139 if (rv == GC_ADD)
1140 glyphcache_add(&sc->sc_gc, c, x, y);
1141 }
1142
1143 static void
1144 summitfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
1145 {
1146 struct rasops_info *ri = cookie;
1147 struct vcons_screen *scr = ri->ri_hw;
1148 struct summitfb_softc *sc = scr->scr_cookie;
1149 int32_t xs, xd, y, width, height;
1150
1151 if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
1152 if (ri->ri_crow == row &&
1153 ri->ri_ccol >= srccol && ri->ri_ccol < (srccol + ncols) &&
1154 (ri->ri_flg & RI_CURSOR)) {
1155 summitfb_nuke_cursor(ri);
1156 }
1157
1158 xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
1159 xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
1160 y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1161 width = ri->ri_font->fontwidth * ncols;
1162 height = ri->ri_font->fontheight;
1163 summitfb_bitblt(sc, xs, y, xd, y, width, height, RopSrc);
1164 if (ri->ri_crow == row &&
1165 ri->ri_ccol >= dstcol && ri->ri_ccol < (dstcol + ncols))
1166 ri->ri_flg &= ~RI_CURSOR;
1167 }
1168 }
1169
1170 static void
1171 summitfb_erasecols(void *cookie, int row, int startcol, int ncols,
1172 long fillattr)
1173 {
1174 struct rasops_info *ri = cookie;
1175 struct vcons_screen *scr = ri->ri_hw;
1176 struct summitfb_softc *sc = scr->scr_cookie;
1177 int32_t x, y, width, height, fg, bg, ul;
1178
1179 if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
1180 x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
1181 y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1182 width = ri->ri_font->fontwidth * ncols;
1183 height = ri->ri_font->fontheight;
1184 rasops_unpack_attr(fillattr, &fg, &bg, &ul);
1185
1186 summitfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
1187 if (ri->ri_crow == row &&
1188 ri->ri_ccol >= startcol &&
1189 ri->ri_ccol < (startcol + ncols))
1190 ri->ri_flg &= ~RI_CURSOR;
1191 }
1192 }
1193
1194 static void
1195 summitfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
1196 {
1197 struct rasops_info *ri = cookie;
1198 struct vcons_screen *scr = ri->ri_hw;
1199 struct summitfb_softc *sc = scr->scr_cookie;
1200 int32_t x, ys, yd, width, height;
1201
1202 if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
1203 if (ri->ri_crow >= srcrow && ri->ri_crow < (srcrow + nrows) &&
1204 (ri->ri_flg & RI_CURSOR)) {
1205 summitfb_nuke_cursor(ri);
1206 }
1207 x = ri->ri_xorigin;
1208 ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
1209 yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
1210 width = ri->ri_emuwidth;
1211 height = ri->ri_font->fontheight * nrows;
1212 summitfb_bitblt(sc, x, ys, x, yd, width, height, RopSrc);
1213 if (ri->ri_crow >= dstrow && ri->ri_crow < (dstrow + nrows))
1214 ri->ri_flg &= ~RI_CURSOR;
1215 }
1216 }
1217
1218 static void
1219 summitfb_eraserows(void *cookie, int row, int nrows, long fillattr)
1220 {
1221 struct rasops_info *ri = cookie;
1222 struct vcons_screen *scr = ri->ri_hw;
1223 struct summitfb_softc *sc = scr->scr_cookie;
1224 int32_t x, y, width, height, fg, bg, ul;
1225
1226 if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
1227 x = ri->ri_xorigin;
1228 y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1229 width = ri->ri_emuwidth;
1230 height = ri->ri_font->fontheight * nrows;
1231 rasops_unpack_attr(fillattr, &fg, &bg, &ul);
1232
1233 summitfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
1234
1235 if (ri->ri_crow >= row && ri->ri_crow < (row + nrows))
1236 ri->ri_flg &= ~RI_CURSOR;
1237 }
1238 }
1239
1240 static void
1241 summitfb_move_cursor(struct summitfb_softc *sc, int x, int y)
1242 {
1243 uint32_t pos;
1244
1245 sc->sc_cursor_x = x;
1246 x -= sc->sc_hot_x;
1247 sc->sc_cursor_y = y;
1248 y -= sc->sc_hot_y;
1249
1250 if (x < 0) x = 0x1000 - x;
1251 if (y < 0) y = 0x1000 - y;
1252 pos = (x << 16) | y;
1253 if (sc->sc_enabled) pos |= 0x80000000;
1254 summitfb_write4(sc, VISFX_CURSOR_POS, pos);
1255 }
1256
1257 static int
1258 summitfb_do_cursor(struct summitfb_softc *sc, struct wsdisplay_cursor *cur)
1259 {
1260
1261 if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
1262 sc->sc_enabled = cur->enable;
1263 cur->which |= WSDISPLAY_CURSOR_DOPOS;
1264 }
1265 if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
1266 sc->sc_hot_x = cur->hot.x;
1267 sc->sc_hot_y = cur->hot.y;
1268 cur->which |= WSDISPLAY_CURSOR_DOPOS;
1269 }
1270 if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
1271 summitfb_move_cursor(sc, cur->pos.x, cur->pos.y);
1272 }
1273 if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
1274 uint32_t rgb;
1275 uint8_t r[2], g[2], b[2];
1276
1277 copyin(cur->cmap.blue, b, 2);
1278 copyin(cur->cmap.green, g, 2);
1279 copyin(cur->cmap.red, r, 2);
1280 mutex_enter(&sc->sc_hwlock);
1281 summitfb_write4(sc, VISFX_CURSOR_INDEX, 0);
1282 rgb = r[0] << 16 | g[0] << 8 | b[0];
1283 summitfb_write4(sc, VISFX_CURSOR_COLOR, rgb);
1284 rgb = r[1] << 16 | g[1] << 8 | b[1];
1285 summitfb_write4(sc, VISFX_CURSOR_COLOR + 4, rgb);
1286 mutex_exit(&sc->sc_hwlock);
1287 }
1288 if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
1289
1290 uint32_t buffer[128], latch, tmp;
1291 int i;
1292
1293 copyin(cur->mask, buffer, 512);
1294 summitfb_write4(sc, VISFX_CURSOR_INDEX, 0);
1295 for (i = 0; i < 128; i += 2) {
1296 latch = 0;
1297 tmp = buffer[i] & 0x80808080;
1298 latch |= tmp >> 7;
1299 tmp = buffer[i] & 0x40404040;
1300 latch |= tmp >> 5;
1301 tmp = buffer[i] & 0x20202020;
1302 latch |= tmp >> 3;
1303 tmp = buffer[i] & 0x10101010;
1304 latch |= tmp >> 1;
1305 tmp = buffer[i] & 0x08080808;
1306 latch |= tmp << 1;
1307 tmp = buffer[i] & 0x04040404;
1308 latch |= tmp << 3;
1309 tmp = buffer[i] & 0x02020202;
1310 latch |= tmp << 5;
1311 tmp = buffer[i] & 0x01010101;
1312 latch |= tmp << 7;
1313 summitfb_write4(sc, VISFX_CURSOR_DATA, latch);
1314 latch = 0;
1315 tmp = buffer[i + 1] & 0x80808080;
1316 latch |= tmp >> 7;
1317 tmp = buffer[i + 1] & 0x40404040;
1318 latch |= tmp >> 5;
1319 tmp = buffer[i + 1] & 0x20202020;
1320 latch |= tmp >> 3;
1321 tmp = buffer[i + 1] & 0x10101010;
1322 latch |= tmp >> 1;
1323 tmp = buffer[i + 1] & 0x08080808;
1324 latch |= tmp << 1;
1325 tmp = buffer[i + 1] & 0x04040404;
1326 latch |= tmp << 3;
1327 tmp = buffer[i + 1] & 0x02020202;
1328 latch |= tmp << 5;
1329 tmp = buffer[i + 1] & 0x01010101;
1330 latch |= tmp << 7;
1331 summitfb_write4(sc, VISFX_CURSOR_DATA, latch);
1332 }
1333
1334 summitfb_write4(sc, VISFX_CURSOR_INDEX, 0x80);
1335 copyin(cur->image, buffer, 512);
1336 for (i = 0; i < 128; i += 2) {
1337 latch = 0;
1338 tmp = buffer[i] & 0x80808080;
1339 latch |= tmp >> 7;
1340 tmp = buffer[i] & 0x40404040;
1341 latch |= tmp >> 5;
1342 tmp = buffer[i] & 0x20202020;
1343 latch |= tmp >> 3;
1344 tmp = buffer[i] & 0x10101010;
1345 latch |= tmp >> 1;
1346 tmp = buffer[i] & 0x08080808;
1347 latch |= tmp << 1;
1348 tmp = buffer[i] & 0x04040404;
1349 latch |= tmp << 3;
1350 tmp = buffer[i] & 0x02020202;
1351 latch |= tmp << 5;
1352 tmp = buffer[i] & 0x01010101;
1353 latch |= tmp << 7;
1354 summitfb_write4(sc, VISFX_CURSOR_DATA, latch);
1355 latch = 0;
1356 tmp = buffer[i + 1] & 0x80808080;
1357 latch |= tmp >> 7;
1358 tmp = buffer[i + 1] & 0x40404040;
1359 latch |= tmp >> 5;
1360 tmp = buffer[i + 1] & 0x20202020;
1361 latch |= tmp >> 3;
1362 tmp = buffer[i + 1] & 0x10101010;
1363 latch |= tmp >> 1;
1364 tmp = buffer[i + 1] & 0x08080808;
1365 latch |= tmp << 1;
1366 tmp = buffer[i + 1] & 0x04040404;
1367 latch |= tmp << 3;
1368 tmp = buffer[i + 1] & 0x02020202;
1369 latch |= tmp << 5;
1370 tmp = buffer[i + 1] & 0x01010101;
1371 latch |= tmp << 7;
1372 summitfb_write4(sc, VISFX_CURSOR_DATA, latch);
1373 }
1374 summitfb_setup_fb(sc);
1375 }
1376
1377 return 0;
1378 }
1379
1380 static void
1381 summitfb_set_video(struct summitfb_softc *sc, int on)
1382 {
1383
1384 if (sc->sc_video_on == on)
1385 return;
1386
1387 sc->sc_video_on = on;
1388
1389 summitfb_wait(sc);
1390 if (on) {
1391 } else {
1392 }
1393 }
1394