Home | History | Annotate | Line # | Download | only in sbus
zx.c revision 1.39.24.1
      1  1.39.24.1     skrll /*	$NetBSD: zx.c,v 1.39.24.1 2015/12/27 12:09:58 skrll 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  *
     19        1.1        ad  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1        ad  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1        ad  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1        ad  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1        ad  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1        ad  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1        ad  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1        ad  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1        ad  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1        ad  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1        ad  *  POSSIBILITY OF SUCH DAMAGE.
     30        1.1        ad  */
     31        1.1        ad 
     32        1.1        ad /*
     33        1.1        ad  * Driver for the Sun ZX display adapter.  This would be called 'leo', but
     34        1.1        ad  * NetBSD/amiga already has a driver by that name.  The XFree86 and Linux
     35        1.1        ad  * drivers were used as "living documentation" when writing this; thanks
     36        1.1        ad  * to the authors.
     37        1.1        ad  *
     38        1.1        ad  * Issues (which can be solved with wscons, happily enough):
     39        1.1        ad  *
     40        1.1        ad  * o There is lots of unnecessary mucking about rasops in here, primarily
     41        1.1        ad  *   to appease the sparc fb code.
     42        1.1        ad  *
     43        1.1        ad  * o RASTERCONSOLE is required.  X needs the board set up correctly, and
     44        1.1        ad  *   that's difficult to reconcile with using the PROM for output.
     45        1.1        ad  */
     46        1.1        ad 
     47        1.1        ad #include <sys/cdefs.h>
     48  1.39.24.1     skrll __KERNEL_RCSID(0, "$NetBSD: zx.c,v 1.39.24.1 2015/12/27 12:09:58 skrll Exp $");
     49        1.1        ad 
     50        1.1        ad #include <sys/param.h>
     51        1.1        ad #include <sys/systm.h>
     52        1.1        ad #include <sys/device.h>
     53        1.1        ad #include <sys/ioctl.h>
     54        1.1        ad #include <sys/malloc.h>
     55        1.1        ad #include <sys/mman.h>
     56        1.1        ad #include <sys/tty.h>
     57        1.1        ad #include <sys/conf.h>
     58        1.1        ad #include <sys/syslog.h>
     59        1.1        ad #include <sys/buf.h>
     60       1.38  uebayasi #ifdef DEBUG
     61       1.38  uebayasi /* for log(9) in zxioctl() */
     62       1.38  uebayasi #include <sys/lwp.h>
     63       1.38  uebayasi #include <sys/proc.h>
     64       1.38  uebayasi #endif
     65        1.1        ad 
     66       1.20        ad #include <sys/bus.h>
     67        1.1        ad #include <machine/autoconf.h>
     68        1.1        ad 
     69        1.1        ad #include <dev/sun/fbio.h>
     70        1.1        ad #include <dev/sun/fbvar.h>
     71        1.1        ad 
     72       1.27  macallan #include "wsdisplay.h"
     73       1.27  macallan #if NWSDISPLAY > 0
     74       1.27  macallan #include <dev/wscons/wsconsio.h>
     75       1.27  macallan #include <dev/wsfont/wsfont.h>
     76       1.27  macallan #include <dev/rasops/rasops.h>
     77       1.27  macallan #include <dev/wscons/wsdisplay_vconsvar.h>
     78       1.27  macallan 
     79       1.27  macallan #include "opt_wsemul.h"
     80       1.27  macallan #endif
     81       1.27  macallan 
     82        1.1        ad #include <dev/sbus/zxreg.h>
     83        1.1        ad #include <dev/sbus/zxvar.h>
     84        1.1        ad #include <dev/sbus/sbusvar.h>
     85        1.1        ad 
     86        1.1        ad #include <dev/wscons/wsconsio.h>
     87        1.1        ad 
     88       1.32   tsutsui #include "ioconf.h"
     89       1.32   tsutsui 
     90       1.27  macallan #if (NWSDISPLAY == 0) && !defined(RASTERCONSOLE)
     91       1.27  macallan #error Sorry, this driver needs WSCONS or RASTERCONSOLE
     92       1.27  macallan #endif
     93       1.27  macallan 
     94       1.27  macallan #if (NWSDISPLAY > 0) && defined(RASTERCONSOLE)
     95       1.27  macallan #error Sorry, RASTERCONSOLE and WSCONS are mutually exclusive
     96        1.1        ad #endif
     97        1.1        ad 
     98        1.1        ad #define	ZX_STD_ROP	(ZX_ROP_NEW | ZX_ATTR_WE_ENABLE | \
     99        1.1        ad     ZX_ATTR_OE_ENABLE | ZX_ATTR_FORCE_WID)
    100        1.1        ad 
    101       1.27  macallan static void	zx_attach(device_t, device_t, void *);
    102       1.29    cegger static int	zx_match(device_t, cfdata_t, void *);
    103        1.1        ad 
    104       1.27  macallan static void	zx_blank(device_t);
    105       1.27  macallan static int	zx_cmap_put(struct zx_softc *);
    106       1.27  macallan static void	zx_copyrect(struct zx_softc *, int, int, int, int, int, int);
    107       1.27  macallan static int	zx_cross_loadwid(struct zx_softc *, u_int, u_int, u_int);
    108       1.27  macallan static int	zx_cross_wait(struct zx_softc *);
    109       1.27  macallan static void	zx_fillrect(struct zx_softc *, int, int, int, int, uint32_t, int);
    110       1.27  macallan static int	zx_intr(void *);
    111       1.27  macallan static void	zx_reset(struct zx_softc *);
    112       1.27  macallan static void	zx_unblank(device_t);
    113       1.27  macallan 
    114       1.27  macallan static void	zx_cursor_blank(struct zx_softc *);
    115       1.27  macallan static void	zx_cursor_color(struct zx_softc *);
    116       1.27  macallan static void	zx_cursor_move(struct zx_softc *);
    117       1.27  macallan static void	zx_cursor_set(struct zx_softc *);
    118       1.27  macallan static void	zx_cursor_unblank(struct zx_softc *);
    119       1.27  macallan 
    120       1.27  macallan static void	zx_copycols(void *, int, int, int, int);
    121       1.27  macallan static void	zx_copyrows(void *, int, int, int);
    122       1.27  macallan static void	zx_do_cursor(void *, int, int, int);
    123       1.27  macallan static void	zx_erasecols(void *, int, int, int, long);
    124       1.27  macallan static void	zx_eraserows(void *, int, int, long);
    125       1.27  macallan static void	zx_putchar(void *, int, int, u_int, long);
    126        1.1        ad 
    127        1.1        ad struct zx_mmo {
    128        1.1        ad 	off_t	mo_va;
    129        1.1        ad 	off_t	mo_pa;
    130        1.1        ad 	off_t	mo_size;
    131        1.1        ad } static const zx_mmo[] = {
    132        1.1        ad 	{ ZX_FB0_VOFF,		ZX_OFF_SS0,		0x00800000 },
    133        1.1        ad 	{ ZX_LC0_VOFF,		ZX_OFF_LC_SS0_USR,	0x00001000 },
    134        1.1        ad 	{ ZX_LD0_VOFF,		ZX_OFF_LD_SS0,		0x00001000 },
    135        1.1        ad 	{ ZX_LX0_CURSOR_VOFF,	ZX_OFF_LX_CURSOR,	0x00001000 },
    136        1.1        ad 	{ ZX_FB1_VOFF,		ZX_OFF_SS1,		0x00800000 },
    137        1.1        ad 	{ ZX_LC1_VOFF,		ZX_OFF_LC_SS1_USR,	0x00001000 },
    138        1.1        ad 	{ ZX_LD1_VOFF,		ZX_OFF_LD_SS1,		0x00001000 },
    139        1.1        ad 	{ ZX_LX_KRN_VOFF,	ZX_OFF_LX_CROSS,	0x00001000 },
    140        1.1        ad 	{ ZX_LC0_KRN_VOFF,	ZX_OFF_LC_SS0_KRN,	0x00001000 },
    141        1.1        ad 	{ ZX_LC1_KRN_VOFF,	ZX_OFF_LC_SS1_KRN,	0x00001000 },
    142        1.1        ad 	{ ZX_LD_GBL_VOFF,	ZX_OFF_LD_GBL,		0x00001000 },
    143       1.14     perry };
    144        1.1        ad 
    145       1.27  macallan CFATTACH_DECL_NEW(zx, sizeof(struct zx_softc),
    146        1.5   thorpej     zx_match, zx_attach, NULL, NULL);
    147        1.1        ad 
    148       1.27  macallan static dev_type_open(zxopen);
    149       1.27  macallan static dev_type_close(zxclose);
    150       1.27  macallan static dev_type_ioctl(zxioctl);
    151       1.27  macallan static dev_type_mmap(zxmmap);
    152        1.1        ad 
    153        1.1        ad static struct fbdriver zx_fbdriver = {
    154        1.1        ad 	zx_unblank, zxopen, zxclose, zxioctl, nopoll, zxmmap
    155        1.1        ad };
    156        1.1        ad 
    157       1.27  macallan #if NWSDISPLAY > 0
    158       1.27  macallan struct wsscreen_descr zx_defaultscreen = {
    159       1.27  macallan 	"std",
    160       1.27  macallan 	0, 0,	/* will be filled in -- XXX shouldn't, it's global */
    161       1.27  macallan 		/* doesn't matter - you can't really have more than one leo */
    162       1.27  macallan 	NULL,		/* textops */
    163       1.27  macallan 	8, 16,	/* font width/height */
    164       1.27  macallan 	WSSCREEN_WSCOLORS,	/* capabilities */
    165       1.27  macallan 	NULL	/* modecookie */
    166       1.27  macallan };
    167       1.27  macallan 
    168       1.27  macallan static int 	zx_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    169       1.27  macallan static paddr_t	zx_mmap(void *, void *, off_t, int);
    170       1.27  macallan static void	zx_init_screen(void *, struct vcons_screen *, int, long *);
    171       1.27  macallan 
    172       1.27  macallan static int	zx_putcmap(struct zx_softc *, struct wsdisplay_cmap *);
    173       1.27  macallan static int	zx_getcmap(struct zx_softc *, struct wsdisplay_cmap *);
    174       1.27  macallan 
    175       1.27  macallan struct wsdisplay_accessops zx_accessops = {
    176       1.27  macallan 	zx_ioctl,
    177       1.27  macallan 	zx_mmap,
    178       1.27  macallan 	NULL,	/* alloc_screen */
    179       1.27  macallan 	NULL,	/* free_screen */
    180       1.27  macallan 	NULL,	/* show_screen */
    181       1.27  macallan 	NULL, 	/* load_font */
    182       1.27  macallan 	NULL,	/* pollc */
    183       1.27  macallan 	NULL	/* scroll */
    184       1.27  macallan };
    185       1.27  macallan 
    186       1.27  macallan const struct wsscreen_descr *_zx_scrlist[] = {
    187       1.27  macallan 	&zx_defaultscreen
    188       1.27  macallan };
    189       1.27  macallan 
    190       1.27  macallan struct wsscreen_list zx_screenlist = {
    191       1.27  macallan 	sizeof(_zx_scrlist) / sizeof(struct wsscreen_descr *),
    192       1.27  macallan 	_zx_scrlist
    193       1.27  macallan };
    194       1.27  macallan 
    195       1.27  macallan 
    196       1.27  macallan extern const u_char rasops_cmap[768];
    197       1.27  macallan 
    198       1.27  macallan static struct vcons_screen zx_console_screen;
    199       1.27  macallan #endif /* NWSDISPLAY > 0 */
    200       1.27  macallan 
    201       1.27  macallan static int
    202       1.29    cegger zx_match(device_t parent, cfdata_t cf, void *aux)
    203        1.1        ad {
    204        1.1        ad 	struct sbus_attach_args *sa;
    205       1.14     perry 
    206        1.1        ad 	sa = (struct sbus_attach_args *)aux;
    207        1.1        ad 
    208        1.1        ad 	return (strcmp(sa->sa_name, "SUNW,leo") == 0);
    209        1.1        ad }
    210        1.1        ad 
    211       1.27  macallan static void
    212       1.27  macallan zx_attach(device_t parent, device_t self, void *args)
    213        1.1        ad {
    214        1.1        ad 	struct zx_softc *sc;
    215        1.1        ad 	struct sbus_attach_args *sa;
    216        1.1        ad 	bus_space_handle_t bh;
    217        1.1        ad 	bus_space_tag_t bt;
    218        1.1        ad 	struct fbdevice *fb;
    219       1.27  macallan #if NWSDISPLAY > 0
    220       1.27  macallan 	struct wsemuldisplaydev_attach_args aa;
    221       1.27  macallan 	struct rasops_info *ri = &zx_console_screen.scr_ri;
    222       1.27  macallan 	unsigned long defattr;
    223       1.27  macallan #endif
    224       1.28  macallan 	int isconsole, width, height;
    225        1.1        ad 
    226       1.24  drochner 	sc = device_private(self);
    227       1.27  macallan 	sc->sc_dv = self;
    228       1.27  macallan 
    229        1.1        ad 	sa = args;
    230        1.1        ad 	fb = &sc->sc_fb;
    231        1.1        ad 	bt = sa->sa_bustag;
    232        1.1        ad 	sc->sc_bt = bt;
    233        1.1        ad 	sc->sc_paddr = sbus_bus_addr(bt, sa->sa_slot, sa->sa_offset);
    234        1.1        ad 
    235       1.30  macallan 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_SS0,
    236       1.30  macallan 	    0x800000, BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE, &bh) != 0) {
    237       1.21    cegger 		aprint_error_dev(self, "can't map bits\n");
    238        1.1        ad 		return;
    239        1.1        ad 	}
    240       1.19  christos 	fb->fb_pixels = (void *)bus_space_vaddr(bt, bh);
    241       1.33   tsutsui 	sc->sc_pixels = (uint32_t *)fb->fb_pixels;
    242        1.1        ad 
    243        1.1        ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LC_SS0_USR,
    244        1.1        ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    245       1.21    cegger 		aprint_error_dev(self, "can't map zc\n");
    246        1.1        ad 		return;
    247        1.1        ad 	}
    248       1.27  macallan 
    249       1.25   tsutsui 	sc->sc_bhzc = bh;
    250        1.1        ad 
    251        1.1        ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LD_SS0,
    252        1.1        ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    253       1.21    cegger 		aprint_error_dev(self, "can't map ld/ss0\n");
    254        1.1        ad 		return;
    255        1.1        ad 	}
    256       1.25   tsutsui 	sc->sc_bhzdss0 = bh;
    257        1.1        ad 
    258        1.1        ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LD_SS1,
    259        1.1        ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    260       1.21    cegger 		aprint_error_dev(self, "can't map ld/ss1\n");
    261        1.1        ad 		return;
    262        1.1        ad 	}
    263       1.25   tsutsui 	sc->sc_bhzdss1 = bh;
    264        1.1        ad 
    265        1.1        ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LX_CROSS,
    266        1.1        ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    267       1.21    cegger 		aprint_error_dev(self, "can't map zx\n");
    268        1.1        ad 		return;
    269        1.1        ad 	}
    270       1.25   tsutsui 	sc->sc_bhzx = bh;
    271        1.1        ad 
    272        1.1        ad 	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + ZX_OFF_LX_CURSOR,
    273        1.1        ad 	    PAGE_SIZE, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    274       1.21    cegger 		aprint_error_dev(self, "can't map zcu\n");
    275        1.1        ad 		return;
    276        1.1        ad 	}
    277       1.25   tsutsui 	sc->sc_bhzcu = bh;
    278        1.1        ad 
    279        1.1        ad 	fb->fb_driver = &zx_fbdriver;
    280       1.27  macallan 	fb->fb_device = sc->sc_dv;
    281       1.27  macallan 	fb->fb_flags = device_cfdata(sc->sc_dv)->cf_flags & FB_USERMASK;
    282        1.1        ad 	fb->fb_pfour = NULL;
    283       1.26   tsutsui 	fb->fb_linebytes = prom_getpropint(sa->sa_node, "linebytes", 8192);
    284        1.1        ad 
    285       1.26   tsutsui 	width = prom_getpropint(sa->sa_node, "width", 1280);
    286       1.26   tsutsui 	height = prom_getpropint(sa->sa_node, "height", 1024);
    287       1.26   tsutsui 	fb_setsize_obp(fb, 32, width, height, sa->sa_node);
    288        1.1        ad 
    289        1.1        ad 	fb->fb_type.fb_cmsize = 256;
    290        1.1        ad 	fb->fb_type.fb_depth = 32;
    291        1.1        ad 	fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
    292        1.1        ad 	fb->fb_type.fb_type = FBTYPE_SUNLEO;
    293        1.1        ad 
    294        1.1        ad 	printf(": %d x %d", fb->fb_type.fb_width, fb->fb_type.fb_height);
    295        1.1        ad 	isconsole = fb_is_console(sa->sa_node);
    296        1.1        ad 	if (isconsole)
    297        1.1        ad 		printf(" (console)");
    298        1.1        ad 	printf("\n");
    299        1.1        ad 
    300        1.1        ad 	if (sa->sa_nintr != 0)
    301        1.6        pk 		bus_intr_establish(bt, sa->sa_pri, IPL_NONE, zx_intr, sc);
    302        1.1        ad 
    303        1.1        ad 	sc->sc_cmap = malloc(768, M_DEVBUF, M_NOWAIT);
    304        1.1        ad 	zx_reset(sc);
    305        1.1        ad 
    306       1.27  macallan #if NWSDISPLAY > 0
    307       1.27  macallan 	sc->sc_width = fb->fb_type.fb_width;
    308       1.27  macallan 	sc->sc_stride = 8192; /* 32 bit */
    309       1.27  macallan 	sc->sc_height = fb->fb_type.fb_height;
    310       1.27  macallan 
    311       1.27  macallan 	/* setup rasops and so on for wsdisplay */
    312       1.27  macallan 	wsfont_init();
    313       1.27  macallan 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    314       1.27  macallan 	sc->sc_bg = WS_DEFAULT_BG;
    315       1.27  macallan 
    316       1.27  macallan 	vcons_init(&sc->vd, sc, &zx_defaultscreen, &zx_accessops);
    317       1.27  macallan 	sc->vd.init_screen = zx_init_screen;
    318       1.27  macallan 
    319       1.27  macallan 	if (isconsole) {
    320       1.27  macallan 		/* we mess with zx_console_screen only once */
    321       1.27  macallan 		vcons_init_screen(&sc->vd, &zx_console_screen, 1,
    322       1.27  macallan 		    &defattr);
    323       1.27  macallan 		zx_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    324       1.27  macallan 
    325       1.27  macallan 		zx_defaultscreen.textops = &ri->ri_ops;
    326       1.27  macallan 		zx_defaultscreen.capabilities = WSSCREEN_WSCOLORS;
    327       1.27  macallan 		zx_defaultscreen.nrows = ri->ri_rows;
    328       1.27  macallan 		zx_defaultscreen.ncols = ri->ri_cols;
    329       1.28  macallan 		zx_fillrect(sc, 0, 0, width, height,
    330       1.28  macallan 		     ri->ri_devcmap[defattr >> 16], ZX_STD_ROP);
    331       1.34  macallan 		wsdisplay_cnattach(&zx_defaultscreen, ri, 0, 0, defattr);
    332       1.34  macallan 		vcons_replay_msgbuf(&zx_console_screen);
    333       1.27  macallan 	} else {
    334       1.27  macallan 		/*
    335       1.27  macallan 		 * we're not the console so we just clear the screen and don't
    336       1.27  macallan 		 * set up any sort of text display
    337       1.27  macallan 		 */
    338       1.27  macallan 		if (zx_defaultscreen.textops == NULL) {
    339       1.27  macallan 			/*
    340       1.27  macallan 			 * ugly, but...
    341       1.27  macallan 			 * we want the console settings to win, so we only
    342       1.27  macallan 			 * touch anything when we find an untouched screen
    343       1.27  macallan 			 * definition. In this case we fill it from fb to
    344       1.27  macallan 			 * avoid problems in case no zx is the console
    345       1.27  macallan 			 */
    346       1.27  macallan 			ri = &sc->sc_fb.fb_rinfo;
    347       1.27  macallan 			zx_defaultscreen.textops = &ri->ri_ops;
    348       1.27  macallan 			zx_defaultscreen.capabilities = ri->ri_caps;
    349       1.27  macallan 			zx_defaultscreen.nrows = ri->ri_rows;
    350       1.27  macallan 			zx_defaultscreen.ncols = ri->ri_cols;
    351       1.27  macallan 		}
    352       1.27  macallan 	}
    353        1.1        ad 
    354       1.27  macallan 	aa.scrdata = &zx_screenlist;
    355       1.27  macallan 	aa.console = isconsole;
    356       1.27  macallan 	aa.accessops = &zx_accessops;
    357       1.27  macallan 	aa.accesscookie = &sc->vd;
    358       1.27  macallan 	config_found(sc->sc_dv, &aa, wsemuldisplaydevprint);
    359       1.27  macallan #endif
    360       1.27  macallan 	fb_attach(&sc->sc_fb, isconsole);
    361        1.1        ad }
    362        1.1        ad 
    363       1.27  macallan static int
    364       1.16  christos zxopen(dev_t dev, int flags, int mode, struct lwp *l)
    365        1.1        ad {
    366        1.1        ad 
    367        1.1        ad 	if (device_lookup(&zx_cd, minor(dev)) == NULL)
    368        1.1        ad 		return (ENXIO);
    369        1.1        ad 	return (0);
    370        1.1        ad }
    371        1.1        ad 
    372       1.27  macallan static int
    373       1.16  christos zxclose(dev_t dev, int flags, int mode, struct lwp *l)
    374        1.1        ad {
    375        1.1        ad 	struct zx_softc *sc;
    376        1.1        ad 
    377       1.23    cegger 	sc = device_lookup_private(&zx_cd, minor(dev));
    378        1.1        ad 
    379        1.1        ad 	zx_reset(sc);
    380        1.1        ad 	zx_cursor_blank(sc);
    381        1.1        ad 	return (0);
    382        1.1        ad }
    383        1.1        ad 
    384       1.27  macallan static int
    385       1.19  christos zxioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
    386        1.1        ad {
    387        1.1        ad 	struct zx_softc *sc;
    388        1.1        ad 	struct fbcmap *cm;
    389        1.1        ad 	struct fbcursor *cu;
    390       1.13       chs 	uint32_t curbits[2][32];
    391  1.39.24.1     skrll 	int rv, v, count, i, error;
    392        1.1        ad 
    393       1.23    cegger 	sc = device_lookup_private(&zx_cd, minor(dev));
    394       1.14     perry 
    395        1.1        ad 	switch (cmd) {
    396        1.1        ad 	case FBIOGTYPE:
    397        1.1        ad 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    398        1.1        ad 		break;
    399        1.1        ad 
    400        1.1        ad 	case FBIOGATTR:
    401        1.1        ad #define fba ((struct fbgattr *)data)
    402        1.1        ad 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    403        1.1        ad 		fba->owner = 0;		/* XXX ??? */
    404        1.1        ad 		fba->fbtype = sc->sc_fb.fb_type;
    405        1.1        ad 		fba->sattr.flags = 0;
    406        1.1        ad 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    407        1.1        ad 		fba->sattr.dev_specific[0] = -1;
    408        1.1        ad 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    409        1.1        ad 		fba->emu_types[1] = -1;
    410        1.1        ad 		fba->emu_types[2] = -1;
    411        1.1        ad #undef fba
    412        1.1        ad 		break;
    413        1.1        ad 
    414        1.1        ad 	case FBIOGVIDEO:
    415        1.1        ad 		*(int *)data = ((sc->sc_flags & ZX_BLANKED) != 0);
    416        1.1        ad 		break;
    417        1.1        ad 
    418        1.1        ad 	case FBIOSVIDEO:
    419        1.1        ad 		if (*(int *)data)
    420       1.27  macallan 			zx_unblank(sc->sc_dv);
    421        1.1        ad 		else
    422       1.27  macallan 			zx_blank(sc->sc_dv);
    423        1.1        ad 		break;
    424        1.1        ad 
    425        1.1        ad 	case FBIOGETCMAP:
    426        1.1        ad 		cm = (struct fbcmap *)data;
    427        1.1        ad 		if (cm->index > 256 || cm->count > 256 - cm->index)
    428        1.1        ad 			return (EINVAL);
    429        1.1        ad 		rv = copyout(sc->sc_cmap + cm->index, cm->red, cm->count);
    430        1.2        ad 		if (rv == 0)
    431        1.1        ad 			rv = copyout(sc->sc_cmap + 256 + cm->index, cm->green,
    432        1.1        ad 			    cm->count);
    433        1.2        ad 		if (rv == 0)
    434        1.1        ad 			rv = copyout(sc->sc_cmap + 512 + cm->index, cm->blue,
    435        1.1        ad 			    cm->count);
    436        1.1        ad 		return (rv);
    437        1.1        ad 
    438        1.1        ad 	case FBIOPUTCMAP:
    439        1.1        ad 		cm = (struct fbcmap *)data;
    440        1.1        ad 		if (cm->index > 256 || cm->count > 256 - cm->index)
    441        1.1        ad 			return (EINVAL);
    442        1.1        ad 		rv = copyin(cm->red, sc->sc_cmap + cm->index, cm->count);
    443        1.2        ad 		if (rv == 0)
    444        1.1        ad 			rv = copyin(cm->green, sc->sc_cmap + 256 + cm->index,
    445        1.1        ad 			    cm->count);
    446        1.2        ad 		if (rv == 0)
    447        1.1        ad 			rv = copyin(cm->blue, sc->sc_cmap + 512 + cm->index,
    448        1.1        ad 			    cm->count);
    449        1.1        ad 		zx_cmap_put(sc);
    450        1.1        ad 		return (rv);
    451        1.1        ad 
    452        1.1        ad 	case FBIOGCURPOS:
    453        1.1        ad 		*(struct fbcurpos *)data = sc->sc_curpos;
    454        1.1        ad 		break;
    455        1.1        ad 
    456        1.1        ad 	case FBIOSCURPOS:
    457        1.1        ad 		sc->sc_curpos = *(struct fbcurpos *)data;
    458        1.1        ad 		zx_cursor_move(sc);
    459        1.1        ad 		break;
    460        1.1        ad 
    461        1.1        ad 	case FBIOGCURMAX:
    462        1.1        ad 		((struct fbcurpos *)data)->x = 32;
    463        1.1        ad 		((struct fbcurpos *)data)->y = 32;
    464        1.1        ad 		break;
    465        1.1        ad 
    466        1.1        ad 	case FBIOSCURSOR:
    467        1.1        ad 		cu = (struct fbcursor *)data;
    468        1.1        ad 		v = cu->set;
    469        1.1        ad 
    470        1.1        ad 		if ((v & FB_CUR_SETSHAPE) != 0) {
    471        1.1        ad 			if ((u_int)cu->size.x > 32 || (u_int)cu->size.y > 32)
    472        1.1        ad 				return (EINVAL);
    473        1.1        ad 			count = cu->size.y * 4;
    474       1.13       chs 			rv = copyin(cu->mask, curbits[0], count);
    475       1.13       chs 			if (rv)
    476       1.13       chs 				return rv;
    477       1.13       chs 			rv = copyin(cu->image, curbits[1], count);
    478       1.13       chs 			if (rv)
    479       1.13       chs 				return rv;
    480        1.1        ad 		}
    481        1.1        ad 		if ((v & FB_CUR_SETCUR) != 0) {
    482        1.1        ad 			if (cu->enable)
    483        1.1        ad 				zx_cursor_unblank(sc);
    484        1.1        ad 			else
    485        1.1        ad 				zx_cursor_blank(sc);
    486        1.1        ad 		}
    487        1.1        ad 		if ((v & (FB_CUR_SETPOS | FB_CUR_SETHOT)) != 0) {
    488        1.1        ad 			if ((v & FB_CUR_SETPOS) != 0)
    489        1.1        ad 				sc->sc_curpos = cu->pos;
    490        1.1        ad 			if ((v & FB_CUR_SETHOT) != 0)
    491        1.1        ad 				sc->sc_curhot = cu->hot;
    492        1.1        ad 			zx_cursor_move(sc);
    493        1.1        ad 		}
    494        1.1        ad 		if ((v & FB_CUR_SETCMAP) != 0) {
    495        1.1        ad 			if (cu->cmap.index > 2 ||
    496        1.1        ad 			    cu->cmap.count > 2 - cu->cmap.index)
    497        1.1        ad 				return (EINVAL);
    498        1.1        ad 			for (i = 0; i < cu->cmap.count; i++) {
    499        1.1        ad 				if ((v = fubyte(&cu->cmap.red[i])) < 0)
    500        1.1        ad 					return (EFAULT);
    501        1.1        ad 				sc->sc_curcmap[i + cu->cmap.index + 0] = v;
    502        1.1        ad 				if ((v = fubyte(&cu->cmap.green[i])) < 0)
    503        1.1        ad 					return (EFAULT);
    504        1.1        ad 				sc->sc_curcmap[i + cu->cmap.index + 2] = v;
    505        1.1        ad 				if ((v = fubyte(&cu->cmap.blue[i])) < 0)
    506        1.1        ad 					return (EFAULT);
    507        1.1        ad 				sc->sc_curcmap[i + cu->cmap.index + 4] = v;
    508        1.1        ad 			}
    509        1.1        ad 			zx_cursor_color(sc);
    510        1.1        ad 		}
    511        1.1        ad 		if ((v & FB_CUR_SETSHAPE) != 0) {
    512        1.1        ad 			sc->sc_cursize = cu->size;
    513        1.1        ad 			count = cu->size.y * 4;
    514        1.1        ad 			memset(sc->sc_curbits, 0, sizeof(sc->sc_curbits));
    515       1.13       chs 			memcpy(sc->sc_curbits[0], curbits[0], count);
    516       1.13       chs 			memcpy(sc->sc_curbits[1], curbits[1], count);
    517        1.1        ad 			zx_cursor_set(sc);
    518        1.1        ad 		}
    519        1.1        ad 		break;
    520        1.1        ad 
    521        1.1        ad 	case FBIOGCURSOR:
    522        1.1        ad 		cu = (struct fbcursor *)data;
    523        1.1        ad 
    524        1.1        ad 		cu->set = FB_CUR_SETALL;
    525        1.1        ad 		cu->enable = ((sc->sc_flags & ZX_CURSOR) != 0);
    526        1.1        ad 		cu->pos = sc->sc_curpos;
    527        1.1        ad 		cu->hot = sc->sc_curhot;
    528        1.1        ad 		cu->size = sc->sc_cursize;
    529        1.1        ad 
    530        1.1        ad 		if (cu->image != NULL) {
    531        1.1        ad 			count = sc->sc_cursize.y * 4;
    532       1.13       chs 			rv = copyout(sc->sc_curbits[1], cu->image, count);
    533        1.1        ad 			if (rv)
    534        1.1        ad 				return (rv);
    535       1.13       chs 			rv = copyout(sc->sc_curbits[0], cu->mask, count);
    536        1.1        ad 			if (rv)
    537        1.1        ad 				return (rv);
    538        1.1        ad 		}
    539        1.1        ad 		if (cu->cmap.red != NULL) {
    540  1.39.24.1     skrll 			uint8_t red[2], green[2], blue[2];
    541  1.39.24.1     skrll 			const uint8_t *ccm = sc->sc_curcmap;
    542  1.39.24.1     skrll 			cm = &cu->cmap;
    543  1.39.24.1     skrll 
    544  1.39.24.1     skrll 			if (cm->index > 2 || cm->count > 2 - cm->index)
    545  1.39.24.1     skrll 				return EINVAL;
    546  1.39.24.1     skrll 
    547  1.39.24.1     skrll 			for (i = 0; i < cm->count; i++) {
    548  1.39.24.1     skrll 				red[i] = ccm[i + cm->index + 0];
    549  1.39.24.1     skrll 				green[i] = ccm[i + cm->index + 2];
    550  1.39.24.1     skrll 				blue[i] = ccm[i + cm->index + 4];
    551        1.1        ad 			}
    552  1.39.24.1     skrll 
    553  1.39.24.1     skrll 			if ((error = copyout(red, cm->red, cm->count)) ||
    554  1.39.24.1     skrll 			    (error = copyout(green, cm->green, cm->count)) ||
    555  1.39.24.1     skrll 			    (error = copyout(blue, cm->blue, cm->count)))
    556  1.39.24.1     skrll 				return error;
    557        1.1        ad 		} else {
    558        1.1        ad 			cu->cmap.index = 0;
    559        1.1        ad 			cu->cmap.count = 2;
    560        1.1        ad 		}
    561        1.1        ad 		break;
    562        1.1        ad 
    563        1.1        ad 	default:
    564        1.1        ad #ifdef DEBUG
    565        1.1        ad 		log(LOG_NOTICE, "zxioctl(0x%lx) (%s[%d])\n", cmd,
    566       1.18       jdc 		    l->l_proc->p_comm, l->l_proc->p_pid);
    567        1.1        ad #endif
    568        1.1        ad 		return (ENOTTY);
    569        1.1        ad 	}
    570        1.1        ad 
    571        1.1        ad 	return (0);
    572        1.1        ad }
    573        1.1        ad 
    574       1.27  macallan static int
    575        1.1        ad zx_intr(void *cookie)
    576        1.1        ad {
    577        1.1        ad 
    578        1.1        ad 	return (1);
    579        1.1        ad }
    580        1.1        ad 
    581       1.27  macallan static void
    582        1.1        ad zx_reset(struct zx_softc *sc)
    583        1.1        ad {
    584        1.1        ad 	struct fbtype *fbt;
    585        1.1        ad 	u_int i;
    586        1.1        ad 
    587        1.1        ad 	fbt = &sc->sc_fb.fb_type;
    588        1.1        ad 
    589        1.1        ad 	zx_cross_loadwid(sc, ZX_WID_DBL_8, 0, 0x2c0);
    590        1.1        ad 	zx_cross_loadwid(sc, ZX_WID_DBL_8, 1, 0x30);
    591        1.1        ad 	zx_cross_loadwid(sc, ZX_WID_DBL_8, 2, 0x20);
    592        1.1        ad 	zx_cross_loadwid(sc, ZX_WID_DBL_24, 1, 0x30);
    593        1.1        ad 
    594       1.25   tsutsui 	i = bus_space_read_4(sc->sc_bt, sc->sc_bhzdss1, zd_misc);
    595        1.1        ad 	i |= ZX_SS1_MISC_ENABLE;
    596       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss1, zd_misc, i);
    597        1.1        ad 
    598       1.27  macallan 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_wid, 1);
    599       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_widclip, 0);
    600       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_wmask, 0xffff);
    601       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_vclipmin, 0);
    602       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_vclipmax,
    603        1.1        ad 	    (fbt->fb_width - 1) | ((fbt->fb_height - 1) << 16));
    604       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_fg, 0);
    605       1.27  macallan 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_planemask, 0xffffffff);
    606       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_rop, ZX_STD_ROP);
    607        1.1        ad 
    608       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzc, zc_extent,
    609        1.1        ad 	    (fbt->fb_width - 1) | ((fbt->fb_height - 1) << 11));
    610       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzc, zc_addrspace,
    611       1.25   tsutsui 	    ZX_ADDRSPC_FONT_OBGR);
    612       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzc, zc_fontt, 0);
    613        1.1        ad 
    614        1.1        ad 	for (i = 0; i < 256; i++) {
    615        1.1        ad 		sc->sc_cmap[i] = rasops_cmap[i * 3];
    616        1.1        ad 		sc->sc_cmap[i + 256] = rasops_cmap[i * 3 + 1];
    617        1.1        ad 		sc->sc_cmap[i + 512] = rasops_cmap[i * 3 + 2];
    618        1.1        ad 	}
    619        1.1        ad 
    620        1.1        ad 	zx_cmap_put(sc);
    621        1.1        ad }
    622        1.1        ad 
    623       1.27  macallan static int
    624        1.1        ad zx_cross_wait(struct zx_softc *sc)
    625        1.1        ad {
    626        1.1        ad 	int i;
    627        1.1        ad 
    628        1.1        ad 	for (i = 300000; i != 0; i--) {
    629       1.25   tsutsui 		if ((bus_space_read_4(sc->sc_bt, sc->sc_bhzx, zx_csr) &
    630       1.25   tsutsui 		    ZX_CROSS_CSR_PROGRESS) == 0)
    631        1.1        ad 			break;
    632        1.1        ad 		DELAY(1);
    633        1.1        ad 	}
    634        1.1        ad 
    635        1.1        ad 	if (i == 0)
    636        1.1        ad 		printf("zx_cross_wait: timed out\n");
    637        1.1        ad 
    638        1.1        ad 	return (i);
    639        1.1        ad }
    640        1.1        ad 
    641       1.27  macallan static int
    642        1.1        ad zx_cross_loadwid(struct zx_softc *sc, u_int type, u_int index, u_int value)
    643        1.1        ad {
    644       1.12       chs 	u_int tmp = 0;
    645        1.1        ad 
    646       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_type, ZX_CROSS_TYPE_WID);
    647        1.1        ad 
    648        1.1        ad 	if (zx_cross_wait(sc))
    649        1.1        ad 		return (1);
    650        1.1        ad 
    651        1.1        ad 	if (type == ZX_WID_DBL_8)
    652        1.1        ad 		tmp = (index & 0x0f) + 0x40;
    653        1.1        ad 	else if (type == ZX_WID_DBL_24)
    654        1.1        ad 		tmp = index & 0x3f;
    655        1.1        ad 
    656       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_type, 0x5800 + tmp);
    657       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_value, value);
    658       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_type, ZX_CROSS_TYPE_WID);
    659       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_csr,
    660       1.25   tsutsui 	    ZX_CROSS_CSR_UNK | ZX_CROSS_CSR_UNK2);
    661        1.1        ad 
    662        1.1        ad 	return (0);
    663        1.1        ad }
    664        1.1        ad 
    665       1.27  macallan static int
    666        1.1        ad zx_cmap_put(struct zx_softc *sc)
    667        1.1        ad {
    668        1.1        ad 	const u_char *b;
    669        1.1        ad 	u_int i, t;
    670        1.1        ad 
    671       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_type, ZX_CROSS_TYPE_CLUT0);
    672       1.27  macallan 
    673       1.27  macallan 	zx_cross_wait(sc);
    674        1.1        ad 
    675       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_type,
    676       1.25   tsutsui 	    ZX_CROSS_TYPE_CLUTDATA);
    677        1.1        ad 
    678        1.1        ad 	for (i = 0, b = sc->sc_cmap; i < 256; i++) {
    679        1.1        ad 		t = b[i];
    680        1.1        ad 		t |= b[i + 256] << 8;
    681        1.1        ad 		t |= b[i + 512] << 16;
    682       1.25   tsutsui 		bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_value, t);
    683        1.1        ad 	}
    684        1.1        ad 
    685       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_type, ZX_CROSS_TYPE_CLUT0);
    686       1.25   tsutsui 	i = bus_space_read_4(sc->sc_bt, sc->sc_bhzx, zx_csr);
    687        1.1        ad 	i = i | ZX_CROSS_CSR_UNK | ZX_CROSS_CSR_UNK2;
    688       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_csr, i);
    689        1.1        ad 	return (0);
    690        1.1        ad }
    691        1.1        ad 
    692       1.27  macallan static void
    693        1.1        ad zx_cursor_move(struct zx_softc *sc)
    694        1.1        ad {
    695        1.1        ad 	int sx, sy, x, y;
    696        1.1        ad 
    697        1.1        ad 	x = sc->sc_curpos.x - sc->sc_curhot.x;
    698        1.1        ad 	y = sc->sc_curpos.y - sc->sc_curhot.y;
    699        1.1        ad 
    700        1.1        ad 	if (x < 0) {
    701        1.1        ad 		sx = min(-x, 32);
    702        1.1        ad 		x = 0;
    703        1.1        ad 	} else
    704        1.1        ad 		sx = 0;
    705        1.1        ad 
    706        1.1        ad 	if (y < 0) {
    707        1.1        ad 		sy = min(-y, 32);
    708        1.1        ad 		y = 0;
    709        1.1        ad 	} else
    710        1.1        ad 		sy = 0;
    711        1.1        ad 
    712        1.1        ad 	if (sx != sc->sc_shiftx || sy != sc->sc_shifty) {
    713        1.1        ad 		sc->sc_shiftx = sx;
    714        1.1        ad 		sc->sc_shifty = sy;
    715        1.1        ad 		zx_cursor_set(sc);
    716        1.1        ad 	}
    717        1.1        ad 
    718       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_sxy,
    719       1.25   tsutsui 	    ((y & 0x7ff) << 11) | (x & 0x7ff));
    720       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc,
    721       1.25   tsutsui 	    bus_space_read_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc) | 0x30);
    722        1.1        ad 
    723        1.1        ad 	/* XXX Necessary? */
    724       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc,
    725       1.25   tsutsui 	    bus_space_read_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc) | 0x80);
    726        1.1        ad }
    727        1.1        ad 
    728       1.27  macallan static void
    729        1.1        ad zx_cursor_set(struct zx_softc *sc)
    730        1.1        ad {
    731        1.1        ad 	int i, j, data;
    732        1.1        ad 
    733        1.2        ad 	if ((sc->sc_flags & ZX_CURSOR) != 0)
    734       1.25   tsutsui 		bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc,
    735       1.25   tsutsui 		    bus_space_read_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc) &
    736       1.25   tsutsui 		    ~0x80);
    737        1.1        ad 
    738        1.1        ad 	for (j = 0; j < 2; j++) {
    739       1.25   tsutsui 		bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_type, 0x20 << j);
    740        1.2        ad 
    741        1.1        ad 		for (i = sc->sc_shifty; i < 32; i++) {
    742        1.1        ad 			data = sc->sc_curbits[j][i];
    743       1.25   tsutsui 			bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_data,
    744       1.25   tsutsui 			    data >> sc->sc_shiftx);
    745        1.1        ad 		}
    746        1.1        ad 		for (i = sc->sc_shifty; i != 0; i--)
    747       1.25   tsutsui 			bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_data, 0);
    748        1.1        ad 	}
    749        1.2        ad 
    750        1.2        ad 	if ((sc->sc_flags & ZX_CURSOR) != 0)
    751       1.25   tsutsui 		bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc,
    752       1.25   tsutsui 		    bus_space_read_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc) | 0x80);
    753        1.1        ad }
    754        1.1        ad 
    755       1.27  macallan static void
    756        1.1        ad zx_cursor_blank(struct zx_softc *sc)
    757        1.1        ad {
    758        1.1        ad 
    759        1.1        ad 	sc->sc_flags &= ~ZX_CURSOR;
    760       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc,
    761       1.25   tsutsui 	    bus_space_read_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc) & ~0x80);
    762        1.1        ad }
    763        1.1        ad 
    764       1.27  macallan static void
    765        1.1        ad zx_cursor_unblank(struct zx_softc *sc)
    766        1.1        ad {
    767        1.1        ad 
    768        1.1        ad 	sc->sc_flags |= ZX_CURSOR;
    769       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc,
    770       1.25   tsutsui 	    bus_space_read_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc) | 0x80);
    771        1.1        ad }
    772        1.1        ad 
    773       1.27  macallan static void
    774        1.1        ad zx_cursor_color(struct zx_softc *sc)
    775        1.1        ad {
    776       1.33   tsutsui 	uint8_t tmp;
    777        1.1        ad 
    778       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_type, 0x50);
    779        1.1        ad 
    780        1.1        ad 	tmp = sc->sc_curcmap[0] | (sc->sc_curcmap[2] << 8) |
    781        1.1        ad 	    (sc->sc_curcmap[4] << 16);
    782       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_data, tmp);
    783        1.1        ad 
    784        1.1        ad 	tmp = sc->sc_curcmap[1] | (sc->sc_curcmap[3] << 8) |
    785        1.1        ad 	    (sc->sc_curcmap[5] << 16);
    786       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_data, sc->sc_curcmap[1]);
    787        1.1        ad 
    788       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc,
    789       1.25   tsutsui 	    bus_space_read_4(sc->sc_bt, sc->sc_bhzcu, zcu_misc) | 0x03);
    790        1.1        ad }
    791        1.1        ad 
    792       1.27  macallan static void
    793       1.27  macallan zx_blank(device_t dv)
    794        1.1        ad {
    795        1.1        ad 	struct zx_softc *sc;
    796        1.1        ad 
    797       1.24  drochner 	sc = device_private(dv);
    798        1.1        ad 
    799        1.1        ad 	if ((sc->sc_flags & ZX_BLANKED) != 0)
    800        1.1        ad 		return;
    801        1.1        ad 	sc->sc_flags |= ZX_BLANKED;
    802        1.1        ad 
    803       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_type, ZX_CROSS_TYPE_VIDEO);
    804       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_csr,
    805       1.25   tsutsui 	    bus_space_read_4(sc->sc_bt, sc->sc_bhzx, zx_csr) &
    806       1.25   tsutsui 	    ~ZX_CROSS_CSR_ENABLE);
    807        1.1        ad }
    808        1.1        ad 
    809       1.27  macallan static void
    810       1.27  macallan zx_unblank(device_t dv)
    811        1.1        ad {
    812        1.1        ad 	struct zx_softc *sc;
    813        1.1        ad 
    814       1.24  drochner 	sc = device_private(dv);
    815        1.1        ad 
    816        1.1        ad 	if ((sc->sc_flags & ZX_BLANKED) == 0)
    817        1.1        ad 		return;
    818        1.1        ad 	sc->sc_flags &= ~ZX_BLANKED;
    819        1.1        ad 
    820       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_type, ZX_CROSS_TYPE_VIDEO);
    821       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzx, zx_csr,
    822       1.25   tsutsui 	    bus_space_read_4(sc->sc_bt, sc->sc_bhzx, zx_csr) |
    823       1.25   tsutsui 	    ZX_CROSS_CSR_ENABLE);
    824        1.1        ad }
    825        1.1        ad 
    826       1.27  macallan static paddr_t
    827        1.1        ad zxmmap(dev_t dev, off_t off, int prot)
    828        1.1        ad {
    829        1.1        ad 	struct zx_softc *sc;
    830       1.15   tsutsui 	const struct zx_mmo *mm, *mmmax;
    831        1.2        ad 
    832       1.23    cegger 	sc = device_lookup_private(&zx_cd, minor(dev));
    833        1.2        ad 	off = trunc_page(off);
    834        1.1        ad 	mm = zx_mmo;
    835       1.15   tsutsui 	mmmax = mm + sizeof(zx_mmo) / sizeof(zx_mmo[0]);
    836        1.1        ad 
    837       1.15   tsutsui 	for (; mm < mmmax; mm++)
    838        1.1        ad 		if (off >= mm->mo_va && off < mm->mo_va + mm->mo_size) {
    839        1.1        ad 			off = off - mm->mo_va + mm->mo_pa;
    840        1.1        ad 			return (bus_space_mmap(sc->sc_bt, sc->sc_paddr,
    841        1.1        ad 			    off, prot, BUS_SPACE_MAP_LINEAR));
    842        1.1        ad 		}
    843        1.1        ad 
    844        1.1        ad 	return (-1);
    845        1.1        ad }
    846        1.1        ad 
    847       1.27  macallan static void
    848       1.27  macallan zx_fillrect(struct zx_softc *sc, int x, int y, int w, int h, uint32_t bg,
    849        1.1        ad 	    int rop)
    850        1.1        ad {
    851        1.1        ad 
    852        1.1        ad 
    853       1.25   tsutsui 	while ((bus_space_read_4(sc->sc_bt, sc->sc_bhzc, zc_csr) &
    854       1.25   tsutsui 	    ZX_CSR_BLT_BUSY) != 0)
    855        1.1        ad 		;
    856        1.1        ad 
    857       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_rop, rop);
    858       1.27  macallan 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_fg, bg);
    859       1.34  macallan 	bus_space_write_4(sc->sc_bt, sc->sc_bhzc, zc_extent,
    860       1.34  macallan 	    (w - 1) | ((h - 1) << 11));
    861       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzc, zc_fill,
    862       1.25   tsutsui 	    x | (y << 11) | 0x80000000);
    863        1.1        ad }
    864        1.1        ad 
    865       1.27  macallan static void
    866       1.27  macallan zx_copyrect(struct zx_softc *sc, int sx, int sy, int dx, int dy, int w,
    867        1.1        ad 	    int h)
    868        1.1        ad {
    869       1.27  macallan 	uint32_t dir;
    870        1.1        ad 
    871       1.35  macallan 	w -= 1;
    872       1.35  macallan 	h -= 1;
    873       1.35  macallan 
    874        1.1        ad 	if (sy < dy || sx < dx) {
    875        1.1        ad 		dir = 0x80000000;
    876        1.1        ad 		sx += w;
    877        1.1        ad 		sy += h;
    878        1.1        ad 		dx += w;
    879        1.1        ad 		dy += h;
    880        1.1        ad 	} else
    881        1.1        ad 		dir = 0;
    882        1.1        ad 
    883       1.25   tsutsui 	while ((bus_space_read_4(sc->sc_bt, sc->sc_bhzc, zc_csr) &
    884       1.25   tsutsui 	    ZX_CSR_BLT_BUSY) != 0)
    885        1.1        ad 		;
    886        1.1        ad 
    887       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_rop, ZX_STD_ROP);
    888       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzc, zc_extent,
    889       1.25   tsutsui 	    w | (h << 11) | dir);
    890       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzc, zc_src, sx | (sy << 11));
    891       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzc, zc_copy, dx | (dy << 11));
    892        1.1        ad }
    893        1.1        ad 
    894       1.27  macallan static void
    895       1.27  macallan zx_do_cursor(void *cookie, int on, int row, int col)
    896        1.1        ad {
    897       1.27  macallan 	struct rasops_info *ri = cookie;
    898       1.27  macallan 	struct vcons_screen *scr = ri->ri_hw;
    899       1.27  macallan 	struct zx_softc *sc = scr->scr_cookie;
    900       1.27  macallan 	int x, y, wi, he;
    901       1.27  macallan 
    902       1.27  macallan 	wi = ri->ri_font->fontwidth;
    903       1.27  macallan 	he = ri->ri_font->fontheight;
    904       1.27  macallan 
    905       1.27  macallan 	if (ri->ri_flg & RI_CURSOR) {
    906       1.27  macallan 		x = ri->ri_ccol * wi + ri->ri_xorigin;
    907       1.27  macallan 		y = ri->ri_crow * he + ri->ri_yorigin;
    908       1.27  macallan 		zx_fillrect(sc, x, y, wi, he, 0xff000000,
    909       1.27  macallan 		  ZX_ROP_NEW_XOR_OLD | ZX_ATTR_WE_ENABLE | ZX_ATTR_OE_ENABLE |
    910       1.27  macallan 		  ZX_ATTR_FORCE_WID);
    911       1.27  macallan 		ri->ri_flg &= ~RI_CURSOR;
    912       1.27  macallan 	}
    913        1.1        ad 
    914       1.27  macallan 	ri->ri_crow = row;
    915       1.27  macallan 	ri->ri_ccol = col;
    916        1.1        ad 
    917       1.27  macallan 	if (on)
    918       1.27  macallan 	{
    919       1.27  macallan 		x = ri->ri_ccol * wi + ri->ri_xorigin;
    920       1.27  macallan 		y = ri->ri_crow * he + ri->ri_yorigin;
    921       1.27  macallan 		zx_fillrect(sc, x, y, wi, he, 0xff000000,
    922       1.27  macallan 		  ZX_ROP_NEW_XOR_OLD | ZX_ATTR_WE_ENABLE | ZX_ATTR_OE_ENABLE |
    923       1.27  macallan 		  ZX_ATTR_FORCE_WID);
    924       1.27  macallan 		ri->ri_flg |= RI_CURSOR;
    925       1.27  macallan 	}
    926        1.1        ad }
    927        1.1        ad 
    928       1.27  macallan static void
    929       1.27  macallan zx_erasecols(void *cookie, int row, int startcol, int ncols, long attr)
    930        1.1        ad {
    931       1.27  macallan 	struct rasops_info *ri = cookie;
    932       1.27  macallan 	struct vcons_screen *scr = ri->ri_hw;
    933       1.27  macallan 	struct zx_softc *sc = scr->scr_cookie;
    934       1.27  macallan 	int32_t x, y, width, height, bg;
    935       1.27  macallan 
    936       1.27  macallan 	x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
    937       1.27  macallan 	y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    938       1.27  macallan 	width = ri->ri_font->fontwidth * ncols;
    939       1.27  macallan 	height = ri->ri_font->fontheight;
    940       1.27  macallan 	bg = ((uint32_t)ri->ri_devcmap[(attr >> 16) & 0xff]) << 24;
    941       1.27  macallan 	zx_fillrect(sc, x, y, width, height, bg, ZX_STD_ROP);
    942       1.27  macallan }
    943       1.27  macallan 
    944       1.27  macallan static void
    945       1.27  macallan zx_eraserows(void *cookie, int row, int nrows, long attr)
    946       1.27  macallan {
    947       1.27  macallan 	struct rasops_info *ri = cookie;
    948       1.27  macallan 	struct vcons_screen *scr = ri->ri_hw;
    949       1.27  macallan 	struct zx_softc *sc = scr->scr_cookie;
    950       1.27  macallan 	int32_t x, y, width, height, bg;
    951       1.27  macallan 
    952       1.27  macallan 	if ((row == 0) && (nrows == ri->ri_rows)) {
    953       1.27  macallan 		x = y = 0;
    954       1.27  macallan 		width = ri->ri_width;
    955       1.27  macallan 		height = ri->ri_height;
    956       1.27  macallan 	} else {
    957       1.27  macallan 		x = ri->ri_xorigin;
    958       1.27  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    959       1.27  macallan 		width = ri->ri_emuwidth;
    960       1.27  macallan 		height = ri->ri_font->fontheight * nrows;
    961       1.27  macallan 	}
    962       1.27  macallan 	bg = ((uint32_t)ri->ri_devcmap[(attr >> 16) & 0xff]) << 24;
    963       1.27  macallan 	zx_fillrect(sc, x, y, width, height, bg, ZX_STD_ROP);
    964        1.1        ad }
    965        1.1        ad 
    966       1.27  macallan static void
    967       1.27  macallan zx_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
    968        1.1        ad {
    969       1.27  macallan 	struct rasops_info *ri = cookie;
    970       1.27  macallan 	struct vcons_screen *scr = ri->ri_hw;
    971       1.27  macallan 	struct zx_softc *sc = scr->scr_cookie;
    972       1.27  macallan 	int32_t x, ys, yd, width, height;
    973        1.1        ad 
    974       1.27  macallan 	x = ri->ri_xorigin;
    975       1.27  macallan 	ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
    976       1.27  macallan 	yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
    977       1.27  macallan 	width = ri->ri_emuwidth;
    978       1.27  macallan 	height = ri->ri_font->fontheight * nrows;
    979       1.27  macallan 	zx_copyrect(sc, x, ys, x, yd, width, height);
    980        1.1        ad }
    981        1.1        ad 
    982       1.27  macallan static void
    983       1.27  macallan zx_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
    984        1.1        ad {
    985       1.27  macallan 	struct rasops_info *ri = cookie;
    986       1.27  macallan 	struct vcons_screen *scr = ri->ri_hw;
    987       1.27  macallan 	struct zx_softc *sc = scr->scr_cookie;
    988       1.27  macallan 	int32_t xs, xd, y, width, height;
    989        1.1        ad 
    990       1.27  macallan 	xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
    991       1.27  macallan 	xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
    992       1.27  macallan 	y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    993       1.27  macallan 	width = ri->ri_font->fontwidth * ncols;
    994       1.27  macallan 	height = ri->ri_font->fontheight;
    995       1.27  macallan 	zx_copyrect(sc, xs, y, xd, y, width, height);
    996        1.1        ad }
    997        1.1        ad 
    998       1.27  macallan static void
    999        1.1        ad zx_putchar(void *cookie, int row, int col, u_int uc, long attr)
   1000        1.1        ad {
   1001       1.27  macallan 	struct rasops_info *ri = cookie;
   1002       1.36  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
   1003       1.27  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1004       1.27  macallan 	struct zx_softc *sc = scr->scr_cookie;
   1005       1.33   tsutsui 	volatile uint32_t *dp;
   1006       1.33   tsutsui 	uint8_t *fb;
   1007       1.27  macallan 	int fs, i, ul;
   1008       1.27  macallan 	uint32_t fg, bg;
   1009       1.27  macallan 
   1010       1.27  macallan 	rasops_unpack_attr(attr, &fg, &bg, &ul);
   1011       1.27  macallan 	bg = ((uint32_t)ri->ri_devcmap[bg]) << 24;
   1012       1.27  macallan 	fg = ((uint32_t)ri->ri_devcmap[fg]) << 24;
   1013       1.27  macallan 	if (uc == ' ') {
   1014       1.27  macallan 		int x, y;
   1015        1.1        ad 
   1016       1.36  macallan 		x = ri->ri_xorigin + font->fontwidth * col;
   1017       1.36  macallan 		y = ri->ri_yorigin + font->fontheight * row;
   1018       1.36  macallan 		zx_fillrect(sc, x, y, font->fontwidth,
   1019       1.36  macallan 			    font->fontheight, bg, ZX_STD_ROP);
   1020        1.1        ad 		return;
   1021        1.1        ad 	}
   1022        1.1        ad 
   1023       1.33   tsutsui 	dp = (volatile uint32_t *)sc->sc_pixels +
   1024       1.27  macallan 	    ((row * font->fontheight + ri->ri_yorigin) << 11) +
   1025       1.27  macallan 	    (col * font->fontwidth + ri->ri_xorigin);
   1026       1.33   tsutsui 	fb = (uint8_t *)font->data + (uc - font->firstchar) *
   1027        1.1        ad 	    ri->ri_fontscale;
   1028        1.1        ad 	fs = font->stride;
   1029        1.1        ad 
   1030       1.25   tsutsui 	while ((bus_space_read_4(sc->sc_bt, sc->sc_bhzc, zc_csr) &
   1031       1.25   tsutsui 	    ZX_CSR_BLT_BUSY) != 0)
   1032        1.1        ad 		;
   1033        1.1        ad 
   1034       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_rop, ZX_STD_ROP);
   1035       1.27  macallan 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_fg, fg);
   1036       1.27  macallan 	bus_space_write_4(sc->sc_bt, sc->sc_bhzdss0, zd_bg, bg);
   1037       1.25   tsutsui 	bus_space_write_4(sc->sc_bt, sc->sc_bhzc, zc_fontmsk,
   1038       1.27  macallan 	    0xffffffff << (32 - font->fontwidth));
   1039        1.1        ad 
   1040       1.27  macallan 	if (font->fontwidth <= 8) {
   1041       1.27  macallan 		for (i = font->fontheight; i != 0; i--, dp += 2048) {
   1042        1.1        ad 			*dp = *fb << 24;
   1043        1.1        ad 			fb += fs;
   1044        1.1        ad 		}
   1045        1.1        ad 	} else {
   1046       1.27  macallan 		for (i = font->fontheight; i != 0; i--, dp += 2048) {
   1047       1.33   tsutsui 			*dp = *((uint16_t *)fb) << 16;
   1048        1.1        ad 			fb += fs;
   1049        1.1        ad 		}
   1050        1.1        ad 	}
   1051        1.1        ad 
   1052        1.1        ad 	if (ul) {
   1053        1.1        ad 		dp -= 4096;
   1054        1.1        ad 		*dp = 0xffffffff;
   1055        1.1        ad 	}
   1056        1.1        ad }
   1057       1.27  macallan 
   1058       1.27  macallan #if NWSDISPLAY > 0
   1059       1.27  macallan static int
   1060       1.27  macallan zx_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
   1061       1.27  macallan 	struct lwp *l)
   1062       1.27  macallan {
   1063       1.27  macallan 	/* we'll probably need to add more stuff here */
   1064       1.27  macallan 	struct vcons_data *vd = v;
   1065       1.27  macallan 	struct zx_softc *sc = vd->cookie;
   1066       1.27  macallan 	struct wsdisplay_fbinfo *wdf;
   1067       1.27  macallan 	struct rasops_info *ri = &sc->sc_fb.fb_rinfo;
   1068       1.27  macallan 	struct vcons_screen *ms = sc->vd.active;
   1069       1.27  macallan 	switch (cmd) {
   1070       1.27  macallan 		case WSDISPLAYIO_GTYPE:
   1071       1.27  macallan 			*(u_int *)data = WSDISPLAY_TYPE_SUNTCX;
   1072       1.27  macallan 			return 0;
   1073       1.27  macallan 		case WSDISPLAYIO_GINFO:
   1074       1.27  macallan 			wdf = (void *)data;
   1075       1.27  macallan 			wdf->height = ri->ri_height;
   1076       1.27  macallan 			wdf->width = ri->ri_width;
   1077       1.27  macallan 			wdf->depth = ri->ri_depth;
   1078       1.27  macallan 			wdf->cmsize = 256;
   1079       1.27  macallan 			return 0;
   1080       1.27  macallan 
   1081       1.27  macallan 		case WSDISPLAYIO_GETCMAP:
   1082       1.27  macallan 			return zx_getcmap(sc,
   1083       1.27  macallan 			    (struct wsdisplay_cmap *)data);
   1084       1.27  macallan 		case WSDISPLAYIO_PUTCMAP:
   1085       1.27  macallan 			return zx_putcmap(sc,
   1086       1.27  macallan 			    (struct wsdisplay_cmap *)data);
   1087       1.27  macallan 
   1088       1.27  macallan 		case WSDISPLAYIO_SMODE:
   1089       1.27  macallan 			{
   1090       1.27  macallan 				int new_mode = *(int*)data;
   1091       1.27  macallan 				if (new_mode != sc->sc_mode)
   1092       1.27  macallan 				{
   1093       1.27  macallan 					sc->sc_mode = new_mode;
   1094       1.27  macallan 					if(new_mode == WSDISPLAYIO_MODE_EMUL)
   1095       1.27  macallan 					{
   1096       1.34  macallan 						zx_reset(sc);
   1097       1.27  macallan 						vcons_redraw_screen(ms);
   1098       1.27  macallan 					}
   1099       1.27  macallan 				}
   1100       1.27  macallan 			}
   1101       1.27  macallan 	}
   1102       1.27  macallan 	return EPASSTHROUGH;
   1103       1.27  macallan }
   1104       1.27  macallan 
   1105       1.27  macallan static paddr_t
   1106       1.27  macallan zx_mmap(void *v, void *vs, off_t offset, int prot)
   1107       1.27  macallan {
   1108       1.27  macallan 	/* I'm not at all sure this is the right thing to do */
   1109       1.27  macallan 	return zxmmap(0, offset, prot); /* assume minor dev 0 for now */
   1110       1.27  macallan }
   1111       1.27  macallan 
   1112       1.27  macallan static int
   1113       1.27  macallan zx_putcmap(struct zx_softc *sc, struct wsdisplay_cmap *cm)
   1114       1.27  macallan {
   1115       1.27  macallan 	u_int index = cm->index;
   1116       1.27  macallan 	u_int count = cm->count;
   1117       1.27  macallan 	int error,i;
   1118       1.27  macallan 	if (index >= 256 || count > 256 || index + count > 256)
   1119       1.27  macallan 		return EINVAL;
   1120       1.27  macallan 
   1121       1.27  macallan 	for (i = 0; i < count; i++)
   1122       1.27  macallan 	{
   1123       1.27  macallan 		error = copyin(&cm->red[i],
   1124       1.27  macallan 		    &sc->sc_cmap[index + i], 1);
   1125       1.27  macallan 		if (error)
   1126       1.27  macallan 			return error;
   1127       1.27  macallan 		error = copyin(&cm->green[i],
   1128       1.27  macallan 		    &sc->sc_cmap[index + i + 256], 1);
   1129       1.27  macallan 		if (error)
   1130       1.27  macallan 			return error;
   1131       1.27  macallan 		error = copyin(&cm->blue[i],
   1132       1.27  macallan 		    &sc->sc_cmap[index + i + 512], 1);
   1133       1.27  macallan 		if (error)
   1134       1.27  macallan 			return error;
   1135       1.27  macallan 	}
   1136       1.27  macallan 	zx_cmap_put(sc);
   1137       1.27  macallan 
   1138       1.27  macallan 	return 0;
   1139       1.27  macallan }
   1140       1.27  macallan 
   1141       1.27  macallan static int
   1142       1.27  macallan zx_getcmap(struct zx_softc *sc, struct wsdisplay_cmap *cm)
   1143       1.27  macallan {
   1144       1.27  macallan 	u_int index = cm->index;
   1145       1.27  macallan 	u_int count = cm->count;
   1146       1.27  macallan 	int error,i;
   1147       1.27  macallan 
   1148       1.27  macallan 	if (index >= 256 || count > 256 || index + count > 256)
   1149       1.27  macallan 		return EINVAL;
   1150       1.27  macallan 
   1151       1.27  macallan 	for (i = 0; i < count; i++)
   1152       1.27  macallan 	{
   1153       1.27  macallan 		error = copyout(&sc->sc_cmap[index + i],
   1154       1.27  macallan 		    &cm->red[i], 1);
   1155       1.27  macallan 		if (error)
   1156       1.27  macallan 			return error;
   1157       1.27  macallan 		error = copyout(&sc->sc_cmap[index + i + 256],
   1158       1.27  macallan 		    &cm->green[i], 1);
   1159       1.27  macallan 		if (error)
   1160       1.27  macallan 			return error;
   1161       1.27  macallan 		error = copyout(&sc->sc_cmap[index + i + 256],
   1162       1.27  macallan 		    &cm->blue[i], 1);
   1163       1.27  macallan 		if (error)
   1164       1.27  macallan 			return error;
   1165       1.27  macallan 	}
   1166       1.27  macallan 
   1167       1.27  macallan 	return 0;
   1168       1.27  macallan }
   1169       1.27  macallan 
   1170       1.27  macallan static void
   1171       1.27  macallan zx_init_screen(void *cookie, struct vcons_screen *scr,
   1172       1.27  macallan     int existing, long *defattr)
   1173       1.27  macallan {
   1174       1.27  macallan 	struct zx_softc *sc = cookie;
   1175       1.27  macallan 	struct rasops_info *ri = &scr->scr_ri;
   1176       1.27  macallan 
   1177       1.27  macallan 	ri->ri_depth = 8; /*sc->sc_fb.fb_type.fb_depth = 32;*/
   1178       1.27  macallan 	ri->ri_width = sc->sc_width;
   1179       1.27  macallan 	ri->ri_height = sc->sc_height;
   1180       1.27  macallan 	ri->ri_stride = sc->sc_stride;
   1181       1.27  macallan 	ri->ri_flg = RI_CENTER;
   1182       1.27  macallan 
   1183       1.27  macallan 	ri->ri_bits = (void *)sc->sc_pixels;
   1184       1.27  macallan 
   1185       1.39  macallan 	rasops_init(ri, 0, 0);
   1186       1.27  macallan 	ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
   1187       1.27  macallan 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
   1188       1.27  macallan 		    sc->sc_width / ri->ri_font->fontwidth);
   1189       1.27  macallan 
   1190       1.27  macallan 	ri->ri_hw = scr;
   1191       1.27  macallan 
   1192       1.27  macallan 	ri->ri_ops.cursor = zx_do_cursor;
   1193       1.27  macallan 	ri->ri_ops.copycols = zx_copycols;
   1194       1.27  macallan 	ri->ri_ops.copyrows = zx_copyrows;
   1195       1.27  macallan 	ri->ri_ops.erasecols = zx_erasecols;
   1196       1.27  macallan 	ri->ri_ops.eraserows = zx_eraserows;
   1197       1.27  macallan 	ri->ri_ops.putchar = zx_putchar;
   1198       1.27  macallan }
   1199       1.27  macallan 
   1200       1.27  macallan #endif /* NWSDISPLAY > 0 */
   1201