Home | History | Annotate | Line # | Download | only in pci
wcfb.c revision 1.12.14.2
      1  1.12.14.2     skrll /*	$NetBSD: wcfb.c,v 1.12.14.2 2016/10/05 20:55:55 skrll Exp $ */
      2        1.1  macallan 
      3  1.12.14.1     skrll /*
      4  1.12.14.1     skrll  * Copyright (c) 2007, 2008, 2009 Miodrag Vallat.
      5  1.12.14.1     skrll  *               2010 Michael Lorenz
      6        1.1  macallan  *
      7  1.12.14.1     skrll  * Permission to use, copy, modify, and distribute this software for any
      8  1.12.14.1     skrll  * purpose with or without fee is hereby granted, provided that the above
      9  1.12.14.1     skrll  * copyright notice and this permission notice appear in all copies.
     10        1.1  macallan  *
     11  1.12.14.1     skrll  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12  1.12.14.1     skrll  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13  1.12.14.1     skrll  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14  1.12.14.1     skrll  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15  1.12.14.1     skrll  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16  1.12.14.1     skrll  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17  1.12.14.1     skrll  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18        1.1  macallan  */
     19        1.1  macallan 
     20  1.12.14.1     skrll /* a driver for (some) 3DLabs Wildcat cards, based on OpenBSD's ifb driver */
     21  1.12.14.1     skrll 
     22        1.1  macallan #include <sys/cdefs.h>
     23  1.12.14.2     skrll __KERNEL_RCSID(0, "$NetBSD: wcfb.c,v 1.12.14.2 2016/10/05 20:55:55 skrll Exp $");
     24        1.1  macallan 
     25        1.1  macallan #include <sys/param.h>
     26        1.1  macallan #include <sys/systm.h>
     27        1.1  macallan #include <sys/kernel.h>
     28        1.1  macallan #include <sys/device.h>
     29        1.1  macallan #include <sys/proc.h>
     30        1.1  macallan #include <sys/mutex.h>
     31        1.1  macallan #include <sys/ioctl.h>
     32        1.1  macallan #include <sys/kernel.h>
     33        1.1  macallan #include <sys/systm.h>
     34        1.1  macallan #include <sys/kauth.h>
     35        1.3  macallan #include <sys/kmem.h>
     36        1.1  macallan 
     37        1.1  macallan #include <dev/pci/pcidevs.h>
     38        1.1  macallan #include <dev/pci/pcireg.h>
     39        1.1  macallan #include <dev/pci/pcivar.h>
     40        1.1  macallan #include <dev/pci/pciio.h>
     41        1.6  macallan #include <dev/pci/wcfbreg.h>
     42        1.1  macallan 
     43        1.1  macallan #include <dev/wscons/wsdisplayvar.h>
     44        1.1  macallan #include <dev/wscons/wsconsio.h>
     45        1.1  macallan #include <dev/wsfont/wsfont.h>
     46        1.1  macallan #include <dev/rasops/rasops.h>
     47        1.1  macallan #include <dev/wscons/wsdisplay_vconsvar.h>
     48        1.8    cegger #include <dev/pci/wsdisplay_pci.h>
     49        1.1  macallan 
     50        1.1  macallan #include "opt_wsfb.h"
     51        1.5  macallan #include "opt_wsdisplay_compat.h"
     52        1.1  macallan 
     53        1.1  macallan #ifdef WCFB_DEBUG
     54        1.1  macallan # define DPRINTF printf
     55        1.1  macallan #else
     56        1.1  macallan # define DPRINTF while (0) printf
     57        1.1  macallan #endif
     58        1.1  macallan 
     59        1.1  macallan static int	wcfb_match(device_t, cfdata_t, void *);
     60        1.1  macallan static void	wcfb_attach(device_t, device_t, void *);
     61        1.1  macallan static int	wcfb_ioctl(void *, void *, u_long, void *, int,
     62        1.1  macallan 		    struct lwp *);
     63        1.1  macallan static paddr_t	wcfb_mmap(void *, void *, off_t, int);
     64        1.1  macallan 
     65        1.1  macallan struct wcfb_softc {
     66        1.1  macallan 	device_t sc_dev;
     67        1.1  macallan 
     68        1.1  macallan 	pci_chipset_tag_t sc_pc;
     69        1.1  macallan 	pcitag_t sc_pcitag;
     70        1.1  macallan 
     71        1.1  macallan 	bus_space_tag_t sc_memt;
     72        1.1  macallan 	bus_space_tag_t sc_regt, sc_wtft;
     73        1.1  macallan 	bus_space_tag_t sc_iot;
     74        1.1  macallan 
     75        1.1  macallan 	bus_space_handle_t sc_fbh, sc_wtfh;
     76        1.1  macallan 	bus_space_handle_t sc_regh;
     77        1.1  macallan 	bus_addr_t sc_fb, sc_reg, sc_wtf;
     78        1.1  macallan 	bus_size_t sc_fbsize, sc_regsize, sc_wtfsize;
     79        1.1  macallan 
     80        1.1  macallan 	int sc_width, sc_height, sc_stride;
     81        1.1  macallan 	int sc_locked;
     82        1.3  macallan 	uint8_t *sc_fbaddr, *sc_fb0, *sc_fb1, *sc_shadow;
     83        1.1  macallan 	struct vcons_screen sc_console_screen;
     84        1.1  macallan 	struct wsscreen_descr sc_defaultscreen_descr;
     85        1.1  macallan 	const struct wsscreen_descr *sc_screens[1];
     86        1.1  macallan 	struct wsscreen_list sc_screenlist;
     87        1.1  macallan 	struct vcons_data vd;
     88        1.1  macallan 	int sc_mode;
     89        1.1  macallan 	u_char sc_cmap_red[256];
     90        1.1  macallan 	u_char sc_cmap_green[256];
     91        1.1  macallan 	u_char sc_cmap_blue[256];
     92        1.6  macallan 	uint32_t sc_fb0off, sc_fb1off;
     93        1.1  macallan 
     94        1.1  macallan 	void (*copycols)(void *, int, int, int, int);
     95        1.1  macallan 	void (*erasecols)(void *, int, int, int, long);
     96        1.1  macallan 	void (*copyrows)(void *, int, int, int);
     97        1.1  macallan 	void (*eraserows)(void *, int, int, long);
     98        1.1  macallan 	void (*putchar)(void *, int, int, u_int, long);
     99        1.1  macallan 	void (*cursor)(void *, int, int, int);
    100       1.12  macallan 	int sc_is_jfb;
    101        1.1  macallan };
    102        1.1  macallan 
    103        1.1  macallan static void	wcfb_init_screen(void *, struct vcons_screen *, int, long *);
    104        1.1  macallan 
    105        1.1  macallan CFATTACH_DECL_NEW(wcfb, sizeof(struct wcfb_softc),
    106        1.1  macallan     wcfb_match, wcfb_attach, NULL, NULL);
    107        1.1  macallan 
    108        1.1  macallan struct wsdisplay_accessops wcfb_accessops = {
    109        1.1  macallan 	wcfb_ioctl,
    110        1.1  macallan 	wcfb_mmap,
    111        1.1  macallan 	NULL,	/* alloc_screen */
    112        1.1  macallan 	NULL,	/* free_screen */
    113        1.1  macallan 	NULL,	/* show_screen */
    114        1.1  macallan 	NULL, 	/* load_font */
    115        1.1  macallan 	NULL,	/* pollc */
    116        1.1  macallan 	NULL	/* scroll */
    117        1.1  macallan };
    118        1.1  macallan 
    119        1.1  macallan static void	wcfb_putchar(void *, int, int, u_int, long);
    120        1.1  macallan static void	wcfb_cursor(void *, int, int, int);
    121        1.1  macallan static void	wcfb_copycols(void *, int, int, int, int);
    122        1.1  macallan static void	wcfb_erasecols(void *, int, int, int, long);
    123        1.1  macallan static void	wcfb_copyrows(void *, int, int, int);
    124        1.1  macallan static void	wcfb_eraserows(void *, int, int, long);
    125        1.1  macallan 
    126       1.12  macallan static void	wcfb_acc_putchar(void *, int, int, u_int, long);
    127       1.12  macallan static void	wcfb_acc_cursor(void *, int, int, int);
    128       1.12  macallan static void	wcfb_acc_copycols(void *, int, int, int, int);
    129       1.12  macallan static void	wcfb_acc_erasecols(void *, int, int, int, long);
    130       1.12  macallan static void	wcfb_acc_copyrows(void *, int, int, int);
    131       1.12  macallan static void	wcfb_acc_eraserows(void *, int, int, long);
    132       1.12  macallan 
    133        1.1  macallan static void 	wcfb_putpalreg(struct wcfb_softc *, int, int, int, int);
    134        1.1  macallan 
    135       1.12  macallan static void	wcfb_bitblt(struct wcfb_softc *, int, int, int, int, int,
    136       1.12  macallan 			int, uint32_t);
    137       1.12  macallan static void	wcfb_rectfill(struct wcfb_softc *, int, int, int, int, int);
    138  1.12.14.2     skrll static void	wcfb_rop_common(struct wcfb_softc *, bus_addr_t, int, int, int,
    139       1.12  macallan 			int, int, int, uint32_t, int32_t);
    140  1.12.14.2     skrll static void	wcfb_rop_jfb(struct wcfb_softc *, int, int, int, int, int, int,
    141       1.12  macallan 			uint32_t, int32_t);
    142       1.12  macallan static int	wcfb_rop_wait(struct wcfb_softc *);
    143       1.12  macallan 
    144        1.1  macallan static int
    145        1.1  macallan wcfb_match(device_t parent, cfdata_t match, void *aux)
    146        1.1  macallan {
    147        1.1  macallan 	struct pci_attach_args *pa = aux;
    148        1.1  macallan 
    149        1.1  macallan 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_3DLABS &&
    150        1.1  macallan 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_3DLABS_WILDCAT5110)
    151        1.1  macallan 		return 100;
    152        1.1  macallan 
    153        1.1  macallan 	return 0;
    154        1.1  macallan }
    155        1.1  macallan 
    156        1.1  macallan static void
    157        1.1  macallan wcfb_attach(device_t parent, device_t self, void *aux)
    158        1.1  macallan {
    159        1.1  macallan 	struct wcfb_softc *sc = device_private(self);
    160        1.1  macallan 	struct pci_attach_args *pa = aux;
    161        1.1  macallan 	struct rasops_info	*ri;
    162        1.1  macallan 	prop_dictionary_t	dict;
    163        1.1  macallan 	struct wsemuldisplaydev_attach_args aa;
    164        1.1  macallan 	int 			i, j;
    165        1.6  macallan 	uint32_t		reg;
    166        1.1  macallan 	unsigned long		defattr;
    167        1.6  macallan 	bool			is_console = 0;
    168       1.12  macallan 	void 			*wtf;
    169       1.12  macallan 	uint32_t		sub;
    170        1.1  macallan 
    171        1.1  macallan 	sc->sc_dev = self;
    172        1.1  macallan 	sc->putchar = NULL;
    173       1.10  drochner 	pci_aprint_devinfo(pa, NULL);
    174        1.1  macallan 
    175        1.1  macallan 	dict = device_properties(self);
    176        1.1  macallan 	prop_dictionary_get_bool(dict, "is_console", &is_console);
    177        1.6  macallan #ifndef WCFB_DEBUG
    178        1.6  macallan 	if (!is_console) return;
    179        1.6  macallan #endif
    180        1.1  macallan 	sc->sc_memt = pa->pa_memt;
    181  1.12.14.2     skrll 	sc->sc_iot = pa->pa_iot;
    182        1.1  macallan 	sc->sc_pc = pa->pa_pc;
    183        1.1  macallan 	sc->sc_pcitag = pa->pa_tag;
    184        1.1  macallan 
    185        1.1  macallan 	if (pci_mapreg_map(pa, 0x14, PCI_MAPREG_TYPE_MEM, 0,
    186        1.1  macallan 	    &sc->sc_regt, &sc->sc_regh, &sc->sc_reg, &sc->sc_regsize)) {
    187        1.1  macallan 		aprint_error("%s: failed to map registers.\n",
    188        1.1  macallan 		    device_xname(sc->sc_dev));
    189        1.1  macallan 	}
    190        1.1  macallan 
    191        1.1  macallan 	if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM, BUS_SPACE_MAP_LINEAR,
    192        1.1  macallan 	    &sc->sc_memt, &sc->sc_fbh, &sc->sc_fb, &sc->sc_fbsize)) {
    193        1.1  macallan 		aprint_error("%s: failed to map framebuffer.\n",
    194        1.1  macallan 		    device_xname(sc->sc_dev));
    195        1.1  macallan 	}
    196        1.1  macallan 
    197        1.1  macallan 	if (pci_mapreg_map(pa, 0x18, PCI_MAPREG_TYPE_MEM, BUS_SPACE_MAP_LINEAR,
    198        1.1  macallan 	    &sc->sc_wtft, &sc->sc_wtfh, &sc->sc_wtf, &sc->sc_wtfsize)) {
    199        1.1  macallan 		aprint_error("%s: failed to map wtf.\n",
    200        1.1  macallan 		    device_xname(sc->sc_dev));
    201        1.1  macallan 	}
    202        1.1  macallan 	wtf = bus_space_vaddr(sc->sc_wtft, sc->sc_wtfh);
    203        1.1  macallan 	memset(wtf, 0, 0x100000);
    204        1.1  macallan 
    205        1.1  macallan 	sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
    206        1.1  macallan 
    207        1.6  macallan 	sc->sc_fb0off =
    208       1.12  macallan 	    bus_space_read_4(sc->sc_regt, sc->sc_regh,
    209       1.12  macallan 	        WC_FB8_ADDR0) - sc->sc_fb;
    210        1.3  macallan 	sc->sc_fb0 = sc->sc_fbaddr + sc->sc_fb0off;
    211  1.12.14.2     skrll 	sc->sc_fb1off =
    212       1.12  macallan 	    bus_space_read_4(sc->sc_regt, sc->sc_regh,
    213       1.12  macallan 	        WC_FB8_ADDR1) - sc->sc_fb;
    214        1.6  macallan 	sc->sc_fb1 = sc->sc_fbaddr + sc->sc_fb1off;
    215        1.6  macallan 
    216       1.12  macallan 	sub = pci_conf_read(sc->sc_pc, sc->sc_pcitag, PCI_SUBSYS_ID_REG);
    217  1.12.14.2     skrll 	aprint_normal("subsys: %08x\n", sub);
    218       1.12  macallan 	switch (sub) {
    219       1.12  macallan 		case WC_XVR1200:
    220       1.12  macallan 			sc->sc_is_jfb = 1;
    221       1.12  macallan 			break;
    222       1.12  macallan 		default:
    223       1.12  macallan 			sc->sc_is_jfb = 0;
    224       1.12  macallan 	}
    225       1.12  macallan 
    226        1.6  macallan 	reg = bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_RESOLUTION);
    227        1.6  macallan 	sc->sc_height = (reg >> 16) + 1;
    228       1.12  macallan #ifdef WCFB_DEBUG
    229       1.12  macallan 	sc->sc_height -= 200;
    230       1.12  macallan #endif
    231        1.6  macallan 	sc->sc_width = (reg & 0xffff) + 1;
    232        1.6  macallan 	sc->sc_stride = 1 <<
    233        1.6  macallan 	    ((bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_CONFIG) &
    234        1.6  macallan 	      0x00ff0000) >> 16);
    235  1.12.14.2     skrll 	aprint_normal_dev(self, "%d x %d, %d\n",
    236        1.1  macallan 	    sc->sc_width, sc->sc_height, sc->sc_stride);
    237        1.3  macallan 
    238       1.12  macallan 	if (sc->sc_is_jfb == 0) {
    239       1.12  macallan 		sc->sc_shadow = kmem_alloc(sc->sc_stride * sc->sc_height,
    240       1.12  macallan 		    KM_SLEEP);
    241       1.12  macallan 		if (sc->sc_shadow == NULL) {
    242  1.12.14.2     skrll 			aprint_error_dev(self,
    243  1.12.14.2     skrll 			    "failed to allocate shadow buffer\n");
    244       1.12  macallan 			return;
    245       1.12  macallan 		}
    246        1.3  macallan 	}
    247        1.3  macallan 
    248        1.1  macallan 	for (i = 0x40; i < 0x100; i += 16) {
    249  1.12.14.2     skrll 		aprint_normal("%04x:", i);
    250        1.1  macallan 		for (j = 0; j < 16; j += 4) {
    251  1.12.14.2     skrll 			aprint_normal(" %08x", bus_space_read_4(sc->sc_regt,
    252        1.1  macallan 			    sc->sc_regh, 0x8000 + i + j));
    253        1.1  macallan 		}
    254  1.12.14.2     skrll 		aprint_normal("\n");
    255        1.1  macallan 	}
    256        1.1  macallan 
    257        1.6  macallan 	/* make sure video output is on */
    258        1.6  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_DPMS_STATE, WC_DPMS_ON);
    259        1.6  macallan 
    260        1.1  macallan 	sc->sc_defaultscreen_descr = (struct wsscreen_descr){
    261        1.1  macallan 		"default",
    262        1.1  macallan 		0, 0,
    263        1.1  macallan 		NULL,
    264        1.1  macallan 		8, 16,
    265        1.1  macallan 		WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    266        1.1  macallan 		NULL
    267        1.1  macallan 	};
    268        1.1  macallan 	sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
    269        1.1  macallan 	sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
    270        1.1  macallan 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    271        1.1  macallan 	sc->sc_locked = 0;
    272        1.1  macallan 
    273        1.1  macallan 	vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
    274        1.1  macallan 	    &wcfb_accessops);
    275        1.1  macallan 	sc->vd.init_screen = wcfb_init_screen;
    276        1.1  macallan 
    277        1.1  macallan 	/* init engine here */
    278        1.1  macallan #if 0
    279        1.1  macallan 	wcfb_init(sc);
    280        1.1  macallan #endif
    281        1.1  macallan 
    282        1.1  macallan 	ri = &sc->sc_console_screen.scr_ri;
    283        1.1  macallan 
    284        1.1  macallan 	j = 0;
    285        1.1  macallan 	for (i = 0; i < 256; i++) {
    286        1.1  macallan 
    287        1.1  macallan 		sc->sc_cmap_red[i] = rasops_cmap[j];
    288        1.1  macallan 		sc->sc_cmap_green[i] = rasops_cmap[j + 1];
    289        1.1  macallan 		sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
    290        1.1  macallan 		wcfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
    291        1.1  macallan 		    rasops_cmap[j + 2]);
    292        1.1  macallan 		j += 3;
    293        1.1  macallan 	}
    294        1.1  macallan 
    295        1.1  macallan 	if (is_console) {
    296        1.1  macallan 		vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
    297        1.1  macallan 		    &defattr);
    298        1.1  macallan 		sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    299        1.1  macallan 
    300       1.12  macallan 		if (sc->sc_is_jfb) {
    301       1.12  macallan 			wcfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
    302       1.12  macallan 				ri->ri_devcmap[(defattr >> 16) & 0xff]);
    303       1.12  macallan 		} else {
    304       1.12  macallan 			memset(sc->sc_fb0,
    305       1.12  macallan 			    ri->ri_devcmap[(defattr >> 16) & 0xff],
    306       1.12  macallan 			    sc->sc_stride * sc->sc_height);
    307       1.12  macallan 			memset(sc->sc_fb1,
    308       1.12  macallan 			    ri->ri_devcmap[(defattr >> 16) & 0xff],
    309       1.12  macallan 			    sc->sc_stride * sc->sc_height);
    310       1.12  macallan 		}
    311        1.1  macallan 		sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
    312        1.1  macallan 		sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
    313        1.1  macallan 		sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
    314        1.1  macallan 		sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
    315        1.1  macallan 		wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
    316        1.1  macallan 		    defattr);
    317        1.1  macallan 		vcons_replay_msgbuf(&sc->sc_console_screen);
    318        1.1  macallan 	} else {
    319        1.1  macallan 		/*
    320        1.1  macallan 		 * since we're not the console we can postpone the rest
    321        1.1  macallan 		 * until someone actually allocates a screen for us
    322        1.1  macallan 		 */
    323        1.6  macallan 		memset(sc->sc_fb0, WS_DEFAULT_BG,
    324        1.6  macallan 		    sc->sc_stride * sc->sc_height);
    325        1.6  macallan 		memset(sc->sc_fb1, WS_DEFAULT_BG,
    326        1.6  macallan 		    sc->sc_stride * sc->sc_height);
    327        1.6  macallan 		return;
    328        1.1  macallan 	}
    329        1.1  macallan 
    330        1.1  macallan 	aa.console = is_console;
    331        1.1  macallan 	aa.scrdata = &sc->sc_screenlist;
    332        1.1  macallan 	aa.accessops = &wcfb_accessops;
    333        1.1  macallan 	aa.accesscookie = &sc->vd;
    334        1.1  macallan 
    335        1.1  macallan 	config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
    336        1.1  macallan }
    337        1.1  macallan 
    338        1.1  macallan static int
    339        1.1  macallan wcfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    340        1.1  macallan     struct lwp *l)
    341        1.1  macallan {
    342        1.1  macallan 	struct wcfb_softc *sc = v;
    343        1.1  macallan 
    344        1.1  macallan 	switch (cmd) {
    345        1.7    cegger 	case WSDISPLAYIO_GTYPE:
    346        1.7    cegger 		*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
    347        1.7    cegger 		return 0;
    348        1.7    cegger 
    349        1.7    cegger 	/* PCI config read/write passthrough. */
    350        1.7    cegger 	case PCI_IOC_CFGREAD:
    351        1.7    cegger 	case PCI_IOC_CFGWRITE:
    352        1.7    cegger 		return pci_devioctl(sc->sc_pc, sc->sc_pcitag,
    353        1.7    cegger 		    cmd, data, flag, l);
    354        1.8    cegger 
    355        1.8    cegger 	case WSDISPLAYIO_GET_BUSID:
    356        1.8    cegger 		return wsdisplayio_busid_pci(sc->sc_dev, sc->sc_pc,
    357        1.8    cegger 		    sc->sc_pcitag, data);
    358        1.8    cegger 
    359        1.7    cegger 	case WSDISPLAYIO_SMODE: {
    360        1.7    cegger 		/*int new_mode = *(int*)data, i;*/
    361        1.7    cegger 		}
    362        1.7    cegger 		return 0;
    363        1.1  macallan 	}
    364        1.1  macallan 
    365        1.1  macallan 	return EPASSTHROUGH;
    366        1.1  macallan }
    367        1.1  macallan 
    368        1.1  macallan static paddr_t
    369        1.1  macallan wcfb_mmap(void *v, void *vs, off_t offset, int prot)
    370        1.1  macallan {
    371        1.1  macallan 	struct wcfb_softc *sc = v;
    372        1.1  macallan 
    373        1.1  macallan 	/* no point in allowing a wsfb map if we can't provide one */
    374        1.1  macallan 	/*
    375        1.1  macallan 	 * restrict all other mappings to processes with superuser privileges
    376        1.1  macallan 	 * or the kernel itself
    377        1.1  macallan 	 */
    378  1.12.14.2     skrll 	if (kauth_authorize_machdep(kauth_cred_get(),
    379       1.12  macallan 	    KAUTH_MACHDEP_UNMANAGEDMEM,
    380       1.11      elad 	    NULL, NULL, NULL, NULL) != 0) {
    381        1.1  macallan 		aprint_normal_dev(sc->sc_dev, "mmap() rejected.\n");
    382        1.1  macallan 		return -1;
    383        1.1  macallan 	}
    384        1.1  macallan 
    385        1.1  macallan #ifdef WSFB_FAKE_VGA_FB
    386        1.1  macallan 	if ((offset >= 0xa0000) && (offset < 0xbffff)) {
    387        1.1  macallan 
    388        1.1  macallan 		return bus_space_mmap(sc->sc_memt, sc->sc_gen.sc_fboffset,
    389        1.1  macallan 		   offset - 0xa0000, prot, BUS_SPACE_MAP_LINEAR);
    390        1.1  macallan 	}
    391        1.1  macallan #endif
    392        1.1  macallan 
    393        1.1  macallan 	return -1;
    394        1.1  macallan }
    395        1.1  macallan 
    396        1.1  macallan static void
    397        1.1  macallan wcfb_init_screen(void *cookie, struct vcons_screen *scr,
    398        1.1  macallan     int existing, long *defattr)
    399        1.1  macallan {
    400        1.1  macallan 	struct wcfb_softc *sc = cookie;
    401        1.1  macallan 	struct rasops_info *ri = &scr->scr_ri;
    402        1.1  macallan 
    403        1.1  macallan 	ri->ri_depth = 8;
    404        1.1  macallan 	ri->ri_width = sc->sc_width;
    405        1.1  macallan 	ri->ri_height = sc->sc_height;
    406        1.1  macallan 	ri->ri_stride = sc->sc_stride;
    407        1.1  macallan 	ri->ri_flg = RI_CENTER /*| RI_FULLCLEAR*/;
    408        1.1  macallan 
    409       1.12  macallan 	if (sc->sc_is_jfb) {
    410       1.12  macallan 		ri->ri_bits = sc->sc_fb0;
    411       1.12  macallan 	} else {
    412       1.12  macallan 		ri->ri_bits = sc->sc_shadow;
    413       1.12  macallan 	}
    414        1.1  macallan 	if (existing) {
    415        1.1  macallan 		ri->ri_flg |= RI_CLEAR;
    416        1.1  macallan 	}
    417        1.1  macallan 
    418        1.9  macallan 	rasops_init(ri, 0, 0);
    419        1.1  macallan 	ri->ri_caps = WSSCREEN_WSCOLORS;
    420        1.1  macallan 
    421        1.1  macallan 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
    422        1.1  macallan 		    sc->sc_width / ri->ri_font->fontwidth);
    423        1.1  macallan 
    424        1.1  macallan 	ri->ri_hw = scr;
    425        1.1  macallan 	sc->putchar = ri->ri_ops.putchar;
    426        1.1  macallan 	sc->copyrows = ri->ri_ops.copyrows;
    427        1.1  macallan 	sc->eraserows = ri->ri_ops.eraserows;
    428        1.1  macallan 	sc->copycols = ri->ri_ops.copycols;
    429        1.1  macallan 	sc->erasecols = ri->ri_ops.erasecols;
    430        1.1  macallan 
    431       1.12  macallan 	if (sc->sc_is_jfb) {
    432       1.12  macallan 		ri->ri_ops.copyrows = wcfb_acc_copyrows;
    433       1.12  macallan 		ri->ri_ops.copycols = wcfb_acc_copycols;
    434       1.12  macallan 		ri->ri_ops.eraserows = wcfb_acc_eraserows;
    435       1.12  macallan 		ri->ri_ops.erasecols = wcfb_acc_erasecols;
    436       1.12  macallan 		ri->ri_ops.putchar = wcfb_acc_putchar;
    437       1.12  macallan 		ri->ri_ops.cursor = wcfb_acc_cursor;
    438       1.12  macallan 	} else {
    439       1.12  macallan 		ri->ri_ops.copyrows = wcfb_copyrows;
    440       1.12  macallan 		ri->ri_ops.copycols = wcfb_copycols;
    441       1.12  macallan 		ri->ri_ops.eraserows = wcfb_eraserows;
    442       1.12  macallan 		ri->ri_ops.erasecols = wcfb_erasecols;
    443       1.12  macallan 		ri->ri_ops.putchar = wcfb_putchar;
    444       1.12  macallan 		ri->ri_ops.cursor = wcfb_cursor;
    445       1.12  macallan 	}
    446        1.1  macallan }
    447        1.1  macallan 
    448        1.1  macallan static void
    449        1.1  macallan wcfb_putchar(void *cookie, int row, int col, u_int c, long attr)
    450        1.1  macallan {
    451        1.1  macallan 	struct rasops_info *ri = cookie;
    452        1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    453        1.1  macallan 	struct wcfb_softc *sc = scr->scr_cookie;
    454        1.3  macallan 	int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
    455        1.3  macallan 	    sc->sc_stride + ri->ri_xorigin + col * ri->ri_font->fontwidth;
    456        1.3  macallan 	uint8_t *from, *to0, *to1;
    457        1.3  macallan 	int i;
    458        1.1  macallan 
    459        1.1  macallan 	sc->putchar(ri, row, col, c, attr);
    460        1.3  macallan 	from = sc->sc_shadow + offset;
    461        1.3  macallan 	to0 = sc->sc_fb0 + offset;
    462        1.3  macallan 	to1 = sc->sc_fb1 + offset;
    463        1.3  macallan 	for (i = 0; i < ri->ri_font->fontheight; i++) {
    464        1.3  macallan 		memcpy(to0, from, ri->ri_font->fontwidth);
    465        1.3  macallan 		memcpy(to1, from, ri->ri_font->fontwidth);
    466        1.3  macallan 		to0 += sc->sc_stride;
    467        1.3  macallan 		to1 += sc->sc_stride;
    468        1.3  macallan 		from += sc->sc_stride;
    469        1.3  macallan 	}
    470  1.12.14.2     skrll }
    471        1.1  macallan 
    472        1.1  macallan static void
    473        1.1  macallan wcfb_putpalreg(struct wcfb_softc *sc, int i, int r, int g, int b)
    474        1.1  macallan {
    475        1.1  macallan 	uint32_t rgb;
    476        1.1  macallan 
    477        1.6  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_CMAP_INDEX, i);
    478        1.1  macallan 	rgb = (b << 22) | (g << 12) | (r << 2);
    479        1.6  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_CMAP_DATA, rgb);
    480        1.1  macallan }
    481        1.1  macallan 
    482        1.1  macallan static void
    483        1.1  macallan wcfb_cursor(void *cookie, int on, int row, int col)
    484        1.1  macallan {
    485        1.1  macallan 	struct rasops_info *ri = cookie;
    486        1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    487        1.1  macallan 	struct wcfb_softc *sc = scr->scr_cookie;
    488        1.4  macallan 	int coffset;
    489  1.12.14.2     skrll 
    490        1.4  macallan 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    491        1.4  macallan 
    492        1.4  macallan 		if (ri->ri_flg & RI_CURSOR) {
    493        1.4  macallan 			/* remove cursor */
    494        1.4  macallan 			coffset = ri->ri_ccol + (ri->ri_crow * ri->ri_cols);
    495        1.4  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    496        1.4  macallan 			coffset += scr->scr_offset_to_zero;
    497        1.4  macallan #endif
    498  1.12.14.2     skrll 			wcfb_putchar(cookie, ri->ri_crow,
    499  1.12.14.2     skrll 			    ri->ri_ccol, scr->scr_chars[coffset],
    500        1.4  macallan 			    scr->scr_attrs[coffset]);
    501        1.4  macallan 			ri->ri_flg &= ~RI_CURSOR;
    502        1.4  macallan 		}
    503        1.4  macallan 		ri->ri_crow = row;
    504        1.4  macallan 		ri->ri_ccol = col;
    505        1.4  macallan 		if (on) {
    506        1.4  macallan 			long attr, revattr;
    507        1.4  macallan 			coffset = col + (row * ri->ri_cols);
    508        1.4  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    509        1.4  macallan 			coffset += scr->scr_offset_to_zero;
    510        1.1  macallan #endif
    511        1.4  macallan 			attr = scr->scr_attrs[coffset];
    512        1.4  macallan 			revattr = attr ^ 0xffff0000;
    513        1.4  macallan 
    514        1.4  macallan 			wcfb_putchar(cookie, ri->ri_crow, ri->ri_ccol,
    515        1.4  macallan 			    scr->scr_chars[coffset], revattr);
    516        1.4  macallan 			ri->ri_flg |= RI_CURSOR;
    517        1.4  macallan 		}
    518        1.4  macallan 	} else {
    519        1.4  macallan 		ri->ri_crow = row;
    520        1.4  macallan 		ri->ri_ccol = col;
    521        1.4  macallan 		ri->ri_flg &= ~RI_CURSOR;
    522        1.4  macallan 	}
    523        1.1  macallan }
    524        1.1  macallan 
    525        1.1  macallan static void
    526        1.1  macallan wcfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
    527        1.1  macallan {
    528        1.1  macallan 	struct rasops_info *ri = cookie;
    529        1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    530        1.1  macallan 	struct wcfb_softc *sc = scr->scr_cookie;
    531        1.3  macallan 	int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
    532        1.3  macallan 	    sc->sc_stride + ri->ri_xorigin + dstcol * ri->ri_font->fontwidth;
    533        1.3  macallan 	uint8_t *from, *to0, *to1;
    534        1.3  macallan 	int i;
    535        1.1  macallan 
    536        1.1  macallan 	sc->copycols(ri, row, srccol, dstcol, ncols);
    537        1.3  macallan 	from = sc->sc_shadow + offset;
    538        1.3  macallan 	to0 = sc->sc_fb0 + offset;
    539        1.3  macallan 	to1 = sc->sc_fb1 + offset;
    540        1.3  macallan 	for (i = 0; i < ri->ri_font->fontheight; i++) {
    541        1.3  macallan 		memcpy(to0, from, ri->ri_font->fontwidth * ncols);
    542        1.3  macallan 		memcpy(to1, from, ri->ri_font->fontwidth * ncols);
    543        1.3  macallan 		to0 += sc->sc_stride;
    544        1.3  macallan 		to1 += sc->sc_stride;
    545        1.3  macallan 		from += sc->sc_stride;
    546        1.3  macallan 	}
    547        1.1  macallan }
    548        1.1  macallan 
    549        1.1  macallan static void
    550        1.3  macallan wcfb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
    551        1.1  macallan {
    552        1.1  macallan 	struct rasops_info *ri = cookie;
    553        1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    554        1.1  macallan 	struct wcfb_softc *sc = scr->scr_cookie;
    555        1.3  macallan 	int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
    556        1.3  macallan 	    sc->sc_stride + ri->ri_xorigin + startcol * ri->ri_font->fontwidth;
    557        1.3  macallan 	uint8_t *to0, *to1;
    558        1.3  macallan 	int i;
    559        1.3  macallan 
    560        1.3  macallan 	sc->erasecols(ri, row, startcol, ncols, fillattr);
    561        1.3  macallan 
    562        1.3  macallan 	to0 = sc->sc_fb0 + offset;
    563        1.3  macallan 	to1 = sc->sc_fb1 + offset;
    564        1.3  macallan 	for (i = 0; i < ri->ri_font->fontheight; i++) {
    565        1.3  macallan 		memset(to0, ri->ri_devcmap[(fillattr >> 16) & 0xff],
    566        1.3  macallan 		    ri->ri_font->fontwidth * ncols);
    567        1.3  macallan 		memset(to1, ri->ri_devcmap[(fillattr >> 16) & 0xff],
    568        1.3  macallan 		    ri->ri_font->fontwidth * ncols);
    569        1.3  macallan 		to0 += sc->sc_stride;
    570        1.3  macallan 		to1 += sc->sc_stride;
    571        1.3  macallan 	}
    572        1.1  macallan }
    573        1.1  macallan 
    574        1.1  macallan static void
    575        1.3  macallan wcfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
    576        1.1  macallan {
    577        1.1  macallan 	struct rasops_info *ri = cookie;
    578        1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    579        1.1  macallan 	struct wcfb_softc *sc = scr->scr_cookie;
    580        1.3  macallan 	int offset = (ri->ri_yorigin + dstrow * ri->ri_font->fontheight) *
    581        1.3  macallan 	    sc->sc_stride + ri->ri_xorigin;
    582        1.3  macallan 	uint8_t *from, *to0, *to1;
    583        1.3  macallan 	int i;
    584        1.3  macallan 
    585        1.3  macallan 	sc->copyrows(ri, srcrow, dstrow, nrows);
    586        1.3  macallan 
    587        1.3  macallan 	from = sc->sc_shadow + offset;
    588        1.3  macallan 	to0 = sc->sc_fb0 + offset;
    589        1.3  macallan 	to1 = sc->sc_fb1 + offset;
    590        1.3  macallan 	for (i = 0; i < ri->ri_font->fontheight * nrows; i++) {
    591        1.3  macallan 		memcpy(to0, from, ri->ri_emuwidth);
    592        1.3  macallan 		memcpy(to1, from, ri->ri_emuwidth);
    593        1.3  macallan 		to0 += sc->sc_stride;
    594        1.3  macallan 		to1 += sc->sc_stride;
    595        1.3  macallan 		from += sc->sc_stride;
    596        1.3  macallan 	}
    597        1.1  macallan }
    598        1.1  macallan 
    599        1.1  macallan static void
    600        1.1  macallan wcfb_eraserows(void *cookie, int row, int nrows, long fillattr)
    601        1.1  macallan {
    602        1.1  macallan 	struct rasops_info *ri = cookie;
    603        1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    604        1.1  macallan 	struct wcfb_softc *sc = scr->scr_cookie;
    605        1.3  macallan 	int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
    606        1.3  macallan 	    sc->sc_stride + ri->ri_xorigin;
    607        1.3  macallan 	uint8_t *to0, *to1;
    608        1.3  macallan 	int i;
    609        1.1  macallan 
    610        1.1  macallan 	sc->eraserows(ri, row, nrows, fillattr);
    611        1.3  macallan 
    612        1.3  macallan 	to0 = sc->sc_fb0 + offset;
    613        1.3  macallan 	to1 = sc->sc_fb1 + offset;
    614        1.3  macallan 	for (i = 0; i < ri->ri_font->fontheight * nrows; i++) {
    615        1.3  macallan 		memset(to0, ri->ri_devcmap[(fillattr >> 16) & 0xff],
    616        1.3  macallan 		    ri->ri_emuwidth);
    617        1.3  macallan 		memset(to1, ri->ri_devcmap[(fillattr >> 16) & 0xff],
    618        1.3  macallan 		    ri->ri_emuwidth);
    619        1.3  macallan 		to0 += sc->sc_stride;
    620        1.3  macallan 		to1 += sc->sc_stride;
    621        1.3  macallan 	}
    622        1.1  macallan }
    623       1.12  macallan 
    624       1.12  macallan static void
    625       1.12  macallan wcfb_bitblt(struct wcfb_softc *sc, int sx, int sy, int dx, int dy, int w,
    626       1.12  macallan 		 int h, uint32_t rop)
    627       1.12  macallan {
    628       1.12  macallan 	wcfb_rop_wait(sc);
    629       1.12  macallan 	wcfb_rop_jfb(sc, sx, sy, dx, dy, w, h, rop, 0xff);
    630       1.12  macallan }
    631       1.12  macallan 
    632       1.12  macallan static void
    633       1.12  macallan wcfb_rectfill(struct wcfb_softc *sc, int x, int y, int w, int h, int bg)
    634       1.12  macallan {
    635       1.12  macallan 	int32_t mask;
    636       1.12  macallan 
    637       1.12  macallan 	/* pixels to set... */
    638       1.12  macallan 	mask = 0xff & bg;
    639       1.12  macallan 	if (mask != 0) {
    640       1.12  macallan 		wcfb_rop_wait(sc);
    641       1.12  macallan 		wcfb_rop_jfb(sc, x, y, x, y, w, h, WC_ROP_SET, mask);
    642       1.12  macallan 	}
    643       1.12  macallan 
    644       1.12  macallan 	/* pixels to clear... */
    645       1.12  macallan 	mask = 0xff & ~bg;
    646       1.12  macallan 	if (mask != 0) {
    647       1.12  macallan 		wcfb_rop_wait(sc);
    648       1.12  macallan 		wcfb_rop_jfb(sc, x, y, x, y, w, h, WC_ROP_CLEAR, mask);
    649       1.12  macallan 	}
    650       1.12  macallan }
    651       1.12  macallan 
    652       1.12  macallan void
    653       1.12  macallan wcfb_rop_common(struct wcfb_softc *sc, bus_addr_t reg, int sx, int sy,
    654       1.12  macallan     int dx, int dy, int w, int h, uint32_t rop, int32_t planemask)
    655       1.12  macallan {
    656       1.12  macallan 	int dir = 0;
    657       1.12  macallan 
    658       1.12  macallan 	/*
    659       1.12  macallan 	 * Compute rop direction. This only really matters for
    660       1.12  macallan 	 * screen-to-screen copies.
    661       1.12  macallan 	 */
    662       1.12  macallan 	if (sy < dy /* && sy + h > dy */) {
    663       1.12  macallan 		sy += h - 1;
    664       1.12  macallan 		dy += h;
    665       1.12  macallan 		dir |= WC_BLT_DIR_BACKWARDS_Y;
    666       1.12  macallan 	}
    667       1.12  macallan 	if (sx < dx /* && sx + w > dx */) {
    668       1.12  macallan 		sx += w - 1;
    669       1.12  macallan 		dx += w;
    670       1.12  macallan 		dir |= WC_BLT_DIR_BACKWARDS_X;
    671       1.12  macallan 	}
    672       1.12  macallan 
    673       1.12  macallan 	/* Which one of those below is your magic number for today? */
    674       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x61000001);
    675       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0);
    676       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x6301c080);
    677       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x80000000);
    678       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, rop);
    679       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, planemask);
    680       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0);
    681       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x64000303);
    682       1.12  macallan 	/*
    683       1.12  macallan 	 * This value is a pixel offset within the destination area. It is
    684       1.12  macallan 	 * probably used to define complex polygon shapes, with the
    685       1.12  macallan 	 * last pixel in the list being back to (0,0).
    686       1.12  macallan 	 */
    687       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, WCFB_COORDS(0, 0));
    688       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0);
    689       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x00030000);
    690       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x2200010d);
    691       1.12  macallan 
    692       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x33f01000 | dir);
    693       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, WCFB_COORDS(dx, dy));
    694       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, WCFB_COORDS(w, h));
    695       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, WCFB_COORDS(sx, sy));
    696       1.12  macallan }
    697       1.12  macallan 
    698       1.12  macallan 
    699       1.12  macallan static void
    700       1.12  macallan wcfb_rop_jfb(struct wcfb_softc *sc, int sx, int sy, int dx, int dy,
    701       1.12  macallan              int w, int h, uint32_t rop, int32_t planemask)
    702       1.12  macallan {
    703       1.12  macallan 	bus_addr_t reg = WC_JFB_ENGINE;
    704       1.12  macallan 	uint32_t spr, splr;
    705       1.12  macallan 
    706       1.12  macallan #if 0
    707       1.12  macallan 	/*
    708       1.12  macallan 	 * Pick the current spr and splr values from the communication
    709       1.12  macallan 	 * area if possible.
    710       1.12  macallan 	 */
    711       1.12  macallan 	if (sc->sc_comm != NULL) {
    712       1.12  macallan 		spr = sc->sc_comm[IFB_SHARED_TERM8_SPR >> 2];
    713       1.12  macallan 		splr = sc->sc_comm[IFB_SHARED_TERM8_SPLR >> 2];
    714  1.12.14.2     skrll 	} else
    715       1.12  macallan #endif
    716       1.12  macallan 	{
    717       1.12  macallan 		/* supposedly sane defaults */
    718       1.12  macallan 		spr = 0x54ff0303;
    719       1.12  macallan 		splr = 0x5c0000ff;
    720       1.12  macallan 	}
    721       1.12  macallan 
    722       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x00400016);
    723       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x5b000002);
    724       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x5a000000);
    725       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, spr);
    726       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, splr);
    727       1.12  macallan 
    728       1.12  macallan 	wcfb_rop_common(sc, reg, sx, sy, dx, dy, w, h, rop, planemask);
    729       1.12  macallan 
    730       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x5a000001);
    731       1.12  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x5b000001);
    732       1.12  macallan }
    733       1.12  macallan 
    734       1.12  macallan static int
    735       1.12  macallan wcfb_rop_wait(struct wcfb_softc *sc)
    736       1.12  macallan {
    737       1.12  macallan 	int i;
    738       1.12  macallan 
    739       1.12  macallan 	for (i = 1000000; i != 0; i--) {
    740       1.12  macallan 		if (bus_space_read_4(sc->sc_regt, sc->sc_regh,
    741       1.12  macallan 		    WC_STATUS) & WC_STATUS_DONE)
    742       1.12  macallan 			break;
    743       1.12  macallan 		delay(1);
    744       1.12  macallan 	}
    745       1.12  macallan 
    746       1.12  macallan 	return i;
    747       1.12  macallan }
    748       1.12  macallan 
    749       1.12  macallan static void
    750       1.12  macallan wcfb_acc_putchar(void *cookie, int row, int col, u_int c, long attr)
    751       1.12  macallan {
    752       1.12  macallan 	struct rasops_info *ri = cookie;
    753       1.12  macallan 	struct vcons_screen *scr = ri->ri_hw;
    754       1.12  macallan 	struct wcfb_softc *sc = scr->scr_cookie;
    755       1.12  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, c);
    756       1.12  macallan 	int x, y, wi, he;
    757       1.12  macallan 	uint32_t bg;
    758       1.12  macallan 
    759       1.12  macallan 	wi = font->fontwidth;
    760       1.12  macallan 	he = font->fontheight;
    761       1.12  macallan 	x = ri->ri_xorigin + col * wi;
    762       1.12  macallan 	y = ri->ri_yorigin + row * he;
    763       1.12  macallan 	bg = ri->ri_devcmap[(attr >> 16) & 0xf];
    764       1.12  macallan 	if (c == 0x20) {
    765       1.12  macallan 		wcfb_rectfill(sc, x, y, wi, he, bg);
    766       1.12  macallan 		return;
    767       1.12  macallan 	}
    768       1.12  macallan 	/* we wait until the blitter is idle... */
    769       1.12  macallan 	wcfb_rop_wait(sc);
    770       1.12  macallan 	/* ... draw the character into buffer 0 ... */
    771       1.12  macallan 	sc->putchar(ri, row, col, c, attr);
    772       1.12  macallan 	/* ... and then blit it into buffer 1 */
    773       1.12  macallan 	wcfb_bitblt(sc, x, y, x, y, wi, he, WC_ROP_COPY);
    774  1.12.14.2     skrll }
    775       1.12  macallan 
    776       1.12  macallan static void
    777       1.12  macallan wcfb_acc_cursor(void *cookie, int on, int row, int col)
    778       1.12  macallan {
    779       1.12  macallan 	struct rasops_info *ri = cookie;
    780       1.12  macallan 	struct vcons_screen *scr = ri->ri_hw;
    781       1.12  macallan 	struct wcfb_softc *sc = scr->scr_cookie;
    782       1.12  macallan 	int x, y, wi, he;
    783  1.12.14.2     skrll 
    784       1.12  macallan 	wi = ri->ri_font->fontwidth;
    785       1.12  macallan 	he = ri->ri_font->fontheight;
    786  1.12.14.2     skrll 
    787       1.12  macallan 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    788       1.12  macallan 		x = ri->ri_ccol * wi + ri->ri_xorigin;
    789       1.12  macallan 		y = ri->ri_crow * he + ri->ri_yorigin;
    790       1.12  macallan 		if (ri->ri_flg & RI_CURSOR) {
    791       1.12  macallan 			wcfb_bitblt(sc, x, y, x, y, wi, he, WC_ROP_XOR);
    792       1.12  macallan 			ri->ri_flg &= ~RI_CURSOR;
    793       1.12  macallan 		}
    794       1.12  macallan 		ri->ri_crow = row;
    795       1.12  macallan 		ri->ri_ccol = col;
    796       1.12  macallan 		if (on) {
    797       1.12  macallan 			x = ri->ri_ccol * wi + ri->ri_xorigin;
    798       1.12  macallan 			y = ri->ri_crow * he + ri->ri_yorigin;
    799       1.12  macallan 			wcfb_bitblt(sc, x, y, x, y, wi, he, WC_ROP_XOR);
    800       1.12  macallan 			ri->ri_flg |= RI_CURSOR;
    801       1.12  macallan 		}
    802       1.12  macallan 	} else {
    803       1.12  macallan 		scr->scr_ri.ri_crow = row;
    804       1.12  macallan 		scr->scr_ri.ri_ccol = col;
    805       1.12  macallan 		scr->scr_ri.ri_flg &= ~RI_CURSOR;
    806       1.12  macallan 	}
    807       1.12  macallan 
    808       1.12  macallan }
    809       1.12  macallan 
    810       1.12  macallan static void
    811       1.12  macallan wcfb_acc_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
    812       1.12  macallan {
    813       1.12  macallan 	struct rasops_info *ri = cookie;
    814       1.12  macallan 	struct vcons_screen *scr = ri->ri_hw;
    815       1.12  macallan 	struct wcfb_softc *sc = scr->scr_cookie;
    816       1.12  macallan 	int32_t xs, xd, y, width, height;
    817  1.12.14.2     skrll 
    818       1.12  macallan 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    819       1.12  macallan 		xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
    820       1.12  macallan 		xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
    821       1.12  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    822       1.12  macallan 		width = ri->ri_font->fontwidth * ncols;
    823       1.12  macallan 		height = ri->ri_font->fontheight;
    824       1.12  macallan 		wcfb_bitblt(sc, xs, y, xd, y, width, height, WC_ROP_COPY);
    825       1.12  macallan 	}
    826       1.12  macallan }
    827       1.12  macallan 
    828       1.12  macallan static void
    829       1.12  macallan wcfb_acc_erasecols(void *cookie, int row, int startcol, int ncols,
    830       1.12  macallan 		long fillattr)
    831       1.12  macallan {
    832       1.12  macallan 	struct rasops_info *ri = cookie;
    833       1.12  macallan 	struct vcons_screen *scr = ri->ri_hw;
    834       1.12  macallan 	struct wcfb_softc *sc = scr->scr_cookie;
    835       1.12  macallan 	int32_t x, y, width, height, fg, bg, ul;
    836  1.12.14.2     skrll 
    837       1.12  macallan 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    838       1.12  macallan 		x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
    839       1.12  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    840       1.12  macallan 		width = ri->ri_font->fontwidth * ncols;
    841       1.12  macallan 		height = ri->ri_font->fontheight;
    842       1.12  macallan 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
    843       1.12  macallan 
    844       1.12  macallan 		wcfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
    845       1.12  macallan 	}
    846       1.12  macallan }
    847       1.12  macallan 
    848       1.12  macallan static void
    849       1.12  macallan wcfb_acc_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
    850       1.12  macallan {
    851       1.12  macallan 	struct rasops_info *ri = cookie;
    852       1.12  macallan 	struct vcons_screen *scr = ri->ri_hw;
    853       1.12  macallan 	struct wcfb_softc *sc = scr->scr_cookie;
    854       1.12  macallan 	int32_t x, ys, yd, width, height;
    855       1.12  macallan 
    856       1.12  macallan 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    857       1.12  macallan 		x = ri->ri_xorigin;
    858       1.12  macallan 		ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
    859       1.12  macallan 		yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
    860       1.12  macallan 		width = ri->ri_emuwidth;
    861       1.12  macallan 		height = ri->ri_font->fontheight * nrows;
    862       1.12  macallan 		wcfb_bitblt(sc, x, ys, x, yd, width, height, WC_ROP_COPY);
    863       1.12  macallan 	}
    864       1.12  macallan }
    865       1.12  macallan 
    866       1.12  macallan static void
    867       1.12  macallan wcfb_acc_eraserows(void *cookie, int row, int nrows, long fillattr)
    868       1.12  macallan {
    869       1.12  macallan 	struct rasops_info *ri = cookie;
    870       1.12  macallan 	struct vcons_screen *scr = ri->ri_hw;
    871       1.12  macallan 	struct wcfb_softc *sc = scr->scr_cookie;
    872       1.12  macallan 	int32_t x, y, width, height, fg, bg, ul;
    873  1.12.14.2     skrll 
    874       1.12  macallan 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    875       1.12  macallan 		x = ri->ri_xorigin;
    876       1.12  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    877       1.12  macallan 		width = ri->ri_emuwidth;
    878       1.12  macallan 		height = ri->ri_font->fontheight * nrows;
    879       1.12  macallan 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
    880       1.12  macallan 
    881       1.12  macallan 		wcfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
    882       1.12  macallan 	}
    883       1.12  macallan }
    884