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