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