Home | History | Annotate | Line # | Download | only in tc
mfb.c revision 1.1
      1 /* $NetBSD: mfb.c,v 1.1 1998/10/29 12:24:24 nisimura Exp $ */
      2 
      3 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
      4 
      5 __KERNEL_RCSID(0, "$NetBSD: mfb.c,v 1.1 1998/10/29 12:24:24 nisimura Exp $");
      6 
      7 #include <sys/param.h>
      8 #include <sys/systm.h>
      9 #include <sys/kernel.h>
     10 #include <sys/device.h>
     11 #include <sys/malloc.h>
     12 #include <sys/buf.h>
     13 #include <sys/ioctl.h>
     14 #include <vm/vm.h>
     15 
     16 #include <machine/bus.h>
     17 #include <machine/intr.h>
     18 
     19 #include <dev/rcons/raster.h>
     20 #include <dev/wscons/wsconsio.h>
     21 #include <dev/wscons/wscons_raster.h>
     22 #include <dev/wscons/wsdisplayvar.h>
     23 #include <machine/autoconf.h>
     24 
     25 #include <dev/tc/tcvar.h>
     26 #include <dev/ic/bt431reg.h>
     27 
     28 #include "opt_uvm.h"
     29 #if defined(UVM)
     30 #include <uvm/uvm_extern.h>
     31 #define useracc uvm_useracc
     32 #endif
     33 
     34 /* XXX BUS'IFYING XXX */
     35 
     36 #if defined(__pmax__)
     37 #define	machine_btop(x) mips_btop(x)
     38 #define	MACHINE_KSEG0_TO_PHYS(x) MIPS_KSEG0_TO_PHYS(x)
     39 
     40 struct bt455reg {
     41 	u_int8_t	bt_reg;
     42 	unsigned : 24;
     43 	u_int8_t	bt_cmap;
     44 	unsigned : 24;
     45 	u_int8_t	bt_clr;
     46 	unsigned : 24;
     47 	u_int8_t	bt_ovly;
     48 };
     49 
     50 /* it's really painful to manipulate 'twined' registers... */
     51 struct bt431reg {
     52 	u_int16_t	bt_lo;
     53 	unsigned : 16;
     54 	u_int16_t	bt_hi;
     55 	unsigned : 16;
     56 	u_int16_t	bt_ram;
     57 	unsigned : 16;
     58 	u_int16_t	bt_ctl;
     59 };
     60 
     61 #endif
     62 
     63 #if defined(__alpha__) || defined(alpha)
     64 /*
     65  * Digital UNIX never supports PMAG-AA
     66  */
     67 #define machine_btop(x) alpha_btop(x)
     68 #define MACHINE_KSEG0_TO_PHYS(x) ALPHA_K0SEG_TO_PHYS(x)
     69 
     70 struct bt455reg {
     71 	u_int32_t	bt_reg;
     72 	u_int32_t	bt_cmap;
     73 	u_int32_t	bt_clr;
     74 	u_int32_t	bt_ovly;
     75 };
     76 
     77 /* it's really painful to manipulate 'twined' registers... */
     78 struct bt431reg {
     79 	u_int32_t	bt_lo;
     80 	u_int32_t	bt_hi;
     81 	u_int32_t	bt_ram;
     82 	u_int32_t	bt_ctl;
     83 };
     84 #endif
     85 
     86 /* XXX XXX XXX */
     87 
     88 struct fb_devconfig {
     89 	vaddr_t dc_vaddr;		/* memory space virtual base address */
     90 	paddr_t dc_paddr;		/* memory space physical base address */
     91 	vsize_t dc_size;		/* size of slot memory */
     92 	int	dc_wid;			/* width of frame buffer */
     93 	int	dc_ht;			/* height of frame buffer */
     94 	int	dc_depth;		/* depth, bits per pixel */
     95 	int	dc_rowbytes;		/* bytes in a FB scan line */
     96 	vaddr_t dc_videobase;		/* base of flat frame buffer */
     97 	struct raster	dc_raster;	/* raster description */
     98 	struct rcons	dc_rcons;	/* raster blitter control info */
     99 	int	    dc_blanked;		/* currently has video disabled */
    100 };
    101 
    102 struct hwcursor {
    103 	struct wsdisplay_curpos cc_pos;
    104 	struct wsdisplay_curpos cc_hot;
    105 	struct wsdisplay_curpos cc_size;
    106 #define	CURSOR_MAX_SIZE	64
    107 	u_int8_t cc_color[6];
    108 	u_int64_t cc_image[64 + 64];
    109 };
    110 
    111 struct mfb_softc {
    112 	struct device sc_dev;
    113 	struct fb_devconfig *sc_dc;	/* device configuration */
    114 	struct hwcursor sc_cursor;	/* software copy of cursor */
    115 	int sc_curenb;			/* cursor sprite enabled */
    116 	int sc_changed;			/* need update of colormap */
    117 #define	DATA_ENB_CHANGED	0x01	/* cursor enable changed */
    118 #define	DATA_CURCMAP_CHANGED	0x02	/* cursor colormap changed */
    119 #define	DATA_CURSHAPE_CHANGED	0x04	/* cursor size, image, mask changed */
    120 #define	DATA_CMAP_CHANGED	0x08	/* colormap changed */
    121 #define	DATA_ALL_CHANGED	0x0f
    122 	int nscreens;
    123 };
    124 
    125 int  mfbmatch __P((struct device *, struct cfdata *, void *));
    126 void mfbattach __P((struct device *, struct device *, void *));
    127 
    128 struct cfattach mfb_ca = {
    129 	sizeof(struct mfb_softc), mfbmatch, mfbattach,
    130 };
    131 
    132 void mfb_getdevconfig __P((tc_addr_t, struct fb_devconfig *));
    133 struct fb_devconfig mfb_console_dc;
    134 tc_addr_t mfb_consaddr;
    135 
    136 struct wsdisplay_emulops mfb_emulops = {
    137 	rcons_cursor,			/* could use hardware cursor; punt */
    138 	rcons_mapchar,
    139 	rcons_putchar,
    140 	rcons_copycols,
    141 	rcons_erasecols,
    142 	rcons_copyrows,
    143 	rcons_eraserows,
    144 	rcons_alloc_attr
    145 };
    146 
    147 struct wsscreen_descr mfb_stdscreen = {
    148 	"std", 0, 0,
    149 	&mfb_emulops,
    150 	0, 0,
    151 	0
    152 };
    153 
    154 const struct wsscreen_descr *_mfb_scrlist[] = {
    155 	&mfb_stdscreen,
    156 };
    157 
    158 struct wsscreen_list mfb_screenlist = {
    159 	sizeof(_mfb_scrlist) / sizeof(struct wsscreen_descr *), _mfb_scrlist
    160 };
    161 
    162 int	mfbioctl __P((void *, u_long, caddr_t, int, struct proc *));
    163 int	mfbmmap __P((void *, off_t, int));
    164 
    165 int	mfb_alloc_screen __P((void *, const struct wsscreen_descr *,
    166 				      void **, int *, int *, long *));
    167 void	mfb_free_screen __P((void *, void *));
    168 void	mfb_show_screen __P((void *, void *));
    169 int	mfb_load_font __P((void *, void *, int, int, int, void *));
    170 
    171 struct wsdisplay_accessops mfb_accessops = {
    172 	mfbioctl,
    173 	mfbmmap,
    174 	mfb_alloc_screen,
    175 	mfb_free_screen,
    176 	mfb_show_screen,
    177 	mfb_load_font
    178 };
    179 
    180 int  mfb_cnattach __P((tc_addr_t));
    181 int  mfbintr __P((void *));
    182 void mfbinit __P((struct fb_devconfig *));
    183 
    184 static int  set_cursor __P((struct mfb_softc *, struct wsdisplay_cursor *));
    185 static int  get_cursor __P((struct mfb_softc *, struct wsdisplay_cursor *));
    186 static void set_curpos __P((struct mfb_softc *, struct wsdisplay_curpos *));
    187 void bt431_set_curpos __P((struct mfb_softc *));
    188 
    189 #define	TWIN_LO(x) (twin = (x) & 0x00ff, twin << 8 | twin)
    190 #define	TWIN_HI(x) (twin = (x) & 0xff00, twin | twin >> 8)
    191 
    192 /* XXX XXX XXX */
    193 #define	BT431_SELECT(curs, regno) do {	\
    194 	u_int16_t twin;			\
    195 	curs->bt_lo = TWIN_LO(regno);	\
    196 	curs->bt_hi = TWIN_HI(regno);	\
    197 	tc_wmb();			\
    198    } while (0)
    199 
    200 #define BT455_SELECT(vdac, index) do {	\
    201 	vdac->bt_reg = index;		\
    202 	vdac->bt_clr = 0;		\
    203 	tc_wmb();			\
    204    } while (0)
    205 /* XXX XXX XXX */
    206 
    207 #define	MFB_FB_OFFSET		0x200000
    208 #define	MFB_FB_SIZE		 0x40000
    209 #define	MFB_BT455_OFFSET	0x100000
    210 #define	MFB_BT431_OFFSET	0x180000
    211 #define	MFB_IREQ_OFFSET		0x080000	/* Interrupt req. control */
    212 
    213 int
    214 mfbmatch(parent, match, aux)
    215 	struct device *parent;
    216 	struct cfdata *match;
    217 	void *aux;
    218 {
    219 	struct tc_attach_args *ta = aux;
    220 
    221 	if (strncmp("PMAG-AA ", ta->ta_modname, TC_ROM_LLEN) != 0)
    222 		return (0);
    223 
    224 	return (1);
    225 }
    226 
    227 void
    228 mfb_getdevconfig(dense_addr, dc)
    229 	tc_addr_t dense_addr;
    230 	struct fb_devconfig *dc;
    231 {
    232 	struct raster *rap;
    233 	struct rcons *rcp;
    234 	int i;
    235 
    236 	dc->dc_vaddr = dense_addr;
    237 	dc->dc_paddr = MACHINE_KSEG0_TO_PHYS(dc->dc_vaddr + MFB_FB_OFFSET);
    238 
    239 	dc->dc_wid = 1280;
    240 	dc->dc_ht = 1024;
    241 	dc->dc_depth = 1;
    242 	dc->dc_rowbytes = 2048 / 8;
    243 	dc->dc_videobase = dc->dc_vaddr + MFB_FB_OFFSET;
    244 	dc->dc_blanked = 0;
    245 
    246 	/* initialize colormap and cursor resource */
    247 	mfbinit(dc);
    248 
    249 	/* clear the screen */
    250 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
    251 		*(u_int32_t *)(dc->dc_videobase + i) = 0;
    252 
    253 	/* initialize the raster */
    254 	rap = &dc->dc_raster;
    255 	rap->width = dc->dc_wid;
    256 	rap->height = dc->dc_ht;
    257 	rap->depth = dc->dc_depth;
    258 	rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
    259 	rap->pixels = (u_int32_t *)dc->dc_videobase;
    260 
    261 	/* initialize the raster console blitter */
    262 	rcp = &dc->dc_rcons;
    263 	rcp->rc_sp = rap;
    264 	rcp->rc_crow = rcp->rc_ccol = -1;
    265 	rcp->rc_crowp = &rcp->rc_crow;
    266 	rcp->rc_ccolp = &rcp->rc_ccol;
    267 	rcons_init(rcp, 34, 80);
    268 
    269 	mfb_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
    270 	mfb_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
    271 }
    272 
    273 void
    274 mfbattach(parent, self, aux)
    275 	struct device *parent, *self;
    276 	void *aux;
    277 {
    278 	struct mfb_softc *sc = (struct mfb_softc *)self;
    279 	struct tc_attach_args *ta = aux;
    280 	struct wsemuldisplaydev_attach_args waa;
    281 	caddr_t mfbbase;
    282 	int console;
    283 	volatile register int junk;
    284 
    285 	console = (ta->ta_addr == mfb_consaddr);
    286 	if (console) {
    287 		sc->sc_dc = &mfb_console_dc;
    288 		sc->nscreens = 1;
    289 	}
    290 	else {
    291 		sc->sc_dc = (struct fb_devconfig *)
    292 		    malloc(sizeof(struct fb_devconfig), M_DEVBUF, M_WAITOK);
    293 		mfb_getdevconfig(ta->ta_addr, sc->sc_dc);
    294 	}
    295 	printf(": %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
    296 	    sc->sc_dc->dc_depth);
    297 
    298         tc_intr_establish(parent, ta->ta_cookie, TC_IPL_TTY, mfbintr, sc);
    299 
    300 	mfbbase = (caddr_t)sc->sc_dc->dc_vaddr;
    301 	*(u_int8_t *)(mfbbase + MFB_IREQ_OFFSET) = 0;
    302 	junk = *(u_int8_t *)(mfbbase + MFB_IREQ_OFFSET);
    303 	*(u_int8_t *)(mfbbase + MFB_IREQ_OFFSET) = 1;
    304 
    305 	waa.console = console;
    306 	waa.scrdata = &mfb_screenlist;
    307 	waa.accessops = &mfb_accessops;
    308 	waa.accesscookie = sc;
    309 
    310 	config_found(self, &waa, wsemuldisplaydevprint);
    311 }
    312 
    313 int
    314 mfbioctl(v, cmd, data, flag, p)
    315 	void *v;
    316 	u_long cmd;
    317 	caddr_t data;
    318 	int flag;
    319 	struct proc *p;
    320 {
    321 	struct mfb_softc *sc = v;
    322 	struct fb_devconfig *dc = sc->sc_dc;
    323 	int turnoff;
    324 
    325 	switch (cmd) {
    326 	case WSDISPLAYIO_GTYPE:
    327 		*(u_int *)data = WSDISPLAY_TYPE_MFB;
    328 		return (0);
    329 
    330 	case WSDISPLAYIO_GINFO:
    331 #define	wsd_fbip ((struct wsdisplay_fbinfo *)data)
    332 		wsd_fbip->height = sc->sc_dc->dc_ht;
    333 		wsd_fbip->width = sc->sc_dc->dc_wid;
    334 		wsd_fbip->depth = sc->sc_dc->dc_depth;
    335 		wsd_fbip->cmsize = 0;
    336 #undef fbt
    337 		return (0);
    338 
    339 	case WSDISPLAYIO_GETCMAP:
    340 	case WSDISPLAYIO_PUTCMAP:
    341 		return (ENOTTY);
    342 
    343 	case WSDISPLAYIO_SVIDEO:
    344 		turnoff = *(int *)data == WSDISPLAYIO_VIDEO_OFF;
    345 		if ((dc->dc_blanked == 0) ^ turnoff) {
    346 			/* sc->sc_changed |= DATA_ALL_CHANGED; */
    347 			dc->dc_blanked = turnoff;
    348 		}
    349 		return (0);
    350 
    351 	case WSDISPLAYIO_GVIDEO:
    352 		*(u_int *)data = dc->dc_blanked ?
    353 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    354 		return (0);
    355 
    356 	case WSDISPLAYIO_GCURPOS:
    357 		*(struct wsdisplay_curpos *)data = sc->sc_cursor.cc_pos;
    358 		return (0);
    359 
    360 	case WSDISPLAYIO_SCURPOS:
    361 		set_curpos(sc, (struct wsdisplay_curpos *)data);
    362 		bt431_set_curpos(sc);
    363 		return (0);
    364 
    365 	case WSDISPLAYIO_GCURMAX:
    366 		((struct wsdisplay_curpos *)data)->x =
    367 		((struct wsdisplay_curpos *)data)->y = CURSOR_MAX_SIZE;
    368 		return (0);
    369 
    370 	case WSDISPLAYIO_GCURSOR:
    371 		return get_cursor(sc, (struct wsdisplay_cursor *)data);
    372 
    373 	case WSDISPLAYIO_SCURSOR:
    374 		return set_cursor(sc, (struct wsdisplay_cursor *)data);
    375 	}
    376 	return ENOTTY;
    377 }
    378 
    379 int
    380 mfbmmap(v, offset, prot)
    381 	void *v;
    382 	off_t offset;
    383 	int prot;
    384 {
    385 	struct mfb_softc *sc = v;
    386 
    387 	if (offset > MFB_FB_SIZE)
    388 		return (-1);
    389 	return machine_btop(sc->sc_dc->dc_paddr + offset);
    390 }
    391 
    392 int
    393 mfb_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
    394 	void *v;
    395 	const struct wsscreen_descr *type;
    396 	void **cookiep;
    397 	int *curxp, *curyp;
    398 	long *attrp;
    399 {
    400 	struct mfb_softc *sc = v;
    401 	long defattr;
    402 
    403 	if (sc->nscreens > 0)
    404 		return (ENOMEM);
    405 
    406 	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
    407 	*curxp = 0;
    408 	*curyp = 0;
    409 	rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
    410 	*attrp = defattr;
    411 	sc->nscreens++;
    412 	return (0);
    413 }
    414 
    415 void
    416 mfb_free_screen(v, cookie)
    417 	void *v;
    418 	void *cookie;
    419 {
    420 	struct mfb_softc *sc = v;
    421 
    422 	if (sc->sc_dc == &mfb_console_dc)
    423 		panic("mfb_free_screen: console");
    424 
    425 	sc->nscreens--;
    426 }
    427 
    428 void
    429 mfb_show_screen(v, cookie)
    430 	void *v;
    431 	void *cookie;
    432 {
    433 }
    434 
    435 int
    436 mfb_load_font(v, cookie, first, num, stride, data)
    437 	void *v;
    438 	void *cookie;
    439 	int first, num, stride;
    440 	void *data;
    441 {
    442 	return (EINVAL);
    443 }
    444 
    445 int
    446 mfb_cnattach(addr)
    447         tc_addr_t addr;
    448 {
    449         struct fb_devconfig *dcp = &mfb_console_dc;
    450         long defattr;
    451 
    452         mfb_getdevconfig(addr, dcp);
    453 
    454         rcons_alloc_attr(&dcp->dc_rcons, 0, 0, 0, &defattr);
    455 
    456         wsdisplay_cnattach(&mfb_stdscreen, &dcp->dc_rcons,
    457                            0, 0, defattr);
    458         mfb_consaddr = addr;
    459         return(0);
    460 }
    461 
    462 
    463 int
    464 mfbintr(arg)
    465 	void *arg;
    466 {
    467 	struct mfb_softc *sc = arg;
    468 	caddr_t mfbbase = (caddr_t)sc->sc_dc->dc_vaddr;
    469 	struct bt455reg *vdac;
    470 	struct bt431reg *curs;
    471 	int v;
    472 	volatile register int junk;
    473 
    474 	junk = *(u_int8_t *)(mfbbase + MFB_IREQ_OFFSET);
    475 	/* *(u_int8_t *)(mfbbase + MFB_IREQ_OFFSET) = 1; */
    476 
    477 	if (sc->sc_changed == 0)
    478 		return (1);
    479 
    480 	vdac = (void *)(mfbbase + MFB_BT455_OFFSET);
    481 	curs = (void *)(mfbbase + MFB_BT431_OFFSET);
    482 
    483 	v = sc->sc_changed;
    484 	sc->sc_changed = 0;
    485 	if (v & DATA_ENB_CHANGED) {
    486 		BT431_SELECT(curs, BT431_REG_COMMAND);
    487 		curs->bt_ctl = (sc->sc_curenb) ? 0x4444 : 0x0404;
    488 	}
    489 	if (v & DATA_CURSHAPE_CHANGED) {
    490 		u_int8_t *bp1, *bp2;
    491 		u_int16_t twin;
    492 		int index;
    493 
    494 		bp1 = (u_int8_t *)&sc->sc_cursor.cc_image;
    495 		bp2 = (u_int8_t *)(&sc->sc_cursor.cc_image + CURSOR_MAX_SIZE);
    496 
    497 		BT431_SELECT(curs, BT431_REG_CRAM_BASE+0);
    498 		for (index = 0;
    499 		    index < sizeof(sc->sc_cursor.cc_image)/sizeof(u_int16_t);
    500 		    index++) {
    501 			twin = *bp1++ | (*bp2++ << 8);
    502 			curs->bt_ram = twin;
    503 			tc_wmb();
    504 		}
    505 	}
    506 	return (1);
    507 }
    508 
    509 void
    510 mfbinit(dc)
    511 	struct fb_devconfig *dc;
    512 {
    513 	caddr_t mfbbase = (caddr_t)dc->dc_vaddr;
    514 	struct bt431reg *curs = (void *)(mfbbase + MFB_BT431_OFFSET);
    515 	struct bt455reg *vdac = (void *)(mfbbase + MFB_BT455_OFFSET);
    516 	int i;
    517 
    518 	BT455_SELECT(vdac, 0);
    519 	vdac->bt_cmap = 0;	tc_wmb();
    520 	vdac->bt_cmap = 0;	tc_wmb();
    521 	vdac->bt_cmap = 0;	tc_wmb();
    522 
    523 	vdac->bt_cmap = 0;	tc_wmb();
    524 	vdac->bt_cmap = 0xff;	tc_wmb();
    525 	vdac->bt_cmap = 0;	tc_wmb();
    526 
    527 	for (i = 2; i < 16; i++) {
    528 		vdac->bt_cmap = 0;	tc_wmb();
    529 		vdac->bt_cmap = 0;	tc_wmb();
    530 		vdac->bt_cmap = 0;	tc_wmb();
    531 	}
    532 
    533 	BT455_SELECT(vdac, 8);
    534 	vdac->bt_cmap = 0;	tc_wmb();
    535 	vdac->bt_cmap = 0;	tc_wmb();
    536 	vdac->bt_cmap = 0;	tc_wmb();
    537 
    538 	vdac->bt_cmap = 0;	tc_wmb();
    539 	vdac->bt_cmap = 0;	tc_wmb();
    540 	vdac->bt_cmap = 0;	tc_wmb();
    541 
    542 	vdac->bt_ovly = 0;	tc_wmb();
    543 	vdac->bt_ovly = 0xff;	tc_wmb();
    544 	vdac->bt_ovly = 0;	tc_wmb();
    545 
    546 	BT431_SELECT(curs, BT431_REG_COMMAND);
    547 	curs->bt_ctl = 0x0404;	tc_wmb();
    548 	curs->bt_ctl = 0;	tc_wmb();
    549 	curs->bt_ctl = 0;	tc_wmb();
    550 	curs->bt_ctl = 0;	tc_wmb();
    551 	curs->bt_ctl = 0;	tc_wmb();
    552 	curs->bt_ctl = 0;	tc_wmb();
    553 	curs->bt_ctl = 0;	tc_wmb();
    554 	curs->bt_ctl = 0;	tc_wmb();
    555 	curs->bt_ctl = 0;	tc_wmb();
    556 	curs->bt_ctl = 0;	tc_wmb();
    557 	curs->bt_ctl = 0;	tc_wmb();
    558 	curs->bt_ctl = 0;	tc_wmb();
    559 	curs->bt_ctl = 0;	tc_wmb();
    560 }
    561 
    562 static int
    563 set_cursor(sc, p)
    564 	struct mfb_softc *sc;
    565 	struct wsdisplay_cursor *p;
    566 {
    567 #define	cc (&sc->sc_cursor)
    568 	int v, count;
    569 
    570 	v = p->which;
    571 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    572 		if (p->size.x > CURSOR_MAX_SIZE || p->size.y > CURSOR_MAX_SIZE)
    573 			return (EINVAL);
    574 		count = (CURSOR_MAX_SIZE / NBBY) * p->size.y;
    575 		if (!useracc(p->image, count, B_READ) ||
    576 		    !useracc(p->mask, count, B_READ))
    577 			return (EFAULT);
    578 	}
    579 	if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOCUR)) {
    580 		if (v & WSDISPLAY_CURSOR_DOCUR)
    581 			cc->cc_hot = p->hot;
    582 		if (v & WSDISPLAY_CURSOR_DOPOS)
    583 			set_curpos(sc, &p->pos);
    584 		bt431_set_curpos(sc);
    585 	}
    586 
    587 	sc->sc_changed = 0;
    588 	if (v & WSDISPLAY_CURSOR_DOCUR) {
    589 		sc->sc_curenb = p->enable;
    590 		sc->sc_changed |= DATA_ENB_CHANGED;
    591 	}
    592 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    593 		cc->cc_size = p->size;
    594 		memset(cc->cc_image, 0, sizeof cc->cc_image);
    595 		copyin(p->image, (caddr_t)cc->cc_image, count);
    596 		copyin(p->mask, (caddr_t)(cc->cc_image+CURSOR_MAX_SIZE), count);
    597 		sc->sc_changed |= DATA_CURSHAPE_CHANGED;
    598 	}
    599 
    600 	return (0);
    601 #undef cc
    602 }
    603 
    604 static int
    605 get_cursor(sc, p)
    606 	struct mfb_softc *sc;
    607 	struct wsdisplay_cursor *p;
    608 {
    609 	return (ENOTTY); /* XXX */
    610 }
    611 
    612 static void
    613 set_curpos(sc, curpos)
    614 	struct mfb_softc *sc;
    615 	struct wsdisplay_curpos *curpos;
    616 {
    617 	struct fb_devconfig *dc = sc->sc_dc;
    618 	int x = curpos->x, y = curpos->y;
    619 
    620 	if (y < 0)
    621 		y = 0;
    622 	else if (y > dc->dc_ht - sc->sc_cursor.cc_size.y - 1)
    623 		y = dc->dc_ht - sc->sc_cursor.cc_size.y - 1;
    624 	if (x < 0)
    625 		x = 0;
    626 	else if (x > dc->dc_wid - sc->sc_cursor.cc_size.x - 1)
    627 		x = dc->dc_wid - sc->sc_cursor.cc_size.x - 1;
    628 	sc->sc_cursor.cc_pos.x = x;
    629 	sc->sc_cursor.cc_pos.y = y;
    630 }
    631 
    632 void
    633 bt431_set_curpos(sc)
    634 	struct mfb_softc *sc;
    635 {
    636 	caddr_t mfbbase = (caddr_t)sc->sc_dc->dc_vaddr;
    637 	struct bt431reg *curs = (void *)(mfbbase + MFB_BT431_OFFSET);
    638 	int x = 360, y = 36; /* magic offset of MX coordinate */
    639 	u_int16_t twin;
    640 	int s;
    641 
    642 	x += sc->sc_cursor.cc_pos.x;
    643 	y += sc->sc_cursor.cc_pos.y;
    644 
    645 #if 0 /* MACH legend tells */
    646 	/*
    647 	 * Cx = x + D + H - P
    648 	 *  P = 37 if 1:1, 52 if 4:1, 57 if 5:1
    649 	 *  D = pixel skew between outdata and external data
    650 	 *  H = pixels between HSYNCH falling and active video
    651 	 *
    652 	 * Cy = y + V - 32
    653 	 *  V = scanlines between HSYNCH falling, two or more
    654 	 *	clocks after VSYNCH falling, and active video
    655 	 */
    656 #endif
    657 	s = spltty();
    658 
    659 	BT431_SELECT(curs, BT431_REG_CURSOR_X_LOW);
    660 	curs->bt_ctl = TWIN_LO(x);
    661 	curs->bt_ctl = TWIN_HI(x);
    662 	curs->bt_ctl = TWIN_LO(y);
    663 	curs->bt_ctl = TWIN_HI(y);
    664 
    665 	splx(s);
    666 }
    667