Home | History | Annotate | Line # | Download | only in pci
r128fb.c revision 1.6
      1  1.6  jmcneill /*	$NetBSD: r128fb.c,v 1.6 2008/08/25 23:09:23 jmcneill Exp $	*/
      2  1.1  macallan 
      3  1.1  macallan /*
      4  1.1  macallan  * Copyright (c) 2007 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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1  macallan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.1  macallan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.1  macallan  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.1  macallan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  1.1  macallan  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  1.1  macallan  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  1.1  macallan  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  1.1  macallan  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  1.1  macallan  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  1.1  macallan  */
     27  1.1  macallan 
     28  1.1  macallan /*
     29  1.1  macallan  * A console driver for ATI Rage 128 graphics controllers
     30  1.1  macallan  * tested on macppc only so far
     31  1.1  macallan  */
     32  1.1  macallan 
     33  1.1  macallan #include <sys/cdefs.h>
     34  1.6  jmcneill __KERNEL_RCSID(0, "$NetBSD: r128fb.c,v 1.6 2008/08/25 23:09:23 jmcneill Exp $");
     35  1.1  macallan 
     36  1.1  macallan #include <sys/param.h>
     37  1.1  macallan #include <sys/systm.h>
     38  1.1  macallan #include <sys/kernel.h>
     39  1.1  macallan #include <sys/device.h>
     40  1.1  macallan #include <sys/malloc.h>
     41  1.1  macallan #include <sys/lwp.h>
     42  1.1  macallan #include <sys/kauth.h>
     43  1.1  macallan 
     44  1.1  macallan #include <uvm/uvm_extern.h>
     45  1.1  macallan 
     46  1.1  macallan #include <dev/videomode/videomode.h>
     47  1.1  macallan 
     48  1.1  macallan #include <dev/pci/pcivar.h>
     49  1.1  macallan #include <dev/pci/pcireg.h>
     50  1.1  macallan #include <dev/pci/pcidevs.h>
     51  1.1  macallan #include <dev/pci/pciio.h>
     52  1.1  macallan #include <dev/pci/r128fbreg.h>
     53  1.1  macallan 
     54  1.1  macallan #include <dev/wscons/wsdisplayvar.h>
     55  1.1  macallan #include <dev/wscons/wsconsio.h>
     56  1.1  macallan #include <dev/wsfont/wsfont.h>
     57  1.1  macallan #include <dev/rasops/rasops.h>
     58  1.1  macallan #include <dev/wscons/wsdisplay_vconsvar.h>
     59  1.1  macallan 
     60  1.1  macallan #include <dev/i2c/i2cvar.h>
     61  1.1  macallan 
     62  1.1  macallan struct r128fb_softc {
     63  1.1  macallan 	device_t sc_dev;
     64  1.1  macallan 
     65  1.1  macallan 	pci_chipset_tag_t sc_pc;
     66  1.1  macallan 	pcitag_t sc_pcitag;
     67  1.1  macallan 
     68  1.1  macallan 	bus_space_tag_t sc_memt;
     69  1.1  macallan 	bus_space_tag_t sc_iot;
     70  1.1  macallan 
     71  1.1  macallan 	bus_space_handle_t sc_fbh;
     72  1.1  macallan 	bus_space_handle_t sc_regh;
     73  1.1  macallan 	bus_addr_t sc_fb, sc_reg;
     74  1.1  macallan 	bus_size_t sc_fbsize, sc_regsize;
     75  1.1  macallan 
     76  1.1  macallan 	int sc_width, sc_height, sc_depth, sc_stride;
     77  1.1  macallan 	int sc_locked;
     78  1.1  macallan 	void *sc_fbaddr;
     79  1.1  macallan 	struct vcons_screen sc_console_screen;
     80  1.1  macallan 	struct wsscreen_descr sc_defaultscreen_descr;
     81  1.1  macallan 	const struct wsscreen_descr *sc_screens[1];
     82  1.1  macallan 	struct wsscreen_list sc_screenlist;
     83  1.1  macallan 	struct vcons_data vd;
     84  1.1  macallan 	int sc_mode;
     85  1.1  macallan 	u_char sc_cmap_red[256];
     86  1.1  macallan 	u_char sc_cmap_green[256];
     87  1.1  macallan 	u_char sc_cmap_blue[256];
     88  1.1  macallan 	/* engine stuff */
     89  1.1  macallan 	uint32_t sc_master_cntl;
     90  1.1  macallan };
     91  1.1  macallan 
     92  1.1  macallan static int	r128fb_match(device_t, cfdata_t, void *);
     93  1.1  macallan static void	r128fb_attach(device_t, device_t, void *);
     94  1.1  macallan 
     95  1.1  macallan CFATTACH_DECL_NEW(r128fb, sizeof(struct r128fb_softc),
     96  1.1  macallan     r128fb_match, r128fb_attach, NULL, NULL);
     97  1.1  macallan 
     98  1.1  macallan extern const u_char rasops_cmap[768];
     99  1.1  macallan 
    100  1.1  macallan static int	r128fb_ioctl(void *, void *, u_long, void *, int,
    101  1.1  macallan 			     struct lwp *);
    102  1.1  macallan static paddr_t	r128fb_mmap(void *, void *, off_t, int);
    103  1.1  macallan static void	r128fb_init_screen(void *, struct vcons_screen *, int, long *);
    104  1.1  macallan 
    105  1.1  macallan static int	r128fb_putcmap(struct r128fb_softc *, struct wsdisplay_cmap *);
    106  1.1  macallan static int 	r128fb_getcmap(struct r128fb_softc *, struct wsdisplay_cmap *);
    107  1.1  macallan static void	r128fb_restore_palette(struct r128fb_softc *);
    108  1.1  macallan static int 	r128fb_putpalreg(struct r128fb_softc *, uint8_t, uint8_t,
    109  1.1  macallan 			    uint8_t, uint8_t);
    110  1.1  macallan 
    111  1.1  macallan static void	r128fb_init(struct r128fb_softc *);
    112  1.1  macallan static void	r128fb_flush_engine(struct r128fb_softc *);
    113  1.1  macallan static void	r128fb_rectfill(struct r128fb_softc *, int, int, int, int,
    114  1.1  macallan 			    uint32_t);
    115  1.1  macallan static void	r128fb_bitblt(struct r128fb_softc *, int, int, int, int, int,
    116  1.1  macallan 			    int, int);
    117  1.1  macallan 
    118  1.1  macallan static void	r128fb_cursor(void *, int, int, int);
    119  1.1  macallan #if 0
    120  1.1  macallan static void	r128fb_putchar(void *, int, int, u_int, long);
    121  1.1  macallan #endif
    122  1.1  macallan static void	r128fb_copycols(void *, int, int, int, int);
    123  1.1  macallan static void	r128fb_erasecols(void *, int, int, int, long);
    124  1.1  macallan static void	r128fb_copyrows(void *, int, int, int);
    125  1.1  macallan static void	r128fb_eraserows(void *, int, int, long);
    126  1.1  macallan 
    127  1.1  macallan struct wsdisplay_accessops r128fb_accessops = {
    128  1.1  macallan 	r128fb_ioctl,
    129  1.1  macallan 	r128fb_mmap,
    130  1.1  macallan 	NULL,	/* alloc_screen */
    131  1.1  macallan 	NULL,	/* free_screen */
    132  1.1  macallan 	NULL,	/* show_screen */
    133  1.1  macallan 	NULL, 	/* load_font */
    134  1.1  macallan 	NULL,	/* pollc */
    135  1.1  macallan 	NULL	/* scroll */
    136  1.1  macallan };
    137  1.1  macallan 
    138  1.1  macallan static inline void
    139  1.1  macallan r128fb_wait(struct r128fb_softc *sc, int slots)
    140  1.1  macallan {
    141  1.1  macallan 	uint32_t reg;
    142  1.1  macallan 
    143  1.1  macallan 	do {
    144  1.1  macallan 		reg = (bus_space_read_4(sc->sc_memt, sc->sc_regh,
    145  1.1  macallan 		    R128_GUI_STAT) & R128_GUI_FIFOCNT_MASK);
    146  1.1  macallan 	} while (reg <= slots);
    147  1.1  macallan }
    148  1.1  macallan 
    149  1.1  macallan static void
    150  1.1  macallan r128fb_flush_engine(struct r128fb_softc *sc)
    151  1.1  macallan {
    152  1.1  macallan 	uint32_t reg;
    153  1.1  macallan 
    154  1.1  macallan 	reg = bus_space_read_4(sc->sc_memt, sc->sc_regh, R128_PC_NGUI_CTLSTAT);
    155  1.1  macallan 	reg |= R128_PC_FLUSH_ALL;
    156  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_PC_NGUI_CTLSTAT, reg);
    157  1.1  macallan 	do {
    158  1.1  macallan 		reg = bus_space_read_4(sc->sc_memt, sc->sc_regh,
    159  1.1  macallan 		    R128_PC_NGUI_CTLSTAT);
    160  1.1  macallan 	} while (reg & R128_PC_BUSY);
    161  1.1  macallan }
    162  1.1  macallan 
    163  1.1  macallan static int
    164  1.1  macallan r128fb_match(device_t parent, cfdata_t match, void *aux)
    165  1.1  macallan {
    166  1.1  macallan 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
    167  1.1  macallan 
    168  1.5  macallan 	if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY)
    169  1.1  macallan 		return 0;
    170  1.1  macallan 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_ATI)
    171  1.1  macallan 		return 0;
    172  1.1  macallan 
    173  1.5  macallan 	/* only cards tested on so far - likely need a list */
    174  1.5  macallan 	if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ATI_RAGE1AGP4XT) ||
    175  1.6  jmcneill 	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ATI_RAGE3AGP4XT) ||
    176  1.6  jmcneill 	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ATI_RAGE_MOB_M3_AGP))
    177  1.1  macallan 		return 100;
    178  1.1  macallan 	return (0);
    179  1.1  macallan }
    180  1.1  macallan 
    181  1.1  macallan static void
    182  1.1  macallan r128fb_attach(device_t parent, device_t self, void *aux)
    183  1.1  macallan {
    184  1.1  macallan 	struct r128fb_softc	*sc = device_private(self);
    185  1.1  macallan 	struct pci_attach_args	*pa = aux;
    186  1.1  macallan 	struct rasops_info	*ri;
    187  1.1  macallan 	char devinfo[256];
    188  1.1  macallan 	struct wsemuldisplaydev_attach_args aa;
    189  1.1  macallan 	prop_dictionary_t	dict;
    190  1.1  macallan 	unsigned long		defattr;
    191  1.1  macallan 	bool			is_console;
    192  1.1  macallan 	int i, j;
    193  1.1  macallan 
    194  1.1  macallan 	sc->sc_pc = pa->pa_pc;
    195  1.1  macallan 	sc->sc_pcitag = pa->pa_tag;
    196  1.1  macallan 	sc->sc_memt = pa->pa_memt;
    197  1.1  macallan 	sc->sc_iot = pa->pa_iot;
    198  1.1  macallan 	sc->sc_dev = self;
    199  1.1  macallan 
    200  1.1  macallan 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    201  1.1  macallan 	aprint_normal(": %s\n", devinfo);
    202  1.1  macallan 
    203  1.1  macallan 	/* fill in parameters from properties */
    204  1.1  macallan 	dict = device_properties(self);
    205  1.1  macallan 	if (!prop_dictionary_get_uint32(dict, "width", &sc->sc_width)) {
    206  1.1  macallan 		aprint_error("%s: no width property\n", device_xname(self));
    207  1.1  macallan 		return;
    208  1.1  macallan 	}
    209  1.1  macallan 	if (!prop_dictionary_get_uint32(dict, "height", &sc->sc_height)) {
    210  1.1  macallan 		aprint_error("%s: no height property\n", device_xname(self));
    211  1.1  macallan 		return;
    212  1.1  macallan 	}
    213  1.1  macallan 	if (!prop_dictionary_get_uint32(dict, "depth", &sc->sc_depth)) {
    214  1.1  macallan 		aprint_error("%s: no depth property\n", device_xname(self));
    215  1.1  macallan 		return;
    216  1.1  macallan 	}
    217  1.1  macallan 	if (!prop_dictionary_get_uint32(dict, "linebytes", &sc->sc_stride)) {
    218  1.1  macallan 		aprint_error("%s: no linebytes property\n",
    219  1.1  macallan 		    device_xname(self));
    220  1.1  macallan 		return;
    221  1.1  macallan 	}
    222  1.1  macallan 
    223  1.1  macallan 	prop_dictionary_get_bool(dict, "is_console", &is_console);
    224  1.1  macallan 
    225  1.1  macallan 	if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM,
    226  1.1  macallan 	    BUS_SPACE_MAP_LINEAR,
    227  1.1  macallan 	    &sc->sc_memt, &sc->sc_fbh, &sc->sc_fb, &sc->sc_fbsize)) {
    228  1.1  macallan 		aprint_error("%s: failed to map the frame buffer.\n",
    229  1.1  macallan 		    device_xname(sc->sc_dev));
    230  1.1  macallan 	}
    231  1.1  macallan 	sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
    232  1.1  macallan 
    233  1.1  macallan 	if (pci_mapreg_map(pa, 0x18, PCI_MAPREG_TYPE_MEM, 0,
    234  1.1  macallan 	    &sc->sc_memt, &sc->sc_regh, &sc->sc_reg, &sc->sc_regsize)) {
    235  1.1  macallan 		aprint_error("%s: failed to map registers.\n",
    236  1.1  macallan 		    device_xname(sc->sc_dev));
    237  1.1  macallan 	}
    238  1.1  macallan 
    239  1.2  macallan 	/*
    240  1.2  macallan 	 * XXX yeah, casting the fb address to uint32_t is formally wrong
    241  1.2  macallan 	 * but as far as I know there are no mach64 with 64bit BARs
    242  1.2  macallan 	 */
    243  1.1  macallan 	aprint_normal("%s: %d MB aperture at 0x%08x\n", device_xname(self),
    244  1.2  macallan 	    (int)(sc->sc_fbsize >> 20), (uint32_t)sc->sc_fb);
    245  1.1  macallan 
    246  1.1  macallan 	sc->sc_defaultscreen_descr = (struct wsscreen_descr){
    247  1.1  macallan 		"default",
    248  1.1  macallan 		0, 0,
    249  1.1  macallan 		NULL,
    250  1.1  macallan 		8, 16,
    251  1.1  macallan 		WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    252  1.1  macallan 		NULL
    253  1.1  macallan 	};
    254  1.1  macallan 	sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
    255  1.1  macallan 	sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
    256  1.1  macallan 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    257  1.1  macallan 	sc->sc_locked = 0;
    258  1.1  macallan 
    259  1.1  macallan 	vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
    260  1.1  macallan 	    &r128fb_accessops);
    261  1.1  macallan 	sc->vd.init_screen = r128fb_init_screen;
    262  1.1  macallan 
    263  1.1  macallan 	/* init engine here */
    264  1.1  macallan 	r128fb_init(sc);
    265  1.1  macallan 
    266  1.1  macallan 	ri = &sc->sc_console_screen.scr_ri;
    267  1.1  macallan 
    268  1.1  macallan 	if (is_console) {
    269  1.1  macallan 		vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
    270  1.1  macallan 		    &defattr);
    271  1.1  macallan 		sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    272  1.1  macallan 
    273  1.1  macallan 		sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
    274  1.1  macallan 		sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
    275  1.1  macallan 		sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
    276  1.1  macallan 		sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
    277  1.1  macallan 		wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
    278  1.1  macallan 		    defattr);
    279  1.1  macallan 	} else {
    280  1.1  macallan 		/*
    281  1.1  macallan 		 * since we're not the console we can postpone the rest
    282  1.1  macallan 		 * until someone actually allocates a screen for us
    283  1.1  macallan 		 */
    284  1.1  macallan 		(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    285  1.1  macallan 	}
    286  1.1  macallan 
    287  1.1  macallan 	j = 0;
    288  1.1  macallan 	for (i = 0; i < (1 << sc->sc_depth); i++) {
    289  1.1  macallan 
    290  1.1  macallan 		sc->sc_cmap_red[i] = rasops_cmap[j];
    291  1.1  macallan 		sc->sc_cmap_green[i] = rasops_cmap[j + 1];
    292  1.1  macallan 		sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
    293  1.1  macallan 		r128fb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
    294  1.1  macallan 		    rasops_cmap[j + 2]);
    295  1.1  macallan 		j += 3;
    296  1.1  macallan 	}
    297  1.1  macallan 
    298  1.1  macallan 	r128fb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
    299  1.1  macallan 	    ri->ri_devcmap[(defattr >> 16) & 0xff]);
    300  1.1  macallan 
    301  1.1  macallan 	aa.console = is_console;
    302  1.1  macallan 	aa.scrdata = &sc->sc_screenlist;
    303  1.1  macallan 	aa.accessops = &r128fb_accessops;
    304  1.1  macallan 	aa.accesscookie = &sc->vd;
    305  1.1  macallan 
    306  1.1  macallan 	config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
    307  1.1  macallan 
    308  1.1  macallan }
    309  1.1  macallan 
    310  1.1  macallan static int
    311  1.1  macallan r128fb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    312  1.1  macallan 	struct lwp *l)
    313  1.1  macallan {
    314  1.1  macallan 	struct vcons_data *vd = v;
    315  1.1  macallan 	struct r128fb_softc *sc = vd->cookie;
    316  1.1  macallan 	struct wsdisplay_fbinfo *wdf;
    317  1.1  macallan 	struct vcons_screen *ms = vd->active;
    318  1.1  macallan 
    319  1.1  macallan 	switch (cmd) {
    320  1.1  macallan 
    321  1.1  macallan 		case WSDISPLAYIO_GTYPE:
    322  1.1  macallan 			*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
    323  1.1  macallan 			return 0;
    324  1.1  macallan 
    325  1.1  macallan 		/* PCI config read/write passthrough. */
    326  1.1  macallan 		case PCI_IOC_CFGREAD:
    327  1.1  macallan 		case PCI_IOC_CFGWRITE:
    328  1.1  macallan 			return (pci_devioctl(sc->sc_pc, sc->sc_pcitag,
    329  1.1  macallan 			    cmd, data, flag, l));
    330  1.1  macallan 
    331  1.1  macallan 		case WSDISPLAYIO_GINFO:
    332  1.1  macallan 			if (ms == NULL)
    333  1.1  macallan 				return ENODEV;
    334  1.1  macallan 			wdf = (void *)data;
    335  1.1  macallan 			wdf->height = ms->scr_ri.ri_height;
    336  1.1  macallan 			wdf->width = ms->scr_ri.ri_width;
    337  1.1  macallan 			wdf->depth = ms->scr_ri.ri_depth;
    338  1.1  macallan 			wdf->cmsize = 256;
    339  1.1  macallan 			return 0;
    340  1.1  macallan 
    341  1.1  macallan 		case WSDISPLAYIO_GETCMAP:
    342  1.1  macallan 			return r128fb_getcmap(sc,
    343  1.1  macallan 			    (struct wsdisplay_cmap *)data);
    344  1.1  macallan 
    345  1.1  macallan 		case WSDISPLAYIO_PUTCMAP:
    346  1.1  macallan 			return r128fb_putcmap(sc,
    347  1.1  macallan 			    (struct wsdisplay_cmap *)data);
    348  1.1  macallan 
    349  1.1  macallan 		case WSDISPLAYIO_LINEBYTES:
    350  1.1  macallan 			*(u_int *)data = sc->sc_stride;
    351  1.1  macallan 			return 0;
    352  1.1  macallan 
    353  1.1  macallan 		case WSDISPLAYIO_SMODE:
    354  1.1  macallan 			{
    355  1.1  macallan 				int new_mode = *(int*)data;
    356  1.1  macallan 
    357  1.1  macallan 				/* notify the bus backend */
    358  1.1  macallan 				if (new_mode != sc->sc_mode) {
    359  1.1  macallan 					sc->sc_mode = new_mode;
    360  1.1  macallan 					if(new_mode == WSDISPLAYIO_MODE_EMUL) {
    361  1.1  macallan 						r128fb_restore_palette(sc);
    362  1.1  macallan 						vcons_redraw_screen(ms);
    363  1.1  macallan 					}
    364  1.1  macallan 				}
    365  1.1  macallan 			}
    366  1.1  macallan 			return 0;
    367  1.1  macallan 	}
    368  1.1  macallan 	return EPASSTHROUGH;
    369  1.1  macallan }
    370  1.1  macallan 
    371  1.1  macallan static paddr_t
    372  1.1  macallan r128fb_mmap(void *v, void *vs, off_t offset, int prot)
    373  1.1  macallan {
    374  1.1  macallan 	struct vcons_data *vd = v;
    375  1.1  macallan 	struct r128fb_softc *sc = vd->cookie;
    376  1.1  macallan 	struct lwp *me;
    377  1.1  macallan 	paddr_t pa;
    378  1.1  macallan 
    379  1.1  macallan 	/* 'regular' framebuffer mmap()ing */
    380  1.1  macallan 	if (offset < sc->sc_fbsize) {
    381  1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, sc->sc_fb + offset, 0, prot,
    382  1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
    383  1.1  macallan 		return pa;
    384  1.1  macallan 	}
    385  1.1  macallan 
    386  1.1  macallan 	/*
    387  1.1  macallan 	 * restrict all other mappings to processes with superuser privileges
    388  1.1  macallan 	 * or the kernel itself
    389  1.1  macallan 	 */
    390  1.1  macallan 	me = curlwp;
    391  1.1  macallan 	if (me != NULL) {
    392  1.1  macallan 		if (kauth_authorize_generic(me->l_cred, KAUTH_GENERIC_ISSUSER,
    393  1.1  macallan 		    NULL) != 0) {
    394  1.1  macallan 			aprint_normal("%s: mmap() rejected.\n",
    395  1.1  macallan 			    device_xname(sc->sc_dev));
    396  1.1  macallan 			return -1;
    397  1.1  macallan 		}
    398  1.1  macallan 	}
    399  1.1  macallan 
    400  1.1  macallan 	if ((offset >= sc->sc_fb) && (offset < (sc->sc_fb + sc->sc_fbsize))) {
    401  1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
    402  1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
    403  1.1  macallan 		return pa;
    404  1.1  macallan 	}
    405  1.1  macallan 
    406  1.1  macallan 	if ((offset >= sc->sc_reg) &&
    407  1.1  macallan 	    (offset < (sc->sc_reg + sc->sc_regsize))) {
    408  1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
    409  1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
    410  1.1  macallan 		return pa;
    411  1.1  macallan 	}
    412  1.1  macallan 
    413  1.3  macallan #ifdef PCI_MAGIC_IO_RANGE
    414  1.1  macallan 	/* allow mapping of IO space */
    415  1.3  macallan 	if ((offset >= PCI_MAGIC_IO_RANGE) &&
    416  1.3  macallan 	    (offset < PCI_MAGIC_IO_RANGE + 0x10000)) {
    417  1.3  macallan 		pa = bus_space_mmap(sc->sc_iot, offset - PCI_MAGIC_IO_RANGE,
    418  1.3  macallan 		    0, prot, BUS_SPACE_MAP_LINEAR);
    419  1.1  macallan 		return pa;
    420  1.1  macallan 	}
    421  1.1  macallan #endif
    422  1.1  macallan 
    423  1.1  macallan #ifdef OFB_ALLOW_OTHERS
    424  1.1  macallan 	if (offset >= 0x80000000) {
    425  1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
    426  1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
    427  1.1  macallan 		return pa;
    428  1.1  macallan 	}
    429  1.1  macallan #endif
    430  1.1  macallan 	return -1;
    431  1.1  macallan }
    432  1.1  macallan 
    433  1.1  macallan static void
    434  1.1  macallan r128fb_init_screen(void *cookie, struct vcons_screen *scr,
    435  1.1  macallan     int existing, long *defattr)
    436  1.1  macallan {
    437  1.1  macallan 	struct r128fb_softc *sc = cookie;
    438  1.1  macallan 	struct rasops_info *ri = &scr->scr_ri;
    439  1.1  macallan 
    440  1.1  macallan 	ri->ri_depth = sc->sc_depth;
    441  1.1  macallan 	ri->ri_width = sc->sc_width;
    442  1.1  macallan 	ri->ri_height = sc->sc_height;
    443  1.1  macallan 	ri->ri_stride = sc->sc_stride;
    444  1.1  macallan 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
    445  1.1  macallan 
    446  1.1  macallan 	ri->ri_bits = (char *)sc->sc_fbaddr;
    447  1.1  macallan 
    448  1.1  macallan 	if (existing) {
    449  1.1  macallan 		ri->ri_flg |= RI_CLEAR;
    450  1.1  macallan 	}
    451  1.1  macallan 
    452  1.1  macallan 	rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
    453  1.1  macallan 	ri->ri_caps = WSSCREEN_WSCOLORS;
    454  1.1  macallan 
    455  1.1  macallan 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
    456  1.1  macallan 		    sc->sc_width / ri->ri_font->fontwidth);
    457  1.1  macallan 
    458  1.1  macallan 	ri->ri_hw = scr;
    459  1.1  macallan 	ri->ri_ops.copyrows = r128fb_copyrows;
    460  1.1  macallan 	ri->ri_ops.copycols = r128fb_copycols;
    461  1.1  macallan 	ri->ri_ops.eraserows = r128fb_eraserows;
    462  1.1  macallan 	ri->ri_ops.erasecols = r128fb_erasecols;
    463  1.1  macallan 	ri->ri_ops.cursor = r128fb_cursor;
    464  1.1  macallan #if 0
    465  1.1  macallan 	ri->ri_ops.putchar = r128fb_putchar;
    466  1.1  macallan #endif
    467  1.1  macallan }
    468  1.1  macallan 
    469  1.1  macallan static int
    470  1.1  macallan r128fb_putcmap(struct r128fb_softc *sc, struct wsdisplay_cmap *cm)
    471  1.1  macallan {
    472  1.1  macallan 	u_char *r, *g, *b;
    473  1.1  macallan 	u_int index = cm->index;
    474  1.1  macallan 	u_int count = cm->count;
    475  1.1  macallan 	int i, error;
    476  1.1  macallan 	u_char rbuf[256], gbuf[256], bbuf[256];
    477  1.1  macallan 
    478  1.1  macallan #ifdef R128FB_DEBUG
    479  1.1  macallan 	aprint_debug("putcmap: %d %d\n",index, count);
    480  1.1  macallan #endif
    481  1.1  macallan 	if (cm->index >= 256 || cm->count > 256 ||
    482  1.1  macallan 	    (cm->index + cm->count) > 256)
    483  1.1  macallan 		return EINVAL;
    484  1.1  macallan 	error = copyin(cm->red, &rbuf[index], count);
    485  1.1  macallan 	if (error)
    486  1.1  macallan 		return error;
    487  1.1  macallan 	error = copyin(cm->green, &gbuf[index], count);
    488  1.1  macallan 	if (error)
    489  1.1  macallan 		return error;
    490  1.1  macallan 	error = copyin(cm->blue, &bbuf[index], count);
    491  1.1  macallan 	if (error)
    492  1.1  macallan 		return error;
    493  1.1  macallan 
    494  1.1  macallan 	memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
    495  1.1  macallan 	memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
    496  1.1  macallan 	memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
    497  1.1  macallan 
    498  1.1  macallan 	r = &sc->sc_cmap_red[index];
    499  1.1  macallan 	g = &sc->sc_cmap_green[index];
    500  1.1  macallan 	b = &sc->sc_cmap_blue[index];
    501  1.1  macallan 
    502  1.1  macallan 	for (i = 0; i < count; i++) {
    503  1.1  macallan 		r128fb_putpalreg(sc, index, *r, *g, *b);
    504  1.1  macallan 		index++;
    505  1.1  macallan 		r++, g++, b++;
    506  1.1  macallan 	}
    507  1.1  macallan 	return 0;
    508  1.1  macallan }
    509  1.1  macallan 
    510  1.1  macallan static int
    511  1.1  macallan r128fb_getcmap(struct r128fb_softc *sc, struct wsdisplay_cmap *cm)
    512  1.1  macallan {
    513  1.1  macallan 	u_int index = cm->index;
    514  1.1  macallan 	u_int count = cm->count;
    515  1.1  macallan 	int error;
    516  1.1  macallan 
    517  1.1  macallan 	if (index >= 255 || count > 256 || index + count > 256)
    518  1.1  macallan 		return EINVAL;
    519  1.1  macallan 
    520  1.1  macallan 	error = copyout(&sc->sc_cmap_red[index],   cm->red,   count);
    521  1.1  macallan 	if (error)
    522  1.1  macallan 		return error;
    523  1.1  macallan 	error = copyout(&sc->sc_cmap_green[index], cm->green, count);
    524  1.1  macallan 	if (error)
    525  1.1  macallan 		return error;
    526  1.1  macallan 	error = copyout(&sc->sc_cmap_blue[index],  cm->blue,  count);
    527  1.1  macallan 	if (error)
    528  1.1  macallan 		return error;
    529  1.1  macallan 
    530  1.1  macallan 	return 0;
    531  1.1  macallan }
    532  1.1  macallan 
    533  1.1  macallan static void
    534  1.1  macallan r128fb_restore_palette(struct r128fb_softc *sc)
    535  1.1  macallan {
    536  1.1  macallan 	int i;
    537  1.1  macallan 
    538  1.1  macallan 	for (i = 0; i < (1 << sc->sc_depth); i++) {
    539  1.1  macallan 		r128fb_putpalreg(sc, i, sc->sc_cmap_red[i],
    540  1.1  macallan 		    sc->sc_cmap_green[i], sc->sc_cmap_blue[i]);
    541  1.1  macallan 	}
    542  1.1  macallan }
    543  1.1  macallan 
    544  1.1  macallan static int
    545  1.1  macallan r128fb_putpalreg(struct r128fb_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
    546  1.1  macallan     uint8_t b)
    547  1.1  macallan {
    548  1.1  macallan 	uint32_t reg;
    549  1.1  macallan 
    550  1.1  macallan 	/* whack the DAC */
    551  1.1  macallan 	reg = (r << 16) | (g << 8) | b;
    552  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_PALETTE_INDEX, idx);
    553  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_PALETTE_DATA, reg);
    554  1.1  macallan 	return 0;
    555  1.1  macallan }
    556  1.1  macallan 
    557  1.1  macallan static void
    558  1.1  macallan r128fb_init(struct r128fb_softc *sc)
    559  1.1  macallan {
    560  1.1  macallan 	uint32_t datatype;
    561  1.1  macallan 
    562  1.1  macallan 	r128fb_flush_engine(sc);
    563  1.1  macallan 
    564  1.1  macallan 	r128fb_wait(sc, 8);
    565  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_CRTC_OFFSET, 0);
    566  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DEFAULT_OFFSET, 0);
    567  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DEFAULT_PITCH,
    568  1.1  macallan 	    sc->sc_stride >> 3);
    569  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_AUX_SC_CNTL, 0);
    570  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh,
    571  1.1  macallan 	    R128_DEFAULT_SC_BOTTOM_RIGHT,
    572  1.1  macallan 	    R128_DEFAULT_SC_RIGHT_MAX | R128_DEFAULT_SC_BOTTOM_MAX);
    573  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_SC_TOP_LEFT, 0);
    574  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_SC_BOTTOM_RIGHT,
    575  1.1  macallan 	    R128_DEFAULT_SC_RIGHT_MAX | R128_DEFAULT_SC_BOTTOM_MAX);
    576  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_DATATYPE,
    577  1.1  macallan 	    R128_HOST_BIG_ENDIAN_EN);
    578  1.1  macallan 
    579  1.1  macallan 	r128fb_wait(sc, 5);
    580  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_SRC_PITCH,
    581  1.1  macallan 	    sc->sc_stride >> 3);
    582  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_PITCH,
    583  1.1  macallan 	    sc->sc_stride >> 3);
    584  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_SRC_OFFSET, 0);
    585  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_OFFSET, 0);
    586  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_WRITE_MASK,
    587  1.1  macallan 	    0xffffffff);
    588  1.1  macallan 
    589  1.1  macallan 	switch (sc->sc_depth) {
    590  1.1  macallan 		case 8:
    591  1.1  macallan 			datatype = R128_GMC_DST_8BPP_CI;
    592  1.1  macallan 			break;
    593  1.1  macallan 		case 15:
    594  1.1  macallan 			datatype = R128_GMC_DST_15BPP;
    595  1.1  macallan 			break;
    596  1.1  macallan 		case 16:
    597  1.1  macallan 			datatype = R128_GMC_DST_16BPP;
    598  1.1  macallan 			break;
    599  1.1  macallan 		case 24:
    600  1.1  macallan 			datatype = R128_GMC_DST_24BPP;
    601  1.1  macallan 			break;
    602  1.1  macallan 		case 32:
    603  1.1  macallan 			datatype = R128_GMC_DST_32BPP;
    604  1.1  macallan 			break;
    605  1.1  macallan 		default:
    606  1.1  macallan 			aprint_error("%s: unsupported depth %d\n",
    607  1.1  macallan 			    device_xname(sc->sc_dev), sc->sc_depth);
    608  1.1  macallan 			return;
    609  1.1  macallan 	}
    610  1.1  macallan 	sc->sc_master_cntl = R128_GMC_CLR_CMP_CNTL_DIS |
    611  1.1  macallan 	    R128_GMC_AUX_CLIP_DIS | datatype;
    612  1.1  macallan 
    613  1.1  macallan 	r128fb_flush_engine(sc);
    614  1.1  macallan }
    615  1.1  macallan 
    616  1.1  macallan static void
    617  1.1  macallan r128fb_rectfill(struct r128fb_softc *sc, int x, int y, int wi, int he,
    618  1.1  macallan      uint32_t colour)
    619  1.1  macallan {
    620  1.1  macallan 
    621  1.1  macallan 	r128fb_wait(sc, 6);
    622  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_GUI_MASTER_CNTL,
    623  1.1  macallan 	    R128_GMC_BRUSH_SOLID_COLOR |
    624  1.1  macallan 	    R128_GMC_SRC_DATATYPE_COLOR |
    625  1.1  macallan 	    R128_ROP3_P |
    626  1.1  macallan 	    sc->sc_master_cntl);
    627  1.1  macallan 
    628  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_BRUSH_FRGD_CLR,
    629  1.1  macallan 	    colour);
    630  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_CNTL,
    631  1.1  macallan 	    R128_DST_X_LEFT_TO_RIGHT | R128_DST_Y_TOP_TO_BOTTOM);
    632  1.1  macallan 	/* now feed it coordinates */
    633  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_X_Y,
    634  1.1  macallan 	    (x << 16) | y);
    635  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_WIDTH_HEIGHT,
    636  1.1  macallan 	    (wi << 16) | he);
    637  1.1  macallan 	r128fb_flush_engine(sc);
    638  1.1  macallan }
    639  1.1  macallan 
    640  1.1  macallan static void
    641  1.1  macallan r128fb_bitblt(struct r128fb_softc *sc, int xs, int ys, int xd, int yd,
    642  1.1  macallan     int wi, int he, int rop)
    643  1.1  macallan {
    644  1.1  macallan 	uint32_t dp_cntl = 0;
    645  1.1  macallan 
    646  1.1  macallan 	r128fb_wait(sc, 5);
    647  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_GUI_MASTER_CNTL,
    648  1.1  macallan 	    R128_GMC_BRUSH_SOLID_COLOR |
    649  1.1  macallan 	    R128_GMC_SRC_DATATYPE_COLOR |
    650  1.1  macallan 	    rop |
    651  1.1  macallan 	    R128_DP_SRC_SOURCE_MEMORY |
    652  1.1  macallan 	    sc->sc_master_cntl);
    653  1.1  macallan 
    654  1.1  macallan 	if (yd <= ys) {
    655  1.1  macallan 		dp_cntl = R128_DST_Y_TOP_TO_BOTTOM;
    656  1.1  macallan 	} else {
    657  1.1  macallan 		ys += he - 1;
    658  1.1  macallan 		yd += he - 1;
    659  1.1  macallan 	}
    660  1.1  macallan 	if (xd <= xs) {
    661  1.1  macallan 		dp_cntl |= R128_DST_X_LEFT_TO_RIGHT;
    662  1.1  macallan 	} else {
    663  1.1  macallan 		xs += wi - 1;
    664  1.1  macallan 		xd += wi - 1;
    665  1.1  macallan 	}
    666  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_CNTL, dp_cntl);
    667  1.1  macallan 
    668  1.1  macallan 	/* now feed it coordinates */
    669  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_SRC_X_Y,
    670  1.1  macallan 	    (xs << 16) | ys);
    671  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_X_Y,
    672  1.1  macallan 	    (xd << 16) | yd);
    673  1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_WIDTH_HEIGHT,
    674  1.1  macallan 	    (wi << 16) | he);
    675  1.1  macallan 	r128fb_flush_engine(sc);
    676  1.1  macallan }
    677  1.1  macallan 
    678  1.1  macallan static void
    679  1.1  macallan r128fb_cursor(void *cookie, int on, int row, int col)
    680  1.1  macallan {
    681  1.1  macallan 	struct rasops_info *ri = cookie;
    682  1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    683  1.1  macallan 	struct r128fb_softc *sc = scr->scr_cookie;
    684  1.1  macallan 	int x, y, wi, he;
    685  1.1  macallan 
    686  1.1  macallan 	wi = ri->ri_font->fontwidth;
    687  1.1  macallan 	he = ri->ri_font->fontheight;
    688  1.1  macallan 
    689  1.1  macallan 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    690  1.1  macallan 		x = ri->ri_ccol * wi + ri->ri_xorigin;
    691  1.1  macallan 		y = ri->ri_crow * he + ri->ri_yorigin;
    692  1.1  macallan 		if (ri->ri_flg & RI_CURSOR) {
    693  1.1  macallan 			r128fb_bitblt(sc, x, y, x, y, wi, he, R128_ROP3_Dn);
    694  1.1  macallan 			ri->ri_flg &= ~RI_CURSOR;
    695  1.1  macallan 		}
    696  1.1  macallan 		ri->ri_crow = row;
    697  1.1  macallan 		ri->ri_ccol = col;
    698  1.1  macallan 		if (on) {
    699  1.1  macallan 			x = ri->ri_ccol * wi + ri->ri_xorigin;
    700  1.1  macallan 			y = ri->ri_crow * he + ri->ri_yorigin;
    701  1.1  macallan 			r128fb_bitblt(sc, x, y, x, y, wi, he, R128_ROP3_Dn);
    702  1.1  macallan 			ri->ri_flg |= RI_CURSOR;;
    703  1.1  macallan 		}
    704  1.1  macallan 	} else {
    705  1.1  macallan 		scr->scr_ri.ri_crow = row;
    706  1.1  macallan 		scr->scr_ri.ri_ccol = col;
    707  1.1  macallan 		scr->scr_ri.ri_flg &= ~RI_CURSOR;
    708  1.1  macallan 	}
    709  1.1  macallan 
    710  1.1  macallan }
    711  1.1  macallan 
    712  1.1  macallan #if 0
    713  1.1  macallan static void
    714  1.1  macallan r128fb_putchar(void *cookie, int row, int col, u_int c, long attr)
    715  1.1  macallan {
    716  1.1  macallan }
    717  1.1  macallan #endif
    718  1.1  macallan 
    719  1.1  macallan static void
    720  1.1  macallan r128fb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
    721  1.1  macallan {
    722  1.1  macallan 	struct rasops_info *ri = cookie;
    723  1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    724  1.1  macallan 	struct r128fb_softc *sc = scr->scr_cookie;
    725  1.1  macallan 	int32_t xs, xd, y, width, height;
    726  1.1  macallan 
    727  1.1  macallan 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    728  1.1  macallan 		xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
    729  1.1  macallan 		xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
    730  1.1  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    731  1.1  macallan 		width = ri->ri_font->fontwidth * ncols;
    732  1.1  macallan 		height = ri->ri_font->fontheight;
    733  1.1  macallan 		r128fb_bitblt(sc, xs, y, xd, y, width, height, R128_ROP3_S);
    734  1.1  macallan 	}
    735  1.1  macallan }
    736  1.1  macallan 
    737  1.1  macallan static void
    738  1.1  macallan r128fb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
    739  1.1  macallan {
    740  1.1  macallan 	struct rasops_info *ri = cookie;
    741  1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    742  1.1  macallan 	struct r128fb_softc *sc = scr->scr_cookie;
    743  1.1  macallan 	int32_t x, y, width, height, fg, bg, ul;
    744  1.1  macallan 
    745  1.1  macallan 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    746  1.1  macallan 		x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
    747  1.1  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    748  1.1  macallan 		width = ri->ri_font->fontwidth * ncols;
    749  1.1  macallan 		height = ri->ri_font->fontheight;
    750  1.1  macallan 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
    751  1.1  macallan 
    752  1.1  macallan 		r128fb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
    753  1.1  macallan 	}
    754  1.1  macallan }
    755  1.1  macallan 
    756  1.1  macallan static void
    757  1.1  macallan r128fb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
    758  1.1  macallan {
    759  1.1  macallan 	struct rasops_info *ri = cookie;
    760  1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    761  1.1  macallan 	struct r128fb_softc *sc = scr->scr_cookie;
    762  1.1  macallan 	int32_t x, ys, yd, width, height;
    763  1.1  macallan 
    764  1.1  macallan 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    765  1.1  macallan 		x = ri->ri_xorigin;
    766  1.1  macallan 		ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
    767  1.1  macallan 		yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
    768  1.1  macallan 		width = ri->ri_emuwidth;
    769  1.1  macallan 		height = ri->ri_font->fontheight*nrows;
    770  1.1  macallan 		r128fb_bitblt(sc, x, ys, x, yd, width, height, R128_ROP3_S);
    771  1.1  macallan 	}
    772  1.1  macallan }
    773  1.1  macallan 
    774  1.1  macallan static void
    775  1.1  macallan r128fb_eraserows(void *cookie, int row, int nrows, long fillattr)
    776  1.1  macallan {
    777  1.1  macallan 	struct rasops_info *ri = cookie;
    778  1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    779  1.1  macallan 	struct r128fb_softc *sc = scr->scr_cookie;
    780  1.1  macallan 	int32_t x, y, width, height, fg, bg, ul;
    781  1.1  macallan 
    782  1.1  macallan 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    783  1.1  macallan 		x = ri->ri_xorigin;
    784  1.1  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    785  1.1  macallan 		width = ri->ri_emuwidth;
    786  1.1  macallan 		height = ri->ri_font->fontheight * nrows;
    787  1.1  macallan 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
    788  1.1  macallan 
    789  1.1  macallan 		r128fb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
    790  1.1  macallan 	}
    791  1.1  macallan }
    792  1.1  macallan 
    793