Home | History | Annotate | Line # | Download | only in dev
ffb.c revision 1.37.4.1
      1  1.37.4.1     rmind /*	$NetBSD: ffb.c,v 1.37.4.1 2011/03/05 20:52:05 rmind 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.37.4.1     rmind __KERNEL_RCSID(0, "$NetBSD: ffb.c,v 1.37.4.1 2011/03/05 20:52:05 rmind 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.16  macallan #include <sys/ioctl.h>
     45      1.16  macallan #include <sys/malloc.h>
     46      1.16  macallan #include <sys/mman.h>
     47       1.1    petrov 
     48       1.1    petrov #include <machine/bus.h>
     49       1.1    petrov #include <machine/autoconf.h>
     50       1.1    petrov #include <machine/openfirm.h>
     51      1.11    martin #include <machine/vmparam.h>
     52       1.1    petrov 
     53       1.1    petrov #include <dev/wscons/wsconsio.h>
     54      1.11    martin #include <dev/sun/fbio.h>
     55      1.11    martin #include <dev/sun/fbvar.h>
     56       1.1    petrov 
     57      1.30    martin #include <dev/wsfont/wsfont.h>
     58      1.30    martin #include <dev/wscons/wsdisplay_vconsvar.h>
     59      1.30    martin 
     60       1.1    petrov #include <sparc64/dev/ffbreg.h>
     61       1.1    petrov #include <sparc64/dev/ffbvar.h>
     62       1.1    petrov 
     63  1.37.4.1     rmind #include "opt_wsdisplay_compat.h"
     64  1.37.4.1     rmind #include "opt_ffb.h"
     65  1.37.4.1     rmind 
     66      1.16  macallan #ifndef WS_DEFAULT_BG
     67      1.16  macallan /* Sun -> background should be white */
     68      1.16  macallan #define WS_DEFAULT_BG 0xf
     69      1.16  macallan #endif
     70      1.16  macallan 
     71  1.37.4.1     rmind #ifdef FFB_SYNC
     72  1.37.4.1     rmind #define SYNC ffb_ras_wait(sc)
     73  1.37.4.1     rmind #else
     74  1.37.4.1     rmind #define SYNC
     75  1.37.4.1     rmind #endif
     76  1.37.4.1     rmind 
     77      1.11    martin extern struct cfdriver ffb_cd;
     78      1.11    martin 
     79       1.1    petrov struct wsscreen_descr ffb_stdscreen = {
     80       1.6      heas 	"sunffb",
     81       1.1    petrov 	0, 0,	/* will be filled in -- XXX shouldn't, it's global. */
     82       1.1    petrov 	0,
     83       1.1    petrov 	0, 0,
     84      1.31    martin 	WSSCREEN_REVERSE | WSSCREEN_WSCOLORS,
     85      1.31    martin 	NULL	/* modecookie */
     86       1.1    petrov };
     87       1.1    petrov 
     88       1.1    petrov const struct wsscreen_descr *ffb_scrlist[] = {
     89       1.1    petrov 	&ffb_stdscreen,
     90       1.1    petrov 	/* XXX other formats? */
     91       1.1    petrov };
     92       1.1    petrov 
     93       1.1    petrov struct wsscreen_list ffb_screenlist = {
     94       1.1    petrov 	sizeof(ffb_scrlist) / sizeof(struct wsscreen_descr *),
     95       1.1    petrov 	    ffb_scrlist
     96       1.1    petrov };
     97       1.1    petrov 
     98      1.30    martin static struct vcons_screen ffb_console_screen;
     99      1.16  macallan 
    100      1.32  christos int	ffb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    101       1.7      heas static int ffb_blank(struct ffb_softc *, u_long, u_int *);
    102      1.24      jmmv paddr_t ffb_mmap(void *, void *, off_t, int);
    103       1.1    petrov void	ffb_ras_fifo_wait(struct ffb_softc *, int);
    104       1.1    petrov void	ffb_ras_wait(struct ffb_softc *);
    105       1.1    petrov void	ffb_ras_init(struct ffb_softc *);
    106       1.1    petrov void	ffb_ras_copyrows(void *, int, int, int);
    107       1.1    petrov void	ffb_ras_erasecols(void *, int, int, int, long int);
    108       1.1    petrov void	ffb_ras_eraserows(void *, int, int, long int);
    109       1.1    petrov void	ffb_ras_do_cursor(struct rasops_info *);
    110       1.1    petrov void	ffb_ras_fill(struct ffb_softc *);
    111  1.37.4.1     rmind static void	ffb_ras_setfg(struct ffb_softc *, int32_t);
    112  1.37.4.1     rmind static void	ffb_ras_setbg(struct ffb_softc *, int32_t);
    113       1.1    petrov 
    114      1.16  macallan void	ffb_clearscreen(struct ffb_softc *);
    115      1.16  macallan int	ffb_load_font(void *, void *, struct wsdisplay_font *);
    116      1.30    martin void	ffb_init_screen(void *, struct vcons_screen *, int,
    117      1.16  macallan 	    long *);
    118      1.16  macallan int	ffb_allocattr(void *, int, int, int, long *);
    119      1.16  macallan void	ffb_putchar(void *, int, int, u_int, long);
    120      1.16  macallan void	ffb_cursor(void *, int, int, int);
    121      1.16  macallan 
    122      1.11    martin /* frame buffer generic driver */
    123      1.11    martin static void ffbfb_unblank(struct device*);
    124      1.11    martin dev_type_open(ffbfb_open);
    125      1.11    martin dev_type_close(ffbfb_close);
    126      1.11    martin dev_type_ioctl(ffbfb_ioctl);
    127      1.11    martin dev_type_mmap(ffbfb_mmap);
    128      1.16  macallan 
    129      1.11    martin static struct fbdriver ffb_fbdriver = {
    130      1.11    martin         ffbfb_unblank, ffbfb_open, ffbfb_close, ffbfb_ioctl, nopoll,
    131      1.11    martin 	ffbfb_mmap, nokqfilter
    132      1.11    martin };
    133      1.11    martin 
    134       1.1    petrov struct wsdisplay_accessops ffb_accessops = {
    135      1.30    martin 	.ioctl = ffb_ioctl,
    136      1.30    martin 	.mmap = ffb_mmap,
    137       1.1    petrov };
    138       1.1    petrov 
    139       1.1    petrov void
    140       1.1    petrov ffb_attach(struct ffb_softc *sc)
    141       1.1    petrov {
    142       1.1    petrov 	struct wsemuldisplaydev_attach_args waa;
    143      1.16  macallan 	struct rasops_info *ri;
    144      1.16  macallan 	long defattr;
    145      1.15  christos 	const char *model;
    146       1.1    petrov 	int btype;
    147      1.30    martin 	uint32_t dac;
    148       1.4        pk 	int maxrow, maxcol;
    149       1.7      heas 	u_int blank = WSDISPLAYIO_VIDEO_ON;
    150       1.4        pk 	char buf[6+1];
    151       1.1    petrov 
    152       1.1    petrov 	printf(":");
    153  1.37.4.1     rmind 
    154       1.1    petrov 	if (sc->sc_type == FFB_CREATOR) {
    155       1.5        pk 		btype = prom_getpropint(sc->sc_node, "board_type", 0);
    156       1.1    petrov 		if ((btype & 7) == 3)
    157       1.1    petrov 			printf(" Creator3D");
    158       1.1    petrov 		else
    159       1.1    petrov 			printf(" Creator");
    160       1.1    petrov 	} else
    161       1.1    petrov 		printf(" Elite3D");
    162       1.1    petrov 
    163       1.5        pk 	model = prom_getpropstring(sc->sc_node, "model");
    164       1.1    petrov 	if (model == NULL || strlen(model) == 0)
    165       1.1    petrov 		model = "unknown";
    166       1.1    petrov 
    167       1.1    petrov 	sc->sc_depth = 24;
    168       1.1    petrov 	sc->sc_linebytes = 8192;
    169       1.5        pk 	sc->sc_height = prom_getpropint(sc->sc_node, "height", 0);
    170       1.5        pk 	sc->sc_width = prom_getpropint(sc->sc_node, "width", 0);
    171      1.30    martin 
    172      1.30    martin 	sc->sc_locked = 0;
    173      1.30    martin 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    174      1.30    martin 
    175       1.4        pk 	maxcol = (prom_getoption("screen-#columns", buf, sizeof buf) == 0)
    176       1.4        pk 		? strtoul(buf, NULL, 10)
    177       1.4        pk 		: 80;
    178       1.4        pk 
    179      1.30    martin 	maxrow = (prom_getoption("screen-#rows", buf, sizeof buf) != 0)
    180       1.4        pk 		? strtoul(buf, NULL, 10)
    181       1.4        pk 		: 34;
    182       1.4        pk 
    183      1.16  macallan 	ffb_ras_init(sc);
    184       1.1    petrov 
    185       1.8      heas 	/* collect DAC version, as Elite3D cursor enable bit is reversed */
    186       1.8      heas 	DAC_WRITE(sc, FFB_DAC_TYPE, FFB_DAC_GVERS);
    187      1.30    martin 	dac = DAC_READ(sc, FFB_DAC_VALUE);
    188      1.30    martin 	sc->sc_dacrev = (dac >> 28) & 0xf;
    189       1.8      heas 
    190      1.30    martin 	if (sc->sc_type == FFB_AFB) {
    191       1.8      heas 		sc->sc_dacrev = 10;
    192      1.30    martin 		sc->sc_needredraw = 0;
    193      1.30    martin 	} else {
    194      1.30    martin 		/* see what kind of DAC we have */
    195      1.30    martin 		int pnum = (dac & 0x0ffff000) >> 12;
    196      1.30    martin 		if (pnum == 0x236e) {
    197      1.30    martin 			sc->sc_needredraw = 0;
    198      1.30    martin 		} else {
    199      1.30    martin 			sc->sc_needredraw = 1;
    200      1.30    martin 		}
    201      1.30    martin 	}
    202       1.8      heas 	printf(", model %s, dac %u\n", model, sc->sc_dacrev);
    203      1.30    martin 	if (sc->sc_needredraw)
    204      1.30    martin 		printf("%s: found old DAC, enabling redraw on unblank\n",
    205      1.33    cegger 		    device_xname(&sc->sc_dv));
    206       1.8      heas 
    207       1.7      heas 	ffb_blank(sc, WSDISPLAYIO_SVIDEO, &blank);
    208       1.7      heas 
    209      1.23   thorpej 	sc->sc_accel = ((device_cfdata(&sc->sc_dv)->cf_flags &
    210      1.23   thorpej 	    FFB_CFFLAG_NOACCEL) == 0);
    211      1.16  macallan 
    212      1.16  macallan 	wsfont_init();
    213      1.16  macallan 
    214      1.30    martin 	vcons_init(&sc->vd, sc, &ffb_stdscreen, &ffb_accessops);
    215      1.30    martin 	sc->vd.init_screen = ffb_init_screen;
    216      1.30    martin 
    217      1.19       jdc 	/* we mess with ffb_console_screen only once */
    218      1.19       jdc 	if (sc->sc_console) {
    219      1.30    martin 		vcons_init_screen(&sc->vd, &ffb_console_screen, 1, &defattr);
    220      1.30    martin 		SCREEN_VISIBLE((&ffb_console_screen));
    221      1.30    martin 		/*
    222      1.30    martin 		 * XXX we shouldn't use a global variable for the console
    223      1.30    martin 		 * screen
    224      1.30    martin 		 */
    225      1.30    martin 		sc->vd.active = &ffb_console_screen;
    226      1.30    martin 		ffb_console_screen.scr_flags = VCONS_SCREEN_IS_STATIC;
    227      1.30    martin 	} else {
    228      1.30    martin 		if (ffb_console_screen.scr_ri.ri_rows == 0) {
    229      1.30    martin 			/* do some minimal setup to avoid weirdnesses later */
    230      1.30    martin 			vcons_init_screen(&sc->vd, &ffb_console_screen, 1, &defattr);
    231      1.30    martin 		}
    232      1.19       jdc 	}
    233      1.30    martin 	ri = &ffb_console_screen.scr_ri;
    234      1.16  macallan 
    235      1.16  macallan 	ffb_stdscreen.nrows = ri->ri_rows;
    236      1.16  macallan 	ffb_stdscreen.ncols = ri->ri_cols;
    237      1.16  macallan 	ffb_stdscreen.textops = &ri->ri_ops;
    238      1.16  macallan 	ffb_stdscreen.capabilities = ri->ri_caps;
    239      1.16  macallan 
    240      1.11    martin 	sc->sc_fb.fb_driver = &ffb_fbdriver;
    241      1.11    martin 	sc->sc_fb.fb_type.fb_cmsize = 0;
    242      1.11    martin 	sc->sc_fb.fb_type.fb_size = maxrow * sc->sc_linebytes;
    243      1.11    martin 	sc->sc_fb.fb_type.fb_type = FBTYPE_CREATOR;
    244      1.12    mhitch 	sc->sc_fb.fb_type.fb_width = sc->sc_width;
    245      1.12    mhitch 	sc->sc_fb.fb_type.fb_depth = sc->sc_depth;
    246      1.12    mhitch 	sc->sc_fb.fb_type.fb_height = sc->sc_height;
    247      1.11    martin 	sc->sc_fb.fb_device = &sc->sc_dv;
    248      1.11    martin 	fb_attach(&sc->sc_fb, sc->sc_console);
    249      1.11    martin 
    250      1.37  macallan 	ffb_clearscreen(sc);
    251      1.37  macallan 
    252       1.1    petrov 	if (sc->sc_console) {
    253      1.16  macallan 		wsdisplay_cnattach(&ffb_stdscreen, ri, 0, 0, defattr);
    254      1.37  macallan 		vcons_replay_msgbuf(&ffb_console_screen);
    255       1.1    petrov 	}
    256      1.16  macallan 
    257       1.1    petrov 	waa.console = sc->sc_console;
    258       1.1    petrov 	waa.scrdata = &ffb_screenlist;
    259       1.1    petrov 	waa.accessops = &ffb_accessops;
    260      1.30    martin 	waa.accesscookie = &sc->vd;
    261       1.1    petrov 	config_found(&sc->sc_dv, &waa, wsemuldisplaydevprint);
    262       1.1    petrov }
    263       1.1    petrov 
    264       1.1    petrov int
    265      1.32  christos ffb_ioctl(void *v, void *vs, u_long cmd, void *data, int flags, struct lwp *l)
    266       1.1    petrov {
    267      1.30    martin 	struct vcons_data *vd = v;
    268      1.30    martin 	struct ffb_softc *sc = vd->cookie;
    269       1.1    petrov 	struct wsdisplay_fbinfo *wdf;
    270      1.30    martin 	struct vcons_screen *ms = vd->active;
    271      1.30    martin 
    272  1.37.4.1     rmind #ifdef FFB_DEBUG
    273       1.1    petrov 	printf("ffb_ioctl: %s cmd _IO%s%s('%c', %lu)\n",
    274      1.33    cegger 	       device_xname(&sc->sc_dv),
    275       1.1    petrov 	       (cmd & IOC_IN) ? "W" : "", (cmd & IOC_OUT) ? "R" : "",
    276       1.1    petrov 	       (char)IOCGROUP(cmd), cmd & 0xff);
    277       1.2    petrov #endif
    278       1.1    petrov 
    279       1.1    petrov 	switch (cmd) {
    280      1.11    martin 	case FBIOGTYPE:
    281      1.11    martin 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    282      1.11    martin 		break;
    283      1.11    martin 	case FBIOGATTR:
    284      1.11    martin #define fba ((struct fbgattr *)data)
    285      1.11    martin 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    286      1.11    martin 		fba->owner = 0; 	/* XXX ??? */
    287      1.11    martin 		fba->fbtype = sc->sc_fb.fb_type;
    288      1.11    martin 		fba->sattr.flags = 0;
    289      1.11    martin 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    290      1.11    martin 		fba->sattr.dev_specific[0] = -1;
    291      1.11    martin 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    292      1.11    martin 		fba->emu_types[1] = -1;
    293      1.11    martin #undef fba
    294      1.11    martin 		break;
    295      1.11    martin 
    296      1.11    martin 	case FBIOGETCMAP:
    297      1.11    martin 	case FBIOPUTCMAP:
    298      1.11    martin 		return EIO;
    299      1.11    martin 
    300      1.11    martin 	case FBIOGVIDEO:
    301      1.11    martin 	case FBIOSVIDEO:
    302      1.11    martin 		return ffb_blank(sc, cmd == FBIOGVIDEO?
    303      1.11    martin 		    WSDISPLAYIO_GVIDEO : WSDISPLAYIO_SVIDEO,
    304      1.11    martin 		    (u_int *)data);
    305      1.11    martin 		break;
    306      1.11    martin 	case FBIOGCURSOR:
    307      1.11    martin 	case FBIOSCURSOR:
    308      1.13    martin 		/* the console driver is not using the hardware cursor */
    309      1.13    martin 		break;
    310      1.11    martin 	case FBIOGCURPOS:
    311      1.33    cegger 		printf("%s: FBIOGCURPOS not implemented\n", device_xname(&sc->sc_dv));
    312      1.11    martin 		return EIO;
    313      1.11    martin 	case FBIOSCURPOS:
    314      1.33    cegger 		printf("%s: FBIOSCURPOS not implemented\n", device_xname(&sc->sc_dv));
    315      1.11    martin 		return EIO;
    316      1.11    martin 	case FBIOGCURMAX:
    317      1.33    cegger 		printf("%s: FBIOGCURMAX not implemented\n", device_xname(&sc->sc_dv));
    318      1.11    martin 		return EIO;
    319      1.11    martin 
    320       1.1    petrov 	case WSDISPLAYIO_GTYPE:
    321       1.6      heas 		*(u_int *)data = WSDISPLAY_TYPE_SUNFFB;
    322       1.1    petrov 		break;
    323       1.1    petrov 	case WSDISPLAYIO_SMODE:
    324      1.16  macallan 		{
    325      1.16  macallan 			if (sc->sc_mode != *(u_int *)data) {
    326      1.16  macallan 				sc->sc_mode = *(u_int *)data;
    327      1.30    martin 				if ((sc->sc_mode == WSDISPLAYIO_MODE_EMUL) &&
    328      1.30    martin 				    (sc->sc_locked == 0)) {
    329      1.16  macallan 					ffb_ras_init(sc);
    330      1.30    martin 					vcons_redraw_screen(ms);
    331      1.16  macallan 				}
    332      1.16  macallan 			}
    333      1.16  macallan 		}
    334       1.1    petrov 		break;
    335       1.1    petrov 	case WSDISPLAYIO_GINFO:
    336       1.1    petrov 		wdf = (void *)data;
    337       1.1    petrov 		wdf->height = sc->sc_height;
    338       1.1    petrov 		wdf->width  = sc->sc_width;
    339       1.1    petrov 		wdf->depth  = 32;
    340       1.1    petrov 		wdf->cmsize = 256; /* XXX */
    341       1.1    petrov 		break;
    342       1.1    petrov #ifdef WSDISPLAYIO_LINEBYTES
    343       1.1    petrov 	case WSDISPLAYIO_LINEBYTES:
    344       1.1    petrov 		*(u_int *)data = sc->sc_linebytes;
    345       1.1    petrov 		break;
    346       1.1    petrov #endif
    347       1.1    petrov 	case WSDISPLAYIO_GETCMAP:
    348       1.1    petrov 		break;/* XXX */
    349       1.1    petrov 
    350       1.1    petrov 	case WSDISPLAYIO_PUTCMAP:
    351       1.1    petrov 		break;/* XXX */
    352       1.1    petrov 
    353       1.1    petrov 	case WSDISPLAYIO_SVIDEO:
    354       1.1    petrov 	case WSDISPLAYIO_GVIDEO:
    355       1.7      heas 		return(ffb_blank(sc, cmd, (u_int *)data));
    356       1.7      heas 		break;
    357       1.1    petrov 	case WSDISPLAYIO_GCURPOS:
    358       1.1    petrov 	case WSDISPLAYIO_SCURPOS:
    359       1.1    petrov 	case WSDISPLAYIO_GCURMAX:
    360       1.1    petrov 	case WSDISPLAYIO_GCURSOR:
    361       1.1    petrov 	case WSDISPLAYIO_SCURSOR:
    362       1.9    martin 		return EIO; /* not supported yet */
    363       1.1    petrov 	default:
    364       1.9    martin 		return EPASSTHROUGH;
    365       1.1    petrov         }
    366       1.1    petrov 
    367       1.1    petrov 	return (0);
    368       1.1    petrov }
    369       1.1    petrov 
    370       1.7      heas /* blank/unblank the screen */
    371       1.7      heas static int
    372       1.7      heas ffb_blank(struct ffb_softc *sc, u_long cmd, u_int *data)
    373       1.7      heas {
    374      1.30    martin 	struct vcons_screen *ms = sc->vd.active;
    375       1.7      heas 	u_int val;
    376      1.30    martin 
    377       1.7      heas 	DAC_WRITE(sc, FFB_DAC_TYPE, FFB_DAC_GSBLANK);
    378       1.7      heas 	val = DAC_READ(sc, FFB_DAC_VALUE);
    379       1.7      heas 
    380       1.7      heas 	switch (cmd) {
    381       1.7      heas 	case WSDISPLAYIO_GVIDEO:
    382       1.7      heas 		*data = val & 1;
    383       1.7      heas 		return(0);
    384       1.7      heas 		break;
    385       1.7      heas 	case WSDISPLAYIO_SVIDEO:
    386       1.7      heas 		if (*data == WSDISPLAYIO_VIDEO_OFF)
    387       1.7      heas 			val &= ~1;
    388       1.7      heas 		else if (*data == WSDISPLAYIO_VIDEO_ON)
    389       1.7      heas 			val |= 1;
    390       1.7      heas 		else
    391       1.7      heas 			return(EINVAL);
    392       1.7      heas 		break;
    393       1.7      heas 	default:
    394       1.7      heas 		return(EINVAL);
    395       1.7      heas 	}
    396       1.7      heas 
    397       1.7      heas 	DAC_WRITE(sc, FFB_DAC_TYPE, FFB_DAC_GSBLANK);
    398       1.7      heas 	DAC_WRITE(sc, FFB_DAC_VALUE, val);
    399      1.30    martin 
    400      1.30    martin 	if ((val & 1) && sc->sc_needredraw) {
    401      1.30    martin 		if (ms != NULL) {
    402      1.30    martin 			if ((sc->sc_mode == WSDISPLAYIO_MODE_EMUL) &&
    403      1.30    martin 			    (sc->sc_locked == 0)) {
    404      1.30    martin 				ffb_ras_init(sc);
    405      1.30    martin 				vcons_redraw_screen(ms);
    406      1.30    martin 			}
    407      1.30    martin 		}
    408      1.30    martin 	}
    409       1.7      heas 
    410       1.7      heas 	return(0);
    411       1.7      heas }
    412       1.7      heas 
    413       1.1    petrov paddr_t
    414      1.24      jmmv ffb_mmap(void *vsc, void *vs, off_t off, int prot)
    415       1.1    petrov {
    416      1.30    martin 	struct vcons_data *vd = vsc;
    417      1.30    martin 	struct ffb_softc *sc = vd->cookie;
    418       1.1    petrov 	int i;
    419       1.1    petrov 
    420       1.1    petrov 	switch (sc->sc_mode) {
    421       1.1    petrov 	case WSDISPLAYIO_MODE_MAPPED:
    422       1.1    petrov 		for (i = 0; i < sc->sc_nreg; i++) {
    423       1.1    petrov 			/* Before this set? */
    424       1.1    petrov 			if (off < sc->sc_addrs[i])
    425       1.1    petrov 				continue;
    426       1.1    petrov 			/* After this set? */
    427       1.1    petrov 			if (off >= (sc->sc_addrs[i] + sc->sc_sizes[i]))
    428       1.1    petrov 				continue;
    429       1.1    petrov 
    430       1.1    petrov 			return (bus_space_mmap(sc->sc_bt, sc->sc_addrs[i],
    431       1.1    petrov 			    off - sc->sc_addrs[i], prot, BUS_SPACE_MAP_LINEAR));
    432       1.1    petrov 		}
    433       1.1    petrov 		break;
    434       1.1    petrov #ifdef WSDISPLAYIO_MODE_DUMBFB
    435       1.1    petrov 	case WSDISPLAYIO_MODE_DUMBFB:
    436       1.1    petrov 		if (sc->sc_nreg < FFB_REG_DFB24)
    437       1.1    petrov 			break;
    438       1.1    petrov 		if (off >= 0 && off < sc->sc_sizes[FFB_REG_DFB24])
    439       1.1    petrov 			return (bus_space_mmap(sc->sc_bt,
    440       1.1    petrov 			    sc->sc_addrs[FFB_REG_DFB24], off, prot,
    441       1.1    petrov 			    BUS_SPACE_MAP_LINEAR));
    442       1.1    petrov 		break;
    443       1.1    petrov #endif
    444       1.1    petrov 	}
    445       1.1    petrov 	return (-1);
    446       1.1    petrov }
    447       1.1    petrov 
    448       1.1    petrov void
    449      1.10    martin ffb_ras_fifo_wait(struct ffb_softc *sc, int n)
    450       1.1    petrov {
    451       1.1    petrov 	int32_t cache = sc->sc_fifo_cache;
    452       1.1    petrov 
    453       1.1    petrov 	if (cache < n) {
    454       1.1    petrov 		do {
    455       1.1    petrov 			cache = FBC_READ(sc, FFB_FBC_UCSR);
    456       1.1    petrov 			cache = (cache & FBC_UCSR_FIFO_MASK) - 8;
    457       1.1    petrov 		} while (cache < n);
    458       1.1    petrov 	}
    459       1.1    petrov 	sc->sc_fifo_cache = cache - n;
    460       1.1    petrov }
    461       1.1    petrov 
    462       1.1    petrov void
    463      1.10    martin ffb_ras_wait(struct ffb_softc *sc)
    464       1.1    petrov {
    465      1.22       cdi 	uint32_t ucsr, r;
    466       1.1    petrov 
    467       1.1    petrov 	while (1) {
    468       1.1    petrov 		ucsr = FBC_READ(sc, FFB_FBC_UCSR);
    469       1.1    petrov 		if ((ucsr & (FBC_UCSR_FB_BUSY|FBC_UCSR_RP_BUSY)) == 0)
    470       1.1    petrov 			break;
    471       1.1    petrov 		r = ucsr & (FBC_UCSR_READ_ERR | FBC_UCSR_FIFO_OVFL);
    472       1.1    petrov 		if (r != 0)
    473       1.1    petrov 			FBC_WRITE(sc, FFB_FBC_UCSR, r);
    474       1.1    petrov 	}
    475       1.1    petrov }
    476       1.1    petrov 
    477       1.1    petrov void
    478      1.10    martin ffb_ras_init(struct ffb_softc *sc)
    479       1.1    petrov {
    480       1.1    petrov 	ffb_ras_fifo_wait(sc, 7);
    481       1.1    petrov 	FBC_WRITE(sc, FFB_FBC_PPC,
    482  1.37.4.1     rmind 	    FBC_PPC_VCE_DIS | FBC_PPC_TBE_OPAQUE | FBC_PPC_ACE_DIS |
    483  1.37.4.1     rmind 	    FBC_PPC_APE_DIS | FBC_PPC_DCE_DIS | FBC_PPC_CS_CONST);
    484       1.1    petrov 	FBC_WRITE(sc, FFB_FBC_FBC,
    485       1.1    petrov 	    FFB_FBC_WB_A | FFB_FBC_RB_A | FFB_FBC_SB_BOTH |
    486       1.1    petrov 	    FFB_FBC_XE_OFF | FFB_FBC_RGBE_MASK);
    487       1.1    petrov 	FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_NEW);
    488       1.1    petrov 	FBC_WRITE(sc, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE);
    489       1.1    petrov 	FBC_WRITE(sc, FFB_FBC_PMASK, 0xffffffff);
    490       1.1    petrov 	FBC_WRITE(sc, FFB_FBC_FONTINC, 0x10000);
    491       1.1    petrov 	sc->sc_fg_cache = 0;
    492       1.1    petrov 	FBC_WRITE(sc, FFB_FBC_FG, sc->sc_fg_cache);
    493       1.1    petrov 	ffb_ras_wait(sc);
    494       1.1    petrov }
    495       1.1    petrov 
    496       1.1    petrov void
    497      1.10    martin ffb_ras_eraserows(void *cookie, int row, int n, long attr)
    498       1.1    petrov {
    499       1.1    petrov 	struct rasops_info *ri = cookie;
    500      1.30    martin 	struct vcons_screen *scr = ri->ri_hw;
    501      1.30    martin 	struct ffb_softc *sc = scr->scr_cookie;
    502       1.1    petrov 
    503      1.30    martin 	if (row < 0) {
    504      1.30    martin 		n += row;
    505      1.30    martin 		row = 0;
    506      1.30    martin 	}
    507      1.30    martin 	if (row + n > ri->ri_rows)
    508      1.30    martin 		n = ri->ri_rows - row;
    509      1.30    martin 	if (n <= 0)
    510      1.30    martin 		return;
    511      1.16  macallan 
    512      1.30    martin 	ffb_ras_fill(sc);
    513      1.30    martin 	ffb_ras_setfg(sc, ri->ri_devcmap[(attr >> 16) & 0xf]);
    514      1.30    martin 	ffb_ras_fifo_wait(sc, 4);
    515      1.30    martin 	if ((n == ri->ri_rows) && (ri->ri_flg & RI_FULLCLEAR)) {
    516      1.30    martin 		FBC_WRITE(sc, FFB_FBC_BY, 0);
    517      1.30    martin 		FBC_WRITE(sc, FFB_FBC_BX, 0);
    518      1.30    martin 		FBC_WRITE(sc, FFB_FBC_BH, ri->ri_height);
    519      1.30    martin 		FBC_WRITE(sc, FFB_FBC_BW, ri->ri_width);
    520      1.30    martin 	} else {
    521      1.30    martin 		row *= ri->ri_font->fontheight;
    522      1.30    martin 		FBC_WRITE(sc, FFB_FBC_BY, ri->ri_yorigin + row);
    523      1.30    martin 		FBC_WRITE(sc, FFB_FBC_BX, ri->ri_xorigin);
    524      1.30    martin 		FBC_WRITE(sc, FFB_FBC_BH, n * ri->ri_font->fontheight);
    525      1.30    martin 		FBC_WRITE(sc, FFB_FBC_BW, ri->ri_emuwidth);
    526       1.1    petrov 	}
    527  1.37.4.1     rmind 	SYNC;
    528       1.1    petrov }
    529       1.1    petrov 
    530       1.1    petrov void
    531      1.10    martin ffb_ras_erasecols(void *cookie, int row, int col, int n, long attr)
    532       1.1    petrov {
    533       1.1    petrov 	struct rasops_info *ri = cookie;
    534      1.30    martin 	struct vcons_screen *scr = ri->ri_hw;
    535      1.30    martin 	struct ffb_softc *sc = scr->scr_cookie;
    536      1.30    martin 
    537      1.30    martin 	if ((row < 0) || (row >= ri->ri_rows))
    538      1.30    martin 		return;
    539      1.30    martin 	if (col < 0) {
    540      1.30    martin 		n += col;
    541      1.30    martin 		col = 0;
    542      1.30    martin 	}
    543      1.30    martin 	if (col + n > ri->ri_cols)
    544      1.30    martin 		n = ri->ri_cols - col;
    545      1.30    martin 	if (n <= 0)
    546      1.30    martin 		return;
    547      1.30    martin 	n *= ri->ri_font->fontwidth;
    548      1.30    martin 	col *= ri->ri_font->fontwidth;
    549      1.30    martin 	row *= ri->ri_font->fontheight;
    550       1.1    petrov 
    551      1.30    martin 	ffb_ras_fill(sc);
    552      1.30    martin 	ffb_ras_setfg(sc, ri->ri_devcmap[(attr >> 16) & 0xf]);
    553      1.30    martin 	ffb_ras_fifo_wait(sc, 4);
    554      1.30    martin 	FBC_WRITE(sc, FFB_FBC_BY, ri->ri_yorigin + row);
    555      1.30    martin 	FBC_WRITE(sc, FFB_FBC_BX, ri->ri_xorigin + col);
    556      1.30    martin 	FBC_WRITE(sc, FFB_FBC_BH, ri->ri_font->fontheight);
    557      1.30    martin 	FBC_WRITE(sc, FFB_FBC_BW, n - 1);
    558  1.37.4.1     rmind 	SYNC;
    559       1.1    petrov }
    560       1.1    petrov 
    561       1.1    petrov void
    562      1.10    martin ffb_ras_fill(struct ffb_softc *sc)
    563       1.1    petrov {
    564       1.1    petrov 	ffb_ras_fifo_wait(sc, 2);
    565       1.1    petrov 	FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_NEW);
    566       1.1    petrov 	FBC_WRITE(sc, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE);
    567  1.37.4.1     rmind 	SYNC;
    568       1.1    petrov }
    569       1.1    petrov 
    570       1.1    petrov void
    571      1.10    martin ffb_ras_copyrows(void *cookie, int src, int dst, int n)
    572       1.1    petrov {
    573       1.1    petrov 	struct rasops_info *ri = cookie;
    574      1.30    martin 	struct vcons_screen *scr = ri->ri_hw;
    575      1.30    martin 	struct ffb_softc *sc = scr->scr_cookie;
    576       1.1    petrov 
    577      1.30    martin 	if (dst == src)
    578      1.30    martin 		return;
    579      1.30    martin 	if (src < 0) {
    580      1.30    martin 		n += src;
    581      1.30    martin 		src = 0;
    582      1.30    martin 	}
    583      1.30    martin 	if ((src + n) > ri->ri_rows)
    584      1.30    martin 		n = ri->ri_rows - src;
    585      1.30    martin 	if (dst < 0) {
    586      1.30    martin 		n += dst;
    587      1.30    martin 		dst = 0;
    588      1.30    martin 	}
    589      1.30    martin 	if ((dst + n) > ri->ri_rows)
    590      1.30    martin 		n = ri->ri_rows - dst;
    591      1.30    martin 	if (n <= 0)
    592      1.30    martin 		return;
    593      1.30    martin 	n *= ri->ri_font->fontheight;
    594      1.30    martin 	src *= ri->ri_font->fontheight;
    595      1.30    martin 	dst *= ri->ri_font->fontheight;
    596      1.30    martin 
    597      1.30    martin 	ffb_ras_fifo_wait(sc, 8);
    598      1.30    martin 	FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_OLD | (FBC_ROP_OLD << 8));
    599      1.30    martin 	FBC_WRITE(sc, FFB_FBC_DRAWOP, FBC_DRAWOP_VSCROLL);
    600      1.30    martin 	FBC_WRITE(sc, FFB_FBC_BY, ri->ri_yorigin + src);
    601      1.30    martin 	FBC_WRITE(sc, FFB_FBC_BX, ri->ri_xorigin);
    602      1.30    martin 	FBC_WRITE(sc, FFB_FBC_DY, ri->ri_yorigin + dst);
    603      1.30    martin 	FBC_WRITE(sc, FFB_FBC_DX, ri->ri_xorigin);
    604      1.30    martin 	FBC_WRITE(sc, FFB_FBC_BH, n);
    605      1.30    martin 	FBC_WRITE(sc, FFB_FBC_BW, ri->ri_emuwidth);
    606  1.37.4.1     rmind 	SYNC;
    607       1.1    petrov }
    608       1.1    petrov 
    609  1.37.4.1     rmind static void
    610      1.10    martin ffb_ras_setfg(struct ffb_softc *sc, int32_t fg)
    611       1.1    petrov {
    612       1.1    petrov 	ffb_ras_fifo_wait(sc, 1);
    613       1.1    petrov 	if (fg == sc->sc_fg_cache)
    614       1.1    petrov 		return;
    615       1.1    petrov 	sc->sc_fg_cache = fg;
    616       1.1    petrov 	FBC_WRITE(sc, FFB_FBC_FG, fg);
    617  1.37.4.1     rmind 	SYNC;
    618  1.37.4.1     rmind }
    619  1.37.4.1     rmind 
    620  1.37.4.1     rmind static void
    621  1.37.4.1     rmind ffb_ras_setbg(struct ffb_softc *sc, int32_t bg)
    622  1.37.4.1     rmind {
    623  1.37.4.1     rmind 	ffb_ras_fifo_wait(sc, 1);
    624  1.37.4.1     rmind 	if (bg == sc->sc_bg_cache)
    625  1.37.4.1     rmind 		return;
    626  1.37.4.1     rmind 	sc->sc_bg_cache = bg;
    627  1.37.4.1     rmind 	FBC_WRITE(sc, FFB_FBC_BG, bg);
    628  1.37.4.1     rmind 	SYNC;
    629       1.1    petrov }
    630      1.11    martin 
    631      1.11    martin /* frame buffer generic driver support functions */
    632      1.11    martin static void
    633      1.11    martin ffbfb_unblank(struct device *dev)
    634      1.11    martin {
    635      1.35    martin 	struct ffb_softc *sc = device_private(dev);
    636      1.30    martin 	struct vcons_screen *ms = sc->vd.active;
    637      1.29    martin 	u_int on = 1;
    638      1.30    martin 	int redraw = 0;
    639      1.30    martin 
    640      1.30    martin 	ffb_ras_init(sc);
    641      1.30    martin 	if (sc->sc_locked) {
    642      1.30    martin 		sc->sc_locked = 0;
    643      1.30    martin 		redraw = 1;
    644      1.30    martin 	}
    645      1.30    martin 
    646      1.36  macallan 	ffb_blank(sc, WSDISPLAYIO_SVIDEO, &on);
    647      1.36  macallan #if 0
    648      1.30    martin 	if ((sc->vd.active != &ffb_console_screen) &&
    649      1.30    martin 	    (ffb_console_screen.scr_flags & VCONS_SCREEN_IS_STATIC)) {
    650      1.30    martin 		/*
    651      1.30    martin 		 * force-switch to the console screen.
    652      1.30    martin 		 * Caveat: the higher layer will think we're still on the
    653      1.30    martin 		 * other screen
    654      1.30    martin 		 */
    655      1.30    martin 
    656      1.30    martin 		SCREEN_INVISIBLE(sc->vd.active);
    657      1.30    martin 		sc->vd.active = &ffb_console_screen;
    658      1.30    martin 		SCREEN_VISIBLE(sc->vd.active);
    659      1.30    martin 		ms = sc->vd.active;
    660      1.30    martin 		redraw = 1;
    661      1.30    martin 	}
    662      1.36  macallan #endif
    663      1.30    martin 	if (redraw) {
    664      1.30    martin 		vcons_redraw_screen(ms);
    665      1.30    martin 	}
    666      1.11    martin }
    667      1.11    martin 
    668      1.11    martin int
    669      1.21  christos ffbfb_open(dev_t dev, int flags, int mode, struct lwp *l)
    670      1.11    martin {
    671      1.30    martin 	struct ffb_softc *sc;
    672      1.11    martin 
    673      1.34    cegger 	sc = device_lookup_private(&ffb_cd, minor(dev));
    674      1.34    cegger 	if (sc == NULL)
    675      1.11    martin 		return ENXIO;
    676      1.30    martin 
    677      1.30    martin 	sc->sc_locked = 1;
    678      1.11    martin 	return 0;
    679      1.11    martin }
    680      1.11    martin 
    681      1.11    martin int
    682      1.21  christos ffbfb_close(dev_t dev, int flags, int mode, struct lwp *l)
    683      1.11    martin {
    684      1.34    cegger 	struct ffb_softc *sc = device_lookup_private(&ffb_cd, minor(dev));
    685      1.30    martin 	struct vcons_screen *ms = sc->vd.active;
    686      1.30    martin 
    687      1.30    martin 	sc->sc_locked = 0;
    688      1.30    martin 	if (ms != NULL) {
    689      1.30    martin 		if ((sc->sc_mode == WSDISPLAYIO_MODE_EMUL) &&
    690      1.30    martin 		    (sc->sc_locked == 0)) {
    691      1.30    martin 			ffb_ras_init(sc);
    692      1.30    martin 			vcons_redraw_screen(ms);
    693      1.30    martin 		}
    694      1.30    martin 	}
    695      1.11    martin 	return 0;
    696      1.11    martin }
    697      1.11    martin 
    698      1.11    martin int
    699      1.32  christos ffbfb_ioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
    700      1.11    martin {
    701      1.34    cegger 	struct ffb_softc *sc = device_lookup_private(&ffb_cd, minor(dev));
    702      1.11    martin 
    703      1.30    martin 	return ffb_ioctl(&sc->vd, NULL, cmd, data, flags, l);
    704      1.11    martin }
    705      1.11    martin 
    706      1.11    martin paddr_t
    707      1.11    martin ffbfb_mmap(dev_t dev, off_t off, int prot)
    708      1.11    martin {
    709      1.34    cegger 	struct ffb_softc *sc = device_lookup_private(&ffb_cd, minor(dev));
    710      1.14  macallan 	uint64_t size;
    711      1.11    martin 	int i, reg;
    712      1.11    martin 	off_t o;
    713      1.11    martin 
    714      1.11    martin 	/*
    715      1.11    martin 	 * off is a magic cookie (see xfree86/drivers/sunffb/ffb.h),
    716      1.11    martin 	 * which we map to an index into the "reg" property, and use
    717      1.11    martin 	 * our copy of the firmware data as arguments for the real
    718      1.11    martin 	 * mapping.
    719      1.11    martin 	 */
    720      1.11    martin 	static struct { unsigned long voff; int reg; } map[] = {
    721      1.11    martin 		{ 0x00000000, FFB_REG_SFB8R },
    722      1.11    martin 		{ 0x00400000, FFB_REG_SFB8G },
    723      1.11    martin 		{ 0x00800000, FFB_REG_SFB8B },
    724      1.11    martin 		{ 0x00c00000, FFB_REG_SFB8X },
    725      1.11    martin 		{ 0x01000000, FFB_REG_SFB32 },
    726      1.11    martin 		{ 0x02000000, FFB_REG_SFB64  },
    727      1.11    martin 		{ 0x04000000, FFB_REG_FBC },
    728      1.11    martin 		{ 0x04004000, FFB_REG_DFB8R },
    729      1.11    martin 		{ 0x04404000, FFB_REG_DFB8G },
    730      1.11    martin 		{ 0x04804000, FFB_REG_DFB8B },
    731      1.11    martin 		{ 0x04c04000, FFB_REG_DFB8X },
    732      1.11    martin 		{ 0x05004000, FFB_REG_DFB24 },
    733      1.11    martin 		{ 0x06004000, FFB_REG_DFB32 },
    734      1.11    martin 		{ 0x07004000, FFB_REG_DFB422A },
    735      1.11    martin 		{ 0x0bc06000, FFB_REG_DAC },
    736      1.11    martin 		{ 0x0bc08000, FFB_REG_PROM },
    737      1.14  macallan 		{ 0x0bc18000, 0 }
    738      1.11    martin 	};
    739      1.11    martin 
    740      1.11    martin 	/* special value "FFB_EXP_VOFF" - not backed by any "reg" entry */
    741      1.11    martin 	if (off == 0x0bc18000)
    742      1.11    martin 		return bus_space_mmap(sc->sc_bt, sc->sc_addrs[FFB_REG_PROM],
    743      1.11    martin 		    0x00200000, prot, BUS_SPACE_MAP_LINEAR);
    744      1.14  macallan 
    745      1.14  macallan 	/*
    746      1.14  macallan 	 * FFB_VOFF_FBC_KREGS - used by afbinit to upload firmware. We should
    747      1.14  macallan 	 * probably mmap them only on afb boards
    748      1.14  macallan 	 */
    749      1.14  macallan 	if ((off >= 0x0bc04000) && (off < 0x0bc06000))
    750      1.14  macallan 		return bus_space_mmap(sc->sc_bt, sc->sc_addrs[FFB_REG_PROM],
    751      1.14  macallan 		    0x00610000 + (off - 0x0bc04000), prot,
    752      1.14  macallan 		    BUS_SPACE_MAP_LINEAR);
    753      1.14  macallan 
    754      1.11    martin #define NELEMS(arr) (sizeof(arr)/sizeof((arr)[0]))
    755      1.11    martin 
    756      1.11    martin 	/* the map is ordered by voff */
    757      1.14  macallan 	for (i = 0; i < NELEMS(map)-1; i++) {
    758      1.11    martin 		reg = map[i].reg;
    759      1.16  macallan 		/* the number of entries in reg seems to vary */
    760      1.14  macallan 		if (reg < sc->sc_nreg) {
    761      1.14  macallan 			size = min((map[i + 1].voff - map[i].voff),
    762      1.14  macallan 			    sc->sc_sizes[reg]);
    763      1.14  macallan 			if ((off >= map[i].voff) &&
    764      1.14  macallan 			    (off < (map[i].voff + size))) {
    765      1.14  macallan 				o = off - map[i].voff;
    766      1.14  macallan 				return bus_space_mmap(sc->sc_bt,
    767      1.14  macallan 				    sc->sc_addrs[reg], o, prot,
    768      1.14  macallan 				    BUS_SPACE_MAP_LINEAR);
    769      1.14  macallan 			}
    770      1.14  macallan 		}
    771      1.11    martin 	}
    772      1.11    martin 
    773      1.11    martin 	return -1;
    774      1.11    martin }
    775      1.16  macallan 
    776      1.16  macallan void
    777      1.16  macallan ffb_clearscreen(struct ffb_softc *sc)
    778      1.16  macallan {
    779      1.30    martin 	struct rasops_info *ri = &ffb_console_screen.scr_ri;
    780      1.16  macallan 	ffb_ras_fill(sc);
    781      1.16  macallan 	ffb_ras_setfg(sc, ri->ri_devcmap[WS_DEFAULT_BG]);
    782      1.16  macallan 	ffb_ras_fifo_wait(sc, 4);
    783      1.16  macallan 	FBC_WRITE(sc, FFB_FBC_BY, 0);
    784      1.16  macallan 	FBC_WRITE(sc, FFB_FBC_BX, 0);
    785      1.30    martin 	FBC_WRITE(sc, FFB_FBC_BH, sc->sc_height);
    786      1.30    martin 	FBC_WRITE(sc, FFB_FBC_BW, sc->sc_width);
    787      1.16  macallan }
    788      1.16  macallan 
    789      1.16  macallan void
    790      1.16  macallan ffb_cursor(void *cookie, int on, int row, int col)
    791      1.16  macallan {
    792      1.16  macallan 	struct rasops_info *ri = cookie;
    793      1.30    martin 	struct vcons_screen *scr;
    794      1.30    martin 	struct ffb_softc *sc;
    795      1.16  macallan 	int x, y, wi, he, coffset;
    796      1.16  macallan 
    797      1.30    martin 	if (cookie != NULL) {
    798      1.30    martin 		scr = ri->ri_hw;
    799      1.30    martin 		sc = scr->scr_cookie;
    800      1.30    martin 
    801      1.30    martin 		wi = ri->ri_font->fontwidth;
    802      1.30    martin 		he = ri->ri_font->fontheight;
    803      1.30    martin 
    804      1.30    martin 		if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    805      1.30    martin 			x = ri->ri_ccol * wi + ri->ri_xorigin;
    806      1.30    martin 			y = ri->ri_crow * he + ri->ri_yorigin;
    807      1.30    martin 
    808      1.30    martin 			if (ri->ri_flg & RI_CURSOR) {
    809      1.30    martin 				/* remove cursor */
    810      1.30    martin 				coffset = ri->ri_ccol + (ri->ri_crow *
    811      1.30    martin 				    ri->ri_cols);
    812      1.36  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    813      1.36  macallan 				coffset += scr->scr_offset_to_zero;
    814      1.36  macallan #endif
    815      1.30    martin 				ffb_ras_wait(sc);
    816  1.37.4.1     rmind 				ffb_putchar(cookie, ri->ri_crow,
    817      1.30    martin 				    ri->ri_ccol, scr->scr_chars[coffset],
    818      1.30    martin 				    scr->scr_attrs[coffset]);
    819      1.30    martin 				ri->ri_flg &= ~RI_CURSOR;
    820      1.30    martin 			}
    821      1.30    martin 			ri->ri_crow = row;
    822      1.30    martin 			ri->ri_ccol = col;
    823      1.30    martin 			if (on)
    824      1.30    martin 			{
    825      1.30    martin 				long attr, revattr;
    826      1.30    martin 				x = ri->ri_ccol * wi + ri->ri_xorigin;
    827      1.30    martin 				y = ri->ri_crow * he + ri->ri_yorigin;
    828      1.30    martin 				coffset = col + (row * ri->ri_cols);
    829      1.36  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    830      1.36  macallan 				coffset += scr->scr_offset_to_zero;
    831      1.36  macallan #endif
    832      1.30    martin 				attr = scr->scr_attrs[coffset];
    833      1.16  macallan #ifdef FFB_CURSOR_SWAP_COLOURS
    834      1.30    martin 				revattr=((attr >> 8 ) & 0x000f0000) | ((attr &
    835      1.30    martin 				    0x000f0000)<<8) | (attr & 0x0000ffff);
    836      1.16  macallan #else
    837      1.30    martin 				revattr = attr ^ 0xffff0000;
    838      1.16  macallan #endif
    839      1.30    martin 				ffb_ras_wait(sc);
    840  1.37.4.1     rmind 				ffb_putchar(cookie, ri->ri_crow, ri->ri_ccol,
    841      1.30    martin 				    scr->scr_chars[coffset], revattr);
    842      1.30    martin 				ri->ri_flg |= RI_CURSOR;
    843      1.30    martin 			}
    844      1.30    martin 		} else {
    845      1.30    martin 			ri->ri_crow = row;
    846      1.30    martin 			ri->ri_ccol = col;
    847      1.30    martin 			ri->ri_flg &= ~RI_CURSOR;
    848      1.16  macallan 		}
    849      1.16  macallan 	}
    850      1.16  macallan }
    851      1.16  macallan 
    852      1.16  macallan void
    853      1.16  macallan ffb_putchar(void *cookie, int row, int col, u_int c, long attr)
    854      1.16  macallan {
    855      1.16  macallan 	struct rasops_info *ri = cookie;
    856      1.30    martin 	struct vcons_screen *scr = ri->ri_hw;
    857  1.37.4.1     rmind 	struct wsdisplay_font *font = PICK_FONT(ri, c);
    858      1.30    martin 	struct ffb_softc *sc = scr->scr_cookie;
    859      1.16  macallan 
    860  1.37.4.1     rmind 	/*
    861  1.37.4.1     rmind 	 * font operations don't use the blitter so we have to wait here
    862  1.37.4.1     rmind 	 * in case we were scrolling
    863  1.37.4.1     rmind 	 */
    864  1.37.4.1     rmind 
    865  1.37.4.1     rmind 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    866  1.37.4.1     rmind 		void *data;
    867  1.37.4.1     rmind 		uint32_t fg, bg;
    868  1.37.4.1     rmind 		int uc, i;
    869  1.37.4.1     rmind 		int x, y, wi, he;
    870  1.37.4.1     rmind 
    871  1.37.4.1     rmind 		wi = font->fontwidth;
    872  1.37.4.1     rmind 		he = font->fontheight;
    873  1.37.4.1     rmind 
    874  1.37.4.1     rmind 		if (!CHAR_IN_FONT(c, font))
    875  1.37.4.1     rmind 			return;
    876  1.37.4.1     rmind 		bg = ri->ri_devcmap[(attr >> 16) & 0xf];
    877  1.37.4.1     rmind 		fg = ri->ri_devcmap[(attr >> 24) & 0xf];
    878  1.37.4.1     rmind 		x = ri->ri_xorigin + col * wi;
    879  1.37.4.1     rmind 		y = ri->ri_yorigin + row * he;
    880  1.37.4.1     rmind 
    881  1.37.4.1     rmind 		uc = c - font->firstchar;
    882  1.37.4.1     rmind 		data = (uint8_t *)font->data + uc * ri->ri_fontscale;
    883  1.37.4.1     rmind 
    884  1.37.4.1     rmind 		ffb_ras_setbg(sc, bg);
    885  1.37.4.1     rmind 		ffb_ras_setfg(sc, fg);
    886  1.37.4.1     rmind 		ffb_ras_fifo_wait(sc, 3);
    887  1.37.4.1     rmind 		FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_NEW);
    888  1.37.4.1     rmind 		FBC_WRITE(sc, FFB_FBC_FONTXY, (y << 16) | x);
    889  1.37.4.1     rmind 		FBC_WRITE(sc, FFB_FBC_FONTW, wi);
    890  1.37.4.1     rmind 
    891  1.37.4.1     rmind 		switch (ri->ri_font->stride) {
    892  1.37.4.1     rmind 			case 1: {
    893  1.37.4.1     rmind 				uint8_t *data8 = data;
    894  1.37.4.1     rmind 				uint32_t reg;
    895  1.37.4.1     rmind 				for (i = 0; i < he; i++) {
    896  1.37.4.1     rmind 					reg = *data8;
    897  1.37.4.1     rmind 					FBC_WRITE(sc, FFB_FBC_FONT, reg << 24);
    898  1.37.4.1     rmind 					data8++;
    899  1.37.4.1     rmind 				}
    900  1.37.4.1     rmind 				break;
    901  1.37.4.1     rmind 			}
    902  1.37.4.1     rmind 			case 2: {
    903  1.37.4.1     rmind 				uint16_t *data16 = data;
    904  1.37.4.1     rmind 				uint32_t reg;
    905  1.37.4.1     rmind 				for (i = 0; i < he; i++) {
    906  1.37.4.1     rmind 					reg = *data16;
    907  1.37.4.1     rmind 					FBC_WRITE(sc, FFB_FBC_FONT, reg << 16);
    908  1.37.4.1     rmind 					data16++;
    909  1.37.4.1     rmind 				}
    910  1.37.4.1     rmind 				break;
    911  1.37.4.1     rmind 			}
    912  1.37.4.1     rmind 		}
    913      1.16  macallan 	}
    914      1.16  macallan }
    915      1.16  macallan 
    916      1.16  macallan int
    917      1.16  macallan ffb_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
    918      1.16  macallan {
    919      1.16  macallan 	if ((fg == 0) && (bg == 0))
    920      1.16  macallan 	{
    921      1.16  macallan 		fg = WS_DEFAULT_FG;
    922      1.16  macallan 		bg = WS_DEFAULT_BG;
    923      1.16  macallan 	}
    924      1.16  macallan 	if (flags & WSATTR_REVERSE) {
    925      1.16  macallan 		*attrp = (bg & 0xff) << 24 | (fg & 0xff) << 16 |
    926      1.16  macallan 		    (flags & 0xff);
    927      1.16  macallan 	} else
    928      1.16  macallan 		*attrp = (fg & 0xff) << 24 | (bg & 0xff) << 16 |
    929      1.16  macallan 		    (flags & 0xff);
    930      1.16  macallan 	return 0;
    931      1.16  macallan }
    932      1.16  macallan 
    933      1.16  macallan void
    934      1.30    martin ffb_init_screen(void *cookie, struct vcons_screen *scr,
    935      1.16  macallan     int existing, long *defattr)
    936      1.16  macallan {
    937      1.30    martin 	struct ffb_softc *sc = cookie;
    938      1.30    martin 	struct rasops_info *ri = &scr->scr_ri;
    939      1.16  macallan 
    940      1.16  macallan 	ri->ri_depth = 32;
    941      1.16  macallan 	ri->ri_width = sc->sc_width;
    942      1.16  macallan 	ri->ri_height = sc->sc_height;
    943      1.16  macallan 	ri->ri_stride = sc->sc_linebytes;
    944      1.16  macallan 	ri->ri_flg = RI_CENTER;
    945      1.16  macallan 
    946  1.37.4.1     rmind 	/*
    947  1.37.4.1     rmind 	 * we can't accelerate copycols() so instead of falling back to
    948  1.37.4.1     rmind 	 * software use vcons' putchar() based implementation
    949  1.37.4.1     rmind 	 */
    950  1.37.4.1     rmind 	scr->scr_flags |= VCONS_NO_COPYCOLS;
    951  1.37.4.1     rmind 
    952  1.37.4.1     rmind #ifdef FFB_DEBUG
    953      1.16  macallan 	printf("addr: %08lx\n",(ulong)ri->ri_bits);
    954      1.16  macallan #endif
    955      1.16  macallan 	rasops_init(ri, sc->sc_height/8, sc->sc_width/8);
    956      1.16  macallan 	ri->ri_caps = WSSCREEN_WSCOLORS;
    957      1.16  macallan 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
    958      1.16  macallan 		    sc->sc_width / ri->ri_font->fontwidth);
    959      1.16  macallan 
    960      1.16  macallan 	/* enable acceleration */
    961      1.16  macallan 	ri->ri_ops.copyrows = ffb_ras_copyrows;
    962      1.16  macallan 	ri->ri_ops.eraserows = ffb_ras_eraserows;
    963      1.16  macallan 	ri->ri_ops.erasecols = ffb_ras_erasecols;
    964      1.16  macallan 	ri->ri_ops.cursor = ffb_cursor;
    965      1.16  macallan 	ri->ri_ops.allocattr = ffb_allocattr;
    966      1.16  macallan 	ri->ri_ops.putchar = ffb_putchar;
    967      1.16  macallan }
    968