hyperfb.c revision 1.7 1 /* $NetBSD: hyperfb.c,v 1.7 2024/07/31 16:38:00 riastradh Exp $ */
2
3 /*
4 * Copyright (c) 2024 Michael Lorenz
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /*
30 * a native driver for HCRX / hyperdrive cards
31 * tested on a HCRX24Z in a C360 only so far
32 */
33
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: hyperfb.c,v 1.7 2024/07/31 16:38:00 riastradh Exp $");
36
37 #include "opt_cputype.h"
38 #include "opt_hyperfb.h"
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43
44 #include <sys/bus.h>
45 #include <machine/cpu.h>
46 #include <machine/iomod.h>
47 #include <machine/autoconf.h>
48
49 #include <dev/wscons/wsdisplayvar.h>
50 #include <dev/wscons/wsconsio.h>
51 #include <dev/wsfont/wsfont.h>
52 #include <dev/rasops/rasops.h>
53 #include <dev/wscons/wsdisplay_vconsvar.h>
54 #include <dev/wscons/wsdisplay_glyphcachevar.h>
55
56 #include <dev/ic/stireg.h>
57 #include <dev/ic/stivar.h>
58
59 #include <hppa/dev/cpudevs.h>
60 #include <hppa/hppa/machdep.h>
61
62 #ifdef HYPERFB_DEBUG
63 #define DPRINTF printf
64 #else
65 #define DPRINTF if (0) printf
66 #endif
67
68 #define STI_ROMSIZE (sizeof(struct sti_dd) * 4)
69
70 #define HCRX_FBOFFSET 0x01000000
71 #define HCRX_FBLEN 0x01000000
72 #define HCRX_REGOFFSET 0x00100000
73 #define HCRX_REGLEN 0x00280000
74
75 #define HCRX_CONFIG_24BIT 0x100
76
77 int hyperfb_match(device_t, cfdata_t, void *);
78 void hyperfb_attach(device_t, device_t, void *);
79
80 struct hyperfb_softc {
81 device_t sc_dev;
82 bus_space_tag_t sc_iot;
83 bus_addr_t sc_base;
84 bus_space_handle_t sc_hfb, sc_hreg;
85 void *sc_fb;
86
87 int sc_width, sc_height;
88 int sc_locked, sc_is_console, sc_24bit;
89 struct vcons_screen sc_console_screen;
90 struct wsscreen_descr sc_defaultscreen_descr;
91 const struct wsscreen_descr *sc_screens[1];
92 struct wsscreen_list sc_screenlist;
93 struct vcons_data vd;
94 int sc_mode;
95 void (*sc_putchar)(void *, int, int, u_int, long);
96 u_char sc_cmap_red[256];
97 u_char sc_cmap_green[256];
98 u_char sc_cmap_blue[256];
99 kmutex_t sc_hwlock;
100 uint32_t sc_hwmode;
101 #define HW_FB 0
102 #define HW_FILL 1
103 #define HW_BLIT 2
104 #define HW_SFILL 3
105 /* cursor stuff */
106 int sc_cursor_x, sc_cursor_y;
107 int sc_hot_x, sc_hot_y, sc_enabled;
108 int sc_video_on;
109 glyphcache sc_gc;
110 };
111
112 extern struct cfdriver hyperfb_cd;
113
114 CFATTACH_DECL_NEW(hyperfb, sizeof(struct hyperfb_softc), hyperfb_match,
115 hyperfb_attach, NULL, NULL);
116
117 static inline void hyperfb_setup_fb(struct hyperfb_softc *);
118 static inline void hyperfb_setup_fb24(struct hyperfb_softc *);
119 static void hyperfb_init_screen(void *, struct vcons_screen *,
120 int, long *);
121 static int hyperfb_ioctl(void *, void *, u_long, void *, int,
122 struct lwp *);
123 static paddr_t hyperfb_mmap(void *, void *, off_t, int);
124
125 static int hyperfb_putcmap(struct hyperfb_softc *,
126 struct wsdisplay_cmap *);
127 static int hyperfb_getcmap(struct hyperfb_softc *,
128 struct wsdisplay_cmap *);
129 static void hyperfb_restore_palette(struct hyperfb_softc *);
130 static int hyperfb_putpalreg(struct hyperfb_softc *, uint8_t, uint8_t,
131 uint8_t, uint8_t);
132 void hyperfb_setup(struct hyperfb_softc *);
133 static void hyperfb_set_video(struct hyperfb_softc *, int);
134
135 static void hyperfb_rectfill(struct hyperfb_softc *, int, int, int, int,
136 uint32_t);
137 static void hyperfb_bitblt(void *, int, int, int, int, int,
138 int, int);
139
140 static void hyperfb_cursor(void *, int, int, int);
141 static void hyperfb_putchar(void *, int, int, u_int, long);
142 static void hyperfb_copycols(void *, int, int, int, int);
143 static void hyperfb_erasecols(void *, int, int, int, long);
144 static void hyperfb_copyrows(void *, int, int, int);
145 static void hyperfb_eraserows(void *, int, int, long);
146
147 static void hyperfb_move_cursor(struct hyperfb_softc *, int, int);
148 static int hyperfb_do_cursor(struct hyperfb_softc *,
149 struct wsdisplay_cursor *);
150
151 static inline void hyperfb_wait_fifo(struct hyperfb_softc *, uint32_t);
152
153 #define ngle_bt458_write(sc, r, v) \
154 hyperfb_write4(sc, NGLE_REG_RAMDAC + ((r) << 2), (v) << 24)
155
156 struct wsdisplay_accessops hyperfb_accessops = {
157 hyperfb_ioctl,
158 hyperfb_mmap,
159 NULL, /* alloc_screen */
160 NULL, /* free_screen */
161 NULL, /* show_screen */
162 NULL, /* load_font */
163 NULL, /* pollc */
164 NULL /* scroll */
165 };
166
167 static inline uint32_t
168 hyperfb_read4(struct hyperfb_softc *sc, uint32_t offset)
169 {
170 return bus_space_read_4(sc->sc_iot, sc->sc_hreg, offset);
171 }
172
173 static inline uint8_t
174 hyperfb_read1(struct hyperfb_softc *sc, uint32_t offset)
175 {
176 return bus_space_read_1(sc->sc_iot, sc->sc_hreg, offset);
177 }
178
179 static inline void
180 hyperfb_write4(struct hyperfb_softc *sc, uint32_t offset, uint32_t val)
181 {
182 bus_space_write_4(sc->sc_iot, sc->sc_hreg, offset, val);
183 }
184
185 static inline void
186 hyperfb_write1(struct hyperfb_softc *sc, uint32_t offset, uint8_t val)
187 {
188 bus_space_write_1(sc->sc_iot, sc->sc_hreg, offset, val);
189 }
190
191 static inline void
192 hyperfb_wait(struct hyperfb_softc *sc)
193 {
194 uint8_t stat;
195
196 do {
197 stat = hyperfb_read1(sc, NGLE_REG_15b0);
198 if (stat == 0)
199 stat = hyperfb_read1(sc, NGLE_REG_15b0);
200 } while (stat != 0);
201 }
202
203 static inline void
204 hyperfb_wait_fifo(struct hyperfb_softc *sc, uint32_t slots)
205 {
206 uint32_t reg;
207
208 do {
209 reg = hyperfb_read4(sc, NGLE_REG_34);
210 } while (reg < slots);
211 }
212
213 static inline void
214 hyperfb_setup_fb(struct hyperfb_softc *sc)
215 {
216
217 /*
218 * turns out the plane mask is applied to everything, including
219 * direct framebuffer writes, so make sure we always set it
220 */
221 hyperfb_wait(sc);
222 if ((sc->sc_mode != WSDISPLAYIO_MODE_EMUL) && sc->sc_24bit) {
223 hyperfb_write4(sc, NGLE_REG_10, 0xBBA0A000); /* 24bit */
224 hyperfb_write4(sc, NGLE_REG_13, 0xffffffff);
225 } else {
226 hyperfb_write4(sc, NGLE_REG_10, 0x13602000); /* 8bit */
227 hyperfb_write4(sc, NGLE_REG_13, 0xff);
228 }
229 hyperfb_write4(sc, NGLE_REG_14, 0x83000300);
230 hyperfb_wait(sc);
231 hyperfb_write1(sc, NGLE_REG_16b1, 1);
232 sc->sc_hwmode = HW_FB;
233 }
234
235 static inline void
236 hyperfb_setup_fb24(struct hyperfb_softc *sc)
237 {
238
239 hyperfb_wait(sc);
240 hyperfb_write4(sc, NGLE_REG_10, 0xBBA0A000); /* 24bit */
241 hyperfb_write4(sc, NGLE_REG_13, 0xffffffff);
242 hyperfb_write4(sc, NGLE_REG_14, 0x83000300);
243 //IBOvals(RopSrc,0,BitmapExtent08,0,DataDynamic,MaskDynamic,0,0)
244 hyperfb_wait(sc);
245 hyperfb_write1(sc, NGLE_REG_16b1, 1);
246 sc->sc_hwmode = HW_FB;
247 }
248
249 int
250 hyperfb_match(device_t parent, cfdata_t cf, void *aux)
251 {
252 struct confargs *ca = aux;
253 bus_space_handle_t romh;
254 paddr_t rom;
255 uint32_t id = 0;
256 u_char devtype;
257 int rv = 0, romunmapped = 0;
258
259 if (ca->ca_type.iodc_type != HPPA_TYPE_FIO)
260 return 0;
261
262 /* these need further checking for the graphics id */
263 if (ca->ca_type.iodc_sv_model != HPPA_FIO_GSGC &&
264 ca->ca_type.iodc_sv_model != HPPA_FIO_SGC)
265 return 0;
266
267 if (ca->ca_naddrs > 0)
268 rom = ca->ca_addrs[0].addr;
269 else
270 rom = ca->ca_hpa;
271
272 DPRINTF("%s: hpa=%x, rom=%x\n", __func__, (uint)ca->ca_hpa,
273 (uint)rom);
274
275 /* if it does not map, probably part of the lasi space */
276 if (bus_space_map(ca->ca_iot, rom, STI_ROMSIZE, 0, &romh)) {
277 DPRINTF("%s: can't map rom space (%d)\n", __func__, rv);
278
279 if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN) {
280 romh = rom;
281 romunmapped++;
282 } else {
283 /* in this case nobody has no freaking idea */
284 return 0;
285 }
286 }
287
288 devtype = bus_space_read_1(ca->ca_iot, romh, 3);
289 DPRINTF("%s: devtype=%d\n", __func__, devtype);
290 rv = 1;
291 switch (devtype) {
292 case STI_DEVTYPE4:
293 id = bus_space_read_4(ca->ca_iot, romh, STI_DEV4_DD_GRID);
294 break;
295 case STI_DEVTYPE1:
296 id = (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID
297 + 3) << 24) |
298 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID
299 + 7) << 16) |
300 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID
301 + 11) << 8) |
302 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID
303 + 15));
304 break;
305 default:
306 DPRINTF("%s: unknown type (%x)\n", __func__, devtype);
307 rv = 0;
308 }
309
310 if (id == STI_DD_HCRX)
311 rv = 100; /* beat out sti */
312
313 ca->ca_addrs[ca->ca_naddrs].addr = rom;
314 ca->ca_addrs[ca->ca_naddrs].size = sti_rom_size(ca->ca_iot, romh);
315 ca->ca_naddrs++;
316
317 if (!romunmapped)
318 bus_space_unmap(ca->ca_iot, romh, STI_ROMSIZE);
319 return rv;
320 }
321
322 void
323 hyperfb_attach(device_t parent, device_t self, void *aux)
324 {
325 struct hyperfb_softc *sc = device_private(self);
326 struct confargs *ca = aux;
327 struct rasops_info *ri;
328 struct wsemuldisplaydev_attach_args aa;
329 bus_space_handle_t hrom;
330 hppa_hpa_t consaddr;
331 long defattr;
332 int pagezero_cookie;
333 paddr_t rom;
334 uint32_t config;
335
336 pagezero_cookie = hppa_pagezero_map();
337 consaddr = (hppa_hpa_t)PAGE0->mem_cons.pz_hpa;
338 hppa_pagezero_unmap(pagezero_cookie);
339
340 sc->sc_dev = self;
341 sc->sc_base = ca->ca_hpa;
342 sc->sc_iot = ca->ca_iot;
343 sc->sc_is_console =(ca->ca_hpa == consaddr);
344 sc->sc_width = 1280;
345 sc->sc_height = 1024;
346
347 /* we can *not* be interrupted when doing colour map accesses */
348 mutex_init(&sc->sc_hwlock, MUTEX_DEFAULT, IPL_HIGH);
349
350 /* we stashed rom addr/len into the last slot during probe */
351 rom = ca->ca_addrs[ca->ca_naddrs - 1].addr;
352
353 if (bus_space_map(sc->sc_iot,
354 sc->sc_base + HCRX_FBOFFSET, HCRX_FBLEN,
355 BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE,
356 &sc->sc_hfb)) {
357 aprint_error_dev(sc->sc_dev,
358 "failed to map the framebuffer\n");
359 return;
360 }
361 sc->sc_fb = bus_space_vaddr(sc->sc_iot, sc->sc_hfb);
362
363 if (bus_space_map(sc->sc_iot,
364 sc->sc_base + HCRX_REGOFFSET, HCRX_REGLEN, 0, &sc->sc_hreg)) {
365 aprint_error_dev(sc->sc_dev, "failed to map registers\n");
366 return;
367 }
368
369 /*
370 * we really only need the first word so we can grab the config bits
371 * between the bytes
372 */
373 if (bus_space_map(sc->sc_iot, rom, 4, 0, &hrom)) {
374 aprint_error_dev(sc->sc_dev,
375 "failed to map ROM, assuming 8bit\n");
376 config = 0;
377 } else {
378 /* alright, we got the ROM. now do the idle dance. */
379 volatile uint32_t r = hyperfb_read4(sc, NGLE_REG_15);
380 __USE(r);
381 hyperfb_wait(sc);
382 config = bus_space_read_4(sc->sc_iot, hrom, 0);
383 bus_space_unmap(sc->sc_iot, hrom, 4);
384 }
385 sc->sc_24bit = ((config & HCRX_CONFIG_24BIT) != 0);
386
387 printf(" %s\n", sc->sc_24bit ? "HCRX24" : "HCRX");
388 #ifdef HP7300LC_CPU
389 /*
390 * PCXL2: enable accel I/O for this space, see PCX-L2 ERS "ACCEL_IO".
391 * "pcxl2_ers.{ps,pdf}", (section / chapter . rel. page / abs. page)
392 * 8.7.4 / 8-12 / 92, 11.3.14 / 11-14 / 122 and 14.8 / 14-5 / 203.
393 */
394 if (hppa_cpu_info->hci_cputype == hpcxl2
395 && ca->ca_hpa >= PCXL2_ACCEL_IO_START
396 && ca->ca_hpa <= PCXL2_ACCEL_IO_END)
397 eaio_l2(PCXL2_ACCEL_IO_ADDR2MASK(ca->ca_hpa));
398 #endif /* HP7300LC_CPU */
399
400 sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
401 sc->sc_locked = 0;
402
403 hyperfb_setup(sc);
404 hyperfb_setup_fb(sc);
405
406 sc->sc_defaultscreen_descr = (struct wsscreen_descr){
407 "default",
408 0, 0,
409 NULL,
410 8, 16,
411 WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_UNDERLINE |
412 WSSCREEN_RESIZE,
413 NULL
414 };
415
416 sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
417 sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
418
419 vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
420 &hyperfb_accessops);
421 sc->vd.init_screen = hyperfb_init_screen;
422 sc->vd.show_screen_cookie = &sc->sc_gc;
423 sc->vd.show_screen_cb = glyphcache_adapt;
424
425 ri = &sc->sc_console_screen.scr_ri;
426
427 //sc->sc_gc.gc_bitblt = hyperfb_bitblt;
428 //sc->sc_gc.gc_blitcookie = sc;
429 //sc->sc_gc.gc_rop = RopSrc;
430
431 if (sc->sc_is_console) {
432 vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
433 &defattr);
434 sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
435
436 sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
437 sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
438 sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
439 sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
440
441 #if 0
442 glyphcache_init(&sc->sc_gc, sc->sc_height + 5,
443 sc->sc_scr.fbheight - sc->sc_height - 5,
444 sc->sc_scr.fbwidth,
445 ri->ri_font->fontwidth,
446 ri->ri_font->fontheight,
447 defattr);
448 #endif
449 wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
450 defattr);
451
452 hyperfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
453 ri->ri_devcmap[(defattr >> 16) & 0xff]);
454
455 vcons_replay_msgbuf(&sc->sc_console_screen);
456 } else {
457 /*
458 * since we're not the console we can postpone the rest
459 * until someone actually allocates a screen for us
460 */
461 if (sc->sc_console_screen.scr_ri.ri_rows == 0) {
462 /* do some minimal setup to avoid weirdnesses later */
463 vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
464 &defattr);
465 } else
466 (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
467
468 #if 0
469 glyphcache_init(&sc->sc_gc, sc->sc_height + 5,
470 sc->sc_scr.fbheight - sc->sc_height - 5,
471 sc->sc_scr.fbwidth,
472 ri->ri_font->fontwidth,
473 ri->ri_font->fontheight,
474 defattr);
475 #endif
476 }
477
478 hyperfb_restore_palette(sc);
479
480 /* no suspend/resume support yet */
481 if (!pmf_device_register(sc->sc_dev, NULL, NULL))
482 aprint_error_dev(sc->sc_dev,
483 "couldn't establish power handler\n");
484
485 aa.console = sc->sc_is_console;
486 aa.scrdata = &sc->sc_screenlist;
487 aa.accessops = &hyperfb_accessops;
488 aa.accesscookie = &sc->vd;
489
490 config_found(sc->sc_dev, &aa, wsemuldisplaydevprint, CFARGS_NONE);
491
492 hyperfb_setup_fb(sc);
493 }
494
495 static void
496 hyperfb_init_screen(void *cookie, struct vcons_screen *scr,
497 int existing, long *defattr)
498 {
499 struct hyperfb_softc *sc = cookie;
500 struct rasops_info *ri = &scr->scr_ri;
501
502 ri->ri_depth = 8;
503 ri->ri_width = 1280;
504 ri->ri_height = 1024;
505 ri->ri_stride = 2048;
506 ri->ri_flg = RI_CENTER | RI_8BIT_IS_RGB /*|
507 RI_ENABLE_ALPHA | RI_PREFER_ALPHA*/;
508
509 ri->ri_bits = (void *)sc->sc_fb;
510 rasops_init(ri, 0, 0);
511 ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_UNDERLINE |
512 WSSCREEN_RESIZE;
513 scr->scr_flags |= VCONS_LOADFONT;
514
515 rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
516 sc->sc_width / ri->ri_font->fontwidth);
517
518 ri->ri_hw = scr;
519
520 sc->sc_putchar = ri->ri_ops.putchar;
521 ri->ri_ops.copyrows = hyperfb_copyrows;
522 ri->ri_ops.copycols = hyperfb_copycols;
523 ri->ri_ops.eraserows = hyperfb_eraserows;
524 ri->ri_ops.erasecols = hyperfb_erasecols;
525 ri->ri_ops.cursor = hyperfb_cursor;
526 ri->ri_ops.putchar = hyperfb_putchar;
527 }
528
529 static int
530 hyperfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
531 struct lwp *l)
532 {
533 struct vcons_data *vd = v;
534 struct hyperfb_softc *sc = vd->cookie;
535 struct wsdisplay_fbinfo *wdf;
536 struct vcons_screen *ms = vd->active;
537
538 switch (cmd) {
539 case WSDISPLAYIO_GTYPE:
540 *(u_int *)data = WSDISPLAY_TYPE_STI;
541 return 0;
542
543 case WSDISPLAYIO_GINFO:
544 if (ms == NULL)
545 return ENODEV;
546 wdf = (void *)data;
547 wdf->height = ms->scr_ri.ri_height;
548 wdf->width = sc->sc_24bit ? ms->scr_ri.ri_width << 2
549 : ms->scr_ri.ri_width;
550 wdf->depth = ms->scr_ri.ri_depth;
551 wdf->cmsize = 256;
552 return 0;
553
554 case WSDISPLAYIO_GETCMAP:
555 return hyperfb_getcmap(sc,
556 (struct wsdisplay_cmap *)data);
557
558 case WSDISPLAYIO_PUTCMAP:
559 return hyperfb_putcmap(sc,
560 (struct wsdisplay_cmap *)data);
561 case WSDISPLAYIO_LINEBYTES:
562 *(u_int *)data = sc->sc_24bit ? 8192 : 2048;
563 return 0;
564
565 case WSDISPLAYIO_SMODE: {
566 int new_mode = *(int*)data;
567 if (new_mode != sc->sc_mode) {
568 sc->sc_mode = new_mode;
569 if (new_mode == WSDISPLAYIO_MODE_EMUL) {
570 hyperfb_setup(sc);
571 hyperfb_restore_palette(sc);
572 #if 0
573 glyphcache_wipe(&sc->sc_gc);
574 #endif
575 hyperfb_rectfill(sc, 0, 0, sc->sc_width,
576 sc->sc_height, ms->scr_ri.ri_devcmap[
577 (ms->scr_defattr >> 16) & 0xff]);
578 vcons_redraw_screen(ms);
579 hyperfb_set_video(sc, 1);
580 } else {
581 hyperfb_setup(sc);
582 hyperfb_rectfill(sc, 0, 0, sc->sc_width,
583 sc->sc_height, 0xff);
584 hyperfb_setup_fb24(sc);
585 }
586 }
587 }
588 return 0;
589
590 case WSDISPLAYIO_GET_FBINFO: {
591 struct wsdisplayio_fbinfo *fbi = data;
592 int ret;
593
594 ret = wsdisplayio_get_fbinfo(&ms->scr_ri, fbi);
595 fbi->fbi_fbsize = sc->sc_height * 2048;
596 if (sc->sc_24bit) {
597 fbi->fbi_stride = 8192;
598 fbi->fbi_bitsperpixel = 32;
599 fbi->fbi_pixeltype = WSFB_RGB;
600 fbi->fbi_subtype.fbi_rgbmasks.red_offset = 16;
601 fbi->fbi_subtype.fbi_rgbmasks.red_size = 8;
602 fbi->fbi_subtype.fbi_rgbmasks.green_offset = 8;
603 fbi->fbi_subtype.fbi_rgbmasks.green_size = 8;
604 fbi->fbi_subtype.fbi_rgbmasks.blue_offset = 0;
605 fbi->fbi_subtype.fbi_rgbmasks.blue_size = 8;
606 fbi->fbi_subtype.fbi_rgbmasks.alpha_size = 0;
607 fbi->fbi_fbsize = sc->sc_height * 8192;
608 }
609 return ret;
610 }
611
612 case WSDISPLAYIO_GCURPOS: {
613 struct wsdisplay_curpos *cp = (void *)data;
614
615 cp->x = sc->sc_cursor_x;
616 cp->y = sc->sc_cursor_y;
617 }
618 return 0;
619
620 case WSDISPLAYIO_SCURPOS: {
621 struct wsdisplay_curpos *cp = (void *)data;
622
623 hyperfb_move_cursor(sc, cp->x, cp->y);
624 }
625 return 0;
626
627 case WSDISPLAYIO_GCURMAX: {
628 struct wsdisplay_curpos *cp = (void *)data;
629
630 cp->x = 64;
631 cp->y = 64;
632 }
633 return 0;
634
635 case WSDISPLAYIO_SCURSOR: {
636 struct wsdisplay_cursor *cursor = (void *)data;
637
638 return hyperfb_do_cursor(sc, cursor);
639 }
640
641 case WSDISPLAYIO_SVIDEO:
642 hyperfb_set_video(sc, *(int *)data);
643 return 0;
644 case WSDISPLAYIO_GVIDEO:
645 return sc->sc_video_on ?
646 WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF;
647 }
648 return EPASSTHROUGH;
649 }
650
651 static paddr_t
652 hyperfb_mmap(void *v, void *vs, off_t offset, int prot)
653 {
654 struct vcons_data *vd = v;
655 struct hyperfb_softc *sc = vd->cookie;
656 paddr_t pa = -1;
657
658
659 if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)
660 return -1;
661
662 if (offset >= 0 || offset < 2048 * 1024) {
663 /* framebuffer */
664 pa = bus_space_mmap(sc->sc_iot, sc->sc_base + HCRX_FBOFFSET,
665 offset, prot,
666 BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE);
667 } else if (offset >= 0x80000000 && offset < 0x8040000) {
668 /* blitter registers etc. */
669 pa = bus_space_mmap(sc->sc_iot, sc->sc_base + HCRX_REGOFFSET,
670 offset - 0x80000000, prot, BUS_SPACE_MAP_LINEAR);
671 }
672
673 return pa;
674 }
675
676 static int
677 hyperfb_putcmap(struct hyperfb_softc *sc, struct wsdisplay_cmap *cm)
678 {
679 u_char *r, *g, *b;
680 u_int index = cm->index;
681 u_int count = cm->count;
682 int i, error;
683 u_char rbuf[256], gbuf[256], bbuf[256];
684
685 if (cm->index >= 256 || cm->count > 256 ||
686 (cm->index + cm->count) > 256)
687 return EINVAL;
688 error = copyin(cm->red, &rbuf[index], count);
689 if (error)
690 return error;
691 error = copyin(cm->green, &gbuf[index], count);
692 if (error)
693 return error;
694 error = copyin(cm->blue, &bbuf[index], count);
695 if (error)
696 return error;
697
698 memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
699 memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
700 memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
701
702 r = &sc->sc_cmap_red[index];
703 g = &sc->sc_cmap_green[index];
704 b = &sc->sc_cmap_blue[index];
705
706 for (i = 0; i < count; i++) {
707 hyperfb_putpalreg(sc, index, *r, *g, *b);
708 index++;
709 r++, g++, b++;
710 }
711 return 0;
712 }
713
714 static int
715 hyperfb_getcmap(struct hyperfb_softc *sc, struct wsdisplay_cmap *cm)
716 {
717 u_int index = cm->index;
718 u_int count = cm->count;
719 int error;
720
721 if (index >= 255 || count > 256 || index + count > 256)
722 return EINVAL;
723
724 error = copyout(&sc->sc_cmap_red[index], cm->red, count);
725 if (error)
726 return error;
727 error = copyout(&sc->sc_cmap_green[index], cm->green, count);
728 if (error)
729 return error;
730 error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
731 if (error)
732 return error;
733
734 return 0;
735 }
736
737 static void
738 hyperfb_restore_palette(struct hyperfb_softc *sc)
739 {
740 uint8_t cmap[768];
741 int i, j;
742
743 j = 0;
744 rasops_get_cmap(&sc->sc_console_screen.scr_ri, cmap, sizeof(cmap));
745 for (i = 0; i < 256; i++) {
746 sc->sc_cmap_red[i] = cmap[j];
747 sc->sc_cmap_green[i] = cmap[j + 1];
748 sc->sc_cmap_blue[i] = cmap[j + 2];
749 hyperfb_putpalreg(sc, i, cmap[j], cmap[j + 1], cmap[j + 2]);
750 j += 3;
751 }
752 }
753
754 static int
755 hyperfb_putpalreg(struct hyperfb_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
756 uint8_t b)
757 {
758
759 mutex_enter(&sc->sc_hwlock);
760 hyperfb_wait(sc);
761 hyperfb_write4(sc, NGLE_REG_10, 0xbbe0f000);
762 hyperfb_write4(sc, NGLE_REG_14, 0x03000300);
763 hyperfb_write4(sc, NGLE_REG_13, 0xffffffff);
764
765 hyperfb_wait(sc);
766 hyperfb_write4(sc, NGLE_REG_3, 0x400 | (idx << 2));
767 hyperfb_write4(sc, NGLE_REG_4, (r << 16) | (g << 8) | b);
768
769 hyperfb_write4(sc, NGLE_REG_2, 0x400);
770 hyperfb_write4(sc, NGLE_REG_38, 0x82000100);
771 hyperfb_setup_fb(sc);
772 mutex_exit(&sc->sc_hwlock);
773 return 0;
774 }
775
776 void
777 hyperfb_setup(struct hyperfb_softc *sc)
778 {
779 int i;
780 uint32_t reg;
781
782 sc->sc_hwmode = HW_FB;
783 sc->sc_hot_x = 0;
784 sc->sc_hot_y = 0;
785 sc->sc_enabled = 0;
786 sc->sc_video_on = 1;
787
788 /* set Bt458 read mask register to all planes */
789 /* XXX I'm not sure HCRX even has one of these */
790 hyperfb_wait(sc);
791 ngle_bt458_write(sc, 0x08, 0x04);
792 ngle_bt458_write(sc, 0x0a, 0xff);
793
794 reg = hyperfb_read4(sc, NGLE_REG_32);
795 DPRINTF("planereg %08x\n", reg);
796 hyperfb_write4(sc, NGLE_REG_32, 0xffffffff);
797
798 /* hyperbowl */
799 hyperfb_wait(sc);
800 if (sc->sc_24bit) {
801 /* write must happen twice because hw bug */
802 hyperfb_write4(sc, NGLE_REG_40,
803 HYPERBOWL_MODE01_8_24_LUT0_TRANSPARENT_LUT1_OPAQUE);
804 hyperfb_write4(sc, NGLE_REG_40,
805 HYPERBOWL_MODE01_8_24_LUT0_TRANSPARENT_LUT1_OPAQUE);
806 hyperfb_write4(sc, NGLE_REG_39, HYPERBOWL_MODE2_8_24);
807 /* Set lut 0 to be the direct color */
808 hyperfb_write4(sc, NGLE_REG_42, 0x014c0148);
809 hyperfb_write4(sc, NGLE_REG_43, 0x404c4048);
810 hyperfb_write4(sc, NGLE_REG_44, 0x034c0348);
811 hyperfb_write4(sc, NGLE_REG_45, 0x444c4448);
812 } else {
813 hyperfb_write4(sc, NGLE_REG_40,
814 HYPERBOWL_MODE_FOR_8_OVER_88_LUT0_NO_TRANSPARENCIES);
815 hyperfb_write4(sc, NGLE_REG_40,
816 HYPERBOWL_MODE_FOR_8_OVER_88_LUT0_NO_TRANSPARENCIES);
817
818 hyperfb_write4(sc, NGLE_REG_42, 0);
819 hyperfb_write4(sc, NGLE_REG_43, 0);
820 hyperfb_write4(sc, NGLE_REG_44, 0);
821 hyperfb_write4(sc, NGLE_REG_45, 0x444c4048);
822 }
823
824 /* attr. planes */
825 hyperfb_wait(sc);
826 hyperfb_write4(sc, NGLE_REG_11,
827 BA(IndexedDcd, Otc32, OtsIndirect, AddrLong, 0, BINattr, 0));
828 hyperfb_write4(sc, NGLE_REG_14,
829 IBOvals(RopSrc, 0, BitmapExtent08, 1, DataDynamic, MaskOtc, 1, 0));
830 hyperfb_write4(sc, NGLE_REG_12, 0x04000F00/*NGLE_BUFF0_CMAP0*/);
831 hyperfb_write4(sc, NGLE_REG_8, 0xffffffff);
832
833 hyperfb_wait(sc);
834 hyperfb_write4(sc, NGLE_REG_6, 0x00000000);
835 hyperfb_write4(sc, NGLE_REG_9,
836 (sc->sc_width << 16) | sc->sc_height);
837 /*
838 * blit into offscreen memory to force flush previous - apparently
839 * some chips have a bug this works around
840 */
841 hyperfb_wait(sc);
842 hyperfb_write4(sc, NGLE_REG_6, 0x05000000);
843 hyperfb_write4(sc, NGLE_REG_9, 0x00040001);
844
845 /*
846 * on 24bit-capable hardware we:
847 * - make overlay colour 255 transparent
848 * - blit the 24bit buffer all white
849 * - install a linear ramp in CMAP 0
850 */
851 if (sc->sc_24bit) {
852 /* overlay transparency */
853 hyperfb_wait_fifo(sc, 7);
854 hyperfb_write4(sc, NGLE_REG_11, 0x13a02000);
855 hyperfb_write4(sc, NGLE_REG_14, 0x03000300);
856 hyperfb_write4(sc, NGLE_REG_3, 0x000017f0);
857 hyperfb_write4(sc, NGLE_REG_13, 0xffffffff);
858 hyperfb_write4(sc, NGLE_REG_22, 0xffffffff);
859 hyperfb_write4(sc, NGLE_REG_23, 0x0);
860
861 hyperfb_wait(sc);
862 hyperfb_write4(sc, NGLE_REG_12, 0x00000000);
863
864 /* clear 24bit buffer */
865 hyperfb_wait(sc);
866 /* plane mask */
867 hyperfb_write4(sc, NGLE_REG_13, 0xffffffff);
868 hyperfb_write4(sc, NGLE_REG_8, 0xffffffff); /* transfer data */
869 /* bitmap op */
870 hyperfb_write4(sc, NGLE_REG_14,
871 IBOvals(RopSrc, 0, BitmapExtent32, 0, DataDynamic, MaskOtc,
872 0, 0));
873 /* dst bitmap access */
874 hyperfb_write4(sc, NGLE_REG_11,
875 BA(IndexedDcd, Otc32, OtsIndirect, AddrLong, 0, BINapp0F8,
876 0));
877 hyperfb_wait_fifo(sc, 3);
878 hyperfb_write4(sc, NGLE_REG_35, 0x00ffffff); /* fg colour */
879 hyperfb_write4(sc, NGLE_REG_6, 0x00000000); /* dst xy */
880 hyperfb_write4(sc, NGLE_REG_9,
881 (sc->sc_width << 16) | sc->sc_height);
882
883 /* write a linear ramp into CMAP0 */
884 hyperfb_wait(sc);
885 hyperfb_write4(sc, NGLE_REG_10, 0xbbe0f000);
886 hyperfb_write4(sc, NGLE_REG_14, 0x03000300);
887 hyperfb_write4(sc, NGLE_REG_13, 0xffffffff);
888
889 hyperfb_wait(sc);
890 hyperfb_write4(sc, NGLE_REG_3, 0);
891 for (i = 0; i < 256; i++) {
892 hyperfb_wait(sc);
893 hyperfb_write4(sc, NGLE_REG_4,
894 (i << 16) | (i << 8) | i);
895 }
896 hyperfb_write4(sc, NGLE_REG_2, 0x0);
897 hyperfb_write4(sc, NGLE_REG_38,
898 LBC_ENABLE | LBC_TYPE_CMAP | 0x100);
899 hyperfb_wait(sc);
900 }
901
902 hyperfb_setup_fb(sc);
903
904 /* make sure video output is enabled */
905 hyperfb_wait(sc);
906 hyperfb_write4(sc, NGLE_REG_33,
907 hyperfb_read4(sc, NGLE_REG_33) | 0x0a000000);
908
909 /* cursor mask */
910 hyperfb_wait(sc);
911 hyperfb_write4(sc, NGLE_REG_30, 0);
912 for (i = 0; i < 64; i++) {
913 hyperfb_write4(sc, NGLE_REG_31, 0xffffffff);
914 hyperfb_write4(sc, NGLE_REG_31, 0xffffffff);
915 }
916
917 /* cursor image */
918 hyperfb_wait(sc);
919 hyperfb_write4(sc, NGLE_REG_30, 0x80);
920 for (i = 0; i < 64; i++) {
921 hyperfb_write4(sc, NGLE_REG_31, 0xff00ff00);
922 hyperfb_write4(sc, NGLE_REG_31, 0xff00ff00);
923 }
924
925 /* colour map */
926 hyperfb_wait(sc);
927 hyperfb_write4(sc, NGLE_REG_10, 0xBBE0F000);
928 hyperfb_write4(sc, NGLE_REG_14, 0x03000300);
929 hyperfb_write4(sc, NGLE_REG_13, 0xffffffff);
930 hyperfb_wait(sc);
931 hyperfb_write4(sc, NGLE_REG_3, 0);
932 hyperfb_write4(sc, NGLE_REG_4, 0x000000ff); /* BG */
933 hyperfb_write4(sc, NGLE_REG_4, 0x00ff0000); /* FG */
934 hyperfb_wait(sc);
935 hyperfb_write4(sc, NGLE_REG_2, 0);
936 hyperfb_write4(sc, NGLE_REG_38, LBC_ENABLE | LBC_TYPE_CURSOR | 4);
937 hyperfb_setup_fb(sc);
938
939 hyperfb_move_cursor(sc, 100, 100);
940 }
941
942 static void
943 hyperfb_set_video(struct hyperfb_softc *sc, int on)
944 {
945 uint32_t reg;
946
947 if (sc->sc_video_on == on)
948 return;
949
950 sc->sc_video_on = on;
951
952 hyperfb_wait(sc);
953 reg = hyperfb_read4(sc, NGLE_REG_33);
954
955 if (on) {
956 hyperfb_write4(sc, NGLE_REG_33, reg | HCRX_VIDEO_ENABLE);
957 } else {
958 hyperfb_write4(sc, NGLE_REG_33, reg & ~HCRX_VIDEO_ENABLE);
959 }
960 }
961
962 static void
963 hyperfb_rectfill(struct hyperfb_softc *sc, int x, int y, int wi, int he,
964 uint32_t bg)
965 {
966 /*
967 * XXX
968 * HCRX has the same problem as VisEG drawing rectangles less than 32
969 * pixels wide, but here we don't seem to have any usable offscreen
970 * memory, at least not as long as we're using the overlay planes.
971 * As a workaround, fall back to memset()-based fills for rectangles
972 * less than 32 pixels wide
973 */
974 if (wi < 32) {
975 #if 0
976 int i;
977 uint8_t *ptr = (uint8_t *)sc->sc_fb + (y << 11) + x;
978
979 if (sc->sc_hwmode != HW_FB)
980 hyperfb_setup_fb(sc);
981
982 for (i = 0; i < he; i++) {
983 memset(ptr, bg, wi);
984 ptr += 2048;
985 }
986 #else
987 /*
988 * instead of memset() we abuse the blitter - set / clear the
989 * planes we want, select colour by planemask, do two passes
990 * where necessary ( as in, anything not black or white )
991 */
992 if (sc->sc_hwmode != HW_SFILL) {
993 hyperfb_wait(sc);
994 hyperfb_write4(sc, NGLE_REG_10, 0x13a02000);
995 sc->sc_hwmode = HW_SFILL;
996 }
997 bg &= 0xff;
998 hyperfb_wait_fifo(sc, 2);
999 hyperfb_write4(sc, NGLE_REG_24, (x << 16) | y);
1000 if (bg != 0) {
1001 hyperfb_wait_fifo(sc, 4);
1002 hyperfb_write4(sc, NGLE_REG_14,
1003 IBOvals(RopSet, 0, BitmapExtent08, 1, DataDynamic,
1004 MaskOtc, 0, 0));
1005 hyperfb_write4(sc, NGLE_REG_13, bg);
1006 hyperfb_write4(sc, NGLE_REG_7, (wi << 16) | he);
1007 hyperfb_write4(sc, NGLE_REG_25, (x << 16) | y);
1008 }
1009 if (bg != 0xff) {
1010 hyperfb_wait_fifo(sc, 4);
1011 hyperfb_write4(sc, NGLE_REG_14,
1012 IBOvals(RopClr, 0, BitmapExtent08, 1, DataDynamic,
1013 MaskOtc, 0, 0));
1014 hyperfb_write4(sc, NGLE_REG_13, bg ^ 0xff);
1015 hyperfb_write4(sc, NGLE_REG_7, (wi << 16) | he);
1016 hyperfb_write4(sc, NGLE_REG_25, (x << 16) | y);
1017 }
1018 #endif
1019 return;
1020 }
1021 if (sc->sc_hwmode != HW_FILL) {
1022 hyperfb_wait_fifo(sc, 4);
1023 /* transfer data */
1024 hyperfb_write4(sc, NGLE_REG_8, 0xffffffff);
1025 /* plane mask */
1026 hyperfb_write4(sc, NGLE_REG_13, 0xff);
1027 /* bitmap op */
1028 hyperfb_write4(sc, NGLE_REG_14,
1029 IBOvals(RopSrc, 0, BitmapExtent08, 0, DataDynamic, MaskOtc,
1030 0, 0));
1031 /* dst bitmap access */
1032 hyperfb_write4(sc, NGLE_REG_11,
1033 BA(IndexedDcd, Otc32, OtsIndirect, AddrLong, 0, BINovly,
1034 0));
1035 sc->sc_hwmode = HW_FILL;
1036 }
1037 hyperfb_wait_fifo(sc, 3);
1038 hyperfb_write4(sc, NGLE_REG_35, bg);
1039 /* dst XY */
1040 hyperfb_write4(sc, NGLE_REG_6, (x << 16) | y);
1041 /* len XY start */
1042 hyperfb_write4(sc, NGLE_REG_9, (wi << 16) | he);
1043 }
1044
1045 static void
1046 hyperfb_bitblt(void *cookie, int xs, int ys, int xd, int yd, int wi,
1047 int he, int rop)
1048 {
1049 struct hyperfb_softc *sc = cookie;
1050
1051 if (sc->sc_hwmode != HW_BLIT) {
1052 hyperfb_wait(sc);
1053 hyperfb_write4(sc, NGLE_REG_10, 0x13a02000);
1054 hyperfb_write4(sc, NGLE_REG_13, 0xff);
1055 sc->sc_hwmode = HW_BLIT;
1056 }
1057 hyperfb_wait_fifo(sc, 4);
1058 hyperfb_write4(sc, NGLE_REG_14, ((rop << 8) & 0xf00) | 0x23000000);
1059 /* IBOvals(rop, 0, BitmapExtent08, 1, DataDynamic, MaskOtc, 0, 0) */
1060 hyperfb_write4(sc, NGLE_REG_24, (xs << 16) | ys);
1061 hyperfb_write4(sc, NGLE_REG_7, (wi << 16) | he);
1062 hyperfb_write4(sc, NGLE_REG_25, (xd << 16) | yd);
1063 }
1064
1065 static void
1066 hyperfb_nuke_cursor(struct rasops_info *ri)
1067 {
1068 struct vcons_screen *scr = ri->ri_hw;
1069 struct hyperfb_softc *sc = scr->scr_cookie;
1070 int wi, he, x, y;
1071
1072 if (ri->ri_flg & RI_CURSOR) {
1073 wi = ri->ri_font->fontwidth;
1074 he = ri->ri_font->fontheight;
1075 x = ri->ri_ccol * wi + ri->ri_xorigin;
1076 y = ri->ri_crow * he + ri->ri_yorigin;
1077 hyperfb_bitblt(sc, x, y, x, y, wi, he, RopInv);
1078 ri->ri_flg &= ~RI_CURSOR;
1079 }
1080 }
1081
1082 static void
1083 hyperfb_cursor(void *cookie, int on, int row, int col)
1084 {
1085 struct rasops_info *ri = cookie;
1086 struct vcons_screen *scr = ri->ri_hw;
1087 struct hyperfb_softc *sc = scr->scr_cookie;
1088 int x, y, wi, he;
1089
1090 wi = ri->ri_font->fontwidth;
1091 he = ri->ri_font->fontheight;
1092
1093 if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
1094 if (on) {
1095 if (ri->ri_flg & RI_CURSOR) {
1096 hyperfb_nuke_cursor(ri);
1097 }
1098 x = col * wi + ri->ri_xorigin;
1099 y = row * he + ri->ri_yorigin;
1100 hyperfb_bitblt(sc, x, y, x, y, wi, he, RopInv);
1101 ri->ri_flg |= RI_CURSOR;
1102 }
1103 ri->ri_crow = row;
1104 ri->ri_ccol = col;
1105 } else {
1106 ri->ri_crow = row;
1107 ri->ri_ccol = col;
1108 ri->ri_flg &= ~RI_CURSOR;
1109 }
1110 }
1111
1112 static void
1113 hyperfb_putchar(void *cookie, int row, int col, u_int c, long attr)
1114 {
1115 struct rasops_info *ri = cookie;
1116 struct wsdisplay_font *font = PICK_FONT(ri, c);
1117 struct vcons_screen *scr = ri->ri_hw;
1118 struct hyperfb_softc *sc = scr->scr_cookie;
1119 int x, y, wi, he/*, rv = GC_NOPE*/;
1120 uint32_t bg;
1121
1122 if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL)
1123 return;
1124
1125 if (!CHAR_IN_FONT(c, font))
1126 return;
1127
1128 if (row == ri->ri_crow && col == ri->ri_ccol) {
1129 ri->ri_flg &= ~RI_CURSOR;
1130 }
1131
1132 wi = font->fontwidth;
1133 he = font->fontheight;
1134
1135 x = ri->ri_xorigin + col * wi;
1136 y = ri->ri_yorigin + row * he;
1137
1138 bg = ri->ri_devcmap[(attr >> 16) & 0xf];
1139
1140 if (c == 0x20) {
1141 hyperfb_rectfill(sc, x, y, wi, he, bg);
1142 return;
1143 }
1144
1145 #if 0
1146 rv = glyphcache_try(&sc->sc_gc, c, x, y, attr);
1147 if (rv == GC_OK)
1148 return;
1149 #endif
1150 if (sc->sc_hwmode != HW_FB) hyperfb_setup_fb(sc);
1151 sc->sc_putchar(cookie, row, col, c, attr);
1152 #if 0
1153 if (rv == GC_ADD)
1154 glyphcache_add(&sc->sc_gc, c, x, y);
1155 #endif
1156 }
1157
1158 static void
1159 hyperfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
1160 {
1161 struct rasops_info *ri = cookie;
1162 struct vcons_screen *scr = ri->ri_hw;
1163 struct hyperfb_softc *sc = scr->scr_cookie;
1164 int32_t xs, xd, y, width, height;
1165
1166 if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
1167 if (ri->ri_crow == row &&
1168 (ri->ri_ccol >= srccol && ri->ri_ccol < (srccol + ncols)) &&
1169 (ri->ri_flg & RI_CURSOR)) {
1170 hyperfb_nuke_cursor(ri);
1171 }
1172
1173 xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
1174 xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
1175 y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1176 width = ri->ri_font->fontwidth * ncols;
1177 height = ri->ri_font->fontheight;
1178 hyperfb_bitblt(sc, xs, y, xd, y, width, height, RopSrc);
1179 if (ri->ri_crow == row &&
1180 (ri->ri_ccol >= dstcol && ri->ri_ccol < (dstcol + ncols)))
1181 ri->ri_flg &= ~RI_CURSOR;
1182 }
1183 }
1184
1185 static void
1186 hyperfb_erasecols(void *cookie, int row, int startcol, int ncols,
1187 long fillattr)
1188 {
1189 struct rasops_info *ri = cookie;
1190 struct vcons_screen *scr = ri->ri_hw;
1191 struct hyperfb_softc *sc = scr->scr_cookie;
1192 int32_t x, y, width, height, fg, bg, ul;
1193
1194 if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
1195 x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
1196 y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1197 width = ri->ri_font->fontwidth * ncols;
1198 height = ri->ri_font->fontheight;
1199 rasops_unpack_attr(fillattr, &fg, &bg, &ul);
1200
1201 hyperfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
1202 if (ri->ri_crow == row &&
1203 (ri->ri_ccol >= startcol &&
1204 ri->ri_ccol < (startcol + ncols)))
1205 ri->ri_flg &= ~RI_CURSOR;
1206 }
1207 }
1208
1209 static void
1210 hyperfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
1211 {
1212 struct rasops_info *ri = cookie;
1213 struct vcons_screen *scr = ri->ri_hw;
1214 struct hyperfb_softc *sc = scr->scr_cookie;
1215 int32_t x, ys, yd, width, height;
1216
1217 if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
1218 if ((ri->ri_crow >= srcrow &&
1219 ri->ri_crow < (srcrow + nrows)) &&
1220 (ri->ri_flg & RI_CURSOR)) {
1221 hyperfb_nuke_cursor(ri);
1222 }
1223 x = ri->ri_xorigin;
1224 ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
1225 yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
1226 width = ri->ri_emuwidth;
1227 height = ri->ri_font->fontheight * nrows;
1228 hyperfb_bitblt(sc, x, ys, x, yd, width, height, RopSrc);
1229 if (ri->ri_crow >= dstrow && ri->ri_crow < (dstrow + nrows))
1230 ri->ri_flg &= ~RI_CURSOR;
1231 }
1232 }
1233
1234 static void
1235 hyperfb_eraserows(void *cookie, int row, int nrows, long fillattr)
1236 {
1237 struct rasops_info *ri = cookie;
1238 struct vcons_screen *scr = ri->ri_hw;
1239 struct hyperfb_softc *sc = scr->scr_cookie;
1240 int32_t x, y, width, height, fg, bg, ul;
1241
1242 if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
1243 x = ri->ri_xorigin;
1244 y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1245 width = ri->ri_emuwidth;
1246 height = ri->ri_font->fontheight * nrows;
1247 rasops_unpack_attr(fillattr, &fg, &bg, &ul);
1248
1249 hyperfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
1250
1251 if (ri->ri_crow >= row && ri->ri_crow < (row + nrows))
1252 ri->ri_flg &= ~RI_CURSOR;
1253 }
1254 }
1255
1256 static void
1257 hyperfb_move_cursor(struct hyperfb_softc *sc, int x, int y)
1258 {
1259 uint32_t pos;
1260
1261 sc->sc_cursor_x = x;
1262 x -= sc->sc_hot_x;
1263 sc->sc_cursor_y = y;
1264 y -= sc->sc_hot_y;
1265
1266 if (x < 0) x = 0x1000 - x;
1267 if (y < 0) y = 0x1000 - y;
1268 pos = (x << 16) | y;
1269 if (sc->sc_enabled) pos |= HCRX_ENABLE_CURSOR;
1270 hyperfb_wait(sc);
1271 hyperfb_write4(sc, NGLE_REG_29, pos);
1272 }
1273
1274 static int
1275 hyperfb_do_cursor(struct hyperfb_softc *sc, struct wsdisplay_cursor *cur)
1276 {
1277
1278 if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
1279
1280 sc->sc_enabled = cur->enable;
1281 cur->which |= WSDISPLAY_CURSOR_DOPOS;
1282 }
1283 if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
1284
1285 sc->sc_hot_x = cur->hot.x;
1286 sc->sc_hot_y = cur->hot.y;
1287 cur->which |= WSDISPLAY_CURSOR_DOPOS;
1288 }
1289 if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
1290
1291 hyperfb_move_cursor(sc, cur->pos.x, cur->pos.y);
1292 }
1293 if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
1294 uint32_t rgb;
1295 uint8_t r[2], g[2], b[2];
1296
1297 copyin(cur->cmap.blue, b, 2);
1298 copyin(cur->cmap.green, g, 2);
1299 copyin(cur->cmap.red, r, 2);
1300 mutex_enter(&sc->sc_hwlock);
1301 hyperfb_wait(sc);
1302 hyperfb_write4(sc, NGLE_REG_10, 0xBBE0F000);
1303 hyperfb_write4(sc, NGLE_REG_14, 0x03000300);
1304 hyperfb_write4(sc, NGLE_REG_13, 0xffffffff);
1305 hyperfb_wait(sc);
1306 hyperfb_write4(sc, NGLE_REG_3, 0);
1307 rgb = (r[0] << 16) | (g[0] << 8) | b[0];
1308 hyperfb_write4(sc, NGLE_REG_4, rgb); /* BG */
1309 rgb = (r[1] << 16) | (g[1] << 8) | b[1];
1310 hyperfb_write4(sc, NGLE_REG_4, rgb); /* FG */
1311 hyperfb_write4(sc, NGLE_REG_2, 0);
1312 hyperfb_write4(sc, NGLE_REG_38,
1313 LBC_ENABLE | LBC_TYPE_CURSOR | 4);
1314
1315 hyperfb_setup_fb(sc);
1316 mutex_exit(&sc->sc_hwlock);
1317
1318 }
1319 if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
1320 uint32_t buffer[128], latch, tmp;
1321 int i;
1322
1323 copyin(cur->mask, buffer, 512);
1324 hyperfb_wait(sc);
1325 hyperfb_write4(sc, NGLE_REG_30, 0);
1326 for (i = 0; i < 128; i += 2) {
1327 latch = 0;
1328 tmp = buffer[i] & 0x80808080;
1329 latch |= tmp >> 7;
1330 tmp = buffer[i] & 0x40404040;
1331 latch |= tmp >> 5;
1332 tmp = buffer[i] & 0x20202020;
1333 latch |= tmp >> 3;
1334 tmp = buffer[i] & 0x10101010;
1335 latch |= tmp >> 1;
1336 tmp = buffer[i] & 0x08080808;
1337 latch |= tmp << 1;
1338 tmp = buffer[i] & 0x04040404;
1339 latch |= tmp << 3;
1340 tmp = buffer[i] & 0x02020202;
1341 latch |= tmp << 5;
1342 tmp = buffer[i] & 0x01010101;
1343 latch |= tmp << 7;
1344 hyperfb_write4(sc, NGLE_REG_31, latch);
1345 latch = 0;
1346 tmp = buffer[i + 1] & 0x80808080;
1347 latch |= tmp >> 7;
1348 tmp = buffer[i + 1] & 0x40404040;
1349 latch |= tmp >> 5;
1350 tmp = buffer[i + 1] & 0x20202020;
1351 latch |= tmp >> 3;
1352 tmp = buffer[i + 1] & 0x10101010;
1353 latch |= tmp >> 1;
1354 tmp = buffer[i + 1] & 0x08080808;
1355 latch |= tmp << 1;
1356 tmp = buffer[i + 1] & 0x04040404;
1357 latch |= tmp << 3;
1358 tmp = buffer[i + 1] & 0x02020202;
1359 latch |= tmp << 5;
1360 tmp = buffer[i + 1] & 0x01010101;
1361 latch |= tmp << 7;
1362 hyperfb_write4(sc, NGLE_REG_31, latch);
1363 }
1364
1365 copyin(cur->image, buffer, 512);
1366 hyperfb_wait(sc);
1367 hyperfb_write4(sc, NGLE_REG_30, 0x80);
1368 for (i = 0; i < 128; i += 2) {
1369 latch = 0;
1370 tmp = buffer[i] & 0x80808080;
1371 latch |= tmp >> 7;
1372 tmp = buffer[i] & 0x40404040;
1373 latch |= tmp >> 5;
1374 tmp = buffer[i] & 0x20202020;
1375 latch |= tmp >> 3;
1376 tmp = buffer[i] & 0x10101010;
1377 latch |= tmp >> 1;
1378 tmp = buffer[i] & 0x08080808;
1379 latch |= tmp << 1;
1380 tmp = buffer[i] & 0x04040404;
1381 latch |= tmp << 3;
1382 tmp = buffer[i] & 0x02020202;
1383 latch |= tmp << 5;
1384 tmp = buffer[i] & 0x01010101;
1385 latch |= tmp << 7;
1386 hyperfb_write4(sc, NGLE_REG_31, latch);
1387 latch = 0;
1388 tmp = buffer[i + 1] & 0x80808080;
1389 latch |= tmp >> 7;
1390 tmp = buffer[i + 1] & 0x40404040;
1391 latch |= tmp >> 5;
1392 tmp = buffer[i + 1] & 0x20202020;
1393 latch |= tmp >> 3;
1394 tmp = buffer[i + 1] & 0x10101010;
1395 latch |= tmp >> 1;
1396 tmp = buffer[i + 1] & 0x08080808;
1397 latch |= tmp << 1;
1398 tmp = buffer[i + 1] & 0x04040404;
1399 latch |= tmp << 3;
1400 tmp = buffer[i + 1] & 0x02020202;
1401 latch |= tmp << 5;
1402 tmp = buffer[i + 1] & 0x01010101;
1403 latch |= tmp << 7;
1404 hyperfb_write4(sc, NGLE_REG_31, latch);
1405 }
1406 hyperfb_setup_fb(sc);
1407 }
1408
1409 return 0;
1410 }
1411