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