hpcfb.c revision 1.7 1 /* $NetBSD: hpcfb.c,v 1.7 2001/07/07 09:19:40 toshii Exp $ */
2
3 /*-
4 * Copyright (c) 1999
5 * Shin Takemura and PocketBSD Project. All rights reserved.
6 * Copyright (c) 2000,2001
7 * SATO Kazumi. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the PocketBSD project
20 * and its contributors.
21 * 4. Neither the name of the project nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 */
38
39 /*
40 * jump scroll, scroll thread, multiscreen, virtual text vram
41 * and hpcfb_emulops functions
42 * written by SATO Kazumi.
43 */
44
45 #define FBDEBUG
46 static const char _copyright[] __attribute__ ((unused)) =
47 "Copyright (c) 1999 Shin Takemura. All rights reserved.";
48 static const char _rcsid[] __attribute__ ((unused)) =
49 "$NetBSD: hpcfb.c,v 1.7 2001/07/07 09:19:40 toshii Exp $";
50
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/kernel.h>
54 #include <sys/signalvar.h>
55 #include <sys/map.h>
56 #include <sys/proc.h>
57 #include <sys/kthread.h>
58 #include <sys/lock.h>
59 #include <sys/user.h>
60 #include <sys/device.h>
61 #include <sys/conf.h>
62 #include <sys/malloc.h>
63 #include <sys/buf.h>
64 #include <sys/ioctl.h>
65
66 #include <uvm/uvm_extern.h>
67
68 #include <machine/bus.h>
69
70 #include <dev/wscons/wsconsio.h>
71 #include <dev/wscons/wsdisplayvar.h>
72 #include <dev/wscons/wscons_callbacks.h>
73
74 #include <dev/wsfont/wsfont.h>
75 #include <dev/rasops/rasops.h>
76
77 #include <dev/hpc/hpcfbvar.h>
78 #include <dev/hpc/hpcfbio.h>
79
80 #include "bivideo.h"
81 #if NBIVIDEO > 0
82 #include <dev/hpc/bivideovar.h>
83 #endif
84
85 #ifdef FBDEBUG
86 int hpcfb_debug = 0;
87 #define DPRINTF(arg) if (hpcfb_debug) printf arg;
88 #else
89 #define DPRINTF(arg)
90 #endif
91
92 #ifndef HPCFB_MAX_COLUMN
93 #define HPCFB_MAX_COLUMN 130
94 #endif /* HPCFB_MAX_COLUMN */
95 #ifndef HPCFB_MAX_ROW
96 #define HPCFB_MAX_ROW 80
97 #endif /* HPCFB_MAX_ROW */
98
99 /*
100 * currently experimental
101 #define HPCFB_JUMP
102 */
103
104 struct hpcfb_vchar {
105 u_int c;
106 long attr;
107 };
108
109 struct hpcfb_tvrow {
110 int maxcol;
111 int spacecol;
112 struct hpcfb_vchar col[HPCFB_MAX_COLUMN];
113 };
114
115 struct hpcfb_devconfig {
116 struct rasops_info dc_rinfo; /* rasops infomation */
117
118 int dc_blanked; /* currently had video disabled */
119 struct hpcfb_softc *dc_sc;
120 int dc_rows;
121 int dc_cols;
122 struct hpcfb_tvrow *dc_tvram;
123 int dc_curx;
124 int dc_cury;
125 #ifdef HPCFB_JUMP
126 int dc_min_row;
127 int dc_max_row;
128 int dc_scroll;
129 struct callout dc_scroll_ch;
130 int dc_scroll_src;
131 int dc_scroll_dst;
132 int dc_scroll_num;
133 #endif /* HPCFB_JUMP */
134 volatile int dc_state;
135 #define HPCFB_DC_CURRENT 0x80000000
136 #define HPCFB_DC_DRAWING 0x01 /* drawing raster ops */
137 #define HPCFB_DC_TDRAWING 0x02 /* drawing tvram */
138 #define HPCFB_DC_SCROLLPENDING 0x04 /* scroll is pending */
139 #define HPCFB_DC_UPDATE 0x08 /* tvram update */
140 #define HPCFB_DC_SCRDELAY 0x10 /* scroll time but delay it */
141 #define HPCFB_DC_SCRTHREAD 0x20 /* in scroll thread or callout */
142 #define HPCFB_DC_UPDATEALL 0x40 /* need to redraw all */
143 #define HPCFB_DC_ABORT 0x80 /* abort redrawing */
144 int dc_scrno;
145 int dc_memsize;
146 u_char *dc_fbaddr;
147 };
148
149 #define HPCFB_MAX_SCREEN 5
150 #define HPCFB_MAX_JUMP 5
151
152 struct hpcfb_softc {
153 struct device sc_dev;
154 struct hpcfb_devconfig *sc_dc; /* device configuration */
155 struct hpcfb_devconfig *screens[HPCFB_MAX_SCREEN];
156 const struct hpcfb_accessops *sc_accessops;
157 void *sc_accessctx;
158 int nscreens;
159 void *sc_powerhook; /* power management hook */
160 struct device *sc_wsdisplay;
161 int sc_screen_resumed;
162 int sc_polling;
163 int sc_mapping;
164 struct proc *sc_thread;
165 struct lock sc_lock;
166 void *sc_wantedscreen;
167 void (*sc_switchcb)(void *, int, int);
168 void *sc_switchcbarg;
169 struct callout sc_switch_callout;
170 };
171
172 /*
173 * function prototypes
174 */
175 int hpcfbmatch(struct device *, struct cfdata *, void *);
176 void hpcfbattach(struct device *, struct device *, void *);
177 int hpcfbprint(void *, const char *);
178
179 int hpcfb_ioctl(void *, u_long, caddr_t, int, struct proc *);
180 paddr_t hpcfb_mmap(void *, off_t, int);
181
182 void hpcfb_refresh_screen(struct hpcfb_softc *);
183 void hpcfb_doswitch(struct hpcfb_softc *);
184
185 #ifdef HPCFB_JUMP
186 static void hpcfb_create_thread(void *);
187 static void hpcfb_thread(void *);
188 #endif /* HPCFB_JUMP */
189
190 static int hpcfb_init(struct hpcfb_fbconf *, struct hpcfb_devconfig *);
191 static int hpcfb_alloc_screen(void *, const struct wsscreen_descr *,
192 void **, int *, int *, long *);
193 static void hpcfb_free_screen(void *, void *);
194 static int hpcfb_show_screen(void *, void *, int,
195 void (*) (void *, int, int), void *);
196 static void hpcfb_pollc(void *, int);
197 static void hpcfb_power(int, void *);
198 static void hpcfb_cmap_reorder(struct hpcfb_fbconf *,
199 struct hpcfb_devconfig *);
200
201 static int pow(int, int);
202
203 void hpcfb_cursor(void *, int, int, int);
204 int hpcfb_mapchar(void *, int, unsigned int *);
205 void hpcfb_putchar(void *, int, int, u_int, long);
206 void hpcfb_copycols(void *, int, int, int, int);
207 void hpcfb_erasecols(void *, int, int, int, long);
208 void hpcfb_redraw(void *, int, int, int);
209 void hpcfb_copyrows(void *, int, int, int);
210 void hpcfb_eraserows(void *, int, int, long);
211 int hpcfb_alloc_attr(void *, int, int, int, long *);
212 void hpcfb_cursor_raw(void *, int, int, int);
213
214 #ifdef HPCFB_JUMP
215 void hpcfb_update(void *);
216 void hpcfb_do_scroll(void *);
217 void hpcfb_check_update(void *);
218 #endif /* HPCFB_JUMP */
219
220 struct wsdisplay_emulops hpcfb_emulops = {
221 hpcfb_cursor,
222 hpcfb_mapchar,
223 hpcfb_putchar,
224 hpcfb_copycols,
225 hpcfb_erasecols,
226 hpcfb_copyrows,
227 hpcfb_eraserows,
228 hpcfb_alloc_attr
229 };
230
231 /*
232 * static variables
233 */
234 struct cfattach hpcfb_ca = {
235 sizeof(struct hpcfb_softc), hpcfbmatch, hpcfbattach,
236 };
237
238 struct wsscreen_descr hpcfb_stdscreen = {
239 "std",
240 0, 0, /* will be filled in -- XXX shouldn't, it's global */
241 &hpcfb_emulops, /* XXX */
242 0, 0,
243 WSSCREEN_REVERSE
244 };
245
246 const struct wsscreen_descr *_hpcfb_scrlist[] = {
247 &hpcfb_stdscreen,
248 /* XXX other formats, graphics screen? */
249 };
250
251 struct wsscreen_list hpcfb_screenlist = {
252 sizeof(_hpcfb_scrlist) / sizeof(struct wsscreen_descr *),
253 _hpcfb_scrlist
254 };
255
256 struct wsdisplay_accessops hpcfb_accessops = {
257 hpcfb_ioctl,
258 hpcfb_mmap,
259 hpcfb_alloc_screen,
260 hpcfb_free_screen,
261 hpcfb_show_screen,
262 0 /* load_font */,
263 hpcfb_pollc
264 };
265
266 void hpcfb_tv_putchar(struct hpcfb_devconfig *, int, int, u_int, long);
267 void hpcfb_tv_copycols(struct hpcfb_devconfig *, int, int, int, int);
268 void hpcfb_tv_erasecols(struct hpcfb_devconfig *, int, int, int, long);
269 void hpcfb_tv_copyrows(struct hpcfb_devconfig *, int, int, int);
270 void hpcfb_tv_eraserows(struct hpcfb_devconfig *, int, int, long);
271
272 struct wsdisplay_emulops rasops_emul;
273
274 static int hpcfbconsole;
275 struct hpcfb_devconfig hpcfb_console_dc;
276 struct wsscreen_descr hpcfb_console_wsscreen;
277 struct hpcfb_tvrow hpcfb_console_tvram[HPCFB_MAX_ROW];
278
279 /*
280 * function bodies
281 */
282 static int
283 pow(int x, int n)
284 {
285 int res = 1;
286 while (0 < n--) {
287 res *= x;
288 }
289 return (res);
290 }
291
292 int
293 hpcfbmatch(struct device *parent, struct cfdata *match, void *aux)
294 {
295 return (1);
296 }
297
298 void
299 hpcfbattach(struct device *parent, struct device *self, void *aux)
300 {
301 struct hpcfb_softc *sc = (struct hpcfb_softc *)self;
302 struct hpcfb_attach_args *ha = aux;
303 struct wsemuldisplaydev_attach_args wa;
304
305 sc->sc_accessops = ha->ha_accessops;
306 sc->sc_accessctx = ha->ha_accessctx;
307
308 if (hpcfbconsole) {
309 sc->screens[0] =
310 sc->sc_dc = &hpcfb_console_dc;
311 sc->nscreens = 1;
312 hpcfb_console_dc.dc_sc = sc;
313 } else {
314 sc->screens[0] =
315 sc->sc_dc = (struct hpcfb_devconfig *)
316 malloc(sizeof(struct hpcfb_devconfig), M_DEVBUF, M_WAITOK);
317 sc->nscreens = 0; /* XXXX */
318 memset(sc->sc_dc, 0, sizeof(struct hpcfb_devconfig));
319 if (hpcfb_init(&ha->ha_fbconflist[0], sc->sc_dc) != 0) {
320 return;
321 }
322 sc->sc_dc->dc_tvram = hpcfb_console_tvram;
323 memset(hpcfb_console_tvram, 0, sizeof(hpcfb_console_tvram));
324 sc->sc_dc->dc_sc = sc;
325 }
326 sc->sc_polling = 0; /* XXX */
327 sc->sc_mapping = 0; /* XXX */
328 callout_init(&sc->sc_switch_callout);
329 hpcfb_stdscreen.nrows = sc->sc_dc->dc_rows;
330 hpcfb_stdscreen.ncols = sc->sc_dc->dc_cols;
331 hpcfb_stdscreen.capabilities = sc->sc_dc->dc_rinfo.ri_caps;
332 printf(": hpcrasops %dx%d pixels, %d colors, %dx%d chars: multi",
333 sc->sc_dc->dc_rinfo.ri_width,
334 sc->sc_dc->dc_rinfo.ri_height,
335 pow(2, sc->sc_dc->dc_rinfo.ri_depth),
336 sc->sc_dc->dc_rinfo.ri_cols,
337 sc->sc_dc->dc_rinfo.ri_rows);
338 printf("\n");
339
340 /* Set video chip dependent CLUT if any. */
341 if (hpcfbconsole && sc->sc_accessops->setclut) {
342 sc->sc_accessops->setclut(sc->sc_accessctx,
343 &hpcfb_console_dc.dc_rinfo);
344 }
345
346 /* set font for hardware accel */
347 if (sc->sc_accessops->font) {
348 sc->sc_accessops->font(sc->sc_accessctx,
349 sc->sc_dc->dc_rinfo.ri_font);
350 }
351
352 /* Add a power hook to power management */
353 sc->sc_powerhook = powerhook_establish(hpcfb_power, sc);
354 if (sc->sc_powerhook == NULL)
355 printf("%s: WARNING: unable to establish power hook\n",
356 sc->sc_dev.dv_xname);
357
358 wa.console = hpcfbconsole;
359 wa.scrdata = &hpcfb_screenlist;
360 wa.accessops = &hpcfb_accessops;
361 wa.accesscookie = sc;
362
363 sc->sc_wsdisplay = config_found(self, &wa, wsemuldisplaydevprint);
364
365 #ifdef HPCFB_JUMP
366 /*
367 * Create a kernel thread to scroll,
368 */
369 kthread_create(hpcfb_create_thread, sc);
370 #endif /* HPCFB_JUMP */
371 }
372
373 #ifdef HPCFB_JUMP
374 void
375 hpcfb_create_thread(void *arg)
376 {
377 struct hpcfb_softc *sc = arg;
378
379 if (kthread_create1(hpcfb_thread, sc, &sc->sc_thread,
380 "%s", sc->sc_dev.dv_xname) == 0)
381 return;
382
383 /*
384 * We were unable to create the HPCFB thread; bail out.
385 */
386 sc->sc_thread = 0;
387 printf("%s: unable to create thread, kernel hpcfb scroll support disabled\n",
388 sc->sc_dev.dv_xname);
389 }
390
391 void
392 hpcfb_thread(void *arg)
393 {
394 struct hpcfb_softc *sc = arg;
395
396 /*
397 * Loop forever, doing a periodic check for update events.
398 */
399 for (;;) {
400 /* HPCFB_LOCK(sc); */
401 sc->sc_dc->dc_state |= HPCFB_DC_SCRTHREAD;
402 if (!sc->sc_mapping) /* draw only EMUL mode */
403 hpcfb_update(sc->sc_dc);
404 sc->sc_dc->dc_state &= ~HPCFB_DC_SCRTHREAD;
405 /* APM_UNLOCK(sc); */
406 (void) tsleep(sc, PWAIT, "hpcfb", (8 * hz) / 7 / 10);
407 }
408 }
409 #endif /* HPCFB_JUMP */
410
411 /* Print function (for parent devices). */
412 int
413 hpcfbprint(void *aux, const char *pnp)
414 {
415 if (pnp)
416 printf("hpcfb at %s", pnp);
417
418 return (UNCONF);
419 }
420
421 int
422 hpcfb_cnattach(struct hpcfb_fbconf *fbconf)
423 {
424 struct hpcfb_fbconf __fbconf __attribute__((__unused__));
425 long defattr;
426
427 #if NBIVIDEO > 0
428 if (fbconf == 0) {
429 memset(&__fbconf, 0, sizeof(struct hpcfb_fbconf));
430 if (bivideo_getcnfb(&__fbconf) != 0)
431 return (ENXIO);
432 fbconf = &__fbconf;
433 }
434 #endif /* NBIVIDEO > 0 */
435 memset(&hpcfb_console_dc, 0, sizeof(struct hpcfb_devconfig));
436 if (hpcfb_init(fbconf, &hpcfb_console_dc) != 0)
437 return (ENXIO);
438
439 hpcfb_console_dc.dc_tvram = hpcfb_console_tvram;
440 memset(hpcfb_console_tvram, 0, sizeof(hpcfb_console_tvram));
441
442 hpcfb_console_wsscreen = hpcfb_stdscreen;
443 hpcfb_console_wsscreen.nrows = hpcfb_console_dc.dc_rows;
444 hpcfb_console_wsscreen.ncols = hpcfb_console_dc.dc_cols;
445 hpcfb_console_wsscreen.capabilities = hpcfb_console_dc.dc_rinfo.ri_caps;
446 hpcfb_alloc_attr(&hpcfb_console_dc, 7, 0, 0, &defattr);
447 wsdisplay_cnattach(&hpcfb_console_wsscreen, &hpcfb_console_dc,
448 0, 0, defattr);
449 hpcfbconsole = 1;
450
451 return (0);
452 }
453
454 int
455 hpcfb_init(struct hpcfb_fbconf *fbconf, struct hpcfb_devconfig *dc)
456 {
457 struct rasops_info *ri;
458 vaddr_t fbaddr;
459
460 fbaddr = (vaddr_t)fbconf->hf_baseaddr;
461 dc->dc_fbaddr = (u_char *)fbaddr;
462
463 /* init rasops */
464 ri = &dc->dc_rinfo;
465 memset(ri, 0, sizeof(struct rasops_info));
466 ri->ri_depth = fbconf->hf_pixel_width;
467 ri->ri_bits = (caddr_t)fbaddr;
468 ri->ri_width = fbconf->hf_width;
469 ri->ri_height = fbconf->hf_height;
470 ri->ri_stride = fbconf->hf_bytes_per_line;
471 #if 0
472 ri->ri_flg = RI_FORCEMONO | RI_CURSOR;
473 #else
474 ri->ri_flg = RI_CURSOR;
475 #endif
476 if (fbconf->hf_swap_flags != 0) {
477 if (fbconf->hf_swap_flags == HPCFB_SWAP_BYTE)
478 ri->ri_flg |= RI_BSWAP;
479 else
480 panic("not supported swap method.");
481 }
482
483 if (rasops_init(ri, HPCFB_MAX_ROW, HPCFB_MAX_COLUMN)) {
484 panic("%s(%d): rasops_init() failed!", __FILE__, __LINE__);
485 }
486
487 /* over write color map of rasops */
488 hpcfb_cmap_reorder (fbconf, dc);
489
490 dc->dc_curx = -1;
491 dc->dc_cury = -1;
492 dc->dc_rows = dc->dc_rinfo.ri_rows;
493 dc->dc_cols = dc->dc_rinfo.ri_cols;
494 dc->dc_state |= HPCFB_DC_CURRENT;
495 #ifdef HPCFB_JUMP
496 dc->dc_max_row = 0;
497 dc->dc_min_row = dc->dc_rows;
498 dc->dc_scroll = 0;
499 callout_init(&dc->dc_scroll_ch);
500 #endif /* HPCFB_JUMP */
501 dc->dc_memsize = ri->ri_stride * ri->ri_height;
502 dc->dc_scrno = 0;
503 /* hook rasops in hpcfb_ops */
504 rasops_emul = ri->ri_ops; /* struct copy */
505 ri->ri_ops = hpcfb_emulops; /* struct copy */
506
507 return (0);
508 }
509
510 static void
511 hpcfb_cmap_reorder(struct hpcfb_fbconf *fbconf, struct hpcfb_devconfig *dc)
512 {
513 struct rasops_info *ri = &dc->dc_rinfo;
514 int reverse = fbconf->hf_access_flags & HPCFB_ACCESS_REVERSE;
515 int *cmap = ri->ri_devcmap;
516 vaddr_t fbaddr = (vaddr_t)fbconf->hf_baseaddr;
517 int i, j, bg, fg, tmp;
518
519 /*
520 * Set forground and background so that the screen
521 * looks black on white.
522 * Normally, black = 00 and white = ff.
523 * HPCFB_ACCESS_REVERSE means black = ff and white = 00.
524 */
525 switch (fbconf->hf_pixel_width) {
526 case 1:
527 /* FALLTHROUGH */
528 case 2:
529 /* FALLTHROUGH */
530 case 4:
531 if (reverse) {
532 bg = 0;
533 fg = ~0;
534 } else {
535 bg = ~0;
536 fg = 0;
537 }
538 /* for gray-scale LCD, hi-contrast color map */
539 cmap[0] = bg;
540 for (i = 1; i < 16; i++)
541 cmap[i] = fg;
542 break;
543 case 8:
544 /* FALLTHROUGH */
545 case 16:
546 if (reverse) {
547 for (i = 0, j = 15; i < 8; i++, j--) {
548 tmp = cmap[i];
549 cmap[i] = cmap[j];
550 cmap[j] = tmp;
551 }
552 }
553 break;
554 }
555
556 /* clear the screen */
557 bg = cmap[0];
558 for (i = 0;
559 i < fbconf->hf_height * fbconf->hf_bytes_per_line;
560 i += sizeof(u_int32_t)) {
561 *(u_int32_t *)(fbaddr + i) = bg;
562 }
563 }
564
565 int
566 hpcfb_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
567 {
568 struct hpcfb_softc *sc = v;
569 struct hpcfb_devconfig *dc = sc->sc_dc;
570 struct wsdisplay_fbinfo *wdf;
571
572 switch (cmd) {
573 case WSKBDIO_BELL:
574 return (0);
575 break;
576
577 case WSDISPLAYIO_GTYPE:
578 *(u_int *)data = WSDISPLAY_TYPE_HPCFB;
579 return (0);
580
581 case WSDISPLAYIO_GINFO:
582 wdf = (void *)data;
583 wdf->height = dc->dc_rinfo.ri_height;
584 wdf->width = dc->dc_rinfo.ri_width;
585 wdf->depth = dc->dc_rinfo.ri_depth;
586 wdf->cmsize = 256; /* XXXX */
587 return (0);
588
589 case WSDISPLAYIO_SMODE:
590 if (*(int *)data == WSDISPLAYIO_MODE_EMUL){
591 if (sc->sc_mapping){
592 sc->sc_mapping = 0;
593 if (dc->dc_state&HPCFB_DC_DRAWING)
594 dc->dc_state &= ~HPCFB_DC_ABORT;
595 #ifdef HPCFB_FORCE_REDRAW
596 hpcfb_refresh_screen(sc);
597 #else
598 dc->dc_state |= HPCFB_DC_UPDATEALL;
599 #endif
600 }
601 } else {
602 if (!sc->sc_mapping) {
603 sc->sc_mapping = 1;
604 dc->dc_state |= HPCFB_DC_ABORT;
605 }
606 sc->sc_mapping = 1;
607 }
608 if (sc && sc->sc_accessops->iodone)
609 (*sc->sc_accessops->iodone)(sc->sc_accessctx);
610 return (0);
611
612 case WSDISPLAYIO_GETCMAP:
613 case WSDISPLAYIO_PUTCMAP:
614 case WSDISPLAYIO_GETPARAM:
615 case WSDISPLAYIO_SETPARAM:
616 case HPCFBIO_GCONF:
617 case HPCFBIO_SCONF:
618 case HPCFBIO_GDSPCONF:
619 case HPCFBIO_SDSPCONF:
620 case HPCFBIO_GOP:
621 case HPCFBIO_SOP:
622 return ((*sc->sc_accessops->ioctl)(sc->sc_accessctx,
623 cmd, data, flag, p));
624
625 default:
626 if (IOCGROUP(cmd) != 't')
627 DPRINTF(("%s(%d): hpcfb_ioctl(%lx, %lx) grp=%c num=%ld\n",
628 __FILE__, __LINE__,
629 cmd, (u_long)data, (char)IOCGROUP(cmd), cmd&0xff));
630 break;
631 }
632
633 return (ENOTTY); /* Inappropriate ioctl for device */
634 }
635
636 paddr_t
637 hpcfb_mmap(void *v, off_t offset, int prot)
638 {
639 struct hpcfb_softc *sc = v;
640
641 return ((*sc->sc_accessops->mmap)(sc->sc_accessctx, offset, prot));
642 }
643
644 static void
645 hpcfb_power(int why, void *arg)
646 {
647 struct hpcfb_softc *sc = arg;
648
649 switch (why) {
650 case PWR_STANDBY:
651 break;
652 case PWR_SOFTSUSPEND:
653 /* XXX, casting to 'struct wsdisplay_softc *' means
654 that you should not call the method here... */
655 sc->sc_screen_resumed = wsdisplay_getactivescreen(
656 (struct wsdisplay_softc *)sc->sc_wsdisplay);
657 if (wsdisplay_switch(sc->sc_wsdisplay,
658 WSDISPLAY_NULLSCREEN,
659 1 /* waitok */) == 0) {
660 wsscreen_switchwait(
661 (struct wsdisplay_softc *)sc->sc_wsdisplay,
662 WSDISPLAY_NULLSCREEN);
663 } else {
664 sc->sc_screen_resumed = WSDISPLAY_NULLSCREEN;
665 }
666 break;
667 case PWR_SOFTRESUME:
668 if (sc->sc_screen_resumed != WSDISPLAY_NULLSCREEN)
669 wsdisplay_switch(sc->sc_wsdisplay,
670 sc->sc_screen_resumed,
671 1 /* waitok */);
672 break;
673 }
674 }
675
676 void
677 hpcfb_refresh_screen(struct hpcfb_softc *sc)
678 {
679 struct hpcfb_devconfig *dc = sc->sc_dc;
680 int x, y;
681
682 if (dc == NULL)
683 return;
684
685 #ifdef HPCFB_JUMP
686 if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
687 dc->dc_state &= ~HPCFB_DC_SCROLLPENDING;
688 dc->dc_state &= ~HPCFB_DC_UPDATE;
689 callout_stop(&dc->dc_scroll_ch);
690 }
691 #endif /* HPCFB_JUMP */
692 /*
693 * refresh screen
694 */
695 dc->dc_state &= ~HPCFB_DC_UPDATEALL;
696 x = dc->dc_curx;
697 y = dc->dc_cury;
698 if (0 <= x && 0 <= y)
699 hpcfb_cursor_raw(dc, 0, y, x); /* disable cursor */
700 /* redraw all text */
701 hpcfb_redraw(dc, 0, dc->dc_rows, 1);
702 if (0 <= x && 0 <= y)
703 hpcfb_cursor_raw(dc, 1, y, x); /* enable cursor */
704 }
705
706 static int
707 hpcfb_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
708 int *curxp, int *curyp, long *attrp)
709 {
710 struct hpcfb_softc *sc = v;
711 struct hpcfb_devconfig *dc;
712
713 DPRINTF(("%s(%d): hpcfb_alloc_screen()\n", __FILE__, __LINE__));
714
715 if (!hpcfbconsole && sc->nscreens > 0) /* XXXXX */
716 return (ENOMEM);
717
718 if (sc->nscreens > HPCFB_MAX_SCREEN)
719 return (ENOMEM);
720
721 if (sc->screens[sc->nscreens] == NULL){
722 sc->screens[sc->nscreens] =
723 malloc(sizeof(struct hpcfb_devconfig), M_DEVBUF, M_WAITOK);
724 if (sc->screens[sc->nscreens] == NULL)
725 return (ENOMEM);
726 memset(sc->screens[sc->nscreens], 0,
727 sizeof(struct hpcfb_devconfig));
728 }
729 dc = sc->screens[sc->nscreens];
730 dc->dc_sc = sc;
731
732 /* copy master raster info */
733 dc->dc_rinfo = sc->sc_dc->dc_rinfo;
734 if (sc->sc_accessops->font) {
735 sc->sc_accessops->font(sc->sc_accessctx,
736 sc->sc_dc->dc_rinfo.ri_font);
737 }
738
739 dc->dc_fbaddr = dc->dc_rinfo.ri_bits;
740 dc->dc_rows = dc->dc_rinfo.ri_rows;
741 dc->dc_cols = dc->dc_rinfo.ri_cols;
742 dc->dc_memsize = dc->dc_rinfo.ri_stride * dc->dc_rinfo.ri_height;
743
744 dc->dc_scrno = sc->nscreens;
745 dc->dc_curx = -1;
746 dc->dc_cury = -1;
747 if (dc->dc_tvram == NULL){
748 dc->dc_tvram =
749 malloc(sizeof(struct hpcfb_tvrow)*dc->dc_rows,
750 M_DEVBUF, M_WAITOK);
751 if (dc->dc_tvram == NULL){
752 free(sc->screens[sc->nscreens], M_DEVBUF);
753 sc->screens[sc->nscreens] = NULL;
754 return (ENOMEM);
755 }
756 memset(dc->dc_tvram, 0,
757 sizeof(struct hpcfb_tvrow)*dc->dc_rows);
758 }
759
760 *curxp = 0;
761 *curyp = 0;
762 sc->nscreens++;
763 *cookiep = dc;
764 hpcfb_alloc_attr(*cookiep, 7, 0, 0, attrp);
765 return (0);
766 }
767
768 static void
769 hpcfb_free_screen(void *v, void *cookie)
770 {
771 struct hpcfb_softc *sc = v;
772
773 if (sc->nscreens == 1 && sc->sc_dc == &hpcfb_console_dc)
774 panic("hpcfb_free_screen: console");
775 sc->nscreens--;
776 }
777
778 static int
779 hpcfb_show_screen(void *v, void *cookie, int waitok,
780 void (*cb)(void *, int, int), void *cbarg)
781 {
782 struct hpcfb_softc *sc = v;
783 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
784 struct hpcfb_devconfig *odc;
785
786 DPRINTF(("%s(%d): hpcfb_show_screen()\n", __FILE__, __LINE__));
787
788 odc = sc->sc_dc;
789
790 if (dc == NULL || odc == dc) {
791 hpcfb_refresh_screen(sc);
792 return (0);
793 }
794
795 sc->sc_wantedscreen = cookie;
796 sc->sc_switchcb = cb;
797 sc->sc_switchcbarg = cbarg;
798 if (cb) {
799 callout_reset(&sc->sc_switch_callout, 0,
800 (void(*)(void *))hpcfb_doswitch, sc);
801 return (EAGAIN);
802 }
803
804 hpcfb_doswitch(sc);
805 return (0);
806 }
807
808 void
809 hpcfb_doswitch(struct hpcfb_softc *sc)
810 {
811 struct hpcfb_devconfig *dc;
812 struct hpcfb_devconfig *odc;
813
814 odc = sc->sc_dc;
815 dc = sc->sc_wantedscreen;
816
817 if (!dc) {
818 (*sc->sc_switchcb)(sc->sc_switchcbarg, EIO, 0);
819 return;
820 }
821
822 if (odc == dc)
823 return;
824
825 if (odc) {
826 #ifdef HPCFB_JUMP
827 odc->dc_state |= HPCFB_DC_ABORT;
828 #endif /* HPCFB_JUMP */
829
830 if (odc->dc_curx >= 0 && odc->dc_cury >= 0)
831 hpcfb_cursor_raw(odc, 0, odc->dc_cury, odc->dc_curx);
832 /* disable cursor */
833 /* disable old screen */
834 odc->dc_state &= ~HPCFB_DC_CURRENT;
835 odc->dc_rinfo.ri_bits = NULL;
836 }
837 /* switch screen to new one */
838 dc->dc_state |= HPCFB_DC_CURRENT;
839 dc->dc_rinfo.ri_bits = dc->dc_fbaddr;
840 sc->sc_dc = dc;
841
842 /* redraw screen image */
843 hpcfb_refresh_screen(sc);
844
845 sc->sc_wantedscreen = NULL;
846 if (sc->sc_switchcb)
847 (*sc->sc_switchcb)(sc->sc_switchcbarg, 0, 0);
848
849 return;
850 }
851
852 static void
853 hpcfb_pollc(void *v, int on)
854 {
855 struct hpcfb_softc *sc = v;
856
857 if (sc == NULL)
858 return;
859 sc->sc_polling = on;
860 if (sc->sc_accessops->iodone)
861 (*sc->sc_accessops->iodone)(sc->sc_accessctx);
862 if (on) {
863 hpcfb_refresh_screen(sc);
864 if (sc->sc_accessops->iodone)
865 (*sc->sc_accessops->iodone)(sc->sc_accessctx);
866 }
867
868 return;
869 }
870
871 /*
872 * cursor
873 */
874 void
875 hpcfb_cursor(void *cookie, int on, int row, int col)
876 {
877 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
878
879 if (on) {
880 dc->dc_curx = col;
881 dc->dc_cury = row;
882 } else {
883 dc->dc_curx = -1;
884 dc->dc_cury = -1;
885 }
886
887 hpcfb_cursor_raw(cookie, on, row, col);
888 }
889
890 void
891 hpcfb_cursor_raw(cookie, on, row, col)
892 void *cookie;
893 int on, row, col;
894 {
895 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
896 struct hpcfb_softc *sc = dc->dc_sc;
897 struct rasops_info *ri = &dc->dc_rinfo;
898 int curwidth, curheight;
899 int xoff, yoff;
900
901 #ifdef HPCFB_JUMP
902 if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
903 dc->dc_state |= HPCFB_DC_UPDATE;
904 return;
905 }
906 #endif /* HPCFB_JUMP */
907 if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
908 return;
909
910 if (ri->ri_bits == NULL)
911 return;
912
913 dc->dc_state |= HPCFB_DC_DRAWING;
914 if (sc && sc->sc_accessops->cursor) {
915 xoff = col * ri->ri_font->fontwidth;
916 yoff = row * ri->ri_font->fontheight;
917 curheight = ri->ri_font->fontheight;
918 curwidth = ri->ri_font->fontwidth;
919 (*sc->sc_accessops->cursor)(sc->sc_accessctx,
920 on, xoff, yoff, curwidth, curheight);
921 } else
922 rasops_emul.cursor(ri, on, row, col);
923 dc->dc_state &= ~HPCFB_DC_DRAWING;
924 }
925
926 /*
927 * mapchar
928 */
929 int
930 hpcfb_mapchar(void *cookie, int c, unsigned int *cp)
931 {
932 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
933 struct rasops_info *ri = &dc->dc_rinfo;
934
935 return (rasops_emul.mapchar(ri, c, cp));
936 }
937
938 /*
939 * putchar
940 */
941 void
942 hpcfb_tv_putchar(struct hpcfb_devconfig *dc, int row, int col, u_int uc,
943 long attr)
944 {
945 struct hpcfb_tvrow *vscn = dc->dc_tvram;
946 struct hpcfb_vchar *vc = &vscn[row].col[col];
947 struct hpcfb_vchar *vcb;
948
949 if (vscn == 0)
950 return;
951
952 dc->dc_state |= HPCFB_DC_TDRAWING;
953 #ifdef HPCFB_JUMP
954 if (row < dc->dc_min_row)
955 dc->dc_min_row = row;
956 if (row > dc->dc_max_row)
957 dc->dc_max_row = row;
958
959 #endif /* HPCFB_JUMP */
960 if (vscn[row].maxcol +1 == col)
961 vscn[row].maxcol = col;
962 else if (vscn[row].maxcol < col) {
963 vcb = &vscn[row].col[vscn[row].maxcol+1];
964 memset(vcb, 0,
965 sizeof(struct hpcfb_vchar)*(col-vscn[row].maxcol-1));
966 vscn[row].maxcol = col;
967 }
968 vc->c = uc;
969 vc->attr = attr;
970 dc->dc_state &= ~HPCFB_DC_TDRAWING;
971 #ifdef HPCFB_JUMP
972 hpcfb_check_update(dc);
973 #endif /* HPCFB_JUMP */
974 }
975
976 void
977 hpcfb_putchar(void *cookie, int row, int col, u_int uc, long attr)
978 {
979 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
980 struct hpcfb_softc *sc = dc->dc_sc;
981 struct rasops_info *ri = &dc->dc_rinfo;
982 int xoff;
983 int yoff;
984 int fclr, uclr;
985 struct wsdisplay_font *font;
986
987 hpcfb_tv_putchar(dc, row, col, uc, attr);
988 #ifdef HPCFB_JUMP
989 if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
990 dc->dc_state |= HPCFB_DC_UPDATE;
991 return;
992 }
993 #endif /* HPCFB_JUMP */
994
995 if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
996 return;
997 if (ri->ri_bits == NULL)
998 return;
999
1000 dc->dc_state |= HPCFB_DC_DRAWING;
1001 if (sc && sc->sc_accessops->putchar
1002 && (dc->dc_state&HPCFB_DC_CURRENT)) {
1003 font = ri->ri_font;
1004 yoff = row * ri->ri_font->fontheight;
1005 xoff = col * ri->ri_font->fontwidth;
1006 fclr = ri->ri_devcmap[((u_int)attr >> 24) & 15];
1007 uclr = ri->ri_devcmap[((u_int)attr >> 16) & 15];
1008
1009 (*sc->sc_accessops->putchar)(sc->sc_accessctx,
1010 xoff, yoff, font, fclr, uclr, uc, attr);
1011 } else
1012 rasops_emul.putchar(ri, row, col, uc, attr);
1013 dc->dc_state &= ~HPCFB_DC_DRAWING;
1014 #ifdef HPCFB_JUMP
1015 hpcfb_check_update(dc);
1016 #endif /* HPCFB_JUMP */
1017 }
1018
1019 /*
1020 * copycols
1021 */
1022 void
1023 hpcfb_tv_copycols(struct hpcfb_devconfig *dc, int row, int srccol, int dstcol,
1024 int ncols)
1025 {
1026 struct hpcfb_tvrow *vscn = dc->dc_tvram;
1027 struct hpcfb_vchar *svc = &vscn[row].col[srccol];
1028 struct hpcfb_vchar *dvc = &vscn[row].col[dstcol];
1029
1030 if (vscn == 0)
1031 return;
1032
1033 dc->dc_state |= HPCFB_DC_TDRAWING;
1034 #ifdef HPCFB_JUMP
1035 if (row < dc->dc_min_row)
1036 dc->dc_min_row = row;
1037 if (row > dc->dc_max_row)
1038 dc->dc_max_row = row;
1039 #endif /* HPCFB_JUMP */
1040
1041 memcpy(dvc, svc, ncols*sizeof(struct hpcfb_vchar));
1042 if (vscn[row].maxcol < srccol+ncols-1)
1043 vscn[row].maxcol = srccol+ncols-1;
1044 if (vscn[row].maxcol < dstcol+ncols-1)
1045 vscn[row].maxcol = dstcol+ncols-1;
1046 dc->dc_state &= ~HPCFB_DC_TDRAWING;
1047 #ifdef HPCFB_JUMP
1048 hpcfb_check_update(dc);
1049 #endif /* HPCFB_JUMP */
1050 }
1051
1052 void
1053 hpcfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
1054 {
1055 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1056 struct hpcfb_softc *sc = dc->dc_sc;
1057 struct rasops_info *ri = &dc->dc_rinfo;
1058 int srcxoff,dstxoff;
1059 int srcyoff,dstyoff;
1060 int height, width;
1061
1062 hpcfb_tv_copycols(dc, row, srccol, dstcol, ncols);
1063 #ifdef HPCFB_JUMP
1064 if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
1065 dc->dc_state |= HPCFB_DC_UPDATE;
1066 return;
1067 }
1068 #endif /* HPCFB_JUMP */
1069 if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
1070 return;
1071 if (ri->ri_bits == NULL)
1072 return;
1073
1074 dc->dc_state |= HPCFB_DC_DRAWING;
1075 if (sc && sc->sc_accessops->bitblit
1076 && (dc->dc_state&HPCFB_DC_CURRENT)) {
1077 srcxoff = srccol * ri->ri_font->fontwidth;
1078 srcyoff = row * ri->ri_font->fontheight;
1079 dstxoff = dstcol * ri->ri_font->fontwidth;
1080 dstyoff = row * ri->ri_font->fontheight;
1081 width = ncols * ri->ri_font->fontwidth;
1082 height = ri->ri_font->fontheight;
1083 (*sc->sc_accessops->bitblit)(sc->sc_accessctx,
1084 srcxoff, srcyoff, dstxoff, dstyoff, height, width);
1085 } else
1086 rasops_emul.copycols(ri, row, srccol, dstcol, ncols);
1087 dc->dc_state &= ~HPCFB_DC_DRAWING;
1088 #ifdef HPCFB_JUMP
1089 hpcfb_check_update(dc);
1090 #endif /* HPCFB_JUMP */
1091 }
1092
1093
1094 /*
1095 * erasecols
1096 */
1097 void
1098 hpcfb_tv_erasecols(struct hpcfb_devconfig *dc, int row, int startcol,
1099 int ncols, long attr)
1100 {
1101 struct hpcfb_tvrow *vscn = dc->dc_tvram;
1102
1103 if (vscn == 0)
1104 return;
1105
1106 dc->dc_state |= HPCFB_DC_TDRAWING;
1107 #ifdef HPCFB_JUMP
1108 if (row < dc->dc_min_row)
1109 dc->dc_min_row = row;
1110 if (row > dc->dc_max_row)
1111 dc->dc_max_row = row;
1112 #endif /* HPCFB_JUMP */
1113
1114 vscn[row].maxcol = startcol-1;
1115 if (vscn[row].spacecol < startcol+ncols-1)
1116 vscn[row].spacecol = startcol+ncols-1;
1117 dc->dc_state &= ~HPCFB_DC_TDRAWING;
1118 #ifdef HPCFB_JUMP
1119 hpcfb_check_update(dc);
1120 #endif /* HPCFB_JUMP */
1121 }
1122
1123 void
1124 hpcfb_erasecols(void *cookie, int row, int startcol, int ncols, long attr)
1125 {
1126 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1127 struct hpcfb_softc *sc = dc->dc_sc;
1128 struct rasops_info *ri = &dc->dc_rinfo;
1129 int xoff, yoff;
1130 int width, height;
1131
1132 hpcfb_tv_erasecols(dc, row, startcol, ncols, attr);
1133 #ifdef HPCFB_JUMP
1134 if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
1135 dc->dc_state |= HPCFB_DC_UPDATE;
1136 return;
1137 }
1138 #endif /* HPCFB_JUMP */
1139 if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
1140 return;
1141 if (ri->ri_bits == NULL)
1142 return;
1143
1144 dc->dc_state |= HPCFB_DC_DRAWING;
1145 if (sc && sc->sc_accessops->erase
1146 && (dc->dc_state&HPCFB_DC_CURRENT)) {
1147 xoff = startcol * ri->ri_font->fontwidth;
1148 yoff = row * ri->ri_font->fontheight;
1149 width = ncols * ri->ri_font->fontwidth;
1150 height = ri->ri_font->fontheight;
1151 (*sc->sc_accessops->erase)(sc->sc_accessctx,
1152 xoff, yoff, height, width, attr);
1153 } else
1154 rasops_emul.erasecols(ri, row, startcol, ncols, attr);
1155 dc->dc_state &= ~HPCFB_DC_DRAWING;
1156 #ifdef HPCFB_JUMP
1157 hpcfb_check_update(dc);
1158 #endif /* HPCFB_JUMP */
1159 }
1160
1161 /*
1162 * Copy rows.
1163 */
1164 void
1165 hpcfb_tv_copyrows(struct hpcfb_devconfig *dc, int src, int dst, int num)
1166 {
1167 struct hpcfb_tvrow *vscn = dc->dc_tvram;
1168 struct hpcfb_tvrow *svc = &vscn[src];
1169 struct hpcfb_tvrow *dvc = &vscn[dst];
1170 int i;
1171 int d;
1172
1173 if (vscn == 0)
1174 return;
1175
1176 dc->dc_state |= HPCFB_DC_TDRAWING;
1177 #ifdef HPCFB_JUMP
1178 if (dst < dc->dc_min_row)
1179 dc->dc_min_row = dst;
1180 if (dst + num > dc->dc_max_row)
1181 dc->dc_max_row = dst + num -1;
1182 #endif /* HPCFB_JUMP */
1183
1184 if (svc > dvc)
1185 d = 1;
1186 else if (svc < dvc) {
1187 svc += num-1;
1188 dvc += num-1;
1189 d = -1;
1190 } else {
1191 dc->dc_state &= ~HPCFB_DC_TDRAWING;
1192 #ifdef HPCFB_JUMP
1193 hpcfb_check_update(dc);
1194 #endif /* HPCFB_JUMP */
1195 return;
1196 }
1197
1198 for (i = 0; i < num; i++) {
1199 memcpy(&dvc->col[0], &svc->col[0], sizeof(struct hpcfb_vchar)*(svc->maxcol+1));
1200 if (svc->maxcol < dvc->maxcol && dvc->spacecol < dvc->maxcol)
1201 dvc->spacecol = dvc->maxcol;
1202 dvc->maxcol = svc->maxcol;
1203 svc+=d;
1204 dvc+=d;
1205 }
1206 dc->dc_state &= ~HPCFB_DC_TDRAWING;
1207 #ifdef HPCFB_JUMP
1208 hpcfb_check_update(dc);
1209 #endif /* HPCFB_JUMP */
1210 }
1211
1212 void
1213 hpcfb_redraw(cookie, row, num, all)
1214 void *cookie;
1215 int row, num;
1216 int all;
1217 {
1218 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1219 struct rasops_info *ri = &dc->dc_rinfo;
1220 int cols;
1221 struct hpcfb_tvrow *vscn = dc->dc_tvram;
1222 struct hpcfb_vchar *svc;
1223 int i, j;
1224
1225 #ifdef HPCFB_JUMP
1226 if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
1227 dc->dc_state |= HPCFB_DC_UPDATE;
1228 return;
1229 }
1230 #endif /* HPCFB_JUMP */
1231 if (dc->dc_sc != NULL
1232 && !dc->dc_sc->sc_polling
1233 && dc->dc_sc->sc_mapping)
1234 return;
1235
1236 dc->dc_state &= ~HPCFB_DC_ABORT;
1237
1238 if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
1239 return;
1240 if (vscn == 0)
1241 return;
1242
1243 if (ri->ri_bits == NULL)
1244 return;
1245
1246 dc->dc_state |= HPCFB_DC_DRAWING;
1247 dc->dc_state |= HPCFB_DC_TDRAWING;
1248 for (i = 0; i < num; i++) {
1249 if (dc->dc_state&HPCFB_DC_ABORT)
1250 break;
1251 cols = vscn[row+i].maxcol;
1252 for (j = 0; j <= cols; j++) {
1253 if (dc->dc_state&HPCFB_DC_ABORT)
1254 continue;
1255 svc = &vscn[row+i].col[j];
1256 rasops_emul.putchar(ri, row + i, j, svc->c, svc->attr);
1257 }
1258 if (all)
1259 cols = dc->dc_cols-1;
1260 else
1261 cols = vscn[row+i].spacecol;
1262 for (; j <= cols; j++) {
1263 if (dc->dc_state&HPCFB_DC_ABORT)
1264 continue;
1265 rasops_emul.putchar(ri, row + i, j, ' ', 0);
1266 }
1267 vscn[row+i].spacecol = 0;
1268 }
1269 if (dc->dc_state&HPCFB_DC_ABORT)
1270 dc->dc_state &= ~HPCFB_DC_ABORT;
1271 dc->dc_state &= ~HPCFB_DC_DRAWING;
1272 dc->dc_state &= ~HPCFB_DC_TDRAWING;
1273 #ifdef HPCFB_JUMP
1274 hpcfb_check_update(dc);
1275 #endif /* HPCFB_JUMP */
1276 }
1277
1278 #ifdef HPCFB_JUMP
1279 void
1280 hpcfb_update(void *v)
1281 {
1282 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)v;
1283
1284 /* callout_stop(&dc->dc_scroll_ch); */
1285 dc->dc_state &= ~HPCFB_DC_SCROLLPENDING;
1286 if (dc->dc_curx > 0 && dc->dc_cury > 0)
1287 hpcfb_cursor_raw(dc, 0, dc->dc_cury, dc->dc_curx);
1288 if ((dc->dc_state&HPCFB_DC_UPDATEALL)) {
1289 hpcfb_redraw(dc, 0, dc->dc_rows, 1);
1290 dc->dc_state &= ~(HPCFB_DC_UPDATE|HPCFB_DC_UPDATEALL);
1291 } else if ((dc->dc_state&HPCFB_DC_UPDATE)) {
1292 hpcfb_redraw(dc, dc->dc_min_row,
1293 dc->dc_max_row - dc->dc_min_row, 0);
1294 dc->dc_state &= ~HPCFB_DC_UPDATE;
1295 } else {
1296 hpcfb_redraw(dc, dc->dc_scroll_dst, dc->dc_scroll_num, 0);
1297 }
1298 if (dc->dc_curx > 0 && dc->dc_cury > 0)
1299 hpcfb_cursor_raw(dc, 1, dc->dc_cury, dc->dc_curx);
1300 }
1301
1302 void
1303 hpcfb_do_scroll(void *v)
1304 {
1305 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)v;
1306
1307 dc->dc_state |= HPCFB_DC_SCRTHREAD;
1308 if (dc->dc_state&(HPCFB_DC_DRAWING|HPCFB_DC_TDRAWING))
1309 dc->dc_state |= HPCFB_DC_SCRDELAY;
1310 else if (dc->dc_sc != NULL && dc->dc_sc->sc_thread)
1311 wakeup(dc->dc_sc);
1312 else if (dc->dc_sc != NULL && !dc->dc_sc->sc_mapping) {
1313 /* draw only EMUL mode */
1314 hpcfb_update(v);
1315 }
1316 dc->dc_state &= ~HPCFB_DC_SCRTHREAD;
1317 }
1318
1319 void
1320 hpcfb_check_update(void *v)
1321 {
1322 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)v;
1323
1324 if (dc->dc_sc != NULL
1325 && dc->dc_sc->sc_polling
1326 && (dc->dc_state&HPCFB_DC_SCROLLPENDING)){
1327 callout_stop(&dc->dc_scroll_ch);
1328 dc->dc_state &= ~HPCFB_DC_SCRDELAY;
1329 hpcfb_update(v);
1330 }
1331 else if (dc->dc_state&HPCFB_DC_SCRDELAY){
1332 dc->dc_state &= ~HPCFB_DC_SCRDELAY;
1333 hpcfb_update(v);
1334 } else if (dc->dc_state&HPCFB_DC_UPDATEALL){
1335 dc->dc_state &= ~HPCFB_DC_UPDATEALL;
1336 hpcfb_update(v);
1337 }
1338 }
1339 #endif /* HPCFB_JUMP */
1340
1341 void
1342 hpcfb_copyrows(void *cookie, int src, int dst, int num)
1343 {
1344 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1345 struct rasops_info *ri = &dc->dc_rinfo;
1346 struct hpcfb_softc *sc = dc->dc_sc;
1347 int srcyoff, dstyoff;
1348 int width, height;
1349
1350 hpcfb_tv_copyrows(cookie, src, dst, num);
1351
1352 if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
1353 return;
1354 if (ri->ri_bits == NULL)
1355 return;
1356
1357 if (sc && sc->sc_accessops->bitblit
1358 && (dc->dc_state&HPCFB_DC_CURRENT)) {
1359 dc->dc_state |= HPCFB_DC_DRAWING;
1360 srcyoff = src * ri->ri_font->fontheight;
1361 dstyoff = dst * ri->ri_font->fontheight;
1362 width = dc->dc_cols * ri->ri_font->fontwidth;
1363 height = num * ri->ri_font->fontheight;
1364 (*sc->sc_accessops->bitblit)(sc->sc_accessctx,
1365 0, srcyoff, 0, dstyoff, height, width);
1366 dc->dc_state &= ~HPCFB_DC_DRAWING;
1367 }
1368 else {
1369 #ifdef HPCFB_JUMP
1370 if (sc && sc->sc_polling) {
1371 hpcfb_check_update(dc);
1372 } else if ((dc->dc_state&HPCFB_DC_SCROLLPENDING) == 0) {
1373 dc->dc_state |= HPCFB_DC_SCROLLPENDING;
1374 dc->dc_scroll = 1;
1375 dc->dc_scroll_src = src;
1376 dc->dc_scroll_dst = dst;
1377 dc->dc_scroll_num = num;
1378 callout_reset(&dc->dc_scroll_ch, hz/100, &hpcfb_do_scroll, dc);
1379 return;
1380 } else if (dc->dc_scroll++ < dc->dc_rows/HPCFB_MAX_JUMP) {
1381 dc->dc_state |= HPCFB_DC_UPDATE;
1382 return;
1383 } else {
1384 dc->dc_state &= ~HPCFB_DC_SCROLLPENDING;
1385 callout_stop(&dc->dc_scroll_ch);
1386 }
1387 if (dc->dc_state&HPCFB_DC_UPDATE) {
1388 dc->dc_state &= ~HPCFB_DC_UPDATE;
1389 hpcfb_redraw(cookie, dc->dc_min_row,
1390 dc->dc_max_row - dc->dc_min_row, 0);
1391 dc->dc_max_row = 0;
1392 dc->dc_min_row = dc->dc_rows;
1393 if (dc->dc_curx > 0 && dc->dc_cury > 0)
1394 hpcfb_cursor(dc, 1, dc->dc_cury, dc->dc_curx);
1395 return;
1396 }
1397 #endif /* HPCFB_JUMP */
1398 hpcfb_redraw(cookie, dst, num, 0);
1399 }
1400 #ifdef HPCFB_JUMP
1401 hpcfb_check_update(dc);
1402 #endif /* HPCFB_JUMP */
1403 }
1404
1405 /*
1406 * eraserows
1407 */
1408 void
1409 hpcfb_tv_eraserows(struct hpcfb_devconfig *dc, int row, int nrow, long attr)
1410 {
1411 struct hpcfb_tvrow *vscn = dc->dc_tvram;
1412 int cols;
1413 int i;
1414
1415 if (vscn == 0)
1416 return;
1417
1418 dc->dc_state |= HPCFB_DC_TDRAWING;
1419 dc->dc_state &= ~HPCFB_DC_TDRAWING;
1420 #ifdef HPCFB_JUMP
1421 if (row < dc->dc_min_row)
1422 dc->dc_min_row = row;
1423 if (row + nrow > dc->dc_max_row)
1424 dc->dc_max_row = row + nrow;
1425 #endif /* HPCFB_JUMP */
1426
1427 for (i = 0; i < nrow; i++) {
1428 cols = vscn[row+i].maxcol;
1429 if (vscn[row+i].spacecol < cols)
1430 vscn[row+i].spacecol = cols;
1431 vscn[row+i].maxcol = -1;
1432 }
1433 #ifdef HPCFB_JUMP
1434 hpcfb_check_update(dc);
1435 #endif /* HPCFB_JUMP */
1436 }
1437
1438 void
1439 hpcfb_eraserows(void *cookie, int row, int nrow, long attr)
1440 {
1441 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1442 struct hpcfb_softc *sc = dc->dc_sc;
1443 struct rasops_info *ri = &dc->dc_rinfo;
1444 int yoff;
1445 int width;
1446 int height;
1447
1448 hpcfb_tv_eraserows(dc, row, nrow, attr);
1449 #ifdef HPCFB_JUMP
1450 if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
1451 dc->dc_state |= HPCFB_DC_UPDATE;
1452 return;
1453 }
1454 #endif /* HPCFB_JUMP */
1455 if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
1456 return;
1457 if (ri->ri_bits == NULL)
1458 return;
1459
1460 dc->dc_state |= HPCFB_DC_DRAWING;
1461 if (sc && sc->sc_accessops->erase
1462 && (dc->dc_state&HPCFB_DC_CURRENT)) {
1463 yoff = row * ri->ri_font->fontheight;
1464 width = dc->dc_cols * ri->ri_font->fontwidth;
1465 height = nrow * ri->ri_font->fontheight;
1466 (*sc->sc_accessops->erase)(sc->sc_accessctx,
1467 0, yoff, height, width, attr);
1468 } else
1469 rasops_emul.eraserows(ri, row, nrow, attr);
1470 dc->dc_state &= ~HPCFB_DC_DRAWING;
1471 #ifdef HPCFB_JUMP
1472 hpcfb_check_update(dc);
1473 #endif /* HPCFB_JUMP */
1474 }
1475
1476 /*
1477 * alloc_attr
1478 */
1479 int
1480 hpcfb_alloc_attr(void *cookie, int fg, int bg, int flags, long *attrp)
1481 {
1482 struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1483 struct rasops_info *ri = &dc->dc_rinfo;
1484
1485 return (rasops_emul.alloc_attr(ri, fg, bg, flags, attrp));
1486 }
1487