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