Home | History | Annotate | Line # | Download | only in dev
cgfourteen.c revision 1.39.2.3
      1  1.39.2.3      yamt /*	$NetBSD: cgfourteen.c,v 1.39.2.3 2007/09/03 14:29:55 yamt Exp $ */
      2       1.1    abrown 
      3       1.1    abrown /*
      4      1.12        pk  * Copyright (c) 1996
      5       1.1    abrown  *	The President and Fellows of Harvard College. All rights reserved.
      6       1.1    abrown  * Copyright (c) 1992, 1993
      7       1.1    abrown  *	The Regents of the University of California.  All rights reserved.
      8       1.1    abrown  *
      9       1.1    abrown  * This software was developed by the Computer Systems Engineering group
     10       1.1    abrown  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     11       1.1    abrown  * contributed to Berkeley.
     12       1.1    abrown  *
     13       1.1    abrown  * All advertising materials mentioning features or use of this software
     14       1.1    abrown  * must display the following acknowledgement:
     15       1.1    abrown  *	This product includes software developed by Harvard University.
     16       1.1    abrown  *	This product includes software developed by the University of
     17       1.1    abrown  *	California, Lawrence Berkeley Laboratory.
     18       1.1    abrown  *
     19       1.1    abrown  * Redistribution and use in source and binary forms, with or without
     20       1.1    abrown  * modification, are permitted provided that the following conditions
     21       1.1    abrown  * are met:
     22       1.1    abrown  * 1. Redistributions of source code must retain the above copyright
     23       1.1    abrown  *    notice, this list of conditions and the following disclaimer.
     24       1.1    abrown  * 2. Redistributions in binary form must reproduce the above copyright
     25       1.1    abrown  *    notice, this list of conditions and the following disclaimer in the
     26       1.1    abrown  *    documentation and/or other materials provided with the distribution.
     27       1.1    abrown  * 3. All advertising materials mentioning features or use of this software
     28       1.1    abrown  *    must display the following acknowledgement:
     29       1.1    abrown  *	This product includes software developed by the University of
     30       1.1    abrown  *	California, Berkeley and its contributors.
     31       1.1    abrown  *	This product includes software developed by Harvard University and
     32       1.1    abrown  *	its contributors.
     33       1.1    abrown  * 4. Neither the name of the University nor the names of its contributors
     34       1.1    abrown  *    may be used to endorse or promote products derived from this software
     35       1.1    abrown  *    without specific prior written permission.
     36       1.1    abrown  *
     37       1.1    abrown  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     38       1.1    abrown  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     39       1.1    abrown  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     40       1.1    abrown  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     41       1.1    abrown  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     42       1.1    abrown  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     43       1.1    abrown  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     44       1.1    abrown  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     45       1.1    abrown  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     46       1.1    abrown  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     47       1.1    abrown  * SUCH DAMAGE.
     48       1.1    abrown  *
     49       1.1    abrown  *   Based on:
     50       1.1    abrown  *	NetBSD: cgthree.c,v 1.28 1996/05/31 09:59:22 pk Exp
     51       1.1    abrown  *	NetBSD: cgsix.c,v 1.25 1996/04/01 17:30:00 christos Exp
     52       1.1    abrown  */
     53       1.1    abrown 
     54       1.1    abrown /*
     55       1.1    abrown  * Driver for Campus-II on-board mbus-based video (cgfourteen).
     56       1.1    abrown  * Provides minimum emulation of a Sun cgthree 8-bit framebuffer to
     57       1.1    abrown  * allow X to run.
     58       1.1    abrown  *
     59       1.1    abrown  * Does not handle interrupts, even though they can occur.
     60       1.1    abrown  *
     61       1.1    abrown  * XXX should defer colormap updates to vertical retrace interrupts
     62       1.1    abrown  */
     63      1.10       mrg 
     64      1.12        pk /*
     65       1.1    abrown  * The following is for debugging only; it opens up a security hole
     66      1.12        pk  * enabled by allowing any user to map the control registers for the
     67       1.1    abrown  * cg14 into their space.
     68       1.1    abrown  */
     69  1.39.2.2      yamt #undef CG14_MAP_REGS
     70       1.1    abrown 
     71       1.1    abrown /*
     72       1.1    abrown  * The following enables 24-bit operation: when opened, the framebuffer
     73      1.12        pk  * will switch to 24-bit mode (actually 32-bit mode), and provide a
     74       1.1    abrown  * simple cg8 emulation.
     75       1.1    abrown  */
     76  1.39.2.1      yamt #define CG14_CG8
     77       1.1    abrown 
     78       1.1    abrown #include <sys/param.h>
     79       1.1    abrown #include <sys/systm.h>
     80       1.1    abrown #include <sys/buf.h>
     81       1.1    abrown #include <sys/device.h>
     82       1.1    abrown #include <sys/ioctl.h>
     83       1.1    abrown #include <sys/malloc.h>
     84       1.1    abrown #include <sys/mman.h>
     85       1.1    abrown #include <sys/tty.h>
     86       1.1    abrown #include <sys/conf.h>
     87       1.1    abrown 
     88      1.18       mrg #include <uvm/uvm_extern.h>
     89       1.1    abrown 
     90      1.20        pk #include <dev/sun/fbio.h>
     91  1.39.2.1      yamt #include <machine/autoconf.h>
     92  1.39.2.1      yamt #include <machine/pmap.h>
     93      1.20        pk #include <dev/sun/fbvar.h>
     94  1.39.2.1      yamt #include <machine/cpu.h>
     95  1.39.2.1      yamt #include <dev/sbus/sbusvar.h>
     96       1.1    abrown 
     97  1.39.2.3      yamt #include "wsdisplay.h"
     98  1.39.2.3      yamt #include <dev/wscons/wsconsio.h>
     99  1.39.2.3      yamt #include <dev/wsfont/wsfont.h>
    100  1.39.2.3      yamt #include <dev/rasops/rasops.h>
    101  1.39.2.3      yamt 
    102  1.39.2.3      yamt #include <dev/wscons/wsdisplay_vconsvar.h>
    103  1.39.2.3      yamt 
    104       1.1    abrown #include <sparc/dev/cgfourteenreg.h>
    105       1.1    abrown #include <sparc/dev/cgfourteenvar.h>
    106       1.1    abrown 
    107  1.39.2.3      yamt #include "opt_wsemul.h"
    108  1.39.2.3      yamt 
    109       1.1    abrown /* autoconfiguration driver */
    110       1.6        pk static int	cgfourteenmatch(struct device *, struct cfdata *, void *);
    111  1.39.2.1      yamt static void	cgfourteenattach(struct device *, struct device *, void *);
    112       1.1    abrown static void	cgfourteenunblank(struct device *);
    113       1.1    abrown 
    114      1.29   thorpej CFATTACH_DECL(cgfourteen, sizeof(struct cgfourteen_softc),
    115      1.30   thorpej     cgfourteenmatch, cgfourteenattach, NULL, NULL);
    116  1.39.2.1      yamt 
    117       1.8   thorpej extern struct cfdriver cgfourteen_cd;
    118       1.1    abrown 
    119      1.26   gehenna dev_type_open(cgfourteenopen);
    120      1.26   gehenna dev_type_close(cgfourteenclose);
    121      1.26   gehenna dev_type_ioctl(cgfourteenioctl);
    122      1.26   gehenna dev_type_mmap(cgfourteenmmap);
    123  1.39.2.1      yamt dev_type_poll(cgfourteenpoll);
    124      1.26   gehenna 
    125      1.26   gehenna const struct cdevsw cgfourteen_cdevsw = {
    126  1.39.2.1      yamt         cgfourteenopen, cgfourteenclose, noread, nowrite, cgfourteenioctl,
    127  1.39.2.1      yamt         nostop, notty, cgfourteenpoll, cgfourteenmmap, nokqfilter,
    128      1.26   gehenna };
    129      1.26   gehenna 
    130       1.1    abrown /* frame buffer generic driver */
    131       1.1    abrown static struct fbdriver cgfourteenfbdriver = {
    132      1.12        pk 	cgfourteenunblank, cgfourteenopen, cgfourteenclose, cgfourteenioctl,
    133  1.39.2.1      yamt 	cgfourteenpoll, cgfourteenmmap, nokqfilter
    134       1.1    abrown };
    135       1.1    abrown 
    136  1.39.2.1      yamt extern struct tty *fbconstty;
    137  1.39.2.1      yamt 
    138  1.39.2.1      yamt static void cg14_set_video(struct cgfourteen_softc *, int);
    139  1.39.2.1      yamt static int  cg14_get_video(struct cgfourteen_softc *);
    140  1.39.2.1      yamt static int  cg14_get_cmap(struct fbcmap *, union cg14cmap *, int);
    141  1.39.2.1      yamt static int  cg14_put_cmap(struct fbcmap *, union cg14cmap *, int);
    142  1.39.2.1      yamt static void cg14_load_hwcmap(struct cgfourteen_softc *, int, int);
    143  1.39.2.1      yamt static void cg14_init(struct cgfourteen_softc *);
    144  1.39.2.1      yamt static void cg14_reset(struct cgfourteen_softc *);
    145      1.23   darrenr 
    146  1.39.2.3      yamt #if NWSDISPLAY > 0
    147  1.39.2.3      yamt static void cg14_setup_wsdisplay(struct cgfourteen_softc *, int);
    148  1.39.2.3      yamt static void cg14_init_cmap(struct cgfourteen_softc *);
    149  1.39.2.3      yamt static int  cg14_putcmap(struct cgfourteen_softc *, struct wsdisplay_cmap *);
    150  1.39.2.3      yamt static int  cg14_getcmap(struct cgfourteen_softc *, struct wsdisplay_cmap *);
    151  1.39.2.3      yamt static void cg14_set_depth(struct cgfourteen_softc *, int);
    152  1.39.2.3      yamt static void cg14_move_cursor(struct cgfourteen_softc *, int, int);
    153  1.39.2.3      yamt static int  cg14_do_cursor(struct cgfourteen_softc *,
    154  1.39.2.3      yamt                            struct wsdisplay_cursor *);
    155  1.39.2.3      yamt #endif
    156  1.39.2.3      yamt 
    157  1.39.2.3      yamt #if defined(RASTERCONSOLE) && (NWSDISPLAY > 0)
    158  1.39.2.3      yamt #error You can't have it both ways - either RASTERCONSOLE or wsdisplay
    159  1.39.2.3      yamt #endif
    160  1.39.2.3      yamt 
    161      1.23   darrenr /*
    162       1.1    abrown  * Match a cgfourteen.
    163       1.1    abrown  */
    164       1.1    abrown int
    165  1.39.2.1      yamt cgfourteenmatch(struct device *parent, struct cfdata *cf, void *aux)
    166       1.1    abrown {
    167      1.11        pk 	union obio_attach_args *uoba = aux;
    168      1.11        pk 	struct sbus_attach_args *sa = &uoba->uoba_sbus;
    169       1.1    abrown 
    170       1.1    abrown 	/*
    171       1.1    abrown 	 * The cgfourteen is a local-bus video adaptor, accessed directly
    172       1.1    abrown 	 * via the processor, and not through device space or an external
    173       1.1    abrown 	 * bus. Thus we look _only_ at the obio bus.
    174       1.1    abrown 	 * Additionally, these things exist only on the Sun4m.
    175       1.1    abrown 	 */
    176      1.11        pk 
    177      1.11        pk 	if (uoba->uoba_isobio4 != 0 || !CPU_ISSUN4M)
    178      1.11        pk 		return (0);
    179      1.11        pk 
    180      1.11        pk 	/* Check driver name */
    181      1.27   thorpej 	return (strcmp(cf->cf_name, sa->sa_name) == 0);
    182       1.1    abrown }
    183       1.1    abrown 
    184       1.1    abrown /*
    185  1.39.2.1      yamt  * Set COLOUR_OFFSET to the offset of the video RAM.  This is to provide
    186  1.39.2.1      yamt  *  space for faked overlay junk for the cg8 emulation.
    187  1.39.2.1      yamt  *
    188  1.39.2.1      yamt  * As it happens, this value is correct for both cg3 and cg8 emulation!
    189  1.39.2.1      yamt  */
    190  1.39.2.1      yamt #define COLOUR_OFFSET (256*1024)
    191  1.39.2.1      yamt 
    192  1.39.2.1      yamt #ifdef RASTERCONSOLE
    193  1.39.2.1      yamt static void cg14_set_rcons_luts(struct cgfourteen_softc *sc)
    194  1.39.2.1      yamt {
    195  1.39.2.1      yamt 	int i;
    196  1.39.2.1      yamt 
    197  1.39.2.1      yamt 	for (i=0;i<CG14_CLUT_SIZE;i++) sc->sc_xlut->xlut_lut[i] = 0x22;
    198  1.39.2.1      yamt 	for (i=0;i<CG14_CLUT_SIZE;i++) sc->sc_clut2->clut_lut[i] = 0x00ffffff;
    199  1.39.2.1      yamt 	sc->sc_clut2->clut_lut[0] = 0x00ffffff;
    200  1.39.2.1      yamt 	sc->sc_clut2->clut_lut[255] = 0;
    201  1.39.2.1      yamt }
    202  1.39.2.1      yamt #endif /* RASTERCONSOLE */
    203  1.39.2.1      yamt 
    204  1.39.2.3      yamt #if NWSDISPLAY > 0
    205  1.39.2.3      yamt static int	cg14_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    206  1.39.2.3      yamt static paddr_t	cg14_mmap(void *, void *, off_t, int);
    207  1.39.2.3      yamt static void	cg14_init_screen(void *, struct vcons_screen *, int, long *);
    208  1.39.2.3      yamt 
    209  1.39.2.3      yamt 
    210  1.39.2.3      yamt struct wsdisplay_accessops cg14_accessops = {
    211  1.39.2.3      yamt 	cg14_ioctl,
    212  1.39.2.3      yamt 	cg14_mmap,
    213  1.39.2.3      yamt 	NULL,	/* alloc_screen */
    214  1.39.2.3      yamt 	NULL,	/* free_screen */
    215  1.39.2.3      yamt 	NULL,	/* show_screen */
    216  1.39.2.3      yamt 	NULL, 	/* load_font */
    217  1.39.2.3      yamt 	NULL,	/* pollc */
    218  1.39.2.3      yamt 	NULL	/* scroll */
    219  1.39.2.3      yamt };
    220  1.39.2.3      yamt #endif
    221  1.39.2.3      yamt 
    222  1.39.2.1      yamt /*
    223       1.1    abrown  * Attach a display.  We need to notice if it is the console, too.
    224       1.1    abrown  */
    225       1.1    abrown void
    226  1.39.2.1      yamt cgfourteenattach(struct device *parent, struct device *self, void *aux)
    227       1.1    abrown {
    228      1.11        pk 	union obio_attach_args *uoba = aux;
    229      1.11        pk 	struct sbus_attach_args *sa = &uoba->uoba_sbus;
    230      1.11        pk 	struct cgfourteen_softc *sc = (struct cgfourteen_softc *)self;
    231      1.11        pk 	struct fbdevice *fb = &sc->sc_fb;
    232      1.11        pk 	bus_space_handle_t bh;
    233      1.11        pk 	int node, ramsize;
    234  1.39.2.1      yamt 	volatile uint32_t *lut;
    235       1.1    abrown 	int i, isconsole;
    236      1.11        pk 
    237      1.11        pk 	node = sa->sa_node;
    238      1.11        pk 
    239      1.11        pk 	/* Remember cookies for cgfourteenmmap() */
    240      1.11        pk 	sc->sc_bustag = sa->sa_bustag;
    241       1.1    abrown 
    242      1.11        pk 	fb->fb_driver = &cgfourteenfbdriver;
    243      1.11        pk 	fb->fb_device = &sc->sc_dev;
    244      1.11        pk 	/* Mask out invalid flags from the user. */
    245  1.39.2.1      yamt 	fb->fb_flags = device_cfdata(&sc->sc_dev)->cf_flags & FB_USERMASK;
    246       1.1    abrown 
    247       1.1    abrown 	/*
    248       1.1    abrown 	 * We're emulating a cg3/8, so represent ourselves as one
    249       1.1    abrown 	 */
    250       1.1    abrown #ifdef CG14_CG8
    251      1.11        pk 	fb->fb_type.fb_type = FBTYPE_MEMCOLOR;
    252      1.11        pk 	fb->fb_type.fb_depth = 32;
    253  1.39.2.1      yamt 	fb_setsize_obp(fb, sc->sc_fb.fb_type.fb_depth, 1152, 900, node);
    254  1.39.2.1      yamt 	ramsize = roundup(fb->fb_type.fb_height * 1152 * 4, NBPG);
    255       1.1    abrown #else
    256      1.11        pk 	fb->fb_type.fb_type = FBTYPE_SUN3COLOR;
    257      1.11        pk 	fb->fb_type.fb_depth = 8;
    258      1.11        pk 	fb_setsize_obp(fb, sc->sc_fb.fb_type.fb_depth, 1152, 900, node);
    259  1.39.2.1      yamt 	ramsize = roundup(fb->fb_type.fb_height * fb->fb_linebytes, NBPG);
    260      1.23   darrenr #endif
    261      1.11        pk 	fb->fb_type.fb_cmsize = CG14_CLUT_SIZE;
    262  1.39.2.1      yamt 	fb->fb_type.fb_size = ramsize + COLOUR_OFFSET;
    263      1.11        pk 
    264      1.13        pk 	if (sa->sa_nreg < 2) {
    265      1.13        pk 		printf("%s: only %d register sets\n",
    266      1.13        pk 			self->dv_xname, sa->sa_nreg);
    267      1.11        pk 		return;
    268      1.11        pk 	}
    269      1.13        pk 	bcopy(sa->sa_reg, sc->sc_physadr,
    270  1.39.2.1      yamt 	      sa->sa_nreg * sizeof(struct sbus_reg));
    271       1.1    abrown 
    272  1.39.2.3      yamt 	sc->sc_vramsize = sc->sc_physadr[CG14_PXL_IDX].sbr_size;
    273  1.39.2.3      yamt 
    274  1.39.2.3      yamt 	printf(": %d MB VRAM", (uint32_t)(sc->sc_vramsize >> 20));
    275       1.1    abrown 	/*
    276       1.1    abrown 	 * Now map in the 8 useful pages of registers
    277       1.1    abrown 	 */
    278      1.11        pk 	if (sa->sa_size < 0x10000) {
    279       1.1    abrown #ifdef DIAGNOSTIC
    280       1.5  christos 		printf("warning: can't find all cgfourteen registers...\n");
    281       1.1    abrown #endif
    282      1.11        pk 		sa->sa_size = 0x10000;
    283       1.1    abrown 	}
    284  1.39.2.1      yamt 	if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
    285  1.39.2.1      yamt 			 sa->sa_offset,
    286  1.39.2.1      yamt 			 sa->sa_size,
    287  1.39.2.1      yamt 			 BUS_SPACE_MAP_LINEAR,
    288  1.39.2.1      yamt 			 &bh) != 0) {
    289      1.11        pk 		printf("%s: cannot map control registers\n", self->dv_xname);
    290      1.11        pk 		return;
    291      1.11        pk 	}
    292  1.39.2.3      yamt 	sc->sc_regh = bh;
    293      1.11        pk 
    294      1.11        pk 	sc->sc_ctl   = (struct cg14ctl  *) (bh);
    295      1.11        pk 	sc->sc_hwc   = (struct cg14curs *) (bh + CG14_OFFSET_CURS);
    296      1.11        pk 	sc->sc_dac   = (struct cg14dac  *) (bh + CG14_OFFSET_DAC);
    297      1.11        pk 	sc->sc_xlut  = (struct cg14xlut *) (bh + CG14_OFFSET_XLUT);
    298      1.11        pk 	sc->sc_clut1 = (struct cg14clut *) (bh + CG14_OFFSET_CLUT1);
    299      1.11        pk 	sc->sc_clut2 = (struct cg14clut *) (bh + CG14_OFFSET_CLUT2);
    300      1.11        pk 	sc->sc_clut3 = (struct cg14clut *) (bh + CG14_OFFSET_CLUT3);
    301      1.11        pk 	sc->sc_clutincr =        (u_int *) (bh + CG14_OFFSET_CLUTINCR);
    302       1.1    abrown 
    303       1.1    abrown 	/*
    304       1.1    abrown 	 * Let the user know that we're here
    305       1.1    abrown 	 */
    306       1.1    abrown #ifdef CG14_CG8
    307       1.5  christos 	printf(": cgeight emulated at %dx%dx24bpp",
    308      1.11        pk 		fb->fb_type.fb_width, fb->fb_type.fb_height);
    309       1.1    abrown #else
    310       1.5  christos 	printf(": cgthree emulated at %dx%dx8bpp",
    311      1.11        pk 		fb->fb_type.fb_width, fb->fb_type.fb_height);
    312       1.1    abrown #endif
    313       1.1    abrown 	/*
    314  1.39.2.1      yamt 	 * Enable the video.
    315       1.1    abrown 	 */
    316       1.1    abrown 	cg14_set_video(sc, 1);
    317       1.1    abrown 
    318       1.1    abrown 	/*
    319       1.1    abrown 	 * Grab the initial colormap
    320       1.1    abrown 	 */
    321      1.39   tsutsui 	lut = sc->sc_clut1->clut_lut;
    322       1.1    abrown 	for (i = 0; i < CG14_CLUT_SIZE; i++)
    323       1.1    abrown 		sc->sc_cmap.cm_chip[i] = lut[i];
    324       1.1    abrown 
    325       1.1    abrown 	/* See if we're the console */
    326  1.39.2.1      yamt         isconsole = fb_is_console(node);
    327       1.1    abrown 
    328  1.39.2.3      yamt #if defined(RASTERCONSOLE)
    329       1.1    abrown 	if (isconsole) {
    330       1.5  christos 		printf(" (console)\n");
    331  1.39.2.1      yamt 		/* *sbus*_bus_map?  but that's how we map the regs... */
    332  1.39.2.1      yamt 		if (sbus_bus_map( sc->sc_bustag,
    333  1.39.2.1      yamt 				  sc->sc_physadr[CG14_PXL_IDX].sbr_slot,
    334  1.39.2.3      yamt 				  sc->sc_physadr[CG14_PXL_IDX].sbr_offset +
    335  1.39.2.3      yamt 				    0x03800000,
    336  1.39.2.3      yamt 				  1152 * 900, BUS_SPACE_MAP_LINEAR,
    337  1.39.2.1      yamt 				  &bh) != 0) {
    338  1.39.2.1      yamt 			printf("%s: cannot map pixels\n",&sc->sc_dev.dv_xname[0]);
    339  1.39.2.3      yamt 			return;
    340  1.39.2.1      yamt 		}
    341  1.39.2.3      yamt 		sc->sc_rcfb = sc->sc_fb;
    342  1.39.2.3      yamt 		sc->sc_rcfb.fb_type.fb_type = FBTYPE_SUN3COLOR;
    343  1.39.2.3      yamt 		sc->sc_rcfb.fb_type.fb_depth = 8;
    344  1.39.2.3      yamt 		sc->sc_rcfb.fb_linebytes = 1152;
    345  1.39.2.3      yamt 		sc->sc_rcfb.fb_type.fb_size = roundup(1152*900,NBPG);
    346  1.39.2.3      yamt 		sc->sc_rcfb.fb_pixels = (void *)bh;
    347  1.39.2.3      yamt 
    348  1.39.2.3      yamt 		printf("vram at %p\n",(void *)bh);
    349  1.39.2.3      yamt 		/* XXX should use actual screen size */
    350  1.39.2.3      yamt 
    351  1.39.2.3      yamt 		for (i = 0; i < 1152 * 900; i++)
    352  1.39.2.3      yamt 		    ((unsigned char *)bh)[i] = 0;
    353  1.39.2.3      yamt 		fbrcons_init(&sc->sc_rcfb);
    354  1.39.2.3      yamt 		cg14_set_rcons_luts(sc);
    355  1.39.2.3      yamt 		sc->sc_ctl->ctl_mctl = CG14_MCTL_ENABLEVID |
    356  1.39.2.3      yamt 		    CG14_MCTL_PIXMODE_32 | CG14_MCTL_POWERCTL;
    357       1.1    abrown 	} else
    358       1.5  christos 		printf("\n");
    359  1.39.2.3      yamt #endif
    360  1.39.2.3      yamt 
    361  1.39.2.3      yamt #if NWSDISPLAY > 0
    362  1.39.2.3      yamt 	if (sbus_bus_map( sc->sc_bustag,
    363  1.39.2.3      yamt 	    sc->sc_physadr[CG14_PXL_IDX].sbr_slot,
    364  1.39.2.3      yamt 	    sc->sc_physadr[CG14_PXL_IDX].sbr_offset,
    365  1.39.2.3      yamt 	    ramsize, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    366  1.39.2.3      yamt 		printf("%s: cannot map pixels\n",&sc->sc_dev.dv_xname[0]);
    367  1.39.2.3      yamt 		return;
    368  1.39.2.3      yamt 	}
    369  1.39.2.3      yamt 
    370  1.39.2.3      yamt 	sc->sc_fb.fb_pixels = bus_space_vaddr(sc->sc_bustag, bh);
    371  1.39.2.3      yamt 	if (isconsole)
    372  1.39.2.3      yamt 		printf(" (console)\n");
    373  1.39.2.3      yamt 	else
    374  1.39.2.3      yamt 		printf("\n");
    375  1.39.2.3      yamt 
    376  1.39.2.3      yamt 	sc->sc_depth = 8;
    377  1.39.2.3      yamt 	cg14_setup_wsdisplay(sc, isconsole);
    378  1.39.2.3      yamt #endif
    379       1.1    abrown 
    380       1.1    abrown 	/* Attach to /dev/fb */
    381      1.16        pk 	fb_attach(&sc->sc_fb, isconsole);
    382       1.1    abrown }
    383       1.1    abrown 
    384       1.1    abrown /*
    385      1.12        pk  * Keep track of the number of opens made. In the 24-bit driver, we need to
    386       1.1    abrown  * switch to 24-bit mode on the first open, and switch back to 8-bit on
    387       1.1    abrown  * the last close. This kind of nonsense is needed to give screenblank
    388       1.1    abrown  * a fighting chance of working.
    389       1.1    abrown  */
    390       1.1    abrown static int cg14_opens = 0;
    391       1.1    abrown 
    392       1.1    abrown int
    393  1.39.2.1      yamt cgfourteenopen(dev_t dev, int flags, int mode, struct lwp *l)
    394       1.1    abrown {
    395  1.39.2.1      yamt 	struct cgfourteen_softc *sc;
    396  1.39.2.1      yamt 	int unit;
    397       1.1    abrown 	int s, oldopens;
    398       1.1    abrown 
    399  1.39.2.1      yamt 	unit = minor(dev);
    400  1.39.2.1      yamt 	if (unit >= cgfourteen_cd.cd_ndevs)
    401  1.39.2.1      yamt 		return(ENXIO);
    402  1.39.2.1      yamt 	sc = cgfourteen_cd.cd_devs[minor(dev)];
    403  1.39.2.1      yamt 	if (sc == NULL)
    404  1.39.2.1      yamt 		return(ENXIO);
    405       1.1    abrown 	s = splhigh();
    406       1.1    abrown 	oldopens = cg14_opens++;
    407       1.1    abrown 	splx(s);
    408       1.1    abrown 
    409       1.1    abrown 	/* Setup the cg14 as we want it, and save the original PROM state */
    410       1.1    abrown 	if (oldopens == 0)	/* first open only, to make screenblank work */
    411       1.1    abrown 		cg14_init(sc);
    412       1.1    abrown 
    413       1.1    abrown 	return (0);
    414       1.1    abrown }
    415       1.1    abrown 
    416       1.1    abrown int
    417  1.39.2.1      yamt cgfourteenclose(dev_t dev, int flags, int mode, struct lwp *l)
    418       1.1    abrown {
    419      1.11        pk 	struct cgfourteen_softc *sc = cgfourteen_cd.cd_devs[minor(dev)];
    420       1.1    abrown 	int s, opens;
    421       1.1    abrown 
    422       1.1    abrown 	s = splhigh();
    423       1.1    abrown 	opens = --cg14_opens;
    424       1.1    abrown 	if (cg14_opens < 0)
    425       1.1    abrown 		opens = cg14_opens = 0;
    426       1.1    abrown 	splx(s);
    427       1.1    abrown 
    428       1.1    abrown 	/*
    429       1.1    abrown 	 * Restore video state to make the PROM happy, on last close.
    430       1.1    abrown 	 */
    431       1.1    abrown 	if (opens == 0)
    432       1.1    abrown 		cg14_reset(sc);
    433       1.1    abrown 
    434       1.1    abrown 	return (0);
    435       1.1    abrown }
    436       1.1    abrown 
    437       1.1    abrown int
    438  1.39.2.3      yamt cgfourteenioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
    439       1.1    abrown {
    440      1.11        pk 	struct cgfourteen_softc *sc = cgfourteen_cd.cd_devs[minor(dev)];
    441      1.11        pk 	struct fbgattr *fba;
    442  1.39.2.1      yamt 	int error;
    443       1.1    abrown 
    444       1.1    abrown 	switch (cmd) {
    445       1.1    abrown 
    446       1.1    abrown 	case FBIOGTYPE:
    447       1.1    abrown 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    448       1.1    abrown 		break;
    449       1.1    abrown 
    450       1.1    abrown 	case FBIOGATTR:
    451       1.1    abrown 		fba = (struct fbgattr *)data;
    452       1.1    abrown 		fba->real_type = FBTYPE_MDICOLOR;
    453       1.1    abrown 		fba->owner = 0;		/* XXX ??? */
    454       1.1    abrown 		fba->fbtype = sc->sc_fb.fb_type;
    455       1.1    abrown 		fba->sattr.flags = 0;
    456       1.1    abrown 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    457       1.1    abrown 		fba->sattr.dev_specific[0] = -1;
    458       1.1    abrown 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    459       1.1    abrown 		fba->emu_types[1] = -1;
    460       1.1    abrown 		break;
    461       1.1    abrown 
    462       1.1    abrown 	case FBIOGETCMAP:
    463  1.39.2.1      yamt 		return(cg14_get_cmap((struct fbcmap *)data, &sc->sc_cmap,
    464       1.1    abrown 				     CG14_CLUT_SIZE));
    465       1.1    abrown 
    466       1.1    abrown 	case FBIOPUTCMAP:
    467       1.1    abrown 		/* copy to software map */
    468       1.1    abrown #define p ((struct fbcmap *)data)
    469       1.1    abrown #ifdef CG14_CG8
    470       1.1    abrown 		p->index &= 0xffffff;
    471       1.1    abrown #endif
    472       1.1    abrown 		error = cg14_put_cmap(p, &sc->sc_cmap, CG14_CLUT_SIZE);
    473       1.1    abrown 		if (error)
    474       1.1    abrown 			return (error);
    475       1.1    abrown 		/* now blast them into the chip */
    476       1.1    abrown 		/* XXX should use retrace interrupt */
    477       1.1    abrown 		cg14_load_hwcmap(sc, p->index, p->count);
    478       1.1    abrown #undef p
    479       1.1    abrown 		break;
    480       1.1    abrown 
    481       1.1    abrown 	case FBIOGVIDEO:
    482       1.1    abrown 		*(int *)data = cg14_get_video(sc);
    483       1.1    abrown 		break;
    484       1.1    abrown 
    485       1.1    abrown 	case FBIOSVIDEO:
    486       1.1    abrown 		cg14_set_video(sc, *(int *)data);
    487       1.1    abrown 		break;
    488       1.1    abrown 
    489       1.1    abrown 	default:
    490       1.1    abrown 		return (ENOTTY);
    491       1.1    abrown 	}
    492       1.1    abrown 	return (0);
    493       1.1    abrown }
    494       1.1    abrown 
    495       1.1    abrown /*
    496       1.1    abrown  * Undo the effect of an FBIOSVIDEO that turns the video off.
    497       1.1    abrown  */
    498       1.1    abrown static void
    499  1.39.2.1      yamt cgfourteenunblank(struct device *dev)
    500       1.1    abrown {
    501  1.39.2.3      yamt 	struct cgfourteen_softc *sc = (struct cgfourteen_softc *)dev;
    502       1.1    abrown 
    503  1.39.2.3      yamt 	cg14_set_video(sc, 1);
    504  1.39.2.3      yamt #if NWSDISPLAY > 0
    505  1.39.2.3      yamt 	if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL) {
    506  1.39.2.3      yamt 		cg14_set_depth(sc, 8);
    507  1.39.2.3      yamt 		cg14_init_cmap(sc);
    508  1.39.2.3      yamt 		vcons_redraw_screen(sc->sc_vd.active);
    509  1.39.2.3      yamt 		sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    510  1.39.2.3      yamt 	}
    511  1.39.2.3      yamt #endif
    512       1.1    abrown }
    513       1.1    abrown 
    514       1.1    abrown /*
    515       1.1    abrown  * Return the address that would map the given device at the given
    516       1.1    abrown  * offset, allowing for the given protection, or return -1 for error.
    517       1.1    abrown  *
    518  1.39.2.1      yamt  * Since we're pretending to be a cg8, we put the main video RAM at the
    519  1.39.2.1      yamt  *  same place the cg8 does, at offset 256k.  The cg8 has an enable
    520  1.39.2.1      yamt  *  plane in the 256k space; our "enable" plane works differently.  We
    521  1.39.2.1      yamt  *  can't emulate the enable plane very well, but all X uses it for is
    522  1.39.2.1      yamt  *  to clear it at startup - so we map the first page of video RAM over
    523  1.39.2.1      yamt  *  and over to fill that 256k space.  We also map some other views of
    524  1.39.2.1      yamt  *  the video RAM space.
    525  1.39.2.1      yamt  *
    526  1.39.2.1      yamt  * Our memory map thus looks like
    527  1.39.2.1      yamt  *
    528  1.39.2.1      yamt  *	mmap range		space	base offset
    529  1.39.2.1      yamt  *	00000000-00040000	vram	0 (multi-mapped - see above)
    530  1.39.2.1      yamt  *	00040000-00434800	vram	00000000
    531  1.39.2.1      yamt  *	01000000-01400000	vram	01000000
    532  1.39.2.1      yamt  *	02000000-02200000	vram	02000000
    533  1.39.2.1      yamt  *	02800000-02a00000	vram	02800000
    534  1.39.2.1      yamt  *	03000000-03100000	vram	03000000
    535  1.39.2.1      yamt  *	03400000-03500000	vram	03400000
    536  1.39.2.1      yamt  *	03800000-03900000	vram	03800000
    537  1.39.2.1      yamt  *	03c00000-03d00000	vram	03c00000
    538  1.39.2.1      yamt  *	10000000-10010000	regs	00000000 (only if CG14_MAP_REGS)
    539       1.1    abrown  */
    540      1.17    simonb paddr_t
    541  1.39.2.1      yamt cgfourteenmmap(dev_t dev, off_t off, int prot)
    542       1.1    abrown {
    543      1.11        pk 	struct cgfourteen_softc *sc = cgfourteen_cd.cd_devs[minor(dev)];
    544      1.12        pk 
    545       1.1    abrown 	if (off & PGOFSET)
    546       1.1    abrown 		panic("cgfourteenmmap");
    547      1.14       mrg 
    548      1.14       mrg 	if (off < 0)
    549      1.14       mrg 		return (-1);
    550       1.1    abrown 
    551  1.39.2.1      yamt #if defined(CG14_MAP_REGS) /* XXX: security hole */
    552       1.1    abrown 	/*
    553      1.12        pk 	 * Map the control registers into user space. Should only be
    554       1.1    abrown 	 * used for debugging!
    555       1.1    abrown 	 */
    556       1.1    abrown 	if ((u_int)off >= 0x10000000 && (u_int)off < 0x10000000 + 16*4096) {
    557       1.1    abrown 		off -= 0x10000000;
    558  1.39.2.1      yamt 		return (bus_space_mmap(sc->sc_bustag,
    559      1.21       eeh 			BUS_ADDR(sc->sc_physadr[CG14_CTL_IDX].sbr_slot,
    560  1.39.2.1      yamt 				   sc->sc_physadr[CG14_CTL_IDX].sbr_offset),
    561      1.21       eeh 			off, prot, BUS_SPACE_MAP_LINEAR));
    562       1.1    abrown 	}
    563       1.1    abrown #endif
    564      1.23   darrenr 
    565  1.39.2.1      yamt 	if (off < COLOUR_OFFSET)
    566  1.39.2.1      yamt 		off = 0;
    567  1.39.2.1      yamt 	else if (off < COLOUR_OFFSET+(1152*900*4))
    568  1.39.2.1      yamt 		off -= COLOUR_OFFSET;
    569  1.39.2.1      yamt 	else {
    570  1.39.2.1      yamt 		switch (off >> 20) {
    571  1.39.2.1      yamt 			case 0x010: case 0x011: case 0x012: case 0x013:
    572  1.39.2.1      yamt 			case 0x020: case 0x021:
    573  1.39.2.1      yamt 			case 0x028: case 0x029:
    574  1.39.2.1      yamt 			case 0x030:
    575  1.39.2.1      yamt 			case 0x034:
    576  1.39.2.1      yamt 			case 0x038:
    577  1.39.2.1      yamt 			case 0x03c:
    578  1.39.2.1      yamt 				break;
    579  1.39.2.1      yamt 			default:
    580  1.39.2.1      yamt 				return(-1);
    581  1.39.2.1      yamt 		}
    582       1.1    abrown 	}
    583       1.1    abrown 
    584      1.21       eeh 	return (bus_space_mmap(sc->sc_bustag,
    585  1.39.2.1      yamt 		BUS_ADDR(sc->sc_physadr[CG14_PXL_IDX].sbr_slot,
    586  1.39.2.1      yamt 			   sc->sc_physadr[CG14_PXL_IDX].sbr_offset),
    587      1.21       eeh 		off, prot, BUS_SPACE_MAP_LINEAR));
    588      1.12        pk }
    589       1.1    abrown 
    590  1.39.2.1      yamt int
    591  1.39.2.1      yamt cgfourteenpoll(dev_t dev, int events, struct lwp *l)
    592  1.39.2.1      yamt {
    593  1.39.2.1      yamt 
    594  1.39.2.1      yamt 	return (seltrue(dev, events, l));
    595  1.39.2.1      yamt }
    596  1.39.2.1      yamt 
    597       1.1    abrown /*
    598      1.12        pk  * Miscellaneous helper functions
    599       1.1    abrown  */
    600       1.1    abrown 
    601       1.1    abrown /* Initialize the framebuffer, storing away useful state for later reset */
    602      1.12        pk static void
    603  1.39.2.1      yamt cg14_init(struct cgfourteen_softc *sc)
    604       1.1    abrown {
    605  1.39.2.1      yamt 	volatile uint32_t *clut;
    606  1.39.2.1      yamt 	volatile uint8_t  *xlut;
    607      1.11        pk 	int i;
    608       1.1    abrown 
    609       1.1    abrown 	/*
    610       1.1    abrown 	 * We stash away the following to restore on close:
    611       1.1    abrown 	 *
    612       1.1    abrown 	 * 	color look-up table 1 	(sc->sc_saveclut)
    613       1.1    abrown 	 *	x look-up table		(sc->sc_savexlut)
    614       1.1    abrown 	 *	control register	(sc->sc_savectl)
    615       1.1    abrown 	 *	cursor control register (sc->sc_savehwc)
    616       1.1    abrown 	 */
    617       1.1    abrown 	sc->sc_savectl = sc->sc_ctl->ctl_mctl;
    618       1.1    abrown 	sc->sc_savehwc = sc->sc_hwc->curs_ctl;
    619       1.1    abrown 
    620  1.39.2.1      yamt 	clut = (volatile uint32_t *) sc->sc_clut1->clut_lut;
    621  1.39.2.1      yamt 	xlut = (volatile uint8_t *) sc->sc_xlut->xlut_lut;
    622       1.1    abrown 	for (i = 0; i < CG14_CLUT_SIZE; i++) {
    623       1.1    abrown 		sc->sc_saveclut.cm_chip[i] = clut[i];
    624       1.1    abrown 		sc->sc_savexlut[i] = xlut[i];
    625       1.1    abrown 	}
    626       1.1    abrown 
    627       1.1    abrown #ifdef CG14_CG8
    628       1.1    abrown 	/*
    629       1.1    abrown 	 * Enable the video, and put in 24 bit mode.
    630       1.1    abrown 	 */
    631       1.1    abrown 	sc->sc_ctl->ctl_mctl = CG14_MCTL_ENABLEVID | CG14_MCTL_PIXMODE_32 |
    632       1.1    abrown 		CG14_MCTL_POWERCTL;
    633       1.1    abrown 
    634      1.12        pk 	/*
    635       1.1    abrown 	 * Zero the xlut to enable direct-color mode
    636       1.1    abrown 	 */
    637  1.39.2.1      yamt 	for (i = 0; i < CG14_CLUT_SIZE; i++)
    638  1.39.2.1      yamt 		sc->sc_xlut->xlut_lut[i] = 0;
    639       1.1    abrown #else
    640       1.1    abrown 	/*
    641       1.1    abrown 	 * Enable the video and put it in 8 bit mode
    642       1.1    abrown 	 */
    643       1.1    abrown 	sc->sc_ctl->ctl_mctl = CG14_MCTL_ENABLEVID | CG14_MCTL_PIXMODE_8 |
    644       1.1    abrown 		CG14_MCTL_POWERCTL;
    645       1.1    abrown #endif
    646       1.1    abrown }
    647       1.1    abrown 
    648       1.1    abrown static void
    649  1.39.2.1      yamt /* Restore the state saved on cg14_init */
    650  1.39.2.1      yamt cg14_reset(struct cgfourteen_softc *sc)
    651       1.1    abrown {
    652  1.39.2.1      yamt 	volatile uint32_t *clut;
    653  1.39.2.1      yamt 	volatile uint8_t  *xlut;
    654      1.11        pk 	int i;
    655       1.1    abrown 
    656       1.1    abrown 	/*
    657       1.1    abrown 	 * We restore the following, saved in cg14_init:
    658       1.1    abrown 	 *
    659       1.1    abrown 	 * 	color look-up table 1 	(sc->sc_saveclut)
    660       1.1    abrown 	 *	x look-up table		(sc->sc_savexlut)
    661       1.1    abrown 	 *	control register	(sc->sc_savectl)
    662       1.1    abrown 	 *	cursor control register (sc->sc_savehwc)
    663       1.1    abrown 	 *
    664       1.1    abrown 	 * Note that we don't touch the video enable bits in the
    665       1.1    abrown 	 * control register; otherwise, screenblank wouldn't work.
    666       1.1    abrown 	 */
    667       1.1    abrown 	sc->sc_ctl->ctl_mctl = (sc->sc_ctl->ctl_mctl & (CG14_MCTL_ENABLEVID |
    668       1.1    abrown 							CG14_MCTL_POWERCTL)) |
    669       1.1    abrown 				(sc->sc_savectl & ~(CG14_MCTL_ENABLEVID |
    670       1.1    abrown 						    CG14_MCTL_POWERCTL));
    671       1.1    abrown 	sc->sc_hwc->curs_ctl = sc->sc_savehwc;
    672       1.1    abrown 
    673      1.39   tsutsui 	clut = sc->sc_clut1->clut_lut;
    674      1.39   tsutsui 	xlut = sc->sc_xlut->xlut_lut;
    675       1.1    abrown 	for (i = 0; i < CG14_CLUT_SIZE; i++) {
    676       1.1    abrown 		clut[i] = sc->sc_saveclut.cm_chip[i];
    677       1.1    abrown 		xlut[i] = sc->sc_savexlut[i];
    678       1.1    abrown 	}
    679       1.1    abrown }
    680       1.1    abrown 
    681       1.1    abrown /* Enable/disable video display; power down monitor if DPMS-capable */
    682       1.1    abrown static void
    683  1.39.2.1      yamt cg14_set_video(struct cgfourteen_softc *sc, int enable)
    684       1.1    abrown {
    685      1.12        pk 	/*
    686       1.1    abrown 	 * We can only use DPMS to power down the display if the chip revision
    687       1.1    abrown 	 * is greater than 0.
    688       1.1    abrown 	 */
    689       1.1    abrown 	if (enable) {
    690       1.1    abrown 		if ((sc->sc_ctl->ctl_rsr & CG14_RSR_REVMASK) > 0)
    691       1.1    abrown 			sc->sc_ctl->ctl_mctl |= (CG14_MCTL_ENABLEVID |
    692       1.1    abrown 						 CG14_MCTL_POWERCTL);
    693       1.1    abrown 		else
    694       1.1    abrown 			sc->sc_ctl->ctl_mctl |= CG14_MCTL_ENABLEVID;
    695       1.1    abrown 	} else {
    696       1.1    abrown 		if ((sc->sc_ctl->ctl_rsr & CG14_RSR_REVMASK) > 0)
    697       1.1    abrown 			sc->sc_ctl->ctl_mctl &= ~(CG14_MCTL_ENABLEVID |
    698       1.1    abrown 						  CG14_MCTL_POWERCTL);
    699       1.1    abrown 		else
    700       1.1    abrown 			sc->sc_ctl->ctl_mctl &= ~CG14_MCTL_ENABLEVID;
    701       1.1    abrown 	}
    702       1.1    abrown }
    703       1.1    abrown 
    704       1.1    abrown /* Get status of video display */
    705       1.1    abrown static int
    706  1.39.2.1      yamt cg14_get_video(struct cgfourteen_softc *sc)
    707       1.1    abrown {
    708       1.1    abrown 	return ((sc->sc_ctl->ctl_mctl & CG14_MCTL_ENABLEVID) != 0);
    709       1.1    abrown }
    710       1.1    abrown 
    711       1.1    abrown /* Read the software shadow colormap */
    712      1.12        pk static int
    713  1.39.2.1      yamt cg14_get_cmap(struct fbcmap *p, union cg14cmap *cm, int cmsize)
    714       1.1    abrown {
    715  1.39.2.1      yamt         u_int i, start, count;
    716  1.39.2.1      yamt         u_char *cp;
    717  1.39.2.1      yamt         int error;
    718  1.39.2.1      yamt 
    719  1.39.2.1      yamt         start = p->index;
    720  1.39.2.1      yamt         count = p->count;
    721  1.39.2.1      yamt         if (start >= cmsize || count > cmsize - start)
    722  1.39.2.1      yamt                 return (EINVAL);
    723  1.39.2.1      yamt 
    724  1.39.2.1      yamt         for (cp = &cm->cm_map[start][0], i = 0; i < count; cp += 4, i++) {
    725  1.39.2.1      yamt                 error = copyout(&cp[3], &p->red[i], 1);
    726  1.39.2.1      yamt                 if (error)
    727  1.39.2.1      yamt                         return error;
    728  1.39.2.1      yamt                 error = copyout(&cp[2], &p->green[i], 1);
    729  1.39.2.1      yamt                 if (error)
    730  1.39.2.1      yamt                         return error;
    731  1.39.2.1      yamt                 error = copyout(&cp[1], &p->blue[i], 1);
    732  1.39.2.1      yamt                 if (error)
    733  1.39.2.1      yamt                         return error;
    734  1.39.2.1      yamt         }
    735  1.39.2.1      yamt         return (0);
    736       1.1    abrown }
    737       1.1    abrown 
    738       1.1    abrown /* Write the software shadow colormap */
    739       1.1    abrown static int
    740  1.39.2.1      yamt cg14_put_cmap(struct fbcmap *p, union cg14cmap *cm, int cmsize)
    741  1.39.2.1      yamt {
    742  1.39.2.1      yamt         u_int i, start, count;
    743  1.39.2.1      yamt         u_char *cp;
    744  1.39.2.1      yamt         u_char cmap[256][4];
    745  1.39.2.1      yamt         int error;
    746  1.39.2.1      yamt 
    747  1.39.2.1      yamt         start = p->index;
    748  1.39.2.1      yamt         count = p->count;
    749  1.39.2.1      yamt         if (start >= cmsize || count > cmsize - start)
    750  1.39.2.1      yamt                 return (EINVAL);
    751  1.39.2.1      yamt 
    752  1.39.2.1      yamt         memcpy(&cmap, &cm->cm_map, sizeof cmap);
    753  1.39.2.1      yamt         for (cp = &cmap[start][0], i = 0; i < count; cp += 4, i++) {
    754  1.39.2.1      yamt                 error = copyin(&p->red[i], &cp[3], 1);
    755  1.39.2.1      yamt                 if (error)
    756  1.39.2.1      yamt                         return error;
    757  1.39.2.1      yamt                 error = copyin(&p->green[i], &cp[2], 1);
    758  1.39.2.1      yamt                 if (error)
    759  1.39.2.1      yamt                         return error;
    760  1.39.2.1      yamt                 error = copyin(&p->blue[i], &cp[1], 1);
    761  1.39.2.1      yamt                 if (error)
    762  1.39.2.1      yamt                         return error;
    763  1.39.2.1      yamt                 cp[0] = 0;      /* no alpha channel */
    764  1.39.2.1      yamt         }
    765  1.39.2.1      yamt         memcpy(&cm->cm_map, &cmap, sizeof cmap);
    766  1.39.2.1      yamt         return (0);
    767       1.1    abrown }
    768       1.1    abrown 
    769       1.1    abrown static void
    770  1.39.2.1      yamt cg14_load_hwcmap(struct cgfourteen_softc *sc, int start, int ncolors)
    771       1.1    abrown {
    772       1.1    abrown 	/* XXX switch to auto-increment, and on retrace intr */
    773  1.39.2.1      yamt 
    774       1.1    abrown 	/* Setup pointers to source and dest */
    775  1.39.2.1      yamt 	uint32_t *colp = &sc->sc_cmap.cm_chip[start];
    776  1.39.2.1      yamt 	volatile uint32_t *lutp = &sc->sc_clut1->clut_lut[start];
    777       1.1    abrown 
    778       1.1    abrown 	/* Copy by words */
    779       1.1    abrown 	while (--ncolors >= 0)
    780       1.1    abrown 		*lutp++ = *colp++;
    781       1.1    abrown }
    782  1.39.2.3      yamt 
    783  1.39.2.3      yamt #if NWSDISPLAY > 0
    784  1.39.2.3      yamt static void
    785  1.39.2.3      yamt cg14_setup_wsdisplay(struct cgfourteen_softc *sc, int is_cons)
    786  1.39.2.3      yamt {
    787  1.39.2.3      yamt 	struct wsemuldisplaydev_attach_args aa;
    788  1.39.2.3      yamt 	struct rasops_info *ri;
    789  1.39.2.3      yamt 	long defattr;
    790  1.39.2.3      yamt 
    791  1.39.2.3      yamt  	sc->sc_defaultscreen_descr = (struct wsscreen_descr){
    792  1.39.2.3      yamt 		"default",
    793  1.39.2.3      yamt 		0, 0,
    794  1.39.2.3      yamt 		NULL,
    795  1.39.2.3      yamt 		8, 16,
    796  1.39.2.3      yamt 		WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    797  1.39.2.3      yamt 		NULL
    798  1.39.2.3      yamt 	};
    799  1.39.2.3      yamt 	sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
    800  1.39.2.3      yamt 	sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
    801  1.39.2.3      yamt 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    802  1.39.2.3      yamt 	vcons_init(&sc->sc_vd, sc, &sc->sc_defaultscreen_descr,
    803  1.39.2.3      yamt 	    &cg14_accessops);
    804  1.39.2.3      yamt 	sc->sc_vd.init_screen = cg14_init_screen;
    805  1.39.2.3      yamt 
    806  1.39.2.3      yamt 	ri = &sc->sc_console_screen.scr_ri;
    807  1.39.2.3      yamt 
    808  1.39.2.3      yamt 	if (is_cons) {
    809  1.39.2.3      yamt 		vcons_init_screen(&sc->sc_vd, &sc->sc_console_screen, 1,
    810  1.39.2.3      yamt 		    &defattr);
    811  1.39.2.3      yamt 		sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    812  1.39.2.3      yamt 
    813  1.39.2.3      yamt 		sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
    814  1.39.2.3      yamt 		sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
    815  1.39.2.3      yamt 		sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
    816  1.39.2.3      yamt 		sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
    817  1.39.2.3      yamt 		wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
    818  1.39.2.3      yamt 		    defattr);
    819  1.39.2.3      yamt 	} else {
    820  1.39.2.3      yamt 		/*
    821  1.39.2.3      yamt 		 * since we're not the console we can postpone the rest
    822  1.39.2.3      yamt 		 * until someone actually allocates a screen for us
    823  1.39.2.3      yamt 		 */
    824  1.39.2.3      yamt 	}
    825  1.39.2.3      yamt 
    826  1.39.2.3      yamt 	cg14_init_cmap(sc);
    827  1.39.2.3      yamt 
    828  1.39.2.3      yamt 	aa.console = is_cons;
    829  1.39.2.3      yamt 	aa.scrdata = &sc->sc_screenlist;
    830  1.39.2.3      yamt 	aa.accessops = &cg14_accessops;
    831  1.39.2.3      yamt 	aa.accesscookie = &sc->sc_vd;
    832  1.39.2.3      yamt 
    833  1.39.2.3      yamt 	config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
    834  1.39.2.3      yamt }
    835  1.39.2.3      yamt 
    836  1.39.2.3      yamt static void
    837  1.39.2.3      yamt cg14_init_cmap(struct cgfourteen_softc *sc)
    838  1.39.2.3      yamt {
    839  1.39.2.3      yamt 	int i, j = 0;
    840  1.39.2.3      yamt 
    841  1.39.2.3      yamt 	for (i = 0; i < 256; i++) {
    842  1.39.2.3      yamt 
    843  1.39.2.3      yamt 		sc->sc_cmap.cm_map[i][3] = rasops_cmap[j];
    844  1.39.2.3      yamt 		sc->sc_cmap.cm_map[i][2] = rasops_cmap[j + 1];
    845  1.39.2.3      yamt 		sc->sc_cmap.cm_map[i][1] = rasops_cmap[j + 2];
    846  1.39.2.3      yamt 		j += 3;
    847  1.39.2.3      yamt 	}
    848  1.39.2.3      yamt 	cg14_load_hwcmap(sc, 0, 256);
    849  1.39.2.3      yamt }
    850  1.39.2.3      yamt 
    851  1.39.2.3      yamt static int
    852  1.39.2.3      yamt cg14_putcmap(struct cgfourteen_softc *sc, struct wsdisplay_cmap *cm)
    853  1.39.2.3      yamt {
    854  1.39.2.3      yamt 	u_int index = cm->index;
    855  1.39.2.3      yamt 	u_int count = cm->count;
    856  1.39.2.3      yamt 	int i, error;
    857  1.39.2.3      yamt 	u_char rbuf[256], gbuf[256], bbuf[256];
    858  1.39.2.3      yamt 
    859  1.39.2.3      yamt 	if (cm->index >= 256 || cm->count > 256 ||
    860  1.39.2.3      yamt 	    (cm->index + cm->count) > 256)
    861  1.39.2.3      yamt 		return EINVAL;
    862  1.39.2.3      yamt 	error = copyin(cm->red, &rbuf[index], count);
    863  1.39.2.3      yamt 	if (error)
    864  1.39.2.3      yamt 		return error;
    865  1.39.2.3      yamt 	error = copyin(cm->green, &gbuf[index], count);
    866  1.39.2.3      yamt 	if (error)
    867  1.39.2.3      yamt 		return error;
    868  1.39.2.3      yamt 	error = copyin(cm->blue, &bbuf[index], count);
    869  1.39.2.3      yamt 	if (error)
    870  1.39.2.3      yamt 		return error;
    871  1.39.2.3      yamt 
    872  1.39.2.3      yamt 	for (i = 0; i < count; i++) {
    873  1.39.2.3      yamt 		sc->sc_cmap.cm_map[index][3] = rbuf[index];
    874  1.39.2.3      yamt 		sc->sc_cmap.cm_map[index][2] = gbuf[index];
    875  1.39.2.3      yamt 		sc->sc_cmap.cm_map[index][1] = bbuf[index];
    876  1.39.2.3      yamt 
    877  1.39.2.3      yamt 		index++;
    878  1.39.2.3      yamt 	}
    879  1.39.2.3      yamt 	cg14_load_hwcmap(sc, 0, 256);
    880  1.39.2.3      yamt 	return 0;
    881  1.39.2.3      yamt }
    882  1.39.2.3      yamt 
    883  1.39.2.3      yamt static int
    884  1.39.2.3      yamt cg14_getcmap(struct cgfourteen_softc *sc, struct wsdisplay_cmap *cm)
    885  1.39.2.3      yamt {
    886  1.39.2.3      yamt 	uint8_t rbuf[256], gbuf[256], bbuf[256];
    887  1.39.2.3      yamt 	u_int index = cm->index;
    888  1.39.2.3      yamt 	u_int count = cm->count;
    889  1.39.2.3      yamt 	int error, i;
    890  1.39.2.3      yamt 
    891  1.39.2.3      yamt 	if (index >= 255 || count > 256 || index + count > 256)
    892  1.39.2.3      yamt 		return EINVAL;
    893  1.39.2.3      yamt 
    894  1.39.2.3      yamt 
    895  1.39.2.3      yamt 	for (i = 0; i < count; i++) {
    896  1.39.2.3      yamt 		rbuf[i] = sc->sc_cmap.cm_map[index][3];
    897  1.39.2.3      yamt 		gbuf[i] = sc->sc_cmap.cm_map[index][2];
    898  1.39.2.3      yamt 		bbuf[i] = sc->sc_cmap.cm_map[index][1];
    899  1.39.2.3      yamt 
    900  1.39.2.3      yamt 		index++;
    901  1.39.2.3      yamt 	}
    902  1.39.2.3      yamt 	error = copyout(rbuf,   cm->red,   count);
    903  1.39.2.3      yamt 	if (error)
    904  1.39.2.3      yamt 		return error;
    905  1.39.2.3      yamt 	error = copyout(gbuf, cm->green, count);
    906  1.39.2.3      yamt 	if (error)
    907  1.39.2.3      yamt 		return error;
    908  1.39.2.3      yamt 	error = copyout(bbuf,  cm->blue,  count);
    909  1.39.2.3      yamt 	if (error)
    910  1.39.2.3      yamt 		return error;
    911  1.39.2.3      yamt 
    912  1.39.2.3      yamt 	return 0;
    913  1.39.2.3      yamt }
    914  1.39.2.3      yamt static int
    915  1.39.2.3      yamt cg14_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    916  1.39.2.3      yamt 	struct lwp *l)
    917  1.39.2.3      yamt {
    918  1.39.2.3      yamt 	struct vcons_data *vd = v;
    919  1.39.2.3      yamt 	struct cgfourteen_softc *sc = vd->cookie;
    920  1.39.2.3      yamt 	struct wsdisplay_fbinfo *wdf;
    921  1.39.2.3      yamt 	struct vcons_screen *ms = vd->active;
    922  1.39.2.3      yamt 
    923  1.39.2.3      yamt 	switch (cmd) {
    924  1.39.2.3      yamt 
    925  1.39.2.3      yamt 		case WSDISPLAYIO_GTYPE:
    926  1.39.2.3      yamt 			*(uint32_t *)data = WSDISPLAY_TYPE_SUNCG14;
    927  1.39.2.3      yamt 			return 0;
    928  1.39.2.3      yamt 
    929  1.39.2.3      yamt 		case WSDISPLAYIO_GINFO:
    930  1.39.2.3      yamt 			wdf = (void *)data;
    931  1.39.2.3      yamt 			wdf->height = ms->scr_ri.ri_height;
    932  1.39.2.3      yamt 			wdf->width = ms->scr_ri.ri_width;
    933  1.39.2.3      yamt 			wdf->depth = 32;
    934  1.39.2.3      yamt 			wdf->cmsize = 256;
    935  1.39.2.3      yamt 			return 0;
    936  1.39.2.3      yamt 
    937  1.39.2.3      yamt 		case WSDISPLAYIO_GETCMAP:
    938  1.39.2.3      yamt 			return cg14_getcmap(sc,
    939  1.39.2.3      yamt 			    (struct wsdisplay_cmap *)data);
    940  1.39.2.3      yamt 
    941  1.39.2.3      yamt 		case WSDISPLAYIO_PUTCMAP:
    942  1.39.2.3      yamt 			return cg14_putcmap(sc,
    943  1.39.2.3      yamt 			    (struct wsdisplay_cmap *)data);
    944  1.39.2.3      yamt 
    945  1.39.2.3      yamt 		case WSDISPLAYIO_LINEBYTES:
    946  1.39.2.3      yamt 			*(u_int *)data = ms->scr_ri.ri_width << 2;
    947  1.39.2.3      yamt 			return 0;
    948  1.39.2.3      yamt 
    949  1.39.2.3      yamt 		case WSDISPLAYIO_SMODE:
    950  1.39.2.3      yamt 			{
    951  1.39.2.3      yamt 				int new_mode = *(int*)data;
    952  1.39.2.3      yamt 				if (new_mode != sc->sc_mode) {
    953  1.39.2.3      yamt 					sc->sc_mode = new_mode;
    954  1.39.2.3      yamt 					if(new_mode == WSDISPLAYIO_MODE_EMUL) {
    955  1.39.2.3      yamt 						bus_space_write_1(sc->sc_bustag,
    956  1.39.2.3      yamt 						    sc->sc_regh,
    957  1.39.2.3      yamt 						    CG14_CURSOR_CONTROL, 0);
    958  1.39.2.3      yamt 						cg14_set_depth(sc, 8);
    959  1.39.2.3      yamt 						cg14_init_cmap(sc);
    960  1.39.2.3      yamt 						vcons_redraw_screen(ms);
    961  1.39.2.3      yamt 					} else
    962  1.39.2.3      yamt 						cg14_set_depth(sc, 32);
    963  1.39.2.3      yamt 				}
    964  1.39.2.3      yamt 			}
    965  1.39.2.3      yamt 			return 0;
    966  1.39.2.3      yamt 		case WSDISPLAYIO_SVIDEO:
    967  1.39.2.3      yamt 			cg14_set_video(sc, *(int *)data);
    968  1.39.2.3      yamt 			return 0;
    969  1.39.2.3      yamt 		case WSDISPLAYIO_GVIDEO:
    970  1.39.2.3      yamt 			return cg14_get_video(sc) ?
    971  1.39.2.3      yamt 			    WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF;
    972  1.39.2.3      yamt 		case WSDISPLAYIO_GCURPOS:
    973  1.39.2.3      yamt 			{
    974  1.39.2.3      yamt 				struct wsdisplay_curpos *cp = (void *)data;
    975  1.39.2.3      yamt 
    976  1.39.2.3      yamt 				cp->x = sc->sc_cursor.cc_pos.x;
    977  1.39.2.3      yamt 				cp->y = sc->sc_cursor.cc_pos.y;
    978  1.39.2.3      yamt 			}
    979  1.39.2.3      yamt 			return 0;
    980  1.39.2.3      yamt 		case WSDISPLAYIO_SCURPOS:
    981  1.39.2.3      yamt 			{
    982  1.39.2.3      yamt 				struct wsdisplay_curpos *cp = (void *)data;
    983  1.39.2.3      yamt 
    984  1.39.2.3      yamt 				cg14_move_cursor(sc, cp->x, cp->y);
    985  1.39.2.3      yamt 			}
    986  1.39.2.3      yamt 			return 0;
    987  1.39.2.3      yamt 		case WSDISPLAYIO_GCURMAX:
    988  1.39.2.3      yamt 			{
    989  1.39.2.3      yamt 				struct wsdisplay_curpos *cp = (void *)data;
    990  1.39.2.3      yamt 
    991  1.39.2.3      yamt 				cp->x = 32;
    992  1.39.2.3      yamt 				cp->y = 32;
    993  1.39.2.3      yamt 			}
    994  1.39.2.3      yamt 			return 0;
    995  1.39.2.3      yamt 		case WSDISPLAYIO_SCURSOR:
    996  1.39.2.3      yamt 			{
    997  1.39.2.3      yamt 				struct wsdisplay_cursor *cursor = (void *)data;
    998  1.39.2.3      yamt 
    999  1.39.2.3      yamt 				return cg14_do_cursor(sc, cursor);
   1000  1.39.2.3      yamt 			}
   1001  1.39.2.3      yamt 	}
   1002  1.39.2.3      yamt 	return EPASSTHROUGH;
   1003  1.39.2.3      yamt }
   1004  1.39.2.3      yamt 
   1005  1.39.2.3      yamt static paddr_t
   1006  1.39.2.3      yamt cg14_mmap(void *v, void *vs, off_t offset, int prot)
   1007  1.39.2.3      yamt {
   1008  1.39.2.3      yamt 	struct vcons_data *vd = v;
   1009  1.39.2.3      yamt 	struct cgfourteen_softc *sc = vd->cookie;
   1010  1.39.2.3      yamt 
   1011  1.39.2.3      yamt 	/* allow mmap()ing the full framebuffer, not just what we use */
   1012  1.39.2.3      yamt 	if (offset < sc->sc_vramsize)
   1013  1.39.2.3      yamt 		return bus_space_mmap(sc->sc_bustag,
   1014  1.39.2.3      yamt 		    BUS_ADDR(sc->sc_physadr[CG14_PXL_IDX].sbr_slot,
   1015  1.39.2.3      yamt 		      sc->sc_physadr[CG14_PXL_IDX].sbr_offset),
   1016  1.39.2.3      yamt 		    offset + CG14_FB_CBGR, prot, BUS_SPACE_MAP_LINEAR);
   1017  1.39.2.3      yamt 
   1018  1.39.2.3      yamt 	return -1;
   1019  1.39.2.3      yamt }
   1020  1.39.2.3      yamt 
   1021  1.39.2.3      yamt static void
   1022  1.39.2.3      yamt cg14_init_screen(void *cookie, struct vcons_screen *scr,
   1023  1.39.2.3      yamt     int existing, long *defattr)
   1024  1.39.2.3      yamt {
   1025  1.39.2.3      yamt 	struct cgfourteen_softc *sc = cookie;
   1026  1.39.2.3      yamt 	struct rasops_info *ri = &scr->scr_ri;
   1027  1.39.2.3      yamt 
   1028  1.39.2.3      yamt 	ri->ri_depth = 8;
   1029  1.39.2.3      yamt 	ri->ri_width = sc->sc_fb.fb_type.fb_width;
   1030  1.39.2.3      yamt 	ri->ri_height = sc->sc_fb.fb_type.fb_height;
   1031  1.39.2.3      yamt 	ri->ri_stride = ri->ri_width;
   1032  1.39.2.3      yamt 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
   1033  1.39.2.3      yamt 
   1034  1.39.2.3      yamt 	ri->ri_bits = (char *)sc->sc_fb.fb_pixels;
   1035  1.39.2.3      yamt 
   1036  1.39.2.3      yamt 	if (existing) {
   1037  1.39.2.3      yamt 		ri->ri_flg |= RI_CLEAR;
   1038  1.39.2.3      yamt 	}
   1039  1.39.2.3      yamt 
   1040  1.39.2.3      yamt 	rasops_init(ri, sc->sc_fb.fb_type.fb_height / 8,
   1041  1.39.2.3      yamt 	     sc->sc_fb.fb_type.fb_width / 8);
   1042  1.39.2.3      yamt 	ri->ri_caps = WSSCREEN_WSCOLORS;
   1043  1.39.2.3      yamt 
   1044  1.39.2.3      yamt 	rasops_reconfig(ri,
   1045  1.39.2.3      yamt 	    sc->sc_fb.fb_type.fb_height / ri->ri_font->fontheight,
   1046  1.39.2.3      yamt 	    sc->sc_fb.fb_type.fb_width / ri->ri_font->fontwidth);
   1047  1.39.2.3      yamt 
   1048  1.39.2.3      yamt 	ri->ri_hw = scr;
   1049  1.39.2.3      yamt }
   1050  1.39.2.3      yamt 
   1051  1.39.2.3      yamt static void
   1052  1.39.2.3      yamt cg14_set_depth(struct cgfourteen_softc *sc, int depth)
   1053  1.39.2.3      yamt {
   1054  1.39.2.3      yamt 	int i;
   1055  1.39.2.3      yamt 
   1056  1.39.2.3      yamt 	if (sc->sc_depth == depth)
   1057  1.39.2.3      yamt 		return;
   1058  1.39.2.3      yamt 	switch (depth) {
   1059  1.39.2.3      yamt 		case 8:
   1060  1.39.2.3      yamt 			bus_space_write_1(sc->sc_bustag, sc->sc_regh,
   1061  1.39.2.3      yamt 			    CG14_MCTL, CG14_MCTL_ENABLEVID |
   1062  1.39.2.3      yamt 			    CG14_MCTL_PIXMODE_8 | CG14_MCTL_POWERCTL);
   1063  1.39.2.3      yamt 			sc->sc_depth = 8;
   1064  1.39.2.3      yamt 			/* everything is CLUT1 */
   1065  1.39.2.3      yamt 			for (i = 0; i < CG14_CLUT_SIZE; i++)
   1066  1.39.2.3      yamt 			     sc->sc_xlut->xlut_lut[i] = 0;
   1067  1.39.2.3      yamt 			break;
   1068  1.39.2.3      yamt 		case 32:
   1069  1.39.2.3      yamt 			bus_space_write_1(sc->sc_bustag, sc->sc_regh,
   1070  1.39.2.3      yamt 			    CG14_MCTL, CG14_MCTL_ENABLEVID |
   1071  1.39.2.3      yamt 			    CG14_MCTL_PIXMODE_32 | CG14_MCTL_POWERCTL);
   1072  1.39.2.3      yamt 			sc->sc_depth = 32;
   1073  1.39.2.3      yamt 			for (i = 0; i < CG14_CLUT_SIZE; i++)
   1074  1.39.2.3      yamt 			     sc->sc_xlut->xlut_lut[i] = 0;
   1075  1.39.2.3      yamt 			break;
   1076  1.39.2.3      yamt 		default:
   1077  1.39.2.3      yamt 			printf("%s: can't change to depth %d\n",
   1078  1.39.2.3      yamt 			    sc->sc_dev.dv_xname, depth);
   1079  1.39.2.3      yamt 	}
   1080  1.39.2.3      yamt }
   1081  1.39.2.3      yamt 
   1082  1.39.2.3      yamt static void
   1083  1.39.2.3      yamt cg14_move_cursor(struct cgfourteen_softc *sc, int x, int y)
   1084  1.39.2.3      yamt {
   1085  1.39.2.3      yamt 	uint32_t pos;
   1086  1.39.2.3      yamt 
   1087  1.39.2.3      yamt 	sc->sc_cursor.cc_pos.x = x;
   1088  1.39.2.3      yamt 	sc->sc_cursor.cc_pos.y = y;
   1089  1.39.2.3      yamt 	pos = ((sc->sc_cursor.cc_pos.x - sc->sc_cursor.cc_hot.x ) << 16) |
   1090  1.39.2.3      yamt 	      ((sc->sc_cursor.cc_pos.y - sc->sc_cursor.cc_hot.y ) & 0xffff);
   1091  1.39.2.3      yamt 	bus_space_write_4(sc->sc_bustag, sc->sc_regh, CG14_CURSOR_X, pos);
   1092  1.39.2.3      yamt }
   1093  1.39.2.3      yamt 
   1094  1.39.2.3      yamt static int
   1095  1.39.2.3      yamt cg14_do_cursor(struct cgfourteen_softc *sc, struct wsdisplay_cursor *cur)
   1096  1.39.2.3      yamt {
   1097  1.39.2.3      yamt 	if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
   1098  1.39.2.3      yamt 
   1099  1.39.2.3      yamt 		bus_space_write_1(sc->sc_bustag, sc->sc_regh,
   1100  1.39.2.3      yamt 		    CG14_CURSOR_CONTROL, cur->enable ? CG14_CRSR_ENABLE : 0);
   1101  1.39.2.3      yamt 	}
   1102  1.39.2.3      yamt 	if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
   1103  1.39.2.3      yamt 
   1104  1.39.2.3      yamt 		sc->sc_cursor.cc_hot.x = cur->hot.x;
   1105  1.39.2.3      yamt 		sc->sc_cursor.cc_hot.y = cur->hot.y;
   1106  1.39.2.3      yamt 		cur->which |= WSDISPLAY_CURSOR_DOPOS;
   1107  1.39.2.3      yamt 	}
   1108  1.39.2.3      yamt 	if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
   1109  1.39.2.3      yamt 
   1110  1.39.2.3      yamt 		cg14_move_cursor(sc, cur->pos.x, cur->pos.y);
   1111  1.39.2.3      yamt 	}
   1112  1.39.2.3      yamt 	if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
   1113  1.39.2.3      yamt 		int i;
   1114  1.39.2.3      yamt 		uint32_t val;
   1115  1.39.2.3      yamt 
   1116  1.39.2.3      yamt 		for (i = 0; i < cur->cmap.count; i++) {
   1117  1.39.2.3      yamt 			val = (cur->cmap.red[i] ) |
   1118  1.39.2.3      yamt 			      (cur->cmap.green[i] << 8) |
   1119  1.39.2.3      yamt 			      (cur->cmap.blue[i] << 16);
   1120  1.39.2.3      yamt 			bus_space_write_4(sc->sc_bustag, sc->sc_regh,
   1121  1.39.2.3      yamt 			    CG14_CURSOR_COLOR1 + ((i + cur->cmap.index) << 2),
   1122  1.39.2.3      yamt 			    val);
   1123  1.39.2.3      yamt 		}
   1124  1.39.2.3      yamt 	}
   1125  1.39.2.3      yamt 	if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
   1126  1.39.2.3      yamt 		uint32_t buffer[32], latch, tmp;
   1127  1.39.2.3      yamt 		int i;
   1128  1.39.2.3      yamt 
   1129  1.39.2.3      yamt 		memcpy(buffer, cur->mask, 128);
   1130  1.39.2.3      yamt 		for (i = 0; i < 32; i++) {
   1131  1.39.2.3      yamt 			latch = 0;
   1132  1.39.2.3      yamt 			tmp = buffer[i] & 0x80808080;
   1133  1.39.2.3      yamt 			latch |= tmp >> 7;
   1134  1.39.2.3      yamt 			tmp = buffer[i] & 0x40404040;
   1135  1.39.2.3      yamt 			latch |= tmp >> 5;
   1136  1.39.2.3      yamt 			tmp = buffer[i] & 0x20202020;
   1137  1.39.2.3      yamt 			latch |= tmp >> 3;
   1138  1.39.2.3      yamt 			tmp = buffer[i] & 0x10101010;
   1139  1.39.2.3      yamt 			latch |= tmp >> 1;
   1140  1.39.2.3      yamt 			tmp = buffer[i] & 0x08080808;
   1141  1.39.2.3      yamt 			latch |= tmp << 1;
   1142  1.39.2.3      yamt 			tmp = buffer[i] & 0x04040404;
   1143  1.39.2.3      yamt 			latch |= tmp << 3;
   1144  1.39.2.3      yamt 			tmp = buffer[i] & 0x02020202;
   1145  1.39.2.3      yamt 			latch |= tmp << 5;
   1146  1.39.2.3      yamt 			tmp = buffer[i] & 0x01010101;
   1147  1.39.2.3      yamt 			latch |= tmp << 7;
   1148  1.39.2.3      yamt 			bus_space_write_4(sc->sc_bustag, sc->sc_regh,
   1149  1.39.2.3      yamt 			    CG14_CURSOR_PLANE0 + (i << 2), latch);
   1150  1.39.2.3      yamt 		}
   1151  1.39.2.3      yamt 		memcpy(buffer, cur->image, 128);
   1152  1.39.2.3      yamt 		for (i = 0; i < 32; i++) {
   1153  1.39.2.3      yamt 			latch = 0;
   1154  1.39.2.3      yamt 			tmp = buffer[i] & 0x80808080;
   1155  1.39.2.3      yamt 			latch |= tmp >> 7;
   1156  1.39.2.3      yamt 			tmp = buffer[i] & 0x40404040;
   1157  1.39.2.3      yamt 			latch |= tmp >> 5;
   1158  1.39.2.3      yamt 			tmp = buffer[i] & 0x20202020;
   1159  1.39.2.3      yamt 			latch |= tmp >> 3;
   1160  1.39.2.3      yamt 			tmp = buffer[i] & 0x10101010;
   1161  1.39.2.3      yamt 			latch |= tmp >> 1;
   1162  1.39.2.3      yamt 			tmp = buffer[i] & 0x08080808;
   1163  1.39.2.3      yamt 			latch |= tmp << 1;
   1164  1.39.2.3      yamt 			tmp = buffer[i] & 0x04040404;
   1165  1.39.2.3      yamt 			latch |= tmp << 3;
   1166  1.39.2.3      yamt 			tmp = buffer[i] & 0x02020202;
   1167  1.39.2.3      yamt 			latch |= tmp << 5;
   1168  1.39.2.3      yamt 			tmp = buffer[i] & 0x01010101;
   1169  1.39.2.3      yamt 			latch |= tmp << 7;
   1170  1.39.2.3      yamt 			bus_space_write_4(sc->sc_bustag, sc->sc_regh,
   1171  1.39.2.3      yamt 			    CG14_CURSOR_PLANE1 + (i << 2), latch);
   1172  1.39.2.3      yamt 		}
   1173  1.39.2.3      yamt 	}
   1174  1.39.2.3      yamt 	return 0;
   1175  1.39.2.3      yamt }
   1176  1.39.2.3      yamt #endif
   1177