Home | History | Annotate | Line # | Download | only in sbus
p9100.c revision 1.23
      1  1.23   tsutsui /*	$NetBSD: p9100.c,v 1.23 2005/06/04 04:36:04 tsutsui Exp $ */
      2   1.1        pk 
      3   1.1        pk /*-
      4   1.1        pk  * Copyright (c) 1998 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.23   tsutsui __KERNEL_RCSID(0, "$NetBSD: p9100.c,v 1.23 2005/06/04 04:36:04 tsutsui 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.21  macallan #include "opt_wsemul.h"
     78  1.22  macallan #include "rasops_glue.h"
     79  1.21  macallan 
     80   1.1        pk #include "tctrl.h"
     81   1.1        pk #if NTCTRL > 0
     82   1.1        pk #include <machine/tctrl.h>
     83   1.1        pk #include <sparc/dev/tctrlvar.h>/*XXX*/
     84   1.1        pk #endif
     85   1.1        pk 
     86   1.1        pk /* per-display variables */
     87   1.1        pk struct p9100_softc {
     88   1.1        pk 	struct device	sc_dev;		/* base device */
     89   1.1        pk 	struct sbusdev	sc_sd;		/* sbus device */
     90   1.1        pk 	struct fbdevice	sc_fb;		/* frame buffer device */
     91   1.1        pk 	bus_space_tag_t	sc_bustag;
     92   1.8        pk 
     93   1.8        pk 	bus_addr_t	sc_ctl_paddr;	/* phys address description */
     94   1.1        pk 	bus_size_t	sc_ctl_psize;	/*   for device mmap() */
     95   1.1        pk 	bus_space_handle_t sc_ctl_memh;	/*   bus space handle */
     96   1.8        pk 
     97   1.8        pk 	bus_addr_t	sc_cmd_paddr;	/* phys address description */
     98   1.1        pk 	bus_size_t	sc_cmd_psize;	/*   for device mmap() */
     99   1.1        pk 	bus_space_handle_t sc_cmd_memh;	/*   bus space handle */
    100   1.8        pk 
    101   1.8        pk 	bus_addr_t	sc_fb_paddr;	/* phys address description */
    102   1.1        pk 	bus_size_t	sc_fb_psize;	/*   for device mmap() */
    103   1.1        pk 	bus_space_handle_t sc_fb_memh;	/*   bus space handle */
    104   1.8        pk 
    105   1.1        pk 	uint32_t sc_junk;
    106  1.21  macallan 	uint32_t sc_mono_width;	/* for setup_mono */
    107  1.21  macallan 
    108  1.21  macallan 	uint32_t sc_width;
    109  1.21  macallan 	uint32_t sc_height;	/* panel width / height */
    110  1.21  macallan 	uint32_t sc_stride;
    111  1.21  macallan 	uint32_t sc_depth;
    112  1.21  macallan 	union	bt_cmap sc_cmap;	/* Brooktree color map */
    113  1.21  macallan 
    114  1.21  macallan #ifdef PNOZZ_SOFT_PUTCHAR
    115  1.21  macallan 	void (*putchar)(void *c, int row, int col, u_int uc, long attr);
    116  1.21  macallan #endif
    117  1.21  macallan 	int sc_mode;
    118  1.21  macallan 	uint32_t sc_bg;
    119  1.21  macallan 	void (*switchcb)(void *, int, int);
    120  1.21  macallan 	void *switchcbarg;
    121  1.21  macallan 	struct callout switch_callout;
    122  1.21  macallan 	LIST_HEAD(, p9100_screen) screens;
    123  1.21  macallan 	struct p9100_screen *active, *wanted;
    124  1.21  macallan 	const struct wsscreen_descr *currenttype;
    125  1.21  macallan 
    126  1.21  macallan };
    127  1.21  macallan 
    128  1.21  macallan struct p9100_screen {
    129  1.21  macallan 	struct rasops_info ri;
    130  1.21  macallan 	LIST_ENTRY(p9100_screen) next;
    131  1.21  macallan 	struct p9100_softc *sc;
    132  1.21  macallan 	const struct wsscreen_descr *type;
    133  1.21  macallan 	int active;
    134  1.21  macallan 	u_int16_t *chars;
    135  1.21  macallan 	long *attrs;
    136  1.21  macallan 	int dispoffset;
    137  1.21  macallan 	int mindispoffset;
    138  1.21  macallan 	int maxdispoffset;
    139  1.21  macallan 
    140  1.21  macallan 	int cursoron;
    141  1.21  macallan 	int cursorcol;
    142  1.21  macallan 	int cursorrow;
    143  1.21  macallan 	int cursordrawn;
    144  1.21  macallan };
    145  1.21  macallan 
    146  1.21  macallan static struct p9100_screen p9100_console_screen;
    147  1.21  macallan 
    148  1.21  macallan extern const u_char rasops_cmap[768];
    149  1.21  macallan 
    150  1.21  macallan struct wsscreen_descr p9100_defscreendesc = {
    151  1.21  macallan 	"default",
    152  1.21  macallan 	0, 0,
    153  1.21  macallan 	NULL,
    154  1.21  macallan 	8, 16,
    155  1.21  macallan 	WSSCREEN_WSCOLORS,
    156  1.21  macallan };
    157   1.1        pk 
    158  1.21  macallan const struct wsscreen_descr *_p9100_scrlist[] = {
    159  1.21  macallan 	&p9100_defscreendesc,
    160  1.21  macallan 	/* XXX other formats, graphics screen? */
    161   1.1        pk };
    162   1.1        pk 
    163  1.21  macallan struct wsscreen_list p9100_screenlist = {
    164  1.21  macallan 	sizeof(_p9100_scrlist) / sizeof(struct wsscreen_descr *), _p9100_scrlist
    165  1.21  macallan };
    166   1.1        pk 
    167   1.1        pk /* autoconfiguration driver */
    168   1.1        pk static int	p9100_sbus_match(struct device *, struct cfdata *, void *);
    169   1.1        pk static void	p9100_sbus_attach(struct device *, struct device *, void *);
    170   1.1        pk 
    171   1.1        pk static void	p9100unblank(struct device *);
    172   1.1        pk static void	p9100_shutdown(void *);
    173   1.1        pk 
    174  1.12   thorpej CFATTACH_DECL(pnozz, sizeof(struct p9100_softc),
    175  1.13   thorpej     p9100_sbus_match, p9100_sbus_attach, NULL, NULL);
    176   1.1        pk 
    177   1.1        pk extern struct cfdriver pnozz_cd;
    178   1.1        pk 
    179  1.10   gehenna dev_type_open(p9100open);
    180  1.10   gehenna dev_type_ioctl(p9100ioctl);
    181  1.10   gehenna dev_type_mmap(p9100mmap);
    182  1.10   gehenna 
    183  1.10   gehenna const struct cdevsw pnozz_cdevsw = {
    184  1.10   gehenna 	p9100open, nullclose, noread, nowrite, p9100ioctl,
    185  1.14  jdolecek 	nostop, notty, nopoll, p9100mmap, nokqfilter,
    186  1.10   gehenna };
    187  1.10   gehenna 
    188   1.1        pk /* frame buffer generic driver */
    189   1.1        pk static struct fbdriver p9100fbdriver = {
    190  1.10   gehenna 	p9100unblank, p9100open, nullclose, p9100ioctl, nopoll,
    191  1.14  jdolecek 	p9100mmap, nokqfilter
    192   1.1        pk };
    193   1.1        pk 
    194  1.21  macallan static void	p9100loadcmap(struct p9100_softc *, int, int);
    195  1.21  macallan static void	p9100_set_video(struct p9100_softc *, int);
    196  1.21  macallan static int	p9100_get_video(struct p9100_softc *);
    197   1.1        pk static uint32_t p9100_ctl_read_4(struct p9100_softc *, bus_size_t);
    198  1.21  macallan static void	p9100_ctl_write_4(struct p9100_softc *, bus_size_t, uint32_t);
    199  1.21  macallan uint8_t		p9100_ramdac_read(struct p9100_softc *, bus_size_t);
    200  1.21  macallan void		p9100_ramdac_write(struct p9100_softc *, bus_size_t, uint8_t);
    201  1.21  macallan 
    202  1.21  macallan static void	p9100_sync(struct p9100_softc *);
    203  1.21  macallan void 		p9100_bitblt(struct p9100_softc *, int, int, int, int, int, int, 		    uint32_t);	/* coordinates, rasop */
    204  1.21  macallan void 		p9100_rectfill(struct p9100_softc *, int, int, int, int,
    205  1.21  macallan 		    uint32_t);	/* coordinates, colour */
    206  1.21  macallan static void 	p9100_init_engine(struct p9100_softc *);
    207  1.21  macallan void		p9100_setup_mono(struct p9100_softc *, int, int, int, int,
    208  1.21  macallan 		    uint32_t, uint32_t);
    209  1.21  macallan void		p9100_feed_line(struct p9100_softc *, int, uint8_t *);
    210  1.21  macallan static void	p9100_set_color_reg(struct p9100_softc *, int, int32_t);
    211  1.21  macallan 
    212  1.21  macallan void	p9100_cursor(void *, int, int, int);
    213  1.21  macallan int	p9100_mapchar(void *, int, u_int *);
    214  1.21  macallan void	p9100_putchar(void *, int, int, u_int, long);
    215  1.21  macallan void	p9100_copycols(void *, int, int, int, int);
    216  1.21  macallan void	p9100_erasecols(void *, int, int, int, long);
    217  1.21  macallan void	p9100_copyrows(void *, int, int, int);
    218  1.21  macallan void	p9100_eraserows(void *, int, int, long);
    219  1.21  macallan int	p9100_allocattr(void *, int, int, int, long *);
    220  1.21  macallan 
    221  1.21  macallan void	p9100_scroll(void *, void *, int);
    222  1.21  macallan 
    223  1.21  macallan int	p9100_putcmap(struct p9100_softc *, struct wsdisplay_cmap *);
    224  1.21  macallan int 	p9100_getcmap(struct p9100_softc *, struct wsdisplay_cmap *);
    225  1.21  macallan int	p9100_ioctl(void *, u_long, caddr_t, int, struct proc *);
    226  1.21  macallan paddr_t	p9100_mmap(void *, off_t, int);
    227  1.21  macallan int	p9100_alloc_screen(void *, const struct wsscreen_descr *, void **,
    228  1.21  macallan 	    int *, int *, long *);
    229  1.21  macallan void	p9100_free_screen(void *, void *);
    230  1.21  macallan int	p9100_show_screen(void *, void *, int, void (*)(void *, int, int),
    231  1.21  macallan 	    void *);
    232  1.21  macallan void	p9100_switch_screen(struct p9100_softc *);
    233  1.21  macallan void	p9100_restore_screen(struct p9100_screen *,
    234  1.21  macallan 	    const struct wsscreen_descr *, u_int16_t *);
    235  1.21  macallan void	p9100_clearscreen(struct p9100_softc *);
    236  1.21  macallan 
    237  1.21  macallan int	p9100_load_font(void *, void *, struct wsdisplay_font *);
    238  1.21  macallan 
    239  1.21  macallan void	p9100_init_screen(struct p9100_softc *, struct p9100_screen *, int,
    240  1.21  macallan 	    long *);
    241  1.21  macallan 
    242  1.21  macallan int	p9100_intr(void *);
    243  1.21  macallan 
    244  1.21  macallan struct wsdisplay_accessops p9100_accessops = {
    245  1.21  macallan 	p9100_ioctl,
    246  1.21  macallan 	p9100_mmap,
    247  1.21  macallan 	p9100_alloc_screen,
    248  1.21  macallan 	p9100_free_screen,
    249  1.21  macallan 	p9100_show_screen,
    250  1.21  macallan 	NULL,	/* load_font */
    251  1.21  macallan 	NULL,	/* polls */
    252  1.21  macallan 	NULL,	/* getwschar */
    253  1.21  macallan 	NULL,	/* putwschar */
    254  1.21  macallan 	NULL,	/* scroll */
    255  1.21  macallan 	NULL,	/* getborder */
    256  1.21  macallan 	NULL	/* setborder */
    257  1.21  macallan };
    258   1.1        pk 
    259   1.1        pk /*
    260   1.1        pk  * Match a p9100.
    261   1.1        pk  */
    262   1.1        pk static int
    263   1.1        pk p9100_sbus_match(struct device *parent, struct cfdata *cf, void *aux)
    264   1.1        pk {
    265   1.1        pk 	struct sbus_attach_args *sa = aux;
    266   1.1        pk 
    267   1.1        pk 	return (strcmp("p9100", sa->sa_name) == 0);
    268   1.1        pk }
    269   1.1        pk 
    270   1.1        pk 
    271   1.1        pk /*
    272   1.1        pk  * Attach a display.  We need to notice if it is the console, too.
    273   1.1        pk  */
    274   1.1        pk static void
    275   1.1        pk p9100_sbus_attach(struct device *parent, struct device *self, void *args)
    276   1.1        pk {
    277   1.1        pk 	struct p9100_softc *sc = (struct p9100_softc *)self;
    278   1.1        pk 	struct sbus_attach_args *sa = args;
    279   1.1        pk 	struct fbdevice *fb = &sc->sc_fb;
    280   1.1        pk 	int isconsole;
    281   1.1        pk 	int node;
    282  1.21  macallan 	int i, j;
    283  1.21  macallan 
    284  1.21  macallan #if NWSDISPLAY > 0
    285  1.21  macallan 	struct wsemuldisplaydev_attach_args aa;
    286  1.21  macallan 	struct rasops_info *ri;
    287  1.21  macallan 	unsigned long defattr;
    288  1.21  macallan #endif
    289   1.1        pk 
    290   1.1        pk 	/* Remember cookies for p9100_mmap() */
    291   1.1        pk 	sc->sc_bustag = sa->sa_bustag;
    292  1.20     perry 	sc->sc_ctl_paddr = sbus_bus_addr(sa->sa_bustag,
    293   1.9   thorpej 		sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base);
    294  1.21  macallan 	sc->sc_ctl_psize = 0x8000;/*(bus_size_t)sa->sa_reg[0].oa_size;*/
    295   1.3       eeh 
    296  1.20     perry 	sc->sc_cmd_paddr = sbus_bus_addr(sa->sa_bustag,
    297   1.9   thorpej 		sa->sa_reg[1].oa_space, sa->sa_reg[1].oa_base);
    298   1.9   thorpej 	sc->sc_cmd_psize = (bus_size_t)sa->sa_reg[1].oa_size;
    299   1.3       eeh 
    300  1.20     perry 	sc->sc_fb_paddr = sbus_bus_addr(sa->sa_bustag,
    301   1.9   thorpej 		sa->sa_reg[2].oa_space, sa->sa_reg[2].oa_base);
    302   1.9   thorpej 	sc->sc_fb_psize = (bus_size_t)sa->sa_reg[2].oa_size;
    303   1.1        pk 
    304   1.1        pk 	fb->fb_driver = &p9100fbdriver;
    305   1.1        pk 	fb->fb_device = &sc->sc_dev;
    306   1.1        pk 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
    307  1.21  macallan #ifdef PNOZZ_EMUL_CG3
    308   1.1        pk 	fb->fb_type.fb_type = FBTYPE_SUN3COLOR;
    309  1.21  macallan #else
    310  1.21  macallan 	fb->fb_type.fb_type = FBTYPE_P9100;
    311  1.21  macallan #endif
    312   1.7     cyber 	fb->fb_pixels = NULL;
    313  1.21  macallan 
    314  1.21  macallan 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    315  1.21  macallan #ifdef PNOZZ_SOFT_PUTCHAR
    316  1.21  macallan 	sc->putchar = NULL;
    317  1.21  macallan #endif
    318  1.21  macallan 
    319  1.21  macallan 	LIST_INIT(&sc->screens);
    320  1.21  macallan 	sc->active = NULL;
    321  1.21  macallan 	sc->currenttype = &p9100_defscreendesc;
    322  1.21  macallan 	callout_init(&sc->switch_callout);
    323   1.1        pk 
    324   1.1        pk 	node = sa->sa_node;
    325   1.7     cyber 	isconsole = fb_is_console(node);
    326   1.7     cyber 	if (!isconsole) {
    327  1.21  macallan 		printf("\n%s: fatal error: PROM didn't configure device\n",
    328  1.21  macallan 		    self->dv_xname);
    329   1.7     cyber 		return;
    330   1.7     cyber 	}
    331   1.1        pk 
    332   1.1        pk 	/*
    333   1.1        pk 	 * When the ROM has mapped in a p9100 display, the address
    334   1.1        pk 	 * maps only the video RAM, so in any case we have to map the
    335   1.1        pk 	 * registers ourselves.  We only need the video RAM if we are
    336   1.1        pk 	 * going to print characters via rconsole.
    337   1.1        pk 	 */
    338   1.8        pk 	if (sbus_bus_map(sc->sc_bustag,
    339   1.9   thorpej 			 sa->sa_reg[0].oa_space,
    340   1.9   thorpej 			 sa->sa_reg[0].oa_base,
    341  1.21  macallan 			 /*
    342  1.21  macallan 			  * XXX for some reason the SBus resources don't cover
    343  1.21  macallan 			  * all registers, so we just map what we need
    344  1.21  macallan 			  */
    345  1.21  macallan 			 /*sc->sc_ctl_psize*/ 0x8000,
    346   1.8        pk 			 BUS_SPACE_MAP_LINEAR, &sc->sc_ctl_memh) != 0) {
    347   1.1        pk 		printf("%s: cannot map control registers\n", self->dv_xname);
    348   1.1        pk 		return;
    349   1.1        pk 	}
    350   1.1        pk 
    351   1.1        pk 	if (sa->sa_npromvaddrs != 0)
    352   1.1        pk 		fb->fb_pixels = (caddr_t)sa->sa_promvaddrs[0];
    353   1.7     cyber 
    354   1.7     cyber 	if (fb->fb_pixels == NULL) {
    355   1.8        pk 		if (sbus_bus_map(sc->sc_bustag,
    356   1.9   thorpej 				sa->sa_reg[2].oa_space,
    357   1.9   thorpej 				sa->sa_reg[2].oa_base,
    358   1.8        pk 				sc->sc_fb_psize,
    359   1.8        pk 				BUS_SPACE_MAP_LINEAR, &sc->sc_fb_memh) != 0) {
    360   1.1        pk 			printf("%s: cannot map framebuffer\n", self->dv_xname);
    361   1.1        pk 			return;
    362   1.1        pk 		}
    363   1.1        pk 		fb->fb_pixels = (char *)sc->sc_fb_memh;
    364   1.1        pk 	} else {
    365   1.1        pk 		sc->sc_fb_memh = (bus_space_handle_t) fb->fb_pixels;
    366   1.1        pk 	}
    367   1.1        pk 
    368   1.1        pk 	i = p9100_ctl_read_4(sc, 0x0004);
    369   1.1        pk 	switch ((i >> 26) & 7) {
    370   1.1        pk 	    case 5: fb->fb_type.fb_depth = 32; break;
    371   1.1        pk 	    case 7: fb->fb_type.fb_depth = 24; break;
    372   1.1        pk 	    case 3: fb->fb_type.fb_depth = 16; break;
    373   1.1        pk 	    case 2: fb->fb_type.fb_depth = 8; break;
    374   1.1        pk 	    default: {
    375   1.1        pk 		panic("pnozz: can't determine screen depth (0x%02x)", i);
    376   1.1        pk 	    }
    377   1.1        pk 	}
    378  1.21  macallan 	sc->sc_depth = (fb->fb_type.fb_depth >> 3);
    379  1.21  macallan 
    380  1.21  macallan 	/* XXX for some reason I get a kernel trap with this */
    381  1.21  macallan 	sc->sc_width = prom_getpropint(node, "width", 800);
    382  1.21  macallan 	sc->sc_height = prom_getpropint(node, "height", 600);
    383  1.21  macallan 
    384  1.21  macallan 	sc->sc_stride = prom_getpropint(node, "linebytes", sc->sc_width *
    385  1.21  macallan 	    (fb->fb_type.fb_depth >> 3));
    386  1.21  macallan 
    387  1.21  macallan 	p9100_init_engine(sc);
    388  1.21  macallan 
    389  1.21  macallan 	fb_setsize_obp(fb, fb->fb_type.fb_depth, sc->sc_width, sc->sc_height,
    390  1.21  macallan 	    node);
    391   1.1        pk 
    392   1.1        pk 	sbus_establish(&sc->sc_sd, &sc->sc_dev);
    393   1.1        pk 
    394   1.1        pk 	fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
    395  1.21  macallan 	printf(": rev %d, %dx%d, depth %d mem %x",
    396   1.1        pk 	       (i & 7), fb->fb_type.fb_width, fb->fb_type.fb_height,
    397  1.21  macallan 	       fb->fb_type.fb_depth, (unsigned int)sc->sc_fb_psize);
    398   1.1        pk 
    399  1.19        pk 	fb->fb_type.fb_cmsize = prom_getpropint(node, "cmsize", 256);
    400   1.1        pk 	if ((1 << fb->fb_type.fb_depth) != fb->fb_type.fb_cmsize)
    401   1.1        pk 		printf(", %d entry colormap", fb->fb_type.fb_cmsize);
    402   1.1        pk 
    403   1.1        pk 	/* Initialize the default color map. */
    404  1.21  macallan 	/*bt_initcmap(&sc->sc_cmap, 256);*/
    405  1.21  macallan 	j = 0;
    406  1.21  macallan 	for (i = 0; i < 256; i++) {
    407  1.21  macallan 		sc->sc_cmap.cm_map[i][0] = rasops_cmap[j];
    408  1.21  macallan 		j++;
    409  1.21  macallan 		sc->sc_cmap.cm_map[i][1] = rasops_cmap[j];
    410  1.21  macallan 		j++;
    411  1.21  macallan 		sc->sc_cmap.cm_map[i][2] = rasops_cmap[j];
    412  1.21  macallan 		j++;
    413  1.21  macallan 	}
    414   1.1        pk 	p9100loadcmap(sc, 0, 256);
    415   1.1        pk 
    416   1.1        pk 	/* make sure we are not blanked */
    417   1.7     cyber 	if (isconsole)
    418   1.7     cyber 		p9100_set_video(sc, 1);
    419   1.1        pk 
    420   1.1        pk 	if (shutdownhook_establish(p9100_shutdown, sc) == NULL) {
    421   1.1        pk 		panic("%s: could not establish shutdown hook",
    422   1.1        pk 		      sc->sc_dev.dv_xname);
    423   1.1        pk 	}
    424   1.1        pk 
    425   1.1        pk 	if (isconsole) {
    426   1.1        pk 		printf(" (console)\n");
    427   1.1        pk #ifdef RASTERCONSOLE
    428  1.21  macallan 		/*p9100loadcmap(sc, 255, 1);*/
    429   1.1        pk 		fbrcons_init(fb);
    430   1.1        pk #endif
    431   1.1        pk 	} else
    432   1.1        pk 		printf("\n");
    433  1.21  macallan 
    434  1.21  macallan #if NWSDISPLAY > 0
    435  1.21  macallan 	wsfont_init();
    436  1.21  macallan 
    437  1.21  macallan 	p9100_init_screen(sc, &p9100_console_screen, 1, &defattr);
    438  1.21  macallan 	p9100_console_screen.active = 1;
    439  1.21  macallan 	sc->active = &p9100_console_screen;
    440  1.21  macallan 	ri = &p9100_console_screen.ri;
    441  1.21  macallan 
    442  1.21  macallan 	p9100_defscreendesc.nrows = ri->ri_rows;
    443  1.21  macallan 	p9100_defscreendesc.ncols = ri->ri_cols;
    444  1.21  macallan 	p9100_defscreendesc.textops = &ri->ri_ops;
    445  1.21  macallan 	p9100_defscreendesc.capabilities = ri->ri_caps;
    446  1.21  macallan 
    447  1.21  macallan 	if(isconsole) {
    448  1.21  macallan 		wsdisplay_cnattach(&p9100_defscreendesc, ri, 0, 0, defattr);
    449  1.21  macallan 	}
    450  1.21  macallan 
    451  1.21  macallan 	sc->sc_bg = (defattr >> 16) & 0xff;
    452  1.21  macallan 
    453  1.21  macallan 	p9100_clearscreen(sc);
    454  1.21  macallan 
    455  1.21  macallan 	aa.console = isconsole;
    456  1.21  macallan 	aa.scrdata = &p9100_screenlist;
    457  1.21  macallan 	aa.accessops = &p9100_accessops;
    458  1.21  macallan 	aa.accesscookie = sc;
    459   1.1        pk 
    460  1.21  macallan 	config_found(self, &aa, wsemuldisplaydevprint);
    461  1.21  macallan #endif
    462  1.21  macallan 	/* attach the fb */
    463   1.1        pk 	fb_attach(fb, isconsole);
    464  1.21  macallan 
    465  1.21  macallan #if 0
    466  1.21  macallan 	p9100_rectfill(sc, 10, 10, 200, 200, 0x01);
    467  1.21  macallan 	p9100_rectfill(sc, 210, 10, 200, 200, 0xff);
    468  1.21  macallan 	p9100_bitblt(sc, 10, 10, 110, 110, 400, 200, ROP_SRC);
    469  1.21  macallan #endif
    470  1.21  macallan #if 0
    471  1.21  macallan 	p9100_setup_mono(sc, 750, 500, 32, 1, 1, 6);
    472  1.21  macallan 	{
    473  1.21  macallan 		uint32_t ev = 0xc3000000, odd = 0x3c000000;
    474  1.21  macallan 		for (i = 0; i < 16; i++) {
    475  1.21  macallan 			p9100_feed_line(sc, 1, (uint8_t*)&ev);
    476  1.21  macallan 			p9100_feed_line(sc, 1, (uint8_t*)&odd);
    477  1.21  macallan 		}
    478  1.21  macallan 	}
    479  1.21  macallan 	delay(4000000);
    480  1.21  macallan #endif
    481   1.1        pk }
    482   1.1        pk 
    483   1.1        pk static void
    484   1.1        pk p9100_shutdown(arg)
    485   1.1        pk 	void *arg;
    486   1.1        pk {
    487   1.1        pk 	struct p9100_softc *sc = arg;
    488  1.21  macallan 
    489   1.2       mrg #ifdef RASTERCONSOLE
    490   1.1        pk 	sc->sc_cmap.cm_map[0][0] = 0xff;
    491   1.1        pk 	sc->sc_cmap.cm_map[0][1] = 0xff;
    492   1.1        pk 	sc->sc_cmap.cm_map[0][2] = 0xff;
    493   1.1        pk 	sc->sc_cmap.cm_map[1][0] = 0;
    494   1.1        pk 	sc->sc_cmap.cm_map[1][1] = 0;
    495  1.21  macallan 	sc->sc_cmap.cm_map[1][2] = 0x00;
    496   1.1        pk 	p9100loadcmap(sc, 0, 2);
    497   1.1        pk 	sc->sc_cmap.cm_map[255][0] = 0;
    498   1.1        pk 	sc->sc_cmap.cm_map[255][1] = 0;
    499   1.1        pk 	sc->sc_cmap.cm_map[255][2] = 0;
    500   1.1        pk 	p9100loadcmap(sc, 255, 1);
    501   1.1        pk #endif
    502   1.1        pk 	p9100_set_video(sc, 1);
    503   1.1        pk }
    504   1.1        pk 
    505   1.1        pk int
    506  1.16      fvdl p9100open(dev_t dev, int flags, int mode, struct proc *p)
    507   1.1        pk {
    508   1.1        pk 	int unit = minor(dev);
    509   1.1        pk 
    510   1.1        pk 	if (unit >= pnozz_cd.cd_ndevs || pnozz_cd.cd_devs[unit] == NULL)
    511   1.1        pk 		return (ENXIO);
    512   1.1        pk 	return (0);
    513   1.1        pk }
    514   1.1        pk 
    515   1.1        pk int
    516  1.16      fvdl p9100ioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
    517   1.1        pk {
    518   1.1        pk 	struct p9100_softc *sc = pnozz_cd.cd_devs[minor(dev)];
    519   1.1        pk 	struct fbgattr *fba;
    520   1.1        pk 	int error;
    521   1.1        pk 
    522   1.1        pk 	switch (cmd) {
    523   1.1        pk 
    524   1.1        pk 	case FBIOGTYPE:
    525   1.1        pk 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    526   1.1        pk 		break;
    527   1.1        pk 
    528   1.1        pk 	case FBIOGATTR:
    529   1.1        pk 		fba = (struct fbgattr *)data;
    530   1.1        pk 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    531   1.1        pk 		fba->owner = 0;		/* XXX ??? */
    532   1.1        pk 		fba->fbtype = sc->sc_fb.fb_type;
    533   1.1        pk 		fba->sattr.flags = 0;
    534   1.1        pk 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    535   1.1        pk 		fba->sattr.dev_specific[0] = -1;
    536   1.1        pk 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    537   1.1        pk 		fba->emu_types[1] = -1;
    538   1.1        pk 		break;
    539   1.1        pk 
    540   1.1        pk 	case FBIOGETCMAP:
    541   1.1        pk #define p ((struct fbcmap *)data)
    542   1.1        pk 		return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
    543   1.1        pk 
    544   1.1        pk 	case FBIOPUTCMAP:
    545   1.1        pk 		/* copy to software map */
    546   1.1        pk 		error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
    547   1.1        pk 		if (error)
    548   1.1        pk 			return (error);
    549   1.1        pk 		/* now blast them into the chip */
    550   1.1        pk 		/* XXX should use retrace interrupt */
    551   1.1        pk 		p9100loadcmap(sc, p->index, p->count);
    552   1.1        pk #undef p
    553   1.1        pk 		break;
    554   1.1        pk 
    555   1.1        pk 	case FBIOGVIDEO:
    556   1.1        pk 		*(int *)data = p9100_get_video(sc);
    557   1.1        pk 		break;
    558   1.1        pk 
    559   1.1        pk 	case FBIOSVIDEO:
    560   1.1        pk 		p9100_set_video(sc, *(int *)data);
    561   1.1        pk 		break;
    562   1.1        pk 
    563   1.1        pk 	default:
    564   1.1        pk 		return (ENOTTY);
    565   1.1        pk 	}
    566   1.1        pk 	return (0);
    567   1.1        pk }
    568   1.1        pk 
    569   1.1        pk static uint32_t
    570   1.1        pk p9100_ctl_read_4(struct p9100_softc *sc, bus_size_t off)
    571   1.1        pk {
    572   1.1        pk 	sc->sc_junk = bus_space_read_4(sc->sc_bustag, sc->sc_fb_memh, off);
    573   1.1        pk 	return bus_space_read_4(sc->sc_bustag, sc->sc_ctl_memh, off);
    574   1.1        pk }
    575   1.1        pk 
    576   1.1        pk static void
    577   1.1        pk p9100_ctl_write_4(struct p9100_softc *sc, bus_size_t off, uint32_t v)
    578   1.1        pk {
    579   1.1        pk 	sc->sc_junk = bus_space_read_4(sc->sc_bustag, sc->sc_fb_memh, off);
    580   1.1        pk 	bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh, off, v);
    581   1.1        pk }
    582   1.1        pk 
    583  1.21  macallan /* wait until the engine is idle */
    584  1.21  macallan static void
    585  1.21  macallan p9100_sync(struct p9100_softc *sc)
    586  1.21  macallan {
    587  1.21  macallan 	while((p9100_ctl_read_4(sc, ENGINE_STATUS) &
    588  1.21  macallan 	    (ENGINE_BUSY | BLITTER_BUSY)) != 0);
    589  1.21  macallan }
    590  1.21  macallan 
    591  1.21  macallan static void
    592  1.21  macallan p9100_set_color_reg(struct p9100_softc *sc, int reg, int32_t col)
    593  1.21  macallan {
    594  1.21  macallan 	uint32_t out;
    595  1.21  macallan 
    596  1.21  macallan 	switch(sc->sc_depth)
    597  1.21  macallan 	{
    598  1.21  macallan 		case 1:	/* 8 bit */
    599  1.21  macallan 			out = (col << 8) | col;
    600  1.21  macallan 			out |= out << 16;
    601  1.21  macallan 			break;
    602  1.21  macallan 		case 2: /* 16 bit */
    603  1.21  macallan 			out = col | (col << 16);
    604  1.21  macallan 			break;
    605  1.21  macallan 		default:
    606  1.21  macallan 			out = col;
    607  1.21  macallan 	}
    608  1.21  macallan 	p9100_ctl_write_4(sc, reg, out);
    609  1.21  macallan }
    610  1.21  macallan 
    611  1.21  macallan /* initialize the drawing engine */
    612  1.21  macallan static void
    613  1.21  macallan p9100_init_engine(struct p9100_softc *sc)
    614  1.21  macallan {
    615  1.21  macallan 	/* reset clipping rectangles */
    616  1.23   tsutsui 	uint32_t rmax = ((sc->sc_width & 0x3fff) << 16) |
    617  1.21  macallan 	    (sc->sc_height & 0x3fff);
    618  1.21  macallan 
    619  1.21  macallan 	p9100_ctl_write_4(sc, WINDOW_OFFSET, 0);
    620  1.21  macallan 	p9100_ctl_write_4(sc, WINDOW_MIN, 0);
    621  1.23   tsutsui 	p9100_ctl_write_4(sc, WINDOW_MAX, rmax);
    622  1.21  macallan 	p9100_ctl_write_4(sc, BYTE_CLIP_MIN, 0);
    623  1.23   tsutsui 	p9100_ctl_write_4(sc, BYTE_CLIP_MAX, rmax);
    624  1.21  macallan 	p9100_ctl_write_4(sc, DRAW_MODE, 0);
    625  1.21  macallan 	p9100_ctl_write_4(sc, PLANE_MASK, 0xffffffff);
    626  1.21  macallan 	p9100_ctl_write_4(sc, PATTERN0, 0xffffffff);
    627  1.21  macallan 	p9100_ctl_write_4(sc, PATTERN1, 0xffffffff);
    628  1.21  macallan 	p9100_ctl_write_4(sc, PATTERN2, 0xffffffff);
    629  1.21  macallan 	p9100_ctl_write_4(sc, PATTERN3, 0xffffffff);
    630  1.21  macallan }
    631  1.21  macallan 
    632  1.21  macallan /* screen-to-screen blit */
    633  1.21  macallan void
    634  1.21  macallan p9100_bitblt(struct p9100_softc *sc, int xs, int ys, int xd, int yd, int wi,
    635  1.21  macallan     int he, uint32_t rop)
    636  1.21  macallan {
    637  1.21  macallan 	uint32_t src, dst, srcw, dstw, junk;
    638  1.21  macallan 
    639  1.21  macallan 	src = ((xs & 0x3fff) << 16) | (ys & 0x3fff);
    640  1.21  macallan 	dst = ((xd & 0x3fff) << 16) | (yd & 0x3fff);
    641  1.21  macallan 	srcw = (((xs + wi - 1) & 0x3fff) << 16) | ((ys + he - 1) & 0x3fff);
    642  1.21  macallan 	dstw = (((xd + wi - 1) & 0x3fff) << 16) | ((yd + he - 1) & 0x3fff);
    643  1.21  macallan 	p9100_sync(sc);
    644  1.21  macallan 	p9100_ctl_write_4(sc, RASTER_OP, rop);
    645  1.21  macallan 
    646  1.21  macallan 	p9100_ctl_write_4(sc, ABS_XY0, src);
    647  1.21  macallan 
    648  1.21  macallan 	p9100_ctl_write_4(sc, ABS_XY1, srcw);
    649  1.21  macallan 	p9100_ctl_write_4(sc, ABS_XY2, dst);
    650  1.21  macallan 	p9100_ctl_write_4(sc, ABS_XY3, dstw);
    651  1.21  macallan 	junk = p9100_ctl_read_4(sc, COMMAND_BLIT);
    652  1.21  macallan }
    653  1.21  macallan 
    654  1.21  macallan /* solid rectangle fill */
    655  1.21  macallan void
    656  1.21  macallan p9100_rectfill(struct p9100_softc *sc, int xs, int ys, int wi, int he, uint32_t col)
    657  1.21  macallan {
    658  1.21  macallan 	uint32_t src, srcw, junk;
    659  1.21  macallan 
    660  1.21  macallan 	src = ((xs & 0x3fff) << 16) | (ys & 0x3fff);
    661  1.21  macallan 	srcw = (((xs + wi) & 0x3fff) << 16) | ((ys + he) & 0x3fff);
    662  1.21  macallan 	p9100_sync(sc);
    663  1.21  macallan 	p9100_set_color_reg(sc, FOREGROUND_COLOR, col);
    664  1.21  macallan 	p9100_set_color_reg(sc, BACKGROUND_COLOR, col);
    665  1.21  macallan 	p9100_ctl_write_4(sc, RASTER_OP, ROP_PAT);
    666  1.21  macallan 	p9100_ctl_write_4(sc, COORD_INDEX, 0);
    667  1.21  macallan 	p9100_ctl_write_4(sc, RECT_RTW_XY, src);
    668  1.21  macallan 	p9100_ctl_write_4(sc, RECT_RTW_XY, srcw);
    669  1.21  macallan 	junk=p9100_ctl_read_4(sc, COMMAND_QUAD);
    670  1.21  macallan }
    671  1.21  macallan 
    672  1.21  macallan /* setup for mono->colour expansion */
    673  1.21  macallan void
    674  1.21  macallan p9100_setup_mono(struct p9100_softc *sc, int x, int y, int wi, int he,
    675  1.21  macallan     uint32_t fg, uint32_t bg)
    676  1.21  macallan {
    677  1.21  macallan 	p9100_sync(sc);
    678  1.21  macallan 	/*
    679  1.21  macallan 	 * this doesn't make any sense to me either, but for some reason the
    680  1.21  macallan 	 * chip applies the foreground colour to 0 pixels
    681  1.21  macallan 	 */
    682  1.21  macallan 
    683  1.21  macallan 	p9100_set_color_reg(sc,FOREGROUND_COLOR,bg);
    684  1.21  macallan 	p9100_set_color_reg(sc,BACKGROUND_COLOR,fg);
    685  1.21  macallan 
    686  1.21  macallan 	p9100_ctl_write_4(sc, RASTER_OP, ROP_SRC);
    687  1.21  macallan 	p9100_ctl_write_4(sc, ABS_X0, x);
    688  1.21  macallan 	p9100_ctl_write_4(sc, ABS_XY1, (x << 16) | (y & 0xFFFFL));
    689  1.21  macallan 	p9100_ctl_write_4(sc, ABS_X2, (x + wi));
    690  1.21  macallan 	p9100_ctl_write_4(sc, ABS_Y3, he);
    691  1.21  macallan 	/* now feed the data into the chip */
    692  1.21  macallan 	sc->sc_mono_width = wi;
    693  1.21  macallan }
    694  1.21  macallan 
    695  1.21  macallan /* write monochrome data to the screen through the blitter */
    696  1.21  macallan void
    697  1.21  macallan p9100_feed_line(struct p9100_softc *sc, int count, uint8_t *data)
    698  1.21  macallan {
    699  1.21  macallan 	int i;
    700  1.21  macallan 	uint32_t latch = 0, bork;
    701  1.21  macallan 	int shift = 24;
    702  1.21  macallan 	int to_go = sc->sc_mono_width;
    703  1.21  macallan 
    704  1.21  macallan 	for (i = 0; i < count; i++) {
    705  1.21  macallan 		bork = data[i];
    706  1.21  macallan 		latch |= (bork << shift);
    707  1.21  macallan 		if (shift == 0) {
    708  1.21  macallan 			/* check how many bits are significant */
    709  1.21  macallan 			if (to_go > 31) {
    710  1.21  macallan 				p9100_ctl_write_4(sc, (PIXEL_1 +
    711  1.21  macallan 				    (31 << 2)), latch);
    712  1.21  macallan 				to_go -= 32;
    713  1.21  macallan 			} else
    714  1.21  macallan 			{
    715  1.21  macallan 				p9100_ctl_write_4(sc, (PIXEL_1 +
    716  1.21  macallan 				    ((to_go - 1) << 2)), latch);
    717  1.21  macallan 				to_go = 0;
    718  1.21  macallan 			}
    719  1.21  macallan 			latch = 0;
    720  1.21  macallan 			shift = 24;
    721  1.21  macallan 		} else
    722  1.21  macallan 			shift -= 8;
    723  1.21  macallan 		}
    724  1.21  macallan 	if (shift != 24)
    725  1.21  macallan 		p9100_ctl_write_4(sc, (PIXEL_1 + ((to_go - 1) << 2)), latch);
    726  1.21  macallan }
    727  1.21  macallan 
    728  1.21  macallan void
    729  1.21  macallan p9100_clearscreen(struct p9100_softc *sc)
    730  1.21  macallan {
    731  1.21  macallan 	p9100_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height, sc->sc_bg);
    732  1.21  macallan }
    733  1.21  macallan 
    734  1.21  macallan uint8_t
    735   1.1        pk p9100_ramdac_read(struct p9100_softc *sc, bus_size_t off)
    736   1.1        pk {
    737   1.1        pk 	sc->sc_junk = p9100_ctl_read_4(sc, PWRUP_CNFG);
    738  1.21  macallan 	sc->sc_junk = bus_space_read_4(sc->sc_bustag, sc->sc_fb_memh, off);
    739  1.21  macallan 	return ((bus_space_read_4(sc->sc_bustag,
    740  1.21  macallan 	    sc->sc_ctl_memh, off) >> 16) & 0xff);
    741   1.1        pk }
    742   1.1        pk 
    743  1.21  macallan void
    744   1.1        pk p9100_ramdac_write(struct p9100_softc *sc, bus_size_t off, uint8_t v)
    745   1.1        pk {
    746   1.1        pk 	sc->sc_junk = p9100_ctl_read_4(sc, PWRUP_CNFG);
    747  1.21  macallan 	sc->sc_junk = bus_space_read_4(sc->sc_bustag, sc->sc_fb_memh, off);
    748  1.21  macallan 	bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh, off,
    749  1.21  macallan 	    ((uint32_t)v) << 16);
    750   1.1        pk }
    751   1.1        pk 
    752   1.1        pk /*
    753   1.1        pk  * Undo the effect of an FBIOSVIDEO that turns the video off.
    754   1.1        pk  */
    755   1.1        pk static void
    756   1.1        pk p9100unblank(struct device *dev)
    757   1.1        pk {
    758   1.1        pk 	p9100_set_video((struct p9100_softc *)dev, 1);
    759   1.1        pk }
    760   1.1        pk 
    761   1.1        pk static void
    762   1.1        pk p9100_set_video(struct p9100_softc *sc, int enable)
    763   1.1        pk {
    764   1.1        pk 	u_int32_t v = p9100_ctl_read_4(sc, SCRN_RPNT_CTL_1);
    765  1.21  macallan 
    766   1.1        pk 	if (enable)
    767   1.1        pk 		v |= VIDEO_ENABLED;
    768   1.1        pk 	else
    769   1.1        pk 		v &= ~VIDEO_ENABLED;
    770   1.1        pk 	p9100_ctl_write_4(sc, SCRN_RPNT_CTL_1, v);
    771   1.1        pk #if NTCTRL > 0
    772   1.1        pk 	/* Turn On/Off the TFT if we know how.
    773   1.1        pk 	 */
    774   1.1        pk 	tadpole_set_video(enable);
    775   1.1        pk #endif
    776   1.1        pk }
    777   1.1        pk 
    778   1.1        pk static int
    779   1.1        pk p9100_get_video(struct p9100_softc *sc)
    780   1.1        pk {
    781   1.1        pk 	return (p9100_ctl_read_4(sc, SCRN_RPNT_CTL_1) & VIDEO_ENABLED) != 0;
    782   1.1        pk }
    783   1.1        pk 
    784   1.1        pk /*
    785   1.1        pk  * Load a subset of the current (new) colormap into the IBM RAMDAC.
    786   1.1        pk  */
    787   1.1        pk static void
    788   1.1        pk p9100loadcmap(struct p9100_softc *sc, int start, int ncolors)
    789   1.1        pk {
    790  1.21  macallan 	int i;
    791   1.1        pk 	p9100_ramdac_write(sc, DAC_CMAP_WRIDX, start);
    792   1.1        pk 
    793  1.21  macallan 	for (i=0;i<ncolors;i++) {
    794  1.21  macallan 		p9100_ramdac_write(sc, DAC_CMAP_DATA,
    795  1.21  macallan 		    sc->sc_cmap.cm_map[i + start][0]);
    796  1.21  macallan 		p9100_ramdac_write(sc, DAC_CMAP_DATA,
    797  1.21  macallan 		    sc->sc_cmap.cm_map[i + start][1]);
    798  1.21  macallan 		p9100_ramdac_write(sc, DAC_CMAP_DATA,
    799  1.21  macallan 		    sc->sc_cmap.cm_map[i + start][2]);
    800   1.1        pk 	}
    801   1.1        pk }
    802   1.1        pk 
    803   1.1        pk /*
    804   1.1        pk  * Return the address that would map the given device at the given
    805   1.1        pk  * offset, allowing for the given protection, or return -1 for error.
    806   1.1        pk  */
    807   1.1        pk paddr_t
    808   1.1        pk p9100mmap(dev_t dev, off_t off, int prot)
    809   1.1        pk {
    810   1.1        pk 	struct p9100_softc *sc = pnozz_cd.cd_devs[minor(dev)];
    811   1.1        pk 
    812   1.1        pk 	if (off & PGOFSET)
    813   1.1        pk 		panic("p9100mmap");
    814   1.1        pk 	if (off < 0)
    815   1.1        pk 		return (-1);
    816   1.1        pk 
    817  1.21  macallan #ifdef PNOZZ_EMUL_CG3
    818   1.1        pk #define CG3_MMAP_OFFSET	0x04000000
    819   1.1        pk 	/* Make Xsun think we are a CG3 (SUN3COLOR)
    820   1.1        pk 	 */
    821   1.1        pk 	if (off >= CG3_MMAP_OFFSET && off < CG3_MMAP_OFFSET + sc->sc_fb_psize) {
    822   1.1        pk 		off -= CG3_MMAP_OFFSET;
    823   1.3       eeh 		return (bus_space_mmap(sc->sc_bustag,
    824   1.3       eeh 			sc->sc_fb_paddr,
    825   1.3       eeh 			off,
    826   1.3       eeh 			prot,
    827   1.3       eeh 			BUS_SPACE_MAP_LINEAR));
    828   1.1        pk 	}
    829  1.21  macallan #endif
    830   1.1        pk 
    831   1.1        pk 	if (off >= sc->sc_fb_psize + sc->sc_ctl_psize + sc->sc_cmd_psize)
    832   1.1        pk 		return (-1);
    833   1.1        pk 
    834   1.1        pk 	if (off < sc->sc_fb_psize) {
    835   1.3       eeh 		return (bus_space_mmap(sc->sc_bustag,
    836   1.3       eeh 			sc->sc_fb_paddr,
    837   1.3       eeh 			off,
    838   1.3       eeh 			prot,
    839   1.3       eeh 			BUS_SPACE_MAP_LINEAR));
    840   1.1        pk 	}
    841   1.1        pk 	off -= sc->sc_fb_psize;
    842   1.1        pk 	if (off < sc->sc_ctl_psize) {
    843   1.3       eeh 		return (bus_space_mmap(sc->sc_bustag,
    844   1.3       eeh 			sc->sc_ctl_paddr,
    845   1.3       eeh 			off,
    846   1.3       eeh 			prot,
    847   1.3       eeh 			BUS_SPACE_MAP_LINEAR));
    848   1.1        pk 	}
    849   1.1        pk 	off -= sc->sc_ctl_psize;
    850   1.1        pk 
    851   1.3       eeh 	return (bus_space_mmap(sc->sc_bustag,
    852   1.3       eeh 		sc->sc_cmd_paddr,
    853   1.3       eeh 		off,
    854   1.3       eeh 		prot,
    855   1.3       eeh 		BUS_SPACE_MAP_LINEAR));
    856   1.1        pk }
    857  1.21  macallan 
    858  1.21  macallan /* wscons stuff */
    859  1.21  macallan 
    860  1.21  macallan void
    861  1.21  macallan p9100_switch_screen(struct p9100_softc *sc)
    862  1.21  macallan {
    863  1.21  macallan 	struct p9100_screen *scr, *oldscr;
    864  1.21  macallan 
    865  1.21  macallan 	scr = sc->wanted;
    866  1.21  macallan 	if (!scr) {
    867  1.21  macallan 		printf("p9100_switch_screen: disappeared\n");
    868  1.21  macallan 		(*sc->switchcb)(sc->switchcbarg, EIO, 0);
    869  1.21  macallan 		return;
    870  1.21  macallan 	}
    871  1.21  macallan 	oldscr = sc->active; /* can be NULL! */
    872  1.21  macallan #ifdef DIAGNOSTIC
    873  1.21  macallan 	if (oldscr) {
    874  1.21  macallan 		if (!oldscr->active)
    875  1.21  macallan 			panic("p9100_switch_screen: not active");
    876  1.21  macallan 	}
    877  1.21  macallan #endif
    878  1.21  macallan 	if (scr == oldscr)
    879  1.21  macallan 		return;
    880  1.21  macallan 
    881  1.21  macallan #ifdef DIAGNOSTIC
    882  1.21  macallan 	if (scr->active)
    883  1.21  macallan 		panic("p9100_switch_screen: active");
    884  1.21  macallan #endif
    885  1.21  macallan 
    886  1.21  macallan 	if (oldscr)
    887  1.21  macallan 		oldscr->active = 0;
    888  1.21  macallan #ifdef notyet
    889  1.21  macallan 	if (sc->currenttype != type) {
    890  1.21  macallan 		p9100_set_screentype(sc, type);
    891  1.21  macallan 		sc->currenttype = type;
    892  1.21  macallan 	}
    893  1.21  macallan #endif
    894  1.21  macallan 
    895  1.21  macallan 	/* Clear the entire screen. */
    896  1.21  macallan 
    897  1.21  macallan 	scr->active = 1;
    898  1.21  macallan 	p9100_restore_screen(scr, &p9100_defscreendesc, scr->chars);
    899  1.21  macallan 
    900  1.21  macallan 	sc->active = scr;
    901  1.21  macallan 
    902  1.21  macallan 	scr->ri.ri_ops.cursor(scr, scr->cursoron, scr->cursorrow,
    903  1.21  macallan 	    scr->cursorcol);
    904  1.21  macallan 
    905  1.21  macallan 	sc->wanted = 0;
    906  1.21  macallan 	if (sc->switchcb)
    907  1.21  macallan 		(*sc->switchcb)(sc->switchcbarg, 0, 0);
    908  1.21  macallan }
    909  1.21  macallan 
    910  1.21  macallan void
    911  1.21  macallan p9100_restore_screen(struct p9100_screen *scr,
    912  1.21  macallan     const struct wsscreen_descr *type, u_int16_t *mem)
    913  1.21  macallan {
    914  1.21  macallan 	int i, j, offset = 0;
    915  1.21  macallan 	uint16_t *charptr = scr->chars;
    916  1.21  macallan 	long *attrptr = scr->attrs;
    917  1.21  macallan 
    918  1.21  macallan 	p9100_clearscreen(scr->sc);
    919  1.21  macallan 	for (i = 0; i < scr->ri.ri_rows; i++) {
    920  1.21  macallan 		for (j = 0; j < scr->ri.ri_cols; j++) {
    921  1.21  macallan 			p9100_putchar(scr, i, j, charptr[offset],
    922  1.21  macallan 			    attrptr[offset]);
    923  1.21  macallan 			offset++;
    924  1.21  macallan 		}
    925  1.21  macallan 	}
    926  1.21  macallan 	scr->cursordrawn = 0;
    927  1.21  macallan }
    928  1.21  macallan 
    929  1.21  macallan void
    930  1.21  macallan p9100_cursor(void *cookie, int on, int row, int col)
    931  1.21  macallan {
    932  1.21  macallan 	struct rasops_info *ri = cookie;
    933  1.21  macallan 	struct p9100_screen *scr = ri->ri_hw;
    934  1.21  macallan 	struct p9100_softc *sc = scr->sc;
    935  1.21  macallan 	int x, y, wi,he;
    936  1.21  macallan 
    937  1.21  macallan 	wi = ri->ri_font->fontwidth;
    938  1.21  macallan 	he = ri->ri_font->fontheight;
    939  1.21  macallan 
    940  1.21  macallan 	if ((scr->active) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    941  1.21  macallan 		x = scr->cursorcol * wi + ri->ri_xorigin;
    942  1.21  macallan 		y = scr->cursorrow * he + ri->ri_yorigin;
    943  1.21  macallan 		if (scr->cursordrawn) {
    944  1.21  macallan 			p9100_bitblt(sc, x, y, x, y, wi, he, (ROP_SRC ^ 0xff));
    945  1.21  macallan 			scr->cursordrawn = 0;
    946  1.21  macallan 		}
    947  1.21  macallan 		scr->cursorrow = row;
    948  1.21  macallan 		scr->cursorcol = col;
    949  1.21  macallan 		if ((scr->cursoron = on) != 0)
    950  1.21  macallan 		{
    951  1.21  macallan 			x = scr->cursorcol * wi + ri->ri_xorigin;
    952  1.21  macallan 			y = scr->cursorrow * he + ri->ri_yorigin;
    953  1.21  macallan 			p9100_bitblt(sc, x, y, x, y, wi, he, (ROP_SRC ^ 0xff));
    954  1.21  macallan 			scr->cursordrawn = 1;
    955  1.21  macallan 		}
    956  1.21  macallan 	} else {
    957  1.21  macallan 		scr->cursoron = on;
    958  1.21  macallan 		scr->cursorrow = row;
    959  1.21  macallan 		scr->cursorcol = col;
    960  1.21  macallan 		scr->cursordrawn = 0;
    961  1.21  macallan 	}
    962  1.21  macallan }
    963  1.21  macallan 
    964  1.21  macallan #if 0
    965  1.21  macallan int
    966  1.21  macallan p9100_mapchar(void *cookie, int uni, u_int *index)
    967  1.21  macallan {
    968  1.21  macallan 	return 0;
    969  1.21  macallan }
    970  1.21  macallan #endif
    971  1.21  macallan 
    972  1.21  macallan void
    973  1.21  macallan p9100_putchar(void *cookie, int row, int col, u_int c, long attr)
    974  1.21  macallan {
    975  1.21  macallan 	struct rasops_info *ri = cookie;
    976  1.21  macallan 	struct p9100_screen *scr = ri->ri_hw;
    977  1.21  macallan 	struct p9100_softc *sc = scr->sc;
    978  1.21  macallan 	int pos;
    979  1.21  macallan 
    980  1.21  macallan 	if ((row >= 0) && (row < ri->ri_rows) && (col >= 0) &&
    981  1.21  macallan 	     (col < ri->ri_cols)) {
    982  1.21  macallan 		pos = col + row * ri->ri_cols;
    983  1.21  macallan 		scr->attrs[pos] = attr;
    984  1.21  macallan 		scr->chars[pos] = c;
    985  1.21  macallan 
    986  1.21  macallan #ifdef PNOZZ_SOFT_PUTCHAR
    987  1.21  macallan 		if ((sc->putchar != NULL) && (	scr->active) &&
    988  1.21  macallan 		    (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    989  1.21  macallan 			p9100_sync(sc);
    990  1.21  macallan 			sc->putchar(cookie, row, col, c, attr);
    991  1.21  macallan 		}
    992  1.21  macallan #else
    993  1.21  macallan 		if ((scr->active) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    994  1.21  macallan 			int fg, bg, uc, i;
    995  1.21  macallan 			uint8_t *data;
    996  1.21  macallan 			int x, y, wi,he;
    997  1.21  macallan 
    998  1.21  macallan 			wi = ri->ri_font->fontwidth;
    999  1.21  macallan 			he = ri->ri_font->fontheight;
   1000  1.21  macallan 
   1001  1.21  macallan 			if (!CHAR_IN_FONT(c, ri->ri_font))
   1002  1.21  macallan 				return;
   1003  1.21  macallan 			bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xff];
   1004  1.21  macallan 			fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xff];
   1005  1.21  macallan 			x = ri->ri_xorigin + col * wi;
   1006  1.21  macallan 			y = ri->ri_yorigin + row * he;
   1007  1.21  macallan 			if (c == 0x20) {
   1008  1.21  macallan 				p9100_rectfill(sc, x, y, wi, he, bg);
   1009  1.21  macallan 			} else {
   1010  1.21  macallan 				uc = c-ri->ri_font->firstchar;
   1011  1.21  macallan 				data = (uint8_t *)ri->ri_font->data + uc *
   1012  1.21  macallan 				    ri->ri_fontscale;
   1013  1.21  macallan 
   1014  1.21  macallan 				p9100_setup_mono(sc, x, y, wi, 1, fg, bg);
   1015  1.21  macallan 				for (i = 0; i < he; i++) {
   1016  1.21  macallan 					p9100_feed_line(sc, ri->ri_font->stride,
   1017  1.21  macallan 					    data);
   1018  1.21  macallan 					data += ri->ri_font->stride;
   1019  1.21  macallan 				}
   1020  1.21  macallan 				/*p9100_sync(sc);*/
   1021  1.21  macallan 			}
   1022  1.21  macallan 		}
   1023  1.21  macallan #endif
   1024  1.21  macallan 	}
   1025  1.21  macallan }
   1026  1.21  macallan 
   1027  1.21  macallan void
   1028  1.21  macallan p9100_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
   1029  1.21  macallan {
   1030  1.21  macallan 	struct rasops_info *ri = cookie;
   1031  1.21  macallan 	struct p9100_screen *scr = ri->ri_hw;
   1032  1.21  macallan 	struct p9100_softc *sc = scr->sc;
   1033  1.21  macallan 	int32_t xs, xd, y, width, height;
   1034  1.21  macallan 	int from = srccol + row * ri->ri_cols;
   1035  1.21  macallan 	int to = dstcol + row * ri->ri_cols;
   1036  1.21  macallan 
   1037  1.21  macallan 	memmove(&scr->attrs[to], &scr->attrs[from], ncols * sizeof(long));
   1038  1.21  macallan 	memmove(&scr->chars[to], &scr->chars[from], ncols * sizeof(uint16_t));
   1039  1.21  macallan 
   1040  1.21  macallan 	if ((scr->active) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
   1041  1.21  macallan 		xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
   1042  1.21  macallan 		xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
   1043  1.21  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1044  1.21  macallan 		width = ri->ri_font->fontwidth * ncols;
   1045  1.21  macallan 		height = ri->ri_font->fontheight;
   1046  1.21  macallan 		p9100_bitblt(sc, xs, y, xd, y, width, height, ROP_SRC);
   1047  1.21  macallan 	}
   1048  1.21  macallan }
   1049  1.21  macallan 
   1050  1.21  macallan void
   1051  1.21  macallan p9100_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
   1052  1.21  macallan {
   1053  1.21  macallan 	struct rasops_info *ri = cookie;
   1054  1.21  macallan 	struct p9100_screen *scr = ri->ri_hw;
   1055  1.21  macallan 	struct p9100_softc *sc = scr->sc;
   1056  1.21  macallan 	int32_t x, y, width, height, bg;
   1057  1.21  macallan 	int start = startcol + row * ri->ri_cols;
   1058  1.21  macallan 	int end = start + ncols, i;
   1059  1.21  macallan 
   1060  1.21  macallan 	for (i = start; i < end; i++) {
   1061  1.21  macallan 		scr->attrs[i] = fillattr;
   1062  1.21  macallan 		scr->chars[i] = 0x20;
   1063  1.21  macallan 	}
   1064  1.21  macallan 	if ((scr->active) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
   1065  1.21  macallan 		x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
   1066  1.21  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1067  1.21  macallan 		width = ri->ri_font->fontwidth * ncols;
   1068  1.21  macallan 		height = ri->ri_font->fontheight;
   1069  1.21  macallan 		bg = (fillattr >> 16) & 0xff;
   1070  1.21  macallan 		p9100_rectfill(sc, x, y, width, height, bg);
   1071  1.21  macallan 	}
   1072  1.21  macallan }
   1073  1.21  macallan 
   1074  1.21  macallan void
   1075  1.21  macallan p9100_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
   1076  1.21  macallan {
   1077  1.21  macallan 	struct rasops_info *ri = cookie;
   1078  1.21  macallan 	struct p9100_screen *scr = ri->ri_hw;
   1079  1.21  macallan 	struct p9100_softc *sc = scr->sc;
   1080  1.21  macallan 	int32_t x, ys, yd, width, height;
   1081  1.21  macallan 	int from, to, len;
   1082  1.21  macallan 
   1083  1.21  macallan 	from = ri->ri_cols * srcrow;
   1084  1.21  macallan 	to = ri->ri_cols * dstrow;
   1085  1.21  macallan 	len = ri->ri_cols * nrows;
   1086  1.21  macallan 
   1087  1.21  macallan 	memmove(&scr->attrs[to], &scr->attrs[from], len * sizeof(long));
   1088  1.21  macallan 	memmove(&scr->chars[to], &scr->chars[from], len * sizeof(uint16_t));
   1089  1.21  macallan 
   1090  1.21  macallan 	if ((scr->active) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
   1091  1.21  macallan 		x = ri->ri_xorigin;
   1092  1.21  macallan 		ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
   1093  1.21  macallan 		yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
   1094  1.21  macallan 		width = ri->ri_emuwidth;
   1095  1.21  macallan 		height = ri->ri_font->fontheight * nrows;
   1096  1.21  macallan 		p9100_bitblt(sc, x, ys, x, yd, width, height, ROP_SRC);
   1097  1.21  macallan 	}
   1098  1.21  macallan }
   1099  1.21  macallan 
   1100  1.21  macallan void
   1101  1.21  macallan p9100_eraserows(void *cookie, int row, int nrows, long fillattr)
   1102  1.21  macallan {
   1103  1.21  macallan 	struct rasops_info *ri = cookie;
   1104  1.21  macallan 	struct p9100_screen *scr = ri->ri_hw;
   1105  1.21  macallan 	struct p9100_softc *sc = scr->sc;
   1106  1.21  macallan 	int32_t x,y,width,height,bg;
   1107  1.21  macallan 	int start, end, i;
   1108  1.21  macallan 
   1109  1.21  macallan 	start = ri->ri_cols * row;
   1110  1.21  macallan 	end = ri->ri_cols * (row + nrows);
   1111  1.21  macallan 
   1112  1.21  macallan 	for (i = start; i < end; i++) {
   1113  1.21  macallan 		scr->attrs[i] = fillattr;
   1114  1.21  macallan 		scr->chars[i] = 0x20;
   1115  1.21  macallan 	}
   1116  1.21  macallan 
   1117  1.21  macallan 	if ((scr->active) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
   1118  1.21  macallan 		x = ri->ri_xorigin;
   1119  1.21  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1120  1.21  macallan 		width = ri->ri_emuwidth;
   1121  1.21  macallan 		height = ri->ri_font->fontheight * nrows;
   1122  1.21  macallan 		bg = (fillattr >> 16) & 0xff;
   1123  1.21  macallan 		p9100_rectfill(sc, x, y, width, height, bg);
   1124  1.21  macallan 	}
   1125  1.21  macallan }
   1126  1.21  macallan 
   1127  1.21  macallan int
   1128  1.21  macallan p9100_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
   1129  1.21  macallan {
   1130  1.21  macallan 	if ((fg == 0) && (bg == 0))
   1131  1.21  macallan 	{
   1132  1.21  macallan 		fg = WS_DEFAULT_FG;
   1133  1.21  macallan 		bg = WS_DEFAULT_BG;
   1134  1.21  macallan 	}
   1135  1.21  macallan 	if (flags & WSATTR_REVERSE) {
   1136  1.21  macallan 		*attrp = (bg & 0xff) << 24 | (fg & 0xff) << 16 |
   1137  1.21  macallan 		    (flags & 0xff) << 8;
   1138  1.21  macallan 	} else
   1139  1.21  macallan 		*attrp = (fg & 0xff) << 24 | (bg & 0xff) << 16 |
   1140  1.21  macallan 		    (flags & 0xff) << 8;
   1141  1.21  macallan 	return 0;
   1142  1.21  macallan }
   1143  1.21  macallan 
   1144  1.21  macallan /*
   1145  1.21  macallan  * wsdisplay_accessops
   1146  1.21  macallan  */
   1147  1.21  macallan 
   1148  1.21  macallan int
   1149  1.21  macallan p9100_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
   1150  1.21  macallan {
   1151  1.21  macallan 	struct p9100_softc *sc = v;
   1152  1.21  macallan 	struct wsdisplay_fbinfo *wdf;
   1153  1.21  macallan 	struct p9100_screen *ms = sc->active;
   1154  1.21  macallan 
   1155  1.21  macallan 	switch (cmd) {
   1156  1.21  macallan 		case WSDISPLAYIO_GTYPE:
   1157  1.21  macallan 			*(u_int *)data = WSDISPLAY_TYPE_SB_P9100;
   1158  1.21  macallan 			return 0;
   1159  1.21  macallan 
   1160  1.21  macallan 		case FBIOGVIDEO:
   1161  1.21  macallan 		case WSDISPLAYIO_GVIDEO:
   1162  1.21  macallan 			*(int *)data = p9100_get_video(sc);
   1163  1.21  macallan 			return 0;
   1164  1.21  macallan 
   1165  1.21  macallan 		case WSDISPLAYIO_SVIDEO:
   1166  1.21  macallan 		case FBIOSVIDEO:
   1167  1.21  macallan 			p9100_set_video(sc, *(int *)data);
   1168  1.21  macallan 			return 0;
   1169  1.21  macallan 
   1170  1.21  macallan 		case WSDISPLAYIO_GINFO:
   1171  1.21  macallan 			wdf = (void *)data;
   1172  1.21  macallan 			wdf->height = ms->ri.ri_height;
   1173  1.21  macallan 			wdf->width = ms->ri.ri_width;
   1174  1.21  macallan 			wdf->depth = ms->ri.ri_depth;
   1175  1.21  macallan 			wdf->cmsize = 256;
   1176  1.21  macallan 			return 0;
   1177  1.21  macallan 
   1178  1.21  macallan 		case WSDISPLAYIO_GETCMAP:
   1179  1.21  macallan 			return p9100_getcmap(sc, (struct wsdisplay_cmap *)data);
   1180  1.21  macallan 
   1181  1.21  macallan 		case WSDISPLAYIO_PUTCMAP:
   1182  1.21  macallan 			return p9100_putcmap(sc, (struct wsdisplay_cmap *)data);
   1183  1.21  macallan 
   1184  1.21  macallan 		case WSDISPLAYIO_SMODE:
   1185  1.21  macallan 			{
   1186  1.21  macallan 				int new_mode = *(int*)data;
   1187  1.21  macallan 				if (new_mode != sc->sc_mode)
   1188  1.21  macallan 				{
   1189  1.21  macallan 					sc->sc_mode = new_mode;
   1190  1.21  macallan 					if (new_mode == WSDISPLAYIO_MODE_EMUL)
   1191  1.21  macallan 					{
   1192  1.21  macallan 						p9100_init_engine(sc);
   1193  1.21  macallan 						p9100loadcmap(sc,0,256);
   1194  1.21  macallan 						p9100_restore_screen(ms,
   1195  1.21  macallan 						    ms->type, ms->chars);
   1196  1.21  macallan 						p9100_cursor(ms, ms->cursoron,
   1197  1.21  macallan 						    ms->cursorrow,
   1198  1.21  macallan 						    ms->cursorcol);
   1199  1.21  macallan 					}
   1200  1.21  macallan 				}
   1201  1.21  macallan 			}
   1202  1.21  macallan 	}
   1203  1.21  macallan 	return EPASSTHROUGH;
   1204  1.21  macallan }
   1205  1.21  macallan 
   1206  1.21  macallan paddr_t
   1207  1.21  macallan p9100_mmap(void *v, off_t offset, int prot)
   1208  1.21  macallan {
   1209  1.21  macallan 	struct p9100_softc *sc = v;
   1210  1.21  macallan 	paddr_t pa;
   1211  1.21  macallan 
   1212  1.21  macallan 	/* 'regular' framebuffer mmap()ing */
   1213  1.21  macallan 	if (offset < sc->sc_fb_psize) {
   1214  1.21  macallan 		pa = bus_space_mmap(sc->sc_bustag, sc->sc_fb_paddr + offset, 0,
   1215  1.21  macallan 		    prot, BUS_SPACE_MAP_LINEAR);
   1216  1.21  macallan 		return pa;
   1217  1.21  macallan 	}
   1218  1.21  macallan 
   1219  1.21  macallan 	if ((offset >= sc->sc_fb_paddr) && (offset < (sc->sc_fb_paddr +
   1220  1.21  macallan 	    sc->sc_fb_psize))) {
   1221  1.21  macallan 		pa = bus_space_mmap(sc->sc_bustag, offset, 0, prot,
   1222  1.21  macallan 		    BUS_SPACE_MAP_LINEAR);
   1223  1.21  macallan 		return pa;
   1224  1.21  macallan 	}
   1225  1.21  macallan 
   1226  1.21  macallan 	if ((offset >= sc->sc_ctl_paddr) && (offset < (sc->sc_ctl_paddr +
   1227  1.21  macallan 	    sc->sc_ctl_psize))) {
   1228  1.21  macallan 		pa = bus_space_mmap(sc->sc_bustag, offset, 0, prot,
   1229  1.21  macallan 		    BUS_SPACE_MAP_LINEAR);
   1230  1.21  macallan 		return pa;
   1231  1.21  macallan 	}
   1232  1.21  macallan 
   1233  1.21  macallan 	return -1;
   1234  1.21  macallan }
   1235  1.21  macallan 
   1236  1.21  macallan void
   1237  1.21  macallan p9100_init_screen(struct p9100_softc *sc, struct p9100_screen *scr,
   1238  1.21  macallan     int existing, long *defattr)
   1239  1.21  macallan {
   1240  1.21  macallan 	struct rasops_info *ri = &scr->ri;
   1241  1.21  macallan 	int cnt;
   1242  1.21  macallan 
   1243  1.21  macallan 	scr->sc = sc;
   1244  1.21  macallan 	/*scr->type = type;*/
   1245  1.21  macallan 	scr->dispoffset = 0;
   1246  1.21  macallan 	scr->cursorcol = 0;
   1247  1.21  macallan 	scr->cursorrow = 0;
   1248  1.21  macallan 	scr->cursordrawn=0;
   1249  1.21  macallan 
   1250  1.21  macallan 	ri->ri_depth = sc->sc_depth << 3;
   1251  1.21  macallan 	ri->ri_width = sc->sc_width;
   1252  1.21  macallan 	ri->ri_height = sc->sc_height;
   1253  1.21  macallan 	ri->ri_stride = sc->sc_stride;
   1254  1.21  macallan 	ri->ri_flg = RI_CENTER;
   1255  1.21  macallan 
   1256  1.21  macallan 	ri->ri_bits = bus_space_vaddr(sc->sc_bustag, sc->sc_fb_memh);
   1257  1.21  macallan 
   1258  1.21  macallan #ifdef DEBUG_P9100
   1259  1.21  macallan 	printf("addr: %08lx\n",(ulong)ri->ri_bits);
   1260  1.21  macallan #endif
   1261  1.21  macallan 	rasops_init(ri, sc->sc_height/8, sc->sc_width/8);
   1262  1.21  macallan 	ri->ri_caps = WSSCREEN_WSCOLORS;
   1263  1.21  macallan 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
   1264  1.21  macallan 		    sc->sc_width / ri->ri_font->fontwidth);
   1265  1.21  macallan 
   1266  1.21  macallan 	p9100_allocattr(ri, WS_DEFAULT_FG, WS_DEFAULT_BG, 0, defattr);
   1267  1.21  macallan 
   1268  1.21  macallan 	/*
   1269  1.21  macallan 	 * we allocate both chars and attributes in one chunk, attributes first
   1270  1.21  macallan 	 * because they have the (potentially) bigger alignment
   1271  1.21  macallan 	 */
   1272  1.21  macallan 	cnt=ri->ri_rows * ri->ri_cols;
   1273  1.21  macallan 	scr->attrs = (long *)malloc(cnt * (sizeof(long) + sizeof(uint16_t)),
   1274  1.21  macallan 	    M_DEVBUF, M_WAITOK);
   1275  1.21  macallan 	scr->chars = (uint16_t *)&scr->attrs[cnt];
   1276  1.21  macallan 
   1277  1.21  macallan 	/* enable acceleration */
   1278  1.21  macallan 	ri->ri_hw = scr;
   1279  1.21  macallan 	ri->ri_ops.copyrows = p9100_copyrows;
   1280  1.21  macallan 	ri->ri_ops.copycols = p9100_copycols;
   1281  1.21  macallan 	ri->ri_ops.eraserows = p9100_eraserows;
   1282  1.21  macallan 	ri->ri_ops.erasecols = p9100_erasecols;
   1283  1.21  macallan 	ri->ri_ops.cursor = p9100_cursor;
   1284  1.21  macallan 	ri->ri_ops.allocattr = p9100_allocattr;
   1285  1.21  macallan #ifdef PNOZZ_SOFT_PUTCHAR
   1286  1.21  macallan 	if (sc->putchar == NULL)
   1287  1.21  macallan 		sc->putchar=ri->ri_ops.putchar;
   1288  1.21  macallan #endif
   1289  1.21  macallan 	ri->ri_ops.putchar = p9100_putchar;
   1290  1.21  macallan 
   1291  1.21  macallan 	if (existing) {
   1292  1.21  macallan 		scr->active = 1;
   1293  1.21  macallan 	} else {
   1294  1.21  macallan 		scr->active = 0;
   1295  1.21  macallan 	}
   1296  1.21  macallan 
   1297  1.21  macallan 	p9100_eraserows(&scr->ri, 0, ri->ri_rows, *defattr);
   1298  1.21  macallan 
   1299  1.21  macallan 	LIST_INSERT_HEAD(&sc->screens, scr, next);
   1300  1.21  macallan }
   1301  1.21  macallan 
   1302  1.21  macallan int
   1303  1.21  macallan p9100_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
   1304  1.21  macallan     int *curxp, int *curyp, long *defattrp)
   1305  1.21  macallan {
   1306  1.21  macallan 	struct p9100_softc *sc = v;
   1307  1.21  macallan 	struct p9100_screen *scr;
   1308  1.21  macallan 
   1309  1.21  macallan 	scr = malloc(sizeof(struct p9100_screen), M_DEVBUF, M_WAITOK | M_ZERO);
   1310  1.21  macallan 	p9100_init_screen(sc, scr, 0, defattrp);
   1311  1.21  macallan 
   1312  1.21  macallan 	if (sc->active == NULL) {
   1313  1.21  macallan 		scr->active = 1;
   1314  1.21  macallan 		sc->active = scr;
   1315  1.21  macallan 		sc->currenttype = type;
   1316  1.21  macallan 	}
   1317  1.21  macallan 
   1318  1.21  macallan 	*cookiep = scr;
   1319  1.21  macallan 	*curxp = scr->cursorcol;
   1320  1.21  macallan 	*curyp = scr->cursorrow;
   1321  1.21  macallan 	return 0;
   1322  1.21  macallan }
   1323  1.21  macallan 
   1324  1.21  macallan void
   1325  1.21  macallan p9100_free_screen(void *v, void *cookie)
   1326  1.21  macallan {
   1327  1.21  macallan 	struct p9100_softc *sc = v;
   1328  1.21  macallan 	struct p9100_screen *scr = cookie;
   1329  1.21  macallan 
   1330  1.21  macallan 	LIST_REMOVE(scr, next);
   1331  1.21  macallan 	if (scr != &p9100_console_screen) {
   1332  1.21  macallan 		free(scr->attrs, M_DEVBUF);
   1333  1.21  macallan 		free(scr, M_DEVBUF);
   1334  1.21  macallan 	} else
   1335  1.21  macallan 		panic("p9100_free_screen: console");
   1336  1.21  macallan 
   1337  1.21  macallan 	if (sc->active == scr)
   1338  1.21  macallan 		sc->active = 0;
   1339  1.21  macallan }
   1340  1.21  macallan 
   1341  1.21  macallan int
   1342  1.21  macallan p9100_show_screen(void *v, void *cookie, int waitok,
   1343  1.21  macallan     void (*cb)(void *, int, int), void *cbarg)
   1344  1.21  macallan {
   1345  1.21  macallan 	struct p9100_softc *sc = v;
   1346  1.21  macallan 	struct p9100_screen *scr, *oldscr;
   1347  1.21  macallan 
   1348  1.21  macallan 	scr = cookie;
   1349  1.21  macallan 	oldscr = sc->active;
   1350  1.21  macallan 	if (scr == oldscr)
   1351  1.21  macallan 		return 0;
   1352  1.21  macallan 
   1353  1.21  macallan 	sc->wanted = scr;
   1354  1.21  macallan 	sc->switchcb = cb;
   1355  1.21  macallan 	sc->switchcbarg = cbarg;
   1356  1.21  macallan 	if (cb) {
   1357  1.21  macallan 		callout_reset(&sc->switch_callout, 0,
   1358  1.21  macallan 		    (void(*)(void *))p9100_switch_screen, sc);
   1359  1.21  macallan 		return EAGAIN;
   1360  1.21  macallan 	}
   1361  1.21  macallan 
   1362  1.21  macallan 	p9100_switch_screen(sc);
   1363  1.21  macallan 	return 0;
   1364  1.21  macallan }
   1365  1.21  macallan 
   1366  1.21  macallan int
   1367  1.21  macallan p9100_putcmap(struct p9100_softc *sc, struct wsdisplay_cmap *cm)
   1368  1.21  macallan {
   1369  1.21  macallan 	u_int index = cm->index;
   1370  1.21  macallan 	u_int count = cm->count;
   1371  1.21  macallan 	int i, error;
   1372  1.21  macallan 	u_char rbuf[256], gbuf[256], bbuf[256];
   1373  1.21  macallan 	u_char *r, *g, *b;
   1374  1.21  macallan 
   1375  1.21  macallan 	printf("putcmap: %d %d\n",index, count);
   1376  1.21  macallan 	if (cm->index >= 256 || cm->count > 256 ||
   1377  1.21  macallan 	    (cm->index + cm->count) > 256)
   1378  1.21  macallan 		return EINVAL;
   1379  1.21  macallan 	error = copyin(cm->red, &rbuf[index], count);
   1380  1.21  macallan 	if (error)
   1381  1.21  macallan 		return error;
   1382  1.21  macallan 	error = copyin(cm->green, &gbuf[index], count);
   1383  1.21  macallan 	if (error)
   1384  1.21  macallan 		return error;
   1385  1.21  macallan 	error = copyin(cm->blue, &bbuf[index], count);
   1386  1.21  macallan 	if (error)
   1387  1.21  macallan 		return error;
   1388  1.21  macallan 
   1389  1.21  macallan 	r = &rbuf[index];
   1390  1.21  macallan 	g = &gbuf[index];
   1391  1.21  macallan 	b = &bbuf[index];
   1392  1.21  macallan 
   1393  1.21  macallan 	for (i = 0; i < count; i++) {
   1394  1.21  macallan 		sc->sc_cmap.cm_map[index][0] = *r;
   1395  1.21  macallan 		sc->sc_cmap.cm_map[index][1] = *g;
   1396  1.21  macallan 		sc->sc_cmap.cm_map[index][2] = *b;
   1397  1.21  macallan 		index++;
   1398  1.21  macallan 		r++, g++, b++;
   1399  1.21  macallan 	}
   1400  1.21  macallan 	p9100loadcmap(sc, 0, 256);
   1401  1.21  macallan 	return 0;
   1402  1.21  macallan }
   1403  1.21  macallan 
   1404  1.21  macallan int
   1405  1.21  macallan p9100_getcmap(struct p9100_softc *sc, struct wsdisplay_cmap *cm)
   1406  1.21  macallan {
   1407  1.21  macallan 	u_int index = cm->index;
   1408  1.21  macallan 	u_int count = cm->count;
   1409  1.21  macallan 	int error, i;
   1410  1.21  macallan 	uint8_t red[256],green[256],blue[256];
   1411  1.21  macallan 
   1412  1.21  macallan 	if (index >= 255 || count > 256 || index + count > 256)
   1413  1.21  macallan 		return EINVAL;
   1414  1.21  macallan 
   1415  1.21  macallan 	i = index;
   1416  1.21  macallan 	while (i < (index + count)) {
   1417  1.21  macallan 		red[i] = sc->sc_cmap.cm_map[i][0];
   1418  1.21  macallan 		green[i] = sc->sc_cmap.cm_map[i][1];
   1419  1.21  macallan 		blue[i] = sc->sc_cmap.cm_map[i][2];
   1420  1.21  macallan 		i++;
   1421  1.21  macallan 	}
   1422  1.21  macallan 	error = copyout(&red[index],   cm->red,   count);
   1423  1.21  macallan 	if (error)
   1424  1.21  macallan 		return error;
   1425  1.21  macallan 	error = copyout(&green[index], cm->green, count);
   1426  1.21  macallan 	if (error)
   1427  1.21  macallan 		return error;
   1428  1.21  macallan 	error = copyout(&blue[index],  cm->blue,  count);
   1429  1.21  macallan 	if (error)
   1430  1.21  macallan 		return error;
   1431  1.21  macallan 
   1432  1.21  macallan 	return 0;
   1433  1.21  macallan }
   1434  1.21  macallan 
   1435  1.21  macallan #if 0
   1436  1.21  macallan int
   1437  1.21  macallan p9100_load_font(void *v, void *cookie, struct wsdisplay_font *data)
   1438  1.21  macallan {
   1439  1.21  macallan 
   1440  1.21  macallan 	return 0;
   1441  1.21  macallan }
   1442  1.21  macallan #endif
   1443  1.21  macallan 
   1444  1.21  macallan int
   1445  1.21  macallan p9100_intr(void *arg)
   1446  1.21  macallan {
   1447  1.21  macallan 	/*p9100_softc *sc=arg;
   1448  1.21  macallan 	printf(".");*/
   1449  1.21  macallan 	return 1;
   1450  1.21  macallan }
   1451