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