Home | History | Annotate | Line # | Download | only in sbus
p9100.c revision 1.26.8.2
      1  1.26.8.2      yamt /*	$NetBSD: p9100.c,v 1.26.8.2 2006/04/01 12:07:27 yamt Exp $ */
      2       1.1        pk 
      3       1.1        pk /*-
      4  1.26.8.1      yamt  * Copyright (c) 1998, 2005, 2006 The NetBSD Foundation, Inc.
      5       1.1        pk  * All rights reserved.
      6       1.1        pk  *
      7       1.1        pk  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1        pk  * by Matt Thomas.
      9       1.1        pk  *
     10       1.1        pk  * Redistribution and use in source and binary forms, with or without
     11       1.1        pk  * modification, are permitted provided that the following conditions
     12       1.1        pk  * are met:
     13       1.1        pk  * 1. Redistributions of source code must retain the above copyright
     14       1.1        pk  *    notice, this list of conditions and the following disclaimer.
     15       1.1        pk  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1        pk  *    notice, this list of conditions and the following disclaimer in the
     17       1.1        pk  *    documentation and/or other materials provided with the distribution.
     18       1.1        pk  * 3. All advertising materials mentioning features or use of this software
     19       1.1        pk  *    must display the following acknowledgement:
     20       1.1        pk  *        This product includes software developed by the NetBSD
     21       1.1        pk  *        Foundation, Inc. and its contributors.
     22       1.1        pk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1        pk  *    contributors may be used to endorse or promote products derived
     24       1.1        pk  *    from this software without specific prior written permission.
     25       1.1        pk  *
     26       1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1        pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1        pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1        pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1        pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1        pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1        pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1        pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1        pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1        pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1        pk  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1        pk  */
     38       1.1        pk 
     39       1.1        pk /*
     40       1.1        pk  * color display (p9100) driver.
     41       1.1        pk  *
     42       1.1        pk  * Does not handle interrupts, even though they can occur.
     43       1.1        pk  *
     44       1.1        pk  * XXX should defer colormap updates to vertical retrace interrupts
     45       1.1        pk  */
     46       1.5     lukem 
     47       1.5     lukem #include <sys/cdefs.h>
     48  1.26.8.2      yamt __KERNEL_RCSID(0, "$NetBSD: p9100.c,v 1.26.8.2 2006/04/01 12:07:27 yamt Exp $");
     49       1.1        pk 
     50       1.1        pk #include <sys/param.h>
     51       1.1        pk #include <sys/systm.h>
     52       1.1        pk #include <sys/buf.h>
     53       1.1        pk #include <sys/device.h>
     54       1.1        pk #include <sys/ioctl.h>
     55       1.1        pk #include <sys/malloc.h>
     56       1.1        pk #include <sys/mman.h>
     57       1.1        pk #include <sys/tty.h>
     58       1.1        pk #include <sys/conf.h>
     59       1.1        pk 
     60       1.1        pk #include <machine/bus.h>
     61       1.1        pk #include <machine/autoconf.h>
     62       1.1        pk 
     63       1.1        pk #include <dev/sun/fbio.h>
     64       1.1        pk #include <dev/sun/fbvar.h>
     65       1.1        pk #include <dev/sun/btreg.h>
     66       1.1        pk #include <dev/sun/btvar.h>
     67      1.21  macallan 
     68       1.1        pk #include <dev/sbus/p9100reg.h>
     69       1.1        pk 
     70       1.1        pk #include <dev/sbus/sbusvar.h>
     71       1.1        pk 
     72      1.21  macallan /*#include <dev/wscons/wsdisplayvar.h>*/
     73      1.21  macallan #include <dev/wscons/wsconsio.h>
     74      1.21  macallan #include <dev/wsfont/wsfont.h>
     75      1.21  macallan #include <dev/rasops/rasops.h>
     76      1.21  macallan 
     77  1.26.8.1      yamt #include <dev/wscons/wsdisplay_vconsvar.h>
     78  1.26.8.1      yamt 
     79      1.21  macallan #include "opt_wsemul.h"
     80      1.22  macallan #include "rasops_glue.h"
     81      1.21  macallan 
     82       1.1        pk #include "tctrl.h"
     83       1.1        pk #if NTCTRL > 0
     84       1.1        pk #include <machine/tctrl.h>
     85       1.1        pk #include <sparc/dev/tctrlvar.h>/*XXX*/
     86       1.1        pk #endif
     87       1.1        pk 
     88      1.24  macallan struct pnozz_cursor {
     89      1.24  macallan 	short	pc_enable;		/* cursor is enabled */
     90      1.24  macallan 	struct	fbcurpos pc_pos;	/* position */
     91      1.24  macallan 	struct	fbcurpos pc_hot;	/* hot-spot */
     92      1.24  macallan 	struct	fbcurpos pc_size;	/* size of mask & image fields */
     93      1.24  macallan 	uint32_t pc_bits[0x100];	/* space for mask & image bits */
     94      1.24  macallan 	unsigned char red[3], green[3];
     95      1.24  macallan 	unsigned char blue[3];		/* cursor palette */
     96      1.24  macallan };
     97      1.24  macallan 
     98       1.1        pk /* per-display variables */
     99       1.1        pk struct p9100_softc {
    100       1.1        pk 	struct device	sc_dev;		/* base device */
    101       1.1        pk 	struct sbusdev	sc_sd;		/* sbus device */
    102       1.1        pk 	struct fbdevice	sc_fb;		/* frame buffer device */
    103      1.24  macallan 
    104       1.1        pk 	bus_space_tag_t	sc_bustag;
    105       1.8        pk 
    106       1.8        pk 	bus_addr_t	sc_ctl_paddr;	/* phys address description */
    107       1.1        pk 	bus_size_t	sc_ctl_psize;	/*   for device mmap() */
    108       1.1        pk 	bus_space_handle_t sc_ctl_memh;	/*   bus space handle */
    109       1.8        pk 
    110       1.8        pk 	bus_addr_t	sc_cmd_paddr;	/* phys address description */
    111       1.1        pk 	bus_size_t	sc_cmd_psize;	/*   for device mmap() */
    112       1.1        pk 	bus_space_handle_t sc_cmd_memh;	/*   bus space handle */
    113       1.8        pk 
    114       1.8        pk 	bus_addr_t	sc_fb_paddr;	/* phys address description */
    115       1.1        pk 	bus_size_t	sc_fb_psize;	/*   for device mmap() */
    116       1.1        pk 	bus_space_handle_t sc_fb_memh;	/*   bus space handle */
    117       1.8        pk 
    118  1.26.8.1      yamt 	volatile uint32_t sc_junk;
    119      1.21  macallan 	uint32_t sc_mono_width;	/* for setup_mono */
    120      1.21  macallan 
    121      1.21  macallan 	uint32_t sc_width;
    122      1.21  macallan 	uint32_t sc_height;	/* panel width / height */
    123      1.21  macallan 	uint32_t sc_stride;
    124      1.21  macallan 	uint32_t sc_depth;
    125      1.21  macallan 	union	bt_cmap sc_cmap;	/* Brooktree color map */
    126      1.21  macallan 
    127      1.24  macallan 	struct pnozz_cursor sc_cursor;
    128      1.24  macallan 
    129      1.21  macallan 	int sc_mode;
    130  1.26.8.1      yamt 	int sc_video, sc_powerstate;
    131      1.21  macallan 	uint32_t sc_bg;
    132  1.26.8.1      yamt 	volatile uint32_t sc_last_offset;
    133  1.26.8.1      yamt 	struct vcons_data vd;
    134      1.21  macallan };
    135      1.21  macallan 
    136      1.21  macallan 
    137  1.26.8.1      yamt static struct vcons_screen p9100_console_screen;
    138      1.21  macallan 
    139      1.21  macallan extern const u_char rasops_cmap[768];
    140      1.21  macallan 
    141      1.21  macallan struct wsscreen_descr p9100_defscreendesc = {
    142      1.21  macallan 	"default",
    143      1.21  macallan 	0, 0,
    144      1.21  macallan 	NULL,
    145      1.21  macallan 	8, 16,
    146      1.21  macallan 	WSSCREEN_WSCOLORS,
    147      1.21  macallan };
    148       1.1        pk 
    149      1.21  macallan const struct wsscreen_descr *_p9100_scrlist[] = {
    150      1.21  macallan 	&p9100_defscreendesc,
    151      1.21  macallan 	/* XXX other formats, graphics screen? */
    152       1.1        pk };
    153       1.1        pk 
    154      1.21  macallan struct wsscreen_list p9100_screenlist = {
    155      1.21  macallan 	sizeof(_p9100_scrlist) / sizeof(struct wsscreen_descr *), _p9100_scrlist
    156      1.21  macallan };
    157       1.1        pk 
    158       1.1        pk /* autoconfiguration driver */
    159       1.1        pk static int	p9100_sbus_match(struct device *, struct cfdata *, void *);
    160       1.1        pk static void	p9100_sbus_attach(struct device *, struct device *, void *);
    161       1.1        pk 
    162       1.1        pk static void	p9100unblank(struct device *);
    163       1.1        pk static void	p9100_shutdown(void *);
    164       1.1        pk 
    165      1.12   thorpej CFATTACH_DECL(pnozz, sizeof(struct p9100_softc),
    166      1.13   thorpej     p9100_sbus_match, p9100_sbus_attach, NULL, NULL);
    167       1.1        pk 
    168       1.1        pk extern struct cfdriver pnozz_cd;
    169       1.1        pk 
    170  1.26.8.1      yamt static dev_type_open(p9100open);
    171  1.26.8.1      yamt static dev_type_ioctl(p9100ioctl);
    172  1.26.8.1      yamt static dev_type_mmap(p9100mmap);
    173      1.10   gehenna 
    174      1.10   gehenna const struct cdevsw pnozz_cdevsw = {
    175      1.10   gehenna 	p9100open, nullclose, noread, nowrite, p9100ioctl,
    176      1.14  jdolecek 	nostop, notty, nopoll, p9100mmap, nokqfilter,
    177      1.10   gehenna };
    178      1.10   gehenna 
    179       1.1        pk /* frame buffer generic driver */
    180       1.1        pk static struct fbdriver p9100fbdriver = {
    181      1.10   gehenna 	p9100unblank, p9100open, nullclose, p9100ioctl, nopoll,
    182      1.14  jdolecek 	p9100mmap, nokqfilter
    183       1.1        pk };
    184       1.1        pk 
    185      1.21  macallan static void	p9100loadcmap(struct p9100_softc *, int, int);
    186      1.21  macallan static void	p9100_set_video(struct p9100_softc *, int);
    187      1.21  macallan static int	p9100_get_video(struct p9100_softc *);
    188       1.1        pk static uint32_t p9100_ctl_read_4(struct p9100_softc *, bus_size_t);
    189      1.21  macallan static void	p9100_ctl_write_4(struct p9100_softc *, bus_size_t, uint32_t);
    190  1.26.8.1      yamt static uint8_t	p9100_ramdac_read(struct p9100_softc *, bus_size_t);
    191  1.26.8.1      yamt static void	p9100_ramdac_write(struct p9100_softc *, bus_size_t, uint8_t);
    192  1.26.8.1      yamt 
    193  1.26.8.1      yamt static uint8_t	p9100_ramdac_read_ctl(struct p9100_softc *, int);
    194  1.26.8.1      yamt static void	p9100_ramdac_write_ctl(struct p9100_softc *, int, uint8_t);
    195      1.21  macallan 
    196      1.21  macallan static void 	p9100_init_engine(struct p9100_softc *);
    197  1.26.8.1      yamt 
    198  1.26.8.1      yamt #if NWSDISPLAY > 0
    199  1.26.8.1      yamt static void	p9100_sync(struct p9100_softc *);
    200  1.26.8.1      yamt static void	p9100_bitblt(void *, int, int, int, int, int, int, uint32_t);
    201  1.26.8.1      yamt static void 	p9100_rectfill(void *, int, int, int, int, uint32_t);
    202  1.26.8.1      yamt static void	p9100_clearscreen(struct p9100_softc *);
    203  1.26.8.1      yamt 
    204  1.26.8.1      yamt static void	p9100_setup_mono(struct p9100_softc *, int, int, int, int,
    205      1.21  macallan 		    uint32_t, uint32_t);
    206  1.26.8.1      yamt static void	p9100_feed_line(struct p9100_softc *, int, uint8_t *);
    207      1.21  macallan static void	p9100_set_color_reg(struct p9100_softc *, int, int32_t);
    208      1.21  macallan 
    209  1.26.8.1      yamt static void	p9100_copycols(void *, int, int, int, int);
    210  1.26.8.1      yamt static void	p9100_erasecols(void *, int, int, int, long);
    211  1.26.8.1      yamt static void	p9100_copyrows(void *, int, int, int);
    212  1.26.8.1      yamt static void	p9100_eraserows(void *, int, int, long);
    213  1.26.8.1      yamt /*static int	p9100_mapchar(void *, int, u_int *);*/
    214  1.26.8.1      yamt static void	p9100_putchar(void *, int, int, u_int, long);
    215  1.26.8.1      yamt static void	p9100_cursor(void *, int, int, int);
    216  1.26.8.1      yamt static int	p9100_allocattr(void *, int, int, int, long *);
    217  1.26.8.1      yamt 
    218  1.26.8.1      yamt /*static void	p9100_scroll(void *, void *, int);*/
    219  1.26.8.1      yamt 
    220  1.26.8.1      yamt static int	p9100_putcmap(struct p9100_softc *, struct wsdisplay_cmap *);
    221  1.26.8.1      yamt static int 	p9100_getcmap(struct p9100_softc *, struct wsdisplay_cmap *);
    222  1.26.8.1      yamt static int	p9100_ioctl(void *, u_long, caddr_t, int, struct lwp *);
    223  1.26.8.1      yamt static paddr_t	p9100_mmap(void *, off_t, int);
    224      1.21  macallan 
    225  1.26.8.1      yamt /*static int	p9100_load_font(void *, void *, struct wsdisplay_font *);*/
    226      1.21  macallan 
    227  1.26.8.1      yamt static void	p9100_init_screen(void *, struct vcons_screen *, int,
    228      1.21  macallan 	    long *);
    229  1.26.8.1      yamt #endif
    230  1.26.8.1      yamt 
    231  1.26.8.1      yamt static void	p9100_init_cursor(struct p9100_softc *);
    232      1.21  macallan 
    233  1.26.8.1      yamt static void	p9100_set_fbcursor(struct p9100_softc *);
    234  1.26.8.1      yamt static void	p9100_setcursorcmap(struct p9100_softc *);
    235  1.26.8.1      yamt static void	p9100_loadcursor(struct p9100_softc *);
    236      1.21  macallan 
    237  1.26.8.1      yamt static int	p9100_intr(void *);
    238  1.26.8.1      yamt 
    239  1.26.8.1      yamt /* power management stuff */
    240  1.26.8.1      yamt static void p9100_power_hook(int, void *);
    241  1.26.8.1      yamt 
    242  1.26.8.1      yamt static void p9100_set_extvga(void *, int);
    243  1.26.8.1      yamt 
    244  1.26.8.1      yamt #if NWSDISPLAY > 0
    245      1.21  macallan struct wsdisplay_accessops p9100_accessops = {
    246      1.21  macallan 	p9100_ioctl,
    247      1.21  macallan 	p9100_mmap,
    248  1.26.8.1      yamt 	NULL,	/* vcons_alloc_screen */
    249  1.26.8.1      yamt 	NULL,	/* vcons_free_screen */
    250  1.26.8.1      yamt 	NULL,	/* vcons_show_screen */
    251      1.21  macallan 	NULL,	/* load_font */
    252      1.21  macallan 	NULL,	/* polls */
    253      1.21  macallan 	NULL,	/* getwschar */
    254      1.21  macallan 	NULL,	/* putwschar */
    255      1.21  macallan 	NULL,	/* scroll */
    256      1.21  macallan 	NULL,	/* getborder */
    257      1.21  macallan 	NULL	/* setborder */
    258      1.21  macallan };
    259  1.26.8.1      yamt #endif
    260  1.26.8.1      yamt 
    261  1.26.8.1      yamt #define PNOZZ_LATCH(sc, off) if(sc->sc_last_offset == (off & 0xffffff80)) { \
    262  1.26.8.1      yamt 		sc->sc_junk = bus_space_read_4(sc->sc_bustag, sc->sc_fb_memh, \
    263  1.26.8.1      yamt 		    off); \
    264  1.26.8.1      yamt 		sc->sc_last_offset = off & 0xffffff80; }
    265       1.1        pk 
    266       1.1        pk /*
    267       1.1        pk  * Match a p9100.
    268       1.1        pk  */
    269       1.1        pk static int
    270       1.1        pk p9100_sbus_match(struct device *parent, struct cfdata *cf, void *aux)
    271       1.1        pk {
    272       1.1        pk 	struct sbus_attach_args *sa = aux;
    273       1.1        pk 
    274       1.1        pk 	return (strcmp("p9100", sa->sa_name) == 0);
    275       1.1        pk }
    276       1.1        pk 
    277       1.1        pk 
    278       1.1        pk /*
    279       1.1        pk  * Attach a display.  We need to notice if it is the console, too.
    280       1.1        pk  */
    281       1.1        pk static void
    282       1.1        pk p9100_sbus_attach(struct device *parent, struct device *self, void *args)
    283       1.1        pk {
    284       1.1        pk 	struct p9100_softc *sc = (struct p9100_softc *)self;
    285       1.1        pk 	struct sbus_attach_args *sa = args;
    286       1.1        pk 	struct fbdevice *fb = &sc->sc_fb;
    287       1.1        pk 	int isconsole;
    288       1.1        pk 	int node;
    289      1.21  macallan 	int i, j;
    290  1.26.8.1      yamt 	uint8_t ver;
    291      1.21  macallan 
    292      1.21  macallan #if NWSDISPLAY > 0
    293      1.21  macallan 	struct wsemuldisplaydev_attach_args aa;
    294      1.21  macallan 	struct rasops_info *ri;
    295      1.21  macallan 	unsigned long defattr;
    296      1.21  macallan #endif
    297       1.1        pk 
    298  1.26.8.1      yamt 	sc->sc_last_offset = 0xffffffff;
    299  1.26.8.1      yamt 
    300       1.1        pk 	/* Remember cookies for p9100_mmap() */
    301       1.1        pk 	sc->sc_bustag = sa->sa_bustag;
    302      1.20     perry 	sc->sc_ctl_paddr = sbus_bus_addr(sa->sa_bustag,
    303       1.9   thorpej 		sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base);
    304      1.21  macallan 	sc->sc_ctl_psize = 0x8000;/*(bus_size_t)sa->sa_reg[0].oa_size;*/
    305       1.3       eeh 
    306      1.20     perry 	sc->sc_cmd_paddr = sbus_bus_addr(sa->sa_bustag,
    307       1.9   thorpej 		sa->sa_reg[1].oa_space, sa->sa_reg[1].oa_base);
    308       1.9   thorpej 	sc->sc_cmd_psize = (bus_size_t)sa->sa_reg[1].oa_size;
    309       1.3       eeh 
    310      1.20     perry 	sc->sc_fb_paddr = sbus_bus_addr(sa->sa_bustag,
    311       1.9   thorpej 		sa->sa_reg[2].oa_space, sa->sa_reg[2].oa_base);
    312       1.9   thorpej 	sc->sc_fb_psize = (bus_size_t)sa->sa_reg[2].oa_size;
    313       1.1        pk 
    314       1.1        pk 	fb->fb_driver = &p9100fbdriver;
    315       1.1        pk 	fb->fb_device = &sc->sc_dev;
    316  1.26.8.2      yamt 	fb->fb_flags = device_cfdata(&sc->sc_dev)->cf_flags & FB_USERMASK;
    317      1.21  macallan #ifdef PNOZZ_EMUL_CG3
    318       1.1        pk 	fb->fb_type.fb_type = FBTYPE_SUN3COLOR;
    319      1.21  macallan #else
    320      1.21  macallan 	fb->fb_type.fb_type = FBTYPE_P9100;
    321      1.21  macallan #endif
    322       1.7     cyber 	fb->fb_pixels = NULL;
    323      1.21  macallan 
    324      1.21  macallan 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    325       1.1        pk 
    326       1.1        pk 	node = sa->sa_node;
    327       1.7     cyber 	isconsole = fb_is_console(node);
    328       1.7     cyber 	if (!isconsole) {
    329      1.21  macallan 		printf("\n%s: fatal error: PROM didn't configure device\n",
    330      1.21  macallan 		    self->dv_xname);
    331       1.7     cyber 		return;
    332       1.7     cyber 	}
    333       1.1        pk 
    334       1.1        pk 	/*
    335       1.1        pk 	 * When the ROM has mapped in a p9100 display, the address
    336       1.1        pk 	 * maps only the video RAM, so in any case we have to map the
    337       1.1        pk 	 * registers ourselves.  We only need the video RAM if we are
    338       1.1        pk 	 * going to print characters via rconsole.
    339       1.1        pk 	 */
    340       1.8        pk 	if (sbus_bus_map(sc->sc_bustag,
    341       1.9   thorpej 			 sa->sa_reg[0].oa_space,
    342       1.9   thorpej 			 sa->sa_reg[0].oa_base,
    343      1.21  macallan 			 /*
    344      1.21  macallan 			  * XXX for some reason the SBus resources don't cover
    345      1.21  macallan 			  * all registers, so we just map what we need
    346      1.21  macallan 			  */
    347      1.21  macallan 			 /*sc->sc_ctl_psize*/ 0x8000,
    348      1.24  macallan 			 /*BUS_SPACE_MAP_LINEAR*/0, &sc->sc_ctl_memh) != 0) {
    349       1.1        pk 		printf("%s: cannot map control registers\n", self->dv_xname);
    350       1.1        pk 		return;
    351       1.1        pk 	}
    352       1.1        pk 
    353       1.1        pk 	if (sa->sa_npromvaddrs != 0)
    354       1.1        pk 		fb->fb_pixels = (caddr_t)sa->sa_promvaddrs[0];
    355       1.7     cyber 
    356       1.7     cyber 	if (fb->fb_pixels == NULL) {
    357       1.8        pk 		if (sbus_bus_map(sc->sc_bustag,
    358       1.9   thorpej 				sa->sa_reg[2].oa_space,
    359       1.9   thorpej 				sa->sa_reg[2].oa_base,
    360       1.8        pk 				sc->sc_fb_psize,
    361       1.8        pk 				BUS_SPACE_MAP_LINEAR, &sc->sc_fb_memh) != 0) {
    362       1.1        pk 			printf("%s: cannot map framebuffer\n", self->dv_xname);
    363       1.1        pk 			return;
    364       1.1        pk 		}
    365       1.1        pk 		fb->fb_pixels = (char *)sc->sc_fb_memh;
    366       1.1        pk 	} else {
    367       1.1        pk 		sc->sc_fb_memh = (bus_space_handle_t) fb->fb_pixels;
    368       1.1        pk 	}
    369       1.1        pk 
    370       1.1        pk 	i = p9100_ctl_read_4(sc, 0x0004);
    371       1.1        pk 	switch ((i >> 26) & 7) {
    372       1.1        pk 	    case 5: fb->fb_type.fb_depth = 32; break;
    373       1.1        pk 	    case 7: fb->fb_type.fb_depth = 24; break;
    374       1.1        pk 	    case 3: fb->fb_type.fb_depth = 16; break;
    375       1.1        pk 	    case 2: fb->fb_type.fb_depth = 8; break;
    376       1.1        pk 	    default: {
    377       1.1        pk 		panic("pnozz: can't determine screen depth (0x%02x)", i);
    378       1.1        pk 	    }
    379       1.1        pk 	}
    380      1.21  macallan 	sc->sc_depth = (fb->fb_type.fb_depth >> 3);
    381      1.21  macallan 
    382      1.21  macallan 	/* XXX for some reason I get a kernel trap with this */
    383      1.21  macallan 	sc->sc_width = prom_getpropint(node, "width", 800);
    384      1.21  macallan 	sc->sc_height = prom_getpropint(node, "height", 600);
    385      1.21  macallan 
    386      1.21  macallan 	sc->sc_stride = prom_getpropint(node, "linebytes", sc->sc_width *
    387      1.21  macallan 	    (fb->fb_type.fb_depth >> 3));
    388      1.21  macallan 
    389  1.26.8.1      yamt 	/* check the RAMDAC */
    390  1.26.8.1      yamt 	ver = p9100_ramdac_read_ctl(sc, DAC_VERSION);
    391  1.26.8.1      yamt 
    392      1.21  macallan 	p9100_init_engine(sc);
    393      1.21  macallan 
    394      1.21  macallan 	fb_setsize_obp(fb, fb->fb_type.fb_depth, sc->sc_width, sc->sc_height,
    395      1.21  macallan 	    node);
    396       1.1        pk 
    397       1.1        pk 	sbus_establish(&sc->sc_sd, &sc->sc_dev);
    398  1.26.8.1      yamt 	bus_intr_establish(sc->sc_bustag, sa->sa_pri, IPL_BIO,
    399  1.26.8.1      yamt 	    p9100_intr, sc);
    400  1.26.8.1      yamt 
    401       1.1        pk 	fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
    402  1.26.8.1      yamt 	printf(": rev %d / %x, %dx%d, depth %d mem %x",
    403  1.26.8.1      yamt 	       (i & 7), ver, fb->fb_type.fb_width, fb->fb_type.fb_height,
    404      1.21  macallan 	       fb->fb_type.fb_depth, (unsigned int)sc->sc_fb_psize);
    405       1.1        pk 
    406      1.19        pk 	fb->fb_type.fb_cmsize = prom_getpropint(node, "cmsize", 256);
    407       1.1        pk 	if ((1 << fb->fb_type.fb_depth) != fb->fb_type.fb_cmsize)
    408       1.1        pk 		printf(", %d entry colormap", fb->fb_type.fb_cmsize);
    409       1.1        pk 
    410       1.1        pk 	/* Initialize the default color map. */
    411      1.21  macallan 	/*bt_initcmap(&sc->sc_cmap, 256);*/
    412      1.21  macallan 	j = 0;
    413      1.21  macallan 	for (i = 0; i < 256; i++) {
    414      1.21  macallan 		sc->sc_cmap.cm_map[i][0] = rasops_cmap[j];
    415      1.21  macallan 		j++;
    416      1.21  macallan 		sc->sc_cmap.cm_map[i][1] = rasops_cmap[j];
    417      1.21  macallan 		j++;
    418      1.21  macallan 		sc->sc_cmap.cm_map[i][2] = rasops_cmap[j];
    419      1.21  macallan 		j++;
    420      1.21  macallan 	}
    421       1.1        pk 	p9100loadcmap(sc, 0, 256);
    422       1.1        pk 
    423       1.1        pk 	/* make sure we are not blanked */
    424       1.7     cyber 	if (isconsole)
    425       1.7     cyber 		p9100_set_video(sc, 1);
    426       1.1        pk 
    427       1.1        pk 	if (shutdownhook_establish(p9100_shutdown, sc) == NULL) {
    428       1.1        pk 		panic("%s: could not establish shutdown hook",
    429       1.1        pk 		      sc->sc_dev.dv_xname);
    430       1.1        pk 	}
    431       1.1        pk 
    432       1.1        pk 	if (isconsole) {
    433       1.1        pk 		printf(" (console)\n");
    434       1.1        pk #ifdef RASTERCONSOLE
    435      1.21  macallan 		/*p9100loadcmap(sc, 255, 1);*/
    436       1.1        pk 		fbrcons_init(fb);
    437       1.1        pk #endif
    438       1.1        pk 	} else
    439       1.1        pk 		printf("\n");
    440      1.21  macallan 
    441      1.21  macallan #if NWSDISPLAY > 0
    442      1.21  macallan 	wsfont_init();
    443  1.26.8.1      yamt 
    444  1.26.8.1      yamt 	vcons_init(&sc->vd, sc, &p9100_defscreendesc, &p9100_accessops);
    445  1.26.8.1      yamt 	sc->vd.init_screen = p9100_init_screen;
    446  1.26.8.1      yamt 
    447  1.26.8.1      yamt 	vcons_init_screen(&sc->vd, &p9100_console_screen, 1, &defattr);
    448  1.26.8.1      yamt 	p9100_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    449      1.21  macallan 
    450  1.26.8.1      yamt 	sc->sc_bg = (defattr >> 16) & 0xff;
    451  1.26.8.1      yamt 	p9100_clearscreen(sc);
    452  1.26.8.1      yamt 
    453  1.26.8.1      yamt 	ri = &p9100_console_screen.scr_ri;
    454      1.21  macallan 
    455      1.21  macallan 	p9100_defscreendesc.nrows = ri->ri_rows;
    456      1.21  macallan 	p9100_defscreendesc.ncols = ri->ri_cols;
    457      1.21  macallan 	p9100_defscreendesc.textops = &ri->ri_ops;
    458      1.21  macallan 	p9100_defscreendesc.capabilities = ri->ri_caps;
    459      1.21  macallan 
    460      1.21  macallan 	if(isconsole) {
    461      1.21  macallan 		wsdisplay_cnattach(&p9100_defscreendesc, ri, 0, 0, defattr);
    462      1.21  macallan 	}
    463      1.21  macallan 
    464      1.21  macallan 	aa.console = isconsole;
    465      1.21  macallan 	aa.scrdata = &p9100_screenlist;
    466      1.21  macallan 	aa.accessops = &p9100_accessops;
    467  1.26.8.1      yamt 	aa.accesscookie = &sc->vd;
    468       1.1        pk 
    469      1.21  macallan 	config_found(self, &aa, wsemuldisplaydevprint);
    470      1.21  macallan #endif
    471  1.26.8.1      yamt 	/* cursor sprite handling */
    472  1.26.8.1      yamt 	p9100_init_cursor(sc);
    473  1.26.8.1      yamt 
    474      1.21  macallan 	/* attach the fb */
    475       1.1        pk 	fb_attach(fb, isconsole);
    476      1.21  macallan 
    477  1.26.8.1      yamt 	/* register with power management */
    478  1.26.8.1      yamt 	sc->sc_video = 1;
    479  1.26.8.1      yamt 	sc->sc_powerstate = PWR_RESUME;
    480  1.26.8.1      yamt 	powerhook_establish(p9100_power_hook, sc);
    481  1.26.8.1      yamt 
    482  1.26.8.1      yamt #if NTCTRL > 0
    483  1.26.8.1      yamt 	/* register callback for external monitor status change */
    484  1.26.8.1      yamt 	tadpole_register_callback(p9100_set_extvga, sc);
    485      1.21  macallan #endif
    486       1.1        pk }
    487       1.1        pk 
    488       1.1        pk static void
    489       1.1        pk p9100_shutdown(arg)
    490       1.1        pk 	void *arg;
    491       1.1        pk {
    492       1.1        pk 	struct p9100_softc *sc = arg;
    493      1.21  macallan 
    494       1.2       mrg #ifdef RASTERCONSOLE
    495       1.1        pk 	sc->sc_cmap.cm_map[0][0] = 0xff;
    496       1.1        pk 	sc->sc_cmap.cm_map[0][1] = 0xff;
    497       1.1        pk 	sc->sc_cmap.cm_map[0][2] = 0xff;
    498       1.1        pk 	sc->sc_cmap.cm_map[1][0] = 0;
    499       1.1        pk 	sc->sc_cmap.cm_map[1][1] = 0;
    500      1.21  macallan 	sc->sc_cmap.cm_map[1][2] = 0x00;
    501       1.1        pk 	p9100loadcmap(sc, 0, 2);
    502       1.1        pk 	sc->sc_cmap.cm_map[255][0] = 0;
    503       1.1        pk 	sc->sc_cmap.cm_map[255][1] = 0;
    504       1.1        pk 	sc->sc_cmap.cm_map[255][2] = 0;
    505       1.1        pk 	p9100loadcmap(sc, 255, 1);
    506       1.1        pk #endif
    507       1.1        pk 	p9100_set_video(sc, 1);
    508       1.1        pk }
    509       1.1        pk 
    510       1.1        pk int
    511      1.25  christos p9100open(dev_t dev, int flags, int mode, struct lwp *l)
    512       1.1        pk {
    513       1.1        pk 	int unit = minor(dev);
    514       1.1        pk 
    515       1.1        pk 	if (unit >= pnozz_cd.cd_ndevs || pnozz_cd.cd_devs[unit] == NULL)
    516       1.1        pk 		return (ENXIO);
    517       1.1        pk 	return (0);
    518       1.1        pk }
    519       1.1        pk 
    520       1.1        pk int
    521      1.25  christos p9100ioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct lwp *l)
    522       1.1        pk {
    523       1.1        pk 	struct p9100_softc *sc = pnozz_cd.cd_devs[minor(dev)];
    524       1.1        pk 	struct fbgattr *fba;
    525      1.24  macallan 	int error, v;
    526       1.1        pk 
    527       1.1        pk 	switch (cmd) {
    528       1.1        pk 
    529       1.1        pk 	case FBIOGTYPE:
    530       1.1        pk 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    531       1.1        pk 		break;
    532       1.1        pk 
    533       1.1        pk 	case FBIOGATTR:
    534       1.1        pk 		fba = (struct fbgattr *)data;
    535       1.1        pk 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    536       1.1        pk 		fba->owner = 0;		/* XXX ??? */
    537       1.1        pk 		fba->fbtype = sc->sc_fb.fb_type;
    538       1.1        pk 		fba->sattr.flags = 0;
    539       1.1        pk 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    540       1.1        pk 		fba->sattr.dev_specific[0] = -1;
    541       1.1        pk 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    542       1.1        pk 		fba->emu_types[1] = -1;
    543       1.1        pk 		break;
    544       1.1        pk 
    545       1.1        pk 	case FBIOGETCMAP:
    546       1.1        pk #define p ((struct fbcmap *)data)
    547       1.1        pk 		return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
    548       1.1        pk 
    549       1.1        pk 	case FBIOPUTCMAP:
    550       1.1        pk 		/* copy to software map */
    551       1.1        pk 		error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
    552       1.1        pk 		if (error)
    553       1.1        pk 			return (error);
    554       1.1        pk 		/* now blast them into the chip */
    555       1.1        pk 		/* XXX should use retrace interrupt */
    556       1.1        pk 		p9100loadcmap(sc, p->index, p->count);
    557       1.1        pk #undef p
    558       1.1        pk 		break;
    559       1.1        pk 
    560       1.1        pk 	case FBIOGVIDEO:
    561       1.1        pk 		*(int *)data = p9100_get_video(sc);
    562       1.1        pk 		break;
    563       1.1        pk 
    564       1.1        pk 	case FBIOSVIDEO:
    565       1.1        pk 		p9100_set_video(sc, *(int *)data);
    566       1.1        pk 		break;
    567       1.1        pk 
    568      1.24  macallan /* these are for both FBIOSCURSOR and FBIOGCURSOR */
    569      1.24  macallan #define p ((struct fbcursor *)data)
    570      1.24  macallan #define pc (&sc->sc_cursor)
    571      1.24  macallan 
    572      1.24  macallan 	case FBIOGCURSOR:
    573      1.24  macallan 		p->set = FB_CUR_SETALL;	/* close enough, anyway */
    574      1.24  macallan 		p->enable = pc->pc_enable;
    575      1.24  macallan 		p->pos = pc->pc_pos;
    576      1.24  macallan 		p->hot = pc->pc_hot;
    577      1.24  macallan 		p->size = pc->pc_size;
    578      1.24  macallan 
    579      1.24  macallan 		if (p->image != NULL) {
    580      1.24  macallan 			error = copyout(pc->pc_bits, p->image, 0x200);
    581      1.24  macallan 			if (error)
    582      1.24  macallan 				return error;
    583      1.24  macallan 			error = copyout(&pc->pc_bits[0x80], p->mask, 0x200);
    584      1.24  macallan 			if (error)
    585      1.24  macallan 				return error;
    586      1.24  macallan 		}
    587      1.24  macallan 
    588      1.24  macallan 		p->cmap.index = 0;
    589      1.24  macallan 		p->cmap.count = 3;
    590      1.24  macallan 		if (p->cmap.red != NULL) {
    591      1.24  macallan 			copyout(pc->red, p->cmap.red, 3);
    592      1.24  macallan 			copyout(pc->green, p->cmap.green, 3);
    593      1.24  macallan 			copyout(pc->blue, p->cmap.blue, 3);
    594      1.24  macallan 		}
    595      1.24  macallan 		break;
    596      1.24  macallan 
    597      1.24  macallan 	case FBIOSCURSOR:
    598      1.24  macallan 	{
    599      1.24  macallan 		int count;
    600      1.24  macallan 		uint32_t image[0x80], mask[0x80];
    601      1.24  macallan 		uint8_t red[3], green[3], blue[3];
    602      1.24  macallan 
    603      1.24  macallan 		v = p->set;
    604      1.24  macallan 		if (v & FB_CUR_SETCMAP) {
    605      1.24  macallan 			error = copyin(p->cmap.red, red, 3);
    606      1.24  macallan 			error |= copyin(p->cmap.green, green, 3);
    607      1.24  macallan 			error |= copyin(p->cmap.blue, blue, 3);
    608      1.24  macallan 			if (error)
    609      1.24  macallan 				return error;
    610      1.24  macallan 		}
    611      1.24  macallan 		if (v & FB_CUR_SETSHAPE) {
    612      1.24  macallan 			if (p->size.x > 64 || p->size.y > 64)
    613      1.24  macallan 				return EINVAL;
    614      1.24  macallan 			memset(&mask, 0, 0x200);
    615      1.24  macallan 			memset(&image, 0, 0x200);
    616      1.24  macallan 			count = p->size.y * 8;
    617      1.24  macallan 			error = copyin(p->image, image, count);
    618      1.24  macallan 			if (error)
    619      1.24  macallan 				return error;
    620      1.24  macallan 			error = copyin(p->mask, mask, count);
    621      1.24  macallan 			if (error)
    622      1.24  macallan 				return error;
    623      1.24  macallan 		}
    624      1.24  macallan 
    625      1.24  macallan 		/* parameters are OK; do it */
    626      1.24  macallan 		if (v & (FB_CUR_SETCUR | FB_CUR_SETPOS | FB_CUR_SETHOT)) {
    627      1.24  macallan 			if (v & FB_CUR_SETCUR)
    628      1.24  macallan 				pc->pc_enable = p->enable;
    629      1.24  macallan 			if (v & FB_CUR_SETPOS)
    630      1.24  macallan 				pc->pc_pos = p->pos;
    631      1.24  macallan 			if (v & FB_CUR_SETHOT)
    632      1.24  macallan 				pc->pc_hot = p->hot;
    633      1.24  macallan 			p9100_set_fbcursor(sc);
    634      1.24  macallan 		}
    635      1.24  macallan 
    636      1.24  macallan 		if (v & FB_CUR_SETCMAP) {
    637      1.24  macallan 			memcpy(pc->red, red, 3);
    638      1.24  macallan 			memcpy(pc->green, green, 3);
    639      1.24  macallan 			memcpy(pc->blue, blue, 3);
    640      1.24  macallan 			p9100_setcursorcmap(sc);
    641      1.24  macallan 		}
    642      1.24  macallan 
    643      1.24  macallan 		if (v & FB_CUR_SETSHAPE) {
    644      1.24  macallan 			memcpy(pc->pc_bits, image, 0x200);
    645      1.24  macallan 			memcpy(&pc->pc_bits[0x80], mask, 0x200);
    646      1.24  macallan 			p9100_loadcursor(sc);
    647      1.24  macallan 		}
    648      1.24  macallan 	}
    649      1.24  macallan 	break;
    650      1.24  macallan 
    651      1.24  macallan #undef p
    652      1.24  macallan #undef cc
    653      1.24  macallan 
    654      1.24  macallan 	case FBIOGCURPOS:
    655      1.24  macallan 		*(struct fbcurpos *)data = sc->sc_cursor.pc_pos;
    656      1.24  macallan 		break;
    657      1.24  macallan 
    658      1.24  macallan 	case FBIOSCURPOS:
    659      1.24  macallan 		sc->sc_cursor.pc_pos = *(struct fbcurpos *)data;
    660      1.24  macallan 		p9100_set_fbcursor(sc);
    661      1.24  macallan 		break;
    662      1.24  macallan 
    663      1.24  macallan 	case FBIOGCURMAX:
    664      1.24  macallan 		/* max cursor size is 64x64 */
    665      1.24  macallan 		((struct fbcurpos *)data)->x = 64;
    666      1.24  macallan 		((struct fbcurpos *)data)->y = 64;
    667      1.24  macallan 		break;
    668      1.24  macallan 
    669       1.1        pk 	default:
    670       1.1        pk 		return (ENOTTY);
    671       1.1        pk 	}
    672       1.1        pk 	return (0);
    673       1.1        pk }
    674       1.1        pk 
    675       1.1        pk static uint32_t
    676       1.1        pk p9100_ctl_read_4(struct p9100_softc *sc, bus_size_t off)
    677       1.1        pk {
    678  1.26.8.1      yamt 
    679  1.26.8.1      yamt 	PNOZZ_LATCH(sc, off);
    680       1.1        pk 	return bus_space_read_4(sc->sc_bustag, sc->sc_ctl_memh, off);
    681       1.1        pk }
    682       1.1        pk 
    683       1.1        pk static void
    684       1.1        pk p9100_ctl_write_4(struct p9100_softc *sc, bus_size_t off, uint32_t v)
    685       1.1        pk {
    686  1.26.8.1      yamt 
    687  1.26.8.1      yamt 	PNOZZ_LATCH(sc, off);
    688       1.1        pk 	bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh, off, v);
    689       1.1        pk }
    690       1.1        pk 
    691  1.26.8.1      yamt /* initialize the drawing engine */
    692  1.26.8.1      yamt static void
    693  1.26.8.1      yamt p9100_init_engine(struct p9100_softc *sc)
    694  1.26.8.1      yamt {
    695  1.26.8.1      yamt 	/* reset clipping rectangles */
    696  1.26.8.1      yamt 	uint32_t rmax = ((sc->sc_width & 0x3fff) << 16) |
    697  1.26.8.1      yamt 	    (sc->sc_height & 0x3fff);
    698  1.26.8.1      yamt 
    699  1.26.8.1      yamt 	sc->sc_last_offset = 0xffffffff;
    700  1.26.8.1      yamt 
    701  1.26.8.1      yamt 	p9100_ctl_write_4(sc, WINDOW_OFFSET, 0);
    702  1.26.8.1      yamt 	p9100_ctl_write_4(sc, WINDOW_MIN, 0);
    703  1.26.8.1      yamt 	p9100_ctl_write_4(sc, WINDOW_MAX, rmax);
    704  1.26.8.1      yamt 	p9100_ctl_write_4(sc, BYTE_CLIP_MIN, 0);
    705  1.26.8.1      yamt 	p9100_ctl_write_4(sc, BYTE_CLIP_MAX, rmax);
    706  1.26.8.1      yamt 	p9100_ctl_write_4(sc, DRAW_MODE, 0);
    707  1.26.8.1      yamt 	p9100_ctl_write_4(sc, PLANE_MASK, 0xffffffff);
    708  1.26.8.1      yamt 	p9100_ctl_write_4(sc, PATTERN0, 0xffffffff);
    709  1.26.8.1      yamt 	p9100_ctl_write_4(sc, PATTERN1, 0xffffffff);
    710  1.26.8.1      yamt 	p9100_ctl_write_4(sc, PATTERN2, 0xffffffff);
    711  1.26.8.1      yamt 	p9100_ctl_write_4(sc, PATTERN3, 0xffffffff);
    712  1.26.8.1      yamt }
    713  1.26.8.1      yamt 
    714  1.26.8.1      yamt /* we only need these in the wsdisplay case */
    715  1.26.8.1      yamt #if NWSDISPLAY > 0
    716  1.26.8.1      yamt 
    717      1.21  macallan /* wait until the engine is idle */
    718      1.21  macallan static void
    719      1.21  macallan p9100_sync(struct p9100_softc *sc)
    720      1.21  macallan {
    721      1.21  macallan 	while((p9100_ctl_read_4(sc, ENGINE_STATUS) &
    722      1.21  macallan 	    (ENGINE_BUSY | BLITTER_BUSY)) != 0);
    723      1.21  macallan }
    724      1.21  macallan 
    725      1.21  macallan static void
    726      1.21  macallan p9100_set_color_reg(struct p9100_softc *sc, int reg, int32_t col)
    727      1.21  macallan {
    728      1.21  macallan 	uint32_t out;
    729      1.21  macallan 
    730      1.21  macallan 	switch(sc->sc_depth)
    731      1.21  macallan 	{
    732      1.21  macallan 		case 1:	/* 8 bit */
    733      1.21  macallan 			out = (col << 8) | col;
    734      1.21  macallan 			out |= out << 16;
    735      1.21  macallan 			break;
    736      1.21  macallan 		case 2: /* 16 bit */
    737      1.21  macallan 			out = col | (col << 16);
    738      1.21  macallan 			break;
    739      1.21  macallan 		default:
    740      1.21  macallan 			out = col;
    741      1.21  macallan 	}
    742      1.21  macallan 	p9100_ctl_write_4(sc, reg, out);
    743      1.21  macallan }
    744      1.21  macallan 
    745      1.21  macallan /* screen-to-screen blit */
    746  1.26.8.1      yamt static void
    747  1.26.8.1      yamt p9100_bitblt(void *cookie, int xs, int ys, int xd, int yd, int wi,
    748      1.21  macallan     int he, uint32_t rop)
    749      1.21  macallan {
    750  1.26.8.1      yamt 	struct p9100_softc *sc = cookie;
    751  1.26.8.1      yamt 	uint32_t src, dst, srcw, dstw;
    752  1.26.8.1      yamt 
    753  1.26.8.1      yamt 	sc->sc_last_offset = 0xffffffff;
    754  1.26.8.1      yamt 
    755      1.21  macallan 	src = ((xs & 0x3fff) << 16) | (ys & 0x3fff);
    756      1.21  macallan 	dst = ((xd & 0x3fff) << 16) | (yd & 0x3fff);
    757      1.21  macallan 	srcw = (((xs + wi - 1) & 0x3fff) << 16) | ((ys + he - 1) & 0x3fff);
    758      1.21  macallan 	dstw = (((xd + wi - 1) & 0x3fff) << 16) | ((yd + he - 1) & 0x3fff);
    759      1.21  macallan 	p9100_sync(sc);
    760      1.21  macallan 	p9100_ctl_write_4(sc, RASTER_OP, rop);
    761      1.21  macallan 
    762      1.21  macallan 	p9100_ctl_write_4(sc, ABS_XY0, src);
    763      1.21  macallan 
    764      1.21  macallan 	p9100_ctl_write_4(sc, ABS_XY1, srcw);
    765      1.21  macallan 	p9100_ctl_write_4(sc, ABS_XY2, dst);
    766      1.21  macallan 	p9100_ctl_write_4(sc, ABS_XY3, dstw);
    767  1.26.8.1      yamt 	sc->sc_junk = p9100_ctl_read_4(sc, COMMAND_BLIT);
    768      1.21  macallan }
    769      1.21  macallan 
    770      1.21  macallan /* solid rectangle fill */
    771  1.26.8.1      yamt static void
    772  1.26.8.1      yamt p9100_rectfill(void *cookie, int xs, int ys, int wi, int he, uint32_t col)
    773      1.21  macallan {
    774  1.26.8.1      yamt 	struct p9100_softc *sc = cookie;
    775  1.26.8.1      yamt 	uint32_t src, srcw;
    776  1.26.8.1      yamt 
    777  1.26.8.1      yamt 	sc->sc_last_offset = 0xffffffff;
    778  1.26.8.1      yamt 
    779      1.21  macallan 	src = ((xs & 0x3fff) << 16) | (ys & 0x3fff);
    780      1.21  macallan 	srcw = (((xs + wi) & 0x3fff) << 16) | ((ys + he) & 0x3fff);
    781      1.21  macallan 	p9100_sync(sc);
    782      1.21  macallan 	p9100_set_color_reg(sc, FOREGROUND_COLOR, col);
    783      1.21  macallan 	p9100_set_color_reg(sc, BACKGROUND_COLOR, col);
    784      1.21  macallan 	p9100_ctl_write_4(sc, RASTER_OP, ROP_PAT);
    785      1.21  macallan 	p9100_ctl_write_4(sc, COORD_INDEX, 0);
    786      1.21  macallan 	p9100_ctl_write_4(sc, RECT_RTW_XY, src);
    787      1.21  macallan 	p9100_ctl_write_4(sc, RECT_RTW_XY, srcw);
    788  1.26.8.1      yamt 	sc->sc_junk = p9100_ctl_read_4(sc, COMMAND_QUAD);
    789      1.21  macallan }
    790      1.21  macallan 
    791      1.21  macallan /* setup for mono->colour expansion */
    792  1.26.8.1      yamt static void
    793      1.21  macallan p9100_setup_mono(struct p9100_softc *sc, int x, int y, int wi, int he,
    794      1.21  macallan     uint32_t fg, uint32_t bg)
    795      1.21  macallan {
    796  1.26.8.1      yamt 
    797  1.26.8.1      yamt 	sc->sc_last_offset = 0xffffffff;
    798  1.26.8.1      yamt 
    799      1.21  macallan 	p9100_sync(sc);
    800      1.21  macallan 	/*
    801      1.21  macallan 	 * this doesn't make any sense to me either, but for some reason the
    802      1.21  macallan 	 * chip applies the foreground colour to 0 pixels
    803      1.21  macallan 	 */
    804      1.21  macallan 
    805      1.21  macallan 	p9100_set_color_reg(sc,FOREGROUND_COLOR,bg);
    806      1.21  macallan 	p9100_set_color_reg(sc,BACKGROUND_COLOR,fg);
    807      1.21  macallan 
    808      1.21  macallan 	p9100_ctl_write_4(sc, RASTER_OP, ROP_SRC);
    809      1.21  macallan 	p9100_ctl_write_4(sc, ABS_X0, x);
    810      1.21  macallan 	p9100_ctl_write_4(sc, ABS_XY1, (x << 16) | (y & 0xFFFFL));
    811      1.21  macallan 	p9100_ctl_write_4(sc, ABS_X2, (x + wi));
    812      1.21  macallan 	p9100_ctl_write_4(sc, ABS_Y3, he);
    813      1.21  macallan 	/* now feed the data into the chip */
    814      1.21  macallan 	sc->sc_mono_width = wi;
    815      1.21  macallan }
    816      1.21  macallan 
    817      1.21  macallan /* write monochrome data to the screen through the blitter */
    818  1.26.8.1      yamt static void
    819      1.21  macallan p9100_feed_line(struct p9100_softc *sc, int count, uint8_t *data)
    820      1.21  macallan {
    821      1.21  macallan 	int i;
    822      1.21  macallan 	uint32_t latch = 0, bork;
    823      1.21  macallan 	int shift = 24;
    824      1.21  macallan 	int to_go = sc->sc_mono_width;
    825  1.26.8.1      yamt 
    826  1.26.8.1      yamt 	PNOZZ_LATCH(sc, PIXEL_1);
    827  1.26.8.1      yamt 
    828      1.21  macallan 	for (i = 0; i < count; i++) {
    829      1.21  macallan 		bork = data[i];
    830      1.21  macallan 		latch |= (bork << shift);
    831      1.21  macallan 		if (shift == 0) {
    832      1.21  macallan 			/* check how many bits are significant */
    833      1.21  macallan 			if (to_go > 31) {
    834  1.26.8.1      yamt 				bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh,
    835  1.26.8.1      yamt 				    (PIXEL_1 + (31 << 2)), latch);
    836  1.26.8.1      yamt 				/*p9100_ctl_write_4(sc, (PIXEL_1 +
    837  1.26.8.1      yamt 				    (31 << 2)), latch);*/
    838      1.21  macallan 				to_go -= 32;
    839      1.21  macallan 			} else
    840      1.21  macallan 			{
    841  1.26.8.1      yamt 				bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh,
    842  1.26.8.1      yamt 				    (PIXEL_1 + ((to_go - 1) << 2)), latch);
    843  1.26.8.1      yamt 				/*p9100_ctl_write_4(sc, (PIXEL_1 +
    844  1.26.8.1      yamt 				    ((to_go - 1) << 2)), latch);*/
    845      1.21  macallan 				to_go = 0;
    846      1.21  macallan 			}
    847      1.21  macallan 			latch = 0;
    848      1.21  macallan 			shift = 24;
    849      1.21  macallan 		} else
    850      1.21  macallan 			shift -= 8;
    851      1.21  macallan 		}
    852      1.21  macallan 	if (shift != 24)
    853      1.21  macallan 		p9100_ctl_write_4(sc, (PIXEL_1 + ((to_go - 1) << 2)), latch);
    854      1.21  macallan }
    855      1.21  macallan 
    856  1.26.8.1      yamt static void
    857      1.21  macallan p9100_clearscreen(struct p9100_softc *sc)
    858      1.21  macallan {
    859  1.26.8.1      yamt 
    860      1.21  macallan 	p9100_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height, sc->sc_bg);
    861      1.21  macallan }
    862  1.26.8.1      yamt #endif /* NWSDISPLAY > 0 */
    863      1.21  macallan 
    864  1.26.8.1      yamt static uint8_t
    865       1.1        pk p9100_ramdac_read(struct p9100_softc *sc, bus_size_t off)
    866       1.1        pk {
    867  1.26.8.1      yamt 
    868       1.1        pk 	sc->sc_junk = p9100_ctl_read_4(sc, PWRUP_CNFG);
    869      1.21  macallan 	return ((bus_space_read_4(sc->sc_bustag,
    870      1.21  macallan 	    sc->sc_ctl_memh, off) >> 16) & 0xff);
    871       1.1        pk }
    872       1.1        pk 
    873  1.26.8.1      yamt static void
    874       1.1        pk p9100_ramdac_write(struct p9100_softc *sc, bus_size_t off, uint8_t v)
    875       1.1        pk {
    876  1.26.8.1      yamt 
    877       1.1        pk 	sc->sc_junk = p9100_ctl_read_4(sc, PWRUP_CNFG);
    878      1.21  macallan 	bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh, off,
    879      1.21  macallan 	    ((uint32_t)v) << 16);
    880       1.1        pk }
    881       1.1        pk 
    882  1.26.8.1      yamt static uint8_t
    883  1.26.8.1      yamt p9100_ramdac_read_ctl(struct p9100_softc *sc, int off)
    884  1.26.8.1      yamt {
    885  1.26.8.1      yamt 	p9100_ramdac_write(sc, DAC_INDX_LO, off & 0xff);
    886  1.26.8.1      yamt 	p9100_ramdac_write(sc, DAC_INDX_HI, (off & 0xff00) >> 8);
    887  1.26.8.1      yamt 	return p9100_ramdac_read(sc, DAC_INDX_DATA);
    888  1.26.8.1      yamt }
    889  1.26.8.1      yamt 
    890  1.26.8.1      yamt static void
    891  1.26.8.1      yamt p9100_ramdac_write_ctl(struct p9100_softc *sc, int off, uint8_t val)
    892  1.26.8.1      yamt {
    893  1.26.8.1      yamt 	p9100_ramdac_write(sc, DAC_INDX_LO, off & 0xff);
    894  1.26.8.1      yamt 	p9100_ramdac_write(sc, DAC_INDX_HI, (off & 0xff00) >> 8);
    895  1.26.8.1      yamt 	p9100_ramdac_write(sc, DAC_INDX_DATA, val);
    896  1.26.8.1      yamt }
    897  1.26.8.1      yamt 
    898       1.1        pk /*
    899       1.1        pk  * Undo the effect of an FBIOSVIDEO that turns the video off.
    900       1.1        pk  */
    901       1.1        pk static void
    902       1.1        pk p9100unblank(struct device *dev)
    903       1.1        pk {
    904  1.26.8.1      yamt 	struct p9100_softc *sc = (struct p9100_softc *)dev;
    905  1.26.8.1      yamt 
    906       1.1        pk 	p9100_set_video((struct p9100_softc *)dev, 1);
    907  1.26.8.1      yamt 
    908  1.26.8.1      yamt 	/*
    909  1.26.8.1      yamt 	 * Check if we're in terminal mode. If not force the console screen
    910  1.26.8.1      yamt 	 * to front so we can see ddb, panic messages and so on
    911  1.26.8.1      yamt 	 */
    912  1.26.8.1      yamt 	if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL) {
    913  1.26.8.1      yamt 		sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    914  1.26.8.1      yamt 		if (sc->vd.active != &p9100_console_screen) {
    915  1.26.8.1      yamt 			SCREEN_INVISIBLE(sc->vd.active);
    916  1.26.8.1      yamt 			sc->vd.active = &p9100_console_screen;
    917  1.26.8.1      yamt 			SCREEN_VISIBLE(&p9100_console_screen);
    918  1.26.8.1      yamt 		}
    919  1.26.8.1      yamt 		vcons_redraw_screen(&p9100_console_screen);
    920  1.26.8.1      yamt 	}
    921       1.1        pk }
    922       1.1        pk 
    923       1.1        pk static void
    924       1.1        pk p9100_set_video(struct p9100_softc *sc, int enable)
    925       1.1        pk {
    926       1.1        pk 	u_int32_t v = p9100_ctl_read_4(sc, SCRN_RPNT_CTL_1);
    927      1.21  macallan 
    928       1.1        pk 	if (enable)
    929       1.1        pk 		v |= VIDEO_ENABLED;
    930       1.1        pk 	else
    931       1.1        pk 		v &= ~VIDEO_ENABLED;
    932       1.1        pk 	p9100_ctl_write_4(sc, SCRN_RPNT_CTL_1, v);
    933       1.1        pk #if NTCTRL > 0
    934       1.1        pk 	/* Turn On/Off the TFT if we know how.
    935       1.1        pk 	 */
    936       1.1        pk 	tadpole_set_video(enable);
    937       1.1        pk #endif
    938       1.1        pk }
    939       1.1        pk 
    940       1.1        pk static int
    941       1.1        pk p9100_get_video(struct p9100_softc *sc)
    942       1.1        pk {
    943       1.1        pk 	return (p9100_ctl_read_4(sc, SCRN_RPNT_CTL_1) & VIDEO_ENABLED) != 0;
    944       1.1        pk }
    945       1.1        pk 
    946  1.26.8.1      yamt static void
    947  1.26.8.1      yamt p9100_power_hook(int why, void *cookie)
    948  1.26.8.1      yamt {
    949  1.26.8.1      yamt 	struct p9100_softc *sc = cookie;
    950  1.26.8.1      yamt 
    951  1.26.8.1      yamt 	if (why == sc->sc_powerstate)
    952  1.26.8.1      yamt 		return;
    953  1.26.8.1      yamt 
    954  1.26.8.1      yamt 	switch(why)
    955  1.26.8.1      yamt 	{
    956  1.26.8.1      yamt 		case PWR_SUSPEND:
    957  1.26.8.1      yamt 		case PWR_STANDBY:
    958  1.26.8.1      yamt 			sc->sc_video = p9100_get_video(sc);
    959  1.26.8.1      yamt 			p9100_set_video(sc, 0);
    960  1.26.8.1      yamt 			sc->sc_powerstate = why;
    961  1.26.8.1      yamt 			break;
    962  1.26.8.1      yamt 		case PWR_RESUME:
    963  1.26.8.1      yamt 			p9100_set_video(sc, sc->sc_video);
    964  1.26.8.1      yamt 			sc->sc_powerstate = why;
    965  1.26.8.1      yamt 			break;
    966  1.26.8.1      yamt 	}
    967  1.26.8.1      yamt }
    968  1.26.8.1      yamt 
    969       1.1        pk /*
    970       1.1        pk  * Load a subset of the current (new) colormap into the IBM RAMDAC.
    971       1.1        pk  */
    972       1.1        pk static void
    973       1.1        pk p9100loadcmap(struct p9100_softc *sc, int start, int ncolors)
    974       1.1        pk {
    975      1.21  macallan 	int i;
    976  1.26.8.1      yamt 
    977  1.26.8.1      yamt 	sc->sc_last_offset = 0xffffffff;
    978  1.26.8.1      yamt 
    979       1.1        pk 	p9100_ramdac_write(sc, DAC_CMAP_WRIDX, start);
    980       1.1        pk 
    981      1.21  macallan 	for (i=0;i<ncolors;i++) {
    982      1.21  macallan 		p9100_ramdac_write(sc, DAC_CMAP_DATA,
    983      1.21  macallan 		    sc->sc_cmap.cm_map[i + start][0]);
    984      1.21  macallan 		p9100_ramdac_write(sc, DAC_CMAP_DATA,
    985      1.21  macallan 		    sc->sc_cmap.cm_map[i + start][1]);
    986      1.21  macallan 		p9100_ramdac_write(sc, DAC_CMAP_DATA,
    987      1.21  macallan 		    sc->sc_cmap.cm_map[i + start][2]);
    988       1.1        pk 	}
    989       1.1        pk }
    990       1.1        pk 
    991       1.1        pk /*
    992       1.1        pk  * Return the address that would map the given device at the given
    993       1.1        pk  * offset, allowing for the given protection, or return -1 for error.
    994       1.1        pk  */
    995  1.26.8.1      yamt static paddr_t
    996       1.1        pk p9100mmap(dev_t dev, off_t off, int prot)
    997       1.1        pk {
    998       1.1        pk 	struct p9100_softc *sc = pnozz_cd.cd_devs[minor(dev)];
    999       1.1        pk 
   1000       1.1        pk 	if (off & PGOFSET)
   1001       1.1        pk 		panic("p9100mmap");
   1002       1.1        pk 	if (off < 0)
   1003       1.1        pk 		return (-1);
   1004       1.1        pk 
   1005      1.21  macallan #ifdef PNOZZ_EMUL_CG3
   1006       1.1        pk #define CG3_MMAP_OFFSET	0x04000000
   1007       1.1        pk 	/* Make Xsun think we are a CG3 (SUN3COLOR)
   1008       1.1        pk 	 */
   1009       1.1        pk 	if (off >= CG3_MMAP_OFFSET && off < CG3_MMAP_OFFSET + sc->sc_fb_psize) {
   1010       1.1        pk 		off -= CG3_MMAP_OFFSET;
   1011       1.3       eeh 		return (bus_space_mmap(sc->sc_bustag,
   1012       1.3       eeh 			sc->sc_fb_paddr,
   1013       1.3       eeh 			off,
   1014       1.3       eeh 			prot,
   1015       1.3       eeh 			BUS_SPACE_MAP_LINEAR));
   1016       1.1        pk 	}
   1017      1.21  macallan #endif
   1018       1.1        pk 
   1019       1.1        pk 	if (off >= sc->sc_fb_psize + sc->sc_ctl_psize + sc->sc_cmd_psize)
   1020       1.1        pk 		return (-1);
   1021       1.1        pk 
   1022       1.1        pk 	if (off < sc->sc_fb_psize) {
   1023       1.3       eeh 		return (bus_space_mmap(sc->sc_bustag,
   1024       1.3       eeh 			sc->sc_fb_paddr,
   1025       1.3       eeh 			off,
   1026       1.3       eeh 			prot,
   1027       1.3       eeh 			BUS_SPACE_MAP_LINEAR));
   1028       1.1        pk 	}
   1029       1.1        pk 	off -= sc->sc_fb_psize;
   1030       1.1        pk 	if (off < sc->sc_ctl_psize) {
   1031       1.3       eeh 		return (bus_space_mmap(sc->sc_bustag,
   1032       1.3       eeh 			sc->sc_ctl_paddr,
   1033       1.3       eeh 			off,
   1034       1.3       eeh 			prot,
   1035       1.3       eeh 			BUS_SPACE_MAP_LINEAR));
   1036       1.1        pk 	}
   1037       1.1        pk 	off -= sc->sc_ctl_psize;
   1038       1.1        pk 
   1039       1.3       eeh 	return (bus_space_mmap(sc->sc_bustag,
   1040       1.3       eeh 		sc->sc_cmd_paddr,
   1041       1.3       eeh 		off,
   1042       1.3       eeh 		prot,
   1043       1.3       eeh 		BUS_SPACE_MAP_LINEAR));
   1044       1.1        pk }
   1045      1.21  macallan 
   1046      1.21  macallan /* wscons stuff */
   1047  1.26.8.1      yamt #if NWSDISPLAY > 0
   1048      1.21  macallan 
   1049  1.26.8.1      yamt static void
   1050      1.21  macallan p9100_cursor(void *cookie, int on, int row, int col)
   1051      1.21  macallan {
   1052      1.21  macallan 	struct rasops_info *ri = cookie;
   1053  1.26.8.1      yamt 	struct vcons_screen *scr = ri->ri_hw;
   1054  1.26.8.1      yamt 	struct p9100_softc *sc = scr->scr_cookie;
   1055      1.21  macallan 	int x, y, wi,he;
   1056      1.21  macallan 
   1057      1.21  macallan 	wi = ri->ri_font->fontwidth;
   1058      1.21  macallan 	he = ri->ri_font->fontheight;
   1059      1.21  macallan 
   1060  1.26.8.1      yamt 	if (ri->ri_flg & RI_CURSOR) {
   1061  1.26.8.1      yamt 		x = ri->ri_ccol * wi + ri->ri_xorigin;
   1062  1.26.8.1      yamt 		y = ri->ri_crow * he + ri->ri_yorigin;
   1063  1.26.8.1      yamt 		p9100_bitblt(sc, x, y, x, y, wi, he, ROP_SRC ^ 0xff);
   1064  1.26.8.1      yamt 		ri->ri_flg &= ~RI_CURSOR;
   1065  1.26.8.1      yamt 	}
   1066  1.26.8.1      yamt 	ri->ri_crow = row;
   1067  1.26.8.1      yamt 	ri->ri_ccol = col;
   1068  1.26.8.1      yamt 	if (on)
   1069  1.26.8.1      yamt 	{
   1070  1.26.8.1      yamt 		x = ri->ri_ccol * wi + ri->ri_xorigin;
   1071  1.26.8.1      yamt 		y = ri->ri_crow * he + ri->ri_yorigin;
   1072  1.26.8.1      yamt 		p9100_bitblt(sc, x, y, x, y, wi, he, ROP_SRC ^ 0xff);
   1073  1.26.8.1      yamt 		ri->ri_flg |= RI_CURSOR;
   1074      1.21  macallan 	}
   1075      1.21  macallan }
   1076      1.21  macallan 
   1077      1.21  macallan #if 0
   1078  1.26.8.1      yamt static int
   1079      1.21  macallan p9100_mapchar(void *cookie, int uni, u_int *index)
   1080      1.21  macallan {
   1081      1.21  macallan 	return 0;
   1082      1.21  macallan }
   1083      1.21  macallan #endif
   1084      1.21  macallan 
   1085  1.26.8.1      yamt static void
   1086      1.21  macallan p9100_putchar(void *cookie, int row, int col, u_int c, long attr)
   1087      1.21  macallan {
   1088      1.21  macallan 	struct rasops_info *ri = cookie;
   1089  1.26.8.1      yamt 	struct vcons_screen *scr = ri->ri_hw;
   1090  1.26.8.1      yamt 	struct p9100_softc *sc = scr->scr_cookie;
   1091  1.26.8.1      yamt 
   1092  1.26.8.1      yamt 	int fg, bg, uc, i;
   1093  1.26.8.1      yamt 	uint8_t *data;
   1094  1.26.8.1      yamt 	int x, y, wi,he;
   1095      1.21  macallan 
   1096  1.26.8.1      yamt 	wi = ri->ri_font->fontwidth;
   1097  1.26.8.1      yamt 	he = ri->ri_font->fontheight;
   1098      1.21  macallan 
   1099  1.26.8.1      yamt 	if (!CHAR_IN_FONT(c, ri->ri_font))
   1100  1.26.8.1      yamt 		return;
   1101  1.26.8.1      yamt 	bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xff];
   1102  1.26.8.1      yamt 	fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xff];
   1103  1.26.8.1      yamt 	x = ri->ri_xorigin + col * wi;
   1104  1.26.8.1      yamt 	y = ri->ri_yorigin + row * he;
   1105  1.26.8.1      yamt 	if (c == 0x20) {
   1106  1.26.8.1      yamt 		p9100_rectfill(sc, x, y, wi, he, bg);
   1107  1.26.8.1      yamt 	} else {
   1108  1.26.8.1      yamt 		uc = c-ri->ri_font->firstchar;
   1109  1.26.8.1      yamt 		data = (uint8_t *)ri->ri_font->data + uc *
   1110  1.26.8.1      yamt 		    ri->ri_fontscale;
   1111  1.26.8.1      yamt 
   1112  1.26.8.1      yamt 		p9100_setup_mono(sc, x, y, wi, 1, fg, bg);
   1113  1.26.8.1      yamt 		for (i = 0; i < he; i++) {
   1114  1.26.8.1      yamt 			p9100_feed_line(sc, ri->ri_font->stride,
   1115  1.26.8.1      yamt 			    data);
   1116  1.26.8.1      yamt 			data += ri->ri_font->stride;
   1117      1.21  macallan 		}
   1118  1.26.8.1      yamt 		/*p9100_sync(sc);*/
   1119      1.21  macallan 	}
   1120      1.21  macallan }
   1121      1.21  macallan 
   1122      1.21  macallan /*
   1123      1.21  macallan  * wsdisplay_accessops
   1124      1.21  macallan  */
   1125      1.21  macallan 
   1126      1.21  macallan int
   1127      1.26  christos p9100_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct lwp *l)
   1128      1.21  macallan {
   1129  1.26.8.1      yamt 	struct vcons_data *vd = v;
   1130  1.26.8.1      yamt 	struct p9100_softc *sc = vd->cookie;
   1131      1.21  macallan 	struct wsdisplay_fbinfo *wdf;
   1132  1.26.8.1      yamt 	struct vcons_screen *ms = vd->active;
   1133      1.21  macallan 
   1134      1.21  macallan 	switch (cmd) {
   1135      1.21  macallan 		case WSDISPLAYIO_GTYPE:
   1136      1.21  macallan 			*(u_int *)data = WSDISPLAY_TYPE_SB_P9100;
   1137      1.21  macallan 			return 0;
   1138      1.21  macallan 
   1139      1.21  macallan 		case FBIOGVIDEO:
   1140      1.21  macallan 		case WSDISPLAYIO_GVIDEO:
   1141      1.21  macallan 			*(int *)data = p9100_get_video(sc);
   1142      1.21  macallan 			return 0;
   1143      1.21  macallan 
   1144      1.21  macallan 		case WSDISPLAYIO_SVIDEO:
   1145      1.21  macallan 		case FBIOSVIDEO:
   1146      1.21  macallan 			p9100_set_video(sc, *(int *)data);
   1147      1.21  macallan 			return 0;
   1148      1.21  macallan 
   1149      1.21  macallan 		case WSDISPLAYIO_GINFO:
   1150      1.21  macallan 			wdf = (void *)data;
   1151  1.26.8.1      yamt 			wdf->height = ms->scr_ri.ri_height;
   1152  1.26.8.1      yamt 			wdf->width = ms->scr_ri.ri_width;
   1153  1.26.8.1      yamt 			wdf->depth = ms->scr_ri.ri_depth;
   1154      1.21  macallan 			wdf->cmsize = 256;
   1155      1.21  macallan 			return 0;
   1156      1.21  macallan 
   1157      1.21  macallan 		case WSDISPLAYIO_GETCMAP:
   1158      1.21  macallan 			return p9100_getcmap(sc, (struct wsdisplay_cmap *)data);
   1159      1.21  macallan 
   1160      1.21  macallan 		case WSDISPLAYIO_PUTCMAP:
   1161      1.21  macallan 			return p9100_putcmap(sc, (struct wsdisplay_cmap *)data);
   1162      1.21  macallan 
   1163      1.21  macallan 		case WSDISPLAYIO_SMODE:
   1164      1.21  macallan 			{
   1165      1.21  macallan 				int new_mode = *(int*)data;
   1166      1.21  macallan 				if (new_mode != sc->sc_mode)
   1167      1.21  macallan 				{
   1168      1.21  macallan 					sc->sc_mode = new_mode;
   1169      1.21  macallan 					if (new_mode == WSDISPLAYIO_MODE_EMUL)
   1170      1.21  macallan 					{
   1171      1.21  macallan 						p9100_init_engine(sc);
   1172  1.26.8.1      yamt 						p9100loadcmap(sc, 0, 256);
   1173  1.26.8.1      yamt 						p9100_clearscreen(sc);
   1174  1.26.8.1      yamt 						vcons_redraw_screen(ms);
   1175      1.21  macallan 					}
   1176      1.21  macallan 				}
   1177      1.21  macallan 			}
   1178      1.21  macallan 	}
   1179      1.21  macallan 	return EPASSTHROUGH;
   1180      1.21  macallan }
   1181      1.21  macallan 
   1182  1.26.8.1      yamt static paddr_t
   1183      1.21  macallan p9100_mmap(void *v, off_t offset, int prot)
   1184      1.21  macallan {
   1185  1.26.8.1      yamt 	struct vcons_data *vd = v;
   1186  1.26.8.1      yamt 	struct p9100_softc *sc = vd->cookie;
   1187      1.21  macallan 	paddr_t pa;
   1188      1.21  macallan 
   1189      1.21  macallan 	/* 'regular' framebuffer mmap()ing */
   1190      1.21  macallan 	if (offset < sc->sc_fb_psize) {
   1191      1.21  macallan 		pa = bus_space_mmap(sc->sc_bustag, sc->sc_fb_paddr + offset, 0,
   1192      1.21  macallan 		    prot, BUS_SPACE_MAP_LINEAR);
   1193      1.21  macallan 		return pa;
   1194      1.21  macallan 	}
   1195      1.21  macallan 
   1196      1.21  macallan 	if ((offset >= sc->sc_fb_paddr) && (offset < (sc->sc_fb_paddr +
   1197      1.21  macallan 	    sc->sc_fb_psize))) {
   1198      1.21  macallan 		pa = bus_space_mmap(sc->sc_bustag, offset, 0, prot,
   1199      1.21  macallan 		    BUS_SPACE_MAP_LINEAR);
   1200      1.21  macallan 		return pa;
   1201      1.21  macallan 	}
   1202      1.21  macallan 
   1203      1.21  macallan 	if ((offset >= sc->sc_ctl_paddr) && (offset < (sc->sc_ctl_paddr +
   1204      1.21  macallan 	    sc->sc_ctl_psize))) {
   1205      1.21  macallan 		pa = bus_space_mmap(sc->sc_bustag, offset, 0, prot,
   1206      1.21  macallan 		    BUS_SPACE_MAP_LINEAR);
   1207      1.21  macallan 		return pa;
   1208      1.21  macallan 	}
   1209      1.21  macallan 
   1210      1.21  macallan 	return -1;
   1211      1.21  macallan }
   1212      1.21  macallan 
   1213  1.26.8.1      yamt static void
   1214  1.26.8.1      yamt p9100_init_screen(void *cookie, struct vcons_screen *scr,
   1215      1.21  macallan     int existing, long *defattr)
   1216      1.21  macallan {
   1217  1.26.8.1      yamt 	struct p9100_softc *sc = cookie;
   1218  1.26.8.1      yamt 	struct rasops_info *ri = &scr->scr_ri;
   1219      1.21  macallan 
   1220      1.21  macallan 	ri->ri_depth = sc->sc_depth << 3;
   1221      1.21  macallan 	ri->ri_width = sc->sc_width;
   1222      1.21  macallan 	ri->ri_height = sc->sc_height;
   1223      1.21  macallan 	ri->ri_stride = sc->sc_stride;
   1224  1.26.8.1      yamt 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
   1225      1.21  macallan 
   1226      1.21  macallan 	ri->ri_bits = bus_space_vaddr(sc->sc_bustag, sc->sc_fb_memh);
   1227      1.21  macallan 
   1228      1.21  macallan #ifdef DEBUG_P9100
   1229      1.21  macallan 	printf("addr: %08lx\n",(ulong)ri->ri_bits);
   1230      1.21  macallan #endif
   1231      1.21  macallan 	rasops_init(ri, sc->sc_height/8, sc->sc_width/8);
   1232      1.21  macallan 	ri->ri_caps = WSSCREEN_WSCOLORS;
   1233      1.21  macallan 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
   1234      1.21  macallan 		    sc->sc_width / ri->ri_font->fontwidth);
   1235      1.21  macallan 
   1236      1.21  macallan 	/* enable acceleration */
   1237  1.26.8.1      yamt 	ri->ri_ops.cursor    = p9100_cursor;
   1238  1.26.8.1      yamt 	ri->ri_ops.copyrows  = p9100_copyrows;
   1239      1.21  macallan 	ri->ri_ops.eraserows = p9100_eraserows;
   1240  1.26.8.1      yamt 	ri->ri_ops.copycols  = p9100_copycols;
   1241      1.21  macallan 	ri->ri_ops.erasecols = p9100_erasecols;
   1242  1.26.8.1      yamt 	ri->ri_ops.putchar   = p9100_putchar;
   1243      1.21  macallan 	ri->ri_ops.allocattr = p9100_allocattr;
   1244      1.21  macallan }
   1245      1.21  macallan 
   1246  1.26.8.1      yamt static int
   1247      1.21  macallan p9100_putcmap(struct p9100_softc *sc, struct wsdisplay_cmap *cm)
   1248      1.21  macallan {
   1249      1.21  macallan 	u_int index = cm->index;
   1250      1.21  macallan 	u_int count = cm->count;
   1251      1.21  macallan 	int i, error;
   1252      1.21  macallan 	u_char rbuf[256], gbuf[256], bbuf[256];
   1253      1.21  macallan 	u_char *r, *g, *b;
   1254      1.21  macallan 
   1255      1.21  macallan 	if (cm->index >= 256 || cm->count > 256 ||
   1256      1.21  macallan 	    (cm->index + cm->count) > 256)
   1257      1.21  macallan 		return EINVAL;
   1258      1.21  macallan 	error = copyin(cm->red, &rbuf[index], count);
   1259      1.21  macallan 	if (error)
   1260      1.21  macallan 		return error;
   1261      1.21  macallan 	error = copyin(cm->green, &gbuf[index], count);
   1262      1.21  macallan 	if (error)
   1263      1.21  macallan 		return error;
   1264      1.21  macallan 	error = copyin(cm->blue, &bbuf[index], count);
   1265      1.21  macallan 	if (error)
   1266      1.21  macallan 		return error;
   1267      1.21  macallan 
   1268      1.21  macallan 	r = &rbuf[index];
   1269      1.21  macallan 	g = &gbuf[index];
   1270      1.21  macallan 	b = &bbuf[index];
   1271      1.21  macallan 
   1272      1.21  macallan 	for (i = 0; i < count; i++) {
   1273      1.21  macallan 		sc->sc_cmap.cm_map[index][0] = *r;
   1274      1.21  macallan 		sc->sc_cmap.cm_map[index][1] = *g;
   1275      1.21  macallan 		sc->sc_cmap.cm_map[index][2] = *b;
   1276      1.21  macallan 		index++;
   1277      1.21  macallan 		r++, g++, b++;
   1278      1.21  macallan 	}
   1279      1.21  macallan 	p9100loadcmap(sc, 0, 256);
   1280      1.21  macallan 	return 0;
   1281      1.21  macallan }
   1282      1.21  macallan 
   1283  1.26.8.1      yamt static int
   1284      1.21  macallan p9100_getcmap(struct p9100_softc *sc, struct wsdisplay_cmap *cm)
   1285      1.21  macallan {
   1286      1.21  macallan 	u_int index = cm->index;
   1287      1.21  macallan 	u_int count = cm->count;
   1288      1.21  macallan 	int error, i;
   1289  1.26.8.1      yamt 	uint8_t red[256], green[256], blue[256];
   1290      1.21  macallan 
   1291      1.21  macallan 	if (index >= 255 || count > 256 || index + count > 256)
   1292      1.21  macallan 		return EINVAL;
   1293      1.21  macallan 
   1294      1.21  macallan 	i = index;
   1295      1.21  macallan 	while (i < (index + count)) {
   1296      1.21  macallan 		red[i] = sc->sc_cmap.cm_map[i][0];
   1297      1.21  macallan 		green[i] = sc->sc_cmap.cm_map[i][1];
   1298      1.21  macallan 		blue[i] = sc->sc_cmap.cm_map[i][2];
   1299      1.21  macallan 		i++;
   1300      1.21  macallan 	}
   1301      1.21  macallan 	error = copyout(&red[index],   cm->red,   count);
   1302      1.21  macallan 	if (error)
   1303      1.21  macallan 		return error;
   1304      1.21  macallan 	error = copyout(&green[index], cm->green, count);
   1305      1.21  macallan 	if (error)
   1306      1.21  macallan 		return error;
   1307      1.21  macallan 	error = copyout(&blue[index],  cm->blue,  count);
   1308      1.21  macallan 	if (error)
   1309      1.21  macallan 		return error;
   1310      1.21  macallan 
   1311      1.21  macallan 	return 0;
   1312      1.21  macallan }
   1313      1.21  macallan 
   1314  1.26.8.1      yamt static void
   1315  1.26.8.1      yamt p9100_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
   1316  1.26.8.1      yamt {
   1317  1.26.8.1      yamt 	struct rasops_info *ri = cookie;
   1318  1.26.8.1      yamt 	struct vcons_screen *scr = ri->ri_hw;
   1319  1.26.8.1      yamt 	int32_t xs, xd, y, width, height;
   1320  1.26.8.1      yamt 
   1321  1.26.8.1      yamt 	xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
   1322  1.26.8.1      yamt 	xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
   1323  1.26.8.1      yamt 	y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1324  1.26.8.1      yamt 	width = ri->ri_font->fontwidth * ncols;
   1325  1.26.8.1      yamt 	height = ri->ri_font->fontheight;
   1326  1.26.8.1      yamt 	p9100_bitblt(scr->scr_cookie, xs, y, xd, y, width, height, ROP_SRC);
   1327  1.26.8.1      yamt }
   1328  1.26.8.1      yamt 
   1329  1.26.8.1      yamt static void
   1330  1.26.8.1      yamt p9100_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
   1331  1.26.8.1      yamt {
   1332  1.26.8.1      yamt 	struct rasops_info *ri = cookie;
   1333  1.26.8.1      yamt 	struct vcons_screen *scr = ri->ri_hw;
   1334  1.26.8.1      yamt 	int32_t x, y, width, height, bg;
   1335  1.26.8.1      yamt 
   1336  1.26.8.1      yamt 	x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
   1337  1.26.8.1      yamt 	y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1338  1.26.8.1      yamt 	width = ri->ri_font->fontwidth * ncols;
   1339  1.26.8.1      yamt 	height = ri->ri_font->fontheight;
   1340  1.26.8.1      yamt 	bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
   1341  1.26.8.1      yamt 	p9100_rectfill(scr->scr_cookie, x, y, width, height, bg);
   1342  1.26.8.1      yamt }
   1343  1.26.8.1      yamt 
   1344  1.26.8.1      yamt static void
   1345  1.26.8.1      yamt p9100_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
   1346  1.26.8.1      yamt {
   1347  1.26.8.1      yamt 	struct rasops_info *ri = cookie;
   1348  1.26.8.1      yamt 	struct vcons_screen *scr = ri->ri_hw;
   1349  1.26.8.1      yamt 	int32_t x, ys, yd, width, height;
   1350  1.26.8.1      yamt 
   1351  1.26.8.1      yamt 	x = ri->ri_xorigin;
   1352  1.26.8.1      yamt 	ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
   1353  1.26.8.1      yamt 	yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
   1354  1.26.8.1      yamt 	width = ri->ri_emuwidth;
   1355  1.26.8.1      yamt 	height = ri->ri_font->fontheight * nrows;
   1356  1.26.8.1      yamt 	p9100_bitblt(scr->scr_cookie, x, ys, x, yd, width, height, ROP_SRC);
   1357  1.26.8.1      yamt }
   1358  1.26.8.1      yamt 
   1359  1.26.8.1      yamt static void
   1360  1.26.8.1      yamt p9100_eraserows(void *cookie, int row, int nrows, long fillattr)
   1361  1.26.8.1      yamt {
   1362  1.26.8.1      yamt 	struct rasops_info *ri = cookie;
   1363  1.26.8.1      yamt 	struct vcons_screen *scr = ri->ri_hw;
   1364  1.26.8.1      yamt 	int32_t x, y, width, height, bg;
   1365  1.26.8.1      yamt 
   1366  1.26.8.1      yamt 	if ((row == 0) && (nrows == ri->ri_rows)) {
   1367  1.26.8.1      yamt 		x = y = 0;
   1368  1.26.8.1      yamt 		width = ri->ri_width;
   1369  1.26.8.1      yamt 		height = ri->ri_height;
   1370  1.26.8.1      yamt 	} else {
   1371  1.26.8.1      yamt 		x = ri->ri_xorigin;
   1372  1.26.8.1      yamt 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1373  1.26.8.1      yamt 		width = ri->ri_emuwidth;
   1374  1.26.8.1      yamt 		height = ri->ri_font->fontheight * nrows;
   1375  1.26.8.1      yamt 	}
   1376  1.26.8.1      yamt 	bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
   1377  1.26.8.1      yamt 	p9100_rectfill(scr->scr_cookie, x, y, width, height, bg);
   1378  1.26.8.1      yamt }
   1379  1.26.8.1      yamt 
   1380  1.26.8.1      yamt 
   1381  1.26.8.1      yamt static int
   1382  1.26.8.1      yamt p9100_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
   1383  1.26.8.1      yamt {
   1384  1.26.8.1      yamt 	if ((fg == 0) && (bg == 0))
   1385  1.26.8.1      yamt 	{
   1386  1.26.8.1      yamt 		fg = WS_DEFAULT_FG;
   1387  1.26.8.1      yamt 		bg = WS_DEFAULT_BG;
   1388  1.26.8.1      yamt 	}
   1389  1.26.8.1      yamt 	if (flags & WSATTR_REVERSE) {
   1390  1.26.8.1      yamt 		*attrp = (bg & 0xff) << 24 | (fg & 0xff) << 16 |
   1391  1.26.8.1      yamt 		    (flags & 0xff) << 8;
   1392  1.26.8.1      yamt 	} else
   1393  1.26.8.1      yamt 		*attrp = (fg & 0xff) << 24 | (bg & 0xff) << 16 |
   1394  1.26.8.1      yamt 		    (flags & 0xff) << 8;
   1395  1.26.8.1      yamt 	return 0;
   1396  1.26.8.1      yamt }
   1397  1.26.8.1      yamt 
   1398      1.21  macallan #if 0
   1399  1.26.8.1      yamt static int
   1400      1.21  macallan p9100_load_font(void *v, void *cookie, struct wsdisplay_font *data)
   1401      1.21  macallan {
   1402      1.21  macallan 
   1403      1.21  macallan 	return 0;
   1404      1.21  macallan }
   1405      1.21  macallan #endif
   1406      1.21  macallan 
   1407  1.26.8.1      yamt #endif /* NWSDISPLAY > 0 */
   1408  1.26.8.1      yamt 
   1409  1.26.8.1      yamt static int
   1410      1.21  macallan p9100_intr(void *arg)
   1411      1.21  macallan {
   1412      1.21  macallan 	/*p9100_softc *sc=arg;
   1413      1.21  macallan 	printf(".");*/
   1414      1.21  macallan 	return 1;
   1415      1.21  macallan }
   1416      1.24  macallan 
   1417  1.26.8.1      yamt static void
   1418      1.24  macallan p9100_init_cursor(struct p9100_softc *sc)
   1419      1.24  macallan {
   1420      1.24  macallan 
   1421      1.24  macallan 	memset(&sc->sc_cursor, 0, sizeof(struct pnozz_cursor));
   1422      1.24  macallan 	sc->sc_cursor.pc_size.x = 64;
   1423      1.24  macallan 	sc->sc_cursor.pc_size.y = 64;
   1424      1.24  macallan 
   1425      1.24  macallan }
   1426      1.24  macallan 
   1427  1.26.8.1      yamt static void
   1428      1.24  macallan p9100_set_fbcursor(struct p9100_softc *sc)
   1429      1.24  macallan {
   1430      1.24  macallan #ifdef PNOZZ_PARANOID
   1431      1.24  macallan 	int s;
   1432      1.24  macallan 
   1433      1.24  macallan 	s = splhigh();	/* just in case... */
   1434      1.24  macallan #endif
   1435  1.26.8.1      yamt 	sc->sc_last_offset = 0xffffffff;
   1436  1.26.8.1      yamt 
   1437      1.24  macallan 	/* set position and hotspot */
   1438      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_CTL, DAC_INDX_AUTOINCR);
   1439      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_HI, 0);
   1440      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_LO, DAC_CURSOR_CTL);
   1441      1.24  macallan 	if (sc->sc_cursor.pc_enable) {
   1442      1.24  macallan 		p9100_ramdac_write(sc, DAC_INDX_DATA, DAC_CURSOR_X11 |
   1443      1.24  macallan 		    DAC_CURSOR_64);
   1444      1.24  macallan 	} else
   1445      1.24  macallan 		p9100_ramdac_write(sc, DAC_INDX_DATA, DAC_CURSOR_OFF);
   1446      1.24  macallan 	/* next two registers - x low, high, y low, high */
   1447      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_pos.x & 0xff);
   1448      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_DATA, (sc->sc_cursor.pc_pos.x >> 8) &
   1449      1.24  macallan 	    0xff);
   1450      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_pos.y & 0xff);
   1451      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_DATA, (sc->sc_cursor.pc_pos.y >> 8) &
   1452      1.24  macallan 	    0xff);
   1453      1.24  macallan 	/* hotspot */
   1454      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_hot.x & 0xff);
   1455      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_hot.y & 0xff);
   1456      1.24  macallan 
   1457      1.24  macallan #ifdef PNOZZ_PARANOID
   1458      1.24  macallan 	splx(s);
   1459      1.24  macallan #endif
   1460      1.24  macallan 
   1461      1.24  macallan }
   1462      1.24  macallan 
   1463  1.26.8.1      yamt static void
   1464      1.24  macallan p9100_setcursorcmap(struct p9100_softc *sc)
   1465      1.24  macallan {
   1466      1.24  macallan 	int i;
   1467      1.24  macallan 
   1468      1.24  macallan #ifdef PNOZZ_PARANOID
   1469      1.24  macallan 	int s;
   1470      1.24  macallan 	s = splhigh();	/* just in case... */
   1471      1.24  macallan #endif
   1472  1.26.8.1      yamt 	sc->sc_last_offset = 0xffffffff;
   1473      1.24  macallan 
   1474      1.24  macallan 	/* set cursor colours */
   1475      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_CTL, DAC_INDX_AUTOINCR);
   1476      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_HI, 0);
   1477      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_LO, DAC_CURSOR_COL_1);
   1478      1.24  macallan 
   1479      1.24  macallan 	for (i = 0; i < 3; i++) {
   1480      1.24  macallan 		p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.red[i]);
   1481      1.24  macallan 		p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.green[i]);
   1482      1.24  macallan 		p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.blue[i]);
   1483      1.24  macallan 	}
   1484      1.24  macallan 
   1485      1.24  macallan #ifdef PNOZZ_PARANOID
   1486      1.24  macallan 	splx(s);
   1487      1.24  macallan #endif
   1488      1.24  macallan }
   1489      1.24  macallan 
   1490  1.26.8.1      yamt static void
   1491      1.24  macallan p9100_loadcursor(struct p9100_softc *sc)
   1492      1.24  macallan {
   1493      1.24  macallan 	uint32_t *image, *mask;
   1494      1.24  macallan 	uint32_t bit, bbit, im, ma;
   1495      1.24  macallan 	int i, j, k;
   1496      1.24  macallan 	uint8_t latch1, latch2;
   1497      1.24  macallan 
   1498      1.24  macallan #ifdef PNOZZ_PARANOID
   1499      1.24  macallan 	int s;
   1500      1.24  macallan 	s = splhigh();	/* just in case... */
   1501      1.24  macallan #endif
   1502  1.26.8.1      yamt 	sc->sc_last_offset = 0xffffffff;
   1503  1.26.8.1      yamt 
   1504      1.24  macallan 	/* set cursor shape */
   1505      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_CTL, DAC_INDX_AUTOINCR);
   1506      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_HI, 1);
   1507      1.24  macallan 	p9100_ramdac_write(sc, DAC_INDX_LO, 0);
   1508      1.24  macallan 
   1509      1.24  macallan 	image = sc->sc_cursor.pc_bits;
   1510      1.24  macallan 	mask = &sc->sc_cursor.pc_bits[0x80];
   1511      1.24  macallan 
   1512      1.24  macallan 	for (i = 0; i < 0x80; i++) {
   1513      1.24  macallan 		bit = 0x80000000;
   1514      1.24  macallan 		im = image[i];
   1515      1.24  macallan 		ma = mask[i];
   1516      1.24  macallan 		for (k = 0; k < 4; k++) {
   1517      1.24  macallan 			bbit = 0x1;
   1518      1.24  macallan 			latch1 = 0;
   1519      1.24  macallan 			for (j = 0; j < 4; j++) {
   1520      1.24  macallan 				if (im & bit)
   1521      1.24  macallan 					latch1 |= bbit;
   1522      1.24  macallan 				bbit <<= 1;
   1523      1.24  macallan 				if (ma & bit)
   1524      1.24  macallan 					latch1 |= bbit;
   1525      1.24  macallan 				bbit <<= 1;
   1526      1.24  macallan 				bit >>= 1;
   1527      1.24  macallan 			}
   1528      1.24  macallan 			bbit = 0x1;
   1529      1.24  macallan 			latch2 = 0;
   1530      1.24  macallan 			for (j = 0; j < 4; j++) {
   1531      1.24  macallan 				if (im & bit)
   1532      1.24  macallan 					latch2 |= bbit;
   1533      1.24  macallan 				bbit <<= 1;
   1534      1.24  macallan 				if (ma & bit)
   1535      1.24  macallan 					latch2 |= bbit;
   1536      1.24  macallan 				bbit <<= 1;
   1537      1.24  macallan 				bit >>= 1;
   1538      1.24  macallan 			}
   1539      1.24  macallan 			p9100_ramdac_write(sc, DAC_INDX_DATA, latch1);
   1540      1.24  macallan 			p9100_ramdac_write(sc, DAC_INDX_DATA, latch2);
   1541      1.24  macallan 		}
   1542      1.24  macallan 	}
   1543      1.24  macallan #ifdef DEBUG_CURSOR
   1544      1.24  macallan 	printf("image:\n");
   1545      1.24  macallan 	for (i=0;i<0x80;i+=2)
   1546      1.24  macallan 		printf("%08x %08x\n", image[i], image[i+1]);
   1547      1.24  macallan 	printf("mask:\n");
   1548      1.24  macallan 	for (i=0;i<0x80;i+=2)
   1549      1.24  macallan 		printf("%08x %08x\n", mask[i], mask[i+1]);
   1550      1.24  macallan #endif
   1551      1.24  macallan #ifdef PNOZZ_PARANOID
   1552      1.24  macallan 	splx(s);
   1553      1.24  macallan #endif
   1554      1.24  macallan }
   1555  1.26.8.1      yamt 
   1556  1.26.8.1      yamt static void
   1557  1.26.8.1      yamt p9100_set_extvga(void *cookie, int status)
   1558  1.26.8.1      yamt {
   1559  1.26.8.1      yamt 	struct p9100_softc *sc = cookie;
   1560  1.26.8.1      yamt #ifdef PNOZZ_PARANOID
   1561  1.26.8.1      yamt 	int s;
   1562  1.26.8.1      yamt 
   1563  1.26.8.1      yamt 	s = splhigh();
   1564  1.26.8.1      yamt #endif
   1565  1.26.8.1      yamt #ifdef DEBUG
   1566  1.26.8.1      yamt 	printf("%s: external VGA %s\n", sc->sc_dev.dv_xname,
   1567  1.26.8.1      yamt 	    status ? "on" : "off");
   1568  1.26.8.1      yamt #endif
   1569  1.26.8.1      yamt 	sc->sc_last_offset = 0xffffffff;
   1570  1.26.8.1      yamt 
   1571  1.26.8.1      yamt 	if (status) {
   1572  1.26.8.1      yamt 		p9100_ramdac_write_ctl(sc, DAC_POWER,
   1573  1.26.8.1      yamt 		    p9100_ramdac_read_ctl(sc, DAC_POWER) &
   1574  1.26.8.1      yamt 		    ~DAC_POWER_IPWR_DISABLE);
   1575  1.26.8.1      yamt 	} else {
   1576  1.26.8.1      yamt 		p9100_ramdac_write_ctl(sc, DAC_POWER,
   1577  1.26.8.1      yamt 		    p9100_ramdac_read_ctl(sc, DAC_POWER) |
   1578  1.26.8.1      yamt 		    DAC_POWER_IPWR_DISABLE);
   1579  1.26.8.1      yamt 	}
   1580  1.26.8.1      yamt #ifdef PNOZZ_PARANOID
   1581  1.26.8.1      yamt 	splx(s);
   1582  1.26.8.1      yamt #endif
   1583  1.26.8.1      yamt }
   1584