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