Home | History | Annotate | Line # | Download | only in sbus
agten.c revision 1.7.4.2
      1  1.7.4.2  ad /*	$NetBSD: agten.c,v 1.7.4.2 2007/10/09 13:42:03 ad Exp $ */
      2  1.7.4.2  ad 
      3  1.7.4.2  ad /*-
      4  1.7.4.2  ad  * Copyright (c) 2007 Michael Lorenz
      5  1.7.4.2  ad  * All rights reserved.
      6  1.7.4.2  ad  *
      7  1.7.4.2  ad  * Redistribution and use in source and binary forms, with or without
      8  1.7.4.2  ad  * modification, are permitted provided that the following conditions
      9  1.7.4.2  ad  * are met:
     10  1.7.4.2  ad  * 1. Redistributions of source code must retain the above copyright
     11  1.7.4.2  ad  *    notice, this list of conditions and the following disclaimer.
     12  1.7.4.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.7.4.2  ad  *    notice, this list of conditions and the following disclaimer in the
     14  1.7.4.2  ad  *    documentation and/or other materials provided with the distribution.
     15  1.7.4.2  ad  * 3. Neither the name of The NetBSD Foundation nor the names of its
     16  1.7.4.2  ad  *    contributors may be used to endorse or promote products derived
     17  1.7.4.2  ad  *    from this software without specific prior written permission.
     18  1.7.4.2  ad  *
     19  1.7.4.2  ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.7.4.2  ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.7.4.2  ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.7.4.2  ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.7.4.2  ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.7.4.2  ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.7.4.2  ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.7.4.2  ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.7.4.2  ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.7.4.2  ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.7.4.2  ad  * POSSIBILITY OF SUCH DAMAGE.
     30  1.7.4.2  ad  */
     31  1.7.4.2  ad 
     32  1.7.4.2  ad #include <sys/cdefs.h>
     33  1.7.4.2  ad __KERNEL_RCSID(0, "$NetBSD: agten.c,v 1.7.4.2 2007/10/09 13:42:03 ad Exp $");
     34  1.7.4.2  ad 
     35  1.7.4.2  ad /*
     36  1.7.4.2  ad  * a driver for the Fujitsu AG-10e SBus framebuffer
     37  1.7.4.2  ad  *
     38  1.7.4.2  ad  * this thing is Frankenstein's Monster among graphics boards.
     39  1.7.4.2  ad  * it contains three graphics chips:
     40  1.7.4.2  ad  * a GLint - 24bit stuff, double-buffered
     41  1.7.4.2  ad  * an Imagine 128 which provides an 8bit overlay
     42  1.7.4.2  ad  * a Weitek P9100 which provides WIDs
     43  1.7.4.2  ad  * so here we need to mess only with the P9100 and the I128 - for X we just
     44  1.7.4.2  ad  * hide the overlay and let the Xserver mess with the GLint
     45  1.7.4.2  ad  */
     46  1.7.4.2  ad 
     47  1.7.4.2  ad #include <sys/param.h>
     48  1.7.4.2  ad #include <sys/systm.h>
     49  1.7.4.2  ad #include <sys/kernel.h>
     50  1.7.4.2  ad #include <sys/device.h>
     51  1.7.4.2  ad #include <sys/proc.h>
     52  1.7.4.2  ad #include <sys/mutex.h>
     53  1.7.4.2  ad #include <sys/ioctl.h>
     54  1.7.4.2  ad #include <sys/kernel.h>
     55  1.7.4.2  ad #include <sys/systm.h>
     56  1.7.4.2  ad #include <sys/conf.h>
     57  1.7.4.2  ad 
     58  1.7.4.2  ad #include <dev/sun/fbio.h>
     59  1.7.4.2  ad #include <dev/sun/fbvar.h>
     60  1.7.4.2  ad #include <dev/sun/btreg.h>
     61  1.7.4.2  ad #include <dev/sun/btvar.h>
     62  1.7.4.2  ad 
     63  1.7.4.2  ad #include <machine/bus.h>
     64  1.7.4.2  ad #include <machine/autoconf.h>
     65  1.7.4.2  ad 
     66  1.7.4.2  ad #include <dev/sbus/sbusvar.h>
     67  1.7.4.2  ad 
     68  1.7.4.2  ad #include <dev/wscons/wsconsio.h>
     69  1.7.4.2  ad #include <dev/wscons/wsdisplayvar.h>
     70  1.7.4.2  ad #include <dev/rasops/rasops.h>
     71  1.7.4.2  ad #include <dev/wsfont/wsfont.h>
     72  1.7.4.2  ad 
     73  1.7.4.2  ad #include <dev/wscons/wsdisplay_vconsvar.h>
     74  1.7.4.2  ad 
     75  1.7.4.2  ad #include <dev/sbus/p9100reg.h>
     76  1.7.4.2  ad #include <dev/ic/ibm561reg.h>
     77  1.7.4.2  ad #include <dev/ic/i128reg.h>
     78  1.7.4.2  ad #include <dev/ic/i128var.h>
     79  1.7.4.2  ad 
     80  1.7.4.2  ad #include "opt_agten.h"
     81  1.7.4.2  ad 
     82  1.7.4.2  ad static int	agten_match(struct device *, struct cfdata *, void *);
     83  1.7.4.2  ad static void	agten_attach(struct device *, struct device *, void *);
     84  1.7.4.2  ad 
     85  1.7.4.2  ad static int	agten_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     86  1.7.4.2  ad static paddr_t	agten_mmap(void *, void *, off_t, int);
     87  1.7.4.2  ad static void	agten_init_screen(void *, struct vcons_screen *, int, long *);
     88  1.7.4.2  ad 
     89  1.7.4.2  ad struct agten_softc {
     90  1.7.4.2  ad 	struct device	sc_dev;		/* base device */
     91  1.7.4.2  ad 	struct sbusdev	sc_sd;		/* sbus device */
     92  1.7.4.2  ad 	struct fbdevice	sc_fb;		/* frame buffer device */
     93  1.7.4.2  ad 
     94  1.7.4.2  ad 	struct vcons_screen sc_console_screen;
     95  1.7.4.2  ad 	struct wsscreen_descr sc_defaultscreen_descr;
     96  1.7.4.2  ad 	const struct wsscreen_descr *sc_screens[1];
     97  1.7.4.2  ad 	struct wsscreen_list sc_screenlist;
     98  1.7.4.2  ad 
     99  1.7.4.2  ad 	bus_space_tag_t	sc_bustag;
    100  1.7.4.2  ad 
    101  1.7.4.2  ad 	bus_space_handle_t 	sc_i128_fbh;
    102  1.7.4.2  ad 	bus_size_t		sc_i128_fbsz;
    103  1.7.4.2  ad 	bus_space_handle_t 	sc_i128_regh;
    104  1.7.4.2  ad 	bus_space_handle_t 	sc_p9100_regh;
    105  1.7.4.2  ad 	bus_addr_t		sc_glint_fb;
    106  1.7.4.2  ad 	bus_addr_t		sc_glint_regs;
    107  1.7.4.2  ad 	uint32_t		sc_glint_fbsz;
    108  1.7.4.2  ad 
    109  1.7.4.2  ad 	uint32_t	sc_width;
    110  1.7.4.2  ad 	uint32_t	sc_height;	/* panel width / height */
    111  1.7.4.2  ad 	uint32_t	sc_stride;
    112  1.7.4.2  ad 	uint32_t	sc_depth;
    113  1.7.4.2  ad 
    114  1.7.4.2  ad 	int sc_cursor_x;
    115  1.7.4.2  ad 	int sc_cursor_y;
    116  1.7.4.2  ad 	int sc_video;			/* video output enabled */
    117  1.7.4.2  ad 
    118  1.7.4.2  ad 	/* some /dev/fb* stuff */
    119  1.7.4.2  ad 	int sc_fb_is_open;
    120  1.7.4.2  ad 
    121  1.7.4.2  ad 	union	bt_cmap sc_cmap;	/* Brooktree color map */
    122  1.7.4.2  ad 
    123  1.7.4.2  ad 	int sc_mode;
    124  1.7.4.2  ad 	uint32_t sc_bg;
    125  1.7.4.2  ad 	struct vcons_data vd;
    126  1.7.4.2  ad };
    127  1.7.4.2  ad 
    128  1.7.4.2  ad CFATTACH_DECL(agten, sizeof(struct agten_softc),
    129  1.7.4.2  ad     agten_match, agten_attach, NULL, NULL);
    130  1.7.4.2  ad 
    131  1.7.4.2  ad 
    132  1.7.4.2  ad static int	agten_putcmap(struct agten_softc *, struct wsdisplay_cmap *);
    133  1.7.4.2  ad static int 	agten_getcmap(struct agten_softc *, struct wsdisplay_cmap *);
    134  1.7.4.2  ad static int 	agten_putpalreg(struct agten_softc *, uint8_t, uint8_t,
    135  1.7.4.2  ad 			    uint8_t, uint8_t);
    136  1.7.4.2  ad static void	agten_init(struct agten_softc *);
    137  1.7.4.2  ad static void	agten_gfx(struct agten_softc *);
    138  1.7.4.2  ad static void	agten_set_video(struct agten_softc *, int);
    139  1.7.4.2  ad static int	agten_get_video(struct agten_softc *);
    140  1.7.4.2  ad 
    141  1.7.4.2  ad static void	agten_copycols(void *, int, int, int, int);
    142  1.7.4.2  ad static void	agten_erasecols(void *, int, int, int, long);
    143  1.7.4.2  ad static void	agten_copyrows(void *, int, int, int);
    144  1.7.4.2  ad static void	agten_eraserows(void *, int, int, long);
    145  1.7.4.2  ad 
    146  1.7.4.2  ad static void	agten_move_cursor(struct agten_softc *, int, int);
    147  1.7.4.2  ad static int	agten_do_cursor(struct agten_softc *sc,
    148  1.7.4.2  ad 				struct wsdisplay_cursor *);
    149  1.7.4.2  ad static int	agten_do_sun_cursor(struct agten_softc *sc,
    150  1.7.4.2  ad 				struct fbcursor *);
    151  1.7.4.2  ad 
    152  1.7.4.2  ad static uint16_t util_interleave(uint8_t, uint8_t);
    153  1.7.4.2  ad static uint16_t util_interleave_lin(uint8_t, uint8_t);
    154  1.7.4.2  ad 
    155  1.7.4.2  ad extern const u_char rasops_cmap[768];
    156  1.7.4.2  ad 
    157  1.7.4.2  ad struct wsdisplay_accessops agten_accessops = {
    158  1.7.4.2  ad 	agten_ioctl,
    159  1.7.4.2  ad 	agten_mmap,
    160  1.7.4.2  ad 	NULL,	/* alloc_screen */
    161  1.7.4.2  ad 	NULL,	/* free_screen */
    162  1.7.4.2  ad 	NULL,	/* show_screen */
    163  1.7.4.2  ad 	NULL, 	/* load_font */
    164  1.7.4.2  ad 	NULL,	/* pollc */
    165  1.7.4.2  ad 	NULL	/* scroll */
    166  1.7.4.2  ad };
    167  1.7.4.2  ad 
    168  1.7.4.2  ad /* /dev/fb* stuff */
    169  1.7.4.2  ad extern struct cfdriver agten_cd;
    170  1.7.4.2  ad 
    171  1.7.4.2  ad static int agten_fb_open(dev_t, int, int, struct lwp *);
    172  1.7.4.2  ad static int agten_fb_close(dev_t, int, int, struct lwp *);
    173  1.7.4.2  ad static int agten_fb_ioctl(dev_t, u_long, void *, int, struct lwp *);
    174  1.7.4.2  ad static paddr_t agten_fb_mmap(dev_t, off_t, int);
    175  1.7.4.2  ad static void agten_fb_unblank(struct device *);
    176  1.7.4.2  ad 
    177  1.7.4.2  ad static struct fbdriver agtenfbdriver = {
    178  1.7.4.2  ad 	agten_fb_unblank, agten_fb_open, agten_fb_close, agten_fb_ioctl,
    179  1.7.4.2  ad 	nopoll, agten_fb_mmap, nokqfilter
    180  1.7.4.2  ad };
    181  1.7.4.2  ad 
    182  1.7.4.2  ad static inline void
    183  1.7.4.2  ad agten_write_dac(struct agten_softc *sc, int reg, uint8_t val)
    184  1.7.4.2  ad {
    185  1.7.4.2  ad 	bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh,
    186  1.7.4.2  ad 	    0x200 + (reg << 2), (uint32_t)val << 16);
    187  1.7.4.2  ad }
    188  1.7.4.2  ad 
    189  1.7.4.2  ad static inline void
    190  1.7.4.2  ad agten_write_idx(struct agten_softc *sc, int offset)
    191  1.7.4.2  ad {
    192  1.7.4.2  ad 	bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh,
    193  1.7.4.2  ad 	    0x200 + (IBM561_ADDR_LOW << 2), (offset & 0xff) << 16);
    194  1.7.4.2  ad 	bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh,
    195  1.7.4.2  ad 	    0x200 + (IBM561_ADDR_HIGH << 2), ((offset >> 8) & 0xff) << 16);
    196  1.7.4.2  ad }
    197  1.7.4.2  ad 
    198  1.7.4.2  ad static inline void
    199  1.7.4.2  ad agten_write_dac_10(struct agten_softc *sc, int reg, uint16_t val)
    200  1.7.4.2  ad {
    201  1.7.4.2  ad 	agten_write_dac(sc, reg, (val >> 2) & 0xff);
    202  1.7.4.2  ad 	agten_write_dac(sc, reg, (val & 0x3) << 6);
    203  1.7.4.2  ad }
    204  1.7.4.2  ad 
    205  1.7.4.2  ad static int
    206  1.7.4.2  ad agten_match(struct device *dev, struct cfdata *cf, void *aux)
    207  1.7.4.2  ad {
    208  1.7.4.2  ad 	struct sbus_attach_args *sa = aux;
    209  1.7.4.2  ad 
    210  1.7.4.2  ad 	if (strcmp("PFU,aga", sa->sa_name) == 0)
    211  1.7.4.2  ad 		return 100;
    212  1.7.4.2  ad 	return 0;
    213  1.7.4.2  ad }
    214  1.7.4.2  ad 
    215  1.7.4.2  ad static void
    216  1.7.4.2  ad agten_attach(struct device *parent, struct device *dev, void *aux)
    217  1.7.4.2  ad {
    218  1.7.4.2  ad 	struct agten_softc *sc = (struct agten_softc *)dev;
    219  1.7.4.2  ad 	struct sbus_attach_args *sa = aux;
    220  1.7.4.2  ad 	struct fbdevice *fb = &sc->sc_fb;
    221  1.7.4.2  ad 	struct wsemuldisplaydev_attach_args aa;
    222  1.7.4.2  ad 	struct rasops_info *ri;
    223  1.7.4.2  ad 	long defattr;
    224  1.7.4.2  ad 	uint32_t reg;
    225  1.7.4.2  ad 	int node = sa->sa_node;
    226  1.7.4.2  ad 	int console;
    227  1.7.4.2  ad 
    228  1.7.4.2  ad 	sc->sc_defaultscreen_descr = (struct wsscreen_descr){
    229  1.7.4.2  ad 		"default",
    230  1.7.4.2  ad 		0, 0,
    231  1.7.4.2  ad 		NULL,
    232  1.7.4.2  ad 		8, 16,
    233  1.7.4.2  ad 		WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    234  1.7.4.2  ad 		NULL
    235  1.7.4.2  ad 	};
    236  1.7.4.2  ad 	sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
    237  1.7.4.2  ad 	sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
    238  1.7.4.2  ad 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    239  1.7.4.2  ad 	sc->sc_fb_is_open = 0;
    240  1.7.4.2  ad 	sc->sc_video = -1;
    241  1.7.4.2  ad 	sc->sc_bustag = sa->sa_bustag;
    242  1.7.4.2  ad 
    243  1.7.4.2  ad 	reg = prom_getpropint(node, "i128_fb_physaddr", -1);
    244  1.7.4.2  ad 	sc->sc_i128_fbsz = prom_getpropint(node, "i128_fb_size", -1);
    245  1.7.4.2  ad 	if (sbus_bus_map(sc->sc_bustag,
    246  1.7.4.2  ad 	    sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg,
    247  1.7.4.2  ad 	    sc->sc_i128_fbsz, BUS_SPACE_MAP_LINEAR, &sc->sc_i128_fbh) != 0) {
    248  1.7.4.2  ad 
    249  1.7.4.2  ad 		aprint_error("%s: unable to map the framebuffer\n",
    250  1.7.4.2  ad 		    dev->dv_xname);
    251  1.7.4.2  ad 		return;
    252  1.7.4.2  ad 	}
    253  1.7.4.2  ad 	fb->fb_pixels = bus_space_vaddr(sc->sc_bustag, sc->sc_i128_fbh);
    254  1.7.4.2  ad 
    255  1.7.4.2  ad 	reg = prom_getpropint(node, "i128_reg_physaddr", -1);
    256  1.7.4.2  ad 	if (sbus_bus_map(sc->sc_bustag,
    257  1.7.4.2  ad 	    sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg,
    258  1.7.4.2  ad 	    0x10000, 0, &sc->sc_i128_regh) != 0) {
    259  1.7.4.2  ad 
    260  1.7.4.2  ad 		aprint_error("%s: unable to map I128 registers\n",
    261  1.7.4.2  ad 		    dev->dv_xname);
    262  1.7.4.2  ad 		return;
    263  1.7.4.2  ad 	}
    264  1.7.4.2  ad 
    265  1.7.4.2  ad 	reg = prom_getpropint(node, "p9100_reg_physaddr", -1);
    266  1.7.4.2  ad 	if (sbus_bus_map(sc->sc_bustag,
    267  1.7.4.2  ad 	    sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg,
    268  1.7.4.2  ad 	    0x8000, 0, &sc->sc_p9100_regh) != 0) {
    269  1.7.4.2  ad 
    270  1.7.4.2  ad 		aprint_error("%s: unable to map P9100 registers\n",
    271  1.7.4.2  ad 		    dev->dv_xname);
    272  1.7.4.2  ad 		return;
    273  1.7.4.2  ad 	}
    274  1.7.4.2  ad 
    275  1.7.4.2  ad 	reg = prom_getpropint(node, "glint_fb0_physaddr", -1);
    276  1.7.4.2  ad 	sc->sc_glint_fb = sbus_bus_addr(sc->sc_bustag,
    277  1.7.4.2  ad 	    sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg);
    278  1.7.4.2  ad 	sc->sc_glint_fbsz = prom_getpropint(node, "glint_lb_size", -1);
    279  1.7.4.2  ad 	reg = prom_getpropint(node, "glint_reg_physaddr", -1);
    280  1.7.4.2  ad 	sc->sc_glint_regs = sbus_bus_addr(sc->sc_bustag,
    281  1.7.4.2  ad 	    sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg);
    282  1.7.4.2  ad 
    283  1.7.4.2  ad 	sbus_establish(&sc->sc_sd, &sc->sc_dev);
    284  1.7.4.2  ad 
    285  1.7.4.2  ad #if 0
    286  1.7.4.2  ad 	bus_intr_establish(sc->sc_bustag, sa->sa_pri, IPL_BIO,
    287  1.7.4.2  ad 	    agten_intr, sc);
    288  1.7.4.2  ad #endif
    289  1.7.4.2  ad 
    290  1.7.4.2  ad 	sc->sc_width = prom_getpropint(node, "ffb_width", 1152);
    291  1.7.4.2  ad 	sc->sc_height = prom_getpropint(node, "ffb_height", 900);
    292  1.7.4.2  ad 	sc->sc_depth = prom_getpropint(node, "ffb_depth", 8);
    293  1.7.4.2  ad 	sc->sc_stride = sc->sc_width * (sc->sc_depth >> 3);
    294  1.7.4.2  ad 
    295  1.7.4.2  ad 	printf(": %dx%d\n", sc->sc_width, sc->sc_height);
    296  1.7.4.2  ad 	agten_init(sc);
    297  1.7.4.2  ad 
    298  1.7.4.2  ad 	console = fb_is_console(node);
    299  1.7.4.2  ad 
    300  1.7.4.2  ad 	vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
    301  1.7.4.2  ad 	    &agten_accessops);
    302  1.7.4.2  ad 	sc->vd.init_screen = agten_init_screen;
    303  1.7.4.2  ad 
    304  1.7.4.2  ad 	ri = &sc->sc_console_screen.scr_ri;
    305  1.7.4.2  ad 
    306  1.7.4.2  ad 	if (console) {
    307  1.7.4.2  ad 		vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
    308  1.7.4.2  ad 		    &defattr);
    309  1.7.4.2  ad 		sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    310  1.7.4.2  ad 
    311  1.7.4.2  ad 		sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
    312  1.7.4.2  ad 		sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
    313  1.7.4.2  ad 		sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
    314  1.7.4.2  ad 		sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
    315  1.7.4.2  ad 		wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
    316  1.7.4.2  ad 		    defattr);
    317  1.7.4.2  ad 		i128_rectfill(sc->sc_bustag, sc->sc_i128_regh, 0, 0,
    318  1.7.4.2  ad 		    sc->sc_width, sc->sc_height,
    319  1.7.4.2  ad 		    ri->ri_devcmap[(defattr >> 16) & 0xff]);
    320  1.7.4.2  ad 	} else {
    321  1.7.4.2  ad 		/*
    322  1.7.4.2  ad 		 * since we're not the console we can postpone the rest
    323  1.7.4.2  ad 		 * until someone actually allocates a screen for us
    324  1.7.4.2  ad 		 */
    325  1.7.4.2  ad 	}
    326  1.7.4.2  ad 
    327  1.7.4.2  ad 	/* Initialize the default color map. */
    328  1.7.4.2  ad 
    329  1.7.4.2  ad 	aa.console = console;
    330  1.7.4.2  ad 	aa.scrdata = &sc->sc_screenlist;
    331  1.7.4.2  ad 	aa.accessops = &agten_accessops;
    332  1.7.4.2  ad 	aa.accesscookie = &sc->vd;
    333  1.7.4.2  ad 
    334  1.7.4.2  ad 	config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
    335  1.7.4.2  ad 
    336  1.7.4.2  ad 	fb->fb_driver = &agtenfbdriver;
    337  1.7.4.2  ad 	fb->fb_device = &sc->sc_dev;
    338  1.7.4.2  ad 	fb->fb_flags = device_cfdata(&sc->sc_dev)->cf_flags & FB_USERMASK;
    339  1.7.4.2  ad 	fb->fb_type.fb_type = FBTYPE_AG10E;
    340  1.7.4.2  ad 	fb->fb_type.fb_cmsize = 256;	/* doesn't matter, we're always 24bit */
    341  1.7.4.2  ad 	fb->fb_type.fb_size = sc->sc_glint_fbsz;
    342  1.7.4.2  ad 	fb->fb_type.fb_width = sc->sc_width;
    343  1.7.4.2  ad 	fb->fb_type.fb_height = sc->sc_height;
    344  1.7.4.2  ad 	fb->fb_type.fb_depth = 32;
    345  1.7.4.2  ad 	fb->fb_linebytes = sc->sc_stride;
    346  1.7.4.2  ad 	fb_attach(fb, console);
    347  1.7.4.2  ad 	agten_set_video(sc, 1);	/* make sure video's on */
    348  1.7.4.2  ad }
    349  1.7.4.2  ad 
    350  1.7.4.2  ad static int
    351  1.7.4.2  ad agten_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    352  1.7.4.2  ad 	struct lwp *l)
    353  1.7.4.2  ad {
    354  1.7.4.2  ad 	struct vcons_data *vd = v;
    355  1.7.4.2  ad 	struct agten_softc *sc = vd->cookie;
    356  1.7.4.2  ad 	struct wsdisplay_fbinfo *wdf;
    357  1.7.4.2  ad 	struct vcons_screen *ms = vd->active;
    358  1.7.4.2  ad 
    359  1.7.4.2  ad 	switch (cmd) {
    360  1.7.4.2  ad 
    361  1.7.4.2  ad 		case WSDISPLAYIO_GTYPE:
    362  1.7.4.2  ad 			*(u_int *)data = WSDISPLAY_TYPE_AG10;
    363  1.7.4.2  ad 			return 0;
    364  1.7.4.2  ad 
    365  1.7.4.2  ad 		case WSDISPLAYIO_GINFO:
    366  1.7.4.2  ad 			if (ms == NULL)
    367  1.7.4.2  ad 				return ENODEV;
    368  1.7.4.2  ad 			wdf = (void *)data;
    369  1.7.4.2  ad 			wdf->height = ms->scr_ri.ri_height;
    370  1.7.4.2  ad 			wdf->width = ms->scr_ri.ri_width;
    371  1.7.4.2  ad 			wdf->depth = 32;
    372  1.7.4.2  ad 			wdf->cmsize = 256;
    373  1.7.4.2  ad 			return 0;
    374  1.7.4.2  ad 
    375  1.7.4.2  ad 		case WSDISPLAYIO_GVIDEO:
    376  1.7.4.2  ad 			*(int *)data = sc->sc_video;
    377  1.7.4.2  ad 			return 0;
    378  1.7.4.2  ad 
    379  1.7.4.2  ad 		case WSDISPLAYIO_SVIDEO:
    380  1.7.4.2  ad 			agten_set_video(sc, *(int *)data);
    381  1.7.4.2  ad 			return 0;
    382  1.7.4.2  ad 
    383  1.7.4.2  ad 		case WSDISPLAYIO_GETCMAP:
    384  1.7.4.2  ad 			return agten_getcmap(sc,
    385  1.7.4.2  ad 			    (struct wsdisplay_cmap *)data);
    386  1.7.4.2  ad 
    387  1.7.4.2  ad 		case WSDISPLAYIO_PUTCMAP:
    388  1.7.4.2  ad 			return agten_putcmap(sc,
    389  1.7.4.2  ad 			    (struct wsdisplay_cmap *)data);
    390  1.7.4.2  ad 
    391  1.7.4.2  ad 		case WSDISPLAYIO_LINEBYTES:
    392  1.7.4.2  ad 			*(u_int *)data = sc->sc_stride << 2;
    393  1.7.4.2  ad 			return 0;
    394  1.7.4.2  ad 
    395  1.7.4.2  ad 		case WSDISPLAYIO_SMODE:
    396  1.7.4.2  ad 			{
    397  1.7.4.2  ad 				int new_mode = *(int*)data;
    398  1.7.4.2  ad 				if (new_mode != sc->sc_mode) {
    399  1.7.4.2  ad 					sc->sc_mode = new_mode;
    400  1.7.4.2  ad 					if(new_mode == WSDISPLAYIO_MODE_EMUL) {
    401  1.7.4.2  ad 						agten_init(sc);
    402  1.7.4.2  ad 						vcons_redraw_screen(ms);
    403  1.7.4.2  ad 					} else {
    404  1.7.4.2  ad 						agten_gfx(sc);
    405  1.7.4.2  ad 					}
    406  1.7.4.2  ad 				}
    407  1.7.4.2  ad 			}
    408  1.7.4.2  ad 			return 0;
    409  1.7.4.2  ad 
    410  1.7.4.2  ad 		case WSDISPLAYIO_GCURPOS:
    411  1.7.4.2  ad 			{
    412  1.7.4.2  ad 				struct wsdisplay_curpos *cp = (void *)data;
    413  1.7.4.2  ad 
    414  1.7.4.2  ad 				cp->x = sc->sc_cursor_x;
    415  1.7.4.2  ad 				cp->y = sc->sc_cursor_y;
    416  1.7.4.2  ad 			}
    417  1.7.4.2  ad 			return 0;
    418  1.7.4.2  ad 
    419  1.7.4.2  ad 		case WSDISPLAYIO_SCURPOS:
    420  1.7.4.2  ad 			{
    421  1.7.4.2  ad 				struct wsdisplay_curpos *cp = (void *)data;
    422  1.7.4.2  ad 
    423  1.7.4.2  ad 				agten_move_cursor(sc, cp->x, cp->y);
    424  1.7.4.2  ad 			}
    425  1.7.4.2  ad 			return 0;
    426  1.7.4.2  ad 
    427  1.7.4.2  ad 		case WSDISPLAYIO_GCURMAX:
    428  1.7.4.2  ad 			{
    429  1.7.4.2  ad 				struct wsdisplay_curpos *cp = (void *)data;
    430  1.7.4.2  ad 
    431  1.7.4.2  ad 				cp->x = 64;
    432  1.7.4.2  ad 				cp->y = 64;
    433  1.7.4.2  ad 			}
    434  1.7.4.2  ad 			return 0;
    435  1.7.4.2  ad 
    436  1.7.4.2  ad 		case WSDISPLAYIO_SCURSOR:
    437  1.7.4.2  ad 			{
    438  1.7.4.2  ad 				struct wsdisplay_cursor *cursor = (void *)data;
    439  1.7.4.2  ad 
    440  1.7.4.2  ad 				return agten_do_cursor(sc, cursor);
    441  1.7.4.2  ad 			}
    442  1.7.4.2  ad 	}
    443  1.7.4.2  ad 	return EPASSTHROUGH;
    444  1.7.4.2  ad }
    445  1.7.4.2  ad 
    446  1.7.4.2  ad static paddr_t
    447  1.7.4.2  ad agten_mmap(void *v, void *vs, off_t offset, int prot)
    448  1.7.4.2  ad {
    449  1.7.4.2  ad 	struct vcons_data *vd = v;
    450  1.7.4.2  ad 	struct agten_softc *sc = vd->cookie;
    451  1.7.4.2  ad 
    452  1.7.4.2  ad 	if (offset < sc->sc_glint_fbsz)
    453  1.7.4.2  ad 		return bus_space_mmap(sc->sc_bustag, sc->sc_glint_fb, offset,
    454  1.7.4.2  ad 		    prot, BUS_SPACE_MAP_LINEAR);
    455  1.7.4.2  ad 	return -1;
    456  1.7.4.2  ad }
    457  1.7.4.2  ad 
    458  1.7.4.2  ad static void
    459  1.7.4.2  ad agten_init_screen(void *cookie, struct vcons_screen *scr,
    460  1.7.4.2  ad     int existing, long *defattr)
    461  1.7.4.2  ad {
    462  1.7.4.2  ad 	struct agten_softc *sc = cookie;
    463  1.7.4.2  ad 	struct rasops_info *ri = &scr->scr_ri;
    464  1.7.4.2  ad 
    465  1.7.4.2  ad 	ri->ri_depth = sc->sc_depth;
    466  1.7.4.2  ad 	ri->ri_width = sc->sc_width;
    467  1.7.4.2  ad 	ri->ri_height = sc->sc_height;
    468  1.7.4.2  ad 	ri->ri_stride = sc->sc_stride;
    469  1.7.4.2  ad 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
    470  1.7.4.2  ad 
    471  1.7.4.2  ad 	ri->ri_bits = (char *)sc->sc_fb.fb_pixels;
    472  1.7.4.2  ad 
    473  1.7.4.2  ad 	if (existing) {
    474  1.7.4.2  ad 		ri->ri_flg |= RI_CLEAR;
    475  1.7.4.2  ad 	}
    476  1.7.4.2  ad 
    477  1.7.4.2  ad 	rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
    478  1.7.4.2  ad 	ri->ri_caps = WSSCREEN_WSCOLORS;
    479  1.7.4.2  ad 
    480  1.7.4.2  ad 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
    481  1.7.4.2  ad 		    sc->sc_width / ri->ri_font->fontwidth);
    482  1.7.4.2  ad 
    483  1.7.4.2  ad 	ri->ri_hw = scr;
    484  1.7.4.2  ad 	ri->ri_ops.copyrows  = agten_copyrows;
    485  1.7.4.2  ad 	ri->ri_ops.eraserows = agten_eraserows;
    486  1.7.4.2  ad 	ri->ri_ops.copycols  = agten_copycols;
    487  1.7.4.2  ad 	ri->ri_ops.erasecols = agten_erasecols;
    488  1.7.4.2  ad 
    489  1.7.4.2  ad }
    490  1.7.4.2  ad 
    491  1.7.4.2  ad static int
    492  1.7.4.2  ad agten_putcmap(struct agten_softc *sc, struct wsdisplay_cmap *cm)
    493  1.7.4.2  ad {
    494  1.7.4.2  ad 	u_int index = cm->index;
    495  1.7.4.2  ad 	u_int count = cm->count;
    496  1.7.4.2  ad 	int i, error;
    497  1.7.4.2  ad 	u_char rbuf[256], gbuf[256], bbuf[256];
    498  1.7.4.2  ad 	u_char *r, *g, *b;
    499  1.7.4.2  ad 
    500  1.7.4.2  ad 	if (cm->index >= 256 || cm->count > 256 ||
    501  1.7.4.2  ad 	    (cm->index + cm->count) > 256)
    502  1.7.4.2  ad 		return EINVAL;
    503  1.7.4.2  ad 	error = copyin(cm->red, &rbuf[index], count);
    504  1.7.4.2  ad 	if (error)
    505  1.7.4.2  ad 		return error;
    506  1.7.4.2  ad 	error = copyin(cm->green, &gbuf[index], count);
    507  1.7.4.2  ad 	if (error)
    508  1.7.4.2  ad 		return error;
    509  1.7.4.2  ad 	error = copyin(cm->blue, &bbuf[index], count);
    510  1.7.4.2  ad 	if (error)
    511  1.7.4.2  ad 		return error;
    512  1.7.4.2  ad 
    513  1.7.4.2  ad 	r = &rbuf[index];
    514  1.7.4.2  ad 	g = &gbuf[index];
    515  1.7.4.2  ad 	b = &bbuf[index];
    516  1.7.4.2  ad 
    517  1.7.4.2  ad 	for (i = 0; i < count; i++) {
    518  1.7.4.2  ad 		agten_putpalreg(sc, index, *r, *g, *b);
    519  1.7.4.2  ad 		index++;
    520  1.7.4.2  ad 		r++, g++, b++;
    521  1.7.4.2  ad 	}
    522  1.7.4.2  ad 	return 0;
    523  1.7.4.2  ad }
    524  1.7.4.2  ad 
    525  1.7.4.2  ad static int
    526  1.7.4.2  ad agten_getcmap(struct agten_softc *sc, struct wsdisplay_cmap *cm)
    527  1.7.4.2  ad {
    528  1.7.4.2  ad 	u_int index = cm->index;
    529  1.7.4.2  ad 	u_int count = cm->count;
    530  1.7.4.2  ad 	int error, i;
    531  1.7.4.2  ad 	uint8_t red[256], green[256], blue[256];
    532  1.7.4.2  ad 
    533  1.7.4.2  ad 	if (index >= 255 || count > 256 || index + count > 256)
    534  1.7.4.2  ad 		return EINVAL;
    535  1.7.4.2  ad 
    536  1.7.4.2  ad 	i = index;
    537  1.7.4.2  ad 	while (i < (index + count)) {
    538  1.7.4.2  ad 		red[i] = sc->sc_cmap.cm_map[i][0];
    539  1.7.4.2  ad 		green[i] = sc->sc_cmap.cm_map[i][1];
    540  1.7.4.2  ad 		blue[i] = sc->sc_cmap.cm_map[i][2];
    541  1.7.4.2  ad 		i++;
    542  1.7.4.2  ad 	}
    543  1.7.4.2  ad 	error = copyout(&red[index],   cm->red,   count);
    544  1.7.4.2  ad 	if (error)
    545  1.7.4.2  ad 		return error;
    546  1.7.4.2  ad 	error = copyout(&green[index], cm->green, count);
    547  1.7.4.2  ad 	if (error)
    548  1.7.4.2  ad 		return error;
    549  1.7.4.2  ad 	error = copyout(&blue[index],  cm->blue,  count);
    550  1.7.4.2  ad 	if (error)
    551  1.7.4.2  ad 		return error;
    552  1.7.4.2  ad 
    553  1.7.4.2  ad 	return 0;
    554  1.7.4.2  ad }
    555  1.7.4.2  ad 
    556  1.7.4.2  ad static int
    557  1.7.4.2  ad agten_putpalreg(struct agten_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
    558  1.7.4.2  ad     uint8_t b)
    559  1.7.4.2  ad {
    560  1.7.4.2  ad 
    561  1.7.4.2  ad 	sc->sc_cmap.cm_map[idx][0] = r;
    562  1.7.4.2  ad 	sc->sc_cmap.cm_map[idx][1] = g;
    563  1.7.4.2  ad 	sc->sc_cmap.cm_map[idx][2] = b;
    564  1.7.4.2  ad 	agten_write_idx(sc, IBM561_CMAP_TABLE + idx);
    565  1.7.4.2  ad 	agten_write_dac(sc, IBM561_CMD_CMAP, r);
    566  1.7.4.2  ad 	agten_write_dac(sc, IBM561_CMD_CMAP, g);
    567  1.7.4.2  ad 	agten_write_dac(sc, IBM561_CMD_CMAP, b);
    568  1.7.4.2  ad 	return 0;
    569  1.7.4.2  ad }
    570  1.7.4.2  ad 
    571  1.7.4.2  ad static void
    572  1.7.4.2  ad agten_init(struct agten_softc *sc)
    573  1.7.4.2  ad {
    574  1.7.4.2  ad 	int i, j;
    575  1.7.4.2  ad 	uint32_t src, srcw;
    576  1.7.4.2  ad 	volatile uint32_t junk;
    577  1.7.4.2  ad 
    578  1.7.4.2  ad 	/* first we set up the colour map */
    579  1.7.4.2  ad 	j = 0;
    580  1.7.4.2  ad 	for (i = 0; i < 256; i++) {
    581  1.7.4.2  ad 
    582  1.7.4.2  ad 		agten_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
    583  1.7.4.2  ad 		    rasops_cmap[j + 2]);
    584  1.7.4.2  ad 		j += 3;
    585  1.7.4.2  ad 	}
    586  1.7.4.2  ad 
    587  1.7.4.2  ad 	/* then we set up a linear LUT for 24bit colour */
    588  1.7.4.2  ad 	agten_write_idx(sc, IBM561_CMAP_TABLE + 256);
    589  1.7.4.2  ad 	for (i = 0; i < 256; i++) {
    590  1.7.4.2  ad 		agten_write_dac(sc, IBM561_CMD_CMAP, i);
    591  1.7.4.2  ad 		agten_write_dac(sc, IBM561_CMD_CMAP, i);
    592  1.7.4.2  ad 		agten_write_dac(sc, IBM561_CMD_CMAP, i);
    593  1.7.4.2  ad 	}
    594  1.7.4.2  ad 
    595  1.7.4.2  ad 	/* and the linear gamma maps */
    596  1.7.4.2  ad 	agten_write_idx(sc, IBM561_RED_GAMMA_TABLE);
    597  1.7.4.2  ad 	for (i = 0; i < 0x3ff; i+= 4)
    598  1.7.4.2  ad 		agten_write_dac_10(sc, IBM561_CMD_GAMMA, i);
    599  1.7.4.2  ad 	agten_write_idx(sc, IBM561_GREEN_GAMMA_TABLE);
    600  1.7.4.2  ad 	for (i = 0; i < 0x3ff; i+= 4)
    601  1.7.4.2  ad 		agten_write_dac_10(sc, IBM561_CMD_GAMMA, i);
    602  1.7.4.2  ad 	agten_write_idx(sc, IBM561_BLUE_GAMMA_TABLE);
    603  1.7.4.2  ad 	for (i = 0; i < 0x3ff; i+= 4)
    604  1.7.4.2  ad 		agten_write_dac_10(sc, IBM561_CMD_GAMMA, i);
    605  1.7.4.2  ad 
    606  1.7.4.2  ad 	/* enable outouts, RGB mode */
    607  1.7.4.2  ad 	agten_write_idx(sc, IBM561_CONFIG_REG3);
    608  1.7.4.2  ad 	agten_write_dac(sc, IBM561_CMD, 0x41);
    609  1.7.4.2  ad 
    610  1.7.4.2  ad 	/* MUX 4:1 basic, 8bit overlay, 8bit WIDs */
    611  1.7.4.2  ad 	agten_write_idx(sc, IBM561_CONFIG_REG1);
    612  1.7.4.2  ad 	agten_write_dac(sc, IBM561_CMD, 0x2c);
    613  1.7.4.2  ad 
    614  1.7.4.2  ad 	/* use internal PLL, enable video output */
    615  1.7.4.2  ad 	agten_write_idx(sc, IBM561_CONFIG_REG2);
    616  1.7.4.2  ad 	agten_write_dac(sc, IBM561_CMD, CR2_ENABLE_CLC | CR2_PLL_REF_SELECT |
    617  1.7.4.2  ad 	    CR2_PIXEL_CLOCK_SELECT | CR2_ENABLE_RGB_OUTPUT);
    618  1.7.4.2  ad 
    619  1.7.4.2  ad 	/* now set up some window attributes */
    620  1.7.4.2  ad 
    621  1.7.4.2  ad 	/*
    622  1.7.4.2  ad 	 * direct colour, 24 bit, transparency off, LUT from 0x100
    623  1.7.4.2  ad 	 * we need to use direct colour and a linear LUT because for some
    624  1.7.4.2  ad 	 * reason true color mode gives messed up colours
    625  1.7.4.2  ad 	 */
    626  1.7.4.2  ad 	agten_write_idx(sc, IBM561_FB_WINTYPE);
    627  1.7.4.2  ad 	agten_write_dac_10(sc, IBM561_CMD_FB_WAT, 0x134);
    628  1.7.4.2  ad 
    629  1.7.4.2  ad 	/* use gamma LUTs, no crosshair, 0 is transparent */
    630  1.7.4.2  ad 	agten_write_idx(sc, IBM561_AUXFB_WINTYPE);
    631  1.7.4.2  ad 	agten_write_dac(sc, IBM561_CMD_FB_WAT, 0x0);
    632  1.7.4.2  ad 
    633  1.7.4.2  ad 	/* overlay is 8 bit, opaque */
    634  1.7.4.2  ad 	agten_write_idx(sc, IBM561_OL_WINTYPE);
    635  1.7.4.2  ad 	agten_write_dac_10(sc, IBM561_CMD_FB_WAT, 0x00);
    636  1.7.4.2  ad 
    637  1.7.4.2  ad 	/* now we fill the WID fb with zeroes */
    638  1.7.4.2  ad 	src = 0;
    639  1.7.4.2  ad 	srcw = sc->sc_width << 16 | sc->sc_height;
    640  1.7.4.2  ad 	bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, FOREGROUND_COLOR,
    641  1.7.4.2  ad 	    0x0);
    642  1.7.4.2  ad 	bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, BACKGROUND_COLOR,
    643  1.7.4.2  ad 	    0x0);
    644  1.7.4.2  ad 	bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, RASTER_OP, ROP_PAT);
    645  1.7.4.2  ad 	bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, COORD_INDEX, 0);
    646  1.7.4.2  ad 	bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, RECT_RTW_XY, src);
    647  1.7.4.2  ad 	bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, RECT_RTW_XY, srcw);
    648  1.7.4.2  ad 	junk = bus_space_read_4(sc->sc_bustag, sc->sc_p9100_regh, COMMAND_QUAD);
    649  1.7.4.2  ad 
    650  1.7.4.2  ad 	/* initialize the cursor registers */
    651  1.7.4.2  ad 
    652  1.7.4.2  ad 	/* initialize the Imagine 128 */
    653  1.7.4.2  ad 	i128_init(sc->sc_bustag, sc->sc_i128_regh, sc->sc_stride, 8);
    654  1.7.4.2  ad }
    655  1.7.4.2  ad 
    656  1.7.4.2  ad static void
    657  1.7.4.2  ad agten_gfx(struct agten_softc *sc)
    658  1.7.4.2  ad {
    659  1.7.4.2  ad 	/* enable overlay transparency on colour 0x00 */
    660  1.7.4.2  ad 	agten_write_idx(sc, IBM561_OL_WINTYPE);
    661  1.7.4.2  ad 	agten_write_dac_10(sc, IBM561_CMD_FB_WAT, 0x01);
    662  1.7.4.2  ad 
    663  1.7.4.2  ad 	/* then blit the overlay full of 0x00 */
    664  1.7.4.2  ad 	i128_rectfill(sc->sc_bustag, sc->sc_i128_regh, 0, 0, sc->sc_width,
    665  1.7.4.2  ad 	    sc->sc_height, 0);
    666  1.7.4.2  ad 
    667  1.7.4.2  ad 	/* ... so we can see the 24bit framebuffer */
    668  1.7.4.2  ad }
    669  1.7.4.2  ad 
    670  1.7.4.2  ad static void
    671  1.7.4.2  ad agten_set_video(struct agten_softc *sc, int flag)
    672  1.7.4.2  ad {
    673  1.7.4.2  ad 	uint8_t reg =
    674  1.7.4.2  ad 	    CR2_ENABLE_CLC | CR2_PLL_REF_SELECT | CR2_PIXEL_CLOCK_SELECT;
    675  1.7.4.2  ad 
    676  1.7.4.2  ad 	if (flag == sc->sc_video)
    677  1.7.4.2  ad 		return;
    678  1.7.4.2  ad 
    679  1.7.4.2  ad 	agten_write_idx(sc, IBM561_CONFIG_REG2);
    680  1.7.4.2  ad 	agten_write_dac(sc, IBM561_CMD, flag ? reg | CR2_ENABLE_RGB_OUTPUT :
    681  1.7.4.2  ad 	    reg);
    682  1.7.4.2  ad 
    683  1.7.4.2  ad 	sc->sc_video = flag;
    684  1.7.4.2  ad }
    685  1.7.4.2  ad 
    686  1.7.4.2  ad static int
    687  1.7.4.2  ad agten_get_video(struct agten_softc *sc)
    688  1.7.4.2  ad {
    689  1.7.4.2  ad 
    690  1.7.4.2  ad 	return sc->sc_video;
    691  1.7.4.2  ad }
    692  1.7.4.2  ad 
    693  1.7.4.2  ad static void
    694  1.7.4.2  ad agten_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
    695  1.7.4.2  ad {
    696  1.7.4.2  ad 	struct rasops_info *ri = cookie;
    697  1.7.4.2  ad 	struct vcons_screen *scr = ri->ri_hw;
    698  1.7.4.2  ad 	struct agten_softc *sc = scr->scr_cookie;
    699  1.7.4.2  ad 	int32_t xs, xd, y, width, height;
    700  1.7.4.2  ad 
    701  1.7.4.2  ad 	xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
    702  1.7.4.2  ad 	xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
    703  1.7.4.2  ad 	y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    704  1.7.4.2  ad 	width = ri->ri_font->fontwidth * ncols;
    705  1.7.4.2  ad 	height = ri->ri_font->fontheight;
    706  1.7.4.2  ad 	i128_bitblt(sc->sc_bustag, sc->sc_i128_regh, xs, y, xd, y, width,
    707  1.7.4.2  ad 	    height, CR_COPY);
    708  1.7.4.2  ad }
    709  1.7.4.2  ad 
    710  1.7.4.2  ad static void
    711  1.7.4.2  ad agten_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
    712  1.7.4.2  ad {
    713  1.7.4.2  ad 	struct rasops_info *ri = cookie;
    714  1.7.4.2  ad 	struct vcons_screen *scr = ri->ri_hw;
    715  1.7.4.2  ad 	struct agten_softc *sc = scr->scr_cookie;
    716  1.7.4.2  ad 	int32_t x, y, width, height, bg;
    717  1.7.4.2  ad 
    718  1.7.4.2  ad 	x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
    719  1.7.4.2  ad 	y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    720  1.7.4.2  ad 	width = ri->ri_font->fontwidth * ncols;
    721  1.7.4.2  ad 	height = ri->ri_font->fontheight;
    722  1.7.4.2  ad 	bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
    723  1.7.4.2  ad 	i128_rectfill(sc->sc_bustag, sc->sc_i128_regh, x, y, width, height, bg);
    724  1.7.4.2  ad }
    725  1.7.4.2  ad 
    726  1.7.4.2  ad static void
    727  1.7.4.2  ad agten_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
    728  1.7.4.2  ad {
    729  1.7.4.2  ad 	struct rasops_info *ri = cookie;
    730  1.7.4.2  ad 	struct vcons_screen *scr = ri->ri_hw;
    731  1.7.4.2  ad 	struct agten_softc *sc = scr->scr_cookie;
    732  1.7.4.2  ad 	int32_t x, ys, yd, width, height;
    733  1.7.4.2  ad 
    734  1.7.4.2  ad 	x = ri->ri_xorigin;
    735  1.7.4.2  ad 	ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
    736  1.7.4.2  ad 	yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
    737  1.7.4.2  ad 	width = ri->ri_emuwidth;
    738  1.7.4.2  ad 	height = ri->ri_font->fontheight * nrows;
    739  1.7.4.2  ad 	i128_bitblt(sc->sc_bustag, sc->sc_i128_regh, x, ys, x, yd, width,
    740  1.7.4.2  ad 	    height, CR_COPY);
    741  1.7.4.2  ad }
    742  1.7.4.2  ad 
    743  1.7.4.2  ad static void
    744  1.7.4.2  ad agten_eraserows(void *cookie, int row, int nrows, long fillattr)
    745  1.7.4.2  ad {
    746  1.7.4.2  ad 	struct rasops_info *ri = cookie;
    747  1.7.4.2  ad 	struct vcons_screen *scr = ri->ri_hw;
    748  1.7.4.2  ad 	struct agten_softc *sc = scr->scr_cookie;
    749  1.7.4.2  ad 	int32_t x, y, width, height, bg;
    750  1.7.4.2  ad 
    751  1.7.4.2  ad 	if ((row == 0) && (nrows == ri->ri_rows)) {
    752  1.7.4.2  ad 		x = y = 0;
    753  1.7.4.2  ad 		width = ri->ri_width;
    754  1.7.4.2  ad 		height = ri->ri_height;
    755  1.7.4.2  ad 	} else {
    756  1.7.4.2  ad 		x = ri->ri_xorigin;
    757  1.7.4.2  ad 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    758  1.7.4.2  ad 		width = ri->ri_emuwidth;
    759  1.7.4.2  ad 		height = ri->ri_font->fontheight * nrows;
    760  1.7.4.2  ad 	}
    761  1.7.4.2  ad 	bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
    762  1.7.4.2  ad 	i128_rectfill(sc->sc_bustag, sc->sc_i128_regh, x, y, width, height, bg);
    763  1.7.4.2  ad }
    764  1.7.4.2  ad 
    765  1.7.4.2  ad static void
    766  1.7.4.2  ad agten_move_cursor(struct agten_softc *sc, int x, int y)
    767  1.7.4.2  ad {
    768  1.7.4.2  ad 
    769  1.7.4.2  ad 	sc->sc_cursor_x = x;
    770  1.7.4.2  ad 	sc->sc_cursor_y = y;
    771  1.7.4.2  ad 	agten_write_idx(sc, IBM561_CURSOR_X_REG);
    772  1.7.4.2  ad 	agten_write_dac(sc, IBM561_CMD, x & 0xff);
    773  1.7.4.2  ad 	agten_write_dac(sc, IBM561_CMD, (x >> 8) & 0xff);
    774  1.7.4.2  ad 	agten_write_dac(sc, IBM561_CMD, y & 0xff);
    775  1.7.4.2  ad 	agten_write_dac(sc, IBM561_CMD, (y >> 8) & 0xff);
    776  1.7.4.2  ad }
    777  1.7.4.2  ad 
    778  1.7.4.2  ad static int
    779  1.7.4.2  ad agten_do_cursor(struct agten_softc *sc, struct wsdisplay_cursor *cur)
    780  1.7.4.2  ad {
    781  1.7.4.2  ad 	if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
    782  1.7.4.2  ad 
    783  1.7.4.2  ad 		agten_write_idx(sc, IBM561_CURS_CNTL_REG);
    784  1.7.4.2  ad 		agten_write_dac(sc, IBM561_CMD, cur->enable ?
    785  1.7.4.2  ad 		    CURS_ENABLE : 0);
    786  1.7.4.2  ad 	}
    787  1.7.4.2  ad 	if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
    788  1.7.4.2  ad 
    789  1.7.4.2  ad 		agten_write_idx(sc, IBM561_HOTSPOT_X_REG);
    790  1.7.4.2  ad 		agten_write_dac(sc, IBM561_CMD, cur->hot.x);
    791  1.7.4.2  ad 		agten_write_dac(sc, IBM561_CMD, cur->hot.y);
    792  1.7.4.2  ad 	}
    793  1.7.4.2  ad 	if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
    794  1.7.4.2  ad 
    795  1.7.4.2  ad 		agten_move_cursor(sc, cur->pos.x, cur->pos.y);
    796  1.7.4.2  ad 	}
    797  1.7.4.2  ad 	if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
    798  1.7.4.2  ad 		int i;
    799  1.7.4.2  ad 
    800  1.7.4.2  ad 		agten_write_idx(sc, IBM561_CURSOR_LUT + cur->cmap.index + 2);
    801  1.7.4.2  ad 		for (i = 0; i < cur->cmap.count; i++) {
    802  1.7.4.2  ad 			agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.red[i]);
    803  1.7.4.2  ad 			agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.green[i]);
    804  1.7.4.2  ad 			agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.blue[i]);
    805  1.7.4.2  ad 		}
    806  1.7.4.2  ad 	}
    807  1.7.4.2  ad 	if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
    808  1.7.4.2  ad 		int i;
    809  1.7.4.2  ad 		uint16_t tmp;
    810  1.7.4.2  ad 
    811  1.7.4.2  ad 		agten_write_idx(sc, IBM561_CURSOR_BITMAP);
    812  1.7.4.2  ad 		for (i = 0; i < 512; i++) {
    813  1.7.4.2  ad 			tmp = util_interleave(cur->mask[i], cur->image[i]);
    814  1.7.4.2  ad 			agten_write_dac(sc, IBM561_CMD, (tmp >> 8) & 0xff);
    815  1.7.4.2  ad 			agten_write_dac(sc, IBM561_CMD, tmp & 0xff);
    816  1.7.4.2  ad 		}
    817  1.7.4.2  ad 	}
    818  1.7.4.2  ad 	return 0;
    819  1.7.4.2  ad }
    820  1.7.4.2  ad 
    821  1.7.4.2  ad static int
    822  1.7.4.2  ad agten_do_sun_cursor(struct agten_softc *sc, struct fbcursor *cur)
    823  1.7.4.2  ad {
    824  1.7.4.2  ad 	if (cur->set & FB_CUR_SETCUR) {
    825  1.7.4.2  ad 
    826  1.7.4.2  ad 		agten_write_idx(sc, IBM561_CURS_CNTL_REG);
    827  1.7.4.2  ad 		agten_write_dac(sc, IBM561_CMD, cur->enable ?
    828  1.7.4.2  ad 		    CURS_ENABLE : 0);
    829  1.7.4.2  ad 	}
    830  1.7.4.2  ad 	if (cur->set & FB_CUR_SETHOT) {
    831  1.7.4.2  ad 
    832  1.7.4.2  ad 		agten_write_idx(sc, IBM561_HOTSPOT_X_REG);
    833  1.7.4.2  ad 		agten_write_dac(sc, IBM561_CMD, cur->hot.x);
    834  1.7.4.2  ad 		agten_write_dac(sc, IBM561_CMD, cur->hot.y);
    835  1.7.4.2  ad 	}
    836  1.7.4.2  ad 	if (cur->set & FB_CUR_SETPOS) {
    837  1.7.4.2  ad 
    838  1.7.4.2  ad 		agten_move_cursor(sc, cur->pos.x, cur->pos.y);
    839  1.7.4.2  ad 	}
    840  1.7.4.2  ad 	if (cur->set & FB_CUR_SETCMAP) {
    841  1.7.4.2  ad 		int i;
    842  1.7.4.2  ad 
    843  1.7.4.2  ad 		agten_write_idx(sc, IBM561_CURSOR_LUT + cur->cmap.index + 2);
    844  1.7.4.2  ad 		for (i = 0; i < cur->cmap.count; i++) {
    845  1.7.4.2  ad 			agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.red[i]);
    846  1.7.4.2  ad 			agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.green[i]);
    847  1.7.4.2  ad 			agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.blue[i]);
    848  1.7.4.2  ad 		}
    849  1.7.4.2  ad 	}
    850  1.7.4.2  ad 	if (cur->set & FB_CUR_SETSHAPE) {
    851  1.7.4.2  ad 		int i;
    852  1.7.4.2  ad 		uint16_t tmp;
    853  1.7.4.2  ad 
    854  1.7.4.2  ad 		agten_write_idx(sc, IBM561_CURSOR_BITMAP);
    855  1.7.4.2  ad 		for (i = 0; i < 512; i++) {
    856  1.7.4.2  ad 			tmp = util_interleave_lin(cur->mask[i], cur->image[i]);
    857  1.7.4.2  ad 			agten_write_dac(sc, IBM561_CMD, (tmp >> 8) & 0xff);
    858  1.7.4.2  ad 			agten_write_dac(sc, IBM561_CMD, tmp & 0xff);
    859  1.7.4.2  ad 		}
    860  1.7.4.2  ad 	}
    861  1.7.4.2  ad 	return 0;
    862  1.7.4.2  ad }
    863  1.7.4.2  ad 
    864  1.7.4.2  ad uint16_t
    865  1.7.4.2  ad util_interleave(uint8_t b1, uint8_t b2)
    866  1.7.4.2  ad {
    867  1.7.4.2  ad 	int i;
    868  1.7.4.2  ad 	uint16_t ret = 0;
    869  1.7.4.2  ad 	uint16_t mask = 0x8000;
    870  1.7.4.2  ad 	uint8_t mask8 = 0x01;
    871  1.7.4.2  ad 
    872  1.7.4.2  ad 	for (i = 0; i < 8; i++) {
    873  1.7.4.2  ad 		if (b1 & mask8)
    874  1.7.4.2  ad 			ret |= mask;
    875  1.7.4.2  ad 		mask = mask >> 1;
    876  1.7.4.2  ad 		if (b2 & mask8)
    877  1.7.4.2  ad 			ret |= mask;
    878  1.7.4.2  ad 		mask = mask >> 1;
    879  1.7.4.2  ad 		mask8 = mask8 << 1;
    880  1.7.4.2  ad 	}
    881  1.7.4.2  ad 	return ret;
    882  1.7.4.2  ad }
    883  1.7.4.2  ad 
    884  1.7.4.2  ad uint16_t
    885  1.7.4.2  ad util_interleave_lin(uint8_t b1, uint8_t b2)
    886  1.7.4.2  ad {
    887  1.7.4.2  ad 	int i;
    888  1.7.4.2  ad 	uint16_t ret = 0;
    889  1.7.4.2  ad 	uint16_t mask = 0x8000;
    890  1.7.4.2  ad 	uint8_t mask8 = 0x80;
    891  1.7.4.2  ad 
    892  1.7.4.2  ad 	for (i = 0; i < 8; i++) {
    893  1.7.4.2  ad 		if (b1 & mask8)
    894  1.7.4.2  ad 			ret |= mask;
    895  1.7.4.2  ad 		mask = mask >> 1;
    896  1.7.4.2  ad 		if (b2 & mask8)
    897  1.7.4.2  ad 			ret |= mask;
    898  1.7.4.2  ad 		mask = mask >> 1;
    899  1.7.4.2  ad 		mask8 = mask8 >> 1;
    900  1.7.4.2  ad 	}
    901  1.7.4.2  ad 	return ret;
    902  1.7.4.2  ad }
    903  1.7.4.2  ad 
    904  1.7.4.2  ad /* and now the /dev/fb* stuff */
    905  1.7.4.2  ad static void
    906  1.7.4.2  ad agten_fb_unblank(struct device *dev)
    907  1.7.4.2  ad {
    908  1.7.4.2  ad 	struct agten_softc *sc = (void *)dev;
    909  1.7.4.2  ad 
    910  1.7.4.2  ad 	agten_init(sc);
    911  1.7.4.2  ad 	agten_set_video(sc, 1);
    912  1.7.4.2  ad }
    913  1.7.4.2  ad 
    914  1.7.4.2  ad static int
    915  1.7.4.2  ad agten_fb_open(dev_t dev, int flags, int mode, struct lwp *l)
    916  1.7.4.2  ad {
    917  1.7.4.2  ad 	struct agten_softc *sc = agten_cd.cd_devs[minor(dev)];
    918  1.7.4.2  ad 	int unit = minor(dev);
    919  1.7.4.2  ad 
    920  1.7.4.2  ad 	if (unit >= agten_cd.cd_ndevs || agten_cd.cd_devs[unit] == NULL)
    921  1.7.4.2  ad 		return (ENXIO);
    922  1.7.4.2  ad 	if (sc->sc_fb_is_open)
    923  1.7.4.2  ad 		return 0;
    924  1.7.4.2  ad 
    925  1.7.4.2  ad 	sc->sc_fb_is_open++;
    926  1.7.4.2  ad 	agten_gfx(sc);
    927  1.7.4.2  ad 
    928  1.7.4.2  ad 	return (0);
    929  1.7.4.2  ad }
    930  1.7.4.2  ad 
    931  1.7.4.2  ad static int
    932  1.7.4.2  ad agten_fb_close(dev_t dev, int flags, int mode, struct lwp *l)
    933  1.7.4.2  ad {
    934  1.7.4.2  ad 	struct agten_softc *sc = agten_cd.cd_devs[minor(dev)];
    935  1.7.4.2  ad 
    936  1.7.4.2  ad 	sc->sc_fb_is_open--;
    937  1.7.4.2  ad 	if (sc->sc_fb_is_open < 0)
    938  1.7.4.2  ad 		sc->sc_fb_is_open = 0;
    939  1.7.4.2  ad 
    940  1.7.4.2  ad 	if (sc->sc_fb_is_open == 0) {
    941  1.7.4.2  ad 		agten_init(sc);
    942  1.7.4.2  ad 		vcons_redraw_screen(sc->vd.active);
    943  1.7.4.2  ad 	}
    944  1.7.4.2  ad 
    945  1.7.4.2  ad 	return (0);
    946  1.7.4.2  ad }
    947  1.7.4.2  ad 
    948  1.7.4.2  ad static int
    949  1.7.4.2  ad agten_fb_ioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
    950  1.7.4.2  ad {
    951  1.7.4.2  ad 	struct agten_softc *sc = agten_cd.cd_devs[minor(dev)];
    952  1.7.4.2  ad 	struct fbgattr *fba;
    953  1.7.4.2  ad 	int error;
    954  1.7.4.2  ad 
    955  1.7.4.2  ad 	switch (cmd) {
    956  1.7.4.2  ad 
    957  1.7.4.2  ad 	case FBIOGTYPE:
    958  1.7.4.2  ad 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    959  1.7.4.2  ad 		break;
    960  1.7.4.2  ad 
    961  1.7.4.2  ad 	case FBIOGATTR:
    962  1.7.4.2  ad 		fba = (struct fbgattr *)data;
    963  1.7.4.2  ad 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    964  1.7.4.2  ad 		fba->owner = 0;		/* XXX ??? */
    965  1.7.4.2  ad 		fba->fbtype = sc->sc_fb.fb_type;
    966  1.7.4.2  ad 		fba->sattr.flags = 0;
    967  1.7.4.2  ad 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    968  1.7.4.2  ad 		fba->sattr.dev_specific[0] = -1;
    969  1.7.4.2  ad 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    970  1.7.4.2  ad 		fba->emu_types[1] = -1;
    971  1.7.4.2  ad 		break;
    972  1.7.4.2  ad 
    973  1.7.4.2  ad 	case FBIOGETCMAP:
    974  1.7.4.2  ad #define p ((struct fbcmap *)data)
    975  1.7.4.2  ad 		return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
    976  1.7.4.2  ad 
    977  1.7.4.2  ad 	case FBIOPUTCMAP:
    978  1.7.4.2  ad 		/* copy to software map */
    979  1.7.4.2  ad 		error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
    980  1.7.4.2  ad 		if (error)
    981  1.7.4.2  ad 			return (error);
    982  1.7.4.2  ad 		/* now blast them into the chip */
    983  1.7.4.2  ad 		/* don't bother - we're 24bit */
    984  1.7.4.2  ad #undef p
    985  1.7.4.2  ad 		break;
    986  1.7.4.2  ad 
    987  1.7.4.2  ad 	case FBIOGVIDEO:
    988  1.7.4.2  ad 		*(int *)data = agten_get_video(sc);
    989  1.7.4.2  ad 		break;
    990  1.7.4.2  ad 
    991  1.7.4.2  ad 	case FBIOSVIDEO:
    992  1.7.4.2  ad 		agten_set_video(sc, *(int *)data);
    993  1.7.4.2  ad 		break;
    994  1.7.4.2  ad 
    995  1.7.4.2  ad /* these are for both FBIOSCURSOR and FBIOGCURSOR */
    996  1.7.4.2  ad #define p ((struct fbcursor *)data)
    997  1.7.4.2  ad #define pc (&sc->sc_cursor)
    998  1.7.4.2  ad 
    999  1.7.4.2  ad 	case FBIOGCURSOR:
   1000  1.7.4.2  ad 		/* does anyone use this ioctl?! */
   1001  1.7.4.2  ad 		p->set = FB_CUR_SETALL;	/* close enough, anyway */
   1002  1.7.4.2  ad 		p->enable = 1;
   1003  1.7.4.2  ad 		p->pos.x = sc->sc_cursor_x;
   1004  1.7.4.2  ad 		p->pos.y = sc->sc_cursor_y;
   1005  1.7.4.2  ad 		p->size.x = 64;
   1006  1.7.4.2  ad 		p->size.y = 64;
   1007  1.7.4.2  ad 		break;
   1008  1.7.4.2  ad 
   1009  1.7.4.2  ad 	case FBIOSCURSOR:
   1010  1.7.4.2  ad 		agten_do_sun_cursor(sc, p);
   1011  1.7.4.2  ad 	break;
   1012  1.7.4.2  ad 
   1013  1.7.4.2  ad #undef p
   1014  1.7.4.2  ad #undef cc
   1015  1.7.4.2  ad 
   1016  1.7.4.2  ad 	case FBIOGCURPOS:
   1017  1.7.4.2  ad 	{
   1018  1.7.4.2  ad 		struct fbcurpos *cp = (struct fbcurpos *)data;
   1019  1.7.4.2  ad 		cp->x = sc->sc_cursor_x;
   1020  1.7.4.2  ad 		cp->y = sc->sc_cursor_y;
   1021  1.7.4.2  ad 	}
   1022  1.7.4.2  ad 	break;
   1023  1.7.4.2  ad 
   1024  1.7.4.2  ad 	case FBIOSCURPOS:
   1025  1.7.4.2  ad 	{
   1026  1.7.4.2  ad 		struct fbcurpos *cp = (struct fbcurpos *)data;
   1027  1.7.4.2  ad 		agten_move_cursor(sc, cp->x, cp->y);
   1028  1.7.4.2  ad 	}
   1029  1.7.4.2  ad 	break;
   1030  1.7.4.2  ad 
   1031  1.7.4.2  ad 	case FBIOGCURMAX:
   1032  1.7.4.2  ad 		/* max cursor size is 64x64 */
   1033  1.7.4.2  ad 		((struct fbcurpos *)data)->x = 64;
   1034  1.7.4.2  ad 		((struct fbcurpos *)data)->y = 64;
   1035  1.7.4.2  ad 		break;
   1036  1.7.4.2  ad 
   1037  1.7.4.2  ad 	default:
   1038  1.7.4.2  ad 		return (ENOTTY);
   1039  1.7.4.2  ad 	}
   1040  1.7.4.2  ad 	return (0);
   1041  1.7.4.2  ad }
   1042  1.7.4.2  ad 
   1043  1.7.4.2  ad static paddr_t
   1044  1.7.4.2  ad agten_fb_mmap(dev_t dev, off_t off, int prot)
   1045  1.7.4.2  ad {
   1046  1.7.4.2  ad 	struct agten_softc *sc = agten_cd.cd_devs[minor(dev)];
   1047  1.7.4.2  ad 
   1048  1.7.4.2  ad 	/*
   1049  1.7.4.2  ad 	 * mappings are subject to change
   1050  1.7.4.2  ad 	 * for now we put the framebuffer at offset 0 and the GLint registers
   1051  1.7.4.2  ad 	 * right after that. We may want to expose more register ranges and
   1052  1.7.4.2  ad 	 * probably will want to map the 2nd framebuffer as well
   1053  1.7.4.2  ad 	 */
   1054  1.7.4.2  ad 
   1055  1.7.4.2  ad 	if (off < 0)
   1056  1.7.4.2  ad 		return EINVAL;
   1057  1.7.4.2  ad 
   1058  1.7.4.2  ad 	if (off >= sc->sc_glint_fbsz + 0x10000)
   1059  1.7.4.2  ad 		return EINVAL;
   1060  1.7.4.2  ad 
   1061  1.7.4.2  ad 	if (off < sc->sc_glint_fbsz) {
   1062  1.7.4.2  ad 		return (bus_space_mmap(sc->sc_bustag,
   1063  1.7.4.2  ad 			sc->sc_glint_fb,
   1064  1.7.4.2  ad 			off,
   1065  1.7.4.2  ad 			prot,
   1066  1.7.4.2  ad 			BUS_SPACE_MAP_LINEAR));
   1067  1.7.4.2  ad 	}
   1068  1.7.4.2  ad 
   1069  1.7.4.2  ad 	off -= sc->sc_glint_fbsz;
   1070  1.7.4.2  ad 	if (off < 0x10000) {
   1071  1.7.4.2  ad 		return (bus_space_mmap(sc->sc_bustag,
   1072  1.7.4.2  ad 			sc->sc_glint_regs,
   1073  1.7.4.2  ad 			off,
   1074  1.7.4.2  ad 			prot,
   1075  1.7.4.2  ad 			BUS_SPACE_MAP_LINEAR));
   1076  1.7.4.2  ad 	}
   1077  1.7.4.2  ad 	return EINVAL;
   1078  1.7.4.2  ad }
   1079