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