Home | History | Annotate | Line # | Download | only in sbus
zx.c revision 1.2
      1  1.2  ad /*	$NetBSD: zx.c,v 1.2 2002/09/18 18:42:06 ad 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.2  ad __KERNEL_RCSID(0, "$NetBSD: zx.c,v 1.2 2002/09/18 18:42:06 ad 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.1  ad struct cfattach zx_ca = {
    138  1.1  ad 	sizeof(struct zx_softc), zx_match, zx_attach
    139  1.1  ad };
    140  1.1  ad 
    141  1.1  ad extern struct cfdriver zx_cd;
    142  1.1  ad 
    143  1.1  ad dev_type_open(zxopen);
    144  1.1  ad dev_type_close(zxclose);
    145  1.1  ad dev_type_ioctl(zxioctl);
    146  1.1  ad dev_type_mmap(zxmmap);
    147  1.1  ad 
    148  1.1  ad static struct fbdriver zx_fbdriver = {
    149  1.1  ad 	zx_unblank, zxopen, zxclose, zxioctl, nopoll, zxmmap
    150  1.1  ad };
    151  1.1  ad 
    152  1.1  ad int
    153  1.1  ad zx_match(struct device *parent, struct cfdata *cf, void *aux)
    154  1.1  ad {
    155  1.1  ad 	struct sbus_attach_args *sa;
    156  1.1  ad 
    157  1.1  ad 	sa = (struct sbus_attach_args *)aux;
    158  1.1  ad 
    159  1.1  ad 	return (strcmp(sa->sa_name, "SUNW,leo") == 0);
    160  1.1  ad }
    161  1.1  ad 
    162  1.1  ad void
    163  1.1  ad zx_attach(struct device *parent, struct device *self, void *args)
    164  1.1  ad {
    165  1.1  ad 	struct zx_softc *sc;
    166  1.1  ad 	struct sbus_attach_args *sa;
    167  1.1  ad 	bus_space_handle_t bh;
    168  1.1  ad 	bus_space_tag_t bt;
    169  1.1  ad 	struct fbdevice *fb;
    170  1.1  ad 	struct rasops_info *ri;
    171  1.1  ad 	volatile struct zx_command *zc;
    172  1.1  ad 	int isconsole;
    173  1.1  ad 
    174  1.1  ad 	sc = (struct zx_softc *)self;
    175  1.1  ad 	sa = args;
    176  1.1  ad 	fb = &sc->sc_fb;
    177  1.1  ad 	ri = &fb->fb_rinfo;
    178  1.1  ad 	bt = sa->sa_bustag;
    179  1.1  ad 	sc->sc_bt = bt;
    180  1.1  ad 
    181  1.1  ad 	sc->sc_paddr = sbus_bus_addr(bt, sa->sa_slot, sa->sa_offset);
    182  1.1  ad 
    183  1.1  ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_SS0,
    184  1.1  ad 	    0x800000, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    185  1.1  ad 		printf("%s: can't map bits\n", self->dv_xname);
    186  1.1  ad 		return;
    187  1.1  ad 	}
    188  1.1  ad 	fb->fb_pixels = (caddr_t)bus_space_vaddr(bt, bh);
    189  1.1  ad 	sc->sc_pixels = (u_int32_t *)fb->fb_pixels;
    190  1.1  ad 
    191  1.1  ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LC_SS0_USR,
    192  1.1  ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    193  1.1  ad 		printf("%s: can't map zc\n", self->dv_xname);
    194  1.1  ad 		return;
    195  1.1  ad 	}
    196  1.1  ad 	sc->sc_zc = (struct zx_command *)bus_space_vaddr(bt, bh);
    197  1.1  ad 
    198  1.1  ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LD_SS0,
    199  1.1  ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    200  1.1  ad 		printf("%s: can't map ld/ss0\n", self->dv_xname);
    201  1.1  ad 		return;
    202  1.1  ad 	}
    203  1.1  ad 	sc->sc_zd_ss0 = (struct zx_draw *)bus_space_vaddr(bt, bh);
    204  1.1  ad 
    205  1.1  ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LD_SS1,
    206  1.1  ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    207  1.1  ad 		printf("%s: can't map ld/ss1\n", self->dv_xname);
    208  1.1  ad 		return;
    209  1.1  ad 	}
    210  1.1  ad 	sc->sc_zd_ss1 =
    211  1.1  ad 	    (struct zx_draw_ss1 *)bus_space_vaddr(bt, bh);
    212  1.1  ad 
    213  1.1  ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LX_CROSS,
    214  1.1  ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    215  1.1  ad 		printf("%s: can't map zx\n", self->dv_xname);
    216  1.1  ad 		return;
    217  1.1  ad 	}
    218  1.1  ad 	sc->sc_zx = (struct zx_cross *)bus_space_vaddr(bt, bh);
    219  1.1  ad 
    220  1.1  ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LX_CURSOR,
    221  1.1  ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    222  1.1  ad 		printf("%s: can't map zcu\n", self->dv_xname);
    223  1.1  ad 		return;
    224  1.1  ad 	}
    225  1.1  ad 	sc->sc_zcu = (struct zx_cursor *)bus_space_vaddr(bt, bh);
    226  1.1  ad 
    227  1.1  ad 	fb->fb_driver = &zx_fbdriver;
    228  1.1  ad 	fb->fb_device = &sc->sc_dv;
    229  1.1  ad 	fb->fb_flags = sc->sc_dv.dv_cfdata->cf_flags & FB_USERMASK;
    230  1.1  ad 	fb->fb_pfour = NULL;
    231  1.1  ad 	fb->fb_linebytes = 8192;
    232  1.1  ad 
    233  1.1  ad 	fb_setsize_obp(fb, 32, 1280, 1024, sa->sa_node);
    234  1.1  ad 
    235  1.1  ad 	fb->fb_type.fb_cmsize = 256;
    236  1.1  ad 	fb->fb_type.fb_depth = 32;
    237  1.1  ad 	fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
    238  1.1  ad 	fb->fb_type.fb_type = FBTYPE_SUNLEO;
    239  1.1  ad 
    240  1.1  ad 	printf(": %d x %d", fb->fb_type.fb_width, fb->fb_type.fb_height);
    241  1.1  ad 	isconsole = fb_is_console(sa->sa_node);
    242  1.1  ad 	if (isconsole)
    243  1.1  ad 		printf(" (console)");
    244  1.1  ad 	printf("\n");
    245  1.1  ad 
    246  1.1  ad 	sbus_establish(&sc->sc_sd, &sc->sc_dv);
    247  1.1  ad 	if (sa->sa_nintr != 0)
    248  1.1  ad 		bus_intr_establish(bt, sa->sa_pri, IPL_NONE, 0, zx_intr, sc);
    249  1.1  ad 
    250  1.1  ad 	sc->sc_cmap = malloc(768, M_DEVBUF, M_NOWAIT);
    251  1.1  ad 	fb_attach(&sc->sc_fb, isconsole);
    252  1.1  ad 	zx_reset(sc);
    253  1.1  ad 
    254  1.1  ad 	/*
    255  1.1  ad 	 * Attach to rcons.  XXX At this point, rasops_do_cursor() will be
    256  1.1  ad 	 * called before we get our hooks in place.  So, we mask off access
    257  1.1  ad 	 * to the framebuffer until it's done.
    258  1.1  ad 	 */
    259  1.1  ad 	zc = sc->sc_zc;
    260  1.1  ad 	SETREG(zc->zc_fontt, 1);
    261  1.1  ad 	SETREG(zc->zc_fontmsk, 0);
    262  1.1  ad 
    263  1.1  ad 	fbrcons_init(&sc->sc_fb);
    264  1.1  ad 
    265  1.1  ad 	SETREG(zc->zc_fontt, 0);
    266  1.1  ad 	SETREG(zc->zc_fontmsk, 0xffffffff);
    267  1.1  ad 
    268  1.1  ad 	ri->ri_hw = sc;
    269  1.1  ad 	ri->ri_do_cursor = zx_do_cursor;
    270  1.1  ad 	ri->ri_ops.copycols = zx_copycols;
    271  1.1  ad 	ri->ri_ops.copyrows = zx_copyrows;
    272  1.1  ad 	ri->ri_ops.erasecols = zx_erasecols;
    273  1.1  ad 	ri->ri_ops.eraserows = zx_eraserows;
    274  1.1  ad 	ri->ri_ops.putchar = zx_putchar;
    275  1.1  ad 
    276  1.1  ad 	sc->sc_fontw = ri->ri_font->fontwidth;
    277  1.1  ad 	sc->sc_fonth = ri->ri_font->fontheight;
    278  1.1  ad }
    279  1.1  ad 
    280  1.1  ad int
    281  1.1  ad zxopen(dev_t dev, int flags, int mode, struct proc *p)
    282  1.1  ad {
    283  1.1  ad 
    284  1.1  ad 	if (device_lookup(&zx_cd, minor(dev)) == NULL)
    285  1.1  ad 		return (ENXIO);
    286  1.1  ad 	return (0);
    287  1.1  ad }
    288  1.1  ad 
    289  1.1  ad int
    290  1.1  ad zxclose(dev_t dev, int flags, int mode, struct proc *p)
    291  1.1  ad {
    292  1.1  ad 	struct zx_softc *sc;
    293  1.1  ad 
    294  1.1  ad 	sc = (struct zx_softc *)device_lookup(&zx_cd, minor(dev));
    295  1.1  ad 
    296  1.1  ad 	zx_reset(sc);
    297  1.1  ad 	zx_cursor_blank(sc);
    298  1.1  ad 	return (0);
    299  1.1  ad }
    300  1.1  ad 
    301  1.1  ad int
    302  1.1  ad zxioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
    303  1.1  ad {
    304  1.1  ad 	struct zx_softc *sc;
    305  1.1  ad 	struct fbcmap *cm;
    306  1.1  ad 	struct fbcursor *cu;
    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.1  ad 
    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.1  ad 			if (!uvm_useracc(cu->image, count, B_READ) ||
    391  1.1  ad 			    !uvm_useracc(cu->mask, count, B_READ))
    392  1.1  ad 				return (EFAULT);
    393  1.1  ad 		}
    394  1.1  ad 		if ((v & FB_CUR_SETCUR) != 0) {
    395  1.1  ad 			if (cu->enable)
    396  1.1  ad 				zx_cursor_unblank(sc);
    397  1.1  ad 			else
    398  1.1  ad 				zx_cursor_blank(sc);
    399  1.1  ad 		}
    400  1.1  ad 		if ((v & (FB_CUR_SETPOS | FB_CUR_SETHOT)) != 0) {
    401  1.1  ad 			if ((v & FB_CUR_SETPOS) != 0)
    402  1.1  ad 				sc->sc_curpos = cu->pos;
    403  1.1  ad 			if ((v & FB_CUR_SETHOT) != 0)
    404  1.1  ad 				sc->sc_curhot = cu->hot;
    405  1.1  ad 			zx_cursor_move(sc);
    406  1.1  ad 		}
    407  1.1  ad 		if ((v & FB_CUR_SETCMAP) != 0) {
    408  1.1  ad 			if (cu->cmap.index > 2 ||
    409  1.1  ad 			    cu->cmap.count > 2 - cu->cmap.index)
    410  1.1  ad 				return (EINVAL);
    411  1.1  ad 			for (i = 0; i < cu->cmap.count; i++) {
    412  1.1  ad 				if ((v = fubyte(&cu->cmap.red[i])) < 0)
    413  1.1  ad 					return (EFAULT);
    414  1.1  ad 				sc->sc_curcmap[i + cu->cmap.index + 0] = v;
    415  1.1  ad 				if ((v = fubyte(&cu->cmap.green[i])) < 0)
    416  1.1  ad 					return (EFAULT);
    417  1.1  ad 				sc->sc_curcmap[i + cu->cmap.index + 2] = v;
    418  1.1  ad 				if ((v = fubyte(&cu->cmap.blue[i])) < 0)
    419  1.1  ad 					return (EFAULT);
    420  1.1  ad 				sc->sc_curcmap[i + cu->cmap.index + 4] = v;
    421  1.1  ad 			}
    422  1.1  ad 			zx_cursor_color(sc);
    423  1.1  ad 		}
    424  1.1  ad 		if ((v & FB_CUR_SETSHAPE) != 0) {
    425  1.1  ad 			sc->sc_cursize = cu->size;
    426  1.1  ad 			count = cu->size.y * 4;
    427  1.1  ad 			memset(sc->sc_curbits, 0, sizeof(sc->sc_curbits));
    428  1.1  ad 			copyin(cu->mask, (caddr_t)sc->sc_curbits[0], count);
    429  1.1  ad 			copyin(cu->image, (caddr_t)sc->sc_curbits[1], count);
    430  1.1  ad 			zx_cursor_set(sc);
    431  1.1  ad 		}
    432  1.1  ad 		break;
    433  1.1  ad 
    434  1.1  ad 	case FBIOGCURSOR:
    435  1.1  ad 		cu = (struct fbcursor *)data;
    436  1.1  ad 
    437  1.1  ad 		cu->set = FB_CUR_SETALL;
    438  1.1  ad 		cu->enable = ((sc->sc_flags & ZX_CURSOR) != 0);
    439  1.1  ad 		cu->pos = sc->sc_curpos;
    440  1.1  ad 		cu->hot = sc->sc_curhot;
    441  1.1  ad 		cu->size = sc->sc_cursize;
    442  1.1  ad 
    443  1.1  ad 		if (cu->image != NULL) {
    444  1.1  ad 			count = sc->sc_cursize.y * 4;
    445  1.1  ad 			rv = copyout((caddr_t)sc->sc_curbits[1],
    446  1.1  ad 			    (caddr_t)cu->image, count);
    447  1.1  ad 			if (rv)
    448  1.1  ad 				return (rv);
    449  1.1  ad 			rv = copyout((caddr_t)sc->sc_curbits[0],
    450  1.1  ad 			    (caddr_t)cu->mask, count);
    451  1.1  ad 			if (rv)
    452  1.1  ad 				return (rv);
    453  1.1  ad 		}
    454  1.1  ad 		if (cu->cmap.red != NULL) {
    455  1.1  ad 			if (cu->cmap.index > 2 ||
    456  1.1  ad 			    cu->cmap.count > 2 - cu->cmap.index)
    457  1.1  ad 				return (EINVAL);
    458  1.1  ad 			for (i = 0; i < cu->cmap.count; i++) {
    459  1.1  ad 				v = sc->sc_curcmap[i + cu->cmap.index + 0];
    460  1.1  ad 				if (subyte(&cu->cmap.red[i], v))
    461  1.1  ad 					return (EFAULT);
    462  1.1  ad 				v = sc->sc_curcmap[i + cu->cmap.index + 2];
    463  1.1  ad 				if (subyte(&cu->cmap.green[i], v))
    464  1.1  ad 					return (EFAULT);
    465  1.1  ad 				v = sc->sc_curcmap[i + cu->cmap.index + 4];
    466  1.1  ad 				if (subyte(&cu->cmap.blue[i], v))
    467  1.1  ad 					return (EFAULT);
    468  1.1  ad 			}
    469  1.1  ad 		} else {
    470  1.1  ad 			cu->cmap.index = 0;
    471  1.1  ad 			cu->cmap.count = 2;
    472  1.1  ad 		}
    473  1.1  ad 		break;
    474  1.1  ad 
    475  1.1  ad 	default:
    476  1.1  ad #ifdef DEBUG
    477  1.1  ad 		log(LOG_NOTICE, "zxioctl(0x%lx) (%s[%d])\n", cmd,
    478  1.1  ad 		    p->p_comm, p->p_pid);
    479  1.1  ad #endif
    480  1.1  ad 		return (ENOTTY);
    481  1.1  ad 	}
    482  1.1  ad 
    483  1.1  ad 	return (0);
    484  1.1  ad }
    485  1.1  ad 
    486  1.1  ad int
    487  1.1  ad zx_intr(void *cookie)
    488  1.1  ad {
    489  1.1  ad 
    490  1.1  ad 	return (1);
    491  1.1  ad }
    492  1.1  ad 
    493  1.1  ad void
    494  1.1  ad zx_reset(struct zx_softc *sc)
    495  1.1  ad {
    496  1.1  ad 	volatile struct zx_draw *zd;
    497  1.1  ad 	volatile struct zx_command *zc;
    498  1.1  ad 	struct fbtype *fbt;
    499  1.1  ad 	u_int i;
    500  1.1  ad 
    501  1.1  ad 	zd = sc->sc_zd_ss0;
    502  1.1  ad 	zc = sc->sc_zc;
    503  1.1  ad 	fbt = &sc->sc_fb.fb_type;
    504  1.1  ad 
    505  1.1  ad 	zx_cross_loadwid(sc, ZX_WID_DBL_8, 0, 0x2c0);
    506  1.1  ad 	zx_cross_loadwid(sc, ZX_WID_DBL_8, 1, 0x30);
    507  1.1  ad 	zx_cross_loadwid(sc, ZX_WID_DBL_8, 2, 0x20);
    508  1.1  ad 	zx_cross_loadwid(sc, ZX_WID_DBL_24, 1, 0x30);
    509  1.1  ad 
    510  1.1  ad 	i = sc->sc_zd_ss1->zd_misc;
    511  1.1  ad 	i |= ZX_SS1_MISC_ENABLE;
    512  1.1  ad 	SETREG(sc->sc_zd_ss1->zd_misc, i);
    513  1.1  ad 
    514  1.2  ad 	SETREG(zd->zd_wid, 0xffffffff);
    515  1.2  ad 	SETREG(zd->zd_widclip, 0);
    516  1.1  ad 	SETREG(zd->zd_wmask, 0xffff);
    517  1.1  ad 	SETREG(zd->zd_vclipmin, 0);
    518  1.1  ad 	SETREG(zd->zd_vclipmax,
    519  1.1  ad 	    (fbt->fb_width - 1) | ((fbt->fb_height - 1) << 16));
    520  1.1  ad 	SETREG(zd->zd_fg, 0);
    521  1.1  ad 	SETREG(zd->zd_planemask, 0xff000000);
    522  1.1  ad 	SETREG(zd->zd_rop, ZX_STD_ROP);
    523  1.1  ad 
    524  1.1  ad 	SETREG(zc->zc_extent,
    525  1.1  ad 	    (fbt->fb_width - 1) | ((fbt->fb_height - 1) << 11));
    526  1.1  ad 	SETREG(zc->zc_addrspace, ZX_ADDRSPC_FONT_OBGR);
    527  1.1  ad 	SETREG(zc->zc_fontt, 0);
    528  1.1  ad 
    529  1.1  ad 	for (i = 0; i < 256; i++) {
    530  1.1  ad 		sc->sc_cmap[i] = rasops_cmap[i * 3];
    531  1.1  ad 		sc->sc_cmap[i + 256] = rasops_cmap[i * 3 + 1];
    532  1.1  ad 		sc->sc_cmap[i + 512] = rasops_cmap[i * 3 + 2];
    533  1.1  ad 	}
    534  1.1  ad 
    535  1.1  ad 	zx_cmap_put(sc);
    536  1.1  ad }
    537  1.1  ad 
    538  1.1  ad int
    539  1.1  ad zx_cross_wait(struct zx_softc *sc)
    540  1.1  ad {
    541  1.1  ad 	volatile struct zx_cross *zx;
    542  1.1  ad 	int i;
    543  1.1  ad 
    544  1.1  ad 	zx = sc->sc_zx;
    545  1.1  ad 
    546  1.1  ad 	for (i = 300000; i != 0; i--) {
    547  1.1  ad 		if ((zx->zx_csr & ZX_CROSS_CSR_PROGRESS) == 0)
    548  1.1  ad 			break;
    549  1.1  ad 		DELAY(1);
    550  1.1  ad 	}
    551  1.1  ad 
    552  1.1  ad 	if (i == 0)
    553  1.1  ad 		printf("zx_cross_wait: timed out\n");
    554  1.1  ad 
    555  1.1  ad 	return (i);
    556  1.1  ad }
    557  1.1  ad 
    558  1.1  ad int
    559  1.1  ad zx_cross_loadwid(struct zx_softc *sc, u_int type, u_int index, u_int value)
    560  1.1  ad {
    561  1.1  ad 	volatile struct zx_cross *zx;
    562  1.1  ad 	u_int tmp;
    563  1.1  ad 
    564  1.1  ad 	zx = sc->sc_zx;
    565  1.1  ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_WID);
    566  1.1  ad 
    567  1.1  ad 	if (zx_cross_wait(sc))
    568  1.1  ad 		return (1);
    569  1.1  ad 
    570  1.1  ad 	if (type == ZX_WID_DBL_8)
    571  1.1  ad 		tmp = (index & 0x0f) + 0x40;
    572  1.1  ad 	else if (type == ZX_WID_DBL_24)
    573  1.1  ad 		tmp = index & 0x3f;
    574  1.1  ad 
    575  1.1  ad 	SETREG(zx->zx_type, 0x5800 + tmp);
    576  1.1  ad 	SETREG(zx->zx_value, value);
    577  1.1  ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_WID);
    578  1.1  ad 	SETREG(zx->zx_csr, ZX_CROSS_CSR_UNK | ZX_CROSS_CSR_UNK2);
    579  1.1  ad 
    580  1.1  ad 	return (0);
    581  1.1  ad }
    582  1.1  ad 
    583  1.1  ad int
    584  1.1  ad zx_cmap_put(struct zx_softc *sc)
    585  1.1  ad {
    586  1.1  ad 	volatile struct zx_cross *zx;
    587  1.1  ad 	const u_char *b;
    588  1.1  ad 	u_int i, t;
    589  1.1  ad 
    590  1.1  ad 	zx = sc->sc_zx;
    591  1.1  ad 
    592  1.1  ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_CLUT0);
    593  1.1  ad 	if (zx_cross_wait(sc))
    594  1.1  ad 		return (1);
    595  1.1  ad 
    596  1.1  ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_CLUTDATA);
    597  1.1  ad 
    598  1.1  ad 	for (i = 0, b = sc->sc_cmap; i < 256; i++) {
    599  1.1  ad 		t = b[i];
    600  1.1  ad 		t |= b[i + 256] << 8;
    601  1.1  ad 		t |= b[i + 512] << 16;
    602  1.1  ad 		SETREG(zx->zx_value, t);
    603  1.1  ad 	}
    604  1.1  ad 
    605  1.1  ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_CLUT0);
    606  1.1  ad 	i = zx->zx_csr;
    607  1.1  ad 	i = i | ZX_CROSS_CSR_UNK | ZX_CROSS_CSR_UNK2;
    608  1.1  ad 	SETREG(zx->zx_csr, i);
    609  1.1  ad 	return (0);
    610  1.1  ad }
    611  1.1  ad 
    612  1.1  ad void
    613  1.1  ad zx_cursor_move(struct zx_softc *sc)
    614  1.1  ad {
    615  1.1  ad 	volatile struct zx_cursor *zcu;
    616  1.1  ad 	int sx, sy, x, y;
    617  1.1  ad 
    618  1.1  ad 	x = sc->sc_curpos.x - sc->sc_curhot.x;
    619  1.1  ad 	y = sc->sc_curpos.y - sc->sc_curhot.y;
    620  1.1  ad 	zcu = sc->sc_zcu;
    621  1.1  ad 
    622  1.1  ad 	if (x < 0) {
    623  1.1  ad 		sx = min(-x, 32);
    624  1.1  ad 		x = 0;
    625  1.1  ad 	} else
    626  1.1  ad 		sx = 0;
    627  1.1  ad 
    628  1.1  ad 	if (y < 0) {
    629  1.1  ad 		sy = min(-y, 32);
    630  1.1  ad 		y = 0;
    631  1.1  ad 	} else
    632  1.1  ad 		sy = 0;
    633  1.1  ad 
    634  1.1  ad 	if (sx != sc->sc_shiftx || sy != sc->sc_shifty) {
    635  1.1  ad 		sc->sc_shiftx = sx;
    636  1.1  ad 		sc->sc_shifty = sy;
    637  1.1  ad 		zx_cursor_set(sc);
    638  1.1  ad 	}
    639  1.1  ad 
    640  1.1  ad 	SETREG(zcu->zcu_sxy, ((y & 0x7ff) << 11) | (x & 0x7ff));
    641  1.1  ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x30);
    642  1.1  ad 
    643  1.1  ad 	/* XXX Necessary? */
    644  1.1  ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x80);
    645  1.1  ad }
    646  1.1  ad 
    647  1.1  ad void
    648  1.1  ad zx_cursor_set(struct zx_softc *sc)
    649  1.1  ad {
    650  1.1  ad 	volatile struct zx_cursor *zcu;
    651  1.1  ad 	int i, j, data;
    652  1.1  ad 
    653  1.1  ad 	zcu = sc->sc_zcu;
    654  1.2  ad 
    655  1.2  ad 	if ((sc->sc_flags & ZX_CURSOR) != 0)
    656  1.2  ad 		SETREG(zcu->zcu_misc, zcu->zcu_misc & ~0x80);
    657  1.1  ad 
    658  1.1  ad 	for (j = 0; j < 2; j++) {
    659  1.2  ad 		SETREG(zcu->zcu_type, 0x20 << i);
    660  1.2  ad 
    661  1.1  ad 		for (i = sc->sc_shifty; i < 32; i++) {
    662  1.1  ad 			data = sc->sc_curbits[j][i];
    663  1.1  ad 			SETREG(zcu->zcu_data, data >> sc->sc_shiftx);
    664  1.1  ad 		}
    665  1.1  ad 		for (i = sc->sc_shifty; i != 0; i--)
    666  1.1  ad 			SETREG(zcu->zcu_data, 0);
    667  1.1  ad 	}
    668  1.2  ad 
    669  1.2  ad 	if ((sc->sc_flags & ZX_CURSOR) != 0)
    670  1.2  ad 		SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x80);
    671  1.1  ad }
    672  1.1  ad 
    673  1.1  ad void
    674  1.1  ad zx_cursor_blank(struct zx_softc *sc)
    675  1.1  ad {
    676  1.1  ad 	volatile struct zx_cursor *zcu;
    677  1.1  ad 
    678  1.1  ad 	sc->sc_flags &= ~ZX_CURSOR;
    679  1.1  ad 	zcu = sc->sc_zcu;
    680  1.1  ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc & ~0x80);
    681  1.1  ad }
    682  1.1  ad 
    683  1.1  ad void
    684  1.1  ad zx_cursor_unblank(struct zx_softc *sc)
    685  1.1  ad {
    686  1.1  ad 	volatile struct zx_cursor *zcu;
    687  1.1  ad 
    688  1.1  ad 	sc->sc_flags |= ZX_CURSOR;
    689  1.1  ad 	zcu = sc->sc_zcu;
    690  1.1  ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x80);
    691  1.1  ad }
    692  1.1  ad 
    693  1.1  ad void
    694  1.1  ad zx_cursor_color(struct zx_softc *sc)
    695  1.1  ad {
    696  1.1  ad 	volatile struct zx_cursor *zcu;
    697  1.1  ad 	u_int8_t tmp;
    698  1.1  ad 
    699  1.1  ad 	zcu = sc->sc_zcu;
    700  1.1  ad 
    701  1.1  ad 	SETREG(zcu->zcu_type, 0x50);
    702  1.1  ad 
    703  1.1  ad 	tmp = sc->sc_curcmap[0] | (sc->sc_curcmap[2] << 8) |
    704  1.1  ad 	    (sc->sc_curcmap[4] << 16);
    705  1.1  ad 	SETREG(zcu->zcu_data, tmp);
    706  1.1  ad 
    707  1.1  ad 	tmp = sc->sc_curcmap[1] | (sc->sc_curcmap[3] << 8) |
    708  1.1  ad 	    (sc->sc_curcmap[5] << 16);
    709  1.1  ad 	SETREG(zcu->zcu_data, sc->sc_curcmap[1]);
    710  1.1  ad 
    711  1.1  ad 	SETREG(zcu->zcu_misc, zcu->zcu_misc | 0x03);
    712  1.1  ad }
    713  1.1  ad 
    714  1.1  ad void
    715  1.1  ad zx_blank(struct device *dv)
    716  1.1  ad {
    717  1.1  ad 	struct zx_softc *sc;
    718  1.1  ad 	volatile struct zx_cross *zx;
    719  1.1  ad 
    720  1.1  ad 	sc = (struct zx_softc *)dv;
    721  1.1  ad 
    722  1.1  ad 	if ((sc->sc_flags & ZX_BLANKED) != 0)
    723  1.1  ad 		return;
    724  1.1  ad 	sc->sc_flags |= ZX_BLANKED;
    725  1.1  ad 
    726  1.1  ad 	zx = sc->sc_zx;
    727  1.1  ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_VIDEO);
    728  1.1  ad 	SETREG(zx->zx_csr, zx->zx_csr & ~ZX_CROSS_CSR_ENABLE);
    729  1.1  ad }
    730  1.1  ad 
    731  1.1  ad void
    732  1.1  ad zx_unblank(struct device *dv)
    733  1.1  ad {
    734  1.1  ad 	struct zx_softc *sc;
    735  1.1  ad 	volatile struct zx_cross *zx;
    736  1.1  ad 
    737  1.1  ad 	sc = (struct zx_softc *)dv;
    738  1.1  ad 
    739  1.1  ad 	if ((sc->sc_flags & ZX_BLANKED) == 0)
    740  1.1  ad 		return;
    741  1.1  ad 	sc->sc_flags &= ~ZX_BLANKED;
    742  1.1  ad 
    743  1.1  ad 	zx = sc->sc_zx;
    744  1.1  ad 	SETREG(zx->zx_type, ZX_CROSS_TYPE_VIDEO);
    745  1.1  ad 	SETREG(zx->zx_csr, zx->zx_csr | ZX_CROSS_CSR_ENABLE);
    746  1.1  ad }
    747  1.1  ad 
    748  1.1  ad paddr_t
    749  1.1  ad zxmmap(dev_t dev, off_t off, int prot)
    750  1.1  ad {
    751  1.1  ad 	struct zx_softc *sc;
    752  1.1  ad 	const struct zx_mmo *mm, *max;
    753  1.2  ad 
    754  1.1  ad 	sc = device_lookup(&zx_cd, minor(dev));
    755  1.2  ad 	off = trunc_page(off);
    756  1.1  ad 	mm = zx_mmo;
    757  1.1  ad 	max = mm + sizeof(zx_mmo) / sizeof(zx_mmo[0]);
    758  1.1  ad 
    759  1.1  ad 	for (; mm < max; mm++)
    760  1.1  ad 		if (off >= mm->mo_va && off < mm->mo_va + mm->mo_size) {
    761  1.1  ad 			off = off - mm->mo_va + mm->mo_pa;
    762  1.1  ad 			return (bus_space_mmap(sc->sc_bt, sc->sc_paddr,
    763  1.1  ad 			    off, prot, BUS_SPACE_MAP_LINEAR));
    764  1.1  ad 		}
    765  1.1  ad 
    766  1.1  ad 	return (-1);
    767  1.1  ad }
    768  1.1  ad 
    769  1.1  ad void
    770  1.1  ad zx_fillrect(struct rasops_info *ri, int x, int y, int w, int h, long attr,
    771  1.1  ad 	    int rop)
    772  1.1  ad {
    773  1.1  ad 	struct zx_softc *sc;
    774  1.1  ad 	volatile struct zx_command *zc;
    775  1.1  ad 	volatile struct zx_draw *zd;
    776  1.1  ad 	int fg, bg;
    777  1.1  ad 
    778  1.1  ad 	sc = ri->ri_hw;
    779  1.1  ad 	zc = sc->sc_zc;
    780  1.1  ad 	zd = sc->sc_zd_ss0;
    781  1.1  ad 
    782  1.1  ad 	rasops_unpack_attr(attr, &fg, &bg, NULL);
    783  1.1  ad 	x = x * sc->sc_fontw + ri->ri_xorigin;
    784  1.1  ad 	y = y * sc->sc_fonth + ri->ri_yorigin;
    785  1.1  ad 	w = sc->sc_fontw * w - 1;
    786  1.1  ad 	h = sc->sc_fonth * h - 1;
    787  1.1  ad 
    788  1.1  ad 	while ((zc->zc_csr & ZX_CSR_BLT_BUSY) != 0)
    789  1.1  ad 		;
    790  1.1  ad 
    791  1.1  ad 	SETREG(zd->zd_rop, rop);
    792  1.1  ad 	SETREG(zd->zd_fg, (bg & 7) ? 0x00000000 : 0xff000000);
    793  1.1  ad 	SETREG(zc->zc_extent, w | (h << 11));
    794  1.1  ad 	SETREG(zc->zc_fill, x | (y << 11) | 0x80000000);
    795  1.1  ad }
    796  1.1  ad 
    797  1.1  ad void
    798  1.1  ad zx_copyrect(struct rasops_info *ri, int sx, int sy, int dx, int dy, int w,
    799  1.1  ad 	    int h)
    800  1.1  ad {
    801  1.1  ad 	struct zx_softc *sc;
    802  1.1  ad 	volatile struct zx_command *zc;
    803  1.1  ad 	volatile struct zx_draw *zd;
    804  1.1  ad 	int dir;
    805  1.1  ad 
    806  1.1  ad 	sc = ri->ri_hw;
    807  1.1  ad 	zc = sc->sc_zc;
    808  1.1  ad 	zd = sc->sc_zd_ss0;
    809  1.1  ad 
    810  1.1  ad 	sx = sx * sc->sc_fontw + ri->ri_xorigin;
    811  1.1  ad 	sy = sy * sc->sc_fonth + ri->ri_yorigin;
    812  1.1  ad 	dx = dx * sc->sc_fontw + ri->ri_xorigin;
    813  1.1  ad 	dy = dy * sc->sc_fonth + ri->ri_yorigin;
    814  1.1  ad 	w = w * sc->sc_fontw - 1;
    815  1.1  ad 	h = h * sc->sc_fonth - 1;
    816  1.1  ad 
    817  1.1  ad 	if (sy < dy || sx < dx) {
    818  1.1  ad 		dir = 0x80000000;
    819  1.1  ad 		sx += w;
    820  1.1  ad 		sy += h;
    821  1.1  ad 		dx += w;
    822  1.1  ad 		dy += h;
    823  1.1  ad 	} else
    824  1.1  ad 		dir = 0;
    825  1.1  ad 
    826  1.1  ad 	while ((zc->zc_csr & ZX_CSR_BLT_BUSY) != 0)
    827  1.1  ad 		;
    828  1.1  ad 
    829  1.1  ad 	SETREG(zd->zd_rop, ZX_STD_ROP);
    830  1.1  ad 	SETREG(zc->zc_extent, w | (h << 11) | dir);
    831  1.1  ad 	SETREG(zc->zc_src, sx | (sy << 11));
    832  1.1  ad 	SETREG(zc->zc_copy, dx | (dy << 11));
    833  1.1  ad }
    834  1.1  ad 
    835  1.1  ad void
    836  1.1  ad zx_do_cursor(struct rasops_info *ri)
    837  1.1  ad {
    838  1.1  ad 
    839  1.1  ad 	zx_fillrect(ri, ri->ri_ccol, ri->ri_crow, 1, 1, 0,
    840  1.1  ad 	    ZX_ROP_NEW_XOR_OLD | ZX_ATTR_WE_ENABLE | ZX_ATTR_OE_ENABLE |
    841  1.1  ad 	    ZX_ATTR_FORCE_WID);
    842  1.1  ad }
    843  1.1  ad 
    844  1.1  ad void
    845  1.1  ad zx_erasecols(void *cookie, int row, int col, int num, long attr)
    846  1.1  ad {
    847  1.1  ad 	struct rasops_info *ri;
    848  1.1  ad 
    849  1.1  ad 	ri = (struct rasops_info *)cookie;
    850  1.1  ad 
    851  1.1  ad 	zx_fillrect(ri, col, row, num, 1, attr, ZX_STD_ROP);
    852  1.1  ad }
    853  1.1  ad 
    854  1.1  ad void
    855  1.1  ad zx_eraserows(void *cookie, int row, int num, long attr)
    856  1.1  ad {
    857  1.1  ad 	struct rasops_info *ri;
    858  1.1  ad 
    859  1.1  ad 	ri = (struct rasops_info *)cookie;
    860  1.1  ad 
    861  1.1  ad 	zx_fillrect(ri, 0, row, ri->ri_cols, num, attr, ZX_STD_ROP);
    862  1.1  ad }
    863  1.1  ad 
    864  1.1  ad void
    865  1.1  ad zx_copyrows(void *cookie, int src, int dst, int num)
    866  1.1  ad {
    867  1.1  ad 	struct rasops_info *ri;
    868  1.1  ad 
    869  1.1  ad 	ri = (struct rasops_info *)cookie;
    870  1.1  ad 
    871  1.1  ad 	zx_copyrect(ri, 0, src, 0, dst, ri->ri_cols, num);
    872  1.1  ad }
    873  1.1  ad 
    874  1.1  ad void
    875  1.1  ad zx_copycols(void *cookie, int row, int src, int dst, int num)
    876  1.1  ad {
    877  1.1  ad 	struct rasops_info *ri;
    878  1.1  ad 
    879  1.1  ad 	ri = (struct rasops_info *)cookie;
    880  1.1  ad 
    881  1.1  ad 	zx_copyrect(ri, src, row, dst, row, num, 1);
    882  1.1  ad }
    883  1.1  ad 
    884  1.1  ad void
    885  1.1  ad zx_putchar(void *cookie, int row, int col, u_int uc, long attr)
    886  1.1  ad {
    887  1.1  ad 	struct rasops_info *ri;
    888  1.1  ad 	struct zx_softc *sc;
    889  1.1  ad 	struct wsdisplay_font *font;
    890  1.1  ad 	volatile struct zx_command *zc;
    891  1.1  ad 	volatile struct zx_draw *zd;
    892  1.1  ad 	volatile u_int32_t *dp;
    893  1.1  ad 	u_int8_t *fb;
    894  1.1  ad 	int fs, i, fg, bg, ul;
    895  1.1  ad 
    896  1.1  ad 	ri = (struct rasops_info *)cookie;
    897  1.1  ad 
    898  1.1  ad 	if (uc == ' ') {
    899  1.1  ad 		zx_fillrect(ri, col, row, 1, 1, attr, ZX_STD_ROP);
    900  1.1  ad 		return;
    901  1.1  ad 	}
    902  1.1  ad 
    903  1.1  ad 	sc = (struct zx_softc *)ri->ri_hw;
    904  1.1  ad 	font = ri->ri_font;
    905  1.1  ad 	zc = sc->sc_zc;
    906  1.1  ad 	zd = sc->sc_zd_ss0;
    907  1.1  ad 
    908  1.1  ad 	dp = (volatile u_int32_t *)sc->sc_pixels +
    909  1.1  ad 	    ((row * sc->sc_fonth + ri->ri_yorigin) << 11) +
    910  1.1  ad 	    (col * sc->sc_fontw + ri->ri_xorigin);
    911  1.1  ad 	fb = (u_int8_t *)font->data + (uc - font->firstchar) *
    912  1.1  ad 	    ri->ri_fontscale;
    913  1.1  ad 	fs = font->stride;
    914  1.1  ad 	rasops_unpack_attr(attr, &fg, &bg, &ul);
    915  1.1  ad 
    916  1.1  ad 	while ((zc->zc_csr & ZX_CSR_BLT_BUSY) != 0)
    917  1.1  ad 		;
    918  1.1  ad 
    919  1.1  ad 	SETREG(zd->zd_rop, ZX_STD_ROP);
    920  1.1  ad 	SETREG(zd->zd_fg, (fg & 7) ? 0x00000000 : 0xff000000);
    921  1.1  ad 	SETREG(zd->zd_bg, (bg & 7) ? 0x00000000 : 0xff000000);
    922  1.1  ad 	SETREG(zc->zc_fontmsk, 0xffffffff << (32 - sc->sc_fontw));
    923  1.1  ad 
    924  1.1  ad 	if (sc->sc_fontw <= 8) {
    925  1.1  ad 		for (i = sc->sc_fonth; i != 0; i--, dp += 2048) {
    926  1.1  ad 			*dp = *fb << 24;
    927  1.1  ad 			fb += fs;
    928  1.1  ad 		}
    929  1.1  ad 	} else {
    930  1.1  ad 		for (i = sc->sc_fonth; i != 0; i--, dp += 2048) {
    931  1.1  ad 			*dp = *((u_int16_t *)fb) << 16;
    932  1.1  ad 			fb += fs;
    933  1.1  ad 		}
    934  1.1  ad 	}
    935  1.1  ad 
    936  1.1  ad 	if (ul) {
    937  1.1  ad 		dp -= 4096;
    938  1.1  ad 		*dp = 0xffffffff;
    939  1.1  ad 	}
    940  1.1  ad }
    941