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