Home | History | Annotate | Line # | Download | only in sbus
zx.c revision 1.6
      1  1.6       pk /*	$NetBSD: zx.c,v 1.6 2002/12/10 13:44:48 pk 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.6       pk __KERNEL_RCSID(0, "$NetBSD: zx.c,v 1.6 2002/12/10 13:44:48 pk 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.1       ad };
    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.1       ad 
    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.1       ad 	fb->fb_flags = sc->sc_dv.dv_cfdata->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.1       ad zxopen(dev_t dev, int flags, int mode, struct proc *p)
    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.1       ad zxclose(dev_t dev, int flags, int mode, struct proc *p)
    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.1       ad zxioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
    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.1       ad 	int rv, v, count, i;
    307  1.1       ad 
    308  1.1       ad 	sc = zx_cd.cd_devs[minor(dev)];
    309  1.1       ad 
    310  1.1       ad 	switch (cmd) {
    311  1.1       ad 	case FBIOGTYPE:
    312  1.1       ad 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    313  1.1       ad 		break;
    314  1.1       ad 
    315  1.1       ad 	case FBIOGATTR:
    316  1.1       ad #define fba ((struct fbgattr *)data)
    317  1.1       ad 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    318  1.1       ad 		fba->owner = 0;		/* XXX ??? */
    319  1.1       ad 		fba->fbtype = sc->sc_fb.fb_type;
    320  1.1       ad 		fba->sattr.flags = 0;
    321  1.1       ad 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    322  1.1       ad 		fba->sattr.dev_specific[0] = -1;
    323  1.1       ad 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    324  1.1       ad 		fba->emu_types[1] = -1;
    325  1.1       ad 		fba->emu_types[2] = -1;
    326  1.1       ad #undef fba
    327  1.1       ad 		break;
    328  1.1       ad 
    329  1.1       ad 	case FBIOGVIDEO:
    330  1.1       ad 		*(int *)data = ((sc->sc_flags & ZX_BLANKED) != 0);
    331  1.1       ad 		break;
    332  1.1       ad 
    333  1.1       ad 	case FBIOSVIDEO:
    334  1.1       ad 		if (*(int *)data)
    335  1.1       ad 			zx_unblank(&sc->sc_dv);
    336  1.1       ad 		else
    337  1.1       ad 			zx_blank(&sc->sc_dv);
    338  1.1       ad 		break;
    339  1.1       ad 
    340  1.1       ad 	case FBIOGETCMAP:
    341  1.1       ad 		cm = (struct fbcmap *)data;
    342  1.1       ad 		if (cm->index > 256 || cm->count > 256 - cm->index)
    343  1.1       ad 			return (EINVAL);
    344  1.1       ad 		rv = copyout(sc->sc_cmap + cm->index, cm->red, cm->count);
    345  1.2       ad 		if (rv == 0)
    346  1.1       ad 			rv = copyout(sc->sc_cmap + 256 + cm->index, cm->green,
    347  1.1       ad 			    cm->count);
    348  1.2       ad 		if (rv == 0)
    349  1.1       ad 			rv = copyout(sc->sc_cmap + 512 + cm->index, cm->blue,
    350  1.1       ad 			    cm->count);
    351  1.1       ad 		return (rv);
    352  1.1       ad 
    353  1.1       ad 	case FBIOPUTCMAP:
    354  1.1       ad 		cm = (struct fbcmap *)data;
    355  1.1       ad 		if (cm->index > 256 || cm->count > 256 - cm->index)
    356  1.1       ad 			return (EINVAL);
    357  1.1       ad 		rv = copyin(cm->red, sc->sc_cmap + cm->index, cm->count);
    358  1.2       ad 		if (rv == 0)
    359  1.1       ad 			rv = copyin(cm->green, sc->sc_cmap + 256 + cm->index,
    360  1.1       ad 			    cm->count);
    361  1.2       ad 		if (rv == 0)
    362  1.1       ad 			rv = copyin(cm->blue, sc->sc_cmap + 512 + cm->index,
    363  1.1       ad 			    cm->count);
    364  1.1       ad 		zx_cmap_put(sc);
    365  1.1       ad 		return (rv);
    366  1.1       ad 
    367  1.1       ad 	case FBIOGCURPOS:
    368  1.1       ad 		*(struct fbcurpos *)data = sc->sc_curpos;
    369  1.1       ad 		break;
    370  1.1       ad 
    371  1.1       ad 	case FBIOSCURPOS:
    372  1.1       ad 		sc->sc_curpos = *(struct fbcurpos *)data;
    373  1.1       ad 		zx_cursor_move(sc);
    374  1.1       ad 		break;
    375  1.1       ad 
    376  1.1       ad 	case FBIOGCURMAX:
    377  1.1       ad 		((struct fbcurpos *)data)->x = 32;
    378  1.1       ad 		((struct fbcurpos *)data)->y = 32;
    379  1.1       ad 		break;
    380  1.1       ad 
    381  1.1       ad 	case FBIOSCURSOR:
    382  1.1       ad 		cu = (struct fbcursor *)data;
    383  1.1       ad 		v = cu->set;
    384  1.1       ad 
    385  1.1       ad 		if ((v & FB_CUR_SETSHAPE) != 0) {
    386  1.1       ad 			if ((u_int)cu->size.x > 32 || (u_int)cu->size.y > 32)
    387  1.1       ad 				return (EINVAL);
    388  1.1       ad 			count = cu->size.y * 4;
    389  1.1       ad 			if (!uvm_useracc(cu->image, count, B_READ) ||
    390  1.1       ad 			    !uvm_useracc(cu->mask, count, B_READ))
    391  1.1       ad 				return (EFAULT);
    392  1.1       ad 		}
    393  1.1       ad 		if ((v & FB_CUR_SETCUR) != 0) {
    394  1.1       ad 			if (cu->enable)
    395  1.1       ad 				zx_cursor_unblank(sc);
    396  1.1       ad 			else
    397  1.1       ad 				zx_cursor_blank(sc);
    398  1.1       ad 		}
    399  1.1       ad 		if ((v & (FB_CUR_SETPOS | FB_CUR_SETHOT)) != 0) {
    400  1.1       ad 			if ((v & FB_CUR_SETPOS) != 0)
    401  1.1       ad 				sc->sc_curpos = cu->pos;
    402  1.1       ad 			if ((v & FB_CUR_SETHOT) != 0)
    403  1.1       ad 				sc->sc_curhot = cu->hot;
    404  1.1       ad 			zx_cursor_move(sc);
    405  1.1       ad 		}
    406  1.1       ad 		if ((v & FB_CUR_SETCMAP) != 0) {
    407  1.1       ad 			if (cu->cmap.index > 2 ||
    408  1.1       ad 			    cu->cmap.count > 2 - cu->cmap.index)
    409  1.1       ad 				return (EINVAL);
    410  1.1       ad 			for (i = 0; i < cu->cmap.count; i++) {
    411  1.1       ad 				if ((v = fubyte(&cu->cmap.red[i])) < 0)
    412  1.1       ad 					return (EFAULT);
    413  1.1       ad 				sc->sc_curcmap[i + cu->cmap.index + 0] = v;
    414  1.1       ad 				if ((v = fubyte(&cu->cmap.green[i])) < 0)
    415  1.1       ad 					return (EFAULT);
    416  1.1       ad 				sc->sc_curcmap[i + cu->cmap.index + 2] = v;
    417  1.1       ad 				if ((v = fubyte(&cu->cmap.blue[i])) < 0)
    418  1.1       ad 					return (EFAULT);
    419  1.1       ad 				sc->sc_curcmap[i + cu->cmap.index + 4] = v;
    420  1.1       ad 			}
    421  1.1       ad 			zx_cursor_color(sc);
    422  1.1       ad 		}
    423  1.1       ad 		if ((v & FB_CUR_SETSHAPE) != 0) {
    424  1.1       ad 			sc->sc_cursize = cu->size;
    425  1.1       ad 			count = cu->size.y * 4;
    426  1.1       ad 			memset(sc->sc_curbits, 0, sizeof(sc->sc_curbits));
    427  1.1       ad 			copyin(cu->mask, (caddr_t)sc->sc_curbits[0], count);
    428  1.1       ad 			copyin(cu->image, (caddr_t)sc->sc_curbits[1], count);
    429  1.1       ad 			zx_cursor_set(sc);
    430  1.1       ad 		}
    431  1.1       ad 		break;
    432  1.1       ad 
    433  1.1       ad 	case FBIOGCURSOR:
    434  1.1       ad 		cu = (struct fbcursor *)data;
    435  1.1       ad 
    436  1.1       ad 		cu->set = FB_CUR_SETALL;
    437  1.1       ad 		cu->enable = ((sc->sc_flags & ZX_CURSOR) != 0);
    438  1.1       ad 		cu->pos = sc->sc_curpos;
    439  1.1       ad 		cu->hot = sc->sc_curhot;
    440  1.1       ad 		cu->size = sc->sc_cursize;
    441  1.1       ad 
    442  1.1       ad 		if (cu->image != NULL) {
    443  1.1       ad 			count = sc->sc_cursize.y * 4;
    444  1.1       ad 			rv = copyout((caddr_t)sc->sc_curbits[1],
    445  1.1       ad 			    (caddr_t)cu->image, count);
    446  1.1       ad 			if (rv)
    447  1.1       ad 				return (rv);
    448  1.1       ad 			rv = copyout((caddr_t)sc->sc_curbits[0],
    449  1.1       ad 			    (caddr_t)cu->mask, count);
    450  1.1       ad 			if (rv)
    451  1.1       ad 				return (rv);
    452  1.1       ad 		}
    453  1.1       ad 		if (cu->cmap.red != NULL) {
    454  1.1       ad 			if (cu->cmap.index > 2 ||
    455  1.1       ad 			    cu->cmap.count > 2 - cu->cmap.index)
    456  1.1       ad 				return (EINVAL);
    457  1.1       ad 			for (i = 0; i < cu->cmap.count; i++) {
    458  1.1       ad 				v = sc->sc_curcmap[i + cu->cmap.index + 0];
    459  1.1       ad 				if (subyte(&cu->cmap.red[i], v))
    460  1.1       ad 					return (EFAULT);
    461  1.1       ad 				v = sc->sc_curcmap[i + cu->cmap.index + 2];
    462  1.1       ad 				if (subyte(&cu->cmap.green[i], v))
    463  1.1       ad 					return (EFAULT);
    464  1.1       ad 				v = sc->sc_curcmap[i + cu->cmap.index + 4];
    465  1.1       ad 				if (subyte(&cu->cmap.blue[i], v))
    466  1.1       ad 					return (EFAULT);
    467  1.1       ad 			}
    468  1.1       ad 		} else {
    469  1.1       ad 			cu->cmap.index = 0;
    470  1.1       ad 			cu->cmap.count = 2;
    471  1.1       ad 		}
    472  1.1       ad 		break;
    473  1.1       ad 
    474  1.1       ad 	default:
    475  1.1       ad #ifdef DEBUG
    476  1.1       ad 		log(LOG_NOTICE, "zxioctl(0x%lx) (%s[%d])\n", cmd,
    477  1.1       ad 		    p->p_comm, p->p_pid);
    478  1.1       ad #endif
    479  1.1       ad 		return (ENOTTY);
    480  1.1       ad 	}
    481  1.1       ad 
    482  1.1       ad 	return (0);
    483  1.1       ad }
    484  1.1       ad 
    485  1.1       ad int
    486  1.1       ad zx_intr(void *cookie)
    487  1.1       ad {
    488  1.1       ad 
    489  1.1       ad 	return (1);
    490  1.1       ad }
    491  1.1       ad 
    492  1.1       ad void
    493  1.1       ad zx_reset(struct zx_softc *sc)
    494  1.1       ad {
    495  1.1       ad 	volatile struct zx_draw *zd;
    496  1.1       ad 	volatile struct zx_command *zc;
    497  1.1       ad 	struct fbtype *fbt;
    498  1.1       ad 	u_int i;
    499  1.1       ad 
    500  1.1       ad 	zd = sc->sc_zd_ss0;
    501  1.1       ad 	zc = sc->sc_zc;
    502  1.1       ad 	fbt = &sc->sc_fb.fb_type;
    503  1.1       ad 
    504  1.1       ad 	zx_cross_loadwid(sc, ZX_WID_DBL_8, 0, 0x2c0);
    505  1.1       ad 	zx_cross_loadwid(sc, ZX_WID_DBL_8, 1, 0x30);
    506  1.1       ad 	zx_cross_loadwid(sc, ZX_WID_DBL_8, 2, 0x20);
    507  1.1       ad 	zx_cross_loadwid(sc, ZX_WID_DBL_24, 1, 0x30);
    508  1.1       ad 
    509  1.1       ad 	i = sc->sc_zd_ss1->zd_misc;
    510  1.1       ad 	i |= ZX_SS1_MISC_ENABLE;
    511  1.1       ad 	SETREG(sc->sc_zd_ss1->zd_misc, i);
    512  1.1       ad 
    513  1.2       ad 	SETREG(zd->zd_wid, 0xffffffff);
    514  1.2       ad 	SETREG(zd->zd_widclip, 0);
    515  1.1       ad 	SETREG(zd->zd_wmask, 0xffff);
    516  1.1       ad 	SETREG(zd->zd_vclipmin, 0);
    517  1.1       ad 	SETREG(zd->zd_vclipmax,
    518  1.1       ad 	    (fbt->fb_width - 1) | ((fbt->fb_height - 1) << 16));
    519  1.1       ad 	SETREG(zd->zd_fg, 0);
    520  1.1       ad 	SETREG(zd->zd_planemask, 0xff000000);
    521  1.1       ad 	SETREG(zd->zd_rop, ZX_STD_ROP);
    522  1.1       ad 
    523  1.1       ad 	SETREG(zc->zc_extent,
    524  1.1       ad 	    (fbt->fb_width - 1) | ((fbt->fb_height - 1) << 11));
    525  1.1       ad 	SETREG(zc->zc_addrspace, ZX_ADDRSPC_FONT_OBGR);
    526  1.1       ad 	SETREG(zc->zc_fontt, 0);
    527  1.1       ad 
    528  1.1       ad 	for (i = 0; i < 256; i++) {
    529  1.1       ad 		sc->sc_cmap[i] = rasops_cmap[i * 3];
    530  1.1       ad 		sc->sc_cmap[i + 256] = rasops_cmap[i * 3 + 1];
    531  1.1       ad 		sc->sc_cmap[i + 512] = rasops_cmap[i * 3 + 2];
    532  1.1       ad 	}
    533  1.1       ad 
    534  1.1       ad 	zx_cmap_put(sc);
    535  1.1       ad }
    536  1.1       ad 
    537  1.1       ad int
    538  1.1       ad zx_cross_wait(struct zx_softc *sc)
    539  1.1       ad {
    540  1.1       ad 	volatile struct zx_cross *zx;
    541  1.1       ad 	int i;
    542  1.1       ad 
    543  1.1       ad 	zx = sc->sc_zx;
    544  1.1       ad 
    545  1.1       ad 	for (i = 300000; i != 0; i--) {
    546  1.1       ad 		if ((zx->zx_csr & ZX_CROSS_CSR_PROGRESS) == 0)
    547  1.1       ad 			break;
    548  1.1       ad 		DELAY(1);
    549  1.1       ad 	}
    550  1.1       ad 
    551  1.1       ad 	if (i == 0)
    552  1.1       ad 		printf("zx_cross_wait: timed out\n");
    553  1.1       ad 
    554  1.1       ad 	return (i);
    555  1.1       ad }
    556  1.1       ad 
    557  1.1       ad int
    558  1.1       ad zx_cross_loadwid(struct zx_softc *sc, u_int type, u_int index, u_int value)
    559  1.1       ad {
    560  1.1       ad 	volatile struct zx_cross *zx;
    561  1.1       ad 	u_int tmp;
    562  1.1       ad 
    563  1.1       ad 	zx = sc->sc_zx;
    564  1.1       ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_WID);
    565  1.1       ad 
    566  1.1       ad 	if (zx_cross_wait(sc))
    567  1.1       ad 		return (1);
    568  1.1       ad 
    569  1.1       ad 	if (type == ZX_WID_DBL_8)
    570  1.1       ad 		tmp = (index & 0x0f) + 0x40;
    571  1.1       ad 	else if (type == ZX_WID_DBL_24)
    572  1.1       ad 		tmp = index & 0x3f;
    573  1.1       ad 
    574  1.1       ad 	SETREG(zx->zx_type, 0x5800 + tmp);
    575  1.1       ad 	SETREG(zx->zx_value, value);
    576  1.1       ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_WID);
    577  1.1       ad 	SETREG(zx->zx_csr, ZX_CROSS_CSR_UNK | ZX_CROSS_CSR_UNK2);
    578  1.1       ad 
    579  1.1       ad 	return (0);
    580  1.1       ad }
    581  1.1       ad 
    582  1.1       ad int
    583  1.1       ad zx_cmap_put(struct zx_softc *sc)
    584  1.1       ad {
    585  1.1       ad 	volatile struct zx_cross *zx;
    586  1.1       ad 	const u_char *b;
    587  1.1       ad 	u_int i, t;
    588  1.1       ad 
    589  1.1       ad 	zx = sc->sc_zx;
    590  1.1       ad 
    591  1.1       ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_CLUT0);
    592  1.1       ad 	if (zx_cross_wait(sc))
    593  1.1       ad 		return (1);
    594  1.1       ad 
    595  1.1       ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_CLUTDATA);
    596  1.1       ad 
    597  1.1       ad 	for (i = 0, b = sc->sc_cmap; i < 256; i++) {
    598  1.1       ad 		t = b[i];
    599  1.1       ad 		t |= b[i + 256] << 8;
    600  1.1       ad 		t |= b[i + 512] << 16;
    601  1.1       ad 		SETREG(zx->zx_value, t);
    602  1.1       ad 	}
    603  1.1       ad 
    604  1.1       ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_CLUT0);
    605  1.1       ad 	i = zx->zx_csr;
    606  1.1       ad 	i = i | ZX_CROSS_CSR_UNK | ZX_CROSS_CSR_UNK2;
    607  1.1       ad 	SETREG(zx->zx_csr, i);
    608  1.1       ad 	return (0);
    609  1.1       ad }
    610  1.1       ad 
    611  1.1       ad void
    612  1.1       ad zx_cursor_move(struct zx_softc *sc)
    613  1.1       ad {
    614  1.1       ad 	volatile struct zx_cursor *zcu;
    615  1.1       ad 	int sx, sy, x, y;
    616  1.1       ad 
    617  1.1       ad 	x = sc->sc_curpos.x - sc->sc_curhot.x;
    618  1.1       ad 	y = sc->sc_curpos.y - sc->sc_curhot.y;
    619  1.1       ad 	zcu = sc->sc_zcu;
    620  1.1       ad 
    621  1.1       ad 	if (x < 0) {
    622  1.1       ad 		sx = min(-x, 32);
    623  1.1       ad 		x = 0;
    624  1.1       ad 	} else
    625  1.1       ad 		sx = 0;
    626  1.1       ad 
    627  1.1       ad 	if (y < 0) {
    628  1.1       ad 		sy = min(-y, 32);
    629  1.1       ad 		y = 0;
    630  1.1       ad 	} else
    631  1.1       ad 		sy = 0;
    632  1.1       ad 
    633  1.1       ad 	if (sx != sc->sc_shiftx || sy != sc->sc_shifty) {
    634  1.1       ad 		sc->sc_shiftx = sx;
    635  1.1       ad 		sc->sc_shifty = sy;
    636  1.1       ad 		zx_cursor_set(sc);
    637  1.1       ad 	}
    638  1.1       ad 
    639  1.1       ad 	SETREG(zcu->zcu_sxy, ((y & 0x7ff) << 11) | (x & 0x7ff));
    640  1.1       ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x30);
    641  1.1       ad 
    642  1.1       ad 	/* XXX Necessary? */
    643  1.1       ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x80);
    644  1.1       ad }
    645  1.1       ad 
    646  1.1       ad void
    647  1.1       ad zx_cursor_set(struct zx_softc *sc)
    648  1.1       ad {
    649  1.1       ad 	volatile struct zx_cursor *zcu;
    650  1.1       ad 	int i, j, data;
    651  1.1       ad 
    652  1.1       ad 	zcu = sc->sc_zcu;
    653  1.2       ad 
    654  1.2       ad 	if ((sc->sc_flags & ZX_CURSOR) != 0)
    655  1.2       ad 		SETREG(zcu->zcu_misc, zcu->zcu_misc & ~0x80);
    656  1.1       ad 
    657  1.1       ad 	for (j = 0; j < 2; j++) {
    658  1.2       ad 		SETREG(zcu->zcu_type, 0x20 << i);
    659  1.2       ad 
    660  1.1       ad 		for (i = sc->sc_shifty; i < 32; i++) {
    661  1.1       ad 			data = sc->sc_curbits[j][i];
    662  1.1       ad 			SETREG(zcu->zcu_data, data >> sc->sc_shiftx);
    663  1.1       ad 		}
    664  1.1       ad 		for (i = sc->sc_shifty; i != 0; i--)
    665  1.1       ad 			SETREG(zcu->zcu_data, 0);
    666  1.1       ad 	}
    667  1.2       ad 
    668  1.2       ad 	if ((sc->sc_flags & ZX_CURSOR) != 0)
    669  1.2       ad 		SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x80);
    670  1.1       ad }
    671  1.1       ad 
    672  1.1       ad void
    673  1.1       ad zx_cursor_blank(struct zx_softc *sc)
    674  1.1       ad {
    675  1.1       ad 	volatile struct zx_cursor *zcu;
    676  1.1       ad 
    677  1.1       ad 	sc->sc_flags &= ~ZX_CURSOR;
    678  1.1       ad 	zcu = sc->sc_zcu;
    679  1.1       ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc & ~0x80);
    680  1.1       ad }
    681  1.1       ad 
    682  1.1       ad void
    683  1.1       ad zx_cursor_unblank(struct zx_softc *sc)
    684  1.1       ad {
    685  1.1       ad 	volatile struct zx_cursor *zcu;
    686  1.1       ad 
    687  1.1       ad 	sc->sc_flags |= ZX_CURSOR;
    688  1.1       ad 	zcu = sc->sc_zcu;
    689  1.1       ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x80);
    690  1.1       ad }
    691  1.1       ad 
    692  1.1       ad void
    693  1.1       ad zx_cursor_color(struct zx_softc *sc)
    694  1.1       ad {
    695  1.1       ad 	volatile struct zx_cursor *zcu;
    696  1.1       ad 	u_int8_t tmp;
    697  1.1       ad 
    698  1.1       ad 	zcu = sc->sc_zcu;
    699  1.1       ad 
    700  1.1       ad 	SETREG(zcu->zcu_type, 0x50);
    701  1.1       ad 
    702  1.1       ad 	tmp = sc->sc_curcmap[0] | (sc->sc_curcmap[2] << 8) |
    703  1.1       ad 	    (sc->sc_curcmap[4] << 16);
    704  1.1       ad 	SETREG(zcu->zcu_data, tmp);
    705  1.1       ad 
    706  1.1       ad 	tmp = sc->sc_curcmap[1] | (sc->sc_curcmap[3] << 8) |
    707  1.1       ad 	    (sc->sc_curcmap[5] << 16);
    708  1.1       ad 	SETREG(zcu->zcu_data, sc->sc_curcmap[1]);
    709  1.1       ad 
    710  1.1       ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x03);
    711  1.1       ad }
    712  1.1       ad 
    713  1.1       ad void
    714  1.1       ad zx_blank(struct device *dv)
    715  1.1       ad {
    716  1.1       ad 	struct zx_softc *sc;
    717  1.1       ad 	volatile struct zx_cross *zx;
    718  1.1       ad 
    719  1.1       ad 	sc = (struct zx_softc *)dv;
    720  1.1       ad 
    721  1.1       ad 	if ((sc->sc_flags & ZX_BLANKED) != 0)
    722  1.1       ad 		return;
    723  1.1       ad 	sc->sc_flags |= ZX_BLANKED;
    724  1.1       ad 
    725  1.1       ad 	zx = sc->sc_zx;
    726  1.1       ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_VIDEO);
    727  1.1       ad 	SETREG(zx->zx_csr, zx->zx_csr & ~ZX_CROSS_CSR_ENABLE);
    728  1.1       ad }
    729  1.1       ad 
    730  1.1       ad void
    731  1.1       ad zx_unblank(struct device *dv)
    732  1.1       ad {
    733  1.1       ad 	struct zx_softc *sc;
    734  1.1       ad 	volatile struct zx_cross *zx;
    735  1.1       ad 
    736  1.1       ad 	sc = (struct zx_softc *)dv;
    737  1.1       ad 
    738  1.1       ad 	if ((sc->sc_flags & ZX_BLANKED) == 0)
    739  1.1       ad 		return;
    740  1.1       ad 	sc->sc_flags &= ~ZX_BLANKED;
    741  1.1       ad 
    742  1.1       ad 	zx = sc->sc_zx;
    743  1.1       ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_VIDEO);
    744  1.1       ad 	SETREG(zx->zx_csr, zx->zx_csr | ZX_CROSS_CSR_ENABLE);
    745  1.1       ad }
    746  1.1       ad 
    747  1.1       ad paddr_t
    748  1.1       ad zxmmap(dev_t dev, off_t off, int prot)
    749  1.1       ad {
    750  1.1       ad 	struct zx_softc *sc;
    751  1.1       ad 	const struct zx_mmo *mm, *max;
    752  1.2       ad 
    753  1.1       ad 	sc = device_lookup(&zx_cd, minor(dev));
    754  1.2       ad 	off = trunc_page(off);
    755  1.1       ad 	mm = zx_mmo;
    756  1.1       ad 	max = mm + sizeof(zx_mmo) / sizeof(zx_mmo[0]);
    757  1.1       ad 
    758  1.1       ad 	for (; mm < max; mm++)
    759  1.1       ad 		if (off >= mm->mo_va && off < mm->mo_va + mm->mo_size) {
    760  1.1       ad 			off = off - mm->mo_va + mm->mo_pa;
    761  1.1       ad 			return (bus_space_mmap(sc->sc_bt, sc->sc_paddr,
    762  1.1       ad 			    off, prot, BUS_SPACE_MAP_LINEAR));
    763  1.1       ad 		}
    764  1.1       ad 
    765  1.1       ad 	return (-1);
    766  1.1       ad }
    767  1.1       ad 
    768  1.1       ad void
    769  1.1       ad zx_fillrect(struct rasops_info *ri, int x, int y, int w, int h, long attr,
    770  1.1       ad 	    int rop)
    771  1.1       ad {
    772  1.1       ad 	struct zx_softc *sc;
    773  1.1       ad 	volatile struct zx_command *zc;
    774  1.1       ad 	volatile struct zx_draw *zd;
    775  1.1       ad 	int fg, bg;
    776  1.1       ad 
    777  1.1       ad 	sc = ri->ri_hw;
    778  1.1       ad 	zc = sc->sc_zc;
    779  1.1       ad 	zd = sc->sc_zd_ss0;
    780  1.1       ad 
    781  1.1       ad 	rasops_unpack_attr(attr, &fg, &bg, NULL);
    782  1.1       ad 	x = x * sc->sc_fontw + ri->ri_xorigin;
    783  1.1       ad 	y = y * sc->sc_fonth + ri->ri_yorigin;
    784  1.1       ad 	w = sc->sc_fontw * w - 1;
    785  1.1       ad 	h = sc->sc_fonth * h - 1;
    786  1.1       ad 
    787  1.1       ad 	while ((zc->zc_csr & ZX_CSR_BLT_BUSY) != 0)
    788  1.1       ad 		;
    789  1.1       ad 
    790  1.1       ad 	SETREG(zd->zd_rop, rop);
    791  1.1       ad 	SETREG(zd->zd_fg, (bg & 7) ? 0x00000000 : 0xff000000);
    792  1.1       ad 	SETREG(zc->zc_extent, w | (h << 11));
    793  1.1       ad 	SETREG(zc->zc_fill, x | (y << 11) | 0x80000000);
    794  1.1       ad }
    795  1.1       ad 
    796  1.1       ad void
    797  1.1       ad zx_copyrect(struct rasops_info *ri, int sx, int sy, int dx, int dy, int w,
    798  1.1       ad 	    int h)
    799  1.1       ad {
    800  1.1       ad 	struct zx_softc *sc;
    801  1.1       ad 	volatile struct zx_command *zc;
    802  1.1       ad 	volatile struct zx_draw *zd;
    803  1.1       ad 	int dir;
    804  1.1       ad 
    805  1.1       ad 	sc = ri->ri_hw;
    806  1.1       ad 	zc = sc->sc_zc;
    807  1.1       ad 	zd = sc->sc_zd_ss0;
    808  1.1       ad 
    809  1.1       ad 	sx = sx * sc->sc_fontw + ri->ri_xorigin;
    810  1.1       ad 	sy = sy * sc->sc_fonth + ri->ri_yorigin;
    811  1.1       ad 	dx = dx * sc->sc_fontw + ri->ri_xorigin;
    812  1.1       ad 	dy = dy * sc->sc_fonth + ri->ri_yorigin;
    813  1.1       ad 	w = w * sc->sc_fontw - 1;
    814  1.1       ad 	h = h * sc->sc_fonth - 1;
    815  1.1       ad 
    816  1.1       ad 	if (sy < dy || sx < dx) {
    817  1.1       ad 		dir = 0x80000000;
    818  1.1       ad 		sx += w;
    819  1.1       ad 		sy += h;
    820  1.1       ad 		dx += w;
    821  1.1       ad 		dy += h;
    822  1.1       ad 	} else
    823  1.1       ad 		dir = 0;
    824  1.1       ad 
    825  1.1       ad 	while ((zc->zc_csr & ZX_CSR_BLT_BUSY) != 0)
    826  1.1       ad 		;
    827  1.1       ad 
    828  1.1       ad 	SETREG(zd->zd_rop, ZX_STD_ROP);
    829  1.1       ad 	SETREG(zc->zc_extent, w | (h << 11) | dir);
    830  1.1       ad 	SETREG(zc->zc_src, sx | (sy << 11));
    831  1.1       ad 	SETREG(zc->zc_copy, dx | (dy << 11));
    832  1.1       ad }
    833  1.1       ad 
    834  1.1       ad void
    835  1.1       ad zx_do_cursor(struct rasops_info *ri)
    836  1.1       ad {
    837  1.1       ad 
    838  1.1       ad 	zx_fillrect(ri, ri->ri_ccol, ri->ri_crow, 1, 1, 0,
    839  1.1       ad 	    ZX_ROP_NEW_XOR_OLD | ZX_ATTR_WE_ENABLE | ZX_ATTR_OE_ENABLE |
    840  1.1       ad 	    ZX_ATTR_FORCE_WID);
    841  1.1       ad }
    842  1.1       ad 
    843  1.1       ad void
    844  1.1       ad zx_erasecols(void *cookie, int row, int col, int num, long attr)
    845  1.1       ad {
    846  1.1       ad 	struct rasops_info *ri;
    847  1.1       ad 
    848  1.1       ad 	ri = (struct rasops_info *)cookie;
    849  1.1       ad 
    850  1.1       ad 	zx_fillrect(ri, col, row, num, 1, attr, ZX_STD_ROP);
    851  1.1       ad }
    852  1.1       ad 
    853  1.1       ad void
    854  1.1       ad zx_eraserows(void *cookie, int row, int num, long attr)
    855  1.1       ad {
    856  1.1       ad 	struct rasops_info *ri;
    857  1.1       ad 
    858  1.1       ad 	ri = (struct rasops_info *)cookie;
    859  1.1       ad 
    860  1.1       ad 	zx_fillrect(ri, 0, row, ri->ri_cols, num, attr, ZX_STD_ROP);
    861  1.1       ad }
    862  1.1       ad 
    863  1.1       ad void
    864  1.1       ad zx_copyrows(void *cookie, int src, int dst, int num)
    865  1.1       ad {
    866  1.1       ad 	struct rasops_info *ri;
    867  1.1       ad 
    868  1.1       ad 	ri = (struct rasops_info *)cookie;
    869  1.1       ad 
    870  1.1       ad 	zx_copyrect(ri, 0, src, 0, dst, ri->ri_cols, num);
    871  1.1       ad }
    872  1.1       ad 
    873  1.1       ad void
    874  1.1       ad zx_copycols(void *cookie, int row, int src, int dst, int num)
    875  1.1       ad {
    876  1.1       ad 	struct rasops_info *ri;
    877  1.1       ad 
    878  1.1       ad 	ri = (struct rasops_info *)cookie;
    879  1.1       ad 
    880  1.1       ad 	zx_copyrect(ri, src, row, dst, row, num, 1);
    881  1.1       ad }
    882  1.1       ad 
    883  1.1       ad void
    884  1.1       ad zx_putchar(void *cookie, int row, int col, u_int uc, long attr)
    885  1.1       ad {
    886  1.1       ad 	struct rasops_info *ri;
    887  1.1       ad 	struct zx_softc *sc;
    888  1.1       ad 	struct wsdisplay_font *font;
    889  1.1       ad 	volatile struct zx_command *zc;
    890  1.1       ad 	volatile struct zx_draw *zd;
    891  1.1       ad 	volatile u_int32_t *dp;
    892  1.1       ad 	u_int8_t *fb;
    893  1.1       ad 	int fs, i, fg, bg, ul;
    894  1.1       ad 
    895  1.1       ad 	ri = (struct rasops_info *)cookie;
    896  1.1       ad 
    897  1.1       ad 	if (uc == ' ') {
    898  1.1       ad 		zx_fillrect(ri, col, row, 1, 1, attr, ZX_STD_ROP);
    899  1.1       ad 		return;
    900  1.1       ad 	}
    901  1.1       ad 
    902  1.1       ad 	sc = (struct zx_softc *)ri->ri_hw;
    903  1.1       ad 	font = ri->ri_font;
    904  1.1       ad 	zc = sc->sc_zc;
    905  1.1       ad 	zd = sc->sc_zd_ss0;
    906  1.1       ad 
    907  1.1       ad 	dp = (volatile u_int32_t *)sc->sc_pixels +
    908  1.1       ad 	    ((row * sc->sc_fonth + ri->ri_yorigin) << 11) +
    909  1.1       ad 	    (col * sc->sc_fontw + ri->ri_xorigin);
    910  1.1       ad 	fb = (u_int8_t *)font->data + (uc - font->firstchar) *
    911  1.1       ad 	    ri->ri_fontscale;
    912  1.1       ad 	fs = font->stride;
    913  1.1       ad 	rasops_unpack_attr(attr, &fg, &bg, &ul);
    914  1.1       ad 
    915  1.1       ad 	while ((zc->zc_csr & ZX_CSR_BLT_BUSY) != 0)
    916  1.1       ad 		;
    917  1.1       ad 
    918  1.1       ad 	SETREG(zd->zd_rop, ZX_STD_ROP);
    919  1.1       ad 	SETREG(zd->zd_fg, (fg & 7) ? 0x00000000 : 0xff000000);
    920  1.1       ad 	SETREG(zd->zd_bg, (bg & 7) ? 0x00000000 : 0xff000000);
    921  1.1       ad 	SETREG(zc->zc_fontmsk, 0xffffffff << (32 - sc->sc_fontw));
    922  1.1       ad 
    923  1.1       ad 	if (sc->sc_fontw <= 8) {
    924  1.1       ad 		for (i = sc->sc_fonth; i != 0; i--, dp += 2048) {
    925  1.1       ad 			*dp = *fb << 24;
    926  1.1       ad 			fb += fs;
    927  1.1       ad 		}
    928  1.1       ad 	} else {
    929  1.1       ad 		for (i = sc->sc_fonth; i != 0; i--, dp += 2048) {
    930  1.1       ad 			*dp = *((u_int16_t *)fb) << 16;
    931  1.1       ad 			fb += fs;
    932  1.1       ad 		}
    933  1.1       ad 	}
    934  1.1       ad 
    935  1.1       ad 	if (ul) {
    936  1.1       ad 		dp -= 4096;
    937  1.1       ad 		*dp = 0xffffffff;
    938  1.1       ad 	}
    939  1.1       ad }
    940