Home | History | Annotate | Line # | Download | only in pci
pm2fb.c revision 1.2.2.2
      1  1.2.2.1  uebayasi /*	$NetBSD: pm2fb.c,v 1.2.2.2 2010/08/17 06:46:34 uebayasi Exp $	*/
      2      1.1  macallan 
      3      1.1  macallan /*
      4      1.1  macallan  * Copyright (c) 2009 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 Permedia 2 graphics controllers
     30      1.1  macallan  * tested on sparc64 only so far
     31      1.1  macallan  */
     32      1.1  macallan 
     33      1.1  macallan #include <sys/cdefs.h>
     34  1.2.2.1  uebayasi __KERNEL_RCSID(0, "$NetBSD: pm2fb.c,v 1.2.2.2 2010/08/17 06:46:34 uebayasi 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/pm2reg.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 pm2fb_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_regh;
     72      1.1  macallan 	bus_addr_t sc_fb, sc_reg;
     73      1.1  macallan 	bus_size_t sc_fbsize, sc_regsize;
     74      1.1  macallan 
     75      1.1  macallan 	int sc_width, sc_height, sc_depth, sc_stride;
     76      1.1  macallan 	int sc_locked;
     77      1.1  macallan 	struct vcons_screen sc_console_screen;
     78      1.1  macallan 	struct wsscreen_descr sc_defaultscreen_descr;
     79      1.1  macallan 	const struct wsscreen_descr *sc_screens[1];
     80      1.1  macallan 	struct wsscreen_list sc_screenlist;
     81      1.1  macallan 	struct vcons_data vd;
     82      1.1  macallan 	int sc_mode;
     83      1.1  macallan 	u_char sc_cmap_red[256];
     84      1.1  macallan 	u_char sc_cmap_green[256];
     85      1.1  macallan 	u_char sc_cmap_blue[256];
     86      1.1  macallan 	/* engine stuff */
     87  1.2.2.1  uebayasi 	uint32_t sc_pprod;
     88      1.1  macallan };
     89      1.1  macallan 
     90      1.1  macallan static int	pm2fb_match(device_t, cfdata_t, void *);
     91      1.1  macallan static void	pm2fb_attach(device_t, device_t, void *);
     92      1.1  macallan 
     93      1.1  macallan CFATTACH_DECL_NEW(pm2fb, sizeof(struct pm2fb_softc),
     94      1.1  macallan     pm2fb_match, pm2fb_attach, NULL, NULL);
     95      1.1  macallan 
     96      1.1  macallan extern const u_char rasops_cmap[768];
     97      1.1  macallan 
     98      1.1  macallan static int	pm2fb_ioctl(void *, void *, u_long, void *, int,
     99      1.1  macallan 			     struct lwp *);
    100      1.1  macallan static paddr_t	pm2fb_mmap(void *, void *, off_t, int);
    101      1.1  macallan static void	pm2fb_init_screen(void *, struct vcons_screen *, int, long *);
    102      1.1  macallan 
    103      1.1  macallan static int	pm2fb_putcmap(struct pm2fb_softc *, struct wsdisplay_cmap *);
    104      1.1  macallan static int 	pm2fb_getcmap(struct pm2fb_softc *, struct wsdisplay_cmap *);
    105      1.1  macallan static void	pm2fb_restore_palette(struct pm2fb_softc *);
    106      1.1  macallan static int 	pm2fb_putpalreg(struct pm2fb_softc *, uint8_t, uint8_t,
    107      1.1  macallan 			    uint8_t, uint8_t);
    108      1.1  macallan 
    109      1.1  macallan static void	pm2fb_init(struct pm2fb_softc *);
    110      1.1  macallan static void	pm2fb_flush_engine(struct pm2fb_softc *);
    111      1.1  macallan static void	pm2fb_rectfill(struct pm2fb_softc *, int, int, int, int,
    112      1.1  macallan 			    uint32_t);
    113      1.1  macallan static void	pm2fb_bitblt(struct pm2fb_softc *, int, int, int, int, int,
    114      1.1  macallan 			    int, int);
    115      1.1  macallan 
    116      1.1  macallan static void	pm2fb_cursor(void *, int, int, int);
    117      1.1  macallan static void	pm2fb_putchar(void *, int, int, u_int, long);
    118      1.1  macallan static void	pm2fb_copycols(void *, int, int, int, int);
    119      1.1  macallan static void	pm2fb_erasecols(void *, int, int, int, long);
    120      1.1  macallan static void	pm2fb_copyrows(void *, int, int, int);
    121      1.1  macallan static void	pm2fb_eraserows(void *, int, int, long);
    122      1.1  macallan 
    123      1.1  macallan struct wsdisplay_accessops pm2fb_accessops = {
    124      1.1  macallan 	pm2fb_ioctl,
    125      1.1  macallan 	pm2fb_mmap,
    126      1.1  macallan 	NULL,	/* alloc_screen */
    127      1.1  macallan 	NULL,	/* free_screen */
    128      1.1  macallan 	NULL,	/* show_screen */
    129      1.1  macallan 	NULL, 	/* load_font */
    130      1.1  macallan 	NULL,	/* pollc */
    131      1.1  macallan 	NULL	/* scroll */
    132      1.1  macallan };
    133      1.1  macallan 
    134      1.1  macallan static inline void
    135      1.1  macallan pm2fb_wait(struct pm2fb_softc *sc, int slots)
    136      1.1  macallan {
    137      1.1  macallan 	uint32_t reg;
    138      1.1  macallan 
    139      1.1  macallan 	do {
    140      1.1  macallan 		reg = bus_space_read_4(sc->sc_memt, sc->sc_regh,
    141      1.1  macallan 			PM2_INPUT_FIFO_SPACE);
    142      1.1  macallan 	} while (reg <= slots);
    143      1.1  macallan }
    144      1.1  macallan 
    145      1.1  macallan static void
    146      1.1  macallan pm2fb_flush_engine(struct pm2fb_softc *sc)
    147      1.1  macallan {
    148      1.1  macallan 
    149      1.1  macallan 	pm2fb_wait(sc, 2);
    150      1.1  macallan 
    151      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_FILTER_MODE,
    152      1.1  macallan 	    PM2FLT_PASS_SYNC);
    153      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_SYNC, 0);
    154      1.1  macallan 	do {
    155      1.1  macallan 		while (bus_space_read_4(sc->sc_memt, sc->sc_regh,
    156      1.1  macallan 			PM2_OUTPUT_FIFO_WORDS) == 0);
    157      1.1  macallan 	} while (bus_space_read_4(sc->sc_memt, sc->sc_regh, PM2_OUTPUT_FIFO) !=
    158      1.1  macallan 	    0x188);
    159      1.1  macallan }
    160      1.1  macallan 
    161      1.1  macallan static int
    162      1.1  macallan pm2fb_match(device_t parent, cfdata_t match, void *aux)
    163      1.1  macallan {
    164      1.1  macallan 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
    165      1.1  macallan 
    166      1.1  macallan 	if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY)
    167      1.1  macallan 		return 0;
    168      1.1  macallan 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3DLABS)
    169      1.1  macallan 		return 0;
    170      1.1  macallan 
    171      1.1  macallan 	/* only cards tested on so far - likely need a list */
    172      1.1  macallan 	if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_3DLABS_PERMEDIA2) ||
    173      1.1  macallan 	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_3DLABS_PERMEDIA2V))
    174      1.1  macallan 		return 100;
    175      1.1  macallan 	return (0);
    176      1.1  macallan }
    177      1.1  macallan 
    178      1.1  macallan static void
    179      1.1  macallan pm2fb_attach(device_t parent, device_t self, void *aux)
    180      1.1  macallan {
    181      1.1  macallan 	struct pm2fb_softc	*sc = device_private(self);
    182      1.1  macallan 	struct pci_attach_args	*pa = aux;
    183      1.1  macallan 	struct rasops_info	*ri;
    184      1.1  macallan 	char devinfo[256];
    185      1.1  macallan 	struct wsemuldisplaydev_attach_args aa;
    186      1.1  macallan 	prop_dictionary_t	dict;
    187      1.1  macallan 	unsigned long		defattr;
    188      1.1  macallan 	bool			is_console;
    189      1.1  macallan 	int i, j;
    190  1.2.2.1  uebayasi 	uint32_t flags;
    191      1.1  macallan 
    192      1.1  macallan 	sc->sc_pc = pa->pa_pc;
    193      1.1  macallan 	sc->sc_pcitag = pa->pa_tag;
    194      1.1  macallan 	sc->sc_memt = pa->pa_memt;
    195      1.1  macallan 	sc->sc_iot = pa->pa_iot;
    196      1.1  macallan 	sc->sc_dev = self;
    197      1.1  macallan 
    198      1.1  macallan 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    199      1.1  macallan 	aprint_normal(": %s\n", devinfo);
    200      1.1  macallan 
    201      1.1  macallan 	/* fill in parameters from properties */
    202      1.1  macallan 	dict = device_properties(self);
    203      1.1  macallan 	if (!prop_dictionary_get_uint32(dict, "width", &sc->sc_width)) {
    204      1.1  macallan 		aprint_error("%s: no width property\n", device_xname(self));
    205      1.1  macallan 		return;
    206      1.1  macallan 	}
    207      1.1  macallan 	if (!prop_dictionary_get_uint32(dict, "height", &sc->sc_height)) {
    208      1.1  macallan 		aprint_error("%s: no height property\n", device_xname(self));
    209      1.1  macallan 		return;
    210      1.1  macallan 	}
    211      1.1  macallan 	if (!prop_dictionary_get_uint32(dict, "depth", &sc->sc_depth)) {
    212      1.1  macallan 		aprint_error("%s: no depth property\n", device_xname(self));
    213      1.1  macallan 		return;
    214      1.1  macallan 	}
    215      1.1  macallan 	/*
    216      1.1  macallan 	 * don't look at the linebytes property - The Raptor firmware lies
    217      1.1  macallan 	 * about it. Get it from width * depth >> 3 instead.
    218      1.1  macallan 	 */
    219      1.1  macallan 	sc->sc_stride = sc->sc_width * (sc->sc_depth >> 3);
    220      1.1  macallan 
    221      1.1  macallan 	prop_dictionary_get_bool(dict, "is_console", &is_console);
    222      1.1  macallan 
    223  1.2.2.1  uebayasi 	pci_mapreg_info(pa->pa_pc, pa->pa_tag, 0x14, PCI_MAPREG_TYPE_MEM,
    224  1.2.2.1  uebayasi 	    &sc->sc_fb, &sc->sc_fbsize, &flags);
    225      1.1  macallan 
    226      1.1  macallan 	if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM, 0,
    227      1.1  macallan 	    &sc->sc_memt, &sc->sc_regh, &sc->sc_reg, &sc->sc_regsize)) {
    228      1.1  macallan 		aprint_error("%s: failed to map registers.\n",
    229      1.1  macallan 		    device_xname(sc->sc_dev));
    230      1.1  macallan 	}
    231      1.1  macallan 
    232      1.1  macallan 	/*
    233      1.1  macallan 	 * XXX yeah, casting the fb address to uint32_t is formally wrong
    234      1.1  macallan 	 * but as far as I know there are no PM2 with 64bit BARs
    235      1.1  macallan 	 */
    236      1.1  macallan 	aprint_normal("%s: %d MB aperture at 0x%08x\n", device_xname(self),
    237      1.1  macallan 	    (int)(sc->sc_fbsize >> 20), (uint32_t)sc->sc_fb);
    238      1.1  macallan 
    239      1.1  macallan 	sc->sc_defaultscreen_descr = (struct wsscreen_descr){
    240      1.1  macallan 		"default",
    241      1.1  macallan 		0, 0,
    242      1.1  macallan 		NULL,
    243      1.1  macallan 		8, 16,
    244      1.1  macallan 		WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    245      1.1  macallan 		NULL
    246      1.1  macallan 	};
    247      1.1  macallan 	sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
    248      1.1  macallan 	sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
    249      1.1  macallan 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    250      1.1  macallan 	sc->sc_locked = 0;
    251      1.1  macallan 
    252      1.1  macallan 	vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
    253      1.1  macallan 	    &pm2fb_accessops);
    254      1.1  macallan 	sc->vd.init_screen = pm2fb_init_screen;
    255      1.1  macallan 
    256      1.1  macallan 	/* init engine here */
    257      1.1  macallan 	pm2fb_init(sc);
    258      1.1  macallan 
    259      1.1  macallan 	ri = &sc->sc_console_screen.scr_ri;
    260      1.1  macallan 
    261      1.1  macallan 	j = 0;
    262      1.1  macallan 	for (i = 0; i < (1 << sc->sc_depth); i++) {
    263      1.1  macallan 
    264      1.1  macallan 		sc->sc_cmap_red[i] = rasops_cmap[j];
    265      1.1  macallan 		sc->sc_cmap_green[i] = rasops_cmap[j + 1];
    266      1.1  macallan 		sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
    267      1.1  macallan 		pm2fb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
    268      1.1  macallan 		    rasops_cmap[j + 2]);
    269      1.1  macallan 		j += 3;
    270      1.1  macallan 	}
    271      1.1  macallan 
    272      1.1  macallan 	if (is_console) {
    273      1.1  macallan 		vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
    274      1.1  macallan 		    &defattr);
    275      1.1  macallan 		sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    276      1.1  macallan 
    277      1.1  macallan 		pm2fb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
    278      1.1  macallan 		    ri->ri_devcmap[(defattr >> 16) & 0xff]);
    279      1.1  macallan 		sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
    280      1.1  macallan 		sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
    281      1.1  macallan 		sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
    282      1.1  macallan 		sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
    283      1.1  macallan 		wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
    284      1.1  macallan 		    defattr);
    285      1.1  macallan 		vcons_replay_msgbuf(&sc->sc_console_screen);
    286      1.1  macallan 	} else {
    287      1.1  macallan 		/*
    288      1.1  macallan 		 * since we're not the console we can postpone the rest
    289      1.1  macallan 		 * until someone actually allocates a screen for us
    290      1.1  macallan 		 */
    291      1.1  macallan 		(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    292      1.1  macallan 	}
    293      1.1  macallan 
    294      1.1  macallan 	aa.console = is_console;
    295      1.1  macallan 	aa.scrdata = &sc->sc_screenlist;
    296      1.1  macallan 	aa.accessops = &pm2fb_accessops;
    297      1.1  macallan 	aa.accesscookie = &sc->vd;
    298      1.1  macallan 
    299  1.2.2.1  uebayasi 	config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
    300      1.1  macallan }
    301      1.1  macallan 
    302      1.1  macallan static int
    303      1.1  macallan pm2fb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    304      1.1  macallan 	struct lwp *l)
    305      1.1  macallan {
    306      1.1  macallan 	struct vcons_data *vd = v;
    307      1.1  macallan 	struct pm2fb_softc *sc = vd->cookie;
    308      1.1  macallan 	struct wsdisplay_fbinfo *wdf;
    309      1.1  macallan 	struct vcons_screen *ms = vd->active;
    310      1.1  macallan 
    311      1.1  macallan 	switch (cmd) {
    312      1.1  macallan 
    313      1.1  macallan 		case WSDISPLAYIO_GTYPE:
    314      1.1  macallan 			*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
    315      1.1  macallan 			return 0;
    316      1.1  macallan 
    317      1.1  macallan 		/* PCI config read/write passthrough. */
    318      1.1  macallan 		case PCI_IOC_CFGREAD:
    319      1.1  macallan 		case PCI_IOC_CFGWRITE:
    320      1.1  macallan 			return (pci_devioctl(sc->sc_pc, sc->sc_pcitag,
    321      1.1  macallan 			    cmd, data, flag, l));
    322      1.1  macallan 
    323      1.1  macallan 		case WSDISPLAYIO_GINFO:
    324      1.1  macallan 			if (ms == NULL)
    325      1.1  macallan 				return ENODEV;
    326      1.1  macallan 			wdf = (void *)data;
    327      1.1  macallan 			wdf->height = ms->scr_ri.ri_height;
    328      1.1  macallan 			wdf->width = ms->scr_ri.ri_width;
    329      1.1  macallan 			wdf->depth = ms->scr_ri.ri_depth;
    330      1.1  macallan 			wdf->cmsize = 256;
    331      1.1  macallan 			return 0;
    332      1.1  macallan 
    333      1.1  macallan 		case WSDISPLAYIO_GETCMAP:
    334      1.1  macallan 			return pm2fb_getcmap(sc,
    335      1.1  macallan 			    (struct wsdisplay_cmap *)data);
    336      1.1  macallan 
    337      1.1  macallan 		case WSDISPLAYIO_PUTCMAP:
    338      1.1  macallan 			return pm2fb_putcmap(sc,
    339      1.1  macallan 			    (struct wsdisplay_cmap *)data);
    340      1.1  macallan 
    341      1.1  macallan 		case WSDISPLAYIO_LINEBYTES:
    342      1.1  macallan 			*(u_int *)data = sc->sc_stride;
    343      1.1  macallan 			return 0;
    344      1.1  macallan 
    345      1.1  macallan 		case WSDISPLAYIO_SMODE:
    346      1.1  macallan 			{
    347      1.1  macallan 				int new_mode = *(int*)data;
    348      1.1  macallan 
    349      1.1  macallan 				if (new_mode != sc->sc_mode) {
    350      1.1  macallan 					sc->sc_mode = new_mode;
    351      1.1  macallan 					if(new_mode == WSDISPLAYIO_MODE_EMUL) {
    352      1.1  macallan 						pm2fb_restore_palette(sc);
    353      1.1  macallan 						vcons_redraw_screen(ms);
    354  1.2.2.1  uebayasi 					} else
    355  1.2.2.1  uebayasi 						pm2fb_flush_engine(sc);
    356      1.1  macallan 				}
    357      1.1  macallan 			}
    358      1.1  macallan 			return 0;
    359      1.1  macallan 	}
    360      1.1  macallan 	return EPASSTHROUGH;
    361      1.1  macallan }
    362      1.1  macallan 
    363      1.1  macallan static paddr_t
    364      1.1  macallan pm2fb_mmap(void *v, void *vs, off_t offset, int prot)
    365      1.1  macallan {
    366      1.1  macallan 	struct vcons_data *vd = v;
    367      1.1  macallan 	struct pm2fb_softc *sc = vd->cookie;
    368      1.1  macallan 	paddr_t pa;
    369      1.1  macallan 
    370      1.1  macallan 	/* 'regular' framebuffer mmap()ing */
    371      1.1  macallan 	if (offset < sc->sc_fbsize) {
    372      1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, sc->sc_fb + offset, 0, prot,
    373      1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
    374      1.1  macallan 		return pa;
    375      1.1  macallan 	}
    376      1.1  macallan 
    377      1.1  macallan 	/*
    378      1.1  macallan 	 * restrict all other mappings to processes with superuser privileges
    379      1.1  macallan 	 * or the kernel itself
    380      1.1  macallan 	 */
    381      1.1  macallan 	if (kauth_authorize_generic(kauth_cred_get(), KAUTH_GENERIC_ISSUSER,
    382      1.1  macallan 	    NULL) != 0) {
    383      1.1  macallan 		aprint_normal("%s: mmap() rejected.\n",
    384      1.1  macallan 		    device_xname(sc->sc_dev));
    385      1.1  macallan 		return -1;
    386      1.1  macallan 	}
    387      1.1  macallan 
    388      1.1  macallan 	if ((offset >= sc->sc_fb) && (offset < (sc->sc_fb + sc->sc_fbsize))) {
    389      1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
    390      1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
    391      1.1  macallan 		return pa;
    392      1.1  macallan 	}
    393      1.1  macallan 
    394      1.1  macallan 	if ((offset >= sc->sc_reg) &&
    395      1.1  macallan 	    (offset < (sc->sc_reg + sc->sc_regsize))) {
    396      1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
    397      1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
    398      1.1  macallan 		return pa;
    399      1.1  macallan 	}
    400      1.1  macallan 
    401      1.1  macallan #ifdef PCI_MAGIC_IO_RANGE
    402      1.1  macallan 	/* allow mapping of IO space */
    403      1.1  macallan 	if ((offset >= PCI_MAGIC_IO_RANGE) &&
    404      1.1  macallan 	    (offset < PCI_MAGIC_IO_RANGE + 0x10000)) {
    405      1.1  macallan 		pa = bus_space_mmap(sc->sc_iot, offset - PCI_MAGIC_IO_RANGE,
    406      1.1  macallan 		    0, prot, BUS_SPACE_MAP_LINEAR);
    407      1.1  macallan 		return pa;
    408      1.1  macallan 	}
    409      1.1  macallan #endif
    410      1.1  macallan 
    411      1.1  macallan 	return -1;
    412      1.1  macallan }
    413      1.1  macallan 
    414      1.1  macallan static void
    415      1.1  macallan pm2fb_init_screen(void *cookie, struct vcons_screen *scr,
    416      1.1  macallan     int existing, long *defattr)
    417      1.1  macallan {
    418      1.1  macallan 	struct pm2fb_softc *sc = cookie;
    419      1.1  macallan 	struct rasops_info *ri = &scr->scr_ri;
    420      1.1  macallan 
    421      1.1  macallan 	ri->ri_depth = sc->sc_depth;
    422      1.1  macallan 	ri->ri_width = sc->sc_width;
    423      1.1  macallan 	ri->ri_height = sc->sc_height;
    424      1.1  macallan 	ri->ri_stride = sc->sc_stride;
    425  1.2.2.1  uebayasi 	ri->ri_flg = RI_CENTER;
    426      1.1  macallan 
    427      1.1  macallan 	rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
    428      1.1  macallan 	ri->ri_caps = WSSCREEN_WSCOLORS;
    429      1.1  macallan 
    430      1.1  macallan 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
    431      1.1  macallan 		    sc->sc_width / ri->ri_font->fontwidth);
    432      1.1  macallan 
    433      1.1  macallan 	ri->ri_hw = scr;
    434      1.1  macallan 	ri->ri_ops.copyrows = pm2fb_copyrows;
    435      1.1  macallan 	ri->ri_ops.copycols = pm2fb_copycols;
    436      1.1  macallan 	ri->ri_ops.cursor = pm2fb_cursor;
    437      1.1  macallan 	ri->ri_ops.eraserows = pm2fb_eraserows;
    438      1.1  macallan 	ri->ri_ops.erasecols = pm2fb_erasecols;
    439      1.1  macallan 	ri->ri_ops.putchar = pm2fb_putchar;
    440      1.1  macallan }
    441      1.1  macallan 
    442      1.1  macallan static int
    443      1.1  macallan pm2fb_putcmap(struct pm2fb_softc *sc, struct wsdisplay_cmap *cm)
    444      1.1  macallan {
    445      1.1  macallan 	u_char *r, *g, *b;
    446      1.1  macallan 	u_int index = cm->index;
    447      1.1  macallan 	u_int count = cm->count;
    448      1.1  macallan 	int i, error;
    449      1.1  macallan 	u_char rbuf[256], gbuf[256], bbuf[256];
    450      1.1  macallan 
    451      1.1  macallan #ifdef PM2FB_DEBUG
    452      1.1  macallan 	aprint_debug("putcmap: %d %d\n",index, count);
    453      1.1  macallan #endif
    454      1.1  macallan 	if (cm->index >= 256 || cm->count > 256 ||
    455      1.1  macallan 	    (cm->index + cm->count) > 256)
    456      1.1  macallan 		return EINVAL;
    457      1.1  macallan 	error = copyin(cm->red, &rbuf[index], count);
    458      1.1  macallan 	if (error)
    459      1.1  macallan 		return error;
    460      1.1  macallan 	error = copyin(cm->green, &gbuf[index], count);
    461      1.1  macallan 	if (error)
    462      1.1  macallan 		return error;
    463      1.1  macallan 	error = copyin(cm->blue, &bbuf[index], count);
    464      1.1  macallan 	if (error)
    465      1.1  macallan 		return error;
    466      1.1  macallan 
    467      1.1  macallan 	memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
    468      1.1  macallan 	memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
    469      1.1  macallan 	memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
    470      1.1  macallan 
    471      1.1  macallan 	r = &sc->sc_cmap_red[index];
    472      1.1  macallan 	g = &sc->sc_cmap_green[index];
    473      1.1  macallan 	b = &sc->sc_cmap_blue[index];
    474      1.1  macallan 
    475      1.1  macallan 	for (i = 0; i < count; i++) {
    476      1.1  macallan 		pm2fb_putpalreg(sc, index, *r, *g, *b);
    477      1.1  macallan 		index++;
    478      1.1  macallan 		r++, g++, b++;
    479      1.1  macallan 	}
    480      1.1  macallan 	return 0;
    481      1.1  macallan }
    482      1.1  macallan 
    483      1.1  macallan static int
    484      1.1  macallan pm2fb_getcmap(struct pm2fb_softc *sc, struct wsdisplay_cmap *cm)
    485      1.1  macallan {
    486      1.1  macallan 	u_int index = cm->index;
    487      1.1  macallan 	u_int count = cm->count;
    488      1.1  macallan 	int error;
    489      1.1  macallan 
    490      1.1  macallan 	if (index >= 255 || count > 256 || index + count > 256)
    491      1.1  macallan 		return EINVAL;
    492      1.1  macallan 
    493      1.1  macallan 	error = copyout(&sc->sc_cmap_red[index],   cm->red,   count);
    494      1.1  macallan 	if (error)
    495      1.1  macallan 		return error;
    496      1.1  macallan 	error = copyout(&sc->sc_cmap_green[index], cm->green, count);
    497      1.1  macallan 	if (error)
    498      1.1  macallan 		return error;
    499      1.1  macallan 	error = copyout(&sc->sc_cmap_blue[index],  cm->blue,  count);
    500      1.1  macallan 	if (error)
    501      1.1  macallan 		return error;
    502      1.1  macallan 
    503      1.1  macallan 	return 0;
    504      1.1  macallan }
    505      1.1  macallan 
    506      1.1  macallan static void
    507      1.1  macallan pm2fb_restore_palette(struct pm2fb_softc *sc)
    508      1.1  macallan {
    509      1.1  macallan 	int i;
    510      1.1  macallan 
    511      1.1  macallan 	for (i = 0; i < (1 << sc->sc_depth); i++) {
    512      1.1  macallan 		pm2fb_putpalreg(sc, i, sc->sc_cmap_red[i],
    513      1.1  macallan 		    sc->sc_cmap_green[i], sc->sc_cmap_blue[i]);
    514      1.1  macallan 	}
    515      1.1  macallan }
    516      1.1  macallan 
    517      1.1  macallan static int
    518      1.1  macallan pm2fb_putpalreg(struct pm2fb_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
    519      1.1  macallan     uint8_t b)
    520      1.1  macallan {
    521      1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh, PM2_DAC_PAL_WRITE_IDX, idx);
    522      1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh, PM2_DAC_DATA, r);
    523      1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh, PM2_DAC_DATA, g);
    524      1.1  macallan 	bus_space_write_1(sc->sc_memt, sc->sc_regh, PM2_DAC_DATA, b);
    525      1.1  macallan 	return 0;
    526      1.1  macallan }
    527      1.1  macallan 
    528      1.1  macallan static void
    529      1.1  macallan pm2fb_init(struct pm2fb_softc *sc)
    530      1.1  macallan {
    531      1.1  macallan 	pm2fb_flush_engine(sc);
    532      1.1  macallan 
    533      1.1  macallan 	pm2fb_wait(sc, 8);
    534      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_SCREEN_BASE, 0);
    535      1.1  macallan #if 0
    536      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_BYPASS_MASK,
    537      1.1  macallan 		0xffffffff);
    538      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_FB_WRITE_MASK,
    539      1.1  macallan 		0xffffffff);
    540  1.2.2.1  uebayasi #endif
    541  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_HW_WRITEMASK,
    542  1.2.2.1  uebayasi 		0xffffffff);
    543  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_SW_WRITEMASK,
    544  1.2.2.1  uebayasi 		0xffffffff);
    545  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_WRITE_MODE,
    546  1.2.2.1  uebayasi 		PM2WM_WRITE_EN);
    547  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_SCREENSIZE,
    548  1.2.2.1  uebayasi 	    (sc->sc_height << 16) | sc->sc_width);
    549  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_SCISSOR_MODE,
    550  1.2.2.1  uebayasi 	    PM2SC_SCREEN_EN);
    551  1.2.2.1  uebayasi 	pm2fb_wait(sc, 8);
    552  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_DITHER_MODE, 0);
    553  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_ALPHA_MODE, 0);
    554  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_DDA_MODE, 0);
    555  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_TEX_COLOUR_MODE, 0);
    556  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_TEX_ADDRESS_MODE, 0);
    557  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_TEX_READ_MODE, 0);
    558  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_TEX_LUT_MODE, 0);
    559  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_YUV_MODE, 0);
    560  1.2.2.1  uebayasi 	pm2fb_wait(sc, 8);
    561  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_DEPTH_MODE, 0);
    562  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_DEPTH, 0);
    563  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_STENCIL_MODE, 0);
    564  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_STIPPLE_MODE, 0);
    565  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_ROP_MODE, 0);
    566  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_WINDOW_ORIGIN, 0);
    567  1.2.2.1  uebayasi 	sc->sc_pprod = bus_space_read_4(sc->sc_memt, sc->sc_regh,
    568  1.2.2.1  uebayasi 	    PM2_FB_READMODE) &
    569  1.2.2.1  uebayasi 	    (PM2FB_PP0_MASK | PM2FB_PP1_MASK | PM2FB_PP2_MASK);
    570  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_FB_READMODE,
    571  1.2.2.1  uebayasi 	    sc->sc_pprod);
    572  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_TEXMAP_FORMAT,
    573  1.2.2.1  uebayasi 	    sc->sc_pprod);
    574  1.2.2.1  uebayasi 	pm2fb_wait(sc, 8);
    575  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_DY, 1 << 16);
    576  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_DXDOM, 0);
    577  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_STARTXDOM, 0);
    578  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_STARTXSUB, 0);
    579  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_STARTY, 0);
    580  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_COUNT, 0);
    581  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_SCISSOR_MINYX, 0);
    582  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_SCISSOR_MAXYX,
    583  1.2.2.1  uebayasi 	    0x0fff0fff);
    584      1.1  macallan 	pm2fb_flush_engine(sc);
    585      1.1  macallan }
    586      1.1  macallan 
    587      1.1  macallan static void
    588      1.1  macallan pm2fb_rectfill(struct pm2fb_softc *sc, int x, int y, int wi, int he,
    589      1.1  macallan      uint32_t colour)
    590      1.1  macallan {
    591      1.1  macallan 
    592  1.2.2.1  uebayasi 	pm2fb_wait(sc, 7);
    593  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_DDA_MODE, 0);
    594  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_MODE, 0);
    595      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_CONFIG,
    596      1.1  macallan 	    PM2RECFG_WRITE_EN);
    597      1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_BLOCK_COLOUR,
    598      1.1  macallan 	    colour);
    599      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_RECT_START,
    600      1.1  macallan 	    (y << 16) | x);
    601      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_RECT_SIZE,
    602      1.1  macallan 	    (he << 16) | wi);
    603      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_RENDER,
    604      1.2  macallan 	    PM2RE_RECTANGLE | PM2RE_INC_X | PM2RE_INC_Y | PM2RE_FASTFILL);
    605      1.1  macallan }
    606      1.1  macallan 
    607      1.1  macallan static void
    608      1.1  macallan pm2fb_bitblt(struct pm2fb_softc *sc, int xs, int ys, int xd, int yd,
    609      1.1  macallan     int wi, int he, int rop)
    610      1.1  macallan {
    611      1.1  macallan 	uint32_t dir = 0;
    612      1.1  macallan 
    613      1.1  macallan 	if (yd <= ys) {
    614      1.1  macallan 		dir |= PM2RE_INC_Y;
    615      1.1  macallan 	}
    616      1.1  macallan 	if (xd <= xs) {
    617      1.1  macallan 		dir |= PM2RE_INC_X;
    618      1.1  macallan 	}
    619  1.2.2.1  uebayasi 	pm2fb_wait(sc, 7);
    620      1.2  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_DDA_MODE, 0);
    621  1.2.2.1  uebayasi 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_MODE, 0);
    622  1.2.2.1  uebayasi 	if (rop == 3) {
    623  1.2.2.1  uebayasi 		bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_CONFIG,
    624  1.2.2.1  uebayasi 		    PM2RECFG_READ_SRC | PM2RECFG_WRITE_EN | PM2RECFG_ROP_EN |
    625  1.2.2.1  uebayasi 		    PM2RECFG_PACKED | (rop << 6));
    626  1.2.2.1  uebayasi 	} else {
    627  1.2.2.1  uebayasi 		bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_CONFIG,
    628  1.2.2.1  uebayasi 		    PM2RECFG_READ_SRC | PM2RECFG_READ_DST | PM2RECFG_WRITE_EN |
    629  1.2.2.1  uebayasi 		    PM2RECFG_PACKED | PM2RECFG_ROP_EN | (rop << 6));
    630  1.2.2.1  uebayasi 	}
    631      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_RECT_START,
    632      1.1  macallan 	    (yd << 16) | xd);
    633      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_RECT_SIZE,
    634      1.1  macallan 	    (he << 16) | wi);
    635      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_SOURCE_DELTA,
    636      1.1  macallan 	    (((ys - yd) & 0xfff) << 16) | ((xs - xd) & 0xfff));
    637      1.1  macallan 	bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_RENDER,
    638      1.1  macallan 	    PM2RE_RECTANGLE | dir);
    639      1.1  macallan }
    640      1.1  macallan 
    641      1.1  macallan static void
    642      1.1  macallan pm2fb_cursor(void *cookie, int on, int row, int col)
    643      1.1  macallan {
    644      1.1  macallan 	struct rasops_info *ri = cookie;
    645      1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    646      1.1  macallan 	struct pm2fb_softc *sc = scr->scr_cookie;
    647      1.1  macallan 	int x, y, wi, he;
    648      1.1  macallan 
    649      1.1  macallan 	wi = ri->ri_font->fontwidth;
    650      1.1  macallan 	he = ri->ri_font->fontheight;
    651      1.1  macallan 
    652      1.1  macallan 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    653      1.1  macallan 		x = ri->ri_ccol * wi + ri->ri_xorigin;
    654      1.1  macallan 		y = ri->ri_crow * he + ri->ri_yorigin;
    655      1.1  macallan 		if (ri->ri_flg & RI_CURSOR) {
    656      1.1  macallan 			pm2fb_bitblt(sc, x, y, x, y, wi, he, 12);
    657      1.1  macallan 			ri->ri_flg &= ~RI_CURSOR;
    658      1.1  macallan 		}
    659      1.1  macallan 		ri->ri_crow = row;
    660      1.1  macallan 		ri->ri_ccol = col;
    661      1.1  macallan 		if (on) {
    662      1.1  macallan 			x = ri->ri_ccol * wi + ri->ri_xorigin;
    663      1.1  macallan 			y = ri->ri_crow * he + ri->ri_yorigin;
    664      1.1  macallan 			pm2fb_bitblt(sc, x, y, x, y, wi, he, 12);
    665      1.1  macallan 			ri->ri_flg |= RI_CURSOR;
    666      1.1  macallan 		}
    667      1.1  macallan 	} else {
    668      1.1  macallan 		scr->scr_ri.ri_crow = row;
    669      1.1  macallan 		scr->scr_ri.ri_ccol = col;
    670      1.1  macallan 		scr->scr_ri.ri_flg &= ~RI_CURSOR;
    671      1.1  macallan 	}
    672      1.1  macallan 
    673      1.1  macallan }
    674      1.1  macallan 
    675      1.1  macallan static void
    676      1.1  macallan pm2fb_putchar(void *cookie, int row, int col, u_int c, long attr)
    677      1.1  macallan {
    678  1.2.2.1  uebayasi 	struct rasops_info *ri = cookie;
    679  1.2.2.2  uebayasi 	struct wsdisplay_font *font = PICK_FONT(ri, c);
    680  1.2.2.1  uebayasi 	struct vcons_screen *scr = ri->ri_hw;
    681  1.2.2.1  uebayasi 	struct pm2fb_softc *sc = scr->scr_cookie;
    682  1.2.2.1  uebayasi 	uint32_t mode;
    683  1.2.2.1  uebayasi 
    684  1.2.2.1  uebayasi 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    685  1.2.2.1  uebayasi 		void *data;
    686  1.2.2.1  uebayasi 		uint32_t fg, bg;
    687  1.2.2.1  uebayasi 		int uc, i;
    688  1.2.2.1  uebayasi 		int x, y, wi, he;
    689  1.2.2.1  uebayasi 
    690  1.2.2.2  uebayasi 		wi = font->fontwidth;
    691  1.2.2.2  uebayasi 		he = font->fontheight;
    692  1.2.2.1  uebayasi 
    693  1.2.2.2  uebayasi 		if (!CHAR_IN_FONT(c, font))
    694  1.2.2.1  uebayasi 			return;
    695  1.2.2.1  uebayasi 		bg = ri->ri_devcmap[(attr >> 16) & 0xf];
    696  1.2.2.1  uebayasi 		fg = ri->ri_devcmap[(attr >> 24) & 0xf];
    697  1.2.2.1  uebayasi 		x = ri->ri_xorigin + col * wi;
    698  1.2.2.1  uebayasi 		y = ri->ri_yorigin + row * he;
    699  1.2.2.1  uebayasi 		if (c == 0x20) {
    700  1.2.2.1  uebayasi 			pm2fb_rectfill(sc, x, y, wi, he, bg);
    701  1.2.2.1  uebayasi 		} else {
    702  1.2.2.2  uebayasi 			uc = c - font->firstchar;
    703  1.2.2.2  uebayasi 			data = (uint8_t *)font->data + uc * ri->ri_fontscale;
    704  1.2.2.1  uebayasi 
    705  1.2.2.1  uebayasi 			mode = PM2RM_MASK_MIRROR;
    706  1.2.2.1  uebayasi 			switch (ri->ri_font->stride) {
    707  1.2.2.1  uebayasi 				case 1:
    708  1.2.2.1  uebayasi 					mode |= 3 << 7;
    709  1.2.2.1  uebayasi 					break;
    710  1.2.2.1  uebayasi 				case 2:
    711  1.2.2.1  uebayasi 					mode |= 2 << 7;
    712  1.2.2.1  uebayasi 					break;
    713  1.2.2.1  uebayasi 			}
    714  1.2.2.1  uebayasi 
    715  1.2.2.1  uebayasi 			pm2fb_wait(sc, 8);
    716  1.2.2.1  uebayasi 
    717  1.2.2.1  uebayasi 			bus_space_write_4(sc->sc_memt, sc->sc_regh,
    718  1.2.2.1  uebayasi 			    PM2_RE_MODE, mode);
    719  1.2.2.1  uebayasi 			bus_space_write_4(sc->sc_memt, sc->sc_regh,
    720  1.2.2.1  uebayasi 			    PM2_RE_CONFIG, PM2RECFG_WRITE_EN);
    721  1.2.2.1  uebayasi 			bus_space_write_4(sc->sc_memt, sc->sc_regh,
    722  1.2.2.1  uebayasi 			    PM2_RE_BLOCK_COLOUR, bg);
    723  1.2.2.1  uebayasi 			bus_space_write_4(sc->sc_memt, sc->sc_regh,
    724  1.2.2.1  uebayasi 			    PM2_RE_RECT_START, (y << 16) | x);
    725  1.2.2.1  uebayasi 			bus_space_write_4(sc->sc_memt, sc->sc_regh,
    726  1.2.2.1  uebayasi 			    PM2_RE_RECT_SIZE, (he << 16) | wi);
    727  1.2.2.1  uebayasi 			bus_space_write_4(sc->sc_memt, sc->sc_regh,
    728  1.2.2.1  uebayasi 			    PM2_RE_RENDER,
    729  1.2.2.1  uebayasi 			    PM2RE_RECTANGLE |
    730  1.2.2.1  uebayasi 			    PM2RE_INC_X | PM2RE_INC_Y | PM2RE_FASTFILL);
    731  1.2.2.1  uebayasi 			bus_space_write_4(sc->sc_memt, sc->sc_regh,
    732  1.2.2.1  uebayasi 			    PM2_RE_BLOCK_COLOUR, fg);
    733  1.2.2.1  uebayasi 			bus_space_write_4(sc->sc_memt, sc->sc_regh,
    734  1.2.2.1  uebayasi 			    PM2_RE_RENDER,
    735  1.2.2.1  uebayasi 			    PM2RE_RECTANGLE | PM2RE_SYNC_ON_MASK |
    736  1.2.2.1  uebayasi 			    PM2RE_INC_X | PM2RE_INC_Y | PM2RE_FASTFILL);
    737  1.2.2.1  uebayasi 
    738  1.2.2.1  uebayasi 			pm2fb_wait(sc, he);
    739  1.2.2.1  uebayasi 			switch (ri->ri_font->stride) {
    740  1.2.2.1  uebayasi 			case 1: {
    741  1.2.2.1  uebayasi 				uint8_t *data8 = data;
    742  1.2.2.1  uebayasi 				uint32_t reg;
    743  1.2.2.1  uebayasi 				for (i = 0; i < he; i++) {
    744  1.2.2.1  uebayasi 					reg = *data8;
    745  1.2.2.1  uebayasi 					bus_space_write_4(sc->sc_memt,
    746  1.2.2.1  uebayasi 					    sc->sc_regh,
    747  1.2.2.1  uebayasi 					    PM2_RE_BITMASK, reg);
    748  1.2.2.1  uebayasi 					data8++;
    749  1.2.2.1  uebayasi 				}
    750  1.2.2.1  uebayasi 				break;
    751  1.2.2.1  uebayasi 				}
    752  1.2.2.1  uebayasi 			case 2: {
    753  1.2.2.1  uebayasi 				uint16_t *data16 = data;
    754  1.2.2.1  uebayasi 				uint32_t reg;
    755  1.2.2.1  uebayasi 				for (i = 0; i < he; i++) {
    756  1.2.2.1  uebayasi 					reg = *data16;
    757  1.2.2.1  uebayasi 					bus_space_write_4(sc->sc_memt,
    758  1.2.2.1  uebayasi 					    sc->sc_regh,
    759  1.2.2.1  uebayasi 					    PM2_RE_BITMASK, reg);
    760  1.2.2.1  uebayasi 					data16++;
    761  1.2.2.1  uebayasi 				}
    762  1.2.2.1  uebayasi 				break;
    763  1.2.2.1  uebayasi 			}
    764  1.2.2.1  uebayasi 			}
    765  1.2.2.1  uebayasi 		}
    766  1.2.2.1  uebayasi 	}
    767      1.1  macallan }
    768      1.1  macallan 
    769      1.1  macallan static void
    770      1.1  macallan pm2fb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
    771      1.1  macallan {
    772      1.1  macallan 	struct rasops_info *ri = cookie;
    773      1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    774      1.1  macallan 	struct pm2fb_softc *sc = scr->scr_cookie;
    775      1.1  macallan 	int32_t xs, xd, y, width, height;
    776      1.1  macallan 
    777      1.1  macallan 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    778      1.1  macallan 		xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
    779      1.1  macallan 		xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
    780      1.1  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    781      1.1  macallan 		width = ri->ri_font->fontwidth * ncols;
    782      1.1  macallan 		height = ri->ri_font->fontheight;
    783      1.1  macallan 		pm2fb_bitblt(sc, xs, y, xd, y, width, height, 3);
    784      1.1  macallan 	}
    785      1.1  macallan }
    786      1.1  macallan 
    787      1.1  macallan static void
    788      1.1  macallan pm2fb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
    789      1.1  macallan {
    790      1.1  macallan 	struct rasops_info *ri = cookie;
    791      1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    792      1.1  macallan 	struct pm2fb_softc *sc = scr->scr_cookie;
    793      1.1  macallan 	int32_t x, y, width, height, fg, bg, ul;
    794      1.1  macallan 
    795      1.1  macallan 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    796      1.1  macallan 		x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
    797      1.1  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    798      1.1  macallan 		width = ri->ri_font->fontwidth * ncols;
    799      1.1  macallan 		height = ri->ri_font->fontheight;
    800      1.1  macallan 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
    801      1.1  macallan 
    802      1.1  macallan 		pm2fb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
    803      1.1  macallan 	}
    804      1.1  macallan }
    805      1.1  macallan 
    806      1.1  macallan static void
    807      1.1  macallan pm2fb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
    808      1.1  macallan {
    809      1.1  macallan 	struct rasops_info *ri = cookie;
    810      1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    811      1.1  macallan 	struct pm2fb_softc *sc = scr->scr_cookie;
    812      1.1  macallan 	int32_t x, ys, yd, width, height;
    813      1.1  macallan 
    814      1.1  macallan 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    815      1.1  macallan 		x = ri->ri_xorigin;
    816      1.1  macallan 		ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
    817      1.1  macallan 		yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
    818      1.1  macallan 		width = ri->ri_emuwidth;
    819      1.1  macallan 		height = ri->ri_font->fontheight*nrows;
    820      1.1  macallan 		pm2fb_bitblt(sc, x, ys, x, yd, width, height, 3);
    821      1.1  macallan 	}
    822      1.1  macallan }
    823      1.1  macallan 
    824      1.1  macallan static void
    825      1.1  macallan pm2fb_eraserows(void *cookie, int row, int nrows, long fillattr)
    826      1.1  macallan {
    827      1.1  macallan 	struct rasops_info *ri = cookie;
    828      1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    829      1.1  macallan 	struct pm2fb_softc *sc = scr->scr_cookie;
    830      1.1  macallan 	int32_t x, y, width, height, fg, bg, ul;
    831      1.1  macallan 
    832      1.1  macallan 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
    833      1.1  macallan 		x = ri->ri_xorigin;
    834      1.1  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    835      1.1  macallan 		width = ri->ri_emuwidth;
    836      1.1  macallan 		height = ri->ri_font->fontheight * nrows;
    837      1.1  macallan 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
    838      1.1  macallan 
    839      1.1  macallan 		pm2fb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
    840      1.1  macallan 	}
    841      1.1  macallan }
    842      1.1  macallan 
    843