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