Home | History | Annotate | Line # | Download | only in dev
ite_et.c revision 1.31.12.1
      1  1.31.12.1   thorpej /*	$NetBSD: ite_et.c,v 1.31.12.1 2021/03/21 21:08:57 thorpej Exp $	*/
      2        1.1       leo 
      3        1.1       leo /*
      4        1.1       leo  * Copyright (c) 1996 Leo Weppelman.
      5        1.1       leo  * All rights reserved.
      6        1.1       leo  *
      7        1.1       leo  * Redistribution and use in source and binary forms, with or without
      8        1.1       leo  * modification, are permitted provided that the following conditions
      9        1.1       leo  * are met:
     10        1.1       leo  * 1. Redistributions of source code must retain the above copyright
     11        1.1       leo  *    notice, this list of conditions and the following disclaimer.
     12        1.1       leo  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1       leo  *    notice, this list of conditions and the following disclaimer in the
     14        1.1       leo  *    documentation and/or other materials provided with the distribution.
     15        1.1       leo  *
     16        1.1       leo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17        1.1       leo  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18        1.1       leo  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19        1.1       leo  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20        1.1       leo  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21        1.1       leo  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22        1.1       leo  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23        1.1       leo  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24        1.1       leo  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25        1.1       leo  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26        1.1       leo  */
     27       1.17     lukem 
     28       1.17     lukem #include <sys/cdefs.h>
     29  1.31.12.1   thorpej __KERNEL_RCSID(0, "$NetBSD: ite_et.c,v 1.31.12.1 2021/03/21 21:08:57 thorpej Exp $");
     30       1.17     lukem 
     31        1.1       leo #include <sys/param.h>
     32        1.1       leo #include <sys/systm.h>
     33        1.1       leo #include <sys/conf.h>
     34        1.1       leo #include <sys/ioctl.h>
     35        1.1       leo #include <sys/malloc.h>
     36        1.1       leo #include <sys/device.h>
     37        1.1       leo #include <dev/cons.h>
     38        1.1       leo 
     39        1.1       leo #include <machine/cpu.h>
     40        1.1       leo 
     41        1.1       leo #include <atari/atari/device.h>
     42        1.1       leo 
     43        1.1       leo #include <atari/dev/itevar.h>
     44        1.1       leo #include <atari/dev/iteioctl.h>
     45        1.1       leo #include <atari/dev/grfioctl.h>
     46        1.3       leo #include <atari/dev/grf_etreg.h>
     47        1.1       leo #include <atari/dev/grfabs_reg.h>
     48        1.3       leo #include <atari/dev/grfabs_et.h>
     49        1.1       leo #include <atari/dev/grfvar.h>
     50        1.1       leo #include <atari/dev/font.h>
     51        1.1       leo #include <atari/dev/viewioctl.h>
     52        1.1       leo #include <atari/dev/viewvar.h>
     53        1.1       leo 
     54        1.1       leo #include "grfet.h"
     55        1.1       leo 
     56        1.1       leo /*
     57        1.1       leo  * This is what ip->priv points to;
     58        1.1       leo  * it contains local variables for custom-chip ites.
     59        1.1       leo  */
     60        1.1       leo struct ite_priv {
     61        1.1       leo 	volatile u_char	*regkva;
     62        1.1       leo };
     63        1.1       leo 
     64        1.1       leo typedef struct ite_priv ipriv_t;
     65        1.1       leo 
     66        1.1       leo static ipriv_t	con_ipriv;
     67        1.1       leo 
     68        1.1       leo /* Console colors */
     69        1.1       leo static u_char etconscolors[3][3] = {	/* background, foreground, hilite */
     70        1.1       leo 	{0x0, 0x0, 0x0}, {0x30, 0x30, 0x30}, { 0x3f,  0x3f,  0x3f}
     71        1.1       leo };
     72        1.1       leo 
     73        1.1       leo /* XXX: Shouldn't these be in font.h???? */
     74        1.1       leo extern font_info	font_info_8x8;
     75        1.1       leo extern font_info	font_info_8x16;
     76        1.1       leo 
     77       1.21       dsl static void grfet_iteinit(struct grf_softc *);
     78       1.21       dsl static void view_init(struct ite_softc *);
     79       1.21       dsl static void view_deinit(struct ite_softc *);
     80       1.21       dsl static int  iteet_ioctl(struct ite_softc *, u_long, void *, int,
     81       1.21       dsl 							struct lwp *);
     82       1.21       dsl static int  ite_newsize(struct ite_softc *, struct itewinsize *);
     83       1.21       dsl static void et_inittextmode(struct ite_softc *, et_sv_reg_t *, int);
     84       1.21       dsl void et_cursor(struct ite_softc *ip, int flag);
     85       1.21       dsl void et_clear(struct ite_softc *ip, int sy, int sx, int h, int w);
     86       1.21       dsl void et_putc(struct ite_softc *ip, int c, int dy, int dx, int mode);
     87       1.21       dsl void et_scroll(struct ite_softc *ip, int sy, int sx, int count,
     88       1.21       dsl     int dir);
     89        1.1       leo 
     90        1.1       leo /*
     91        1.1       leo  * grfet config stuff
     92        1.1       leo  */
     93       1.31   tsutsui static void grfetattach(device_t, device_t, void *);
     94       1.31   tsutsui static int  grfetmatch(device_t, cfdata_t, void *);
     95       1.31   tsutsui static int  grfetprint(void *, const char *);
     96        1.1       leo 
     97       1.30   tsutsui CFATTACH_DECL_NEW(grfet, sizeof(struct grf_softc),
     98       1.15   thorpej     grfetmatch, grfetattach, NULL, NULL);
     99        1.1       leo 
    100        1.1       leo /*
    101        1.1       leo  * only used in console init.
    102        1.1       leo  */
    103        1.1       leo static struct cfdata *cfdata_grf   = NULL;
    104        1.1       leo 
    105       1.31   tsutsui static int
    106       1.30   tsutsui grfetmatch(device_t parent, cfdata_t cf, void *aux)
    107        1.1       leo {
    108       1.10       leo 	static int	card_probed  = -1;
    109       1.10       leo 	static int	did_consinit = 0;
    110       1.30   tsutsui 	grf_auxp_t	*grf_auxp = aux;
    111       1.13   gehenna 	extern const struct cdevsw view_cdevsw;
    112        1.1       leo 
    113        1.6       leo 	if (card_probed <= 0) {
    114        1.6       leo 		if (card_probed == 0) /* Probed but failed */
    115        1.1       leo 			return 0;
    116        1.6       leo 		card_probed = 0;
    117        1.6       leo 
    118        1.1       leo 		/*
    119        1.1       leo 		 * Check if the layers we depend on exist
    120        1.1       leo 		 */
    121       1.29   tsutsui 		if (!(machineid & ATARI_HADES))
    122        1.6       leo 			return 0;
    123        1.6       leo 		if (!et_probe_card())
    124        1.6       leo 			return 0;
    125        1.1       leo 		if (grfabs_probe(&et_probe_video) == 0)
    126        1.1       leo 			return 0;
    127        1.1       leo 		viewprobe();
    128        1.6       leo 		card_probed = 1; /* Probed and found */
    129        1.1       leo 	}
    130        1.1       leo 
    131        1.1       leo 	if (atari_realconfig == 0) {
    132        1.1       leo 		/*
    133       1.10       leo 		 * Early console init. Only match first unit.
    134        1.1       leo 		 */
    135       1.10       leo 		if (did_consinit)
    136        1.1       leo 			return 0;
    137       1.30   tsutsui 		if ((*view_cdevsw.d_open)(cf->cf_unit, 0, 0, NULL))
    138        1.1       leo 			return 0;
    139       1.30   tsutsui 		cfdata_grf = cf;
    140       1.10       leo 		did_consinit = 1;
    141        1.1       leo 		return 1;
    142        1.1       leo 	}
    143        1.1       leo 
    144        1.1       leo 	/*
    145        1.1       leo 	 * Normal config. When we are called directly from the grfbus,
    146       1.10       leo 	 * we only match the first unit. The attach function will call us for
    147        1.1       leo 	 * the other configured units.
    148        1.1       leo 	 */
    149        1.1       leo 	if (grf_auxp->from_bus_match
    150       1.10       leo 	    && ((did_consinit > 1) || !et_probe_card()))
    151        1.1       leo 		return 0;
    152        1.1       leo 
    153       1.30   tsutsui 	if (!grf_auxp->from_bus_match && (grf_auxp->unit != cf->cf_unit))
    154        1.1       leo 		return 0;
    155        1.1       leo 
    156        1.1       leo 	/*
    157        1.1       leo 	 * Final constraint: each grf needs a view....
    158        1.1       leo 	 */
    159       1.29   tsutsui 	if ((cfdata_grf == NULL) || (did_consinit > 1)) {
    160       1.30   tsutsui 		if ((*view_cdevsw.d_open)(cf->cf_unit, 0, 0, NULL))
    161       1.29   tsutsui 			return 0;
    162        1.1       leo 	}
    163       1.10       leo 	did_consinit = 2;
    164        1.1       leo 	return 1;
    165        1.1       leo }
    166        1.1       leo 
    167        1.1       leo /*
    168        1.1       leo  * attach: initialize the grf-structure and try to attach an ite to us.
    169       1.30   tsutsui  * note  : self is NULL during early console init.
    170        1.1       leo  */
    171       1.31   tsutsui static void
    172       1.30   tsutsui grfetattach(device_t parent, device_t self, void *aux)
    173        1.1       leo {
    174        1.1       leo 	static struct grf_softc		congrf;
    175       1.11       leo 	static int			first_attach = 1;
    176       1.30   tsutsui 	       grf_auxp_t		*grf_bus_auxp = aux;
    177        1.1       leo 	       grf_auxp_t		grf_auxp;
    178       1.30   tsutsui 	       struct grf_softc		*sc;
    179        1.1       leo 	       int			maj;
    180       1.13   gehenna 	extern const struct cdevsw grf_cdevsw;
    181        1.1       leo 
    182        1.1       leo 	/*
    183        1.1       leo 	 * find our major device number
    184        1.1       leo 	 */
    185       1.13   gehenna 	maj = cdevsw_lookup_major(&grf_cdevsw);
    186        1.1       leo 
    187        1.1       leo 	/*
    188       1.28       wiz 	 * Handle exception case: early console init
    189        1.1       leo 	 */
    190       1.30   tsutsui 	if (self == NULL) {
    191       1.30   tsutsui 		struct device itedev;
    192       1.30   tsutsui 
    193       1.30   tsutsui 		memset(&itedev, 0, sizeof(itedev));
    194       1.30   tsutsui 		itedev.dv_private = &congrf;
    195       1.30   tsutsui 
    196       1.11       leo 		congrf.g_unit    = cfdata_grf->cf_unit;
    197       1.11       leo 		congrf.g_grfdev  = makedev(maj, congrf.g_unit);
    198        1.1       leo 		congrf.g_itedev  = (dev_t)-1;
    199        1.1       leo 		congrf.g_flags   = GF_ALIVE;
    200        1.1       leo 		congrf.g_mode    = grf_mode;
    201        1.1       leo 		congrf.g_conpri  = CN_INTERNAL;
    202        1.1       leo 		congrf.g_viewdev = congrf.g_unit;
    203        1.1       leo 		grfet_iteinit(&congrf);
    204        1.1       leo 		grf_viewsync(&congrf);
    205        1.1       leo 
    206        1.1       leo 		/* Attach console ite */
    207       1.30   tsutsui 		atari_config_found(cfdata_grf, &itedev, &congrf, grfetprint);
    208        1.1       leo 		return;
    209        1.1       leo 	}
    210        1.1       leo 
    211       1.30   tsutsui 	sc = device_private(self);
    212       1.30   tsutsui 	sc->g_device = self;
    213       1.30   tsutsui 	sc->g_unit = device_unit(self);
    214       1.30   tsutsui 	grfsp[sc->g_unit] = sc;
    215        1.1       leo 
    216       1.30   tsutsui 	if ((cfdata_grf != NULL) && (sc->g_unit == congrf.g_unit)) {
    217        1.1       leo 		/*
    218        1.1       leo 		 * We inited earlier just copy the info, take care
    219        1.1       leo 		 * not to copy the device struct though.
    220        1.1       leo 		 */
    221       1.30   tsutsui 		memcpy(&sc->g_display, &congrf.g_display,
    222       1.30   tsutsui 			(char *)&sc[1] - (char *)&sc->g_display);
    223       1.29   tsutsui 	} else {
    224       1.30   tsutsui 		sc->g_grfdev  = makedev(maj, sc->g_unit);
    225       1.30   tsutsui 		sc->g_itedev  = (dev_t)-1;
    226       1.30   tsutsui 		sc->g_flags   = GF_ALIVE;
    227       1.30   tsutsui 		sc->g_mode    = grf_mode;
    228       1.30   tsutsui 		sc->g_conpri  = 0;
    229       1.30   tsutsui 		sc->g_viewdev = sc->g_unit;
    230       1.30   tsutsui 		grfet_iteinit(sc);
    231       1.30   tsutsui 		grf_viewsync(sc);
    232        1.1       leo 	}
    233        1.1       leo 
    234       1.30   tsutsui 	printf(": %dx%d", sc->g_display.gd_dwidth, sc->g_display.gd_dheight);
    235       1.30   tsutsui 	if (sc->g_display.gd_colors == 2)
    236        1.4  christos 		printf(" monochrome\n");
    237       1.29   tsutsui 	else
    238       1.30   tsutsui 		printf(" colors %d\n", sc->g_display.gd_colors);
    239        1.1       leo 
    240        1.1       leo 	/*
    241        1.1       leo 	 * try and attach an ite
    242        1.1       leo 	 */
    243  1.31.12.1   thorpej 	config_found(self, sc /* XXX */, grfetprint, CFARG_EOL);
    244        1.1       leo 
    245        1.1       leo 	/*
    246       1.11       leo 	 * If attaching the first unit, go ahead and 'find' the rest of us
    247        1.1       leo 	 */
    248       1.11       leo 	if (first_attach) {
    249       1.11       leo 		first_attach = 0;
    250        1.1       leo 		grf_auxp.from_bus_match = 0;
    251        1.1       leo 		for (grf_auxp.unit=0; grf_auxp.unit < NGRFET; grf_auxp.unit++) {
    252       1.30   tsutsui 			config_found(parent, (void*)&grf_auxp,
    253  1.31.12.1   thorpej 			    grf_bus_auxp->busprint, CFARG_EOL);
    254        1.1       leo 		}
    255        1.1       leo 	}
    256        1.1       leo }
    257        1.1       leo 
    258       1.31   tsutsui static int
    259       1.30   tsutsui grfetprint(void *aux, const char *pnp)
    260        1.1       leo {
    261       1.29   tsutsui 
    262       1.29   tsutsui 	if (pnp) /* XXX */
    263       1.16   thorpej 		aprint_normal("ite at %s", pnp);
    264       1.29   tsutsui 	return UNCONF;
    265        1.1       leo }
    266        1.1       leo 
    267        1.1       leo /*
    268        1.1       leo  * Init ite portion of grf_softc struct
    269        1.1       leo  */
    270        1.1       leo static void
    271       1.30   tsutsui grfet_iteinit(struct grf_softc *sc)
    272        1.1       leo {
    273        1.1       leo 
    274       1.30   tsutsui 	sc->g_itecursor = et_cursor;
    275       1.30   tsutsui 	sc->g_iteputc   = et_putc;
    276       1.30   tsutsui 	sc->g_iteclear  = et_clear;
    277       1.30   tsutsui 	sc->g_itescroll = et_scroll;
    278       1.30   tsutsui 	sc->g_iteinit   = view_init;
    279       1.30   tsutsui 	sc->g_itedeinit = view_deinit;
    280        1.1       leo }
    281        1.1       leo 
    282        1.1       leo static void
    283       1.22       dsl view_deinit(struct ite_softc *ip)
    284        1.1       leo {
    285        1.1       leo 	ip->flags &= ~ITE_INITED;
    286        1.1       leo }
    287        1.1       leo 
    288        1.1       leo static void
    289       1.22       dsl view_init(register struct ite_softc *ip)
    290        1.1       leo {
    291        1.1       leo 	struct itewinsize	wsz;
    292        1.1       leo 	ipriv_t			*cci;
    293        1.1       leo 	view_t			*view;
    294        1.3       leo 	save_area_t		*et_save;
    295        1.1       leo 
    296       1.29   tsutsui 	if ((cci = ip->priv) != NULL)
    297        1.1       leo 		return;
    298        1.1       leo 
    299        1.3       leo 	ip->itexx_ioctl = iteet_ioctl;
    300        1.3       leo 
    301        1.1       leo #if defined(KFONT_8X8)
    302        1.1       leo 	ip->font = font_info_8x8;
    303        1.1       leo #else
    304        1.1       leo 	ip->font = font_info_8x16;
    305        1.1       leo #endif
    306        1.1       leo 
    307        1.1       leo 	/* Find the correct set of rendering routines for this font.  */
    308       1.29   tsutsui 	if (ip->font.width != 8)
    309        1.1       leo 		panic("kernel font size not supported");
    310        1.1       leo 
    311       1.29   tsutsui 	if (!atari_realconfig)
    312        1.1       leo 		ip->priv = cci = &con_ipriv;
    313       1.29   tsutsui 	else
    314       1.29   tsutsui 		ip->priv = cci = malloc(sizeof(*cci), M_DEVBUF, M_WAITOK);
    315       1.29   tsutsui 	if (cci == NULL)
    316        1.1       leo 		panic("No memory for ite-view");
    317       1.24    cegger 	memset(cci, 0, sizeof(*cci));
    318        1.1       leo 
    319        1.1       leo 	wsz.x      = ite_default_x;
    320        1.1       leo 	wsz.y      = ite_default_y;
    321        1.1       leo 	wsz.width  = ite_default_width;
    322        1.1       leo 	wsz.height = ite_default_height;
    323        1.1       leo 	wsz.depth  = ite_default_depth;
    324        1.1       leo 
    325        1.1       leo 	ite_newsize (ip, &wsz);
    326        1.1       leo 
    327        1.1       leo 	view  = viewview(ip->grf->g_viewdev);
    328        1.1       leo 	cci->regkva = view->bitmap->regs;
    329        1.1       leo 
    330        1.1       leo 	/*
    331        1.1       leo 	 * Only console will be turned on by default..
    332        1.1       leo 	 */
    333       1.29   tsutsui 	if (ip->flags & ITE_ISCONS)
    334        1.1       leo 		ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
    335        1.1       leo 
    336        1.3       leo 	/*
    337        1.3       leo 	 * Activate text-mode settings
    338        1.3       leo 	 */
    339        1.3       leo 	et_save = (save_area_t *)view->save_area;
    340        1.3       leo 	if (et_save == NULL)
    341        1.3       leo 		et_inittextmode(ip, NULL, view->flags & VF_DISPLAY);
    342        1.3       leo 	else {
    343        1.3       leo 		et_inittextmode(ip, &et_save->sv_regs, view->flags&VF_DISPLAY);
    344        1.3       leo 		et_save->fb_size = ip->cols * ip->rows;
    345        1.3       leo 	}
    346        1.1       leo }
    347        1.1       leo 
    348        1.1       leo static int
    349       1.22       dsl ite_newsize(struct ite_softc *ip, struct itewinsize *winsz)
    350        1.1       leo {
    351        1.1       leo 	struct view_size	vs;
    352        1.1       leo 	int			error = 0;
    353        1.3       leo 	save_area_t		*et_save;
    354        1.1       leo 	view_t			*view;
    355       1.13   gehenna 	extern const struct cdevsw view_cdevsw;
    356        1.1       leo 
    357        1.1       leo 	vs.x      = winsz->x;
    358        1.1       leo 	vs.y      = winsz->y;
    359        1.1       leo 	vs.width  = winsz->width;
    360        1.1       leo 	vs.height = winsz->height;
    361        1.1       leo 	vs.depth  = winsz->depth;
    362        1.1       leo 
    363       1.13   gehenna 	error = (*view_cdevsw.d_ioctl)(ip->grf->g_viewdev, VIOCSSIZE,
    364       1.20  christos 				       (void *)&vs, 0, NOLWP);
    365        1.1       leo 	view  = viewview(ip->grf->g_viewdev);
    366        1.1       leo 
    367        1.1       leo 	/*
    368        1.1       leo 	 * Reinitialize our structs
    369        1.1       leo 	 */
    370        1.1       leo 	ip->cols = view->display.width  / ip->font.width;
    371        1.1       leo 	ip->rows = view->display.height / ip->font.height;
    372        1.1       leo 
    373        1.1       leo 	/*
    374        1.1       leo 	 * save new values so that future opens use them
    375        1.1       leo 	 * this may not be correct when we implement Virtual Consoles
    376        1.1       leo 	 */
    377        1.1       leo 	ite_default_height = view->display.height;
    378        1.1       leo 	ite_default_width  = view->display.width;
    379        1.1       leo 	ite_default_x      = view->display.x;
    380        1.1       leo 	ite_default_y      = view->display.y;
    381        1.1       leo 	ite_default_depth  = view->bitmap->depth;
    382        1.1       leo 
    383        1.3       leo 	et_save = (save_area_t *)view->save_area;
    384        1.3       leo 	if (et_save == NULL)
    385       1.29   tsutsui 		et_inittextmode(ip, NULL, view->flags & VF_DISPLAY);
    386        1.3       leo 	else {
    387       1.29   tsutsui 		et_inittextmode(ip, &et_save->sv_regs,
    388       1.29   tsutsui 		    view->flags & VF_DISPLAY);
    389       1.29   tsutsui 		et_save->fb_size = ip->cols * ip->rows;
    390        1.3       leo 	}
    391        1.3       leo 	et_clear(ip, 0, 0, ip->rows, ip->cols);
    392        1.3       leo 
    393       1.29   tsutsui 	return error;
    394        1.1       leo }
    395        1.1       leo 
    396        1.3       leo int
    397       1.29   tsutsui iteet_ioctl(struct ite_softc *ip, u_long cmd, void * addr, int flag,
    398       1.29   tsutsui     struct lwp *l)
    399        1.3       leo {
    400        1.3       leo 	struct winsize		ws;
    401        1.3       leo 	struct itewinsize	*is;
    402        1.3       leo 	int			error = 0;
    403        1.3       leo 	view_t			*view = viewview(ip->grf->g_viewdev);
    404       1.13   gehenna 	extern const struct cdevsw ite_cdevsw;
    405       1.13   gehenna 	extern const struct cdevsw view_cdevsw;
    406        1.3       leo 
    407        1.3       leo 	switch (cmd) {
    408        1.3       leo 	case ITEIOCSWINSZ:
    409        1.3       leo 		is = (struct itewinsize *)addr;
    410        1.3       leo 
    411       1.29   tsutsui 		if (ite_newsize(ip, is))
    412        1.3       leo 			error = ENOMEM;
    413        1.3       leo 		else {
    414        1.3       leo 			view         = viewview(ip->grf->g_viewdev);
    415        1.3       leo 			ws.ws_row    = ip->rows;
    416        1.3       leo 			ws.ws_col    = ip->cols;
    417        1.3       leo 			ws.ws_xpixel = view->display.width;
    418        1.3       leo 			ws.ws_ypixel = view->display.height;
    419        1.3       leo 			ite_reset(ip);
    420        1.3       leo 			/*
    421        1.3       leo 			 * XXX tell tty about the change
    422        1.3       leo 			 * XXX this is messy, but works
    423        1.3       leo 			 */
    424       1.13   gehenna 			(*ite_cdevsw.d_ioctl)(ip->grf->g_itedev, TIOCSWINSZ,
    425       1.20  christos 					      (void *)&ws, 0, l);
    426        1.3       leo 		}
    427        1.3       leo 		break;
    428        1.3       leo 	case VIOCSCMAP:
    429        1.3       leo 	case VIOCGCMAP:
    430        1.3       leo 		/*
    431       1.18  christos 		 * XXX watchout for that NOLWP. its not really the kernel
    432        1.3       leo 		 * XXX talking these two commands don't use the proc pointer
    433        1.3       leo 		 * XXX though.
    434        1.3       leo 		 */
    435       1.13   gehenna 		error = (*view_cdevsw.d_ioctl)(ip->grf->g_viewdev, cmd, addr,
    436       1.18  christos 					       flag, NOLWP);
    437        1.3       leo 		break;
    438        1.3       leo 	default:
    439       1.12    atatat 		error = EPASSTHROUGH;
    440        1.3       leo 		break;
    441        1.3       leo 	}
    442       1.29   tsutsui 	return error;
    443        1.3       leo }
    444        1.3       leo 
    445        1.1       leo void
    446       1.22       dsl et_cursor(struct ite_softc *ip, int flag)
    447        1.1       leo {
    448        1.1       leo 	volatile u_char	*ba;
    449        1.1       leo 		 view_t	*v;
    450        1.1       leo 		 u_long cpos;
    451        1.1       leo 
    452        1.1       leo 	ba = ((ipriv_t*)ip->priv)->regkva;
    453        1.1       leo 	v  = viewview(ip->grf->g_viewdev);
    454        1.1       leo 
    455        1.1       leo 	/*
    456        1.1       leo 	 * Don't update the cursor when not on display
    457        1.1       leo 	 */
    458        1.1       leo 	if (!(v->flags & VF_DISPLAY))
    459        1.1       leo 		return;
    460        1.1       leo 
    461        1.1       leo 	switch (flag) {
    462        1.1       leo  	    case DRAW_CURSOR:
    463        1.1       leo 		/*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
    464        1.1       leo 	    case MOVE_CURSOR:
    465        1.1       leo 		cpos  =  RCrt(ba, CRT_ID_START_ADDR_LOW) & 0xff;
    466        1.1       leo 		cpos |= (RCrt(ba, CRT_ID_START_ADDR_HIGH) & 0xff) << 8;
    467        1.1       leo 		cpos += ip->curx + ip->cury * ip->cols;
    468        1.1       leo 		WCrt(ba, CRT_ID_CURSOR_LOC_LOW, cpos & 0xff);
    469        1.1       leo 		WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, (cpos >> 8) & 0xff);
    470        1.1       leo 		WCrt(ba, CTR_ID_EXT_START, (cpos >> (16-2)) & 0x0c);
    471        1.1       leo 
    472        1.1       leo 		ip->cursorx = ip->curx;
    473        1.1       leo 		ip->cursory = ip->cury;
    474        1.1       leo 		break;
    475        1.1       leo 	    case ERASE_CURSOR:
    476        1.1       leo 		/*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
    477        1.1       leo 	    case START_CURSOROPT:
    478        1.1       leo 	    case END_CURSOROPT:
    479        1.1       leo 	    default:
    480        1.1       leo 		break;
    481        1.1       leo     	}
    482        1.1       leo }
    483        1.1       leo 
    484        1.1       leo void
    485       1.22       dsl et_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
    486        1.1       leo {
    487        1.1       leo 	view_t	*v   = viewview(ip->grf->g_viewdev);
    488        1.1       leo 	u_char	attr;
    489        1.1       leo 	u_short	*cp;
    490        1.1       leo 
    491        1.1       leo 	attr = (unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
    492        1.1       leo 	if (mode & ATTR_UL)     attr |= 0x01;
    493        1.1       leo 	if (mode & ATTR_BOLD)   attr |= 0x08;
    494        1.1       leo 	if (mode & ATTR_BLINK)  attr |= 0x80;
    495        1.1       leo 
    496        1.1       leo 	cp  = (u_short*)v->bitmap->plane;
    497        1.1       leo 	cp[(dy * ip->cols) + dx] = (c << 8) | attr;
    498        1.1       leo }
    499        1.1       leo 
    500        1.1       leo void
    501       1.22       dsl et_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
    502        1.1       leo {
    503        1.9       leo 	/* et_clear and et_scroll both rely on ite passing arguments
    504        1.1       leo 	 * which describe continuous regions.  For a VT200 terminal,
    505        1.1       leo 	 * this is safe behavior.
    506        1.1       leo 	 */
    507        1.1       leo 	view_t		*v   = viewview(ip->grf->g_viewdev);
    508        1.1       leo 	u_short		*dest;
    509        1.1       leo 	int		len;
    510        1.1       leo 
    511        1.1       leo 	dest = (u_short *)v->bitmap->plane + (sy * ip->cols) + sx;
    512       1.29   tsutsui 	for (len = w * h; len-- ;)
    513        1.1       leo 		*dest++ = 0x2007;
    514        1.1       leo }
    515        1.1       leo 
    516        1.1       leo void
    517       1.22       dsl et_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
    518        1.1       leo {
    519        1.1       leo 	view_t	*v   = viewview(ip->grf->g_viewdev);
    520        1.1       leo 	u_short	*fb;
    521        1.1       leo 	u_short	*src, *dst;
    522        1.1       leo 	int	len;
    523        1.1       leo 
    524        1.1       leo 	fb = (u_short*)v->bitmap->plane + sy * ip->cols;
    525        1.1       leo 	switch (dir) {
    526        1.1       leo 	    case SCROLL_UP:
    527        1.1       leo 			src = fb;
    528        1.1       leo 			dst = fb - count * ip->cols;
    529        1.1       leo 			len = (ip->bottom_margin + 1 - sy) * ip->cols;
    530        1.1       leo 			break;
    531        1.1       leo 	    case SCROLL_DOWN:
    532        1.1       leo 			src = fb;
    533        1.1       leo 			dst = fb + count * ip->cols;
    534        1.1       leo 			len = (ip->bottom_margin + 1 - (sy + count)) * ip->cols;
    535        1.1       leo 			break;
    536        1.1       leo 	    case SCROLL_RIGHT:
    537        1.1       leo 			src = fb + sx;
    538        1.1       leo 			dst = fb + sx + count;
    539        1.1       leo 			len = ip->cols - sx + count;
    540        1.1       leo 			break;
    541        1.1       leo 	    case SCROLL_LEFT:
    542        1.1       leo 			src = fb + sx;
    543        1.1       leo 			dst = fb + sx - count;
    544        1.1       leo 			len = ip->cols - sx;
    545        1.1       leo 			break;
    546        1.1       leo 	    default:
    547        1.1       leo 			return;
    548        1.1       leo 	}
    549        1.1       leo 	if (src > dst) {
    550        1.1       leo 		while (len--)
    551        1.1       leo 			*dst++ = *src++;
    552       1.29   tsutsui 	} else {
    553        1.1       leo 		src = &src[len];
    554        1.1       leo 		dst = &dst[len];
    555        1.1       leo 		while (len--)
    556        1.1       leo 			*--dst = *--src;
    557        1.1       leo 	}
    558        1.1       leo }
    559        1.1       leo 
    560        1.1       leo static void
    561       1.22       dsl et_inittextmode(struct ite_softc *ip, et_sv_reg_t *etregs, int loadfont)
    562        1.1       leo {
    563        1.1       leo 	volatile u_char *ba;
    564        1.1       leo 	font_info	*fd;
    565        1.1       leo 	u_char		*fb;
    566        1.1       leo 	u_char		*c, *f, tmp;
    567        1.1       leo 	u_short		z, y;
    568        1.1       leo 	int		s;
    569        1.1       leo 	view_t		*v   = viewview(ip->grf->g_viewdev);
    570        1.3       leo 	et_sv_reg_t	loc_regs;
    571        1.1       leo 
    572        1.3       leo 	if (etregs == NULL) {
    573        1.3       leo 		etregs = &loc_regs;
    574        1.3       leo 		et_hwsave(etregs);
    575        1.3       leo 	}
    576        1.1       leo 
    577        1.1       leo 	ba = ((ipriv_t*)ip->priv)->regkva;
    578        1.1       leo 	fb = v->bitmap->plane;
    579        1.1       leo 
    580        1.1       leo #if defined(KFONT_8X8)
    581        1.1       leo 	fd = &font_info_8x8;
    582        1.1       leo #else
    583        1.1       leo 	fd = &font_info_8x16;
    584        1.1       leo #endif
    585        1.1       leo 
    586        1.3       leo 	if (loadfont) { /* XXX: We should set the colormap */
    587        1.3       leo 		/*
    588        1.3       leo 		 * set colors (B&W)
    589        1.3       leo 		 */
    590        1.3       leo 		vgaw(ba, VDAC_ADDRESS_W, 0);
    591        1.3       leo 		for (z = 0; z < 256; z++) {
    592        1.3       leo 			y = (z & 1) ? ((z > 7) ? 2 : 1) : 0;
    593        1.1       leo 
    594        1.3       leo 			vgaw(ba, VDAC_DATA, etconscolors[y][0]);
    595        1.3       leo 			vgaw(ba, VDAC_DATA, etconscolors[y][1]);
    596        1.3       leo 			vgaw(ba, VDAC_DATA, etconscolors[y][2]);
    597        1.3       leo 		}
    598        1.1       leo 
    599        1.3       leo 		/*
    600        1.3       leo 		 * Enter a suitable mode to download the font. This
    601        1.3       leo 		 * basically means sequential addressing mode
    602        1.3       leo 		 */
    603        1.3       leo 		s = splhigh();
    604        1.1       leo 
    605        1.3       leo 		WAttr(ba, 0x20 | ACT_ID_ATTR_MODE_CNTL, 0x0a);
    606        1.3       leo 		WSeq(ba, SEQ_ID_MAP_MASK,	 0x04);
    607        1.3       leo 		WSeq(ba, SEQ_ID_MEMORY_MODE,	 0x06);
    608        1.3       leo 		WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x02);
    609        1.3       leo 		WGfx(ba, GCT_ID_GRAPHICS_MODE,	 0x00);
    610        1.3       leo 		WGfx(ba, GCT_ID_MISC,		 0x04);
    611        1.3       leo 		splx(s);
    612        1.1       leo 
    613        1.3       leo 		/*
    614        1.3       leo 		 * load text font into beginning of display memory. Each
    615        1.3       leo 		 * character cell is 32 bytes long (enough for 4 planes)
    616        1.3       leo 		 */
    617        1.3       leo 		for (z = 0, c = fb; z < 256 * 32; z++)
    618        1.3       leo 			*c++ = 0;
    619        1.1       leo 
    620        1.3       leo 		c = (unsigned char *) (fb) + (32 * fd->font_lo);
    621        1.3       leo 		f = fd->font_p;
    622        1.3       leo 		z = fd->font_lo;
    623        1.3       leo 		for (; z <= fd->font_hi; z++, c += (32 - fd->height))
    624        1.3       leo 			for (y = 0; y < fd->height; y++) {
    625        1.3       leo 				*c++ = *f++;
    626        1.3       leo 			}
    627        1.3       leo 	}
    628        1.1       leo 
    629        1.1       leo 	/*
    630        1.1       leo 	 * Odd/Even addressing
    631        1.1       leo 	 */
    632        1.3       leo 	etregs->seq[SEQ_ID_MAP_MASK]        = 0x03;
    633        1.3       leo 	etregs->seq[SEQ_ID_MEMORY_MODE]     = 0x03;
    634        1.3       leo 	etregs->grf[GCT_ID_READ_MAP_SELECT] = 0x00;
    635        1.3       leo 	etregs->grf[GCT_ID_GRAPHICS_MODE]   = 0x10;
    636        1.3       leo 	etregs->grf[GCT_ID_MISC]            = 0x06;
    637        1.1       leo 
    638        1.1       leo 	/*
    639        1.1       leo 	 * Font height + underline location
    640        1.1       leo 	 */
    641        1.3       leo 	tmp = etregs->crt[CRT_ID_MAX_ROW_ADDRESS] & 0xe0;
    642        1.3       leo 	etregs->crt[CRT_ID_MAX_ROW_ADDRESS] = tmp | (fd->height - 1);
    643        1.3       leo 	tmp = etregs->crt[CRT_ID_UNDERLINE_LOC] & 0xe0;
    644        1.3       leo 	etregs->crt[CRT_ID_UNDERLINE_LOC] = tmp | (fd->height - 1);
    645        1.1       leo 
    646        1.1       leo 	/*
    647        1.1       leo 	 * Cursor setup
    648        1.1       leo 	 */
    649        1.3       leo 	etregs->crt[CRT_ID_CURSOR_START]    = 0x00;
    650        1.3       leo 	etregs->crt[CRT_ID_CURSOR_END]      = fd->height - 1;
    651        1.3       leo 	etregs->crt[CRT_ID_CURSOR_LOC_HIGH] = 0x00;
    652        1.3       leo 	etregs->crt[CRT_ID_CURSOR_LOC_LOW]  = 0x00;
    653        1.1       leo 
    654        1.3       leo 	/*
    655        1.3       leo 	 * Enter text mode
    656        1.3       leo 	 */
    657        1.3       leo 	etregs->crt[CRT_ID_MODE_CONTROL]    = 0xa3;
    658        1.3       leo 	etregs->attr[ACT_ID_ATTR_MODE_CNTL] = 0x0a;
    659        1.1       leo 
    660        1.3       leo #if 1
    661        1.3       leo 	if (loadfont || (etregs == &loc_regs))
    662        1.3       leo #else
    663        1.3       leo 	if (etregs == &loc_regs)
    664        1.3       leo #endif
    665        1.3       leo 		et_hwrest(etregs);
    666        1.1       leo }
    667