Home | History | Annotate | Line # | Download | only in ibus
pm.c revision 1.9
      1  1.9   tsutsui /*	$NetBSD: pm.c,v 1.9 2011/06/04 01:31:23 tsutsui Exp $	*/
      2  1.2        ad 
      3  1.2        ad /*-
      4  1.2        ad  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
      5  1.2        ad  * All rights reserved.
      6  1.2        ad  *
      7  1.2        ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2        ad  * by Andrew Doran.
      9  1.2        ad  *
     10  1.2        ad  * Redistribution and use in source and binary forms, with or without
     11  1.2        ad  * modification, are permitted provided that the following conditions
     12  1.2        ad  * are met:
     13  1.2        ad  * 1. Redistributions of source code must retain the above copyright
     14  1.2        ad  *    notice, this list of conditions and the following disclaimer.
     15  1.2        ad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2        ad  *    notice, this list of conditions and the following disclaimer in the
     17  1.2        ad  *    documentation and/or other materials provided with the distribution.
     18  1.2        ad  *
     19  1.2        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.2        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.2        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.2        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.2        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.2        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.2        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.2        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.2        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.2        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.2        ad  * POSSIBILITY OF SUCH DAMAGE.
     30  1.2        ad  */
     31  1.2        ad 
     32  1.2        ad #include <sys/cdefs.h>
     33  1.9   tsutsui __KERNEL_RCSID(0, "$NetBSD: pm.c,v 1.9 2011/06/04 01:31:23 tsutsui Exp $");
     34  1.2        ad 
     35  1.2        ad #include <sys/param.h>
     36  1.2        ad #include <sys/systm.h>
     37  1.2        ad #include <sys/kernel.h>
     38  1.2        ad #include <sys/device.h>
     39  1.2        ad #include <sys/buf.h>
     40  1.2        ad #include <sys/ioctl.h>
     41  1.2        ad 
     42  1.2        ad #include <machine/bus.h>
     43  1.2        ad #include <machine/intr.h>
     44  1.2        ad 
     45  1.2        ad #include <dev/wscons/wsconsio.h>
     46  1.2        ad #include <dev/wscons/wsdisplayvar.h>
     47  1.2        ad #include <dev/rasops/rasops.h>
     48  1.2        ad #include <dev/wsfont/wsfont.h>
     49  1.2        ad 
     50  1.2        ad #include <pmax/pmax/kn01.h>
     51  1.2        ad 
     52  1.2        ad #include <pmax/ibus/ibusvar.h>
     53  1.2        ad #include <pmax/ibus/pmreg.h>
     54  1.2        ad 
     55  1.2        ad #include <uvm/uvm_extern.h>
     56  1.2        ad 
     57  1.2        ad #define	CURSOR_MAX_SIZE	16
     58  1.2        ad 
     59  1.2        ad struct hwcmap256 {
     60  1.2        ad 	uint8_t r[256];
     61  1.2        ad 	uint8_t g[256];
     62  1.2        ad 	uint8_t b[256];
     63  1.2        ad };
     64  1.2        ad 
     65  1.2        ad struct hwcursor64 {
     66  1.2        ad 	struct wsdisplay_curpos cc_pos;
     67  1.2        ad 	struct wsdisplay_curpos cc_hot;
     68  1.2        ad 	struct wsdisplay_curpos cc_size;
     69  1.2        ad 	uint8_t cc_color[6];
     70  1.2        ad 
     71  1.2        ad 	/*
     72  1.2        ad 	 * Max cursor size is 16x16.  The X server pads bitmap scanlines to
     73  1.2        ad 	 * a word boundary.  We take the easy route and waste some space.
     74  1.2        ad 	 */
     75  1.2        ad 	u_short cc_image[32 + 32];
     76  1.2        ad };
     77  1.2        ad 
     78  1.2        ad struct pm_softc {
     79  1.9   tsutsui 	device_t		sc_dev;
     80  1.2        ad 	size_t			sc_cmap_size;
     81  1.2        ad 	size_t			sc_fb_size;
     82  1.2        ad 	int			sc_type;
     83  1.2        ad 	int			sc_blanked;
     84  1.2        ad 	int			sc_curenb;
     85  1.2        ad 	int			sc_changed;
     86  1.2        ad 	int			sc_nscreens;
     87  1.2        ad 	struct hwcursor64	sc_cursor;
     88  1.2        ad 	struct hwcmap256	sc_cmap;
     89  1.2        ad };
     90  1.2        ad #define	WSDISPLAY_CMAP_DOLUT	0x20
     91  1.2        ad 
     92  1.9   tsutsui int	pm_match(device_t, cfdata_t, void *);
     93  1.9   tsutsui void	pm_attach(device_t, device_t, void *);
     94  1.5  christos int	pm_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     95  1.4      jmmv paddr_t	pm_mmap(void *, void *, off_t, int);
     96  1.2        ad int	pm_alloc_screen(void *, const struct wsscreen_descr *,
     97  1.2        ad 				void **, int *, int *, long *);
     98  1.2        ad void	pm_free_screen(void *, void *);
     99  1.2        ad int	pm_show_screen(void *, void *, int,
    100  1.2        ad 			       void (*) (void *, int, int), void *);
    101  1.2        ad void	pm_cursor_off(void);
    102  1.2        ad void	pm_cursor_on(struct pm_softc *);
    103  1.2        ad int	pm_cnattach(void);
    104  1.2        ad void	pm_common_init(void);
    105  1.2        ad int	pm_flush(struct pm_softc *);
    106  1.2        ad int	pm_get_cmap(struct pm_softc *, struct wsdisplay_cmap *);
    107  1.2        ad int	pm_set_cmap(struct pm_softc *, struct wsdisplay_cmap *);
    108  1.2        ad int	pm_set_cursor(struct pm_softc *, struct wsdisplay_cursor *);
    109  1.2        ad int	pm_get_cursor(struct pm_softc *, struct wsdisplay_cursor *);
    110  1.2        ad void	pm_set_curpos(struct pm_softc *, struct wsdisplay_curpos *);
    111  1.2        ad void	pm_init_cmap(struct pm_softc *);
    112  1.2        ad 
    113  1.9   tsutsui CFATTACH_DECL_NEW(pm, sizeof(struct pm_softc),
    114  1.2        ad    pm_match, pm_attach, NULL, NULL);
    115  1.2        ad 
    116  1.2        ad struct rasops_info pm_ri;
    117  1.2        ad 
    118  1.2        ad struct wsscreen_descr pm_stdscreen = {
    119  1.2        ad 	"std", 0, 0,
    120  1.2        ad 	0, /* textops */
    121  1.2        ad 	0, 0,
    122  1.2        ad 	WSSCREEN_REVERSE
    123  1.2        ad };
    124  1.2        ad 
    125  1.2        ad const struct wsscreen_descr *_pm_scrlist[] = {
    126  1.2        ad 	&pm_stdscreen,
    127  1.2        ad };
    128  1.2        ad 
    129  1.2        ad const struct wsscreen_list pm_screenlist = {
    130  1.2        ad 	sizeof(_pm_scrlist) / sizeof(struct wsscreen_descr *), _pm_scrlist
    131  1.2        ad };
    132  1.2        ad 
    133  1.2        ad const struct wsdisplay_accessops pm_accessops = {
    134  1.2        ad 	pm_ioctl,
    135  1.2        ad 	pm_mmap,
    136  1.2        ad 	pm_alloc_screen,
    137  1.2        ad 	pm_free_screen,
    138  1.2        ad 	pm_show_screen,
    139  1.2        ad 	0 /* load_font */
    140  1.2        ad };
    141  1.2        ad 
    142  1.2        ad u_int	pm_creg;
    143  1.2        ad 
    144  1.2        ad int
    145  1.9   tsutsui pm_match(device_t parent, cfdata_t cf, void *aux)
    146  1.2        ad {
    147  1.2        ad 	struct ibus_attach_args *ia;
    148  1.5  christos 	void *pmaddr;
    149  1.2        ad 
    150  1.2        ad 	ia = aux;
    151  1.5  christos 	pmaddr = (void *)ia->ia_addr;
    152  1.2        ad 
    153  1.2        ad 	if (strcmp(ia->ia_name, "pm") != 0)
    154  1.2        ad 		return (0);
    155  1.2        ad 
    156  1.2        ad 	if (badaddr(pmaddr, 4))
    157  1.2        ad 		return (0);
    158  1.2        ad 
    159  1.2        ad 	return (1);
    160  1.2        ad }
    161  1.2        ad 
    162  1.2        ad void
    163  1.9   tsutsui pm_attach(device_t parent, device_t self, void *aux)
    164  1.2        ad {
    165  1.2        ad 	struct pm_softc *sc;
    166  1.2        ad 	struct rasops_info *ri;
    167  1.2        ad 	struct wsemuldisplaydev_attach_args waa;
    168  1.2        ad 	int console;
    169  1.2        ad 
    170  1.9   tsutsui 	sc = device_private(self);
    171  1.9   tsutsui 	sc->sc_dev = self;
    172  1.2        ad 	ri = &pm_ri;
    173  1.2        ad 	console = (ri->ri_bits != NULL);
    174  1.2        ad 
    175  1.8   tsutsui 	if (console) {
    176  1.2        ad 		sc->sc_nscreens = 1;
    177  1.8   tsutsui 		ri->ri_flg &= ~RI_NO_AUTO;
    178  1.8   tsutsui 	} else
    179  1.2        ad 		pm_common_init();
    180  1.2        ad 
    181  1.2        ad 	printf(": %dx%d, %dbpp\n", ri->ri_width, ri->ri_height, ri->ri_depth);
    182  1.2        ad 
    183  1.2        ad 	pm_init_cmap(sc);
    184  1.2        ad 
    185  1.2        ad 	sc->sc_blanked = 0;
    186  1.2        ad 	sc->sc_curenb = 0;
    187  1.2        ad 
    188  1.2        ad 	waa.console = console;
    189  1.2        ad 	waa.scrdata = &pm_screenlist;
    190  1.2        ad 	waa.accessops = &pm_accessops;
    191  1.2        ad 	waa.accesscookie = sc;
    192  1.2        ad 
    193  1.2        ad 	config_found(self, &waa, wsemuldisplaydevprint);
    194  1.2        ad }
    195  1.2        ad 
    196  1.2        ad void
    197  1.2        ad pm_init_cmap(struct pm_softc *sc)
    198  1.2        ad {
    199  1.2        ad 	struct hwcmap256 *cm;
    200  1.2        ad 	struct rasops_info *ri;
    201  1.2        ad 	const uint8_t *p;
    202  1.2        ad 	int index;
    203  1.2        ad 
    204  1.2        ad 	cm = &sc->sc_cmap;
    205  1.2        ad 	ri = &pm_ri;
    206  1.2        ad 
    207  1.2        ad 	if (ri->ri_depth == 8) {
    208  1.2        ad 		p = rasops_cmap;
    209  1.2        ad 		for (index = 0; index < 256; index++, p += 3) {
    210  1.2        ad 			cm->r[index] = p[0];
    211  1.2        ad 			cm->g[index] = p[1];
    212  1.2        ad 			cm->b[index] = p[2];
    213  1.2        ad 		}
    214  1.2        ad 
    215  1.2        ad 		sc->sc_type = WSDISPLAY_TYPE_PM_COLOR;
    216  1.2        ad 		sc->sc_cmap_size = 256;
    217  1.2        ad 		sc->sc_fb_size = 0x100000;
    218  1.2        ad 	} else {
    219  1.2        ad 		cm->r[0] = 0x00;
    220  1.2        ad 		cm->g[0] = 0x00;
    221  1.2        ad 		cm->b[0] = 0x00;
    222  1.2        ad 
    223  1.2        ad 		cm->r[1] = 0x00;
    224  1.2        ad 		cm->g[1] = 0xff;
    225  1.2        ad 		cm->b[1] = 0x00;
    226  1.2        ad 
    227  1.2        ad 		sc->sc_type = WSDISPLAY_TYPE_PM_MONO;
    228  1.2        ad 		sc->sc_cmap_size = 2;
    229  1.2        ad 		sc->sc_fb_size = 0x40000;
    230  1.2        ad 	}
    231  1.2        ad }
    232  1.2        ad 
    233  1.2        ad void
    234  1.2        ad pm_common_init(void)
    235  1.2        ad {
    236  1.2        ad 	struct rasops_info *ri;
    237  1.2        ad 	int cookie, bior, i;
    238  1.2        ad 	PCCRegs *pcc;
    239  1.2        ad 	VDACRegs *vdac;
    240  1.2        ad 	uint16_t kn01csr;
    241  1.2        ad 
    242  1.2        ad 	kn01csr = *(volatile uint16_t *)MIPS_PHYS_TO_KSEG1(KN01_SYS_CSR);
    243  1.2        ad 	pcc = (void *)MIPS_PHYS_TO_KSEG1(KN01_SYS_PCC);
    244  1.2        ad 	vdac = (void *)MIPS_PHYS_TO_KSEG1(KN01_SYS_VDAC);
    245  1.2        ad 	ri = &pm_ri;
    246  1.2        ad 
    247  1.2        ad 	ri->ri_flg = RI_CENTER;
    248  1.8   tsutsui 	if (ri->ri_bits == NULL)
    249  1.8   tsutsui 		ri->ri_flg |= RI_NO_AUTO;
    250  1.2        ad 	ri->ri_depth = ((kn01csr & KN01_CSR_MONO) != 0 ? 1 : 8);
    251  1.2        ad 	ri->ri_width = 1024;
    252  1.2        ad 	ri->ri_height = 864;
    253  1.2        ad 	ri->ri_stride = (ri->ri_depth == 8 ? 1024 : 2048 / 8);
    254  1.2        ad 	ri->ri_bits = (void *)MIPS_PHYS_TO_KSEG1(KN01_PHYS_FBUF_START);
    255  1.2        ad 
    256  1.2        ad 	/*
    257  1.2        ad 	 * Clear the screen.
    258  1.2        ad 	 */
    259  1.2        ad 	memset(ri->ri_bits, 0, ri->ri_stride * ri->ri_height);
    260  1.2        ad 
    261  1.2        ad 	/*
    262  1.2        ad 	 * Get a font to use.
    263  1.2        ad 	 */
    264  1.2        ad 	bior = (ri->ri_depth == 8 ? WSDISPLAY_FONTORDER_L2R :
    265  1.2        ad 	    WSDISPLAY_FONTORDER_R2L);
    266  1.2        ad 
    267  1.2        ad 	wsfont_init();
    268  1.2        ad 	if (ri->ri_depth == 8)
    269  1.2        ad 		cookie = wsfont_find(NULL, 12, 0, 0, bior,
    270  1.2        ad 		    WSDISPLAY_FONTORDER_L2R);
    271  1.2        ad 	else
    272  1.2        ad 		cookie = wsfont_find(NULL, 8, 0, 0, bior,
    273  1.2        ad 		    WSDISPLAY_FONTORDER_L2R);
    274  1.2        ad 	if (cookie <= 0)
    275  1.2        ad 		cookie = wsfont_find(NULL, 0, 0, 0, bior,
    276  1.2        ad 		    WSDISPLAY_FONTORDER_L2R);
    277  1.2        ad 	if (cookie <= 0) {
    278  1.2        ad 		printf("pm: font table is empty\n");
    279  1.2        ad 		return;
    280  1.2        ad 	}
    281  1.2        ad 
    282  1.2        ad 	if (wsfont_lock(cookie, &ri->ri_font)) {
    283  1.2        ad 		printf("pm: couldn't lock font\n");
    284  1.2        ad 		return;
    285  1.2        ad 	}
    286  1.2        ad 	ri->ri_wsfcookie = cookie;
    287  1.2        ad 
    288  1.2        ad 	/*
    289  1.2        ad 	 * Set up the raster operations set.
    290  1.2        ad 	 */
    291  1.2        ad 	rasops_init(ri, 1000, 1000);
    292  1.2        ad 
    293  1.2        ad 	pm_stdscreen.nrows = ri->ri_rows;
    294  1.2        ad 	pm_stdscreen.ncols = ri->ri_cols;
    295  1.2        ad 	pm_stdscreen.textops = &ri->ri_ops;
    296  1.2        ad 	pm_stdscreen.capabilities = ri->ri_caps;
    297  1.2        ad 
    298  1.2        ad 	/*
    299  1.2        ad 	 * Initalize the VDAC.
    300  1.2        ad 	 */
    301  1.2        ad 	*(uint8_t *)MIPS_PHYS_TO_KSEG1(KN01_PHYS_COLMASK_START) = 0xff;
    302  1.2        ad 	wbflush();
    303  1.2        ad 
    304  1.2        ad 	vdac->overWA = 0x04; wbflush();
    305  1.2        ad 	vdac->over = 0x00; wbflush();
    306  1.2        ad 	vdac->over = 0x00; wbflush();
    307  1.2        ad 	vdac->over = 0x00; wbflush();
    308  1.2        ad 	vdac->overWA = 0x08; wbflush();
    309  1.2        ad 	vdac->over = 0x00; wbflush();
    310  1.2        ad 	vdac->over = 0x00; wbflush();
    311  1.2        ad 	vdac->over = 0x7f; wbflush();
    312  1.2        ad 	vdac->overWA = 0x0c; wbflush();
    313  1.2        ad 	vdac->over = 0xff; wbflush();
    314  1.2        ad 	vdac->over = 0xff; wbflush();
    315  1.2        ad 	vdac->over = 0xff; wbflush();
    316  1.2        ad 
    317  1.2        ad 	/*
    318  1.2        ad 	 * Set in the initial colormap.
    319  1.2        ad 	 */
    320  1.2        ad 	if (ri->ri_depth == 8) {
    321  1.2        ad 		vdac->mapWA = 0;
    322  1.2        ad 		wbflush();
    323  1.2        ad 
    324  1.2        ad 		for (i = 0; i < 256 * 3; i += 3) {
    325  1.2        ad 			vdac->map = rasops_cmap[i];
    326  1.2        ad 			wbflush();
    327  1.2        ad 			vdac->map = rasops_cmap[i + 1];
    328  1.2        ad 			wbflush();
    329  1.2        ad 			vdac->map = rasops_cmap[i + 2];
    330  1.2        ad 			wbflush();
    331  1.2        ad 		}
    332  1.2        ad 	} else {
    333  1.2        ad 		vdac->mapWA = 0;
    334  1.2        ad 		wbflush();
    335  1.2        ad 
    336  1.2        ad 		for (i = 0; i < 256; i++) {
    337  1.2        ad 			vdac->map = 0x00;
    338  1.2        ad 			wbflush();
    339  1.2        ad 			vdac->map = (i < 128 ? 0x00 : 0xff);
    340  1.2        ad 			wbflush();
    341  1.2        ad 			vdac->map = 0x00;
    342  1.2        ad 			wbflush();
    343  1.2        ad 		}
    344  1.2        ad 	}
    345  1.2        ad 
    346  1.2        ad 	/*
    347  1.2        ad 	 * Turn off the hardware cursor sprite for text mode.
    348  1.2        ad 	 */
    349  1.2        ad 	pcc->cmdr = PCC_FOPB | PCC_VBHI;
    350  1.2        ad 	wbflush();
    351  1.2        ad 	pm_creg = 0;
    352  1.2        ad 	pm_cursor_off();
    353  1.2        ad }
    354  1.2        ad 
    355  1.2        ad void
    356  1.2        ad pm_cursor_off(void)
    357  1.2        ad {
    358  1.2        ad 	PCCRegs *pcc;
    359  1.2        ad 
    360  1.2        ad 	pcc = (void *)MIPS_PHYS_TO_KSEG1(KN01_SYS_PCC);
    361  1.2        ad 	pcc->cmdr = (pm_creg &= ~(PCC_ENPA | PCC_ENPB));
    362  1.2        ad 	wbflush();
    363  1.2        ad }
    364  1.2        ad 
    365  1.2        ad void
    366  1.2        ad pm_cursor_on(struct pm_softc *sc)
    367  1.2        ad {
    368  1.2        ad 	PCCRegs *pcc;
    369  1.2        ad 
    370  1.2        ad 	if (sc->sc_curenb) {
    371  1.2        ad 		pcc = (void *)MIPS_PHYS_TO_KSEG1(KN01_SYS_PCC);
    372  1.2        ad 		pcc->cmdr = (pm_creg |= (PCC_ENPA | PCC_ENPB));
    373  1.2        ad 		wbflush();
    374  1.2        ad 	}
    375  1.2        ad }
    376  1.2        ad 
    377  1.2        ad int
    378  1.5  christos pm_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    379  1.2        ad {
    380  1.2        ad 	struct pm_softc *sc;
    381  1.2        ad 	struct rasops_info *ri;
    382  1.2        ad 	int turnoff, rv, i;
    383  1.2        ad 	PCCRegs *pcc;
    384  1.2        ad 	VDACRegs *vdac;
    385  1.2        ad 
    386  1.2        ad 	sc = v;
    387  1.2        ad 	ri = &pm_ri;
    388  1.2        ad 	rv = 0;
    389  1.2        ad 	pcc = (void *)MIPS_PHYS_TO_KSEG1(KN01_SYS_PCC);
    390  1.2        ad 	vdac = (void *)MIPS_PHYS_TO_KSEG1(KN01_SYS_VDAC);
    391  1.2        ad 
    392  1.2        ad 	switch (cmd) {
    393  1.2        ad 	case WSDISPLAYIO_GTYPE:
    394  1.2        ad 		*(u_int *)data = sc->sc_type;
    395  1.2        ad 		break;
    396  1.2        ad 
    397  1.2        ad 	case WSDISPLAYIO_SMODE:
    398  1.2        ad 		if (*(u_int *)data == WSDISPLAYIO_MODE_EMUL) {
    399  1.2        ad 			pm_cursor_off();
    400  1.2        ad 			pm_init_cmap(sc);
    401  1.2        ad 			memset(ri->ri_bits, 0, ri->ri_stride * ri->ri_height);
    402  1.2        ad 			sc->sc_curenb = 0;
    403  1.2        ad 			sc->sc_changed |= WSDISPLAY_CMAP_DOLUT;
    404  1.2        ad 		}
    405  1.2        ad 		break;
    406  1.2        ad 
    407  1.2        ad 	case WSDISPLAYIO_GINFO:
    408  1.2        ad #define	wsd_fbip ((struct wsdisplay_fbinfo *)data)
    409  1.2        ad 		wsd_fbip->height = ri->ri_height;
    410  1.2        ad 		wsd_fbip->width = ri->ri_width;
    411  1.2        ad 		wsd_fbip->depth = ri->ri_depth;
    412  1.2        ad 		wsd_fbip->cmsize = sc->sc_cmap_size;
    413  1.2        ad #undef fbt
    414  1.2        ad 		break;
    415  1.2        ad 
    416  1.2        ad 	case WSDISPLAYIO_GETCMAP:
    417  1.2        ad 		rv = pm_get_cmap(sc, (struct wsdisplay_cmap *)data);
    418  1.2        ad 		break;
    419  1.2        ad 
    420  1.2        ad 	case WSDISPLAYIO_PUTCMAP:
    421  1.2        ad 		rv = pm_set_cmap(sc, (struct wsdisplay_cmap *)data);
    422  1.2        ad 		break;
    423  1.2        ad 
    424  1.2        ad 	case WSDISPLAYIO_SVIDEO:
    425  1.2        ad 		turnoff = (*(int *)data == WSDISPLAYIO_VIDEO_OFF);
    426  1.2        ad 		if ((sc->sc_blanked == 0) ^ turnoff) {
    427  1.2        ad 			sc->sc_blanked = turnoff;
    428  1.2        ad 			if (turnoff == 0) {
    429  1.2        ad 				pcc->cmdr =
    430  1.2        ad 				    (pm_creg &= ~(PCC_FOPA | PCC_FOPB));
    431  1.2        ad 				wbflush();
    432  1.2        ad 				pm_cursor_on(sc);
    433  1.2        ad 				sc->sc_changed |= WSDISPLAY_CURSOR_DOCMAP;
    434  1.2        ad 			} else {
    435  1.2        ad 				pm_cursor_off();
    436  1.2        ad 				pcc->cmdr =
    437  1.2        ad 				    (pm_creg |= (PCC_FOPA | PCC_FOPB));
    438  1.2        ad 				wbflush();
    439  1.2        ad 				vdac->overWA = 0x0c;
    440  1.2        ad 				wbflush();
    441  1.2        ad 				for (i = 0; i < 3; i++) {
    442  1.2        ad 					vdac->over = 0;
    443  1.2        ad 					wbflush();
    444  1.2        ad 				}
    445  1.2        ad 			}
    446  1.2        ad 		}
    447  1.2        ad 		break;
    448  1.2        ad 
    449  1.2        ad 	case WSDISPLAYIO_GVIDEO:
    450  1.2        ad 		*(u_int *)data = (sc->sc_blanked ?
    451  1.2        ad 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON);
    452  1.2        ad 		break;
    453  1.2        ad 
    454  1.2        ad 	case WSDISPLAYIO_GCURPOS:
    455  1.2        ad 		*(struct wsdisplay_curpos *)data = sc->sc_cursor.cc_pos;
    456  1.2        ad 		break;
    457  1.2        ad 
    458  1.2        ad 	case WSDISPLAYIO_SCURPOS:
    459  1.2        ad 		pm_set_curpos(sc, (struct wsdisplay_curpos *)data);
    460  1.2        ad 		sc->sc_changed |= WSDISPLAY_CURSOR_DOPOS;
    461  1.2        ad 		break;
    462  1.2        ad 
    463  1.2        ad 	case WSDISPLAYIO_GCURMAX:
    464  1.2        ad 		((struct wsdisplay_curpos *)data)->x =
    465  1.2        ad 		((struct wsdisplay_curpos *)data)->y = CURSOR_MAX_SIZE;
    466  1.2        ad 		break;
    467  1.2        ad 
    468  1.2        ad 	case WSDISPLAYIO_GCURSOR:
    469  1.2        ad 		rv = pm_get_cursor(sc, (struct wsdisplay_cursor *)data);
    470  1.2        ad 		break;
    471  1.2        ad 
    472  1.2        ad 	case WSDISPLAYIO_SCURSOR:
    473  1.2        ad 		rv = pm_set_cursor(sc, (struct wsdisplay_cursor *)data);
    474  1.2        ad 		break;
    475  1.2        ad 
    476  1.2        ad 	default:
    477  1.2        ad 		rv = ENOTTY;
    478  1.2        ad 		break;
    479  1.2        ad 	}
    480  1.2        ad 
    481  1.2        ad 	pm_flush(sc);
    482  1.2        ad 	return (rv);
    483  1.2        ad }
    484  1.2        ad 
    485  1.2        ad paddr_t
    486  1.4      jmmv pm_mmap(void *v, void *vs, off_t offset, int prot)
    487  1.2        ad {
    488  1.2        ad 	struct pm_softc *sc;
    489  1.2        ad 
    490  1.2        ad 	sc = v;
    491  1.2        ad 
    492  1.2        ad 	if (offset >= sc->sc_fb_size || offset < 0)
    493  1.2        ad 		return (-1);
    494  1.2        ad 
    495  1.2        ad 	return (mips_btop(KN01_PHYS_FBUF_START + offset));
    496  1.2        ad }
    497  1.2        ad 
    498  1.2        ad int
    499  1.2        ad pm_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
    500  1.2        ad 		int *curxp, int *curyp, long *attrp)
    501  1.2        ad {
    502  1.2        ad 	struct pm_softc *sc;
    503  1.2        ad 	struct rasops_info *ri;
    504  1.2        ad 	long defattr;
    505  1.2        ad 
    506  1.2        ad 	sc = v;
    507  1.2        ad 	ri = &pm_ri;
    508  1.2        ad 
    509  1.2        ad 	if (sc->sc_nscreens > 0)
    510  1.2        ad 		return (ENOMEM);
    511  1.2        ad 
    512  1.2        ad 	*cookiep = ri;	 /* one and only for now */
    513  1.2        ad 	*curxp = 0;
    514  1.2        ad 	*curyp = 0;
    515  1.2        ad 	(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    516  1.2        ad 	*attrp = defattr;
    517  1.2        ad 	sc->sc_nscreens++;
    518  1.2        ad 	return (0);
    519  1.2        ad }
    520  1.2        ad 
    521  1.2        ad void
    522  1.2        ad pm_free_screen(void *v, void *cookie)
    523  1.2        ad {
    524  1.2        ad 
    525  1.2        ad 	panic("pm_free_screen: console");
    526  1.2        ad }
    527  1.2        ad 
    528  1.2        ad int
    529  1.2        ad pm_show_screen(void *v, void *cookie, int waitok,
    530  1.2        ad 	       void (*cb)(void *, int, int), void *cbarg)
    531  1.2        ad {
    532  1.2        ad 
    533  1.2        ad 	return (0);
    534  1.2        ad }
    535  1.2        ad 
    536  1.2        ad /* EXPORT */ int
    537  1.2        ad pm_cnattach(void)
    538  1.2        ad {
    539  1.2        ad 	struct rasops_info *ri;
    540  1.2        ad 	long defattr;
    541  1.2        ad 
    542  1.2        ad 	ri = &pm_ri;
    543  1.2        ad 
    544  1.2        ad 	pm_common_init();
    545  1.2        ad 	(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    546  1.2        ad 	wsdisplay_cnattach(&pm_stdscreen, ri, 0, 0, defattr);
    547  1.2        ad 	return (1);
    548  1.2        ad }
    549  1.2        ad 
    550  1.2        ad int
    551  1.2        ad pm_flush(struct pm_softc *sc)
    552  1.2        ad {
    553  1.2        ad 	VDACRegs *vdac;
    554  1.2        ad 	PCCRegs *pcc;
    555  1.2        ad 	uint8_t *cp;
    556  1.2        ad 	int v, i, x, y;
    557  1.2        ad 	u_short *p, *pe;
    558  1.2        ad 	struct hwcmap256 *cm;
    559  1.2        ad 	struct rasops_info *ri;
    560  1.2        ad 
    561  1.2        ad 	if (sc->sc_changed == 0)
    562  1.2        ad 		return (1);
    563  1.2        ad 
    564  1.2        ad 	vdac = (void *)MIPS_PHYS_TO_KSEG1(KN01_SYS_VDAC);
    565  1.2        ad 	pcc = (void *)MIPS_PHYS_TO_KSEG1(KN01_SYS_PCC);
    566  1.2        ad 	ri = &pm_ri;
    567  1.2        ad 	v = sc->sc_changed;
    568  1.2        ad 
    569  1.2        ad 	if ((v & WSDISPLAY_CURSOR_DOCUR) != 0) {
    570  1.2        ad 		if (sc->sc_curenb)
    571  1.2        ad 			pm_cursor_on(sc);
    572  1.2        ad 		else
    573  1.2        ad 			pm_cursor_off();
    574  1.2        ad 	}
    575  1.2        ad 
    576  1.2        ad 	if ((v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) != 0) {
    577  1.2        ad 		x = sc->sc_cursor.cc_pos.x - sc->sc_cursor.cc_hot.x;
    578  1.2        ad 		y = sc->sc_cursor.cc_pos.y - sc->sc_cursor.cc_hot.y;
    579  1.2        ad 		pcc->xpos = x + PCC_X_OFFSET;
    580  1.2        ad 		pcc->ypos = y + PCC_Y_OFFSET;
    581  1.2        ad 		wbflush();
    582  1.2        ad 	}
    583  1.2        ad 	if ((v & WSDISPLAY_CURSOR_DOCMAP) != 0) {
    584  1.2        ad 		cp = sc->sc_cursor.cc_color;
    585  1.2        ad 
    586  1.2        ad 		vdac->overWA = 0x04;
    587  1.2        ad 		wbflush();
    588  1.2        ad 		for (i = 1; i < 6; i += 2) {
    589  1.2        ad 			vdac->over = cp[i];
    590  1.2        ad 			wbflush();
    591  1.2        ad 		}
    592  1.2        ad 
    593  1.2        ad 		vdac->overWA = 0x08;
    594  1.2        ad 		wbflush();
    595  1.2        ad 		vdac->over = 0x00;
    596  1.2        ad 		wbflush();
    597  1.2        ad 		vdac->over = 0x00;
    598  1.2        ad 		wbflush();
    599  1.2        ad 		vdac->over = 0x7f;
    600  1.2        ad 		wbflush();
    601  1.2        ad 
    602  1.2        ad 		vdac->overWA = 0x0c;
    603  1.2        ad 		wbflush();
    604  1.2        ad 		for (i = 0; i < 6; i += 2) {
    605  1.2        ad 			vdac->over = cp[i];
    606  1.2        ad 			wbflush();
    607  1.2        ad 		}
    608  1.2        ad 	}
    609  1.2        ad 	if ((v & WSDISPLAY_CURSOR_DOSHAPE) != 0) {
    610  1.2        ad 		pcc->cmdr = (pm_creg | PCC_LODSA);
    611  1.2        ad 		wbflush();
    612  1.2        ad 
    613  1.2        ad 		p = sc->sc_cursor.cc_image;
    614  1.2        ad 		x = 0xffff >> (16 - sc->sc_cursor.cc_size.x);
    615  1.2        ad 		for (pe = p + 64; p < pe; p += 2) {
    616  1.2        ad 			pcc->memory = *p & x;
    617  1.2        ad 			wbflush();
    618  1.2        ad 		}
    619  1.2        ad 
    620  1.2        ad 		pcc->cmdr = (pm_creg &= ~PCC_LODSA);
    621  1.2        ad 		wbflush();
    622  1.2        ad 	}
    623  1.2        ad 
    624  1.2        ad 	if ((v & WSDISPLAY_CMAP_DOLUT) != 0) {
    625  1.2        ad 		cm = &sc->sc_cmap;
    626  1.2        ad 
    627  1.2        ad 		vdac->mapWA = 0;
    628  1.2        ad 		wbflush();
    629  1.2        ad 
    630  1.2        ad 		if (sc->sc_cmap_size == 2) {
    631  1.2        ad 			for (i = 0; i < 128; i++) {
    632  1.2        ad 				vdac->map = 0;
    633  1.2        ad 				wbflush();
    634  1.2        ad 				vdac->map = cm->g[0];
    635  1.2        ad 				wbflush();
    636  1.2        ad 				vdac->map = 0;
    637  1.2        ad 				wbflush();
    638  1.2        ad 			}
    639  1.2        ad 			for (; i < 256; i++) {
    640  1.2        ad 				vdac->map = 0;
    641  1.2        ad 				wbflush();
    642  1.2        ad 				vdac->map = cm->g[1];
    643  1.2        ad 				wbflush();
    644  1.2        ad 				vdac->map = 0;
    645  1.2        ad 				wbflush();
    646  1.2        ad 			}
    647  1.2        ad 		} else {
    648  1.2        ad 			for (i = 0; i < sc->sc_cmap_size; i++) {
    649  1.2        ad 				vdac->map = cm->r[i];
    650  1.2        ad 				wbflush();
    651  1.2        ad 				vdac->map = cm->g[i];
    652  1.2        ad 				wbflush();
    653  1.2        ad 				vdac->map = cm->b[i];
    654  1.2        ad 				wbflush();
    655  1.2        ad 			}
    656  1.2        ad 		}
    657  1.2        ad 	}
    658  1.2        ad 
    659  1.2        ad 	sc->sc_changed = 0;
    660  1.2        ad 	return (1);
    661  1.2        ad }
    662  1.2        ad 
    663  1.2        ad int
    664  1.2        ad pm_get_cmap(struct pm_softc *sc, struct wsdisplay_cmap *p)
    665  1.2        ad {
    666  1.2        ad 	u_int index, count;
    667  1.2        ad 	int rv;
    668  1.2        ad 
    669  1.2        ad 	index = p->index;
    670  1.2        ad 	count = p->count;
    671  1.2        ad 
    672  1.2        ad 	if (index >= sc->sc_cmap_size || (index + count) > sc->sc_cmap_size)
    673  1.2        ad 		return (EINVAL);
    674  1.2        ad 
    675  1.2        ad 	if ((rv = copyout(&sc->sc_cmap.r[index], p->red, count)) != 0)
    676  1.2        ad 		return (rv);
    677  1.2        ad 	if ((rv = copyout(&sc->sc_cmap.g[index], p->green, count)) != 0)
    678  1.2        ad 		return (rv);
    679  1.2        ad 	return (copyout(&sc->sc_cmap.b[index], p->blue, count));
    680  1.2        ad }
    681  1.2        ad 
    682  1.2        ad int
    683  1.2        ad pm_set_cmap(struct pm_softc *sc, struct wsdisplay_cmap *p)
    684  1.2        ad {
    685  1.2        ad 	u_int index, count;
    686  1.2        ad 	int rv;
    687  1.2        ad 
    688  1.2        ad 	index = p->index;
    689  1.2        ad 	count = p->count;
    690  1.2        ad 
    691  1.2        ad 	if (index >= sc->sc_cmap_size || (index + count) > sc->sc_cmap_size)
    692  1.2        ad 		return (EINVAL);
    693  1.2        ad 
    694  1.2        ad 	if ((rv = copyin(p->red, &sc->sc_cmap.r[index], count)) != 0)
    695  1.2        ad 		return (rv);
    696  1.2        ad 	if ((rv = copyin(p->green, &sc->sc_cmap.g[index], count)) != 0)
    697  1.2        ad 		return (rv);
    698  1.2        ad 	if ((rv = copyin(p->blue, &sc->sc_cmap.b[index], count)) != 0)
    699  1.2        ad 		return (rv);
    700  1.2        ad 	sc->sc_changed |= WSDISPLAY_CMAP_DOLUT;
    701  1.2        ad 	return (0);
    702  1.2        ad }
    703  1.2        ad 
    704  1.2        ad int
    705  1.2        ad pm_set_cursor(struct pm_softc *sc, struct wsdisplay_cursor *p)
    706  1.2        ad {
    707  1.2        ad 	u_int v, index, count;
    708  1.2        ad 	struct hwcursor64 *cc;
    709  1.2        ad 	int rv;
    710  1.2        ad 
    711  1.2        ad 	v = p->which;
    712  1.2        ad 	cc = &sc->sc_cursor;
    713  1.2        ad 
    714  1.2        ad 	if ((v & WSDISPLAY_CURSOR_DOCUR) != 0)
    715  1.2        ad 		sc->sc_curenb = p->enable;
    716  1.2        ad 	if ((v & WSDISPLAY_CURSOR_DOPOS) != 0)
    717  1.2        ad 		pm_set_curpos(sc, &p->pos);
    718  1.2        ad 	if ((v & WSDISPLAY_CURSOR_DOHOT) != 0)
    719  1.2        ad 		cc->cc_hot = p->hot;
    720  1.2        ad 	if ((v & WSDISPLAY_CURSOR_DOCMAP) != 0) {
    721  1.2        ad 		index = p->cmap.index;
    722  1.2        ad 		count = p->cmap.count;
    723  1.2        ad 		if (index >= 2 || (index + count) > 2)
    724  1.2        ad 			return (EINVAL);
    725  1.2        ad 
    726  1.2        ad 		rv = copyin(p->cmap.red, &cc->cc_color[index], count);
    727  1.2        ad 		if (rv != 0)
    728  1.2        ad 			return (rv);
    729  1.2        ad 		rv = copyin(p->cmap.green, &cc->cc_color[index + 2], count);
    730  1.2        ad 		if (rv != 0)
    731  1.2        ad 			return (rv);
    732  1.2        ad 		rv = copyin(p->cmap.blue, &cc->cc_color[index + 4], count);
    733  1.2        ad 		if (rv != 0)
    734  1.2        ad 			return (rv);
    735  1.2        ad 	}
    736  1.2        ad 	if ((v & WSDISPLAY_CURSOR_DOSHAPE) != 0) {
    737  1.2        ad 		if (p->size.x > CURSOR_MAX_SIZE ||
    738  1.2        ad 		    p->size.y > CURSOR_MAX_SIZE)
    739  1.2        ad 			return (EINVAL);
    740  1.2        ad 
    741  1.2        ad 		cc->cc_size = p->size;
    742  1.2        ad 		memset(cc->cc_image, 0, sizeof(cc->cc_image));
    743  1.2        ad 		rv = copyin(p->image, cc->cc_image, p->size.y * 4);
    744  1.2        ad 		if (rv != 0)
    745  1.2        ad 			return (rv);
    746  1.2        ad 		rv = copyin(p->mask, cc->cc_image+32, p->size.y * 4);
    747  1.2        ad 		if (rv != 0)
    748  1.2        ad 			return (rv);
    749  1.2        ad 	}
    750  1.2        ad 
    751  1.2        ad 	sc->sc_changed |= v;
    752  1.2        ad 	return (0);
    753  1.2        ad }
    754  1.2        ad 
    755  1.2        ad int
    756  1.2        ad pm_get_cursor(struct pm_softc *sc, struct wsdisplay_cursor *p)
    757  1.2        ad {
    758  1.2        ad 
    759  1.2        ad 	return (ENOTTY); /* XXX */
    760  1.2        ad }
    761  1.2        ad 
    762  1.2        ad void
    763  1.2        ad pm_set_curpos(struct pm_softc *sc, struct wsdisplay_curpos *curpos)
    764  1.2        ad {
    765  1.2        ad 	struct rasops_info *ri;
    766  1.2        ad 	int x, y;
    767  1.2        ad 
    768  1.2        ad 	ri = &pm_ri;
    769  1.2        ad 	x = curpos->x;
    770  1.2        ad 	y = curpos->y;
    771  1.2        ad 
    772  1.2        ad 	if (y < 0)
    773  1.2        ad 		y = 0;
    774  1.2        ad 	else if (y > ri->ri_height)
    775  1.2        ad 		y = ri->ri_height;
    776  1.2        ad 	if (x < 0)
    777  1.2        ad 		x = 0;
    778  1.2        ad 	else if (x > ri->ri_width)
    779  1.2        ad 		x = ri->ri_width;
    780  1.2        ad 	sc->sc_cursor.cc_pos.x = x;
    781  1.2        ad 	sc->sc_cursor.cc_pos.y = y;
    782  1.2        ad }
    783