Home | History | Annotate | Line # | Download | only in dev
ffb.c revision 1.8.10.5
      1  1.8.10.5    tron /*	$NetBSD: ffb.c,v 1.8.10.5 2005/06/07 17:49:52 tron Exp $	*/
      2       1.1  petrov /*	$OpenBSD: creator.c,v 1.20 2002/07/30 19:48:15 jason Exp $	*/
      3       1.1  petrov 
      4       1.1  petrov /*
      5       1.1  petrov  * Copyright (c) 2002 Jason L. Wright (jason (at) thought.net)
      6       1.1  petrov  * All rights reserved.
      7       1.1  petrov  *
      8       1.1  petrov  * Redistribution and use in source and binary forms, with or without
      9       1.1  petrov  * modification, are permitted provided that the following conditions
     10       1.1  petrov  * are met:
     11       1.1  petrov  * 1. Redistributions of source code must retain the above copyright
     12       1.1  petrov  *    notice, this list of conditions and the following disclaimer.
     13       1.1  petrov  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.1  petrov  *    notice, this list of conditions and the following disclaimer in the
     15       1.1  petrov  *    documentation and/or other materials provided with the distribution.
     16       1.1  petrov  * 3. All advertising materials mentioning features or use of this software
     17       1.1  petrov  *    must display the following acknowledgement:
     18       1.1  petrov  *	This product includes software developed by Jason L. Wright
     19       1.1  petrov  * 4. The name of the author may not be used to endorse or promote products
     20       1.1  petrov  *    derived from this software without specific prior written permission.
     21       1.1  petrov  *
     22       1.1  petrov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23       1.1  petrov  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24       1.1  petrov  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25       1.1  petrov  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     26       1.1  petrov  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     27       1.1  petrov  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28       1.1  petrov  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29       1.1  petrov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     30       1.1  petrov  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     31       1.1  petrov  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32       1.1  petrov  * POSSIBILITY OF SUCH DAMAGE.
     33       1.1  petrov  */
     34       1.3   lukem 
     35       1.3   lukem #include <sys/cdefs.h>
     36  1.8.10.5    tron __KERNEL_RCSID(0, "$NetBSD: ffb.c,v 1.8.10.5 2005/06/07 17:49:52 tron Exp $");
     37       1.1  petrov 
     38       1.1  petrov #include <sys/types.h>
     39       1.1  petrov #include <sys/param.h>
     40       1.1  petrov #include <sys/systm.h>
     41       1.1  petrov #include <sys/kernel.h>
     42       1.1  petrov #include <sys/device.h>
     43       1.1  petrov #include <sys/conf.h>
     44       1.1  petrov 
     45       1.1  petrov #include <machine/bus.h>
     46       1.1  petrov #include <machine/autoconf.h>
     47       1.1  petrov #include <machine/openfirm.h>
     48  1.8.10.3    tron #include <machine/vmparam.h>
     49       1.1  petrov 
     50       1.1  petrov #include <dev/wscons/wsconsio.h>
     51  1.8.10.3    tron #include <dev/sun/fbio.h>
     52  1.8.10.3    tron #include <dev/sun/fbvar.h>
     53       1.1  petrov 
     54       1.1  petrov #include <sparc64/dev/ffbreg.h>
     55       1.1  petrov #include <sparc64/dev/ffbvar.h>
     56       1.1  petrov 
     57  1.8.10.3    tron extern struct cfdriver ffb_cd;
     58  1.8.10.3    tron 
     59       1.1  petrov struct wsscreen_descr ffb_stdscreen = {
     60       1.6    heas 	"sunffb",
     61       1.1  petrov 	0, 0,	/* will be filled in -- XXX shouldn't, it's global. */
     62       1.1  petrov 	0,
     63       1.1  petrov 	0, 0,
     64       1.1  petrov 	WSSCREEN_REVERSE | WSSCREEN_WSCOLORS
     65       1.1  petrov };
     66       1.1  petrov 
     67       1.1  petrov const struct wsscreen_descr *ffb_scrlist[] = {
     68       1.1  petrov 	&ffb_stdscreen,
     69       1.1  petrov 	/* XXX other formats? */
     70       1.1  petrov };
     71       1.1  petrov 
     72       1.1  petrov struct wsscreen_list ffb_screenlist = {
     73       1.1  petrov 	sizeof(ffb_scrlist) / sizeof(struct wsscreen_descr *),
     74       1.1  petrov 	    ffb_scrlist
     75       1.1  petrov };
     76       1.1  petrov 
     77       1.1  petrov int	ffb_ioctl(void *, u_long, caddr_t, int, struct proc *);
     78       1.1  petrov int	ffb_alloc_screen(void *, const struct wsscreen_descr *, void **,
     79       1.1  petrov 	    int *, int *, long *);
     80       1.7    heas static int ffb_blank(struct ffb_softc *, u_long, u_int *);
     81       1.1  petrov void	ffb_free_screen(void *, void *);
     82       1.1  petrov int	ffb_show_screen(void *, void *, int, void (*cb)(void *, int, int),
     83       1.1  petrov 	    void *);
     84       1.1  petrov paddr_t ffb_mmap(void *, off_t, int);
     85       1.1  petrov void	ffb_ras_fifo_wait(struct ffb_softc *, int);
     86       1.1  petrov void	ffb_ras_wait(struct ffb_softc *);
     87       1.1  petrov void	ffb_ras_init(struct ffb_softc *);
     88       1.1  petrov void	ffb_ras_copyrows(void *, int, int, int);
     89       1.1  petrov void	ffb_ras_erasecols(void *, int, int, int, long int);
     90       1.1  petrov void	ffb_ras_eraserows(void *, int, int, long int);
     91       1.1  petrov void	ffb_ras_do_cursor(struct rasops_info *);
     92       1.1  petrov void	ffb_ras_fill(struct ffb_softc *);
     93       1.1  petrov void	ffb_ras_setfg(struct ffb_softc *, int32_t);
     94       1.1  petrov 
     95  1.8.10.3    tron /* frame buffer generic driver */
     96  1.8.10.3    tron static void ffbfb_unblank(struct device*);
     97  1.8.10.3    tron dev_type_open(ffbfb_open);
     98  1.8.10.3    tron dev_type_close(ffbfb_close);
     99  1.8.10.3    tron dev_type_ioctl(ffbfb_ioctl);
    100  1.8.10.3    tron dev_type_mmap(ffbfb_mmap);
    101  1.8.10.3    tron static struct fbdriver ffb_fbdriver = {
    102  1.8.10.3    tron         ffbfb_unblank, ffbfb_open, ffbfb_close, ffbfb_ioctl, nopoll,
    103  1.8.10.3    tron 	ffbfb_mmap, nokqfilter
    104  1.8.10.3    tron };
    105  1.8.10.3    tron 
    106       1.1  petrov struct wsdisplay_accessops ffb_accessops = {
    107       1.1  petrov 	ffb_ioctl,
    108       1.1  petrov 	ffb_mmap,
    109       1.1  petrov 	ffb_alloc_screen,
    110       1.1  petrov 	ffb_free_screen,
    111       1.1  petrov 	ffb_show_screen,
    112       1.1  petrov 	NULL,	/* load font */
    113       1.8    heas 	NULL,	/* pollc */
    114       1.8    heas 	NULL,	/* getwschar */
    115       1.8    heas 	NULL,	/* putwschar */
    116       1.8    heas 	NULL,	/* scroll */
    117       1.1  petrov };
    118       1.1  petrov 
    119       1.1  petrov void
    120       1.1  petrov ffb_attach(struct ffb_softc *sc)
    121       1.1  petrov {
    122       1.1  petrov 	struct wsemuldisplaydev_attach_args waa;
    123       1.1  petrov 	char *model;
    124       1.1  petrov 	int btype;
    125       1.4      pk 	int maxrow, maxcol;
    126       1.7    heas 	u_int blank = WSDISPLAYIO_VIDEO_ON;
    127       1.4      pk 	char buf[6+1];
    128       1.1  petrov 
    129       1.1  petrov 	printf(":");
    130       1.1  petrov 
    131       1.1  petrov 	if (sc->sc_type == FFB_CREATOR) {
    132       1.5      pk 		btype = prom_getpropint(sc->sc_node, "board_type", 0);
    133       1.1  petrov 		if ((btype & 7) == 3)
    134       1.1  petrov 			printf(" Creator3D");
    135       1.1  petrov 		else
    136       1.1  petrov 			printf(" Creator");
    137       1.1  petrov 	} else
    138       1.1  petrov 		printf(" Elite3D");
    139       1.1  petrov 
    140       1.5      pk 	model = prom_getpropstring(sc->sc_node, "model");
    141       1.1  petrov 	if (model == NULL || strlen(model) == 0)
    142       1.1  petrov 		model = "unknown";
    143       1.1  petrov 
    144       1.1  petrov 	sc->sc_depth = 24;
    145       1.1  petrov 	sc->sc_linebytes = 8192;
    146       1.5      pk 	sc->sc_height = prom_getpropint(sc->sc_node, "height", 0);
    147       1.5      pk 	sc->sc_width = prom_getpropint(sc->sc_node, "width", 0);
    148       1.1  petrov 
    149  1.8.10.3    tron 	sc->sc_fb.fb_rinfo.ri_depth = 32;
    150  1.8.10.3    tron 	sc->sc_fb.fb_rinfo.ri_stride = sc->sc_linebytes;
    151  1.8.10.3    tron 	sc->sc_fb.fb_rinfo.ri_flg = RI_CENTER;
    152  1.8.10.3    tron 	sc->sc_fb.fb_rinfo.ri_bits = (void *)bus_space_vaddr(sc->sc_bt,
    153       1.1  petrov 	    sc->sc_pixel_h);
    154       1.1  petrov 
    155  1.8.10.3    tron 	sc->sc_fb.fb_rinfo.ri_width = sc->sc_width;
    156  1.8.10.3    tron 	sc->sc_fb.fb_rinfo.ri_height = sc->sc_height;
    157  1.8.10.3    tron 	sc->sc_fb.fb_rinfo.ri_hw = sc;
    158       1.1  petrov 
    159       1.4      pk 	maxcol = (prom_getoption("screen-#columns", buf, sizeof buf) == 0)
    160       1.4      pk 		? strtoul(buf, NULL, 10)
    161       1.4      pk 		: 80;
    162       1.4      pk 
    163       1.4      pk 	maxrow = (prom_getoption("screen-#rows", buf, sizeof buf) != 0)
    164       1.4      pk 		? strtoul(buf, NULL, 10)
    165       1.4      pk 		: 34;
    166       1.4      pk 
    167  1.8.10.3    tron 	rasops_init(&sc->sc_fb.fb_rinfo, maxrow, maxcol);
    168       1.1  petrov 
    169       1.1  petrov 	if ((sc->sc_dv.dv_cfdata->cf_flags & FFB_CFFLAG_NOACCEL) == 0) {
    170  1.8.10.3    tron 		sc->sc_fb.fb_rinfo.ri_hw = sc;
    171  1.8.10.3    tron 		sc->sc_fb.fb_rinfo.ri_ops.eraserows = ffb_ras_eraserows;
    172  1.8.10.3    tron 		sc->sc_fb.fb_rinfo.ri_ops.erasecols = ffb_ras_erasecols;
    173  1.8.10.3    tron 		sc->sc_fb.fb_rinfo.ri_ops.copyrows = ffb_ras_copyrows;
    174       1.1  petrov 		ffb_ras_init(sc);
    175       1.1  petrov 	}
    176       1.1  petrov 
    177  1.8.10.3    tron 	ffb_stdscreen.nrows = sc->sc_fb.fb_rinfo.ri_rows;
    178  1.8.10.3    tron 	ffb_stdscreen.ncols = sc->sc_fb.fb_rinfo.ri_cols;
    179  1.8.10.3    tron 	ffb_stdscreen.textops = &sc->sc_fb.fb_rinfo.ri_ops;
    180       1.1  petrov 
    181       1.8    heas 	/* collect DAC version, as Elite3D cursor enable bit is reversed */
    182       1.8    heas 	DAC_WRITE(sc, FFB_DAC_TYPE, FFB_DAC_GVERS);
    183       1.8    heas 	sc->sc_dacrev = DAC_READ(sc, FFB_DAC_VALUE) >> 28;
    184       1.8    heas 
    185       1.8    heas 	if (sc->sc_type == FFB_AFB)
    186       1.8    heas 		sc->sc_dacrev = 10;
    187       1.8    heas 	printf(", model %s, dac %u\n", model, sc->sc_dacrev);
    188       1.8    heas 
    189       1.7    heas 	ffb_blank(sc, WSDISPLAYIO_SVIDEO, &blank);
    190       1.7    heas 
    191  1.8.10.3    tron 	sc->sc_fb.fb_driver = &ffb_fbdriver;
    192  1.8.10.3    tron 	sc->sc_fb.fb_type.fb_cmsize = 0;
    193  1.8.10.3    tron 	sc->sc_fb.fb_type.fb_size = maxrow * sc->sc_linebytes;
    194  1.8.10.3    tron 	sc->sc_fb.fb_type.fb_type = FBTYPE_CREATOR;
    195  1.8.10.4    tron 	sc->sc_fb.fb_type.fb_width = sc->sc_width;
    196  1.8.10.4    tron 	sc->sc_fb.fb_type.fb_depth = sc->sc_depth;
    197  1.8.10.4    tron 	sc->sc_fb.fb_type.fb_height = sc->sc_height;
    198  1.8.10.3    tron 	sc->sc_fb.fb_device = &sc->sc_dv;
    199  1.8.10.3    tron 	fb_attach(&sc->sc_fb, sc->sc_console);
    200  1.8.10.3    tron 
    201       1.1  petrov 	if (sc->sc_console) {
    202       1.1  petrov 		int *ccolp, *crowp;
    203       1.1  petrov 		long defattr;
    204       1.1  petrov 
    205       1.1  petrov 		if (romgetcursoraddr(&crowp, &ccolp))
    206       1.1  petrov 			ccolp = crowp = NULL;
    207       1.1  petrov 		if (ccolp != NULL)
    208  1.8.10.3    tron 			sc->sc_fb.fb_rinfo.ri_ccol = *ccolp;
    209       1.1  petrov 		if (crowp != NULL)
    210  1.8.10.3    tron 			sc->sc_fb.fb_rinfo.ri_crow = *crowp;
    211       1.1  petrov 
    212  1.8.10.3    tron 		sc->sc_fb.fb_rinfo.ri_ops.allocattr(&sc->sc_fb.fb_rinfo,
    213       1.1  petrov 		    0, 0, 0, &defattr);
    214       1.1  petrov 
    215  1.8.10.3    tron 		wsdisplay_cnattach(&ffb_stdscreen, &sc->sc_fb.fb_rinfo,
    216  1.8.10.3    tron 		    sc->sc_fb.fb_rinfo.ri_ccol, sc->sc_fb.fb_rinfo.ri_crow, defattr);
    217       1.1  petrov 	}
    218       1.1  petrov 
    219       1.1  petrov 	waa.console = sc->sc_console;
    220       1.1  petrov 	waa.scrdata = &ffb_screenlist;
    221       1.1  petrov 	waa.accessops = &ffb_accessops;
    222       1.1  petrov 	waa.accesscookie = sc;
    223       1.1  petrov 	config_found(&sc->sc_dv, &waa, wsemuldisplaydevprint);
    224       1.1  petrov }
    225       1.1  petrov 
    226       1.1  petrov int
    227  1.8.10.2    tron ffb_ioctl(void *v, u_long cmd, caddr_t data, int flags, struct proc *p)
    228       1.1  petrov {
    229       1.1  petrov 	struct ffb_softc *sc = v;
    230       1.1  petrov 	struct wsdisplay_fbinfo *wdf;
    231       1.1  petrov 
    232       1.2  petrov #ifdef FFBDEBUG
    233       1.1  petrov 	printf("ffb_ioctl: %s cmd _IO%s%s('%c', %lu)\n",
    234       1.1  petrov 	       sc->sc_dv.dv_xname,
    235       1.1  petrov 	       (cmd & IOC_IN) ? "W" : "", (cmd & IOC_OUT) ? "R" : "",
    236       1.1  petrov 	       (char)IOCGROUP(cmd), cmd & 0xff);
    237       1.2  petrov #endif
    238       1.1  petrov 
    239       1.1  petrov 	switch (cmd) {
    240  1.8.10.3    tron 	case FBIOGTYPE:
    241  1.8.10.3    tron 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    242  1.8.10.3    tron 		break;
    243  1.8.10.3    tron 	case FBIOGATTR:
    244  1.8.10.3    tron #define fba ((struct fbgattr *)data)
    245  1.8.10.3    tron 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    246  1.8.10.3    tron 		fba->owner = 0; 	/* XXX ??? */
    247  1.8.10.3    tron 		fba->fbtype = sc->sc_fb.fb_type;
    248  1.8.10.3    tron 		fba->sattr.flags = 0;
    249  1.8.10.3    tron 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    250  1.8.10.3    tron 		fba->sattr.dev_specific[0] = -1;
    251  1.8.10.3    tron 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    252  1.8.10.3    tron 		fba->emu_types[1] = -1;
    253  1.8.10.3    tron #undef fba
    254  1.8.10.3    tron 		break;
    255  1.8.10.3    tron 
    256  1.8.10.3    tron 	case FBIOGETCMAP:
    257  1.8.10.3    tron 	case FBIOPUTCMAP:
    258  1.8.10.3    tron 		return EIO;
    259  1.8.10.3    tron 
    260  1.8.10.3    tron 	case FBIOGVIDEO:
    261  1.8.10.3    tron 	case FBIOSVIDEO:
    262  1.8.10.3    tron 		return ffb_blank(sc, cmd == FBIOGVIDEO?
    263  1.8.10.3    tron 		    WSDISPLAYIO_GVIDEO : WSDISPLAYIO_SVIDEO,
    264  1.8.10.3    tron 		    (u_int *)data);
    265  1.8.10.3    tron 		break;
    266  1.8.10.3    tron 	case FBIOGCURSOR:
    267  1.8.10.3    tron 	case FBIOSCURSOR:
    268  1.8.10.5    tron 		/* the console driver is not using the hardware cursor */
    269  1.8.10.5    tron 		break;
    270  1.8.10.3    tron 	case FBIOGCURPOS:
    271  1.8.10.3    tron 		printf("%s: FBIOGCURPOS not implemented\n", sc->sc_dv.dv_xname);
    272  1.8.10.3    tron 		return EIO;
    273  1.8.10.3    tron 	case FBIOSCURPOS:
    274  1.8.10.3    tron 		printf("%s: FBIOSCURPOS not implemented\n", sc->sc_dv.dv_xname);
    275  1.8.10.3    tron 		return EIO;
    276  1.8.10.3    tron 	case FBIOGCURMAX:
    277  1.8.10.3    tron 		printf("%s: FBIOGCURMAX not implemented\n", sc->sc_dv.dv_xname);
    278  1.8.10.3    tron 		return EIO;
    279  1.8.10.3    tron 
    280       1.1  petrov 	case WSDISPLAYIO_GTYPE:
    281       1.6    heas 		*(u_int *)data = WSDISPLAY_TYPE_SUNFFB;
    282       1.1  petrov 		break;
    283       1.1  petrov 	case WSDISPLAYIO_SMODE:
    284       1.1  petrov 		sc->sc_mode = *(u_int *)data;
    285       1.1  petrov 		break;
    286       1.1  petrov 	case WSDISPLAYIO_GINFO:
    287       1.1  petrov 		wdf = (void *)data;
    288       1.1  petrov 		wdf->height = sc->sc_height;
    289       1.1  petrov 		wdf->width  = sc->sc_width;
    290       1.1  petrov 		wdf->depth  = 32;
    291       1.1  petrov 		wdf->cmsize = 256; /* XXX */
    292       1.1  petrov 		break;
    293       1.1  petrov #ifdef WSDISPLAYIO_LINEBYTES
    294       1.1  petrov 	case WSDISPLAYIO_LINEBYTES:
    295       1.1  petrov 		*(u_int *)data = sc->sc_linebytes;
    296       1.1  petrov 		break;
    297       1.1  petrov #endif
    298       1.1  petrov 	case WSDISPLAYIO_GETCMAP:
    299       1.1  petrov 		break;/* XXX */
    300       1.1  petrov 
    301       1.1  petrov 	case WSDISPLAYIO_PUTCMAP:
    302       1.1  petrov 		break;/* XXX */
    303       1.1  petrov 
    304       1.1  petrov 	case WSDISPLAYIO_SVIDEO:
    305       1.1  petrov 	case WSDISPLAYIO_GVIDEO:
    306       1.7    heas 		return(ffb_blank(sc, cmd, (u_int *)data));
    307       1.7    heas 		break;
    308       1.1  petrov 	case WSDISPLAYIO_GCURPOS:
    309       1.1  petrov 	case WSDISPLAYIO_SCURPOS:
    310       1.1  petrov 	case WSDISPLAYIO_GCURMAX:
    311       1.1  petrov 	case WSDISPLAYIO_GCURSOR:
    312       1.1  petrov 	case WSDISPLAYIO_SCURSOR:
    313  1.8.10.1    tron 		return EIO; /* not supported yet */
    314       1.1  petrov 	default:
    315  1.8.10.1    tron 		return EPASSTHROUGH;
    316       1.1  petrov         }
    317       1.1  petrov 
    318       1.1  petrov 	return (0);
    319       1.1  petrov }
    320       1.1  petrov 
    321       1.1  petrov int
    322  1.8.10.2    tron ffb_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
    323  1.8.10.2    tron     int *curxp, int *curyp, long *attrp)
    324       1.1  petrov {
    325       1.1  petrov 	struct ffb_softc *sc = v;
    326       1.1  petrov 
    327       1.1  petrov 	if (sc->sc_nscreens > 0)
    328       1.1  petrov 		return (ENOMEM);
    329       1.1  petrov 
    330  1.8.10.3    tron 	*cookiep = &sc->sc_fb.fb_rinfo;
    331       1.1  petrov 	*curyp = 0;
    332       1.1  petrov 	*curxp = 0;
    333       1.1  petrov 
    334  1.8.10.3    tron 	sc->sc_fb.fb_rinfo.ri_ops.allocattr(&sc->sc_fb.fb_rinfo, 0, 0, 0, attrp);
    335       1.1  petrov 
    336       1.1  petrov 	sc->sc_nscreens++;
    337       1.1  petrov 	return (0);
    338       1.1  petrov }
    339       1.1  petrov 
    340       1.7    heas /* blank/unblank the screen */
    341       1.7    heas static int
    342       1.7    heas ffb_blank(struct ffb_softc *sc, u_long cmd, u_int *data)
    343       1.7    heas {
    344       1.7    heas 	u_int val;
    345       1.7    heas 
    346       1.7    heas 	DAC_WRITE(sc, FFB_DAC_TYPE, FFB_DAC_GSBLANK);
    347       1.7    heas 	val = DAC_READ(sc, FFB_DAC_VALUE);
    348       1.7    heas 
    349       1.7    heas 	switch (cmd) {
    350       1.7    heas 	case WSDISPLAYIO_GVIDEO:
    351       1.7    heas 		*data = val & 1;
    352       1.7    heas 		return(0);
    353       1.7    heas 		break;
    354       1.7    heas 	case WSDISPLAYIO_SVIDEO:
    355       1.7    heas 		if (*data == WSDISPLAYIO_VIDEO_OFF)
    356       1.7    heas 			val &= ~1;
    357       1.7    heas 		else if (*data == WSDISPLAYIO_VIDEO_ON)
    358       1.7    heas 			val |= 1;
    359       1.7    heas 		else
    360       1.7    heas 			return(EINVAL);
    361       1.7    heas 		break;
    362       1.7    heas 	default:
    363       1.7    heas 		return(EINVAL);
    364       1.7    heas 	}
    365       1.7    heas 
    366       1.7    heas 	DAC_WRITE(sc, FFB_DAC_TYPE, FFB_DAC_GSBLANK);
    367       1.7    heas 	DAC_WRITE(sc, FFB_DAC_VALUE, val);
    368       1.7    heas 
    369       1.7    heas 	return(0);
    370       1.7    heas }
    371       1.7    heas 
    372       1.1  petrov void
    373  1.8.10.2    tron ffb_free_screen(void *v, void *cookie)
    374       1.1  petrov {
    375       1.1  petrov 	struct ffb_softc *sc = v;
    376       1.1  petrov 
    377       1.1  petrov 	sc->sc_nscreens--;
    378       1.1  petrov }
    379       1.1  petrov 
    380       1.1  petrov int
    381  1.8.10.2    tron ffb_show_screen(void *v, void *cookie, int waitok,
    382  1.8.10.2    tron     void (*cb)(void *, int, int), void *cbarg)
    383       1.1  petrov {
    384       1.1  petrov 	return (0);
    385       1.1  petrov }
    386       1.1  petrov 
    387       1.1  petrov paddr_t
    388  1.8.10.2    tron ffb_mmap(void *vsc, off_t off, int prot)
    389       1.1  petrov {
    390       1.1  petrov 	struct ffb_softc *sc = vsc;
    391       1.1  petrov 	int i;
    392       1.1  petrov 
    393       1.1  petrov 	switch (sc->sc_mode) {
    394       1.1  petrov 	case WSDISPLAYIO_MODE_MAPPED:
    395       1.1  petrov 		for (i = 0; i < sc->sc_nreg; i++) {
    396       1.1  petrov 			/* Before this set? */
    397       1.1  petrov 			if (off < sc->sc_addrs[i])
    398       1.1  petrov 				continue;
    399       1.1  petrov 			/* After this set? */
    400       1.1  petrov 			if (off >= (sc->sc_addrs[i] + sc->sc_sizes[i]))
    401       1.1  petrov 				continue;
    402       1.1  petrov 
    403       1.1  petrov 			return (bus_space_mmap(sc->sc_bt, sc->sc_addrs[i],
    404       1.1  petrov 			    off - sc->sc_addrs[i], prot, BUS_SPACE_MAP_LINEAR));
    405       1.1  petrov 		}
    406       1.1  petrov 		break;
    407       1.1  petrov #ifdef WSDISPLAYIO_MODE_DUMBFB
    408       1.1  petrov 	case WSDISPLAYIO_MODE_DUMBFB:
    409       1.1  petrov 		if (sc->sc_nreg < FFB_REG_DFB24)
    410       1.1  petrov 			break;
    411       1.1  petrov 		if (off >= 0 && off < sc->sc_sizes[FFB_REG_DFB24])
    412       1.1  petrov 			return (bus_space_mmap(sc->sc_bt,
    413       1.1  petrov 			    sc->sc_addrs[FFB_REG_DFB24], off, prot,
    414       1.1  petrov 			    BUS_SPACE_MAP_LINEAR));
    415       1.1  petrov 		break;
    416       1.1  petrov #endif
    417       1.1  petrov 	}
    418       1.1  petrov 
    419       1.1  petrov 	return (-1);
    420       1.1  petrov }
    421       1.1  petrov 
    422       1.1  petrov void
    423  1.8.10.2    tron ffb_ras_fifo_wait(struct ffb_softc *sc, int n)
    424       1.1  petrov {
    425       1.1  petrov 	int32_t cache = sc->sc_fifo_cache;
    426       1.1  petrov 
    427       1.1  petrov 	if (cache < n) {
    428       1.1  petrov 		do {
    429       1.1  petrov 			cache = FBC_READ(sc, FFB_FBC_UCSR);
    430       1.1  petrov 			cache = (cache & FBC_UCSR_FIFO_MASK) - 8;
    431       1.1  petrov 		} while (cache < n);
    432       1.1  petrov 	}
    433       1.1  petrov 	sc->sc_fifo_cache = cache - n;
    434       1.1  petrov }
    435       1.1  petrov 
    436       1.1  petrov void
    437  1.8.10.2    tron ffb_ras_wait(struct ffb_softc *sc)
    438       1.1  petrov {
    439       1.1  petrov 	u_int32_t ucsr, r;
    440       1.1  petrov 
    441       1.1  petrov 	while (1) {
    442       1.1  petrov 		ucsr = FBC_READ(sc, FFB_FBC_UCSR);
    443       1.1  petrov 		if ((ucsr & (FBC_UCSR_FB_BUSY|FBC_UCSR_RP_BUSY)) == 0)
    444       1.1  petrov 			break;
    445       1.1  petrov 		r = ucsr & (FBC_UCSR_READ_ERR | FBC_UCSR_FIFO_OVFL);
    446       1.1  petrov 		if (r != 0)
    447       1.1  petrov 			FBC_WRITE(sc, FFB_FBC_UCSR, r);
    448       1.1  petrov 	}
    449       1.1  petrov }
    450       1.1  petrov 
    451       1.1  petrov void
    452  1.8.10.2    tron ffb_ras_init(struct ffb_softc *sc)
    453       1.1  petrov {
    454       1.1  petrov 	ffb_ras_fifo_wait(sc, 7);
    455       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_PPC,
    456       1.1  petrov 	    FBC_PPC_VCE_DIS | FBC_PPC_TBE_OPAQUE |
    457       1.1  petrov 	    FBC_PPC_APE_DIS | FBC_PPC_CS_CONST);
    458       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_FBC,
    459       1.1  petrov 	    FFB_FBC_WB_A | FFB_FBC_RB_A | FFB_FBC_SB_BOTH |
    460       1.1  petrov 	    FFB_FBC_XE_OFF | FFB_FBC_RGBE_MASK);
    461       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_NEW);
    462       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE);
    463       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_PMASK, 0xffffffff);
    464       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_FONTINC, 0x10000);
    465       1.1  petrov 	sc->sc_fg_cache = 0;
    466       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_FG, sc->sc_fg_cache);
    467       1.1  petrov 	ffb_ras_wait(sc);
    468       1.1  petrov }
    469       1.1  petrov 
    470       1.1  petrov void
    471  1.8.10.2    tron ffb_ras_eraserows(void *cookie, int row, int n, long attr)
    472       1.1  petrov {
    473       1.1  petrov 	struct rasops_info *ri = cookie;
    474       1.1  petrov 	struct ffb_softc *sc = ri->ri_hw;
    475       1.1  petrov 
    476       1.1  petrov 	if (row < 0) {
    477       1.1  petrov 		n += row;
    478       1.1  petrov 		row = 0;
    479       1.1  petrov 	}
    480       1.1  petrov 	if (row + n > ri->ri_rows)
    481       1.1  petrov 		n = ri->ri_rows - row;
    482       1.1  petrov 	if (n <= 0)
    483       1.1  petrov 		return;
    484       1.1  petrov 
    485       1.1  petrov 	ffb_ras_fill(sc);
    486       1.1  petrov 	ffb_ras_setfg(sc, ri->ri_devcmap[(attr >> 16) & 0xf]);
    487       1.1  petrov 	ffb_ras_fifo_wait(sc, 4);
    488       1.1  petrov 	if ((n == ri->ri_rows) && (ri->ri_flg & RI_FULLCLEAR)) {
    489       1.1  petrov 		FBC_WRITE(sc, FFB_FBC_BY, 0);
    490       1.1  petrov 		FBC_WRITE(sc, FFB_FBC_BX, 0);
    491       1.1  petrov 		FBC_WRITE(sc, FFB_FBC_BH, ri->ri_height);
    492       1.1  petrov 		FBC_WRITE(sc, FFB_FBC_BW, ri->ri_width);
    493       1.1  petrov 	} else {
    494       1.1  petrov 		row *= ri->ri_font->fontheight;
    495       1.1  petrov 		FBC_WRITE(sc, FFB_FBC_BY, ri->ri_yorigin + row);
    496       1.1  petrov 		FBC_WRITE(sc, FFB_FBC_BX, ri->ri_xorigin);
    497       1.1  petrov 		FBC_WRITE(sc, FFB_FBC_BH, n * ri->ri_font->fontheight);
    498       1.1  petrov 		FBC_WRITE(sc, FFB_FBC_BW, ri->ri_emuwidth);
    499       1.1  petrov 	}
    500       1.1  petrov 	ffb_ras_wait(sc);
    501       1.1  petrov }
    502       1.1  petrov 
    503       1.1  petrov void
    504  1.8.10.2    tron ffb_ras_erasecols(void *cookie, int row, int col, int n, long attr)
    505       1.1  petrov {
    506       1.1  petrov 	struct rasops_info *ri = cookie;
    507       1.1  petrov 	struct ffb_softc *sc = ri->ri_hw;
    508       1.1  petrov 
    509       1.1  petrov 	if ((row < 0) || (row >= ri->ri_rows))
    510       1.1  petrov 		return;
    511       1.1  petrov 	if (col < 0) {
    512       1.1  petrov 		n += col;
    513       1.1  petrov 		col = 0;
    514       1.1  petrov 	}
    515       1.1  petrov 	if (col + n > ri->ri_cols)
    516       1.1  petrov 		n = ri->ri_cols - col;
    517       1.1  petrov 	if (n <= 0)
    518       1.1  petrov 		return;
    519       1.1  petrov 	n *= ri->ri_font->fontwidth;
    520       1.1  petrov 	col *= ri->ri_font->fontwidth;
    521       1.1  petrov 	row *= ri->ri_font->fontheight;
    522       1.1  petrov 
    523       1.1  petrov 	ffb_ras_fill(sc);
    524       1.1  petrov 	ffb_ras_setfg(sc, ri->ri_devcmap[(attr >> 16) & 0xf]);
    525       1.1  petrov 	ffb_ras_fifo_wait(sc, 4);
    526       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_BY, ri->ri_yorigin + row);
    527       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_BX, ri->ri_xorigin + col);
    528       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_BH, ri->ri_font->fontheight);
    529       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_BW, n - 1);
    530       1.1  petrov 	ffb_ras_wait(sc);
    531       1.1  petrov }
    532       1.1  petrov 
    533       1.1  petrov void
    534  1.8.10.2    tron ffb_ras_fill(struct ffb_softc *sc)
    535       1.1  petrov {
    536       1.1  petrov 	ffb_ras_fifo_wait(sc, 2);
    537       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_NEW);
    538       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE);
    539       1.1  petrov 	ffb_ras_wait(sc);
    540       1.1  petrov }
    541       1.1  petrov 
    542       1.1  petrov void
    543  1.8.10.2    tron ffb_ras_copyrows(void *cookie, int src, int dst, int n)
    544       1.1  petrov {
    545       1.1  petrov 	struct rasops_info *ri = cookie;
    546       1.1  petrov 	struct ffb_softc *sc = ri->ri_hw;
    547       1.1  petrov 
    548       1.1  petrov 	if (dst == src)
    549       1.1  petrov 		return;
    550       1.1  petrov 	if (src < 0) {
    551       1.1  petrov 		n += src;
    552       1.1  petrov 		src = 0;
    553       1.1  petrov 	}
    554       1.1  petrov 	if ((src + n) > ri->ri_rows)
    555       1.1  petrov 		n = ri->ri_rows - src;
    556       1.1  petrov 	if (dst < 0) {
    557       1.1  petrov 		n += dst;
    558       1.1  petrov 		dst = 0;
    559       1.1  petrov 	}
    560       1.1  petrov 	if ((dst + n) > ri->ri_rows)
    561       1.1  petrov 		n = ri->ri_rows - dst;
    562       1.1  petrov 	if (n <= 0)
    563       1.1  petrov 		return;
    564       1.1  petrov 	n *= ri->ri_font->fontheight;
    565       1.1  petrov 	src *= ri->ri_font->fontheight;
    566       1.1  petrov 	dst *= ri->ri_font->fontheight;
    567       1.1  petrov 
    568       1.1  petrov 	ffb_ras_fifo_wait(sc, 8);
    569       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_OLD | (FBC_ROP_OLD << 8));
    570       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_DRAWOP, FBC_DRAWOP_VSCROLL);
    571       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_BY, ri->ri_yorigin + src);
    572       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_BX, ri->ri_xorigin);
    573       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_DY, ri->ri_yorigin + dst);
    574       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_DX, ri->ri_xorigin);
    575       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_BH, n);
    576       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_BW, ri->ri_emuwidth);
    577       1.1  petrov 	ffb_ras_wait(sc);
    578       1.1  petrov }
    579       1.1  petrov 
    580       1.1  petrov void
    581  1.8.10.2    tron ffb_ras_setfg(struct ffb_softc *sc, int32_t fg)
    582       1.1  petrov {
    583       1.1  petrov 	ffb_ras_fifo_wait(sc, 1);
    584       1.1  petrov 	if (fg == sc->sc_fg_cache)
    585       1.1  petrov 		return;
    586       1.1  petrov 	sc->sc_fg_cache = fg;
    587       1.1  petrov 	FBC_WRITE(sc, FFB_FBC_FG, fg);
    588       1.1  petrov 	ffb_ras_wait(sc);
    589       1.1  petrov }
    590  1.8.10.3    tron 
    591  1.8.10.3    tron /* frame buffer generic driver support functions */
    592  1.8.10.3    tron static void
    593  1.8.10.3    tron ffbfb_unblank(struct device *dev)
    594  1.8.10.3    tron {
    595  1.8.10.3    tron 	/* u_int on = 1; */
    596  1.8.10.3    tron 
    597  1.8.10.3    tron 	if (dev && dev->dv_xname)
    598  1.8.10.3    tron 		printf("%s: ffbfb_unblank\n", dev->dv_xname);
    599  1.8.10.3    tron 	else
    600  1.8.10.3    tron 		printf("ffbfb_unblank(%p)n", dev);
    601  1.8.10.3    tron 	/* ffb_blank((struct ffb_softc*)dev, WSDISPLAYIO_SVIDEO, &on); */
    602  1.8.10.3    tron }
    603  1.8.10.3    tron 
    604  1.8.10.3    tron int
    605  1.8.10.3    tron ffbfb_open(dev_t dev, int flags, int mode, struct proc *p)
    606  1.8.10.3    tron {
    607  1.8.10.3    tron 	int unit = minor(dev);
    608  1.8.10.3    tron 
    609  1.8.10.3    tron 	if (unit >= ffb_cd.cd_ndevs || ffb_cd.cd_devs[unit] == NULL)
    610  1.8.10.3    tron 		return ENXIO;
    611  1.8.10.3    tron 
    612  1.8.10.3    tron 	return 0;
    613  1.8.10.3    tron }
    614  1.8.10.3    tron 
    615  1.8.10.3    tron int
    616  1.8.10.3    tron ffbfb_close(dev_t dev, int flags, int mode, struct proc *p)
    617  1.8.10.3    tron {
    618  1.8.10.3    tron 	return 0;
    619  1.8.10.3    tron }
    620  1.8.10.3    tron 
    621  1.8.10.3    tron int
    622  1.8.10.3    tron ffbfb_ioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
    623  1.8.10.3    tron {
    624  1.8.10.3    tron 	struct ffb_softc *sc = ffb_cd.cd_devs[minor(dev)];
    625  1.8.10.3    tron 
    626  1.8.10.3    tron 	return ffb_ioctl(sc, cmd, data, flags, p);
    627  1.8.10.3    tron }
    628  1.8.10.3    tron 
    629  1.8.10.3    tron paddr_t
    630  1.8.10.3    tron ffbfb_mmap(dev_t dev, off_t off, int prot)
    631  1.8.10.3    tron {
    632  1.8.10.3    tron 	struct ffb_softc *sc = ffb_cd.cd_devs[minor(dev)];
    633  1.8.10.3    tron 	int i, reg;
    634  1.8.10.3    tron 	off_t o;
    635  1.8.10.3    tron 
    636  1.8.10.3    tron 	/*
    637  1.8.10.3    tron 	 * off is a magic cookie (see xfree86/drivers/sunffb/ffb.h),
    638  1.8.10.3    tron 	 * which we map to an index into the "reg" property, and use
    639  1.8.10.3    tron 	 * our copy of the firmware data as arguments for the real
    640  1.8.10.3    tron 	 * mapping.
    641  1.8.10.3    tron 	 */
    642  1.8.10.3    tron 	static struct { unsigned long voff; int reg; } map[] = {
    643  1.8.10.3    tron 		{ 0x00000000, FFB_REG_SFB8R },
    644  1.8.10.3    tron 		{ 0x00400000, FFB_REG_SFB8G },
    645  1.8.10.3    tron 		{ 0x00800000, FFB_REG_SFB8B },
    646  1.8.10.3    tron 		{ 0x00c00000, FFB_REG_SFB8X },
    647  1.8.10.3    tron 		{ 0x01000000, FFB_REG_SFB32 },
    648  1.8.10.3    tron 		{ 0x02000000, FFB_REG_SFB64  },
    649  1.8.10.3    tron 		{ 0x04000000, FFB_REG_FBC },
    650  1.8.10.3    tron 		{ 0x04004000, FFB_REG_DFB8R },
    651  1.8.10.3    tron 		{ 0x04404000, FFB_REG_DFB8G },
    652  1.8.10.3    tron 		{ 0x04804000, FFB_REG_DFB8B },
    653  1.8.10.3    tron 		{ 0x04c04000, FFB_REG_DFB8X },
    654  1.8.10.3    tron 		{ 0x05004000, FFB_REG_DFB24 },
    655  1.8.10.3    tron 		{ 0x06004000, FFB_REG_DFB32 },
    656  1.8.10.3    tron 		{ 0x07004000, FFB_REG_DFB422A },
    657  1.8.10.3    tron 		{ 0x0bc06000, FFB_REG_DAC },
    658  1.8.10.3    tron 		{ 0x0bc08000, FFB_REG_PROM },
    659  1.8.10.3    tron 	};
    660  1.8.10.3    tron 
    661  1.8.10.3    tron 	/* special value "FFB_EXP_VOFF" - not backed by any "reg" entry */
    662  1.8.10.3    tron 	if (off == 0x0bc18000)
    663  1.8.10.3    tron 		return bus_space_mmap(sc->sc_bt, sc->sc_addrs[FFB_REG_PROM],
    664  1.8.10.3    tron 		    0x00200000, prot, BUS_SPACE_MAP_LINEAR);
    665  1.8.10.3    tron 
    666  1.8.10.3    tron #define NELEMS(arr) (sizeof(arr)/sizeof((arr)[0]))
    667  1.8.10.3    tron 
    668  1.8.10.3    tron 	/* the map is ordered by voff */
    669  1.8.10.3    tron 	for (i = 0; i < NELEMS(map); i++) {
    670  1.8.10.3    tron 		if (map[i].voff > off)
    671  1.8.10.3    tron 			break;		/* beyound */
    672  1.8.10.3    tron 		reg = map[i].reg;
    673  1.8.10.3    tron 		if (map[i].voff + sc->sc_sizes[reg] < off)
    674  1.8.10.3    tron 			continue;	/* not there yet */
    675  1.8.10.3    tron 		if (off > map[i].voff + sc->sc_sizes[reg])
    676  1.8.10.3    tron 			break;		/* out of range */
    677  1.8.10.3    tron 		o = off - map[i].voff;
    678  1.8.10.3    tron 		return bus_space_mmap(sc->sc_bt, sc->sc_addrs[reg], o, prot,
    679  1.8.10.3    tron 		    BUS_SPACE_MAP_LINEAR);
    680  1.8.10.3    tron 	}
    681  1.8.10.3    tron 
    682  1.8.10.3    tron 	return -1;
    683  1.8.10.3    tron }
    684