Home | History | Annotate | Line # | Download | only in sbus
zx.c revision 1.16.10.1
      1  1.16.10.1      elad /*	$NetBSD: zx.c,v 1.16.10.1 2006/04/19 03:26:08 elad Exp $	*/
      2        1.1        ad 
      3        1.1        ad /*
      4        1.1        ad  *  Copyright (c) 2002 The NetBSD Foundation, Inc.
      5        1.1        ad  *  All rights reserved.
      6        1.1        ad  *
      7        1.1        ad  *  This code is derived from software contributed to The NetBSD Foundation
      8        1.1        ad  *  by Andrew Doran.
      9        1.1        ad  *
     10        1.1        ad  *  Redistribution and use in source and binary forms, with or without
     11        1.1        ad  *  modification, are permitted provided that the following conditions
     12        1.1        ad  *  are met:
     13        1.1        ad  *  1. Redistributions of source code must retain the above copyright
     14        1.1        ad  *     notice, this list of conditions and the following disclaimer.
     15        1.1        ad  *  2. Redistributions in binary form must reproduce the above copyright
     16        1.1        ad  *     notice, this list of conditions and the following disclaimer in the
     17        1.1        ad  *     documentation and/or other materials provided with the distribution.
     18        1.1        ad  *  3. All advertising materials mentioning features or use of this software
     19        1.1        ad  *     must display the following acknowledgement:
     20        1.1        ad  *         This product includes software developed by the NetBSD
     21        1.1        ad  *         Foundation, Inc. and its contributors.
     22        1.1        ad  *  4. Neither the name of The NetBSD Foundation nor the names of its
     23        1.1        ad  *     contributors may be used to endorse or promote products derived
     24        1.1        ad  *     from this software without specific prior written permission.
     25        1.1        ad  *
     26        1.1        ad  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27        1.1        ad  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28        1.1        ad  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29        1.1        ad  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30        1.1        ad  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31        1.1        ad  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32        1.1        ad  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33        1.1        ad  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34        1.1        ad  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35        1.1        ad  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36        1.1        ad  *  POSSIBILITY OF SUCH DAMAGE.
     37        1.1        ad  */
     38        1.1        ad 
     39        1.1        ad /*
     40        1.1        ad  * Driver for the Sun ZX display adapter.  This would be called 'leo', but
     41        1.1        ad  * NetBSD/amiga already has a driver by that name.  The XFree86 and Linux
     42        1.1        ad  * drivers were used as "living documentation" when writing this; thanks
     43        1.1        ad  * to the authors.
     44        1.1        ad  *
     45        1.1        ad  * Issues (which can be solved with wscons, happily enough):
     46        1.1        ad  *
     47        1.1        ad  * o There is lots of unnecessary mucking about rasops in here, primarily
     48        1.1        ad  *   to appease the sparc fb code.
     49        1.1        ad  *
     50        1.1        ad  * o RASTERCONSOLE is required.  X needs the board set up correctly, and
     51        1.1        ad  *   that's difficult to reconcile with using the PROM for output.
     52        1.1        ad  */
     53        1.1        ad 
     54        1.1        ad #include <sys/cdefs.h>
     55  1.16.10.1      elad __KERNEL_RCSID(0, "$NetBSD: zx.c,v 1.16.10.1 2006/04/19 03:26:08 elad Exp $");
     56        1.1        ad 
     57        1.1        ad #include <sys/param.h>
     58        1.1        ad #include <sys/systm.h>
     59        1.1        ad #include <sys/device.h>
     60        1.1        ad #include <sys/ioctl.h>
     61        1.1        ad #include <sys/malloc.h>
     62        1.1        ad #include <sys/mman.h>
     63        1.1        ad #include <sys/tty.h>
     64        1.1        ad #include <sys/conf.h>
     65        1.1        ad #include <sys/syslog.h>
     66        1.1        ad #include <sys/buf.h>
     67        1.1        ad 
     68        1.1        ad #include <machine/bus.h>
     69        1.1        ad #include <machine/autoconf.h>
     70        1.1        ad 
     71        1.1        ad #include <uvm/uvm_extern.h>
     72        1.1        ad 
     73        1.1        ad #include <dev/sun/fbio.h>
     74        1.1        ad #include <dev/sun/fbvar.h>
     75        1.1        ad 
     76        1.1        ad #include <dev/sbus/zxreg.h>
     77        1.1        ad #include <dev/sbus/zxvar.h>
     78        1.1        ad #include <dev/sbus/sbusvar.h>
     79        1.1        ad 
     80        1.1        ad #include <dev/wscons/wsconsio.h>
     81        1.1        ad 
     82        1.1        ad #ifndef RASTERCONSOLE
     83        1.1        ad #error Sorry, this driver needs the RASTERCONSOLE option
     84        1.1        ad #endif
     85        1.1        ad 
     86        1.1        ad /* Force 32-bit writes. */
     87        1.1        ad #define	SETREG(r, v)	(*((volatile u_int32_t *)&r) = (v))
     88        1.1        ad 
     89        1.1        ad #define	ZX_STD_ROP	(ZX_ROP_NEW | ZX_ATTR_WE_ENABLE | \
     90        1.1        ad     ZX_ATTR_OE_ENABLE | ZX_ATTR_FORCE_WID)
     91        1.1        ad 
     92        1.1        ad void	zx_attach(struct device *, struct device *, void *);
     93        1.1        ad int	zx_match(struct device *, struct cfdata *, void *);
     94        1.1        ad 
     95        1.1        ad void	zx_blank(struct device *);
     96        1.1        ad int	zx_cmap_put(struct zx_softc *);
     97        1.1        ad void	zx_copyrect(struct rasops_info *, int, int, int, int, int, int);
     98        1.1        ad int	zx_cross_loadwid(struct zx_softc *, u_int, u_int, u_int);
     99        1.1        ad int	zx_cross_wait(struct zx_softc *);
    100        1.1        ad void	zx_fillrect(struct rasops_info *, int, int, int, int, long, int);
    101        1.1        ad int	zx_intr(void *);
    102        1.1        ad void	zx_reset(struct zx_softc *);
    103        1.1        ad void	zx_unblank(struct device *);
    104        1.1        ad 
    105        1.1        ad void	zx_cursor_blank(struct zx_softc *);
    106        1.1        ad void	zx_cursor_color(struct zx_softc *);
    107        1.1        ad void	zx_cursor_move(struct zx_softc *);
    108        1.1        ad void	zx_cursor_set(struct zx_softc *);
    109        1.1        ad void	zx_cursor_unblank(struct zx_softc *);
    110        1.1        ad 
    111        1.1        ad void	zx_copycols(void *, int, int, int, int);
    112        1.1        ad void	zx_copyrows(void *, int, int, int);
    113        1.1        ad void	zx_cursor(void *, int, int, int);
    114        1.1        ad void	zx_do_cursor(struct rasops_info *);
    115        1.1        ad void	zx_erasecols(void *, int, int, int, long);
    116        1.1        ad void	zx_eraserows(void *, int, int, long);
    117        1.1        ad void	zx_putchar(void *, int, int, u_int, long);
    118        1.1        ad 
    119        1.1        ad struct zx_mmo {
    120        1.1        ad 	off_t	mo_va;
    121        1.1        ad 	off_t	mo_pa;
    122        1.1        ad 	off_t	mo_size;
    123        1.1        ad } static const zx_mmo[] = {
    124        1.1        ad 	{ ZX_FB0_VOFF,		ZX_OFF_SS0,		0x00800000 },
    125        1.1        ad 	{ ZX_LC0_VOFF,		ZX_OFF_LC_SS0_USR,	0x00001000 },
    126        1.1        ad 	{ ZX_LD0_VOFF,		ZX_OFF_LD_SS0,		0x00001000 },
    127        1.1        ad 	{ ZX_LX0_CURSOR_VOFF,	ZX_OFF_LX_CURSOR,	0x00001000 },
    128        1.1        ad 	{ ZX_FB1_VOFF,		ZX_OFF_SS1,		0x00800000 },
    129        1.1        ad 	{ ZX_LC1_VOFF,		ZX_OFF_LC_SS1_USR,	0x00001000 },
    130        1.1        ad 	{ ZX_LD1_VOFF,		ZX_OFF_LD_SS1,		0x00001000 },
    131        1.1        ad 	{ ZX_LX_KRN_VOFF,	ZX_OFF_LX_CROSS,	0x00001000 },
    132        1.1        ad 	{ ZX_LC0_KRN_VOFF,	ZX_OFF_LC_SS0_KRN,	0x00001000 },
    133        1.1        ad 	{ ZX_LC1_KRN_VOFF,	ZX_OFF_LC_SS1_KRN,	0x00001000 },
    134        1.1        ad 	{ ZX_LD_GBL_VOFF,	ZX_OFF_LD_GBL,		0x00001000 },
    135       1.14     perry };
    136        1.1        ad 
    137        1.4   thorpej CFATTACH_DECL(zx, sizeof(struct zx_softc),
    138        1.5   thorpej     zx_match, zx_attach, NULL, NULL);
    139        1.1        ad 
    140        1.1        ad extern struct cfdriver zx_cd;
    141        1.1        ad 
    142        1.1        ad dev_type_open(zxopen);
    143        1.1        ad dev_type_close(zxclose);
    144        1.1        ad dev_type_ioctl(zxioctl);
    145        1.1        ad dev_type_mmap(zxmmap);
    146        1.1        ad 
    147        1.1        ad static struct fbdriver zx_fbdriver = {
    148        1.1        ad 	zx_unblank, zxopen, zxclose, zxioctl, nopoll, zxmmap
    149        1.1        ad };
    150        1.1        ad 
    151        1.1        ad int
    152        1.1        ad zx_match(struct device *parent, struct cfdata *cf, void *aux)
    153        1.1        ad {
    154        1.1        ad 	struct sbus_attach_args *sa;
    155       1.14     perry 
    156        1.1        ad 	sa = (struct sbus_attach_args *)aux;
    157        1.1        ad 
    158        1.1        ad 	return (strcmp(sa->sa_name, "SUNW,leo") == 0);
    159        1.1        ad }
    160        1.1        ad 
    161        1.1        ad void
    162        1.1        ad zx_attach(struct device *parent, struct device *self, void *args)
    163        1.1        ad {
    164        1.1        ad 	struct zx_softc *sc;
    165        1.1        ad 	struct sbus_attach_args *sa;
    166        1.1        ad 	bus_space_handle_t bh;
    167        1.1        ad 	bus_space_tag_t bt;
    168        1.1        ad 	struct fbdevice *fb;
    169        1.1        ad 	struct rasops_info *ri;
    170        1.1        ad 	volatile struct zx_command *zc;
    171        1.1        ad 	int isconsole;
    172        1.1        ad 
    173        1.1        ad 	sc = (struct zx_softc *)self;
    174        1.1        ad 	sa = args;
    175        1.1        ad 	fb = &sc->sc_fb;
    176        1.1        ad 	ri = &fb->fb_rinfo;
    177        1.1        ad 	bt = sa->sa_bustag;
    178        1.1        ad 	sc->sc_bt = bt;
    179        1.1        ad 
    180        1.1        ad 	sc->sc_paddr = sbus_bus_addr(bt, sa->sa_slot, sa->sa_offset);
    181        1.1        ad 
    182        1.1        ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_SS0,
    183        1.1        ad 	    0x800000, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    184        1.1        ad 		printf("%s: can't map bits\n", self->dv_xname);
    185        1.1        ad 		return;
    186        1.1        ad 	}
    187        1.1        ad 	fb->fb_pixels = (caddr_t)bus_space_vaddr(bt, bh);
    188        1.1        ad 	sc->sc_pixels = (u_int32_t *)fb->fb_pixels;
    189        1.1        ad 
    190        1.1        ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LC_SS0_USR,
    191        1.1        ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    192        1.1        ad 		printf("%s: can't map zc\n", self->dv_xname);
    193        1.1        ad 		return;
    194        1.1        ad 	}
    195        1.1        ad 	sc->sc_zc = (struct zx_command *)bus_space_vaddr(bt, bh);
    196        1.1        ad 
    197        1.1        ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LD_SS0,
    198        1.1        ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    199        1.1        ad 		printf("%s: can't map ld/ss0\n", self->dv_xname);
    200        1.1        ad 		return;
    201        1.1        ad 	}
    202        1.1        ad 	sc->sc_zd_ss0 = (struct zx_draw *)bus_space_vaddr(bt, bh);
    203        1.1        ad 
    204        1.1        ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LD_SS1,
    205        1.1        ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    206        1.1        ad 		printf("%s: can't map ld/ss1\n", self->dv_xname);
    207        1.1        ad 		return;
    208        1.1        ad 	}
    209        1.1        ad 	sc->sc_zd_ss1 =
    210        1.1        ad 	    (struct zx_draw_ss1 *)bus_space_vaddr(bt, bh);
    211        1.1        ad 
    212        1.1        ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LX_CROSS,
    213        1.1        ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    214        1.1        ad 		printf("%s: can't map zx\n", self->dv_xname);
    215        1.1        ad 		return;
    216        1.1        ad 	}
    217        1.1        ad 	sc->sc_zx = (struct zx_cross *)bus_space_vaddr(bt, bh);
    218        1.1        ad 
    219        1.1        ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LX_CURSOR,
    220        1.1        ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    221        1.1        ad 		printf("%s: can't map zcu\n", self->dv_xname);
    222        1.1        ad 		return;
    223        1.1        ad 	}
    224        1.1        ad 	sc->sc_zcu = (struct zx_cursor *)bus_space_vaddr(bt, bh);
    225        1.1        ad 
    226        1.1        ad 	fb->fb_driver = &zx_fbdriver;
    227        1.1        ad 	fb->fb_device = &sc->sc_dv;
    228  1.16.10.1      elad 	fb->fb_flags = device_cfdata(&sc->sc_dv)->cf_flags & FB_USERMASK;
    229        1.1        ad 	fb->fb_pfour = NULL;
    230        1.1        ad 	fb->fb_linebytes = 8192;
    231        1.1        ad 
    232        1.1        ad 	fb_setsize_obp(fb, 32, 1280, 1024, sa->sa_node);
    233        1.1        ad 
    234        1.1        ad 	fb->fb_type.fb_cmsize = 256;
    235        1.1        ad 	fb->fb_type.fb_depth = 32;
    236        1.1        ad 	fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
    237        1.1        ad 	fb->fb_type.fb_type = FBTYPE_SUNLEO;
    238        1.1        ad 
    239        1.1        ad 	printf(": %d x %d", fb->fb_type.fb_width, fb->fb_type.fb_height);
    240        1.1        ad 	isconsole = fb_is_console(sa->sa_node);
    241        1.1        ad 	if (isconsole)
    242        1.1        ad 		printf(" (console)");
    243        1.1        ad 	printf("\n");
    244        1.1        ad 
    245        1.1        ad 	sbus_establish(&sc->sc_sd, &sc->sc_dv);
    246        1.1        ad 	if (sa->sa_nintr != 0)
    247        1.6        pk 		bus_intr_establish(bt, sa->sa_pri, IPL_NONE, zx_intr, sc);
    248        1.1        ad 
    249        1.1        ad 	sc->sc_cmap = malloc(768, M_DEVBUF, M_NOWAIT);
    250        1.1        ad 	fb_attach(&sc->sc_fb, isconsole);
    251        1.1        ad 	zx_reset(sc);
    252        1.1        ad 
    253        1.1        ad 	/*
    254        1.1        ad 	 * Attach to rcons.  XXX At this point, rasops_do_cursor() will be
    255        1.1        ad 	 * called before we get our hooks in place.  So, we mask off access
    256        1.1        ad 	 * to the framebuffer until it's done.
    257        1.1        ad 	 */
    258        1.1        ad 	zc = sc->sc_zc;
    259        1.1        ad 	SETREG(zc->zc_fontt, 1);
    260        1.1        ad 	SETREG(zc->zc_fontmsk, 0);
    261        1.1        ad 
    262        1.1        ad 	fbrcons_init(&sc->sc_fb);
    263        1.1        ad 
    264        1.1        ad 	SETREG(zc->zc_fontt, 0);
    265        1.1        ad 	SETREG(zc->zc_fontmsk, 0xffffffff);
    266        1.1        ad 
    267        1.1        ad 	ri->ri_hw = sc;
    268        1.1        ad 	ri->ri_do_cursor = zx_do_cursor;
    269        1.1        ad 	ri->ri_ops.copycols = zx_copycols;
    270        1.1        ad 	ri->ri_ops.copyrows = zx_copyrows;
    271        1.1        ad 	ri->ri_ops.erasecols = zx_erasecols;
    272        1.1        ad 	ri->ri_ops.eraserows = zx_eraserows;
    273        1.1        ad 	ri->ri_ops.putchar = zx_putchar;
    274        1.1        ad 
    275        1.1        ad 	sc->sc_fontw = ri->ri_font->fontwidth;
    276        1.1        ad 	sc->sc_fonth = ri->ri_font->fontheight;
    277        1.1        ad }
    278        1.1        ad 
    279        1.1        ad int
    280       1.16  christos zxopen(dev_t dev, int flags, int mode, struct lwp *l)
    281        1.1        ad {
    282        1.1        ad 
    283        1.1        ad 	if (device_lookup(&zx_cd, minor(dev)) == NULL)
    284        1.1        ad 		return (ENXIO);
    285        1.1        ad 	return (0);
    286        1.1        ad }
    287        1.1        ad 
    288        1.1        ad int
    289       1.16  christos zxclose(dev_t dev, int flags, int mode, struct lwp *l)
    290        1.1        ad {
    291        1.1        ad 	struct zx_softc *sc;
    292        1.1        ad 
    293        1.1        ad 	sc = (struct zx_softc *)device_lookup(&zx_cd, minor(dev));
    294        1.1        ad 
    295        1.1        ad 	zx_reset(sc);
    296        1.1        ad 	zx_cursor_blank(sc);
    297        1.1        ad 	return (0);
    298        1.1        ad }
    299        1.1        ad 
    300        1.1        ad int
    301       1.16  christos zxioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct lwp *l)
    302        1.1        ad {
    303        1.1        ad 	struct zx_softc *sc;
    304        1.1        ad 	struct fbcmap *cm;
    305        1.1        ad 	struct fbcursor *cu;
    306       1.13       chs 	uint32_t curbits[2][32];
    307        1.1        ad 	int rv, v, count, i;
    308        1.1        ad 
    309        1.1        ad 	sc = zx_cd.cd_devs[minor(dev)];
    310       1.14     perry 
    311        1.1        ad 	switch (cmd) {
    312        1.1        ad 	case FBIOGTYPE:
    313        1.1        ad 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    314        1.1        ad 		break;
    315        1.1        ad 
    316        1.1        ad 	case FBIOGATTR:
    317        1.1        ad #define fba ((struct fbgattr *)data)
    318        1.1        ad 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    319        1.1        ad 		fba->owner = 0;		/* XXX ??? */
    320        1.1        ad 		fba->fbtype = sc->sc_fb.fb_type;
    321        1.1        ad 		fba->sattr.flags = 0;
    322        1.1        ad 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    323        1.1        ad 		fba->sattr.dev_specific[0] = -1;
    324        1.1        ad 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    325        1.1        ad 		fba->emu_types[1] = -1;
    326        1.1        ad 		fba->emu_types[2] = -1;
    327        1.1        ad #undef fba
    328        1.1        ad 		break;
    329        1.1        ad 
    330        1.1        ad 	case FBIOGVIDEO:
    331        1.1        ad 		*(int *)data = ((sc->sc_flags & ZX_BLANKED) != 0);
    332        1.1        ad 		break;
    333        1.1        ad 
    334        1.1        ad 	case FBIOSVIDEO:
    335        1.1        ad 		if (*(int *)data)
    336        1.1        ad 			zx_unblank(&sc->sc_dv);
    337        1.1        ad 		else
    338        1.1        ad 			zx_blank(&sc->sc_dv);
    339        1.1        ad 		break;
    340        1.1        ad 
    341        1.1        ad 	case FBIOGETCMAP:
    342        1.1        ad 		cm = (struct fbcmap *)data;
    343        1.1        ad 		if (cm->index > 256 || cm->count > 256 - cm->index)
    344        1.1        ad 			return (EINVAL);
    345        1.1        ad 		rv = copyout(sc->sc_cmap + cm->index, cm->red, cm->count);
    346        1.2        ad 		if (rv == 0)
    347        1.1        ad 			rv = copyout(sc->sc_cmap + 256 + cm->index, cm->green,
    348        1.1        ad 			    cm->count);
    349        1.2        ad 		if (rv == 0)
    350        1.1        ad 			rv = copyout(sc->sc_cmap + 512 + cm->index, cm->blue,
    351        1.1        ad 			    cm->count);
    352        1.1        ad 		return (rv);
    353        1.1        ad 
    354        1.1        ad 	case FBIOPUTCMAP:
    355        1.1        ad 		cm = (struct fbcmap *)data;
    356        1.1        ad 		if (cm->index > 256 || cm->count > 256 - cm->index)
    357        1.1        ad 			return (EINVAL);
    358        1.1        ad 		rv = copyin(cm->red, sc->sc_cmap + cm->index, cm->count);
    359        1.2        ad 		if (rv == 0)
    360        1.1        ad 			rv = copyin(cm->green, sc->sc_cmap + 256 + cm->index,
    361        1.1        ad 			    cm->count);
    362        1.2        ad 		if (rv == 0)
    363        1.1        ad 			rv = copyin(cm->blue, sc->sc_cmap + 512 + cm->index,
    364        1.1        ad 			    cm->count);
    365        1.1        ad 		zx_cmap_put(sc);
    366        1.1        ad 		return (rv);
    367        1.1        ad 
    368        1.1        ad 	case FBIOGCURPOS:
    369        1.1        ad 		*(struct fbcurpos *)data = sc->sc_curpos;
    370        1.1        ad 		break;
    371        1.1        ad 
    372        1.1        ad 	case FBIOSCURPOS:
    373        1.1        ad 		sc->sc_curpos = *(struct fbcurpos *)data;
    374        1.1        ad 		zx_cursor_move(sc);
    375        1.1        ad 		break;
    376        1.1        ad 
    377        1.1        ad 	case FBIOGCURMAX:
    378        1.1        ad 		((struct fbcurpos *)data)->x = 32;
    379        1.1        ad 		((struct fbcurpos *)data)->y = 32;
    380        1.1        ad 		break;
    381        1.1        ad 
    382        1.1        ad 	case FBIOSCURSOR:
    383        1.1        ad 		cu = (struct fbcursor *)data;
    384        1.1        ad 		v = cu->set;
    385        1.1        ad 
    386        1.1        ad 		if ((v & FB_CUR_SETSHAPE) != 0) {
    387        1.1        ad 			if ((u_int)cu->size.x > 32 || (u_int)cu->size.y > 32)
    388        1.1        ad 				return (EINVAL);
    389        1.1        ad 			count = cu->size.y * 4;
    390       1.13       chs 			rv = copyin(cu->mask, curbits[0], count);
    391       1.13       chs 			if (rv)
    392       1.13       chs 				return rv;
    393       1.13       chs 			rv = copyin(cu->image, curbits[1], count);
    394       1.13       chs 			if (rv)
    395       1.13       chs 				return rv;
    396        1.1        ad 		}
    397        1.1        ad 		if ((v & FB_CUR_SETCUR) != 0) {
    398        1.1        ad 			if (cu->enable)
    399        1.1        ad 				zx_cursor_unblank(sc);
    400        1.1        ad 			else
    401        1.1        ad 				zx_cursor_blank(sc);
    402        1.1        ad 		}
    403        1.1        ad 		if ((v & (FB_CUR_SETPOS | FB_CUR_SETHOT)) != 0) {
    404        1.1        ad 			if ((v & FB_CUR_SETPOS) != 0)
    405        1.1        ad 				sc->sc_curpos = cu->pos;
    406        1.1        ad 			if ((v & FB_CUR_SETHOT) != 0)
    407        1.1        ad 				sc->sc_curhot = cu->hot;
    408        1.1        ad 			zx_cursor_move(sc);
    409        1.1        ad 		}
    410        1.1        ad 		if ((v & FB_CUR_SETCMAP) != 0) {
    411        1.1        ad 			if (cu->cmap.index > 2 ||
    412        1.1        ad 			    cu->cmap.count > 2 - cu->cmap.index)
    413        1.1        ad 				return (EINVAL);
    414        1.1        ad 			for (i = 0; i < cu->cmap.count; i++) {
    415        1.1        ad 				if ((v = fubyte(&cu->cmap.red[i])) < 0)
    416        1.1        ad 					return (EFAULT);
    417        1.1        ad 				sc->sc_curcmap[i + cu->cmap.index + 0] = v;
    418        1.1        ad 				if ((v = fubyte(&cu->cmap.green[i])) < 0)
    419        1.1        ad 					return (EFAULT);
    420        1.1        ad 				sc->sc_curcmap[i + cu->cmap.index + 2] = v;
    421        1.1        ad 				if ((v = fubyte(&cu->cmap.blue[i])) < 0)
    422        1.1        ad 					return (EFAULT);
    423        1.1        ad 				sc->sc_curcmap[i + cu->cmap.index + 4] = v;
    424        1.1        ad 			}
    425        1.1        ad 			zx_cursor_color(sc);
    426        1.1        ad 		}
    427        1.1        ad 		if ((v & FB_CUR_SETSHAPE) != 0) {
    428        1.1        ad 			sc->sc_cursize = cu->size;
    429        1.1        ad 			count = cu->size.y * 4;
    430        1.1        ad 			memset(sc->sc_curbits, 0, sizeof(sc->sc_curbits));
    431       1.13       chs 			memcpy(sc->sc_curbits[0], curbits[0], count);
    432       1.13       chs 			memcpy(sc->sc_curbits[1], curbits[1], count);
    433        1.1        ad 			zx_cursor_set(sc);
    434        1.1        ad 		}
    435        1.1        ad 		break;
    436        1.1        ad 
    437        1.1        ad 	case FBIOGCURSOR:
    438        1.1        ad 		cu = (struct fbcursor *)data;
    439        1.1        ad 
    440        1.1        ad 		cu->set = FB_CUR_SETALL;
    441        1.1        ad 		cu->enable = ((sc->sc_flags & ZX_CURSOR) != 0);
    442        1.1        ad 		cu->pos = sc->sc_curpos;
    443        1.1        ad 		cu->hot = sc->sc_curhot;
    444        1.1        ad 		cu->size = sc->sc_cursize;
    445        1.1        ad 
    446        1.1        ad 		if (cu->image != NULL) {
    447        1.1        ad 			count = sc->sc_cursize.y * 4;
    448       1.13       chs 			rv = copyout(sc->sc_curbits[1], cu->image, count);
    449        1.1        ad 			if (rv)
    450        1.1        ad 				return (rv);
    451       1.13       chs 			rv = copyout(sc->sc_curbits[0], cu->mask, count);
    452        1.1        ad 			if (rv)
    453        1.1        ad 				return (rv);
    454        1.1        ad 		}
    455        1.1        ad 		if (cu->cmap.red != NULL) {
    456        1.1        ad 			if (cu->cmap.index > 2 ||
    457        1.1        ad 			    cu->cmap.count > 2 - cu->cmap.index)
    458        1.1        ad 				return (EINVAL);
    459        1.1        ad 			for (i = 0; i < cu->cmap.count; i++) {
    460        1.1        ad 				v = sc->sc_curcmap[i + cu->cmap.index + 0];
    461        1.1        ad 				if (subyte(&cu->cmap.red[i], v))
    462        1.1        ad 					return (EFAULT);
    463        1.1        ad 				v = sc->sc_curcmap[i + cu->cmap.index + 2];
    464        1.1        ad 				if (subyte(&cu->cmap.green[i], v))
    465        1.1        ad 					return (EFAULT);
    466        1.1        ad 				v = sc->sc_curcmap[i + cu->cmap.index + 4];
    467        1.1        ad 				if (subyte(&cu->cmap.blue[i], v))
    468        1.1        ad 					return (EFAULT);
    469        1.1        ad 			}
    470        1.1        ad 		} else {
    471        1.1        ad 			cu->cmap.index = 0;
    472        1.1        ad 			cu->cmap.count = 2;
    473        1.1        ad 		}
    474        1.1        ad 		break;
    475        1.1        ad 
    476        1.1        ad 	default:
    477        1.1        ad #ifdef DEBUG
    478        1.1        ad 		log(LOG_NOTICE, "zxioctl(0x%lx) (%s[%d])\n", cmd,
    479        1.8      fvdl 		    p->p_comm, p->p_pid);
    480        1.1        ad #endif
    481        1.1        ad 		return (ENOTTY);
    482        1.1        ad 	}
    483        1.1        ad 
    484        1.1        ad 	return (0);
    485        1.1        ad }
    486        1.1        ad 
    487        1.1        ad int
    488        1.1        ad zx_intr(void *cookie)
    489        1.1        ad {
    490        1.1        ad 
    491        1.1        ad 	return (1);
    492        1.1        ad }
    493        1.1        ad 
    494        1.1        ad void
    495        1.1        ad zx_reset(struct zx_softc *sc)
    496        1.1        ad {
    497        1.1        ad 	volatile struct zx_draw *zd;
    498        1.1        ad 	volatile struct zx_command *zc;
    499        1.1        ad 	struct fbtype *fbt;
    500        1.1        ad 	u_int i;
    501        1.1        ad 
    502        1.1        ad 	zd = sc->sc_zd_ss0;
    503        1.1        ad 	zc = sc->sc_zc;
    504        1.1        ad 	fbt = &sc->sc_fb.fb_type;
    505        1.1        ad 
    506        1.1        ad 	zx_cross_loadwid(sc, ZX_WID_DBL_8, 0, 0x2c0);
    507        1.1        ad 	zx_cross_loadwid(sc, ZX_WID_DBL_8, 1, 0x30);
    508        1.1        ad 	zx_cross_loadwid(sc, ZX_WID_DBL_8, 2, 0x20);
    509        1.1        ad 	zx_cross_loadwid(sc, ZX_WID_DBL_24, 1, 0x30);
    510        1.1        ad 
    511        1.1        ad 	i = sc->sc_zd_ss1->zd_misc;
    512        1.1        ad 	i |= ZX_SS1_MISC_ENABLE;
    513        1.1        ad 	SETREG(sc->sc_zd_ss1->zd_misc, i);
    514        1.1        ad 
    515        1.2        ad 	SETREG(zd->zd_wid, 0xffffffff);
    516        1.2        ad 	SETREG(zd->zd_widclip, 0);
    517        1.1        ad 	SETREG(zd->zd_wmask, 0xffff);
    518        1.1        ad 	SETREG(zd->zd_vclipmin, 0);
    519        1.1        ad 	SETREG(zd->zd_vclipmax,
    520        1.1        ad 	    (fbt->fb_width - 1) | ((fbt->fb_height - 1) << 16));
    521        1.1        ad 	SETREG(zd->zd_fg, 0);
    522        1.1        ad 	SETREG(zd->zd_planemask, 0xff000000);
    523        1.1        ad 	SETREG(zd->zd_rop, ZX_STD_ROP);
    524        1.1        ad 
    525        1.1        ad 	SETREG(zc->zc_extent,
    526        1.1        ad 	    (fbt->fb_width - 1) | ((fbt->fb_height - 1) << 11));
    527        1.1        ad 	SETREG(zc->zc_addrspace, ZX_ADDRSPC_FONT_OBGR);
    528        1.1        ad 	SETREG(zc->zc_fontt, 0);
    529        1.1        ad 
    530        1.1        ad 	for (i = 0; i < 256; i++) {
    531        1.1        ad 		sc->sc_cmap[i] = rasops_cmap[i * 3];
    532        1.1        ad 		sc->sc_cmap[i + 256] = rasops_cmap[i * 3 + 1];
    533        1.1        ad 		sc->sc_cmap[i + 512] = rasops_cmap[i * 3 + 2];
    534        1.1        ad 	}
    535        1.1        ad 
    536        1.1        ad 	zx_cmap_put(sc);
    537        1.1        ad }
    538        1.1        ad 
    539        1.1        ad int
    540        1.1        ad zx_cross_wait(struct zx_softc *sc)
    541        1.1        ad {
    542        1.1        ad 	volatile struct zx_cross *zx;
    543        1.1        ad 	int i;
    544        1.1        ad 
    545        1.1        ad 	zx = sc->sc_zx;
    546        1.1        ad 
    547        1.1        ad 	for (i = 300000; i != 0; i--) {
    548        1.1        ad 		if ((zx->zx_csr & ZX_CROSS_CSR_PROGRESS) == 0)
    549        1.1        ad 			break;
    550        1.1        ad 		DELAY(1);
    551        1.1        ad 	}
    552        1.1        ad 
    553        1.1        ad 	if (i == 0)
    554        1.1        ad 		printf("zx_cross_wait: timed out\n");
    555        1.1        ad 
    556        1.1        ad 	return (i);
    557        1.1        ad }
    558        1.1        ad 
    559        1.1        ad int
    560        1.1        ad zx_cross_loadwid(struct zx_softc *sc, u_int type, u_int index, u_int value)
    561        1.1        ad {
    562        1.1        ad 	volatile struct zx_cross *zx;
    563       1.12       chs 	u_int tmp = 0;
    564        1.1        ad 
    565        1.1        ad 	zx = sc->sc_zx;
    566        1.1        ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_WID);
    567        1.1        ad 
    568        1.1        ad 	if (zx_cross_wait(sc))
    569        1.1        ad 		return (1);
    570        1.1        ad 
    571        1.1        ad 	if (type == ZX_WID_DBL_8)
    572        1.1        ad 		tmp = (index & 0x0f) + 0x40;
    573        1.1        ad 	else if (type == ZX_WID_DBL_24)
    574        1.1        ad 		tmp = index & 0x3f;
    575        1.1        ad 
    576        1.1        ad 	SETREG(zx->zx_type, 0x5800 + tmp);
    577        1.1        ad 	SETREG(zx->zx_value, value);
    578        1.1        ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_WID);
    579        1.1        ad 	SETREG(zx->zx_csr, ZX_CROSS_CSR_UNK | ZX_CROSS_CSR_UNK2);
    580        1.1        ad 
    581        1.1        ad 	return (0);
    582        1.1        ad }
    583        1.1        ad 
    584        1.1        ad int
    585        1.1        ad zx_cmap_put(struct zx_softc *sc)
    586        1.1        ad {
    587        1.1        ad 	volatile struct zx_cross *zx;
    588        1.1        ad 	const u_char *b;
    589        1.1        ad 	u_int i, t;
    590        1.1        ad 
    591        1.1        ad 	zx = sc->sc_zx;
    592        1.1        ad 
    593        1.1        ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_CLUT0);
    594        1.1        ad 	if (zx_cross_wait(sc))
    595        1.1        ad 		return (1);
    596        1.1        ad 
    597        1.1        ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_CLUTDATA);
    598        1.1        ad 
    599        1.1        ad 	for (i = 0, b = sc->sc_cmap; i < 256; i++) {
    600        1.1        ad 		t = b[i];
    601        1.1        ad 		t |= b[i + 256] << 8;
    602        1.1        ad 		t |= b[i + 512] << 16;
    603        1.1        ad 		SETREG(zx->zx_value, t);
    604        1.1        ad 	}
    605        1.1        ad 
    606        1.1        ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_CLUT0);
    607        1.1        ad 	i = zx->zx_csr;
    608        1.1        ad 	i = i | ZX_CROSS_CSR_UNK | ZX_CROSS_CSR_UNK2;
    609        1.1        ad 	SETREG(zx->zx_csr, i);
    610        1.1        ad 	return (0);
    611        1.1        ad }
    612        1.1        ad 
    613        1.1        ad void
    614        1.1        ad zx_cursor_move(struct zx_softc *sc)
    615        1.1        ad {
    616        1.1        ad 	volatile struct zx_cursor *zcu;
    617        1.1        ad 	int sx, sy, x, y;
    618        1.1        ad 
    619        1.1        ad 	x = sc->sc_curpos.x - sc->sc_curhot.x;
    620        1.1        ad 	y = sc->sc_curpos.y - sc->sc_curhot.y;
    621        1.1        ad 	zcu = sc->sc_zcu;
    622        1.1        ad 
    623        1.1        ad 	if (x < 0) {
    624        1.1        ad 		sx = min(-x, 32);
    625        1.1        ad 		x = 0;
    626        1.1        ad 	} else
    627        1.1        ad 		sx = 0;
    628        1.1        ad 
    629        1.1        ad 	if (y < 0) {
    630        1.1        ad 		sy = min(-y, 32);
    631        1.1        ad 		y = 0;
    632        1.1        ad 	} else
    633        1.1        ad 		sy = 0;
    634        1.1        ad 
    635        1.1        ad 	if (sx != sc->sc_shiftx || sy != sc->sc_shifty) {
    636        1.1        ad 		sc->sc_shiftx = sx;
    637        1.1        ad 		sc->sc_shifty = sy;
    638        1.1        ad 		zx_cursor_set(sc);
    639        1.1        ad 	}
    640        1.1        ad 
    641        1.1        ad 	SETREG(zcu->zcu_sxy, ((y & 0x7ff) << 11) | (x & 0x7ff));
    642        1.1        ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x30);
    643        1.1        ad 
    644        1.1        ad 	/* XXX Necessary? */
    645        1.1        ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x80);
    646        1.1        ad }
    647        1.1        ad 
    648        1.1        ad void
    649        1.1        ad zx_cursor_set(struct zx_softc *sc)
    650        1.1        ad {
    651        1.1        ad 	volatile struct zx_cursor *zcu;
    652        1.1        ad 	int i, j, data;
    653        1.1        ad 
    654        1.1        ad 	zcu = sc->sc_zcu;
    655        1.2        ad 
    656        1.2        ad 	if ((sc->sc_flags & ZX_CURSOR) != 0)
    657        1.2        ad 		SETREG(zcu->zcu_misc, zcu->zcu_misc & ~0x80);
    658        1.1        ad 
    659        1.1        ad 	for (j = 0; j < 2; j++) {
    660       1.11        ad 		SETREG(zcu->zcu_type, 0x20 << j);
    661        1.2        ad 
    662        1.1        ad 		for (i = sc->sc_shifty; i < 32; i++) {
    663        1.1        ad 			data = sc->sc_curbits[j][i];
    664        1.1        ad 			SETREG(zcu->zcu_data, data >> sc->sc_shiftx);
    665        1.1        ad 		}
    666        1.1        ad 		for (i = sc->sc_shifty; i != 0; i--)
    667        1.1        ad 			SETREG(zcu->zcu_data, 0);
    668        1.1        ad 	}
    669        1.2        ad 
    670        1.2        ad 	if ((sc->sc_flags & ZX_CURSOR) != 0)
    671        1.2        ad 		SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x80);
    672        1.1        ad }
    673        1.1        ad 
    674        1.1        ad void
    675        1.1        ad zx_cursor_blank(struct zx_softc *sc)
    676        1.1        ad {
    677        1.1        ad 	volatile struct zx_cursor *zcu;
    678        1.1        ad 
    679        1.1        ad 	sc->sc_flags &= ~ZX_CURSOR;
    680        1.1        ad 	zcu = sc->sc_zcu;
    681        1.1        ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc & ~0x80);
    682        1.1        ad }
    683        1.1        ad 
    684        1.1        ad void
    685        1.1        ad zx_cursor_unblank(struct zx_softc *sc)
    686        1.1        ad {
    687        1.1        ad 	volatile struct zx_cursor *zcu;
    688        1.1        ad 
    689        1.1        ad 	sc->sc_flags |= ZX_CURSOR;
    690        1.1        ad 	zcu = sc->sc_zcu;
    691        1.1        ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x80);
    692        1.1        ad }
    693        1.1        ad 
    694        1.1        ad void
    695        1.1        ad zx_cursor_color(struct zx_softc *sc)
    696        1.1        ad {
    697        1.1        ad 	volatile struct zx_cursor *zcu;
    698        1.1        ad 	u_int8_t tmp;
    699        1.1        ad 
    700        1.1        ad 	zcu = sc->sc_zcu;
    701        1.1        ad 
    702        1.1        ad 	SETREG(zcu->zcu_type, 0x50);
    703        1.1        ad 
    704        1.1        ad 	tmp = sc->sc_curcmap[0] | (sc->sc_curcmap[2] << 8) |
    705        1.1        ad 	    (sc->sc_curcmap[4] << 16);
    706        1.1        ad 	SETREG(zcu->zcu_data, tmp);
    707        1.1        ad 
    708        1.1        ad 	tmp = sc->sc_curcmap[1] | (sc->sc_curcmap[3] << 8) |
    709        1.1        ad 	    (sc->sc_curcmap[5] << 16);
    710        1.1        ad 	SETREG(zcu->zcu_data, sc->sc_curcmap[1]);
    711        1.1        ad 
    712        1.1        ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x03);
    713        1.1        ad }
    714        1.1        ad 
    715        1.1        ad void
    716        1.1        ad zx_blank(struct device *dv)
    717        1.1        ad {
    718        1.1        ad 	struct zx_softc *sc;
    719        1.1        ad 	volatile struct zx_cross *zx;
    720        1.1        ad 
    721        1.1        ad 	sc = (struct zx_softc *)dv;
    722        1.1        ad 
    723        1.1        ad 	if ((sc->sc_flags & ZX_BLANKED) != 0)
    724        1.1        ad 		return;
    725        1.1        ad 	sc->sc_flags |= ZX_BLANKED;
    726        1.1        ad 
    727        1.1        ad 	zx = sc->sc_zx;
    728        1.1        ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_VIDEO);
    729        1.1        ad 	SETREG(zx->zx_csr, zx->zx_csr & ~ZX_CROSS_CSR_ENABLE);
    730        1.1        ad }
    731        1.1        ad 
    732        1.1        ad void
    733        1.1        ad zx_unblank(struct device *dv)
    734        1.1        ad {
    735        1.1        ad 	struct zx_softc *sc;
    736        1.1        ad 	volatile struct zx_cross *zx;
    737        1.1        ad 
    738        1.1        ad 	sc = (struct zx_softc *)dv;
    739        1.1        ad 
    740        1.1        ad 	if ((sc->sc_flags & ZX_BLANKED) == 0)
    741        1.1        ad 		return;
    742        1.1        ad 	sc->sc_flags &= ~ZX_BLANKED;
    743        1.1        ad 
    744        1.1        ad 	zx = sc->sc_zx;
    745        1.1        ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_VIDEO);
    746        1.1        ad 	SETREG(zx->zx_csr, zx->zx_csr | ZX_CROSS_CSR_ENABLE);
    747        1.1        ad }
    748        1.1        ad 
    749        1.1        ad paddr_t
    750        1.1        ad zxmmap(dev_t dev, off_t off, int prot)
    751        1.1        ad {
    752        1.1        ad 	struct zx_softc *sc;
    753       1.15   tsutsui 	const struct zx_mmo *mm, *mmmax;
    754        1.2        ad 
    755        1.1        ad 	sc = device_lookup(&zx_cd, minor(dev));
    756        1.2        ad 	off = trunc_page(off);
    757        1.1        ad 	mm = zx_mmo;
    758       1.15   tsutsui 	mmmax = mm + sizeof(zx_mmo) / sizeof(zx_mmo[0]);
    759        1.1        ad 
    760       1.15   tsutsui 	for (; mm < mmmax; mm++)
    761        1.1        ad 		if (off >= mm->mo_va && off < mm->mo_va + mm->mo_size) {
    762        1.1        ad 			off = off - mm->mo_va + mm->mo_pa;
    763        1.1        ad 			return (bus_space_mmap(sc->sc_bt, sc->sc_paddr,
    764        1.1        ad 			    off, prot, BUS_SPACE_MAP_LINEAR));
    765        1.1        ad 		}
    766        1.1        ad 
    767        1.1        ad 	return (-1);
    768        1.1        ad }
    769        1.1        ad 
    770        1.1        ad void
    771        1.1        ad zx_fillrect(struct rasops_info *ri, int x, int y, int w, int h, long attr,
    772        1.1        ad 	    int rop)
    773        1.1        ad {
    774        1.1        ad 	struct zx_softc *sc;
    775        1.1        ad 	volatile struct zx_command *zc;
    776        1.1        ad 	volatile struct zx_draw *zd;
    777        1.1        ad 	int fg, bg;
    778        1.1        ad 
    779        1.1        ad 	sc = ri->ri_hw;
    780        1.1        ad 	zc = sc->sc_zc;
    781        1.1        ad 	zd = sc->sc_zd_ss0;
    782        1.1        ad 
    783        1.1        ad 	rasops_unpack_attr(attr, &fg, &bg, NULL);
    784        1.1        ad 	x = x * sc->sc_fontw + ri->ri_xorigin;
    785        1.1        ad 	y = y * sc->sc_fonth + ri->ri_yorigin;
    786        1.1        ad 	w = sc->sc_fontw * w - 1;
    787        1.1        ad 	h = sc->sc_fonth * h - 1;
    788        1.1        ad 
    789        1.1        ad 	while ((zc->zc_csr & ZX_CSR_BLT_BUSY) != 0)
    790        1.1        ad 		;
    791        1.1        ad 
    792        1.1        ad 	SETREG(zd->zd_rop, rop);
    793        1.1        ad 	SETREG(zd->zd_fg, (bg & 7) ? 0x00000000 : 0xff000000);
    794        1.1        ad 	SETREG(zc->zc_extent, w | (h << 11));
    795        1.1        ad 	SETREG(zc->zc_fill, x | (y << 11) | 0x80000000);
    796        1.1        ad }
    797        1.1        ad 
    798        1.1        ad void
    799        1.1        ad zx_copyrect(struct rasops_info *ri, int sx, int sy, int dx, int dy, int w,
    800        1.1        ad 	    int h)
    801        1.1        ad {
    802        1.1        ad 	struct zx_softc *sc;
    803        1.1        ad 	volatile struct zx_command *zc;
    804        1.1        ad 	volatile struct zx_draw *zd;
    805        1.1        ad 	int dir;
    806        1.1        ad 
    807        1.1        ad 	sc = ri->ri_hw;
    808        1.1        ad 	zc = sc->sc_zc;
    809        1.1        ad 	zd = sc->sc_zd_ss0;
    810        1.1        ad 
    811        1.1        ad 	sx = sx * sc->sc_fontw + ri->ri_xorigin;
    812        1.1        ad 	sy = sy * sc->sc_fonth + ri->ri_yorigin;
    813        1.1        ad 	dx = dx * sc->sc_fontw + ri->ri_xorigin;
    814        1.1        ad 	dy = dy * sc->sc_fonth + ri->ri_yorigin;
    815        1.1        ad 	w = w * sc->sc_fontw - 1;
    816        1.1        ad 	h = h * sc->sc_fonth - 1;
    817        1.1        ad 
    818        1.1        ad 	if (sy < dy || sx < dx) {
    819        1.1        ad 		dir = 0x80000000;
    820        1.1        ad 		sx += w;
    821        1.1        ad 		sy += h;
    822        1.1        ad 		dx += w;
    823        1.1        ad 		dy += h;
    824        1.1        ad 	} else
    825        1.1        ad 		dir = 0;
    826        1.1        ad 
    827        1.1        ad 	while ((zc->zc_csr & ZX_CSR_BLT_BUSY) != 0)
    828        1.1        ad 		;
    829        1.1        ad 
    830        1.1        ad 	SETREG(zd->zd_rop, ZX_STD_ROP);
    831        1.1        ad 	SETREG(zc->zc_extent, w | (h << 11) | dir);
    832        1.1        ad 	SETREG(zc->zc_src, sx | (sy << 11));
    833        1.1        ad 	SETREG(zc->zc_copy, dx | (dy << 11));
    834        1.1        ad }
    835        1.1        ad 
    836        1.1        ad void
    837        1.1        ad zx_do_cursor(struct rasops_info *ri)
    838        1.1        ad {
    839        1.1        ad 
    840        1.1        ad 	zx_fillrect(ri, ri->ri_ccol, ri->ri_crow, 1, 1, 0,
    841        1.1        ad 	    ZX_ROP_NEW_XOR_OLD | ZX_ATTR_WE_ENABLE | ZX_ATTR_OE_ENABLE |
    842        1.1        ad 	    ZX_ATTR_FORCE_WID);
    843        1.1        ad }
    844        1.1        ad 
    845        1.1        ad void
    846        1.1        ad zx_erasecols(void *cookie, int row, int col, int num, long attr)
    847        1.1        ad {
    848        1.1        ad 	struct rasops_info *ri;
    849        1.1        ad 
    850        1.1        ad 	ri = (struct rasops_info *)cookie;
    851        1.1        ad 
    852        1.1        ad 	zx_fillrect(ri, col, row, num, 1, attr, ZX_STD_ROP);
    853        1.1        ad }
    854        1.1        ad 
    855        1.1        ad void
    856        1.1        ad zx_eraserows(void *cookie, int row, int num, long attr)
    857        1.1        ad {
    858        1.1        ad 	struct rasops_info *ri;
    859        1.1        ad 
    860        1.1        ad 	ri = (struct rasops_info *)cookie;
    861        1.1        ad 
    862        1.1        ad 	zx_fillrect(ri, 0, row, ri->ri_cols, num, attr, ZX_STD_ROP);
    863        1.1        ad }
    864        1.1        ad 
    865        1.1        ad void
    866        1.1        ad zx_copyrows(void *cookie, int src, int dst, int num)
    867        1.1        ad {
    868        1.1        ad 	struct rasops_info *ri;
    869        1.1        ad 
    870        1.1        ad 	ri = (struct rasops_info *)cookie;
    871        1.1        ad 
    872        1.1        ad 	zx_copyrect(ri, 0, src, 0, dst, ri->ri_cols, num);
    873        1.1        ad }
    874        1.1        ad 
    875        1.1        ad void
    876        1.1        ad zx_copycols(void *cookie, int row, int src, int dst, int num)
    877        1.1        ad {
    878        1.1        ad 	struct rasops_info *ri;
    879        1.1        ad 
    880        1.1        ad 	ri = (struct rasops_info *)cookie;
    881        1.1        ad 
    882        1.1        ad 	zx_copyrect(ri, src, row, dst, row, num, 1);
    883        1.1        ad }
    884        1.1        ad 
    885        1.1        ad void
    886        1.1        ad zx_putchar(void *cookie, int row, int col, u_int uc, long attr)
    887        1.1        ad {
    888        1.1        ad 	struct rasops_info *ri;
    889        1.1        ad 	struct zx_softc *sc;
    890        1.1        ad 	struct wsdisplay_font *font;
    891        1.1        ad 	volatile struct zx_command *zc;
    892        1.1        ad 	volatile struct zx_draw *zd;
    893        1.1        ad 	volatile u_int32_t *dp;
    894        1.1        ad 	u_int8_t *fb;
    895        1.1        ad 	int fs, i, fg, bg, ul;
    896        1.1        ad 
    897        1.1        ad 	ri = (struct rasops_info *)cookie;
    898        1.1        ad 
    899        1.1        ad 	if (uc == ' ') {
    900        1.1        ad 		zx_fillrect(ri, col, row, 1, 1, attr, ZX_STD_ROP);
    901        1.1        ad 		return;
    902        1.1        ad 	}
    903        1.1        ad 
    904        1.1        ad 	sc = (struct zx_softc *)ri->ri_hw;
    905        1.1        ad 	font = ri->ri_font;
    906        1.1        ad 	zc = sc->sc_zc;
    907        1.1        ad 	zd = sc->sc_zd_ss0;
    908        1.1        ad 
    909        1.1        ad 	dp = (volatile u_int32_t *)sc->sc_pixels +
    910        1.1        ad 	    ((row * sc->sc_fonth + ri->ri_yorigin) << 11) +
    911        1.1        ad 	    (col * sc->sc_fontw + ri->ri_xorigin);
    912        1.1        ad 	fb = (u_int8_t *)font->data + (uc - font->firstchar) *
    913        1.1        ad 	    ri->ri_fontscale;
    914        1.1        ad 	fs = font->stride;
    915        1.1        ad 	rasops_unpack_attr(attr, &fg, &bg, &ul);
    916        1.1        ad 
    917        1.1        ad 	while ((zc->zc_csr & ZX_CSR_BLT_BUSY) != 0)
    918        1.1        ad 		;
    919        1.1        ad 
    920        1.1        ad 	SETREG(zd->zd_rop, ZX_STD_ROP);
    921        1.1        ad 	SETREG(zd->zd_fg, (fg & 7) ? 0x00000000 : 0xff000000);
    922        1.1        ad 	SETREG(zd->zd_bg, (bg & 7) ? 0x00000000 : 0xff000000);
    923        1.1        ad 	SETREG(zc->zc_fontmsk, 0xffffffff << (32 - sc->sc_fontw));
    924        1.1        ad 
    925        1.1        ad 	if (sc->sc_fontw <= 8) {
    926        1.1        ad 		for (i = sc->sc_fonth; i != 0; i--, dp += 2048) {
    927        1.1        ad 			*dp = *fb << 24;
    928        1.1        ad 			fb += fs;
    929        1.1        ad 		}
    930        1.1        ad 	} else {
    931        1.1        ad 		for (i = sc->sc_fonth; i != 0; i--, dp += 2048) {
    932        1.1        ad 			*dp = *((u_int16_t *)fb) << 16;
    933        1.1        ad 			fb += fs;
    934        1.1        ad 		}
    935        1.1        ad 	}
    936        1.1        ad 
    937        1.1        ad 	if (ul) {
    938        1.1        ad 		dp -= 4096;
    939        1.1        ad 		*dp = 0xffffffff;
    940        1.1        ad 	}
    941        1.1        ad }
    942