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