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