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